diff -Nru a/Documentation/Changes b/Documentation/Changes
--- a/Documentation/Changes	Mon Dec 23 21:22:00 2002
+++ b/Documentation/Changes	Mon Dec 23 21:22:00 2002
@@ -61,6 +61,7 @@
 o  PPP                    2.4.0                   # pppd --version
 o  isdn4k-utils           3.1pre1                 # isdnctrl 2>&1|grep version
 o  procps                 2.0.9                   # ps --version
+o  oprofile               0.5                     # oprofiled --version
 
 Kernel compilation
 ==================
@@ -368,6 +369,10 @@
 ---------
 o  <ftp://ftp.inr.ac.ru/ip-routing/iproute2-2.2.4-now-ss991023.tar.gz>
 
+OProfile
+--------
+o  <http://oprofile.sf.net/download.php3>
+ 
 Suggestions and corrections
 ===========================
 
diff -Nru a/Documentation/DMA-API.txt b/Documentation/DMA-API.txt
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/Documentation/DMA-API.txt	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,325 @@
+               Dynamic DMA mapping using the generic device
+               ============================================
+
+        James E.J. Bottomley <James.Bottomley@HansenPartnership.com>
+
+This document describes the DMA API.  For a more gentle introduction
+phrased in terms of the pci_ equivalents (and actual examples) see
+DMA-mapping.txt
+
+This API is split into two pieces.  Part I describes the API and the
+corresponding pci_ API.  Part II describes the extensions to the API
+for supporting non-consistent memory machines.  Unless you know that
+your driver absolutely has to support non-consistent platforms (this
+is usually only legacy platforms) you should only use the API
+described in part I.
+
+Part I - pci_ and dma_ Equivalent API 
+-------------------------------------
+
+To get the pci_ API, you must #include <linux/pci.h>
+To get the dma_ API, you must #include <linux/dma-mapping.h>
+
+void *
+dma_alloc_coherent(struct device *dev, size_t size,
+			     dma_addr_t *dma_handle)
+void *
+pci_alloc_consistent(struct pci_dev *dev, size_t size,
+			     dma_addr_t *dma_handle)
+
+Consistent memory is memory for which a write by either the device or
+the processor can immediately be read by the processor or device
+without having to worry about caching effects.
+
+This routine allocates a region of <size> bytes of consistent memory.
+it also returns a <dma_handle> which may be cast to an unsigned
+integer the same width as the bus and used as the physical address
+base of the region.
+
+Returns: a pointer to the allocated region (in the processor's virtual
+address space) or NULL if the allocation failed.
+
+Note: consistent memory can be expensive on some platforms, and the
+minimum allocation length may be as big as a page, so you should
+consolidate your requests for consistent memory as much as possible.
+
+void
+dma_free_coherent(struct device *dev, size_t size, void *cpu_addr
+			   dma_addr_t dma_handle)
+void
+pci_free_consistent(struct pci_dev *dev, size_t size, void *cpu_addr
+			   dma_addr_t dma_handle)
+
+Free the region of consistent memory you previously allocated.  dev,
+size and dma_handle must all be the same as those passed into the
+consistent allocate.  cpu_addr must be the virtual address returned by
+the consistent allocate
+
+int
+dma_supported(struct device *dev, u64 mask)
+int
+pci_dma_supported(struct device *dev, u64 mask)
+
+Checks to see if the device can support DMA to the memory described by
+mask.
+
+Returns: 1 if it can and 0 if it can't.
+
+Notes: This routine merely tests to see if the mask is possible.  It
+won't change the current mask settings.  It is more intended as an
+internal API for use by the platform than an external API for use by
+driver writers.
+
+int
+dma_set_mask(struct device *dev, u64 mask)
+int
+pci_dma_set_mask(struct pci_device *dev, u64 mask)
+
+Checks to see if the mask is possible and updates the device
+parameters if it is.
+
+Returns: 1 if successful and 0 if not
+
+dma_addr_t
+dma_map_single(struct device *dev, void *cpu_addr, size_t size,
+		      enum dma_data_direction direction)
+dma_addr_t
+pci_map_single(struct device *dev, void *cpu_addr, size_t size,
+		      int direction)
+
+Maps a piece of processor virtual memory so it can be accessed by the
+device and returns the physical handle of the memory.
+
+The direction for both api's may be converted freely by casting.
+However the dma_ API uses a strongly typed enumerator for its
+direction:
+
+DMA_NONE		= PCI_DMA_NONE		no direction (used for
+						debugging)
+DMA_TO_DEVICE		= PCI_DMA_TODEVICE	data is going from the
+						memory to the device
+DMA_FROM_DEVICE		= PCI_DMA_FROMDEVICE	data is coming from
+						the device to the
+						memory
+DMA_BIDIRECTIONAL	= PCI_DMA_BIDIRECTIONAL	direction isn't known
+
+Notes:  Not all memory regions in a machine can be mapped by this
+API.  Further, regions that appear to be physically contiguous in
+kernel virtual space may not be contiguous as physical memory.  Since
+this API does not provide any scatter/gather capability, it will fail
+if the user tries to map a non physically contiguous piece of memory.
+For this reason, it is recommended that memory mapped by this API be
+obtained only from sources which guarantee to be physically contiguous
+(like kmalloc).
+
+Further, the physical address of the memory must be within the
+dma_mask of the device (the dma_mask represents a bit mask of the
+addressable region for the device.  i.e. if the physical address of
+the memory anded with the dma_mask is still equal to the physical
+address, then the device can perform DMA to the memory).  In order to
+ensure that the memory allocated by kmalloc is within the dma_mask,
+the driver may specify various platform dependent flags to restrict
+the physical memory range of the allocation (e.g. on x86, GFP_DMA
+guarantees to be within the first 16Mb of available physical memory,
+as required by ISA devices).
+
+Note also that the above constraints on physical contiguity and
+dma_mask may not apply if the platform has an IOMMU (a device which
+supplies a physical to virtual mapping between the I/O memory bus and
+the device).  However, to be portable, device driver writers may *not*
+assume that such an IOMMU exists.
+
+Warnings:  Memory coherency operates at a granularity called the cache
+line width.  In order for memory mapped by this API to operate
+correctly, the mapped region must begin exactly on a cache line
+boundary and end exactly on one (to prevent two separately mapped
+regions from sharing a single cache line).  Since the cache line size
+may not be known at compile time, the API will not enforce this
+requirement.  Therefore, it is recommended that driver writers who
+don't take special care to determine the cache line size at run time
+only map virtual regions that begin and end on page boundaries (which
+are guaranteed also to be cache line boundaries).
+
+DMA_TO_DEVICE synchronisation must be done after the last modification
+of the memory region by the software and before it is handed off to
+the driver.  Once this primitive is used.  Memory covered by this
+primitive should be treated as read only by the device.  If the device
+may write to it at any point, it should be DMA_BIDIRECTIONAL (see
+below).
+
+DMA_FROM_DEVICE synchronisation must be done before the driver
+accesses data that may be changed by the device.  This memory should
+be treated as read only by the driver.  If the driver needs to write
+to it at any point, it should be DMA_BIDIRECTIONAL (see below).
+
+DMA_BIDIRECTIONAL requires special handling: it means that the driver
+isn't sure if the memory was modified before being handed off to the
+device and also isn't sure if the device will also modify it.  Thus,
+you must always sync bidirectional memory twice: once before the
+memory is handed off to the device (to make sure all memory changes
+are flushed from the processor) and once before the data may be
+accessed after being used by the device (to make sure any processor
+cache lines are updated with data that the device may have changed.
+
+void
+dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
+		 enum dma_data_direction direction)
+void
+pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
+		 size_t size, int direction)
+
+Unmaps the region previously mapped.  All the parameters passed in
+must be identical to those passed in (and returned) by the mapping
+API.
+
+dma_addr_t
+dma_map_page(struct device *dev, struct page *page,
+		    unsigned long offset, size_t size,
+		    enum dma_data_direction direction)
+dma_addr_t
+pci_map_page(struct pci_dev *hwdev, struct page *page,
+		    unsigned long offset, size_t size, int direction)
+void
+dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
+	       enum dma_data_direction direction)
+void
+pci_unmap_page(struct pci_dev *hwdev, dma_addr_t dma_address,
+	       size_t size, int direction)
+
+API for mapping and unmapping for pages.  All the notes and warnings
+for the other mapping APIs apply here.  Also, although the <offset>
+and <size> parameters are provided to do partial page mapping, it is
+recommended that you never use these unless you really know what the
+cache width is.
+
+int
+dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
+	   enum dma_data_direction direction)
+int
+pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
+	   int nents, int direction)
+
+Maps a scatter gather list from the block layer.
+
+Returns: the number of physical segments mapped (this may be shorted
+than <nents> passed in if the block layer determines that some
+elements of the scatter/gather list are physically adjacent and thus
+may be mapped with a single entry).
+
+void
+dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
+	     enum dma_data_direction direction)
+void
+pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
+	     int nents, int direction)
+
+unmap the previously mapped scatter/gather list.  All the parameters
+must be the same as those and passed in to the scatter/gather mapping
+API.
+
+Note: <nents> must be the number you passed in, *not* the number of
+physical entries returned.
+
+void
+dma_sync_single(struct device *dev, dma_addr_t dma_handle, size_t size,
+		enum dma_data_direction direction)
+void
+pci_dma_sync_single(struct pci_dev *hwdev, dma_addr_t dma_handle,
+			   size_t size, int direction)
+void
+dma_sync_sg(struct device *dev, struct scatterlist *sg, int nelems,
+			  enum dma_data_direction direction)
+void
+pci_dma_sync_sg(struct pci_dev *hwdev, struct scatterlist *sg,
+		       int nelems, int direction)
+
+synchronise a single contiguous or scatter/gather mapping.  All the
+parameters must be the same as those passed into the single mapping
+API.
+
+Notes:  You must do this:
+
+- Before reading values that have been written by DMA from the device
+  (use the DMA_FROM_DEVICE direction)
+- After writing values that will be written to the device using DMA
+  (use the DMA_TO_DEVICE) direction
+- before *and* after handing memory to the device if the memory is
+  DMA_BIDIRECTIONAL
+
+See also dma_map_single().
+
+Part II - Advanced dma_ usage
+-----------------------------
+
+Warning: These pieces of the DMA API have no PCI equivalent.  They
+should also not be used in the majority of cases, since they cater for
+unlikely corner cases that don't belong in usual drivers.
+
+If you don't understand how cache line coherency works between a
+processor and an I/O device, you should not be using this part of the
+API at all.
+
+void *
+dma_alloc_noncoherent(struct device *dev, size_t size,
+			       dma_addr_t *dma_handle)
+
+Identical to dma_alloc_coherent() except that the platform will
+choose to return either consistent or non-consistent memory as it sees
+fit.  By using this API, you are guaranteeing to the platform that you
+have all the correct and necessary sync points for this memory in the
+driver should it choose to return non-consistent memory.
+
+Note: where the platform can return consistent memory, it will
+guarantee that the sync points become nops.
+
+Warning:  Handling non-consistent memory is a real pain.  You should
+only ever use this API if you positively know your driver will be
+required to work on one of the rare (usually non-PCI) architectures
+that simply cannot make consistent memory.
+
+void
+dma_free_noncoherent(struct device *dev, size_t size, void *cpu_addr,
+			      dma_addr_t dma_handle)
+
+free memory allocated by the nonconsistent API.  All parameters must
+be identical to those passed in (and returned by
+dma_alloc_noncoherent()).
+
+int
+dma_is_consistent(dma_addr_t dma_handle)
+
+returns true if the memory pointed to by the dma_handle is actually
+consistent.
+
+int
+dma_get_cache_alignment(void)
+
+returns the processor cache alignment.  This is the absolute minimum
+alignment *and* width that you must observe when either mapping
+memory or doing partial flushes.
+
+Notes: This API may return a number *larger* than the actual cache
+line, but it will guarantee that one or more cache lines fit exactly
+into the width returned by this call.  It will also always be a power
+of two for easy alignment
+
+void
+dma_sync_single_range(struct device *dev, dma_addr_t dma_handle,
+		      unsigned long offset, size_t size,
+		      enum dma_data_direction direction)
+
+does a partial sync.  starting at offset and continuing for size.  You
+must be careful to observe the cache alignment and width when doing
+anything like this.  You must also be extra careful about accessing
+memory you intend to sync partially.
+
+void
+dma_cache_sync(void *vaddr, size_t size,
+	       enum dma_data_direction direction)
+
+Do a partial sync of memory that was allocated by
+dma_alloc_noncoherent(), starting at virtual address vaddr and
+continuing on for size.  Again, you *must* observe the cache line
+boundaries when doing this.
+
+
diff -Nru a/Documentation/DMA-mapping.txt b/Documentation/DMA-mapping.txt
--- a/Documentation/DMA-mapping.txt	Mon Dec 23 21:21:55 2002
+++ b/Documentation/DMA-mapping.txt	Mon Dec 23 21:21:55 2002
@@ -5,6 +5,10 @@
 		 Richard Henderson <rth@cygnus.com>
 		  Jakub Jelinek <jakub@redhat.com>
 
+This document describes the DMA mapping system in terms of the pci_
+API.  For a similar API that works for generic devices, see
+DMA-API.txt.
+
 Most of the 64bit platforms have special hardware that translates bus
 addresses (DMA addresses) into physical addresses.  This is similar to
 how page tables and/or a TLB translates virtual addresses to physical
diff -Nru a/Documentation/filesystems/Locking b/Documentation/filesystems/Locking
--- a/Documentation/filesystems/Locking	Mon Dec 23 21:22:00 2002
+++ b/Documentation/filesystems/Locking	Mon Dec 23 21:22:00 2002
@@ -92,7 +92,7 @@
 	void (*delete_inode) (struct inode *);
 	void (*put_super) (struct super_block *);
 	void (*write_super) (struct super_block *);
-	void (*sync_fs) (struct super_block *sb, int wait);
+	int (*sync_fs) (struct super_block *sb, int wait);
 	int (*statfs) (struct super_block *, struct statfs *);
 	int (*remount_fs) (struct super_block *, int *, char *);
 	void (*clear_inode) (struct inode *);
diff -Nru a/Documentation/networking/bonding.txt b/Documentation/networking/bonding.txt
--- a/Documentation/networking/bonding.txt	Mon Dec 23 21:21:52 2002
+++ b/Documentation/networking/bonding.txt	Mon Dec 23 21:21:52 2002
@@ -17,6 +17,23 @@
 For new versions of the driver, patches for older kernels and the updated
 userspace tools, please follow the links at the end of this file.
 
+
+Table of Contents
+=================
+ 
+Installation
+Bond Configuration
+Module Parameters
+Configuring Multiple Bonds
+Switch Configuration
+Verifying Bond Configuration
+Frequently Asked Questions
+High Availability
+Promiscuous Sniffing notes
+Limitations
+Resources and Links
+
+
 Installation
 ============
 
@@ -51,16 +68,21 @@
     # gcc -Wall -Wstrict-prototypes -O -I/usr/src/linux/include ifenslave.c -o ifenslave 
     # cp ifenslave /sbin/ifenslave
 
-3) Configure your system
-------------------------
-Also see the following section on the module parameters. You will need to add
-at least the following line to /etc/conf.modules (or /etc/modules.conf):
+
+Bond Configuration
+==================
+
+You will need to add at least the following line to /etc/modules.conf
+so the bonding driver will automatically load when the bond0 interface is 
+configured. Refer to the modules.conf manual page for specific modules.conf 
+syntax details. The Module Parameters section of this document describes each 
+bonding driver parameter. 
 
 	alias bond0 bonding
 
-Use standard distribution techniques to define bond0 network interface. For
-example, on modern RedHat distributions, create ifcfg-bond0 file in
-/etc/sysconfig/network-scripts directory that looks like this:
+Use standard distribution techniques to define the bond0 network interface. For
+example, on modern Red Hat distributions, create an ifcfg-bond0 file in
+the /etc/sysconfig/network-scripts directory that resembles the following:
 
 DEVICE=bond0
 IPADDR=192.168.1.1
@@ -71,12 +93,12 @@
 BOOTPROTO=none
 USERCTL=no
 
-(put the appropriate values for you network instead of 192.168.1).
+(use appropriate values for your network above)
 
-All interfaces that are part of the trunk, should have SLAVE and MASTER
-definitions. For example, in the case of RedHat, if you wish to make eth0 and
-eth1 (or other interfaces) a part of the bonding interface bond0, their config
-files (ifcfg-eth0, ifcfg-eth1, etc.) should look like this:
+All interfaces that are part of a bond should have SLAVE and MASTER
+definitions. For example, in the case of Red Hat, if you wish to make eth0 and
+eth1 a part of the bonding interface bond0, their config files (ifcfg-eth0 and
+ifcfg-eth1) should resemble the following:
 
 DEVICE=eth0
 USERCTL=no
@@ -85,89 +107,261 @@
 SLAVE=yes
 BOOTPROTO=none
 
-(use DEVICE=eth1 for eth1 and MASTER=bond1 for bond1 if you have configured
-second bonding interface). 
+Use DEVICE=eth1 in the ifcfg-eth1 config file. If you configure a second bonding
+interface (bond1), use MASTER=bond1 in the config file to make the network
+interface be a slave of bond1.
 
 Restart the networking subsystem or just bring up the bonding device if your
-administration tools allow it. Otherwise, reboot. (For the case of RedHat
-distros, you can do `ifup bond0' or `/etc/rc.d/init.d/network restart'.)
+administration tools allow it. Otherwise, reboot. On Red Hat distros you can 
+issue `ifup bond0' or `/etc/rc.d/init.d/network restart'.
 
 If the administration tools of your distribution do not support master/slave
-notation in configuration of network interfaces, you will need to configure
-the bonding device with the following commands manually:
+notation in configuring network interfaces, you will need to manually configure 
+the bonding device with the following commands:
+
+    # /sbin/ifconfig bond0 192.168.1.1 netmask 255.255.255.0 \
+      broadcast 192.168.1.255 up
 
-    # /sbin/ifconfig bond0 192.168.1.1 up
     # /sbin/ifenslave bond0 eth0
     # /sbin/ifenslave bond0 eth1
 
-(substitute 192.168.1.1 with your IP address and add custom network and custom
-netmask to the arguments of ifconfig if required).
+(use appropriate values for your network above)
 
-You can then create a script with these commands and put it into the appropriate
-rc directory.
+You can then create a script containing these commands and place it in the 
+appropriate rc directory.
 
-If you specifically need that all your network drivers are loaded before the
-bonding driver, use one of modutils' powerful features : in your modules.conf,
-tell that when asked for bond0, modprobe should first load all your interfaces :
+If you specifically need all network drivers loaded before the bonding driver,
+adding the following line to modules.conf will cause the network driver for 
+eth0 and eth1 to be loaded before the bonding driver.
 
 probeall bond0 eth0 eth1 bonding
 
-Be careful not to reference bond0 itself at the end of the line, or modprobe will
-die in an endless recursive loop.
-
-4) Module parameters.
----------------------
-The following module parameters can be passed:
+Be careful not to reference bond0 itself at the end of the line, or modprobe 
+will die in an endless recursive loop.
 
-    mode=
+To have device characteristics (such as MTU size) propagate to slave devices, 
+set the bond characteristics before enslaving the device.  The characteristics 
+are propagated during the enslave process.
+
+If running SNMP agents, the bonding driver should be loaded before any network 
+drivers participating in a bond. This requirement is due to the the interface 
+index (ipAdEntIfIndex) being associated to the first interface found with a 
+given IP address. That is, there is only one ipAdEntIfIndex for each IP 
+address. For example, if eth0 and eth1 are slaves of bond0 and the driver for 
+eth0 is loaded before the bonding driver, the interface for the IP address 
+will be associated with the eth0 interface. This configuration is shown below, 
+the IP address 192.168.1.1 has an interface index of 2 which indexes to eth0 
+in the ifDescr table (ifDescr.2).
+
+     interfaces.ifTable.ifEntry.ifDescr.1 = lo
+     interfaces.ifTable.ifEntry.ifDescr.2 = eth0
+     interfaces.ifTable.ifEntry.ifDescr.3 = eth1
+     interfaces.ifTable.ifEntry.ifDescr.4 = eth2
+     interfaces.ifTable.ifEntry.ifDescr.5 = eth3
+     interfaces.ifTable.ifEntry.ifDescr.6 = bond0
+     ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.10.10.10.10 = 5
+     ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.192.168.1.1 = 2
+     ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.10.74.20.94 = 4
+     ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.127.0.0.1 = 1
+
+This problem is avoided by loading the bonding driver before any network
+drivers participating in a bond. Below is an example of loading the bonding 
+driver first, the IP address 192.168.1.1 is correctly associated with ifDescr.2.
+
+     interfaces.ifTable.ifEntry.ifDescr.1 = lo
+     interfaces.ifTable.ifEntry.ifDescr.2 = bond0
+     interfaces.ifTable.ifEntry.ifDescr.3 = eth0
+     interfaces.ifTable.ifEntry.ifDescr.4 = eth1
+     interfaces.ifTable.ifEntry.ifDescr.5 = eth2
+     interfaces.ifTable.ifEntry.ifDescr.6 = eth3
+     ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.10.10.10.10 = 6
+     ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.192.168.1.1 = 2
+     ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.10.74.20.94 = 5
+     ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex.127.0.0.1 = 1
+
+While some distributions may not report the interface name in ifDescr,
+the association between the IP address and IfIndex remains and SNMP
+functions such as Interface_Scan_Next will report that association.
 
-Possible values are 0 (round robin policy, default) and 1 (active backup
-policy), and 2 (XOR).  See question 9 and the HA section for additional info.
 
-    miimon=
-
-Use integer value for the frequency (in ms) of MII link monitoring. Zero value
-is default and means the link monitoring will be disabled. A good value is 100
-if you wish to use link monitoring. See HA section for additional info.
+Module Parameters
+=================
 
-    downdelay=
+Optional parameters for the bonding driver can be supplied as command line 
+arguments to the insmod command. Typically, these parameters are specified in 
+the file /etc/modules.conf (see the manual page for modules.conf). The 
+available bonding driver parameters are listed below. If a parameter is not 
+specified the default value is used. When initially configuring a bond, it
+is recommended "tail -f /var/log/messages" be run in a separate window to
+watch for bonding driver error messages.
+
+It is critical that either the miimon or arp_interval and arp_ip_target
+parameters be specified, otherwise serious network degradation will occur
+during link failures.
+
+mode
+        Specifies one of four bonding policies. The default is round-robin.
+        Possible values are:
+ 
+        0       Round-robin policy: Transmit in a sequential order from the
+                first available slave through the last. This mode provides
+                load balancing and fault tolerance.
+
+        1       Active-backup policy: Only one slave in the bond is active. A 
+                different slave becomes active if, and only if, the active slave
+                fails. The bond's MAC address is externally visible on only 
+                one port (network adapter) to avoid confusing the switch.
+                This mode provides fault tolerance.
+ 
+ 
+        2       XOR policy: Transmit based on [(source MAC address XOR'd with 
+                destination MAC address) modula slave count]. This selects the 
+                same slave for each destination MAC address. This mode provides
+                load balancing and fault tolerance.
+
+        3       Broadcast policy: transmits everything on all slave interfaces.
+                This mode provides fault tolerance.
+
+miimon
+ 
+        Specifies the frequency in milli-seconds that MII link monitoring will 
+        occur. A value of zero disables MII link monitoring. A value of 
+        100 is a good starting point. See High Availability section for 
+        additional information. The default value is 0.
+
+downdelay
+ 
+        Specifies the delay time in milli-seconds to disable a link after a 
+        link failure has been detected. This should be a multiple of miimon
+        value, otherwise the value will be rounded. The default value is 0.
+
+updelay
+ 
+        Specifies the delay time in milli-seconds to enable a link after a 
+        link up status has been detected. This should be a multiple of miimon
+        value, otherwise the value will be rounded. The default value is 0.
+ 
+arp_interval
+ 
+        Specifies the ARP monitoring frequency in milli-seconds. 
+        If ARP monitoring is used in a load-balancing mode (mode 0 or 2), the 
+        switch should be configured in a mode that evenly distributes packets 
+        across all links - such as round-robin. If the switch is configured to 
+        distribute the packets in an XOR fashion, all replies from the ARP 
+        targets will be received on the same link which could cause the other 
+        team members to fail. ARP monitoring should not be used in conjunction
+        with miimon. A value of 0 disables ARP monitoring. The default value 
+        is 0.
+ 
+arp_ip_target
+ 
+        Specifies the ip addresses to use when arp_interval is > 0. These are
+        the targets of the ARP request sent to determine the health of the link
+        to the targets. Specify these values in ddd.ddd.ddd.ddd format.
+        Multiple ip adresses must be seperated by a comma. At least one ip
+        address needs to be given for ARP monitoring to work. The maximum number
+        of targets that can be specified is set at 16.
+
+primary
+
+        A string (eth0, eth2, etc) to equate to a primary device. If this 
+        value is entered, and the device is on-line, it will be used first as 
+        the output media. Only when this device is off-line, will alternate 
+        devices be used. Otherwise, once a failover is detected and a new 
+        default output is chosen, it will remain the output media until it too 
+        fails. This is useful when one slave was preferred over another, i.e. 
+        when one slave is 1000Mbps and another is 100Mbps. If the 1000Mbps 
+        slave fails and is later restored, it may be preferred the faster slave
+        gracefully become the active slave - without deliberately failing the
+        100Mbps slave. Specifying a primary is only valid in active-backup mode.
+
+multicast
+
+        Integer value for the mode of operation for multicast support.
+        Possible values are:
+
+        0       Disabled (no multicast support)
+
+        1       Enabled on active slave only, useful in active-backup mode
+
+        2       Enabled on all slaves, this is the default
+
+
+Configuring Multiple Bonds
+==========================
+
+If several bonding interfaces are required, the driver must be loaded
+multiple times. For example, to configure two bonding interfaces with link 
+monitoring performed every 100 milli-seconds, the /etc/conf.modules should
+resemble the following:
 
-Use integer value for delaying disabling a link by this number (in ms) after
-the link failure has been detected. Must be a multiple of miimon. Default
-value is zero. See HA section for additional info.
+alias bond0 bonding
+alias bond1 bonding
 
-    updelay=
+options bond0 miimon=100
+options bond1 -o bonding1 miimon=100
 
-Use integer value for delaying enabling a link by this number (in ms) after
-the "link up" status has been detected. Must be a multiple of miimon. Default
-value is zero. See HA section for additional info.
+Configuring Multiple ARP Targets
+================================
 
-    arp_interval=
+While ARP monitoring can be done with just one target, it can be usefull
+in a High Availability setup to have several targets to monitor. In the
+case of just one target,  the target itself may go down or have a problem
+making it unresponsive to ARP requests. Having an additional target (or
+several) would increase the reliability of the ARP monitoring.
+Multiple ARP targets must be seperated by commas as follows:
 
-Use integer value for the frequency (in ms) of arp monitoring.  Zero value 
-is default and means the arp monitoring will be disabled.  See HA section
-for additional info.   This field is value in active_backup mode only.
+# example options for ARP monitoring with three targets
+alias bond0 bonding
+options bond0 arp_interval=60 arp_ip_target=192.168.0.1,192.168.0.3,192.168.0.9
 
-    arp_ip_target=
+For just a single target the options would resemble:
 
-An ip address to use when arp_interval is > 0.  This is the target of the
-arp request sent to determine the health of the link to the target.  
-Specify this value in ddd.ddd.ddd.ddd format.
+# example options for ARP monitoring with one target
+alias bond0 bonding
+options bond0 arp_interval=60 arp_ip_target=192.168.0.100
 
-If you need to configure several bonding devices, the driver must be loaded
-several times. I.e. for two bonding devices, your /etc/conf.modules must look
-like this:
 
-alias bond0 bonding
-alias bond1 bonding
 
-options bond0 miimon=100
-options bond1 -o bonding1 miimon=100
+Switch Configuration
+====================
 
-5) Testing configuration
-------------------------
-You can test the configuration and transmit policy with ifconfig. For example,
-for round robin policy, you should get something like this:
+While the switch does not need to be configured when the active-backup
+policy is used (mode=1), it does need to be configured for the round-robin, 
+XOR, and broadcast policies (mode=0, mode=2, and mode=3). 
+
+
+Verifying Bond Configuration
+============================
+
+1) Bonding information files
+----------------------------
+The bonding driver information files reside in the /proc/net/bond* directories. 
+
+Sample contents of /proc/net/bond0/info after the driver is loaded with 
+parameters of mode=0 and miimon=1000 is shown below.
+ 
+        Bonding Mode: load balancing (round-robin)
+        Currently Active Slave: eth0
+        MII Status: up
+        MII Polling Interval (ms): 1000
+        Up Delay (ms): 0
+        Down Delay (ms): 0
+ 
+        Slave Interface: eth1
+        MII Status: up
+        Link Failure Count: 1
+ 
+        Slave Interface: eth0
+        MII Status: up
+        Link Failure Count: 1
+
+2) Network verification
+-----------------------
+The network configuration can be verified using the ifconfig command. In
+the example below, the bond0 interface is the master (MASTER) while eth0 and 
+eth1 are slaves (SLAVE). Notice all slaves of bond0 have the same MAC address 
+(HWaddr) as bond0.
 
 [root]# /sbin/ifconfig
 bond0     Link encap:Ethernet  HWaddr 00:C0:F0:1F:37:B4  
@@ -193,12 +387,13 @@
           collisions:0 txqueuelen:100 
           Interrupt:9 Base address:0x1400 
 
-Questions :
-===========
+
+Frequently Asked Questions
+==========================
 
 1.  Is it SMP safe?
 
-	Yes.  The old 2.0.xx channel bonding patch was not SMP safe.
+	Yes. The old 2.0.xx channel bonding patch was not SMP safe.
 	The new driver was designed to be SMP safe from the start.
 
 2.  What type of cards will work with it?
@@ -209,31 +404,30 @@
 
 3.  How many bonding devices can I have?
 
-	One for each module you load. See section on module parameters for how
+	One for each module you load. See section on Module Parameters for how
 	to accomplish this.
 
 4.  How many slaves can a bonding device have?
 
-	Limited by the number of network interfaces Linux supports and the
-	number of cards you can place in your system.
+	Limited by the number of network interfaces Linux supports and/or the
+	number of network cards you can place in your system.
 
 5.  What happens when a slave link dies?
 
-	If your ethernet cards support MII status monitoring and the MII
-	monitoring has been enabled in the driver (see description of module
-	parameters), there will be no adverse consequences. This release
-	of the bonding driver knows how to get the MII information and
+	If your ethernet cards support MII or ETHTOOL link status monitoring 
+        and the MII monitoring has been enabled in the driver (see description 
+        of module parameters), there will be no adverse consequences. This 
+        release of the bonding driver knows how to get the MII information and
 	enables or disables its slaves according to their link status.
-	See section on HA for additional information.
+	See section on High Availability for additional information.
 
-	For ethernet cards not supporting MII status, or if you wish to 
-	verify that packets have been both send and received, you may
-	configure the arp_interval and arp_ip_target.  If packets have
-	not been sent or received during this interval, an arp request
-	is sent to the target to generate send and receive traffic.  
-	If after this interval, either the successful send and/or 
-	receive count has not incremented, the next slave in the sequence
-	will become the active slave.
+	For ethernet cards not supporting MII status, the arp_interval and
+        arp_ip_target parameters must be specified for bonding to work
+        correctly. If packets have not been sent or received during the
+        specified arp_interval durration, an ARP request is sent to the targets 
+        to generate send and receive traffic. If after this interval, either 
+        the successful send and/or receive count has not incremented, the next 
+        slave in the sequence will become the active slave.
 
 	If neither mii_monitor and arp_interval is configured, the bonding
 	driver will not handle this situation very well. The driver will 
@@ -245,11 +439,12 @@
 6.  Can bonding be used for High Availability?
 
 	Yes, if you use MII monitoring and ALL your cards support MII link
-	status reporting. See section on HA for more information.
+	status reporting. See section on High Availability for more information.
 
 7.  Which switches/systems does it work with?
 
-	In round-robin mode, it works with systems that support trunking:
+	In round-robin and XOR mode, it works with systems that support 
+	trunking:
 	
 	* Cisco 5500 series (look for EtherChannel support).
 	* SunTrunking software.
@@ -259,7 +454,8 @@
 	  units.
 	* Linux bonding, of course !
 	
-	In Active-backup mode, it should work with any Layer-II switches.
+	In active-backup mode, it should work with any Layer-II switche.
+
 
 8.  Where does a bonding device get its MAC address from?
 
@@ -297,55 +493,68 @@
 
 9.  Which transmit polices can be used?
 
-	Round robin, based on the order of enslaving, the output device
-	is selected base on the next available slave.  Regardless of
+	Round-robin, based on the order of enslaving, the output device
+	is selected base on the next available slave. Regardless of
 	the source and/or destination of the packet.
 
-	XOR, based on (src hw addr XOR dst hw addr) % slave cnt.  This
-	selects the same slave for each destination hw address.
-
 	Active-backup policy that ensures that one and only one device will
 	transmit at any given moment. Active-backup policy is useful for
 	implementing high availability solutions using two hubs (see
-	section on HA).
+	section on High Availability).
+
+	XOR, based on (src hw addr XOR dst hw addr) % slave count. This
+	policy selects the same slave for each destination hw address.
 
-High availability
+	Broadcast policy transmits everything on all slave interfaces.
+
+
+High Availability
 =================
 
-To implement high availability using the bonding driver, you need to
-compile the driver as module because currently it is the only way to pass
-parameters to the driver. This may change in the future.
-
-High availability is achieved by using MII status reporting. You need to
-verify that all your interfaces support MII link status reporting. On Linux
-kernel 2.2.17, all the 100 Mbps capable drivers and yellowfin gigabit driver
-support it. If your system has an interface that does not support MII status
-reporting, a failure of its link will not be detected!
-
-The bonding driver can regularly check all its slaves links by checking the
-MII status registers. The check interval is specified by the module argument
-"miimon" (MII monitoring). It takes an integer that represents the
-checking time in milliseconds. It should not come to close to (1000/HZ)
-(10 ms on i386) because it may then reduce the system interactivity. 100 ms
-seems to be a good value. It means that a dead link will be detected at most
-100 ms after it goes down.
+To implement high availability using the bonding driver, the driver needs to be
+compiled as a module, because currently it is the only way to pass parameters 
+to the driver. This may change in the future.
+
+High availability is achieved by using MII or ETHTOOL status reporting. You 
+need to verify that all your interfaces support MII or ETHTOOL link status 
+reporting.  On Linux kernel 2.2.17, all the 100 Mbps capable drivers and 
+yellowfin gigabit driver support MII. To determine if ETHTOOL link reporting 
+is available for interface eth0, type "ethtool eth0" and the "Link detected:" 
+line should contain the correct link status. If your system has an interface 
+that does not support MII or ETHTOOL status reporting, a failure of its link 
+will not be detected! A message indicating MII and ETHTOOL is not supported by 
+a network driver is logged when the bonding driver is loaded with a non-zero 
+miimon value.
+
+The bonding driver can regularly check all its slaves links using the ETHTOOL
+IOCTL (ETHTOOL_GLINK command) or by checking the MII status registers. The 
+check interval is specified by the module argument "miimon" (MII monitoring). 
+It takes an integer that represents the checking time in milliseconds. It 
+should not come to close to (1000/HZ) (10 milli-seconds on i386) because it 
+may then reduce the system interactivity. A value of 100 seems to be a good 
+starting point. It means that a dead link will be detected at most 100 
+milli-seconds after it goes down.
 
 Example:
 
    # modprobe bonding miimon=100
 
-Or, put in your /etc/modules.conf :
+Or, put the following lines in /etc/modules.conf:
 
    alias bond0 bonding
    options bond0 miimon=100
 
-There are currently two policies for high availability, depending on whether
-a) hosts are connected to a single host or switch that support trunking
-b) hosts are connected to several different switches or a single switch that
-   does not support trunking.
+There are currently two policies for high availability. They are dependent on 
+whether:
+
+   a) hosts are connected to a single host or switch that support trunking
+
+   b) hosts are connected to several different switches or a single switch that
+      does not support trunking
 
-1) HA on a single switch or host - load balancing
--------------------------------------------------
+
+1) High Availability on a single switch or host - load balancing
+----------------------------------------------------------------
 It is the easiest to set up and to understand. Simply configure the
 remote equipment (host or switch) to aggregate traffic over several
 ports (Trunk, EtherChannel, etc.) and configure the bonding interfaces.
@@ -356,7 +565,7 @@
 long time if all ports in a trunk go down. This is not Linux, but really
 the switch (reboot it to ensure).
 
-Example 1 : host to host at double speed
+Example 1 : host to host at twice the speed
 
           +----------+                          +----------+
           |          |eth0                  eth0|          |
@@ -370,7 +579,7 @@
      # ifconfig bond0 addr
      # ifenslave bond0 eth0 eth1
 
-Example 2 : host to switch at double speed
+Example 2 : host to switch at twice the speed
 
           +----------+                          +----------+
           |          |eth0                 port1|          |
@@ -384,7 +593,9 @@
      # ifconfig bond0 addr                     and port2
      # ifenslave bond0 eth0 eth1
 
-2) HA on two or more switches (or a single switch without trunking support)
+
+2) High Availability on two or more switches (or a single switch without 
+   trunking support)
 ---------------------------------------------------------------------------
 This mode is more problematic because it relies on the fact that there
 are multiple ports and the host's MAC address should be visible on one
@@ -423,14 +634,14 @@
                +--------------+ host2 +----------------+
                          eth0 +-------+ eth1
 
-In this configuration, there are an ISL - Inter Switch Link (could be a trunk),
+In this configuration, there is an ISL - Inter Switch Link (could be a trunk),
 several servers (host1, host2 ...) attached to both switches each, and one or
 more ports to the outside world (port3...). One an only one slave on each host
 is active at a time, while all links are still monitored (the system can
 detect a failure of active and backup links).
 
 Each time a host changes its active interface, it sticks to the new one until
-it goes down. In this example, the hosts are not too much affected by the
+it goes down. In this example, the hosts are negligibly affected by the
 expiration time of the switches' forwarding tables.
 
 If host1 and host2 have the same functionality and are used in load balancing
@@ -460,6 +671,7 @@
 it goes down. In this example, the host is strongly affected by the expiration
 time of the switch forwarding table.
 
+
 3) Adapting to your switches' timing
 ------------------------------------
 If your switches take a long time to go into backup mode, it may be
@@ -488,8 +700,34 @@
     # modprobe bonding miimon=100 mode=1 downdelay=2000 updelay=5000
     # modprobe bonding miimon=100 mode=0 downdelay=0 updelay=5000
 
-4) Limitations
---------------
+
+Promiscuous Sniffing notes
+==========================
+
+If you wish to bond channels together for a network sniffing
+application --- you wish to run tcpdump, or ethereal, or an IDS like
+snort, with its input aggregated from multiple interfaces using the
+bonding driver --- then you need to handle the Promiscuous interface
+setting by hand. Specifically, when you "ifconfing bond0 up" you
+must add the promisc flag there; it will be propagated down to the
+slave interfaces at ifenslave time; a full example might look like:
+
+   grep bond0 /etc/modules.conf || echo alias bond0 bonding >/etc/modules.conf
+   ifconfig bond0 promisc up
+   for if in eth1 eth2 ...;do
+       ifconfig $if up
+       ifenslave bond0 $if
+   done
+   snort ... -i bond0 ...
+
+Ifenslave also wants to propagate addresses from interface to
+interface, appropriately for its design functions in HA and channel
+capacity aggregating; but it works fine for unnumbered interfaces;
+just ignore all the warnings it emits.
+
+
+Limitations
+===========
 The main limitations are :
   - only the link status is monitored. If the switch on the other side is
     partially down (e.g. doesn't forward anymore, but the link is OK), the link
@@ -500,7 +738,13 @@
     Use the arp_interval/arp_ip_target parameters to count incoming/outgoing
     frames.  
 
-Resources and links
+  - A Transmit Load Balancing policy is not currently available. This mode 
+    allows every slave in the bond to transmit while only one receives. If 
+    the "receiving" slave fails, another slave takes over the MAC address of 
+    the failed receiving slave.
+
+
+Resources and Links
 ===================
 
 Current development on this driver is posted to:
diff -Nru a/Documentation/networking/ifenslave.c b/Documentation/networking/ifenslave.c
--- a/Documentation/networking/ifenslave.c	Mon Dec 23 21:21:51 2002
+++ b/Documentation/networking/ifenslave.c	Mon Dec 23 21:21:51 2002
@@ -41,6 +41,16 @@
  *    - 2002/02/18 Erik Habbinga <erik_habbinga @ hp dot com> :
  *       - ifr2.ifr_flags was not initialized in the hwaddr_notset case,
  *         SIOCGIFFLAGS now called before hwaddr_notset test
+ *
+ *    - 2002/10/31 Tony Cureington <tony.cureington * hp_com> :
+ *       - If the master does not have a hardware address when the first slave
+ *         is enslaved, the master is assigned the hardware address of that 
+ *         slave - there is a comment in bonding.c stating "ifenslave takes 
+ *         care of this now." This corrects the problem of slaves having 
+ *         different hardware addresses in active-backup mode when 
+ *         multiple interfaces are specified on a single ifenslave command
+ *         (ifenslave bond0 eth0 eth1).
+ *
  */
 
 static char *version =
@@ -131,6 +141,7 @@
 	sa_family_t master_family;
 	char **spp, *master_ifname, *slave_ifname;
 	int hwaddr_notset;
+	int master_up;
 
 	while ((c = getopt_long(argc, argv, "acdfrvV?h", longopts, 0)) != EOF)
 		switch (c) {
@@ -300,10 +311,86 @@
 				return 1;
 			}
 
-			if (hwaddr_notset) { /* we do nothing */
+			if (hwaddr_notset) {
+				/* assign the slave hw address to the 
+				 * master since it currently does not 
+				 * have one; otherwise, slaves may
+				 * have different hw addresses in 
+				 * active-backup mode as seen when enslaving 
+				 * using "ifenslave bond0 eth0 eth1" because
+				 * hwaddr_notset is set outside this loop.
+				 * TODO: put this and the "else" portion in
+				 *       a function.
+				 */
+				goterr = 0;
+				master_up = 0;
+				if (if_flags.ifr_flags & IFF_UP) {
+					if_flags.ifr_flags &= ~IFF_UP;
+					if (ioctl(skfd, SIOCSIFFLAGS, 
+							&if_flags) < 0) {
+						goterr = 1;
+						fprintf(stderr, 
+							"Shutting down "
+							"interface %s failed: "
+							"%s\n",
+							master_ifname, 
+							strerror(errno));
+					} else {
+						/* we took the master down, 
+						 * so we must bring it up 
+						 */
+						master_up = 1; 
+					}
+				}
 
-			}
-			else {  /* we'll assign master's hwaddr to this slave */
+				if (!goterr) {
+					/* get the slaves MAC address */
+					strncpy(if_hwaddr.ifr_name, 
+							slave_ifname, IFNAMSIZ);
+					if (ioctl(skfd, SIOCGIFHWADDR, 
+							&if_hwaddr) < 0) {
+						fprintf(stderr, 
+							"Could not get MAC "
+							"address of %s: %s\n",
+							slave_ifname, 
+							strerror(errno));
+						strncpy(if_hwaddr.ifr_name, 
+							master_ifname, 
+							IFNAMSIZ);
+						goterr=1;
+					}
+				}
+
+				if (!goterr) {
+					strncpy(if_hwaddr.ifr_name, 
+						master_ifname, IFNAMSIZ);
+					if (ioctl(skfd, SIOCSIFHWADDR, 
+							&if_hwaddr) < 0) {
+						fprintf(stderr, 
+							"Could not set MAC "
+							"address of %s: %s\n",
+							master_ifname, 
+							strerror(errno));
+						goterr=1;
+					} else {
+						hwaddr_notset = 0;
+					}
+				}
+
+				if (master_up) {
+					if_flags.ifr_flags |= IFF_UP;
+					if (ioctl(skfd, SIOCSIFFLAGS, 
+							&if_flags) < 0) {
+						fprintf(stderr, 
+							"Bringing up interface "
+							"%s failed: %s\n",
+							master_ifname, 
+							strerror(errno));
+					}
+				}
+
+			} else {  
+				/* we'll assign master's hwaddr to this slave */
 				if (ifr2.ifr_flags & IFF_UP) {
 					ifr2.ifr_flags &= ~IFF_UP;
 					if (ioctl(skfd, SIOCSIFFLAGS, &ifr2) < 0) {
diff -Nru a/Documentation/scsi/aic79xx.txt b/Documentation/scsi/aic79xx.txt
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/Documentation/scsi/aic79xx.txt	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,323 @@
+====================================================================
+=             Adaptec Ultra320 Family Manager Set v1.1.1           =
+=                                                                  =
+=                            README for                            =
+=                    The Linux Operating System                    =
+====================================================================
+
+The following information is available in this file:
+
+  1. Supported Hardware
+  2. Version History
+  3. Command Line Options
+  4. Additional Notes
+  5. Contacting Adaptec
+
+
+1. Supported Hardware
+
+   The following Adaptec SCSI Host Adapters are supported by this 
+   driver set. 
+
+   Ultra320 Adapters         Description
+   ----------------------------------------------------------------
+   Adaptec SCSI Card 39320   Dual Channel 64-bit PCI-X 133MHz to
+                             Ultra320 SCSI Card (one external 
+                             68-pin, two internal 68-pin)
+   Adaptec SCSI Card 39320D  Dual Channel 64-bit PCI-X 133MHz to
+                             Ultra320 SCSI Card (two external VHDC
+                             and one internal 68-pin)
+   Adaptec SCSI Card 29320   Single Channel 64-bit PCI-X 133MHz to
+                             Ultra320 SCSI Card (one external 
+                             68-pin, two internal 68-pin, one
+                             internal 50-pin)
+   Adaptec SCSI Card 29320LP Single Channel 64-bit Low Profile
+                             PCI-X 133MHz to Ultra320 SCSI Card
+                             (One external VHDC, one internal
+                             68-pin)
+   AIC-7901A                 Single Channel 64-bit PCI-X 133MHz to 
+                             Ultra320 SCSI ASIC
+   AIC-7902A4                Dual Channel 64-bit PCI-X 133MHz to 
+                             Ultra320 SCSI ASIC
+
+
+2. Version History
+
+   (V1.1.1, September 2002) Added support for the Linux 2.5.X kernel series
+
+   (V1.1, August 2002) Added support for four additional SCSI
+   products: ASC-39320, ASC-29320, ASC-29320LP, AIC-7901.
+
+   (V1.0, May 2002) This is the initial release of the 
+   Ultra320 FMS.  The following is a list of supported features:
+
+   2.1. Software/Hardware Features
+        - Support for the SPI-4 "Ultra320" standard:
+          - 320MB/s transfer rates
+          - Packetized SCSI Protocol at 160MB/s and 320MB/s
+          - Quick Arbitration Selection (QAS)
+          - Initiator Mode (target mode not currently 
+            supported)
+          - Support for the PCI-x standard up to 133MHz
+          - Support for the PCI v2.2 standard
+
+   2.2. Operating System Support:
+        - Redhat Linux 7.2, 7.3, Advanced Server 2.1
+	- SuSE Linux 7.3, 8.0, Enterprise Server 7
+        - only Intel and AMD x86 supported at this time
+	- >4GB memory configurations supported.
+
+     Refer to the User's Guide for more details on this.
+
+
+3. Command Line Options
+
+        WARNING: ALTERING OR ADDING THESE DRIVER PARAMETERS
+                 INCORRECTLY CAN RENDER YOUR SYSTEM INOPERABLE.
+                 USE THEM WITH CAUTION. 
+
+   Edit the file "modules.conf" in the directory /etc and add/edit a
+   line containing 'options aic79xx=[command[,command...]]' where
+   'command' is one or more of the following:
+   -----------------------------------------------------------------
+              Option: verbose
+          Definition: enable additional informative messages during
+                      driver operation.
+     Possible Values: This option is a flag
+       Default Value: disabled
+   -----------------------------------------------------------------
+              Option: debug:[value]
+          Definition: Enables various levels of debugging information
+     Possible Values: 0x0000 = no debugging, 0xffff = full debugging
+       Default Value: 0x0000
+   -----------------------------------------------------------------
+              Option: no_reset
+          Definition: Do not reset the bus during the initial probe
+                      phase
+     Possible Values: This option is a flag
+       Default Value: disabled
+   -----------------------------------------------------------------
+              Option: extended
+          Definition: Force extended translation on the controller
+     Possible Values: This option is a flag
+       Default Value: disabled
+   -----------------------------------------------------------------
+              Option: periodic_otag
+          Definition: Send an ordered tag periodically to prevent
+                      tag starvation.  Needed for some older devices
+     Possible Values: This option is a flag
+       Default Value: disabled
+   -----------------------------------------------------------------
+              Option: reverse_scan
+          Definition: Probe the scsi bus in reverse order, starting
+                      with target 15
+     Possible Values: This option is a flag
+       Default Value: disabled
+   -----------------------------------------------------------------
+	      Option: global_tag_depth
+          Definition: Global tag depth for all targets on all busses.
+		      This option sets the default tag depth which
+		      may be selectively overridden vi the tag_info
+		      option.
+     Possible Values: 1 - 253
+       Default Value: 32
+   -----------------------------------------------------------------
+              Option: tag_info:{{value[,value...]}[,{value[,value...]}...]}
+          Definition: Set the per-target tagged queue depth on a
+		      per controller basis.  Both controllers and targets
+		      may be ommitted indicating that they should retain
+		      the default tag depth.
+            Examples: tag_info:{{16,32,32,64,8,8,,32,32,32,32,32,32,32,32,32}
+			On Controller 0
+			  specifies a tag depth of 16 for target 0
+			  specifies a tag depth of 64 for target 3
+			  specifies a tag depth of 8 for targets 4 and 5
+			  leaves target 6 at the default
+		          specifies a tag depth of 32 for targets 1,2,7-15
+			All other targets retain the default depth.
+
+		      tag_info:{{},{32,,32}}
+			On Controller 1
+			  specifies a tag depth of 32 for targets 0 and 2
+			All other targets retain the default depth.
+			
+     Possible Values: 1 - 253
+       Default Value: 32
+   -----------------------------------------------------------------
+              Option: rd_strm: {rd_strm_bitmask[,rd_strm_bitmask...]}
+          Definition: Enable read streaming on a per target basis.
+                      The rd_strm_bitmask is a 16 bit hex value in which
+		      each bit represents a target.  Setting the target's
+                      bit to '1' enables read streaming for that
+                      target.  Controllers may be ommitted indicating that
+		      they should retain the default read streaming setting.
+	     Example: rd_strm:{0x0041}
+			On Controller 0
+			  enables read streaming for targets 0 and 6.
+			  disables read streaming for targets 1-5,7-15.
+			All other targets retain the default read
+			streaming setting.
+	     Example: rd_strm:{0x0023,,0xFFFF}
+			On Controller 0
+			  enables read streaming for targets 1,2, and 5.
+			  disables read streaming for targets 3,4,6-15.
+			On Controller 2
+			  enables read streaming for all targets.
+			All other targets retain the default read
+			streaming setting.
+		      
+     Possible Values: 0x0000 - 0xffff
+       Default Value: 0x0000
+   -----------------------------------------------------------------
+              Option: precomp: {value[,value...]}
+          Definition: Set IO Cell precompensation value on a per-controller
+		      basis.
+                      Controllers may be ommitted indicating that
+		      they should retain the default precompensation setting.
+	     Example: precomp:{0x1}
+			On Controller 0 set precompensation to 1.
+	     Example: precomp:{1,,7}
+			On Controller 0 set precompensation to 1.
+			On Controller 2 set precompensation to 8.
+		      
+     Possible Values: 0 - 7
+       Default Value: Varies based on chip revision
+   -----------------------------------------------------------------
+              Option: slewrate: {value[,value...]}
+          Definition: Set IO Cell slew rate on a per-controller basis.
+                      Controllers may be ommitted indicating that
+		      they should retain the default slew rate setting.
+	     Example: slewrate:{0x1}
+			On Controller 0 set slew rate to 1.
+	     Example: slewrate :{1,,8}
+			On Controller 0 set slew rate to 1.
+			On Controller 2 set slew rate to 8.
+		      
+     Possible Values: 0 - 15
+       Default Value: Varies based on chip revision
+   -----------------------------------------------------------------
+              Option: amplitude: {value[,value...]}
+          Definition: Set IO Cell signal amplitude on a per-controller basis.
+                      Controllers may be ommitted indicating that
+		      they should retain the default read streaming setting.
+	     Example: amplitude:{0x1}
+			On Controller 0 set amplitude to 1.
+	     Example: amplitude :{1,,7}
+			On Controller 0 set amplitude to 1.
+			On Controller 2 set amplitude to 7.
+		      
+     Possible Values: 1 - 7
+       Default Value: Varies based on chip revision
+   -----------------------------------------------------------------
+              Option: seltime:[value]
+          Definition: Specifies the selection timeout value
+     Possible Values: 0 = 256ms, 1 = 128ms, 2 = 64ms, 3 = 32ms
+       Default Value: 0
+   -----------------------------------------------------------------
+
+   Example: 'options aic79xx=verbose,rd_strm:{{0x0041}}'
+	enables verbose output in the driver and turns read streaming on
+	for targets 0 and 6 of Controller 0.
+
+4. Additional Notes
+
+   4.1. Known/Unresolved or FYI Issues
+
+	* Domain Validation is not implemented.
+	* Under SuSE Linux Enterprise 7, the driver may fail to operate
+	  correctly due to a problem with PCI interrupt routing in the
+	  Linux kernel.  Please contact SuSE for an updated Linux
+	  kernel.
+
+   4.2. Third-Party Compatibility Issues
+
+        * Adaptec only supports Ultra320 hard drives running
+          the latest firmware available. Please check with
+          your hard drive manufacturer to ensure you have the
+          latest version.
+
+   4.3. Operating System or Technology Limitations
+        
+        * PCI Hot Plug is untested and may cause the operating system 
+          to stop responding.
+
+
+5. Contacting Adaptec
+
+   A Technical Support Identification (TSID) Number is required for 
+   Adaptec technical support.
+    - The 12-digit TSID can be found on the white barcode-type label
+      included inside the box with your product. The TSID helps us 
+      provide more efficient service by accurately identifying your 
+      product and support status.
+   Support Options
+    - Search the Adaptec Support Knowledgebase (ASK) at
+      http://ask.adaptec.com for articles, troubleshooting tips, and
+      frequently asked questions for your product.
+    - For support via Email, submit your question to Adaptec's 
+      Technical Support Specialists at http://ask.adaptec.com.
+     
+   North America
+    - Visit our Web site at http://www.adaptec.com.
+    - To speak with a Fibre Channel/RAID/External Storage Technical
+      Support Specialist, call 1-321-207-2000,
+      Hours: Monday-Friday, 3:00 A.M. to 5:00 P.M., PST.
+      (Not open on holidays)
+    - For Technical Support in all other technologies including 
+      SCSI, call 1-408-934-7274,
+      Hours: Monday-Friday, 6:00 A.M. to 5:00 P.M., PST.
+      (Not open on holidays)
+    - For after hours support, call 1-800-416-8066 ($99/call, 
+      $149/call on holidays)
+    - To order Adaptec products including software and cables, call
+      1-800-442-7274 or 1-408-957-7274. You can also visit our 
+      online store at http://www.adaptecstore.com
+
+   Europe
+    - Visit our Web site at http://www.adaptec-europe.com.
+    - English and French: To speak with a Technical Support 
+      Specialist, call one of the following numbers:
+        - English: +32-2-352-3470
+        - French:  +32-2-352-3460
+      Hours: Monday-Thursday, 10:00 to 12:30, 13:30 to 17:30 CET 
+             Friday, 10:00 to 12:30, 13:30 to 16:30 CET
+    - German: To speak with a Technical Support Specialist,
+      call +49-89-456-40660
+      Hours: Monday-Thursday, 09:30 to 12:30, 13:30 to 16:30 CET
+             Friday, 09:30 to 12:30, 13:30 to 15:00 CET
+    - To order Adaptec products, including accessories and cables:
+        - UK: +0800-96-65-26 or fax +0800-731-02-95
+        - Other European countries: +32-11-300-379
+
+   Australia and New Zealand
+    - Visit our Web site at http://www.adaptec.com.au.
+    - To speak with a Technical Support Specialist, call 
+      +612-9416-0698
+      Hours: Monday-Friday, 10:00 A.M. to 4:30 P.M., EAT
+      (Not open on holidays)
+
+   Japan
+    - To speak with a Technical Support Specialist, call 
+      +81-3-5308-6120 
+      Hours: Monday-Friday, 9:00 a.m. to 12:00 p.m., 1:00 p.m. to
+      6:00 p.m. TSC
+
+   Hong Kong and China
+    - To speak with a Technical Support Specialist, call 
+      +852-2869-7200
+      Hours: Monday-Friday, 10:00 to 17:00.
+    - Fax Technical Support at +852-2869-7100.
+
+   Singapore
+    - To speak with a Technical Support Specialist, call 
+      +65-245-7470
+      Hours: Monday-Friday, 10:00 to 17:00.
+    - Fax Technical Support at +852-2869-7100
+
+-------------------------------------------------------------------
+
+(c) 2002 Adaptec, Inc. All Rights Reserved. No part of this 
+publication may be reproduced, stored in a retrieval system, or 
+transmitted in any form or by any means, electronic, mechanical, 
+photocopying, recording or otherwise, without prior written consent 
+of Adaptec, Inc., 691 South Milpitas Blvd., Milpitas, CA 95035.
diff -Nru a/Documentation/scsi/aic7xxx.txt b/Documentation/scsi/aic7xxx.txt
--- a/Documentation/scsi/aic7xxx.txt	Mon Dec 23 21:21:54 2002
+++ b/Documentation/scsi/aic7xxx.txt	Mon Dec 23 21:22:04 2002
@@ -1,477 +1,294 @@
-			    AIC7xxx Driver for Linux
-
-Introduction
-----------------------------
-The AIC7xxx SCSI driver adds support for Adaptec (http://www.adaptec.com)
-SCSI controllers and chipsets. Major portions of the driver and driver
-development are shared between both Linux and FreeBSD. Support for the
-AIC-7xxx chipsets have been in the default Linux kernel since approximately
-linux-1.1.x and fairly stable since linux-1.2.x, and are also in FreeBSD
-2.1.0 or later.
-
-  Supported cards/chipsets
-  ----------------------------
-    Adaptec Cards
-    ----------------------------
-    AHA-274x
-    AHA-274xT
-    AHA-274xW
-    AHA-284x
-    AHA-284xW
-    All PCI based cards using any of the chipsets listed under motherboard
-    chipsets.  In general, this means *all* of the Adaptec SCSI controllers
-    except the ones specifically excluded later on in this document.
-
-    Motherboard Chipsets
-    ----------------------------
-    AIC-777x
-    AIC-785x
-    AIC-786x
-    AIC-787x
-    AIC-788x
-    AIC-789x
-    AIC-3860
-
-    Bus Types
-    ----------------------------
-    W - Wide SCSI, SCSI-3, 16bit bus, 68pin connector, will also support
-        SCSI-1/SCSI-2 50pin devices, transfer rates up to 20MB/s.
-    U - Ultra SCSI, transfer rates up to 40MB/s.
-    U2- Ultra 2 SCSI, transfer rates up to 80MB/s.
-    U3- Ultra 3 SCSI, transfer rates up to 160MB/s.
-    D - Differential SCSI.
-    T - Twin Channel SCSI. Up to 14 SCSI devices.
-
-    AHA-274x - EISA SCSI controller
-    AHA-284x - VLB SCSI controller
-    AHA-29xx - PCI SCSI controller
-    AHA-39xx - PCI controllers with multiple separate SCSI channels on-board.
-
-  Not Supported Devices
-  ------------------------------
-    Adaptec Cards
-    ----------------------------
-    AHA-2920 (Only the cards that use the Future Domain chipset are not
-              supported, any 2920 cards based on Adaptec AIC chipsets,
-	      such as the 2920C, are supported)
-    AAA-13x Raid Adapters
-    AAA-113x Raid Port Card
-
-    Motherboard Chipsets
-    ----------------------------
-    AIC-781x
-
-    Bus Types
-    ----------------------------
-    R - Raid Port busses are not supported.
-
-    The hardware RAID devices sold by Adaptec are *NOT* supported by this
-    driver (and will people please stop emailing me about them, they are
-    a totally separate beast from the bare SCSI controllers and this driver
-    can not be retrofitted in any sane manner to support the hardware RAID
-    features on those cards - Doug Ledford).
-    
-
-  People
-  ------------------------------
-    Justin T Gibbs  gibbs@plutotech.com
-      (BSD Driver Author)
-    Dan Eischen     deischen@iworks.InterWorks.org
-      (Original Linux Driver Co-maintainer)
-    Dean Gehnert    deang@teleport.com
-      (Original Linux FTP/patch maintainer)
-    Jess Johnson    jester@frenzy.com
-      (AIC7xxx FAQ author)
-    Doug Ledford    dledford@redhat.com
-      (Current Linux aic7xxx-5.x.x Driver/Patch/FTP maintainer)
-    
-    Special thanks go to John Aycock (aycock@cpsc.ucalgary.ca), the original
-    author of the driver. John has since retired from the project. Thanks
-    again for all his work!
-    
-  Mailing list
-  ------------------------------
-    There is a mailing list available for users who want to track development
-    and converse with other users and developers. This list is for both
-    FreeBSD and Linux support of the AIC7xxx chipsets.
-
-    To subscribe to the AIC7xxx mailing list send mail to the list server,
-    with "subscribe AIC7xxx" in the body (no Subject: required):
-        To: majordomo@FreeBSD.ORG
-        ---
-        subscribe AIC7xxx
-
-    To unsubscribe from the list, send mail to the list server with:
-        To: majordomo@FreeBSD.ORG
-        ---
-        unsubscribe AIC7xxx
-
-    Send regular messages and replies to: AIC7xxx@FreeBSD.ORG
-    
-  Boot Command line options
-  ------------------------------
-    "aic7xxx=no_reset" -  Eliminate the SCSI bus reset during startup.
-        Some SCSI devices need the initial reset that this option disables
-	in order to work.  If you have problems at bootup, please make sure
-	you aren't using this option.
-	
-    "aic7xxx=reverse_scan" - Certain PCI motherboards scan for devices at
-        bootup by scanning from the highest numbered PCI device to the
-	lowest numbered PCI device, others do just the opposite and scan
-	from lowest to highest numbered PCI device.  There is no reliable
-	way to autodetect this ordering.  So, we default to the most common
-	order, which is lowest to highest.  Then, in case your motherboard
-	scans from highest to lowest, we have this option.  If your BIOS
-	finds the drives on controller A before controller B but the linux
-	kernel finds your drives on controller B before A, then you should
-	use this option.
-	
-    "aic7xxx=extended" - Force the driver to detect extended drive translation
-        on your controller.  This helps those people who have cards without
-        a SEEPROM make sure that linux and all other operating systems think
-        the same way about your hard drives.
-
-    "aic7xxx=scbram" - Some cards have external SCB RAM that can be used to
-        give the card more hardware SCB slots.  This allows the driver to use
-	that SCB RAM.  Without this option, the driver won't touch the SCB
-	RAM because it is known to cause problems on a few cards out there
-	(such as 3985 class cards).
-	
-    "aic7xxx=irq_trigger:x" - Replace x with either 0 or 1 to force the kernel
-        to use the correct IRQ type for your card.  This only applies to EISA
-        based controllers.  On these controllers, 0 is for Edge triggered
-        interrupts, and 1 is for Level triggered interrupts.  If you aren't
-        sure or don't know which IRQ trigger type your EISA card uses, then
-        let the kernel autodetect the trigger type.
-	
-    "aic7xxx=verbose" - This option can be used in one of two ways.  If you
-        simply specify aic7xxx=verbose, then the kernel will automatically
-	pick the default set of verbose messages for you to see.
-	Alternatively, you can specify the command as 
-	"aic7xxx=verbose:0xXXXX" where the X entries are replaced with
-	hexadecimal digits.  This option is a bit field type option.  For
-	a full listing of the available options, search for the 
-	#define VERBOSE_xxxxxx lines in the aic7xxx.c file.  If you want
-	verbose messages, then it is recommended that you simply use the
-	aic7xxx=verbose variant of this command.
-	
-    "aic7xxx=pci_parity:x" - This option controls whether or not the driver
-        enables PCI parity error checking on the PCI bus.  By default, this
-        checking is disabled.  To enable the checks, simply specify pci_parity
-        with no value afterwords.  To reverse the parity from even to odd,
-        supply any number other than 0 or 255.  In short:
-          pci_parity     - Even parity checking (even is the normal PCI parity)
-          pci_parity:x   - Where x > 0, Odd parity checking
-          pci_parity:0   - No check (default)
-        NOTE: In order to get Even PCI parity checking, you must use the
-        version of the option that does not include the : and a number at
-        the end (unless you want to enter exactly 2^32 - 1 as the number).
-	
-    "aic7xxx=no_probe" - This option will disable the probing for any VLB
-        based 2842 controllers and any EISA based controllers.  This is
-	needed on certain newer motherboards where the normal EISA I/O ranges
-	have been claimed by other PCI devices.  Probing on those machines
-	will often result in the machine crashing or spontaneously rebooting
-	during startup.  Examples of machines that need this are the
-	Dell PowerEdge 6300 machines.
-
-    "aic7xxx=seltime:2" - This option controls how long the card waits
-        during a device selection sequence for the device to respond.
-	The original SCSI spec says that this "should be" 256ms.  This
-	is generally not required with modern devices.  However, some
-	very old SCSI I devices need the full 256ms.  Most modern devices
-	can run fine with only 64ms.  The default for this option is
-	64ms.  If you need to change this option, then use the following
-	table to set the proper value in the example above:
-	  0  -  256ms
-	  1  -  128ms
-	  2  -   64ms
-	  3  -   32ms
-	
-    "aic7xxx=panic_on_abort" - This option is for debugging and will cause
-        the driver to panic the linux kernel and freeze the system the first
-	time the drivers abort or reset routines are called.  This is most
-	helpful when some problem causes infinite reset loops that scroll too
-	fast to see.  By using this option, you can write down what the errors
-	actually are and send that information to me so it can be fixed.
-	
-    "aic7xxx=dump_card" - This option will print out the *entire* set of
-        configuration registers on the card during the init sequence.  This
-	is a debugging aid used to see exactly what state the card is in
-	when we finally finish our initialization routines.  If you don't
-	have documentation on the chipsets, this will do you absolutely
-	no good unless you are simply trying to write all the information
-	down in order to send it to me.
-	
-    "aic7xxx=dump_sequencer" - This is the same as the above options except
-        that instead of dumping the register contents on the card, this
-	option dumps the contents of the sequencer program RAM.  This gives
-	the ability to verify that the instructions downloaded to the
-	card's sequencer are indeed what they are suppossed to be.  Again,
-	unless you have documentation to tell you how to interpret these
-	numbers, then it is totally useless.
-	
-    "aic7xxx=override_term:0xffffffff" - This option is used to force the
-    	termination on your SCSI controllers to a particular setting.  This
-	is a bit mask variable that applies for up to 8 aic7xxx SCSI channels.
-	Each channel gets 4 bits, divided as follows:
-	bit   3   2   1   0
-	      |   |   |   Enable/Disable Single Ended Low Byte Termination
-	      |   |   En/Disable Single Ended High Byte Termination
-	      |   En/Disable Low Byte LVD Termination
-	      En/Disable High Byte LVD Termination
-
-	The upper 2 bits that deal with LVD termination only apply to Ultra2
-	controllers.  Futhermore, due to the current Ultra2 controller
-	designs, these bits are tied together such that setting either bit
-	enables both low and high byte LVD termination.  It is not possible
-	to only set high or low byte LVD termination in this manner.  This is
-	an artifact of the BIOS definition on Ultra2 controllers.  For other
-	controllers, the only important bits are the two lowest bits.  Setting
-	the higher bits on non-Ultra2 controllers has no effect.  A few
-	examples of how to use this option:
-
-	Enable low and high byte termination on a non-ultra2 controller that
-	is the first aic7xxx controller (the correct bits are 0011), 
-	aic7xxx=override_term:0x3
-
-	Enable all termination on the third aic7xxx controller, high byte
-	termination on the second aic7xxx controller, and low and high byte
-	SE termination on the first aic7xxx controller 
-	(bits are 1111 0010 0011), 
-	aic7xxx=override_term:0xf23
-	
-	No attempt has been made to make this option non-cryptic.  It really
-	shouldn't be used except in dire circumstances, and if that happens,
-	I'm probably going to be telling you what to set this to anyway :)
-
-    "aic7xxx=stpwlev:0xffffffff" - This option is used to control the STPWLEV
-        bit in the DEVCONFIG PCI register.  Currently, this is one of the
-	very few registers that we have absolutely *no* way of detecting
-	what the variable should be.  It depends entirely on how the chipset
-	and external terminators were coupled by the card/motherboard maker.
-	Further, a chip reset (at power up) always sets this bit to 0.  If
-	there is no BIOS to run on the chipset/card (such as with a 2910C
-	or a motherboard controller with the BIOS totally disabled) then
-	the variable may not get set properly.  Of course, if the proper
-	setting was 0, then that's what it would be after the reset, but if
-	the proper setting is actually 1.....you get the picture.  Now, since
-	we can't detect this at all, I've added this option to force the
-	setting.  If you have a BIOS on your controller then you should never
-	need to use this option.  However, if you are having lots of SCSI
-	reset problems and can't seem to get them knocked out, this may help.
-
-	Here's a test to know for certain if you need this option.  Make
-	a boot floppy that you can use to boot your computer up and that
-	will detect the aic7xxx controller.  Next, power down your computer.
-	While it's down, unplug all SCSI cables from your Adaptec SCSI
-	controller.  Boot the system back up to the Adaptec EZ-SCSI BIOS
-	and then make sure that termination is enabled on your adapter (if
-	you have an Adaptec BIOS of course).  Next, boot up the floppy you
-	made and wait for it to detect the aic7xxx controller.  If the kernel
-	finds the controller fine, says scsi : x hosts and then tries to
-	detect your devices like normal, up to the point where it fails to
-	mount your root file system and panics, then you're fine.  If, on
-	the other hand, the system goes into an infinite reset loop, then
-	you need to use this option and/or the previous option to force the
-	proper termination settings on your controller.   If this happens,
-	then you next need to figure out what your settings should be.
-
-	To find the correct settings, power your machine back down, connect
-	back up the SCSI cables, and boot back into your machine like normal.
-	However, boot with the aic7xxx=verbose:0x39 option.  Record the
-	initial DEVCONFIG values for each of your aic7xxx controllers as
-	they are listed, and also record what the machine is detecting as
-	the proper termination on your controllers.  NOTE: the order in
-	which the initial DEVCONFIG values are printed out is not gauranteed
-	to be the same order as the SCSI controllers are registered.  The
-	above option and this option both work on the order of the SCSI
-	controllers as they are registered, so make sure you match the right
-	DEVCONFIG values with the right controllers if you have more than
-	one aic7xxx controller.
-
-	Once you have the detected termination settings and the initial
-	DEVCONFIG values for each controller, then figure out what the
-	termination on each of the controllers *should* be.  Hopefully, that
-	part is correct, but it could possibly be wrong if there is
-	bogus cable detection logic on your controller or something similar.
-	If all the controllers have the correct termination settings, then
-	don't set the aic7xxx=override_term variable at all, leave it alone.
-	Next, on any controllers that go into an infinite reset loop when
-	you unplug all the SCSI cables, get the starting DEVCONFIG value.
-	If the initial DEVCONFIG value is divisible by 2, then the correct
-	setting for that controller is 0.  If it's an odd number, then
-	the correct setting for that controller is 1.  For any other
-	controllers that didn't have an infinite reset problem, then reverse
-	the above options.  If DEVCONFIG was even, then the correct setting
-	is 1, if not then the correct setting is 0.
-
-	Now that you know what the correct setting was for each controller,
-	we need to encode that into the aic7xxx=stpwlev:0x... variable.
-	This variable is a bit field encoded variable.  Bit 0 is for the first
-	aic7xxx controller, bit 1 for the next, etc.  Put all these bits
-	together and you get a number.  For example, if the third aic7xxx
-	needed a 1, but the second and first both needed a 0, then the bits
-	would be 100 in binary.  This then translates to 0x04.  You would
-	therefore set aic7xxx=stpwlev:0x04.  This is fairly standard binary
-	to hexadecimal conversions here.  If you aren't up to speed on the
-	binary->hex conversion then send an email to the aic7xxx mailing
-	list and someone can help you out.
-
-    "aic7xxx=tag_info:{{8,8..},{8,8..},..}" - This option is used to disable
-        or enable Tagged Command Queueing (TCQ) on specific devices.  As of
-	driver version 5.1.11, TCQ is now either on or off by default
-	according to the setting you choose during the make config process.
-	In order to en/disable TCQ for certian devices at boot time, a user
-	may use this boot param.  The driver will then parse this message out
-        and en/disable the specific device entries that are present based upon
-        the value given.  The param line is parsed in the following manner:
-
-          { - first instance indicates the start of this parameter values
-              second instance is the start of entries for a particular
-              device entry
-          } - end the entries for a particular host adapter, or end the entire
-              set of parameter entries
-          , - move to next entry.  Inside of a set of device entries, this
-              moves us to the next device on the list.  Outside of device
-              entries, this moves us to the next host adapter
-          . - Same effect as , but is safe to use with insmod.
-          x - the number to enter into the array at this position.  
-              0 = Enable tagged queueing on this device and use the default
-                  queue depth
-              1-254 = Enable tagged queueing on this device and use this
-                      number as the queue depth
-              255 = Disable tagged queueing on this device.
-              Note: anything above 32 for an actual queue depth is wasteful
-                    and not recommended.
-
-        A few examples of how this can be used:
-
-        tag_info:{{8,12,,0,,255,4}}
-          This line will only effect the first aic7xxx card registered.  It
-          will set scsi id 0 to a queue depth of 8, id 1 to 12, leave id 2
-          at the default, set id 3 to tagged queueing enabled and use the
-          default queue depth, id 4 default, id 5 disabled, and id 6 to 4.
-          Any not specified entries stay at the default value, repeated
-          commas with no value specified will simply increment to the next id
-          without changing anything for the missing values.
-
-        tag_info:{,,,{,,,255}}
-          First, second, and third adapters at default values.  Fourth
-          adapter, id 3 is disabled.  Notice that leading commas simply
-	  increment what the first number effects, and there are no need
-	  for trailing commas.  When you close out an adapter, or the
-	  entire entry, anything not explicitly set stays at the default
-	  value.
-
-        A final note on this option.  The scanner I used for this isn't
-        perfect or highly robust.  If you mess the line up, the worst that
-        should happen is that the line will get ignored.  If you don't
-        close out the entire entry with the final bracket, then any other
-        aic7xxx options after this will get ignored.  So, in general, be
-        sure of what you are entering, and after you have it right, just
-        add it to the lilo.conf file so there won't be any mistakes.  As
-        a means of checking this parser, the entire tag_info array for
-        each card is now printed out in the /proc/scsi/aic7xxx/x file.  You
-        can use that to verify that your options were parsed correctly. 
-        
-    Boot command line options may be combined to form the proper set of options
-    a user might need.  For example, the following is valid:
-    
-    aic7xxx=verbose,extended,irq_trigger:1
-    
-    The only requirement is that individual options be separated by a comma or
-    a period on the command line.
-        
-  Module Loading command options
-  ------------------------------
-    When loading the aic7xxx driver as a module, the exact same options are
-    available to the user.  However, the syntax to specify the options changes
-    slightly.  For insmod, you need to wrap the aic7xxx= argument in quotes
-    and replace all ',' with '.'.  So, for example, a valid insmod line
-    would be:
-
-    insmod aic7xxx aic7xxx='verbose.irq_trigger:1.extended'
-
-    This line should result in the *exact* same behaviour as if you typed
-    it in at the lilo prompt and the driver was compiled into the kernel
-    instead of being a module.  The reason for the single quote is so that
-    the shell won't try to interpret anything in the line, such as {. 
-    Insmod assumes any options starting with a letter instead of a number
-    is a character string (which is what we want) and by switching all of
-    the commas to periods, insmod won't interpret this as more than one
-    string and write junk into our binary image.  I consider it a bug in
-    the insmod program that even if you wrap your string in quotes (quotes
-    that pass the shell mind you and that insmod sees) it still treates
-    a comma inside of those quotes as starting a new variable, resulting
-    in memory scribbles if you don't switch the commas to periods.
-
-
-  Kernel Compile options
-  ------------------------------
-    The various kernel compile time options for this driver are now fairly
-    well documented in the file Documentation/Configure.help.  In order to
-    see this documentation, you need to use one of the advanced configuration
-    programs (menuconfig and xconfig).  If you are using the "make menuconfig"
-    method of configuring your kernel, then you would simply highlight the
-    option in question and hit the ? key.  If you are using the "make xconfig"
-    method of configuring your kernel, then simply click on the help button
-    next to the option you have questions about.  The help information from
-    the Configure.help file will then get automatically displayed.
-
-  /proc support
-  ------------------------------
-    The /proc support for the AIC7xxx can be found in the /proc/scsi/aic7xxx/
-    directory. That directory contains a file for each SCSI controller in
-    the system. Each file presents the current configuration and transfer
-    statistics (enabled with #define in aic7xxx.c) for each controller.
-
-    Thanks to Michael Neuffer for his upper-level SCSI help, and
-    Matthew Jacob for statistics support.
-
-  Debugging the driver
-  ------------------------------
-    Should you have problems with this driver, and would like some help in
-    getting them solved, there are a couple debugging items built into
-    the driver to facilitate getting the needed information from the system.
-    In general, I need a complete description of the problem, with as many
-    logs as possible concerning what happens.  To help with this, there is
-    a command option aic7xxx=panic_on_abort.  This option, when set, forces
-    the driver to panic the kernel on the first SCSI abort issued by the
-    mid level SCSI code.  If your system is going to reset loops and you
-    can't read the screen, then this is what you need.  Not only will it
-    stop the system, but it also prints out a large amount of state
-    information in the process.  Second, if you specify the option
-    "aic7xxx=verbose:0x1ffff", the system will print out *SOOOO* much
-    information as it runs that you won't be able to see anything.
-    However, this can actually be very useful if your machine simply
-    locks up when trying to boot, since it will pin-point what was last
-    happening (in regards to the aic7xxx driver) immediately prior to
-    the lockup.  This is really only useful if your machine simply can
-    not boot up successfully.  If you can get your machine to run, then
-    this will produce far too much information.
-
-  FTP sites
-  ------------------------------
-    ftp://ftp.redhat.com/pub/aic/
-      - Out of date.  I used to keep stuff here, but too many people
-        complained about having a hard time getting into Red Hat's ftp
-	server.  So use the web site below instead.
-    ftp://ftp.pcnet.com/users/eischen/Linux/
-      - Dan Eischen's driver distribution area
-    ftp://ekf2.vsb.cz/pub/linux/kernel/aic7xxx/ftp.teleport.com/
-      - European Linux mirror of Teleport site
-
-  Web sites
-  ------------------------------
-    http://people.redhat.com/dledford/
-      - My web site, also the primary aic7xxx site with several related
-        pages.
-
-Dean W. Gehnert
-deang@teleport.com
-
-$Revision: 3.0 $
-
-Modified by Doug Ledford 1998-2000
-
+====================================================================
+=    Adaptec Aic7xxx Fast -> Ultra160 Family Manager Set v6.2.10   =
+=                            README for                            =
+=                     The Linux Operating System                   =
+====================================================================
+
+The following information is available in this file:
+
+  1. Supported Hardware
+  2. Command Line Options
+  3. Contacting Adaptec
+
+1. Supported Hardware
+
+   The following Adaptec SCSI Chips and Host Adapters are supported by
+   the aic7xxx driver. 
+
+   Chip    MIPS  Host Bus  MaxSync  MaxWidth  SCBs  Notes
+   ---------------------------------------------------------------
+   aic7770  10    EISA/VL   10MHz    16Bit      4   1
+   aic7850  10    PCI/32    10MHz    8Bit       3
+   aic7855  10    PCI/32    10MHz    8Bit       3
+   aic7856  10    PCI/32    10MHz    8Bit       3
+   aic7859  10    PCI/32    20MHz    8Bit       3
+   aic7860  10    PCI/32    20MHz    8Bit       3
+   aic7870  10    PCI/32    10MHz    16Bit      16
+   aic7880  10    PCI/32    20MHz    16Bit      16
+   aic7890  20    PCI/32    40MHz    16Bit      16      3 4 5 6 7 8
+   aic7891  20    PCI/64    40MHz    16Bit      16      3 4 5 6 7 8
+   aic7892  20   PCI/64-66  80MHz    16Bit      16      3 4 5 6 7 8
+   aic7895  15    PCI/32    20MHz    16Bit      16    2 3 4 5
+   aic7895C 15    PCI/32    20MHz    16Bit      16    2 3 4 5     8
+   aic7896  20    PCI/32    40MHz    16Bit      16    2 3 4 5 6 7 8
+   aic7897  20    PCI/64    40MHz    16Bit      16    2 3 4 5 6 7 8
+   aic7899  20   PCI/64-66  80MHz    16Bit      16    2 3 4 5 6 7 8
+
+   1.   Multiplexed Twin Channel Device - One controller servicing two
+        busses.
+   2.   Multi-function Twin Channel Device - Two controllers on one chip.
+   3.   Command Channel Secondary DMA Engine - Allows scatter gather list
+        and SCB prefetch.
+   4.   64 Byte SCB Support - Allows disconnected, unttagged request table
+        for all possible target/lun combinations.
+   5.   Block Move Instruction Support - Doubles the speed of certain
+        sequencer operations.
+   6.   `Bayonet' style Scatter Gather Engine - Improves S/G prefetch
+	performance.
+   7.   Queuing Registers - Allows queuing of new transactions without
+	pausing the sequencer.
+   8.   Multiple Target IDs - Allows the controller to respond to selection
+        as a target on multiple SCSI IDs.
+
+   Controller      Chip   Host-Bus    Int-Connectors  Ext-Connectors  Notes
+   --------------------------------------------------------------------------
+   AHA-274X[A]    aic7770   EISA        SE-50M          SE-HD50F
+   AHA-274X[A]W   aic7770   EISA        SE-HD68F	SE-HD68F
+				 	SE-50M
+   AHA-274X[A]T   aic7770   EISA       2 X SE-50M	SE-HD50F
+   AHA-2842       aic7770    VL          SE-50M		SE-HD50F
+   AHA-2940AU     aic7860   PCI/32       SE-50M		SE-HD50F
+   AVA-2902I      aic7860   PCI/32       SE-50M
+   AVA-2902E      aic7860   PCI/32       SE-50M
+   AVA-2906       aic7856   PCI/32       SE-50M		SE-DB25F
+   APC-7850       aic7850   PCI/32       SE-50M			      1
+   AVA-2940       aic7860   PCI/32       SE-50M
+   AHA-2920B      aic7860   PCI/32       SE-50M
+   AHA-2930B      aic7860   PCI/32       SE-50M
+   AHA-2920C      aic7856   PCI/32       SE-50M		SE-HD50F
+   AHA-2930C      aic7860   PCI/32       SE-50M
+   AHA-2930C      aic7860   PCI/32       SE-50M
+   AHA-2910C      aic7860   PCI/32       SE-50M
+   AHA-2915C      aic7860   PCI/32       SE-50M
+   AHA-2940AU/CN  aic7860   PCI/32       SE-50M		SE-HD50F
+   AHA-2944W      aic7870   PCI/32     HVD-HD68F	HVD-HD68F
+				        HVD-50M
+   AHA-3940W      aic7870   PCI/32     2 X SE-HD68F	SE-HD68F        2
+   AHA-2940UW     aic7880   PCI/32       SE-HD68F
+					 SE-50M		SE-HD68F
+   AHA-2940U      aic7880   PCI/32       SE-50M		SE-HD50F
+   AHA-2940D      aic7880   PCI/32
+   AHA-2940 A/T   aic7880   PCI/32
+   AHA-2940D A/T  aic7880   PCI/32
+   AHA-3940UW     aic7880   PCI/32     2 X SE-HD68F	SE-HD68F          3
+   AHA-3940UWD    aic7880   PCI/32     2 X SE-HD68F   2 X SE-VHD68F       3
+   AHA-3940U      aic7880   PCI/32     2 X SE-50M	SE-HD50F          3
+   AHA-2944UW     aic7880   PCI/32      HVD-HD68F	HVD-HD68F
+					 HVD-50M
+   AHA-3944UWD    aic7880   PCI/32     2 X HVD-HD68F  2 X HVD-VHD68F      3
+   AHA-4944UW     aic7880   PCI/32
+   AHA-2930UW     aic7880   PCI/32
+   AHA-2940UW Pro aic7880   PCI/32      SE-HD68F	SE-HD68F            4
+					 SE-50M
+   AHA-2940UW/CN  aic7880   PCI/32
+   AHA-2940UDual  aic7895   PCI/32
+   AHA-2940UWDual aic7895   PCI/32
+   AHA-3940UWD    aic7895   PCI/32
+   AHA-3940AUW    aic7895   PCI/32
+   AHA-3940AUWD   aic7895   PCI/32
+   AHA-3940AU     aic7895   PCI/32
+   AHA-3944AUWD   aic7895   PCI/32     2 X HVD-HD68F  2 X HVD-VHD68F
+   AHA-2940U2B    aic7890   PCI/32      LVD-HD68F	LVD-HD68F
+   AHA-2940U2 OEM aic7891   PCI/64
+   AHA-2940U2W    aic7890   PCI/32      LVD-HD68F	LVD-HD68F
+				        SE-HD68F 
+					 SE-50M
+   AHA-2950U2B    aic7891   PCI/64      LVD-HD68F	LVD-HD68F
+   AHA-2930U2     aic7890   PCI/32      LVD-HD68F	SE-HD50F
+					 SE-50M 
+   AHA-3950U2B    aic7897   PCI/64
+   AHA-3950U2D    aic7897   PCI/64
+   AHA-29160      aic7892   PCI/64-66
+   AHA-29160 CPQ  aic7892   PCI/64-66
+   AHA-29160N     aic7892   PCI/32      LVD-HD68F	SE-HD50F
+					 SE-50M
+   AHA-29160LP    aic7892   PCI/64-66
+   AHA-19160      aic7892   PCI/64-66
+   AHA-29150LP    aic7892   PCI/64-66
+   AHA-29130LP    aic7892   PCI/64-66
+   AHA-3960D      aic7899   PCI/64-66  2 X LVD-HD68F  2 X LVD-VHD68F
+					 LVD-50M
+   AHA-3960D CPQ  aic7899   PCI/64-66  2 X LVD-HD68F  2 X LVD-VHD68F
+					 LVD-50M
+   AHA-39160      aic7899   PCI/64-66  2 X LVD-HD68F  2 X LVD-VHD68F
+					 LVD-50M
+
+   1. No BIOS support
+   2. DEC21050 PCI-PCI bridge with multiple controller chips on secondary bus
+   3. DEC2115X PCI-PCI bridge with multiple controller chips on secondary bus
+   4. All three SCSI connectors may be used simultaneously without
+      SCSI "stub" effects.
+
+2. Command Line Options
+
+        WARNING: ALTERING OR ADDING THESE DRIVER PARAMETERS
+                 INCORRECTLY CAN RENDER YOUR SYSTEM INOPERABLE.
+                 USE THEM WITH CAUTION. 
+
+   Edit the file "modules.conf" in the directory /etc and add/edit a
+   line containing 'options aic7xxx=[command[,command...]]' where
+   'command' is one or more of the following:
+   -----------------------------------------------------------------
+              Option: verbose
+          Definition: enable additional informative messages during
+                      driver operation.
+     Possible Values: This option is a flag
+       Default Value: disabled
+   -----------------------------------------------------------------
+              Option: debug:[value]
+          Definition: Enables various levels of debugging information
+     Possible Values: 0x0000 = no debugging, 0xffff = full debugging
+       Default Value: 0x0000
+   -----------------------------------------------------------------
+              Option: no_reset
+          Definition: Do not reset the bus during the initial probe
+                      phase
+     Possible Values: This option is a flag
+       Default Value: disabled
+   -----------------------------------------------------------------
+              Option: extended
+          Definition: Force extended translation on the controller
+     Possible Values: This option is a flag
+       Default Value: disabled
+   -----------------------------------------------------------------
+              Option: periodic_otag
+          Definition: Send an ordered tag periodically to prevent
+                      tag starvation.  Needed for some older devices
+     Possible Values: This option is a flag
+       Default Value: disabled
+   -----------------------------------------------------------------
+              Option: reverse_scan
+          Definition: Probe the scsi bus in reverse order, starting
+                      with target 15
+     Possible Values: This option is a flag
+       Default Value: disabled
+   -----------------------------------------------------------------
+	      Option: global_tag_depth
+          Definition: Global tag depth for all targets on all busses.
+		      This option sets the default tag depth which
+		      may be selectively overridden vi the tag_info
+		      option.
+     Possible Values: 1 - 253
+       Default Value: 32
+   -----------------------------------------------------------------
+              Option: tag_info:{{value[,value...]}[,{value[,value...]}...]}
+          Definition: Set the per-target tagged queue depth on a
+		      per controller basis.  Both controllers and targets
+		      may be ommitted indicating that they should retain
+		      the default tag depth.
+            Examples: tag_info:{{16,32,32,64,8,8,,32,32,32,32,32,32,32,32,32}
+			On Controller 0
+			  specifies a tag depth of 16 for target 0
+			  specifies a tag depth of 64 for target 3
+			  specifies a tag depth of 8 for targets 4 and 5
+			  leaves target 6 at the default
+		          specifies a tag depth of 32 for targets 1,2,7-15
+			All other targets retain the default depth.
+
+		      tag_info:{{},{32,,32}}
+			On Controller 1
+			  specifies a tag depth of 32 for targets 0 and 2
+			All other targets retain the default depth.
+			
+     Possible Values: 1 - 253
+       Default Value: 32
+   -----------------------------------------------------------------
+              Option: seltime:[value]
+          Definition: Specifies the selection timeout value
+     Possible Values: 0 = 256ms, 1 = 128ms, 2 = 64ms, 3 = 32ms
+       Default Value: 0
+   -----------------------------------------------------------------
+
+   Example: 'options aic7xxx=verbose,no_probe,tag_info:{{},{,,10}},seltime:1"
+	enables verbose logging, Disable EISA/VLB probing,
+	and set tag depth on Controller 1/Target 2 to 10 tags.
+
+3. Contacting Adaptec
+
+   A Technical Support Identification (TSID) Number is required for 
+   Adaptec technical support.
+    - The 12-digit TSID can be found on the white barcode-type label
+      included inside the box with your product. The TSID helps us 
+      provide more efficient service by accurately identifying your 
+      product and support status.
+   Support Options
+    - Search the Adaptec Support Knowledgebase (ASK) at
+      http://ask.adaptec.com for articles, troubleshooting tips, and
+      frequently asked questions for your product.
+    - For support via Email, submit your question to Adaptec's 
+      Technical Support Specialists at http://ask.adaptec.com.
+     
+   North America
+    - Visit our Web site at http://www.adaptec.com.
+    - To speak with a Fibre Channel/RAID/External Storage Technical
+      Support Specialist, call 1-321-207-2000,
+      Hours: Monday-Friday, 3:00 A.M. to 5:00 P.M., PST.
+      (Not open on holidays)
+    - For Technical Support in all other technologies including 
+      SCSI, call 1-408-934-7274,
+      Hours: Monday-Friday, 6:00 A.M. to 5:00 P.M., PST.
+      (Not open on holidays)
+    - For after hours support, call 1-800-416-8066 ($99/call, 
+      $149/call on holidays)
+    - To order Adaptec products including software and cables, call
+      1-800-442-7274 or 1-408-957-7274. You can also visit our 
+      online store at http://www.adaptecstore.com
+
+   Europe
+    - Visit our Web site at http://www.adaptec-europe.com.
+    - English and French: To speak with a Technical Support 
+      Specialist, call one of the following numbers:
+        - English: +32-2-352-3470
+        - French:  +32-2-352-3460
+      Hours: Monday-Thursday, 10:00 to 12:30, 13:30 to 17:30 CET 
+             Friday, 10:00 to 12:30, 13:30 to 16:30 CET
+    - German: To speak with a Technical Support Specialist,
+      call +49-89-456-40660
+      Hours: Monday-Thursday, 09:30 to 12:30, 13:30 to 16:30 CET
+             Friday, 09:30 to 12:30, 13:30 to 15:00 CET
+    - To order Adaptec products, including accessories and cables:
+        - UK: +0800-96-65-26 or fax +0800-731-02-95
+        - Other European countries: +32-11-300-379
+
+   Australia and New Zealand
+    - Visit our Web site at http://www.adaptec.com.au.
+    - To speak with a Technical Support Specialist, call 
+      +612-9416-0698
+      Hours: Monday-Friday, 10:00 A.M. to 4:30 P.M., EAT
+      (Not open on holidays)
+
+   Japan
+    - To speak with a Technical Support Specialist, call 
+      +81-3-5308-6120 
+      Hours: Monday-Friday, 9:00 a.m. to 12:00 p.m., 1:00 p.m. to
+      6:00 p.m. TSC
+
+   Hong Kong and China
+    - To speak with a Technical Support Specialist, call 
+      +852-2869-7200
+      Hours: Monday-Friday, 10:00 to 17:00.
+    - Fax Technical Support at +852-2869-7100.
+
+   Singapore
+    - To speak with a Technical Support Specialist, call 
+      +65-245-7470
+      Hours: Monday-Friday, 10:00 to 17:00.
+    - Fax Technical Support at +852-2869-7100
+
+-------------------------------------------------------------------
+
+(c) 2002 Adaptec, Inc. All Rights Reserved. No part of this 
+publication may be reproduced, stored in a retrieval system, or 
+transmitted in any form or by any means, electronic, mechanical, 
+photocopying, recording or otherwise, without prior written consent 
+of Adaptec, Inc., 691 South Milpitas Blvd., Milpitas, CA 95035.
diff -Nru a/Documentation/sound/alsa/ALSA-Configuration.txt b/Documentation/sound/alsa/ALSA-Configuration.txt
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/Documentation/sound/alsa/ALSA-Configuration.txt	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,1188 @@
+
+		Advanced Linux Sound Architecture - Driver
+		==========================================
+			    Configuration guide
+
+
+Kernel Configuration
+====================
+
+To enable the ALSA support, at least you need to build the kernel with
+the primary sound card support (CONFIG_SOUND).  Since ALSA can emulate
+the OSS, you don't have to choose any of the OSS/Free modules.  Please
+enable "OSS API emulation" (CONFIG_SND_OSSEMUL) and both OSS mixer and
+PCM supports if you want to run the OSS application with the ALSA.
+
+When you want to support the WaveTable functionality on some cards
+such like SB Live!, you need to enable "Sequencer support"
+(CONFIG_SND_SEQUENCER).
+
+For getting more verbose debug messages, turn on "Verbose printk" and
+"Debug" options.  For checking the memory leaks, you can turn on
+"Debug memory" option, too.  "Debug detection" will put more
+additional checks for the detection of cards.
+
+Please note that all the ALSA ISA drivers support Linux isapnp API (if
+the card supports).  You don't need to configure the PnP via
+isapnptools.
+
+
+Module parameters
+=================
+
+  A user can modify or set parameters at the load time of the module. If
+  the module supports more cards and you have got more than one card
+  of the same type, you may simply specify more values for the parameter,
+  delimited by commas.
+  
+  Note that module option names were changed in 0.9.0rc4. The 'snd_'
+  prefix was removed.
+
+  Module snd
+  ----------
+
+    The module snd is the ALSA core module, which is used by all ALSA
+    card drivers.  This takes the global options for creating devices,
+    etc.
+
+    major	- major # for sound driver
+		- default is 116
+    cards_limit
+		- specifies card limit # (1-8)
+		- good for kmod support if you do not want to search
+		  for soundcards which are not installed in your system
+    device_mode
+		- specifies permission mask for dynamic sound device filesystem
+		- default value = 0666
+		- for example 'device_mode=0660'
+    device_gid
+		- specifies GID number for dynamic sound device filesystem
+		- default value = 0 (root)
+    device_uid
+		- specifies UID number for dynamic sound device filesystem
+		- default value = 0 (root)
+
+  
+  Module snd-pcm-oss
+  ------------------
+
+    The PCM OSS emulation module.
+    This module takes the options to change the mapping of devices.
+
+    dsp_map	- PCM device number maps assigned to the 1st OSS device.
+		  (default: 0)
+    adsp_map	- PCM device number maps assigned to the 2st OSS device.
+		  (default: 1)
+    nonblock_open - Don't block opening busy PCM devices.
+
+    For example, when dsp_map=2, /dev/dsp will be mapped to PCM #2 of
+    the card #0.  Similarly, when adsp_map=0, /dev/adsp will be mapped
+    to PCM #0 of the card #0.
+    For changing the second or later card, specify the option with
+    commas, such like "dsp_map=0,1".
+
+    nonblock_open option is used to change the behavior of the PCM
+    regarding opening the device.  When this option is non-zero,
+    opening a busy OSS PCM device won't be blocked but return
+    immediately with EAGAIN (just like O_NONBLOCK flag).
+    
+  Module snd-rawmidi
+  ------------------
+
+    This module takes the options to change the mapping of OSS
+    devices like snd-pcm-oss module.
+
+    midi_map	- MIDI device number maps assigned to the 1st OSS device.
+		  (default: 0)
+    amidi_map	- MIDI device number maps assigned to the 2st OSS device.
+		  (default: 1)
+
+  Global parameters for top soundcard modules
+  -------------------------------------------
+
+    Each of top-level soundcard module takes some general options,
+
+    index	- 0-7 - index (slot #) for soundcard
+                - if not set or -1, first free index (slot #) is assigned
+    id		- user identification for card (up to 15 chars)
+		- default expression is 'card<index>' (for example card1)
+		- value is used for /proc/asound filesystem
+		- this value can be used by applications for identification
+		  of card if user does not want identify card with index number
+    enable  	- enable card (only first card is enabled by default)
+
+  Module snd-ad1816a
+  ------------------
+
+    Module for soundcards based on Analog Devices AD1816A/AD1815 ISA chips.
+
+    port	- port # for AD1816A chip (PnP setup)
+    mpu_port	- port # for MPU-401 UART (PnP setup)
+    fm_port	- port # for OPL3 (PnP setup)
+    irq		- IRQ # for AD1816A chip (PnP setup)
+    mpu_irq	- IRQ # for MPU-401 UART (PnP setup)
+    dma1	- first DMA # for AD1816A chip (PnP setup)
+    dma2	- second DMA # for AD1816A chip (PnP setup)
+    
+    Module supports up to 8 cards, autoprobe and PnP.
+    
+  Module snd-ad1848
+  -----------------
+
+    Module for soundcards based on AD1848/AD1847/CS4248 ISA chips.
+
+    port	- port # for AD1848 chip
+    irq		- IRQ # for AD1848  chip
+    dma1	- DMA # for AD1848 chip (0,1,3)
+    
+    Module supports up to 8 cards. This module does not support autoprobe
+    thus main port must be specified!!! Other ports are optional.
+    
+  Module snd-ali5451
+  ------------------
+
+    Module for ALi M5451 PCI chip.
+
+    pcm_channels    - Number of hardware channels assigned for PCM
+
+    Module supports autoprobe and multiple chips (max 8).
+
+    The power-management is supported.
+
+  Module snd-als100
+  -----------------
+
+    Module for soundcards based on Avance Logic ALS100/ALS120 ISA chips.
+
+    port	- port # for ALS100 (SB16) chip (PnP setup)
+    irq		- IRQ # for ALS100 (SB16) chip (PnP setup)
+    dma8	- 8-bit DMA # for ALS100 (SB16) chip (PnP setup)
+    dma16	- 16-bit DMA # for ALS100 (SB16) chip (PnP setup)
+    mpu_port	- port # for MPU-401 UART (PnP setup)
+    mpu_irq	- IRQ # for MPU-401 (PnP setup)
+    fm_port	- port # for OPL3 FM (PnP setup)
+    
+    Module supports up to 8 cards, autoprobe and PnP.
+
+  Module snd-als4000
+  ------------------
+
+    Module for soundcards based on Avance Logic ALS4000 PCI chip.
+
+    joystick_port - port # for legacy joystick support.
+                        default: 0x200 for the 1st card.
+                        0 = disabled
+    
+    Module supports up to 8 cards, autoprobe and PnP.
+
+  Module snd-azt2320
+  ------------------
+
+    Module for soundcards based on Aztech System AZT2320 ISA chip (PnP only).
+
+    port	- port # for AZT2320 chip (PnP setup)
+    wss_port	- port # for WSS (PnP setup)
+    mpu_port	- port # for MPU-401 UART (PnP setup)
+    fm_port	- FM port # for AZT2320 chip (PnP setup)
+    irq		- IRQ # for AZT2320 (WSS) chip (PnP setup)
+    mpu_irq	- IRQ # for MPU-401 UART (PnP setup)
+    dma1	- 1st DMA # for AZT2320 (WSS) chip (PnP setup)
+    dma2	- 2nd DMA # for AZT2320 (WSS) chip (PnP setup)
+    
+    Module supports up to 8 cards, PnP and autoprobe.
+    
+  Module snd-cmi8330
+  ------------------
+
+    Module for soundcards based on C-Media CMI8330 ISA chips.
+
+    wssport	- port # for CMI8330 chip (WSS)
+    wssirq	- IRQ # for CMI8330 chip (WSS)
+    wssdma	- first DMA # for CMI8330 chip (WSS)
+    sbport	- port # for CMI8330 chip (SB16)
+    sbirq	- IRQ # for CMI8330 chip (SB16)
+    sbdma8	- 8bit DMA # for CMI8330 chip (SB16)
+    sbdma16	- 16bit DMA # for CMI8330 chip (SB16)
+
+    Module supports up to 8 cards and autoprobe.
+
+  Module snd-cmipci
+  -----------------
+
+    Module for C-Media CMI8338 and 8738 PCI soundcards.
+
+    mpu_port	- 0x300 (default),0x310,0x320,0x330, -1 (diable)
+    fm_port     - 0x388 (default), -1 (disable)
+
+    Module supports autoprobe and multiple chips (max 8).
+    
+  Module snd-cs4231
+  -----------------
+
+    Module for soundcards based on CS4231 ISA chips.
+
+    port	- port # for CS4231 chip
+    mpu_port	- port # for MPU-401 UART (optional), -1 = disable
+    irq		- IRQ # for CS4231 chip
+    mpu_irq	- IRQ # for MPU-401 UART
+    dma1	- first DMA # for CS4231 chip
+    dma2	- second DMA # for CS4231 chip
+    
+    Module supports up to 8 cards. This module does not support autoprobe
+    thus main port must be specified!!! Other ports are optional.
+
+    The power-management is supported.
+    
+  Module snd-cs4232
+  -----------------
+
+    Module for soundcards based on CS4232/CS4232A ISA chips.
+
+    port	- port # for CS4232 chip (PnP setup - 0x534)
+    cport	- control port # for CS4232 chip (PnP setup - 0x120,0x210,0xf00)
+    mpu_port	- port # for MPU-401 UART (PnP setup - 0x300), -1 = disable
+    fm_port	- FM port # for CS4232 chip (PnP setup - 0x388), -1 = disable
+    irq		- IRQ # for CS4232 chip (5,7,9,11,12,15)
+    mpu_irq	- IRQ # for MPU-401 UART (9,11,12,15)
+    dma1	- first DMA # for CS4232 chip (0,1,3)
+    dma2	- second DMA # for Yamaha CS4232 chip (0,1,3), -1 = disable
+    isapnp	- ISA PnP detection - 0 = disable, 1 = enable (default)
+    
+    Module supports up to 8 cards. This module does not support autoprobe
+    thus main port must be specified!!! Other ports are optional.
+
+    The power-management is supported.
+    
+  Module snd-cs4236
+  -----------------
+
+    Module for soundcards based on CS4235/CS4236/CS4236B/CS4237B/
+                                   CS4238B/CS4239 ISA chips.
+
+    port	- port # for CS4236 chip (PnP setup - 0x534)
+    cport	- control port # for CS4236 chip (PnP setup - 0x120,0x210,0xf00)
+    mpu_port	- port # for MPU-401 UART (PnP setup - 0x300), -1 = disable
+    fm_port	- FM port # for CS4236 chip (PnP setup - 0x388), -1 = disable
+    irq		- IRQ # for CS4236 chip (5,7,9,11,12,15)
+    mpu_irq	- IRQ # for MPU-401 UART (9,11,12,15)
+    dma1	- first DMA # for CS4236 chip (0,1,3)
+    dma2	- second DMA # for CS4236 chip (0,1,3), -1 = disable
+    isapnp	- ISA PnP detection - 0 = disable, 1 = enable (default)
+    
+    Module supports up to 8 cards. This module does not support autoprobe
+    (if ISA PnP is not used) thus main port and control port must be
+    specified!!! Other ports are optional.
+
+    The power-management is supported.
+
+  Module snd-cs4281
+  -----------------
+
+    Module for Cirrus Logic CS4281 soundchip.
+
+    dual_codec	- Secondary codec ID (0 = disable, default)
+
+    Module supports up to 8 cards.
+
+    The power-management is supported.
+
+  Module snd-cs46xx
+  -----------------
+
+    Module for PCI soundcards based on CS4610/CS4612/CS4614/CS4615/CS4622/
+				       CS4624/CS4630/CS4280 PCI chips.
+
+    external_amp     - Force to enable external amplifer.
+    thinkpad         - Force to enable Thinkpad's CLKRUN control.
+    mmap_valid       - Support OSS mmap mode (default = 0).
+
+    Module supports up to 8 cards and autoprobe.
+    Usually external amp and CLKRUN controls are detected automatically
+    from PCI sub vendor/device ids.  If they don't work, give the options
+    above explicitly.
+
+    The power-management is supported.
+    
+  Module snd-dt019x
+  -----------------
+
+    Module for Diamond Technologies DT-019X / Avance Logic ALS-007 (PnP
+    only)
+
+    port	- Port # (PnP setup)
+    mpu_port	- Port # for MPU-401 (PnP setup)
+    fm_port	- Port # for FM OPL-3 (PnP setup)
+    irq		- IRQ # (PnP setup)
+    mpu_irq	- IRQ # for MPU-401 (PnP setup)
+    dma8	- DMA # (PnP setup)
+
+    Module supports up to 8 cards.  This module is enabled only with
+    ISA PnP support.
+
+  Module snd-dummy
+  ----------------
+
+    Module for the dummy soundcard. This soundcard doesn't do any output
+    or input, but you may use this module for any application which
+    requires a soundcard (like RealPlayer).
+
+  Module snd-emu10k1
+  ------------------
+
+    Module for EMU10K1/EMU10k2 based PCI soundcards.
+			* Sound Blaster Live!
+			* Sound Blaster PCI 512
+			* Emu APS (partially supported)
+			* Sound Blaster Audigy
+
+    extin   - bitmap of available external inputs for FX8010 (see bellow)
+    extout  - bitmap of available external outputs for FX8010 (see bellow)
+    seq_ports - allocated sequencer ports (4 by default)
+    max_synth_voices - limit of voices used for wavetable (64 by default)
+    max_buffer_size  - specifies the maximum size of wavetable/pcm buffers
+                       given in MB unit.  Default value is 128.
+    enable_ir - enable IR
+
+    Module supports up to 8 cards and autoprobe.
+
+    Input & Output configurations 			[extin/extout]
+	* Creative Card wo/Digital out			[0x0003/0x1f03]
+	* Creative Card w/Digital out			[0x0003/0x1f0f]
+	* Creative Card w/Digital CD in			[0x000f/0x1f0f]
+	* Creative Card wo/Digital out + LiveDrive	[0x3fc3/0x1fc3]
+	* Creative Card w/Digital out + LiveDrive	[0x3fc3/0x1fcf]
+	* Creative Card w/Digital CD in + LiveDrive	[0x3fcf/0x1fcf]
+	* Creative Card wo/Digital out + Digital I/O 2  [0x0fc3/0x1f0f]
+	* Creative Card w/Digital out + Digital I/O 2	[0x0fc3/0x1f0f]
+	* Creative Card w/Digital CD in + Digital I/O 2	[0x0fcf/0x1f0f]
+        * Creative Card 5.1/w Digital out + LiveDrive	[0x3fc3/0x1fff]
+        * Creative Card all ins and outs		[0x3fff/0x1fff]
+    
+  Module snd-ens1370
+  ------------------
+
+    Module for Ensoniq AudioPCI ES1370 PCI soundcards.
+			* SoundBlaster PCI 64
+			* SoundBlaster PCI 128
+
+    Module supports up to 8 cards and autoprobe.
+    
+  Module snd-ens1371
+  ------------------
+
+    Module for Ensoniq AudioPCI ES1371 PCI soundcards.
+			* SoundBlaster PCI 64
+			* SoundBlaster PCI 128
+			* SoundBlaster Vibra PCI
+
+    Module supports up to 8 cards and autoprobe.
+    
+  Module snd-es968
+  ----------------
+
+    Module for soundcards based on ESS ES968 chip (PnP only).
+
+    port	- port # for ES968 (SB8) chip (PnP setup)
+    irq		- IRQ # for ES968 (SB8) chip (PnP setup)
+    dma1	- DMA # for ES968 (SB8) chip (PnP setup)
+    
+    Module supports up to 8 cards, PnP and autoprobe.
+    
+  Module snd-es1688
+  -----------------
+
+    Module for ESS AudioDrive ES-1688 and ES-688 soundcards.
+
+    port	- port # for ES-1688 chip (0x220,0x240,0x260)
+    mpu_port	- port # for MPU-401 port (0x300,0x310,0x320,0x330), -1 = disable (default)
+    irq		- IRQ # for ES-1688 chip (5,7,9,10)
+    mpu_irq	- IRQ # for MPU-401 port (5,7,9,10)
+    dma8	- DMA # for ES-1688 chip (0,1,3)
+
+    Module supports up to 8 cards and autoprobe (without MPU-401 port).
+
+  Module snd-es18xx
+  -----------------
+
+    Module for ESS AudioDrive ES-18xx soundcards.
+
+    port	- port # for ES-18xx chip (0x220,0x240,0x260)
+    mpu_port	- port # for MPU-401 port (0x300,0x310,0x320,0x330), -1 = disable (default)
+    fm_port	- port # for FM (optional, not used)
+    irq		- IRQ # for ES-18xx chip (5,7,9,10)
+    dma1	- first DMA # for ES-18xx chip (0,1,3)
+    dma2	- first DMA # for ES-18xx chip (0,1,3)
+    isapnp	- ISA PnP detection - 0 = disable, 1 = enable (default)
+
+    Module supports up to 8 cards ISA PnP and autoprobe (without MPU-401 port
+    if native ISA PnP routines are not used).
+    When dma2 is equal with dma1, the driver works as half-duplex.
+
+    The power-management is supported.
+
+  Module snd-es1938
+  -----------------
+
+    Module for soundcards based on ESS Solo-1 (ES1938,ES1946) chips.
+
+    Module supports up to 8 cards and autoprobe.
+
+  Module snd-es1968
+  -----------------
+
+    Module for soundcards based on ESS Maestro-1/2/2E (ES1968/ES1978) chips.
+
+    total_bufsize	- total buffer size in kB (1-4096kB)
+    pcm_substreams_p	- playback channels (1-8, default=2)
+    pcm_substreams_c	- capture channels (1-8, default=0)
+    clock		- clock (0 = auto-detection)
+    use_pm		- support the power-management (0 = off, 1 = on,
+			  2 = auto)
+
+    Module supports up to 8 cards and autoprobe.
+
+    The power-management is supported.
+
+  Module snd-fm801
+  ----------------
+
+    Module for ForteMedia FM801 based PCI soundcards.
+
+    Module supports up to 8 cards and autoprobe.
+    
+  Module snd-gusclassic
+  ---------------------
+
+    Module for Gravis UltraSound Classic soundcard.
+
+    port	- port # for GF1 chip (0x220,0x230,0x240,0x250,0x260)
+    irq		- IRQ # for GF1 chip (3,5,9,11,12,15)
+    dma1	- DMA # for GF1 chip (1,3,5,6,7)
+    dma2	- DMA # for GF1 chip (1,3,5,6,7,-1=disable)
+    joystick_dac - 0 to 31, (0.59V-4.52V or 0.389V-2.98V)
+    voices	- GF1 voices limit (14-32)
+    pcm_voices	- reserved PCM voices
+
+    Module supports up to 8 cards and autoprobe.
+
+  Module snd-gusextreme
+  ---------------------
+
+    Module for Gravis UltraSound Extreme (Synergy ViperMax) soundcard.
+
+    port	- port # for ES-1688 chip (0x220,0x230,0x240,0x250,0x260)
+    gf1_port	- port # for GF1 chip (0x210,0x220,0x230,0x240,0x250,0x260,0x270)
+    mpu_port	- port # for MPU-401 port (0x300,0x310,0x320,0x330), -1 = disable
+    irq		- IRQ # for ES-1688 chip (5,7,9,10)
+    gf1_irq	- IRQ # for GF1 chip (3,5,9,11,12,15)
+    mpu_irq	- IRQ # for MPU-401 port (5,7,9,10)
+    dma8	- DMA # for ES-1688 chip (0,1,3)
+    dma1	- DMA # for GF1 chip (1,3,5,6,7)
+    joystick_dac - 0 to 31, (0.59V-4.52V or 0.389V-2.98V)
+    voices	- GF1 voices limit (14-32)
+    pcm_voices	- reserved PCM voices
+
+    Module supports up to 8 cards and autoprobe (without MPU-401 port).
+
+  Module snd-gusmax
+  -----------------
+
+    Module for Gravis UltraSound MAX soundcard.
+
+    port	- port # for GF1 chip (0x220,0x230,0x240,0x250,0x260)
+    irq		- IRQ # for GF1 chip (3,5,9,11,12,15)
+    dma1	- DMA # for GF1 chip (1,3,5,6,7)
+    dma2	- DMA # for GF1 chip (1,3,5,6,7,-1=disable)
+    joystick_dac - 0 to 31, (0.59V-4.52V or 0.389V-2.98V)
+    voices	- GF1 voices limit (14-32)
+    pcm_voices	- reserved PCM voices
+
+    Module supports up to 8 cards and autoprobe.
+    
+  Module snd-hdsp
+  ---------------
+
+    Module for RME Hammerfall DSP audio interface(s)
+
+    precise_ptr	      - Enable precise pointer (doesn't work reliably).
+			(default = 0)
+    line_outs_monitor - Send all input and playback streams to line outs
+			by default. (default = 0)
+    force_firmware    - Force a reload of the I/O box firmware
+			(default = 0)
+
+    Module supports up to 8 cards.
+
+  Module snd-ice1712
+  ------------------
+
+    Module for Envy24 (ICE1712) based PCI soundcards.
+			* MidiMan M Audio Delta 1010
+			* MidiMan M Audio Delta DiO 2496
+			* MidiMan M Audio Delta 66
+			* MidiMan M Audio Delta 44
+			* MidiMan M Audio Audiophile 2496
+                        * TerraTec EWS 88MT
+                        * TerraTec EWS 88D
+                        * TerraTec EWX 24/96
+
+    omni	- Omni I/O support for MidiMan M-Audio Delta44/66
+
+    Module supports up to 8 cards and autoprobe. Note: The consumer part
+    is not used with all Envy24 based cards (for example in the MidiMan Delta
+    serie).
+
+  Module snd-intel8x0
+  -------------------
+
+    Module for AC'97 motherboards from Intel and compatibles.
+			* Intel i810/810E, i815, i820, i830, i84x, MX440
+			* SiS 7012 (SiS 735)
+			* NVidia NForce, NForce2
+			* AMD AMD768, AMD8111
+			* ALi m5455
+
+    ac97_clock	  - AC'97 codec clock base (0 = auto-detect)
+    joystick_port - Joystick port # (0 = disabled, 0x200)
+    mpu_port      - MPU401 port # (0 = disabled, 0x330,0x300)
+
+    Module supports autoprobe and multiple bus-master chips (max 8).
+    Note: the latest driver supports auto-detection of chip clock.
+    if you still encounter too fast playback, specify the clock
+    explicitly via the module option "ac97_clock=41194".
+
+    The joystick and MPU-401 are supported only certain hardwares.
+    MPU401 is experimental,  It doesn't work perfectly.
+
+    The power-management is supported.
+    
+  Module snd-interwave
+  --------------------
+
+    Module for Gravis UltraSound PnP, Dynasonic 3-D/Pro, STB Sound Rage 32
+    and other soundcards based on AMD InterWave (tm) chip.
+  
+    port	- port # for InterWave chip (0x210,0x220,0x230,0x240,0x250,0x260)
+    irq		- IRQ # for InterWave chip (3,5,9,11,12,15)
+    dma1	- DMA # for InterWave chip (0,1,3,5,6,7)
+    dma2	- DMA # for InterWave chip (0,1,3,5,6,7,-1=disable)
+    joystick_dac - 0 to 31, (0.59V-4.52V or 0.389V-2.98V)
+    midi	- 1 = MIDI UART enable, 0 = MIDI UART disable (default)
+    pcm_voices	- reserved PCM voices for the synthesizer (default 2)
+    effect	- 1 = InterWave effects enable (default 0);
+                  requires 8 voices
+
+    Module supports up to 8 cards, autoprobe and ISA PnP.
+
+  Module snd-interwave-stb
+  ------------------------
+
+    Module for UltraSound 32-Pro (soundcard from STB used by Compaq)
+    and other soundcards based on AMD InterWave (tm) chip with TEA6330T
+    circuit for extended control of bass, treble and master volume.
+  
+    port	- port # for InterWave chip (0x210,0x220,0x230,0x240,0x250,0x260)
+    port_tc	- tone control (i2c bus) port # for TEA6330T chip (0x350,0x360,0x370,0x380)
+    irq		- IRQ # for InterWave chip (3,5,9,11,12,15)
+    dma1	- DMA # for InterWave chip (0,1,3,5,6,7)
+    dma2	- DMA # for InterWave chip (0,1,3,5,6,7,-1=disable)
+    joystick_dac - 0 to 31, (0.59V-4.52V or 0.389V-2.98V)
+    midi	- 1 = MIDI UART enable, 0 = MIDI UART disable (default)
+    pcm_voices	- reserved PCM voices for the synthesizer (default 2)
+    effect	- 1 = InterWave effects enable (default 0);
+                  requires 8 voices
+
+    Module supports up to 8 cards, autoprobe and ISA PnP.
+
+  Module snd-korg1212
+  -------------------
+
+    Module for Korg 1212 IO PCI card
+
+    Module supports up to 8 cards.
+
+  Module snd-maestro3
+  -------------------
+
+    Module for Allegro/Maestro3 chips
+
+    external_amp     - enable external amp (enabled by default)
+    amp_gpio         - GPIO pin number for external amp (0-15) or
+                       -1 for default pin (8 for allegro, 1 for
+                       others) 
+
+    Module supports autoprobe and multiple chips (max 8).
+    Note: the binding of amplifier is dependent on hardware.
+    If there is no sound even though all channels are unmuted, try to
+    specify other gpio connection via amp_gpio option. 
+    For example, a Panasonic notebook might need "amp_gpio=0x0d"
+    option.
+
+    The power-management is supported.
+
+  Module snd-mpu401
+  -----------------
+
+    Module for MPU-401 UART devices.
+
+    port	- port number or -1 (disable)
+    irq		- IRQ number or -1 (disable)
+
+    Module supports multiple devices (max 8).
+    
+  Module snd-mtpav
+  ----------------
+
+    Module for MOTU MidiTimePiece AV multiport MIDI (on the parallel
+    port).
+
+    port	- I/O port # for MTPAV (0x378,0x278, default=0x378)
+    irq		- IRQ # for MTPAV (7,5, default=7)
+    hwports	- number of supported hardware ports, default=8.
+    
+    Module supports only 1 card.  This module has no enable option.
+
+  Module snd-nm256
+  ----------------
+
+    Module for NeoMagic NM256AV/ZX chips
+
+    playback_bufsize - max playback frame size in kB (4-128kB)
+    capture_bufsize  - max capture frame size in kB (4-128kB)
+    force_ac97       - 0 or 1 (disabled by default)
+    buffer_top       - specify buffer top address
+    use_cache        - 0 or 1 (disabled by default)
+    vaio_hack        - alias buffer_top=0x25a800
+
+    Module supports autoprobe and multiple chips (max 8).
+    Note: on some notebooks the buffer address cannot be detected
+    automatically, or causes hang-up during initialization.
+    In such a case, specify the buffer top address explicity via
+    buffer_top option.
+    For example,
+      Sony F250: buffer_top=0x25a800
+      Sony F270: buffer_top=0x272800
+    The driver supports only ac97 codec.  It's possible to force
+    to initialize/use ac97 although it's not detected.  In such a
+    case, use force_ac97=1 option.
+
+    The power-management is supported.
+
+  Module snd-opl3sa2
+  ------------------
+
+    Module for Yamaha OPL3-SA2/SA3 soundcards.
+
+    port	- control port # for OPL3-SA chip (0x370)
+    sb_port	- SB port # for OPL3-SA chip (0x220,0x240)
+    wss_port	- WSS port # for OPL3-SA chip (0x530,0xe80,0xf40,0x604)
+    midi_port	- port # for MPU-401 UART (0x300,0x330), -1 = disable
+    fm_port	- FM port # for OPL3-SA chip (0x388), -1 = disable
+    irq		- IRQ # for OPL3-SA chip (5,7,9,10)
+    dma1	- first DMA # for Yamaha OPL3-SA chip (0,1,3)
+    dma2	- second DMA # for Yamaha OPL3-SA chip (0,1,3), -1 = disable
+    isapnp	- ISA PnP detection - 0 = disable, 1 = enable (default)
+    
+    Module supports up to 8 cards and ISA PnP. This module does not support
+    autoprobe (if ISA PnP is not used) thus all ports must be specified!!!
+    
+    The power-management is supported.
+
+  Module snd-opti92x-ad1848
+  -------------------------
+
+    Module for soundcards based on OPTi 82c92x and Analog Devices AD1848 chips.
+    Module works with OAK Mozart cards as well.
+    
+    port      - port # for WSS chip (0x530,0xe80,0xf40,0x604)
+    mpu_port  - port # for MPU-401 UART (0x300,0x310,0x320,0x330)
+    fm_port   - port # for OPL3 device (0x388)
+    irq       - IRQ # for WSS chip (5,7,9,10,11)
+    mpu_irq   - IRQ # for MPU-401 UART (5,7,9,10)
+    dma1      - first DMA # for WSS chip (0,1,3)
+
+    This module supports only one card, autoprobe and PnP.
+
+  Module snd-opti92x-cs4231
+  -------------------------
+
+    Module for soundcards based on OPTi 82c92x and Crystal CS4231 chips.
+    
+    port      - port # for WSS chip (0x530,0xe80,0xf40,0x604)
+    mpu_port  - port # for MPU-401 UART (0x300,0x310,0x320,0x330)
+    fm_port   - port # for OPL3 device (0x388)
+    irq       - IRQ # for WSS chip (5,7,9,10,11)
+    mpu_irq   - IRQ # for MPU-401 UART (5,7,9,10)
+    dma1      - first DMA # for WSS chip (0,1,3)
+    dma2      - second DMA # for WSS chip (0,1,3)
+
+    This module supports only one card, autoprobe and PnP.
+
+  Module snd-opti93x
+  ------------------
+
+    Module for soundcards based on OPTi 82c93x chips.
+    
+    port      - port # for WSS chip (0x530,0xe80,0xf40,0x604)
+    mpu_port  - port # for MPU-401 UART (0x300,0x310,0x320,0x330)
+    fm_port   - port # for OPL3 device (0x388)
+    irq       - IRQ # for WSS chip (5,7,9,10,11)
+    mpu_irq   - IRQ # for MPU-401 UART (5,7,9,10)
+    dma1      - first DMA # for WSS chip (0,1,3)
+    dma2      - second DMA # for WSS chip (0,1,3)
+
+    This module supports only one card, autoprobe and PnP.
+
+  Module snd-powermac (on ppc only)
+  ---------------------------------
+
+    Module for PowerMac, iMac and iBook on-board soundchips
+
+    enable_beep     - enable beep using PCM (enabled as default)
+
+    Module supports autoprobe a chip.
+    Note: the driver may have problems regarding endianess.
+
+    The power-management is supported.
+
+  Module snd-rme32
+  ----------------
+
+    Module for RME Digi32, Digi32/8 and Digi32 PRO soundcards.
+
+    Module supports up to 8 cards.
+
+  Module snd-rme96
+  ----------------
+
+    Module for RME Digi96, Digi96/8 and Digi96/8 PRO/PAD/PST soundcards.
+
+    Module supports up to 8 cards.
+
+  Module snd-rme9652
+  ------------------
+
+    Module for RME Digi9652 (Hammerfall, Hammerfall-Light) soundcards.
+
+    precise_ptr	- Enable precise pointer (doesn't work reliably).
+		  (default = 0)
+
+    Module supports up to 8 cards.
+
+  Module snd-sa11xx-uda1341 (on arm only)
+  ---------------------------------------
+
+    Module for Philips UDA1341TS on Compaq iPAQ H3600 soundcard.
+
+    Module supports only one card.
+    Module has no enable and index options.
+
+  Module snd-sb8
+  --------------
+
+    Module for 8-bit SoundBlaster cards: SoundBlaster 1.0,
+					 SoundBlaster 2.0,
+					 SoundBlaster Pro
+
+    port	- port # for SB DSP chip (0x220,0x240,0x260)
+    irq		- IRQ # for SB DSP chip (5,7,9,10)
+    dma8	- DMA # for SB DSP chip (1,3)
+
+    Module supports up to 8 cards and autoprobe.
+    
+  Module snd-sb16 and snd-sbawe
+  -----------------------------
+
+    Module for 16-bit SoundBlaster cards: SoundBlaster 16 (PnP),
+					  SoundBlaster AWE 32 (PnP),
+					  SoundBlaster AWE 64 PnP
+
+    port	- port # for SB DSP 4.x chip (0x220,0x240,0x260)
+    mpu_port	- port # for MPU-401 UART (0x300,0x330), -1 = disable
+    awe_port	- base port # for EMU8000 synthesizer (0x620,0x640,0x660)
+                   (snd-sbawe module only)
+    irq		- IRQ # for SB DSP 4.x chip (5,7,9,10)
+    dma8	- 8-bit DMA # for SB DSP 4.x chip (0,1,3)
+    dma16	- 16-bit DMA # for SB DSP 4.x chip (5,6,7)
+    mic_agc	- Mic Auto-Gain-Control - 0 = disable, 1 = enable (default)
+    csp		- ASP/CSP chip support - 0 = disable (default), 1 = enable
+    isapnp	- ISA PnP detection - 0 = disable, 1 = enable (default)
+    
+    Module supports up to 8 cards, autoprobe and ISA PnP.
+
+    Note: To use Vibra16X cards in 16-bit half duplex mode, you must
+          disable 16bit DMA with dma16 = -1 module parameter.
+          Also, all Sound Blaster 16 type cards can operate in 16-bit
+          half duplex mode through 8-bit DMA channel by disabling their
+          16-bit DMA channel.
+    
+  Module snd-sgalaxy
+  ------------------
+
+    Module for Aztech Sound Galaxy soundcard.
+
+    sbport	- Port # for SB16 interface (0x220,0x240)
+    wssport	- Port # for WSS interface (0x530,0xe80,0xf40,0x604)
+    irq		- IRQ # (7,9,10,11)
+    dma1	- DMA #
+
+    Module supports up to 8 cards.
+
+  Module snd-sun-amd7930 (on sparc only)
+  --------------------------------------
+
+    Module for AMD7930 sound chips found on Sparcs.
+
+    Module supports up to 8 cards.
+
+  Module snd-sun-cs4231 (on sparc only)
+  -------------------------------------
+
+    Module for CS4231 sound chips found on Sparcs.
+
+    Module supports up to 8 cards.
+
+  Module snd-wavefront
+  --------------------
+
+    Module for Turtle Beach Maui, Tropez and Tropez+ soundcards.
+
+    cs4232_pcm_port - Port # for CS4232 PCM interface.
+    cs4232_pcm_irq  - IRQ # for CS4232 PCM interface (5,7,9,11,12,15).
+    cs4232_mpu_port - Port # for CS4232 MPU-401 interface.
+    cs4232_mpu_irq  - IRQ # for CS4232 MPU-401 interface (9,11,12,15).
+    use_cs4232_midi - Use CS4232 MPU-401 interface
+                      (inaccessibly located inside your computer)
+    ics2115_port    - Port # for ICS2115
+    ics2115_irq     - IRQ # for ICS2115
+    fm_port         - FM OPL-3 Port #
+    dma1            - DMA1 # for CS4232 PCM interface.
+    dma2            - DMA2 # for CS4232 PCM interface.
+    isapnp          - ISA PnP detection - 0 = disable, 1 = enable (default)
+
+    Module supports up to 8 cards and ISA PnP.
+
+  Module snd-sonicvibes
+  ---------------------
+
+    Module for S3 SonicVibes PCI soundcards.
+			* PINE Schubert 32 PCI
+
+    reverb    - Reverb Enable - 1 = enable, 0 = disable (default)
+                  - SoundCard must have onboard SRAM for this.
+    mge       - Mic Gain Enable - 1 = enable, 0 = disable (default)
+    
+    Module supports up to 8 cards and autoprobe.
+
+  Module snd-serial-u16550
+  ------------------------
+
+    Module for UART16550A serial MIDI ports.
+
+    port	- port # for UART16550A chip
+    irq		- IRQ # for UART16550A chip, -1 = poll mode
+    speed	- speed in bauds (9600,19200,38400,57600,115200)
+		  38400 = default
+    base	- base for divisor in bauds (57600,115200,230400,460800)
+		  115200 = default
+    outs	- number of MIDI ports in a serial port (1-4)
+		  1 = default
+    adaptor	- Type of adaptor.
+                  0 = Soundcanvas, 1 = MS-124T, 2 = MS-124W S/A,
+		  3 = MS-124W M/B, 4 = Generic
+    
+    Module supports up to 8 cards. This module does not support autoprobe
+    thus the main port must be specified!!! Other options are optional.
+
+  Module snd-trident
+  ------------------
+
+    Module for Trident 4DWave DX/NX soundcards.
+			* Best Union  Miss Melody 4DWave PCI
+			* HIS  4DWave PCI
+			* Warpspeed  ONSpeed 4DWave PCI
+			* AzTech  PCI 64-Q3D
+			* Addonics  SV 750
+			* CHIC  True Sound 4Dwave
+			* Shark  Predator4D-PCI
+			* Jaton  SonicWave 4D
+
+    pcm_channels   - max channels (voices) reserved for PCM
+    wavetable_size - max wavetable size in kB (4-?kb)
+
+    Module supports up to 8 cards and autoprobe.
+
+    The power-management is supported.
+
+  Module snd-usb-audio
+  --------------------
+
+    Module for USB audio and USB MIDI devices.
+
+    vid             - Vendor ID for the device (optional)
+    pid             - Product ID for the device (optional)
+
+    This module supports up to 8 cards, autoprobe and hotplugging.
+
+  Module snd-via82xx
+  ------------------
+
+    Module for AC'97 motherboards based on VIA 82C686A/686B, 8233
+    (south) bridge.
+
+    mpu_port	- 0x300,0x310,0x320,0x330, otherwise obtain BIOS setup
+    ac97_clock	- AC'97 codec clock base (default 48000Hz)
+
+    Module supports autoprobe and multiple bus-master chips (max 8).
+    Note: on some SMP motherboards like MSI 694D the interrupts might
+          not be generated properly.  In such a case, please try to
+          set the SMP (or MPS) version on BIOS to 1.1 instead of
+          default value 1.4.  Then the interrupt number will be
+          assigned under 15. You might also upgrade your BIOS.
+    
+  Module snd-virmidi
+  ------------------
+
+    Module for virtual rawmidi devices.
+    This module creates virtual rawmidi devices which communicate
+    to the corresponding ALSA sequencer ports.
+
+    midi_devs	- MIDI devices # (1-8, default=4)
+    
+    Module supports up to 8 cards.
+
+  Module snd-ymfpci
+  -----------------
+
+    Module for Yamaha PCI chips (YMF72x, YMF74x & YMF75x).
+
+    mpu_port	- 0x300,0x330,0x332,0x334, -1 (disable) by default
+    fm_port	- 0x388,0x398,0x3a0,0x3a8, -1 (disable) by default
+    rear_switch - enable shared rear/line-in switch (bool)
+
+    Module supports autoprobe and multiple chips (max 8).
+    
+    The power-management is supported.
+
+
+modprobe/kmod support
+=====================
+
+The modprobe program must know which modules are used for the
+device major numbers.
+Native ALSA devices have got default number 116. Thus a line like
+'alias char-major-116 snd' must be added to /etc/modules.conf. If you have 
+compiled the ALSA driver with the OSS/Free emulation code, then you
+will need to add lines as explained below:
+
+The ALSA driver uses soundcore multiplexer for 2.2+ kernels and OSS compatible
+devices. You should add line like 'alias char-major-14 soundcore'.
+
+Example with OSS/Free emulation turned on:
+
+----- /etc/modules.conf
+
+# ALSA portion
+alias char-major-116 snd
+# OSS/Free portion
+alias char-major-14 soundcore
+
+----- /etc/modules.conf
+
+After the main multiplexer is loaded, its code requests top-level soundcard
+module. String 'snd-card-%i' is requested for native devices where %i is
+soundcard number from zero to seven. String 'sound-slot-%i' is requested
+for native devices where %i is slot number (for ALSA owner this means soundcard
+number).
+
+----- /etc/modules.conf
+
+# ALSA portion
+alias snd-card-0 snd-interwave
+alias snd-card-1 snd-ens1371
+# OSS/Free portion
+alias sound-slot-0 snd-card-0
+alias sound-slot-1 snd-card-1
+
+----- /etc/modules.conf
+
+We are finished at this point with the configuration for ALSA native devices,
+but you may also need autoloading for ALSA's add-on OSS/Free emulation
+modules. At this time only one module does not depend on any others, thus
+must be loaded separately - snd-pcm-oss. String 'sound-service-%i-%i'
+is requested for OSS/Free service where first %i means slot number
+(e.g. card number) and second %i means service number.
+
+----- /etc/modules.conf
+
+# OSS/Free portion - card #1
+alias sound-service-0-0 snd-mixer-oss
+alias sound-service-0-1 snd-seq-oss
+alias sound-service-0-3 snd-pcm-oss
+alias sound-service-0-8 snd-seq-oss
+alias sound-service-0-12 snd-pcm-oss
+# OSS/Free portion - card #2
+alias sound-service-1-0 snd-mixer-oss
+alias sound-service-1-3 snd-pcm-oss
+alias sound-service-1-12 snd-pcm-oss
+
+----- /etc/modules.conf
+
+A complete example for Gravis UltraSound PnP soundcard:
+
+----- /etc/modules.conf
+
+# ISA PnP support (don't use IRQs 9,10,11,12,13)
+options isapnp isapnp_reserve_irq=9,10,11,12,13
+
+# ALSA native device support
+alias char-major-116 snd
+options snd major=116 cards_limit=1
+alias snd-card-0 snd-interwave
+options snd-interwave index=0 id="GusPnP"
+
+# OSS/Free setup
+alias char-major-14 soundcore
+alias sound-slot-0 snd-card-0
+alias sound-service-0-0 snd-mixer-oss
+alias sound-service-0-1 snd-seq-oss
+alias sound-service-0-3 snd-pcm-oss
+alias sound-service-0-8 snd-seq-oss
+alias sound-service-0-12 snd-pcm-oss
+
+-----
+
+A complete example if you want to use more soundcards in one machine
+(the configuration below is for Sound Blaster 16 and Gravis UltraSound Classic):
+
+----- /etc/modules.conf
+
+# ISA PnP support (don't use IRQs 9,10,11,12,13)
+# it's only an example to reserve some IRQs for another hardware
+options isapnp isapnp_reserve_irq=9,10,11,12,13
+
+# ALSA native device support
+alias char-major-116 snd
+options snd major=116 cards_limit=2
+alias snd-card-0 snd-gusclassic
+alias snd-card-1 snd-sb16
+options snd-gusclassic index=0 id="Gus" \
+        port=0x220 irq=5 dma1=6 dma2=7
+options snd-sb16 index=1 id="SB16"
+
+# OSS/Free setup
+alias char-major-14 soundcore
+alias sound-slot-0 snd-card-0
+alias sound-service-0-0 snd-mixer-oss
+alias sound-service-0-1 snd-seq-oss
+alias sound-service-0-3 snd-pcm-oss
+alias sound-service-0-8 snd-seq-oss
+alias sound-service-0-12 snd-pcm-oss
+alias sound-slot-1 snd-card-1
+alias sound-service-1-0 snd-mixer-oss
+alias sound-service-1-3 snd-pcm-oss
+alias sound-service-1-12 snd-pcm-oss
+
+-----
+
+A complete example, two Gravis UltraSound Classic soundcards are installed
+in the system:
+
+----- /etc/modules.conf
+
+# ALSA native device support
+alias char-major-116 snd
+options snd major=116 cards_limit=2
+alias snd-card-0 snd-gusclassic
+alias snd-card-1 snd-gusclassic
+options snd-gusclassic index=0,1 id="Gus1","Gus2" \
+        port=0x220,0x240 irq=5,7 dma1=1,5 dma2=3,6
+
+# OSS/Free setup
+alias char-major-14 soundcore
+alias sound-slot-0 snd-card-0
+alias sound-service-0-0 snd-mixer-oss
+alias sound-service-0-1 snd-seq-oss
+alias sound-service-0-3 snd-pcm-oss
+alias sound-service-0-8 snd-seq-oss
+alias sound-service-0-12 snd-pcm-oss
+alias sound-slot-1 snd-card-1
+alias sound-service-1-0 snd-mixer-oss
+alias sound-service-1-3 snd-pcm-oss
+alias sound-service-1-12 snd-pcm-oss
+
+-----
+
+If you want to autoclean your modules, you should put below line to your
+/etc/crontab:
+
+*/10 * * * *   root  /sbin/modprobe -rs snd-card-0 snd-card-1; /sbin/rmmod -as
+
+You may also want to extend the soundcard list to follow your requirements.
+
+
+ALSA PCM devices to OSS devices mapping
+=======================================
+
+/dev/snd/pcmC0D0  -> /dev/audio0 (/dev/audio) -> minor 4
+/dev/snd/pcmC0D0  -> /dev/dsp0 (/dev/dsp)     -> minor 3
+/dev/snd/pcmC0D1  -> /dev/adsp0 (/dev/adsp)   -> minor 12
+/dev/snd/pcmC1D0  -> /dev/audio1              -> minor 4+16 = 20
+/dev/snd/pcmC1D0  -> /dev/dsp1                -> minor 3+16 = 19
+/dev/snd/pcmC1D1  -> /dev/adsp1               -> minor 12+16 = 28
+/dev/snd/pcmC2D0  -> /dev/audio2              -> minor 4+32 = 36
+/dev/snd/pcmC2D0  -> /dev/dsp2                -> minor 3+32 = 39
+/dev/snd/pcmC2D1  -> /dev/adsp2               -> minor 12+32 = 44
+
+The first number from /dev/snd/pcmC{X}D{Y} expression means soundcard number
+and second means device number.
+Please note that the device mapping above may be varied via the module
+options of snd-pcm-oss module.
+
+
+DEVFS support
+=============
+
+The ALSA driver fully supports the devfs extension.
+You should add lines below to your devfsd.conf file:
+
+LOOKUP snd MODLOAD ACTION snd
+REGISTER ^sound/.* PERMISSIONS root.audio 660
+REGISTER ^snd/.* PERMISSIONS root.audio 660
+
+Warning: These lines assume that you have the audio group in your system.
+         Otherwise replace audio word with another group name (root for
+         example).
+
+
+Proc interfaces (/proc/asound)
+==============================
+
+/proc/asound/card#/pcm#[cp]/oss
+-------------------------------
+  String "erase" - erase all additional informations about OSS applications
+  String "<app_name> <fragments> <fragment_size> [<options>]"
+
+   <app_name> - name of application with (higher priority) or without path
+   <fragments> - number of fragments or zero if auto
+   <fragment_size> - size of fragment in bytes or zero if auto
+   <options> - optional parameters
+	  - disable   the application tries to open a pcm device for
+		      this channel but does not want to use it.
+		      (Cause a bug or mmap needs)
+		      It's good for Quake etc...
+	  - direct    don't use plugins
+	  - block     force block mode (rvplayer)
+	  - non-block force non-block mode
+
+  Example: echo "x11amp 128 16384" > /proc/asound/card0/pcm0p/oss
+           echo "squake 0 0 disable" > /proc/asound/card0/pcm0c/oss
+	   echo "rvplayer 0 0 block" > /proc/asound/card0/pcm0p/oss
+
+
+Links
+=====
+
+  ALSA project homepage
+       http://www.alsa-project.org
+
diff -Nru a/Documentation/sound/alsa/ControlNames.txt b/Documentation/sound/alsa/ControlNames.txt
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/Documentation/sound/alsa/ControlNames.txt	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,82 @@
+This document describes standard names of mixer controls.
+
+Syntax: SOURCE [DIRECTION] FUNCTION
+
+DIRECTION:
+  <nothing>	(both directions)
+  Playback
+  Capture
+  Bypass Playback
+  Bypass Capture
+
+FUNCTION:
+  Switch	(on/off switch)
+  Volume
+  Route		(route control, hardware specific)
+
+SOURCE:
+  Master
+  Master Mono
+  Hardware Master
+  Headphone
+  PC Speaker
+  Phone
+  Phone Input
+  Phone Output
+  Synth
+  FM
+  Mic
+  Line
+  CD
+  Video
+  Zoom Video
+  Aux
+  PCM
+  PCM Front
+  PCM Rear
+  PCM Pan
+  Loopback
+  Analog Loopback	(D/A -> A/D loopback)
+  Digital Loopback	(playback -> capture loopback - without analog path)
+  Mono
+  Mono Output
+  Multi
+  ADC
+  Wave
+  Music
+  I2S
+  IEC958
+
+Exceptions:
+  [Digital] Capture Source
+  [Digital] Capture Switch	(aka input gain switch)
+  [Digital] Capture Volume	(aka input gain volume)
+  [Digital] Playback Switch	(aka output gain switch)
+  [Digital] Playback Volume	(aka output gain volume)
+  Tone Control - Switch
+  Tone Control - Bass
+  Tone Control - Treble
+  3D Control - Switch
+  3D Control - Center
+  3D Control - Depth
+  3D Control - Wide
+  3D Control - Space
+  3D Control - Level
+  Mic Boost [(?dB)]
+
+PCM interface:
+
+  Sample Clock Source	{ "Word", "Internal", "AutoSync" }
+  Clock Sync Status	{ "Lock", "Sync", "No Lock" }
+  External Rate		/* external capture rate */
+  Capture Rate		/* capture rate taken from external source */
+
+IEC958 (S/PDIF) interface:
+
+  IEC958 [...] [Playback|Capture] Switch	/* turn on/off the IEC958 interface */
+  IEC958 [...] [Playback|Capture] Volume	/* digital volume control */
+  IEC958 [...] [Playback|Capture] Default	/* default or global value - read/write */
+  IEC958 [...] [Playback|Capture] Mask		/* consumer and professional mask */
+  IEC958 [...] [Playback|Capture] Con Mask	/* consumer mask */
+  IEC958 [...] [Playback|Capture] Pro Mask	/* professional mask */
+  IEC958 [...] [Playback|Capture] PCM Stream	/* the settings assigned to a PCM stream */
diff -Nru a/MAINTAINERS b/MAINTAINERS
--- a/MAINTAINERS	Mon Dec 23 21:21:56 2002
+++ b/MAINTAINERS	Mon Dec 23 21:21:56 2002
@@ -1521,6 +1521,12 @@
 L:	linux-scsi@vger.kernel.org
 S:	Maintained
 
+SCTP PROTOCOL
+P: Jon Grimm
+M: jgrimm2@us.ibm.com
+L: lksctp-developers@lists.sourceforge.net
+S: Supported
+
 SCx200 CPU SUPPORT
 P:	Christer Weinigel
 M:	christer@weinigel.se
diff -Nru a/Makefile b/Makefile
--- a/Makefile	Mon Dec 23 21:21:51 2002
+++ b/Makefile	Mon Dec 23 21:21:51 2002
@@ -1,6 +1,6 @@
 VERSION = 2
 PATCHLEVEL = 5
-SUBLEVEL = 52
+SUBLEVEL = 53
 EXTRAVERSION =
 
 # *DOCUMENTATION*
@@ -854,7 +854,7 @@
 # FIXME Should go into a make.lib or something 
 # ===========================================================================
 
-a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(NOSTDINC_FLAGS) \
+a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(AFLAGS_KERNEL) $(NOSTDINC_FLAGS) \
 	  $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
 
 quiet_cmd_as_s_S = CPP     $@
diff -Nru a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
--- a/arch/alpha/kernel/traps.c	Mon Dec 23 21:21:59 2002
+++ b/arch/alpha/kernel/traps.c	Mon Dec 23 21:21:59 2002
@@ -638,7 +638,7 @@
 got_exception:
 	/* Ok, we caught the exception, but we don't want it.  Is there
 	   someone to pass it along to?  */
-	if ((fixup = search_exception_table(pc, regs.gp)) != 0) {
+	if ((fixup = search_exception_table(pc)) != 0) {
 		unsigned long newpc;
 		newpc = fixup_exception(una_reg, fixup, pc);
 
diff -Nru a/arch/alpha/lib/clear_user.S b/arch/alpha/lib/clear_user.S
--- a/arch/alpha/lib/clear_user.S	Mon Dec 23 21:21:53 2002
+++ b/arch/alpha/lib/clear_user.S	Mon Dec 23 21:21:53 2002
@@ -29,7 +29,7 @@
 #define EX(x,y...)			\
 	99: x,##y;			\
 	.section __ex_table,"a";	\
-	.gprel32 99b;			\
+	.long 99b - .;			\
 	lda $31, $exception-99b($31); 	\
 	.previous
 
@@ -80,7 +80,6 @@
 	ret	$31, ($28), 1	# .. e1 :
 
 __do_clear_user:
-	ldgp	$29,0($27)	# we do exceptions -- we need the gp.
 	and	$6, 7, $4	# e0    : find dest misalignment
 	beq	$0, $zerolength # .. e1 :
 	addq	$0, $4, $1	# e0    : bias counter
diff -Nru a/arch/alpha/lib/copy_user.S b/arch/alpha/lib/copy_user.S
--- a/arch/alpha/lib/copy_user.S	Mon Dec 23 21:21:51 2002
+++ b/arch/alpha/lib/copy_user.S	Mon Dec 23 21:21:51 2002
@@ -30,29 +30,28 @@
 #define EXI(x,y...)			\
 	99: x,##y;			\
 	.section __ex_table,"a";	\
-	.gprel32 99b;			\
+	.long 99b - .;			\
 	lda $31, $exitin-99b($31);	\
 	.previous
 
 #define EXO(x,y...)			\
 	99: x,##y;			\
 	.section __ex_table,"a";	\
-	.gprel32 99b;			\
+	.long 99b - .;			\
 	lda $31, $exitout-99b($31);	\
 	.previous
 
 	.set noat
-	.align 3
+	.align 4
 	.globl __copy_user
 	.ent __copy_user
 __copy_user:
-	ldgp $29,0($27)			# we do exceptions -- we need the gp.
-	.prologue 1
+	.prologue 0
 	and $6,7,$3
 	beq $0,$35
 	beq $3,$36
 	subq $3,8,$3
-	.align 5
+	.align 4
 $37:
 	EXI( ldq_u $1,0($7) )
 	EXO( ldq_u $2,0($6) )
@@ -73,7 +72,7 @@
 	beq $1,$43
 	beq $4,$48
 	EXI( ldq_u $3,0($7) )
-	.align 5
+	.align 4
 $50:
 	EXI( ldq_u $2,8($7) )
 	subq $4,8,$4
@@ -88,7 +87,7 @@
 	bne $4,$50
 $48:
 	beq $0,$41
-	.align 5
+	.align 4
 $57:
 	EXI( ldq_u $1,0($7) )
 	EXO( ldq_u $2,0($6) )
@@ -105,7 +104,7 @@
 	.align 4
 $43:
 	beq $4,$65
-	.align 5
+	.align 4
 $66:
 	EXI( ldq $1,0($7) )
 	subq $4,8,$4
diff -Nru a/arch/alpha/lib/ev6-clear_user.S b/arch/alpha/lib/ev6-clear_user.S
--- a/arch/alpha/lib/ev6-clear_user.S	Mon Dec 23 21:21:57 2002
+++ b/arch/alpha/lib/ev6-clear_user.S	Mon Dec 23 21:21:57 2002
@@ -47,7 +47,7 @@
 #define EX(x,y...)			\
 	99: x,##y;			\
 	.section __ex_table,"a";	\
-	.gprel32 99b;			\
+	.long 99b - .;			\
 	lda $31, $exception-99b($31); 	\
 	.previous
 
@@ -62,9 +62,6 @@
 
 				# Pipeline info : Slotting & Comments
 __do_clear_user:
-	ldgp	$29,0($27)	# we do exceptions -- we need the gp.
-				# Macro instruction becomes ldah/lda
-				# .. .. E  E	:
 	and	$6, 7, $4	# .. E  .. ..	: find dest head misalignment
 	beq	$0, $zerolength # U  .. .. ..	:  U L U L
 
diff -Nru a/arch/alpha/lib/ev6-copy_user.S b/arch/alpha/lib/ev6-copy_user.S
--- a/arch/alpha/lib/ev6-copy_user.S	Mon Dec 23 21:21:50 2002
+++ b/arch/alpha/lib/ev6-copy_user.S	Mon Dec 23 21:21:50 2002
@@ -41,14 +41,14 @@
 #define EXI(x,y...)			\
 	99: x,##y;			\
 	.section __ex_table,"a";	\
-	.gprel32 99b;			\
+	.long 99b - .;			\
 	lda $31, $exitin-99b($31);	\
 	.previous
 
 #define EXO(x,y...)			\
 	99: x,##y;			\
 	.section __ex_table,"a";	\
-	.gprel32 99b;			\
+	.long 99b - .;			\
 	lda $31, $exitout-99b($31);	\
 	.previous
 
@@ -58,10 +58,7 @@
 	.ent __copy_user
 				# Pipeline info: Slotting & Comments
 __copy_user:
-	ldgp $29,0($27)		# we do exceptions -- we need the gp.
-				# Macro instruction becomes ldah/lda
-				# .. .. E  E
-	.prologue 1
+	.prologue 0
 	subq $0, 32, $1		# .. E  .. ..	: Is this going to be a small copy?
 	beq $0, $zerolength	# U  .. .. ..	: U L U L
 
diff -Nru a/arch/alpha/lib/ev6-strncpy_from_user.S b/arch/alpha/lib/ev6-strncpy_from_user.S
--- a/arch/alpha/lib/ev6-strncpy_from_user.S	Mon Dec 23 21:22:01 2002
+++ b/arch/alpha/lib/ev6-strncpy_from_user.S	Mon Dec 23 21:22:01 2002
@@ -34,7 +34,7 @@
 #define EX(x,y...)			\
 	99: x,##y;			\
 	.section __ex_table,"a";	\
-	.gprel32 99b;			\
+	.long 99b - .;			\
 	lda $31, $exception-99b($0); 	\
 	.previous
 
@@ -46,11 +46,10 @@
 	.globl __strncpy_from_user
 	.ent __strncpy_from_user
 	.frame $30, 0, $26
-	.prologue 1
+	.prologue 0
 
 	.align 4
 __strncpy_from_user:
-	ldgp	$29, 0($27)	# E E : becomes 2 instructions (for exceptions)
 	and	a0, 7, t3	# E : find dest misalignment
 	beq	a2, $zerolength	# U :
 
diff -Nru a/arch/alpha/lib/ev67-strlen_user.S b/arch/alpha/lib/ev67-strlen_user.S
--- a/arch/alpha/lib/ev67-strlen_user.S	Mon Dec 23 21:21:54 2002
+++ b/arch/alpha/lib/ev67-strlen_user.S	Mon Dec 23 21:21:54 2002
@@ -30,7 +30,7 @@
 #define EX(x,y...)			\
 	99: x,##y;			\
 	.section __ex_table,"a";	\
-	.gprel32 99b;			\
+	.long 99b - .;			\
 	lda v0, $exception-99b(zero);	\
 	.previous
 
@@ -56,9 +56,7 @@
 
 	.align 4
 __strnlen_user:
-	ldgp	$29,0($27)	# E E : we do exceptions -- we need the gp.
-				/* Decomposes into lda/ldah */
-	.prologue 1
+	.prologue 0
 	EX( ldq_u t0, 0(a0) )	# L : load first quadword (a0 may be misaligned)
 	lda     t1, -1(zero)	# E :
 
diff -Nru a/arch/alpha/lib/strlen_user.S b/arch/alpha/lib/strlen_user.S
--- a/arch/alpha/lib/strlen_user.S	Mon Dec 23 21:21:55 2002
+++ b/arch/alpha/lib/strlen_user.S	Mon Dec 23 21:21:55 2002
@@ -19,7 +19,7 @@
 #define EX(x,y...)			\
 	99: x,##y;			\
 	.section __ex_table,"a";	\
-	.gprel32 99b;			\
+	.long 99b - .;			\
 	lda v0, $exception-99b(zero);	\
 	.previous
 
@@ -42,8 +42,7 @@
 
 	.align 3
 __strnlen_user:
-	ldgp	$29,0($27)	# we do exceptions -- we need the gp.
-	.prologue 1
+	.prologue 0
 
 	EX( ldq_u t0, 0(a0) )	# load first quadword (a0 may be misaligned)
 	lda     t1, -1(zero)
diff -Nru a/arch/alpha/lib/strncpy_from_user.S b/arch/alpha/lib/strncpy_from_user.S
--- a/arch/alpha/lib/strncpy_from_user.S	Mon Dec 23 21:21:51 2002
+++ b/arch/alpha/lib/strncpy_from_user.S	Mon Dec 23 21:21:51 2002
@@ -19,7 +19,7 @@
 #define EX(x,y...)			\
 	99: x,##y;			\
 	.section __ex_table,"a";	\
-	.gprel32 99b;			\
+	.long 99b - .;			\
 	lda $31, $exception-99b($0); 	\
 	.previous
 
@@ -31,7 +31,7 @@
 	.globl __strncpy_from_user
 	.ent __strncpy_from_user
 	.frame $30, 0, $26
-	.prologue 1
+	.prologue 0
 
 	.align 3
 $aligned:
@@ -100,8 +100,6 @@
 	/*** The Function Entry Point ***/
 	.align 3
 __strncpy_from_user:
-	ldgp	$29, 0($27)	# we do exceptions -- we need the gp.
-
 	mov	a0, v0		# save the string start
 	beq	a2, $zerolength
 
diff -Nru a/arch/alpha/mm/extable.c b/arch/alpha/mm/extable.c
--- a/arch/alpha/mm/extable.c	Mon Dec 23 21:21:51 2002
+++ b/arch/alpha/mm/extable.c	Mon Dec 23 21:21:51 2002
@@ -12,21 +12,17 @@
 static inline unsigned
 search_one_table(const struct exception_table_entry *first,
 		 const struct exception_table_entry *last,
-		 signed long value)
+		 unsigned long value)
 {
-	/* Abort early if the search value is out of range.  */
-	if (value != (signed int)value)
-		return 0;
-
         while (first <= last) {
 		const struct exception_table_entry *mid;
-		long diff;
+		unsigned long mid_value;
 
 		mid = (last - first) / 2 + first;
-		diff = mid->insn - value;
-                if (diff == 0)
+		mid_value = (unsigned long)&mid->insn + mid->insn;
+                if (mid_value == value)
                         return mid->fixup.unit;
-                else if (diff < 0)
+                else if (mid_value < value)
                         first = mid+1;
                 else
                         last = mid-1;
@@ -34,48 +30,13 @@
         return 0;
 }
 
-register unsigned long gp __asm__("$29");
-
-static unsigned
-search_exception_table_without_gp(unsigned long addr)
-{
-	unsigned ret;
-
-#ifndef CONFIG_MODULES
-	/* There is only the kernel to search.  */
-	ret = search_one_table(__start___ex_table, __stop___ex_table - 1,
-			       addr - gp);
-#else
-	extern spinlock_t modlist_lock;
-	unsigned long flags;
-	/* The kernel is the last "module" -- no need to treat it special. */
-	struct module *mp;
-
-	ret = 0;
-	spin_lock_irqsave(&modlist_lock, flags);
-	for (mp = module_list; mp ; mp = mp->next) {
-		if (!mp->ex_table_start || !(mp->flags&(MOD_RUNNING|MOD_INITIALIZING)))
-			continue;
-		ret = search_one_table(mp->ex_table_start,
-				       mp->ex_table_end - 1, addr - mp->gp);
-		if (ret)
-			break;
-	}
-	spin_unlock_irqrestore(&modlist_lock, flags);
-#endif
-
-	return ret;
-}
-
 unsigned
-search_exception_table(unsigned long addr, unsigned long exc_gp)
+search_exception_table(unsigned long addr)
 {
 	unsigned ret;
 
 #ifndef CONFIG_MODULES
-	ret = search_one_table(__start___ex_table, __stop___ex_table - 1,
-			       addr - exc_gp);
-	if (ret) return ret;
+	ret = search_one_table(__start___ex_table, __stop___ex_table-1, addr);
 #else
 	extern spinlock_t modlist_lock;
 	unsigned long flags;
@@ -88,25 +49,12 @@
 		if (!mp->ex_table_start || !(mp->flags&(MOD_RUNNING|MOD_INITIALIZING)))
 			continue;
 		ret = search_one_table(mp->ex_table_start,
-				       mp->ex_table_end - 1, addr - exc_gp);
+				       mp->ex_table_end - 1, addr);
 		if (ret)
 			break;
 	}
 	spin_unlock_irqrestore(&modlist_lock, flags);
-	if (ret) return ret;
 #endif
 
-	/*
-	 * The search failed with the exception gp. To be safe, try the
-	 * old method before giving up.
-	 */
-	ret = search_exception_table_without_gp(addr);
-	if (ret) {
-		printk(KERN_ALERT "%s: [%lx] EX_TABLE search fail with"
-		       "exc frame GP, success with raw GP\n",
-		       current->comm, addr);
-		return ret;
-	}
-
-	return 0;
+	return ret;
 }
diff -Nru a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
--- a/arch/alpha/mm/fault.c	Mon Dec 23 21:21:52 2002
+++ b/arch/alpha/mm/fault.c	Mon Dec 23 21:21:52 2002
@@ -176,7 +176,7 @@
 
  no_context:
 	/* Are we prepared to handle this fault as an exception?  */
-	if ((fixup = search_exception_table(regs->pc, regs->gp)) != 0) {
+	if ((fixup = search_exception_table(regs->pc)) != 0) {
 		unsigned long newpc;
 		newpc = fixup_exception(dpf_reg, fixup, regs->pc);
 		regs->pc = newpc;
diff -Nru a/arch/alpha/vmlinux.lds.S b/arch/alpha/vmlinux.lds.S
--- a/arch/alpha/vmlinux.lds.S	Mon Dec 23 21:21:55 2002
+++ b/arch/alpha/vmlinux.lds.S	Mon Dec 23 21:21:55 2002
@@ -55,6 +55,12 @@
 	__setup_end = .;
   }
 
+  __param ALIGN(8): {
+	__start___param = .;
+	*(__param)
+	__stop___param = .;
+  }
+
   .initcall.init ALIGN(8): {
 	__initcall_start = .;
 	*(.initcall1.init) 
diff -Nru a/arch/i386/Kconfig b/arch/i386/Kconfig
--- a/arch/i386/Kconfig	Mon Dec 23 21:21:51 2002
+++ b/arch/i386/Kconfig	Mon Dec 23 21:21:51 2002
@@ -1553,7 +1553,6 @@
 
 config KALLSYMS
 	bool "Load all symbols for debugging/kksymoops"
-	depends on DEBUG_KERNEL
 	help
 	  Say Y here to let the kernel print out symbolic crash information and
 	  symbolic stack backtraces. This increases the size of the kernel
diff -Nru a/arch/i386/Makefile b/arch/i386/Makefile
--- a/arch/i386/Makefile	Mon Dec 23 21:21:53 2002
+++ b/arch/i386/Makefile	Mon Dec 23 21:21:53 2002
@@ -42,29 +42,41 @@
 cflags-$(CONFIG_MWINCHIPC6)	+= $(call check_gcc,-march=winchip-c6,-march=i586)
 cflags-$(CONFIG_MWINCHIP2)	+= $(call check_gcc,-march=winchip2,-march=i586)
 cflags-$(CONFIG_MWINCHIP3D)	+= -march=i586
-cflags-$(CONFIG_MCYRIXIII)	+= $(call check_gcc,-march=c3,-march=i486) -malign-functions=0 -malign-jumps=0 -malign-loops=0
+cflags-$(CONFIG_MCYRIXIII)	+= $(call check_gcc,-march=c3,-march=i486)
+# The alignment flags change with gcc 3.2
+cflags-$(CONFIG_MCYRIXIII)	+= $(call check_gcc,-falign-functions=0 -falign-jumps=0 -falign-loops=0,-malign-functions=0 -malign-jumps=0 -malign-loops=0)
 
 CFLAGS += $(cflags-y)
 
-ifdef CONFIG_VISWS
-MACHINE	:= mach-visws
-else
-MACHINE	:= mach-generic
-endif
+#default subarch .c files
+mcore-y  := mach-default
+
+#VISWS subarch support
+mflags-$(CONFIG_VISWS) := -Iinclude/asm-i386/mach-visws
+mcore-$(CONFIG_VISWS)  := mach-visws
+
+#NUMAQ subarch support
+mflags-$(CONFIG_X86_NUMAQ) := -Iinclude/asm-i386/mach-numaq
+mcore-$(CONFIG_X86_NUMAQ)  := mach-default
+
+#add other subarch support here
+
+#default subarch .h files
+mflags-y += -Iinclude/asm-i386/mach-default
 
 HEAD := arch/i386/kernel/head.o arch/i386/kernel/init_task.o
 
 libs-y 					+= arch/i386/lib/
 core-y					+= arch/i386/kernel/ \
 					   arch/i386/mm/ \
-					   arch/i386/$(MACHINE)/
+					   arch/i386/$(mcore-y)/
 drivers-$(CONFIG_MATH_EMULATION)	+= arch/i386/math-emu/
 drivers-$(CONFIG_PCI)			+= arch/i386/pci/
 # FIXME: is drivers- right ?
 drivers-$(CONFIG_OPROFILE)		+= arch/i386/oprofile/
 
-CFLAGS += -Iarch/i386/$(MACHINE)
-AFLAGS += -Iarch/i386/$(MACHINE)
+CFLAGS += $(mflags-y)
+AFLAGS += $(mflags-y)
 
 makeboot =$(Q)$(MAKE) -f scripts/Makefile.build obj=arch/i386/boot $(1)
 
diff -Nru a/arch/i386/kernel/Makefile b/arch/i386/kernel/Makefile
--- a/arch/i386/kernel/Makefile	Mon Dec 23 21:21:51 2002
+++ b/arch/i386/kernel/Makefile	Mon Dec 23 21:21:51 2002
@@ -29,6 +29,7 @@
 obj-$(CONFIG_PROFILING)		+= profile.o
 obj-$(CONFIG_EDD)             	+= edd.o
 obj-$(CONFIG_MODULES)		+= module.o
+obj-y				+= sysenter.o
 
 EXTRA_AFLAGS   := -traditional
 
diff -Nru a/arch/i386/kernel/apic.c b/arch/i386/kernel/apic.c
--- a/arch/i386/kernel/apic.c	Mon Dec 23 21:22:02 2002
+++ b/arch/i386/kernel/apic.c	Mon Dec 23 21:22:02 2002
@@ -31,7 +31,8 @@
 #include <asm/pgalloc.h>
 #include <asm/desc.h>
 #include <asm/arch_hooks.h>
-#include "mach_apic.h"
+
+#include <mach_apic.h>
 
 void __init apic_intr_init(void)
 {
@@ -310,11 +311,9 @@
 		__error_in_apic_c();
 
 	/*
-	 * Double-check wether this APIC is really registered.
-	 * This is meaningless in clustered apic mode, so we skip it.
+	 * Double-check whether this APIC is really registered.
 	 */
-	if (!clustered_apic_mode && 
-	    !test_bit(GET_APIC_ID(apic_read(APIC_ID)), &phys_cpu_present_map))
+	if (!apic_id_registered())
 		BUG();
 
 	/*
@@ -322,21 +321,7 @@
 	 * an APIC.  See e.g. "AP-388 82489DX User's Manual" (Intel
 	 * document number 292116).  So here it goes...
 	 */
-
-	if (!clustered_apic_mode) {
-		/*
-		 * In clustered apic mode, the firmware does this for us 
-		 * Put the APIC into flat delivery mode.
-		 * Must be "all ones" explicitly for 82489DX.
-		 */
-		apic_write_around(APIC_DFR, APIC_DFR_VALUE);
-
-		/*
-		 * Set up the logical destination ID.
-		 */
-		value = apic_read(APIC_LDR);
-		apic_write_around(APIC_LDR, calculate_ldr(value));
-	}
+	init_apic_ldr();
 
 	/*
 	 * Set Task Priority to 'accept all'. We never change this
diff -Nru a/arch/i386/kernel/bootflag.c b/arch/i386/kernel/bootflag.c
--- a/arch/i386/kernel/bootflag.c	Mon Dec 23 21:21:59 2002
+++ b/arch/i386/kernel/bootflag.c	Mon Dec 23 21:21:59 2002
@@ -48,7 +48,7 @@
 	unsigned int i;
 	struct sbf_boot sb;
 	
-	memcpy_fromio(&sb, tptr, sizeof(sb));
+	memcpy_fromio(&sb, (void *)tptr, sizeof(sb));
 
 	if(sb.sbf_len != 40 && sb.sbf_len != 39)
 		// 39 on IBM ThinkPad A21m, BIOS version 1.02b (KXET24WW; 2000-12-19).
diff -Nru a/arch/i386/kernel/cpu/common.c b/arch/i386/kernel/cpu/common.c
--- a/arch/i386/kernel/cpu/common.c	Mon Dec 23 21:21:50 2002
+++ b/arch/i386/kernel/cpu/common.c	Mon Dec 23 21:21:50 2002
@@ -12,11 +12,14 @@
 
 static int cachesize_override __initdata = -1;
 static int disable_x86_fxsr __initdata = 0;
+static int disable_x86_serial_nr __initdata = 1;
 
 struct cpu_dev * cpu_devs[X86_VENDOR_NUM] = {};
 
 extern void mcheck_init(struct cpuinfo_x86 *c);
 
+extern int disable_pse;
+
 static void default_init(struct cpuinfo_x86 * c)
 {
 	/* Not much we can do here... */
@@ -249,6 +252,31 @@
 	}
 }
 
+static void __init squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
+{
+	if (cpu_has(c, X86_FEATURE_PN) && disable_x86_serial_nr ) {
+		/* Disable processor serial number */
+		unsigned long lo,hi;
+		rdmsr(MSR_IA32_BBL_CR_CTL,lo,hi);
+		lo |= 0x200000;
+		wrmsr(MSR_IA32_BBL_CR_CTL,lo,hi);
+		printk(KERN_NOTICE "CPU serial number disabled.\n");
+		clear_bit(X86_FEATURE_PN, c->x86_capability);
+
+		/* Disabling the serial number may affect the cpuid level */
+		c->cpuid_level = cpuid_eax(0);
+	}
+}
+
+static int __init x86_serial_nr_setup(char *s)
+{
+	disable_x86_serial_nr = 0;
+	return 1;
+}
+__setup("serialnumber", x86_serial_nr_setup);
+
+
+
 /*
  * This does the hard work of actually picking apart the CPU stuff...
  */
@@ -279,12 +307,6 @@
 	else
 		generic_identify(c);
 
-	printk(KERN_DEBUG "CPU: Before vendor init, caps: %08lx %08lx %08lx, vendor = %d\n",
-	       c->x86_capability[0],
-	       c->x86_capability[1],
-	       c->x86_capability[2],
-	       c->x86_vendor);
-
 	/*
 	 * Vendor-specific initialization.  In this section we
 	 * canonicalize the feature flags, meaning if there are
@@ -298,11 +320,8 @@
 	if (this_cpu->c_init)
 		this_cpu->c_init(c);
 
-	printk(KERN_DEBUG "CPU: After vendor init, caps: %08lx %08lx %08lx %08lx\n",
-	       c->x86_capability[0],
-	       c->x86_capability[1],
-	       c->x86_capability[2],
-	       c->x86_capability[3]);
+	/* Disable the PN if appropriate */
+	squash_the_stupid_serial_number(c);
 
 	/*
 	 * The vendor-specific functions might have changed features.  Now
@@ -319,6 +338,9 @@
 		clear_bit(X86_FEATURE_XMM, c->x86_capability);
 	}
 
+	if (disable_pse)
+		clear_bit(X86_FEATURE_PSE, c->x86_capability);
+
 	/* If the model name is still unset, do table lookup. */
 	if ( !c->x86_model_id[0] ) {
 		char *p;
@@ -351,12 +373,6 @@
 			boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
 	}
 
-	printk(KERN_DEBUG "CPU:             Common caps: %08lx %08lx %08lx %08lx\n",
-	       boot_cpu_data.x86_capability[0],
-	       boot_cpu_data.x86_capability[1],
-	       boot_cpu_data.x86_capability[2],
-	       boot_cpu_data.x86_capability[3]);
-
 	/* Init Machine Check Exception if available. */
 #ifdef CONFIG_X86_MCE
 	mcheck_init(c);
@@ -487,7 +503,7 @@
 		BUG();
 	enter_lazy_tlb(&init_mm, current, cpu);
 
-	t->esp0 = thread->esp0;
+	load_esp0(t, thread->esp0);
 	set_tss_desc(cpu,t);
 	cpu_gdt_table[cpu][GDT_ENTRY_TSS].b &= 0xfffffdff;
 	load_TR_desc();
diff -Nru a/arch/i386/kernel/cpu/intel.c b/arch/i386/kernel/cpu/intel.c
--- a/arch/i386/kernel/cpu/intel.c	Mon Dec 23 21:21:52 2002
+++ b/arch/i386/kernel/cpu/intel.c	Mon Dec 23 21:21:52 2002
@@ -11,7 +11,6 @@
 
 #include "cpu.h"
 
-static int disable_x86_serial_nr __initdata = 1;
 static int disable_P4_HT __initdata = 0;
 extern int trap_init_f00f_bug(void);
 
@@ -69,29 +68,6 @@
 	return 0;
 }
 	
-static void __init squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
-{
-	if (cpu_has(c, X86_FEATURE_PN) && disable_x86_serial_nr ) {
-		/* Disable processor serial number */
-		unsigned long lo,hi;
-		rdmsr(MSR_IA32_BBL_CR_CTL,lo,hi);
-		lo |= 0x200000;
-		wrmsr(MSR_IA32_BBL_CR_CTL,lo,hi);
-		printk(KERN_NOTICE "CPU serial number disabled.\n");
-		clear_bit(X86_FEATURE_PN, c->x86_capability);
-
-		/* Disabling the serial number may affect the cpuid level */
-		c->cpuid_level = cpuid_eax(0);
-	}
-}
-
-static int __init x86_serial_nr_setup(char *s)
-{
-	disable_x86_serial_nr = 0;
-	return 1;
-}
-__setup("serialnumber", x86_serial_nr_setup);
-
 static int __init P4_disable_ht(char *s)
 {
 	disable_P4_HT = 1;
@@ -351,9 +327,6 @@
 	if (disable_P4_HT)
 		clear_bit(X86_FEATURE_HT, c->x86_capability);
 #endif
-
-	/* Disable the PN if appropriate */
-	squash_the_stupid_serial_number(c);
 
 	/* Work around errata */
 	Intel_errata_workarounds(c);
diff -Nru a/arch/i386/kernel/cpu/mtrr/amd.c b/arch/i386/kernel/cpu/mtrr/amd.c
--- a/arch/i386/kernel/cpu/mtrr/amd.c	Mon Dec 23 21:21:55 2002
+++ b/arch/i386/kernel/cpu/mtrr/amd.c	Mon Dec 23 21:21:55 2002
@@ -7,7 +7,7 @@
 
 static void
 amd_get_mtrr(unsigned int reg, unsigned long *base,
-	     unsigned long *size, mtrr_type * type)
+	     unsigned int *size, mtrr_type * type)
 {
 	unsigned long low, high;
 
diff -Nru a/arch/i386/kernel/cpu/mtrr/centaur.c b/arch/i386/kernel/cpu/mtrr/centaur.c
--- a/arch/i386/kernel/cpu/mtrr/centaur.c	Mon Dec 23 21:21:52 2002
+++ b/arch/i386/kernel/cpu/mtrr/centaur.c	Mon Dec 23 21:21:52 2002
@@ -26,7 +26,8 @@
 {
 	int i, max;
 	mtrr_type ltype;
-	unsigned long lbase, lsize;
+	unsigned long lbase;
+	unsigned int lsize;
 
 	max = num_var_ranges;
 	for (i = 0; i < max; ++i) {
@@ -48,7 +49,7 @@
 
 static void
 centaur_get_mcr(unsigned int reg, unsigned long *base,
-		unsigned long *size, mtrr_type * type)
+		unsigned int *size, mtrr_type * type)
 {
 	*base = centaur_mcr[reg].high >> PAGE_SHIFT;
 	*size = -(centaur_mcr[reg].low & 0xfffff000) >> PAGE_SHIFT;
diff -Nru a/arch/i386/kernel/cpu/mtrr/cyrix.c b/arch/i386/kernel/cpu/mtrr/cyrix.c
--- a/arch/i386/kernel/cpu/mtrr/cyrix.c	Mon Dec 23 21:21:55 2002
+++ b/arch/i386/kernel/cpu/mtrr/cyrix.c	Mon Dec 23 21:21:55 2002
@@ -9,7 +9,7 @@
 
 static void
 cyrix_get_arr(unsigned int reg, unsigned long *base,
-	      unsigned long *size, mtrr_type * type)
+	      unsigned int *size, mtrr_type * type)
 {
 	unsigned long flags;
 	unsigned char arr, ccr3, rcr, shift;
@@ -86,7 +86,8 @@
 {
 	int i;
 	mtrr_type ltype;
-	unsigned long lbase, lsize;
+	unsigned long lbase;
+	unsigned int  lsize;
 
 	/* If we are to set up a region >32M then look at ARR7 immediately */
 	if (size > 0x2000) {
@@ -213,7 +214,7 @@
 
 typedef struct {
 	unsigned long base;
-	unsigned long size;
+	unsigned int size;
 	mtrr_type type;
 } arr_state_t;
 
diff -Nru a/arch/i386/kernel/cpu/mtrr/generic.c b/arch/i386/kernel/cpu/mtrr/generic.c
--- a/arch/i386/kernel/cpu/mtrr/generic.c	Mon Dec 23 21:21:56 2002
+++ b/arch/i386/kernel/cpu/mtrr/generic.c	Mon Dec 23 21:21:56 2002
@@ -1,3 +1,5 @@
+/* This only handles 32bit MTRR on 32bit hosts. This is strictly wrong
+   because MTRRs can span upto 40 bits (36bits on most modern x86) */ 
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/mm.h>
@@ -30,7 +32,7 @@
 static void __init
 get_fixed_ranges(mtrr_type * frs)
 {
-	unsigned long *p = (unsigned long *) frs;
+	unsigned int *p = (unsigned int *) frs;
 	int i;
 
 	rdmsr(MTRRfix64K_00000_MSR, p[0], p[1]);
@@ -46,7 +48,7 @@
 {
 	unsigned int i;
 	struct mtrr_var_range *vrs;
-	unsigned long lo, dummy;
+	unsigned lo, dummy;
 
 	if (!mtrr_state.var_ranges) {
 		mtrr_state.var_ranges = kmalloc(num_var_ranges * sizeof (struct mtrr_var_range), 
@@ -102,7 +104,8 @@
 {
 	int i, max;
 	mtrr_type ltype;
-	unsigned long lbase, lsize;
+	unsigned long lbase;
+	unsigned lsize;
 
 	max = num_var_ranges;
 	for (i = 0; i < max; ++i) {
@@ -113,11 +116,10 @@
 	return -ENOSPC;
 }
 
-
 void generic_get_mtrr(unsigned int reg, unsigned long *base,
-		      unsigned long *size, mtrr_type * type)
+		      unsigned int *size, mtrr_type * type)
 {
-	unsigned long mask_lo, mask_hi, base_lo, base_hi;
+	unsigned int mask_lo, mask_hi, base_lo, base_hi;
 
 	rdmsr(MTRRphysMask_MSR(reg), mask_lo, mask_hi);
 	if ((mask_lo & 0x800) == 0) {
@@ -143,10 +145,10 @@
 
 static int __init set_fixed_ranges(mtrr_type * frs)
 {
-	unsigned long *p = (unsigned long *) frs;
+	unsigned int *p = (unsigned int *) frs;
 	int changed = FALSE;
 	int i;
-	unsigned long lo, hi;
+	unsigned int lo, hi;
 
 	rdmsr(MTRRfix64K_00000_MSR, lo, hi);
 	if (p[0] != lo || p[1] != hi) {
@@ -228,13 +230,13 @@
 }
 
 
-static u32 cr4 = 0;
+static unsigned long cr4 = 0;
 static u32 deftype_lo, deftype_hi;
 static spinlock_t set_atomicity_lock = SPIN_LOCK_UNLOCKED;
 
 static void prepare_set(void)
 {
-	u32 cr0;
+	unsigned long cr0;
 
 	/*  Note that this is not ideal, since the cache is only flushed/disabled
 	   for this CPU while the MTRRs are changed, but changing this requires
diff -Nru a/arch/i386/kernel/cpu/mtrr/if.c b/arch/i386/kernel/cpu/mtrr/if.c
--- a/arch/i386/kernel/cpu/mtrr/if.c	Mon Dec 23 21:21:52 2002
+++ b/arch/i386/kernel/cpu/mtrr/if.c	Mon Dec 23 21:21:52 2002
@@ -3,45 +3,39 @@
 #include <linux/devfs_fs_kernel.h>
 #include <linux/ctype.h>
 #include <linux/module.h>
+#include <linux/seq_file.h>
 #include <asm/uaccess.h>
 
-/* What kind of fucking hack is this? */
-#define MTRR_NEED_STRINGS
+#define LINE_SIZE 80
 
 #include <asm/mtrr.h>
 #include "mtrr.h"
 
-static char *ascii_buffer;
-static unsigned int ascii_buf_bytes;
-
+/* RED-PEN: this is accessed without any locking */
 extern unsigned int *usage_table;
 
-#define LINE_SIZE      80
+static int mtrr_seq_show(struct seq_file *seq, void *offset);
+
+#define FILE_FCOUNT(f) (((struct seq_file *)((f)->private_data))->private)
 
 static int
 mtrr_file_add(unsigned long base, unsigned long size,
 	      unsigned int type, char increment, struct file *file, int page)
 {
 	int reg, max;
-	unsigned int *fcount = file->private_data;
+	unsigned int *fcount = FILE_FCOUNT(file); 
 
 	max = num_var_ranges;
 	if (fcount == NULL) {
-		if ((fcount =
-		     kmalloc(max * sizeof *fcount, GFP_KERNEL)) == NULL) {
-			printk("mtrr: could not allocate\n");
+		fcount = kmalloc(max * sizeof *fcount, GFP_KERNEL);
+		if (!fcount)
 			return -ENOMEM;
-		}
 		memset(fcount, 0, max * sizeof *fcount);
-		file->private_data = fcount;
+		FILE_FCOUNT(file) = fcount;
 	}
 	if (!page) {
-		if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1))) {
-			printk
-			    ("mtrr: size and base must be multiples of 4 kiB\n");
-			printk("mtrr: size: 0x%lx  base: 0x%lx\n", size, base);
+		if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1)))
 			return -EINVAL;
-		}
 		base >>= PAGE_SHIFT;
 		size >>= PAGE_SHIFT;
 	}
@@ -59,12 +53,8 @@
 	unsigned int *fcount = file->private_data;
 
 	if (!page) {
-		if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1))) {
-			printk
-			    ("mtrr: size and base must be multiples of 4 kiB\n");
-			printk("mtrr: size: 0x%lx  base: 0x%lx\n", size, base);
+		if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1)))
 			return -EINVAL;
-		}
 		base >>= PAGE_SHIFT;
 		size >>= PAGE_SHIFT;
 	}
@@ -79,19 +69,7 @@
 	return reg;
 }
 
-static ssize_t
-mtrr_read(struct file *file, char *buf, size_t len, loff_t * ppos)
-{
-	if (*ppos >= ascii_buf_bytes)
-		return 0;
-	if (*ppos + len > ascii_buf_bytes)
-		len = ascii_buf_bytes - *ppos;
-	if (copy_to_user(buf, ascii_buffer + *ppos, len))
-		return -EFAULT;
-	*ppos += len;
-	return len;
-}
-
+/* RED-PEN: seq_file can seek now. this is ignored. */
 static ssize_t
 mtrr_write(struct file *file, const char *buf, size_t len, loff_t * ppos)
 /*  Format of control line:
@@ -125,31 +103,22 @@
 			return err;
 		return len;
 	}
-	if (strncmp(line, "base=", 5)) {
-		printk("mtrr: no \"base=\" in line: \"%s\"\n", line);
+	if (strncmp(line, "base=", 5))
 		return -EINVAL;
-	}
 	base = simple_strtoull(line + 5, &ptr, 0);
 	for (; isspace(*ptr); ++ptr) ;
-	if (strncmp(ptr, "size=", 5)) {
-		printk("mtrr: no \"size=\" in line: \"%s\"\n", line);
+	if (strncmp(ptr, "size=", 5))
 		return -EINVAL;
-	}
 	size = simple_strtoull(ptr + 5, &ptr, 0);
-	if ((base & 0xfff) || (size & 0xfff)) {
-		printk("mtrr: size and base must be multiples of 4 kiB\n");
-		printk("mtrr: size: 0x%Lx  base: 0x%Lx\n", size, base);
+	if ((base & 0xfff) || (size & 0xfff))
 		return -EINVAL;
-	}
 	for (; isspace(*ptr); ++ptr) ;
-	if (strncmp(ptr, "type=", 5)) {
-		printk("mtrr: no \"type=\" in line: \"%s\"\n", line);
+	if (strncmp(ptr, "type=", 5))
 		return -EINVAL;
-	}
 	ptr += 5;
 	for (; isspace(*ptr); ++ptr) ;
 	for (i = 0; i < MTRR_NUM_TYPES; ++i) {
-//		if (strcmp(ptr, mtrr_strings[i]))
+		if (strcmp(ptr, mtrr_strings[i]))
 			continue;
 		base >>= PAGE_SHIFT;
 		size >>= PAGE_SHIFT;
@@ -160,7 +129,6 @@
 			return err;
 		return len;
 	}
-	printk("mtrr: illegal type: \"%s\"\n", ptr);
 	return -EINVAL;
 }
 
@@ -291,26 +259,36 @@
 mtrr_close(struct inode *ino, struct file *file)
 {
 	int i, max;
-	unsigned int *fcount = file->private_data;
+	unsigned int *fcount = FILE_FCOUNT(file);
 
-	if (fcount == NULL)
-		return 0;
-	max = num_var_ranges;
-	for (i = 0; i < max; ++i) {
-		while (fcount[i] > 0) {
-			if (mtrr_del(i, 0, 0) < 0)
-				printk("mtrr: reg %d not used\n", i);
-			--fcount[i];
+	if (fcount != NULL) {
+		max = num_var_ranges;
+		for (i = 0; i < max; ++i) {
+			while (fcount[i] > 0) {
+				mtrr_del(i, 0, 0);
+				--fcount[i];
+			}
 		}
+		kfree(fcount);
+		FILE_FCOUNT(file) = NULL;
 	}
-	kfree(fcount);
-	file->private_data = NULL;
-	return 0;
+	return single_release(ino, file);
+}
+
+static int mtrr_open(struct inode *inode, struct file *file)
+{
+	if (!mtrr_if) 
+		return -EIO;
+	if (!mtrr_if->get) 
+		return -ENXIO; 
+	return single_open(file, mtrr_seq_show, NULL);
 }
 
 static struct file_operations mtrr_fops = {
 	.owner   = THIS_MODULE,
-	.read    = mtrr_read,
+	.open	 = mtrr_open, 
+	.read    = seq_read,
+	.llseek  = seq_lseek,
 	.write   = mtrr_write,
 	.ioctl   = mtrr_ioctl,
 	.release = mtrr_close,
@@ -329,14 +307,15 @@
 	return (x <= 6) ? mtrr_strings[x] : "?";
 }
 
-void compute_ascii(void)
+static int mtrr_seq_show(struct seq_file *seq, void *offset)
 {
 	char factor;
-	int i, max;
+	int i, max, len;
 	mtrr_type type;
-	unsigned long base, size;
+	unsigned long base;
+	unsigned int size;
 
-	ascii_buf_bytes = 0;
+	len = 0;
 	max = num_var_ranges;
 	for (i = 0; i < max; i++) {
 		mtrr_if->get(i, &base, &size, &type);
@@ -351,32 +330,19 @@
 				factor = 'M';
 				size >>= 20 - PAGE_SHIFT;
 			}
-			sprintf
-			    (ascii_buffer + ascii_buf_bytes,
-			     "reg%02i: base=0x%05lx000 (%4liMB), size=%4li%cB: %s, count=%d\n",
+			/* RED-PEN: base can be > 32bit */ 
+			len += seq_printf(seq, 
+				   "reg%02i: base=0x%05lx000 (%4liMB), size=%4i%cB: %s, count=%d\n",
 			     i, base, base >> (20 - PAGE_SHIFT), size, factor,
 			     attrib_to_str(type), usage_table[i]);
-			ascii_buf_bytes +=
-			    strlen(ascii_buffer + ascii_buf_bytes);
 		}
 	}
-	devfs_set_file_size(devfs_handle, ascii_buf_bytes);
-#  ifdef CONFIG_PROC_FS
-	if (proc_root_mtrr)
-		proc_root_mtrr->size = ascii_buf_bytes;
-#  endif			/*  CONFIG_PROC_FS  */
+	devfs_set_file_size(devfs_handle, len);	
+	return 0;
 }
 
 static int __init mtrr_if_init(void)
 {
-	int max = num_var_ranges;
-
-	if ((ascii_buffer = kmalloc(max * LINE_SIZE, GFP_KERNEL)) == NULL) {
-		printk("mtrr: could not allocate\n");
-		return -ENOMEM;
-	}
-	ascii_buf_bytes = 0;
-	compute_ascii();
 #ifdef CONFIG_PROC_FS
 	proc_root_mtrr =
 	    create_proc_entry("mtrr", S_IWUSR | S_IRUGO, &proc_root);
diff -Nru a/arch/i386/kernel/cpu/mtrr/main.c b/arch/i386/kernel/cpu/mtrr/main.c
--- a/arch/i386/kernel/cpu/mtrr/main.c	Mon Dec 23 21:21:50 2002
+++ b/arch/i386/kernel/cpu/mtrr/main.c	Mon Dec 23 21:21:50 2002
@@ -36,7 +36,6 @@
 #include <linux/pci.h>
 #include <linux/smp.h>
 
-#define MTRR_NEED_STRINGS
 #include <asm/mtrr.h>
 
 #include <asm/uaccess.h>
@@ -54,6 +53,7 @@
 u32 size_or_mask, size_and_mask;
 
 static struct mtrr_ops * mtrr_ops[X86_VENDOR_NUM] = {};
+
 struct mtrr_ops * mtrr_if = NULL;
 
 __initdata char *mtrr_if_name[] = {
@@ -125,14 +125,6 @@
 	}
 	for (i = 0; i < max; i++)
 		usage_table[i] = 1;
-#ifdef USERSPACE_INTERFACE
-	if ((ascii_buffer = kmalloc(max * LINE_SIZE, GFP_KERNEL)) == NULL) {
-		printk("mtrr: could not allocate\n");
-		return;
-	}
-	ascii_buf_bytes = 0;
-	compute_ascii();
-#endif
 }
 
 struct set_mtrr_data {
@@ -163,7 +155,7 @@
 	}
 
 	/*  The master has cleared me to execute  */
-	if (data->smp_reg != ~0UL) 
+	if (data->smp_reg != ~0U) 
 		mtrr_if->set(data->smp_reg, data->smp_base, 
 			     data->smp_size, data->smp_type);
 	else
@@ -253,7 +245,7 @@
 	 * to replicate across all the APs. 
 	 * If we're doing that @reg is set to something special...
 	 */
-	if (reg != ~0UL) 
+	if (reg != ~0U) 
 		mtrr_if->set(reg,base,size,type);
 
 	/* wait for the others */
@@ -306,7 +298,8 @@
 {
 	int i;
 	mtrr_type ltype;
-	unsigned long lbase, lsize;
+	unsigned long lbase;
+	unsigned int lsize;
 	int error;
 
 	if (!mtrr_if)
@@ -346,7 +339,7 @@
 		if ((base < lbase) || (base + size > lbase + lsize)) {
 			printk(KERN_WARNING
 			       "mtrr: 0x%lx000,0x%lx000 overlaps existing"
-			       " 0x%lx000,0x%lx000\n", base, size, lbase,
+			       " 0x%lx000,0x%x000\n", base, size, lbase,
 			       lsize);
 			goto out;
 		}
@@ -361,7 +354,6 @@
 		}
 		if (increment)
 			++usage_table[i];
-		compute_ascii();
 		error = i;
 		goto out;
 	}
@@ -370,7 +362,6 @@
 	if (i >= 0) {
 		set_mtrr(i, base, size, type);
 		usage_table[i] = 1;
-		compute_ascii();
 	} else
 		printk("mtrr: no more MTRRs available\n");
 	error = i;
@@ -447,7 +438,8 @@
 {
 	int i, max;
 	mtrr_type ltype;
-	unsigned long lbase, lsize;
+	unsigned long lbase;
+	unsigned int lsize;
 	int error = -EINVAL;
 
 	if (!mtrr_if)
@@ -491,7 +483,6 @@
 	}
 	if (--usage_table[reg] < 1)
 		set_mtrr(reg, 0, 0, 0);
-	compute_ascii();
 	error = reg;
  out:
 	up(&main_lock);
@@ -547,7 +538,7 @@
 		get_mtrr_state();
 
 	/* bring up the other processors */
-	set_mtrr(~0UL,0,0,0);
+	set_mtrr(~0U,0,0,0);
 
 	if (use_intel()) {
 		finalize_mtrr_state();
@@ -583,7 +574,7 @@
 			   query the width (in bits) of the physical
 			   addressable memory on the Hammer family.
 			 */
-			if (boot_cpu_data.x86 == 7
+			if (boot_cpu_data.x86 >= 7 
 			    && (cpuid_eax(0x80000000) >= 0x80000008)) {
 				u32 phys_addr;
 				phys_addr = cpuid_eax(0x80000008) & 0xff;
@@ -642,6 +633,17 @@
 	}
 	return mtrr_if ? -ENXIO : 0;
 }
+
+char *mtrr_strings[MTRR_NUM_TYPES] =
+{
+    "uncachable",               /* 0 */
+    "write-combining",          /* 1 */
+    "?",                        /* 2 */
+    "?",                        /* 3 */
+    "write-through",            /* 4 */
+    "write-protect",            /* 5 */
+    "write-back",               /* 6 */
+};
 
 core_initcall(mtrr_init);
 
diff -Nru a/arch/i386/kernel/cpu/mtrr/mtrr.h b/arch/i386/kernel/cpu/mtrr/mtrr.h
--- a/arch/i386/kernel/cpu/mtrr/mtrr.h	Mon Dec 23 21:21:52 2002
+++ b/arch/i386/kernel/cpu/mtrr/mtrr.h	Mon Dec 23 21:21:52 2002
@@ -43,7 +43,7 @@
 	void	(*set_all)(void);
 
 	void	(*get)(unsigned int reg, unsigned long *base,
-		       unsigned long *size, mtrr_type * type);
+		       unsigned int *size, mtrr_type * type);
 	int	(*get_free_region) (unsigned long base, unsigned long size);
 
 	int	(*validate_add_page)(unsigned long base, unsigned long size,
@@ -84,9 +84,6 @@
 void get_mtrr_state(void);
 
 extern void set_mtrr_ops(struct mtrr_ops * ops);
-
-/* Don't even ask... */
-extern void compute_ascii(void);
 
 extern u32 size_or_mask, size_and_mask;
 extern struct mtrr_ops * mtrr_if;
diff -Nru a/arch/i386/kernel/entry.S b/arch/i386/kernel/entry.S
--- a/arch/i386/kernel/entry.S	Mon Dec 23 21:21:52 2002
+++ b/arch/i386/kernel/entry.S	Mon Dec 23 21:21:52 2002
@@ -47,6 +47,7 @@
 #include <asm/errno.h>
 #include <asm/segment.h>
 #include <asm/smp.h>
+#include <asm/page.h>
 #include "irq_vectors.h"
 
 EBX		= 0x00
@@ -94,7 +95,7 @@
 	movl %edx, %ds; \
 	movl %edx, %es;
 
-#define RESTORE_ALL	\
+#define RESTORE_REGS	\
 	popl %ebx;	\
 	popl %ecx;	\
 	popl %edx;	\
@@ -104,14 +105,25 @@
 	popl %eax;	\
 1:	popl %ds;	\
 2:	popl %es;	\
-	addl $4, %esp;	\
-3:	iret;		\
 .section .fixup,"ax";	\
-4:	movl $0,(%esp);	\
+3:	movl $0,(%esp);	\
 	jmp 1b;		\
-5:	movl $0,(%esp);	\
+4:	movl $0,(%esp);	\
 	jmp 2b;		\
-6:	pushl %ss;	\
+.previous;		\
+.section __ex_table,"a";\
+	.align 4;	\
+	.long 1b,3b;	\
+	.long 2b,4b;	\
+.previous
+
+
+#define RESTORE_ALL	\
+	RESTORE_REGS	\
+	addl $4, %esp;	\
+1:	iret;		\
+.section .fixup,"ax";   \
+2:	pushl %ss;	\
 	popl %ds;	\
 	pushl %ss;	\
 	popl %es;	\
@@ -120,11 +132,11 @@
 .previous;		\
 .section __ex_table,"a";\
 	.align 4;	\
-	.long 1b,4b;	\
-	.long 2b,5b;	\
-	.long 3b,6b;	\
+	.long 1b,2b;	\
 .previous
 
+
+
 ENTRY(lcall7)
 	pushfl			# We get a different stack layout with call
 				# gates, which has to be cleaned up later..
@@ -219,6 +231,52 @@
 	cli
 	jmp need_resched
 #endif
+
+/* Points to after the "sysenter" instruction in the vsyscall page */
+#define SYSENTER_RETURN 0xffffe010
+
+	# sysenter call handler stub
+	ALIGN
+ENTRY(sysenter_entry)
+	sti
+	pushl $(__USER_DS)
+	pushl %ebp
+	pushfl
+	pushl $(__USER_CS)
+	pushl $SYSENTER_RETURN
+
+/*
+ * Load the potential sixth argument from user stack.
+ * Careful about security.
+ */
+	cmpl $__PAGE_OFFSET-3,%ebp
+	jae syscall_badsys
+1:	movl (%ebp),%ebp
+.section __ex_table,"a"
+	.align 4
+	.long 1b,syscall_badsys
+.previous
+
+	pushl %eax
+	SAVE_ALL
+	GET_THREAD_INFO(%ebx)
+	cmpl $(NR_syscalls), %eax
+	jae syscall_badsys
+
+	testb $_TIF_SYSCALL_TRACE,TI_FLAGS(%ebx)
+	jnz syscall_trace_entry
+	call *sys_call_table(,%eax,4)
+	movl %eax,EAX(%esp)
+	cli
+	movl TI_FLAGS(%ebx), %ecx
+	testw $_TIF_ALLWORK_MASK, %cx
+	jne syscall_exit_work
+	RESTORE_REGS
+	movl 4(%esp),%edx
+	movl 16(%esp),%ecx
+	sti
+	sysexit
+
 
 	# system call handler stub
 	ALIGN
diff -Nru a/arch/i386/kernel/head.S b/arch/i386/kernel/head.S
--- a/arch/i386/kernel/head.S	Mon Dec 23 21:21:51 2002
+++ b/arch/i386/kernel/head.S	Mon Dec 23 21:21:51 2002
@@ -23,10 +23,10 @@
 #define NEW_CL_POINTER		0x228	/* Relative to real mode data */
 
 /*
- * References to members of the boot_cpu_data structure.
+ * References to members of the new_cpu_data structure.
  */
 
-#define CPU_PARAMS	boot_cpu_data
+#define CPU_PARAMS	new_cpu_data
 #define X86		CPU_PARAMS+0
 #define X86_VENDOR	CPU_PARAMS+1
 #define X86_MODEL	CPU_PARAMS+2
@@ -414,8 +414,8 @@
 	.quad 0x0000000000000000	/* 0x0b reserved */
 	.quad 0x0000000000000000	/* 0x13 reserved */
 	.quad 0x0000000000000000	/* 0x1b reserved */
-	.quad 0x00cffa000000ffff	/* 0x23 user 4GB code at 0x00000000 */
-	.quad 0x00cff2000000ffff	/* 0x2b user 4GB data at 0x00000000 */
+	.quad 0x0000000000000000	/* 0x20 unused */
+	.quad 0x0000000000000000	/* 0x28 unused */
 	.quad 0x0000000000000000	/* 0x33 TLS entry 1 */
 	.quad 0x0000000000000000	/* 0x3b TLS entry 2 */
 	.quad 0x0000000000000000	/* 0x43 TLS entry 3 */
@@ -425,22 +425,25 @@
 
 	.quad 0x00cf9a000000ffff	/* 0x60 kernel 4GB code at 0x00000000 */
 	.quad 0x00cf92000000ffff	/* 0x68 kernel 4GB data at 0x00000000 */
-	.quad 0x0000000000000000	/* 0x70 TSS descriptor */
-	.quad 0x0000000000000000	/* 0x78 LDT descriptor */
+	.quad 0x00cffa000000ffff	/* 0x73 user 4GB code at 0x00000000 */
+	.quad 0x00cff2000000ffff	/* 0x7b user 4GB data at 0x00000000 */
+
+	.quad 0x0000000000000000	/* 0x80 TSS descriptor */
+	.quad 0x0000000000000000	/* 0x88 LDT descriptor */
 
 	/* Segments used for calling PnP BIOS */
-	.quad 0x00c09a0000000000	/* 0x80 32-bit code */
-	.quad 0x00809a0000000000	/* 0x88 16-bit code */
-	.quad 0x0080920000000000	/* 0x90 16-bit data */
-	.quad 0x0080920000000000	/* 0x98 16-bit data */
+	.quad 0x00c09a0000000000	/* 0x90 32-bit code */
+	.quad 0x00809a0000000000	/* 0x98 16-bit code */
 	.quad 0x0080920000000000	/* 0xa0 16-bit data */
+	.quad 0x0080920000000000	/* 0xa8 16-bit data */
+	.quad 0x0080920000000000	/* 0xb0 16-bit data */
 	/*
 	 * The APM segments have byte granularity and their bases
 	 * and limits are set at run time.
 	 */
-	.quad 0x00409a0000000000	/* 0xa8 APM CS    code */
-	.quad 0x00009a0000000000	/* 0xb0 APM CS 16 code (16 bit) */
-	.quad 0x0040920000000000	/* 0xb8 APM DS    data */
+	.quad 0x00409a0000000000	/* 0xb8 APM CS    code */
+	.quad 0x00009a0000000000	/* 0xc0 APM CS 16 code (16 bit) */
+	.quad 0x0040920000000000	/* 0xc8 APM DS    data */
 
 #if CONFIG_SMP
 	.fill (NR_CPUS-1)*GDT_ENTRIES,8,0 /* other CPU's GDT */
diff -Nru a/arch/i386/kernel/i386_ksyms.c b/arch/i386/kernel/i386_ksyms.c
--- a/arch/i386/kernel/i386_ksyms.c	Mon Dec 23 21:22:02 2002
+++ b/arch/i386/kernel/i386_ksyms.c	Mon Dec 23 21:22:02 2002
@@ -124,8 +124,8 @@
 EXPORT_SYMBOL(__copy_to_user);
 EXPORT_SYMBOL(strnlen_user);
 
-EXPORT_SYMBOL(pci_alloc_consistent);
-EXPORT_SYMBOL(pci_free_consistent);
+EXPORT_SYMBOL(dma_alloc_coherent);
+EXPORT_SYMBOL(dma_free_coherent);
 
 #ifdef CONFIG_PCI
 EXPORT_SYMBOL(pcibios_penalize_isa_irq);
diff -Nru a/arch/i386/kernel/io_apic.c b/arch/i386/kernel/io_apic.c
--- a/arch/i386/kernel/io_apic.c	Mon Dec 23 21:21:53 2002
+++ b/arch/i386/kernel/io_apic.c	Mon Dec 23 21:21:53 2002
@@ -35,7 +35,8 @@
 #include <asm/io.h>
 #include <asm/smp.h>
 #include <asm/desc.h>
-#include "mach_apic.h"
+
+#include <mach_apic.h>
 
 #undef APIC_LOCKUP_DEBUG
 
@@ -261,7 +262,7 @@
 	irq_balance_t *entry = irq_balance + irq;
 	unsigned long now = jiffies;
 
-	if (clustered_apic_mode)
+	if (no_balance_irq)
 		return;
 
 	if (unlikely(time_after(now, entry->timestamp + IRQ_BALANCE_INTERVAL))) {
@@ -739,7 +740,6 @@
 		if (irq_trigger(idx)) {
 			entry.trigger = 1;
 			entry.mask = 1;
-			entry.dest.logical.logical_dest = TARGET_CPUS;
 		}
 
 		irq = pin_2_irq(idx, apic, pin);
@@ -747,7 +747,7 @@
 		 * skip adding the timer int on secondary nodes, which causes
 		 * a small but painful rift in the time-space continuum
 		 */
-		if (clustered_apic_mode && (apic != 0) && (irq == 0))
+		if (multi_timer_check(apic, irq))
 			continue;
 		else
 			add_pin_to_irq(irq, apic, pin);
@@ -1135,7 +1135,7 @@
 static void __init setup_ioapic_ids_from_mpc (void)
 {
 	struct IO_APIC_reg_00 reg_00;
-	unsigned long phys_id_present_map = phys_cpu_present_map;
+	unsigned long phys_id_present_map;
 	int apic;
 	int i;
 	unsigned char old_id;
@@ -1145,9 +1145,8 @@
 		/* This gets done during IOAPIC enumeration for ACPI. */
 		return;
 
-	if (clustered_apic_mode)
-		/* We don't have a good way to do this yet - hack */
-		phys_id_present_map = (u_long) 0xf;
+	phys_id_present_map = ioapic_phys_id_map(phys_cpu_present_map);
+
 	/*
 	 * Set the IOAPIC ID to the value stored in the MPC table.
 	 */
diff -Nru a/arch/i386/kernel/mpparse.c b/arch/i386/kernel/mpparse.c
--- a/arch/i386/kernel/mpparse.c	Mon Dec 23 21:21:52 2002
+++ b/arch/i386/kernel/mpparse.c	Mon Dec 23 21:21:52 2002
@@ -30,7 +30,9 @@
 #include <asm/mpspec.h>
 #include <asm/pgalloc.h>
 #include <asm/io_apic.h>
-#include "mach_apic.h"
+
+#include <mach_apic.h>
+#include <mach_mpparse.h>
 
 /* Have we found an MP table */
 int smp_found_config;
@@ -103,28 +105,12 @@
 
 void __init MP_processor_info (struct mpc_config_processor *m)
 {
- 	int ver, quad, logical_apicid;
+ 	int ver, apicid;
  	
 	if (!(m->mpc_cpuflag & CPU_ENABLED))
 		return;
 
-	logical_apicid = m->mpc_apicid;
-	if (clustered_apic_mode) {
-		quad = translation_table[mpc_record]->trans_quad;
-		logical_apicid = (quad << 4) + 
-			(m->mpc_apicid ? m->mpc_apicid << 1 : 1);
-		printk("Processor #%d %ld:%ld APIC version %d (quad %d, apic %d)\n",
-			m->mpc_apicid,
-		        (m->mpc_cpufeature & CPU_FAMILY_MASK)>>8,
-			(m->mpc_cpufeature & CPU_MODEL_MASK)>>4,
-			m->mpc_apicver, quad, logical_apicid);
-	} else {
-		printk("Processor #%d %ld:%ld APIC version %d\n",
-			m->mpc_apicid,
-			(m->mpc_cpufeature & CPU_FAMILY_MASK)>>8,
-			(m->mpc_cpufeature & CPU_MODEL_MASK)>>4,
-			m->mpc_apicver);
-	}
+	apicid = mpc_apic_id(m, translation_table[mpc_record]->trans_quad);
 
 	if (m->mpc_featureflag&(1<<0))
 		Dprintk("    Floating point unit present.\n");
@@ -177,7 +163,7 @@
 	if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
 		Dprintk("    Bootup CPU\n");
 		boot_cpu_physical_apicid = m->mpc_apicid;
-		boot_cpu_logical_apicid = logical_apicid;
+		boot_cpu_logical_apicid = apicid;
 	}
 
 	num_processors++;
@@ -190,11 +176,8 @@
 	}
 	ver = m->mpc_apicver;
 
-	if (clustered_apic_mode) {
-		phys_cpu_present_map |= (logical_apicid&0xf) << (4*quad);
-	} else {
-		phys_cpu_present_map |= apicid_to_cpu_present(m->mpc_apicid);
-	}
+	phys_cpu_present_map |= apicid_to_cpu_present(apicid);
+	
 	/*
 	 * Validate version
 	 */
@@ -209,28 +192,18 @@
 static void __init MP_bus_info (struct mpc_config_bus *m)
 {
 	char str[7];
-	int quad;
 
 	memcpy(str, m->mpc_bustype, 6);
 	str[6] = 0;
-	
-	if (clustered_apic_mode) {
-		quad = translation_table[mpc_record]->trans_quad;
-		mp_bus_id_to_node[m->mpc_busid] = quad;
-		mp_bus_id_to_local[m->mpc_busid] = translation_table[mpc_record]->trans_local;
-		printk("Bus #%d is %s (node %d)\n", m->mpc_busid, str, quad);
-	} else {
-		Dprintk("Bus #%d is %s\n", m->mpc_busid, str);
-	}
+
+	mpc_oem_bus_info(m, str, translation_table[mpc_record]);
 
 	if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA)-1) == 0) {
 		mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
 	} else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA)-1) == 0) {
 		mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
 	} else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI)-1) == 0) {
-		if (clustered_apic_mode){
-			quad_local_to_mp_bus_id[quad][translation_table[mpc_record]->trans_local] = m->mpc_busid;
-		}
+		mpc_oem_pci_bus(m, translation_table[mpc_record]);
 		mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
 		mp_bus_id_to_pci_bus[m->mpc_busid] = mp_current_pci_id;
 		mp_current_pci_id++;
@@ -318,6 +291,7 @@
 	int count = sizeof (*oemtable); /* the header size */
 	unsigned char *oemptr = ((unsigned char *)oemtable)+count;
 	
+	mpc_record = 0;
 	printk("Found an OEM MPC table at %8p - parsing it ... \n", oemtable);
 	if (memcmp(oemtable->oem_signature,MPC_OEM_SIGNATURE,4))
 	{
@@ -394,7 +368,7 @@
 	str[12]=0;
 	printk("Product ID: %s ",str);
 
-	summit_check(oem, str);
+	mps_oem_check(mpc, oem, str);
 
 	printk("APIC at: 0x%lX\n",mpc->mpc_lapic);
 
@@ -405,16 +379,10 @@
 	if (!acpi_lapic)
 		mp_lapic_addr = mpc->mpc_lapic;
 
-	if (clustered_apic_mode && mpc->mpc_oemptr) {
-		/* We need to process the oem mpc tables to tell us which quad things are in ... */
-		mpc_record = 0;
-		smp_read_mpc_oem((struct mp_config_oemtable *) mpc->mpc_oemptr, mpc->mpc_oemsize);
-		mpc_record = 0;
-	}
-
 	/*
 	 *	Now process the configuration blocks.
 	 */
+	mpc_record = 0;
 	while (count < mpc->mpc_length) {
 		switch(*mpt) {
 			case MP_PROCESSOR:
diff -Nru a/arch/i386/kernel/pci-dma.c b/arch/i386/kernel/pci-dma.c
--- a/arch/i386/kernel/pci-dma.c	Mon Dec 23 21:21:52 2002
+++ b/arch/i386/kernel/pci-dma.c	Mon Dec 23 21:21:52 2002
@@ -13,13 +13,13 @@
 #include <linux/pci.h>
 #include <asm/io.h>
 
-void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
+void *dma_alloc_coherent(struct device *dev, size_t size,
 			   dma_addr_t *dma_handle)
 {
 	void *ret;
 	int gfp = GFP_ATOMIC;
 
-	if (hwdev == NULL || ((u32)hwdev->dma_mask != 0xffffffff))
+	if (dev == NULL || ((u32)*dev->dma_mask != 0xffffffff))
 		gfp |= GFP_DMA;
 	ret = (void *)__get_free_pages(gfp, get_order(size));
 
@@ -30,7 +30,7 @@
 	return ret;
 }
 
-void pci_free_consistent(struct pci_dev *hwdev, size_t size,
+void dma_free_coherent(struct device *dev, size_t size,
 			 void *vaddr, dma_addr_t dma_handle)
 {
 	free_pages((unsigned long)vaddr, get_order(size));
diff -Nru a/arch/i386/kernel/process.c b/arch/i386/kernel/process.c
--- a/arch/i386/kernel/process.c	Mon Dec 23 21:21:50 2002
+++ b/arch/i386/kernel/process.c	Mon Dec 23 21:21:50 2002
@@ -44,6 +44,7 @@
 #include <asm/ldt.h>
 #include <asm/processor.h>
 #include <asm/i387.h>
+#include <asm/irq.h>
 #include <asm/desc.h>
 #ifdef CONFIG_MATH_EMULATION
 #include <asm/math_emu.h>
@@ -269,6 +270,8 @@
 			BUG();
 		}
 	}
+
+	release_x86_irqs(dead_task);
 }
 
 /*
@@ -440,7 +443,7 @@
 	/*
 	 * Reload esp0, LDT and the page table pointer:
 	 */
-	tss->esp0 = next->esp0;
+	load_esp0(tss, next->esp0);
 
 	/*
 	 * Load the per-thread Thread-Local Storage descriptor.
diff -Nru a/arch/i386/kernel/setup.c b/arch/i386/kernel/setup.c
--- a/arch/i386/kernel/setup.c	Mon Dec 23 21:21:55 2002
+++ b/arch/i386/kernel/setup.c	Mon Dec 23 21:21:55 2002
@@ -41,6 +41,8 @@
 #include <asm/arch_hooks.h>
 #include "setup_arch_pre.h"
 
+int disable_pse __initdata = 0;
+
 static inline char * __init machine_specific_memory_setup(void);
 
 /*
@@ -48,6 +50,9 @@
  */
 
 char ignore_irq13;		/* set if exception 16 works */
+/* cpu data as detected by the assembly code in head.S */
+struct cpuinfo_x86 new_cpu_data __initdata = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
+/* common cpu data for all cpus */
 struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
 
 unsigned long mmu_cr4_features;
@@ -523,6 +528,7 @@
 			if (!memcmp(from+4, "nopentium", 9)) {
 				from += 9+4;
 				clear_bit(X86_FEATURE_PSE, boot_cpu_data.x86_capability);
+				disable_pse = 1;
 			} else if (!memcmp(from+4, "exactmap", 8)) {
 				from += 8+4;
 				e820.nr_map = 0;
@@ -837,6 +843,7 @@
 {
 	unsigned long max_low_pfn;
 
+	memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
 	pre_setup_arch_hook();
 	early_cpu_init();
 
diff -Nru a/arch/i386/kernel/signal.c b/arch/i386/kernel/signal.c
--- a/arch/i386/kernel/signal.c	Mon Dec 23 21:21:54 2002
+++ b/arch/i386/kernel/signal.c	Mon Dec 23 21:21:54 2002
@@ -609,6 +609,11 @@
 void do_notify_resume(struct pt_regs *regs, sigset_t *oldset,
 		      __u32 thread_info_flags)
 {
+	/* Pending single-step? */
+	if (thread_info_flags & _TIF_SINGLESTEP) {
+		regs->eflags |= TF_MASK;
+		clear_thread_flag(TIF_SINGLESTEP);
+	}
 	/* deal with pending signal delivery */
 	if (thread_info_flags & _TIF_SIGPENDING)
 		do_signal(regs,oldset);
diff -Nru a/arch/i386/kernel/smp.c b/arch/i386/kernel/smp.c
--- a/arch/i386/kernel/smp.c	Mon Dec 23 21:21:51 2002
+++ b/arch/i386/kernel/smp.c	Mon Dec 23 21:21:51 2002
@@ -24,6 +24,7 @@
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
 #include <asm/smpboot.h>
+#include <mach_ipi.h>
 
 /*
  *	Some notes on x86 processor bugs affecting SMP operation:
@@ -225,54 +226,6 @@
 		}
 	}
 	local_irq_restore(flags);
-}
-
-static inline void send_IPI_mask(int mask, int vector)
-{
-	if (clustered_apic_mode) 
-		send_IPI_mask_sequence(mask, vector);
-	else
-		send_IPI_mask_bitmask(mask, vector);
-}
-
-static inline void send_IPI_allbutself(int vector)
-{
-	/*
-	 * if there are no other CPUs in the system then
-	 * we get an APIC send error if we try to broadcast.
-	 * thus we have to avoid sending IPIs in this case.
-	 */
-	if (!(num_online_cpus() > 1))
-		return;
-
-	if (clustered_apic_mode) {
-		// Pointless. Use send_IPI_mask to do this instead
-		int cpu;
-
-		for (cpu = 0; cpu < NR_CPUS; ++cpu) {
-			if (cpu_online(cpu) && cpu != smp_processor_id())
-				send_IPI_mask(1 << cpu, vector);
-		}
-	} else {
-		__send_IPI_shortcut(APIC_DEST_ALLBUT, vector);
-		return;
-	}
-}
-
-static inline void send_IPI_all(int vector)
-{
-	if (clustered_apic_mode) {
-		// Pointless. Use send_IPI_mask to do this instead
-		int cpu;
-
-		for (cpu = 0; cpu < NR_CPUS; ++cpu) {
-			if (!cpu_online(cpu))
-				continue;
-			send_IPI_mask(1 << cpu, vector);
-		}
-	} else {
-		__send_IPI_shortcut(APIC_DEST_ALLINC, vector);
-	}
 }
 
 /*
diff -Nru a/arch/i386/kernel/smpboot.c b/arch/i386/kernel/smpboot.c
--- a/arch/i386/kernel/smpboot.c	Mon Dec 23 21:21:55 2002
+++ b/arch/i386/kernel/smpboot.c	Mon Dec 23 21:21:55 2002
@@ -51,7 +51,8 @@
 #include <asm/desc.h>
 #include <asm/arch_hooks.h>
 #include "smpboot_hooks.h"
-#include "mach_apic.h"
+
+#include <mach_apic.h>
 
 /* Set if we find a B stepping CPU */
 static int __initdata smp_b_stepping;
@@ -848,11 +849,7 @@
 	/*
 	 * Starting actual IPI sequence...
 	 */
-
-	if (clustered_apic_mode)
-		boot_error = wakeup_secondary_via_NMI(apicid);
-	else 
-		boot_error = wakeup_secondary_via_INIT(apicid, start_eip);
+	wakeup_secondary_cpu(apicid, start_eip);
 
 	if (!boot_error) {
 		/*
@@ -1060,15 +1057,7 @@
 	if (GET_APIC_ID(apic_read(APIC_ID)) != boot_cpu_physical_apicid)
 		BUG();
 
-        if (clustered_apic_mode && (numnodes > 1)) {
-                printk("Remapping cross-quad port I/O for %d quads\n",
-			numnodes);
-                xquad_portio = ioremap (XQUAD_PORTIO_BASE, 
-			numnodes * XQUAD_PORTIO_QUAD);
-                printk("xquad_portio vaddr 0x%08lx, len %08lx\n",
-                        (u_long) xquad_portio, 
-			(u_long) numnodes * XQUAD_PORTIO_QUAD);
-        }
+	setup_portio_remap();
 
 	/*
 	 * Scan the CPU present map and fire up the other CPUs via do_boot_cpu
diff -Nru a/arch/i386/kernel/sys_i386.c b/arch/i386/kernel/sys_i386.c
--- a/arch/i386/kernel/sys_i386.c	Mon Dec 23 21:22:00 2002
+++ b/arch/i386/kernel/sys_i386.c	Mon Dec 23 21:22:00 2002
@@ -298,17 +298,17 @@
 {
 	struct mm_struct *mm = current->mm;
 	struct vm_area_struct *vma;
-	struct hugetlb_key *key;
 	int retval;
 
-	vma = find_vma(current->mm, addr);
-	if (!vma || !(vma->vm_flags & VM_HUGETLB) || vma->vm_start != addr)
-		return -EINVAL;
 	down_write(&mm->mmap_sem);
-	key = (struct hugetlb_key *)vma->vm_private_data;
+	vma = find_vma(current->mm, addr);
+	if (!vma || !(vma->vm_flags & VM_HUGETLB) || vma->vm_start != addr) {
+		retval = -EINVAL;
+		goto out;
+	}
 	retval = do_munmap(vma->vm_mm, addr, vma->vm_end - addr);
+out:
 	up_write(&mm->mmap_sem);
-	hugetlb_release_key(key);
 	return retval;
 }
 #else
diff -Nru a/arch/i386/kernel/sysenter.c b/arch/i386/kernel/sysenter.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/arch/i386/kernel/sysenter.c	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,89 @@
+/*
+ * linux/arch/i386/kernel/sysenter.c
+ *
+ * (C) Copyright 2002 Linus Torvalds
+ *
+ * This file contains the needed initializations to support sysenter.
+ */
+
+#include <linux/init.h>
+#include <linux/smp.h>
+#include <linux/thread_info.h>
+#include <linux/sched.h>
+#include <linux/gfp.h>
+#include <linux/string.h>
+
+#include <asm/cpufeature.h>
+#include <asm/msr.h>
+#include <asm/pgtable.h>
+
+extern asmlinkage void sysenter_entry(void);
+
+/*
+ * Create a per-cpu fake "SEP thread" stack, so that we can
+ * enter the kernel without having to worry about things like
+ * "current" etc not working (debug traps and NMI's can happen
+ * before we can switch over to the "real" thread).
+ *
+ * Return the resulting fake stack pointer.
+ */
+struct fake_sep_struct {
+	struct thread_info thread;
+	struct task_struct task;
+	unsigned char trampoline[32] __attribute__((aligned(1024)));
+	unsigned char stack[0];
+} __attribute__((aligned(8192)));
+	
+static void __init enable_sep_cpu(void *info)
+{
+	int cpu = get_cpu();
+	struct tss_struct *tss = init_tss + cpu;
+
+	wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0);
+	wrmsr(MSR_IA32_SYSENTER_ESP, tss->esp0, 0);
+	wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long) sysenter_entry, 0);
+
+	printk("Enabling SEP on CPU %d\n", cpu);
+	put_cpu();	
+}
+
+static int __init sysenter_setup(void)
+{
+	static const char int80[] = {
+		0xcd, 0x80,		/* int $0x80 */
+		0xc3			/* ret */
+	};
+	static const char sysent[] = {
+		0x51,			/* push %ecx */
+		0x52,			/* push %edx */
+		0x55,			/* push %ebp */
+	/* 3: backjump target */
+		0x89, 0xe5,		/* movl %esp,%ebp */
+		0x0f, 0x34,		/* sysenter */
+
+	/* 7: align return point with nop's to make disassembly easier */
+		0x90, 0x90, 0x90, 0x90,
+		0x90, 0x90, 0x90,
+
+	/* 14: System call restart point is here! (SYSENTER_RETURN - 2) */
+		0xeb, 0xf3,		/* jmp to "movl %esp,%ebp" */
+	/* 16: System call normal return point is here! (SYSENTER_RETURN in entry.S) */
+		0x5d,			/* pop %ebp */
+		0x5a,			/* pop %edx */
+		0x59,			/* pop %ecx */
+		0xc3			/* ret */
+	};
+	unsigned long page = get_zeroed_page(GFP_ATOMIC);
+
+	__set_fixmap(FIX_VSYSCALL, __pa(page), PAGE_READONLY);
+	memcpy((void *) page, int80, sizeof(int80));
+	if (!boot_cpu_has(X86_FEATURE_SEP))
+		return 0;
+
+	memcpy((void *) page, sysent, sizeof(sysent));
+	enable_sep_cpu(NULL);
+	smp_call_function(enable_sep_cpu, NULL, 1, 1);
+	return 0;
+}
+
+__initcall(sysenter_setup);
diff -Nru a/arch/i386/kernel/traps.c b/arch/i386/kernel/traps.c
--- a/arch/i386/kernel/traps.c	Mon Dec 23 21:21:51 2002
+++ b/arch/i386/kernel/traps.c	Mon Dec 23 21:21:51 2002
@@ -605,7 +605,7 @@
 		 * interface.
 		 */
 		if ((regs->xcs & 3) == 0)
-			goto clear_TF;
+			goto clear_TF_reenable;
 		if ((tsk->ptrace & (PT_DTRACE|PT_PTRACED)) == PT_DTRACE)
 			goto clear_TF;
 	}
@@ -637,6 +637,8 @@
 	handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, 1);
 	return;
 
+clear_TF_reenable:
+	set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
 clear_TF:
 	regs->eflags &= ~TF_MASK;
 	return;
diff -Nru a/arch/i386/kernel/vm86.c b/arch/i386/kernel/vm86.c
--- a/arch/i386/kernel/vm86.c	Mon Dec 23 21:21:51 2002
+++ b/arch/i386/kernel/vm86.c	Mon Dec 23 21:21:51 2002
@@ -113,7 +113,8 @@
 		do_exit(SIGSEGV);
 	}
 	tss = init_tss + smp_processor_id();
-	tss->esp0 = current->thread.esp0 = current->thread.saved_esp0;
+	current->thread.esp0 = current->thread.saved_esp0;
+	load_esp0(tss, current->thread.esp0);
 	current->thread.saved_esp0 = 0;
 	ret = KVM86->regs32;
 	return ret;
@@ -284,6 +285,7 @@
 	tsk->thread.saved_esp0 = tsk->thread.esp0;
 	tss = init_tss + smp_processor_id();
 	tss->esp0 = tsk->thread.esp0 = (unsigned long) &info->VM86_TSS_ESP0;
+	disable_sysenter();
 
 	tsk->thread.screen_bitmap = info->screen_bitmap;
 	if (info->flags & VM86_SCREEN_BITMAP)
@@ -708,23 +710,6 @@
 	spin_unlock_irqrestore(&irqbits_lock, flags);	
 }
 
-static inline int task_valid(struct task_struct *tsk)
-{
-	struct task_struct *g, *p;
-	int ret = 0;
-
-	read_lock(&tasklist_lock);
-	do_each_thread(g, p)
-		if ((p == tsk) && (p->sig)) {
-			ret = 1;
-			goto out;
-		}
-	while_each_thread(g, p);
-out:
-	read_unlock(&tasklist_lock);
-	return ret;
-}
-
 void release_x86_irqs(struct task_struct *task)
 {
 	int i;
@@ -733,17 +718,6 @@
 		free_vm86_irq(i);
 }
 
-static inline void handle_irq_zombies(void)
-{
-	int i;
-	for (i=3; i<16; i++) {
-		if (vm86_irqs[i].tsk) {
-			if (task_valid(vm86_irqs[i].tsk)) continue;
-			free_vm86_irq(i);
-		}
-	}
-}
-
 static inline int get_and_reset_irq(int irqnumber)
 {
 	int bit;
@@ -772,7 +746,6 @@
 		case VM86_REQUEST_IRQ: {
 			int sig = irqnumber >> 8;
 			int irq = irqnumber & 255;
-			handle_irq_zombies();
 			if (!capable(CAP_SYS_ADMIN)) return -EPERM;
 			if (!((1 << sig) & ALLOWED_SIGS)) return -EPERM;
 			if ( (irq<3) || (irq>15) ) return -EPERM;
@@ -784,7 +757,6 @@
 			return irq;
 		}
 		case  VM86_FREE_IRQ: {
-			handle_irq_zombies();
 			if ( (irqnumber<3) || (irqnumber>15) ) return -EPERM;
 			if (!vm86_irqs[irqnumber].tsk) return 0;
 			if (vm86_irqs[irqnumber].tsk != current) return -EPERM;
diff -Nru a/arch/i386/mach-default/Makefile b/arch/i386/mach-default/Makefile
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/arch/i386/mach-default/Makefile	Mon Dec 23 21:21:52 2002
@@ -0,0 +1,7 @@
+#
+# Makefile for the linux kernel.
+#
+
+EXTRA_CFLAGS	+= -I../kernel
+
+obj-y				:= setup.o topology.o
diff -Nru a/arch/i386/mach-default/setup.c b/arch/i386/mach-default/setup.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/arch/i386/mach-default/setup.c	Mon Dec 23 21:21:53 2002
@@ -0,0 +1,104 @@
+/*
+ *	Machine specific setup for generic
+ */
+
+#include <linux/config.h>
+#include <linux/smp.h>
+#include <linux/init.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <asm/arch_hooks.h>
+
+/**
+ * pre_intr_init_hook - initialisation prior to setting up interrupt vectors
+ *
+ * Description:
+ *	Perform any necessary interrupt initialisation prior to setting up
+ *	the "ordinary" interrupt call gates.  For legacy reasons, the ISA
+ *	interrupts should be initialised here if the machine emulates a PC
+ *	in any way.
+ **/
+void __init pre_intr_init_hook(void)
+{
+	init_ISA_irqs();
+}
+
+/*
+ * IRQ2 is cascade interrupt to second interrupt controller
+ */
+static struct irqaction irq2 = { no_action, 0, 0, "cascade", NULL, NULL};
+
+/**
+ * intr_init_hook - post gate setup interrupt initialisation
+ *
+ * Description:
+ *	Fill in any interrupts that may have been left out by the general
+ *	init_IRQ() routine.  interrupts having to do with the machine rather
+ *	than the devices on the I/O bus (like APIC interrupts in intel MP
+ *	systems) are started here.
+ **/
+void __init intr_init_hook(void)
+{
+#ifdef CONFIG_X86_LOCAL_APIC
+	apic_intr_init();
+#endif
+
+	setup_irq(2, &irq2);
+}
+
+/**
+ * pre_setup_arch_hook - hook called prior to any setup_arch() execution
+ *
+ * Description:
+ *	generally used to activate any machine specific identification
+ *	routines that may be needed before setup_arch() runs.  On VISWS
+ *	this is used to get the board revision and type.
+ **/
+void __init pre_setup_arch_hook(void)
+{
+}
+
+/**
+ * trap_init_hook - initialise system specific traps
+ *
+ * Description:
+ *	Called as the final act of trap_init().  Used in VISWS to initialise
+ *	the various board specific APIC traps.
+ **/
+void __init trap_init_hook(void)
+{
+}
+
+static struct irqaction irq0  = { timer_interrupt, SA_INTERRUPT, 0, "timer", NULL, NULL};
+
+/**
+ * time_init_hook - do any specific initialisations for the system timer.
+ *
+ * Description:
+ *	Must plug the system timer interrupt source at HZ into the IRQ listed
+ *	in irq_vectors.h:TIMER_IRQ
+ **/
+void __init time_init_hook(void)
+{
+	setup_irq(0, &irq0);
+}
+
+#ifdef CONFIG_MCA
+/**
+ * mca_nmi_hook - hook into MCA specific NMI chain
+ *
+ * Description:
+ *	The MCA (Microchannel Arcitecture) has an NMI chain for NMI sources
+ *	along the MCA bus.  Use this to hook into that chain if you will need
+ *	it.
+ **/
+void __init mca_nmi_hook(void)
+{
+	/* If I recall correctly, there's a whole bunch of other things that
+	 * we can do to check for NMI problems, but that's all I know about
+	 * at the moment.
+	 */
+
+	printk("NMI generated from unknown source!\n");
+}
+#endif
diff -Nru a/arch/i386/mach-default/topology.c b/arch/i386/mach-default/topology.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/arch/i386/mach-default/topology.c	Mon Dec 23 21:21:59 2002
@@ -0,0 +1,68 @@
+/*
+ * arch/i386/mach-generic/topology.c - Populate driverfs with topology information
+ *
+ * Written by: Matthew Dobson, IBM Corporation
+ * Original Code: Paul Dorwin, IBM Corporation, Patrick Mochel, OSDL
+ *
+ * Copyright (C) 2002, IBM Corp.
+ *
+ * All rights reserved.          
+ *
+ * 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.
+ *
+ * Send feedback to <colpatch@us.ibm.com>
+ */
+#include <linux/init.h>
+#include <linux/smp.h>
+#include <asm/cpu.h>
+
+struct i386_cpu cpu_devices[NR_CPUS];
+
+#ifdef CONFIG_NUMA
+#include <linux/mmzone.h>
+#include <asm/node.h>
+#include <asm/memblk.h>
+
+struct i386_node node_devices[MAX_NUMNODES];
+struct i386_memblk memblk_devices[MAX_NR_MEMBLKS];
+
+static int __init topology_init(void)
+{
+	int i;
+
+	for (i = 0; i < num_online_nodes(); i++)
+		arch_register_node(i);
+	for (i = 0; i < NR_CPUS; i++)
+		if (cpu_possible(i)) arch_register_cpu(i);
+	for (i = 0; i < num_online_memblks(); i++)
+		arch_register_memblk(i);
+	return 0;
+}
+
+#else /* !CONFIG_NUMA */
+
+static int __init topology_init(void)
+{
+	int i;
+
+	for (i = 0; i < NR_CPUS; i++)
+		if (cpu_possible(i)) arch_register_cpu(i);
+	return 0;
+}
+
+#endif /* CONFIG_NUMA */
+
+subsys_initcall(topology_init);
diff -Nru a/arch/i386/mach-generic/Makefile b/arch/i386/mach-generic/Makefile
--- a/arch/i386/mach-generic/Makefile	Mon Dec 23 21:21:52 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,7 +0,0 @@
-#
-# Makefile for the linux kernel.
-#
-
-EXTRA_CFLAGS	+= -I../kernel
-
-obj-y				:= setup.o topology.o
diff -Nru a/arch/i386/mach-generic/do_timer.h b/arch/i386/mach-generic/do_timer.h
--- a/arch/i386/mach-generic/do_timer.h	Mon Dec 23 21:22:00 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,82 +0,0 @@
-/* defines for inline arch setup functions */
-
-#include <asm/apic.h>
-
-/**
- * do_timer_interrupt_hook - hook into timer tick
- * @regs:	standard registers from interrupt
- *
- * Description:
- *	This hook is called immediately after the timer interrupt is ack'd.
- *	It's primary purpose is to allow architectures that don't possess
- *	individual per CPU clocks (like the CPU APICs supply) to broadcast the
- *	timer interrupt as a means of triggering reschedules etc.
- **/
-
-static inline void do_timer_interrupt_hook(struct pt_regs *regs)
-{
-	do_timer(regs);
-/*
- * In the SMP case we use the local APIC timer interrupt to do the
- * profiling, except when we simulate SMP mode on a uniprocessor
- * system, in that case we have to call the local interrupt handler.
- */
-#ifndef CONFIG_X86_LOCAL_APIC
-	x86_do_profile(regs);
-#else
-	if (!using_apic_timer)
-		smp_local_timer_interrupt(regs);
-#endif
-}
-
-
-/* you can safely undefine this if you don't have the Neptune chipset */
-
-#define BUGGY_NEPTUN_TIMER
-
-/**
- * do_timer_overflow - process a detected timer overflow condition
- * @count:	hardware timer interrupt count on overflow
- *
- * Description:
- *	This call is invoked when the jiffies count has not incremented but
- *	the hardware timer interrupt has.  It means that a timer tick interrupt
- *	came along while the previous one was pending, thus a tick was missed
- **/
-static inline int do_timer_overflow(int count)
-{
-	int i;
-
-	spin_lock(&i8259A_lock);
-	/*
-	 * This is tricky when I/O APICs are used;
-	 * see do_timer_interrupt().
-	 */
-	i = inb(0x20);
-	spin_unlock(&i8259A_lock);
-	
-	/* assumption about timer being IRQ0 */
-	if (i & 0x01) {
-		/*
-		 * We cannot detect lost timer interrupts ... 
-		 * well, that's why we call them lost, don't we? :)
-		 * [hmm, on the Pentium and Alpha we can ... sort of]
-		 */
-		count -= LATCH;
-	} else {
-#ifdef BUGGY_NEPTUN_TIMER
-		/*
-		 * for the Neptun bug we know that the 'latch'
-		 * command doesnt latch the high and low value
-		 * of the counter atomically. Thus we have to 
-		 * substract 256 from the counter 
-		 * ... funny, isnt it? :)
-		 */
-		
-		count -= 256;
-#else
-		printk("do_slow_gettimeoffset(): hardware timer problem?\n");
-#endif
-	}
-	return count;
-}
diff -Nru a/arch/i386/mach-generic/entry_arch.h b/arch/i386/mach-generic/entry_arch.h
--- a/arch/i386/mach-generic/entry_arch.h	Mon Dec 23 21:21:50 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,34 +0,0 @@
-/*
- * This file is designed to contain the BUILD_INTERRUPT specifications for
- * all of the extra named interrupt vectors used by the architecture.
- * Usually this is the Inter Process Interrupts (IPIs)
- */
-
-/*
- * The following vectors are part of the Linux architecture, there
- * is no hardware IRQ pin equivalent for them, they are triggered
- * through the ICC by us (IPIs)
- */
-#ifdef CONFIG_X86_SMP
-BUILD_INTERRUPT(reschedule_interrupt,RESCHEDULE_VECTOR)
-BUILD_INTERRUPT(invalidate_interrupt,INVALIDATE_TLB_VECTOR)
-BUILD_INTERRUPT(call_function_interrupt,CALL_FUNCTION_VECTOR)
-#endif
-
-/*
- * every pentium local APIC has two 'local interrupts', with a
- * soft-definable vector attached to both interrupts, one of
- * which is a timer interrupt, the other one is error counter
- * overflow. Linux uses the local APIC timer interrupt to get
- * a much simpler SMP time architecture:
- */
-#ifdef CONFIG_X86_LOCAL_APIC
-BUILD_INTERRUPT(apic_timer_interrupt,LOCAL_TIMER_VECTOR)
-BUILD_INTERRUPT(error_interrupt,ERROR_APIC_VECTOR)
-BUILD_INTERRUPT(spurious_interrupt,SPURIOUS_APIC_VECTOR)
-
-#ifdef CONFIG_X86_MCE_P4THERMAL
-BUILD_INTERRUPT(thermal_interrupt,THERMAL_APIC_VECTOR)
-#endif
-
-#endif
diff -Nru a/arch/i386/mach-generic/irq_vectors.h b/arch/i386/mach-generic/irq_vectors.h
--- a/arch/i386/mach-generic/irq_vectors.h	Mon Dec 23 21:21:52 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,85 +0,0 @@
-/*
- * This file should contain #defines for all of the interrupt vector
- * numbers used by this architecture.
- *
- * In addition, there are some standard defines:
- *
- *	FIRST_EXTERNAL_VECTOR:
- *		The first free place for external interrupts
- *
- *	SYSCALL_VECTOR:
- *		The IRQ vector a syscall makes the user to kernel transition
- *		under.
- *
- *	TIMER_IRQ:
- *		The IRQ number the timer interrupt comes in at.
- *
- *	NR_IRQS:
- *		The total number of interrupt vectors (including all the
- *		architecture specific interrupts) needed.
- *
- */			
-#ifndef _ASM_IRQ_VECTORS_H
-#define _ASM_IRQ_VECTORS_H
-
-/*
- * IDT vectors usable for external interrupt sources start
- * at 0x20:
- */
-#define FIRST_EXTERNAL_VECTOR	0x20
-
-#define SYSCALL_VECTOR		0x80
-
-/*
- * Vectors 0x20-0x2f are used for ISA interrupts.
- */
-
-/*
- * Special IRQ vectors used by the SMP architecture, 0xf0-0xff
- *
- *  some of the following vectors are 'rare', they are merged
- *  into a single vector (CALL_FUNCTION_VECTOR) to save vector space.
- *  TLB, reschedule and local APIC vectors are performance-critical.
- *
- *  Vectors 0xf0-0xfa are free (reserved for future Linux use).
- */
-#define SPURIOUS_APIC_VECTOR	0xff
-#define ERROR_APIC_VECTOR	0xfe
-#define INVALIDATE_TLB_VECTOR	0xfd
-#define RESCHEDULE_VECTOR	0xfc
-#define CALL_FUNCTION_VECTOR	0xfb
-
-#define THERMAL_APIC_VECTOR	0xf0
-/*
- * Local APIC timer IRQ vector is on a different priority level,
- * to work around the 'lost local interrupt if more than 2 IRQ
- * sources per level' errata.
- */
-#define LOCAL_TIMER_VECTOR	0xef
-
-/*
- * First APIC vector available to drivers: (vectors 0x30-0xee)
- * we start at 0x31 to spread out vectors evenly between priority
- * levels. (0x80 is the syscall vector)
- */
-#define FIRST_DEVICE_VECTOR	0x31
-#define FIRST_SYSTEM_VECTOR	0xef
-
-#define TIMER_IRQ 0
-
-/*
- * 16 8259A IRQ's, 208 potential APIC interrupt sources.
- * Right now the APIC is mostly only used for SMP.
- * 256 vectors is an architectural limit. (we can have
- * more than 256 devices theoretically, but they will
- * have to use shared interrupts)
- * Since vectors 0x00-0x1f are used/reserved for the CPU,
- * the usable vector space is 0x20-0xff (224 vectors)
- */
-#ifdef CONFIG_X86_IO_APIC
-#define NR_IRQS 224
-#else
-#define NR_IRQS 16
-#endif
-
-#endif /* _ASM_IRQ_VECTORS_H */
diff -Nru a/arch/i386/mach-generic/mach_apic.h b/arch/i386/mach-generic/mach_apic.h
--- a/arch/i386/mach-generic/mach_apic.h	Mon Dec 23 21:22:02 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,46 +0,0 @@
-#ifndef __ASM_MACH_APIC_H
-#define __ASM_MACH_APIC_H
-
-static inline unsigned long calculate_ldr(unsigned long old)
-{
-	unsigned long id;
-
-	id = 1UL << smp_processor_id();
-	return ((old & ~APIC_LDR_MASK) | SET_APIC_LOGICAL_ID(id));
-}
-
-#define APIC_DFR_VALUE	(APIC_DFR_FLAT)
-
-#ifdef CONFIG_SMP
- #define TARGET_CPUS (clustered_apic_mode ? 0xf : cpu_online_map)
-#else
- #define TARGET_CPUS 0x01
-#endif
-
-#define APIC_BROADCAST_ID      0x0F
-#define check_apicid_used(bitmap, apicid) (bitmap & (1 << apicid))
-
-static inline void summit_check(char *oem, char *productid) 
-{
-}
-
-static inline void clustered_apic_check(void)
-{
-	printk("Enabling APIC mode:  %s.  Using %d I/O APICs\n",
-		(clustered_apic_mode ? "NUMA-Q" : "Flat"), nr_ioapics);
-}
-
-static inline int cpu_present_to_apicid(int mps_cpu)
-{
-	if (clustered_apic_mode)
-		return ( ((mps_cpu/4)*16) + (1<<(mps_cpu%4)) );
-	else
-		return mps_cpu;
-}
-
-static inline unsigned long apicid_to_cpu_present(int apicid)
-{
-	return (1ul << apicid);
-}
-
-#endif /* __ASM_MACH_APIC_H */
diff -Nru a/arch/i386/mach-generic/setup.c b/arch/i386/mach-generic/setup.c
--- a/arch/i386/mach-generic/setup.c	Mon Dec 23 21:21:53 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,104 +0,0 @@
-/*
- *	Machine specific setup for generic
- */
-
-#include <linux/config.h>
-#include <linux/smp.h>
-#include <linux/init.h>
-#include <linux/irq.h>
-#include <linux/interrupt.h>
-#include <asm/arch_hooks.h>
-
-/**
- * pre_intr_init_hook - initialisation prior to setting up interrupt vectors
- *
- * Description:
- *	Perform any necessary interrupt initialisation prior to setting up
- *	the "ordinary" interrupt call gates.  For legacy reasons, the ISA
- *	interrupts should be initialised here if the machine emulates a PC
- *	in any way.
- **/
-void __init pre_intr_init_hook(void)
-{
-	init_ISA_irqs();
-}
-
-/*
- * IRQ2 is cascade interrupt to second interrupt controller
- */
-static struct irqaction irq2 = { no_action, 0, 0, "cascade", NULL, NULL};
-
-/**
- * intr_init_hook - post gate setup interrupt initialisation
- *
- * Description:
- *	Fill in any interrupts that may have been left out by the general
- *	init_IRQ() routine.  interrupts having to do with the machine rather
- *	than the devices on the I/O bus (like APIC interrupts in intel MP
- *	systems) are started here.
- **/
-void __init intr_init_hook(void)
-{
-#ifdef CONFIG_X86_LOCAL_APIC
-	apic_intr_init();
-#endif
-
-	setup_irq(2, &irq2);
-}
-
-/**
- * pre_setup_arch_hook - hook called prior to any setup_arch() execution
- *
- * Description:
- *	generally used to activate any machine specific identification
- *	routines that may be needed before setup_arch() runs.  On VISWS
- *	this is used to get the board revision and type.
- **/
-void __init pre_setup_arch_hook(void)
-{
-}
-
-/**
- * trap_init_hook - initialise system specific traps
- *
- * Description:
- *	Called as the final act of trap_init().  Used in VISWS to initialise
- *	the various board specific APIC traps.
- **/
-void __init trap_init_hook(void)
-{
-}
-
-static struct irqaction irq0  = { timer_interrupt, SA_INTERRUPT, 0, "timer", NULL, NULL};
-
-/**
- * time_init_hook - do any specific initialisations for the system timer.
- *
- * Description:
- *	Must plug the system timer interrupt source at HZ into the IRQ listed
- *	in irq_vectors.h:TIMER_IRQ
- **/
-void __init time_init_hook(void)
-{
-	setup_irq(0, &irq0);
-}
-
-#ifdef CONFIG_MCA
-/**
- * mca_nmi_hook - hook into MCA specific NMI chain
- *
- * Description:
- *	The MCA (Microchannel Arcitecture) has an NMI chain for NMI sources
- *	along the MCA bus.  Use this to hook into that chain if you will need
- *	it.
- **/
-void __init mca_nmi_hook(void)
-{
-	/* If I recall correctly, there's a whole bunch of other things that
-	 * we can do to check for NMI problems, but that's all I know about
-	 * at the moment.
-	 */
-
-	printk("NMI generated from unknown source!\n");
-}
-#endif
diff -Nru a/arch/i386/mach-generic/setup_arch_post.h b/arch/i386/mach-generic/setup_arch_post.h
--- a/arch/i386/mach-generic/setup_arch_post.h	Mon Dec 23 21:21:59 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,40 +0,0 @@
-/**
- * machine_specific_memory_setup - Hook for machine specific memory setup.
- *
- * Description:
- *	This is included late in kernel/setup.c so that it can make
- *	use of all of the static functions.
- **/
-
-static inline char * __init machine_specific_memory_setup(void)
-{
-	char *who;
-
-
-	who = "BIOS-e820";
-
-	/*
-	 * Try to copy the BIOS-supplied E820-map.
-	 *
-	 * Otherwise fake a memory map; one section from 0k->640k,
-	 * the next section from 1mb->appropriate_mem_k
-	 */
-	sanitize_e820_map(E820_MAP, &E820_MAP_NR);
-	if (copy_e820_map(E820_MAP, E820_MAP_NR) < 0) {
-		unsigned long mem_size;
-
-		/* compare results from other methods and take the greater */
-		if (ALT_MEM_K < EXT_MEM_K) {
-			mem_size = EXT_MEM_K;
-			who = "BIOS-88";
-		} else {
-			mem_size = ALT_MEM_K;
-			who = "BIOS-e801";
-		}
-
-		e820.nr_map = 0;
-		add_memory_region(0, LOWMEMSIZE(), E820_RAM);
-		add_memory_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
-  	}
-	return who;
-}
diff -Nru a/arch/i386/mach-generic/setup_arch_pre.h b/arch/i386/mach-generic/setup_arch_pre.h
--- a/arch/i386/mach-generic/setup_arch_pre.h	Mon Dec 23 21:21:51 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,5 +0,0 @@
-/* Hook to call BIOS initialisation function */
-
-/* no action for generic */
-
-#define ARCH_SETUP
diff -Nru a/arch/i386/mach-generic/smpboot_hooks.h b/arch/i386/mach-generic/smpboot_hooks.h
--- a/arch/i386/mach-generic/smpboot_hooks.h	Mon Dec 23 21:21:52 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,33 +0,0 @@
-/* two abstractions specific to kernel/smpboot.c, mainly to cater to visws
- * which needs to alter them. */
-
-static inline void smpboot_clear_io_apic_irqs(void)
-{
-	io_apic_irqs = 0;
-}
-
-static inline void smpboot_setup_warm_reset_vector(void)
-{
-	/*
-	 * Install writable page 0 entry to set BIOS data area.
-	 */
-	local_flush_tlb();
-
-	/*
-	 * Paranoid:  Set warm reset code and vector here back
-	 * to default values.
-	 */
-	CMOS_WRITE(0, 0xf);
-
-	*((volatile long *) phys_to_virt(0x467)) = 0;
-}
-
-static inline void smpboot_setup_io_apic(void)
-{
-	/*
-	 * Here we can be sure that there is an IO-APIC in the system. Let's
-	 * go and set it up:
-	 */
-	if (!skip_ioapic_setup && nr_ioapics)
-		setup_IO_APIC();
-}
diff -Nru a/arch/i386/mach-generic/topology.c b/arch/i386/mach-generic/topology.c
--- a/arch/i386/mach-generic/topology.c	Mon Dec 23 21:21:59 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,68 +0,0 @@
-/*
- * arch/i386/mach-generic/topology.c - Populate driverfs with topology information
- *
- * Written by: Matthew Dobson, IBM Corporation
- * Original Code: Paul Dorwin, IBM Corporation, Patrick Mochel, OSDL
- *
- * Copyright (C) 2002, IBM Corp.
- *
- * All rights reserved.          
- *
- * 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.
- *
- * Send feedback to <colpatch@us.ibm.com>
- */
-#include <linux/init.h>
-#include <linux/smp.h>
-#include <asm/cpu.h>
-
-struct i386_cpu cpu_devices[NR_CPUS];
-
-#ifdef CONFIG_NUMA
-#include <linux/mmzone.h>
-#include <asm/node.h>
-#include <asm/memblk.h>
-
-struct i386_node node_devices[MAX_NUMNODES];
-struct i386_memblk memblk_devices[MAX_NR_MEMBLKS];
-
-static int __init topology_init(void)
-{
-	int i;
-
-	for (i = 0; i < num_online_nodes(); i++)
-		arch_register_node(i);
-	for (i = 0; i < NR_CPUS; i++)
-		if (cpu_possible(i)) arch_register_cpu(i);
-	for (i = 0; i < num_online_memblks(); i++)
-		arch_register_memblk(i);
-	return 0;
-}
-
-#else /* !CONFIG_NUMA */
-
-static int __init topology_init(void)
-{
-	int i;
-
-	for (i = 0; i < NR_CPUS; i++)
-		if (cpu_possible(i)) arch_register_cpu(i);
-	return 0;
-}
-
-#endif /* CONFIG_NUMA */
-
-subsys_initcall(topology_init);
diff -Nru a/arch/i386/mach-summit/mach_apic.h b/arch/i386/mach-summit/mach_apic.h
--- a/arch/i386/mach-summit/mach_apic.h	Mon Dec 23 21:21:57 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,57 +0,0 @@
-#ifndef __ASM_MACH_APIC_H
-#define __ASM_MACH_APIC_H
-
-extern int x86_summit;
-
-#define XAPIC_DEST_CPUS_MASK    0x0Fu
-#define XAPIC_DEST_CLUSTER_MASK 0xF0u
-
-#define xapic_phys_to_log_apicid(phys_apic) ( (1ul << ((phys_apic) & 0x3)) |\
-		((phys_apic) & XAPIC_DEST_CLUSTER_MASK) )
-
-static inline unsigned long calculate_ldr(unsigned long old)
-{
-	unsigned long id;
-
-	if (x86_summit)
-		id = xapic_phys_to_log_apicid(hard_smp_processor_id());
-	else
-		id = 1UL << smp_processor_id();
-	return ((old & ~APIC_LDR_MASK) | SET_APIC_LOGICAL_ID(id));
-}
-
-#define APIC_DFR_VALUE	(x86_summit ? APIC_DFR_CLUSTER : APIC_DFR_FLAT)
-#define TARGET_CPUS	(x86_summit ? XAPIC_DEST_CPUS_MASK : cpu_online_map)
-
-#define APIC_BROADCAST_ID     (x86_summit ? 0xFF : 0x0F)
-#define check_apicid_used(bitmap, apicid) (0)
-
-static inline void summit_check(char *oem, char *productid)
-{
-	if (!strncmp(oem, "IBM ENSW", 8) && !strncmp(str, "VIGIL SMP", 9))
-		x86_summit = 1;
-}
-
-static inline void clustered_apic_check(void)
-{
-	printk("Enabling APIC mode:  %s.  Using %d I/O APICs\n",
-		(x86_summit ? "Summit" : "Flat"), nr_ioapics);
-}
-
-static inline int cpu_present_to_apicid(int mps_cpu)
-{
-	if (x86_summit)
-		return (int) raw_phys_apicid[mps_cpu];
-	else
-		return mps_cpu;
-}
-
-static inline unsigned long apicid_to_phys_cpu_present(int apicid)
-{
-	if (x86_summit)
-		return (1ul << (((apicid >> 4) << 2) | (apicid & 0x3)));
-	else
-		return (1ul << apicid);
-}
-
-#endif /* __ASM_MACH_APIC_H */
diff -Nru a/arch/i386/mach-visws/do_timer.h b/arch/i386/mach-visws/do_timer.h
--- a/arch/i386/mach-visws/do_timer.h	Mon Dec 23 21:21:52 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,49 +0,0 @@
-/* defines for inline arch setup functions */
-
-#include <asm/fixmap.h>
-#include <asm/cobalt.h>
-
-static inline void do_timer_interrupt_hook(struct pt_regs *regs)
-{
-	/* Clear the interrupt */
-	co_cpu_write(CO_CPU_STAT,co_cpu_read(CO_CPU_STAT) & ~CO_STAT_TIMEINTR);
-
-	do_timer(regs);
-/*
- * In the SMP case we use the local APIC timer interrupt to do the
- * profiling, except when we simulate SMP mode on a uniprocessor
- * system, in that case we have to call the local interrupt handler.
- */
-#ifndef CONFIG_X86_LOCAL_APIC
-	x86_do_profile(regs);
-#else
-	if (!using_apic_timer)
-		smp_local_timer_interrupt(regs);
-#endif
-}
-
-static inline int do_timer_overflow(int count)
-{
-	int i;
-
-	spin_lock(&i8259A_lock);
-	/*
-	 * This is tricky when I/O APICs are used;
-	 * see do_timer_interrupt().
-	 */
-	i = inb(0x20);
-	spin_unlock(&i8259A_lock);
-	
-	/* assumption about timer being IRQ0 */
-	if (i & 0x01) {
-		/*
-		 * We cannot detect lost timer interrupts ... 
-		 * well, that's why we call them lost, don't we? :)
-		 * [hmm, on the Pentium and Alpha we can ... sort of]
-		 */
-		count -= LATCH;
-	} else {
-		printk("do_slow_gettimeoffset(): hardware timer problem?\n");
-	}
-	return count;
-}
diff -Nru a/arch/i386/mach-visws/entry_arch.h b/arch/i386/mach-visws/entry_arch.h
--- a/arch/i386/mach-visws/entry_arch.h	Mon Dec 23 21:22:00 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,23 +0,0 @@
-/*
- * The following vectors are part of the Linux architecture, there
- * is no hardware IRQ pin equivalent for them, they are triggered
- * through the ICC by us (IPIs)
- */
-#ifdef CONFIG_X86_SMP
-BUILD_INTERRUPT(reschedule_interrupt,RESCHEDULE_VECTOR)
-BUILD_INTERRUPT(invalidate_interrupt,INVALIDATE_TLB_VECTOR)
-BUILD_INTERRUPT(call_function_interrupt,CALL_FUNCTION_VECTOR)
-#endif
-
-/*
- * every pentium local APIC has two 'local interrupts', with a
- * soft-definable vector attached to both interrupts, one of
- * which is a timer interrupt, the other one is error counter
- * overflow. Linux uses the local APIC timer interrupt to get
- * a much simpler SMP time architecture:
- */
-#ifdef CONFIG_X86_LOCAL_APIC
-BUILD_INTERRUPT(apic_timer_interrupt,LOCAL_TIMER_VECTOR)
-BUILD_INTERRUPT(error_interrupt,ERROR_APIC_VECTOR)
-BUILD_INTERRUPT(spurious_interrupt,SPURIOUS_APIC_VECTOR)
-#endif
diff -Nru a/arch/i386/mach-visws/irq_vectors.h b/arch/i386/mach-visws/irq_vectors.h
--- a/arch/i386/mach-visws/irq_vectors.h	Mon Dec 23 21:21:51 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,64 +0,0 @@
-#ifndef _ASM_IRQ_VECTORS_H
-#define _ASM_IRQ_VECTORS_H
-
-/*
- * IDT vectors usable for external interrupt sources start
- * at 0x20:
- */
-#define FIRST_EXTERNAL_VECTOR	0x20
-
-#define SYSCALL_VECTOR		0x80
-
-/*
- * Vectors 0x20-0x2f are used for ISA interrupts.
- */
-
-/*
- * Special IRQ vectors used by the SMP architecture, 0xf0-0xff
- *
- *  some of the following vectors are 'rare', they are merged
- *  into a single vector (CALL_FUNCTION_VECTOR) to save vector space.
- *  TLB, reschedule and local APIC vectors are performance-critical.
- *
- *  Vectors 0xf0-0xfa are free (reserved for future Linux use).
- */
-#define SPURIOUS_APIC_VECTOR	0xff
-#define ERROR_APIC_VECTOR	0xfe
-#define INVALIDATE_TLB_VECTOR	0xfd
-#define RESCHEDULE_VECTOR	0xfc
-#define CALL_FUNCTION_VECTOR	0xfb
-
-#define THERMAL_APIC_VECTOR	0xf0
-/*
- * Local APIC timer IRQ vector is on a different priority level,
- * to work around the 'lost local interrupt if more than 2 IRQ
- * sources per level' errata.
- */
-#define LOCAL_TIMER_VECTOR	0xef
-
-/*
- * First APIC vector available to drivers: (vectors 0x30-0xee)
- * we start at 0x31 to spread out vectors evenly between priority
- * levels. (0x80 is the syscall vector)
- */
-#define FIRST_DEVICE_VECTOR	0x31
-#define FIRST_SYSTEM_VECTOR	0xef
-
-#define TIMER_IRQ 0
-
-/*
- * 16 8259A IRQ's, 208 potential APIC interrupt sources.
- * Right now the APIC is mostly only used for SMP.
- * 256 vectors is an architectural limit. (we can have
- * more than 256 devices theoretically, but they will
- * have to use shared interrupts)
- * Since vectors 0x00-0x1f are used/reserved for the CPU,
- * the usable vector space is 0x20-0xff (224 vectors)
- */
-#ifdef CONFIG_X86_IO_APIC
-#define NR_IRQS 224
-#else
-#define NR_IRQS 16
-#endif
-
-#endif /* _ASM_IRQ_VECTORS_H */
diff -Nru a/arch/i386/mach-visws/setup_arch_post.h b/arch/i386/mach-visws/setup_arch_post.h
--- a/arch/i386/mach-visws/setup_arch_post.h	Mon Dec 23 21:21:55 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,37 +0,0 @@
-/* Hook for machine specific memory setup.
- *
- * This is included late in kernel/setup.c so that it can make use of all of
- * the static functions. */
-
-static inline char * __init machine_specific_memory_setup(void)
-{
-	char *who;
-
-
-	who = "BIOS-e820";
-
-	/*
-	 * Try to copy the BIOS-supplied E820-map.
-	 *
-	 * Otherwise fake a memory map; one section from 0k->640k,
-	 * the next section from 1mb->appropriate_mem_k
-	 */
-	sanitize_e820_map(E820_MAP, &E820_MAP_NR);
-	if (copy_e820_map(E820_MAP, E820_MAP_NR) < 0) {
-		unsigned long mem_size;
-
-		/* compare results from other methods and take the greater */
-		if (ALT_MEM_K < EXT_MEM_K) {
-			mem_size = EXT_MEM_K;
-			who = "BIOS-88";
-		} else {
-			mem_size = ALT_MEM_K;
-			who = "BIOS-e801";
-		}
-
-		e820.nr_map = 0;
-		add_memory_region(0, LOWMEMSIZE(), E820_RAM);
-		add_memory_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
-  	}
-	return who;
-}
diff -Nru a/arch/i386/mach-visws/setup_arch_pre.h b/arch/i386/mach-visws/setup_arch_pre.h
--- a/arch/i386/mach-visws/setup_arch_pre.h	Mon Dec 23 21:21:52 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,5 +0,0 @@
-/* Hook to call BIOS initialisation function */
-
-/* no action for visws */
-
-#define ARCH_SETUP
diff -Nru a/arch/i386/mach-visws/smpboot_hooks.h b/arch/i386/mach-visws/smpboot_hooks.h
--- a/arch/i386/mach-visws/smpboot_hooks.h	Mon Dec 23 21:21:51 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,13 +0,0 @@
-/* for visws do nothing for any of these */
-
-static inline void smpboot_clear_io_apic_irqs(void)
-{
-}
-
-static inline void smpboot_setup_warm_reset_vector(void)
-{
-}
-
-static inline void smpboot_setup_io_apic(void)
-{
-}
diff -Nru a/arch/i386/mach-voyager/do_timer.h b/arch/i386/mach-voyager/do_timer.h
--- a/arch/i386/mach-voyager/do_timer.h	Mon Dec 23 21:21:59 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,22 +0,0 @@
-/* defines for inline arch setup functions */
-#include <asm/voyager.h>
-
-static inline void do_timer_interrupt_hook(struct pt_regs *regs)
-{
-	do_timer(regs);
-
-	voyager_timer_interrupt(regs);
-}
-
-static inline int do_timer_overflow(int count)
-{
-	/* can't read the ISR, just assume 1 tick
-	   overflow */
-	if(count > LATCH || count < 0) {
-		printk(KERN_ERR "VOYAGER PROBLEM: count is %d, latch is %d\n", count, LATCH);
-		count = LATCH;
-	}
-	count -= LATCH;
-
-	return count;
-}
diff -Nru a/arch/i386/mach-voyager/entry_arch.h b/arch/i386/mach-voyager/entry_arch.h
--- a/arch/i386/mach-voyager/entry_arch.h	Mon Dec 23 21:21:59 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,26 +0,0 @@
-/* -*- mode: c; c-basic-offset: 8 -*- */
-
-/* Copyright (C) 2002
- *
- * Author: James.Bottomley@HansenPartnership.com
- *
- * linux/arch/i386/voyager/entry_arch.h
- *
- * This file builds the VIC and QIC CPI gates
- */
-
-/* initialise the voyager interrupt gates 
- *
- * This uses the macros in irq.h to set up assembly jump gates.  The
- * calls are then redirected to the same routine with smp_ prefixed */
-BUILD_INTERRUPT(vic_sys_interrupt, VIC_SYS_INT)
-BUILD_INTERRUPT(vic_cmn_interrupt, VIC_CMN_INT)
-BUILD_INTERRUPT(vic_cpi_interrupt, VIC_CPI_LEVEL0);
-
-/* do all the QIC interrupts */
-BUILD_INTERRUPT(qic_timer_interrupt, QIC_TIMER_CPI);
-BUILD_INTERRUPT(qic_invalidate_interrupt, QIC_INVALIDATE_CPI);
-BUILD_INTERRUPT(qic_reschedule_interrupt, QIC_RESCHEDULE_CPI);
-BUILD_INTERRUPT(qic_enable_irq_interrupt, QIC_ENABLE_IRQ_CPI);
-BUILD_INTERRUPT(qic_call_function_interrupt, QIC_CALL_FUNCTION_CPI);
-
diff -Nru a/arch/i386/mach-voyager/irq_vectors.h b/arch/i386/mach-voyager/irq_vectors.h
--- a/arch/i386/mach-voyager/irq_vectors.h	Mon Dec 23 21:21:52 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,71 +0,0 @@
-/* -*- mode: c; c-basic-offset: 8 -*- */
-
-/* Copyright (C) 2002
- *
- * Author: James.Bottomley@HansenPartnership.com
- *
- * linux/arch/i386/voyager/irq_vectors.h
- *
- * This file provides definitions for the VIC and QIC CPIs
- */
-
-#ifndef _ASM_IRQ_VECTORS_H
-#define _ASM_IRQ_VECTORS_H
-
-/*
- * IDT vectors usable for external interrupt sources start
- * at 0x20:
- */
-#define FIRST_EXTERNAL_VECTOR	0x20
-
-#define SYSCALL_VECTOR		0x80
-
-/*
- * Vectors 0x20-0x2f are used for ISA interrupts.
- */
-
-/* These define the CPIs we use in linux */
-#define VIC_CPI_LEVEL0			0
-#define VIC_CPI_LEVEL1			1
-/* now the fake CPIs */
-#define VIC_TIMER_CPI			2
-#define VIC_INVALIDATE_CPI		3
-#define VIC_RESCHEDULE_CPI		4
-#define VIC_ENABLE_IRQ_CPI		5
-#define VIC_CALL_FUNCTION_CPI		6
-
-/* Now the QIC CPIs:  Since we don't need the two initial levels,
- * these are 2 less than the VIC CPIs */
-#define QIC_CPI_OFFSET			1
-#define QIC_TIMER_CPI			(VIC_TIMER_CPI - QIC_CPI_OFFSET)
-#define QIC_INVALIDATE_CPI		(VIC_INVALIDATE_CPI - QIC_CPI_OFFSET)
-#define QIC_RESCHEDULE_CPI		(VIC_RESCHEDULE_CPI - QIC_CPI_OFFSET)
-#define QIC_ENABLE_IRQ_CPI		(VIC_ENABLE_IRQ_CPI - QIC_CPI_OFFSET)
-#define QIC_CALL_FUNCTION_CPI		(VIC_CALL_FUNCTION_CPI - QIC_CPI_OFFSET)
-
-#define VIC_START_FAKE_CPI		VIC_TIMER_CPI
-#define VIC_END_FAKE_CPI		VIC_CALL_FUNCTION_CPI
-
-/* this is the SYS_INT CPI. */
-#define VIC_SYS_INT			8
-#define VIC_CMN_INT			15
-
-/* This is the boot CPI for alternate processors.  It gets overwritten
- * by the above once the system has activated all available processors */
-#define VIC_CPU_BOOT_CPI		VIC_CPI_LEVEL0
-#define VIC_CPU_BOOT_ERRATA_CPI		(VIC_CPI_LEVEL0 + 8)
-
-#define NR_IRQS 224
-
-#ifndef __ASSEMBLY__
-extern asmlinkage void vic_cpi_interrupt(void);
-extern asmlinkage void vic_sys_interrupt(void);
-extern asmlinkage void vic_cmn_interrupt(void);
-extern asmlinkage void qic_timer_interrupt(void);
-extern asmlinkage void qic_invalidate_interrupt(void);
-extern asmlinkage void qic_reschedule_interrupt(void);
-extern asmlinkage void qic_enable_irq_interrupt(void);
-extern asmlinkage void qic_call_function_interrupt(void);
-#endif /* !__ASSEMBLY__ */
-
-#endif /* _ASM_IRQ_VECTORS_H */
diff -Nru a/arch/i386/mach-voyager/setup_arch_post.h b/arch/i386/mach-voyager/setup_arch_post.h
--- a/arch/i386/mach-voyager/setup_arch_post.h	Mon Dec 23 21:21:53 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,73 +0,0 @@
-/* Hook for machine specific memory setup.
- *
- * This is included late in kernel/setup.c so that it can make use of all of
- * the static functions. */
-
-static inline char * __init machine_specific_memory_setup(void)
-{
-	char *who;
-
-	who = "NOT VOYAGER";
-
-	if(voyager_level == 5) {
-		__u32 addr, length;
-		int i;
-
-		who = "Voyager-SUS";
-
-		e820.nr_map = 0;
-		for(i=0; voyager_memory_detect(i, &addr, &length); i++) {
-			add_memory_region(addr, length, E820_RAM);
-		}
-		return who;
-	} else if(voyager_level == 4) {
-		__u32 tom;
-		__u16 catbase = inb(VOYAGER_SSPB_RELOCATION_PORT)<<8;
-		/* select the DINO config space */
-		outb(VOYAGER_DINO, VOYAGER_CAT_CONFIG_PORT);
-		/* Read DINO top of memory register */
-		tom = ((inb(catbase + 0x4) & 0xf0) << 16)
-			+ ((inb(catbase + 0x5) & 0x7f) << 24);
-
-		if(inb(catbase) != VOYAGER_DINO) {
-			printk(KERN_ERR "Voyager: Failed to get DINO for L4, setting tom to EXT_MEM_K\n");
-			tom = (EXT_MEM_K)<<10;
-		}
-		who = "Voyager-TOM";
-		add_memory_region(0, 0x9f000, E820_RAM);
-		/* map from 1M to top of memory */
-		add_memory_region(1*1024*1024, tom - 1*1024*1024, E820_RAM);
-		/* FIXME: Should check the ASICs to see if I need to
-		 * take out the 8M window.  Just do it at the moment
-		 * */
-		add_memory_region(8*1024*1024, 8*1024*1024, E820_RESERVED);
-		return who;
-	}
-
-	who = "BIOS-e820";
-
-	/*
-	 * Try to copy the BIOS-supplied E820-map.
-	 *
-	 * Otherwise fake a memory map; one section from 0k->640k,
-	 * the next section from 1mb->appropriate_mem_k
-	 */
-	sanitize_e820_map(E820_MAP, &E820_MAP_NR);
-	if (copy_e820_map(E820_MAP, E820_MAP_NR) < 0) {
-		unsigned long mem_size;
-
-		/* compare results from other methods and take the greater */
-		if (ALT_MEM_K < EXT_MEM_K) {
-			mem_size = EXT_MEM_K;
-			who = "BIOS-88";
-		} else {
-			mem_size = ALT_MEM_K;
-			who = "BIOS-e801";
-		}
-
-		e820.nr_map = 0;
-		add_memory_region(0, LOWMEMSIZE(), E820_RAM);
-		add_memory_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
-  	}
-	return who;
-}
diff -Nru a/arch/i386/mach-voyager/setup_arch_pre.h b/arch/i386/mach-voyager/setup_arch_pre.h
--- a/arch/i386/mach-voyager/setup_arch_pre.h	Mon Dec 23 21:21:53 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,10 +0,0 @@
-#include <asm/voyager.h>
-#define VOYAGER_BIOS_INFO ((struct voyager_bios_info *)(PARAM+0x40))
-
-/* Hook to call BIOS initialisation function */
-
-/* for voyager, pass the voyager BIOS/SUS info area to the detection 
- * routines */
-
-#define ARCH_SETUP	voyager_detect(VOYAGER_BIOS_INFO);
-
diff -Nru a/arch/i386/mm/hugetlbpage.c b/arch/i386/mm/hugetlbpage.c
--- a/arch/i386/mm/hugetlbpage.c	Mon Dec 23 21:22:00 2002
+++ b/arch/i386/mm/hugetlbpage.c	Mon Dec 23 21:22:00 2002
@@ -84,7 +84,7 @@
 		spin_lock(&htlbpage_lock);
 		hugetlb_key = find_key(key);
 		if (!hugetlb_key) {
-			if (!capable(CAP_SYS_ADMIN) || !in_group_p(0))
+			if (!capable(CAP_SYS_ADMIN) || !capable(CAP_IPC_LOCK) || !in_group_p(0))
 				hugetlb_key = ERR_PTR(-EPERM);
 			else if (!(flag & IPC_CREAT))
 				hugetlb_key = ERR_PTR(-ENOENT);
@@ -110,7 +110,6 @@
 			hugetlb_key = ERR_PTR(-EAGAIN);
 			spin_unlock(&htlbpage_lock);
 		} else if (check_size_prot(hugetlb_key, len, prot, flag) < 0) {
-			hugetlb_key->key = 0;
 			hugetlb_key = ERR_PTR(-EINVAL);
 		} 
 	} while (hugetlb_key == ERR_PTR(-EAGAIN));
@@ -250,7 +249,7 @@
 		vma->vm_end = end;
 	}
 	spin_unlock(&mm->page_table_lock);
-      out_error1:
+out_error1:
 	return -1;
 }
 
@@ -262,7 +261,10 @@
 	struct page *ptepage;
 	unsigned long addr = vma->vm_start;
 	unsigned long end = vma->vm_end;
+	struct hugetlb_key *key = vma->vm_private_data;
 
+	if (key)
+		atomic_inc(&key->count);
 	while (addr < end) {
 		dst_pte = huge_pte_alloc(dst, addr);
 		if (!dst_pte)
@@ -355,6 +357,8 @@
 	spin_unlock(&htlbpage_lock);
 	for (address = start; address < end; address += HPAGE_SIZE) {
 		pte = huge_pte_offset(mm, address);
+		if (pte_none(*pte))
+			continue;
 		page = pte_page(*pte);
 		huge_page_release(page);
 		pte_clear(pte);
@@ -429,7 +433,6 @@
 		if (!page) {
 			page = alloc_hugetlb_page();
 			if (!page) {
-				spin_unlock(&key->lock);
 				ret = -ENOMEM;
 				goto out;
 			}
@@ -437,8 +440,8 @@
 		}
 		set_huge_pte(mm, vma, page, pte, vma->vm_flags & VM_WRITE);
 	}
-	spin_unlock(&key->lock);
 out:
+	spin_unlock(&key->lock);
 	spin_unlock(&mm->page_table_lock);
 	return ret;
 }
@@ -467,8 +470,6 @@
 	}
 
 	retval = prefault_key(hugetlb_key, vma);
-	if (retval)
-		goto out;
 
 	vma->vm_flags |= (VM_HUGETLB | VM_RESERVED);
 	vma->vm_ops = &hugetlb_vm_ops;
@@ -477,17 +478,6 @@
 	clear_key_busy(hugetlb_key);
 	spin_unlock(&htlbpage_lock);
 	return retval;
-out:
-	if (addr > vma->vm_start) {
-		unsigned long raddr;
-		raddr = vma->vm_end;
-		vma->vm_end = addr;
-		zap_hugepage_range(vma, vma->vm_start, vma->vm_end - vma->vm_start);
-		vma->vm_end = raddr;
-	}
-	spin_lock(&mm->page_table_lock);
-	do_munmap(mm, vma->vm_start, len);
-	spin_unlock(&mm->page_table_lock);
 out_release:
 	hugetlb_release_key(hugetlb_key);
 	return retval;
@@ -536,10 +526,8 @@
 
 static int alloc_private_hugetlb_pages(int key, unsigned long addr, unsigned long len, int prot, int flag)
 {
-	if (!capable(CAP_SYS_ADMIN)) {
-		if (!in_group_p(0))
-			return -EPERM;
-	}
+	if (!capable(CAP_IPC_LOCK) && !in_group_p(0))
+		return -EPERM;
 	addr = do_mmap_pgoff(NULL, addr, len, prot,
 			MAP_NORESERVE|MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, 0);
 	if (IS_ERR((void *) addr))
diff -Nru a/arch/i386/mm/init.c b/arch/i386/mm/init.c
--- a/arch/i386/mm/init.c	Mon Dec 23 21:21:59 2002
+++ b/arch/i386/mm/init.c	Mon Dec 23 21:21:59 2002
@@ -72,7 +72,7 @@
 static pte_t * __init one_page_table_init(pmd_t *pmd)
 {
 	pte_t *page_table = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
-	set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
+	set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
 	if (page_table != pte_offset_kernel(pmd, 0))
 		BUG();	
 
diff -Nru a/arch/i386/mm/pageattr.c b/arch/i386/mm/pageattr.c
--- a/arch/i386/mm/pageattr.c	Mon Dec 23 21:21:53 2002
+++ b/arch/i386/mm/pageattr.c	Mon Dec 23 21:21:53 2002
@@ -16,7 +16,12 @@
 static inline pte_t *lookup_address(unsigned long address) 
 { 
 	pgd_t *pgd = pgd_offset_k(address); 
-	pmd_t *pmd = pmd_offset(pgd, address); 	       
+	pmd_t *pmd;
+	if (pgd_none(*pgd))
+		return NULL;
+	pmd = pmd_offset(pgd, address); 	       
+	if (pmd_none(*pmd))
+		return NULL;
 	if (pmd_large(*pmd))
 		return (pte_t *)pmd;
         return pte_offset_kernel(pmd, address);
@@ -95,12 +100,13 @@
 	address = (unsigned long)page_address(page);
 
 	kpte = lookup_address(address);
+	if (!kpte)
+		return -EINVAL;
 	kpte_page = virt_to_page(((unsigned long)kpte) & PAGE_MASK);
 	if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) { 
 		if ((pte_val(*kpte) & _PAGE_PSE) == 0) { 
 			pte_t old = *kpte;
 			pte_t standard = mk_pte(page, PAGE_KERNEL); 
-
 			set_pte_atomic(kpte, mk_pte(page, prot)); 
 			if (pte_same(old,standard))
 				atomic_inc(&kpte_page->count);
@@ -108,6 +114,7 @@
 			struct page *split = split_large_page(address, prot); 
 			if (!split)
 				return -ENOMEM;
+			atomic_inc(&kpte_page->count);
 			set_pmd_pte(kpte,address,mk_pte(split, PAGE_KERNEL));
 		}	
 	} else if ((pte_val(*kpte) & _PAGE_PSE) == 0) { 
diff -Nru a/arch/i386/oprofile/init.c b/arch/i386/oprofile/init.c
--- a/arch/i386/oprofile/init.c	Mon Dec 23 21:21:56 2002
+++ b/arch/i386/oprofile/init.c	Mon Dec 23 21:21:56 2002
@@ -7,7 +7,6 @@
  * @author John Levon <levon@movementarian.org>
  */
 
-#include <linux/kernel.h>
 #include <linux/oprofile.h>
 #include <linux/init.h>
  
diff -Nru a/arch/i386/oprofile/nmi_int.c b/arch/i386/oprofile/nmi_int.c
--- a/arch/i386/oprofile/nmi_int.c	Mon Dec 23 21:22:00 2002
+++ b/arch/i386/oprofile/nmi_int.c	Mon Dec 23 21:22:00 2002
@@ -7,19 +7,13 @@
  * @author John Levon <levon@movementarian.org>
  */
 
-#include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/notifier.h>
 #include <linux/smp.h>
 #include <linux/oprofile.h>
-#include <linux/pm.h>
-#include <linux/thread_info.h>
 #include <asm/nmi.h>
-#include <asm/ptrace.h>
 #include <asm/msr.h>
 #include <asm/apic.h>
-#include <asm/bitops.h>
-#include <asm/processor.h>
  
 #include "op_counter.h"
 #include "op_x86_model.h"
@@ -27,7 +21,6 @@
 static struct op_x86_model_spec const * model;
 static struct op_msrs cpu_msrs[NR_CPUS];
 static unsigned long saved_lvtpc[NR_CPUS];
-static unsigned long kernel_only;
  
 static int nmi_start(void);
 static void nmi_stop(void);
@@ -53,10 +46,9 @@
 }
  
  
-// FIXME: kernel_only
 static int nmi_callback(struct pt_regs * regs, int cpu)
 {
-	return (model->check_ctrs(cpu, &cpu_msrs[cpu], regs));
+	return model->check_ctrs(cpu, &cpu_msrs[cpu], regs);
 }
  
  
@@ -210,7 +202,6 @@
 		oprofilefs_create_ulong(sb, dir, "user", &counter_config[i].user); 
 	}
 
-	oprofilefs_create_ulong(sb, root, "kernel_only", &kernel_only);
 	return 0;
 }
  
diff -Nru a/arch/ia64/Kconfig b/arch/ia64/Kconfig
--- a/arch/ia64/Kconfig	Mon Dec 23 21:22:00 2002
+++ b/arch/ia64/Kconfig	Mon Dec 23 21:22:00 2002
@@ -1,3 +1,8 @@
+#
+# For a description of the syntax of this configuration file,
+# see Documentation/kbuild/kconfig-language.txt.
+#
+
 mainmenu "IA-64 Linux Kernel Configuration"
 
 source "init/Kconfig"
@@ -215,6 +220,22 @@
 	  Access).  This option is for configuring high-end multiprocessor
 	  server systems.  If in doubt, say N.
 
+choice
+	prompt "Maximum Memory per NUMA Node" if NUMA && IA64_DIG
+	depends on NUMA && IA64_DIG
+	default IA64_NODESIZE_16GB
+
+config IA64_NODESIZE_16GB
+	bool "16GB"
+
+config IA64_NODESIZE_64GB
+	bool "64GB"
+
+config IA64_NODESIZE_256GB
+	bool "256GB"
+
+endchoice
+
 config DISCONTIGMEM
 	bool
 	depends on IA64_SGI_SN1 || IA64_SGI_SN2 || (IA64_GENERIC || IA64_DIG || IA64_HP_ZX1) && NUMA
@@ -225,6 +246,21 @@
 	  or have huge holes in the physical address space for other reasons.
 	  See <file:Documentation/vm/numa> for more.
 
+config VIRTUAL_MEM_MAP
+	bool "Enable Virtual Mem Map"
+	depends on !NUMA
+	default y if IA64_GENERIC || IA64_DIG || IA64_HP_ZX1
+	help
+	  Say Y to compile the kernel with support for a virtual mem map.
+	  This is an alternate method of supporting large holes in the
+	  physical address space on non NUMA machines. Since the DISCONTIGMEM
+	  option is not supported on machines with the ZX1 chipset, this is
+	  the only way of supporting more than 1 Gb of memory on those
+	  machines. This code also only takes effect if a memory hole of
+	  greater than 1 Gb is found during boot, so it is safe to enable
+	  unless you require the DISCONTIGMEM option for your machine. If you
+	  are unsure, say Y.
+
 config IA64_MCA
 	bool "Enable IA-64 Machine Check Abort" if IA64_GENERIC || IA64_DIG || IA64_HP_ZX1
 	default y if IA64_SGI_SN1 || IA64_SGI_SN2
@@ -396,6 +432,11 @@
 	  emulation support which makes it possible to transparently
 	  run IA-32 Linux binaries on an IA-64 Linux system.
 	  If in doubt, say Y.
+
+config COMPAT
+	bool
+	depends on IA32_SUPPORT
+	default y
 
 config PERFMON
 	bool "Performance monitor support"
diff -Nru a/arch/ia64/Makefile b/arch/ia64/Makefile
--- a/arch/ia64/Makefile	Mon Dec 23 21:21:50 2002
+++ b/arch/ia64/Makefile	Mon Dec 23 21:21:50 2002
@@ -5,76 +5,69 @@
 # License.  See the file "COPYING" in the main directory of this archive
 # for more details.
 #
-# Copyright (C) 1998-2001 by David Mosberger-Tang <davidm@hpl.hp.com>
+# Copyright (C) 1998-2002 by David Mosberger-Tang <davidm@hpl.hp.com>
 #
 
 NM := $(CROSS_COMPILE)nm -B
-AWK := awk
 
 export AWK
 
-OBJCOPYFLAGS := --strip-all
-LDFLAGS_vmlinux := -static
-AFLAGS_KERNEL := -mconstant-gp
-EXTRA	=
-
-CFLAGS := $(CFLAGS) -pipe $(EXTRA) -ffixed-r13 -mfixed-range=f10-f15,f32-f127 \
-	  -falign-functions=32
-# -ffunction-sections
-CFLAGS_KERNEL := -mconstant-gp
+OBJCOPYFLAGS	:= --strip-all
+LDFLAGS_vmlinux	:= -static
+AFLAGS_KERNEL	:= -mconstant-gp
+EXTRA		:=
+
+cflags-y	:= -pipe $(EXTRA) -ffixed-r13 -mfixed-range=f10-f15,f32-f127 \
+		   -falign-functions=32
+CFLAGS_KERNEL	:= -mconstant-gp
 
 GCC_VERSION=$(shell $(CC) -v 2>&1 | fgrep 'gcc version' | cut -f3 -d' ' | cut -f1 -d'.')
 
 ifneq ($(GCC_VERSION),2)
-	CFLAGS += -frename-registers --param max-inline-insns=5000
+	cflags-y += -frename-registers --param max-inline-insns=5000
 endif
 
-ifeq ($(CONFIG_ITANIUM_BSTEP_SPECIFIC),y)
-	CFLAGS += -mb-step
-endif
-
-HEAD := arch/$(ARCH)/kernel/head.o arch/$(ARCH)/kernel/init_task.o
-
-libs-y				+= arch/$(ARCH)/lib/
-core-y				+= arch/$(ARCH)/kernel/ arch/$(ARCH)/mm/
-core-$(CONFIG_IA32_SUPPORT)	+= arch/$(ARCH)/ia32/
-core-$(CONFIG_IA64_DIG) 	+= arch/$(ARCH)/dig/
-core-$(CONFIG_IA64_GENERIC) 	+= arch/$(ARCH)/dig/ arch/$(ARCH)/hp/common/ arch/$(ARCH)/hp/zx1/ \
-				   arch/$(ARCH)/hp/sim/
-core-$(CONFIG_IA64_HP_ZX1)	+= arch/$(ARCH)/dig/
-core-$(CONFIG_IA64_SGI_SN)	+= arch/$(ARCH)/sn/kernel arch/$(ARCH)/sn/io \
-				   arch/$(ARCH)/sn/fakeprom
-drivers-$(CONFIG_PCI)		+= arch/$(ARCH)/pci/
-drivers-$(CONFIG_IA64_HP_SIM)	+= arch/$(ARCH)/hp/sim/
-drivers-$(CONFIG_IA64_HP_ZX1)	+= arch/$(ARCH)/hp/common/ arch/$(ARCH)/hp/zx1/
-
-ifdef CONFIG_IA64_SGI_SN
-	CFLAGS			+= -DBRINGUP
-        SUBDIRS         	+= arch/$(ARCH)/sn/fakeprom
-endif
+cflags-$(CONFIG_ITANIUM_BSTEP_SPECIFIC)	+= -mb-step
+cflags-$(CONFIG_IA64_SGI_SN)		+= -DBRINGUP
 
-makeboot = $(call descend,arch/ia64/boot,$(1))
-maketool = $(call descend,arch/ia64/tools,$(1))
+CFLAGS += $(cflags-y)
+HEAD := arch/ia64/kernel/head.o arch/ia64/kernel/init_task.o
 
-.PHONY: compressed archclean archmrproper $(TOPDIR)/include/asm-ia64/offsets.h
+libs-y				+= arch/ia64/lib/
+core-y				+= arch/ia64/kernel/ arch/ia64/mm/
+core-$(CONFIG_IA32_SUPPORT)	+= arch/ia64/ia32/
+core-$(CONFIG_IA64_DIG) 	+= arch/ia64/dig/
+core-$(CONFIG_IA64_GENERIC) 	+= arch/ia64/dig/ arch/ia64/hp/common/ arch/ia64/hp/zx1/ \
+				   arch/ia64/hp/sim/
+core-$(CONFIG_IA64_HP_ZX1)	+= arch/ia64/dig/
+core-$(CONFIG_IA64_SGI_SN)	+= arch/ia64/sn/kernel/ \
+				   arch/ia64/sn/io/ \
+				   arch/ia64/sn/kernel/sn2/
+drivers-$(CONFIG_PCI)		+= arch/ia64/pci/
+drivers-$(CONFIG_IA64_HP_SIM)	+= arch/ia64/hp/sim/
+drivers-$(CONFIG_IA64_HP_ZX1)	+= arch/ia64/hp/common/ arch/ia64/hp/zx1/
+drivers-$(CONFIG_IA64_SGI_SN)	+= arch/ia64/sn/fakeprom/
+
+makeboot =$(Q)$(MAKE) -f scripts/Makefile.build obj=arch/ia64/boot $(1)
+maketool =$(Q)$(MAKE) -f scripts/Makefile.build obj=arch/ia64/tools $(1)
 
-all: compressed boot
+.PHONY: boot compressed archclean archmrproper include/asm-ia64/offsets.h
 
-boot: vmlinux
-	+@$(call makeboot,all)
+all compressed: vmlinux.gz
 
-compressed: vmlinux
-	$(OBJCOPY) $(OBJCOPYFLAGS) vmlinux vmlinux-tmp
-	gzip vmlinux-tmp
-	mv vmlinux-tmp.gz vmlinux.gz
+vmlinux.gz: vmlinux
+	$(call makeboot,vmlinux.gz)
 
+archmrproper:
 archclean:
-	$(MAKE) -rR -f scripts/Makefile.clean obj=arch/$(ARCH)/boot
+	$(Q)$(MAKE) -f scripts/Makefile.clean obj=arch/ia64/boot
 
-archmrproper:
+CLEAN_FILES += include/asm-ia64/offsets.h vmlinux.gz bootloader
+
+prepare: include/asm-ia64/offsets.h
 
-prepare: $(TOPDIR)/include/asm-ia64/offsets.h
+boot:	lib/lib.a vmlinux
+	$(call makeboot,$@)
 
-$(TOPDIR)/include/asm-ia64/offsets.h: include/asm include/linux/version.h \
-				      include/config/MARKER
-	+@$(call maketool,$@)
+include/asm-ia64/offsets.h: include/asm include/linux/version.h include/config/MARKER
+	$(call maketool,$@)
diff -Nru a/arch/ia64/boot/Makefile b/arch/ia64/boot/Makefile
--- a/arch/ia64/boot/Makefile	Mon Dec 23 21:21:56 2002
+++ b/arch/ia64/boot/Makefile	Mon Dec 23 21:21:56 2002
@@ -8,20 +8,33 @@
 # Copyright (C) 1998 by David Mosberger-Tang <davidm@hpl.hp.com>
 #
 
-LINKFLAGS = -static -T $(src)/bootloader.lds
+EXTRA_TARGETS := vmlinux.bin vmlinux.gz
 
-OBJS	= $(obj)/bootloader.o
+targets-$(CONFIG_IA64_HP_SIM)  += bootloader
+targets-$(CONFIG_IA64_GENERIC) += bootloader
+EXTRA_TARGETS += $(sort $(targets-y))
 
-targets-$(CONFIG_IA64_HP_SIM)	+= bootloader
-targets-$(CONFIG_IA64_GENERIC)	+= bootloader
+quiet_cmd_cptotop = LN      $@
+      cmd_cptotop = ln -f $< $@
 
-CFLAGS	:= $(CFLAGS) $(CFLAGS_KERNEL)
+vmlinux.gz: $(obj)/vmlinux.gz $(targets-y)
+	$(call cmd,cptotop)
+	@echo '  Kernel: $@ is ready'
 
-all:	$(targets-y)
+boot: bootloader
 
-bootloader: $(OBJS)
-	$(LD) $(LINKFLAGS) $(OBJS) $(TOPDIR)/lib/lib.a $(TOPDIR)/arch/$(ARCH)/lib/lib.a \
-	-o bootloader
+bootloader: $(obj)/bootloader
+	$(call cmd,cptotop)
 
-clean:
-	rm -f $(TARGETS)
+$(obj)/vmlinux.gz: $(obj)/vmlinux.bin FORCE
+	$(call if_changed,gzip)
+
+$(obj)/vmlinux.bin: vmlinux FORCE
+	$(call if_changed,objcopy)
+
+
+LDFLAGS_bootloader = -static -T
+
+$(obj)/bootloader: $(src)/bootloader.lds $(obj)/bootloader.o \
+                   lib/lib.a arch/ia64/lib/lib.a FORCE
+	$(call if_changed,ld)
diff -Nru a/arch/ia64/boot/bootloader.c b/arch/ia64/boot/bootloader.c
--- a/arch/ia64/boot/bootloader.c	Mon Dec 23 21:22:00 2002
+++ b/arch/ia64/boot/bootloader.c	Mon Dec 23 21:22:00 2002
@@ -3,12 +3,14 @@
  *
  * Loads an ELF kernel.
  *
- * Copyright (C) 1998, 1999, 2001 Hewlett-Packard Co
- * Copyright (C) 1998, 1999, 2001 David Mosberger-Tang <davidm@hpl.hp.com>
- * Copyright (C) 1998, 1999 Stephane Eranian <eranian@hpl.hp.com>
+ * Copyright (C) 1998-2002 Hewlett-Packard Co
+ *	David Mosberger-Tang <davidm@hpl.hp.com>
+ *	Stephane Eranian <eranian@hpl.hp.com>
  *
  * 01/07/99 S.Eranian modified to pass command line arguments to kernel
  */
+struct task_struct;	/* forward declaration for elf.h */
+
 #include <linux/config.h>
 #include <linux/elf.h>
 #include <linux/init.h>
@@ -53,6 +55,15 @@
 
 #include "../kernel/fw-emu.c"
 
+/*
+ * Set a break point on this function so that symbols are available to set breakpoints in
+ * the kernel being debugged.
+ */
+static void
+debug_break (void)
+{
+}
+
 static void
 cons_write (const char *buf)
 {
@@ -187,6 +198,7 @@
 
 	ssc(0, (long) kpath, 0, 0, SSC_LOAD_SYMBOLS);
 
+	debug_break();
 	asm volatile ("mov sp=%2; mov r28=%1; br.sptk.few %0"
 		      :: "b"(e_entry), "r"(bp), "r"(__pa(&stack)));
 
diff -Nru a/arch/ia64/hp/sim/simscsi.c b/arch/ia64/hp/sim/simscsi.c
--- a/arch/ia64/hp/sim/simscsi.c	Mon Dec 23 21:21:54 2002
+++ b/arch/ia64/hp/sim/simscsi.c	Mon Dec 23 21:21:54 2002
@@ -23,7 +23,7 @@
 #include "../drivers/scsi/hosts.h"
 #include "simscsi.h"
 
-#define DEBUG_SIMSCSI	1
+#define DEBUG_SIMSCSI	0
 
 /* Simulator system calls: */
 
@@ -377,6 +377,12 @@
 	return 0;
 }
 
+int
+simscsi_host_reset (Scsi_Cmnd *sc)
+{
+	printk ("simscsi_host_reset: not implemented\n");
+	return 0;
+}
 
 static Scsi_Host_Template driver_template = SIMSCSI;
 
diff -Nru a/arch/ia64/hp/sim/simscsi.h b/arch/ia64/hp/sim/simscsi.h
--- a/arch/ia64/hp/sim/simscsi.h	Mon Dec 23 21:21:50 2002
+++ b/arch/ia64/hp/sim/simscsi.h	Mon Dec 23 21:21:50 2002
@@ -1,7 +1,7 @@
 /*
  * Simulated SCSI driver.
  *
- * Copyright (C) 1999 Hewlett-Packard Co
+ * Copyright (C) 1999, 2002 Hewlett-Packard Co
  *	David Mosberger-Tang <davidm@hpl.hp.com>
  */
 #ifndef SIMSCSI_H
@@ -21,14 +21,17 @@
 		sector_t, int[]);
 
 #define SIMSCSI {						\
+	.name			= "simscsi",			\
 	.detect			= simscsi_detect,		\
 	.release		= simscsi_release,		\
 	.info			= simscsi_info,			\
 	.queuecommand		= simscsi_queuecommand,		\
+	.eh_host_reset_handler	= simscsi_host_reset,		\
 	.bios_param		= simscsi_biosparam,		\
 	.can_queue		= SIMSCSI_REQ_QUEUE_LEN,	\
 	.this_id		= -1,				\
 	.sg_tablesize		= SG_ALL,			\
+	.max_sectors		= 1024,				\
 	.cmd_per_lun		= SIMSCSI_REQ_QUEUE_LEN,	\
 	.present		= 0,				\
 	.unchecked_isa_dma	= 0,				\
diff -Nru a/arch/ia64/hp/zx1/hpzx1_misc.c b/arch/ia64/hp/zx1/hpzx1_misc.c
--- a/arch/ia64/hp/zx1/hpzx1_misc.c	Mon Dec 23 21:21:54 2002
+++ b/arch/ia64/hp/zx1/hpzx1_misc.c	Mon Dec 23 21:21:54 2002
@@ -180,7 +180,6 @@
 	list_add_tail(&dev->bus_list, &bus->devices);
 	list_add_tail(&dev->global_list, &pci_devices);
 
-	strcpy(dev->dev.name, dev->name);
 	strcpy(dev->dev.bus_id, dev->slot_name);
 	ret = device_register(&dev->dev);
 	if (ret < 0)
@@ -335,7 +334,7 @@
 
 extern void sba_init(void);
 
-static void
+static int
 hpzx1_init (void)
 {
 	/* zx1 has a hardware I/O TLB which lets us DMA from any device to any address */
@@ -343,6 +342,7 @@
 
 	hpzx1_acpi_dev_init();
 	sba_init();
+	return 0;
 }
 
 subsys_initcall(hpzx1_init);
diff -Nru a/arch/ia64/ia32/Makefile b/arch/ia64/ia32/Makefile
--- a/arch/ia64/ia32/Makefile	Mon Dec 23 21:21:57 2002
+++ b/arch/ia64/ia32/Makefile	Mon Dec 23 21:21:57 2002
@@ -2,5 +2,5 @@
 # Makefile for the ia32 kernel emulation subsystem.
 #
 
-obj-y := ia32_entry.o sys_ia32.o ia32_ioctl.o ia32_signal.o ia32_support.o ia32_traps.o \
-	 binfmt_elf32.o ia32_ldt.o
+obj-y := ia32_entry.o sys_ia32.o ia32_ioctl.o ia32_signal.o \
+	 ia32_support.o ia32_traps.o binfmt_elf32.o ia32_ldt.o
diff -Nru a/arch/ia64/ia32/binfmt_elf32.c b/arch/ia64/ia32/binfmt_elf32.c
--- a/arch/ia64/ia32/binfmt_elf32.c	Mon Dec 23 21:22:00 2002
+++ b/arch/ia64/ia32/binfmt_elf32.c	Mon Dec 23 21:22:00 2002
@@ -162,9 +162,11 @@
 {
 	unsigned long stack_base;
 	struct vm_area_struct *mpnt;
+	struct mm_struct *mm = current->mm;
 	int i;
 
 	stack_base = IA32_STACK_TOP - MAX_ARG_PAGES*PAGE_SIZE;
+	mm->arg_start = bprm->p + stack_base;
 
 	bprm->p += stack_base;
 	if (bprm->loader)
@@ -174,6 +176,11 @@
 	mpnt = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
 	if (!mpnt)
 		return -ENOMEM;
+
+	if (!vm_enough_memory((IA32_STACK_TOP - (PAGE_MASK & (unsigned long) bprm->p))>>PAGE_SHIFT)) {
+		kmem_cache_free(vm_area_cachep, mpnt);
+		return -ENOMEM;
+	}
 
 	down_write(&current->mm->mmap_sem);
 	{
diff -Nru a/arch/ia64/ia32/ia32_entry.S b/arch/ia64/ia32/ia32_entry.S
--- a/arch/ia64/ia32/ia32_entry.S	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/ia32/ia32_entry.S	Mon Dec 23 21:21:55 2002
@@ -196,7 +196,7 @@
 	data8 sys32_fork
 	data8 sys_read
 	data8 sys_write
-	data8 sys_open		  /* 5 */
+	data8 sys32_open	  /* 5 */
 	data8 sys_close
 	data8 sys32_waitpid
 	data8 sys_creat
@@ -221,7 +221,7 @@
 	data8 sys32_alarm
 	data8 sys32_ni_syscall
 	data8 sys32_pause
-	data8 sys32_utime	  /* 30 */
+	data8 compat_sys_utime	  /* 30 */
 	data8 sys32_ni_syscall	  /* old stty syscall holder */
 	data8 sys32_ni_syscall	  /* old gtty syscall holder */
 	data8 sys_access
@@ -234,7 +234,7 @@
 	data8 sys_rmdir		  /* 40 */
 	data8 sys_dup
 	data8 sys32_pipe
-	data8 sys32_times
+	data8 compat_sys_times
 	data8 sys32_ni_syscall	  /* old prof syscall holder */
 	data8 sys32_brk		  /* 45 */
 	data8 sys_setgid	/* 16-bit version */
@@ -295,11 +295,11 @@
 	data8 sys32_ioperm
 	data8 sys32_socketcall
 	data8 sys_syslog
-	data8 sys32_setitimer
-	data8 sys32_getitimer	  /* 105 */
-	data8 sys32_newstat
-	data8 sys32_newlstat
-	data8 sys32_newfstat
+	data8 compat_sys_setitimer
+	data8 compat_sys_getitimer	  /* 105 */
+	data8 compat_sys_newstat
+	data8 compat_sys_newlstat
+	data8 compat_sys_newfstat
 	data8 sys32_ni_syscall
 	data8 sys32_iopl		  /* 110 */
 	data8 sys_vhangup
@@ -353,7 +353,7 @@
 	data8 sys_sched_get_priority_max
 	data8 sys_sched_get_priority_min	 /* 160 */
 	data8 sys32_sched_rr_get_interval
-	data8 sys32_nanosleep
+	data8 compat_sys_nanosleep
 	data8 sys_mremap
 	data8 sys_setresuid	/* 16-bit version */
 	data8 sys32_getresuid16	/* 16-bit version */	  /* 165 */
diff -Nru a/arch/ia64/ia32/ia32_signal.c b/arch/ia64/ia32/ia32_signal.c
--- a/arch/ia64/ia32/ia32_signal.c	Mon Dec 23 21:21:50 2002
+++ b/arch/ia64/ia32/ia32_signal.c	Mon Dec 23 21:21:50 2002
@@ -22,6 +22,7 @@
 #include <linux/stddef.h>
 #include <linux/unistd.h>
 #include <linux/wait.h>
+#include <linux/compat.h>
 
 #include <asm/uaccess.h>
 #include <asm/rse.h>
@@ -165,10 +166,10 @@
  *    sw         ar.fsr(0:15)
  *    tag        ar.fsr(16:31)               with odd numbered bits not used
  *                                           (read returns 0, writes ignored)
- *    ipoff      ar.fir(0:31)   RO
- *    cssel      ar.fir(32:47)  RO
- *    dataoff    ar.fdr(0:31)   RO
- *    datasel    ar.fdr(32:47)  RO
+ *    ipoff      ar.fir(0:31)
+ *    cssel      ar.fir(32:47)
+ *    dataoff    ar.fdr(0:31)
+ *    datasel    ar.fdr(32:47)
  *
  *    _st[(0+TOS)%8]   f8
  *    _st[(1+TOS)%8]   f9                    (f8, f9 from ptregs)
@@ -328,7 +329,7 @@
 	unsigned long num64, mxcsr;
 	struct _fpreg_ia32 *fpregp;
 	char buf[32];
-	unsigned long fsr, fcr;
+	unsigned long fsr, fcr, fir, fdr;
 	int fp_tos, fr8_st_map;
 
 	if (!access_ok(VERIFY_READ, save, sizeof(*save)))
@@ -345,6 +346,8 @@
 	 */
 	asm volatile ( "mov %0=ar.fsr;" : "=r"(fsr));
 	asm volatile ( "mov %0=ar.fcr;" : "=r"(fcr));
+	asm volatile ( "mov %0=ar.fir;" : "=r"(fir));
+	asm volatile ( "mov %0=ar.fdr;" : "=r"(fdr));
 
 	__get_user(mxcsr, (unsigned int *)&save->mxcsr);
 	/* setting bits 0..5 8..12 with cw and 39..47 from mxcsr */
@@ -355,14 +358,34 @@
 
 	/* setting bits 0..31 with sw and tag and 32..37 from mxcsr */
 	__get_user(lo, (unsigned int *)&save->sw);
+	/* set bits 15,7 (fsw.b, fsw.es) to reflect the current error status */
+	if ( !(lo & 0x7f) )
+		lo &= (~0x8080);
 	__get_user(hi, (unsigned int *)&save->tag);
 	num64 = mxcsr & 0x3f;
 	num64 = (num64 << 16) | (hi & 0xffff);
 	num64 = (num64 << 16) | (lo & 0xffff);
 	fsr = (fsr & (~0x3fffffffff)) | num64;
 
+	/* setting bits 0..47 with cssel and ipoff */
+	__get_user(lo, (unsigned int *)&save->ipoff);
+	__get_user(hi, (unsigned int *)&save->cssel);
+	num64 = hi & 0xffff;
+	num64 = (num64 << 32) | lo;
+	fir = (fir & (~0xffffffffffff)) | num64;
+
+	/* setting bits 0..47 with datasel and dataoff */
+	__get_user(lo, (unsigned int *)&save->dataoff);
+	__get_user(hi, (unsigned int *)&save->datasel);
+	num64 = hi & 0xffff;
+	num64 = (num64 << 32) | lo;
+	fdr = (fdr & (~0xffffffffffff)) | num64;
+
 	asm volatile ( "mov ar.fsr=%0;" :: "r"(fsr));
 	asm volatile ( "mov ar.fcr=%0;" :: "r"(fcr));
+	asm volatile ( "mov ar.fir=%0;" :: "r"(fir));
+	asm volatile ( "mov ar.fdr=%0;" :: "r"(fdr));
+
 	/*
 	 * restore f8, f9 onto pt_regs
 	 * restore f10..f15 onto live registers
@@ -570,8 +593,8 @@
 }
 
 asmlinkage long
-sys32_rt_sigtimedwait (sigset32_t *uthese, siginfo_t32 *uinfo, struct timespec32 *uts,
-		       unsigned int sigsetsize)
+sys32_rt_sigtimedwait (sigset32_t *uthese, siginfo_t32 *uinfo,
+		struct compat_timespec *uts, unsigned int sigsetsize)
 {
 	extern asmlinkage long sys_rt_sigtimedwait (const sigset_t *, siginfo_t *,
 						    const struct timespec *, size_t);
diff -Nru a/arch/ia64/ia32/sys_ia32.c b/arch/ia64/ia32/sys_ia32.c
--- a/arch/ia64/ia32/sys_ia32.c	Mon Dec 23 21:21:57 2002
+++ b/arch/ia64/ia32/sys_ia32.c	Mon Dec 23 21:21:57 2002
@@ -20,7 +20,6 @@
 #include <linux/fs.h>
 #include <linux/file.h>
 #include <linux/signal.h>
-#include <linux/utime.h>
 #include <linux/resource.h>
 #include <linux/times.h>
 #include <linux/utsname.h>
@@ -38,7 +37,6 @@
 #include <linux/smb_mount.h>
 #include <linux/ncp_fs.h>
 #include <linux/quota.h>
-#include <linux/module.h>
 #include <linux/sunrpc/svc.h>
 #include <linux/nfsd/nfsd.h>
 #include <linux/nfsd/cache.h>
@@ -49,6 +47,7 @@
 #include <linux/ptrace.h>
 #include <linux/stat.h>
 #include <linux/ipc.h>
+#include <linux/compat.h>
 
 #include <asm/types.h>
 #include <asm/uaccess.h>
@@ -175,8 +174,7 @@
 	return r;
 }
 
-static inline int
-putstat (struct stat32 *ubuf, struct kstat *stat)
+int cp_compat_stat(struct kstat *stat, struct compat_stat *ubuf)
 {
 	int err;
 
@@ -194,50 +192,17 @@
 	err |= __put_user(high2lowgid(stat->gid), &ubuf->st_gid);
 	err |= __put_user(stat->rdev, &ubuf->st_rdev);
 	err |= __put_user(stat->size, &ubuf->st_size);
-	err |= __put_user(stat->atime, &ubuf->st_atime);
-	err |= __put_user(stat->mtime, &ubuf->st_mtime);
-	err |= __put_user(stat->ctime, &ubuf->st_ctime);
+	err |= __put_user(stat->atime.tv_sec, &ubuf->st_atime);
+	err |= __put_user(stat->atime.tv_nsec, &ubuf->st_atime_nsec);
+	err |= __put_user(stat->mtime.tv_sec, &ubuf->st_mtime);
+	err |= __put_user(stat->mtime.tv_nsec, &ubuf->st_mtime_nsec);
+	err |= __put_user(stat->ctime.tv_sec, &ubuf->st_ctime);
+	err |= __put_user(stat->ctime.tv_nsec, &ubuf->st_ctime_nsec);
 	err |= __put_user(stat->blksize, &ubuf->st_blksize);
 	err |= __put_user(stat->blocks, &ubuf->st_blocks);
 	return err;
 }
 
-asmlinkage long
-sys32_newstat (char *filename, struct stat32 *statbuf)
-{
-	struct kstat stat;
-	int ret = vfs_stat(filename, &stat);
-
-	if (!ret)
-		ret = putstat(statbuf, &stat);
-
-	return ret;
-}
-
-asmlinkage long
-sys32_newlstat (char *filename, struct stat32 *statbuf)
-{
-	struct kstat stat;
-	int ret = vfs_lstat(filename, &stat);
-
-	if (!ret)
-		ret = putstat(statbuf, &stat);
-
-	return ret;
-}
-
-asmlinkage long
-sys32_newfstat (unsigned int fd, struct stat32 *statbuf)
-{
-	struct kstat stat;
-	int ret = vfs_fstat(fd, &stat);
-
-	if (!ret)
-		ret = putstat(statbuf, &stat);
-
-	return ret;
-}
-
 #if PAGE_SHIFT > IA32_PAGE_SHIFT
 
 
@@ -616,7 +581,8 @@
 			/* end address is 4KB aligned but not page aligned. */
 			retval = mprotect_subpage(PAGE_START(end), prot);
 			if (retval < 0)
-				return retval;
+				goto out;
+
 			end = PAGE_START(end);
 		}
 		retval = sys_mprotect(start, end - start, prot);
@@ -697,90 +663,20 @@
 	return ret;
 }
 
-struct timeval32
-{
-    int tv_sec, tv_usec;
-};
-
-struct itimerval32
-{
-    struct timeval32 it_interval;
-    struct timeval32 it_value;
-};
-
 static inline long
-get_tv32 (struct timeval *o, struct timeval32 *i)
+get_tv32 (struct timeval *o, struct compat_timeval *i)
 {
 	return (!access_ok(VERIFY_READ, i, sizeof(*i)) ||
 		(__get_user(o->tv_sec, &i->tv_sec) | __get_user(o->tv_usec, &i->tv_usec)));
 }
 
 static inline long
-put_tv32 (struct timeval32 *o, struct timeval *i)
+put_tv32 (struct compat_timeval *o, struct timeval *i)
 {
 	return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
 		(__put_user(i->tv_sec, &o->tv_sec) | __put_user(i->tv_usec, &o->tv_usec)));
 }
 
-static inline long
-get_it32 (struct itimerval *o, struct itimerval32 *i)
-{
-	return (!access_ok(VERIFY_READ, i, sizeof(*i)) ||
-		(__get_user(o->it_interval.tv_sec, &i->it_interval.tv_sec) |
-		 __get_user(o->it_interval.tv_usec, &i->it_interval.tv_usec) |
-		 __get_user(o->it_value.tv_sec, &i->it_value.tv_sec) |
-		 __get_user(o->it_value.tv_usec, &i->it_value.tv_usec)));
-}
-
-static inline long
-put_it32 (struct itimerval32 *o, struct itimerval *i)
-{
-	return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
-		(__put_user(i->it_interval.tv_sec, &o->it_interval.tv_sec) |
-		 __put_user(i->it_interval.tv_usec, &o->it_interval.tv_usec) |
-		 __put_user(i->it_value.tv_sec, &o->it_value.tv_sec) |
-		 __put_user(i->it_value.tv_usec, &o->it_value.tv_usec)));
-}
-
-extern int do_getitimer (int which, struct itimerval *value);
-
-asmlinkage long
-sys32_getitimer (int which, struct itimerval32 *it)
-{
-	struct itimerval kit;
-	int error;
-
-	error = do_getitimer(which, &kit);
-	if (!error && put_it32(it, &kit))
-		error = -EFAULT;
-
-	return error;
-}
-
-extern int do_setitimer (int which, struct itimerval *, struct itimerval *);
-
-asmlinkage long
-sys32_setitimer (int which, struct itimerval32 *in, struct itimerval32 *out)
-{
-	struct itimerval kin, kout;
-	int error;
-
-	if (in) {
-		if (get_it32(&kin, in))
-			return -EFAULT;
-	} else
-		memset(&kin, 0, sizeof(kin));
-
-	error = do_setitimer(which, &kin, out ? &kout : NULL);
-	if (error || !out)
-		return error;
-	if (put_it32(out, &kout))
-		return -EFAULT;
-
-	return 0;
-
-}
-
 asmlinkage unsigned long
 sys32_alarm (unsigned int seconds)
 {
@@ -802,42 +698,11 @@
 /* Translations due to time_t size differences.  Which affects all
    sorts of things, like timeval and itimerval.  */
 
-struct utimbuf_32 {
-	int	atime;
-	int	mtime;
-};
-
-extern asmlinkage long sys_utimes(char * filename, struct timeval * utimes);
-extern asmlinkage long sys_gettimeofday (struct timeval *tv, struct timezone *tz);
-
-asmlinkage long
-sys32_utime (char *filename, struct utimbuf_32 *times32)
-{
-	mm_segment_t old_fs = get_fs();
-	struct timeval tv[2], *tvp;
-	long ret;
-
-	if (times32) {
-		if (get_user(tv[0].tv_sec, &times32->atime))
-			return -EFAULT;
-		tv[0].tv_usec = 0;
-		if (get_user(tv[1].tv_sec, &times32->mtime))
-			return -EFAULT;
-		tv[1].tv_usec = 0;
-		set_fs(KERNEL_DS);
-		tvp = tv;
-	} else
-		tvp = NULL;
-	ret = sys_utimes(filename, tvp);
-	set_fs(old_fs);
-	return ret;
-}
-
 extern struct timezone sys_tz;
 extern int do_sys_settimeofday (struct timeval *tv, struct timezone *tz);
 
 asmlinkage long
-sys32_gettimeofday (struct timeval32 *tv, struct timezone *tz)
+sys32_gettimeofday (struct compat_timeval *tv, struct timezone *tz)
 {
 	if (tv) {
 		struct timeval ktv;
@@ -853,7 +718,7 @@
 }
 
 asmlinkage long
-sys32_settimeofday (struct timeval32 *tv, struct timezone *tz)
+sys32_settimeofday (struct compat_timeval *tv, struct timezone *tz)
 {
 	struct timeval ktv;
 	struct timezone ktz;
@@ -1003,7 +868,7 @@
 #define ROUND_UP_TIME(x,y) (((x)+(y)-1)/(y))
 
 asmlinkage long
-sys32_select (int n, fd_set *inp, fd_set *outp, fd_set *exp, struct timeval32 *tvp32)
+sys32_select (int n, fd_set *inp, fd_set *outp, fd_set *exp, struct compat_timeval *tvp32)
 {
 	fd_set_bits fds;
 	char *bits;
@@ -1110,28 +975,7 @@
 	if (copy_from_user(&a, arg, sizeof(a)))
 		return -EFAULT;
 	return sys32_select(a.n, (fd_set *) A(a.inp), (fd_set *) A(a.outp), (fd_set *) A(a.exp),
-			    (struct timeval32 *) A(a.tvp));
-}
-
-extern asmlinkage long sys_nanosleep (struct timespec *rqtp, struct timespec *rmtp);
-
-asmlinkage long
-sys32_nanosleep (struct timespec32 *rqtp, struct timespec32 *rmtp)
-{
-	struct timespec t;
-	int ret;
-	mm_segment_t old_fs = get_fs();
-
-	if (get_user (t.tv_sec, &rqtp->tv_sec) || get_user (t.tv_nsec, &rqtp->tv_nsec))
-		return -EFAULT;
-	set_fs(KERNEL_DS);
-	ret = sys_nanosleep(&t, rmtp ? &t : NULL);
-	set_fs(old_fs);
-	if (rmtp && ret == -EINTR) {
-		if (put_user(t.tv_sec, &rmtp->tv_sec) || put_user(t.tv_nsec, &rmtp->tv_nsec))
-			return -EFAULT;
-	}
-	return ret;
+			    (struct compat_timeval *) A(a.tvp));
 }
 
 struct iovec32 { unsigned int iov_base; int iov_len; };
@@ -1304,7 +1148,7 @@
 };
 
 struct cmsghdr32 {
-	__kernel_size_t32 cmsg_len;
+	compat_size_t cmsg_len;
 	int               cmsg_level;
 	int               cmsg_type;
 };
@@ -1369,7 +1213,7 @@
 {
 	struct cmsghdr *kcmsg, *kcmsg_base;
 	__kernel_size_t kcmlen, tmp;
-	__kernel_size_t32 ucmlen;
+	compat_size_t ucmlen;
 	struct cmsghdr32 *ucmsg;
 	long err;
 
@@ -1893,10 +1737,10 @@
 extern asmlinkage long sys_getpeername(int fd, struct sockaddr *usockaddr,
 				      int *usockaddr_len);
 extern asmlinkage long sys_send(int fd, void *buff, size_t len, unsigned flags);
-extern asmlinkage long sys_sendto(int fd, u32 buff, __kernel_size_t32 len,
+extern asmlinkage long sys_sendto(int fd, u32 buff, compat_size_t len,
 				   unsigned flags, u32 addr, int addr_len);
 extern asmlinkage long sys_recv(int fd, void *ubuf, size_t size, unsigned flags);
-extern asmlinkage long sys_recvfrom(int fd, u32 ubuf, __kernel_size_t32 size,
+extern asmlinkage long sys_recvfrom(int fd, u32 ubuf, compat_size_t size,
 				     unsigned flags, u32 addr, u32 addr_len);
 extern asmlinkage long sys_setsockopt(int fd, int level, int optname,
 				     char *optval, int optlen);
@@ -1994,11 +1838,11 @@
 
 struct ipc_perm32 {
 	key_t key;
-	__kernel_uid_t32 uid;
-	__kernel_gid_t32 gid;
-	__kernel_uid_t32 cuid;
-	__kernel_gid_t32 cgid;
-	__kernel_mode_t32 mode;
+	compat_uid_t uid;
+	compat_gid_t gid;
+	compat_uid_t cuid;
+	compat_gid_t cgid;
+	compat_mode_t mode;
 	unsigned short seq;
 };
 
@@ -2008,7 +1852,7 @@
 	__kernel_gid32_t32 gid;
 	__kernel_uid32_t32 cuid;
 	__kernel_gid32_t32 cgid;
-	__kernel_mode_t32 mode;
+	compat_mode_t mode;
 	unsigned short __pad1;
 	unsigned short seq;
 	unsigned short __pad2;
@@ -2018,8 +1862,8 @@
 
 struct semid_ds32 {
 	struct ipc_perm32 sem_perm;               /* permissions .. see ipc.h */
-	__kernel_time_t32 sem_otime;              /* last semop time */
-	__kernel_time_t32 sem_ctime;              /* last change time */
+	compat_time_t   sem_otime;              /* last semop time */
+	compat_time_t   sem_ctime;              /* last change time */
 	u32 sem_base;              /* ptr to first semaphore in array */
 	u32 sem_pending;          /* pending operations to be processed */
 	u32 sem_pending_last;    /* last pending operation */
@@ -2029,9 +1873,9 @@
 
 struct semid64_ds32 {
 	struct ipc64_perm32 sem_perm;
-	__kernel_time_t32 sem_otime;
+	compat_time_t   sem_otime;
 	unsigned int __unused1;
-	__kernel_time_t32 sem_ctime;
+	compat_time_t   sem_ctime;
 	unsigned int __unused2;
 	unsigned int sem_nsems;
 	unsigned int __unused3;
@@ -2042,9 +1886,9 @@
 	struct ipc_perm32 msg_perm;
 	u32 msg_first;
 	u32 msg_last;
-	__kernel_time_t32 msg_stime;
-	__kernel_time_t32 msg_rtime;
-	__kernel_time_t32 msg_ctime;
+	compat_time_t   msg_stime;
+	compat_time_t   msg_rtime;
+	compat_time_t   msg_ctime;
 	u32 wwait;
 	u32 rwait;
 	unsigned short msg_cbytes;
@@ -2056,17 +1900,17 @@
 
 struct msqid64_ds32 {
 	struct ipc64_perm32 msg_perm;
-	__kernel_time_t32 msg_stime;
+	compat_time_t   msg_stime;
 	unsigned int __unused1;
-	__kernel_time_t32 msg_rtime;
+	compat_time_t   msg_rtime;
 	unsigned int __unused2;
-	__kernel_time_t32 msg_ctime;
+	compat_time_t   msg_ctime;
 	unsigned int __unused3;
 	unsigned int msg_cbytes;
 	unsigned int msg_qnum;
 	unsigned int msg_qbytes;
-	__kernel_pid_t32 msg_lspid;
-	__kernel_pid_t32 msg_lrpid;
+	compat_pid_t msg_lspid;
+	compat_pid_t msg_lrpid;
 	unsigned int __unused4;
 	unsigned int __unused5;
 };
@@ -2074,9 +1918,9 @@
 struct shmid_ds32 {
 	struct ipc_perm32 shm_perm;
 	int shm_segsz;
-	__kernel_time_t32 shm_atime;
-	__kernel_time_t32 shm_dtime;
-	__kernel_time_t32 shm_ctime;
+	compat_time_t   shm_atime;
+	compat_time_t   shm_dtime;
+	compat_time_t   shm_ctime;
 	__kernel_ipc_pid_t32 shm_cpid;
 	__kernel_ipc_pid_t32 shm_lpid;
 	unsigned short shm_nattch;
@@ -2084,15 +1928,15 @@
 
 struct shmid64_ds32 {
 	struct ipc64_perm shm_perm;
-	__kernel_size_t32 shm_segsz;
-	__kernel_time_t32 shm_atime;
+	compat_size_t shm_segsz;
+	compat_time_t   shm_atime;
 	unsigned int __unused1;
-	__kernel_time_t32 shm_dtime;
+	compat_time_t   shm_dtime;
 	unsigned int __unused2;
-	__kernel_time_t32 shm_ctime;
+	compat_time_t   shm_ctime;
 	unsigned int __unused3;
-	__kernel_pid_t32 shm_cpid;
-	__kernel_pid_t32 shm_lpid;
+	compat_pid_t shm_cpid;
+	compat_pid_t shm_lpid;
 	unsigned int shm_nattch;
 	unsigned int __unused4;
 	unsigned int __unused5;
@@ -2615,8 +2459,8 @@
 }
 
 struct rusage32 {
-	struct timeval32 ru_utime;
-	struct timeval32 ru_stime;
+	struct compat_timeval ru_utime;
+	struct compat_timeval ru_stime;
 	int    ru_maxrss;
 	int    ru_ixrss;
 	int    ru_idrss;
@@ -2708,37 +2552,6 @@
 	return ret;
 }
 
-struct tms32 {
-	__kernel_clock_t32 tms_utime;
-	__kernel_clock_t32 tms_stime;
-	__kernel_clock_t32 tms_cutime;
-	__kernel_clock_t32 tms_cstime;
-};
-
-extern asmlinkage long sys_times (struct tms * tbuf);
-
-asmlinkage long
-sys32_times (struct tms32 *tbuf)
-{
-	mm_segment_t old_fs = get_fs();
-	struct tms t;
-	long ret;
-	int err;
-
-	set_fs(KERNEL_DS);
-	ret = sys_times(tbuf ? &t : NULL);
-	set_fs(old_fs);
-	if (tbuf) {
-		err = put_user (IA32_TICK(t.tms_utime), &tbuf->tms_utime);
-		err |= put_user (IA32_TICK(t.tms_stime), &tbuf->tms_stime);
-		err |= put_user (IA32_TICK(t.tms_cutime), &tbuf->tms_cutime);
-		err |= put_user (IA32_TICK(t.tms_cstime), &tbuf->tms_cstime);
-		if (err)
-			ret = -EFAULT;
-	}
-	return IA32_TICK(ret);
-}
-
 static unsigned int
 ia32_peek (struct pt_regs *regs, struct task_struct *child, unsigned long addr, unsigned int *val)
 {
@@ -2899,57 +2712,152 @@
 }
 
 static int
-save_ia32_fpstate (struct task_struct *tsk, struct _fpstate_ia32 *save)
+save_ia32_fpstate (struct task_struct *tsk, struct ia32_user_i387_struct *save)
 {
 	struct switch_stack *swp;
 	struct pt_regs *ptp;
 	int i, tos;
 
 	if (!access_ok(VERIFY_WRITE, save, sizeof(*save)))
-		return -EIO;
-	__put_user(tsk->thread.fcr, &save->cw);
-	__put_user(tsk->thread.fsr, &save->sw);
-	__put_user(tsk->thread.fsr >> 32, &save->tag);
-	__put_user(tsk->thread.fir, &save->ipoff);
-	__put_user(__USER_CS, &save->cssel);
-	__put_user(tsk->thread.fdr, &save->dataoff);
-	__put_user(__USER_DS, &save->datasel);
+		return -EFAULT;
+
+	__put_user(tsk->thread.fcr & 0xffff, &save->cwd);
+	__put_user(tsk->thread.fsr & 0xffff, &save->swd);
+	__put_user((tsk->thread.fsr>>16) & 0xffff, &save->twd);
+	__put_user(tsk->thread.fir, &save->fip);
+	__put_user((tsk->thread.fir>>32) & 0xffff, &save->fcs);
+	__put_user(tsk->thread.fdr, &save->foo);
+	__put_user((tsk->thread.fdr>>32) & 0xffff, &save->fos);
+
 	/*
 	 *  Stack frames start with 16-bytes of temp space
 	 */
 	swp = (struct switch_stack *)(tsk->thread.ksp + 16);
 	ptp = ia64_task_regs(tsk);
-	tos = (tsk->thread.fsr >> 11) & 3;
+	tos = (tsk->thread.fsr >> 11) & 7;
 	for (i = 0; i < 8; i++)
-		put_fpreg(i, &save->_st[i], ptp, swp, tos);
+		put_fpreg(i, (struct _fpreg_ia32 *)&save->st_space[4*i], ptp, swp, tos);
 	return 0;
 }
 
 static int
-restore_ia32_fpstate (struct task_struct *tsk, struct _fpstate_ia32 *save)
+restore_ia32_fpstate (struct task_struct *tsk, struct ia32_user_i387_struct *save)
 {
 	struct switch_stack *swp;
 	struct pt_regs *ptp;
-	int i, tos, ret;
-	int fsrlo, fsrhi;
+	int i, tos;
+	unsigned int fsrlo, fsrhi, num32;
 
 	if (!access_ok(VERIFY_READ, save, sizeof(*save)))
-		return(-EIO);
-	ret = __get_user(tsk->thread.fcr, (unsigned int *)&save->cw);
-	ret |= __get_user(fsrlo, (unsigned int *)&save->sw);
-	ret |= __get_user(fsrhi, (unsigned int *)&save->tag);
-	tsk->thread.fsr = ((long)fsrhi << 32) | (long)fsrlo;
-	ret |= __get_user(tsk->thread.fir, (unsigned int *)&save->ipoff);
-	ret |= __get_user(tsk->thread.fdr, (unsigned int *)&save->dataoff);
+		return(-EFAULT);
+
+	__get_user(num32, (unsigned int *)&save->cwd);
+	tsk->thread.fcr = (tsk->thread.fcr & (~0x1f3f)) | (num32 & 0x1f3f);
+	__get_user(fsrlo, (unsigned int *)&save->swd);
+	__get_user(fsrhi, (unsigned int *)&save->twd);
+	num32 = (fsrhi << 16) | fsrlo;
+	tsk->thread.fsr = (tsk->thread.fsr & (~0xffffffff)) | num32;
+	__get_user(num32, (unsigned int *)&save->fip);
+	tsk->thread.fir = (tsk->thread.fir & (~0xffffffff)) | num32;
+	__get_user(num32, (unsigned int *)&save->foo);
+	tsk->thread.fdr = (tsk->thread.fdr & (~0xffffffff)) | num32;
+
 	/*
 	 *  Stack frames start with 16-bytes of temp space
 	 */
 	swp = (struct switch_stack *)(tsk->thread.ksp + 16);
 	ptp = ia64_task_regs(tsk);
-	tos = (tsk->thread.fsr >> 11) & 3;
+	tos = (tsk->thread.fsr >> 11) & 7;
 	for (i = 0; i < 8; i++)
-		get_fpreg(i, &save->_st[i], ptp, swp, tos);
-	return ret ? -EFAULT : 0;
+		get_fpreg(i, (struct _fpreg_ia32 *)&save->st_space[4*i], ptp, swp, tos);
+	return 0;
+}
+
+static int
+save_ia32_fpxstate (struct task_struct *tsk, struct ia32_user_fxsr_struct *save)
+{
+	struct switch_stack *swp;
+	struct pt_regs *ptp;
+	int i, tos;
+	unsigned long mxcsr=0;
+	unsigned long num128[2];
+
+	if (!access_ok(VERIFY_WRITE, save, sizeof(*save)))
+		return -EFAULT;
+
+	__put_user(tsk->thread.fcr & 0xffff, &save->cwd);
+	__put_user(tsk->thread.fsr & 0xffff, &save->swd);
+	__put_user((tsk->thread.fsr>>16) & 0xffff, &save->twd);
+	__put_user(tsk->thread.fir, &save->fip);
+	__put_user((tsk->thread.fir>>32) & 0xffff, &save->fcs);
+	__put_user(tsk->thread.fdr, &save->foo);
+	__put_user((tsk->thread.fdr>>32) & 0xffff, &save->fos);
+
+        /*
+         *  Stack frames start with 16-bytes of temp space
+         */
+        swp = (struct switch_stack *)(tsk->thread.ksp + 16);
+        ptp = ia64_task_regs(tsk);
+	tos = (tsk->thread.fsr >> 11) & 7;
+        for (i = 0; i < 8; i++)
+		put_fpreg(i, (struct _fpreg_ia32 *)&save->st_space[4*i], ptp, swp, tos);
+
+	mxcsr = ((tsk->thread.fcr>>32) & 0xff80) | ((tsk->thread.fsr>>32) & 0x3f);
+	__put_user(mxcsr & 0xffff, &save->mxcsr);
+	for (i = 0; i < 8; i++) {
+		memcpy(&(num128[0]), &(swp->f16) + i*2, sizeof(unsigned long));
+		memcpy(&(num128[1]), &(swp->f17) + i*2, sizeof(unsigned long));
+		copy_to_user(&save->xmm_space[0] + 4*i, num128, sizeof(struct _xmmreg_ia32));
+	}
+	return 0;
+}
+
+static int
+restore_ia32_fpxstate (struct task_struct *tsk, struct ia32_user_fxsr_struct *save)
+{
+	struct switch_stack *swp;
+	struct pt_regs *ptp;
+	int i, tos;
+	unsigned int fsrlo, fsrhi, num32;
+	int mxcsr;
+	unsigned long num64;
+	unsigned long num128[2];
+
+	if (!access_ok(VERIFY_READ, save, sizeof(*save)))
+		return(-EFAULT);
+
+	__get_user(num32, (unsigned int *)&save->cwd);
+	tsk->thread.fcr = (tsk->thread.fcr & (~0x1f3f)) | (num32 & 0x1f3f);
+	__get_user(fsrlo, (unsigned int *)&save->swd);
+	__get_user(fsrhi, (unsigned int *)&save->twd);
+	num32 = (fsrhi << 16) | fsrlo;
+	tsk->thread.fsr = (tsk->thread.fsr & (~0xffffffff)) | num32;
+	__get_user(num32, (unsigned int *)&save->fip);
+	tsk->thread.fir = (tsk->thread.fir & (~0xffffffff)) | num32;
+	__get_user(num32, (unsigned int *)&save->foo);
+	tsk->thread.fdr = (tsk->thread.fdr & (~0xffffffff)) | num32;
+
+	/*
+	 *  Stack frames start with 16-bytes of temp space
+	 */
+	swp = (struct switch_stack *)(tsk->thread.ksp + 16);
+	ptp = ia64_task_regs(tsk);
+	tos = (tsk->thread.fsr >> 11) & 7;
+	for (i = 0; i < 8; i++)
+	get_fpreg(i, (struct _fpreg_ia32 *)&save->st_space[4*i], ptp, swp, tos);
+
+	__get_user(mxcsr, (unsigned int *)&save->mxcsr);
+	num64 = mxcsr & 0xff10;
+	tsk->thread.fcr = (tsk->thread.fcr & (~0xff1000000000)) | (num64<<32);
+	num64 = mxcsr & 0x3f;
+	tsk->thread.fsr = (tsk->thread.fsr & (~0x3f00000000)) | (num64<<32);
+
+	for (i = 0; i < 8; i++) {
+		copy_from_user(num128, &save->xmm_space[0] + 4*i, sizeof(struct _xmmreg_ia32));
+		memcpy(&(swp->f16) + i*2, &(num128[0]), sizeof(unsigned long));
+		memcpy(&(swp->f17) + i*2, &(num128[1]), sizeof(unsigned long));
+	}
+	return 0;
 }
 
 extern asmlinkage long sys_ptrace (long, pid_t, unsigned long, unsigned long, long, long, long,
@@ -3061,11 +2969,19 @@
 		break;
 
 	      case IA32_PTRACE_GETFPREGS:
-		ret = save_ia32_fpstate(child, (struct _fpstate_ia32 *) A(data));
+		ret = save_ia32_fpstate(child, (struct ia32_user_i387_struct *) A(data));
+		break;
+
+	      case IA32_PTRACE_GETFPXREGS:
+		ret = save_ia32_fpxstate(child, (struct ia32_user_fxsr_struct *) A(data));
 		break;
 
 	      case IA32_PTRACE_SETFPREGS:
-		ret = restore_ia32_fpstate(child, (struct _fpstate_ia32 *) A(data));
+		ret = restore_ia32_fpstate(child, (struct ia32_user_i387_struct *) A(data));
+		break;
+
+	      case IA32_PTRACE_SETFPXREGS:
+		ret = restore_ia32_fpxstate(child, (struct ia32_user_fxsr_struct *) A(data));
 		break;
 
 	      case PTRACE_SYSCALL:	/* continue, stop after next syscall */
@@ -3535,9 +3451,12 @@
 	err |= __put_user(kbuf->rdev, &ubuf->st_rdev);
 	err |= __put_user(kbuf->size, &ubuf->st_size_lo);
 	err |= __put_user((kbuf->size >> 32), &ubuf->st_size_hi);
-	err |= __put_user(kbuf->atime, &ubuf->st_atime);
-	err |= __put_user(kbuf->mtime, &ubuf->st_mtime);
-	err |= __put_user(kbuf->ctime, &ubuf->st_ctime);
+	err |= __put_user(kbuf->atime.tv_sec, &ubuf->st_atime);
+	err |= __put_user(kbuf->atime.tv_nsec, &ubuf->st_atime_nsec);
+	err |= __put_user(kbuf->mtime.tv_sec, &ubuf->st_mtime);
+	err |= __put_user(kbuf->mtime.tv_nsec, &ubuf->st_mtime_nsec);
+	err |= __put_user(kbuf->ctime.tv_sec, &ubuf->st_ctime);
+	err |= __put_user(kbuf->ctime.tv_nsec, &ubuf->st_ctime_nsec);
 	err |= __put_user(kbuf->blksize, &ubuf->st_blksize);
 	err |= __put_user(kbuf->blocks, &ubuf->st_blocks);
 	return err;
@@ -3624,7 +3543,7 @@
 }
 
 asmlinkage long
-sys32_sched_rr_get_interval (pid_t pid, struct timespec32 *interval)
+sys32_sched_rr_get_interval (pid_t pid, struct compat_timespec *interval)
 {
 	extern asmlinkage long sys_sched_rr_get_interval (pid_t, struct timespec *);
 	mm_segment_t old_fs = get_fs();
@@ -3701,21 +3620,52 @@
 	return ret;
 }
 
+/*
+ * Exactly like fs/open.c:sys_open(), except that it doesn't set the O_LARGEFILE flag.
+ */
+asmlinkage long
+sys32_open (const char * filename, int flags, int mode)
+{
+	char * tmp;
+	int fd, error;
+
+	tmp = getname(filename);
+	fd = PTR_ERR(tmp);
+	if (!IS_ERR(tmp)) {
+		fd = get_unused_fd();
+		if (fd >= 0) {
+			struct file *f = filp_open(tmp, flags, mode);
+			error = PTR_ERR(f);
+			if (IS_ERR(f))
+				goto out_error;
+			fd_install(fd, f);
+		}
+out:
+		putname(tmp);
+	}
+	return fd;
+
+out_error:
+	put_unused_fd(fd);
+	fd = error;
+	goto out;
+}
+
 #ifdef	NOTYET  /* UNTESTED FOR IA64 FROM HERE DOWN */
 
 struct ncp_mount_data32 {
 	int version;
 	unsigned int ncp_fd;
-	__kernel_uid_t32 mounted_uid;
+	compat_uid_t mounted_uid;
 	int wdog_pid;
 	unsigned char mounted_vol[NCP_VOLNAME_LEN + 1];
 	unsigned int time_out;
 	unsigned int retry_count;
 	unsigned int flags;
-	__kernel_uid_t32 uid;
-	__kernel_gid_t32 gid;
-	__kernel_mode_t32 file_mode;
-	__kernel_mode_t32 dir_mode;
+	compat_uid_t uid;
+	compat_gid_t gid;
+	compat_mode_t file_mode;
+	compat_mode_t dir_mode;
 };
 
 static void *
@@ -3737,11 +3687,11 @@
 
 struct smb_mount_data32 {
 	int version;
-	__kernel_uid_t32 mounted_uid;
-	__kernel_uid_t32 uid;
-	__kernel_gid_t32 gid;
-	__kernel_mode_t32 file_mode;
-	__kernel_mode_t32 dir_mode;
+	compat_uid_t mounted_uid;
+	compat_uid_t uid;
+	compat_gid_t gid;
+	compat_mode_t file_mode;
+	compat_mode_t dir_mode;
 };
 
 static void *
@@ -3859,52 +3809,52 @@
 
 extern asmlinkage long sys_setreuid(uid_t ruid, uid_t euid);
 
-asmlinkage long sys32_setreuid(__kernel_uid_t32 ruid, __kernel_uid_t32 euid)
+asmlinkage long sys32_setreuid(compat_uid_t ruid, compat_uid_t euid)
 {
 	uid_t sruid, seuid;
 
-	sruid = (ruid == (__kernel_uid_t32)-1) ? ((uid_t)-1) : ((uid_t)ruid);
-	seuid = (euid == (__kernel_uid_t32)-1) ? ((uid_t)-1) : ((uid_t)euid);
+	sruid = (ruid == (compat_uid_t)-1) ? ((uid_t)-1) : ((uid_t)ruid);
+	seuid = (euid == (compat_uid_t)-1) ? ((uid_t)-1) : ((uid_t)euid);
 	return sys_setreuid(sruid, seuid);
 }
 
 extern asmlinkage long sys_setresuid(uid_t ruid, uid_t euid, uid_t suid);
 
 asmlinkage long
-sys32_setresuid(__kernel_uid_t32 ruid, __kernel_uid_t32 euid,
-		__kernel_uid_t32 suid)
+sys32_setresuid(compat_uid_t ruid, compat_uid_t euid,
+		compat_uid_t suid)
 {
 	uid_t sruid, seuid, ssuid;
 
-	sruid = (ruid == (__kernel_uid_t32)-1) ? ((uid_t)-1) : ((uid_t)ruid);
-	seuid = (euid == (__kernel_uid_t32)-1) ? ((uid_t)-1) : ((uid_t)euid);
-	ssuid = (suid == (__kernel_uid_t32)-1) ? ((uid_t)-1) : ((uid_t)suid);
+	sruid = (ruid == (compat_uid_t)-1) ? ((uid_t)-1) : ((uid_t)ruid);
+	seuid = (euid == (compat_uid_t)-1) ? ((uid_t)-1) : ((uid_t)euid);
+	ssuid = (suid == (compat_uid_t)-1) ? ((uid_t)-1) : ((uid_t)suid);
 	return sys_setresuid(sruid, seuid, ssuid);
 }
 
 extern asmlinkage long sys_setregid(gid_t rgid, gid_t egid);
 
 asmlinkage long
-sys32_setregid(__kernel_gid_t32 rgid, __kernel_gid_t32 egid)
+sys32_setregid(compat_gid_t rgid, compat_gid_t egid)
 {
 	gid_t srgid, segid;
 
-	srgid = (rgid == (__kernel_gid_t32)-1) ? ((gid_t)-1) : ((gid_t)rgid);
-	segid = (egid == (__kernel_gid_t32)-1) ? ((gid_t)-1) : ((gid_t)egid);
+	srgid = (rgid == (compat_gid_t)-1) ? ((gid_t)-1) : ((gid_t)rgid);
+	segid = (egid == (compat_gid_t)-1) ? ((gid_t)-1) : ((gid_t)egid);
 	return sys_setregid(srgid, segid);
 }
 
 extern asmlinkage long sys_setresgid(gid_t rgid, gid_t egid, gid_t sgid);
 
 asmlinkage long
-sys32_setresgid(__kernel_gid_t32 rgid, __kernel_gid_t32 egid,
-		__kernel_gid_t32 sgid)
+sys32_setresgid(compat_gid_t rgid, compat_gid_t egid,
+		compat_gid_t sgid)
 {
 	gid_t srgid, segid, ssgid;
 
-	srgid = (rgid == (__kernel_gid_t32)-1) ? ((gid_t)-1) : ((gid_t)rgid);
-	segid = (egid == (__kernel_gid_t32)-1) ? ((gid_t)-1) : ((gid_t)egid);
-	ssgid = (sgid == (__kernel_gid_t32)-1) ? ((gid_t)-1) : ((gid_t)sgid);
+	srgid = (rgid == (compat_gid_t)-1) ? ((gid_t)-1) : ((gid_t)rgid);
+	segid = (egid == (compat_gid_t)-1) ? ((gid_t)-1) : ((gid_t)egid);
+	ssgid = (sgid == (compat_gid_t)-1) ? ((gid_t)-1) : ((gid_t)sgid);
 	return sys_setresgid(srgid, segid, ssgid);
 }
 
@@ -3926,27 +3876,27 @@
 struct nfsctl_export32 {
 	s8			ex32_client[NFSCLNT_IDMAX+1];
 	s8			ex32_path[NFS_MAXPATHLEN+1];
-	__kernel_dev_t32	ex32_dev;
-	__kernel_ino_t32	ex32_ino;
+	compat_dev_t	ex32_dev;
+	compat_ino_t	ex32_ino;
 	s32			ex32_flags;
-	__kernel_uid_t32	ex32_anon_uid;
-	__kernel_gid_t32	ex32_anon_gid;
+	compat_uid_t	ex32_anon_uid;
+	compat_gid_t	ex32_anon_gid;
 };
 
 struct nfsctl_uidmap32 {
 	u32			ug32_ident;   /* char * */
-	__kernel_uid_t32	ug32_uidbase;
+	compat_uid_t	ug32_uidbase;
 	s32			ug32_uidlen;
 	u32			ug32_udimap;  /* uid_t * */
-	__kernel_uid_t32	ug32_gidbase;
+	compat_uid_t	ug32_gidbase;
 	s32			ug32_gidlen;
 	u32			ug32_gdimap;  /* gid_t * */
 };
 
 struct nfsctl_fhparm32 {
 	struct sockaddr		gf32_addr;
-	__kernel_dev_t32	gf32_dev;
-	__kernel_ino_t32	gf32_ino;
+	compat_dev_t	gf32_dev;
+	compat_ino_t	gf32_ino;
 	s32			gf32_version;
 };
 
@@ -4066,7 +4016,7 @@
 		return -ENOMEM;
 	for(i = 0; i < karg->ca_umap.ug_uidlen; i++)
 		err |= __get_user(karg->ca_umap.ug_udimap[i],
-			      &(((__kernel_uid_t32 *)A(uaddr))[i]));
+			      &(((compat_uid_t *)A(uaddr))[i]));
 	err |= __get_user(karg->ca_umap.ug_gidbase,
 		      &arg32->ca32_umap.ug32_gidbase);
 	err |= __get_user(karg->ca_umap.ug_uidlen,
@@ -4081,7 +4031,7 @@
 		return -ENOMEM;
 	for(i = 0; i < karg->ca_umap.ug_gidlen; i++)
 		err |= __get_user(karg->ca_umap.ug_gdimap[i],
-			      &(((__kernel_gid_t32 *)A(uaddr))[i]));
+			      &(((compat_gid_t *)A(uaddr))[i]));
 
 	return err;
 }
@@ -4193,7 +4143,7 @@
 	u32 modes;
 	s32 offset, freq, maxerror, esterror;
 	s32 status, constant, precision, tolerance;
-	struct timeval32 time;
+	struct compat_timeval time;
 	s32 tick;
 	s32 ppsfreq, jitter, shift, stabil;
 	s32 jitcnt, calcnt, errcnt, stbcnt;
diff -Nru a/arch/ia64/kernel/Makefile b/arch/ia64/kernel/Makefile
--- a/arch/ia64/kernel/Makefile	Mon Dec 23 21:22:02 2002
+++ b/arch/ia64/kernel/Makefile	Mon Dec 23 21:22:02 2002
@@ -6,9 +6,12 @@
 
 export-objs := ia64_ksyms.o
 
-obj-y := acpi.o entry.o gate.o efi.o efi_stub.o ia64_ksyms.o irq.o irq_ia64.o irq_lsapic.o ivt.o \
-	 machvec.o pal.o process.o perfmon.o ptrace.o sal.o semaphore.o setup.o	\
+obj-y := acpi.o entry.o gate.o efi.o efi_stub.o ia64_ksyms.o \
+	 irq.o irq_ia64.o irq_lsapic.o ivt.o \
+	 machvec.o pal.o process.o perfmon.o ptrace.o sal.o \
+	 semaphore.o setup.o	\
 	 signal.o sys_ia64.o traps.o time.o unaligned.o unwind.o
+
 obj-$(CONFIG_IOSAPIC) += iosapic.o
 obj-$(CONFIG_IA64_PALINFO) += palinfo.o
 obj-$(CONFIG_EFI_VARS) += efivars.o
diff -Nru a/arch/ia64/kernel/efi.c b/arch/ia64/kernel/efi.c
--- a/arch/ia64/kernel/efi.c	Mon Dec 23 21:21:50 2002
+++ b/arch/ia64/kernel/efi.c	Mon Dec 23 21:21:50 2002
@@ -306,7 +306,7 @@
 		u64 start;
 		u64 end;
 	} prev, curr;
-	void *efi_map_start, *efi_map_end, *p, *q;
+	void *efi_map_start, *efi_map_end, *p, *q, *r;
 	efi_memory_desc_t *md, *check_md;
 	u64 efi_desc_size, start, end, granule_addr, first_non_wb_addr = 0;
 
@@ -351,11 +351,10 @@
 
 			if (!(first_non_wb_addr > granule_addr))
 				continue;	/* couldn't find enough contiguous memory */
-		}
-
-		/* BUG_ON((md->phys_addr >> IA64_GRANULE_SHIFT) < first_non_wb_addr); */
 
-		trim_top(md, first_non_wb_addr);
+			for (r = p; r < q; r += efi_desc_size)
+				trim_top(r, first_non_wb_addr);
+		}
 
 		if (is_available_memory(md)) {
 			if (md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) > mem_limit) {
diff -Nru a/arch/ia64/kernel/efivars.c b/arch/ia64/kernel/efivars.c
--- a/arch/ia64/kernel/efivars.c	Mon Dec 23 21:21:54 2002
+++ b/arch/ia64/kernel/efivars.c	Mon Dec 23 21:21:54 2002
@@ -29,6 +29,9 @@
  *
  * Changelog:
  *
+ *  10 Dec 2002 - Matt Domsch <Matt_Domsch@dell.com>
+ *   fix locking per Peter Chubb's findings
+ * 
  *  25 Mar 2002 - Matt Domsch <Matt_Domsch@dell.com>
  *   move uuid_unparse() to include/asm-ia64/efi.h:efi_guid_unparse()
  *
@@ -73,7 +76,7 @@
 MODULE_DESCRIPTION("/proc interface to EFI Variables");
 MODULE_LICENSE("GPL");
 
-#define EFIVARS_VERSION "0.05 2002-Mar-26"
+#define EFIVARS_VERSION "0.06 2002-Dec-10"
 
 static int
 efivar_read(char *page, char **start, off_t off,
@@ -106,6 +109,14 @@
 	struct list_head        list;
 } efivar_entry_t;
 
+/*
+  efivars_lock protects two things:
+  1) efivar_list - adds, removals, reads, writes
+  2) efi.[gs]et_variable() calls.
+  It must not be held when creating proc entries or calling kmalloc.
+  efi.get_next_variable() is only called from efivars_init(),
+  which is protected by the BKL, so that path is safe.
+*/
 static spinlock_t efivars_lock = SPIN_LOCK_UNLOCKED;
 static LIST_HEAD(efivar_list);
 static struct proc_dir_entry *efi_vars_dir = NULL;
@@ -150,6 +161,7 @@
  *    variable_name_size = number of bytes required to hold
  *                         variable_name (not counting the NULL
  *                         character at the end.
+ *    efivars_lock is not held on entry or exit.
  * Returns 1 on failure, 0 on success
  */
 static int
@@ -160,10 +172,12 @@
 
 	int i, short_name_size = variable_name_size /
 		sizeof(efi_char16_t) + 38;
-	char *short_name = kmalloc(short_name_size+1,
-				   GFP_KERNEL);
-	efivar_entry_t *new_efivar = kmalloc(sizeof(efivar_entry_t),
-					     GFP_KERNEL);
+	char *short_name;
+	efivar_entry_t *new_efivar;
+
+        short_name = kmalloc(short_name_size+1, GFP_KERNEL);
+        new_efivar = kmalloc(sizeof(efivar_entry_t), GFP_KERNEL);
+
 	if (!short_name || !new_efivar)  {
 		if (short_name)        kfree(short_name);
 		if (new_efivar)        kfree(new_efivar);
@@ -188,20 +202,19 @@
 	*(short_name + strlen(short_name)) = '-';
 	efi_guid_unparse(vendor_guid, short_name + strlen(short_name));
 
-
 	/* Create the entry in proc */
 	new_efivar->entry = create_proc_entry(short_name, 0600, efi_vars_dir);
 	kfree(short_name); short_name = NULL;
 	if (!new_efivar->entry) return 1;
 
-
 	new_efivar->entry->owner = THIS_MODULE;
 	new_efivar->entry->data = new_efivar;
 	new_efivar->entry->read_proc = efivar_read;
 	new_efivar->entry->write_proc = efivar_write;
 
-	list_add(&new_efivar->list, &efivar_list);
-
+        spin_lock(&efivars_lock);
+        list_add(&new_efivar->list, &efivar_list);
+        spin_unlock(&efivars_lock);
 
 	return 0;
 }
@@ -319,6 +332,8 @@
 		kfree(efivar);
 	}
 
+	spin_unlock(&efivars_lock);
+
 	/* If this is a new variable, set up the proc entry for it. */
 	if (!found) {
 		efivar_create_proc_entry(utf8_strsize(var_data->VariableName,
@@ -328,7 +343,6 @@
 	}
 
 	kfree(var_data);
-	spin_unlock(&efivars_lock);
 	return size;
 }
 
@@ -343,8 +357,6 @@
 	efi_char16_t *variable_name = kmalloc(1024, GFP_KERNEL);
 	unsigned long variable_name_size = 1024;
 
-	spin_lock(&efivars_lock);
-
 	printk(KERN_INFO "EFI Variables Facility v%s\n", EFIVARS_VERSION);
 
         /* Since efi.c happens before procfs is available,
@@ -357,8 +369,6 @@
 
 	efi_vars_dir = proc_mkdir("vars", efi_dir);
 
-
-
 	/* Per EFI spec, the maximum storage allocated for both
 	   the variable name and variable data is 1024 bytes.
 	*/
@@ -390,7 +400,6 @@
 	} while (status != EFI_NOT_FOUND);
 
 	kfree(variable_name);
-	spin_unlock(&efivars_lock);
 	return 0;
 }
 
@@ -400,17 +409,16 @@
 	struct list_head *pos, *n;
 	efivar_entry_t *efivar;
 
-	spin_lock(&efivars_lock);
-
+        spin_lock(&efivars_lock);
 	list_for_each_safe(pos, n, &efivar_list) {
 		efivar = efivar_entry(pos);
 		remove_proc_entry(efivar->entry->name, efi_vars_dir);
 		list_del(&efivar->list);
 		kfree(efivar);
 	}
-	remove_proc_entry(efi_vars_dir->name, efi_dir);
 	spin_unlock(&efivars_lock);
 
+	remove_proc_entry(efi_vars_dir->name, efi_dir);
 }
 
 module_init(efivars_init);
diff -Nru a/arch/ia64/kernel/entry.S b/arch/ia64/kernel/entry.S
--- a/arch/ia64/kernel/entry.S	Mon Dec 23 21:21:52 2002
+++ b/arch/ia64/kernel/entry.S	Mon Dec 23 21:21:52 2002
@@ -91,11 +91,12 @@
 END(ia64_execve)
 
 /*
- * sys_clone2(u64 flags, u64 ustack_base, u64 ustack_size, u64 user_tid, u64 tls)
+ * sys_clone2(u64 flags, u64 ustack_base, u64 ustack_size, u64 child_tidptr, u64 parent_tidptr,
+ *	      u64 tls)
  */
 GLOBAL_ENTRY(sys_clone2)
 	.prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(2)
-	alloc r16=ar.pfs,5,2,5,0
+	alloc r16=ar.pfs,6,2,6,0
 	DO_SAVE_SWITCH_STACK
 	adds r2=PT(R16)+IA64_SWITCH_STACK_SIZE+16,sp
 	mov loc0=rp
@@ -104,9 +105,10 @@
 	mov out1=in1
 	mov out3=in2
 	tbit.nz p6,p0=in0,CLONE_SETTLS_BIT
-	mov out4=in3				// valid only w/CLONE_SETTID and/or CLONE_CLEARTID
+	mov out4=in3	// child_tidptr:  valid only w/CLONE_CHILD_SETTID or CLONE_CHILD_CLEARTID
 	;;
-(p6)	st8 [r2]=in4				// store TLS in r13 (tp)
+(p6)	st8 [r2]=in5				// store TLS in r16 for copy_thread()
+	mov out5=in4	// parent_tidptr: valid only w/CLONE_PARENT_SETTID
 	adds out2=IA64_SWITCH_STACK_SIZE+16,sp	// out2 = &regs
 	dep out0=0,in0,CLONE_IDLETASK_BIT,1	// out0 = clone_flags & ~CLONE_IDLETASK
 	br.call.sptk.many rp=do_fork
@@ -535,7 +537,6 @@
 
 GLOBAL_ENTRY(ia64_ret_from_clone)
 	PT_REGS_UNWIND_INFO(0)
-#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT)
 	/*
 	 * We need to call schedule_tail() to complete the scheduling process.
 	 * Called by ia64_switch_to() after do_fork()->copy_thread().  r8 contains the
@@ -543,7 +544,6 @@
 	 */
 	br.call.sptk.many rp=ia64_invoke_schedule_tail
 .ret8:
-#endif
 	adds r2=TI_FLAGS+IA64_TASK_SIZE,r13
 	;;
 	ld4 r2=[r2]
@@ -844,7 +844,6 @@
 	br.cond.sptk ia64_leave_kernel
 END(handle_syscall_error)
 
-#ifdef CONFIG_SMP
 	/*
 	 * Invoke schedule_tail(task) while preserving in0-in7, which may be needed
 	 * in case a system call gets restarted.
@@ -861,8 +860,6 @@
 	br.ret.sptk.many rp
 END(ia64_invoke_schedule_tail)
 
-#endif /* CONFIG_SMP */
-
 #if __GNUC__ < 3
 
 	/*
@@ -1129,18 +1126,18 @@
 	data8 ia64_ni_syscall					/* was: ia64_oldfstat */
 	data8 sys_vhangup
 	data8 sys_lchown
-	data8 sys_vm86				// 1125
+	data8 sys_remap_file_pages		// 1125
 	data8 sys_wait4
 	data8 sys_sysinfo
 	data8 sys_clone
 	data8 sys_setdomainname
 	data8 sys_newuname			// 1130
 	data8 sys_adjtimex
-	data8 ia64_create_module
+	data8 ia64_ni_syscall					/* was: ia64_create_module */
 	data8 sys_init_module
 	data8 sys_delete_module
-	data8 sys_get_kernel_syms		// 1135
-	data8 sys_query_module
+	data8 ia64_ni_syscall			// 1135		/* was: sys_get_kernel_syms */
+	data8 ia64_ni_syscall					/* was: sys_query_module */
 	data8 sys_quotactl
 	data8 sys_bdflush
 	data8 sys_sysfs
@@ -1160,7 +1157,7 @@
 	data8 sys_mlock
 	data8 sys_mlockall
 	data8 sys_mprotect			// 1155
-	data8 sys_mremap
+	data8 ia64_mremap
 	data8 sys_msync
 	data8 sys_munlock
 	data8 sys_munlockall
@@ -1173,11 +1170,7 @@
 	data8 sys_sched_get_priority_min
 	data8 sys_sched_rr_get_interval
 	data8 sys_nanosleep
-#if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE)
 	data8 sys_nfsservctl
-#else
-	data8 sys_ni_syscall
-#endif
 	data8 sys_prctl				// 1170
 	data8 sys_getpagesize
 	data8 sys_mmap2
@@ -1241,7 +1234,7 @@
 	data8 sys_futex				// 1230
 	data8 sys_sched_setaffinity
 	data8 sys_sched_getaffinity
-	data8 sys_ni_syscall
+	data8 sys_set_tid_address
 	data8 sys_alloc_hugepages
 	data8 sys_free_hugepages		// 1235
 	data8 sys_exit_group
@@ -1254,8 +1247,8 @@
 	data8 sys_epoll_create
 	data8 sys_epoll_ctl
 	data8 sys_epoll_wait			// 1245
+	data8 sys_restart_syscall
 	data8 sys_semtimedop
-	data8 ia64_ni_syscall
 	data8 ia64_ni_syscall
 	data8 ia64_ni_syscall
 	data8 ia64_ni_syscall			// 1250
diff -Nru a/arch/ia64/kernel/fw-emu.c b/arch/ia64/kernel/fw-emu.c
--- a/arch/ia64/kernel/fw-emu.c	Mon Dec 23 21:21:50 2002
+++ b/arch/ia64/kernel/fw-emu.c	Mon Dec 23 21:21:50 2002
@@ -20,7 +20,13 @@
 
 #define MB	(1024*1024UL)
 
-#define NUM_MEM_DESCS	3
+#define SIMPLE_MEMMAP	1
+
+#if SIMPLE_MEMMAP
+# define NUM_MEM_DESCS	4
+#else
+# define NUM_MEM_DESCS	16
+#endif
 
 static char fw_mem[(  sizeof(struct ia64_boot_param)
 		    + sizeof(efi_system_table_t)
@@ -379,6 +385,17 @@
 	struct ia64_boot_param *bp;
 	unsigned char checksum = 0;
 	char *cp, *cmd_line;
+	int i = 0;
+#	define MAKE_MD(typ, attr, start, end)		\
+	do {						\
+		md = efi_memmap + i++;			\
+		md->type = typ;				\
+		md->pad = 0;				\
+		md->phys_addr = start;			\
+		md->virt_addr = 0;			\
+		md->num_pages = (end - start) >> 12;	\
+		md->attribute = attr;			\
+	} while (0)
 
 	memset(fw_mem, 0, sizeof(fw_mem));
 
@@ -464,47 +481,29 @@
 
 	sal_systab->checksum = -checksum;
 
+#if SIMPLE_MEMMAP
 	/* simulate free memory at physical address zero */
-	md = &efi_memmap[0];
-	md->type = EFI_BOOT_SERVICES_DATA;
-	md->pad = 0;
-	md->phys_addr = 0*MB;
-	md->virt_addr = 0;
-	md->num_pages = (1*MB) >> 12;	/* 1MB (in 4KB pages) */
-	md->attribute = EFI_MEMORY_WB;
-
-	/* fill in a memory descriptor: */
-	md = &efi_memmap[1];
-	md->type = EFI_CONVENTIONAL_MEMORY;
-	md->pad = 0;
-	md->phys_addr = 2*MB;
-	md->virt_addr = 0;
-	md->num_pages = (128*MB) >> 12;	/* 128MB (in 4KB pages) */
-	md->attribute = EFI_MEMORY_WB;
-
-	/* descriptor for firmware emulator: */
-	md = &efi_memmap[2];
-	md->type = EFI_PAL_CODE;
-	md->pad = 0;
-	md->phys_addr = 1*MB;
-	md->virt_addr = 1*MB;
-	md->num_pages = (1*MB) >> 12;	/* 1MB (in 4KB pages) */
-	md->attribute = EFI_MEMORY_WB;
-
-#if 0
-	/*
-	 * XXX bootmem is broken for now... (remember to NUM_MEM_DESCS
-	 * if you re-enable this!)
-	 */
-
-	/* descriptor for high memory (>4GB): */
-	md = &efi_memmap[3];
-	md->type = EFI_CONVENTIONAL_MEMORY;
-	md->pad = 0;
-	md->phys_addr = 4096*MB;
-	md->virt_addr = 0;
-	md->num_pages = (32*MB) >> 12;	/* 32MB (in 4KB pages) */
-	md->attribute = EFI_MEMORY_WB;
+	MAKE_MD(EFI_BOOT_SERVICES_DATA,		EFI_MEMORY_WB,    0*MB,    1*MB);
+	MAKE_MD(EFI_PAL_CODE,			EFI_MEMORY_WB,    1*MB,    2*MB);
+	MAKE_MD(EFI_CONVENTIONAL_MEMORY,	EFI_MEMORY_WB,    2*MB,  130*MB);
+	MAKE_MD(EFI_CONVENTIONAL_MEMORY,	EFI_MEMORY_WB, 4096*MB, 4128*MB);
+#else
+	MAKE_MD( 4,		   0x9, 0x0000000000000000, 0x0000000000001000);
+	MAKE_MD( 7,		   0x9, 0x0000000000001000, 0x000000000008a000);
+	MAKE_MD( 4,		   0x9, 0x000000000008a000, 0x00000000000a0000);
+	MAKE_MD( 5, 0x8000000000000009, 0x00000000000c0000, 0x0000000000100000);
+	MAKE_MD( 7,		   0x9, 0x0000000000100000, 0x0000000004400000);
+	MAKE_MD( 2,		   0x9, 0x0000000004400000, 0x0000000004be5000);
+	MAKE_MD( 7,		   0x9, 0x0000000004be5000, 0x000000007f77e000);
+	MAKE_MD( 6, 0x8000000000000009, 0x000000007f77e000, 0x000000007fb94000);
+	MAKE_MD( 6, 0x8000000000000009, 0x000000007fb94000, 0x000000007fb95000);
+	MAKE_MD( 6, 0x8000000000000009, 0x000000007fb95000, 0x000000007fc00000);
+	MAKE_MD(13, 0x8000000000000009, 0x000000007fc00000, 0x000000007fc3a000);
+	MAKE_MD( 7,		   0x9, 0x000000007fc3a000, 0x000000007fea0000);
+	MAKE_MD( 5, 0x8000000000000009, 0x000000007fea0000, 0x000000007fea8000);
+	MAKE_MD( 7,		   0x9, 0x000000007fea8000, 0x000000007feab000);
+	MAKE_MD( 5, 0x8000000000000009, 0x000000007feab000, 0x000000007ffff000);
+	MAKE_MD( 7,		   0x9, 0x00000000ff400000, 0x0000000104000000);
 #endif
 
 	bp->efi_systab = __pa(&fw_mem);
diff -Nru a/arch/ia64/kernel/ia64_ksyms.c b/arch/ia64/kernel/ia64_ksyms.c
--- a/arch/ia64/kernel/ia64_ksyms.c	Mon Dec 23 21:21:54 2002
+++ b/arch/ia64/kernel/ia64_ksyms.c	Mon Dec 23 21:21:54 2002
@@ -86,7 +86,7 @@
 EXPORT_SYMBOL(ia64_cpu_to_sapicid);
 #else /* !CONFIG_SMP */
 
-EXPORT_SYMBOL(__flush_tlb_all);
+EXPORT_SYMBOL(local_flush_tlb_all);
 
 #endif /* !CONFIG_SMP */
 
diff -Nru a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
--- a/arch/ia64/kernel/mca.c	Mon Dec 23 21:21:54 2002
+++ b/arch/ia64/kernel/mca.c	Mon Dec 23 21:21:54 2002
@@ -69,10 +69,10 @@
 u64				ia64_mca_bspstore[1024];
 u64				ia64_init_stack[KERNEL_STACK_SIZE] __attribute__((aligned(16)));
 u64				ia64_mca_sal_data_area[1356];
-u64				ia64_mca_min_state_save_info;
 u64				ia64_tlb_functional;
 u64				ia64_os_mca_recovery_successful;
-
+/* TODO: need to assign min-state structure to UC memory */
+u64				ia64_mca_min_state_save_info[MIN_STATE_AREA_SIZE] __attribute__((aligned(512)));
 static void			ia64_mca_wakeup_ipi_wait(void);
 static void			ia64_mca_wakeup(int cpu);
 static void			ia64_mca_wakeup_all(void);
@@ -116,7 +116,7 @@
  *  Outputs :   platform error status
  */
 int
-ia64_mca_log_sal_error_record(int sal_info_type)
+ia64_mca_log_sal_error_record(int sal_info_type, int called_from_init)
 {
 	int platform_err = 0;
 
@@ -131,7 +131,10 @@
 	 */
 
 	platform_err = ia64_log_print(sal_info_type, (prfunc_t)printk);
-	ia64_sal_clear_state_info(sal_info_type);
+	/* temporary: only clear SAL logs on hardware-corrected errors
+		or if we're logging an error after an MCA-initiated reboot */
+	if ((sal_info_type > 1) || (called_from_init))
+		ia64_sal_clear_state_info(sal_info_type);
 
 	return platform_err;
 }
@@ -152,7 +155,7 @@
 	IA64_MCA_DEBUG("ia64_mca_cpe_int_handler: received interrupt. vector = %#x\n", cpe_irq);
 
 	/* Get the CMC error record and log it */
-	ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CPE);
+	ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CPE, 0);
 }
 
 /*
@@ -199,13 +202,15 @@
  *
  *  Outputs :   None
  */
-void
+int
 ia64_mca_check_errors (void)
 {
 	/*
 	 *  If there is an MCA error record pending, get it and log it.
 	 */
-	ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA);
+	ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA, 1);
+
+	return 0;
 }
 
 device_initcall(ia64_mca_check_errors);
@@ -237,49 +242,26 @@
 
 #endif /* PLATFORM_MCA_HANDLERS */
 
-static char *min_state_labels[] = {
-	"nat",
-	"r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8",
-	"r9", "r10","r11", "r12","r13","r14", "r15",
-	"b0r16","b0r17", "b0r18", "b0r19", "b0r20",
-	"b0r21", "b0r22","b0r23", "b0r24", "b0r25",
-	"b0r26", "b0r27", "b0r28","b0r29", "b0r30", "b0r31",
-	"r16", "r17", "r18","r19", "r20", "r21","r22",
-	"r23", "r24","r25", "r26", "r27","r28", "r29", "r30","r31",
-	"preds", "br0", "rsc",
-	"iip", "ipsr", "ifs",
-	"xip", "xpsr", "xfs"
-};
-
-int ia64_pmss_dump_bank0=0;  /* dump bank 0 ? */
-
 /*
  * routine to process and prepare to dump min_state_save
  * information for debugging purposes.
  *
  */
 void
-ia64_process_min_state_save (pal_min_state_area_t *pmss, struct pt_regs *ptregs)
+ia64_process_min_state_save (pal_min_state_area_t *pmss)
 {
-	int i, max=57;
-	u64 *tpmss_ptr=(u64 *)pmss;
+	int i, max = MIN_STATE_AREA_SIZE;
+	u64 *tpmss_ptr = (u64 *)pmss;
+	u64 *return_min_state_ptr = ia64_mca_min_state_save_info;
 
 	/* dump out the min_state_area information */
 
 	for (i=0;i<max;i++) {
 
-		if(!ia64_pmss_dump_bank0) {
-			if(strncmp("B0",min_state_labels[i],2)==0) {
-				tpmss_ptr++;  /* skip to next entry */
-				continue;
-			}
-		}
-
-		printk("%5s=0x%16.16lx ",min_state_labels[i],*tpmss_ptr++);
+		/* copy min-state register info for eventual return to PAL */
+		*return_min_state_ptr++ = *tpmss_ptr;
 
-		if (((i+1)%3)==0 || ((!strcmp("GR16",min_state_labels[i]))
-				     && !ia64_pmss_dump_bank0))
-			printk("\n");
+		tpmss_ptr++;  /* skip to next entry */
 	}
 }
 
@@ -525,19 +507,17 @@
 	ia64_log_init(SAL_INFO_TYPE_CMC);
 	ia64_log_init(SAL_INFO_TYPE_CPE);
 
-	/* Zero the min state save info */
-	ia64_mca_min_state_save_info = 0;
-
 #if defined(MCA_TEST)
 	mca_test();
 #endif /* #if defined(MCA_TEST) */
 
 	printk("Mca related initialization done\n");
 
-#if 0   // Too early in initialization -- error log is lost
+	/* commented out because this is done elsewhere */
+#if 0
 	/* Do post-failure MCA error logging */
 	ia64_mca_check_errors();
-#endif  // Too early in initialization -- error log is lost
+#endif
 }
 
 /*
@@ -632,7 +612,6 @@
 	int cpu = 0;
 
 	/* Mask all interrupts */
-#warning XXX fix me: this used to be: save_and_cli(flags);
 	local_irq_save(flags);
 
 #ifdef CONFIG_SMP
@@ -709,8 +688,8 @@
 	ia64_os_to_sal_handoff_state.imots_context = IA64_MCA_SAME_CONTEXT;
 
 	/* Register pointer to new min state values */
-	/* NOTE: need to do something with this during recovery phase */
-	ia64_os_to_sal_handoff_state.imots_new_min_state = &ia64_mca_min_state_save_info;
+	ia64_os_to_sal_handoff_state.imots_new_min_state =
+		ia64_mca_min_state_save_info;
 }
 
 /*
@@ -735,7 +714,7 @@
 	int platform_err = 0;
 
 	/* Get the MCA error record and log it */
-	platform_err = ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA);
+	platform_err = ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA, 0);
 
 	/*
 	 *  Do Platform-specific mca error handling if required.
@@ -775,7 +754,7 @@
 		       cmc_irq, smp_processor_id());
 
 	/* Get the CMC error record and log it */
-	ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CMC);
+	ia64_mca_log_sal_error_record(SAL_INFO_TYPE_CMC, 0);
 }
 
 /*
@@ -845,8 +824,7 @@
 	plog_ptr=(ia64_err_rec_t *)IA64_LOG_CURR_BUFFER(SAL_INFO_TYPE_INIT);
 	proc_ptr = &plog_ptr->proc_err;
 
-	ia64_process_min_state_save(&proc_ptr->processor_static_info.min_state_area,
-				    regs);
+	ia64_process_min_state_save(&proc_ptr->processor_static_info.min_state_area);
 
 	/* Clear the INIT SAL logs now that they have been saved in the OS buffer */
 	ia64_sal_clear_state_info(SAL_INFO_TYPE_INIT);
@@ -1676,6 +1654,9 @@
 	/* Print processor static info if any */
 	if (slpi->valid.psi_static_struct) {
 		spsi = (sal_processor_static_info_t *)p_data;
+
+		/* copy interrupted context PAL min-state info */
+		ia64_process_min_state_save(&spsi->min_state_area);
 
 		/* Print branch register contents if valid */
 		if (spsi->valid.br)
diff -Nru a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
--- a/arch/ia64/kernel/palinfo.c	Mon Dec 23 21:21:50 2002
+++ b/arch/ia64/kernel/palinfo.c	Mon Dec 23 21:21:50 2002
@@ -101,26 +101,15 @@
 
 #define RSE_HINTS_COUNT (sizeof(rse_hints)/sizeof(const char *))
 
-/*
- * The current revision of the Volume 2 (July 2000) of
- * IA-64 Architecture Software Developer's Manual is wrong.
- * Table 4-10 has invalid information concerning the ma field:
- * Correct table is:
- *      bit 0 - 001 - UC
- *      bit 4 - 100 - UC
- *      bit 5 - 101 - UCE
- *      bit 6 - 110 - WC
- *      bit 7 - 111 - NatPage
- */
 static const char *mem_attrib[]={
-	"Write Back (WB)",		/* 000 */
-	"Uncacheable (UC)",		/* 001 */
-	"Reserved",			/* 010 */
-	"Reserved",			/* 011 */
-	"Uncacheable (UC)",		/* 100 */
-	"Uncacheable Exported (UCE)",	/* 101 */
-	"Write Coalescing (WC)",	/* 110 */
-	"NaTPage"			/* 111 */
+	"WB",		/* 000 */
+	"SW",		/* 001 */
+	"010",		/* 010 */
+	"011",		/* 011 */
+	"UC",		/* 100 */
+	"UCE",		/* 101 */
+	"WC",		/* 110 */
+	"NaTPage"	/* 111 */
 };
 
 /*
@@ -315,6 +304,7 @@
 	pal_vm_info_2_u_t vm_info_2;
 	pal_tc_info_u_t	tc_info;
 	ia64_ptce_info_t ptce;
+	const char *sep;
 	int i, j;
 	s64 status;
 
@@ -339,7 +329,15 @@
 
 	if (ia64_pal_mem_attrib(&attrib) != 0) return 0;
 
-	p += sprintf(p, "Supported memory attributes    : %s\n", mem_attrib[attrib&0x7]);
+	p += sprintf(p, "Supported memory attributes    : ");
+	sep = "";
+	for (i = 0; i < 8; i++) {
+		if (attrib & (1 << i)) {
+			p += sprintf(p, "%s%s", sep, mem_attrib[i]);
+			sep = ", ";
+		}
+	}
+	p += sprintf(p, "\n");
 
 	if ((status=ia64_pal_vm_page_size(&tr_pages, &vw_pages)) !=0) {
 		printk("ia64_pal_vm_page_size=%ld\n", status);
diff -Nru a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c
--- a/arch/ia64/kernel/process.c	Mon Dec 23 21:21:54 2002
+++ b/arch/ia64/kernel/process.c	Mon Dec 23 21:21:54 2002
@@ -10,6 +10,7 @@
 #include <linux/pm.h>
 #include <linux/elf.h>
 #include <linux/errno.h>
+#include <linux/kallsyms.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/module.h>
@@ -376,36 +377,12 @@
 	/* clear list of sampling buffer to free for new task */
 	p->thread.pfm_smpl_buf_list = NULL;
 
-	if (current->thread.pfm_context) retval = pfm_inherit(p, child_ptregs);
+	if (current->thread.pfm_context)
+		retval = pfm_inherit(p, child_ptregs);
 #endif
 	return retval;
 }
 
-void
-do_copy_regs (struct unw_frame_info *info, void *arg)
-{
-	do_copy_task_regs(current, info, arg);
-}
-
-void
-do_dump_fpu (struct unw_frame_info *info, void *arg)
-{
-	do_dump_task_fpu(current, info, arg);
-}
-
-void
-ia64_elf_core_copy_regs (struct pt_regs *pt, elf_gregset_t dst)
-{
-	unw_init_running(do_copy_regs, dst);
-}
-
-int
-dump_fpu (struct pt_regs *pt, elf_fpregset_t dst)
-{
-	unw_init_running(do_dump_fpu, dst);
-	return 1;	/* f0-f31 are always valid so we always return 1 */
-}
-
 static void
 do_copy_task_regs (struct task_struct *task, struct unw_frame_info *info, void *arg)
 {
@@ -497,36 +474,59 @@
 		memcpy(dst + 32, task->thread.fph, 96*16);
 }
 
-int dump_task_regs(struct task_struct *task, elf_gregset_t *regs)
+void
+do_copy_regs (struct unw_frame_info *info, void *arg)
+{
+	do_copy_task_regs(current, info, arg);
+}
+
+void
+do_dump_fpu (struct unw_frame_info *info, void *arg)
+{
+	do_dump_task_fpu(current, info, arg);
+}
+
+int
+dump_task_regs(struct task_struct *task, elf_gregset_t *regs)
 {
 	struct unw_frame_info tcore_info;
 
-	if(current == task) {
+	if (current == task) {
 		unw_init_running(do_copy_regs, regs);
-	}
-	else {
-		memset(&tcore_info, 0, sizeof(tcore_info));	
+	} else {
+		memset(&tcore_info, 0, sizeof(tcore_info));
 		unw_init_from_blocked_task(&tcore_info, task);
 		do_copy_task_regs(task, &tcore_info, regs);
 	}
-
 	return 1;
 }
 
-int dump_task_fpu (struct task_struct *task, elf_fpregset_t *dst)
+void
+ia64_elf_core_copy_regs (struct pt_regs *pt, elf_gregset_t dst)
+{
+	unw_init_running(do_copy_regs, dst);
+}
+
+int
+dump_task_fpu (struct task_struct *task, elf_fpregset_t *dst)
 {
 	struct unw_frame_info tcore_info;
 
-	if(current == task) {
+	if (current == task) {
 		unw_init_running(do_dump_fpu, dst);
-	}
-	else {
-		memset(&tcore_info, 0, sizeof(tcore_info));	
+	} else {
+		memset(&tcore_info, 0, sizeof(tcore_info));
 		unw_init_from_blocked_task(&tcore_info, task);
 		do_dump_task_fpu(task, &tcore_info, dst);
 	}
+	return 1;
+}
 
-	return 1; 
+int
+dump_fpu (struct pt_regs *pt, elf_fpregset_t dst)
+{
+	unw_init_running(do_dump_fpu, dst);
+	return 1;	/* f0-f31 are always valid so we always return 1 */
 }
 
 asmlinkage long
diff -Nru a/arch/ia64/kernel/ptrace.c b/arch/ia64/kernel/ptrace.c
--- a/arch/ia64/kernel/ptrace.c	Mon Dec 23 21:22:01 2002
+++ b/arch/ia64/kernel/ptrace.c	Mon Dec 23 21:22:01 2002
@@ -1,7 +1,7 @@
 /*
  * Kernel support for the ptrace() and syscall tracing interfaces.
  *
- * Copyright (C) 1999-2001 Hewlett-Packard Co
+ * Copyright (C) 1999-2002 Hewlett-Packard Co
  *	David Mosberger-Tang <davidm@hpl.hp.com>
  *
  * Derived from the x86 and Alpha versions.  Most of the code in here
@@ -10,6 +10,7 @@
 #include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
+#include <linux/slab.h>
 #include <linux/mm.h>
 #include <linux/errno.h>
 #include <linux/ptrace.h>
@@ -460,6 +461,60 @@
 	pt->loadrs = 0;
 }
 
+static inline void
+sync_user_rbs_one_thread (struct task_struct *p, int make_writable)
+{
+	struct switch_stack *sw;
+	unsigned long urbs_end;
+	struct pt_regs *pt;
+
+	sw = (struct switch_stack *) (p->thread.ksp + 16);
+	pt = ia64_task_regs(p);
+	urbs_end = ia64_get_user_rbs_end(p, pt, NULL);
+	ia64_sync_user_rbs(p, sw, pt->ar_bspstore, urbs_end);
+	if (make_writable)
+		user_flushrs(p, pt);
+}
+
+struct task_list {
+	struct task_list *next;
+	struct task_struct *task;
+};
+
+#ifdef CONFIG_SMP
+
+static inline void
+collect_task (struct task_list **listp, struct task_struct *p, int make_writable)
+{
+	struct task_list *e;
+
+	e = kmalloc(sizeof(*e), GFP_KERNEL);
+	if (!e)
+		/* oops, can't collect more: finish at least what we collected so far... */
+		return;
+
+	get_task_struct(p);
+	e->task = p;
+	e->next = *listp;
+	*listp = e;
+}
+
+static inline struct task_list *
+finish_task (struct task_list *list, int make_writable)
+{
+	struct task_list *next = list->next;
+
+	sync_user_rbs_one_thread(list->task, make_writable);
+	put_task_struct(list->task);
+	kfree(list);
+	return next;
+}
+
+#else
+# define collect_task(list, p, make_writable)	sync_user_rbs_one_thread(p, make_writable)
+# define finish_task(list, make_writable)	(NULL)
+#endif
+
 /*
  * Synchronize the RSE backing store of CHILD and all tasks that share the address space
  * with it.  CHILD_URBS_END is the address of the end of the register backing store of
@@ -473,7 +528,6 @@
 threads_sync_user_rbs (struct task_struct *child, unsigned long child_urbs_end, int make_writable)
 {
 	struct switch_stack *sw;
-	unsigned long urbs_end;
 	struct task_struct *g, *p;
 	struct mm_struct *mm;
 	struct pt_regs *pt;
@@ -493,20 +547,27 @@
 		if (make_writable)
 			user_flushrs(child, pt);
 	} else {
+		/*
+		 * Note: we can't call ia64_sync_user_rbs() while holding the
+		 * tasklist_lock because that may cause a dead-lock: ia64_sync_user_rbs()
+		 * may indirectly call tlb_flush_all(), which triggers an IPI.
+		 * Furthermore, tasklist_lock is acquired by fork() with interrupts
+		 * disabled, so with the right timing, the IPI never completes, hence
+		 * tasklist_lock never gets released, hence fork() never completes...
+		 */
+		struct task_list *list = NULL;
+
 		read_lock(&tasklist_lock);
 		{
 			do_each_thread(g, p) {
-				if (p->mm == mm && p->state != TASK_RUNNING) {
-					sw = (struct switch_stack *) (p->thread.ksp + 16);
-					pt = ia64_task_regs(p);
-					urbs_end = ia64_get_user_rbs_end(p, pt, NULL);
-					ia64_sync_user_rbs(p, sw, pt->ar_bspstore, urbs_end);
-					if (make_writable)
-						user_flushrs(p, pt);
-				}
+				if (p->mm == mm && p->state != TASK_RUNNING)
+					collect_task(&list, p, make_writable);
 			} while_each_thread(g, p);
 		}
 		read_unlock(&tasklist_lock);
+
+		while (list)
+			list = finish_task(list, make_writable);
 	}
 	child->thread.flags |= IA64_THREAD_KRBS_SYNCED;	/* set the flag in the child thread only */
 }
diff -Nru a/arch/ia64/kernel/sal.c b/arch/ia64/kernel/sal.c
--- a/arch/ia64/kernel/sal.c	Mon Dec 23 21:22:00 2002
+++ b/arch/ia64/kernel/sal.c	Mon Dec 23 21:22:00 2002
@@ -77,7 +77,7 @@
 	return str;
 }
 
-static void __init
+void __init
 ia64_sal_handler_init (void *entry_point, void *gpval)
 {
 	/* fill in the SAL procedure descriptor and point ia64_sal to it: */
diff -Nru a/arch/ia64/kernel/setup.c b/arch/ia64/kernel/setup.c
--- a/arch/ia64/kernel/setup.c	Mon Dec 23 21:21:51 2002
+++ b/arch/ia64/kernel/setup.c	Mon Dec 23 21:21:51 2002
@@ -364,11 +364,13 @@
 #ifdef CONFIG_ACPI_BOOT
 	/* Initialize the ACPI boot-time table parser */
 	acpi_table_init(*cmdline_p);
-
-#ifdef CONFIG_ACPI_NUMA
+# ifdef CONFIG_ACPI_NUMA
 	acpi_numa_init();
-#endif
-
+# endif
+#else
+# ifdef CONFIG_SMP
+	smp_build_cpu_map();	/* happens, e.g., with the Ski simulator */
+# endif
 #endif /* CONFIG_APCI_BOOT */
 
 	find_memory();
@@ -469,9 +471,18 @@
 #	define lpj	loops_per_jiffy
 #	define cpunum	0
 #endif
-	char family[32], features[128], *cp;
+	static struct {
+		unsigned long mask;
+		const char *feature_name;
+	} feature_bits[] = {
+		{ 1UL << 0, "branchlong" },
+		{ 1UL << 1, "spontaneous deferral"},
+		{ 1UL << 2, "16-byte atomic ops" }
+	};
+	char family[32], features[128], *cp, sep;
 	struct cpuinfo_ia64 *c = v;
 	unsigned long mask;
+	int i;
 
 	mask = c->features;
 
@@ -484,13 +495,24 @@
 	/* build the feature string: */
 	memcpy(features, " standard", 10);
 	cp = features;
-	if (mask & 1) {
-		strcpy(cp, " branchlong");
-		cp = strchr(cp, '\0');
-		mask &= ~1UL;
+	sep = 0;
+	for (i = 0; i < sizeof(feature_bits)/sizeof(feature_bits[0]); ++i) {
+		if (mask & feature_bits[i].mask) {
+			if (sep)
+				*cp++ = sep;
+			sep = ',';
+			*cp++ = ' ';
+			strcpy(cp, feature_bits[i].feature_name);
+			cp += strlen(feature_bits[i].feature_name);
+			mask &= ~feature_bits[i].mask;
+		}
 	}
-	if (mask)
+	if (mask) {
+		/* print unknown features as a hex value: */
+		if (sep)
+			*cp++ = sep;
 		sprintf(cp, " 0x%lx", mask);
+	}
 
 	seq_printf(m,
 		   "processor  : %d\n"
@@ -630,9 +652,8 @@
 	 * "NR_CPUS" pages for all CPUs to avoid that AP calls get_zeroed_page().
 	 */
 	if (smp_processor_id() == 0) {
-		cpu_data = (unsigned long) __alloc_bootmem(PERCPU_PAGE_SIZE * NR_CPUS,
-							   PERCPU_PAGE_SIZE,
-							   __pa(MAX_DMA_ADDRESS));
+		cpu_data = __alloc_bootmem(PERCPU_PAGE_SIZE * NR_CPUS, PERCPU_PAGE_SIZE,
+					   __pa(MAX_DMA_ADDRESS));
 		for (cpu = 0; cpu < NR_CPUS; cpu++) {
 			memcpy(cpu_data, __phys_per_cpu_start, __per_cpu_end - __per_cpu_start);
 			__per_cpu_offset[cpu] = (char *) cpu_data - __per_cpu_start;
diff -Nru a/arch/ia64/kernel/signal.c b/arch/ia64/kernel/signal.c
--- a/arch/ia64/kernel/signal.c	Mon Dec 23 21:21:56 2002
+++ b/arch/ia64/kernel/signal.c	Mon Dec 23 21:21:56 2002
@@ -385,15 +385,14 @@
 
 	frame = (void *) scr->pt.r12;
 	tramp_addr = GATE_ADDR + (ia64_sigtramp - __start_gate_section);
-	if (ka->sa.sa_flags & SA_ONSTACK) {
+	if ((ka->sa.sa_flags & SA_ONSTACK) && sas_ss_flags((unsigned long) frame) == 0) {
+		frame = (void *) ((current->sas_ss_sp + current->sas_ss_size)
+				  & ~(STACK_ALIGN - 1));
 		/*
-		 * We need to check the memory and register stacks separately, because
-		 * they're switched separately (memory stack is switched in the kernel,
-		 * register stack is switched in the signal trampoline).
+		 * We need to check for the register stack being on the signal stack
+		 * separately, because it's switched separately (memory stack is switched
+		 * in the kernel, register stack is switched in the signal trampoline).
 		 */
-		if (!on_sig_stack((unsigned long) frame))
-			frame = (void *) ((current->sas_ss_sp + current->sas_ss_size)
-					  & ~(STACK_ALIGN - 1));
 		if (!rbs_on_sig_stack(scr->pt.ar_bspstore))
 			new_rbs  = (current->sas_ss_sp + sizeof(long) - 1) & ~(sizeof(long) - 1);
 	}
@@ -453,16 +452,14 @@
 handle_signal (unsigned long sig, struct k_sigaction *ka, siginfo_t *info, sigset_t *oldset,
 	       struct sigscratch *scr)
 {
-#ifdef CONFIG_IA32_SUPPORT
 	if (IS_IA32_PROCESS(&scr->pt)) {
 		/* send signal to IA-32 process */
 		if (!ia32_setup_frame1(sig, ka, info, oldset, &scr->pt))
 			return 0;
 	} else
-#endif
-	/* send signal to IA-64 process */
-	if (!setup_frame(sig, ka, info, oldset, scr))
-		return 0;
+		/* send signal to IA-64 process */
+		if (!setup_frame(sig, ka, info, oldset, scr))
+			return 0;
 
 	if (ka->sa.sa_flags & SA_ONESHOT)
 		ka->sa.sa_handler = SIG_DFL;
@@ -490,6 +487,7 @@
 	siginfo_t info;
 	long restart = in_syscall;
 	long errno = scr->pt.r8;
+#	define ERR_CODE(c)	(IS_IA32_PROCESS(&scr->pt) ? -(c) : (c))
 
 	/*
 	 * In the ia64_leave_kernel code path, we want the common case to go fast, which
@@ -502,7 +500,6 @@
 	if (!oldset)
 		oldset = &current->blocked;
 
-#ifdef CONFIG_IA32_SUPPORT
 	if (IS_IA32_PROCESS(&scr->pt)) {
 		if (in_syscall) {
 			if (errno >= 0)
@@ -510,9 +507,7 @@
 			else
 				errno = -errno;
 		}
-	} else
-#endif
-	if (scr->pt.r10 != -1)
+	} else if (scr->pt.r10 != -1)
 		/*
 		 * A system calls has to be restarted only if one of the error codes
 		 * ERESTARTNOHAND, ERESTARTSYS, or ERESTARTNOINTR is returned.  If r10
@@ -531,25 +526,24 @@
 
 		if (restart) {
 			switch (errno) {
+			      case ERESTART_RESTARTBLOCK:
+				current_thread_info()->restart_block.fn = do_no_restart_syscall;
+			      case ERESTARTNOHAND:
+				scr->pt.r8 = ERR_CODE(EINTR);
+				/* note: scr->pt.r10 is already -1 */
+				break;
+
 			      case ERESTARTSYS:
 				if ((ka->sa.sa_flags & SA_RESTART) == 0) {
-			      case ERESTARTNOHAND:
-#ifdef CONFIG_IA32_SUPPORT
-					if (IS_IA32_PROCESS(&scr->pt))
-						scr->pt.r8 = -EINTR;
-					else
-#endif
-						scr->pt.r8 = EINTR;
+					scr->pt.r8 = ERR_CODE(EINTR);
 					/* note: scr->pt.r10 is already -1 */
 					break;
 				}
 			      case ERESTARTNOINTR:
-#ifdef CONFIG_IA32_SUPPORT
 				if (IS_IA32_PROCESS(&scr->pt)) {
 					scr->pt.r8 = scr->pt.r1;
 					scr->pt.cr_iip -= 2;
 				} else
-#endif
 					ia64_decrement_ip(&scr->pt);
 			}
 		}
@@ -565,19 +559,26 @@
 	/* Did we come from a system call? */
 	if (restart) {
 		/* Restart the system call - no handlers present */
-		if (errno == ERESTARTNOHAND || errno == ERESTARTSYS || errno == ERESTARTNOINTR) {
-#ifdef CONFIG_IA32_SUPPORT
+		if (errno == ERESTARTNOHAND || errno == ERESTARTSYS || errno == ERESTARTNOINTR
+		    || errno == ERESTART_RESTARTBLOCK)
+		{
 			if (IS_IA32_PROCESS(&scr->pt)) {
 				scr->pt.r8 = scr->pt.r1;
 				scr->pt.cr_iip -= 2;
-			} else
-#endif
-			/*
-			 * Note: the syscall number is in r15 which is saved in pt_regs so
-			 * all we need to do here is adjust ip so that the "break"
-			 * instruction gets re-executed.
-			 */
-			ia64_decrement_ip(&scr->pt);
+				if (errno == ERESTART_RESTARTBLOCK) {
+					scr->pt.r8 = 0;	/* x86 version of __NR_restart_syscall */
+					scr->pt.cr_iip -= 2;
+				}
+			} else {
+				/*
+				 * Note: the syscall number is in r15 which is saved in
+				 * pt_regs so all we need to do here is adjust ip so that
+				 * the "break" instruction gets re-executed.
+				 */
+				ia64_decrement_ip(&scr->pt);
+				if (errno == ERESTART_RESTARTBLOCK)
+					scr->pt.r15 = __NR_restart_syscall;
+			}
 		}
 	}
 	return 0;
diff -Nru a/arch/ia64/kernel/smp.c b/arch/ia64/kernel/smp.c
--- a/arch/ia64/kernel/smp.c	Mon Dec 23 21:22:01 2002
+++ b/arch/ia64/kernel/smp.c	Mon Dec 23 21:22:01 2002
@@ -206,8 +206,27 @@
 void
 smp_flush_tlb_all (void)
 {
-	smp_call_function((void (*)(void *))__flush_tlb_all, 0, 1, 1);
-	__flush_tlb_all();
+	smp_call_function((void (*)(void *))local_flush_tlb_all, 0, 1, 1);
+	local_flush_tlb_all();
+}
+
+void
+smp_flush_tlb_mm (struct mm_struct *mm)
+{
+	local_finish_flush_tlb_mm(mm);
+
+	/* this happens for the common case of a single-threaded fork():  */
+	if (likely(mm == current->active_mm && atomic_read(&mm->mm_users) == 1))
+		return;
+
+	/*
+	 * We could optimize this further by using mm->cpu_vm_mask to track which CPUs
+	 * have been running in the address space.  It's not clear that this is worth the
+	 * trouble though: to avoid races, we have to raise the IPI on the target CPU
+	 * anyhow, and once a CPU is interrupted, the cost of local_flush_tlb_all() is
+	 * rather trivial.
+	 */
+	smp_call_function((void (*)(void *))local_finish_flush_tlb_mm, mm, 1, 1);
 }
 
 /*
diff -Nru a/arch/ia64/kernel/smpboot.c b/arch/ia64/kernel/smpboot.c
--- a/arch/ia64/kernel/smpboot.c	Mon Dec 23 21:21:52 2002
+++ b/arch/ia64/kernel/smpboot.c	Mon Dec 23 21:21:52 2002
@@ -337,7 +337,7 @@
 	 * don't care about the eip and regs settings since we'll never reschedule the
 	 * forked task.
 	 */
-	return do_fork(CLONE_VM|CLONE_IDLETASK, 0, 0, 0, NULL);
+	return do_fork(CLONE_VM|CLONE_IDLETASK, 0, 0, 0, NULL, NULL);
 }
 
 static int __init
@@ -499,7 +499,7 @@
 	/*
 	 * If SMP should be disabled, then really disable it!
 	 */
-	if (!max_cpus || (max_cpus < -1)) {
+	if (!max_cpus) {
 		printk(KERN_INFO "SMP mode deactivated.\n");
 		cpu_online_map = phys_cpu_present_map = 1;
 		return;
diff -Nru a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
--- a/arch/ia64/kernel/sys_ia64.c	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/kernel/sys_ia64.c	Mon Dec 23 21:21:55 2002
@@ -12,6 +12,7 @@
 #include <linux/hugetlb.h>
 #include <linux/mman.h>
 #include <linux/sched.h>
+#include <linux/shm.h>
 #include <linux/file.h>		/* doh, must come after sched.h... */
 #include <linux/smp.h>
 #include <linux/smp_lock.h>
@@ -317,22 +318,26 @@
 
 #endif /* !CONFIG_HUGETLB_PAGE */
 
-asmlinkage long
-sys_vm86 (long arg0, long arg1, long arg2, long arg3)
-{
-	printk(KERN_ERR "sys_vm86(%lx, %lx, %lx, %lx)!\n", arg0, arg1, arg2, arg3);
-	return -ENOSYS;
-}
-
 asmlinkage unsigned long
-ia64_create_module (const char *name_user, size_t size)
+ia64_mremap (unsigned long addr, unsigned long old_len, unsigned long new_len, unsigned long flags,
+	     unsigned long new_addr)
 {
-	extern unsigned long sys_create_module (const char *, size_t);
-	unsigned long   addr;
+	extern unsigned long do_mremap (unsigned long addr,
+					unsigned long old_len,
+					unsigned long new_len,
+					unsigned long flags,
+					unsigned long new_addr);
 
-	addr = sys_create_module (name_user, size);
-	if (!IS_ERR((void *) addr))
-		force_successful_syscall_return();
+	down_write(&current->mm->mmap_sem);
+	{
+		addr = do_mremap(addr, old_len, new_len, flags, new_addr);
+	}
+	up_write(&current->mm->mmap_sem);
+
+	if (IS_ERR((void *) addr))
+		return addr;
+
+	force_successful_syscall_return();
 	return addr;
 }
 
diff -Nru a/arch/ia64/kernel/unaligned.c b/arch/ia64/kernel/unaligned.c
--- a/arch/ia64/kernel/unaligned.c	Mon Dec 23 21:22:00 2002
+++ b/arch/ia64/kernel/unaligned.c	Mon Dec 23 21:22:00 2002
@@ -5,6 +5,10 @@
  *	Stephane Eranian <eranian@hpl.hp.com>
  *	David Mosberger-Tang <davidm@hpl.hp.com>
  *
+ * 2002/12/09   Fix rotating register handling (off-by-1 error, missing fr-rotation).  Fix
+ *		get_rse_reg() to not leak kernel bits to user-level (reading an out-of-frame
+ *		stacked register returns an undefined value; it does NOT trigger a
+ *		"rsvd register fault").
  * 2001/10/11	Fix unaligned access to rotating registers in s/w pipelined loops.
  * 2001/08/13	Correct size of extended floats (float_fsz) from 16 to 10 bytes.
  * 2001/01/17	Add support emulation of unaligned kernel accesses.
@@ -276,6 +280,15 @@
 #	undef F
 }
 
+static inline unsigned long
+rotate_reg (unsigned long sor, unsigned long rrb, unsigned long reg)
+{
+	reg += rrb;
+	if (reg >= sor)
+		reg -= sor;
+	return reg;
+}
+
 static void
 set_rse_reg (struct pt_regs *regs, unsigned long r1, unsigned long val, int nat)
 {
@@ -287,26 +300,22 @@
 	long sof = (regs->cr_ifs) & 0x7f;
 	long sor = 8 * ((regs->cr_ifs >> 14) & 0xf);
 	long rrb_gr = (regs->cr_ifs >> 18) & 0x7f;
-	long ridx;
-
-	if ((r1 - 32) > sor)
-		ridx = -sof + (r1 - 32);
-	else if ((r1 - 32) < (sor - rrb_gr))
-		ridx = -sof + (r1 - 32) + rrb_gr;
-	else
-		ridx = -sof + (r1 - 32) - (sor - rrb_gr);
-
-	DPRINT("r%lu, sw.bspstore=%lx pt.bspstore=%lx sof=%ld sol=%ld ridx=%ld\n",
-	       r1, sw->ar_bspstore, regs->ar_bspstore, sof, (regs->cr_ifs >> 7) & 0x7f, ridx);
+	long ridx = r1 - 32;
 
-	if ((r1 - 32) >= sof) {
+	if (ridx >= sof) {
 		/* this should never happen, as the "rsvd register fault" has higher priority */
 		DPRINT("ignoring write to r%lu; only %lu registers are allocated!\n", r1, sof);
 		return;
 	}
 
+	if (ridx < sor)
+		ridx = rotate_reg(sor, rrb_gr, ridx);
+
+	DPRINT("r%lu, sw.bspstore=%lx pt.bspstore=%lx sof=%ld sol=%ld ridx=%ld\n",
+	       r1, sw->ar_bspstore, regs->ar_bspstore, sof, (regs->cr_ifs >> 7) & 0x7f, ridx);
+
 	on_kbs = ia64_rse_num_regs(kbs, (unsigned long *) sw->ar_bspstore);
-	addr = ia64_rse_skip_regs((unsigned long *) sw->ar_bspstore, ridx);
+	addr = ia64_rse_skip_regs((unsigned long *) sw->ar_bspstore, -sof + ridx);
 	if (addr >= kbs) {
 		/* the register is on the kernel backing store: easy... */
 		rnat_addr = ia64_rse_rnat_addr(addr);
@@ -334,7 +343,7 @@
 	bspstore = (unsigned long *)regs->ar_bspstore;
 	ubs_end = ia64_rse_skip_regs(bspstore, on_kbs);
 	bsp     = ia64_rse_skip_regs(ubs_end, -sof);
-	addr    = ia64_rse_skip_regs(bsp, ridx + sof);
+	addr    = ia64_rse_skip_regs(bsp, ridx);
 
 	DPRINT("ubs_end=%p bsp=%p addr=%p\n", (void *) ubs_end, (void *) bsp, (void *) addr);
 
@@ -368,26 +377,22 @@
 	long sof = (regs->cr_ifs) & 0x7f;
 	long sor = 8 * ((regs->cr_ifs >> 14) & 0xf);
 	long rrb_gr = (regs->cr_ifs >> 18) & 0x7f;
-	long ridx;
+	long ridx = r1 - 32;
 
-	if ((r1 - 32) > sor)
-		ridx = -sof + (r1 - 32);
-	else if ((r1 - 32) < (sor - rrb_gr))
-		ridx = -sof + (r1 - 32) + rrb_gr;
-	else
-		ridx = -sof + (r1 - 32) - (sor - rrb_gr);
+	if (ridx >= sof) {
+		/* read of out-of-frame register returns an undefined value; 0 in our case.  */
+		DPRINT("ignoring read from r%lu; only %lu registers are allocated!\n", r1, sof);
+		goto fail;
+	}
+
+	if (ridx < sor)
+		ridx = rotate_reg(sor, rrb_gr, ridx);
 
 	DPRINT("r%lu, sw.bspstore=%lx pt.bspstore=%lx sof=%ld sol=%ld ridx=%ld\n",
 	       r1, sw->ar_bspstore, regs->ar_bspstore, sof, (regs->cr_ifs >> 7) & 0x7f, ridx);
 
-	if ((r1 - 32) >= sof) {
-		/* this should never happen, as the "rsvd register fault" has higher priority */
-		DPRINT("ignoring read from r%lu; only %lu registers are allocated!\n", r1, sof);
-		return;
-	}
-
 	on_kbs = ia64_rse_num_regs(kbs, (unsigned long *) sw->ar_bspstore);
-	addr = ia64_rse_skip_regs((unsigned long *) sw->ar_bspstore, ridx);
+	addr = ia64_rse_skip_regs((unsigned long *) sw->ar_bspstore, -sof + ridx);
 	if (addr >= kbs) {
 		/* the register is on the kernel backing store: easy... */
 		*val = *addr;
@@ -407,13 +412,13 @@
 	 */
 	if (regs->r12 >= TASK_SIZE) {
 		DPRINT("ignoring kernel read of r%lu; register isn't on the RBS!", r1);
-		return;
+		goto fail;
 	}
 
 	bspstore = (unsigned long *)regs->ar_bspstore;
 	ubs_end = ia64_rse_skip_regs(bspstore, on_kbs);
 	bsp     = ia64_rse_skip_regs(ubs_end, -sof);
-	addr    = ia64_rse_skip_regs(bsp, ridx + sof);
+	addr    = ia64_rse_skip_regs(bsp, ridx);
 
 	DPRINT("ubs_end=%p bsp=%p addr=%p\n", (void *) ubs_end, (void *) bsp, (void *) addr);
 
@@ -428,6 +433,13 @@
 		ia64_peek(current, sw, (unsigned long) ubs_end, (unsigned long) rnat_addr, &rnats);
 		*nat = (rnats & nat_mask) != 0;
 	}
+	return;
+
+  fail:
+	*val = 0;
+	if (nat)
+		*nat = 0;
+	return;
 }
 
 
@@ -486,7 +498,16 @@
 	DPRINT("*0x%lx=0x%lx NaT=%d new unat: %p=%lx\n", addr, val, nat, (void *) unat,*unat);
 }
 
-#define IA64_FPH_OFFS(r) (r - IA64_FIRST_ROTATING_FR)
+/*
+ * Return the (rotated) index for floating point register REGNUM (REGNUM must be in the
+ * range from 32-127, result is in the range from 0-95.
+ */
+static inline unsigned long
+fph_index (struct pt_regs *regs, long regnum)
+{
+	unsigned long rrb_fr = (regs->cr_ifs >> 25) & 0x7f;
+	return rotate_reg(96, rrb_fr, (regnum - IA64_FIRST_ROTATING_FR));
+}
 
 static void
 setfpreg (unsigned long regnum, struct ia64_fpreg *fpval, struct pt_regs *regs)
@@ -507,7 +528,7 @@
 	 */
 	if (regnum >= IA64_FIRST_ROTATING_FR) {
 		ia64_sync_fph(current);
-		current->thread.fph[IA64_FPH_OFFS(regnum)] = *fpval;
+		current->thread.fph[fph_index(regs, regnum)] = *fpval;
 	} else {
 		/*
 		 * pt_regs or switch_stack ?
@@ -566,7 +587,7 @@
 	 */
 	if (regnum >= IA64_FIRST_ROTATING_FR) {
 		ia64_flush_fph(current);
-		*fpval = current->thread.fph[IA64_FPH_OFFS(regnum)];
+		*fpval = current->thread.fph[fph_index(regs, regnum)];
 	} else {
 		/*
 		 * f0 = 0.0, f1= 1.0. Those registers are constant and are thus
@@ -651,8 +672,8 @@
 	 * just in case.
 	 */
 	if (ld.x6_op == 1 || ld.x6_op == 3) {
-		printk("%s %s: register update on speculative load, error\n", KERN_ERR, __FUNCTION__);
-		die_if_kernel("unaligned reference on specualtive load with register update\n",
+		printk(KERN_ERR "%s: register update on speculative load, error\n", __FUNCTION__);
+		die_if_kernel("unaligned reference on speculative load with register update\n",
 			      regs, 30);
 	}
 
@@ -1081,8 +1102,8 @@
 		 * For this reason we keep this sanity check
 		 */
 		if (ld.x6_op == 1 || ld.x6_op == 3)
-			printk("%s %s: register update on speculative load pair, "
-			       "error\n",KERN_ERR, __FUNCTION__);
+			printk(KERN_ERR "%s: register update on speculative load pair, error\n",
+			       __FUNCTION__);
 
 		setreg(ld.r3, ifa, 0, regs);
 	}
diff -Nru a/arch/ia64/mm/Makefile b/arch/ia64/mm/Makefile
--- a/arch/ia64/mm/Makefile	Mon Dec 23 21:21:52 2002
+++ b/arch/ia64/mm/Makefile	Mon Dec 23 21:21:52 2002
@@ -1,13 +1,9 @@
 #
 # Makefile for the ia64-specific parts of the memory manager.
 #
-# Note! Dependencies are done automagically by 'make dep', which also
-# removes any old dependencies. DON'T put your own dependencies here
-# unless it's something special (ie not a .c file).
-#
-# Note 2! The CFLAGS definition is now in the main makefile...
 
-obj-y	 := init.o fault.o tlb.o extable.o
+obj-y := init.o fault.o tlb.o extable.o
+
 obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
-obj-$(CONFIG_NUMA) += numa.o
+obj-$(CONFIG_NUMA)	   += numa.o
 obj-$(CONFIG_DISCONTIGMEM) += discontig.o
diff -Nru a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
--- a/arch/ia64/mm/fault.c	Mon Dec 23 21:22:00 2002
+++ b/arch/ia64/mm/fault.c	Mon Dec 23 21:22:00 2002
@@ -96,13 +96,13 @@
 	 * fault.
 	 */
 	switch (handle_mm_fault(mm, vma, address, (mask & VM_WRITE) != 0)) {
-	      case 1:
+	      case VM_FAULT_MINOR:
 		++current->min_flt;
 		break;
-	      case 2:
+	      case VM_FAULT_MAJOR:
 		++current->maj_flt;
 		break;
-	      case 0:
+	      case VM_FAULT_SIGBUS:
 		/*
 		 * We ran out of memory, or some other thing happened
 		 * to us that made us unable to handle the page fault
@@ -110,8 +110,10 @@
 		 */
 		signal = SIGBUS;
 		goto bad_area;
-	      default:
+	      case VM_FAULT_OOM:
 		goto out_of_memory;
+	      default:
+		BUG();
 	}
 	up_read(&mm->mmap_sem);
 	return;
diff -Nru a/arch/ia64/mm/tlb.c b/arch/ia64/mm/tlb.c
--- a/arch/ia64/mm/tlb.c	Mon Dec 23 21:21:58 2002
+++ b/arch/ia64/mm/tlb.c	Mon Dec 23 21:21:58 2002
@@ -84,7 +84,7 @@
 	for (i = 0; i < NR_CPUS; ++i)
 		if (i != smp_processor_id())
 			per_cpu(ia64_need_tlb_flush, i) = 1;
-	__flush_tlb_all();
+	local_flush_tlb_all();
 }
 
 void
@@ -108,7 +108,7 @@
 }
 
 void
-__flush_tlb_all (void)
+local_flush_tlb_all (void)
 {
 	unsigned long i, j, flags, count0, count1, stride0, stride1, addr;
 
@@ -194,5 +194,5 @@
 	local_cpu_data->ptce_stride[0] = ptce_info.stride[0];
 	local_cpu_data->ptce_stride[1] = ptce_info.stride[1];
 
-	__flush_tlb_all();		/* nuke left overs from bootstrapping... */
+	local_flush_tlb_all();		/* nuke left overs from bootstrapping... */
 }
diff -Nru a/arch/ia64/pci/Makefile b/arch/ia64/pci/Makefile
--- a/arch/ia64/pci/Makefile	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/pci/Makefile	Mon Dec 23 21:21:55 2002
@@ -1 +1,4 @@
+#
+# Makefile for the ia64-specific parts of the pci bus
+#
 obj-y		:= pci.o
diff -Nru a/arch/ia64/pci/pci.c b/arch/ia64/pci/pci.c
--- a/arch/ia64/pci/pci.c	Mon Dec 23 21:21:54 2002
+++ b/arch/ia64/pci/pci.c	Mon Dec 23 21:21:54 2002
@@ -44,10 +44,6 @@
 #define DBG(x...)
 #endif
 
-#ifdef CONFIG_IA64_MCA
-extern void ia64_mca_check_errors( void );
-#endif
-
 struct pci_fixup pcibios_fixups[1];
 
 /*
diff -Nru a/arch/ia64/sn/configs/sn1/defconfig-bigsur-mp b/arch/ia64/sn/configs/sn1/defconfig-bigsur-mp
--- a/arch/ia64/sn/configs/sn1/defconfig-bigsur-mp	Mon Dec 23 21:21:53 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,765 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-CONFIG_EXPERIMENTAL=y
-
-#
-# Loadable module support
-#
-# CONFIG_MODULES is not set
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-CONFIG_ITANIUM=y
-# CONFIG_MCKINLEY is not set
-# CONFIG_IA64_GENERIC is not set
-CONFIG_IA64_DIG=y
-# CONFIG_IA64_HP_SIM is not set
-# CONFIG_IA64_SGI_SN1 is not set
-# CONFIG_IA64_SGI_SN2 is not set
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_BRL_EMU=y
-CONFIG_ITANIUM_BSTEP_SPECIFIC=y
-CONFIG_IA64_L1_CACHE_SHIFT=6
-# CONFIG_NUMA is not set
-# CONFIG_IA64_MCA is not set
-CONFIG_PM=y
-CONFIG_IA64_HAVE_SYNCRONIZED_ITC=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_KCORE_ELF=y
-CONFIG_SMP=y
-CONFIG_IA32_SUPPORT=y
-CONFIG_PERFMON=y
-CONFIG_IA64_PALINFO=y
-# CONFIG_EFI_VARS is not set
-CONFIG_NET=y
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-CONFIG_SYSCTL=y
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Networking options
-#
-# CONFIG_PACKET is not set
-# CONFIG_NETLINK is not set
-# CONFIG_NETFILTER is not set
-# CONFIG_FILTER is not set
-CONFIG_UNIX=y
-CONFIG_INET=y
-# CONFIG_IP_MULTICAST is not set
-# CONFIG_IP_ADVANCED_ROUTER is not set
-# CONFIG_IP_PNP is not set
-# CONFIG_NET_IPIP is not set
-# CONFIG_NET_IPGRE is not set
-# CONFIG_INET_ECN is not set
-# CONFIG_SYN_COOKIES is not set
-# CONFIG_IPV6 is not set
-# CONFIG_KHTTPD is not set
-# CONFIG_ATM is not set
-
-#
-#  
-#
-# CONFIG_IPX is not set
-# CONFIG_ATALK is not set
-# CONFIG_DECNET is not set
-# CONFIG_BRIDGE is not set
-# CONFIG_X25 is not set
-# CONFIG_LAPB is not set
-# CONFIG_LLC is not set
-# CONFIG_NET_DIVERT is not set
-# CONFIG_ECONET is not set
-# CONFIG_WAN_ROUTER is not set
-# CONFIG_NET_FASTROUTE is not set
-# CONFIG_NET_HW_FLOWCONTROL is not set
-
-#
-# QoS and/or fair queueing
-#
-# CONFIG_NET_SCHED is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-# CONFIG_PNPBIOS is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-# CONFIG_BLK_DEV_LOOP is not set
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_LAN is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-CONFIG_BLK_DEV_IDECD=y
-# CONFIG_BLK_DEV_IDETAPE is not set
-CONFIG_BLK_DEV_IDEFLOPPY=y
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDEPCI_SHARE_IRQ is not set
-CONFIG_BLK_DEV_IDEDMA_PCI=y
-CONFIG_BLK_DEV_ADMA=y
-# CONFIG_BLK_DEV_OFFBOARD is not set
-# CONFIG_IDEDMA_PCI_AUTO is not set
-CONFIG_BLK_DEV_IDEDMA=y
-# CONFIG_IDEDMA_NEW_DRIVE_LISTINGS is not set
-# CONFIG_BLK_DEV_AEC62XX is not set
-# CONFIG_AEC62XX_TUNING is not set
-# CONFIG_BLK_DEV_ALI15X3 is not set
-# CONFIG_WDC_ALI15X3 is not set
-# CONFIG_BLK_DEV_AMD74XX is not set
-# CONFIG_AMD74XX_OVERRIDE is not set
-# CONFIG_BLK_DEV_CMD64X is not set
-# CONFIG_BLK_DEV_CY82C693 is not set
-# CONFIG_BLK_DEV_CS5530 is not set
-# CONFIG_BLK_DEV_HPT34X is not set
-# CONFIG_HPT34X_AUTODMA is not set
-# CONFIG_BLK_DEV_HPT366 is not set
-# CONFIG_BLK_DEV_PIIX is not set
-# CONFIG_PIIX_TUNING is not set
-# CONFIG_BLK_DEV_NS87415 is not set
-# CONFIG_BLK_DEV_OPTI621 is not set
-# CONFIG_BLK_DEV_PDC202XX is not set
-# CONFIG_PDC202XX_BURST is not set
-# CONFIG_PDC202XX_FORCE is not set
-# CONFIG_BLK_DEV_SVWKS is not set
-# CONFIG_BLK_DEV_SIS5513 is not set
-# CONFIG_BLK_DEV_TRM290 is not set
-# CONFIG_BLK_DEV_VIA82CXXX is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_IDEDMA_IVB is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-# CONFIG_XSCSI is not set
-
-#
-# SCSI support
-#
-CONFIG_SCSI=y
-
-#
-# SCSI support type (disk, tape, CD-ROM)
-#
-CONFIG_BLK_DEV_SD=y
-CONFIG_SD_EXTRA_DEVS=40
-# CONFIG_CHR_DEV_ST is not set
-# CONFIG_CHR_DEV_OSST is not set
-# CONFIG_BLK_DEV_SR is not set
-# CONFIG_CHR_DEV_SG is not set
-
-#
-# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
-#
-# CONFIG_SCSI_DEBUG_QUEUES is not set
-CONFIG_SCSI_MULTI_LUN=y
-CONFIG_SCSI_CONSTANTS=y
-CONFIG_SCSI_LOGGING=y
-
-#
-# SCSI low-level drivers
-#
-# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
-# CONFIG_SCSI_7000FASST is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_AHA152X is not set
-# CONFIG_SCSI_AHA1542 is not set
-# CONFIG_SCSI_AHA1740 is not set
-# CONFIG_SCSI_AIC7XXX is not set
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-# CONFIG_SCSI_DPT_I2O is not set
-# CONFIG_SCSI_ADVANSYS is not set
-# CONFIG_SCSI_IN2000 is not set
-# CONFIG_SCSI_AM53C974 is not set
-# CONFIG_SCSI_MEGARAID is not set
-# CONFIG_SCSI_BUSLOGIC is not set
-# CONFIG_SCSI_CPQFCTS is not set
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_DTC3280 is not set
-# CONFIG_SCSI_EATA is not set
-# CONFIG_SCSI_EATA_DMA is not set
-# CONFIG_SCSI_EATA_PIO is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_GDTH is not set
-# CONFIG_SCSI_GENERIC_NCR5380 is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_NCR53C406A is not set
-# CONFIG_SCSI_NCR53C7xx is not set
-# CONFIG_SCSI_NCR53C8XX is not set
-# CONFIG_SCSI_SYM53C8XX is not set
-# CONFIG_SCSI_PAS16 is not set
-# CONFIG_SCSI_PCI2000 is not set
-# CONFIG_SCSI_PCI2220I is not set
-# CONFIG_SCSI_PSI240I is not set
-# CONFIG_SCSI_QLOGIC_FAS is not set
-# CONFIG_SCSI_QLOGIC_ISP is not set
-# CONFIG_SCSI_QLOGIC_FC is not set
-CONFIG_SCSI_QLOGIC_1280=y
-# CONFIG_SCSI_QLOGIC_QLA2100 is not set
-# CONFIG_SCSI_SIM710 is not set
-# CONFIG_SCSI_SYM53C416 is not set
-# CONFIG_SCSI_DC390T is not set
-# CONFIG_SCSI_T128 is not set
-# CONFIG_SCSI_U14_34F is not set
-# CONFIG_SCSI_DEBUG is not set
-
-#
-# Network device support
-#
-CONFIG_NETDEVICES=y
-
-#
-# ARCnet devices
-#
-# CONFIG_ARCNET is not set
-CONFIG_DUMMY=y
-# CONFIG_BONDING is not set
-# CONFIG_EQUALIZER is not set
-# CONFIG_TUN is not set
-
-#
-# Ethernet (10 or 100Mbit)
-#
-CONFIG_NET_ETHERNET=y
-# CONFIG_SUNLANCE is not set
-# CONFIG_HAPPYMEAL is not set
-# CONFIG_SUNBMAC is not set
-# CONFIG_SUNQE is not set
-# CONFIG_SUNLANCE is not set
-# CONFIG_SUNGEM is not set
-# CONFIG_NET_VENDOR_3COM is not set
-# CONFIG_LANCE is not set
-# CONFIG_NET_VENDOR_SMC is not set
-# CONFIG_NET_VENDOR_RACAL is not set
-# CONFIG_HP100 is not set
-# CONFIG_NET_ISA is not set
-CONFIG_NET_PCI=y
-# CONFIG_PCNET32 is not set
-# CONFIG_ADAPTEC_STARFIRE is not set
-# CONFIG_APRICOT is not set
-# CONFIG_CS89x0 is not set
-# CONFIG_TULIP is not set
-# CONFIG_DE4X5 is not set
-# CONFIG_DGRS is not set
-# CONFIG_DM9102 is not set
-CONFIG_EEPRO100=y
-# CONFIG_LNE390 is not set
-# CONFIG_FEALNX is not set
-# CONFIG_NATSEMI is not set
-# CONFIG_NE2K_PCI is not set
-# CONFIG_NE3210 is not set
-# CONFIG_ES3210 is not set
-# CONFIG_8139CP is not set
-# CONFIG_8139TOO is not set
-# CONFIG_8139TOO_PIO is not set
-# CONFIG_8139TOO_TUNE_TWISTER is not set
-# CONFIG_8139TOO_8129 is not set
-# CONFIG_SIS900 is not set
-# CONFIG_EPIC100 is not set
-# CONFIG_SUNDANCE is not set
-# CONFIG_TLAN is not set
-# CONFIG_VIA_RHINE is not set
-# CONFIG_WINBOND_840 is not set
-# CONFIG_NET_POCKET is not set
-
-#
-# Ethernet (1000 Mbit)
-#
-# CONFIG_ACENIC is not set
-# CONFIG_DL2K is not set
-# CONFIG_MYRI_SBUS is not set
-# CONFIG_NS83820 is not set
-# CONFIG_HAMACHI is not set
-# CONFIG_YELLOWFIN is not set
-# CONFIG_SK98LIN is not set
-# CONFIG_FDDI is not set
-# CONFIG_HIPPI is not set
-# CONFIG_PLIP is not set
-# CONFIG_PPP is not set
-# CONFIG_SLIP is not set
-
-#
-# Wireless LAN (non-hamradio)
-#
-# CONFIG_NET_RADIO is not set
-
-#
-# Token Ring devices
-#
-# CONFIG_TR is not set
-# CONFIG_NET_FC is not set
-# CONFIG_RCPCI is not set
-# CONFIG_SHAPER is not set
-
-#
-# Wan interfaces
-#
-# CONFIG_WAN is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-CONFIG_VT=y
-CONFIG_VT_CONSOLE=y
-CONFIG_SERIAL=y
-CONFIG_SERIAL_CONSOLE=y
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-CONFIG_MOUSE=y
-CONFIG_PSMOUSE=y
-# CONFIG_82C710_MOUSE is not set
-# CONFIG_PC110_PAD is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-# CONFIG_EFI_RTC is not set
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-# CONFIG_QUOTA is not set
-CONFIG_AUTOFS_FS=y
-CONFIG_AUTOFS4_FS=y
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-CONFIG_FAT_FS=y
-CONFIG_MSDOS_FS=y
-# CONFIG_UMSDOS_FS is not set
-CONFIG_VFAT_FS=y
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-CONFIG_ISO9660_FS=y
-CONFIG_JOLIET=y
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_MOUNT=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-# CONFIG_XFS_SUPPORT is not set
-
-#
-# Network File Systems
-#
-# CONFIG_CODA_FS is not set
-CONFIG_NFS_FS=y
-CONFIG_NFS_V3=y
-# CONFIG_ROOT_NFS is not set
-CONFIG_NFSD=y
-CONFIG_NFSD_V3=y
-CONFIG_SUNRPC=y
-CONFIG_LOCKD=y
-CONFIG_LOCKD_V4=y
-# CONFIG_SMB_FS is not set
-# CONFIG_NCP_FS is not set
-# CONFIG_NCPFS_PACKET_SIGNING is not set
-# CONFIG_NCPFS_IOCTL_LOCKING is not set
-# CONFIG_NCPFS_STRONG is not set
-# CONFIG_NCPFS_NFS_NS is not set
-# CONFIG_NCPFS_OS2_NS is not set
-# CONFIG_NCPFS_SMALLDOS is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_NCPFS_EXTRAS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-CONFIG_NLS=y
-
-#
-# Native Language Support
-#
-CONFIG_NLS_DEFAULT="iso8859-1"
-# CONFIG_NLS_CODEPAGE_437 is not set
-# CONFIG_NLS_CODEPAGE_737 is not set
-# CONFIG_NLS_CODEPAGE_775 is not set
-# CONFIG_NLS_CODEPAGE_850 is not set
-# CONFIG_NLS_CODEPAGE_852 is not set
-# CONFIG_NLS_CODEPAGE_855 is not set
-# CONFIG_NLS_CODEPAGE_857 is not set
-# CONFIG_NLS_CODEPAGE_860 is not set
-# CONFIG_NLS_CODEPAGE_861 is not set
-# CONFIG_NLS_CODEPAGE_862 is not set
-# CONFIG_NLS_CODEPAGE_863 is not set
-# CONFIG_NLS_CODEPAGE_864 is not set
-# CONFIG_NLS_CODEPAGE_865 is not set
-# CONFIG_NLS_CODEPAGE_866 is not set
-# CONFIG_NLS_CODEPAGE_869 is not set
-# CONFIG_NLS_CODEPAGE_936 is not set
-# CONFIG_NLS_CODEPAGE_950 is not set
-# CONFIG_NLS_CODEPAGE_932 is not set
-# CONFIG_NLS_CODEPAGE_949 is not set
-# CONFIG_NLS_CODEPAGE_874 is not set
-# CONFIG_NLS_ISO8859_8 is not set
-# CONFIG_NLS_CODEPAGE_1251 is not set
-# CONFIG_NLS_ISO8859_1 is not set
-# CONFIG_NLS_ISO8859_2 is not set
-# CONFIG_NLS_ISO8859_3 is not set
-# CONFIG_NLS_ISO8859_4 is not set
-# CONFIG_NLS_ISO8859_5 is not set
-# CONFIG_NLS_ISO8859_6 is not set
-# CONFIG_NLS_ISO8859_7 is not set
-# CONFIG_NLS_ISO8859_9 is not set
-# CONFIG_NLS_ISO8859_13 is not set
-# CONFIG_NLS_ISO8859_14 is not set
-# CONFIG_NLS_ISO8859_15 is not set
-# CONFIG_NLS_KOI8_R is not set
-# CONFIG_NLS_KOI8_U is not set
-# CONFIG_NLS_UTF8 is not set
-
-#
-# Console drivers
-#
-CONFIG_VGA_CONSOLE=y
-
-#
-# Frame-buffer support
-#
-# CONFIG_FB is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-# CONFIG_USB_PEGASUS is not set
-# CONFIG_USB_KAWETH is not set
-# CONFIG_USB_CATC is not set
-# CONFIG_USB_CDCETHER is not set
-# CONFIG_USB_USBNET is not set
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# IEEE 1394 (FireWire) support (EXPERIMENTAL)
-#
-# CONFIG_IEEE1394 is not set
-
-#
-# Bluetooth support
-#
-# CONFIG_BT is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-CONFIG_KDB=y
-CONFIG_KDB_MODULES=y
-# CONFIG_KDB_OFF is not set
-
-#
-#   Load all symbols for debugging is required for KDB
-#
-CONFIG_KALLSYMS=y
diff -Nru a/arch/ia64/sn/configs/sn1/defconfig-bigsur-sp b/arch/ia64/sn/configs/sn1/defconfig-bigsur-sp
--- a/arch/ia64/sn/configs/sn1/defconfig-bigsur-sp	Mon Dec 23 21:21:52 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,760 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-CONFIG_EXPERIMENTAL=y
-
-#
-# Loadable module support
-#
-# CONFIG_MODULES is not set
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-CONFIG_ITANIUM=y
-# CONFIG_MCKINLEY is not set
-# CONFIG_IA64_GENERIC is not set
-CONFIG_IA64_DIG=y
-# CONFIG_IA64_HP_SIM is not set
-# CONFIG_IA64_SGI_SN1 is not set
-# CONFIG_IA64_SGI_SN2 is not set
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_BRL_EMU=y
-CONFIG_ITANIUM_BSTEP_SPECIFIC=y
-CONFIG_IA64_L1_CACHE_SHIFT=6
-# CONFIG_NUMA is not set
-# CONFIG_IA64_MCA is not set
-CONFIG_PM=y
-CONFIG_IA64_HAVE_SYNCRONIZED_ITC=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_KCORE_ELF=y
-# CONFIG_SMP is not set
-CONFIG_IA32_SUPPORT=y
-CONFIG_PERFMON=y
-CONFIG_IA64_PALINFO=y
-# CONFIG_EFI_VARS is not set
-CONFIG_NET=y
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-CONFIG_SYSCTL=y
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Networking options
-#
-# CONFIG_PACKET is not set
-# CONFIG_NETLINK is not set
-# CONFIG_NETFILTER is not set
-# CONFIG_FILTER is not set
-CONFIG_UNIX=y
-CONFIG_INET=y
-# CONFIG_IP_MULTICAST is not set
-# CONFIG_IP_ADVANCED_ROUTER is not set
-# CONFIG_IP_PNP is not set
-# CONFIG_NET_IPIP is not set
-# CONFIG_NET_IPGRE is not set
-# CONFIG_INET_ECN is not set
-# CONFIG_SYN_COOKIES is not set
-# CONFIG_IPV6 is not set
-# CONFIG_KHTTPD is not set
-# CONFIG_ATM is not set
-
-#
-#  
-#
-# CONFIG_IPX is not set
-# CONFIG_ATALK is not set
-# CONFIG_DECNET is not set
-# CONFIG_BRIDGE is not set
-# CONFIG_X25 is not set
-# CONFIG_LAPB is not set
-# CONFIG_LLC is not set
-# CONFIG_NET_DIVERT is not set
-# CONFIG_ECONET is not set
-# CONFIG_WAN_ROUTER is not set
-# CONFIG_NET_FASTROUTE is not set
-# CONFIG_NET_HW_FLOWCONTROL is not set
-
-#
-# QoS and/or fair queueing
-#
-# CONFIG_NET_SCHED is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-# CONFIG_PNPBIOS is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-# CONFIG_BLK_DEV_LOOP is not set
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_LAN is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-CONFIG_BLK_DEV_IDECD=y
-# CONFIG_BLK_DEV_IDETAPE is not set
-CONFIG_BLK_DEV_IDEFLOPPY=y
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDEPCI_SHARE_IRQ is not set
-CONFIG_BLK_DEV_IDEDMA_PCI=y
-CONFIG_BLK_DEV_ADMA=y
-# CONFIG_BLK_DEV_OFFBOARD is not set
-# CONFIG_IDEDMA_PCI_AUTO is not set
-CONFIG_BLK_DEV_IDEDMA=y
-# CONFIG_IDEDMA_NEW_DRIVE_LISTINGS is not set
-# CONFIG_BLK_DEV_AEC62XX is not set
-# CONFIG_AEC62XX_TUNING is not set
-# CONFIG_BLK_DEV_ALI15X3 is not set
-# CONFIG_WDC_ALI15X3 is not set
-# CONFIG_BLK_DEV_AMD74XX is not set
-# CONFIG_AMD74XX_OVERRIDE is not set
-# CONFIG_BLK_DEV_CMD64X is not set
-# CONFIG_BLK_DEV_CY82C693 is not set
-# CONFIG_BLK_DEV_CS5530 is not set
-# CONFIG_BLK_DEV_HPT34X is not set
-# CONFIG_HPT34X_AUTODMA is not set
-# CONFIG_BLK_DEV_HPT366 is not set
-# CONFIG_BLK_DEV_PIIX is not set
-# CONFIG_PIIX_TUNING is not set
-# CONFIG_BLK_DEV_NS87415 is not set
-# CONFIG_BLK_DEV_OPTI621 is not set
-# CONFIG_BLK_DEV_PDC202XX is not set
-# CONFIG_PDC202XX_BURST is not set
-# CONFIG_PDC202XX_FORCE is not set
-# CONFIG_BLK_DEV_SVWKS is not set
-# CONFIG_BLK_DEV_SIS5513 is not set
-# CONFIG_BLK_DEV_TRM290 is not set
-# CONFIG_BLK_DEV_VIA82CXXX is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_IDEDMA_IVB is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-# CONFIG_XSCSI is not set
-
-#
-# SCSI support
-#
-CONFIG_SCSI=y
-
-#
-# SCSI support type (disk, tape, CD-ROM)
-#
-CONFIG_BLK_DEV_SD=y
-CONFIG_SD_EXTRA_DEVS=40
-# CONFIG_CHR_DEV_ST is not set
-# CONFIG_CHR_DEV_OSST is not set
-# CONFIG_BLK_DEV_SR is not set
-# CONFIG_CHR_DEV_SG is not set
-
-#
-# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
-#
-# CONFIG_SCSI_DEBUG_QUEUES is not set
-CONFIG_SCSI_MULTI_LUN=y
-CONFIG_SCSI_CONSTANTS=y
-CONFIG_SCSI_LOGGING=y
-
-#
-# SCSI low-level drivers
-#
-# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
-# CONFIG_SCSI_7000FASST is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_AHA152X is not set
-# CONFIG_SCSI_AHA1542 is not set
-# CONFIG_SCSI_AHA1740 is not set
-# CONFIG_SCSI_AIC7XXX is not set
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-# CONFIG_SCSI_DPT_I2O is not set
-# CONFIG_SCSI_ADVANSYS is not set
-# CONFIG_SCSI_IN2000 is not set
-# CONFIG_SCSI_AM53C974 is not set
-# CONFIG_SCSI_MEGARAID is not set
-# CONFIG_SCSI_BUSLOGIC is not set
-# CONFIG_SCSI_CPQFCTS is not set
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_DTC3280 is not set
-# CONFIG_SCSI_EATA is not set
-# CONFIG_SCSI_EATA_DMA is not set
-# CONFIG_SCSI_EATA_PIO is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_GDTH is not set
-# CONFIG_SCSI_GENERIC_NCR5380 is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_NCR53C406A is not set
-# CONFIG_SCSI_NCR53C7xx is not set
-# CONFIG_SCSI_NCR53C8XX is not set
-# CONFIG_SCSI_SYM53C8XX is not set
-# CONFIG_SCSI_PAS16 is not set
-# CONFIG_SCSI_PCI2000 is not set
-# CONFIG_SCSI_PCI2220I is not set
-# CONFIG_SCSI_PSI240I is not set
-# CONFIG_SCSI_QLOGIC_FAS is not set
-# CONFIG_SCSI_QLOGIC_ISP is not set
-# CONFIG_SCSI_QLOGIC_FC is not set
-CONFIG_SCSI_QLOGIC_1280=y
-# CONFIG_SCSI_QLOGIC_QLA2100 is not set
-# CONFIG_SCSI_SIM710 is not set
-# CONFIG_SCSI_SYM53C416 is not set
-# CONFIG_SCSI_DC390T is not set
-# CONFIG_SCSI_T128 is not set
-# CONFIG_SCSI_U14_34F is not set
-# CONFIG_SCSI_DEBUG is not set
-
-#
-# Network device support
-#
-CONFIG_NETDEVICES=y
-
-#
-# ARCnet devices
-#
-# CONFIG_ARCNET is not set
-CONFIG_DUMMY=y
-# CONFIG_BONDING is not set
-# CONFIG_EQUALIZER is not set
-# CONFIG_TUN is not set
-
-#
-# Ethernet (10 or 100Mbit)
-#
-CONFIG_NET_ETHERNET=y
-# CONFIG_SUNLANCE is not set
-# CONFIG_HAPPYMEAL is not set
-# CONFIG_SUNBMAC is not set
-# CONFIG_SUNQE is not set
-# CONFIG_SUNLANCE is not set
-# CONFIG_SUNGEM is not set
-# CONFIG_NET_VENDOR_3COM is not set
-# CONFIG_LANCE is not set
-# CONFIG_NET_VENDOR_SMC is not set
-# CONFIG_NET_VENDOR_RACAL is not set
-# CONFIG_HP100 is not set
-# CONFIG_NET_ISA is not set
-CONFIG_NET_PCI=y
-# CONFIG_PCNET32 is not set
-# CONFIG_ADAPTEC_STARFIRE is not set
-# CONFIG_APRICOT is not set
-# CONFIG_CS89x0 is not set
-# CONFIG_TULIP is not set
-# CONFIG_DE4X5 is not set
-# CONFIG_DGRS is not set
-# CONFIG_DM9102 is not set
-CONFIG_EEPRO100=y
-# CONFIG_LNE390 is not set
-# CONFIG_FEALNX is not set
-# CONFIG_NATSEMI is not set
-# CONFIG_NE2K_PCI is not set
-# CONFIG_NE3210 is not set
-# CONFIG_ES3210 is not set
-# CONFIG_8139CP is not set
-# CONFIG_8139TOO is not set
-# CONFIG_8139TOO_PIO is not set
-# CONFIG_8139TOO_TUNE_TWISTER is not set
-# CONFIG_8139TOO_8129 is not set
-# CONFIG_SIS900 is not set
-# CONFIG_EPIC100 is not set
-# CONFIG_SUNDANCE is not set
-# CONFIG_TLAN is not set
-# CONFIG_VIA_RHINE is not set
-# CONFIG_WINBOND_840 is not set
-# CONFIG_NET_POCKET is not set
-
-#
-# Ethernet (1000 Mbit)
-#
-# CONFIG_ACENIC is not set
-# CONFIG_DL2K is not set
-# CONFIG_MYRI_SBUS is not set
-# CONFIG_NS83820 is not set
-# CONFIG_HAMACHI is not set
-# CONFIG_YELLOWFIN is not set
-# CONFIG_SK98LIN is not set
-# CONFIG_FDDI is not set
-# CONFIG_HIPPI is not set
-# CONFIG_PLIP is not set
-# CONFIG_PPP is not set
-# CONFIG_SLIP is not set
-
-#
-# Wireless LAN (non-hamradio)
-#
-# CONFIG_NET_RADIO is not set
-
-#
-# Token Ring devices
-#
-# CONFIG_TR is not set
-# CONFIG_NET_FC is not set
-# CONFIG_RCPCI is not set
-# CONFIG_SHAPER is not set
-
-#
-# Wan interfaces
-#
-# CONFIG_WAN is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-CONFIG_VT=y
-CONFIG_VT_CONSOLE=y
-CONFIG_SERIAL=y
-CONFIG_SERIAL_CONSOLE=y
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-CONFIG_MOUSE=y
-CONFIG_PSMOUSE=y
-# CONFIG_82C710_MOUSE is not set
-# CONFIG_PC110_PAD is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-# CONFIG_EFI_RTC is not set
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-# CONFIG_QUOTA is not set
-CONFIG_AUTOFS_FS=y
-CONFIG_AUTOFS4_FS=y
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-CONFIG_FAT_FS=y
-CONFIG_MSDOS_FS=y
-# CONFIG_UMSDOS_FS is not set
-CONFIG_VFAT_FS=y
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-CONFIG_ISO9660_FS=y
-CONFIG_JOLIET=y
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_MOUNT=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-# CONFIG_XFS_SUPPORT is not set
-
-#
-# Network File Systems
-#
-# CONFIG_CODA_FS is not set
-CONFIG_NFS_FS=y
-CONFIG_NFS_V3=y
-# CONFIG_ROOT_NFS is not set
-CONFIG_NFSD=y
-CONFIG_NFSD_V3=y
-CONFIG_SUNRPC=y
-CONFIG_LOCKD=y
-CONFIG_LOCKD_V4=y
-# CONFIG_SMB_FS is not set
-# CONFIG_NCP_FS is not set
-# CONFIG_NCPFS_PACKET_SIGNING is not set
-# CONFIG_NCPFS_IOCTL_LOCKING is not set
-# CONFIG_NCPFS_STRONG is not set
-# CONFIG_NCPFS_NFS_NS is not set
-# CONFIG_NCPFS_OS2_NS is not set
-# CONFIG_NCPFS_SMALLDOS is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_NCPFS_EXTRAS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-CONFIG_NLS=y
-
-#
-# Native Language Support
-#
-CONFIG_NLS_DEFAULT="iso8859-1"
-# CONFIG_NLS_CODEPAGE_437 is not set
-# CONFIG_NLS_CODEPAGE_737 is not set
-# CONFIG_NLS_CODEPAGE_775 is not set
-# CONFIG_NLS_CODEPAGE_850 is not set
-# CONFIG_NLS_CODEPAGE_852 is not set
-# CONFIG_NLS_CODEPAGE_855 is not set
-# CONFIG_NLS_CODEPAGE_857 is not set
-# CONFIG_NLS_CODEPAGE_860 is not set
-# CONFIG_NLS_CODEPAGE_861 is not set
-# CONFIG_NLS_CODEPAGE_862 is not set
-# CONFIG_NLS_CODEPAGE_863 is not set
-# CONFIG_NLS_CODEPAGE_864 is not set
-# CONFIG_NLS_CODEPAGE_865 is not set
-# CONFIG_NLS_CODEPAGE_866 is not set
-# CONFIG_NLS_CODEPAGE_869 is not set
-# CONFIG_NLS_CODEPAGE_936 is not set
-# CONFIG_NLS_CODEPAGE_950 is not set
-# CONFIG_NLS_CODEPAGE_932 is not set
-# CONFIG_NLS_CODEPAGE_949 is not set
-# CONFIG_NLS_CODEPAGE_874 is not set
-# CONFIG_NLS_ISO8859_8 is not set
-# CONFIG_NLS_CODEPAGE_1251 is not set
-# CONFIG_NLS_ISO8859_1 is not set
-# CONFIG_NLS_ISO8859_2 is not set
-# CONFIG_NLS_ISO8859_3 is not set
-# CONFIG_NLS_ISO8859_4 is not set
-# CONFIG_NLS_ISO8859_5 is not set
-# CONFIG_NLS_ISO8859_6 is not set
-# CONFIG_NLS_ISO8859_7 is not set
-# CONFIG_NLS_ISO8859_9 is not set
-# CONFIG_NLS_ISO8859_13 is not set
-# CONFIG_NLS_ISO8859_14 is not set
-# CONFIG_NLS_ISO8859_15 is not set
-# CONFIG_NLS_KOI8_R is not set
-# CONFIG_NLS_KOI8_U is not set
-# CONFIG_NLS_UTF8 is not set
-
-#
-# Console drivers
-#
-CONFIG_VGA_CONSOLE=y
-
-#
-# Frame-buffer support
-#
-# CONFIG_FB is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-# CONFIG_USB_PEGASUS is not set
-# CONFIG_USB_KAWETH is not set
-# CONFIG_USB_CATC is not set
-# CONFIG_USB_CDCETHER is not set
-# CONFIG_USB_USBNET is not set
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# IEEE 1394 (FireWire) support (EXPERIMENTAL)
-#
-# CONFIG_IEEE1394 is not set
-
-#
-# Bluetooth support
-#
-# CONFIG_BT is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-# CONFIG_KDB is not set
-# CONFIG_KDB_MODULES is not set
-# CONFIG_KALLSYMS is not set
diff -Nru a/arch/ia64/sn/configs/sn1/defconfig-dig-mp b/arch/ia64/sn/configs/sn1/defconfig-dig-mp
--- a/arch/ia64/sn/configs/sn1/defconfig-dig-mp	Mon Dec 23 21:21:58 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,449 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-# CONFIG_EXPERIMENTAL is not set
-
-#
-# Loadable module support
-#
-# CONFIG_MODULES is not set
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-CONFIG_ITANIUM=y
-# CONFIG_MCKINLEY is not set
-# CONFIG_IA64_GENERIC is not set
-CONFIG_IA64_DIG=y
-# CONFIG_IA64_HP_SIM is not set
-# CONFIG_IA64_SGI_SN1 is not set
-# CONFIG_IA64_SGI_SN2 is not set
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_BRL_EMU=y
-CONFIG_ITANIUM_BSTEP_SPECIFIC=y
-CONFIG_IA64_L1_CACHE_SHIFT=6
-# CONFIG_NUMA is not set
-# CONFIG_IA64_MCA is not set
-CONFIG_PM=y
-CONFIG_IA64_HAVE_SYNCRONIZED_ITC=y
-# CONFIG_DEVFS_FS is not set
-CONFIG_KCORE_ELF=y
-CONFIG_SMP=y
-# CONFIG_IA32_SUPPORT is not set
-# CONFIG_PERFMON is not set
-# CONFIG_IA64_PALINFO is not set
-# CONFIG_EFI_VARS is not set
-# CONFIG_NET is not set
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-# CONFIG_SYSCTL is not set
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-# CONFIG_BLK_DEV_LOOP is not set
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-# CONFIG_XSCSI is not set
-
-#
-# SCSI support
-#
-# CONFIG_SCSI is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-CONFIG_VT=y
-CONFIG_VT_CONSOLE=y
-# CONFIG_SERIAL is not set
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-# CONFIG_MOUSE is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-# CONFIG_EFI_RTC is not set
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-# CONFIG_QUOTA is not set
-# CONFIG_AUTOFS_FS is not set
-# CONFIG_AUTOFS4_FS is not set
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-# CONFIG_FAT_FS is not set
-# CONFIG_MSDOS_FS is not set
-# CONFIG_UMSDOS_FS is not set
-# CONFIG_VFAT_FS is not set
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-# CONFIG_ISO9660_FS is not set
-# CONFIG_JOLIET is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-# CONFIG_DEVFS_FS is not set
-# CONFIG_DEVFS_MOUNT is not set
-# CONFIG_DEVFS_DEBUG is not set
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-# CONFIG_XFS_SUPPORT is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_SMB_FS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-# CONFIG_NLS is not set
-
-#
-# Console drivers
-#
-CONFIG_VGA_CONSOLE=y
-
-#
-# Frame-buffer support
-#
-# CONFIG_FB is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-
-#
-#   Networking support is needed for USB Networking device support
-#
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-# CONFIG_KDB is not set
-# CONFIG_KDB_MODULES is not set
-# CONFIG_KALLSYMS is not set
diff -Nru a/arch/ia64/sn/configs/sn1/defconfig-dig-sp b/arch/ia64/sn/configs/sn1/defconfig-dig-sp
--- a/arch/ia64/sn/configs/sn1/defconfig-dig-sp	Mon Dec 23 21:21:57 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,449 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-# CONFIG_EXPERIMENTAL is not set
-
-#
-# Loadable module support
-#
-# CONFIG_MODULES is not set
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-CONFIG_ITANIUM=y
-# CONFIG_MCKINLEY is not set
-# CONFIG_IA64_GENERIC is not set
-CONFIG_IA64_DIG=y
-# CONFIG_IA64_HP_SIM is not set
-# CONFIG_IA64_SGI_SN1 is not set
-# CONFIG_IA64_SGI_SN2 is not set
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_BRL_EMU=y
-CONFIG_ITANIUM_BSTEP_SPECIFIC=y
-CONFIG_IA64_L1_CACHE_SHIFT=6
-# CONFIG_NUMA is not set
-# CONFIG_IA64_MCA is not set
-CONFIG_PM=y
-CONFIG_IA64_HAVE_SYNCRONIZED_ITC=y
-# CONFIG_DEVFS_FS is not set
-CONFIG_KCORE_ELF=y
-# CONFIG_SMP is not set
-# CONFIG_IA32_SUPPORT is not set
-# CONFIG_PERFMON is not set
-# CONFIG_IA64_PALINFO is not set
-# CONFIG_EFI_VARS is not set
-# CONFIG_NET is not set
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-# CONFIG_SYSCTL is not set
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-# CONFIG_BLK_DEV_LOOP is not set
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-# CONFIG_XSCSI is not set
-
-#
-# SCSI support
-#
-# CONFIG_SCSI is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-CONFIG_VT=y
-CONFIG_VT_CONSOLE=y
-# CONFIG_SERIAL is not set
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-# CONFIG_MOUSE is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-# CONFIG_EFI_RTC is not set
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-# CONFIG_QUOTA is not set
-# CONFIG_AUTOFS_FS is not set
-# CONFIG_AUTOFS4_FS is not set
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-# CONFIG_FAT_FS is not set
-# CONFIG_MSDOS_FS is not set
-# CONFIG_UMSDOS_FS is not set
-# CONFIG_VFAT_FS is not set
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-# CONFIG_ISO9660_FS is not set
-# CONFIG_JOLIET is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-# CONFIG_DEVFS_FS is not set
-# CONFIG_DEVFS_MOUNT is not set
-# CONFIG_DEVFS_DEBUG is not set
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-# CONFIG_XFS_SUPPORT is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_SMB_FS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-# CONFIG_NLS is not set
-
-#
-# Console drivers
-#
-CONFIG_VGA_CONSOLE=y
-
-#
-# Frame-buffer support
-#
-# CONFIG_FB is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-
-#
-#   Networking support is needed for USB Networking device support
-#
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-# CONFIG_KDB is not set
-# CONFIG_KDB_MODULES is not set
-# CONFIG_KALLSYMS is not set
diff -Nru a/arch/ia64/sn/configs/sn1/defconfig-generic-mp b/arch/ia64/sn/configs/sn1/defconfig-generic-mp
--- a/arch/ia64/sn/configs/sn1/defconfig-generic-mp	Mon Dec 23 21:21:59 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,450 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-# CONFIG_EXPERIMENTAL is not set
-
-#
-# Loadable module support
-#
-# CONFIG_MODULES is not set
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-CONFIG_ITANIUM=y
-# CONFIG_MCKINLEY is not set
-CONFIG_IA64_GENERIC=y
-# CONFIG_IA64_DIG is not set
-# CONFIG_IA64_HP_SIM is not set
-# CONFIG_IA64_SGI_SN1 is not set
-# CONFIG_IA64_SGI_SN2 is not set
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_BRL_EMU=y
-CONFIG_ITANIUM_BSTEP_SPECIFIC=y
-CONFIG_IA64_L1_CACHE_SHIFT=6
-CONFIG_KCORE_ELF=y
-CONFIG_SMP=y
-# CONFIG_IA32_SUPPORT is not set
-CONFIG_PERFMON=y
-CONFIG_IA64_PALINFO=y
-# CONFIG_EFI_VARS is not set
-# CONFIG_NET is not set
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-# CONFIG_SYSCTL is not set
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-# CONFIG_BLK_DEV_LOOP is not set
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-# CONFIG_XSCSI is not set
-
-#
-# SCSI support
-#
-# CONFIG_SCSI is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-CONFIG_VT=y
-CONFIG_VT_CONSOLE=y
-# CONFIG_SERIAL is not set
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-# CONFIG_MOUSE is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-# CONFIG_EFI_RTC is not set
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-# CONFIG_QUOTA is not set
-# CONFIG_AUTOFS_FS is not set
-# CONFIG_AUTOFS4_FS is not set
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-# CONFIG_FAT_FS is not set
-# CONFIG_MSDOS_FS is not set
-# CONFIG_UMSDOS_FS is not set
-# CONFIG_VFAT_FS is not set
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-# CONFIG_ISO9660_FS is not set
-# CONFIG_JOLIET is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-# CONFIG_DEVFS_FS is not set
-# CONFIG_DEVFS_MOUNT is not set
-# CONFIG_DEVFS_DEBUG is not set
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-# CONFIG_XFS_SUPPORT is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_SMB_FS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-# CONFIG_NLS is not set
-
-#
-# Console drivers
-#
-CONFIG_VGA_CONSOLE=y
-
-#
-# Frame-buffer support
-#
-# CONFIG_FB is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-
-#
-#   Networking support is needed for USB Networking device support
-#
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# Simulated drivers
-#
-# CONFIG_SIMETH is not set
-# CONFIG_SIM_SERIAL is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-# CONFIG_KDB is not set
-# CONFIG_KDB_MODULES is not set
-# CONFIG_KALLSYMS is not set
diff -Nru a/arch/ia64/sn/configs/sn1/defconfig-generic-sp b/arch/ia64/sn/configs/sn1/defconfig-generic-sp
--- a/arch/ia64/sn/configs/sn1/defconfig-generic-sp	Mon Dec 23 21:22:00 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,450 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-# CONFIG_EXPERIMENTAL is not set
-
-#
-# Loadable module support
-#
-# CONFIG_MODULES is not set
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-CONFIG_ITANIUM=y
-# CONFIG_MCKINLEY is not set
-CONFIG_IA64_GENERIC=y
-# CONFIG_IA64_DIG is not set
-# CONFIG_IA64_HP_SIM is not set
-# CONFIG_IA64_SGI_SN1 is not set
-# CONFIG_IA64_SGI_SN2 is not set
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_BRL_EMU=y
-CONFIG_ITANIUM_BSTEP_SPECIFIC=y
-CONFIG_IA64_L1_CACHE_SHIFT=6
-CONFIG_KCORE_ELF=y
-# CONFIG_SMP is not set
-# CONFIG_IA32_SUPPORT is not set
-CONFIG_PERFMON=y
-CONFIG_IA64_PALINFO=y
-# CONFIG_EFI_VARS is not set
-# CONFIG_NET is not set
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-# CONFIG_SYSCTL is not set
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-# CONFIG_BLK_DEV_LOOP is not set
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-# CONFIG_XSCSI is not set
-
-#
-# SCSI support
-#
-# CONFIG_SCSI is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-CONFIG_VT=y
-CONFIG_VT_CONSOLE=y
-# CONFIG_SERIAL is not set
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-# CONFIG_MOUSE is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-# CONFIG_EFI_RTC is not set
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-# CONFIG_QUOTA is not set
-# CONFIG_AUTOFS_FS is not set
-# CONFIG_AUTOFS4_FS is not set
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-# CONFIG_FAT_FS is not set
-# CONFIG_MSDOS_FS is not set
-# CONFIG_UMSDOS_FS is not set
-# CONFIG_VFAT_FS is not set
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-# CONFIG_ISO9660_FS is not set
-# CONFIG_JOLIET is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-# CONFIG_DEVFS_FS is not set
-# CONFIG_DEVFS_MOUNT is not set
-# CONFIG_DEVFS_DEBUG is not set
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-# CONFIG_XFS_SUPPORT is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_SMB_FS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-# CONFIG_NLS is not set
-
-#
-# Console drivers
-#
-CONFIG_VGA_CONSOLE=y
-
-#
-# Frame-buffer support
-#
-# CONFIG_FB is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-
-#
-#   Networking support is needed for USB Networking device support
-#
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# Simulated drivers
-#
-# CONFIG_SIMETH is not set
-# CONFIG_SIM_SERIAL is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-# CONFIG_KDB is not set
-# CONFIG_KDB_MODULES is not set
-# CONFIG_KALLSYMS is not set
diff -Nru a/arch/ia64/sn/configs/sn1/defconfig-hp-sp b/arch/ia64/sn/configs/sn1/defconfig-hp-sp
--- a/arch/ia64/sn/configs/sn1/defconfig-hp-sp	Mon Dec 23 21:21:55 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,335 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-# CONFIG_EXPERIMENTAL is not set
-
-#
-# Loadable module support
-#
-# CONFIG_MODULES is not set
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ITANIUM=y
-# CONFIG_MCKINLEY is not set
-# CONFIG_IA64_GENERIC is not set
-# CONFIG_IA64_DIG is not set
-CONFIG_IA64_HP_SIM=y
-# CONFIG_IA64_SGI_SN1 is not set
-# CONFIG_IA64_SGI_SN2 is not set
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_BRL_EMU=y
-CONFIG_ITANIUM_BSTEP_SPECIFIC=y
-CONFIG_IA64_L1_CACHE_SHIFT=6
-CONFIG_KCORE_ELF=y
-# CONFIG_SMP is not set
-# CONFIG_IA32_SUPPORT is not set
-# CONFIG_PERFMON is not set
-# CONFIG_IA64_PALINFO is not set
-# CONFIG_EFI_VARS is not set
-CONFIG_NET=y
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-CONFIG_SYSCTL=y
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-
-#
-# Networking options
-#
-# CONFIG_PACKET is not set
-# CONFIG_NETLINK is not set
-# CONFIG_NETFILTER is not set
-# CONFIG_FILTER is not set
-CONFIG_UNIX=y
-CONFIG_INET=y
-# CONFIG_IP_MULTICAST is not set
-# CONFIG_IP_ADVANCED_ROUTER is not set
-# CONFIG_IP_PNP is not set
-# CONFIG_NET_IPIP is not set
-# CONFIG_NET_IPGRE is not set
-# CONFIG_INET_ECN is not set
-# CONFIG_SYN_COOKIES is not set
-
-#
-#  
-#
-# CONFIG_IPX is not set
-# CONFIG_ATALK is not set
-# CONFIG_DECNET is not set
-# CONFIG_BRIDGE is not set
-
-#
-# QoS and/or fair queueing
-#
-# CONFIG_NET_SCHED is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-# CONFIG_XSCSI is not set
-
-#
-# SCSI support
-#
-CONFIG_SCSI=y
-
-#
-# SCSI support type (disk, tape, CD-ROM)
-#
-CONFIG_BLK_DEV_SD=y
-CONFIG_SD_EXTRA_DEVS=40
-# CONFIG_CHR_DEV_ST is not set
-# CONFIG_CHR_DEV_OSST is not set
-# CONFIG_BLK_DEV_SR is not set
-# CONFIG_CHR_DEV_SG is not set
-
-#
-# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
-#
-# CONFIG_SCSI_DEBUG_QUEUES is not set
-# CONFIG_SCSI_MULTI_LUN is not set
-CONFIG_SCSI_CONSTANTS=y
-# CONFIG_SCSI_LOGGING is not set
-
-#
-# SCSI low-level drivers
-#
-# CONFIG_SCSI_7000FASST is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_AHA152X is not set
-# CONFIG_SCSI_AHA1542 is not set
-# CONFIG_SCSI_AHA1740 is not set
-# CONFIG_SCSI_AIC7XXX is not set
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-# CONFIG_SCSI_DPT_I2O is not set
-# CONFIG_SCSI_ADVANSYS is not set
-# CONFIG_SCSI_IN2000 is not set
-# CONFIG_SCSI_AM53C974 is not set
-# CONFIG_SCSI_MEGARAID is not set
-# CONFIG_SCSI_BUSLOGIC is not set
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_DTC3280 is not set
-# CONFIG_SCSI_EATA is not set
-# CONFIG_SCSI_EATA_DMA is not set
-# CONFIG_SCSI_EATA_PIO is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_GDTH is not set
-# CONFIG_SCSI_GENERIC_NCR5380 is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_PPA is not set
-# CONFIG_SCSI_IMM is not set
-# CONFIG_SCSI_NCR53C406A is not set
-# CONFIG_SCSI_NCR53C7xx is not set
-# CONFIG_SCSI_PAS16 is not set
-# CONFIG_SCSI_PCI2000 is not set
-# CONFIG_SCSI_PCI2220I is not set
-# CONFIG_SCSI_PSI240I is not set
-# CONFIG_SCSI_QLOGIC_FAS is not set
-# CONFIG_SCSI_SIM710 is not set
-# CONFIG_SCSI_SYM53C416 is not set
-# CONFIG_SCSI_T128 is not set
-# CONFIG_SCSI_U14_34F is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-CONFIG_VT=y
-CONFIG_VT_CONSOLE=y
-# CONFIG_SERIAL is not set
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-# CONFIG_PRINTER is not set
-# CONFIG_PPDEV is not set
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-# CONFIG_MOUSE is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-CONFIG_EFI_RTC=y
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-# CONFIG_QUOTA is not set
-# CONFIG_AUTOFS_FS is not set
-# CONFIG_AUTOFS4_FS is not set
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-# CONFIG_FAT_FS is not set
-# CONFIG_MSDOS_FS is not set
-# CONFIG_UMSDOS_FS is not set
-# CONFIG_VFAT_FS is not set
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-# CONFIG_ISO9660_FS is not set
-# CONFIG_JOLIET is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-# CONFIG_DEVFS_FS is not set
-# CONFIG_DEVFS_MOUNT is not set
-# CONFIG_DEVFS_DEBUG is not set
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-# CONFIG_XFS_SUPPORT is not set
-
-#
-# Network File Systems
-#
-# CONFIG_CODA_FS is not set
-# CONFIG_NFS_FS is not set
-# CONFIG_NFS_V3 is not set
-# CONFIG_ROOT_NFS is not set
-# CONFIG_NFSD is not set
-# CONFIG_NFSD_V3 is not set
-# CONFIG_SUNRPC is not set
-# CONFIG_LOCKD is not set
-# CONFIG_SMB_FS is not set
-# CONFIG_NCP_FS is not set
-# CONFIG_NCPFS_PACKET_SIGNING is not set
-# CONFIG_NCPFS_IOCTL_LOCKING is not set
-# CONFIG_NCPFS_STRONG is not set
-# CONFIG_NCPFS_NFS_NS is not set
-# CONFIG_NCPFS_OS2_NS is not set
-# CONFIG_NCPFS_SMALLDOS is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_NCPFS_EXTRAS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-# CONFIG_NLS is not set
-
-#
-# Console drivers
-#
-CONFIG_VGA_CONSOLE=y
-
-#
-# Frame-buffer support
-#
-# CONFIG_FB is not set
-
-#
-# Simulated drivers
-#
-CONFIG_SIMETH=y
-CONFIG_SIM_SERIAL=y
-CONFIG_SCSI_SIM=y
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-# CONFIG_KDB is not set
-# CONFIG_KDB_MODULES is not set
-# CONFIG_KALLSYMS is not set
diff -Nru a/arch/ia64/sn/configs/sn1/defconfig-prom-medusa b/arch/ia64/sn/configs/sn1/defconfig-prom-medusa
--- a/arch/ia64/sn/configs/sn1/defconfig-prom-medusa	Mon Dec 23 21:21:53 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,519 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-CONFIG_EXPERIMENTAL=y
-
-#
-# Loadable module support
-#
-# CONFIG_MODULES is not set
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-CONFIG_ITANIUM=y
-# CONFIG_MCKINLEY is not set
-# CONFIG_IA64_GENERIC is not set
-# CONFIG_IA64_DIG is not set
-# CONFIG_IA64_HP_SIM is not set
-CONFIG_IA64_SGI_SN1=y
-# CONFIG_IA64_SGI_SN2 is not set
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_BRL_EMU=y
-CONFIG_ITANIUM_BSTEP_SPECIFIC=y
-CONFIG_IA64_L1_CACHE_SHIFT=7
-CONFIG_IA64_SGI_SN=y
-CONFIG_IA64_SGI_SN_DEBUG=y
-CONFIG_IA64_SGI_SN_SIM=y
-CONFIG_IA64_SGI_AUTOTEST=y
-CONFIG_DEVFS_FS=y
-# CONFIG_DEVFS_DEBUG is not set
-CONFIG_SERIAL_SGI_L1_PROTOCOL=y
-CONFIG_DISCONTIGMEM=y
-CONFIG_IA64_MCA=y
-CONFIG_NUMA=y
-CONFIG_PERCPU_IRQ=y
-CONFIG_PCIBA=y
-CONFIG_KCORE_ELF=y
-CONFIG_SMP=y
-# CONFIG_IA32_SUPPORT is not set
-CONFIG_PERFMON=y
-CONFIG_IA64_PALINFO=y
-# CONFIG_EFI_VARS is not set
-# CONFIG_NET is not set
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-CONFIG_SYSCTL=y
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-# CONFIG_PNPBIOS is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-# CONFIG_BLK_DEV_LOOP is not set
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-# CONFIG_XSCSI is not set
-
-#
-# SCSI support
-#
-CONFIG_SCSI=y
-
-#
-# SCSI support type (disk, tape, CD-ROM)
-#
-CONFIG_BLK_DEV_SD=y
-CONFIG_SD_EXTRA_DEVS=40
-# CONFIG_CHR_DEV_ST is not set
-# CONFIG_CHR_DEV_OSST is not set
-# CONFIG_BLK_DEV_SR is not set
-# CONFIG_CHR_DEV_SG is not set
-
-#
-# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
-#
-# CONFIG_SCSI_DEBUG_QUEUES is not set
-# CONFIG_SCSI_MULTI_LUN is not set
-# CONFIG_SCSI_CONSTANTS is not set
-# CONFIG_SCSI_LOGGING is not set
-
-#
-# SCSI low-level drivers
-#
-# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
-# CONFIG_SCSI_7000FASST is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_AHA152X is not set
-# CONFIG_SCSI_AHA1542 is not set
-# CONFIG_SCSI_AHA1740 is not set
-# CONFIG_SCSI_AIC7XXX is not set
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-# CONFIG_SCSI_DPT_I2O is not set
-# CONFIG_SCSI_ADVANSYS is not set
-# CONFIG_SCSI_IN2000 is not set
-# CONFIG_SCSI_AM53C974 is not set
-# CONFIG_SCSI_MEGARAID is not set
-# CONFIG_SCSI_BUSLOGIC is not set
-# CONFIG_SCSI_CPQFCTS is not set
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_DTC3280 is not set
-# CONFIG_SCSI_EATA is not set
-# CONFIG_SCSI_EATA_DMA is not set
-# CONFIG_SCSI_EATA_PIO is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_GDTH is not set
-# CONFIG_SCSI_GENERIC_NCR5380 is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_NCR53C406A is not set
-# CONFIG_SCSI_NCR53C7xx is not set
-# CONFIG_SCSI_NCR53C8XX is not set
-# CONFIG_SCSI_SYM53C8XX is not set
-# CONFIG_SCSI_PAS16 is not set
-# CONFIG_SCSI_PCI2000 is not set
-# CONFIG_SCSI_PCI2220I is not set
-# CONFIG_SCSI_PSI240I is not set
-# CONFIG_SCSI_QLOGIC_FAS is not set
-# CONFIG_SCSI_QLOGIC_ISP is not set
-CONFIG_SCSI_QLOGIC_FC=y
-# CONFIG_SCSI_QLOGIC_FC_FIRMWARE is not set
-# CONFIG_SCSI_QLOGIC_1280 is not set
-# CONFIG_SCSI_QLOGIC_QLA2100 is not set
-# CONFIG_SCSI_SIM710 is not set
-# CONFIG_SCSI_SYM53C416 is not set
-# CONFIG_SCSI_DC390T is not set
-# CONFIG_SCSI_T128 is not set
-# CONFIG_SCSI_U14_34F is not set
-# CONFIG_SCSI_DEBUG is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-# CONFIG_VT is not set
-CONFIG_SERIAL=y
-# CONFIG_SERIAL_CONSOLE is not set
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-# CONFIG_MOUSE is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-# CONFIG_EFI_RTC is not set
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-# CONFIG_QUOTA is not set
-# CONFIG_AUTOFS_FS is not set
-# CONFIG_AUTOFS4_FS is not set
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-# CONFIG_FAT_FS is not set
-# CONFIG_MSDOS_FS is not set
-# CONFIG_UMSDOS_FS is not set
-# CONFIG_VFAT_FS is not set
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-# CONFIG_ISO9660_FS is not set
-# CONFIG_JOLIET is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-CONFIG_DEVFS_FS=y
-# CONFIG_DEVFS_MOUNT is not set
-# CONFIG_DEVFS_DEBUG is not set
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-# CONFIG_XFS_SUPPORT is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_SMB_FS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-# CONFIG_NLS is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-
-#
-#   Networking support is needed for USB Networking device support
-#
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# IEEE 1394 (FireWire) support (EXPERIMENTAL)
-#
-# CONFIG_IEEE1394 is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-# CONFIG_KDB is not set
-# CONFIG_KDB_MODULES is not set
-# CONFIG_KALLSYMS is not set
diff -Nru a/arch/ia64/sn/configs/sn1/defconfig-sn1-mp b/arch/ia64/sn/configs/sn1/defconfig-sn1-mp
--- a/arch/ia64/sn/configs/sn1/defconfig-sn1-mp	Mon Dec 23 21:21:59 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,726 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-CONFIG_EXPERIMENTAL=y
-
-#
-# Loadable module support
-#
-# CONFIG_MODULES is not set
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-CONFIG_ITANIUM=y
-# CONFIG_MCKINLEY is not set
-# CONFIG_IA64_GENERIC is not set
-# CONFIG_IA64_DIG is not set
-# CONFIG_IA64_HP_SIM is not set
-CONFIG_IA64_SGI_SN1=y
-# CONFIG_IA64_SGI_SN2 is not set
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_BRL_EMU=y
-CONFIG_ITANIUM_BSTEP_SPECIFIC=y
-CONFIG_IA64_L1_CACHE_SHIFT=7
-CONFIG_IA64_SGI_SN=y
-CONFIG_IA64_SGI_SN_DEBUG=y
-CONFIG_IA64_SGI_SN_SIM=y
-CONFIG_IA64_SGI_AUTOTEST=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_SERIAL_SGI_L1_PROTOCOL=y
-CONFIG_DISCONTIGMEM=y
-CONFIG_IA64_MCA=y
-CONFIG_NUMA=y
-CONFIG_PERCPU_IRQ=y
-CONFIG_PCIBA=y
-CONFIG_KCORE_ELF=y
-CONFIG_SMP=y
-CONFIG_IA32_SUPPORT=y
-CONFIG_PERFMON=y
-CONFIG_IA64_PALINFO=y
-# CONFIG_EFI_VARS is not set
-CONFIG_NET=y
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-CONFIG_SYSCTL=y
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Networking options
-#
-CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
-CONFIG_NETLINK=y
-CONFIG_RTNETLINK=y
-CONFIG_NETLINK_DEV=y
-CONFIG_NETFILTER=y
-CONFIG_NETFILTER_DEBUG=y
-CONFIG_FILTER=y
-CONFIG_UNIX=y
-CONFIG_INET=y
-CONFIG_IP_MULTICAST=y
-# CONFIG_IP_ADVANCED_ROUTER is not set
-# CONFIG_IP_PNP is not set
-# CONFIG_NET_IPIP is not set
-# CONFIG_NET_IPGRE is not set
-# CONFIG_IP_MROUTE is not set
-# CONFIG_ARPD is not set
-# CONFIG_INET_ECN is not set
-CONFIG_SYN_COOKIES=y
-
-#
-#   IP: Netfilter Configuration
-#
-# CONFIG_IP_NF_CONNTRACK is not set
-# CONFIG_IP_NF_QUEUE is not set
-# CONFIG_IP_NF_IPTABLES is not set
-# CONFIG_IP_NF_COMPAT_IPCHAINS is not set
-# CONFIG_IP_NF_COMPAT_IPFWADM is not set
-# CONFIG_IPV6 is not set
-# CONFIG_KHTTPD is not set
-# CONFIG_ATM is not set
-
-#
-#  
-#
-# CONFIG_IPX is not set
-# CONFIG_ATALK is not set
-# CONFIG_DECNET is not set
-# CONFIG_BRIDGE is not set
-# CONFIG_X25 is not set
-# CONFIG_LAPB is not set
-# CONFIG_LLC is not set
-# CONFIG_NET_DIVERT is not set
-# CONFIG_ECONET is not set
-# CONFIG_WAN_ROUTER is not set
-# CONFIG_NET_FASTROUTE is not set
-# CONFIG_NET_HW_FLOWCONTROL is not set
-
-#
-# QoS and/or fair queueing
-#
-# CONFIG_NET_SCHED is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-# CONFIG_PNPBIOS is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-CONFIG_BLK_DEV_LOOP=y
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_LAN is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-CONFIG_XSCSI=y
-
-#
-# Alternate SCSI support
-#
-CONFIG_XSCSI_DKSC=y
-# CONFIG_XSCSI_QLFC is not set
-# CONFIG_XSCSI_QL is not set
-# CONFIG_XSCSI_SBP2 is not set
-
-#
-# SCSI support
-#
-CONFIG_SCSI=y
-
-#
-# SCSI support type (disk, tape, CD-ROM)
-#
-CONFIG_BLK_DEV_SD=y
-CONFIG_SD_EXTRA_DEVS=40
-# CONFIG_CHR_DEV_ST is not set
-# CONFIG_CHR_DEV_OSST is not set
-# CONFIG_BLK_DEV_SR is not set
-# CONFIG_CHR_DEV_SG is not set
-
-#
-# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
-#
-# CONFIG_SCSI_DEBUG_QUEUES is not set
-# CONFIG_SCSI_MULTI_LUN is not set
-# CONFIG_SCSI_CONSTANTS is not set
-# CONFIG_SCSI_LOGGING is not set
-
-#
-# SCSI low-level drivers
-#
-# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
-# CONFIG_SCSI_7000FASST is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_AHA152X is not set
-# CONFIG_SCSI_AHA1542 is not set
-# CONFIG_SCSI_AHA1740 is not set
-# CONFIG_SCSI_AIC7XXX is not set
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-# CONFIG_SCSI_DPT_I2O is not set
-# CONFIG_SCSI_ADVANSYS is not set
-# CONFIG_SCSI_IN2000 is not set
-# CONFIG_SCSI_AM53C974 is not set
-# CONFIG_SCSI_MEGARAID is not set
-# CONFIG_SCSI_BUSLOGIC is not set
-# CONFIG_SCSI_CPQFCTS is not set
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_DTC3280 is not set
-# CONFIG_SCSI_EATA is not set
-# CONFIG_SCSI_EATA_DMA is not set
-# CONFIG_SCSI_EATA_PIO is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_GDTH is not set
-# CONFIG_SCSI_GENERIC_NCR5380 is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_NCR53C406A is not set
-# CONFIG_SCSI_NCR53C7xx is not set
-# CONFIG_SCSI_NCR53C8XX is not set
-# CONFIG_SCSI_SYM53C8XX is not set
-# CONFIG_SCSI_PAS16 is not set
-# CONFIG_SCSI_PCI2000 is not set
-# CONFIG_SCSI_PCI2220I is not set
-# CONFIG_SCSI_PSI240I is not set
-# CONFIG_SCSI_QLOGIC_FAS is not set
-# CONFIG_SCSI_QLOGIC_ISP is not set
-CONFIG_SCSI_QLOGIC_FC=y
-# CONFIG_SCSI_QLOGIC_FC_FIRMWARE is not set
-# CONFIG_SCSI_QLOGIC_1280 is not set
-# CONFIG_SCSI_QLOGIC_QLA2100 is not set
-# CONFIG_SCSI_SIM710 is not set
-# CONFIG_SCSI_SYM53C416 is not set
-# CONFIG_SCSI_DC390T is not set
-# CONFIG_SCSI_T128 is not set
-# CONFIG_SCSI_U14_34F is not set
-# CONFIG_SCSI_DEBUG is not set
-
-#
-# Network device support
-#
-CONFIG_NETDEVICES=y
-
-#
-# ARCnet devices
-#
-# CONFIG_ARCNET is not set
-# CONFIG_DUMMY is not set
-# CONFIG_BONDING is not set
-# CONFIG_EQUALIZER is not set
-# CONFIG_TUN is not set
-# CONFIG_ETHERTAP is not set
-
-#
-# Ethernet (10 or 100Mbit)
-#
-CONFIG_NET_ETHERNET=y
-CONFIG_SGI_IOC3_ETH=y
-# CONFIG_SUNLANCE is not set
-# CONFIG_HAPPYMEAL is not set
-# CONFIG_SUNBMAC is not set
-# CONFIG_SUNQE is not set
-# CONFIG_SUNLANCE is not set
-# CONFIG_SUNGEM is not set
-# CONFIG_NET_VENDOR_3COM is not set
-# CONFIG_LANCE is not set
-# CONFIG_NET_VENDOR_SMC is not set
-# CONFIG_NET_VENDOR_RACAL is not set
-# CONFIG_HP100 is not set
-# CONFIG_NET_ISA is not set
-# CONFIG_NET_PCI is not set
-# CONFIG_NET_POCKET is not set
-
-#
-# Ethernet (1000 Mbit)
-#
-# CONFIG_ACENIC is not set
-# CONFIG_DL2K is not set
-# CONFIG_MYRI_SBUS is not set
-# CONFIG_NS83820 is not set
-# CONFIG_HAMACHI is not set
-# CONFIG_YELLOWFIN is not set
-# CONFIG_SK98LIN is not set
-# CONFIG_FDDI is not set
-# CONFIG_HIPPI is not set
-# CONFIG_PLIP is not set
-# CONFIG_PPP is not set
-# CONFIG_SLIP is not set
-
-#
-# Wireless LAN (non-hamradio)
-#
-# CONFIG_NET_RADIO is not set
-
-#
-# Token Ring devices
-#
-# CONFIG_TR is not set
-# CONFIG_NET_FC is not set
-# CONFIG_RCPCI is not set
-# CONFIG_SHAPER is not set
-
-#
-# Wan interfaces
-#
-# CONFIG_WAN is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-# CONFIG_VT is not set
-CONFIG_SERIAL=y
-# CONFIG_SERIAL_CONSOLE is not set
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-# CONFIG_MOUSE is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-CONFIG_EFI_RTC=y
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-CONFIG_QUOTA=y
-CONFIG_AUTOFS_FS=y
-CONFIG_AUTOFS4_FS=y
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-CONFIG_FAT_FS=y
-CONFIG_MSDOS_FS=y
-# CONFIG_UMSDOS_FS is not set
-CONFIG_VFAT_FS=y
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-CONFIG_ISO9660_FS=y
-# CONFIG_JOLIET is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_MOUNT=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-CONFIG_XFS_SUPPORT=y
-
-#
-# Network File Systems
-#
-# CONFIG_CODA_FS is not set
-CONFIG_NFS_FS=y
-CONFIG_NFS_V3=y
-# CONFIG_ROOT_NFS is not set
-CONFIG_NFSD=y
-CONFIG_NFSD_V3=y
-CONFIG_SUNRPC=y
-CONFIG_LOCKD=y
-CONFIG_LOCKD_V4=y
-# CONFIG_SMB_FS is not set
-# CONFIG_NCP_FS is not set
-# CONFIG_NCPFS_PACKET_SIGNING is not set
-# CONFIG_NCPFS_IOCTL_LOCKING is not set
-# CONFIG_NCPFS_STRONG is not set
-# CONFIG_NCPFS_NFS_NS is not set
-# CONFIG_NCPFS_OS2_NS is not set
-# CONFIG_NCPFS_SMALLDOS is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_NCPFS_EXTRAS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-CONFIG_NLS=y
-
-#
-# Native Language Support
-#
-CONFIG_NLS_DEFAULT="n"
-# CONFIG_NLS_CODEPAGE_437 is not set
-# CONFIG_NLS_CODEPAGE_737 is not set
-# CONFIG_NLS_CODEPAGE_775 is not set
-# CONFIG_NLS_CODEPAGE_850 is not set
-# CONFIG_NLS_CODEPAGE_852 is not set
-# CONFIG_NLS_CODEPAGE_855 is not set
-# CONFIG_NLS_CODEPAGE_857 is not set
-# CONFIG_NLS_CODEPAGE_860 is not set
-# CONFIG_NLS_CODEPAGE_861 is not set
-# CONFIG_NLS_CODEPAGE_862 is not set
-# CONFIG_NLS_CODEPAGE_863 is not set
-# CONFIG_NLS_CODEPAGE_864 is not set
-# CONFIG_NLS_CODEPAGE_865 is not set
-# CONFIG_NLS_CODEPAGE_866 is not set
-# CONFIG_NLS_CODEPAGE_869 is not set
-# CONFIG_NLS_CODEPAGE_936 is not set
-# CONFIG_NLS_CODEPAGE_950 is not set
-# CONFIG_NLS_CODEPAGE_932 is not set
-# CONFIG_NLS_CODEPAGE_949 is not set
-# CONFIG_NLS_CODEPAGE_874 is not set
-# CONFIG_NLS_ISO8859_8 is not set
-# CONFIG_NLS_CODEPAGE_1251 is not set
-# CONFIG_NLS_ISO8859_1 is not set
-# CONFIG_NLS_ISO8859_2 is not set
-# CONFIG_NLS_ISO8859_3 is not set
-# CONFIG_NLS_ISO8859_4 is not set
-# CONFIG_NLS_ISO8859_5 is not set
-# CONFIG_NLS_ISO8859_6 is not set
-# CONFIG_NLS_ISO8859_7 is not set
-# CONFIG_NLS_ISO8859_9 is not set
-# CONFIG_NLS_ISO8859_13 is not set
-# CONFIG_NLS_ISO8859_14 is not set
-# CONFIG_NLS_ISO8859_15 is not set
-# CONFIG_NLS_KOI8_R is not set
-# CONFIG_NLS_KOI8_U is not set
-# CONFIG_NLS_UTF8 is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-# CONFIG_USB_PEGASUS is not set
-# CONFIG_USB_KAWETH is not set
-# CONFIG_USB_CATC is not set
-# CONFIG_USB_CDCETHER is not set
-# CONFIG_USB_USBNET is not set
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# IEEE 1394 (FireWire) support (EXPERIMENTAL)
-#
-# CONFIG_IEEE1394 is not set
-
-#
-# Bluetooth support
-#
-# CONFIG_BT is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-CONFIG_KDB=y
-CONFIG_KDB_MODULES=y
-# CONFIG_KDB_OFF is not set
-
-#
-#   Load all symbols for debugging is required for KDB
-#
-CONFIG_KALLSYMS=y
diff -Nru a/arch/ia64/sn/configs/sn1/defconfig-sn1-mp-modules b/arch/ia64/sn/configs/sn1/defconfig-sn1-mp-modules
--- a/arch/ia64/sn/configs/sn1/defconfig-sn1-mp-modules	Mon Dec 23 21:21:58 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,728 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-CONFIG_EXPERIMENTAL=y
-
-#
-# Loadable module support
-#
-CONFIG_MODULES=y
-# CONFIG_MODVERSIONS is not set
-CONFIG_KMOD=y
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-CONFIG_ITANIUM=y
-# CONFIG_MCKINLEY is not set
-# CONFIG_IA64_GENERIC is not set
-# CONFIG_IA64_DIG is not set
-# CONFIG_IA64_HP_SIM is not set
-CONFIG_IA64_SGI_SN1=y
-# CONFIG_IA64_SGI_SN2 is not set
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_BRL_EMU=y
-CONFIG_ITANIUM_BSTEP_SPECIFIC=y
-CONFIG_IA64_L1_CACHE_SHIFT=7
-CONFIG_IA64_SGI_SN=y
-CONFIG_IA64_SGI_SN_DEBUG=y
-CONFIG_IA64_SGI_SN_SIM=y
-CONFIG_IA64_SGI_AUTOTEST=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_SERIAL_SGI_L1_PROTOCOL=y
-CONFIG_DISCONTIGMEM=y
-CONFIG_IA64_MCA=y
-CONFIG_NUMA=y
-CONFIG_PERCPU_IRQ=y
-CONFIG_PCIBA=y
-CONFIG_KCORE_ELF=y
-CONFIG_SMP=y
-CONFIG_IA32_SUPPORT=y
-CONFIG_PERFMON=y
-CONFIG_IA64_PALINFO=y
-# CONFIG_EFI_VARS is not set
-CONFIG_NET=y
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-CONFIG_SYSCTL=y
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Networking options
-#
-CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
-CONFIG_NETLINK=y
-CONFIG_RTNETLINK=y
-CONFIG_NETLINK_DEV=y
-CONFIG_NETFILTER=y
-CONFIG_NETFILTER_DEBUG=y
-CONFIG_FILTER=y
-CONFIG_UNIX=y
-CONFIG_INET=y
-CONFIG_IP_MULTICAST=y
-# CONFIG_IP_ADVANCED_ROUTER is not set
-# CONFIG_IP_PNP is not set
-# CONFIG_NET_IPIP is not set
-# CONFIG_NET_IPGRE is not set
-# CONFIG_IP_MROUTE is not set
-# CONFIG_ARPD is not set
-# CONFIG_INET_ECN is not set
-CONFIG_SYN_COOKIES=y
-
-#
-#   IP: Netfilter Configuration
-#
-# CONFIG_IP_NF_CONNTRACK is not set
-# CONFIG_IP_NF_QUEUE is not set
-# CONFIG_IP_NF_IPTABLES is not set
-# CONFIG_IP_NF_COMPAT_IPCHAINS is not set
-# CONFIG_IP_NF_COMPAT_IPFWADM is not set
-# CONFIG_IPV6 is not set
-# CONFIG_KHTTPD is not set
-# CONFIG_ATM is not set
-
-#
-#  
-#
-# CONFIG_IPX is not set
-# CONFIG_ATALK is not set
-# CONFIG_DECNET is not set
-# CONFIG_BRIDGE is not set
-# CONFIG_X25 is not set
-# CONFIG_LAPB is not set
-# CONFIG_LLC is not set
-# CONFIG_NET_DIVERT is not set
-# CONFIG_ECONET is not set
-# CONFIG_WAN_ROUTER is not set
-# CONFIG_NET_FASTROUTE is not set
-# CONFIG_NET_HW_FLOWCONTROL is not set
-
-#
-# QoS and/or fair queueing
-#
-# CONFIG_NET_SCHED is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-# CONFIG_PNPBIOS is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-CONFIG_BLK_DEV_LOOP=y
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_LAN is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-CONFIG_XSCSI=y
-
-#
-# Alternate SCSI support
-#
-CONFIG_XSCSI_DKSC=y
-# CONFIG_XSCSI_QLFC is not set
-# CONFIG_XSCSI_QL is not set
-# CONFIG_XSCSI_SBP2 is not set
-
-#
-# SCSI support
-#
-CONFIG_SCSI=y
-
-#
-# SCSI support type (disk, tape, CD-ROM)
-#
-CONFIG_BLK_DEV_SD=y
-CONFIG_SD_EXTRA_DEVS=40
-# CONFIG_CHR_DEV_ST is not set
-# CONFIG_CHR_DEV_OSST is not set
-# CONFIG_BLK_DEV_SR is not set
-# CONFIG_CHR_DEV_SG is not set
-
-#
-# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
-#
-# CONFIG_SCSI_DEBUG_QUEUES is not set
-# CONFIG_SCSI_MULTI_LUN is not set
-# CONFIG_SCSI_CONSTANTS is not set
-# CONFIG_SCSI_LOGGING is not set
-
-#
-# SCSI low-level drivers
-#
-# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
-# CONFIG_SCSI_7000FASST is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_AHA152X is not set
-# CONFIG_SCSI_AHA1542 is not set
-# CONFIG_SCSI_AHA1740 is not set
-# CONFIG_SCSI_AIC7XXX is not set
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-# CONFIG_SCSI_DPT_I2O is not set
-# CONFIG_SCSI_ADVANSYS is not set
-# CONFIG_SCSI_IN2000 is not set
-# CONFIG_SCSI_AM53C974 is not set
-# CONFIG_SCSI_MEGARAID is not set
-# CONFIG_SCSI_BUSLOGIC is not set
-# CONFIG_SCSI_CPQFCTS is not set
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_DTC3280 is not set
-# CONFIG_SCSI_EATA is not set
-# CONFIG_SCSI_EATA_DMA is not set
-# CONFIG_SCSI_EATA_PIO is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_GDTH is not set
-# CONFIG_SCSI_GENERIC_NCR5380 is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_NCR53C406A is not set
-# CONFIG_SCSI_NCR53C7xx is not set
-# CONFIG_SCSI_NCR53C8XX is not set
-# CONFIG_SCSI_SYM53C8XX is not set
-# CONFIG_SCSI_PAS16 is not set
-# CONFIG_SCSI_PCI2000 is not set
-# CONFIG_SCSI_PCI2220I is not set
-# CONFIG_SCSI_PSI240I is not set
-# CONFIG_SCSI_QLOGIC_FAS is not set
-# CONFIG_SCSI_QLOGIC_ISP is not set
-CONFIG_SCSI_QLOGIC_FC=y
-# CONFIG_SCSI_QLOGIC_FC_FIRMWARE is not set
-# CONFIG_SCSI_QLOGIC_1280 is not set
-# CONFIG_SCSI_QLOGIC_QLA2100 is not set
-# CONFIG_SCSI_SIM710 is not set
-# CONFIG_SCSI_SYM53C416 is not set
-# CONFIG_SCSI_DC390T is not set
-# CONFIG_SCSI_T128 is not set
-# CONFIG_SCSI_U14_34F is not set
-# CONFIG_SCSI_DEBUG is not set
-
-#
-# Network device support
-#
-CONFIG_NETDEVICES=y
-
-#
-# ARCnet devices
-#
-# CONFIG_ARCNET is not set
-# CONFIG_DUMMY is not set
-# CONFIG_BONDING is not set
-# CONFIG_EQUALIZER is not set
-# CONFIG_TUN is not set
-# CONFIG_ETHERTAP is not set
-
-#
-# Ethernet (10 or 100Mbit)
-#
-CONFIG_NET_ETHERNET=y
-CONFIG_SGI_IOC3_ETH=y
-# CONFIG_SUNLANCE is not set
-# CONFIG_HAPPYMEAL is not set
-# CONFIG_SUNBMAC is not set
-# CONFIG_SUNQE is not set
-# CONFIG_SUNLANCE is not set
-# CONFIG_SUNGEM is not set
-# CONFIG_NET_VENDOR_3COM is not set
-# CONFIG_LANCE is not set
-# CONFIG_NET_VENDOR_SMC is not set
-# CONFIG_NET_VENDOR_RACAL is not set
-# CONFIG_HP100 is not set
-# CONFIG_NET_ISA is not set
-# CONFIG_NET_PCI is not set
-# CONFIG_NET_POCKET is not set
-
-#
-# Ethernet (1000 Mbit)
-#
-# CONFIG_ACENIC is not set
-# CONFIG_DL2K is not set
-# CONFIG_MYRI_SBUS is not set
-# CONFIG_NS83820 is not set
-# CONFIG_HAMACHI is not set
-# CONFIG_YELLOWFIN is not set
-# CONFIG_SK98LIN is not set
-# CONFIG_FDDI is not set
-# CONFIG_HIPPI is not set
-# CONFIG_PLIP is not set
-# CONFIG_PPP is not set
-# CONFIG_SLIP is not set
-
-#
-# Wireless LAN (non-hamradio)
-#
-# CONFIG_NET_RADIO is not set
-
-#
-# Token Ring devices
-#
-# CONFIG_TR is not set
-# CONFIG_NET_FC is not set
-# CONFIG_RCPCI is not set
-# CONFIG_SHAPER is not set
-
-#
-# Wan interfaces
-#
-# CONFIG_WAN is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-# CONFIG_VT is not set
-CONFIG_SERIAL=y
-# CONFIG_SERIAL_CONSOLE is not set
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-# CONFIG_MOUSE is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-CONFIG_EFI_RTC=y
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-CONFIG_QUOTA=y
-CONFIG_AUTOFS_FS=y
-CONFIG_AUTOFS4_FS=y
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-CONFIG_FAT_FS=y
-CONFIG_MSDOS_FS=y
-# CONFIG_UMSDOS_FS is not set
-CONFIG_VFAT_FS=y
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-CONFIG_ISO9660_FS=y
-# CONFIG_JOLIET is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_MOUNT=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-CONFIG_XFS_SUPPORT=y
-
-#
-# Network File Systems
-#
-# CONFIG_CODA_FS is not set
-CONFIG_NFS_FS=y
-CONFIG_NFS_V3=y
-# CONFIG_ROOT_NFS is not set
-CONFIG_NFSD=y
-CONFIG_NFSD_V3=y
-CONFIG_SUNRPC=y
-CONFIG_LOCKD=y
-CONFIG_LOCKD_V4=y
-# CONFIG_SMB_FS is not set
-# CONFIG_NCP_FS is not set
-# CONFIG_NCPFS_PACKET_SIGNING is not set
-# CONFIG_NCPFS_IOCTL_LOCKING is not set
-# CONFIG_NCPFS_STRONG is not set
-# CONFIG_NCPFS_NFS_NS is not set
-# CONFIG_NCPFS_OS2_NS is not set
-# CONFIG_NCPFS_SMALLDOS is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_NCPFS_EXTRAS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-CONFIG_NLS=y
-
-#
-# Native Language Support
-#
-CONFIG_NLS_DEFAULT="n"
-# CONFIG_NLS_CODEPAGE_437 is not set
-# CONFIG_NLS_CODEPAGE_737 is not set
-# CONFIG_NLS_CODEPAGE_775 is not set
-# CONFIG_NLS_CODEPAGE_850 is not set
-# CONFIG_NLS_CODEPAGE_852 is not set
-# CONFIG_NLS_CODEPAGE_855 is not set
-# CONFIG_NLS_CODEPAGE_857 is not set
-# CONFIG_NLS_CODEPAGE_860 is not set
-# CONFIG_NLS_CODEPAGE_861 is not set
-# CONFIG_NLS_CODEPAGE_862 is not set
-# CONFIG_NLS_CODEPAGE_863 is not set
-# CONFIG_NLS_CODEPAGE_864 is not set
-# CONFIG_NLS_CODEPAGE_865 is not set
-# CONFIG_NLS_CODEPAGE_866 is not set
-# CONFIG_NLS_CODEPAGE_869 is not set
-# CONFIG_NLS_CODEPAGE_936 is not set
-# CONFIG_NLS_CODEPAGE_950 is not set
-# CONFIG_NLS_CODEPAGE_932 is not set
-# CONFIG_NLS_CODEPAGE_949 is not set
-# CONFIG_NLS_CODEPAGE_874 is not set
-# CONFIG_NLS_ISO8859_8 is not set
-# CONFIG_NLS_CODEPAGE_1251 is not set
-# CONFIG_NLS_ISO8859_1 is not set
-# CONFIG_NLS_ISO8859_2 is not set
-# CONFIG_NLS_ISO8859_3 is not set
-# CONFIG_NLS_ISO8859_4 is not set
-# CONFIG_NLS_ISO8859_5 is not set
-# CONFIG_NLS_ISO8859_6 is not set
-# CONFIG_NLS_ISO8859_7 is not set
-# CONFIG_NLS_ISO8859_9 is not set
-# CONFIG_NLS_ISO8859_13 is not set
-# CONFIG_NLS_ISO8859_14 is not set
-# CONFIG_NLS_ISO8859_15 is not set
-# CONFIG_NLS_KOI8_R is not set
-# CONFIG_NLS_KOI8_U is not set
-# CONFIG_NLS_UTF8 is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-# CONFIG_USB_PEGASUS is not set
-# CONFIG_USB_KAWETH is not set
-# CONFIG_USB_CATC is not set
-# CONFIG_USB_CDCETHER is not set
-# CONFIG_USB_USBNET is not set
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# IEEE 1394 (FireWire) support (EXPERIMENTAL)
-#
-# CONFIG_IEEE1394 is not set
-
-#
-# Bluetooth support
-#
-# CONFIG_BT is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-CONFIG_KDB=y
-CONFIG_KDB_MODULES=y
-# CONFIG_KDB_OFF is not set
-
-#
-#   Load all symbols for debugging is required for KDB
-#
-CONFIG_KALLSYMS=y
diff -Nru a/arch/ia64/sn/configs/sn1/defconfig-sn1-mp-syn1-0 b/arch/ia64/sn/configs/sn1/defconfig-sn1-mp-syn1-0
--- a/arch/ia64/sn/configs/sn1/defconfig-sn1-mp-syn1-0	Mon Dec 23 21:21:53 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,726 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-CONFIG_EXPERIMENTAL=y
-
-#
-# Loadable module support
-#
-# CONFIG_MODULES is not set
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-CONFIG_ITANIUM=y
-# CONFIG_MCKINLEY is not set
-# CONFIG_IA64_GENERIC is not set
-# CONFIG_IA64_DIG is not set
-# CONFIG_IA64_HP_SIM is not set
-CONFIG_IA64_SGI_SN1=y
-# CONFIG_IA64_SGI_SN2 is not set
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_BRL_EMU=y
-CONFIG_ITANIUM_BSTEP_SPECIFIC=y
-CONFIG_IA64_L1_CACHE_SHIFT=7
-CONFIG_IA64_SGI_SN=y
-CONFIG_IA64_SGI_SN_DEBUG=y
-CONFIG_IA64_SGI_SN_SIM=y
-CONFIG_IA64_SGI_AUTOTEST=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_SERIAL_SGI_L1_PROTOCOL=y
-CONFIG_DISCONTIGMEM=y
-CONFIG_IA64_MCA=y
-CONFIG_NUMA=y
-CONFIG_PERCPU_IRQ=y
-CONFIG_PCIBA=y
-CONFIG_KCORE_ELF=y
-CONFIG_SMP=y
-CONFIG_IA32_SUPPORT=y
-CONFIG_PERFMON=y
-CONFIG_IA64_PALINFO=y
-# CONFIG_EFI_VARS is not set
-CONFIG_NET=y
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-CONFIG_SYSCTL=y
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Networking options
-#
-CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
-CONFIG_NETLINK=y
-CONFIG_RTNETLINK=y
-CONFIG_NETLINK_DEV=y
-CONFIG_NETFILTER=y
-CONFIG_NETFILTER_DEBUG=y
-CONFIG_FILTER=y
-CONFIG_UNIX=y
-CONFIG_INET=y
-CONFIG_IP_MULTICAST=y
-# CONFIG_IP_ADVANCED_ROUTER is not set
-# CONFIG_IP_PNP is not set
-# CONFIG_NET_IPIP is not set
-# CONFIG_NET_IPGRE is not set
-# CONFIG_IP_MROUTE is not set
-# CONFIG_ARPD is not set
-# CONFIG_INET_ECN is not set
-CONFIG_SYN_COOKIES=y
-
-#
-#   IP: Netfilter Configuration
-#
-# CONFIG_IP_NF_CONNTRACK is not set
-# CONFIG_IP_NF_QUEUE is not set
-# CONFIG_IP_NF_IPTABLES is not set
-# CONFIG_IP_NF_COMPAT_IPCHAINS is not set
-# CONFIG_IP_NF_COMPAT_IPFWADM is not set
-# CONFIG_IPV6 is not set
-# CONFIG_KHTTPD is not set
-# CONFIG_ATM is not set
-
-#
-#  
-#
-# CONFIG_IPX is not set
-# CONFIG_ATALK is not set
-# CONFIG_DECNET is not set
-# CONFIG_BRIDGE is not set
-# CONFIG_X25 is not set
-# CONFIG_LAPB is not set
-# CONFIG_LLC is not set
-# CONFIG_NET_DIVERT is not set
-# CONFIG_ECONET is not set
-# CONFIG_WAN_ROUTER is not set
-# CONFIG_NET_FASTROUTE is not set
-# CONFIG_NET_HW_FLOWCONTROL is not set
-
-#
-# QoS and/or fair queueing
-#
-# CONFIG_NET_SCHED is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-# CONFIG_PNPBIOS is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-CONFIG_BLK_DEV_LOOP=y
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_LAN is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-CONFIG_XSCSI=y
-
-#
-# Alternate SCSI support
-#
-CONFIG_XSCSI_DKSC=y
-# CONFIG_XSCSI_QLFC is not set
-# CONFIG_XSCSI_QL is not set
-# CONFIG_XSCSI_SBP2 is not set
-
-#
-# SCSI support
-#
-CONFIG_SCSI=y
-
-#
-# SCSI support type (disk, tape, CD-ROM)
-#
-CONFIG_BLK_DEV_SD=y
-CONFIG_SD_EXTRA_DEVS=40
-# CONFIG_CHR_DEV_ST is not set
-# CONFIG_CHR_DEV_OSST is not set
-# CONFIG_BLK_DEV_SR is not set
-# CONFIG_CHR_DEV_SG is not set
-
-#
-# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
-#
-# CONFIG_SCSI_DEBUG_QUEUES is not set
-# CONFIG_SCSI_MULTI_LUN is not set
-# CONFIG_SCSI_CONSTANTS is not set
-# CONFIG_SCSI_LOGGING is not set
-
-#
-# SCSI low-level drivers
-#
-# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
-# CONFIG_SCSI_7000FASST is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_AHA152X is not set
-# CONFIG_SCSI_AHA1542 is not set
-# CONFIG_SCSI_AHA1740 is not set
-# CONFIG_SCSI_AIC7XXX is not set
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-# CONFIG_SCSI_DPT_I2O is not set
-# CONFIG_SCSI_ADVANSYS is not set
-# CONFIG_SCSI_IN2000 is not set
-# CONFIG_SCSI_AM53C974 is not set
-# CONFIG_SCSI_MEGARAID is not set
-# CONFIG_SCSI_BUSLOGIC is not set
-# CONFIG_SCSI_CPQFCTS is not set
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_DTC3280 is not set
-# CONFIG_SCSI_EATA is not set
-# CONFIG_SCSI_EATA_DMA is not set
-# CONFIG_SCSI_EATA_PIO is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_GDTH is not set
-# CONFIG_SCSI_GENERIC_NCR5380 is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_NCR53C406A is not set
-# CONFIG_SCSI_NCR53C7xx is not set
-# CONFIG_SCSI_NCR53C8XX is not set
-# CONFIG_SCSI_SYM53C8XX is not set
-# CONFIG_SCSI_PAS16 is not set
-# CONFIG_SCSI_PCI2000 is not set
-# CONFIG_SCSI_PCI2220I is not set
-# CONFIG_SCSI_PSI240I is not set
-# CONFIG_SCSI_QLOGIC_FAS is not set
-# CONFIG_SCSI_QLOGIC_ISP is not set
-CONFIG_SCSI_QLOGIC_FC=y
-# CONFIG_SCSI_QLOGIC_FC_FIRMWARE is not set
-# CONFIG_SCSI_QLOGIC_1280 is not set
-# CONFIG_SCSI_QLOGIC_QLA2100 is not set
-# CONFIG_SCSI_SIM710 is not set
-# CONFIG_SCSI_SYM53C416 is not set
-# CONFIG_SCSI_DC390T is not set
-# CONFIG_SCSI_T128 is not set
-# CONFIG_SCSI_U14_34F is not set
-# CONFIG_SCSI_DEBUG is not set
-
-#
-# Network device support
-#
-CONFIG_NETDEVICES=y
-
-#
-# ARCnet devices
-#
-# CONFIG_ARCNET is not set
-# CONFIG_DUMMY is not set
-# CONFIG_BONDING is not set
-# CONFIG_EQUALIZER is not set
-# CONFIG_TUN is not set
-# CONFIG_ETHERTAP is not set
-
-#
-# Ethernet (10 or 100Mbit)
-#
-CONFIG_NET_ETHERNET=y
-CONFIG_SGI_IOC3_ETH=y
-# CONFIG_SUNLANCE is not set
-# CONFIG_HAPPYMEAL is not set
-# CONFIG_SUNBMAC is not set
-# CONFIG_SUNQE is not set
-# CONFIG_SUNLANCE is not set
-# CONFIG_SUNGEM is not set
-# CONFIG_NET_VENDOR_3COM is not set
-# CONFIG_LANCE is not set
-# CONFIG_NET_VENDOR_SMC is not set
-# CONFIG_NET_VENDOR_RACAL is not set
-# CONFIG_HP100 is not set
-# CONFIG_NET_ISA is not set
-# CONFIG_NET_PCI is not set
-# CONFIG_NET_POCKET is not set
-
-#
-# Ethernet (1000 Mbit)
-#
-# CONFIG_ACENIC is not set
-# CONFIG_DL2K is not set
-# CONFIG_MYRI_SBUS is not set
-# CONFIG_NS83820 is not set
-# CONFIG_HAMACHI is not set
-# CONFIG_YELLOWFIN is not set
-# CONFIG_SK98LIN is not set
-# CONFIG_FDDI is not set
-# CONFIG_HIPPI is not set
-# CONFIG_PLIP is not set
-# CONFIG_PPP is not set
-# CONFIG_SLIP is not set
-
-#
-# Wireless LAN (non-hamradio)
-#
-# CONFIG_NET_RADIO is not set
-
-#
-# Token Ring devices
-#
-# CONFIG_TR is not set
-# CONFIG_NET_FC is not set
-# CONFIG_RCPCI is not set
-# CONFIG_SHAPER is not set
-
-#
-# Wan interfaces
-#
-# CONFIG_WAN is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-# CONFIG_VT is not set
-CONFIG_SERIAL=y
-# CONFIG_SERIAL_CONSOLE is not set
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-# CONFIG_MOUSE is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-CONFIG_EFI_RTC=y
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-CONFIG_QUOTA=y
-CONFIG_AUTOFS_FS=y
-CONFIG_AUTOFS4_FS=y
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-CONFIG_FAT_FS=y
-CONFIG_MSDOS_FS=y
-# CONFIG_UMSDOS_FS is not set
-CONFIG_VFAT_FS=y
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-CONFIG_ISO9660_FS=y
-# CONFIG_JOLIET is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_MOUNT=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-CONFIG_XFS_SUPPORT=y
-
-#
-# Network File Systems
-#
-# CONFIG_CODA_FS is not set
-CONFIG_NFS_FS=y
-CONFIG_NFS_V3=y
-# CONFIG_ROOT_NFS is not set
-CONFIG_NFSD=y
-CONFIG_NFSD_V3=y
-CONFIG_SUNRPC=y
-CONFIG_LOCKD=y
-CONFIG_LOCKD_V4=y
-# CONFIG_SMB_FS is not set
-# CONFIG_NCP_FS is not set
-# CONFIG_NCPFS_PACKET_SIGNING is not set
-# CONFIG_NCPFS_IOCTL_LOCKING is not set
-# CONFIG_NCPFS_STRONG is not set
-# CONFIG_NCPFS_NFS_NS is not set
-# CONFIG_NCPFS_OS2_NS is not set
-# CONFIG_NCPFS_SMALLDOS is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_NCPFS_EXTRAS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-CONFIG_NLS=y
-
-#
-# Native Language Support
-#
-CONFIG_NLS_DEFAULT="n"
-# CONFIG_NLS_CODEPAGE_437 is not set
-# CONFIG_NLS_CODEPAGE_737 is not set
-# CONFIG_NLS_CODEPAGE_775 is not set
-# CONFIG_NLS_CODEPAGE_850 is not set
-# CONFIG_NLS_CODEPAGE_852 is not set
-# CONFIG_NLS_CODEPAGE_855 is not set
-# CONFIG_NLS_CODEPAGE_857 is not set
-# CONFIG_NLS_CODEPAGE_860 is not set
-# CONFIG_NLS_CODEPAGE_861 is not set
-# CONFIG_NLS_CODEPAGE_862 is not set
-# CONFIG_NLS_CODEPAGE_863 is not set
-# CONFIG_NLS_CODEPAGE_864 is not set
-# CONFIG_NLS_CODEPAGE_865 is not set
-# CONFIG_NLS_CODEPAGE_866 is not set
-# CONFIG_NLS_CODEPAGE_869 is not set
-# CONFIG_NLS_CODEPAGE_936 is not set
-# CONFIG_NLS_CODEPAGE_950 is not set
-# CONFIG_NLS_CODEPAGE_932 is not set
-# CONFIG_NLS_CODEPAGE_949 is not set
-# CONFIG_NLS_CODEPAGE_874 is not set
-# CONFIG_NLS_ISO8859_8 is not set
-# CONFIG_NLS_CODEPAGE_1251 is not set
-# CONFIG_NLS_ISO8859_1 is not set
-# CONFIG_NLS_ISO8859_2 is not set
-# CONFIG_NLS_ISO8859_3 is not set
-# CONFIG_NLS_ISO8859_4 is not set
-# CONFIG_NLS_ISO8859_5 is not set
-# CONFIG_NLS_ISO8859_6 is not set
-# CONFIG_NLS_ISO8859_7 is not set
-# CONFIG_NLS_ISO8859_9 is not set
-# CONFIG_NLS_ISO8859_13 is not set
-# CONFIG_NLS_ISO8859_14 is not set
-# CONFIG_NLS_ISO8859_15 is not set
-# CONFIG_NLS_KOI8_R is not set
-# CONFIG_NLS_KOI8_U is not set
-# CONFIG_NLS_UTF8 is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-# CONFIG_USB_PEGASUS is not set
-# CONFIG_USB_KAWETH is not set
-# CONFIG_USB_CATC is not set
-# CONFIG_USB_CDCETHER is not set
-# CONFIG_USB_USBNET is not set
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# IEEE 1394 (FireWire) support (EXPERIMENTAL)
-#
-# CONFIG_IEEE1394 is not set
-
-#
-# Bluetooth support
-#
-# CONFIG_BT is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-CONFIG_KDB=y
-CONFIG_KDB_MODULES=y
-# CONFIG_KDB_OFF is not set
-
-#
-#   Load all symbols for debugging is required for KDB
-#
-CONFIG_KALLSYMS=y
diff -Nru a/arch/ia64/sn/configs/sn1/defconfig-sn1-sp b/arch/ia64/sn/configs/sn1/defconfig-sn1-sp
--- a/arch/ia64/sn/configs/sn1/defconfig-sn1-sp	Mon Dec 23 21:21:50 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,726 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-CONFIG_EXPERIMENTAL=y
-
-#
-# Loadable module support
-#
-# CONFIG_MODULES is not set
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-CONFIG_ITANIUM=y
-# CONFIG_MCKINLEY is not set
-# CONFIG_IA64_GENERIC is not set
-# CONFIG_IA64_DIG is not set
-# CONFIG_IA64_HP_SIM is not set
-CONFIG_IA64_SGI_SN1=y
-# CONFIG_IA64_SGI_SN2 is not set
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_BRL_EMU=y
-CONFIG_ITANIUM_BSTEP_SPECIFIC=y
-CONFIG_IA64_L1_CACHE_SHIFT=7
-CONFIG_IA64_SGI_SN=y
-CONFIG_IA64_SGI_SN_DEBUG=y
-CONFIG_IA64_SGI_SN_SIM=y
-CONFIG_IA64_SGI_AUTOTEST=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_SERIAL_SGI_L1_PROTOCOL=y
-CONFIG_DISCONTIGMEM=y
-CONFIG_IA64_MCA=y
-CONFIG_NUMA=y
-CONFIG_PERCPU_IRQ=y
-CONFIG_PCIBA=y
-CONFIG_KCORE_ELF=y
-# CONFIG_SMP is not set
-CONFIG_IA32_SUPPORT=y
-CONFIG_PERFMON=y
-CONFIG_IA64_PALINFO=y
-# CONFIG_EFI_VARS is not set
-CONFIG_NET=y
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-CONFIG_SYSCTL=y
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Networking options
-#
-CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
-CONFIG_NETLINK=y
-CONFIG_RTNETLINK=y
-CONFIG_NETLINK_DEV=y
-CONFIG_NETFILTER=y
-CONFIG_NETFILTER_DEBUG=y
-CONFIG_FILTER=y
-CONFIG_UNIX=y
-CONFIG_INET=y
-CONFIG_IP_MULTICAST=y
-# CONFIG_IP_ADVANCED_ROUTER is not set
-# CONFIG_IP_PNP is not set
-# CONFIG_NET_IPIP is not set
-# CONFIG_NET_IPGRE is not set
-# CONFIG_IP_MROUTE is not set
-# CONFIG_ARPD is not set
-# CONFIG_INET_ECN is not set
-CONFIG_SYN_COOKIES=y
-
-#
-#   IP: Netfilter Configuration
-#
-# CONFIG_IP_NF_CONNTRACK is not set
-# CONFIG_IP_NF_QUEUE is not set
-# CONFIG_IP_NF_IPTABLES is not set
-# CONFIG_IP_NF_COMPAT_IPCHAINS is not set
-# CONFIG_IP_NF_COMPAT_IPFWADM is not set
-# CONFIG_IPV6 is not set
-# CONFIG_KHTTPD is not set
-# CONFIG_ATM is not set
-
-#
-#  
-#
-# CONFIG_IPX is not set
-# CONFIG_ATALK is not set
-# CONFIG_DECNET is not set
-# CONFIG_BRIDGE is not set
-# CONFIG_X25 is not set
-# CONFIG_LAPB is not set
-# CONFIG_LLC is not set
-# CONFIG_NET_DIVERT is not set
-# CONFIG_ECONET is not set
-# CONFIG_WAN_ROUTER is not set
-# CONFIG_NET_FASTROUTE is not set
-# CONFIG_NET_HW_FLOWCONTROL is not set
-
-#
-# QoS and/or fair queueing
-#
-# CONFIG_NET_SCHED is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-# CONFIG_PNPBIOS is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-CONFIG_BLK_DEV_LOOP=y
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_LAN is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-CONFIG_XSCSI=y
-
-#
-# Alternate SCSI support
-#
-CONFIG_XSCSI_DKSC=y
-# CONFIG_XSCSI_QLFC is not set
-# CONFIG_XSCSI_QL is not set
-# CONFIG_XSCSI_SBP2 is not set
-
-#
-# SCSI support
-#
-CONFIG_SCSI=y
-
-#
-# SCSI support type (disk, tape, CD-ROM)
-#
-CONFIG_BLK_DEV_SD=y
-CONFIG_SD_EXTRA_DEVS=40
-# CONFIG_CHR_DEV_ST is not set
-# CONFIG_CHR_DEV_OSST is not set
-# CONFIG_BLK_DEV_SR is not set
-# CONFIG_CHR_DEV_SG is not set
-
-#
-# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
-#
-# CONFIG_SCSI_DEBUG_QUEUES is not set
-# CONFIG_SCSI_MULTI_LUN is not set
-# CONFIG_SCSI_CONSTANTS is not set
-# CONFIG_SCSI_LOGGING is not set
-
-#
-# SCSI low-level drivers
-#
-# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
-# CONFIG_SCSI_7000FASST is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_AHA152X is not set
-# CONFIG_SCSI_AHA1542 is not set
-# CONFIG_SCSI_AHA1740 is not set
-# CONFIG_SCSI_AIC7XXX is not set
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-# CONFIG_SCSI_DPT_I2O is not set
-# CONFIG_SCSI_ADVANSYS is not set
-# CONFIG_SCSI_IN2000 is not set
-# CONFIG_SCSI_AM53C974 is not set
-# CONFIG_SCSI_MEGARAID is not set
-# CONFIG_SCSI_BUSLOGIC is not set
-# CONFIG_SCSI_CPQFCTS is not set
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_DTC3280 is not set
-# CONFIG_SCSI_EATA is not set
-# CONFIG_SCSI_EATA_DMA is not set
-# CONFIG_SCSI_EATA_PIO is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_GDTH is not set
-# CONFIG_SCSI_GENERIC_NCR5380 is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_NCR53C406A is not set
-# CONFIG_SCSI_NCR53C7xx is not set
-# CONFIG_SCSI_NCR53C8XX is not set
-# CONFIG_SCSI_SYM53C8XX is not set
-# CONFIG_SCSI_PAS16 is not set
-# CONFIG_SCSI_PCI2000 is not set
-# CONFIG_SCSI_PCI2220I is not set
-# CONFIG_SCSI_PSI240I is not set
-# CONFIG_SCSI_QLOGIC_FAS is not set
-# CONFIG_SCSI_QLOGIC_ISP is not set
-CONFIG_SCSI_QLOGIC_FC=y
-# CONFIG_SCSI_QLOGIC_FC_FIRMWARE is not set
-# CONFIG_SCSI_QLOGIC_1280 is not set
-# CONFIG_SCSI_QLOGIC_QLA2100 is not set
-# CONFIG_SCSI_SIM710 is not set
-# CONFIG_SCSI_SYM53C416 is not set
-# CONFIG_SCSI_DC390T is not set
-# CONFIG_SCSI_T128 is not set
-# CONFIG_SCSI_U14_34F is not set
-# CONFIG_SCSI_DEBUG is not set
-
-#
-# Network device support
-#
-CONFIG_NETDEVICES=y
-
-#
-# ARCnet devices
-#
-# CONFIG_ARCNET is not set
-# CONFIG_DUMMY is not set
-# CONFIG_BONDING is not set
-# CONFIG_EQUALIZER is not set
-# CONFIG_TUN is not set
-# CONFIG_ETHERTAP is not set
-
-#
-# Ethernet (10 or 100Mbit)
-#
-CONFIG_NET_ETHERNET=y
-CONFIG_SGI_IOC3_ETH=y
-# CONFIG_SUNLANCE is not set
-# CONFIG_HAPPYMEAL is not set
-# CONFIG_SUNBMAC is not set
-# CONFIG_SUNQE is not set
-# CONFIG_SUNLANCE is not set
-# CONFIG_SUNGEM is not set
-# CONFIG_NET_VENDOR_3COM is not set
-# CONFIG_LANCE is not set
-# CONFIG_NET_VENDOR_SMC is not set
-# CONFIG_NET_VENDOR_RACAL is not set
-# CONFIG_HP100 is not set
-# CONFIG_NET_ISA is not set
-# CONFIG_NET_PCI is not set
-# CONFIG_NET_POCKET is not set
-
-#
-# Ethernet (1000 Mbit)
-#
-# CONFIG_ACENIC is not set
-# CONFIG_DL2K is not set
-# CONFIG_MYRI_SBUS is not set
-# CONFIG_NS83820 is not set
-# CONFIG_HAMACHI is not set
-# CONFIG_YELLOWFIN is not set
-# CONFIG_SK98LIN is not set
-# CONFIG_FDDI is not set
-# CONFIG_HIPPI is not set
-# CONFIG_PLIP is not set
-# CONFIG_PPP is not set
-# CONFIG_SLIP is not set
-
-#
-# Wireless LAN (non-hamradio)
-#
-# CONFIG_NET_RADIO is not set
-
-#
-# Token Ring devices
-#
-# CONFIG_TR is not set
-# CONFIG_NET_FC is not set
-# CONFIG_RCPCI is not set
-# CONFIG_SHAPER is not set
-
-#
-# Wan interfaces
-#
-# CONFIG_WAN is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-# CONFIG_VT is not set
-CONFIG_SERIAL=y
-# CONFIG_SERIAL_CONSOLE is not set
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-# CONFIG_MOUSE is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-CONFIG_EFI_RTC=y
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-CONFIG_QUOTA=y
-CONFIG_AUTOFS_FS=y
-CONFIG_AUTOFS4_FS=y
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-CONFIG_FAT_FS=y
-CONFIG_MSDOS_FS=y
-# CONFIG_UMSDOS_FS is not set
-CONFIG_VFAT_FS=y
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-CONFIG_ISO9660_FS=y
-# CONFIG_JOLIET is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_MOUNT=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-CONFIG_XFS_SUPPORT=y
-
-#
-# Network File Systems
-#
-# CONFIG_CODA_FS is not set
-CONFIG_NFS_FS=y
-CONFIG_NFS_V3=y
-# CONFIG_ROOT_NFS is not set
-CONFIG_NFSD=y
-CONFIG_NFSD_V3=y
-CONFIG_SUNRPC=y
-CONFIG_LOCKD=y
-CONFIG_LOCKD_V4=y
-# CONFIG_SMB_FS is not set
-# CONFIG_NCP_FS is not set
-# CONFIG_NCPFS_PACKET_SIGNING is not set
-# CONFIG_NCPFS_IOCTL_LOCKING is not set
-# CONFIG_NCPFS_STRONG is not set
-# CONFIG_NCPFS_NFS_NS is not set
-# CONFIG_NCPFS_OS2_NS is not set
-# CONFIG_NCPFS_SMALLDOS is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_NCPFS_EXTRAS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-CONFIG_NLS=y
-
-#
-# Native Language Support
-#
-CONFIG_NLS_DEFAULT="n"
-# CONFIG_NLS_CODEPAGE_437 is not set
-# CONFIG_NLS_CODEPAGE_737 is not set
-# CONFIG_NLS_CODEPAGE_775 is not set
-# CONFIG_NLS_CODEPAGE_850 is not set
-# CONFIG_NLS_CODEPAGE_852 is not set
-# CONFIG_NLS_CODEPAGE_855 is not set
-# CONFIG_NLS_CODEPAGE_857 is not set
-# CONFIG_NLS_CODEPAGE_860 is not set
-# CONFIG_NLS_CODEPAGE_861 is not set
-# CONFIG_NLS_CODEPAGE_862 is not set
-# CONFIG_NLS_CODEPAGE_863 is not set
-# CONFIG_NLS_CODEPAGE_864 is not set
-# CONFIG_NLS_CODEPAGE_865 is not set
-# CONFIG_NLS_CODEPAGE_866 is not set
-# CONFIG_NLS_CODEPAGE_869 is not set
-# CONFIG_NLS_CODEPAGE_936 is not set
-# CONFIG_NLS_CODEPAGE_950 is not set
-# CONFIG_NLS_CODEPAGE_932 is not set
-# CONFIG_NLS_CODEPAGE_949 is not set
-# CONFIG_NLS_CODEPAGE_874 is not set
-# CONFIG_NLS_ISO8859_8 is not set
-# CONFIG_NLS_CODEPAGE_1251 is not set
-# CONFIG_NLS_ISO8859_1 is not set
-# CONFIG_NLS_ISO8859_2 is not set
-# CONFIG_NLS_ISO8859_3 is not set
-# CONFIG_NLS_ISO8859_4 is not set
-# CONFIG_NLS_ISO8859_5 is not set
-# CONFIG_NLS_ISO8859_6 is not set
-# CONFIG_NLS_ISO8859_7 is not set
-# CONFIG_NLS_ISO8859_9 is not set
-# CONFIG_NLS_ISO8859_13 is not set
-# CONFIG_NLS_ISO8859_14 is not set
-# CONFIG_NLS_ISO8859_15 is not set
-# CONFIG_NLS_KOI8_R is not set
-# CONFIG_NLS_KOI8_U is not set
-# CONFIG_NLS_UTF8 is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-# CONFIG_USB_PEGASUS is not set
-# CONFIG_USB_KAWETH is not set
-# CONFIG_USB_CATC is not set
-# CONFIG_USB_CDCETHER is not set
-# CONFIG_USB_USBNET is not set
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# IEEE 1394 (FireWire) support (EXPERIMENTAL)
-#
-# CONFIG_IEEE1394 is not set
-
-#
-# Bluetooth support
-#
-# CONFIG_BT is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-CONFIG_KDB=y
-CONFIG_KDB_MODULES=y
-# CONFIG_KDB_OFF is not set
-
-#
-#   Load all symbols for debugging is required for KDB
-#
-CONFIG_KALLSYMS=y
diff -Nru a/arch/ia64/sn/configs/sn2/defconfig-dig-numa b/arch/ia64/sn/configs/sn2/defconfig-dig-numa
--- a/arch/ia64/sn/configs/sn2/defconfig-dig-numa	Mon Dec 23 21:21:51 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,450 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-# CONFIG_EXPERIMENTAL is not set
-
-#
-# Loadable module support
-#
-# CONFIG_MODULES is not set
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-CONFIG_ITANIUM=y
-# CONFIG_MCKINLEY is not set
-# CONFIG_IA64_GENERIC is not set
-CONFIG_IA64_DIG=y
-# CONFIG_IA64_HP_SIM is not set
-# CONFIG_IA64_SGI_SN1 is not set
-# CONFIG_IA64_SGI_SN2 is not set
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_BRL_EMU=y
-CONFIG_ITANIUM_BSTEP_SPECIFIC=y
-CONFIG_IA64_L1_CACHE_SHIFT=6
-CONFIG_NUMA=y
-CONFIG_DISCONTIGMEM=y
-# CONFIG_IA64_MCA is not set
-CONFIG_PM=y
-CONFIG_IA64_HAVE_SYNCRONIZED_ITC=y
-# CONFIG_DEVFS_FS is not set
-CONFIG_KCORE_ELF=y
-CONFIG_SMP=y
-# CONFIG_IA32_SUPPORT is not set
-# CONFIG_PERFMON is not set
-# CONFIG_IA64_PALINFO is not set
-# CONFIG_EFI_VARS is not set
-# CONFIG_NET is not set
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-# CONFIG_SYSCTL is not set
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-# CONFIG_BLK_DEV_LOOP is not set
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-# CONFIG_XSCSI is not set
-
-#
-# SCSI support
-#
-# CONFIG_SCSI is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-CONFIG_VT=y
-CONFIG_VT_CONSOLE=y
-# CONFIG_SERIAL is not set
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-# CONFIG_MOUSE is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-# CONFIG_EFI_RTC is not set
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-# CONFIG_QUOTA is not set
-# CONFIG_AUTOFS_FS is not set
-# CONFIG_AUTOFS4_FS is not set
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-# CONFIG_FAT_FS is not set
-# CONFIG_MSDOS_FS is not set
-# CONFIG_UMSDOS_FS is not set
-# CONFIG_VFAT_FS is not set
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-# CONFIG_ISO9660_FS is not set
-# CONFIG_JOLIET is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-# CONFIG_DEVFS_FS is not set
-# CONFIG_DEVFS_MOUNT is not set
-# CONFIG_DEVFS_DEBUG is not set
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-# CONFIG_XFS_SUPPORT is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_SMB_FS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-# CONFIG_NLS is not set
-
-#
-# Console drivers
-#
-CONFIG_VGA_CONSOLE=y
-
-#
-# Frame-buffer support
-#
-# CONFIG_FB is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-
-#
-#   Networking support is needed for USB Networking device support
-#
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-# CONFIG_KDB is not set
-# CONFIG_KDB_MODULES is not set
-# CONFIG_KALLSYMS is not set
diff -Nru a/arch/ia64/sn/configs/sn2/defconfig-sn2-dig-mp b/arch/ia64/sn/configs/sn2/defconfig-sn2-dig-mp
--- a/arch/ia64/sn/configs/sn2/defconfig-sn2-dig-mp	Mon Dec 23 21:22:00 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,449 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-# CONFIG_EXPERIMENTAL is not set
-
-#
-# Loadable module support
-#
-# CONFIG_MODULES is not set
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-CONFIG_ITANIUM=y
-# CONFIG_MCKINLEY is not set
-# CONFIG_IA64_GENERIC is not set
-CONFIG_IA64_DIG=y
-# CONFIG_IA64_HP_SIM is not set
-# CONFIG_IA64_SGI_SN1 is not set
-# CONFIG_IA64_SGI_SN2 is not set
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_BRL_EMU=y
-CONFIG_ITANIUM_BSTEP_SPECIFIC=y
-CONFIG_IA64_L1_CACHE_SHIFT=6
-# CONFIG_NUMA is not set
-# CONFIG_IA64_MCA is not set
-CONFIG_PM=y
-CONFIG_IA64_HAVE_SYNCRONIZED_ITC=y
-# CONFIG_DEVFS_FS is not set
-CONFIG_KCORE_ELF=y
-CONFIG_SMP=y
-# CONFIG_IA32_SUPPORT is not set
-# CONFIG_PERFMON is not set
-# CONFIG_IA64_PALINFO is not set
-# CONFIG_EFI_VARS is not set
-# CONFIG_NET is not set
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-# CONFIG_SYSCTL is not set
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-# CONFIG_BLK_DEV_LOOP is not set
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-# CONFIG_XSCSI is not set
-
-#
-# SCSI support
-#
-# CONFIG_SCSI is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-CONFIG_VT=y
-CONFIG_VT_CONSOLE=y
-# CONFIG_SERIAL is not set
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-# CONFIG_MOUSE is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-# CONFIG_EFI_RTC is not set
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-# CONFIG_QUOTA is not set
-# CONFIG_AUTOFS_FS is not set
-# CONFIG_AUTOFS4_FS is not set
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-# CONFIG_FAT_FS is not set
-# CONFIG_MSDOS_FS is not set
-# CONFIG_UMSDOS_FS is not set
-# CONFIG_VFAT_FS is not set
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-# CONFIG_ISO9660_FS is not set
-# CONFIG_JOLIET is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-# CONFIG_DEVFS_FS is not set
-# CONFIG_DEVFS_MOUNT is not set
-# CONFIG_DEVFS_DEBUG is not set
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-# CONFIG_XFS_SUPPORT is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_SMB_FS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-# CONFIG_NLS is not set
-
-#
-# Console drivers
-#
-CONFIG_VGA_CONSOLE=y
-
-#
-# Frame-buffer support
-#
-# CONFIG_FB is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-
-#
-#   Networking support is needed for USB Networking device support
-#
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-# CONFIG_KDB is not set
-# CONFIG_KDB_MODULES is not set
-# CONFIG_KALLSYMS is not set
diff -Nru a/arch/ia64/sn/configs/sn2/defconfig-sn2-dig-sp b/arch/ia64/sn/configs/sn2/defconfig-sn2-dig-sp
--- a/arch/ia64/sn/configs/sn2/defconfig-sn2-dig-sp	Mon Dec 23 21:22:00 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,449 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-# CONFIG_EXPERIMENTAL is not set
-
-#
-# Loadable module support
-#
-# CONFIG_MODULES is not set
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-CONFIG_ITANIUM=y
-# CONFIG_MCKINLEY is not set
-# CONFIG_IA64_GENERIC is not set
-CONFIG_IA64_DIG=y
-# CONFIG_IA64_HP_SIM is not set
-# CONFIG_IA64_SGI_SN1 is not set
-# CONFIG_IA64_SGI_SN2 is not set
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_BRL_EMU=y
-CONFIG_ITANIUM_BSTEP_SPECIFIC=y
-CONFIG_IA64_L1_CACHE_SHIFT=6
-# CONFIG_NUMA is not set
-# CONFIG_IA64_MCA is not set
-CONFIG_PM=y
-CONFIG_IA64_HAVE_SYNCRONIZED_ITC=y
-# CONFIG_DEVFS_FS is not set
-CONFIG_KCORE_ELF=y
-# CONFIG_SMP is not set
-# CONFIG_IA32_SUPPORT is not set
-# CONFIG_PERFMON is not set
-# CONFIG_IA64_PALINFO is not set
-# CONFIG_EFI_VARS is not set
-# CONFIG_NET is not set
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-# CONFIG_SYSCTL is not set
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-# CONFIG_BLK_DEV_LOOP is not set
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-# CONFIG_XSCSI is not set
-
-#
-# SCSI support
-#
-# CONFIG_SCSI is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-CONFIG_VT=y
-CONFIG_VT_CONSOLE=y
-# CONFIG_SERIAL is not set
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-# CONFIG_MOUSE is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-# CONFIG_EFI_RTC is not set
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-# CONFIG_QUOTA is not set
-# CONFIG_AUTOFS_FS is not set
-# CONFIG_AUTOFS4_FS is not set
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-# CONFIG_FAT_FS is not set
-# CONFIG_MSDOS_FS is not set
-# CONFIG_UMSDOS_FS is not set
-# CONFIG_VFAT_FS is not set
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-# CONFIG_ISO9660_FS is not set
-# CONFIG_JOLIET is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-# CONFIG_DEVFS_FS is not set
-# CONFIG_DEVFS_MOUNT is not set
-# CONFIG_DEVFS_DEBUG is not set
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-# CONFIG_XFS_SUPPORT is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_SMB_FS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-# CONFIG_NLS is not set
-
-#
-# Console drivers
-#
-CONFIG_VGA_CONSOLE=y
-
-#
-# Frame-buffer support
-#
-# CONFIG_FB is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-
-#
-#   Networking support is needed for USB Networking device support
-#
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-# CONFIG_KDB is not set
-# CONFIG_KDB_MODULES is not set
-# CONFIG_KALLSYMS is not set
diff -Nru a/arch/ia64/sn/configs/sn2/defconfig-sn2-mp b/arch/ia64/sn/configs/sn2/defconfig-sn2-mp
--- a/arch/ia64/sn/configs/sn2/defconfig-sn2-mp	Mon Dec 23 21:21:51 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,720 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-CONFIG_EXPERIMENTAL=y
-
-#
-# Loadable module support
-#
-# CONFIG_MODULES is not set
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-# CONFIG_ITANIUM is not set
-CONFIG_MCKINLEY=y
-# CONFIG_IA64_GENERIC is not set
-# CONFIG_IA64_DIG is not set
-# CONFIG_IA64_HP_SIM is not set
-# CONFIG_IA64_SGI_SN1 is not set
-CONFIG_IA64_SGI_SN2=y
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_L1_CACHE_SHIFT=7
-CONFIG_MCKINLEY_ASTEP_SPECIFIC=y
-CONFIG_MCKINLEY_A0_SPECIFIC=y
-CONFIG_IA64_SGI_SN=y
-CONFIG_IA64_SGI_SN_DEBUG=y
-CONFIG_IA64_SGI_SN_SIM=y
-CONFIG_IA64_SGI_AUTOTEST=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_SERIAL_SGI_L1_PROTOCOL=y
-CONFIG_DISCONTIGMEM=y
-CONFIG_IA64_MCA=y
-CONFIG_NUMA=y
-CONFIG_PERCPU_IRQ=y
-CONFIG_PCIBA=y
-CONFIG_KCORE_ELF=y
-CONFIG_SMP=y
-CONFIG_IA32_SUPPORT=y
-CONFIG_PERFMON=y
-CONFIG_IA64_PALINFO=y
-# CONFIG_EFI_VARS is not set
-CONFIG_NET=y
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-CONFIG_SYSCTL=y
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Networking options
-#
-CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
-CONFIG_NETLINK=y
-CONFIG_RTNETLINK=y
-CONFIG_NETLINK_DEV=y
-CONFIG_NETFILTER=y
-CONFIG_NETFILTER_DEBUG=y
-CONFIG_FILTER=y
-CONFIG_UNIX=y
-CONFIG_INET=y
-CONFIG_IP_MULTICAST=y
-# CONFIG_IP_ADVANCED_ROUTER is not set
-# CONFIG_IP_PNP is not set
-# CONFIG_NET_IPIP is not set
-# CONFIG_NET_IPGRE is not set
-# CONFIG_IP_MROUTE is not set
-# CONFIG_ARPD is not set
-# CONFIG_INET_ECN is not set
-CONFIG_SYN_COOKIES=y
-
-#
-#   IP: Netfilter Configuration
-#
-# CONFIG_IP_NF_CONNTRACK is not set
-# CONFIG_IP_NF_QUEUE is not set
-# CONFIG_IP_NF_IPTABLES is not set
-# CONFIG_IP_NF_COMPAT_IPCHAINS is not set
-# CONFIG_IP_NF_COMPAT_IPFWADM is not set
-# CONFIG_IPV6 is not set
-# CONFIG_KHTTPD is not set
-# CONFIG_ATM is not set
-
-#
-#  
-#
-# CONFIG_IPX is not set
-# CONFIG_ATALK is not set
-# CONFIG_DECNET is not set
-# CONFIG_BRIDGE is not set
-# CONFIG_X25 is not set
-# CONFIG_LAPB is not set
-# CONFIG_LLC is not set
-# CONFIG_NET_DIVERT is not set
-# CONFIG_ECONET is not set
-# CONFIG_WAN_ROUTER is not set
-# CONFIG_NET_FASTROUTE is not set
-# CONFIG_NET_HW_FLOWCONTROL is not set
-
-#
-# QoS and/or fair queueing
-#
-# CONFIG_NET_SCHED is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-# CONFIG_PNPBIOS is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-CONFIG_BLK_DEV_LOOP=y
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_LAN is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-CONFIG_XSCSI=y
-
-#
-# Alternate SCSI support
-#
-CONFIG_XSCSI_DKSC=y
-# CONFIG_XSCSI_QLFC is not set
-# CONFIG_XSCSI_QL is not set
-# CONFIG_XSCSI_SBP2 is not set
-
-#
-# SCSI support
-#
-CONFIG_SCSI=y
-
-#
-# SCSI support type (disk, tape, CD-ROM)
-#
-CONFIG_BLK_DEV_SD=y
-CONFIG_SD_EXTRA_DEVS=40
-# CONFIG_CHR_DEV_ST is not set
-# CONFIG_CHR_DEV_OSST is not set
-# CONFIG_BLK_DEV_SR is not set
-# CONFIG_CHR_DEV_SG is not set
-
-#
-# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
-#
-# CONFIG_SCSI_DEBUG_QUEUES is not set
-# CONFIG_SCSI_MULTI_LUN is not set
-# CONFIG_SCSI_CONSTANTS is not set
-# CONFIG_SCSI_LOGGING is not set
-
-#
-# SCSI low-level drivers
-#
-# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
-# CONFIG_SCSI_7000FASST is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_AHA152X is not set
-# CONFIG_SCSI_AHA1542 is not set
-# CONFIG_SCSI_AHA1740 is not set
-# CONFIG_SCSI_AIC7XXX is not set
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-# CONFIG_SCSI_DPT_I2O is not set
-# CONFIG_SCSI_ADVANSYS is not set
-# CONFIG_SCSI_IN2000 is not set
-# CONFIG_SCSI_AM53C974 is not set
-# CONFIG_SCSI_MEGARAID is not set
-# CONFIG_SCSI_BUSLOGIC is not set
-# CONFIG_SCSI_CPQFCTS is not set
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_DTC3280 is not set
-# CONFIG_SCSI_EATA is not set
-# CONFIG_SCSI_EATA_DMA is not set
-# CONFIG_SCSI_EATA_PIO is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_GDTH is not set
-# CONFIG_SCSI_GENERIC_NCR5380 is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_NCR53C406A is not set
-# CONFIG_SCSI_NCR53C7xx is not set
-# CONFIG_SCSI_NCR53C8XX is not set
-# CONFIG_SCSI_SYM53C8XX is not set
-# CONFIG_SCSI_PAS16 is not set
-# CONFIG_SCSI_PCI2000 is not set
-# CONFIG_SCSI_PCI2220I is not set
-# CONFIG_SCSI_PSI240I is not set
-# CONFIG_SCSI_QLOGIC_FAS is not set
-# CONFIG_SCSI_QLOGIC_ISP is not set
-CONFIG_SCSI_QLOGIC_FC=y
-# CONFIG_SCSI_QLOGIC_FC_FIRMWARE is not set
-# CONFIG_SCSI_QLOGIC_1280 is not set
-# CONFIG_SCSI_QLOGIC_QLA2100 is not set
-# CONFIG_SCSI_SIM710 is not set
-# CONFIG_SCSI_SYM53C416 is not set
-# CONFIG_SCSI_DC390T is not set
-# CONFIG_SCSI_T128 is not set
-# CONFIG_SCSI_U14_34F is not set
-# CONFIG_SCSI_DEBUG is not set
-
-#
-# Network device support
-#
-CONFIG_NETDEVICES=y
-
-#
-# ARCnet devices
-#
-# CONFIG_ARCNET is not set
-# CONFIG_DUMMY is not set
-# CONFIG_BONDING is not set
-# CONFIG_EQUALIZER is not set
-# CONFIG_TUN is not set
-# CONFIG_ETHERTAP is not set
-
-#
-# Ethernet (10 or 100Mbit)
-#
-CONFIG_NET_ETHERNET=y
-# CONFIG_SUNLANCE is not set
-# CONFIG_HAPPYMEAL is not set
-# CONFIG_SUNBMAC is not set
-# CONFIG_SUNQE is not set
-# CONFIG_SUNLANCE is not set
-# CONFIG_SUNGEM is not set
-# CONFIG_NET_VENDOR_3COM is not set
-# CONFIG_LANCE is not set
-# CONFIG_NET_VENDOR_SMC is not set
-# CONFIG_NET_VENDOR_RACAL is not set
-# CONFIG_HP100 is not set
-# CONFIG_NET_ISA is not set
-# CONFIG_NET_PCI is not set
-# CONFIG_NET_POCKET is not set
-
-#
-# Ethernet (1000 Mbit)
-#
-# CONFIG_ACENIC is not set
-# CONFIG_DL2K is not set
-# CONFIG_MYRI_SBUS is not set
-# CONFIG_NS83820 is not set
-# CONFIG_HAMACHI is not set
-# CONFIG_YELLOWFIN is not set
-# CONFIG_SK98LIN is not set
-# CONFIG_FDDI is not set
-# CONFIG_HIPPI is not set
-# CONFIG_PLIP is not set
-# CONFIG_PPP is not set
-# CONFIG_SLIP is not set
-
-#
-# Wireless LAN (non-hamradio)
-#
-# CONFIG_NET_RADIO is not set
-
-#
-# Token Ring devices
-#
-# CONFIG_TR is not set
-# CONFIG_NET_FC is not set
-# CONFIG_RCPCI is not set
-# CONFIG_SHAPER is not set
-
-#
-# Wan interfaces
-#
-# CONFIG_WAN is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-# CONFIG_VT is not set
-CONFIG_SERIAL=y
-# CONFIG_SERIAL_CONSOLE is not set
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-# CONFIG_MOUSE is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-CONFIG_EFI_RTC=y
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-CONFIG_QUOTA=y
-CONFIG_AUTOFS_FS=y
-CONFIG_AUTOFS4_FS=y
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-CONFIG_FAT_FS=y
-CONFIG_MSDOS_FS=y
-# CONFIG_UMSDOS_FS is not set
-CONFIG_VFAT_FS=y
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-CONFIG_ISO9660_FS=y
-# CONFIG_JOLIET is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_MOUNT=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-CONFIG_XFS_SUPPORT=y
-
-#
-# Network File Systems
-#
-# CONFIG_CODA_FS is not set
-CONFIG_NFS_FS=y
-CONFIG_NFS_V3=y
-# CONFIG_ROOT_NFS is not set
-CONFIG_NFSD=y
-CONFIG_NFSD_V3=y
-CONFIG_SUNRPC=y
-CONFIG_LOCKD=y
-CONFIG_LOCKD_V4=y
-# CONFIG_SMB_FS is not set
-# CONFIG_NCP_FS is not set
-# CONFIG_NCPFS_PACKET_SIGNING is not set
-# CONFIG_NCPFS_IOCTL_LOCKING is not set
-# CONFIG_NCPFS_STRONG is not set
-# CONFIG_NCPFS_NFS_NS is not set
-# CONFIG_NCPFS_OS2_NS is not set
-# CONFIG_NCPFS_SMALLDOS is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_NCPFS_EXTRAS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-CONFIG_NLS=y
-
-#
-# Native Language Support
-#
-CONFIG_NLS_DEFAULT="n"
-# CONFIG_NLS_CODEPAGE_437 is not set
-# CONFIG_NLS_CODEPAGE_737 is not set
-# CONFIG_NLS_CODEPAGE_775 is not set
-# CONFIG_NLS_CODEPAGE_850 is not set
-# CONFIG_NLS_CODEPAGE_852 is not set
-# CONFIG_NLS_CODEPAGE_855 is not set
-# CONFIG_NLS_CODEPAGE_857 is not set
-# CONFIG_NLS_CODEPAGE_860 is not set
-# CONFIG_NLS_CODEPAGE_861 is not set
-# CONFIG_NLS_CODEPAGE_862 is not set
-# CONFIG_NLS_CODEPAGE_863 is not set
-# CONFIG_NLS_CODEPAGE_864 is not set
-# CONFIG_NLS_CODEPAGE_865 is not set
-# CONFIG_NLS_CODEPAGE_866 is not set
-# CONFIG_NLS_CODEPAGE_869 is not set
-# CONFIG_NLS_CODEPAGE_936 is not set
-# CONFIG_NLS_CODEPAGE_950 is not set
-# CONFIG_NLS_CODEPAGE_932 is not set
-# CONFIG_NLS_CODEPAGE_949 is not set
-# CONFIG_NLS_CODEPAGE_874 is not set
-# CONFIG_NLS_ISO8859_8 is not set
-# CONFIG_NLS_CODEPAGE_1251 is not set
-# CONFIG_NLS_ISO8859_1 is not set
-# CONFIG_NLS_ISO8859_2 is not set
-# CONFIG_NLS_ISO8859_3 is not set
-# CONFIG_NLS_ISO8859_4 is not set
-# CONFIG_NLS_ISO8859_5 is not set
-# CONFIG_NLS_ISO8859_6 is not set
-# CONFIG_NLS_ISO8859_7 is not set
-# CONFIG_NLS_ISO8859_9 is not set
-# CONFIG_NLS_ISO8859_13 is not set
-# CONFIG_NLS_ISO8859_14 is not set
-# CONFIG_NLS_ISO8859_15 is not set
-# CONFIG_NLS_KOI8_R is not set
-# CONFIG_NLS_KOI8_U is not set
-# CONFIG_NLS_UTF8 is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-# CONFIG_USB_PEGASUS is not set
-# CONFIG_USB_KAWETH is not set
-# CONFIG_USB_CATC is not set
-# CONFIG_USB_CDCETHER is not set
-# CONFIG_USB_USBNET is not set
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# IEEE 1394 (FireWire) support (EXPERIMENTAL)
-#
-# CONFIG_IEEE1394 is not set
-
-#
-# Bluetooth support
-#
-# CONFIG_BT is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-# CONFIG_KDB is not set
-# CONFIG_KDB_MODULES is not set
-CONFIG_KALLSYMS=y
diff -Nru a/arch/ia64/sn/configs/sn2/defconfig-sn2-mp-modules b/arch/ia64/sn/configs/sn2/defconfig-sn2-mp-modules
--- a/arch/ia64/sn/configs/sn2/defconfig-sn2-mp-modules	Mon Dec 23 21:21:58 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,722 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-CONFIG_EXPERIMENTAL=y
-
-#
-# Loadable module support
-#
-CONFIG_MODULES=y
-# CONFIG_MODVERSIONS is not set
-CONFIG_KMOD=y
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-# CONFIG_ITANIUM is not set
-CONFIG_MCKINLEY=y
-# CONFIG_IA64_GENERIC is not set
-# CONFIG_IA64_DIG is not set
-# CONFIG_IA64_HP_SIM is not set
-# CONFIG_IA64_SGI_SN1 is not set
-CONFIG_IA64_SGI_SN2=y
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_L1_CACHE_SHIFT=7
-CONFIG_MCKINLEY_ASTEP_SPECIFIC=y
-CONFIG_MCKINLEY_A0_SPECIFIC=y
-CONFIG_IA64_SGI_SN=y
-CONFIG_IA64_SGI_SN_DEBUG=y
-CONFIG_IA64_SGI_SN_SIM=y
-CONFIG_IA64_SGI_AUTOTEST=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_DEBUG=y
-# CONFIG_SERIAL_SGI_L1_PROTOCOL is not set
-CONFIG_DISCONTIGMEM=y
-CONFIG_IA64_MCA=y
-CONFIG_NUMA=y
-CONFIG_PERCPU_IRQ=y
-CONFIG_PCIBA=y
-CONFIG_KCORE_ELF=y
-CONFIG_SMP=y
-CONFIG_IA32_SUPPORT=y
-CONFIG_PERFMON=y
-CONFIG_IA64_PALINFO=y
-# CONFIG_EFI_VARS is not set
-CONFIG_NET=y
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-CONFIG_SYSCTL=y
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Networking options
-#
-CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
-CONFIG_NETLINK=y
-CONFIG_RTNETLINK=y
-CONFIG_NETLINK_DEV=y
-CONFIG_NETFILTER=y
-CONFIG_NETFILTER_DEBUG=y
-CONFIG_FILTER=y
-CONFIG_UNIX=y
-CONFIG_INET=y
-CONFIG_IP_MULTICAST=y
-# CONFIG_IP_ADVANCED_ROUTER is not set
-# CONFIG_IP_PNP is not set
-# CONFIG_NET_IPIP is not set
-# CONFIG_NET_IPGRE is not set
-# CONFIG_IP_MROUTE is not set
-# CONFIG_ARPD is not set
-# CONFIG_INET_ECN is not set
-CONFIG_SYN_COOKIES=y
-
-#
-#   IP: Netfilter Configuration
-#
-# CONFIG_IP_NF_CONNTRACK is not set
-# CONFIG_IP_NF_QUEUE is not set
-# CONFIG_IP_NF_IPTABLES is not set
-# CONFIG_IP_NF_COMPAT_IPCHAINS is not set
-# CONFIG_IP_NF_COMPAT_IPFWADM is not set
-# CONFIG_IPV6 is not set
-# CONFIG_KHTTPD is not set
-# CONFIG_ATM is not set
-
-#
-#  
-#
-# CONFIG_IPX is not set
-# CONFIG_ATALK is not set
-# CONFIG_DECNET is not set
-# CONFIG_BRIDGE is not set
-# CONFIG_X25 is not set
-# CONFIG_LAPB is not set
-# CONFIG_LLC is not set
-# CONFIG_NET_DIVERT is not set
-# CONFIG_ECONET is not set
-# CONFIG_WAN_ROUTER is not set
-# CONFIG_NET_FASTROUTE is not set
-# CONFIG_NET_HW_FLOWCONTROL is not set
-
-#
-# QoS and/or fair queueing
-#
-# CONFIG_NET_SCHED is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-# CONFIG_PNPBIOS is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-CONFIG_BLK_DEV_LOOP=y
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_LAN is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-CONFIG_XSCSI=y
-
-#
-# Alternate SCSI support
-#
-CONFIG_XSCSI_DKSC=y
-# CONFIG_XSCSI_QLFC is not set
-# CONFIG_XSCSI_QL is not set
-# CONFIG_XSCSI_SBP2 is not set
-
-#
-# SCSI support
-#
-CONFIG_SCSI=y
-
-#
-# SCSI support type (disk, tape, CD-ROM)
-#
-CONFIG_BLK_DEV_SD=y
-CONFIG_SD_EXTRA_DEVS=40
-# CONFIG_CHR_DEV_ST is not set
-# CONFIG_CHR_DEV_OSST is not set
-# CONFIG_BLK_DEV_SR is not set
-# CONFIG_CHR_DEV_SG is not set
-
-#
-# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
-#
-# CONFIG_SCSI_DEBUG_QUEUES is not set
-# CONFIG_SCSI_MULTI_LUN is not set
-# CONFIG_SCSI_CONSTANTS is not set
-# CONFIG_SCSI_LOGGING is not set
-
-#
-# SCSI low-level drivers
-#
-# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
-# CONFIG_SCSI_7000FASST is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_AHA152X is not set
-# CONFIG_SCSI_AHA1542 is not set
-# CONFIG_SCSI_AHA1740 is not set
-# CONFIG_SCSI_AIC7XXX is not set
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-# CONFIG_SCSI_DPT_I2O is not set
-# CONFIG_SCSI_ADVANSYS is not set
-# CONFIG_SCSI_IN2000 is not set
-# CONFIG_SCSI_AM53C974 is not set
-# CONFIG_SCSI_MEGARAID is not set
-# CONFIG_SCSI_BUSLOGIC is not set
-# CONFIG_SCSI_CPQFCTS is not set
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_DTC3280 is not set
-# CONFIG_SCSI_EATA is not set
-# CONFIG_SCSI_EATA_DMA is not set
-# CONFIG_SCSI_EATA_PIO is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_GDTH is not set
-# CONFIG_SCSI_GENERIC_NCR5380 is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_NCR53C406A is not set
-# CONFIG_SCSI_NCR53C7xx is not set
-# CONFIG_SCSI_NCR53C8XX is not set
-# CONFIG_SCSI_SYM53C8XX is not set
-# CONFIG_SCSI_PAS16 is not set
-# CONFIG_SCSI_PCI2000 is not set
-# CONFIG_SCSI_PCI2220I is not set
-# CONFIG_SCSI_PSI240I is not set
-# CONFIG_SCSI_QLOGIC_FAS is not set
-# CONFIG_SCSI_QLOGIC_ISP is not set
-CONFIG_SCSI_QLOGIC_FC=y
-# CONFIG_SCSI_QLOGIC_FC_FIRMWARE is not set
-# CONFIG_SCSI_QLOGIC_1280 is not set
-# CONFIG_SCSI_QLOGIC_QLA2100 is not set
-# CONFIG_SCSI_SIM710 is not set
-# CONFIG_SCSI_SYM53C416 is not set
-# CONFIG_SCSI_DC390T is not set
-# CONFIG_SCSI_T128 is not set
-# CONFIG_SCSI_U14_34F is not set
-# CONFIG_SCSI_DEBUG is not set
-
-#
-# Network device support
-#
-CONFIG_NETDEVICES=y
-
-#
-# ARCnet devices
-#
-# CONFIG_ARCNET is not set
-# CONFIG_DUMMY is not set
-# CONFIG_BONDING is not set
-# CONFIG_EQUALIZER is not set
-# CONFIG_TUN is not set
-# CONFIG_ETHERTAP is not set
-
-#
-# Ethernet (10 or 100Mbit)
-#
-CONFIG_NET_ETHERNET=y
-# CONFIG_SUNLANCE is not set
-# CONFIG_HAPPYMEAL is not set
-# CONFIG_SUNBMAC is not set
-# CONFIG_SUNQE is not set
-# CONFIG_SUNLANCE is not set
-# CONFIG_SUNGEM is not set
-# CONFIG_NET_VENDOR_3COM is not set
-# CONFIG_LANCE is not set
-# CONFIG_NET_VENDOR_SMC is not set
-# CONFIG_NET_VENDOR_RACAL is not set
-# CONFIG_HP100 is not set
-# CONFIG_NET_ISA is not set
-# CONFIG_NET_PCI is not set
-# CONFIG_NET_POCKET is not set
-
-#
-# Ethernet (1000 Mbit)
-#
-# CONFIG_ACENIC is not set
-# CONFIG_DL2K is not set
-# CONFIG_MYRI_SBUS is not set
-# CONFIG_NS83820 is not set
-# CONFIG_HAMACHI is not set
-# CONFIG_YELLOWFIN is not set
-# CONFIG_SK98LIN is not set
-# CONFIG_FDDI is not set
-# CONFIG_HIPPI is not set
-# CONFIG_PLIP is not set
-# CONFIG_PPP is not set
-# CONFIG_SLIP is not set
-
-#
-# Wireless LAN (non-hamradio)
-#
-# CONFIG_NET_RADIO is not set
-
-#
-# Token Ring devices
-#
-# CONFIG_TR is not set
-# CONFIG_NET_FC is not set
-# CONFIG_RCPCI is not set
-# CONFIG_SHAPER is not set
-
-#
-# Wan interfaces
-#
-# CONFIG_WAN is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-# CONFIG_VT is not set
-CONFIG_SERIAL=y
-# CONFIG_SERIAL_CONSOLE is not set
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-# CONFIG_MOUSE is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-CONFIG_EFI_RTC=y
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-CONFIG_QUOTA=y
-CONFIG_AUTOFS_FS=y
-CONFIG_AUTOFS4_FS=y
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-CONFIG_FAT_FS=y
-CONFIG_MSDOS_FS=y
-# CONFIG_UMSDOS_FS is not set
-CONFIG_VFAT_FS=y
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-CONFIG_ISO9660_FS=y
-# CONFIG_JOLIET is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_MOUNT=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-CONFIG_XFS_SUPPORT=y
-
-#
-# Network File Systems
-#
-# CONFIG_CODA_FS is not set
-CONFIG_NFS_FS=y
-CONFIG_NFS_V3=y
-# CONFIG_ROOT_NFS is not set
-CONFIG_NFSD=y
-CONFIG_NFSD_V3=y
-CONFIG_SUNRPC=y
-CONFIG_LOCKD=y
-CONFIG_LOCKD_V4=y
-# CONFIG_SMB_FS is not set
-# CONFIG_NCP_FS is not set
-# CONFIG_NCPFS_PACKET_SIGNING is not set
-# CONFIG_NCPFS_IOCTL_LOCKING is not set
-# CONFIG_NCPFS_STRONG is not set
-# CONFIG_NCPFS_NFS_NS is not set
-# CONFIG_NCPFS_OS2_NS is not set
-# CONFIG_NCPFS_SMALLDOS is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_NCPFS_EXTRAS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-CONFIG_NLS=y
-
-#
-# Native Language Support
-#
-CONFIG_NLS_DEFAULT="n"
-# CONFIG_NLS_CODEPAGE_437 is not set
-# CONFIG_NLS_CODEPAGE_737 is not set
-# CONFIG_NLS_CODEPAGE_775 is not set
-# CONFIG_NLS_CODEPAGE_850 is not set
-# CONFIG_NLS_CODEPAGE_852 is not set
-# CONFIG_NLS_CODEPAGE_855 is not set
-# CONFIG_NLS_CODEPAGE_857 is not set
-# CONFIG_NLS_CODEPAGE_860 is not set
-# CONFIG_NLS_CODEPAGE_861 is not set
-# CONFIG_NLS_CODEPAGE_862 is not set
-# CONFIG_NLS_CODEPAGE_863 is not set
-# CONFIG_NLS_CODEPAGE_864 is not set
-# CONFIG_NLS_CODEPAGE_865 is not set
-# CONFIG_NLS_CODEPAGE_866 is not set
-# CONFIG_NLS_CODEPAGE_869 is not set
-# CONFIG_NLS_CODEPAGE_936 is not set
-# CONFIG_NLS_CODEPAGE_950 is not set
-# CONFIG_NLS_CODEPAGE_932 is not set
-# CONFIG_NLS_CODEPAGE_949 is not set
-# CONFIG_NLS_CODEPAGE_874 is not set
-# CONFIG_NLS_ISO8859_8 is not set
-# CONFIG_NLS_CODEPAGE_1251 is not set
-# CONFIG_NLS_ISO8859_1 is not set
-# CONFIG_NLS_ISO8859_2 is not set
-# CONFIG_NLS_ISO8859_3 is not set
-# CONFIG_NLS_ISO8859_4 is not set
-# CONFIG_NLS_ISO8859_5 is not set
-# CONFIG_NLS_ISO8859_6 is not set
-# CONFIG_NLS_ISO8859_7 is not set
-# CONFIG_NLS_ISO8859_9 is not set
-# CONFIG_NLS_ISO8859_13 is not set
-# CONFIG_NLS_ISO8859_14 is not set
-# CONFIG_NLS_ISO8859_15 is not set
-# CONFIG_NLS_KOI8_R is not set
-# CONFIG_NLS_KOI8_U is not set
-# CONFIG_NLS_UTF8 is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-# CONFIG_USB_PEGASUS is not set
-# CONFIG_USB_KAWETH is not set
-# CONFIG_USB_CATC is not set
-# CONFIG_USB_CDCETHER is not set
-# CONFIG_USB_USBNET is not set
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# IEEE 1394 (FireWire) support (EXPERIMENTAL)
-#
-# CONFIG_IEEE1394 is not set
-
-#
-# Bluetooth support
-#
-# CONFIG_BT is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-# CONFIG_KDB is not set
-# CONFIG_KDB_MODULES is not set
-CONFIG_KALLSYMS=y
diff -Nru a/arch/ia64/sn/configs/sn2/defconfig-sn2-prom-medusa b/arch/ia64/sn/configs/sn2/defconfig-sn2-prom-medusa
--- a/arch/ia64/sn/configs/sn2/defconfig-sn2-prom-medusa	Mon Dec 23 21:21:53 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,527 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-CONFIG_EXPERIMENTAL=y
-
-#
-# Loadable module support
-#
-# CONFIG_MODULES is not set
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-# CONFIG_ITANIUM is not set
-CONFIG_MCKINLEY=y
-# CONFIG_IA64_GENERIC is not set
-# CONFIG_IA64_DIG is not set
-# CONFIG_IA64_HP_SIM is not set
-# CONFIG_IA64_SGI_SN1 is not set
-CONFIG_IA64_SGI_SN2=y
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_L1_CACHE_SHIFT=7
-CONFIG_MCKINLEY_ASTEP_SPECIFIC=y
-CONFIG_MCKINLEY_A0_SPECIFIC=y
-CONFIG_IA64_SGI_SN=y
-CONFIG_IA64_SGI_SN_DEBUG=y
-CONFIG_IA64_SGI_SN_SIM=y
-CONFIG_IA64_SGI_AUTOTEST=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_SERIAL_SGI_L1_PROTOCOL=y
-CONFIG_DISCONTIGMEM=y
-CONFIG_IA64_MCA=y
-CONFIG_NUMA=y
-CONFIG_PERCPU_IRQ=y
-CONFIG_PCIBA=y
-CONFIG_KCORE_ELF=y
-CONFIG_SMP=y
-# CONFIG_IA32_SUPPORT is not set
-CONFIG_PERFMON=y
-CONFIG_IA64_PALINFO=y
-# CONFIG_EFI_VARS is not set
-# CONFIG_NET is not set
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-CONFIG_SYSCTL=y
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-# CONFIG_PNPBIOS is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-# CONFIG_BLK_DEV_LOOP is not set
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-CONFIG_XSCSI=y
-
-#
-# Alternate SCSI support
-#
-CONFIG_XSCSI_DKSC=y
-# CONFIG_XSCSI_QLFC is not set
-# CONFIG_XSCSI_QL is not set
-# CONFIG_XSCSI_SBP2 is not set
-
-#
-# SCSI support
-#
-CONFIG_SCSI=y
-
-#
-# SCSI support type (disk, tape, CD-ROM)
-#
-CONFIG_BLK_DEV_SD=y
-CONFIG_SD_EXTRA_DEVS=40
-# CONFIG_CHR_DEV_ST is not set
-# CONFIG_CHR_DEV_OSST is not set
-# CONFIG_BLK_DEV_SR is not set
-# CONFIG_CHR_DEV_SG is not set
-
-#
-# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
-#
-# CONFIG_SCSI_DEBUG_QUEUES is not set
-# CONFIG_SCSI_MULTI_LUN is not set
-# CONFIG_SCSI_CONSTANTS is not set
-# CONFIG_SCSI_LOGGING is not set
-
-#
-# SCSI low-level drivers
-#
-# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
-# CONFIG_SCSI_7000FASST is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_AHA152X is not set
-# CONFIG_SCSI_AHA1542 is not set
-# CONFIG_SCSI_AHA1740 is not set
-# CONFIG_SCSI_AIC7XXX is not set
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-# CONFIG_SCSI_DPT_I2O is not set
-# CONFIG_SCSI_ADVANSYS is not set
-# CONFIG_SCSI_IN2000 is not set
-# CONFIG_SCSI_AM53C974 is not set
-# CONFIG_SCSI_MEGARAID is not set
-# CONFIG_SCSI_BUSLOGIC is not set
-# CONFIG_SCSI_CPQFCTS is not set
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_DTC3280 is not set
-# CONFIG_SCSI_EATA is not set
-# CONFIG_SCSI_EATA_DMA is not set
-# CONFIG_SCSI_EATA_PIO is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_GDTH is not set
-# CONFIG_SCSI_GENERIC_NCR5380 is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_NCR53C406A is not set
-# CONFIG_SCSI_NCR53C7xx is not set
-# CONFIG_SCSI_NCR53C8XX is not set
-# CONFIG_SCSI_SYM53C8XX is not set
-# CONFIG_SCSI_PAS16 is not set
-# CONFIG_SCSI_PCI2000 is not set
-# CONFIG_SCSI_PCI2220I is not set
-# CONFIG_SCSI_PSI240I is not set
-# CONFIG_SCSI_QLOGIC_FAS is not set
-# CONFIG_SCSI_QLOGIC_ISP is not set
-CONFIG_SCSI_QLOGIC_FC=y
-# CONFIG_SCSI_QLOGIC_FC_FIRMWARE is not set
-# CONFIG_SCSI_QLOGIC_1280 is not set
-# CONFIG_SCSI_QLOGIC_QLA2100 is not set
-# CONFIG_SCSI_SIM710 is not set
-# CONFIG_SCSI_SYM53C416 is not set
-# CONFIG_SCSI_DC390T is not set
-# CONFIG_SCSI_T128 is not set
-# CONFIG_SCSI_U14_34F is not set
-# CONFIG_SCSI_DEBUG is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-# CONFIG_VT is not set
-CONFIG_SERIAL=y
-# CONFIG_SERIAL_CONSOLE is not set
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-# CONFIG_MOUSE is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-# CONFIG_EFI_RTC is not set
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-# CONFIG_QUOTA is not set
-# CONFIG_AUTOFS_FS is not set
-# CONFIG_AUTOFS4_FS is not set
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-# CONFIG_FAT_FS is not set
-# CONFIG_MSDOS_FS is not set
-# CONFIG_UMSDOS_FS is not set
-# CONFIG_VFAT_FS is not set
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-# CONFIG_ISO9660_FS is not set
-# CONFIG_JOLIET is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_MOUNT=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-CONFIG_XFS_SUPPORT=y
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_SMB_FS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-# CONFIG_NLS is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-
-#
-#   Networking support is needed for USB Networking device support
-#
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# IEEE 1394 (FireWire) support (EXPERIMENTAL)
-#
-# CONFIG_IEEE1394 is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-# CONFIG_KDB is not set
-# CONFIG_KDB_MODULES is not set
-# CONFIG_KALLSYMS is not set
diff -Nru a/arch/ia64/sn/configs/sn2/defconfig-sn2-sp b/arch/ia64/sn/configs/sn2/defconfig-sn2-sp
--- a/arch/ia64/sn/configs/sn2/defconfig-sn2-sp	Mon Dec 23 21:21:51 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,720 +0,0 @@
-#
-# Automatically generated make config: don't edit
-#
-
-#
-# Code maturity level options
-#
-CONFIG_EXPERIMENTAL=y
-
-#
-# Loadable module support
-#
-# CONFIG_MODULES is not set
-
-#
-# General setup
-#
-CONFIG_IA64=y
-# CONFIG_ISA is not set
-# CONFIG_EISA is not set
-# CONFIG_MCA is not set
-# CONFIG_SBUS is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_ACPI=y
-CONFIG_ACPI_EFI=y
-CONFIG_ACPI_INTERPRETER=y
-CONFIG_ACPI_KERNEL_CONFIG=y
-# CONFIG_ITANIUM is not set
-CONFIG_MCKINLEY=y
-# CONFIG_IA64_GENERIC is not set
-# CONFIG_IA64_DIG is not set
-# CONFIG_IA64_HP_SIM is not set
-# CONFIG_IA64_SGI_SN1 is not set
-CONFIG_IA64_SGI_SN2=y
-# CONFIG_IA64_PAGE_SIZE_4KB is not set
-# CONFIG_IA64_PAGE_SIZE_8KB is not set
-CONFIG_IA64_PAGE_SIZE_16KB=y
-# CONFIG_IA64_PAGE_SIZE_64KB is not set
-CONFIG_IA64_L1_CACHE_SHIFT=7
-CONFIG_MCKINLEY_ASTEP_SPECIFIC=y
-CONFIG_MCKINLEY_A0_SPECIFIC=y
-CONFIG_IA64_SGI_SN=y
-CONFIG_IA64_SGI_SN_DEBUG=y
-CONFIG_IA64_SGI_SN_SIM=y
-CONFIG_IA64_SGI_AUTOTEST=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_SERIAL_SGI_L1_PROTOCOL=y
-CONFIG_DISCONTIGMEM=y
-CONFIG_IA64_MCA=y
-CONFIG_NUMA=y
-CONFIG_PERCPU_IRQ=y
-CONFIG_PCIBA=y
-CONFIG_KCORE_ELF=y
-# CONFIG_SMP is not set
-CONFIG_IA32_SUPPORT=y
-CONFIG_PERFMON=y
-CONFIG_IA64_PALINFO=y
-# CONFIG_EFI_VARS is not set
-CONFIG_NET=y
-CONFIG_SYSVIPC=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-CONFIG_SYSCTL=y
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ACPI_DEBUG is not set
-# CONFIG_ACPI_BUSMGR is not set
-# CONFIG_ACPI_SYS is not set
-# CONFIG_ACPI_CPU is not set
-# CONFIG_ACPI_BUTTON is not set
-# CONFIG_ACPI_AC is not set
-# CONFIG_ACPI_EC is not set
-# CONFIG_ACPI_CMBATT is not set
-# CONFIG_ACPI_THERMAL is not set
-CONFIG_PCI=y
-# CONFIG_PCI_NAMES is not set
-# CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Networking options
-#
-CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
-CONFIG_NETLINK=y
-CONFIG_RTNETLINK=y
-CONFIG_NETLINK_DEV=y
-CONFIG_NETFILTER=y
-CONFIG_NETFILTER_DEBUG=y
-CONFIG_FILTER=y
-CONFIG_UNIX=y
-CONFIG_INET=y
-CONFIG_IP_MULTICAST=y
-# CONFIG_IP_ADVANCED_ROUTER is not set
-# CONFIG_IP_PNP is not set
-# CONFIG_NET_IPIP is not set
-# CONFIG_NET_IPGRE is not set
-# CONFIG_IP_MROUTE is not set
-# CONFIG_ARPD is not set
-# CONFIG_INET_ECN is not set
-CONFIG_SYN_COOKIES=y
-
-#
-#   IP: Netfilter Configuration
-#
-# CONFIG_IP_NF_CONNTRACK is not set
-# CONFIG_IP_NF_QUEUE is not set
-# CONFIG_IP_NF_IPTABLES is not set
-# CONFIG_IP_NF_COMPAT_IPCHAINS is not set
-# CONFIG_IP_NF_COMPAT_IPFWADM is not set
-# CONFIG_IPV6 is not set
-# CONFIG_KHTTPD is not set
-# CONFIG_ATM is not set
-
-#
-#  
-#
-# CONFIG_IPX is not set
-# CONFIG_ATALK is not set
-# CONFIG_DECNET is not set
-# CONFIG_BRIDGE is not set
-# CONFIG_X25 is not set
-# CONFIG_LAPB is not set
-# CONFIG_LLC is not set
-# CONFIG_NET_DIVERT is not set
-# CONFIG_ECONET is not set
-# CONFIG_WAN_ROUTER is not set
-# CONFIG_NET_FASTROUTE is not set
-# CONFIG_NET_HW_FLOWCONTROL is not set
-
-#
-# QoS and/or fair queueing
-#
-# CONFIG_NET_SCHED is not set
-
-#
-# Memory Technology Devices (MTD)
-#
-# CONFIG_MTD is not set
-
-#
-# Plug and Play configuration
-#
-# CONFIG_PNP is not set
-# CONFIG_ISAPNP is not set
-# CONFIG_PNPBIOS is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_FD is not set
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-CONFIG_BLK_DEV_LOOP=y
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_BLK_DEV_INITRD is not set
-
-#
-# I2O device support
-#
-# CONFIG_I2O is not set
-# CONFIG_I2O_PCI is not set
-# CONFIG_I2O_BLOCK is not set
-# CONFIG_I2O_LAN is not set
-# CONFIG_I2O_SCSI is not set
-# CONFIG_I2O_PROC is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
-
-#
-# ATA/IDE/MFM/RLL support
-#
-CONFIG_IDE=y
-
-#
-# IDE, ATA and ATAPI Block devices
-#
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_HD_IDE is not set
-# CONFIG_BLK_DEV_HD is not set
-CONFIG_BLK_DEV_IDEDISK=y
-# CONFIG_IDEDISK_MULTI_MODE is not set
-# CONFIG_BLK_DEV_IDECS is not set
-# CONFIG_BLK_DEV_IDECD is not set
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-# CONFIG_IDE_CHIPSETS is not set
-# CONFIG_IDEDMA_AUTO is not set
-# CONFIG_BLK_DEV_IDE_MODES is not set
-# CONFIG_BLK_DEV_ATARAID is not set
-# CONFIG_BLK_DEV_ATARAID_PDC is not set
-# CONFIG_BLK_DEV_ATARAID_HPT is not set
-
-#
-# Alternate 1394 support
-#
-# CONFIG_X1394 is not set
-
-#
-# Alternate SCSI support
-#
-CONFIG_XSCSI=y
-
-#
-# Alternate SCSI support
-#
-CONFIG_XSCSI_DKSC=y
-# CONFIG_XSCSI_QLFC is not set
-# CONFIG_XSCSI_QL is not set
-# CONFIG_XSCSI_SBP2 is not set
-
-#
-# SCSI support
-#
-CONFIG_SCSI=y
-
-#
-# SCSI support type (disk, tape, CD-ROM)
-#
-CONFIG_BLK_DEV_SD=y
-CONFIG_SD_EXTRA_DEVS=40
-# CONFIG_CHR_DEV_ST is not set
-# CONFIG_CHR_DEV_OSST is not set
-# CONFIG_BLK_DEV_SR is not set
-# CONFIG_CHR_DEV_SG is not set
-
-#
-# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
-#
-# CONFIG_SCSI_DEBUG_QUEUES is not set
-# CONFIG_SCSI_MULTI_LUN is not set
-# CONFIG_SCSI_CONSTANTS is not set
-# CONFIG_SCSI_LOGGING is not set
-
-#
-# SCSI low-level drivers
-#
-# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
-# CONFIG_SCSI_7000FASST is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_AHA152X is not set
-# CONFIG_SCSI_AHA1542 is not set
-# CONFIG_SCSI_AHA1740 is not set
-# CONFIG_SCSI_AIC7XXX is not set
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-# CONFIG_SCSI_DPT_I2O is not set
-# CONFIG_SCSI_ADVANSYS is not set
-# CONFIG_SCSI_IN2000 is not set
-# CONFIG_SCSI_AM53C974 is not set
-# CONFIG_SCSI_MEGARAID is not set
-# CONFIG_SCSI_BUSLOGIC is not set
-# CONFIG_SCSI_CPQFCTS is not set
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_DTC3280 is not set
-# CONFIG_SCSI_EATA is not set
-# CONFIG_SCSI_EATA_DMA is not set
-# CONFIG_SCSI_EATA_PIO is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_GDTH is not set
-# CONFIG_SCSI_GENERIC_NCR5380 is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_NCR53C406A is not set
-# CONFIG_SCSI_NCR53C7xx is not set
-# CONFIG_SCSI_NCR53C8XX is not set
-# CONFIG_SCSI_SYM53C8XX is not set
-# CONFIG_SCSI_PAS16 is not set
-# CONFIG_SCSI_PCI2000 is not set
-# CONFIG_SCSI_PCI2220I is not set
-# CONFIG_SCSI_PSI240I is not set
-# CONFIG_SCSI_QLOGIC_FAS is not set
-# CONFIG_SCSI_QLOGIC_ISP is not set
-CONFIG_SCSI_QLOGIC_FC=y
-# CONFIG_SCSI_QLOGIC_FC_FIRMWARE is not set
-# CONFIG_SCSI_QLOGIC_1280 is not set
-# CONFIG_SCSI_QLOGIC_QLA2100 is not set
-# CONFIG_SCSI_SIM710 is not set
-# CONFIG_SCSI_SYM53C416 is not set
-# CONFIG_SCSI_DC390T is not set
-# CONFIG_SCSI_T128 is not set
-# CONFIG_SCSI_U14_34F is not set
-# CONFIG_SCSI_DEBUG is not set
-
-#
-# Network device support
-#
-CONFIG_NETDEVICES=y
-
-#
-# ARCnet devices
-#
-# CONFIG_ARCNET is not set
-# CONFIG_DUMMY is not set
-# CONFIG_BONDING is not set
-# CONFIG_EQUALIZER is not set
-# CONFIG_TUN is not set
-# CONFIG_ETHERTAP is not set
-
-#
-# Ethernet (10 or 100Mbit)
-#
-CONFIG_NET_ETHERNET=y
-# CONFIG_SUNLANCE is not set
-# CONFIG_HAPPYMEAL is not set
-# CONFIG_SUNBMAC is not set
-# CONFIG_SUNQE is not set
-# CONFIG_SUNLANCE is not set
-# CONFIG_SUNGEM is not set
-# CONFIG_NET_VENDOR_3COM is not set
-# CONFIG_LANCE is not set
-# CONFIG_NET_VENDOR_SMC is not set
-# CONFIG_NET_VENDOR_RACAL is not set
-# CONFIG_HP100 is not set
-# CONFIG_NET_ISA is not set
-# CONFIG_NET_PCI is not set
-# CONFIG_NET_POCKET is not set
-
-#
-# Ethernet (1000 Mbit)
-#
-# CONFIG_ACENIC is not set
-# CONFIG_DL2K is not set
-# CONFIG_MYRI_SBUS is not set
-# CONFIG_NS83820 is not set
-# CONFIG_HAMACHI is not set
-# CONFIG_YELLOWFIN is not set
-# CONFIG_SK98LIN is not set
-# CONFIG_FDDI is not set
-# CONFIG_HIPPI is not set
-# CONFIG_PLIP is not set
-# CONFIG_PPP is not set
-# CONFIG_SLIP is not set
-
-#
-# Wireless LAN (non-hamradio)
-#
-# CONFIG_NET_RADIO is not set
-
-#
-# Token Ring devices
-#
-# CONFIG_TR is not set
-# CONFIG_NET_FC is not set
-# CONFIG_RCPCI is not set
-# CONFIG_SHAPER is not set
-
-#
-# Wan interfaces
-#
-# CONFIG_WAN is not set
-
-#
-# Amateur Radio support
-#
-# CONFIG_HAMRADIO is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# CD-ROM drivers (not for SCSI or IDE/ATAPI drives)
-#
-# CONFIG_CD_NO_IDESCSI is not set
-
-#
-# Input core support
-#
-# CONFIG_INPUT is not set
-# CONFIG_INPUT_KEYBDEV is not set
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
-
-#
-# Character devices
-#
-# CONFIG_VT is not set
-CONFIG_SERIAL=y
-# CONFIG_SERIAL_CONSOLE is not set
-# CONFIG_SERIAL_EXTENDED is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_UNIX98_PTY_COUNT=256
-
-#
-# I2C support
-#
-# CONFIG_I2C is not set
-
-#
-# Mice
-#
-# CONFIG_BUSMOUSE is not set
-# CONFIG_MOUSE is not set
-
-#
-# Joysticks
-#
-# CONFIG_INPUT_GAMEPORT is not set
-
-#
-# Input core support is needed for gameports
-#
-
-#
-# Input core support is needed for joysticks
-#
-# CONFIG_QIC02_TAPE is not set
-
-#
-# Watchdog Cards
-#
-# CONFIG_WATCHDOG is not set
-# CONFIG_INTEL_RNG is not set
-# CONFIG_NVRAM is not set
-# CONFIG_RTC is not set
-CONFIG_EFI_RTC=y
-# CONFIG_DTLK is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-
-#
-# Ftape, the floppy tape device driver
-#
-# CONFIG_FTAPE is not set
-# CONFIG_AGP is not set
-# CONFIG_DRM is not set
-# CONFIG_MWAVE is not set
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-
-#
-# File systems
-#
-CONFIG_QUOTA=y
-CONFIG_AUTOFS_FS=y
-CONFIG_AUTOFS4_FS=y
-# CONFIG_REISERFS_FS is not set
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_BFS_FS is not set
-CONFIG_FAT_FS=y
-CONFIG_MSDOS_FS=y
-# CONFIG_UMSDOS_FS is not set
-CONFIG_VFAT_FS=y
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-CONFIG_TMPFS=y
-# CONFIG_RAMFS is not set
-CONFIG_ISO9660_FS=y
-# CONFIG_JOLIET is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
-# CONFIG_HPFS_FS is not set
-CONFIG_PROC_FS=y
-CONFIG_DEVFS_FS=y
-CONFIG_DEVFS_MOUNT=y
-CONFIG_DEVFS_DEBUG=y
-CONFIG_DEVPTS_FS=y
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_EXT2_FS=y
-# CONFIG_SYSV_FS is not set
-# CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
-# CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-CONFIG_XFS_SUPPORT=y
-
-#
-# Network File Systems
-#
-# CONFIG_CODA_FS is not set
-CONFIG_NFS_FS=y
-CONFIG_NFS_V3=y
-# CONFIG_ROOT_NFS is not set
-CONFIG_NFSD=y
-CONFIG_NFSD_V3=y
-CONFIG_SUNRPC=y
-CONFIG_LOCKD=y
-CONFIG_LOCKD_V4=y
-# CONFIG_SMB_FS is not set
-# CONFIG_NCP_FS is not set
-# CONFIG_NCPFS_PACKET_SIGNING is not set
-# CONFIG_NCPFS_IOCTL_LOCKING is not set
-# CONFIG_NCPFS_STRONG is not set
-# CONFIG_NCPFS_NFS_NS is not set
-# CONFIG_NCPFS_OS2_NS is not set
-# CONFIG_NCPFS_SMALLDOS is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_NCPFS_EXTRAS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-CONFIG_NLS=y
-
-#
-# Native Language Support
-#
-CONFIG_NLS_DEFAULT="n"
-# CONFIG_NLS_CODEPAGE_437 is not set
-# CONFIG_NLS_CODEPAGE_737 is not set
-# CONFIG_NLS_CODEPAGE_775 is not set
-# CONFIG_NLS_CODEPAGE_850 is not set
-# CONFIG_NLS_CODEPAGE_852 is not set
-# CONFIG_NLS_CODEPAGE_855 is not set
-# CONFIG_NLS_CODEPAGE_857 is not set
-# CONFIG_NLS_CODEPAGE_860 is not set
-# CONFIG_NLS_CODEPAGE_861 is not set
-# CONFIG_NLS_CODEPAGE_862 is not set
-# CONFIG_NLS_CODEPAGE_863 is not set
-# CONFIG_NLS_CODEPAGE_864 is not set
-# CONFIG_NLS_CODEPAGE_865 is not set
-# CONFIG_NLS_CODEPAGE_866 is not set
-# CONFIG_NLS_CODEPAGE_869 is not set
-# CONFIG_NLS_CODEPAGE_936 is not set
-# CONFIG_NLS_CODEPAGE_950 is not set
-# CONFIG_NLS_CODEPAGE_932 is not set
-# CONFIG_NLS_CODEPAGE_949 is not set
-# CONFIG_NLS_CODEPAGE_874 is not set
-# CONFIG_NLS_ISO8859_8 is not set
-# CONFIG_NLS_CODEPAGE_1251 is not set
-# CONFIG_NLS_ISO8859_1 is not set
-# CONFIG_NLS_ISO8859_2 is not set
-# CONFIG_NLS_ISO8859_3 is not set
-# CONFIG_NLS_ISO8859_4 is not set
-# CONFIG_NLS_ISO8859_5 is not set
-# CONFIG_NLS_ISO8859_6 is not set
-# CONFIG_NLS_ISO8859_7 is not set
-# CONFIG_NLS_ISO8859_9 is not set
-# CONFIG_NLS_ISO8859_13 is not set
-# CONFIG_NLS_ISO8859_14 is not set
-# CONFIG_NLS_ISO8859_15 is not set
-# CONFIG_NLS_KOI8_R is not set
-# CONFIG_NLS_KOI8_U is not set
-# CONFIG_NLS_UTF8 is not set
-
-#
-# Sound
-#
-# CONFIG_SOUND is not set
-
-#
-# USB support
-#
-# CONFIG_USB is not set
-
-#
-# USB Controllers
-#
-# CONFIG_USB_UHCI is not set
-# CONFIG_USB_UHCI_ALT is not set
-# CONFIG_USB_OHCI is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_AUDIO is not set
-# CONFIG_USB_BLUETOOTH is not set
-# CONFIG_USB_STORAGE is not set
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_ISD200 is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_HP8200e is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# USB Human Interface Devices (HID)
-#
-
-#
-#   Input core support is needed for USB HID
-#
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_DC2XX is not set
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_SCANNER is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_HPUSBSCSI is not set
-
-#
-# USB Multimedia devices
-#
-
-#
-#   Video4Linux support is needed for USB Multimedia device support
-#
-
-#
-# USB Network adaptors
-#
-# CONFIG_USB_PEGASUS is not set
-# CONFIG_USB_KAWETH is not set
-# CONFIG_USB_CATC is not set
-# CONFIG_USB_CDCETHER is not set
-# CONFIG_USB_USBNET is not set
-
-#
-# USB port drivers
-#
-# CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-# CONFIG_USB_SERIAL_GENERIC is not set
-# CONFIG_USB_SERIAL_BELKIN is not set
-# CONFIG_USB_SERIAL_WHITEHEAT is not set
-# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
-# CONFIG_USB_SERIAL_EMPEG is not set
-# CONFIG_USB_SERIAL_FTDI_SIO is not set
-# CONFIG_USB_SERIAL_VISOR is not set
-# CONFIG_USB_SERIAL_IR is not set
-# CONFIG_USB_SERIAL_EDGEPORT is not set
-# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
-# CONFIG_USB_SERIAL_KEYSPAN is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XA is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA28XB is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19 is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA18X is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA19W is not set
-# CONFIG_USB_SERIAL_KEYSPAN_USA49W is not set
-# CONFIG_USB_SERIAL_MCT_U232 is not set
-# CONFIG_USB_SERIAL_PL2303 is not set
-# CONFIG_USB_SERIAL_CYBERJACK is not set
-# CONFIG_USB_SERIAL_XIRCOM is not set
-# CONFIG_USB_SERIAL_OMNINET is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_RIO500 is not set
-
-#
-# IEEE 1394 (FireWire) support (EXPERIMENTAL)
-#
-# CONFIG_IEEE1394 is not set
-
-#
-# Bluetooth support
-#
-# CONFIG_BT is not set
-
-#
-# Kernel hacking
-#
-CONFIG_DEBUG_KERNEL=y
-CONFIG_IA64_PRINT_HAZARDS=y
-# CONFIG_DISABLE_VHPT is not set
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_IA64_EARLY_PRINTK=y
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_IA64_DEBUG_CMPXCHG is not set
-# CONFIG_IA64_DEBUG_IRQ is not set
-# CONFIG_KDB is not set
-# CONFIG_KDB_MODULES is not set
-CONFIG_KALLSYMS=y
diff -Nru a/arch/ia64/sn/fakeprom/Makefile b/arch/ia64/sn/fakeprom/Makefile
--- a/arch/ia64/sn/fakeprom/Makefile	Mon Dec 23 21:22:00 2002
+++ b/arch/ia64/sn/fakeprom/Makefile	Mon Dec 23 21:22:00 2002
@@ -6,15 +6,15 @@
 #  Copyright (c) 2000-2001 Silicon Graphics, Inc.  All rights reserved.
 #
 
-TOPDIR=../../../..
-
-LIB     = ../../lib/lib.a
-
-OBJ=fpromasm.o main.o  fw-emu.o fpmem.o klgraph_init.o
-obj-y=fprom
+obj-y=fpromasm.o main.o fw-emu.o fpmem.o klgraph_init.o
 
 fprom: $(OBJ)
 	$(LD) -static -Tfprom.lds -o fprom $(OBJ) $(LIB)
+
+.S.o:
+	$(CC)  -D__ASSEMBLY__ $(AFLAGS) $(AFLAGS_KERNEL) -c -o $*.o $<
+.c.o:
+	$(CC)  $(CFLAGS) $(CFLAGS_KERNEL) -c -o $*.o $<
 
 clean:
 	rm -f *.o fprom
diff -Nru a/arch/ia64/sn/fakeprom/README b/arch/ia64/sn/fakeprom/README
--- a/arch/ia64/sn/fakeprom/README	Mon Dec 23 21:22:02 2002
+++ b/arch/ia64/sn/fakeprom/README	Mon Dec 23 21:22:02 2002
@@ -71,7 +71,7 @@
     1GB*<dn>, where dn is the digit number. The amount of memory
     is 8MB*2**<d>. (If <d> = 0, the memory size is 0).
 
-    SN1 doesn't support dimms this small but small memory systems 
+    SN1 doesnt support dimms this small but small memory systems 
     boot faster on Medusa.
 
 
diff -Nru a/arch/ia64/sn/fakeprom/fpmem.c b/arch/ia64/sn/fakeprom/fpmem.c
--- a/arch/ia64/sn/fakeprom/fpmem.c	Mon Dec 23 21:21:53 2002
+++ b/arch/ia64/sn/fakeprom/fpmem.c	Mon Dec 23 21:21:53 2002
@@ -54,10 +54,10 @@
 #define PROMRESERVED_SIZE	(1*MB)
 
 #ifdef CONFIG_IA64_SGI_SN1
-#define PHYS_ADDRESS(_n, _x)		(((long)_n<<33L) | (long)_x)
+#define PHYS_ADDRESS(_n, _x)		(((long)_n<<33) | (long)_x)
 #define MD_BANK_SHFT 30
 #else
-#define PHYS_ADDRESS(_n, _x)		(((long)_n<<38L) | (long)_x | 0x3000000000UL)
+#define PHYS_ADDRESS(_n, _x)		(((long)_n<<38) | (long)_x | 0x3000000000UL)
 #define MD_BANK_SHFT 34
 #endif
 
@@ -94,7 +94,7 @@
 int
 IsCpuPresent(int cnode, int cpu)
 {
-	return  sn_memmap[cnode].cpuconfig & (1<<cpu);
+	return  sn_memmap[cnode].cpuconfig & (1UL<<cpu);
 }
 
 
@@ -142,10 +142,10 @@
 IsBankPresent(int index, node_memmap_t nmemmap)
 {
 	switch (index) {
-		case 0:return nmemmap.ena0;
-		case 1:return nmemmap.ena1;
-		case 2:return nmemmap.ena2;
-		case 3:return nmemmap.ena3;
+		case 0:return BankPresent(nmemmap.b0size);
+		case 1:return BankPresent(nmemmap.b1size);
+		case 2:return BankPresent(nmemmap.b2size);
+		case 3:return BankPresent(nmemmap.b3size);
 		default:return -1 ;
 	}
 }
@@ -153,11 +153,14 @@
 int
 GetBankSize(int index, node_memmap_t nmemmap)
 {
+	/*
+	 * Add 2 because there are 4 dimms per bank.
+	 */
         switch (index) {
-                case 0:return (long)nmemmap.b0size + nmemmap.b0dou;
-                case 1:return (long)nmemmap.b1size + nmemmap.b1dou;
-                case 2:return (long)nmemmap.b2size + nmemmap.b2dou;
-                case 3:return (long)nmemmap.b3size + nmemmap.b3dou;
+                case 0:return 2 + ((long)nmemmap.b0size + nmemmap.b0dou);
+                case 1:return 2 + ((long)nmemmap.b1size + nmemmap.b1dou);
+                case 2:return 2 + ((long)nmemmap.b2size + nmemmap.b2dou);
+                case 3:return 2 + ((long)nmemmap.b3size + nmemmap.b3dou);
                 default:return -1 ;
         }
 }
@@ -189,14 +192,30 @@
 	for (cnode=0;cnode<numnodes;cnode++) {
 		nasid = GetNasid(cnode) ;
 		membank_info = GetMemBankInfo(cnode) ;
-		for (bank=0;bank<PLAT_CLUMPS_PER_NODE;bank++) {
+		for (bank=0;bank<NR_BANKS_PER_NODE;bank++) {
 			if (IsBankPresent(bank, membank_info)) {
 				bsize = GetBankSize(bank, membank_info) ;
                                 paddr = PHYS_ADDRESS(nasid, (long)bank<<MD_BANK_SHFT);
                                 numbytes = BankSizeBytes(bsize);
 #ifdef CONFIG_IA64_SGI_SN2
+				/* 
+				 * Ignore directory.
+				 * Shorten memory chunk by 1 page - makes a better
+				 * testcase & is more like the real PROM.
+				 */
 				numbytes = numbytes * 31 / 32;
 #endif
+				/*
+				 * Only emulate the memory prom grabs
+				 * if we have lots of memory, to allow
+				 * us to simulate smaller memory configs than
+				 * we can actually run on h/w.  Otherwise,
+				 * linux throws away a whole "granule".
+				 */
+				if (cnode == 0 && bank == 0 &&
+				    numbytes > 128*1024*1024) {
+					numbytes -= 1000;
+				}
 
                                 /*
                                  * Check for the node 0 hole. Since banks cant
diff -Nru a/arch/ia64/sn/fakeprom/fpmem.h b/arch/ia64/sn/fakeprom/fpmem.h
--- a/arch/ia64/sn/fakeprom/fpmem.h	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/sn/fakeprom/fpmem.h	Mon Dec 23 21:21:55 2002
@@ -4,7 +4,7 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (C) 2000-2001 Silicon Graphics, Inc.  All rights reserved.
+ * Copyright (C) 2000-2002 Silicon Graphics, Inc.  All rights reserved.
  */
 
 #include <linux/config.h>
@@ -71,7 +71,8 @@
 } node_memmap_t ;
 
 #define SN2_BANK_SIZE_SHIFT		(MBSHIFT+6)     /* 64 MB */
-#define BankSizeBytes(bsize)            (1UL<<((bsize)+SN2_BANK_SIZE_SHIFT))
+#define BankPresent(bsize)		(bsize<6)
+#define BankSizeBytes(bsize)            (BankPresent(bsize) ? 1UL<<((bsize)+SN2_BANK_SIZE_SHIFT) : 0)
 #endif
 
 typedef struct sn_memmap_s
diff -Nru a/arch/ia64/sn/fakeprom/fpromasm.S b/arch/ia64/sn/fakeprom/fpromasm.S
--- a/arch/ia64/sn/fakeprom/fpromasm.S	Mon Dec 23 21:21:52 2002
+++ b/arch/ia64/sn/fakeprom/fpromasm.S	Mon Dec 23 21:21:52 2002
@@ -180,7 +180,7 @@
 
 
 // Now call main & pass it the current LID value.
-	alloc 		r0=ar.pfs,0,0,2,0
+	alloc 		r2=ar.pfs,0,0,2,0
 	mov    		r32=r26
 	mov   		r33=r8;;
 	br.call.sptk.few rp=fmain
diff -Nru a/arch/ia64/sn/fakeprom/fw-emu.c b/arch/ia64/sn/fakeprom/fw-emu.c
--- a/arch/ia64/sn/fakeprom/fw-emu.c	Mon Dec 23 21:21:59 2002
+++ b/arch/ia64/sn/fakeprom/fw-emu.c	Mon Dec 23 21:21:59 2002
@@ -36,6 +36,7 @@
  * http://oss.sgi.com/projects/GenInfo/NoticeExplan
  */
 #include <linux/config.h>
+#include <asm/sn/pda.h>
 #include <linux/efi.h>
 #include <asm/pal.h>
 #include <asm/sal.h>
@@ -46,10 +47,26 @@
 #include <asm/sn/sn2/addrs.h>
 #include <asm/sn/sn2/shub_mmr.h>
 #endif
-#include <asm/acpi-ext.h>
+#include <linux/acpi.h>
 #include "fpmem.h"
 
-#define zzACPI_1_0	1		/* Include ACPI 1.0 tables */
+#define RSDP_NAME               "RSDP"
+#define RSDP_SIG                "RSD PTR "  /* RSDT Pointer signature */
+#define APIC_SIG                "APIC"      /* Multiple APIC Description Table */
+#define DSDT_SIG                "DSDT"      /* Differentiated System Description Table */
+#define FADT_SIG                "FACP"      /* Fixed ACPI Description Table */
+#define FACS_SIG                "FACS"      /* Firmware ACPI Control Structure */
+#define PSDT_SIG                "PSDT"      /* Persistent System Description Table */
+#define RSDT_SIG                "RSDT"      /* Root System Description Table */
+#define XSDT_SIG                "XSDT"      /* Extended  System Description Table */
+#define SSDT_SIG                "SSDT"      /* Secondary System Description Table */
+#define SBST_SIG                "SBST"      /* Smart Battery Specification Table */
+#define SPIC_SIG                "SPIC"      /* IOSAPIC table */
+#define SRAT_SIG                "SRAT"      /* SRAT table */
+#define SLIT_SIG                "SLIT"      /* SLIT table */
+#define BOOT_SIG                "BOOT"      /* Boot table */
+#define ACPI_SRAT_REVISION 1
+#define ACPI_SLIT_REVISION 1
 
 #define OEMID			"SGI"
 #ifdef CONFIG_IA64_SGI_SN1
@@ -77,11 +94,7 @@
 #define CPUS_PER_FSB		2
 #define CPUS_PER_FSB_MASK	(CPUS_PER_FSB-1)
 
-#ifdef ACPI_1_0
-#define NUM_EFI_DESCS		3
-#else
 #define NUM_EFI_DESCS		2
-#endif
 
 #define RSDP_CHECKSUM_LENGTH	20
 
@@ -139,22 +152,16 @@
 		    + sizeof(struct ia64_sal_systab)
 		    + sizeof(struct ia64_sal_desc_entry_point)
 		    + sizeof(struct ia64_sal_desc_ap_wakeup)
-#ifdef ACPI_1_0
-		    + sizeof(acpi_rsdp_t)
-		    + sizeof(acpi_rsdt_t)
-		    + sizeof(acpi_sapic_t)
-		    + MAX_LSAPICS*(sizeof(acpi_entry_lsapic_t))
-#endif
-		    + sizeof(acpi20_rsdp_t)
-		    + sizeof(acpi_xsdt_t)
-		    + sizeof(acpi_slit_t)
+		    + sizeof(struct acpi20_table_rsdp)
+		    + sizeof(struct acpi_table_xsdt)
+		    + sizeof(struct acpi_table_slit)
 		    +   MAX_SN_NODES*MAX_SN_NODES+8
-		    + sizeof(acpi_madt_t)
+		    + sizeof(struct acpi_table_madt)
 		    +   16*MAX_CPUS
 		    + (1+8*MAX_SN_NODES)*(sizeof(efi_memory_desc_t))
-		    + sizeof(acpi_srat_t)
-		    +   MAX_CPUS*sizeof(srat_cpu_affinity_t)
-		    +   MAX_SN_NODES*sizeof(srat_memory_affinity_t)
+		    + sizeof(struct acpi_table_srat)
+		    +   MAX_CPUS*sizeof(struct acpi_table_processor_affinity)
+		    +   MAX_SN_NODES*sizeof(struct acpi_table_memory_affinity)
 		    + sizeof(ia64_sal_desc_ptc_t) +
 		    + MAX_SN_NODES*sizeof(ia64_sal_ptc_domain_info_t) +
 		    + MAX_CPUS*sizeof(ia64_sal_ptc_domain_proc_entry_t) +
@@ -280,6 +287,7 @@
 	} else if (index == SAL_GET_STATE_INFO) {
 		;
 	} else if (index == SAL_GET_STATE_INFO_SIZE) {
+		r9 = 10000;
 		;
 	} else if (index == SAL_CLEAR_STATE_INFO) {
 		;
@@ -328,6 +336,14 @@
 		}
 	} else if (index == SN_SAL_GET_KLCONFIG_ADDR) {
 		r9 = 0x30000;
+	} else if (index == SN_SAL_CONSOLE_PUTC) {
+		status = -1;
+	} else if (index == SN_SAL_CONSOLE_GETC) {
+		status = -1;
+	} else if (index == SN_SAL_CONSOLE_POLL) {
+		status = -1;
+	} else if (index == SN_SAL_SYSCTL_IOBRICK_MODULE_GET) {
+		status = -1;
 	} else {
 		status = -1;
 	}
@@ -396,7 +412,7 @@
 }
 
 void
-acpi_table_init(acpi_desc_table_hdr_t *p, char *sig, int siglen, int revision, int oem_revision)
+acpi_table_initx(struct acpi_table_header *p, char *sig, int siglen, int revision, int oem_revision)
 {
 	memcpy(p->signature, sig, siglen);
 	memcpy(p->oem_id, OEMID, 6);
@@ -404,12 +420,12 @@
 	memcpy(p->oem_table_id+4, PRODUCT, 4);
 	p->revision = revision;
 	p->oem_revision = (revision<<16) + oem_revision;
-	p->creator_id = 1;
-	p->creator_revision = 1;
+	memcpy(p->asl_compiler_id, "FPRM", 4);
+	p->asl_compiler_revision = 1;
 }
 
 void
-acpi_checksum(acpi_desc_table_hdr_t *p, int length)
+acpi_checksum(struct acpi_table_header *p, int length)
 {
 	u8	*cp, *cpe, checksum;
 
@@ -422,16 +438,22 @@
 }
 
 void
-acpi_checksum_rsdp20(acpi20_rsdp_t *p, int length)
+acpi_checksum_rsdp20(struct acpi20_table_rsdp *p, int length)
 {
 	u8	*cp, *cpe, checksum;
 
 	p->checksum = 0;
+	p->ext_checksum = 0;
 	p->length = length;
 	checksum = 0;
-	for (cp=(u8*)p, cpe=cp+RSDP_CHECKSUM_LENGTH; cp<cpe; cp++)
+	for (cp=(u8*)p, cpe=cp+20; cp<cpe; cp++)
 		checksum += *cp;
 	p->checksum = -checksum;
+
+	checksum = 0;
+	for (cp=(u8*)p, cpe=cp+length; cp<cpe; cp++)
+		checksum += *cp;
+	p->ext_checksum = -checksum;
 }
 
 int
@@ -456,21 +478,15 @@
 	static ia64_sal_desc_ptc_t *sal_ptc;
 	static ia64_sal_ptc_domain_info_t *sal_ptcdi;
 	static ia64_sal_ptc_domain_proc_entry_t *sal_ptclid;
-#ifdef ACPI_1_0
-	static acpi_rsdp_t *acpi_rsdp;
-	static acpi_rsdt_t *acpi_rsdt;
-	static acpi_sapic_t *acpi_sapic;
-	static acpi_entry_lsapic_t *acpi_lsapic;
-#endif
-	static acpi20_rsdp_t *acpi20_rsdp;
-	static acpi_xsdt_t *acpi_xsdt;
-	static acpi_slit_t *acpi_slit;
-	static acpi_madt_t *acpi_madt;
-	static acpi20_entry_lsapic_t *lsapic20;
+	static struct acpi20_table_rsdp *acpi20_rsdp;
+	static struct acpi_table_xsdt *acpi_xsdt;
+	static struct acpi_table_slit *acpi_slit;
+	static struct acpi_table_madt *acpi_madt;
+	static struct acpi_table_lsapic *lsapic20;
 	static struct ia64_sal_systab *sal_systab;
-	static acpi_srat_t *acpi_srat;
-	static srat_cpu_affinity_t *srat_cpu_affinity;
-	static srat_memory_affinity_t *srat_memory_affinity;
+	static struct acpi_table_srat *acpi_srat;
+	static struct acpi_table_processor_affinity *srat_cpu_affinity;
+	static struct acpi_table_memory_affinity *srat_memory_affinity;
 	static efi_memory_desc_t *efi_memmap, *md;
 	static unsigned long *pal_desc, *sal_desc;
 	static struct ia64_sal_desc_entry_point *sal_ed;
@@ -519,16 +535,10 @@
 	acpi_xsdt   = (void *) cp; cp += ALIGN8(sizeof(*acpi_xsdt) + 64); 
 			/* save space for more OS defined table pointers. */
 
-#ifdef ACPI_1_0
-	acpi_rsdp   = (void *) cp; cp += ALIGN8(sizeof(*acpi_rsdp));
-	acpi_rsdt   = (void *) cp; cp += ALIGN8(sizeof(*acpi_rsdt));
-	acpi_sapic  = (void *) cp; cp += sizeof(*acpi_sapic);
-	acpi_lsapic = (void *) cp; cp += num_cpus*sizeof(*acpi_lsapic);
-#endif
 	acpi_slit   = (void *) cp; cp += ALIGN8(sizeof(*acpi_slit) + 8 + (max_nasid+1)*(max_nasid+1));
-	acpi_madt   = (void *) cp; cp += ALIGN8(sizeof(*acpi_madt) + 8 * num_cpus+ 8);
-	acpi_srat   = (void *) cp; cp += ALIGN8(sizeof(acpi_srat_t));
-	cp         += sizeof(srat_cpu_affinity_t)*num_cpus + sizeof(srat_memory_affinity_t)*num_nodes;
+	acpi_madt   = (void *) cp; cp += ALIGN8(sizeof(*acpi_madt) + sizeof(struct acpi_table_lsapic) * (num_cpus+1));
+	acpi_srat   = (void *) cp; cp += ALIGN8(sizeof(struct acpi_table_srat));
+	cp         += sizeof(struct acpi_table_processor_affinity)*num_cpus + sizeof(struct acpi_table_memory_affinity)*num_nodes;
 	vendor 	    = (char *) cp; cp += ALIGN8(40);
 	efi_memmap  = (void *) cp; cp += ALIGN8(8*32*sizeof(*efi_memmap));
 	sal_ptcdi   = (void *) cp; cp += ALIGN8(CPUS_PER_FSB*(1+num_nodes)*sizeof(*sal_ptcdi));
@@ -547,8 +557,9 @@
 	 * For now, just bring up bash.
 	 * If you want to execute all the startup scripts, delete the "init=..".
 	 * You can also edit this line to pass other arguments to the kernel.
+	 *    Note: disable kernel text replication.
 	 */
-	strcpy(cmd_line, "init=/bin/bash");
+	strcpy(cmd_line, "init=/bin/bash ktreplicate=0");
 
 	memset(efi_systab, 0, sizeof(efi_systab));
 	efi_systab->hdr.signature = EFI_SYSTEM_TABLE_SIGNATURE;
@@ -578,11 +589,6 @@
 	efi_tables->guid = SAL_SYSTEM_TABLE_GUID;
 	efi_tables->table = __fwtab_pa(base_nasid, sal_systab);
 	efi_tables++;
-#ifdef ACPI_1_0
-	efi_tables->guid = ACPI_TABLE_GUID;
-	efi_tables->table = __fwtab_pa(base_nasid, acpi_rsdp);
-	efi_tables++;
-#endif
 	efi_tables->guid = ACPI_20_TABLE_GUID;
 	efi_tables->table = __fwtab_pa(base_nasid, acpi20_rsdp);
 	efi_tables++;
@@ -593,65 +599,32 @@
 	fix_function_pointer(&efi_reset_system);
 	fix_function_pointer(&efi_set_virtual_address_map);
 
-#ifdef ACPI_1_0
-	/* fill in the ACPI system table - has a pointer to the ACPI table header */
-	memcpy(acpi_rsdp->signature, "RSD PTR ", 8);
-	acpi_rsdp->rsdt = (struct acpi_rsdt*)__fwtab_pa(base_nasid, acpi_rsdt);
-
-	acpi_table_init(&acpi_rsdt->header, ACPI_RSDT_SIG, ACPI_RSDT_SIG_LEN, 1, 1);
-	acpi_rsdt->header.length = sizeof(acpi_rsdt_t);
-	acpi_rsdt->entry_ptrs[0] = __fwtab_pa(base_nasid, acpi_sapic);
-
-	memcpy(acpi_sapic->header.signature, "SPIC ", 4);
-	acpi_sapic->header.length = sizeof(acpi_sapic_t)+num_cpus*sizeof(acpi_entry_lsapic_t);
-
-	for (cnode=0; cnode<num_nodes; cnode++) {
-		nasid = GetNasid(cnode);
-		for(cpu=0; cpu<CPUS_PER_NODE; cpu++) {
-			if (!IsCpuPresent(cnode, cpu))
-				continue;
-			acpi_lsapic->type = ACPI_ENTRY_LOCAL_SAPIC;
-			acpi_lsapic->length = sizeof(acpi_entry_lsapic_t);
-			acpi_lsapic->acpi_processor_id = cnode*4+cpu;
-			acpi_lsapic->flags = LSAPIC_ENABLED|LSAPIC_PRESENT;
-#if defined(CONFIG_IA64_SGI_SN1)
-			acpi_lsapic->eid = cpu;
-			acpi_lsapic->id = nasid;
-#else
-			acpi_lsapic->eid = nasid&0xffff;
-			acpi_lsapic->id = (cpu<<4) | (nasid>>16);
-#endif
-			acpi_lsapic++;
-		}
-	}
-#endif
-
 
 	/* fill in the ACPI20 system table - has a pointer to the ACPI table header */
 	memcpy(acpi20_rsdp->signature, "RSD PTR ", 8);
-	acpi20_rsdp->xsdt = (struct acpi_xsdt*)__fwtab_pa(base_nasid, acpi_xsdt);
+	acpi20_rsdp->xsdt_address = (u64)__fwtab_pa(base_nasid, acpi_xsdt);
 	acpi20_rsdp->revision = 2;
-	acpi_checksum_rsdp20(acpi20_rsdp, sizeof(acpi20_rsdp_t));
+	acpi_checksum_rsdp20(acpi20_rsdp, sizeof(struct acpi20_table_rsdp));
 
 	/* Set up the XSDT table  - contains pointers to the other ACPI tables */
-	acpi_table_init(&acpi_xsdt->header, ACPI_XSDT_SIG, ACPI_XSDT_SIG_LEN, 1, 1);
-	acpi_xsdt->entry_ptrs[0] = __fwtab_pa(base_nasid, acpi_madt);
-	acpi_xsdt->entry_ptrs[1] = __fwtab_pa(base_nasid, acpi_slit);
-	acpi_xsdt->entry_ptrs[2] = __fwtab_pa(base_nasid, acpi_srat);
-	acpi_checksum(&acpi_xsdt->header, sizeof(acpi_xsdt_t) + 16);
-
-	/* Set up the MADT table */
-	acpi_table_init(&acpi_madt->header, ACPI_MADT_SIG, ACPI_MADT_SIG_LEN, 1, 1);
-	lsapic20 = (acpi20_entry_lsapic_t*) (acpi_madt + 1);
+	acpi_table_initx(&acpi_xsdt->header, XSDT_SIG, 4, 1, 1);
+	acpi_xsdt->entry[0] = __fwtab_pa(base_nasid, acpi_madt);
+	acpi_xsdt->entry[1] = __fwtab_pa(base_nasid, acpi_slit);
+	acpi_xsdt->entry[2] = __fwtab_pa(base_nasid, acpi_srat);
+	acpi_checksum(&acpi_xsdt->header, sizeof(struct acpi_table_xsdt) + 16);
+
+	/* Set up the APIC table */
+	acpi_table_initx(&acpi_madt->header, APIC_SIG, 4, 1, 1);
+	lsapic20 = (struct acpi_table_lsapic*) (acpi_madt + 1);
 	for (cnode=0; cnode<num_nodes; cnode++) {
 		nasid = GetNasid(cnode);
 		for(cpu=0; cpu<CPUS_PER_NODE; cpu++) {
 			if (!IsCpuPresent(cnode, cpu))
 				continue;
-			lsapic20->type = ACPI20_ENTRY_LOCAL_SAPIC;
-			lsapic20->length = sizeof(acpi_entry_lsapic_t);
-			lsapic20->acpi_processor_id = cnode*4+cpu;
-			lsapic20->flags = LSAPIC_ENABLED|LSAPIC_PRESENT;
+			lsapic20->header.type = ACPI_MADT_LSAPIC;
+			lsapic20->header.length = sizeof(struct acpi_table_lsapic);
+			lsapic20->acpi_id = cnode*4+cpu;
+			lsapic20->flags.enabled = 1;
 #if defined(CONFIG_IA64_SGI_SN1)
 			lsapic20->eid = cpu;
 			lsapic20->id = nasid;
@@ -659,20 +632,20 @@
 			lsapic20->eid = nasid&0xffff;
 			lsapic20->id = (cpu<<4) | (nasid>>16);
 #endif
-			lsapic20 = (acpi20_entry_lsapic_t*) ((long)lsapic20+sizeof(acpi_entry_lsapic_t));
+			lsapic20 = (struct acpi_table_lsapic*) ((long)lsapic20+sizeof(struct acpi_table_lsapic));
 		}
 	}
 	acpi_checksum(&acpi_madt->header, (char*)lsapic20 - (char*)acpi_madt);
 
 	/* Set up the SRAT table */
-	acpi_table_init(&acpi_srat->header, ACPI_SRAT_SIG, ACPI_SRAT_SIG_LEN, ACPI_SRAT_REVISION, 1);
+	acpi_table_initx(&acpi_srat->header, SRAT_SIG, 4, ACPI_SRAT_REVISION, 1);
 	ptr = acpi_srat+1;
 	for (cnode=0; cnode<num_nodes; cnode++) {
 		nasid = GetNasid(cnode);
 		srat_memory_affinity = ptr;
 		ptr = srat_memory_affinity+1;
-		srat_memory_affinity->type = SRAT_MEMORY_STRUCTURE;
-		srat_memory_affinity->length = sizeof(srat_memory_affinity_t);
+		srat_memory_affinity->header.type = ACPI_SRAT_MEMORY_AFFINITY;
+		srat_memory_affinity->header.length = sizeof(struct acpi_table_memory_affinity);
 		srat_memory_affinity->proximity_domain = PROXIMITY_DOMAIN(nasid);
 		srat_memory_affinity->base_addr_lo = 0;
 		srat_memory_affinity->length_lo = 0;
@@ -684,7 +657,7 @@
 		srat_memory_affinity->length_hi = SN2_NODE_SIZE>>32;
 #endif
 		srat_memory_affinity->memory_type = ACPI_ADDRESS_RANGE_MEMORY;
-		srat_memory_affinity->flags = SRAT_MEMORY_FLAGS_ENABLED;
+		srat_memory_affinity->flags.enabled = 1;
 	}
 
 	for (cnode=0; cnode<num_nodes; cnode++) {
@@ -694,15 +667,15 @@
 				continue;
 			srat_cpu_affinity = ptr;
 			ptr = srat_cpu_affinity + 1;
-			srat_cpu_affinity->type = SRAT_CPU_STRUCTURE;
-			srat_cpu_affinity->length = sizeof(srat_cpu_affinity_t);
+			srat_cpu_affinity->header.type = ACPI_SRAT_PROCESSOR_AFFINITY;
+			srat_cpu_affinity->header.length = sizeof(struct acpi_table_processor_affinity);
 			srat_cpu_affinity->proximity_domain = PROXIMITY_DOMAIN(nasid);
-			srat_cpu_affinity->flags = SRAT_CPU_FLAGS_ENABLED;
+			srat_cpu_affinity->flags.enabled = 1;
 #if defined(CONFIG_IA64_SGI_SN1)
 			srat_cpu_affinity->apic_id = nasid;
-			srat_cpu_affinity->local_sapic_eid = cpu;
+			srat_cpu_affinity->lsapic_eid = cpu;
 #else
-			srat_cpu_affinity->local_sapic_eid = nasid&0xffff;
+			srat_cpu_affinity->lsapic_eid = nasid&0xffff;
 			srat_cpu_affinity->apic_id = (cpu<<4) | (nasid>>16);
 #endif
 		}
@@ -711,9 +684,9 @@
 
 
 	/* Set up the SLIT table */
-	acpi_table_init(&acpi_slit->header, ACPI_SLIT_SIG, ACPI_SLIT_SIG_LEN, ACPI_SLIT_REVISION, 1);
+	acpi_table_initx(&acpi_slit->header, SLIT_SIG, 4, ACPI_SLIT_REVISION, 1);
 	acpi_slit->localities = PROXIMITY_DOMAIN(max_nasid)+1;
-	cp=acpi_slit->entries;
+	cp=acpi_slit->entry;
 	memset(cp, 255, acpi_slit->localities*acpi_slit->localities);
 
 	for (i=0; i<=max_nasid; i++)
@@ -721,7 +694,7 @@
 			if (nasid_present(i) && nasid_present(j))
 				*(cp+PROXIMITY_DOMAIN(i)*acpi_slit->localities+PROXIMITY_DOMAIN(j)) = 10 + MIN(254, 5*ABS(i-j));
 
-	cp = acpi_slit->entries + acpi_slit->localities*acpi_slit->localities;
+	cp = acpi_slit->entry + acpi_slit->localities*acpi_slit->localities;
 	acpi_checksum(&acpi_slit->header, cp - (char*)acpi_slit);
 
 
@@ -731,6 +704,8 @@
 	sal_systab->sal_rev_minor = 1;
 	sal_systab->sal_rev_major = 0;
 	sal_systab->entry_count = 3;
+	sal_systab->sal_b_rev_major = 0x1; /* set the SN SAL rev to */
+	sal_systab->sal_b_rev_minor = 0x0; /* 1.00 */
 
 	strcpy(sal_systab->oem_id, "SGI");
 	strcpy(sal_systab->product_id, "SN1");
@@ -785,11 +760,6 @@
 	 * table. We dont build enough table & the kernel aborts.
 	 * Note that the PROM hasd thhhe same problem!!
 	 */
-#ifdef DOESNT_WORK
-	for (checksum=0, cp=(char*)acpi_rsdp, cpe=cp+RSDP_CHECKSUM_LENGTH; cp<cpe; ++cp)
-		checksum += *cp;
-	acpi_rsdp->checksum = -checksum;
-#endif
 
 	md = &efi_memmap[0];
 	num_memmd = build_efi_memmap((void *)md, mdsize) ;
diff -Nru a/arch/ia64/sn/fakeprom/klgraph_init.c b/arch/ia64/sn/fakeprom/klgraph_init.c
--- a/arch/ia64/sn/fakeprom/klgraph_init.c	Mon Dec 23 21:21:50 2002
+++ b/arch/ia64/sn/fakeprom/klgraph_init.c	Mon Dec 23 21:21:50 2002
@@ -1,4 +1,4 @@
-/* $Id: klgraph_init.c,v 1.2 2001/12/05 16:58:41 jh Exp $
+/* $Id: klgraph_init.c,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
@@ -49,8 +49,9 @@
 klgraph_init(void)
 {
 
-	u64	*temp;
-
+#ifdef CONFIG_IA64_SGI_SN1
+	u64 *temp;
+#endif
 	/*
 	 * Initialize some hub/xbow registers that allows access to 
 	 * Xbridge etc.  These are normally done in PROM.
@@ -109,6 +110,8 @@
 // [PI]       *(volatile u32 *)0xc00000080f000288L = 0xba98;
 #endif	/* CONFIG_IA64_SGI_SN1 */
 
+#ifdef CONFIG_IA64_SGI_SN1
+
 	/*
 	 * kldir entries initialization - mankato
 	 */
@@ -282,6 +285,7 @@
 	convert(0x8000000000002560, 0xffffffffffffffff, 0xffffffffffffffff);
 	convert(0x8000000000002570, 0xffffffffffffffff, 0xffffffffffffffff);
 	convert(0x8000000000002580, 0x000000000000ffff, 0x0000000000000000);
+#endif
 	
 }
 
diff -Nru a/arch/ia64/sn/fakeprom/main.c b/arch/ia64/sn/fakeprom/main.c
--- a/arch/ia64/sn/fakeprom/main.c	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/sn/fakeprom/main.c	Mon Dec 23 21:21:55 2002
@@ -98,7 +98,7 @@
 
 	/*
 	 * Enable all FSB flashed interrupts.
-	 * ZZZ - I'd really like defines for this......
+	 * I'd really like defines for this......
 	 */
 	base = (long*)0x80000e0000000000LL;		/* base of synergy regs */
 	for (off = 0x2a0; off < 0x2e0; off+=8)		/* offset for VEC_MASK_{0-3}_A/B */
diff -Nru a/arch/ia64/sn/io/Makefile b/arch/ia64/sn/io/Makefile
--- a/arch/ia64/sn/io/Makefile	Mon Dec 23 21:21:52 2002
+++ b/arch/ia64/sn/io/Makefile	Mon Dec 23 21:21:52 2002
@@ -5,35 +5,20 @@
 #
 # Copyright (C) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
 #
-#
-# Makefile for the linux kernel.
-#
-# Note! Dependencies are done automagically by 'make dep', which also
-# removes any old dependencies. DON'T put your own dependencies here
-# unless it's something special (ie not a .c file).
-#
+# Makefile for the sn kernel routines.
 
 EXTRA_CFLAGS    := -DLITTLE_ENDIAN
 
-export-objs = pciio.o hcl.o
+ifdef CONFIG_IA64_SGI_SN2
+EXTRA_CFLAGS    += -DSHUB_SWAP_WAR
+endif
+
+export-objs := hcl.o pci_dma.o
+
+obj-$(CONFIG_IA64_SGI_SN) += stubs.o sgi_if.o xswitch.o klgraph_hack.o \
+		hcl.o labelcl.o invent.o sgi_io_sim.o \
+		klgraph_hack.o hcl_util.o cdl.o hubdev.o hubspc.o \
+		alenlist.o pci.o pci_dma.o ate_utils.o \
+		ifconfig_net.o io.o ifconfig_bus.o
 
-obj-y  := stubs.o sgi_if.o pciio.o xtalk.o xbow.o xswitch.o klgraph_hack.o \
-		hcl.o labelcl.o invent.o klgraph.o klconflib.o sgi_io_sim.o \
-		module.o sgi_io_init.o klgraph_hack.o ml_SN_init.o \
-		ml_iograph.o hcl_util.o cdl.o hubdev.o hubspc.o \
-		alenlist.o pci_bus_cvlink.o \
-		eeprom.o pci.o pci_dma.o l1.o l1_command.o ate_utils.o \
-		ifconfig_net.o efi-rtc.o io.o
-
-obj-$(CONFIG_IA64_SGI_SN1)   += sn1/ml_SN_intr.o sn1/mem_refcnt.o sn1/hubcounters.o \
-				sn1/ip37.o sn1/huberror.o sn1/hub_intr.o sn1/pcibr.o
-
-obj-$(CONFIG_IA64_SGI_SN2)   += sn2/ml_SN_intr.o sn2/shub_intr.o sn2/shuberror.o \
-				sn2/bte_error.o \
-				sn2/pcibr/pcibr_dvr.o sn2/pcibr/pcibr_ate.o \
-				sn2/pcibr/pcibr_config.o sn2/pcibr/pcibr_dvr.o \
-				sn2/pcibr/pcibr_hints.o \
-				sn2/pcibr/pcibr_idbg.o sn2/pcibr/pcibr_intr.o \
-				sn2/pcibr/pcibr_rrb.o sn2/pcibr/pcibr_slot.o 
-
-obj-$(CONFIG_PCIBA) += pciba.o
+obj-$(CONFIG_PCIBA)		+= pciba.o
diff -Nru a/arch/ia64/sn/io/alenlist.c b/arch/ia64/sn/io/alenlist.c
--- a/arch/ia64/sn/io/alenlist.c	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/sn/io/alenlist.c	Mon Dec 23 21:21:55 2002
@@ -192,9 +192,9 @@
 #define AL_FIXED_SIZE	0x1	/* List is pre-allocated, and of fixed size */
 
 
-zone_t *alenlist_zone = NULL;
-zone_t *alenlist_chunk_zone = NULL;
-zone_t *alenlist_cursor_zone = NULL;
+struct zone *alenlist_zone = NULL;
+struct zone *alenlist_chunk_zone = NULL;
+struct zone *alenlist_cursor_zone = NULL;
 
 #if DEBUG
 int alenlist_count=0;		/* Currently allocated Lists */
diff -Nru a/arch/ia64/sn/io/ate_utils.c b/arch/ia64/sn/io/ate_utils.c
--- a/arch/ia64/sn/io/ate_utils.c	Mon Dec 23 21:21:54 2002
+++ b/arch/ia64/sn/io/ate_utils.c	Mon Dec 23 21:21:54 2002
@@ -1,4 +1,4 @@
-/* $Id$
+/* $Id: ate_utils.c,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
diff -Nru a/arch/ia64/sn/io/cdl.c b/arch/ia64/sn/io/cdl.c
--- a/arch/ia64/sn/io/cdl.c	Mon Dec 23 21:21:52 2002
+++ b/arch/ia64/sn/io/cdl.c	Mon Dec 23 21:21:52 2002
@@ -7,6 +7,7 @@
  * Copyright (C) 1992 - 1997, 2000-2002 Silicon Graphics, Inc. All rights reserved.
  */
 
+#include <linux/config.h>
 #include <linux/types.h>
 #include <asm/sn/sgi.h>
 #include <asm/io.h>
@@ -19,6 +20,8 @@
 /* these get called directly in cdl_add_connpt in fops bypass hack */
 extern int pcibr_attach(devfs_handle_t);
 extern int xbow_attach(devfs_handle_t);
+extern int pic_attach(devfs_handle_t);
+
 
 /*
  *    cdl: Connection and Driver List
@@ -35,13 +38,24 @@
     int (*attach) (devfs_handle_t);
 } dummy_reg;
 
+#ifdef CONFIG_IA64_SGI_SN1
 #define MAX_SGI_IO_INFRA_DRVR 4
-struct cdl sgi_infrastructure_drivers[MAX_SGI_IO_INFRA_DRVR] =
+#else
+#define MAX_SGI_IO_INFRA_DRVR 7
+#endif
+static struct cdl sgi_infrastructure_drivers[MAX_SGI_IO_INFRA_DRVR] =
 {
 	{ XBRIDGE_WIDGET_PART_NUM, XBRIDGE_WIDGET_MFGR_NUM, pcibr_attach /* &pcibr_fops  */},
 	{ BRIDGE_WIDGET_PART_NUM,  BRIDGE_WIDGET_MFGR_NUM,  pcibr_attach /* &pcibr_fops */},
+#ifndef CONFIG_IA64_SGI_SN1
+	{ PIC_WIDGET_PART_NUM_BUS0,  PIC_WIDGET_MFGR_NUM,   pic_attach /* &pic_fops */},
+	{ PIC_WIDGET_PART_NUM_BUS1,  PIC_WIDGET_MFGR_NUM,   pic_attach /* &pic_fops */},
+#endif
 	{ XXBOW_WIDGET_PART_NUM,   XXBOW_WIDGET_MFGR_NUM,   xbow_attach /* &xbow_fops */},
 	{ XBOW_WIDGET_PART_NUM,    XBOW_WIDGET_MFGR_NUM,    xbow_attach /* &xbow_fops */},
+#ifndef CONFIG_IA64_SGI_SN1
+	{ PXBOW_WIDGET_PART_NUM,   XXBOW_WIDGET_MFGR_NUM,   xbow_attach /* &xbow_fops */},
+#endif
 };
 
 /*
diff -Nru a/arch/ia64/sn/io/hcl.c b/arch/ia64/sn/io/hcl.c
--- a/arch/ia64/sn/io/hcl.c	Mon Dec 23 21:21:59 2002
+++ b/arch/ia64/sn/io/hcl.c	Mon Dec 23 21:21:59 2002
@@ -6,7 +6,7 @@
  *
  *  hcl - SGI's Hardware Graph compatibility layer.
  *
- * Copyright (C) 1992 - 1997, 2000-2001 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 1992 - 1997, 2000-2002 Silicon Graphics, Inc. All rights reserved.
  */
 
 #include <linux/types.h>
@@ -155,7 +155,7 @@
 	/*
 	 * Create the hwgraph_root on devfs.
 	 */
-	rv = hwgraph_path_add(NULL, "hw", &hwgraph_root);
+	rv = hwgraph_path_add(NULL, EDGE_LBL_HW, &hwgraph_root);
 	if (rv)
 		printk ("WARNING: init_hcl: Failed to create hwgraph_root. Error = %d.\n", rv);
 
@@ -183,9 +183,9 @@
 	/*
 	 * Create the directory that links Linux bus numbers to our Xwidget.
 	 */
-	rv = hwgraph_path_add(hwgraph_root, "linux/busnum", &linux_busnum);
+	rv = hwgraph_path_add(hwgraph_root, EDGE_LBL_LINUX_BUS, &linux_busnum);
 	if (linux_busnum == NULL) {
-		panic("HCL: Unable to create hw/linux/busnum\n");
+		panic("HCL: Unable to create %s\n", EDGE_LBL_LINUX_BUS);
 		return(0);
 	}
 
@@ -674,7 +674,6 @@
 		 */
 		namelen = (int) strlen(name);
 		target_handle = devfs_get_handle(from, name, 1); /* Yes traverse symbolic links */
-		devfs_put(target_handle); /* Assume we're the owner */
 		if (target_handle == NULL)
 			return(-1);
 		else
@@ -955,7 +954,6 @@
 	*vertex_handle_ptr = devfs_get_handle(start_vertex_handle,	/* start dir */
 					lookup_path,		/* path */
 					1);			/* traverse symlinks */
-	devfs_put(*vertex_handle_ptr); /* Assume we're the owner */
 	if (*vertex_handle_ptr == NULL)
 		return(-1);
 	else
@@ -963,20 +961,19 @@
 }
 
 /*
- * hwgraph_traverse - Find and return the devfs handle starting from dir.
+ * hwgraph_traverse - Find and return the devfs handle starting from de.
  *
  */
 graph_error_t
-hwgraph_traverse(devfs_handle_t dir, char *path, devfs_handle_t *found)
+hwgraph_traverse(devfs_handle_t de, char *path, devfs_handle_t *found)
 {
 	/* 
 	 * get the directory entry (path should end in a directory)
 	 */
 
-	*found = devfs_get_handle(dir,	/* start dir */
+	*found = devfs_get_handle(de,	/* start dir */
 			    path,	/* path */
 			    1);		/* traverse symlinks */
-	devfs_put(*found); /* Assume we're the owner */
 	if (*found == NULL)
 		return(GRAPH_NOT_FOUND);
 	else
@@ -990,13 +987,9 @@
 devfs_handle_t
 hwgraph_path_to_vertex(char *path)
 {
-	devfs_handle_t de;
-
-	de = devfs_get_handle(NULL,	/* start dir */
+	return(devfs_get_handle(NULL,	/* start dir */
 			path,		/* path */
-		    	1);
-	devfs_put(de); /* Assume we're the owner */
-	return(de);
+		    	1));		/* traverse symlinks */
 }
 
 /*
@@ -1014,34 +1007,26 @@
 
 /*
  * hwgraph_block_device_get - return the handle of the block device file.
- *	The assumption here is that dir is a directory.
+ *	The assumption here is that de is a directory.
 */
 devfs_handle_t
-hwgraph_block_device_get(devfs_handle_t dir)
+hwgraph_block_device_get(devfs_handle_t de)
 {
-	devfs_handle_t de;
-
-	de = devfs_get_handle(dir,		/* start dir */
+	return(devfs_get_handle(de,		/* start dir */
 			"block",		/* path */
-		    	1);			/* traverse symlinks */
-	devfs_put(de); /* Assume we're the owner */
-	return(de);
+		    	1));			/* traverse symlinks */
 }
 
 /*
  * hwgraph_char_device_get - return the handle of the char device file.
- *      The assumption here is that dir is a directory.
+ *      The assumption here is that de is a directory.
 */
 devfs_handle_t
-hwgraph_char_device_get(devfs_handle_t dir)
+hwgraph_char_device_get(devfs_handle_t de)
 {
-	devfs_handle_t de;
-
-	de = devfs_get_handle(dir,		/* start dir */
+	return(devfs_get_handle(de,		/* start dir */
 			"char",			/* path */
-		    	1);			/* traverse symlinks */
-	devfs_put(de); /* Assume we're the owner */
-	return(de);
+		    	1));			/* traverse symlinks */
 }
 
 /*
diff -Nru a/arch/ia64/sn/io/hcl_util.c b/arch/ia64/sn/io/hcl_util.c
--- a/arch/ia64/sn/io/hcl_util.c	Mon Dec 23 21:21:56 2002
+++ b/arch/ia64/sn/io/hcl_util.c	Mon Dec 23 21:21:56 2002
@@ -4,7 +4,7 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (C) 1992 - 1997, 2000-2001 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 1992 - 1997, 2000-2002 Silicon Graphics, Inc. All rights reserved.
  */
 
 #include <linux/types.h>
@@ -93,6 +93,33 @@
 		}
 
 		vhdl = master;
+	}
+}
+
+static devfs_handle_t hwgraph_all_cpuids = GRAPH_VERTEX_NONE;
+extern int maxcpus;
+
+void
+mark_cpuvertex_as_cpu(devfs_handle_t vhdl, cpuid_t cpuid)
+{
+	if (cpuid == CPU_NONE)
+		return;
+
+	(void)labelcl_info_add_LBL(vhdl, INFO_LBL_CPUID, INFO_DESC_EXPORT,
+			(arbitrary_info_t)cpuid);
+	{
+		char cpuid_buffer[10];
+
+		if (hwgraph_all_cpuids == GRAPH_VERTEX_NONE) {
+			(void)hwgraph_path_add( hwgraph_root,
+						EDGE_LBL_CPUNUM,
+						&hwgraph_all_cpuids);
+		}
+
+		sprintf(cpuid_buffer, "%ld", cpuid);
+		(void)hwgraph_edge_add( hwgraph_all_cpuids,
+							vhdl,
+							cpuid_buffer);
 	}
 }
 
diff -Nru a/arch/ia64/sn/io/hubdev.c b/arch/ia64/sn/io/hubdev.c
--- a/arch/ia64/sn/io/hubdev.c	Mon Dec 23 21:21:58 2002
+++ b/arch/ia64/sn/io/hubdev.c	Mon Dec 23 21:21:58 2002
@@ -4,7 +4,7 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (C) 1992 - 1997, 2000-2001 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 1992 - 1997, 2000-2002 Silicon Graphics, Inc. All rights reserved.
  */
 
 #include <linux/config.h>
diff -Nru a/arch/ia64/sn/io/hubspc.c b/arch/ia64/sn/io/hubspc.c
--- a/arch/ia64/sn/io/hubspc.c	Mon Dec 23 21:21:56 2002
+++ b/arch/ia64/sn/io/hubspc.c	Mon Dec 23 21:21:56 2002
@@ -52,7 +52,7 @@
 }cpuprom_info_t;
 
 static cpuprom_info_t	*cpuprom_head;
-spinlock_t	cpuprom_spinlock;
+static spinlock_t	cpuprom_spinlock;
 #define	PROM_LOCK()	mutex_spinlock(&cpuprom_spinlock)
 #define	PROM_UNLOCK(s)	mutex_spinunlock(&cpuprom_spinlock, (s))
 
@@ -161,69 +161,8 @@
 				sizeof(invent_miscinfo_t));
 }
 
-#define FPROM_CONFIG_ADDR	MD_JUNK_BUS_TIMING
-#define FPROM_ENABLE_MASK	MJT_FPROM_ENABLE_MASK
-#define FPROM_ENABLE_SHFT	MJT_FPROM_ENABLE_SHFT
-#define FPROM_SETUP_MASK	MJT_FPROM_SETUP_MASK
-#define FPROM_SETUP_SHFT	MJT_FPROM_SETUP_SHFT
+#endif  /* CONFIG_IA64_SGI_SN1 */
 
-/*ARGSUSED*/
-int
-cpuprom_map(devfs_handle_t dev, vhandl_t *vt, off_t addr, size_t len)
-{
-        int 		errcode = 0;
-	caddr_t 	kvaddr;
-	devfs_handle_t		node;
-	cnodeid_t 	cnode;
-
-	node = prominfo_nodeget(dev);
-
-	if (!node)
-		return EIO;
-        
-
-	kvaddr = hubdev_prombase_get(node);
-	cnode  = hubdev_cnodeid_get(node);
-#ifdef	HUBSPC_DEBUG
-	printk("cpuprom_map: hubnode %d kvaddr 0x%x\n", node, kvaddr);
-#endif
-
-	if (len > RBOOT_SIZE)
-		len = RBOOT_SIZE;
-        /*
-         * Map in the prom space
-         */
-	errcode = v_mapphys(vt, kvaddr, len);
-
-	if (errcode == 0 ){
-		/*
-		 * Set the MD configuration registers suitably.
-		 */
-		nasid_t		nasid;
-		uint64_t	value;
-		volatile hubreg_t	*regaddr;
-
-		nasid = COMPACT_TO_NASID_NODEID(cnode);
-		regaddr = REMOTE_HUB_ADDR(nasid, FPROM_CONFIG_ADDR);
-		value = HUB_L(regaddr);
-		value &= ~(FPROM_SETUP_MASK | FPROM_ENABLE_MASK);
-		{
-			value |= (((long)CONFIG_FPROM_SETUP << FPROM_SETUP_SHFT) | 
-				  ((long)CONFIG_FPROM_ENABLE << FPROM_ENABLE_SHFT));
-		}
-		HUB_S(regaddr, value);
-
-	}
-        return (errcode);
-}
-#endif	/* CONFIG_IA64_SGI_SN1 */
-
-/*ARGSUSED*/
-int
-cpuprom_unmap(devfs_handle_t dev, vhandl_t *vt)
-{
-        return 0;
-}
 
 /***********************************************************************/
 /* Base Hub Space Driver                                               */
@@ -245,15 +184,14 @@
         hubdev_register(mem_refcnt_attach);
 #endif
 
-#if defined(CONFIG_SERIAL_SGI_L1_PROTOCOL)
+#ifdef CONFIG_IA64_SGI_SN1
 	/* L1 system controller link */
 	if ( !IS_RUNNING_ON_SIMULATOR() ) {
 		/* initialize the L1 link */
 		extern void l1_init(void);
 		l1_init();
 	}
-#endif
-
+#endif	/* CONFIG_IA64_SGI_SN1 */
 #ifdef	HUBSPC_DEBUG
 	printk("hubspc_init: Completed\n");
 #endif	/* HUBSPC_DEBUG */
@@ -285,7 +223,7 @@
 
 	/* check validity of request */
 	if( len == 0 ) {
-		return ENXIO;
+		return -ENXIO;
         }
 
 	return errcode;
diff -Nru a/arch/ia64/sn/io/ifconfig_net.c b/arch/ia64/sn/io/ifconfig_net.c
--- a/arch/ia64/sn/io/ifconfig_net.c	Mon Dec 23 21:21:53 2002
+++ b/arch/ia64/sn/io/ifconfig_net.c	Mon Dec 23 21:21:53 2002
@@ -1,4 +1,4 @@
-/* $Id$
+/* $Id: ifconfig_net.c,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
@@ -202,30 +202,16 @@
 	 * Read in the header and see how big of a buffer we really need to 
 	 * allocate.
 	 */
-	ifname_num = kmalloc(sizeof(struct ifname_num), GFP_KERNEL);
-	if (!ifname_num)
-		return -ENOMEM;
-	if (copy_from_user(ifname_num, (char *)arg,
-			   sizeof(struct ifname_num))) {
-		kfree(ifname_num);
-		return -EFAULT;
-	}
+	ifname_num = (struct ifname_num *) kmalloc(sizeof(struct ifname_num), 
+			GFP_KERNEL);
+	copy_from_user( ifname_num, (char *) arg, sizeof(struct ifname_num));
 	size = ifname_num->size;
 	kfree(ifname_num);
-	ifname_num = kmalloc(size, GFP_KERNEL);
-	if (!ifname_num)
-		return -ENOMEM;
+	ifname_num = (struct ifname_num *) kmalloc(size, GFP_KERNEL);
 	ifname_MAC = (struct ifname_MAC *) ((char *)ifname_num + (sizeof(struct ifname_num)) );
 
-	if (copy_from_user(ifname_num, (char *)arg, size)) {
-		kfree(ifname_num);
-		return -EFAULT;
-	}
+	copy_from_user( ifname_num, (char *) arg, size);
 	new_devices =  kmalloc(size - sizeof(struct ifname_num), GFP_KERNEL);
-	if (!new_devices) {
-		kfree(ifname_num);
-		return -EFAULT;
-	}
 	temp_new_devices = new_devices;
 
 	memset(new_devices, 0, size - sizeof(struct ifname_num));
@@ -271,17 +257,17 @@
 	/*
 	 * Copy back to the User Buffer area any new devices encountered.
 	 */
-	if (copy_to_user((char *)arg + (sizeof(struct ifname_num)),
-			 new_devices, size - sizeof(struct ifname_num)))
-		return -EFAULT;
+	copy_to_user((char *)arg + (sizeof(struct ifname_num)), new_devices, 
+			size - sizeof(struct ifname_num));
+
 	return(0);
 
 }
 
 struct file_operations ifconfig_net_fops = {
-	.ioctl =ifconfig_net_ioctl,	/* ioctl */
-	.open =ifconfig_net_open,		/* open */
-	.release =ifconfig_net_close	/* release */
+	ioctl:ifconfig_net_ioctl,	/* ioctl */
+	open:ifconfig_net_open,		/* open */
+	release:ifconfig_net_close	/* release */
 };
 
 
diff -Nru a/arch/ia64/sn/io/invent.c b/arch/ia64/sn/io/invent.c
--- a/arch/ia64/sn/io/invent.c	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/sn/io/invent.c	Mon Dec 23 21:21:55 2002
@@ -4,7 +4,7 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (C) 1992 - 1997, 2000-2001 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 1992 - 1997, 2000-2002 Silicon Graphics, Inc. All rights reserved.
  */
 
 /*
diff -Nru a/arch/ia64/sn/io/io.c b/arch/ia64/sn/io/io.c
--- a/arch/ia64/sn/io/io.c	Mon Dec 23 21:21:54 2002
+++ b/arch/ia64/sn/io/io.c	Mon Dec 23 21:21:54 2002
@@ -7,6 +7,7 @@
  * Copyright (C) 1992-1997, 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
  */
 
+#include <linux/config.h>
 #include <linux/types.h>
 #include <linux/slab.h>
 #include <asm/sn/types.h>
@@ -31,21 +32,6 @@
 extern void hub_intr_init(devfs_handle_t hubv);
 
 
-/*      
- * hub_device_desc_update               
- *      Update the passed in device descriptor with the actual the
- *      target cpu number and interrupt priority level.
- *      NOTE : These might be the same as the ones passed in thru
- *      the descriptor.
- */     
-void
-hub_device_desc_update(device_desc_t    dev_desc,
-                       ilvl_t           intr_swlevel, 
-                       cpuid_t          cpu)
-{       
-}
-
-
 /*
  * Perform any initializations needed to support hub-based I/O.
  * Called once during startup.
@@ -53,11 +39,6 @@
 void
 hubio_init(void)
 {
-#ifdef	LATER
-	/* This isn't needed unless we port the entire sio driver ... */
-        extern void early_brl1_port_init( void );
-	early_brl1_port_init();
-#endif
 }
 
 /* 
@@ -149,6 +130,10 @@
 	nasid_t nasid;
 	volatile hubreg_t junk;
 	unsigned long s;
+	caddr_t kvaddr;
+#ifdef PIOMAP_UNC_ACC_SPACE
+	uint64_t addr;
+#endif
 
 	/* sanity check */
 	if (byte_count_max > byte_count)
@@ -159,8 +144,19 @@
 	/* If xtalk_addr range is mapped by a small window, we don't have 
 	 * to do much 
 	 */
-	if (xtalk_addr + byte_count <= SWIN_SIZE)
-		return(hubinfo_swin_piomap_get(hubinfo, (int)widget));
+	if (xtalk_addr + byte_count <= SWIN_SIZE) {
+		hub_piomap_t piomap;
+
+		piomap = hubinfo_swin_piomap_get(hubinfo, (int)widget);
+#ifdef PIOMAP_UNC_ACC_SPACE
+		if (flags & PIOMAP_UNC_ACC) {
+			addr = (uint64_t)piomap->hpio_xtalk_info.xp_kvaddr;
+			addr |= PIOMAP_UNC_ACC_SPACE;
+			piomap->hpio_xtalk_info.xp_kvaddr = (caddr_t)addr;
+		}
+#endif
+		return piomap;
+	}
 
 	/* We need to use a big window mapping.  */
 
@@ -257,7 +253,15 @@
 	bw_piomap->hpio_xtalk_info.xp_dev = dev;
 	bw_piomap->hpio_xtalk_info.xp_target = widget;
 	bw_piomap->hpio_xtalk_info.xp_xtalk_addr = xtalk_addr;
-	bw_piomap->hpio_xtalk_info.xp_kvaddr = (caddr_t)NODE_BWIN_BASE(nasid, free_bw_index);
+	kvaddr = (caddr_t)NODE_BWIN_BASE(nasid, free_bw_index);
+#ifdef PIOMAP_UNC_ACC_SPACE
+	if (flags & PIOMAP_UNC_ACC) {
+		addr = (uint64_t)kvaddr;
+		addr |= PIOMAP_UNC_ACC_SPACE;
+		kvaddr = (caddr_t)addr;
+	}
+#endif
+	bw_piomap->hpio_xtalk_info.xp_kvaddr = kvaddr;
 	bw_piomap->hpio_holdcnt++;
 	bw_piomap->hpio_bigwin_num = free_bw_index;
 
@@ -378,12 +382,22 @@
 	devfs_handle_t hubv = xwidget_info_master_get(widget_info);
 	hub_piomap_t hub_piomap;
 	hubinfo_t hubinfo;
+	caddr_t addr;
 
 	hubinfo_get(hubv, &hubinfo);
 
 	if (xtalk_addr + byte_count <= SWIN_SIZE) {
 		hub_piomap = hubinfo_swin_piomap_get(hubinfo, (int)widget);
-		return(hub_piomap_addr(hub_piomap, xtalk_addr, byte_count));
+		addr = hub_piomap_addr(hub_piomap, xtalk_addr, byte_count);
+#ifdef PIOMAP_UNC_ACC_SPACE
+		if (flags & PIOMAP_UNC_ACC) {
+			uint64_t iaddr;
+			iaddr = (uint64_t)addr;
+			iaddr |= PIOMAP_UNC_ACC_SPACE;
+			addr = (caddr_t)iaddr;
+		}
+#endif
+		return(addr);
 	} else
 		return(0);
 }
@@ -392,19 +406,6 @@
 /* DMA MANAGEMENT */
 /* Mapping from crosstalk space to system physical space */
 
-/* 
- * There's not really very much to do here, since crosstalk maps
- * directly to system physical space.  It's quite possible that this
- * DMA layer will be bypassed in performance kernels.
- */
-
-
-/* ARGSUSED */
-void
-hub_dma_init(devfs_handle_t hubv)
-{
-}
-
 
 /*
  * Allocate resources needed to set up DMA mappings up to a specified size
@@ -478,7 +479,12 @@
 	}
 
 	/* There isn't actually any DMA mapping hardware on the hub. */
-	return(paddr);
+#ifdef CONFIG_IA64_SGI_SN2
+        return( (PHYS_TO_DMA(paddr)) );
+#else
+        /* no translation needed */
+        return(paddr);
+#endif
 }
 
 /*
@@ -549,8 +555,12 @@
 			size_t byte_count,	/* length */
 			unsigned flags)		/* defined in dma.h */
 {
+#ifdef CONFIG_IA64_SGI_SN2
+	return( (PHYS_TO_DMA(paddr)) );
+#else
 	/* no translation needed */
 	return(paddr);
+#endif
 }
 
 /*
@@ -565,6 +575,7 @@
 			alenlist_t palenlist,	/* system address/length list */
 			unsigned flags)		/* defined in dma.h */
 {
+	BUG();
 	/* no translation needed */
 	return(palenlist);
 }
@@ -603,11 +614,9 @@
 void
 hub_provider_startup(devfs_handle_t hubv)
 {
-	extern void hub_dma_init(devfs_handle_t hubv);
 	extern void hub_pio_init(devfs_handle_t hubv);
 
 	hub_pio_init(hubv);
-	hub_dma_init(hubv);
 	hub_intr_init(hubv);
 }
 
@@ -707,14 +716,12 @@
 {
 	iprb_t prb;
 	int prb_offset;
-#ifdef LATER
 	extern int force_fire_and_forget;
 	extern volatile int ignore_conveyor_override;
 
 	if (force_fire_and_forget && !ignore_conveyor_override)
 	    if (conveyor == HUB_PIO_CONVEYOR)
 		conveyor = HUB_PIO_FIRE_N_FORGET;
-#endif
 
 	/*
 	 * Get the current register value.
diff -Nru a/arch/ia64/sn/io/klgraph_hack.c b/arch/ia64/sn/io/klgraph_hack.c
--- a/arch/ia64/sn/io/klgraph_hack.c	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/sn/io/klgraph_hack.c	Mon Dec 23 21:21:55 2002
@@ -13,13 +13,16 @@
  * initial klgraph information that is normally provided by prom.
  */
 
+#include <linux/config.h>
 #include <linux/types.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <asm/sn/sgi.h>
 #include <asm/sn/io.h>
 #include <asm/sn/klconfig.h>
+#include <asm/sn/simulator.h>
 
+extern u64 klgraph_addr[];
 void * real_port;
 void * real_io_base;
 void * real_addr;
@@ -45,10 +48,15 @@
 #define HUBREG                  ((char *)0xc0000a0001e00000)
 #define WIDGET0                 ((char *)0xc0000a0000000000)
 
+#define convert(a,b,c) temp = (u64 *)a; *temp = b; temp++; *temp = c
+
 void
 klgraph_hack_init(void)
 {
 
+	u64     *temp;
+
+#ifdef CONFIG_IA64_SGI_SN1
 	/*
 	 * We need to know whether we are booting from PROM or 
 	 * boot from disk.
@@ -59,6 +67,139 @@
 	} else {
 		panic("klgraph_hack_init: Unable to locate KLCONFIG TABLE\n");
 	}
+
+	convert(0x0000000000030000, 0x00000000beedbabe, 0x0000004800000000);
+
+#else
+
+	if (IS_RUNNING_ON_SIMULATOR()) {
+		printk("Creating FAKE Klconfig Structure for Embeded Kernel\n");
+		klgraph_addr[0] = 0xe000003000030000;
+
+        /*
+         * klconfig entries initialization - mankato
+         */
+        convert(0xe000003000030000, 0x00000000beedbabe, 0x0000004800000000);
+        convert(0xe000003000030010, 0x0003007000000018, 0x800002000f820178);
+        convert(0xe000003000030020, 0x80000a000f024000, 0x800002000f800000);
+        convert(0xe000003000030030, 0x0300fafa00012580, 0x00000000040f0000);
+        convert(0xe000003000030040, 0x0000000000000000, 0x0003097000030070);
+        convert(0xe000003000030050, 0x00030970000303b0, 0x0003181000033f70);
+        convert(0xe000003000030060, 0x0003d51000037570, 0x0000000000038330);
+        convert(0xe000003000030070, 0x0203110100030140, 0x0001000000000101);
+        convert(0xe000003000030080, 0x0900000000000000, 0x000000004e465e67);
+        convert(0xe000003000030090, 0x0003097000000000, 0x00030b1000030a40);
+        convert(0xe0000030000300a0, 0x00030cb000030be0, 0x000315a0000314d0);
+        convert(0xe0000030000300b0, 0x0003174000031670, 0x0000000000000000);
+        convert(0xe000003000030100, 0x000000000000001a, 0x3350490000000000);
+        convert(0xe000003000030110, 0x0000000000000037, 0x0000000000000000);
+        convert(0xe000003000030140, 0x0002420100030210, 0x0001000000000101);
+        convert(0xe000003000030150, 0x0100000000000000, 0xffffffffffffffff);
+        convert(0xe000003000030160, 0x00030d8000000000, 0x0000000000030e50);
+        convert(0xe0000030000301c0, 0x0000000000000000, 0x0000000000030070);
+        convert(0xe0000030000301d0, 0x0000000000000025, 0x424f490000000000);
+        convert(0xe0000030000301e0, 0x000000004b434952, 0x0000000000000000);
+        convert(0xe000003000030210, 0x00027101000302e0, 0x00010000000e4101);
+        convert(0xe000003000030220, 0x0200000000000000, 0xffffffffffffffff);
+        convert(0xe000003000030230, 0x00030f2000000000, 0x0000000000030ff0);
+        convert(0xe000003000030290, 0x0000000000000000, 0x0000000000030140);
+        convert(0xe0000030000302a0, 0x0000000000000026, 0x7262490000000000);
+        convert(0xe0000030000302b0, 0x00000000006b6369, 0x0000000000000000);
+        convert(0xe0000030000302e0, 0x0002710100000000, 0x00010000000f3101);
+        convert(0xe0000030000302f0, 0x0500000000000000, 0xffffffffffffffff);
+        convert(0xe000003000030300, 0x000310c000000000, 0x0003126000031190);
+        convert(0xe000003000030310, 0x0003140000031330, 0x0000000000000000);
+        convert(0xe000003000030360, 0x0000000000000000, 0x0000000000030140);
+        convert(0xe000003000030370, 0x0000000000000029, 0x7262490000000000);
+        convert(0xe000003000030380, 0x00000000006b6369, 0x0000000000000000);
+        convert(0xe000003000030970, 0x0000000002010102, 0x0000000000000000);
+        convert(0xe000003000030980, 0x000000004e465e67, 0xffffffff00000000);
+        /* convert(0x00000000000309a0, 0x0000000000037570, 0x0000000100000000); */
+        convert(0xe0000030000309a0, 0x0000000000037570, 0xffffffff00000000);
+        convert(0xe0000030000309b0, 0x0000000000030070, 0x0000000000000000);
+        convert(0xe0000030000309c0, 0x000000000003f420, 0x0000000000000000);
+        convert(0xe000003000030a40, 0x0000000002010125, 0x0000000000000000);
+        convert(0xe000003000030a50, 0xffffffffffffffff, 0xffffffff00000000);
+        convert(0xe000003000030a70, 0x0000000000037b78, 0x0000000000000000);
+        convert(0xe000003000030b10, 0x0000000002010125, 0x0000000000000000);
+        convert(0xe000003000030b20, 0xffffffffffffffff, 0xffffffff00000000);
+        convert(0xe000003000030b40, 0x0000000000037d30, 0x0000000000000001);
+        convert(0xe000003000030be0, 0x00000000ff010203, 0x0000000000000000);
+        convert(0xe000003000030bf0, 0xffffffffffffffff, 0xffffffff000000ff);
+        convert(0xe000003000030c10, 0x0000000000037ee8, 0x0100010000000200);
+        convert(0xe000003000030cb0, 0x00000000ff310111, 0x0000000000000000);
+        convert(0xe000003000030cc0, 0xffffffffffffffff, 0x0000000000000000);
+        convert(0xe000003000030d80, 0x0000000002010104, 0x0000000000000000);
+        convert(0xe000003000030d90, 0xffffffffffffffff, 0x00000000000000ff);
+        convert(0xe000003000030db0, 0x0000000000037f18, 0x0000000000000000);
+        convert(0xe000003000030dc0, 0x0000000000000000, 0x0003007000060000);
+        convert(0xe000003000030de0, 0x0000000000000000, 0x0003021000050000);
+        convert(0xe000003000030df0, 0x000302e000050000, 0x0000000000000000);
+        convert(0xe000003000030e30, 0x0000000000000000, 0x000000000000000a);
+        convert(0xe000003000030e50, 0x00000000ff00011a, 0x0000000000000000);
+        convert(0xe000003000030e60, 0xffffffffffffffff, 0x0000000000000000);
+        convert(0xe000003000030e80, 0x0000000000037fe0, 0x9e6e9e9e9e9e9e9e);
+        convert(0xe000003000030e90, 0x000000000000bc6e, 0x0000000000000000);
+        convert(0xe000003000030f20, 0x0000000002010205, 0x00000000d0020000);
+        convert(0xe000003000030f30, 0xffffffffffffffff, 0x0000000e0000000e);
+        convert(0xe000003000030f40, 0x000000000000000e, 0x0000000000000000);
+        convert(0xe000003000030f50, 0x0000000000038010, 0x00000000000007ff);
+        convert(0xe000003000030f70, 0x0000000000000000, 0x0000000022001077);
+        convert(0xe000003000030fa0, 0x0000000000000000, 0x000000000003f4a8);
+        convert(0xe000003000030ff0, 0x0000000000310120, 0x0000000000000000);
+        convert(0xe000003000031000, 0xffffffffffffffff, 0xffffffff00000002);
+        convert(0xe000003000031010, 0x000000000000000e, 0x0000000000000000);
+        convert(0xe000003000031020, 0x0000000000038088, 0x0000000000000000);
+        convert(0xe0000030000310c0, 0x0000000002010205, 0x00000000d0020000);
+        convert(0xe0000030000310d0, 0xffffffffffffffff, 0x0000000f0000000f);
+        convert(0xe0000030000310e0, 0x000000000000000f, 0x0000000000000000);
+        convert(0xe0000030000310f0, 0x00000000000380b8, 0x00000000000007ff);
+        convert(0xe000003000031120, 0x0000000022001077, 0x00000000000310a9);
+        convert(0xe000003000031130, 0x00000000580211c1, 0x000000008009104c);
+        convert(0xe000003000031140, 0x0000000000000000, 0x000000000003f4c0);
+        convert(0xe000003000031190, 0x0000000000310120, 0x0000000000000000);
+        convert(0xe0000030000311a0, 0xffffffffffffffff, 0xffffffff00000003);
+        convert(0xe0000030000311b0, 0x000000000000000f, 0x0000000000000000);
+        convert(0xe0000030000311c0, 0x0000000000038130, 0x0000000000000000);
+        convert(0xe000003000031260, 0x0000000000110106, 0x0000000000000000);
+        convert(0xe000003000031270, 0xffffffffffffffff, 0xffffffff00000004);
+        convert(0xe000003000031270, 0xffffffffffffffff, 0xffffffff00000004);
+        convert(0xe000003000031280, 0x000000000000000f, 0x0000000000000000);
+        convert(0xe0000030000312a0, 0x00000000ff110013, 0x0000000000000000);
+        convert(0xe0000030000312b0, 0xffffffffffffffff, 0xffffffff00000000);
+        convert(0xe0000030000312c0, 0x000000000000000f, 0x0000000000000000);
+        convert(0xe0000030000312e0, 0x0000000000110012, 0x0000000000000000);
+        convert(0xe0000030000312f0, 0xffffffffffffffff, 0xffffffff00000000);
+        convert(0xe000003000031300, 0x000000000000000f, 0x0000000000000000);
+        convert(0xe000003000031310, 0x0000000000038160, 0x0000000000000000);
+        convert(0xe000003000031330, 0x00000000ff310122, 0x0000000000000000);
+        convert(0xe000003000031340, 0xffffffffffffffff, 0xffffffff00000005);
+        convert(0xe000003000031350, 0x000000000000000f, 0x0000000000000000);
+        convert(0xe000003000031360, 0x0000000000038190, 0x0000000000000000);
+        convert(0xe000003000031400, 0x0000000000310121, 0x0000000000000000);
+        convert(0xe000003000031400, 0x0000000000310121, 0x0000000000000000);
+        convert(0xe000003000031410, 0xffffffffffffffff, 0xffffffff00000006);
+        convert(0xe000003000031420, 0x000000000000000f, 0x0000000000000000);
+        convert(0xe000003000031430, 0x00000000000381c0, 0x0000000000000000);
+        convert(0xe0000030000314d0, 0x00000000ff010201, 0x0000000000000000);
+        convert(0xe0000030000314e0, 0xffffffffffffffff, 0xffffffff00000000);
+        convert(0xe000003000031500, 0x00000000000381f0, 0x000030430000ffff);
+        convert(0xe000003000031510, 0x000000000000ffff, 0x0000000000000000);
+        convert(0xe0000030000315a0, 0x00000020ff000201, 0x0000000000000000);
+        convert(0xe0000030000315b0, 0xffffffffffffffff, 0xffffffff00000001);
+        convert(0xe0000030000315d0, 0x0000000000038240, 0x00003f3f0000ffff);
+        convert(0xe0000030000315e0, 0x000000000000ffff, 0x0000000000000000);
+        convert(0xe000003000031670, 0x00000000ff010201, 0x0000000000000000);
+        convert(0xe000003000031680, 0xffffffffffffffff, 0x0000000100000002);
+        convert(0xe0000030000316a0, 0x0000000000038290, 0x000030430000ffff);
+        convert(0xe0000030000316b0, 0x000000000000ffff, 0x0000000000000000);
+        convert(0xe000003000031740, 0x00000020ff000201, 0x0000000000000000);
+        convert(0xe000003000031750, 0xffffffffffffffff, 0x0000000500000003);
+        convert(0xe000003000031770, 0x00000000000382e0, 0x00003f3f0000ffff);
+        convert(0xe000003000031780, 0x000000000000ffff, 0x0000000000000000);
+}
+
+#endif
 
 }
 
diff -Nru a/arch/ia64/sn/io/labelcl.c b/arch/ia64/sn/io/labelcl.c
--- a/arch/ia64/sn/io/labelcl.c	Mon Dec 23 21:21:53 2002
+++ b/arch/ia64/sn/io/labelcl.c	Mon Dec 23 21:21:53 2002
@@ -4,7 +4,7 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (c) 2001 Silicon Graphics, Inc.  All rights reserved.
+ * Copyright (c) 2001-2002 Silicon Graphics, Inc.  All rights reserved.
 */
 
 #include <linux/types.h>
diff -Nru a/arch/ia64/sn/io/pci.c b/arch/ia64/sn/io/pci.c
--- a/arch/ia64/sn/io/pci.c	Mon Dec 23 21:21:52 2002
+++ b/arch/ia64/sn/io/pci.c	Mon Dec 23 21:21:52 2002
@@ -6,7 +6,7 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (c) 1997, 1998, 2000-2001 Silicon Graphics, Inc.  All rights reserved.
+ * Copyright (c) 1997, 1998, 2000-2002 Silicon Graphics, Inc.  All rights reserved.
  */
 #include <linux/init.h>
 #include <linux/types.h>
@@ -44,21 +44,22 @@
 extern devfs_handle_t devfn_to_vertex(unsigned char bus, unsigned char devfn);
 
 /*
- * snia64_read - Read from the config area of the device.
+ * snia64_read_config_byte - Read a byte from the config area of the device.
  */
-static int snia64_read (struct pci_bus *bus, unsigned char devfn,
-                                   int where, int size, unsigned char *val)
+static int snia64_read_config_byte (struct pci_dev *dev,
+                                   int where, unsigned char *val)
 {
 	unsigned long res = 0;
+	unsigned size = 1;
 	devfs_handle_t device_vertex;
 
-	if ( (bus == NULL) || (val == (unsigned char *)0) ) {
+	if ( (dev == (struct pci_dev *)0) || (val == (unsigned char *)0) ) {
 		return PCIBIOS_DEVICE_NOT_FOUND;
 	}
-	device_vertex = devfn_to_vertex(bus->number, devfn);
+	device_vertex = devfn_to_vertex(dev->bus->number, dev->devfn);
 	if (!device_vertex) {
 		DBG("%s : nonexistent device: bus= 0x%x  slot= 0x%x  func= 0x%x\n", 
-		__FUNCTION__, bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
+		__FUNCTION__, dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
 		return(-1);
 	}
 	res = pciio_config_get(device_vertex, (unsigned) where, size);
@@ -67,49 +68,169 @@
 }
 
 /*
- * snia64_write - Writes to the config area of the device.
+ * snia64_read_config_word - Read 2 bytes from the config area of the device.
  */
-static int snia64_write (struct pci_bus *bus, unsigned char devfn,
-                                    int where, int size, unsigned char val)
+static int snia64_read_config_word (struct pci_dev *dev,
+                                   int where, unsigned short *val)
 {
+	unsigned long res = 0;
+	unsigned size = 2; /* 2 bytes */
 	devfs_handle_t device_vertex;
 
-	if ( bus == NULL) {
+	if ( (dev == (struct pci_dev *)0) || (val == (unsigned short *)0) ) {
+		return PCIBIOS_DEVICE_NOT_FOUND;
+	}
+	device_vertex = devfn_to_vertex(dev->bus->number, dev->devfn);
+	if (!device_vertex) {
+		DBG("%s : nonexistent device: bus= 0x%x  slot= 0x%x  func= 0x%x\n", 
+		__FUNCTION__, dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
+		return(-1);
+	}
+	res = pciio_config_get(device_vertex, (unsigned) where, size);
+	*val = (unsigned short) res;
+	return PCIBIOS_SUCCESSFUL;
+}
+
+/*
+ * snia64_read_config_dword - Read 4 bytes from the config area of the device.
+ */
+static int snia64_read_config_dword (struct pci_dev *dev,
+                                    int where, unsigned int *val)
+{
+	unsigned long res = 0;
+	unsigned size = 4; /* 4 bytes */
+	devfs_handle_t device_vertex;
+
+	if (where & 3) {
+		return PCIBIOS_BAD_REGISTER_NUMBER;
+	}
+	if ( (dev == (struct pci_dev *)0) || (val == (unsigned int *)0) ) {
+		return PCIBIOS_DEVICE_NOT_FOUND;
+	}
+
+	device_vertex = devfn_to_vertex(dev->bus->number, dev->devfn);
+	if (!device_vertex) {
+		DBG("%s : nonexistent device: bus= 0x%x  slot= 0x%x  func= 0x%x\n", 
+		__FUNCTION__, dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
+		return(-1);
+	}
+	res = pciio_config_get(device_vertex, (unsigned) where, size);
+	*val = (unsigned int) res;
+	return PCIBIOS_SUCCESSFUL;
+}
+
+/*
+ * snia64_write_config_byte - Writes 1 byte to the config area of the device.
+ */
+static int snia64_write_config_byte (struct pci_dev *dev,
+                                    int where, unsigned char val)
+{
+	devfs_handle_t device_vertex;
+
+	if ( dev == (struct pci_dev *)0 ) {
 		return PCIBIOS_DEVICE_NOT_FOUND;
 	}
 	/* 
 	 * if it's an IOC3 then we bail out, we special
 	 * case them with pci_fixup_ioc3
 	 */
-	/* Starting 2.5.32 struct pci_dev is not passed down */
-	/*if (dev->vendor == PCI_VENDOR_ID_SGI && 
+	if (dev->vendor == PCI_VENDOR_ID_SGI && 
 	    dev->device == PCI_DEVICE_ID_SGI_IOC3 )
 		return PCIBIOS_SUCCESSFUL;
-	*/
 
-	device_vertex = devfn_to_vertex(bus->number, devfn);
+	device_vertex = devfn_to_vertex(dev->bus->number, dev->devfn);
+	if (!device_vertex) {
+		DBG("%s : nonexistent device: bus= 0x%x  slot= 0x%x  func= 0x%x\n", 
+		__FUNCTION__, dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
+		return(-1);
+	}
+	pciio_config_set( device_vertex, (unsigned)where, 1, (uint64_t) val);
+
+	return PCIBIOS_SUCCESSFUL;
+}
+
+/*
+ * snia64_write_config_word - Writes 2 bytes to the config area of the device.
+ */
+static int snia64_write_config_word (struct pci_dev *dev,
+                                    int where, unsigned short val)
+{
+	devfs_handle_t device_vertex = NULL;
+
+	if (where & 1) {
+		return PCIBIOS_BAD_REGISTER_NUMBER;
+	}
+	if ( dev == (struct pci_dev *)0 ) {
+		return PCIBIOS_DEVICE_NOT_FOUND;
+	}
+	/* 
+	 * if it's an IOC3 then we bail out, we special
+	 * case them with pci_fixup_ioc3
+	 */
+	if (dev->vendor == PCI_VENDOR_ID_SGI && 
+	    dev->device == PCI_DEVICE_ID_SGI_IOC3)
+		return PCIBIOS_SUCCESSFUL;
+
+	device_vertex = devfn_to_vertex(dev->bus->number, dev->devfn);
 	if (!device_vertex) {
 		DBG("%s : nonexistent device: bus= 0x%x  slot= 0x%x  func= 0x%x\n", 
-		__FUNCTION__, bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
+		__FUNCTION__, dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
 		return(-1);
 	}
-	pciio_config_set( device_vertex, (unsigned)where, size, (uint64_t) val);
+	pciio_config_set( device_vertex, (unsigned)where, 2, (uint64_t) val);
+
+	return PCIBIOS_SUCCESSFUL;
+}
+
+/*
+ * snia64_write_config_dword - Writes 4 bytes to the config area of the device.
+ */
+static int snia64_write_config_dword (struct pci_dev *dev,
+                                     int where, unsigned int val)
+{
+	devfs_handle_t device_vertex;
+
+	if (where & 3) {
+		return PCIBIOS_BAD_REGISTER_NUMBER;
+	}
+	if ( dev == (struct pci_dev *)0 ) {
+		return PCIBIOS_DEVICE_NOT_FOUND;
+	}
+	/* 
+	 * if it's an IOC3 then we bail out, we special
+	 * case them with pci_fixup_ioc3
+	 */
+	if (dev->vendor == PCI_VENDOR_ID_SGI && 
+	    dev->device == PCI_DEVICE_ID_SGI_IOC3)
+		return PCIBIOS_SUCCESSFUL;
+
+	device_vertex = devfn_to_vertex(dev->bus->number, dev->devfn);
+	if (!device_vertex) {
+		DBG("%s : nonexistent device: bus= 0x%x  slot= 0x%x  func= 0x%x\n", 
+		__FUNCTION__, dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
+		return(-1);
+	}
+	pciio_config_set( device_vertex, (unsigned)where, 4, (uint64_t) val);
 
 	return PCIBIOS_SUCCESSFUL;
 }
 
 static struct pci_ops snia64_pci_ops = {
-	.read =		snia64_read,
-	.write = 	snia64_write,
+	snia64_read_config_byte,
+	snia64_read_config_word,
+	snia64_read_config_dword,
+	snia64_write_config_byte,
+	snia64_write_config_word,
+	snia64_write_config_dword
 };
 
 /*
  * snia64_pci_find_bios - SNIA64 pci_find_bios() platform specific code.
  */
 void __init
-sn1_pci_find_bios(void)
+sn_pci_find_bios(void)
 {
-	extern struct pci_ops pci_conf;
+	extern struct pci_ops *pci_root_ops;
 	/*
 	 * Go initialize our IO Infrastructure ..
 	 */
@@ -117,8 +238,8 @@
 
 	sgi_master_io_infr_init();
 
-	/* sn1_io_infrastructure_init(); */
-	pci_conf = snia64_pci_ops;
+	/* sn_io_infrastructure_init(); */
+	pci_root_ops = &snia64_pci_ops;
 }
 
 void
@@ -155,22 +276,16 @@
                 d->resource[i].flags = 0UL;
         }
 
-	/*
-	 * Hardcode Device 4 register(IOC3 is in Slot 4) to set the 
-	 * DEV_DIRECT bit.  This will not work if IOC3 is not on Slot 
-	 * 4.
-	 */
-	DBG("pci_fixup_ioc3: FIXME .. need to take NASID into account when setting IOC3 devreg 0x%x\n", *(volatile u32 *)0xc0000a000f000220);
-
- 	*(volatile u32 *)0xc0000a000f000220 |= 0x90000; 
-
+#ifdef CONFIG_IA64_SGI_SN1
+	*(volatile u32 *)0xc0000a000f000220 |= 0x90000;
+#endif
         d->subsystem_vendor = 0;
         d->subsystem_device = 0;
 
 }
 
 #else
-void sn1_pci_find_bios(void) {}
+void sn_pci_find_bios(void) {}
 void pci_fixup_ioc3(struct pci_dev *d) {}
 struct list_head pci_root_buses;
 struct list_head pci_root_buses;
diff -Nru a/arch/ia64/sn/io/pci_dma.c b/arch/ia64/sn/io/pci_dma.c
--- a/arch/ia64/sn/io/pci_dma.c	Mon Dec 23 21:21:52 2002
+++ b/arch/ia64/sn/io/pci_dma.c	Mon Dec 23 21:21:52 2002
@@ -9,6 +9,7 @@
  * a description of how these routines should be used.
  */
 
+#include <linux/config.h>
 #include <linux/types.h>
 #include <linux/mm.h>
 #include <linux/string.h>
@@ -31,232 +32,316 @@
 #include <asm/sn/pci/pci_bus_cvlink.h>
 #include <asm/sn/nag.h>
 
+/*
+ * For ATE allocations
+ */
 pciio_dmamap_t get_free_pciio_dmamap(devfs_handle_t);
 void free_pciio_dmamap(pcibr_dmamap_t);
-struct sn1_dma_maps_s *find_sn1_dma_map(dma_addr_t, unsigned char);
+static struct sn_dma_maps_s *find_sn_dma_map(dma_addr_t, unsigned char);
+
+/*
+ * Toplogy stuff
+ */
 extern devfs_handle_t busnum_to_pcibr_vhdl[];
 extern nasid_t busnum_to_nid[];
 extern void * busnum_to_atedmamaps[];
 
-/*
- * Get a free pciio_dmamap_t entry.
+/**
+ * get_free_pciio_dmamap - find and allocate an ATE
+ * @pci_bus: PCI bus to get an entry for
+ *
+ * Finds and allocates an ATE on the PCI bus specified
+ * by @pci_bus.
  */
 pciio_dmamap_t
 get_free_pciio_dmamap(devfs_handle_t pci_bus)
 {
 	int i;
-	struct sn1_dma_maps_s *sn1_dma_map = NULL;
+	struct sn_dma_maps_s *sn_dma_map = NULL;
 
 	/*
 	 * Darn, we need to get the maps allocated for this bus.
 	 */
 	for (i = 0; i < MAX_PCI_XWIDGET; i++) {
 		if (busnum_to_pcibr_vhdl[i] == pci_bus) {
-			sn1_dma_map = busnum_to_atedmamaps[i];
+			sn_dma_map = busnum_to_atedmamaps[i];
 		}
 	}
 
 	/*
 	 * Now get a free dmamap entry from this list.
 	 */
-	for (i=0; i<MAX_ATE_MAPS; i++, sn1_dma_map++) {
-		if (!sn1_dma_map->dma_addr) {
-			sn1_dma_map->dma_addr = -1;
-			return( (pciio_dmamap_t) sn1_dma_map );
+	for (i = 0; i < MAX_ATE_MAPS; i++, sn_dma_map++) {
+		if (!sn_dma_map->dma_addr) {
+			sn_dma_map->dma_addr = -1;
+			return( (pciio_dmamap_t) sn_dma_map );
 		}
 	}
 
-	return(NULL);
-
+	return NULL;
 }
 
-/*
- * Free pciio_dmamap_t entry.
+/**
+ * free_pciio_dmamap - free an ATE
+ * @dma_map: ATE to free
+ *
+ * Frees the ATE specified by @dma_map.
  */
 void
 free_pciio_dmamap(pcibr_dmamap_t dma_map)
 {
-	struct sn1_dma_maps_s *sn1_dma_map;
+	struct sn_dma_maps_s *sn_dma_map;
+
+	sn_dma_map = (struct sn_dma_maps_s *) dma_map;
+	sn_dma_map->dma_addr = 0;
+}
+
+/**
+ * find_sn_dma_map - find an ATE associated with @dma_addr and @busnum
+ * @dma_addr: DMA address to look for
+ * @busnum: PCI bus to look on
+ *
+ * Finds the ATE associated with @dma_addr and @busnum.
+ */
+static struct sn_dma_maps_s *
+find_sn_dma_map(dma_addr_t dma_addr, unsigned char busnum)
+{
 
-	sn1_dma_map = (struct sn1_dma_maps_s *) dma_map;
-	sn1_dma_map->dma_addr = 0;
+	struct sn_dma_maps_s *sn_dma_map = NULL;
+	int i;
+
+	sn_dma_map = busnum_to_atedmamaps[busnum];
+
+	for (i = 0; i < MAX_ATE_MAPS; i++, sn_dma_map++) {
+		if (sn_dma_map->dma_addr == dma_addr) {
+			return sn_dma_map;
+		}
+	}
 
+	return NULL;
 }
 
-/*
- * sn_dma_sync: This routine flushes all DMA buffers for the device into the II.
- *	This does not mean that the data is in the "Coherence Domain".  But it 
- *	is very close.
+/**
+ * sn_dma_sync - try to flush DMA buffers into the coherence domain
+ * @hwdev: device to flush
+ *
+ * This routine flushes all DMA buffers for the device into the II of
+ * the destination hub.
+ *
+ * NOTE!: this does not mean that the data is in the "coherence domain",
+ * but it is very close.  In other words, this routine *does not work*
+ * as advertised due to hardware bugs.  That said, it should be good enough for
+ * most situations.
  */
 void
-sn_dma_sync( struct pci_dev *hwdev )
+sn_dma_sync(struct pci_dev *hwdev)
 {
 
-	struct sn1_device_sysdata *device_sysdata;
+#ifdef SN_DMA_SYNC
+
+	struct sn_device_sysdata *device_sysdata;
 	volatile unsigned long dummy;
 
 	/*
-	 * It is expected that on IA64 platform, a DMA sync ensures that all 
-	 * the DMA (dma_handle) are complete and coherent.
-	 *	1. Flush Write Buffers from Bridge.
-	 *	2. Flush Xbow Port.
+	 * A DMA sync is supposed to ensure that 
+	 * all the DMA from a particular device
+	 * is complete and coherent.  We
+	 * try to do this by
+	 *	1. flushing the write wuffers from Bridge
+	 *	2. flushing the Xbow port.
+	 * Unfortunately, this only gets the DMA transactions 'very close' to
+	 * the coherence domain, but not quite in it.
 	 */
-	device_sysdata = (struct sn1_device_sysdata *)hwdev->sysdata;
+	device_sysdata = (struct sn_device_sysdata *)hwdev->sysdata;
 	dummy = (volatile unsigned long ) *device_sysdata->dma_buf_sync;
 
 	/*
-	 * For the Xbow Port flush, we maybe denied the request because 
-	 * someone else may be flushing the Port .. try again.
+	 * For the Xbow port flush, we may be denied the request because 
+	 * someone else may be flushing the port .. try again.
 	 */
 	while((volatile unsigned long ) *device_sysdata->xbow_buf_sync) {
 		udelay(2);
 	}
+#endif
 }
 
-
-struct sn1_dma_maps_s *
-find_sn1_dma_map(dma_addr_t dma_addr, unsigned char busnum)
-{
-
-	struct sn1_dma_maps_s *sn1_dma_map = NULL;
-	int i;
-
-	sn1_dma_map = busnum_to_atedmamaps[busnum];
-
-	for (i=0; i<MAX_ATE_MAPS; i++, sn1_dma_map++) {
-		if (sn1_dma_map->dma_addr == dma_addr) {
-			return( sn1_dma_map );
-		}
-	}
-
-printk("find_pciio_dmamap: Unable find the corresponding dma map\n");
-
-	return(NULL);
-
-}
-
-/*
- * sn1 platform specific pci_alloc_consistent()
+/**
+ * sn_pci_alloc_consistent - allocate memory for coherent DMA
+ * @hwdev: device to allocate for
+ * @size: size of the region
+ * @dma_handle: DMA (bus) address
+ *
+ * pci_alloc_consistent() returns a pointer to a memory region suitable for
+ * coherent DMA traffic to/from a PCI device.  On SN platforms, this means
+ * that @dma_handle will have the %PCIIO_DMA_CMD flag set.
+ *
+ * This interface is usually used for "command" streams (e.g. the command
+ * queue for a SCSI controller).  See Documentation/DMA-mapping.txt for
+ * more information.  Note that this routine will always put a 32 bit
+ * DMA address into @dma_handle.  This is because most devices
+ * that are capable of 64 bit PCI DMA transactions can't do 64 bit _coherent_
+ * DMAs, and unfortunately this interface has to cater to the LCD.  Oh well.
  *
- * this interface is meant for "command" streams, i.e. called only
- * once for initializing a device, so we don't want prefetching or
- * write gathering turned on, hence the PCIIO_DMA_CMD flag
+ * Also known as platform_pci_alloc_consistent() by the IA64 machvec code.
  */
 void *
-sn1_pci_alloc_consistent (struct pci_dev *hwdev, size_t size, dma_addr_t *dma_handle)
+sn_pci_alloc_consistent(struct pci_dev *hwdev, size_t size, dma_addr_t *dma_handle)
 {
-        void *ret;
-        int gfp = GFP_ATOMIC;
-	devfs_handle_t    vhdl;
-	struct sn1_device_sysdata *device_sysdata;
-	paddr_t temp_ptr;
+        void *cpuaddr;
+	devfs_handle_t vhdl;
+	struct sn_device_sysdata *device_sysdata;
+	unsigned long phys_addr;
+	pciio_dmamap_t dma_map = 0;
+	struct sn_dma_maps_s *sn_dma_map;
 
-	*dma_handle = (dma_addr_t) NULL;
+	*dma_handle = 0;
+
+	/* We can't easily support < 32 bit devices */
+	if (IS_PCI32L(hwdev))
+		return NULL;
 
 	/*
-	 * get vertex for the device
+	 * Get hwgraph vertex for the device
 	 */
-	device_sysdata = (struct sn1_device_sysdata *) hwdev->sysdata;
+	device_sysdata = (struct sn_device_sysdata *) hwdev->sysdata;
 	vhdl = device_sysdata->vhdl;
 
-        if ( (ret = (void *)__get_free_pages(gfp, get_order(size))) ) {
-		memset(ret, 0, size);
-	} else {
-		return(NULL);
-	}
+	/*
+	 * Allocate the memory.  FIXME: if we're allocating for
+	 * two devices on the same bus, we should at least try to
+	 * allocate memory in the same 2 GB window to avoid using
+	 * ATEs for the translation.  See the comment above about the
+	 * 32 bit requirement for this function.
+	 */
+	if(!(cpuaddr = (void *)__get_free_pages(GFP_ATOMIC, get_order(size))))
+		return NULL;
 
-	temp_ptr = (paddr_t) __pa(ret);
-	if (IS_PCIA64(hwdev)) {
+	memset(cpuaddr, 0, size); /* have to zero it out */
 
-		/*
-		 * This device supports 64bits DMA addresses.
-		 */
+	/* physical addr. of the memory we just got */
+	phys_addr = __pa(cpuaddr);
+
+	/*
+	 * This will try to use a Direct Map register to do the
+	 * 32 bit DMA mapping, but it may not succeed if another
+	 * device on the same bus is already mapped with different
+	 * attributes or to a different memory region.
+	 */
 #ifdef CONFIG_IA64_SGI_SN1
-		*dma_handle = pciio_dmatrans_addr(vhdl, NULL, temp_ptr, size,
-			PCIBR_BARRIER | PCIIO_BYTE_STREAM | PCIIO_DMA_CMD
-			| PCIIO_DMA_A64 );
-#else /* SN2 */
-		*dma_handle = pciio_dmatrans_addr(vhdl, NULL, temp_ptr, size,
-			PCIBR_BARRIER | PCIIO_DMA_CMD | PCIIO_DMA_A64 );
+	*dma_handle = pciio_dmatrans_addr(vhdl, NULL, phys_addr, size,
+					  PCIIO_BYTE_STREAM |
+					  PCIIO_DMA_CMD);
+#elif defined(CONFIG_IA64_SGI_SN2)
+	*dma_handle = pciio_dmatrans_addr(vhdl, NULL, phys_addr, size,
+			((IS_PIC_DEVICE(hwdev)) ? 0 : PCIIO_BYTE_STREAM) |
+					  PCIIO_DMA_CMD);
+#else
+#error unsupported platform
 #endif
 
-		return (ret);
-	}
-
 	/*
-	 * Devices that supports 32 Bits upto 63 Bits DMA Address gets
-	 * 32 Bits DMA addresses.
-	 *
-	 * First try to get 32 Bit Direct Map Support.
+	 * It is a 32 bit card and we cannot do direct mapping,
+	 * so we try to use an ATE.
 	 */
-	if (IS_PCI32G(hwdev)) {
+	if (!(*dma_handle)) {
 #ifdef CONFIG_IA64_SGI_SN1
-		*dma_handle = pciio_dmatrans_addr(vhdl, NULL, temp_ptr, size,
-			PCIBR_BARRIER | PCIIO_BYTE_STREAM | PCIIO_DMA_CMD);
-#else /* SN2 */
-		*dma_handle = pciio_dmatrans_addr(vhdl, NULL, temp_ptr, size,
-			PCIBR_BARRIER | PCIIO_DMA_CMD);
+		dma_map = pciio_dmamap_alloc(vhdl, NULL, size,
+					     PCIIO_BYTE_STREAM |
+					     PCIIO_DMA_CMD);
+#elif defined(CONFIG_IA64_SGI_SN2)
+		dma_map = pciio_dmamap_alloc(vhdl, NULL, size,
+				((IS_PIC_DEVICE(hwdev)) ? 0 : PCIIO_BYTE_STREAM) |
+					     PCIIO_DMA_CMD);
+#else
+#error unsupported platform
 #endif
-
-		if (dma_handle) {
-			return (ret);
-		} else {
-			/*
-			 * We need to map this request by using ATEs.
-			 */
-			printk("sn1_pci_alloc_consistent: 32Bits DMA Page Map support not available yet!");
+		if (!dma_map) {
+			printk(KERN_ERR "sn_pci_alloc_consistent: Unable to "
+			       "allocate anymore 32 bit page map entries.\n");
 			BUG();
 		}
+		*dma_handle = (dma_addr_t) pciio_dmamap_addr(dma_map,phys_addr,
+							     size);
+		sn_dma_map = (struct sn_dma_maps_s *)dma_map;
+		sn_dma_map->dma_addr = *dma_handle;
 	}
 
-	if (IS_PCI32L(hwdev)) {
-		/*
-		 * SNIA64 cannot support DMA Addresses smaller than 32 bits.
-		 */
-		return (NULL);
-	}
-
-        return NULL;
+        return cpuaddr;
 }
 
+/**
+ * sn_pci_free_consistent - free memory associated with coherent DMAable region
+ * @hwdev: device to free for
+ * @size: size to free
+ * @vaddr: kernel virtual address to free
+ * @dma_handle: DMA address associated with this region
+ *
+ * Frees the memory allocated by pci_alloc_consistent().  Also known
+ * as platform_pci_free_consistent() by the IA64 machvec code.
+ */
 void
-sn1_pci_free_consistent(struct pci_dev *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle)
+sn_pci_free_consistent(struct pci_dev *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle)
 {
+	struct sn_dma_maps_s *sn_dma_map = NULL;
+
+	/*
+	 * Get the sn_dma_map entry.
+	 */
+	if (IS_PCI32_MAPPED(dma_handle))
+		sn_dma_map = find_sn_dma_map(dma_handle, hwdev->bus->number);
+
+	/*
+	 * and free it if necessary...
+	 */
+	if (sn_dma_map) {
+		pciio_dmamap_done((pciio_dmamap_t)sn_dma_map);
+		pciio_dmamap_free((pciio_dmamap_t)sn_dma_map);
+		sn_dma_map->dma_addr = (dma_addr_t)NULL;
+	}
 	free_pages((unsigned long) vaddr, get_order(size));
 }
 
-/*
- * On sn1 we use the page entry of the scatterlist to store
- * the physical address corresponding to the given virtual address
+/**
+ * sn_pci_map_sg - map a scatter-gather list for DMA
+ * @hwdev: device to map for
+ * @sg: scatterlist to map
+ * @nents: number of entries
+ * @direction: direction of the DMA transaction
+ *
+ * Maps each entry of @sg for DMA.  Also known as platform_pci_map_sg by the
+ * IA64 machvec code.
  */
 int
-sn1_pci_map_sg (struct pci_dev *hwdev,
-                        struct scatterlist *sg, int nents, int direction)
+sn_pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg, int nents, int direction)
 {
 
 	int i;
-	devfs_handle_t	vhdl;
+	devfs_handle_t vhdl;
 	dma_addr_t dma_addr;
-	paddr_t temp_ptr;
-	struct sn1_device_sysdata *device_sysdata;
+	unsigned long phys_addr;
+	struct sn_device_sysdata *device_sysdata;
 	pciio_dmamap_t dma_map;
 
-
-
+	/* can't go anywhere w/o a direction in life */
 	if (direction == PCI_DMA_NONE)
 		BUG();
 
 	/*
-	 * Handle 64 bit cards.
+	 * Get the hwgraph vertex for the device
 	 */
-	device_sysdata = (struct sn1_device_sysdata *) hwdev->sysdata;
+	device_sysdata = (struct sn_device_sysdata *) hwdev->sysdata;
 	vhdl = device_sysdata->vhdl;
+
+	/*
+	 * Setup a DMA address for each entry in the
+	 * scatterlist.
+	 */
 	for (i = 0; i < nents; i++, sg++) {
 		/* this catches incorrectly written drivers that
                    attempt to map scatterlists that they have
                    previously mapped.  we print a warning and
                    continue, but the driver should be fixed */
-		switch (((u64)sg->address) >> 60) {
+		switch (((u64)sg->dma_address) >> 60) {
 		case 0xa:
 		case 0xb:
 #ifdef DEBUG
@@ -264,54 +349,53 @@
 			NAG("A PCI driver (for device at%8s) has attempted to "
 			    "map a scatterlist that was previously mapped at "
 			    "%p - this is currently being worked around.\n",
-			    hwdev->slot_name, (void *)sg->address);
-#endif
-			temp_ptr = (u64)sg->address & TO_PHYS_MASK;
+			    hwdev->slot_name, (void *)sg->dma_address);
+			phys_addr = (u64)sg->dma_address & TO_PHYS_MASK;
 			break;
-		case 0xe: /* a good address, we now map it. */
-			temp_ptr = (paddr_t) __pa(sg->address);
+#endif
+		default: /* not previously mapped, get the phys. addr */
+			phys_addr = __pa(sg->dma_address);
 			break;
-		default:
-			printk(KERN_ERR
-			       "Very bad address (%p) passed to sn1_pci_map_sg\n",
-			       (void *)sg->address);
-			BUG();
 		}
-		sg->page = (char *)NULL;
+		sg->page = NULL;
 		dma_addr = 0;
 
 		/*
-		 * Handle the most common case 64Bit cards.
+		 * Handle the most common case: 64 bit cards.  This
+		 * call should always succeed.
 		 */
 		if (IS_PCIA64(hwdev)) {
-#ifdef CONFIG_IA64_SGI_SN1
-			dma_addr = (dma_addr_t) pciio_dmatrans_addr(vhdl, NULL,
-				temp_ptr, sg->length,
-				PCIIO_BYTE_STREAM | PCIIO_DMA_DATA |
-				PCIIO_DMA_A64 );
-#else
-			dma_addr = (dma_addr_t) pciio_dmatrans_addr(vhdl, NULL,
-				temp_ptr, sg->length,
-				PCIIO_DMA_DATA | PCIIO_DMA_A64 );
-#endif
-			sg->address = (char *)dma_addr;
+			dma_addr = pciio_dmatrans_addr(vhdl, NULL, phys_addr,
+						       sg->length,
+			       ((IS_PIC_DEVICE(hwdev)) ? 0 : PCIIO_BYTE_STREAM) |
+						       PCIIO_DMA_DATA |
+						       PCIIO_DMA_A64);
+			sg->dma_address = (char *)dma_addr;
 			continue;
 		}
 
 		/*
-		 * Handle 32Bits and greater cards.
+		 * Handle 32-63 bit cards via direct mapping
 		 */
 		if (IS_PCI32G(hwdev)) {
 #ifdef CONFIG_IA64_SGI_SN1
-			dma_addr = (dma_addr_t) pciio_dmatrans_addr(vhdl, NULL,
-				temp_ptr, sg->length,
-				PCIIO_BYTE_STREAM | PCIIO_DMA_DATA);
+			dma_addr = pciio_dmatrans_addr(vhdl, NULL, phys_addr,
+						       sg->length,
+						       PCIIO_BYTE_STREAM |
+						       PCIIO_DMA_DATA);
+#elif defined(CONFIG_IA64_SGI_SN2)
+			dma_addr = pciio_dmatrans_addr(vhdl, NULL, phys_addr,
+						       sg->length,
+					((IS_PIC_DEVICE(hwdev)) ? 0 : PCIIO_BYTE_STREAM) |
+						       PCIIO_DMA_DATA);
 #else
-			dma_addr = (dma_addr_t) pciio_dmatrans_addr(vhdl, NULL,
-				temp_ptr, sg->length, PCIIO_DMA_DATA);
+#error unsupported platform
 #endif
+			/*
+			 * See if we got a direct map entry
+			 */
 			if (dma_addr) {
-				sg->address = (char *)dma_addr;
+				sg->dma_address = (char *)dma_addr;
 				continue;
 			}
 
@@ -322,16 +406,25 @@
 		 * so we use an ATE.
 		 */
 		dma_map = 0;
+#ifdef CONFIG_IA64_SGI_SN1
+		dma_map = pciio_dmamap_alloc(vhdl, NULL, sg->length,
+					     PCIIO_BYTE_STREAM |
+					     PCIIO_DMA_DATA);
+#elif defined(CONFIG_IA64_SGI_SN2)
 		dma_map = pciio_dmamap_alloc(vhdl, NULL, sg->length,
-					     DMA_DATA_FLAGS);
+				((IS_PIC_DEVICE(hwdev)) ? 0 : PCIIO_BYTE_STREAM) |
+					     PCIIO_DMA_DATA);
+#else
+#error unsupported platform
+#endif
 		if (!dma_map) {
 			printk(KERN_ERR "sn_pci_map_sg: Unable to allocate "
 			       "anymore 32 bit page map entries.\n");
 			BUG();
 		}
 		dma_addr = pciio_dmamap_addr(dma_map, phys_addr, sg->length);
-		sg->address = (char *)dma_addr;
-		sg->page = (char *)dma_map;
+		sg->dma_address = (char *)dma_addr;
+		sg->page = (struct page *)dma_map;
 		
 	}
 
@@ -339,34 +432,38 @@
 
 }
 
-/*
- * Unmap a set of streaming mode DMA translations.
- * Again, cpu read rules concerning calls here are the same as for
- * pci_unmap_single() above.
+/**
+ * sn_pci_unmap_sg - unmap a scatter-gather list
+ * @hwdev: device to unmap
+ * @sg: scatterlist to unmap
+ * @nents: number of scatterlist entries
+ * @direction: DMA direction
+ *
+ * Unmap a set of streaming mode DMA translations.  Again, cpu read rules
+ * concerning calls here are the same as for pci_unmap_single() below.  Also
+ * known as sn_pci_unmap_sg() by the IA64 machvec code.
  */
 void
-sn1_pci_unmap_sg (struct pci_dev *hwdev, struct scatterlist *sg, int nelems, int direction)
+sn_pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg, int nents, int direction)
 {
 	int i;
-	struct sn1_dma_maps_s *sn1_dma_map;
-
+	struct sn_dma_maps_s *sn_dma_map;
 
+	/* can't go anywhere w/o a direction in life */
 	if (direction == PCI_DMA_NONE)
 		BUG();
 
-	for (i = 0; i < nelems; i++, sg++)
+	for (i = 0; i < nents; i++, sg++)
 		if (sg->page) {
 			/*
 			 * We maintain the DMA Map pointer in sg->page if 
 			 * it is ever allocated.
 			 */
-			/* phys_to_virt((dma_addr_t)sg->address | ~0x80000000); */
-			/* sg->address = sg->page; */
-			sg->address = (char *)-1;
-			sn1_dma_map = (struct sn1_dma_maps_s *)sg->page;
-			pciio_dmamap_done((pciio_dmamap_t)sn1_dma_map);
-			pciio_dmamap_free((pciio_dmamap_t)sn1_dma_map);
-			sn1_dma_map->dma_addr = 0;
+			sg->dma_address = 0;
+			sn_dma_map = (struct sn_dma_maps_s *)sg->page;
+			pciio_dmamap_done((pciio_dmamap_t)sn_dma_map);
+			pciio_dmamap_free((pciio_dmamap_t)sn_dma_map);
+			sn_dma_map->dma_addr = 0;
 			sg->page = 0;
 		}
 
@@ -392,146 +489,212 @@
  *       get rid of dev_desc and vhdl (seems redundant given a pci_dev);
  *       figure out how to save dmamap handle so can use two step.
  */
-dma_addr_t sn1_pci_map_single (struct pci_dev *hwdev,
-				void *ptr, size_t size, int direction)
+dma_addr_t
+sn_pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size, int direction)
 {
-	devfs_handle_t	vhdl;
+	devfs_handle_t vhdl;
 	dma_addr_t dma_addr;
-	paddr_t temp_ptr;
-	struct sn1_device_sysdata *device_sysdata;
+	unsigned long phys_addr;
+	struct sn_device_sysdata *device_sysdata;
 	pciio_dmamap_t dma_map = NULL;
-	struct sn1_dma_maps_s *sn1_dma_map;
-
+	struct sn_dma_maps_s *sn_dma_map;
 
 	if (direction == PCI_DMA_NONE)
 		BUG();
 
+	/* SN cannot support DMA addresses smaller than 32 bits. */
+	if (IS_PCI32L(hwdev))
+		return 0;
 
 	/*
 	 * find vertex for the device
 	 */
-	device_sysdata = (struct sn1_device_sysdata *)hwdev->sysdata;
+	device_sysdata = (struct sn_device_sysdata *)hwdev->sysdata;
 	vhdl = device_sysdata->vhdl;
 
 	/*
 	 * Call our dmamap interface
 	 */
 	dma_addr = 0;
-	temp_ptr = (paddr_t) __pa(ptr);
+	phys_addr = __pa(ptr);
 
 	if (IS_PCIA64(hwdev)) {
-		/*
-		 * This device supports 64bits DMA addresses.
-		 */
-#ifdef CONFIG_IA64_SGI_SN1
-		dma_addr = (dma_addr_t) pciio_dmatrans_addr(vhdl, NULL,
-			temp_ptr, size,
-			PCIIO_BYTE_STREAM | PCIIO_DMA_DATA | PCIIO_DMA_A64 );
-#else
-		dma_addr = (dma_addr_t) pciio_dmatrans_addr(vhdl, NULL,
-			temp_ptr, size, PCIIO_DMA_DATA | PCIIO_DMA_A64 );
-#endif
-		return (dma_addr);
+		/* This device supports 64 bit DMA addresses. */
+		dma_addr = pciio_dmatrans_addr(vhdl, NULL, phys_addr, size,
+		       ((IS_PIC_DEVICE(hwdev)) ? 0 : PCIIO_BYTE_STREAM) |
+					       PCIIO_DMA_DATA |
+					       PCIIO_DMA_A64);
+		return dma_addr;
 	}
 
 	/*
-	 * Devices that supports 32 Bits upto 63 Bits DMA Address gets
-	 * 32 Bits DMA addresses.
+	 * Devices that support 32 bit to 63 bit DMA addresses get
+	 * 32 bit DMA addresses.
 	 *
-	 * First try to get 32 Bit Direct Map Support.
+	 * First try to get a 32 bit direct map register.
 	 */
 	if (IS_PCI32G(hwdev)) {
 #ifdef CONFIG_IA64_SGI_SN1
-		dma_addr = (dma_addr_t) pciio_dmatrans_addr(vhdl, NULL,
-			temp_ptr, size,
-			PCIIO_BYTE_STREAM | PCIIO_DMA_DATA);
+		dma_addr = pciio_dmatrans_addr(vhdl, NULL, phys_addr, size,
+					       PCIIO_BYTE_STREAM |
+					       PCIIO_DMA_DATA);
+#elif defined(CONFIG_IA64_SGI_SN2)
+		dma_addr = pciio_dmatrans_addr(vhdl, NULL, phys_addr, size,
+			((IS_PIC_DEVICE(hwdev)) ? 0 : PCIIO_BYTE_STREAM) |
+					       PCIIO_DMA_DATA);
 #else
-		dma_addr = (dma_addr_t) pciio_dmatrans_addr(vhdl, NULL,
-			temp_ptr, size, PCIIO_DMA_DATA);
+#error unsupported platform
 #endif
-		if (dma_addr) {
-			return (dma_addr);
-		}
+		if (dma_addr)
+			return dma_addr;
 	}
 
-	if (IS_PCI32L(hwdev)) {
-		/*
-		 * SNIA64 cannot support DMA Addresses smaller than 32 bits.
-		 */
-		return ((dma_addr_t) NULL);
-        }
-
 	/*
-	 * It is a 32bit card and we cannot do Direct mapping.
-	 * Let's 32Bit Page map the request.
+	 * It's a 32 bit card and we cannot do direct mapping so
+	 * let's use the PMU instead.
 	 */
 	dma_map = NULL;
 #ifdef CONFIG_IA64_SGI_SN1
-	dma_map = pciio_dmamap_alloc(vhdl, NULL, size, PCIIO_BYTE_STREAM | 
+	dma_map = pciio_dmamap_alloc(vhdl, NULL, size, PCIIO_BYTE_STREAM |
 				     PCIIO_DMA_DATA);
+#elif defined(CONFIG_IA64_SGI_SN2)
+	dma_map = pciio_dmamap_alloc(vhdl, NULL, size, 
+			((IS_PIC_DEVICE(hwdev)) ? 0 : PCIIO_BYTE_STREAM) |
+			PCIIO_DMA_DATA);
 #else
-	dma_map = pciio_dmamap_alloc(vhdl, NULL, size, PCIIO_DMA_DATA);
+#error unsupported platform
 #endif
+
 	if (!dma_map) {
-		printk("pci_map_single: Unable to allocate anymore 32Bits Page Map entries.\n");
+		printk(KERN_ERR "pci_map_single: Unable to allocate anymore "
+		       "32 bit page map entries.\n");
 		BUG();
 	}
 
-	dma_addr = (dma_addr_t) pciio_dmamap_addr(dma_map, temp_ptr, size);
-	/* printk("pci_map_single: dma_map 0x%p Phys Addr 0x%p dma_addr 0x%p\n", dma_map,
-		temp_ptr, dma_addr); */
-	sn1_dma_map = (struct sn1_dma_maps_s *)dma_map;
-	sn1_dma_map->dma_addr = dma_addr;
+	dma_addr = (dma_addr_t) pciio_dmamap_addr(dma_map, phys_addr, size);
+	sn_dma_map = (struct sn_dma_maps_s *)dma_map;
+	sn_dma_map->dma_addr = dma_addr;
 
 	return ((dma_addr_t)dma_addr);
 }
 
+/**
+ * sn_pci_unmap_single - unmap a region used for DMA
+ * @hwdev: device to unmap
+ * @dma_addr: DMA address to unmap
+ * @size: size of region
+ * @direction: DMA direction
+ *
+ * Unmaps the region pointed to by @dma_addr.  Also known as
+ * platform_pci_unmap_single() by the IA64 machvec code.
+ */
 void
-sn1_pci_unmap_single (struct pci_dev *hwdev, dma_addr_t dma_addr, size_t size, int direction)
+sn_pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr, size_t size, int direction)
 {
-
-	struct sn1_dma_maps_s *sn1_dma_map = NULL;
+	struct sn_dma_maps_s *sn_dma_map = NULL;
 
         if (direction == PCI_DMA_NONE)
 		BUG();
 
 	/*
-	 * Get the sn1_dma_map entry.
+	 * Get the sn_dma_map entry.
 	 */
 	if (IS_PCI32_MAPPED(dma_addr))
-		sn1_dma_map = find_sn1_dma_map(dma_addr, hwdev->bus->number);
+		sn_dma_map = find_sn_dma_map(dma_addr, hwdev->bus->number);
 
-	if (sn1_dma_map) {
-		pciio_dmamap_done((pciio_dmamap_t)sn1_dma_map);
-		pciio_dmamap_free((pciio_dmamap_t)sn1_dma_map);
-		sn1_dma_map->dma_addr = (dma_addr_t)NULL;
+	/*
+	 * and free it if necessary...
+	 */
+	if (sn_dma_map) {
+		pciio_dmamap_done((pciio_dmamap_t)sn_dma_map);
+		pciio_dmamap_free((pciio_dmamap_t)sn_dma_map);
+		sn_dma_map->dma_addr = (dma_addr_t)NULL;
 	}
-
 }
 
+/**
+ * sn_pci_dma_sync_single - make sure all DMAs have completed
+ * @hwdev: device to sync
+ * @dma_handle: DMA address to sync
+ * @size: size of region
+ * @direction: DMA direction
+ *
+ * This routine is supposed to sync the DMA region specified
+ * by @dma_handle into the 'coherence domain'.  See sn_dma_sync()
+ * above for more information.   Also known as
+ * platform_pci_dma_sync_single() by the IA64 machvec code.
+ */
 void
-sn1_pci_dma_sync_single (struct pci_dev *hwdev, dma_addr_t dma_handle, size_t size, int direction)
+sn_pci_dma_sync_single(struct pci_dev *hwdev, dma_addr_t dma_handle, size_t size, int direction)
 {
-	
-        if (direction == PCI_DMA_NONE)
+	if (direction == PCI_DMA_NONE)
                 BUG();
 
 	sn_dma_sync(hwdev);
-
 }
 
+/**
+ * sn_pci_dma_sync_sg - make sure all DMAs have completed
+ * @hwdev: device to sync
+ * @sg: scatterlist to sync
+ * @nents: number of entries in the scatterlist
+ * @direction: DMA direction
+ *
+ * This routine is supposed to sync the DMA regions specified
+ * by @sg into the 'coherence domain'.  See sn_dma_sync()
+ * above for more information.   Also known as
+ * platform_pci_dma_sync_sg() by the IA64 machvec code.
+ */
 void
-sn1_pci_dma_sync_sg (struct pci_dev *hwdev, struct scatterlist *sg, int nelems, int direction)
+sn_pci_dma_sync_sg(struct pci_dev *hwdev, struct scatterlist *sg, int nents, int direction)
 {
         if (direction == PCI_DMA_NONE)
                 BUG();
 
 	sn_dma_sync(hwdev);
-
 }
 
+/**
+ * sn_dma_address - get the DMA address for the first entry of a scatterlist
+ * @sg: sg to look at
+ *
+ * Gets the DMA address for the scatterlist @sg.  Also known as
+ * platform_dma_address() by the IA64 machvec code.
+ */
 unsigned long
-sn1_dma_address (struct scatterlist *sg)
+sn_dma_address(struct scatterlist *sg)
 {
-	return ((unsigned long)sg->address);
+	return ((unsigned long)sg->dma_address);
 }
+
+/**
+ * sn_dma_supported - test a DMA mask
+ * @hwdev: device to test
+ * @mask: DMA mask to test
+ *
+ * Return whether the given PCI device DMA address mask can be supported
+ * properly.  For example, if your device can only drive the low 24-bits
+ * during PCI bus mastering, then you would pass 0x00ffffff as the mask to
+ * this function.  Of course, SN only supports devices that have 32 or more
+ * address bits when using the PMU.  We could theoretically support <32 bit
+ * cards using direct mapping, but we'll worry about that later--on the off
+ * chance that someone actually wants to use such a card.
+ */
+int
+sn_pci_dma_supported(struct pci_dev *hwdev, u64 mask)
+{
+	if (mask < 0xffffffff)
+		return 0;
+	return 1;
+}
+
+EXPORT_SYMBOL(sn_pci_unmap_single);
+EXPORT_SYMBOL(sn_pci_map_single);
+EXPORT_SYMBOL(sn_pci_dma_sync_single);
+EXPORT_SYMBOL(sn_pci_map_sg);
+EXPORT_SYMBOL(sn_pci_unmap_sg);
+EXPORT_SYMBOL(sn_pci_alloc_consistent);
+EXPORT_SYMBOL(sn_pci_free_consistent);
+EXPORT_SYMBOL(sn_dma_address);
+EXPORT_SYMBOL(sn_pci_dma_supported);
+
diff -Nru a/arch/ia64/sn/io/pciba.c b/arch/ia64/sn/io/pciba.c
--- a/arch/ia64/sn/io/pciba.c	Mon Dec 23 21:21:50 2002
+++ b/arch/ia64/sn/io/pciba.c	Mon Dec 23 21:21:50 2002
@@ -210,31 +210,31 @@
 
 /* file operations for each type of node */
 static struct file_operations rom_fops = {
-	.owner =	THIS_MODULE,
-	.mmap =		rom_mmap,
-	.open =		generic_open,
-	.release =	rom_release
+	owner:		THIS_MODULE,
+	mmap:		rom_mmap,
+	open:		generic_open,
+	release:	rom_release
 };
  
 
 static struct file_operations base_fops = {
-	.owner =	THIS_MODULE,
-	.mmap =		base_mmap,
-	.open =		generic_open
+	owner:		THIS_MODULE,
+	mmap:		base_mmap,
+	open:		generic_open
 };
 
 
 static struct file_operations config_fops = {
-	.owner =	THIS_MODULE,
-	.ioctl =	config_ioctl,
-	.open =		generic_open
+	owner:		THIS_MODULE,
+	ioctl:		config_ioctl,
+	open:		generic_open
 };	
 
 static struct file_operations dma_fops = {
-	.owner =	THIS_MODULE,
-	.ioctl =	dma_ioctl,
-	.mmap =		dma_mmap,
-	.open =		generic_open
+	owner:		THIS_MODULE,
+	ioctl:		dma_ioctl,
+	mmap:		dma_mmap,
+	open:		generic_open
 };	
 
 
@@ -346,9 +346,6 @@
 
 	return success;
 }
-
-#endif /* CONFIG_IA64_SGI_SN1 */
-
 
 static void __exit
 unregister_with_devfs(void)
diff -Nru a/arch/ia64/sn/io/sgi_if.c b/arch/ia64/sn/io/sgi_if.c
--- a/arch/ia64/sn/io/sgi_if.c	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/sn/io/sgi_if.c	Mon Dec 23 21:21:55 2002
@@ -4,7 +4,7 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (C) 1992 - 1997, 2000-2001 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 1992 - 1997, 2000-2002 Silicon Graphics, Inc. All rights reserved.
  */
 
 #include <linux/types.h>
@@ -20,14 +20,50 @@
 #include <asm/sn/pci/pciio.h>
 #include <asm/sn/slotnum.h>
 
+unsigned char Is_pic_on_this_nasid[512];	/* non-0 when this is a pic shub */
+
 void *
 snia_kmem_zalloc(size_t size, int flag)
 {
         void *ptr = kmalloc(size, GFP_KERNEL);
-        BZERO(ptr, size);
-        return ptr;
+	if ( ptr )
+        	BZERO(ptr, size);
+        return(ptr);
 }
 
+void
+snia_kmem_free(void *ptr, size_t size)
+{
+        kfree(ptr);
+}
+
+int
+nic_vertex_info_match(devfs_handle_t v, char *s)
+{
+	/* we don't support this */
+	return(0);
+}
+
+/*
+ * the alloc/free_node routines do a simple kmalloc for now ..
+ */
+void *
+snia_kmem_alloc_node(register size_t size, register int flags, cnodeid_t node)
+{
+	/* someday will Allocate on node 'node' */
+	return(kmalloc(size, GFP_KERNEL));
+}
+
+void *
+snia_kmem_zalloc_node(register size_t size, register int flags, cnodeid_t node)
+{
+	void *ptr = kmalloc(size, GFP_KERNEL);
+	if ( ptr )
+		BZERO(ptr, size);
+        return(ptr);
+}
+
+
 #define xtod(c)         ((c) <= '9' ? '0' - (c) : 'a' - (c) - 10)
 long
 atoi(register char *p)
@@ -66,4 +102,112 @@
                 }
         }
         return (neg ? n : -n);
+}
+
+char *
+strtok_r(char *string, const char *sepset, char **lasts)
+{
+        register char   *q, *r;
+
+        /*first or subsequent call*/
+        if (string == NULL)
+                string = *lasts;
+
+        if(string == 0)         /* return if no tokens remaining */
+                return(NULL);
+
+        q = string + strspn(string, sepset);    /* skip leading separators */
+
+        if(*q == '\0') {                /* return if no tokens remaining */
+                *lasts = 0;     /* indicate this is last token */
+                return(NULL);
+        }
+
+        if((r = strpbrk(q, sepset)) == NULL)    /* move past token */
+                *lasts = 0;     /* indicate this is last token */
+        else {
+                *r = '\0';
+                *lasts = r+1;
+        }
+        return(q);
+}
+
+/*
+ * print_register() allows formatted printing of bit fields.  individual
+ * bit fields are described by a struct reg_desc, multiple bit fields within
+ * a single word can be described by multiple reg_desc structures.
+ * %r outputs a string of the format "<bit field descriptions>"
+ * %R outputs a string of the format "0x%x<bit field descriptions>"
+ *
+ * The fields in a reg_desc are:
+ *	unsigned long long rd_mask; An appropriate mask to isolate the bit field
+ *				within a word, and'ed with val
+ *
+ *	int rd_shift;		A shift amount to be done to the isolated
+ *				bit field.  done before printing the isolate
+ *				bit field with rd_format and before searching
+ *				for symbolic value names in rd_values
+ *
+ *	char *rd_name;		If non-null, a bit field name to label any
+ *				out from rd_format or searching rd_values.
+ *				if neither rd_format or rd_values is non-null
+ *				rd_name is printed only if the isolated
+ *				bit field is non-null.
+ *
+ *	char *rd_format;	If non-null, the shifted bit field value
+ *				is printed using this format.
+ *
+ *	struct reg_values *rd_values;	If non-null, a pointer to a table
+ *				matching numeric values with symbolic names.
+ *				rd_values are searched and the symbolic
+ *				value is printed if a match is found, if no
+ *				match is found "???" is printed.
+ *				
+ */
+
+void
+print_register(unsigned long long reg, struct reg_desc *addr)
+{
+	register struct reg_desc *rd;
+	register struct reg_values *rv;
+	unsigned long long field;
+	int any;
+
+	printk("<");
+	any = 0;
+	for (rd = addr; rd->rd_mask; rd++) {
+		field = reg & rd->rd_mask;
+		field = (rd->rd_shift > 0) ? field << rd->rd_shift : field >> -rd->rd_shift;
+		if (any && (rd->rd_format || rd->rd_values || (rd->rd_name && field)))
+			printk(",");
+		if (rd->rd_name) {
+			if (rd->rd_format || rd->rd_values || field) {
+				printk("%s", rd->rd_name);
+				any = 1;
+			}
+			if (rd->rd_format || rd->rd_values) {
+				printk("=");
+				any = 1;
+			}
+		}
+		/* You can have any format so long as it is %x */
+		if (rd->rd_format) {
+			printk("%llx", field);
+			any = 1;
+			if (rd->rd_values)
+				printk(":");
+		}
+		if (rd->rd_values) {
+			any = 1;
+			for (rv = rd->rd_values; rv->rv_name; rv++) {
+				if (field == rv->rv_value) {
+					printk("%s", rv->rv_name);
+					break;
+				}
+			}
+			if (rv->rv_name == NULL)
+				printk("???");
+		}
+	}
+	printk(">\n");
 }
diff -Nru a/arch/ia64/sn/io/sgi_io_sim.c b/arch/ia64/sn/io/sgi_io_sim.c
--- a/arch/ia64/sn/io/sgi_io_sim.c	Mon Dec 23 21:21:53 2002
+++ b/arch/ia64/sn/io/sgi_io_sim.c	Mon Dec 23 21:21:53 2002
@@ -4,7 +4,7 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (C) 1992 - 1997, 2000-2001 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 1992 - 1997, 2000-2002 Silicon Graphics, Inc. All rights reserved.
  */
 
 #include <linux/config.h>
@@ -71,6 +71,9 @@
  */
 static __psunsigned_t master_bridge_base = (__psunsigned_t)NULL;
 nasid_t console_nasid = (nasid_t)-1;
+#if !defined(CONFIG_IA64_SGI_SN1)
+char master_baseio_wid;
+#endif
 static char console_wid;
 static char console_pcislot;
 
@@ -92,6 +95,7 @@
                 return 0;
 }
 
+#if defined(CONFIG_IA64_SGI_SN1)
 int
 is_master_nasid_widget(nasid_t test_nasid, xwidgetnum_t test_wid)
 {
@@ -111,6 +115,29 @@
                 return 0;
         }
 }
+#else
+int
+is_master_baseio_nasid_widget(nasid_t test_nasid, xwidgetnum_t test_wid)
+{
+	extern nasid_t master_baseio_nasid;
+
+        /*
+         * If the widget numbers are different, we're not the master.
+         */
+        if (test_wid != (xwidgetnum_t)master_baseio_wid) {
+                return 0;
+	}
+
+        /*
+         * If the NASIDs are the same or equivalent, we're the master.
+         */
+        if (check_nasid_equiv(test_nasid, master_baseio_nasid)) {
+                return 1;
+        } else {
+                return 0;
+        }
+}
+#endif	/* CONFIG_IA64_SGI_SN1 */
 
 /*
  * Routines provided by ml/SN/nvram.c
diff -Nru a/arch/ia64/sn/io/sn1/hub_intr.c b/arch/ia64/sn/io/sn1/hub_intr.c
--- a/arch/ia64/sn/io/sn1/hub_intr.c	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/sn/io/sn1/hub_intr.c	Mon Dec 23 21:21:55 2002
@@ -1,4 +1,4 @@
-/* $Id: io.c,v 1.2 2001/06/26 14:02:43 pfg Exp $
+/* $Id: hub_intr.c,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
diff -Nru a/arch/ia64/sn/io/sn1/hubcounters.c b/arch/ia64/sn/io/sn1/hubcounters.c
--- a/arch/ia64/sn/io/sn1/hubcounters.c	Mon Dec 23 21:21:52 2002
+++ b/arch/ia64/sn/io/sn1/hubcounters.c	Mon Dec 23 21:21:52 2002
@@ -1,10 +1,10 @@
-/* $Id:$
+/* $Id: hubcounters.c,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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.
  *
- * Copyright (C) 1992 - 1997, 2000 - 2001 Silicon Graphics, Inc.
+ * Copyright (C) 1992-1997,2000-2002 Silicon Graphics, Inc.
  * All rights reserved.
  */
 #include <linux/kernel.h>
@@ -24,7 +24,7 @@
 
 static int hubstats_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
 struct file_operations hub_mon_fops = {
-        .ioctl =        hubstats_ioctl,
+        ioctl:          hubstats_ioctl,
 };
 
 #define HUB_CAPTURE_TICKS	(2 * HZ)
diff -Nru a/arch/ia64/sn/io/sn1/huberror.c b/arch/ia64/sn/io/sn1/huberror.c
--- a/arch/ia64/sn/io/sn1/huberror.c	Mon Dec 23 21:21:51 2002
+++ b/arch/ia64/sn/io/sn1/huberror.c	Mon Dec 23 21:21:51 2002
@@ -1,4 +1,4 @@
-/* $Id$
+/* $Id: huberror.c,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
diff -Nru a/arch/ia64/sn/io/sn1/mem_refcnt.c b/arch/ia64/sn/io/sn1/mem_refcnt.c
--- a/arch/ia64/sn/io/sn1/mem_refcnt.c	Mon Dec 23 21:21:52 2002
+++ b/arch/ia64/sn/io/sn1/mem_refcnt.c	Mon Dec 23 21:21:52 2002
@@ -1,4 +1,4 @@
-/* $Id$
+/* $Id: mem_refcnt.c,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
@@ -7,7 +7,6 @@
  * Copyright (C) 1992 - 1997, 2000-2002 Silicon Graphics, Inc. All rights reserved.
  */
 
-#include <linux/config.h>
 #include <linux/types.h>
 #include <asm/sn/arch.h>
 #include <asm/sn/sgi.h>
@@ -43,7 +42,7 @@
 int
 mem_refcnt_attach(devfs_handle_t hub)
 {
-#ifndef CONFIG_IA64_SGI_SN
+#if 0
         devfs_handle_t refcnt_dev;
         
         hwgraph_char_device_add(hub,
diff -Nru a/arch/ia64/sn/io/sn1/ml_SN_intr.c b/arch/ia64/sn/io/sn1/ml_SN_intr.c
--- a/arch/ia64/sn/io/sn1/ml_SN_intr.c	Mon Dec 23 21:21:57 2002
+++ b/arch/ia64/sn/io/sn1/ml_SN_intr.c	Mon Dec 23 21:21:57 2002
@@ -1,4 +1,4 @@
-/* $Id$
+/* $Id: ml_SN_intr.c,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
@@ -13,7 +13,7 @@
  *	handle interrupts on an IP27 board.
  */
 
-#ident  "$Revision: 1.167 $"
+#ident  "$Revision: 1.1 $"
 
 #include <linux/types.h>
 #include <linux/config.h>
@@ -987,13 +987,12 @@
 	char subnode_done[NUM_SUBNODES];
 
 	// cpu = cnodetocpu(cnode);
-	for (cpu = 0; cpu < NR_CPUS; cpu++) {
-		if (!cpu_online(cpu)) continue;
+	for (cpu = 0; cpu < smp_num_cpus; cpu++) {
 		if (cpuid_to_cnodeid(cpu) == cnode) {
 			break;
 		}
 	}
-	if (cpu == NR_CPUS) cpu = CPU_NONE;
+	if (cpu == smp_num_cpus) cpu = CPU_NONE;
 	if (cpu == CPU_NONE) {
 		printk("Node %d has no CPUs", cnode);
 		return;
@@ -1002,7 +1001,7 @@
 	for (i=0; i<NUM_SUBNODES; i++)
 		subnode_done[i] = 0;
 
-	for (; cpu<NR_CPUS && cpu_enabled(cpu) && cpuid_to_cnodeid(cpu) == cnode; cpu++) {
+	for (; cpu<smp_num_cpus && cpu_enabled(cpu) && cpuid_to_cnodeid(cpu) == cnode; cpu++) {
 		int which_subnode = cpuid_to_subnode(cpu);
 		if (subnode_done[which_subnode])
 			continue;
diff -Nru a/arch/ia64/sn/io/sn1/pcibr.c b/arch/ia64/sn/io/sn1/pcibr.c
--- a/arch/ia64/sn/io/sn1/pcibr.c	Mon Dec 23 21:21:58 2002
+++ b/arch/ia64/sn/io/sn1/pcibr.c	Mon Dec 23 21:21:58 2002
@@ -9,7 +9,6 @@
 int NeedXbridgeSwap = 0;
 
 #include <linux/types.h>
-#include <linux/config.h>
 #include <linux/slab.h>
 #include <linux/module.h>
 #include <asm/sn/sgi.h>
@@ -307,22 +306,22 @@
  * appropriate function name below.
  */
 struct file_operations pcibr_fops = {
-        .owner = THIS_MODULE,
-        .llseek = NULL,
-        .read = NULL,
-        .write = NULL,
-        .readdir = NULL,
-        .poll = NULL,
-        .ioctl = NULL,
-        .mmap = NULL,
-        .open = NULL,
-        .flush = NULL,
-        .release = NULL,
-        .fsync = NULL,
-        .fasync = NULL,
-        .lock = NULL,
-        .readv = NULL,
-        .writev = NULL
+        owner:  THIS_MODULE,
+        llseek: NULL,
+        read: NULL,
+        write: NULL,
+        readdir: NULL,
+        poll: NULL,
+        ioctl: NULL,
+        mmap: NULL,
+        open: NULL,
+        flush: NULL,
+        release: NULL,
+        fsync: NULL,
+        fasync: NULL,
+        lock: NULL,
+        readv: NULL,
+        writev: NULL
 };
 
 extern devfs_handle_t hwgraph_root;
@@ -332,7 +331,6 @@
 extern void rmfree(struct map *mp, size_t size, uint64_t a);
 extern int hwgraph_vertex_name_get(devfs_handle_t vhdl, char *buf, uint buflen);
 extern long atoi(register char *p);
-extern void *swap_ptr(void **loc, void *new);
 extern char *dev_to_name(devfs_handle_t dev, char *buf, uint buflen);
 extern cnodeid_t nodevertex_to_cnodeid(devfs_handle_t vhdl);
 extern graph_error_t hwgraph_edge_remove(devfs_handle_t from, char *name, devfs_handle_t *toptr);
@@ -1628,243 +1626,6 @@
 			  "BAD"};
 
 
-#ifdef LATER
-
-void
-pcibr_slot_func_info_return(pcibr_info_h pcibr_infoh,
-                            int func,
-                            pcibr_slot_func_info_resp_t funcp)
-{
-    pcibr_info_t                 pcibr_info = pcibr_infoh[func];
-    int                          win;
-
-    funcp->resp_f_status = 0;
-
-    if (!pcibr_info) {
-        return;
-    }
-
-    funcp->resp_f_status |= FUNC_IS_VALID;
-#ifdef SUPPORT_PRINTING_V_FORMAT
-    sprintf(funcp->resp_f_slot_name, "%v", pcibr_info->f_vertex);
-#else
-    sprintf(funcp->resp_f_slot_name, "%x", pcibr_info->f_vertex);
-#endif
-
-    if(is_sys_critical_vertex(pcibr_info->f_vertex)) {
-        funcp->resp_f_status |= FUNC_IS_SYS_CRITICAL;
-    }
-
-    funcp->resp_f_bus = pcibr_info->f_bus;
-    funcp->resp_f_slot = pcibr_info->f_slot;
-    funcp->resp_f_func = pcibr_info->f_func;
-#ifdef SUPPORT_PRINTING_V_FORMAT
-    sprintf(funcp->resp_f_master_name, "%v", pcibr_info->f_master);
-#else
-    sprintf(funcp->resp_f_master_name, "%x", pcibr_info->f_master);
-#endif
-    funcp->resp_f_pops = pcibr_info->f_pops;
-    funcp->resp_f_efunc = pcibr_info->f_efunc;
-    funcp->resp_f_einfo = pcibr_info->f_einfo;
-
-    funcp->resp_f_vendor = pcibr_info->f_vendor;
-    funcp->resp_f_device = pcibr_info->f_device;
-
-    for(win = 0 ; win < 6 ; win++) {
-        funcp->resp_f_window[win].resp_w_base =
-                                  pcibr_info->f_window[win].w_base;
-        funcp->resp_f_window[win].resp_w_size =
-                                  pcibr_info->f_window[win].w_size;
-        sprintf(funcp->resp_f_window[win].resp_w_space,
-                "%s",
-                pci_space_name[pcibr_info->f_window[win].w_space]);
-    }
-
-    funcp->resp_f_rbase = pcibr_info->f_rbase;
-    funcp->resp_f_rsize = pcibr_info->f_rsize;
-
-    for (win = 0 ; win < 4; win++) {
-        funcp->resp_f_ibit[win] = pcibr_info->f_ibit[win];
-    }
-
-    funcp->resp_f_att_det_error = pcibr_info->f_att_det_error;
-
-}
-
-int
-pcibr_slot_info_return(pcibr_soft_t             pcibr_soft,
-                       pciio_slot_t             slot,
-                       pcibr_slot_info_resp_t   respp)
-{
-    pcibr_soft_slot_t            pss;
-    int                          func;
-    bridge_t                    *bridge = pcibr_soft->bs_base;
-    reg_p                        b_respp;
-    pcibr_slot_info_resp_t       slotp;
-    pcibr_slot_func_info_resp_t  funcp;
-
-    slotp = snia_kmem_zalloc(sizeof(*slotp), KM_SLEEP);
-    if (slotp == NULL) {
-        return(ENOMEM);
-    }
-
-    pss = &pcibr_soft->bs_slot[slot];
-    
-    printk("\nPCI INFRASTRUCTURAL INFO FOR SLOT %d\n\n", slot);
-
-    slotp->resp_has_host = pss->has_host;
-    slotp->resp_host_slot = pss->host_slot;
-#ifdef SUPPORT_PRINTING_V_FORMAT
-    sprintf(slotp->resp_slot_conn_name, "%v", pss->slot_conn);
-#else
-    sprintf(slotp->resp_slot_conn_name, "%x", pss->slot_conn);
-#endif
-    slotp->resp_slot_status = pss->slot_status;
-    slotp->resp_l1_bus_num = io_path_map_widget(pcibr_soft->bs_vhdl);
-
-    if (is_sys_critical_vertex(pss->slot_conn)) {
-        slotp->resp_slot_status |= SLOT_IS_SYS_CRITICAL;
-    }
-
-    slotp->resp_bss_ninfo = pss->bss_ninfo;
-
-    for (func = 0; func < pss->bss_ninfo; func++) {
-        funcp = &(slotp->resp_func[func]);
-        pcibr_slot_func_info_return(pss->bss_infos, func, funcp);
-    }
-
-    sprintf(slotp->resp_bss_devio_bssd_space, "%s",
-            pci_space_name[pss->bss_devio.bssd_space]);
-    slotp->resp_bss_devio_bssd_base = pss->bss_devio.bssd_base;
-    slotp->resp_bss_device = pss->bss_device;
-
-    slotp->resp_bss_pmu_uctr = pss->bss_pmu_uctr;
-    slotp->resp_bss_d32_uctr = pss->bss_d32_uctr;
-    slotp->resp_bss_d64_uctr = pss->bss_d64_uctr;
-
-    slotp->resp_bss_d64_base = pss->bss_d64_base;
-    slotp->resp_bss_d64_flags = pss->bss_d64_flags;
-    slotp->resp_bss_d32_base = pss->bss_d32_base;
-    slotp->resp_bss_d32_flags = pss->bss_d32_flags;
-
-    slotp->resp_bss_ext_ates_active = atomic_read(&pss->bss_ext_ates_active);
-
-    slotp->resp_bss_cmd_pointer = pss->bss_cmd_pointer;
-    slotp->resp_bss_cmd_shadow = pss->bss_cmd_shadow;
-
-    slotp->resp_bs_rrb_valid = pcibr_soft->bs_rrb_valid[slot];
-    slotp->resp_bs_rrb_valid_v = pcibr_soft->bs_rrb_valid[slot +
-                                                      PCIBR_RRB_SLOT_VIRTUAL];
-    slotp->resp_bs_rrb_res = pcibr_soft->bs_rrb_res[slot];
-
-    if (slot & 1) {
-        b_respp = &bridge->b_odd_resp;
-    } else {
-        b_respp = &bridge->b_even_resp;
-    }
-
-    slotp->resp_b_resp = *b_respp;
-
-    slotp->resp_b_int_device = bridge->b_int_device;
-    slotp->resp_b_int_enable = bridge->b_int_enable;
-    slotp->resp_b_int_host = bridge->b_int_addr[slot].addr;
-
-    if (COPYOUT(slotp, respp, sizeof(*respp))) {
-        return(EFAULT);
-    }
-
-    snia_kmem_free(slotp, sizeof(*slotp));
-
-    return(0);
-}
-
-/*
- * pcibr_slot_query
- *	Return information about the PCI slot maintained by the infrastructure.
- *	Information is requested in the request structure.
- *
- *      Information returned in the response structure:
- *		Slot hwgraph name
- *		Vendor/Device info
- *		Base register info
- *		Interrupt mapping from device pins to the bridge pins
- *		Devio register
- *		Software RRB info
- *		RRB register info
- *		Host/Gues info
- *		PCI Bus #,slot #, function #
- *		Slot provider hwgraph name
- *		Provider Functions
- *		Error handler
- *		DMA mapping usage counters
- *		DMA direct translation info
- *		External SSRAM workaround info
- */
-int
-pcibr_slot_query(devfs_handle_t pcibr_vhdl, pcibr_slot_info_req_t reqp)
-{
-    pcibr_soft_t            pcibr_soft = pcibr_soft_get(pcibr_vhdl);
-    pciio_slot_t            slot = reqp->req_slot;
-    pciio_slot_t            tmp_slot;
-    pcibr_slot_info_resp_t  respp = (pcibr_slot_info_resp_t) reqp->req_respp;
-    int                     size = reqp->req_size;
-    int                     error;
-
-    /* Make sure that we are dealing with a bridge device vertex */
-    if (!pcibr_soft) {
-        return(EINVAL);
-    }
-
-    /* Make sure that we have a valid PCI slot number or PCIIO_SLOT_NONE */
-    if ((!PCIBR_VALID_SLOT(slot)) && (slot != PCIIO_SLOT_NONE)) {
-        return(EINVAL);
-    }
-
-    /* Return information for the requested PCI slot */
-    if (slot != PCIIO_SLOT_NONE) {
-        if (size < sizeof(*respp)) {
-            return(EINVAL);
-        }
-
-        /* Acquire read access to the slot */
-        mrlock(pcibr_soft->bs_slot[slot].slot_lock, MR_ACCESS, PZERO);
-
-        error = pcibr_slot_info_return(pcibr_soft, slot, respp);
-
-        /* Release the slot lock */
-        mrunlock(pcibr_soft->bs_slot[slot].slot_lock);
-
-        return(error);
-    }
-
-    /* Return information for all the slots */
-    for (tmp_slot = 0; tmp_slot < 8; tmp_slot++) {
-
-        if (size < sizeof(*respp)) {
-            return(EINVAL);
-        }
-
-        /* Acquire read access to the slot */
-        mrlock(pcibr_soft->bs_slot[tmp_slot].slot_lock, MR_ACCESS, PZERO);
-
-        error = pcibr_slot_info_return(pcibr_soft, tmp_slot, respp);
-
-        /* Release the slot lock */
-        mrunlock(pcibr_soft->bs_slot[tmp_slot].slot_lock);
-
-        if (error) {
-            return(error);
-        }
-
-        ++respp;
-        size -= sizeof(*respp);
-    }
-
-    return(error);
-}
-#endif	/* LATER */
-
-
 /*ARGSUSED */
 int
 pcibr_ioctl(devfs_handle_t dev,
@@ -3617,7 +3378,7 @@
 	self->bl_soft = pcibr_soft;
 	self->bl_vhdl = pcibr_vhdl;
 	self->bl_next = pcibr_list;
-	self->bl_next = swap_ptr((void **) &pcibr_list, (void *)self);
+        pcibr_list = self; 
     }
 #endif
 
@@ -6455,9 +6216,7 @@
 
 	    intr_bit = (short) xtalk_intr_vector_get(xtalk_intr);
 	    cpu = cpuvertex_to_cpuid(xtalk_intr_cpu_get(xtalk_intr));
-#if defined(CONFIG_IA64_SGI_SN1)
 	    REMOTE_CPU_SEND_INTR(cpu, intr_bit);
-#endif
 	}
 }
 
@@ -6822,13 +6581,8 @@
     bridgereg_t            *int_addr = (bridgereg_t *)
     xtalk_intr_sfarg_get(xtalk_intr);
 
-#ifdef CONFIG_IA64_SGI_SN2
-    *int_addr = ((BRIDGE_INT_ADDR_HOST & (addr >> 26)) |
-		 (BRIDGE_INT_ADDR_FLD & vect));
-#elif CONFIG_IA64_SGI_SN1
     *int_addr = ((BRIDGE_INT_ADDR_HOST & (addr >> 30)) |
 		 (BRIDGE_INT_ADDR_FLD & vect));
-#endif
 }
 
 /*ARGSUSED */
@@ -7485,7 +7239,7 @@
 
 #ifdef LITTLE_ENDIAN
 /*
- * on sn-ia we need to twiddle the addresses going out
+ * on sn-ia we need to twiddle the the addresses going out
  * the pci bus because we use the unswizzled synergy space
  * (the alternative is to use the swizzled synergy space
  * and byte swap the data)
diff -Nru a/arch/ia64/sn/io/sn2/bte_error.c b/arch/ia64/sn/io/sn2/bte_error.c
--- a/arch/ia64/sn/io/sn2/bte_error.c	Mon Dec 23 21:21:58 2002
+++ b/arch/ia64/sn/io/sn2/bte_error.c	Mon Dec 23 21:21:58 2002
@@ -1,4 +1,4 @@
-/* $Id$
+/* $Id: bte_error.c,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
@@ -54,96 +54,14 @@
  *									*
  ************************************************************************/
 
-#ifdef BTE_ERROR
-// This routine is not called.  Yet.  It may be someday.  It probably
-// *should* be someday.  Until then, ifdef it out.
-bte_result_t
-bte_error_handler(bte_handle_t *bh)
-/*
- * Function: 	bte_error_handler
- * Purpose:	Process a BTE error after a transfer has failed.
- * Parameters:	bh - bte handle of bte that failed.
- * Returns:	The BTE error type.
- * Notes:
+/* 
+ * >>> bte_crb_error_handler needs to be broken into two parts.  The
+ * first should cleanup the CRB.  The second should wait until all bte
+ * related CRB's are complete and then do the error reset.
  */
-{
-    devfs_handle_t	hub_v;
-    hubinfo_t		hinfo;
-    int			il;
-    hubreg_t		iidsr, imem, ieclr;
-    hubreg_t		bte_status;
-
-    bh->bh_bte->bte_error_count++;
-
-    /* 
-     * Process any CRB logs - we know that the bte_context contains
-     * the BTE completion status, but to avoid a race with error
-     * processing, we force a call to pick up any CRB errors pending. 
-     * After this call, we know that we have any CRB errors related to 
-     * this BTE transfer in the context.
-     */
-    hub_v = cnodeid_to_vertex(bh->bh_bte->bte_cnode);
-    hubinfo_get(hub_v, &hinfo);
-    (void)hubiio_crb_error_handler(hub_v, hinfo);
-
-    /* Be sure BTE is stopped */
-
-    (void)BTE_LOAD(bh->bh_bte->bte_base, BTEOFF_CTRL);
-
-    /*	
-     * Now clear up the rest of the error - be sure to hold crblock 
-     * to avoid race with other cpu on this node.
-     */
-    imem = REMOTE_HUB_L(hinfo->h_nasid, IIO_IMEM);
-    ieclr = REMOTE_HUB_L(hinfo->h_nasid, IIO_IECLR);
-    if (bh->bh_bte->bte_num == 0) {
-	imem |= IIO_IMEM_W0ESD | IIO_IMEM_B0ESD;
-	ieclr|= IECLR_BTE0;
-    } else {
-	imem |= IIO_IMEM_W0ESD | IIO_IMEM_B1ESD;
-	ieclr|= IECLR_BTE1;
-    }
-
-    REMOTE_HUB_S(hinfo->h_nasid, IIO_IMEM, imem);
-    REMOTE_HUB_S(hinfo->h_nasid, IIO_IECLR, ieclr);
-
-    iidsr  = REMOTE_HUB_L(hinfo->h_nasid, IIO_IIDSR);
-    iidsr &= ~IIO_IIDSR_SENT_MASK;
-    iidsr |= IIO_IIDSR_ENB_MASK;
-    REMOTE_HUB_S(hinfo->h_nasid, IIO_IIDSR, iidsr);
-    mutex_spinunlock(&hinfo->h_crblock, il);
-
-    bte_status = BTE_LOAD(bh->bh_bte->bte_base, BTEOFF_STAT);
-    BTE_STORE(bh->bh_bte->bte_base, BTEOFF_STAT, bte_status & ~IBLS_BUSY);
-    ASSERT(!BTE_IS_BUSY(BTE_LOAD(bh->bh_bte->bte_base, BTEOFF_STAT)));
-
-    switch(bh->bh_error) {
-    case IIO_ICRB_ECODE_PERR:
-	return(BTEFAIL_POISON);
-    case IIO_ICRB_ECODE_WERR:
-	return(BTEFAIL_PROT);
-    case IIO_ICRB_ECODE_AERR:
-	return(BTEFAIL_ACCESS);
-    case IIO_ICRB_ECODE_TOUT:
-	return(BTEFAIL_TOUT);
-    case IIO_ICRB_ECODE_XTERR:
-	return(BTEFAIL_ERROR);
-    case IIO_ICRB_ECODE_DERR:
-	return(BTEFAIL_DIR);
-    case IIO_ICRB_ECODE_PWERR:
-    case IIO_ICRB_ECODE_PRERR:
-	/* NO BREAK */
-    default:
-	printk("BTE failure (%d) unexpected\n", 
-		bh->bh_error);
-	return(BTEFAIL_ERROR);
-    }
-}
-#endif // BTE_ERROR
-
 void
 bte_crb_error_handler(devfs_handle_t hub_v, int btenum, 
-		      int crbnum, ioerror_t *ioe)
+		      int crbnum, ioerror_t *ioe, int bteop)
 /*
  * Function: 	bte_crb_error_handler
  * Purpose:	Process a CRB for a specific HUB/BTE
@@ -162,29 +80,70 @@
 	icrba_t		crba; 
 	icrbb_t		crbb; 
 	nasid_t		n;
+	hubreg_t	iidsr, imem, ieclr;
 
 	hubinfo_get(hub_v, &hinfo);
 
 
 	n = hinfo->h_nasid;
 	
-	/* Step 1 */
-	crba.ii_icrb0_a_regval = REMOTE_HUB_L(n, IIO_ICRB_A(crbnum));
-	crbb.ii_icrb0_b_regval = REMOTE_HUB_L(n, IIO_ICRB_B(crbnum));
 
+	/*
+	 * The following 10 lines (or so) are adapted from IRIXs
+	 * bte_crb_error function.  No clear documentation tells
+	 * why the crb needs to complete normally in order for
+	 * the BTE to resume normal operations.  This first step
+	 * appears vital!
+	 */
 
-	/* Zero error and error code to prevent error_dump complaining
-	 * about these CRBs. 
+	/*
+	 * Zero error and error code to prevent error_dump complaining
+	 * about these CRBs. Copy the CRB to the notification line.
+	 * The crb address is in shub format (physical address shifted
+	 * right by cacheline size).
 	 */
+	crbb.ii_icrb0_b_regval = REMOTE_HUB_L(n, IIO_ICRB_B(crbnum));
 	crbb.b_error=0;
 	crbb.b_ecode=0;
+	REMOTE_HUB_S(n, IIO_ICRB_B(crbnum), crbb.ii_icrb0_b_regval);
 
-	/* Step 2 */
+	crba.ii_icrb0_a_regval = REMOTE_HUB_L(n, IIO_ICRB_A(crbnum));
+	crba.a_addr = TO_PHYS((u64)&nodepda->bte_if[btenum].notify) >> 3;
+	crba.a_valid = 1;
 	REMOTE_HUB_S(n, IIO_ICRB_A(crbnum), crba.ii_icrb0_a_regval);
-	/* Step 3 */
+
 	REMOTE_HUB_S(n, IIO_ICCR, 
 		     IIO_ICCR_PENDING | IIO_ICCR_CMD_FLUSH | crbnum);
+
 	while (REMOTE_HUB_L(n, IIO_ICCR) & IIO_ICCR_PENDING)
 	    ;
+
+
+	/* Terminate the BTE. */
+	/* >>> The other bte transfer will need to be restarted. */
+	HUB_L((shubreg_t *)((nodepda->bte_if[btenum].bte_base_addr +
+		       IIO_IBCT0 - IIO_IBLS0)));
+
+	imem = REMOTE_HUB_L(n, IIO_IMEM);
+	ieclr = REMOTE_HUB_L(n, IIO_IECLR);
+	if (btenum == 0) {
+		imem |= IIO_IMEM_W0ESD | IIO_IMEM_B0ESD;
+		ieclr|= IECLR_BTE0;
+	} else {
+		imem |= IIO_IMEM_W0ESD | IIO_IMEM_B1ESD;
+		ieclr|= IECLR_BTE1;
+	}
+	REMOTE_HUB_S(n, IIO_IMEM, imem);
+	REMOTE_HUB_S(n, IIO_IECLR, ieclr);
+		
+	iidsr  = REMOTE_HUB_L(n, IIO_IIDSR);
+	iidsr &= ~IIO_IIDSR_SENT_MASK;
+	iidsr |= IIO_IIDSR_ENB_MASK;
+	REMOTE_HUB_S(n, IIO_IIDSR, iidsr);
+
+
+ 	bte_reset_nasid(n);
+
+	*nodepda->bte_if[btenum].most_rcnt_na = IBLS_ERROR;
 }
 
diff -Nru a/arch/ia64/sn/io/sn2/ml_SN_intr.c b/arch/ia64/sn/io/sn2/ml_SN_intr.c
--- a/arch/ia64/sn/io/sn2/ml_SN_intr.c	Mon Dec 23 21:21:58 2002
+++ b/arch/ia64/sn/io/sn2/ml_SN_intr.c	Mon Dec 23 21:21:58 2002
@@ -1,4 +1,4 @@
-/* $Id$
+/* $Id: ml_SN_intr.c,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
@@ -13,7 +13,7 @@
  *	handle interrupts on an IPXX board.
  */
 
-#ident  "$Revision: 1.167 $"
+#ident  "$Revision: 1.1 $"
 
 #include <linux/types.h>
 #include <linux/slab.h>
@@ -36,6 +36,7 @@
 #include <asm/sn/pci/pcibr_private.h>
 #include <asm/sn/intr.h>
 #include <asm/sn/sn2/shub_mmr_t.h>
+#include <asm/sn/sn2/shubio.h>
 #include <asm/sal.h>
 #include <asm/sn/sn_sal.h>
 
@@ -51,24 +52,15 @@
 		int sn)
 {
 	int 			nasid = cnodeid_to_nasid(node);
-	nasid_t			console_nasid;
 	sh_ii_int0_config_u_t	ii_int_config;
 	cpuid_t			cpu;
 	cpuid_t			cpu0, cpu1;
 	nodepda_t		*lnodepda;
 	sh_ii_int0_enable_u_t	ii_int_enable;
-	sh_local_int0_config_u_t	local_int_config;
-	sh_local_int0_enable_u_t	local_int_enable;
-	sh_fsb_system_agent_config_u_t	fsb_system_agent;
 	sh_int_node_id_config_u_t	node_id_config;
-	int is_console;
+	extern void sn_init_cpei_timer(void);
+	static int timer_added = 0;
 
-	console_nasid = get_console_nasid();
-	if (console_nasid < 0) {
-		console_nasid = master_nasid;
-	}
-
-	is_console = nasid == console_nasid;
 
 	if (is_headless_node(node) ) {
 		int cnode;
@@ -95,13 +87,15 @@
 	}
 
 	// Get the physical id's of the cpu's on this node.
-	cpu0 = id_eid_to_cpu_physical_id(nasid, 0);
-	cpu1 = id_eid_to_cpu_physical_id(nasid, 1);
+	cpu0 = nasid_slice_to_cpu_physical_id(nasid, 0);
+	cpu1 = nasid_slice_to_cpu_physical_id(nasid, 2);
 
 	HUB_S( (unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_PI_ERROR_MASK), 0);
 	HUB_S( (unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_PI_CRBP_ERROR_MASK), 0);
 
+
 	// The II_INT_CONFIG register for cpu 0.
+	ii_int_config.sh_ii_int0_config_regval = 0;
 	ii_int_config.sh_ii_int0_config_s.type = 0;
 	ii_int_config.sh_ii_int0_config_s.agt = 0;
 	ii_int_config.sh_ii_int0_config_s.pid = cpu0;
@@ -110,7 +104,9 @@
 	HUB_S((unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_II_INT0_CONFIG),
 		ii_int_config.sh_ii_int0_config_regval);
 
+
 	// The II_INT_CONFIG register for cpu 1.
+	ii_int_config.sh_ii_int0_config_regval = 0;
 	ii_int_config.sh_ii_int0_config_s.type = 0;
 	ii_int_config.sh_ii_int0_config_s.agt = 0;
 	ii_int_config.sh_ii_int0_config_s.pid = cpu1;
@@ -119,101 +115,28 @@
 	HUB_S((unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_II_INT1_CONFIG),
 		ii_int_config.sh_ii_int0_config_regval);
 
+
 	// Enable interrupts for II_INT0 and 1.
+	ii_int_enable.sh_ii_int0_enable_regval = 0;
 	ii_int_enable.sh_ii_int0_enable_s.ii_enable = 1;
+#ifdef BUS_INT_WAR
+	/* Dont enable any ints from II. We will poll for interrupts. */
+	ii_int_enable.sh_ii_int0_enable_s.ii_enable = 0;
+
+	/* Enable IPIs. We use them ONLY for send INITs to hung cpus */
+	*(volatile long*)GLOBAL_MMR_ADDR(nasid, SH_IPI_INT_ENABLE) = 1;
+#endif
 
 	HUB_S((unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_II_INT0_ENABLE),
 		ii_int_enable.sh_ii_int0_enable_regval);
 	HUB_S((unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_II_INT1_ENABLE),
 		ii_int_enable.sh_ii_int0_enable_regval);
 
-	// init error regs
-	// LOCAL_INT0 is for the UART only.
-
-	local_int_config.sh_local_int0_config_s.type = 0;
-	local_int_config.sh_local_int0_config_s.agt = 0;
-	local_int_config.sh_local_int0_config_s.pid = cpu;
-	local_int_config.sh_local_int0_config_s.base = 0;
-	local_int_config.sh_local_int0_config_s.idx = SGI_UART_VECTOR;
-
-	HUB_S((unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_LOCAL_INT0_CONFIG),
-		local_int_config.sh_local_int0_config_regval);
-
-	// LOCAL_INT1 is for all hardware errors.
-	// It will send a BERR, which will result in an MCA.
-	local_int_config.sh_local_int0_config_s.idx = 0;
-
-	HUB_S((unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_LOCAL_INT1_CONFIG),
-		local_int_config.sh_local_int0_config_regval);
-
-	// Clear the LOCAL_INT_ENABLE register.
-	local_int_enable.sh_local_int0_enable_regval = 0;
-
-	if (is_console) {
-		// Enable the UART interrupt.  Only applies to the console nasid.
-		local_int_enable.sh_local_int0_enable_s.uart_int = 1;
-
-		HUB_S((unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_LOCAL_INT0_ENABLE),
-			local_int_enable.sh_local_int0_enable_regval);
-	}
-
-	// Enable all the error interrupts.
-	local_int_enable.sh_local_int0_enable_s.uart_int = 0;
-	local_int_enable.sh_local_int0_enable_s.pi_hw_int = 1;
-	local_int_enable.sh_local_int0_enable_s.md_hw_int = 1;
-	local_int_enable.sh_local_int0_enable_s.xn_hw_int = 1;
-	local_int_enable.sh_local_int0_enable_s.lb_hw_int = 1;
-	local_int_enable.sh_local_int0_enable_s.ii_hw_int = 1;
-	local_int_enable.sh_local_int0_enable_s.pi_uce_int = 1;
-	local_int_enable.sh_local_int0_enable_s.md_uce_int = 1;
-	local_int_enable.sh_local_int0_enable_s.xn_uce_int = 1;
-	local_int_enable.sh_local_int0_enable_s.system_shutdown_int = 1;
-	local_int_enable.sh_local_int0_enable_s.l1_nmi_int = 1;
-	local_int_enable.sh_local_int0_enable_s.stop_clock = 1;
-
-
-	// Send BERR, rather than an interrupt, for shub errors.
-	local_int_config.sh_local_int0_config_s.agt = 1;
-	HUB_S((unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_LOCAL_INT1_CONFIG),
-		local_int_config.sh_local_int0_config_regval);
-
-	HUB_S((unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_LOCAL_INT1_ENABLE),
-		local_int_enable.sh_local_int0_enable_regval);
-
-	// Make sure BERR is enabled.
-	fsb_system_agent.sh_fsb_system_agent_config_regval = 
-		HUB_L( (unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_FSB_SYSTEM_AGENT_CONFIG) );
-	fsb_system_agent.sh_fsb_system_agent_config_s.berr_assert_en = 1;
-	HUB_S((unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_FSB_SYSTEM_AGENT_CONFIG),
-		fsb_system_agent.sh_fsb_system_agent_config_regval);
-
-	// Set LOCAL_INT2 to field CEs
-
-	local_int_enable.sh_local_int0_enable_regval = 0;
-
-	local_int_config.sh_local_int0_config_s.agt = 0;
-	local_int_config.sh_local_int0_config_s.idx = SGI_SHUB_ERROR_VECTOR;
-	HUB_S((unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_LOCAL_INT2_CONFIG),
-		local_int_config.sh_local_int0_config_regval);
-
-	local_int_enable.sh_local_int0_enable_s.pi_ce_int = 1;
-	local_int_enable.sh_local_int0_enable_s.md_ce_int = 1;
-	local_int_enable.sh_local_int0_enable_s.xn_ce_int = 1;
-
-	HUB_S((unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_LOCAL_INT2_ENABLE),
-		local_int_enable.sh_local_int0_enable_regval);
-
-	// Make sure all the rest of the LOCAL_INT regs are disabled.
-	local_int_enable.sh_local_int0_enable_regval = 0;
-	HUB_S((unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_LOCAL_INT3_ENABLE),
-		local_int_enable.sh_local_int0_enable_regval);
-
-	HUB_S((unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_LOCAL_INT4_ENABLE),
-		local_int_enable.sh_local_int0_enable_regval);
-
-	HUB_S((unsigned long *)GLOBAL_MMR_ADDR(nasid, SH_LOCAL_INT5_ENABLE),
-		local_int_enable.sh_local_int0_enable_regval);
 
+	if (!timer_added) { // can only init the timer once.
+		timer_added = 1;
+		sn_init_cpei_timer();
+	}
 }
 
 // (Un)Reserve an irq on this cpu.
@@ -393,31 +316,40 @@
 		int *resp_bit)
 {
 	cpuid_t		cpuid;
-	cnodeid_t	candidate = -1;
+	cpuid_t		candidate = CPU_NONE;
+	cnodeid_t	candidate_node;
 	devfs_handle_t	pconn_vhdl;
 	pcibr_soft_t	pcibr_soft;
+	int 		bit;
 
 /* SN2 + pcibr addressing limitation */
 /* Due to this limitation, all interrupts from a given bridge must go to the name node.*/
+/* The interrupt must also be targetted for the same processor. */
 /* This limitation does not exist on PIC. */
+/* But, the processor limitation will stay.  The limitation will be similar to */
+/* the bedrock/xbridge limit regarding PI's */
 
 	if ( (hwgraph_edge_get(dev, EDGE_LBL_PCI, &pconn_vhdl) == GRAPH_SUCCESS) &&
 		( (pcibr_soft = pcibr_soft_get(pconn_vhdl) ) != NULL) ) {
 			if (pcibr_soft->bsi_err_intr) {
-				candidate = cpuid_to_cnodeid( ((hub_intr_t)pcibr_soft->bsi_err_intr)->i_cpuid);
+				candidate =  ((hub_intr_t)pcibr_soft->bsi_err_intr)->i_cpuid;
 			}
 	}
 
-	if (candidate >= 0) {
-		// The node was chosen already when we assigned the error interrupt.
-		cpuid = intr_bit_reserve_test(CPU_NONE,
-						0,
-						candidate,
-						req_bit,
-						0,
-						owner_dev,
-						name,
-						resp_bit);
+
+	if (candidate != CPU_NONE) {
+		// The cpu was chosen already when we assigned the error interrupt.
+		bit = intr_reserve_level(candidate, 
+					req_bit, 
+					resflags, 
+					owner_dev, 
+					name);
+		if (bit < 0) {
+			cpuid = CPU_NONE;
+		} else {
+			cpuid = candidate;
+			*resp_bit = bit;
+		}
 	} else {
 		// Need to choose one.  Try the controlling c-brick first.
 		cpuid = intr_bit_reserve_test(CPU_NONE,
@@ -434,10 +366,9 @@
 		return cpuid;
 	}
 
-	if (candidate >= 0) {
-		printk("Cannot target interrupt to target node (%d).\n",candidate);
-		return CPU_NONE;
-	} else {
+	if (candidate  != CPU_NONE) {
+		printk("Cannot target interrupt to target node (%ld).\n",candidate);
+		return CPU_NONE; } else {
 		printk("Cannot target interrupt to closest node (%d) 0x%p\n",
 			master_node_get(dev), (void *)owner_dev);
 	}
@@ -448,11 +379,11 @@
 	{
 		static cnodeid_t last_node = -1;
 		if (last_node >= numnodes) last_node = 0;
-		for (candidate = last_node + 1; candidate != last_node; candidate++) {
-			if (candidate == numnodes) candidate = 0;
+		for (candidate_node = last_node + 1; candidate_node != last_node; candidate_node++) {
+			if (candidate_node == numnodes) candidate_node = 0;
 			cpuid = intr_bit_reserve_test(CPU_NONE,
 							0,
-							candidate,
+							candidate_node,
 							req_bit,
 							0,
 							owner_dev,
diff -Nru a/arch/ia64/sn/io/sn2/pcibr/pcibr_ate.c b/arch/ia64/sn/io/sn2/pcibr/pcibr_ate.c
--- a/arch/ia64/sn/io/sn2/pcibr/pcibr_ate.c	Mon Dec 23 21:21:51 2002
+++ b/arch/ia64/sn/io/sn2/pcibr/pcibr_ate.c	Mon Dec 23 21:21:51 2002
@@ -44,24 +44,6 @@
 #endif
 
 
-#ifdef LATER
-#if (PCIBR_FREEZE_TIME) || PCIBR_ATE_DEBUG
-LOCAL struct reg_desc   ate_bits[] =
-{
-    {0xFFFF000000000000ull, -48, "RMF", "%x"},
-    {~(IOPGSIZE - 1) &			/* may trim off some low bits */
-     0x0000FFFFFFFFF000ull, 0, "XIO", "%x"},
-    {0x0000000000000F00ull, -8, "port", "%x"},
-    {0x0000000000000010ull, 0, "Barrier"},
-    {0x0000000000000008ull, 0, "Prefetch"},
-    {0x0000000000000004ull, 0, "Precise"},
-    {0x0000000000000002ull, 0, "Coherent"},
-    {0x0000000000000001ull, 0, "Valid"},
-    {0}
-};
-#endif
-#endif	/* LATER */
-
 #ifndef LOCAL
 #define LOCAL           static
 #endif
@@ -79,7 +61,7 @@
 	   			unsigned *freeze_time_ptr,
 #endif
 	   			unsigned *cmd_regs);
-void 	  ate_write(bridge_ate_p ate_ptr, int ate_count, bridge_ate_t ate);
+void 	  ate_write(pcibr_soft_t pcibr_soft, bridge_ate_p ate_ptr, int ate_count, bridge_ate_t ate);
 void ate_thaw(pcibr_dmamap_t pcibr_dmamap,
 	 			int ate_index,
 #if PCIBR_FREEZE_TIME
@@ -119,26 +101,73 @@
     int                     i, j;
     bridgereg_t             old_enable, new_enable;
     int                     s;
+    int			    this_is_pic = is_pic(bridge);
 
     /* Probe SSRAM to determine its size. */
-    old_enable = bridge->b_int_enable;
-    new_enable = old_enable & ~BRIDGE_IMR_PCI_MST_TIMEOUT;
-    bridge->b_int_enable = new_enable;
+    if ( this_is_pic ) {
+	old_enable = bridge->b_int_enable;
+	new_enable = old_enable & ~BRIDGE_IMR_PCI_MST_TIMEOUT;
+	bridge->b_int_enable = new_enable;
+    }
+    else {
+	if (io_get_sh_swapper(NASID_GET(bridge))) {
+		old_enable = BRIDGE_REG_GET32((&bridge->b_int_enable));
+		new_enable = old_enable & ~BRIDGE_IMR_PCI_MST_TIMEOUT;
+		BRIDGE_REG_SET32((&bridge->b_int_enable)) = new_enable;
+	}
+	else {
+		old_enable = bridge->b_int_enable;
+		new_enable = old_enable & ~BRIDGE_IMR_PCI_MST_TIMEOUT;
+		bridge->b_int_enable = new_enable;
+	}
+    }
 
     for (i = 1; i < ATE_NUM_SIZES; i++) {
 	/* Try writing a value */
-	bridge->b_ext_ate_ram[ATE_NUM_ENTRIES(i) - 1] = ATE_PROBE_VALUE;
+	if ( this_is_pic ) {
+		bridge->b_ext_ate_ram[ATE_NUM_ENTRIES(i) - 1] = ATE_PROBE_VALUE;
+	}
+	else {
+		if (io_get_sh_swapper(NASID_GET(bridge)))
+			bridge->b_ext_ate_ram[ATE_NUM_ENTRIES(i) - 1] = __swab64(ATE_PROBE_VALUE);
+		else
+			bridge->b_ext_ate_ram[ATE_NUM_ENTRIES(i) - 1] = ATE_PROBE_VALUE;
+	}
 
 	/* Guard against wrap */
 	for (j = 1; j < i; j++)
 	    bridge->b_ext_ate_ram[ATE_NUM_ENTRIES(j) - 1] = 0;
 
 	/* See if value was written */
-	if (bridge->b_ext_ate_ram[ATE_NUM_ENTRIES(i) - 1] == ATE_PROBE_VALUE)
-	    largest_working_size = i;
+	if ( this_is_pic ) {
+		if (bridge->b_ext_ate_ram[ATE_NUM_ENTRIES(i) - 1] == ATE_PROBE_VALUE)
+				largest_working_size = i;
+	}
+	else {
+		if (io_get_sh_swapper(NASID_GET(bridge))) {
+			if (bridge->b_ext_ate_ram[ATE_NUM_ENTRIES(i) - 1] == __swab64(ATE_PROBE_VALUE))
+					largest_working_size = i;
+			else {
+				if (bridge->b_ext_ate_ram[ATE_NUM_ENTRIES(i) - 1] == ATE_PROBE_VALUE)
+					largest_working_size = i;
+			}
+		}
+	}
+    }
+    if ( this_is_pic ) {
+	bridge->b_int_enable = old_enable;
+	bridge->b_wid_tflush;		/* wait until Bridge PIO complete */
+    }
+    else {
+	if (io_get_sh_swapper(NASID_GET(bridge))) {
+		BRIDGE_REG_SET32((&bridge->b_int_enable)) = old_enable;
+		BRIDGE_REG_GET32((&bridge->b_wid_tflush));   /* wait until Bridge PIO complete */
+	}
+	else {
+		bridge->b_int_enable = old_enable;
+		bridge->b_wid_tflush;               /* wait until Bridge PIO complete */
+	}
     }
-    bridge->b_int_enable = old_enable;
-    bridge->b_wid_tflush;		/* wait until Bridge PIO complete */
 
     /*
      * ensure that we write and read without any interruption.
@@ -146,20 +175,41 @@
      */
 
     s = splhi();
-    bridge->b_wid_control = (bridge->b_wid_control
-	& ~BRIDGE_CTRL_SSRAM_SIZE_MASK)
-	| BRIDGE_CTRL_SSRAM_SIZE(largest_working_size);
-    bridge->b_wid_control;		/* inval addr bug war */
+    if ( this_is_pic ) {
+	bridge->b_wid_control = (bridge->b_wid_control
+			& ~BRIDGE_CTRL_SSRAM_SIZE_MASK)
+			| BRIDGE_CTRL_SSRAM_SIZE(largest_working_size);
+	bridge->b_wid_control;		/* inval addr bug war */
+    }
+    else {
+	if (io_get_sh_swapper(NASID_GET(bridge))) {
+		BRIDGE_REG_SET32((&(bridge->b_wid_control))) = 
+				__swab32((BRIDGE_REG_GET32((&bridge->b_wid_control))
+					& ~BRIDGE_CTRL_SSRAM_SIZE_MASK)
+					| BRIDGE_CTRL_SSRAM_SIZE(largest_working_size));
+		BRIDGE_REG_GET32((&bridge->b_wid_control));/* inval addr bug war */
+	}
+	else {
+		bridge->b_wid_control = (bridge->b_wid_control & ~BRIDGE_CTRL_SSRAM_SIZE_MASK)
+				| BRIDGE_CTRL_SSRAM_SIZE(largest_working_size);
+		bridge->b_wid_control;              /* inval addr bug war */
+	}
+    }
     splx(s);
 
     num_entries = ATE_NUM_ENTRIES(largest_working_size);
 
-#if PCIBR_ATE_DEBUG
-    if (num_entries)
-	printk("bridge at 0x%x: clearing %d external ATEs\n", bridge, num_entries);
-    else
-	printk("bridge at 0x%x: no external ATE RAM found\n", bridge);
-#endif
+    if (pcibr_debug_mask & PCIBR_DEBUG_ATE) {
+	if (num_entries) {
+	    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ATE, NULL,
+			"bridge at 0x%x: clearing %d external ATEs\n",
+			bridge, num_entries));
+	} else {
+	    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ATE, NULL,
+			"bridge at 0x%x: no external ATE RAM found\n",
+			bridge));
+	}
+    }
 
     /* Initialize external mapping entries */
     for (entry = 0; entry < num_entries; entry++)
@@ -339,7 +389,8 @@
 #endif
 
     cmd_lwa = 0;
-    for (slot = 0; slot < 8; ++slot)
+    for (slot = pcibr_soft->bs_min_slot; 
+		slot < PCIBR_NUM_SLOTS(pcibr_soft); ++slot)
 	if (atomic_read(&pcibr_soft->bs_slot[slot].bss_ext_ates_active)) {
 	    cmd_reg = pcibr_soft->
 		bs_slot[slot].
@@ -366,28 +417,54 @@
 	    cmd_lwa[0];
 
 	    /* Flush all the write buffers in the bridge */
-	    for (slot = 0; slot < 8; ++slot)
+	    for (slot = pcibr_soft->bs_min_slot; 
+				slot < PCIBR_NUM_SLOTS(pcibr_soft); ++slot) {
 		    if (atomic_read(&pcibr_soft->bs_slot[slot].bss_ext_ates_active)) {
 			    /* Flush the write buffer associated with this
 			     * PCI device which might be using dma map RAM.
 			     */
-			    bridge->b_wr_req_buf[slot].reg;
+			if ( is_pic(bridge) ) {
+				bridge->b_wr_req_buf[slot].reg;
+			}
+			else {
+				if (io_get_sh_swapper(NASID_GET(bridge)) ) {
+					BRIDGE_REG_GET32((&bridge->b_wr_req_buf[slot].reg));
+				}
+				else
+					bridge->b_wr_req_buf[slot].reg;
+			}
 		    }
+	    }
     }
     return s;
 }
 
-#define	ATE_WRITE()    ate_write(ate_ptr, ate_count, ate)
-
 void
-ate_write(bridge_ate_p ate_ptr,
+ate_write(pcibr_soft_t pcibr_soft,
+	  bridge_ate_p ate_ptr,
 	  int ate_count,
 	  bridge_ate_t ate)
 {
-    while (ate_count-- > 0) {
-	*ate_ptr++ = ate;
-	ate += IOPGSIZE;
-    }
+	if (IS_PIC_SOFT(pcibr_soft) ) {
+    		while (ate_count-- > 0) {
+			*ate_ptr++ = ate;
+			ate += IOPGSIZE;
+		}
+	}
+	else {
+		if (io_get_sh_swapper(NASID_GET(ate_ptr))) {
+    			while (ate_count-- > 0) {
+				*ate_ptr++ = __swab64(ate);
+				ate += IOPGSIZE;
+			}
+		}
+		else {
+    			while (ate_count-- > 0) {
+				*ate_ptr++ = ate;
+				ate += IOPGSIZE;
+			}
+		}
+	}
 }
 
 #if PCIBR_FREEZE_TIME
@@ -425,10 +502,24 @@
 	return;
 
     /* restore cmd regs */
-    for (slot = 0; slot < 8; ++slot)
-	if ((cmd_reg = cmd_regs[slot]) & PCI_CMD_BUS_MASTER)
-	    bridge->b_type0_cfg_dev[slot].l[PCI_CFG_COMMAND / 4] = cmd_reg;
-
+    for (slot = pcibr_soft->bs_min_slot; 
+		slot < PCIBR_NUM_SLOTS(pcibr_soft); ++slot) {
+	if ((cmd_reg = cmd_regs[slot]) & PCI_CMD_BUS_MASTER) {
+		if ( IS_PIC_SOFT(pcibr_soft) ) {
+			pcibr_slot_config_set(bridge, slot, PCI_CFG_COMMAND/4, cmd_reg);
+		}
+		else {
+			if (io_get_sh_swapper(NASID_GET(bridge))) {
+				bridge->b_type0_cfg_dev[slot].l[PCI_CFG_COMMAND / 4] = __swab32(cmd_reg);
+			}
+			else {
+//				BUG(); /* Does this really work if called when io_get_sh_swapper = 0? */
+//				bridge->b_type0_cfg_dev[slot].l[PCI_CFG_COMMAND / 4] = cmd_reg;
+				pcibr_slot_config_set(bridge, slot, PCI_CFG_COMMAND/4, cmd_reg);
+			}
+		}
+	}
+    }
     pcibr_dmamap->bd_flags |= PCIBR_DMAMAP_BUSY;
     atomic_inc(&(pcibr_soft->bs_slot[dma_slot]. bss_ext_ates_active));
 
@@ -442,7 +533,7 @@
 	if (max_ate_total < ate_total)
 	    max_ate_total = ate_total;
 	pcibr_unlock(pcibr_soft, s);
-	printk("%s: pci freeze time %d usec for %d ATEs\n"
+	printk( "%s: pci freeze time %d usec for %d ATEs\n"
 		"\tfirst ate: %R\n",
 		pcibr_soft->bs_name,
 		freeze_time * 1000 / 1250,
diff -Nru a/arch/ia64/sn/io/sn2/pcibr/pcibr_config.c b/arch/ia64/sn/io/sn2/pcibr/pcibr_config.c
--- a/arch/ia64/sn/io/sn2/pcibr/pcibr_config.c	Mon Dec 23 21:21:59 2002
+++ b/arch/ia64/sn/io/sn2/pcibr/pcibr_config.c	Mon Dec 23 21:21:59 2002
@@ -10,6 +10,7 @@
 #include <linux/types.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/byteorder/swab.h>
 #include <asm/sn/sgi.h>
 #include <asm/sn/sn_cpuid.h>
 #include <asm/sn/addrs.h>
@@ -34,64 +35,233 @@
 extern pcibr_info_t      pcibr_info_get(devfs_handle_t);
 
 uint64_t          pcibr_config_get(devfs_handle_t, unsigned, unsigned);
-uint64_t          do_pcibr_config_get(cfg_p, unsigned, unsigned);
+uint64_t          do_pcibr_config_get(int, cfg_p, unsigned, unsigned);
 void              pcibr_config_set(devfs_handle_t, unsigned, unsigned, uint64_t);
-void              do_pcibr_config_set(cfg_p, unsigned, unsigned, uint64_t);
+void       	  do_pcibr_config_set(int, cfg_p, unsigned, unsigned, uint64_t);
+static void	  swap_do_pcibr_config_set(cfg_p, unsigned, unsigned, uint64_t);
 
+#ifdef LITTLE_ENDIAN
+/*
+ * on sn-ia we need to twiddle the the addresses going out
+ * the pci bus because we use the unswizzled synergy space
+ * (the alternative is to use the swizzled synergy space
+ * and byte swap the data)
+ */
+#define CB(b,r) (((volatile uint8_t *) b)[((r)^4)])
+#define CS(b,r) (((volatile uint16_t *) b)[((r^4)/2)])
+#define CW(b,r) (((volatile uint32_t *) b)[((r^4)/4)])
+
+#define	CBP(b,r) (((volatile uint8_t *) b)[(r)^3])
+#define	CSP(b,r) (((volatile uint16_t *) b)[((r)/2)^1])
+#define	CWP(b,r) (((volatile uint32_t *) b)[(r)/4])
+
+#define SCB(b,r) (((volatile uint8_t *) b)[((r)^3)])
+#define SCS(b,r) (((volatile uint16_t *) b)[((r^2)/2)])
+#define SCW(b,r) (((volatile uint32_t *) b)[((r)/4)])
+#else
 #define	CB(b,r)	(((volatile uint8_t *) cfgbase)[(r)^3])
 #define	CS(b,r)	(((volatile uint16_t *) cfgbase)[((r)/2)^1])
 #define	CW(b,r)	(((volatile uint32_t *) cfgbase)[(r)/4])
+#endif
 
+/*
+ * Return a config space address for given slot / func / offset.  Note the
+ * returned pointer is a 32bit word (ie. cfg_p) aligned pointer pointing to
+ * the 32bit word that contains the "offset" byte.
+ */
+cfg_p
+pcibr_func_config_addr(bridge_t *bridge, pciio_bus_t bus, pciio_slot_t slot, 
+					pciio_function_t func, int offset)
+{
+	/*
+	 * Type 1 config space
+	 */
+	if (bus > 0) {
+		bridge->b_pci_cfg = ((bus << 16) | (slot << 11));
+		return &bridge->b_type1_cfg.f[func].l[(offset)];
+	}
+
+	/*
+	 * Type 0 config space
+	 */
+	if (is_pic(bridge))
+		slot++;
+	return &bridge->b_type0_cfg_dev[slot].f[func].l[offset];
+}
+
+/*
+ * Return config space address for given slot / offset.  Note the returned
+ * pointer is a 32bit word (ie. cfg_p) aligned pointer pointing to the
+ * 32bit word that contains the "offset" byte.
+ */
+cfg_p
+pcibr_slot_config_addr(bridge_t *bridge, pciio_slot_t slot, int offset)
+{
+	return pcibr_func_config_addr(bridge, 0, slot, 0, offset);
+}
+
+/*
+ * Return config space data for given slot / offset
+ */
+unsigned
+pcibr_slot_config_get(bridge_t *bridge, pciio_slot_t slot, int offset)
+{
+	cfg_p  cfg_base;
+	
+	cfg_base = pcibr_slot_config_addr(bridge, slot, 0);
+	return (do_pcibr_config_get(is_pic(bridge), cfg_base, offset, sizeof(unsigned)));
+}
+
+/*
+ * Return config space data for given slot / func / offset
+ */
+unsigned
+pcibr_func_config_get(bridge_t *bridge, pciio_slot_t slot, 
+					pciio_function_t func, int offset)
+{
+	cfg_p  cfg_base;
+
+	cfg_base = pcibr_func_config_addr(bridge, 0, slot, func, 0);
+	return (do_pcibr_config_get(is_pic(bridge), cfg_base, offset, sizeof(unsigned)));
+}
+
+/*
+ * Set config space data for given slot / offset
+ */
+void
+pcibr_slot_config_set(bridge_t *bridge, pciio_slot_t slot, 
+					int offset, unsigned val)
+{
+	cfg_p  cfg_base;
+
+	cfg_base = pcibr_slot_config_addr(bridge, slot, 0);
+	do_pcibr_config_set(is_pic(bridge), cfg_base, offset, sizeof(unsigned), val);
+}
+
+/*
+ * Set config space data for given slot / func / offset
+ */
+void
+pcibr_func_config_set(bridge_t *bridge, pciio_slot_t slot, 
+			pciio_function_t func, int offset, unsigned val)
+{
+	cfg_p  cfg_base;
+
+	cfg_base = pcibr_func_config_addr(bridge, 0, slot, func, 0);
+	do_pcibr_config_set(is_pic(bridge), cfg_base, offset, sizeof(unsigned), val);
+}
+
+int pcibr_config_debug = 0;
 
 cfg_p
 pcibr_config_addr(devfs_handle_t conn,
 		  unsigned reg)
 {
     pcibr_info_t            pcibr_info;
+    pciio_bus_t		    pciio_bus;
     pciio_slot_t            pciio_slot;
     pciio_function_t        pciio_func;
     pcibr_soft_t            pcibr_soft;
     bridge_t               *bridge;
     cfg_p                   cfgbase = (cfg_p)0;
+    pciio_info_t	    pciio_info;
 
+    pciio_info = pciio_info_get(conn);
     pcibr_info = pcibr_info_get(conn);
 
-    pciio_slot = pcibr_info->f_slot;
+    /*
+     * Determine the PCI bus/slot/func to generate a config address for.
+     */
+
+    if (pciio_info_type1_get(pciio_info)) {
+	/*
+	 * Conn is a vhdl which uses TYPE 1 addressing explicitly passed 
+	 * in reg.
+	 */
+	pciio_bus = PCI_TYPE1_BUS(reg);
+	pciio_slot = PCI_TYPE1_SLOT(reg);
+	pciio_func = PCI_TYPE1_FUNC(reg);
+
+	ASSERT(pciio_bus != 0);
+#if 0
+    } else if (conn != pciio_info_hostdev_get(pciio_info)) {
+	/*
+	 * Conn is on a subordinate bus, so get bus/slot/func directly from
+	 * its pciio_info_t structure.
+	 */
+	pciio_bus = pciio_info->c_bus;
+	pciio_slot = pciio_info->c_slot;
+	pciio_func = pciio_info->c_func;
+	if (pciio_func == PCIIO_FUNC_NONE) {
+		pciio_func = 0;
+	}
+#endif
+    } else {
+	/*
+	 * Conn is directly connected to the host bus.  PCI bus number is
+	 * hardcoded to 0 (even though it may have a logical bus number != 0)
+	 * and slot/function are derived from the pcibr_info_t associated
+	 * with the device.
+	 */
+	pciio_bus = 0;
+
+    pciio_slot = PCIBR_INFO_SLOT_GET_INT(pcibr_info);
     if (pciio_slot == PCIIO_SLOT_NONE)
 	pciio_slot = PCI_TYPE1_SLOT(reg);
 
     pciio_func = pcibr_info->f_func;
     if (pciio_func == PCIIO_FUNC_NONE)
 	pciio_func = PCI_TYPE1_FUNC(reg);
+    }
 
     pcibr_soft = (pcibr_soft_t) pcibr_info->f_mfast;
 
     bridge = pcibr_soft->bs_base;
 
-    cfgbase = bridge->b_type0_cfg_dev[pciio_slot].f[pciio_func].l;
+    cfgbase = pcibr_func_config_addr(bridge,
+			pciio_bus, pciio_slot, pciio_func, 0);
 
     return cfgbase;
 }
 
+extern unsigned char Is_pic_on_this_nasid[];
 uint64_t
 pcibr_config_get(devfs_handle_t conn,
 		 unsigned reg,
 		 unsigned size)
 {
-    return do_pcibr_config_get(pcibr_config_addr(conn, reg),
-			       PCI_TYPE1_REG(reg), size);
+    if ( !Is_pic_on_this_nasid[ NASID_GET((pcibr_config_addr(conn, reg)))] )
+    	return do_pcibr_config_get(0, pcibr_config_addr(conn, reg),
+				PCI_TYPE1_REG(reg), size);
+    else
+    	return do_pcibr_config_get(1, pcibr_config_addr(conn, reg),
+				PCI_TYPE1_REG(reg), size);
 }
 
 uint64_t
 do_pcibr_config_get(
+		       int pic,
 		       cfg_p cfgbase,
 		       unsigned reg,
 		       unsigned size)
 {
     unsigned                value;
 
-    value = CW(cfgbase, reg);
-
+    if ( pic ) {
+	value = CWP(cfgbase, reg);
+    }
+    else {
+	if ( io_get_sh_swapper(NASID_GET(cfgbase)) ) {
+	    /*
+	     * Shub Swapper on - 0 returns PCI Offset 0 but byte swapped!
+	     * Do not swizzle address and byte swap the result.
+	     */
+	    value = SCW(cfgbase, reg);
+	    value = __swab32(value);
+	} else {
+    	    value = CW(cfgbase, reg);
+	}
+    }
     if (reg & 3)
 	value >>= 8 * (reg & 3);
     if (size < 4)
@@ -105,39 +275,103 @@
 		 unsigned size,
 		 uint64_t value)
 {
-    do_pcibr_config_set(pcibr_config_addr(conn, reg),
+    if ( Is_pic_on_this_nasid[ NASID_GET((pcibr_config_addr(conn, reg)))] )
+    	do_pcibr_config_set(1, pcibr_config_addr(conn, reg),
+			PCI_TYPE1_REG(reg), size, value);
+    else
+	swap_do_pcibr_config_set(pcibr_config_addr(conn, reg),
 			PCI_TYPE1_REG(reg), size, value);
 }
 
 void
-do_pcibr_config_set(cfg_p cfgbase,
+do_pcibr_config_set(int pic,
+		    cfg_p cfgbase,
 		    unsigned reg,
 		    unsigned size,
 		    uint64_t value)
 {
+	if ( pic ) {
+		switch (size) {
+		case 1:
+			CBP(cfgbase, reg) = value;
+			break;
+		case 2:
+			if (reg & 1) {
+				CBP(cfgbase, reg) = value;
+				CBP(cfgbase, reg + 1) = value >> 8;
+			} else
+				CSP(cfgbase, reg) = value;
+			break;
+		case 3:
+			if (reg & 1) {
+				CBP(cfgbase, reg) = value;
+				CSP(cfgbase, (reg + 1)) = value >> 8;
+			} else {
+				CSP(cfgbase, reg) = value;
+				CBP(cfgbase, reg + 2) = value >> 16;
+			}
+			break;
+		case 4:
+			CWP(cfgbase, reg) = value;
+			break;
+   		}
+	}
+	else {
+		switch (size) {
+		case 1:
+			CB(cfgbase, reg) = value;
+			break;
+		case 2:
+			if (reg & 1) {
+				CB(cfgbase, reg) = value;
+				CB(cfgbase, reg + 1) = value >> 8;
+			} else
+				CS(cfgbase, reg) = value;
+			break;
+		case 3:
+			if (reg & 1) {
+				CB(cfgbase, reg) = value;
+				CS(cfgbase, (reg + 1)) = value >> 8;
+			} else {
+				CS(cfgbase, reg) = value;
+				CB(cfgbase, reg + 2) = value >> 16;
+			}
+			break;
+		case 4:
+			CW(cfgbase, reg) = value;
+			break;
+   		}
+	}
+}
+
+void
+swap_do_pcibr_config_set(cfg_p cfgbase,
+                    unsigned reg,
+                    unsigned size,
+                    uint64_t value)
+{
+
+    uint64_t temp_value = 0;
+
     switch (size) {
     case 1:
-	CB(cfgbase, reg) = value;
-	break;
+        SCB(cfgbase, reg) = value;
+        break;
     case 2:
-	if (reg & 1) {
-	    CB(cfgbase, reg) = value;
-	    CB(cfgbase, reg + 1) = value >> 8;
-	} else
-	    CS(cfgbase, reg) = value;
-	break;
+	temp_value = __swab16(value);
+        if (reg & 1) {
+            SCB(cfgbase, reg) = temp_value;
+            SCB(cfgbase, reg + 1) = temp_value >> 8;
+        } else
+            SCS(cfgbase, reg) = temp_value;
+        break;
     case 3:
-	if (reg & 1) {
-	    CB(cfgbase, reg) = value;
-	    CS(cfgbase, (reg + 1)) = value >> 8;
-	} else {
-	    CS(cfgbase, reg) = value;
-	    CB(cfgbase, reg + 2) = value >> 16;
-	}
-	break;
+	BUG();
+        break;
 
     case 4:
-	CW(cfgbase, reg) = value;
-	break;
+	temp_value = __swab32(value);
+        SCW(cfgbase, reg) = temp_value;
+        break;
     }
 }
diff -Nru a/arch/ia64/sn/io/sn2/pcibr/pcibr_dvr.c b/arch/ia64/sn/io/sn2/pcibr/pcibr_dvr.c
--- a/arch/ia64/sn/io/sn2/pcibr/pcibr_dvr.c	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/sn/io/sn2/pcibr/pcibr_dvr.c	Mon Dec 23 21:21:55 2002
@@ -7,7 +7,6 @@
  * Copyright (C) 2001-2002 Silicon Graphics, Inc. All rights reserved.
  */
 
-
 #include <linux/types.h>
 #include <linux/slab.h>
 #include <linux/module.h>
@@ -40,6 +39,25 @@
 #endif
 
 /*
+ * global variables to toggle the different levels of pcibr debugging.  
+ *   -pcibr_debug_mask is the mask of the different types of debugging
+ *    you want to enable.  See sys/PCI/pcibr_private.h 
+ *   -pcibr_debug_module is the module you want to trace.  By default
+ *    all modules are trace.  For IP35 this value has the format of
+ *    something like "001c10".  For IP27 this value is a node number,
+ *    i.e. "1", "2"...  For IP30 this is undefined and should be set to
+ *    'all'.
+ *   -pcibr_debug_widget is the widget you want to trace.  For IP27
+ *    the widget isn't exposed in the hwpath so use the xio slot num.
+ *    i.e. for 'io2' set pcibr_debug_widget to "2".
+ *   -pcibr_debug_slot is the pci slot you want to trace.
+ */
+uint32_t pcibr_debug_mask = 0x0;	/* 0x00000000 to disable */
+char      *pcibr_debug_module = "all";		/* 'all' for all modules */
+int	   pcibr_debug_widget = -1;		/* '-1' for all widgets  */
+int	   pcibr_debug_slot = -1;		/* '-1' for all slots    */
+
+/*
  * Macros related to the Lucent USS 302/312 usb timeout workaround.  It
  * appears that if the lucent part can get into a retry loop if it sees a
  * DAC on the bus during a pio read retry.  The loop is broken after about
@@ -64,62 +82,24 @@
  * appropriate function name below.
  */
 struct file_operations pcibr_fops = {
-	.owner =THIS_MODULE,
-	.llseek = NULL,
-	.read = NULL,
-	.write = NULL,
-	.readdir = NULL,
-	.poll = NULL,
-	.ioctl = NULL,
-	.mmap = NULL,
-	.open = NULL,
-	.flush = NULL,
-	.release = NULL,
-	.fsync = NULL,
-	.fasync = NULL,
-	.lock = NULL,
-	.readv = NULL,
-	.writev = NULL
-};
-
-#ifdef LATER
-
-#if PCIBR_ATE_DEBUG
-static struct reg_values ssram_sizes[] =
-{
-    {BRIDGE_CTRL_SSRAM_512K, "512k"},
-    {BRIDGE_CTRL_SSRAM_128K, "128k"},
-    {BRIDGE_CTRL_SSRAM_64K, "64k"},
-    {BRIDGE_CTRL_SSRAM_1K, "1k"},
-    {0}
+	owner:  THIS_MODULE,
+	llseek: NULL,
+	read: NULL,
+	write: NULL,
+	readdir: NULL,
+	poll: NULL,
+	ioctl: NULL,
+	mmap: NULL,
+	open: NULL,
+	flush: NULL,
+	release: NULL,
+	fsync: NULL,
+	fasync: NULL,
+	lock: NULL,
+	readv: NULL,
+	writev: NULL
 };
 
-static struct reg_desc   control_bits[] =
-{
-    {BRIDGE_CTRL_FLASH_WR_EN, 0, "FLASH_WR_EN"},
-    {BRIDGE_CTRL_EN_CLK50, 0, "EN_CLK50"},
-    {BRIDGE_CTRL_EN_CLK40, 0, "EN_CLK40"},
-    {BRIDGE_CTRL_EN_CLK33, 0, "EN_CLK33"},
-    {BRIDGE_CTRL_RST_MASK, -24, "RST", "%x"},
-    {BRIDGE_CTRL_IO_SWAP, 0, "IO_SWAP"},
-    {BRIDGE_CTRL_MEM_SWAP, 0, "MEM_SWAP"},
-    {BRIDGE_CTRL_PAGE_SIZE, 0, "PAGE_SIZE"},
-    {BRIDGE_CTRL_SS_PAR_BAD, 0, "SS_PAR_BAD"},
-    {BRIDGE_CTRL_SS_PAR_EN, 0, "SS_PAR_EN"},
-    {BRIDGE_CTRL_SSRAM_SIZE_MASK, 0, "SSRAM_SIZE", 0, ssram_sizes},
-    {BRIDGE_CTRL_F_BAD_PKT, 0, "F_BAD_PKT"},
-    {BRIDGE_CTRL_LLP_XBAR_CRD_MASK, -12, "LLP_XBAR_CRD", "%d"},
-    {BRIDGE_CTRL_CLR_RLLP_CNT, 0, "CLR_RLLP_CNT"},
-    {BRIDGE_CTRL_CLR_TLLP_CNT, 0, "CLR_TLLP_CNT"},
-    {BRIDGE_CTRL_SYS_END, 0, "SYS_END"},
-
-    {BRIDGE_CTRL_BUS_SPEED_MASK, -4, "BUS_SPEED", "%d"},
-    {BRIDGE_CTRL_WIDGET_ID_MASK, 0, "WIDGET_ID", "%x"},
-    {0}
-};
-#endif
-#endif	/* LATER */
-
 /* kbrick widgetnum-to-bus layout */
 int p_busnum[MAX_PORT_NUM] = {                  /* widget#      */
         0, 0, 0, 0, 0, 0, 0, 0,                 /* 0x0 - 0x7    */
@@ -132,18 +112,6 @@
         3,                                      /* 0xf          */
 };
 
-/*
- * Additional PIO spaces per slot are
- * recorded in this structure.
- */
-struct pciio_piospace_s {
-    pciio_piospace_t        next;       /* another space for this device */
-    char                    free;       /* 1 if free, 0 if in use               */
-    pciio_space_t           space;      /* Which space is in use                */
-    iopaddr_t               start;      /* Starting address of the PIO space    */
-    size_t                  count;      /* size of PIO space                    */
-};
-
 #if PCIBR_SOFT_LIST
 pcibr_list_p            pcibr_list = 0;
 #endif
@@ -152,15 +120,15 @@
 extern int              hub_device_flags_set(devfs_handle_t widget_dev, hub_widget_flags_t flags);
 extern long             atoi(register char *p);
 extern cnodeid_t        nodevertex_to_cnodeid(devfs_handle_t vhdl);
-extern void             *swap_ptr(void **loc, void *new);
 extern char             *dev_to_name(devfs_handle_t dev, char *buf, uint buflen);
 extern struct map       *atemapalloc(uint64_t);
 extern void             atefree(struct map *, size_t, uint64_t);
 extern void             atemapfree(struct map *);
 extern pciio_dmamap_t   get_free_pciio_dmamap(devfs_handle_t);
 extern void		free_pciio_dmamap(pcibr_dmamap_t);
+extern void		xwidget_error_register(devfs_handle_t, error_handler_f *, error_handler_arg_t);
 
-#define	ATE_WRITE()    ate_write(ate_ptr, ate_count, ate)
+#define	ATE_WRITE()    ate_write(pcibr_soft, ate_ptr, ate_count, ate)
 #if PCIBR_FREEZE_TIME
 #define	ATE_FREEZE()	s = ate_freeze(pcibr_dmamap, &freeze_time, cmd_regs)
 #else
@@ -173,7 +141,6 @@
 #define	ATE_THAW()	ate_thaw(pcibr_dmamap, ate_index, cmd_regs, s)
 #endif
 
-
 /* =====================================================================
  *    Function Table of Contents
  *
@@ -183,58 +150,54 @@
  *      perhaps bust this file into smaller chunks.
  */
 
-extern void              do_pcibr_rrb_clear(bridge_t *, int);
-extern void              do_pcibr_rrb_flush(bridge_t *, int);
-extern int               do_pcibr_rrb_count_valid(bridge_t *, pciio_slot_t);
-extern int               do_pcibr_rrb_count_avail(bridge_t *, pciio_slot_t);
-extern int               do_pcibr_rrb_alloc(bridge_t *, pciio_slot_t, int);
-extern int               do_pcibr_rrb_free(bridge_t *, pciio_slot_t, int);
-
-extern void              do_pcibr_rrb_autoalloc(pcibr_soft_t, int, int);
+extern int		 do_pcibr_rrb_free_all(pcibr_soft_t, bridge_t *, pciio_slot_t);
+extern void              do_pcibr_rrb_autoalloc(pcibr_soft_t, int, int, int);
 
 extern int  		 pcibr_wrb_flush(devfs_handle_t);
 extern int               pcibr_rrb_alloc(devfs_handle_t, int *, int *);
-extern int               pcibr_rrb_check(devfs_handle_t, int *, int *, int *, int *);
-extern int               pcibr_alloc_all_rrbs(devfs_handle_t, int, int, int, int, int, int, int, int, int);
 extern void              pcibr_rrb_flush(devfs_handle_t);
 
 static int                pcibr_try_set_device(pcibr_soft_t, pciio_slot_t, unsigned, bridgereg_t);
 void                     pcibr_release_device(pcibr_soft_t, pciio_slot_t, bridgereg_t);
 
-extern void              pcibr_clearwidint(bridge_t *);
 extern void              pcibr_setwidint(xtalk_intr_t);
+extern void              pcibr_clearwidint(bridge_t *);
+
+extern iopaddr_t         pcibr_bus_addr_alloc(pcibr_soft_t, pciio_win_info_t,
+                                              pciio_space_t, int, int, int);
 
 void                     pcibr_init(void);
 int                      pcibr_attach(devfs_handle_t);
+int			 pcibr_attach2(devfs_handle_t, bridge_t *, devfs_handle_t,
+				       int, pcibr_soft_t *);
 int			 pcibr_detach(devfs_handle_t);
 int                      pcibr_open(devfs_handle_t *, int, int, cred_t *);
 int                      pcibr_close(devfs_handle_t, int, int, cred_t *);
 int                      pcibr_map(devfs_handle_t, vhandl_t *, off_t, size_t, uint);
 int                      pcibr_unmap(devfs_handle_t, vhandl_t *);
 int                      pcibr_ioctl(devfs_handle_t, int, void *, int, struct cred *, int *);
-
-void                     pcibr_freeblock_sub(iopaddr_t *, iopaddr_t *, iopaddr_t, size_t);
-
+int			 pcibr_pcix_rbars_calc(pcibr_soft_t);
 extern int               pcibr_init_ext_ate_ram(bridge_t *);
 extern int               pcibr_ate_alloc(pcibr_soft_t, int);
 extern void              pcibr_ate_free(pcibr_soft_t, int, int);
+extern int 		 pcibr_widget_to_bus(devfs_handle_t pcibr_vhdl);
 
-extern unsigned          ate_freeze(pcibr_dmamap_t pcibr_dmamap,
+extern unsigned ate_freeze(pcibr_dmamap_t pcibr_dmamap,
 #if PCIBR_FREEZE_TIME
 	   		 unsigned *freeze_time_ptr,
 #endif
-						unsigned *cmd_regs);
-extern void              ate_write(bridge_ate_p ate_ptr, int ate_count, bridge_ate_t ate);
-extern void              ate_thaw(pcibr_dmamap_t pcibr_dmamap, int ate_index,
+	   		 unsigned *cmd_regs);
+extern void ate_write(pcibr_soft_t pcibr_soft, bridge_ate_p ate_ptr, int ate_count, bridge_ate_t ate);
+extern void ate_thaw(pcibr_dmamap_t pcibr_dmamap, int ate_index,
 #if PCIBR_FREEZE_TIME
-	 				bridge_ate_t ate,
-	 				int ate_total,
-	 				unsigned freeze_time_start,
+	 		bridge_ate_t ate,
+	 		int ate_total,
+	 		unsigned freeze_time_start,
 #endif
-	 				unsigned *cmd_regs,
-	 				unsigned s);
+	 		unsigned *cmd_regs,
+	 		unsigned s);
 
-pcibr_info_t             pcibr_info_get(devfs_handle_t);
+pcibr_info_t      pcibr_info_get(devfs_handle_t);
 
 static iopaddr_t         pcibr_addr_pci_to_xio(devfs_handle_t, pciio_slot_t, pciio_space_t, iopaddr_t, size_t, unsigned);
 
@@ -264,23 +227,23 @@
 void                    pcibr_dmalist_drain(devfs_handle_t, alenlist_t);
 iopaddr_t               pcibr_dmamap_pciaddr_get(pcibr_dmamap_t);
 
-extern unsigned		pcibr_intr_bits(pciio_info_t info, pciio_intr_line_t lines);
+extern unsigned		pcibr_intr_bits(pciio_info_t info, 
+					pciio_intr_line_t lines, int nslots);
 extern pcibr_intr_t     pcibr_intr_alloc(devfs_handle_t, device_desc_t, pciio_intr_line_t, devfs_handle_t);
 extern void             pcibr_intr_free(pcibr_intr_t);
 extern void             pcibr_setpciint(xtalk_intr_t);
-extern int              pcibr_intr_connect(pcibr_intr_t);
+extern int              pcibr_intr_connect(pcibr_intr_t, intr_func_t, intr_arg_t);
 extern void             pcibr_intr_disconnect(pcibr_intr_t);
 
 extern devfs_handle_t     pcibr_intr_cpu_get(pcibr_intr_t);
-extern void             pcibr_xintr_preset(void *, int, xwidgetnum_t, iopaddr_t, xtalk_intr_vector_t);
 extern void             pcibr_intr_func(intr_arg_t);
 
 extern void             print_bridge_errcmd(uint32_t, char *);
 
 extern void             pcibr_error_dump(pcibr_soft_t);
-extern uint32_t         pcibr_errintr_group(uint32_t);
+extern uint32_t       pcibr_errintr_group(uint32_t);
 extern void	        pcibr_pioerr_check(pcibr_soft_t);
-extern void             pcibr_error_intr_handler(intr_arg_t);
+extern void             pcibr_error_intr_handler(int, void *, struct pt_regs *);
 
 extern int              pcibr_addr_toslot(pcibr_soft_t, iopaddr_t, pciio_space_t *, iopaddr_t *, pciio_function_t *);
 extern void             pcibr_error_cleanup(pcibr_soft_t, int);
@@ -289,8 +252,7 @@
 extern int              pcibr_dmard_error(pcibr_soft_t, int, ioerror_mode_t, ioerror_t *);
 extern int              pcibr_dmawr_error(pcibr_soft_t, int, ioerror_mode_t, ioerror_t *);
 extern int              pcibr_error_handler(error_handler_arg_t, int, ioerror_mode_t, ioerror_t *);
-extern int              pcibr_error_devenable(devfs_handle_t, int);
-
+extern int              pcibr_error_handler_wrapper(error_handler_arg_t, int, ioerror_mode_t, ioerror_t *);
 void                    pcibr_provider_startup(devfs_handle_t);
 void                    pcibr_provider_shutdown(devfs_handle_t);
 
@@ -303,7 +265,6 @@
 extern cfg_p            pcibr_config_addr(devfs_handle_t, unsigned);
 extern uint64_t         pcibr_config_get(devfs_handle_t, unsigned, unsigned);
 extern void             pcibr_config_set(devfs_handle_t, unsigned, unsigned, uint64_t);
-extern void             do_pcibr_config_set(cfg_p, unsigned, unsigned, uint64_t);
 
 extern pcibr_hints_t    pcibr_hints_get(devfs_handle_t, int);
 extern void             pcibr_hints_fix_rrbs(devfs_handle_t);
@@ -313,38 +274,31 @@
 extern void             pcibr_hints_handsoff(devfs_handle_t);
 extern void             pcibr_hints_subdevs(devfs_handle_t, pciio_slot_t, uint64_t);
 
-#ifdef BRIDGE_B_DATACORR_WAR
-extern int              ql_bridge_rev_b_war(devfs_handle_t);
-extern int              bridge_rev_b_data_check_disable;
-char                   *rev_b_datacorr_warning =
-"***************************** WARNING! ******************************\n";
-char                   *rev_b_datacorr_mesg =
-"UNRECOVERABLE IO LINK ERROR. CONTACT SERVICE PROVIDER\n";
-#endif
-
 extern int		pcibr_slot_reset(devfs_handle_t,pciio_slot_t);
 extern int		pcibr_slot_info_init(devfs_handle_t,pciio_slot_t);
 extern int		pcibr_slot_info_free(devfs_handle_t,pciio_slot_t);
+extern int	        pcibr_slot_info_return(pcibr_soft_t, pciio_slot_t,
+                                               pcibr_slot_info_resp_t);
+extern void       	pcibr_slot_func_info_return(pcibr_info_h, int,
+                                                    pcibr_slot_func_info_resp_t);
 extern int		pcibr_slot_addr_space_init(devfs_handle_t,pciio_slot_t);
+extern int		pcibr_slot_pcix_rbar_init(pcibr_soft_t, pciio_slot_t);
 extern int		pcibr_slot_device_init(devfs_handle_t, pciio_slot_t);
 extern int		pcibr_slot_guest_info_init(devfs_handle_t,pciio_slot_t);
-extern int		pcibr_slot_call_device_attach(devfs_handle_t, pciio_slot_t, int);
-extern int		pcibr_slot_call_device_detach(devfs_handle_t, pciio_slot_t, int);
-extern int              pcibr_slot_attach(devfs_handle_t, pciio_slot_t, int, char *, int *);
-extern int              pcibr_slot_detach(devfs_handle_t, pciio_slot_t, int);
+extern int		pcibr_slot_call_device_attach(devfs_handle_t,
+						      pciio_slot_t, int);
+extern int		pcibr_slot_call_device_detach(devfs_handle_t,
+						      pciio_slot_t, int);
+extern int              pcibr_slot_attach(devfs_handle_t, pciio_slot_t, int, 
+                                                      char *, int *);
+extern int              pcibr_slot_detach(devfs_handle_t, pciio_slot_t, int,
+                                                      char *, int *);
 extern int 		pcibr_is_slot_sys_critical(devfs_handle_t, pciio_slot_t);
 
-#ifdef LATER
-extern int		pcibr_slot_startup(devfs_handle_t, pcibr_slot_req_t);
-extern int		pcibr_slot_shutdown(devfs_handle_t, pcibr_slot_req_t);
-extern int		pcibr_slot_query(devfs_handle_t, pcibr_slot_req_t);
-#endif
-
 extern int		pcibr_slot_initial_rrb_alloc(devfs_handle_t, pciio_slot_t);
 extern int		pcibr_initial_rrb(devfs_handle_t, pciio_slot_t, pciio_slot_t);
 
 
-
 /* =====================================================================
  *    Device(x) register management
  */
@@ -377,7 +331,7 @@
     bridgereg_t             xmask;
 
     xmask = mask;
-    if (pcibr_soft->bs_xbridge) {
+    if (IS_XBRIDGE_OR_PIC_SOFT(pcibr_soft)) {
     	if (mask == BRIDGE_DEV_PMU_BITS)
 		xmask = XBRIDGE_DEV_PMU_BITS;
 	if (mask == BRIDGE_DEV_D64_BITS)
@@ -464,10 +418,10 @@
 	new &= ~BRIDGE_DEV_WRGA_BITS;
 
     if (flags & PCIIO_BYTE_STREAM)
-	new |= (pcibr_soft->bs_xbridge) ? 
+	new |= (IS_XBRIDGE_OR_PIC_SOFT(pcibr_soft)) ? 
 			BRIDGE_DEV_SWAP_DIR : BRIDGE_DEV_SWAP_BITS;
     if (flags & PCIIO_WORD_VALUES)
-	new &= (pcibr_soft->bs_xbridge) ? 
+	new &= (IS_XBRIDGE_OR_PIC_SOFT(pcibr_soft)) ? 
 			~BRIDGE_DEV_SWAP_DIR : ~BRIDGE_DEV_SWAP_BITS;
 
     /* Provider-specific flags
@@ -492,13 +446,28 @@
     if (flags & PCIBR_NO64BIT)
 	new &= ~BRIDGE_DEV_DEV_SIZE;
 
+    /*
+     * PIC BRINGUP WAR (PV# 855271):
+     * Allow setting BRIDGE_DEV_VIRTUAL_EN on PIC iff we're a 64-bit
+     * device.  The bit is only intended for 64-bit devices and, on
+     * PIC, can cause problems for 32-bit devices.
+     */
+    if (IS_PIC_SOFT(pcibr_soft) && mask == BRIDGE_DEV_D64_BITS &&
+                                PCIBR_WAR_ENABLED(PV855271, pcibr_soft)) {
+        if (flags & PCIBR_VCHAN1) {
+                new |= BRIDGE_DEV_VIRTUAL_EN;
+                xmask |= BRIDGE_DEV_VIRTUAL_EN;
+        }
+    }
+
+
     chg = old ^ new;				/* what are we changing, */
     chg &= xmask;				/* of the interesting bits */
 
     if (chg) {
 
 	badd32 = slotp->bss_d32_uctr ? (BRIDGE_DEV_D32_BITS & chg) : 0;
-	if (pcibr_soft->bs_xbridge) {
+	if (IS_XBRIDGE_OR_PIC_SOFT(pcibr_soft)) {
 		badpmu = slotp->bss_pmu_uctr ? (XBRIDGE_DEV_PMU_BITS & chg) : 0;
 		badd64 = slotp->bss_d64_uctr ? (XBRIDGE_DEV_D64_BITS & chg) : 0;
 	} else {
@@ -517,7 +486,7 @@
 	     * the new stream at all.
 	     */
             if ( (fix = bad & (BRIDGE_DEV_PRECISE |
-                             BRIDGE_DEV_BARRIER)) ){
+                             BRIDGE_DEV_BARRIER)) ) {
 		bad &= ~fix;
 		/* don't change these bits if
 		 * they are already set in "old"
@@ -546,8 +515,10 @@
 	     */
 	    if (bad) {
 		pcibr_unlock(pcibr_soft, s);
-#if (DEBUG && PCIBR_DEV_DEBUG)
-		printk("pcibr_try_set_device: mod blocked by %R\n", bad, device_bits);
+#ifdef PIC_LATER
+		PCIBR_DEBUG((PCIBR_DEBUG_DEVREG, pcibr_soft->bs_vhdl,
+			    "pcibr_try_set_device: mod blocked by %x\n",
+			    bad, device_bits));
 #endif
 		return bad;
 	    }
@@ -571,14 +542,31 @@
 	pcibr_unlock(pcibr_soft, s);
 	return 0;
     }
-    bridge->b_device[slot].reg = new;
-    slotp->bss_device = new;
-    bridge->b_wid_tflush;		/* wait until Bridge PIO complete */
+    if ( IS_PIC_SOFT(pcibr_soft) ) {
+	bridge->b_device[slot].reg = new;
+	slotp->bss_device = new;
+	bridge->b_wid_tflush;		/* wait until Bridge PIO complete */
+    }
+    else {
+	if (io_get_sh_swapper(NASID_GET(bridge))) {
+		BRIDGE_REG_SET32((&bridge->b_device[slot].reg)) = __swab32(new);
+		slotp->bss_device = new;
+		BRIDGE_REG_GET32((&bridge->b_wid_tflush));  /* wait until Bridge PIO complete */
+	} else {
+		bridge->b_device[slot].reg = new;
+		slotp->bss_device = new;
+		bridge->b_wid_tflush;               /* wait until Bridge PIO complete */
+	}
+    }
     pcibr_unlock(pcibr_soft, s);
-#if DEBUG && PCIBR_DEV_DEBUG
-    printk("pcibr Device(%d): 0x%p\n", slot, bridge->b_device[slot].reg);
-#endif
 
+#ifdef PIC_LATER
+    PCIBR_DEBUG((PCIBR_DEBUG_DEVREG, pcibr_soft->bs_vhdl,
+		"pcibr_try_set_device: Device(%d): %x\n",
+		slot, new, device_bits));
+#else
+    printk("pcibr_try_set_device: Device(%d): %x\n", slot, new);
+#endif
     return 0;
 }
 
@@ -616,7 +604,17 @@
     volatile uint32_t     wrf;
     s = pcibr_lock(pcibr_soft);
     bridge = pcibr_soft->bs_base;
-    wrf = bridge->b_wr_req_buf[slot].reg;
+
+    if ( IS_PIC_SOFT(pcibr_soft) ) {
+	wrf = bridge->b_wr_req_buf[slot].reg;
+    }
+    else {
+	if (io_get_sh_swapper(NASID_GET(bridge))) {
+		wrf = BRIDGE_REG_GET32((&bridge->b_wr_req_buf[slot].reg));
+	} else {
+		wrf = bridge->b_wr_req_buf[slot].reg;
+	}
+    }
     pcibr_unlock(pcibr_soft, s);
 }
 
@@ -637,9 +635,7 @@
 void
 pcibr_init(void)
 {
-#if DEBUG && ATTACH_DEBUG
-    printk("pcibr_init\n");
-#endif
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INIT, NULL, "pcibr_init()\n"));
 
     xwidget_driver_register(XBRIDGE_WIDGET_PART_NUM,
 			    XBRIDGE_WIDGET_MFGR_NUM,
@@ -700,7 +696,7 @@
      * XXX- deprecate this in favor of using the
      * real flash driver ...
      */
-    if (!error &&
+    if (IS_BRIDGE_SOFT(pcibr_soft) && !error &&
 	((off == BRIDGE_EXTERNAL_FLASH) ||
 	 (len > BRIDGE_EXTERNAL_FLASH))) {
 	int                     s;
@@ -710,11 +706,16 @@
 	 * The read following the write is required for the Bridge war
 	 */
 	s = splhi();
-	bridge->b_wid_control |= BRIDGE_CTRL_FLASH_WR_EN;
-	bridge->b_wid_control;		/* inval addr bug war */
+
+	if (io_get_sh_swapper(NASID_GET(bridge))) {
+		BRIDGE_REG_SET32((&bridge->b_wid_control)) |= __swab32(BRIDGE_CTRL_FLASH_WR_EN);
+		BRIDGE_REG_GET32((&bridge->b_wid_control));          /* inval addr bug war */
+	} else {
+		bridge->b_wid_control |= BRIDGE_CTRL_FLASH_WR_EN;
+		bridge->b_wid_control;          /* inval addr bug war */
+	}
 	splx(s);
     }
-
     return error;
 }
 
@@ -728,21 +729,53 @@
 
     hwgraph_vertex_unref(pcibr_vhdl);
 
-    /*
-     * If flashprom write was enabled, disable it, as
-     * this is the last unmap.
-     */
-    if (bridge->b_wid_control & BRIDGE_CTRL_FLASH_WR_EN) {
-	int                     s;
-
+    if ( IS_PIC_SOFT(pcibr_soft) ) {
 	/*
-	 * ensure that we write and read without any interruption.
-	 * The read following the write is required for the Bridge war
+	 * If flashprom write was enabled, disable it, as
+	 * this is the last unmap.
 	 */
-	s = splhi();
-	bridge->b_wid_control &= ~BRIDGE_CTRL_FLASH_WR_EN;
-	bridge->b_wid_control;		/* inval addr bug war */
-	splx(s);
+	if (IS_BRIDGE_SOFT(pcibr_soft) && 
+			(bridge->b_wid_control & BRIDGE_CTRL_FLASH_WR_EN)) {
+		int                     s;
+
+		/*
+		 * ensure that we write and read without any interruption.
+		 * The read following the write is required for the Bridge war
+		 */
+		s = splhi();
+		bridge->b_wid_control &= ~BRIDGE_CTRL_FLASH_WR_EN;
+		bridge->b_wid_control;		/* inval addr bug war */
+		splx(s);
+	}
+    }
+    else {
+	if (io_get_sh_swapper(NASID_GET(bridge))) {
+		if (BRIDGE_REG_GET32((&bridge->b_wid_control)) & BRIDGE_CTRL_FLASH_WR_EN) {
+			int                     s;
+
+			/*
+			 * ensure that we write and read without any interruption.
+			 * The read following the write is required for the Bridge war
+			 */
+			s = splhi();
+			BRIDGE_REG_SET32((&bridge->b_wid_control)) &= __swab32((unsigned int)~BRIDGE_CTRL_FLASH_WR_EN);
+			BRIDGE_REG_GET32((&bridge->b_wid_control));          /* inval addr bug war */
+			splx(s);
+		} else {
+			if (bridge->b_wid_control & BRIDGE_CTRL_FLASH_WR_EN) {
+				int                     s;
+
+				/*
+				 * ensure that we write and read without any interruption.
+				 * The read following the write is required for the Bridge war
+				 */
+				s = splhi();
+				bridge->b_wid_control &= ~BRIDGE_CTRL_FLASH_WR_EN;
+				bridge->b_wid_control;          /* inval addr bug war */
+				splx(s);
+    			}
+		}
+	}
     }
     return 0;
 }
@@ -768,7 +801,7 @@
     while (tdev != GRAPH_VERTEX_NONE) {
 	pciio_info = pciio_info_chk(tdev);
 	if (pciio_info) {
-	    slot = pciio_info_slot_get(pciio_info);
+	    slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
 	    break;
 	}
 	hwgraph_vertex_unref(tdev);
@@ -788,167 +821,7 @@
 	    struct cred *cr,
 	    int *rvalp)
 {
-    devfs_handle_t            pcibr_vhdl = hwgraph_connectpt_get((devfs_handle_t)dev);
-#ifdef LATER
-    pcibr_soft_t            pcibr_soft = pcibr_soft_get(pcibr_vhdl);
-#endif
-    int                     error = 0;
-
-    hwgraph_vertex_unref(pcibr_vhdl);
-
-    switch (cmd) {
-#ifdef LATER
-    case GIOCSETBW:
-	{
-	    grio_ioctl_info_t       info;
-	    pciio_slot_t            slot = 0;
-
-	    if (!cap_able((uint64_t)CAP_DEVICE_MGT)) {
-		error = EPERM;
-		break;
-	    }
-	    if (COPYIN(arg, &info, sizeof(grio_ioctl_info_t))) {
-		error = EFAULT;
-		break;
-	    }
-#ifdef GRIO_DEBUG
-	    printk("pcibr:: prev_vhdl: %d reqbw: %lld\n",
-		    info.prev_vhdl, info.reqbw);
-#endif				/* GRIO_DEBUG */
-
-	    if ((slot = pcibr_device_slot_get(info.prev_vhdl)) ==
-		PCIIO_SLOT_NONE) {
-		error = EIO;
-		break;
-	    }
-	    if (info.reqbw)
-		pcibr_priority_bits_set(pcibr_soft, slot, PCI_PRIO_HIGH);
-	    break;
-	}
-
-    case GIOCRELEASEBW:
-	{
-	    grio_ioctl_info_t       info;
-	    pciio_slot_t            slot = 0;
-
-	    if (!cap_able(CAP_DEVICE_MGT)) {
-		error = EPERM;
-		break;
-	    }
-	    if (COPYIN(arg, &info, sizeof(grio_ioctl_info_t))) {
-		error = EFAULT;
-		break;
-	    }
-#ifdef GRIO_DEBUG
-	    printk("pcibr:: prev_vhdl: %d reqbw: %lld\n",
-		    info.prev_vhdl, info.reqbw);
-#endif				/* GRIO_DEBUG */
-
-	    if ((slot = pcibr_device_slot_get(info.prev_vhdl)) ==
-		PCIIO_SLOT_NONE) {
-		error = EIO;
-		break;
-	    }
-	    if (info.reqbw)
-		pcibr_priority_bits_set(pcibr_soft, slot, PCI_PRIO_LOW);
-	    break;
-	}
-
-    case PCIBR_SLOT_STARTUP:
-	{
-	    struct pcibr_slot_req_s        req;
-
-	    if (!cap_able(CAP_DEVICE_MGT)) {
-		error = EPERM;
-		break;
-	    }
-
-            if (COPYIN(arg, &req, sizeof(req))) {
-                error = EFAULT;
-                break;
-            }
-
-	    error = pcibr_slot_startup(pcibr_vhdl, &req);
-	    break;
-	}
-    case PCIBR_SLOT_SHUTDOWN:
-	{
-	    struct pcibr_slot_req_s        req;
-
-	    if (!cap_able(CAP_DEVICE_MGT)) {
-		error = EPERM;
-		break;
-	    }
-
-            if (COPYIN(arg, &req, sizeof(req))) {
-                error = EFAULT;
-                break;
-            }
-
-	    error = pcibr_slot_shutdown(pcibr_vhdl, &req);
-	    break;
-	}
-    case PCIBR_SLOT_QUERY:
-	{
-	    struct pcibr_slot_req_s        req;
-
-	    if (!cap_able(CAP_DEVICE_MGT)) {
-		error = EPERM;
-		break;
-	    }
-
-            if (COPYIN(arg, &req, sizeof(req))) {
-                error = EFAULT;
-                break;
-            }
-
-            error = pcibr_slot_query(pcibr_vhdl, &req);
-	    break;
-	}
-#endif	/* LATER */
-    default:
-	break;
-
-    }
-
-    return error;
-}
-
-void
-pcibr_freeblock_sub(iopaddr_t *free_basep,
-		    iopaddr_t *free_lastp,
-		    iopaddr_t base,
-		    size_t size)
-{
-    iopaddr_t               free_base = *free_basep;
-    iopaddr_t               free_last = *free_lastp;
-    iopaddr_t               last = base + size - 1;
-
-    if ((last < free_base) || (base > free_last));	/* free block outside arena */
-
-    else if ((base <= free_base) && (last >= free_last))
-	/* free block contains entire arena */
-	*free_basep = *free_lastp = 0;
-
-    else if (base <= free_base)
-	/* free block is head of arena */
-	*free_basep = last + 1;
-
-    else if (last >= free_last)
-	/* free block is tail of arena */
-	*free_lastp = base - 1;
-
-    /*
-     * We are left with two regions: the free area
-     * in the arena "below" the block, and the free
-     * area in the arena "above" the block. Keep
-     * the one that is bigger.
-     */
-
-    else if ((base - free_base) > (free_last - last))
-	*free_lastp = base - 1;		/* keep lower chunk */
-    else
-	*free_basep = last + 1;		/* keep upper chunk */
+    return 0;
 }
 
 pcibr_info_t
@@ -971,16 +844,22 @@
 
     func = (rfunc == PCIIO_FUNC_NONE) ? 0 : rfunc;
 
+    /*
+     * Create a pciio_info_s for this device.  pciio_device_info_new()
+     * will set the c_slot (which is suppose to represent the external
+     * slot (i.e the slot number silk screened on the back of the I/O
+     * brick)).  So for PIC we need to adjust this "internal slot" num
+     * passed into us, into it's external representation.  See comment
+     * for the PCIBR_DEVICE_TO_SLOT macro for more information.
+     */
     NEW(pcibr_info);
+    pciio_device_info_new(&pcibr_info->f_c, pcibr_soft->bs_vhdl,
+			  PCIBR_DEVICE_TO_SLOT(pcibr_soft, slot),
+			  rfunc, vendor, device);
+    pcibr_info->f_dev = slot;
 
-    pciio_device_info_new(&pcibr_info->f_c,
-			  pcibr_soft->bs_vhdl,
-			  slot, rfunc,
-			  vendor, device);
-
-/* pfg - this is new ..... */
     /* Set PCI bus number */
-    pcibr_info->f_bus = io_path_map_widget(pcibr_soft->bs_vhdl);
+    pcibr_info->f_bus = pcibr_widget_to_bus(pcibr_soft->bs_vhdl);
 
     if (slot != PCIIO_SLOT_NONE) {
 
@@ -1016,30 +895,6 @@
 }
 
 
-/* FIXME:  for now this is needed by both pcibr.c and
- * pcibr_slot.c.  Need to find a better way, the least
- * of which would be to move it to pcibr_private.h
- */
-
-/*
- * PCI_ADDR_SPACE_LIMITS_STORE
- *	Sets the current values of
- *		pci io base, 
- *		pci io last,
- *		pci low memory base,
- *		pci low memory last,
- *		pci high memory base,
- * 		pci high memory last
- */
-#define PCI_ADDR_SPACE_LIMITS_STORE()			\
-    pcibr_soft->bs_spinfo.pci_io_base = pci_io_fb;	\
-    pcibr_soft->bs_spinfo.pci_io_last = pci_io_fl;	\
-    pcibr_soft->bs_spinfo.pci_swin_base = pci_lo_fb;	\
-    pcibr_soft->bs_spinfo.pci_swin_last = pci_lo_fl;	\
-    pcibr_soft->bs_spinfo.pci_mem_base = pci_hi_fb;	\
-    pcibr_soft->bs_spinfo.pci_mem_last = pci_hi_fl;
-
-
 /*
  * pcibr_device_unregister
  *	This frees up any hardware resources reserved for this PCI device
@@ -1062,7 +917,7 @@
     pciio_info = pciio_info_get(pconn_vhdl);
 
     pcibr_vhdl = pciio_info_master_get(pciio_info);
-    slot = pciio_info_slot_get(pciio_info);
+    slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
 
     pcibr_soft = pcibr_soft_get(pcibr_vhdl);
     bridge = pcibr_soft->bs_base;
@@ -1077,27 +932,24 @@
      * If the RRB configuration for this slot has changed, set it 
      * back to the boot-time default
      */
-    if (pcibr_soft->bs_rrb_valid_dflt[slot] >= 0) {
+    if (pcibr_soft->bs_rrb_valid_dflt[slot][VCHAN0] >= 0) {
 
         s = pcibr_lock(pcibr_soft);
 
-        /* Free the rrbs allocated to this slot */
-        error_call = do_pcibr_rrb_free(bridge, slot, 
-		                       pcibr_soft->bs_rrb_valid[slot] +
-		                       pcibr_soft->bs_rrb_valid[slot + 
-                                       PCIBR_RRB_SLOT_VIRTUAL]);
-
-        if (error_call)
-            error = ERANGE;
-   
-         pcibr_soft->bs_rrb_res[slot] = pcibr_soft->bs_rrb_res[slot] +
-                                        pcibr_soft->bs_rrb_valid[slot] +
-                                        pcibr_soft->bs_rrb_valid[slot +
-                                        PCIBR_RRB_SLOT_VIRTUAL];
-
-        count_vchan0 = pcibr_soft->bs_rrb_valid_dflt[slot];
-        count_vchan1 = pcibr_soft->bs_rrb_valid_dflt[slot +
-                                                     PCIBR_RRB_SLOT_VIRTUAL];
+	/* PIC NOTE: If this is a BRIDGE, VCHAN2 & VCHAN3 will be zero so
+	 * no need to conditionalize this (ie. "if (IS_PIC_SOFT())" ).
+	 */
+        pcibr_soft->bs_rrb_res[slot] = pcibr_soft->bs_rrb_res[slot] +
+                                       pcibr_soft->bs_rrb_valid[slot][VCHAN0] +
+                                       pcibr_soft->bs_rrb_valid[slot][VCHAN1] +
+                                       pcibr_soft->bs_rrb_valid[slot][VCHAN2] +
+                                       pcibr_soft->bs_rrb_valid[slot][VCHAN3];
+
+        /* Free the rrbs allocated to this slot, both the normal & virtual */
+	do_pcibr_rrb_free_all(pcibr_soft, bridge, slot);
+
+        count_vchan0 = pcibr_soft->bs_rrb_valid_dflt[slot][VCHAN0];
+        count_vchan1 = pcibr_soft->bs_rrb_valid_dflt[slot][VCHAN1];
 
         pcibr_unlock(pcibr_soft, s);
 
@@ -1147,12 +999,14 @@
     pcibr_info = pcibr_info_get(pconn_vhdl);
 
     pcibr_vhdl = pciio_info_master_get(pciio_info);
-    slot = pciio_info_slot_get(pciio_info);
+    slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
 
     pcibr_soft = pcibr_soft_get(pcibr_vhdl);
 
+#ifdef PIC_LATER
     /* This may be a loadable driver so lock out any pciconfig actions */
     mrlock(pcibr_soft->bs_bus_lock, MR_UPDATE, PZERO);
+#endif
 
     pcibr_info->f_att_det_error = error;
 
@@ -1164,9 +1018,10 @@
         pcibr_soft->bs_slot[slot].slot_status |= SLOT_STARTUP_CMPLT;
     }
         
+#ifdef PIC_LATER
     /* Release the bus lock */
     mrunlock(pcibr_soft->bs_bus_lock);
-
+#endif
 }
 
 /*
@@ -1195,12 +1050,14 @@
     pcibr_info = pcibr_info_get(pconn_vhdl);
 
     pcibr_vhdl = pciio_info_master_get(pciio_info);
-    slot = pciio_info_slot_get(pciio_info);
+    slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
 
     pcibr_soft = pcibr_soft_get(pcibr_vhdl);
 
+#ifdef PIC_LATER
     /* This may be a loadable driver so lock out any pciconfig actions */
     mrlock(pcibr_soft->bs_bus_lock, MR_UPDATE, PZERO);
+#endif
 
     pcibr_info->f_att_det_error = error;
 
@@ -1211,10 +1068,11 @@
     } else {
         pcibr_soft->bs_slot[slot].slot_status |= SLOT_SHUTDOWN_CMPLT;
     }
-        
+
+#ifdef PIC_LATER
     /* Release the bus lock */
     mrunlock(pcibr_soft->bs_bus_lock);
-
+#endif
 }
 
 /* 
@@ -1226,7 +1084,7 @@
  * depends on hwgraph separator == '/'
  */
 int
-pcibr_bus_cnvlink(devfs_handle_t f_c, int slot)
+pcibr_bus_cnvlink(devfs_handle_t f_c)
 {
         char dst[MAXDEVNAME];
 	char *dp = dst;
@@ -1236,16 +1094,7 @@
 	devfs_handle_t nvtx, svtx;
 	int rv;
 
-#if DEBUG
-	printk("pcibr_bus_cnvlink: slot= %d f_c= %p\n", 
-		slot, f_c);
-	{
-		int pos;
-		char dname[256];
-		pos = devfs_generate_path(f_c, dname, 256);
-		printk("%s : path= %s\n", __FUNCTION__, &dname[pos]);
-	}
-#endif
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ATTACH, f_c, "pcibr_bus_cnvlink\n"));
 
 	if (GRAPH_SUCCESS != hwgraph_vertex_name_get(f_c, dst, MAXDEVNAME))
 		return 0;
@@ -1261,7 +1110,7 @@
 		return 0;
 
 	/* remove "/pci/direct" from path */
-	cp = strstr(dst, "/" EDGE_LBL_PCI "/" "direct");
+	cp = strstr(dst, "/" EDGE_LBL_PCI "/" EDGE_LBL_DIRECT);
 	if (cp == NULL)
 		return 0;
 	*cp = (char)NULL;
@@ -1275,7 +1124,8 @@
 	/* dst example now == /hw/module/001c02/Pbrick */
 
 	/* get the bus number */
-        strcat(dst, "/bus");
+        strcat(dst, "/");
+        strcat(dst, EDGE_LBL_BUS);
         sprintf(pcibus, "%d", p_busnum[widgetnum]);
 
 	/* link to bus to widget */
@@ -1300,75 +1150,74 @@
     /* REFERENCED */
     graph_error_t           rc;
     devfs_handle_t            pcibr_vhdl;
+    bridge_t               *bridge;
+
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ATTACH, xconn_vhdl, "pcibr_attach\n"));
+
+    bridge = (bridge_t *)
+	xtalk_piotrans_addr(xconn_vhdl, NULL,
+			    0, sizeof(bridge_t), 0);
+    /*
+     * Create the vertex for the PCI bus, which we
+     * will also use to hold the pcibr_soft and
+     * which will be the "master" vertex for all the
+     * pciio connection points we will hang off it.
+     * This needs to happen before we call nic_bridge_vertex_info
+     * as we are some of the *_vmc functions need access to the edges.
+     *
+     * Opening this vertex will provide access to
+     * the Bridge registers themselves.
+     */
+    rc = hwgraph_path_add(xconn_vhdl, EDGE_LBL_PCI, &pcibr_vhdl);
+    ASSERT(rc == GRAPH_SUCCESS);
+
+    pciio_provider_register(pcibr_vhdl, &pcibr_provider);
+    pciio_provider_startup(pcibr_vhdl);
+
+    return pcibr_attach2(xconn_vhdl, bridge, pcibr_vhdl, 0, NULL);
+}
+
+
+/*ARGSUSED */
+int
+pcibr_attach2(devfs_handle_t xconn_vhdl, bridge_t *bridge, 
+	      devfs_handle_t pcibr_vhdl, int busnum, pcibr_soft_t *ret_softp)
+{
+    /* REFERENCED */
     devfs_handle_t            ctlr_vhdl;
-    bridge_t               *bridge = NULL;
     bridgereg_t             id;
     int                     rev;
     pcibr_soft_t            pcibr_soft;
     pcibr_info_t            pcibr_info;
     xwidget_info_t          info;
     xtalk_intr_t            xtalk_intr;
-    device_desc_t           dev_desc = (device_desc_t)0;
     int                     slot;
     int                     ibit;
     devfs_handle_t            noslot_conn;
     char                    devnm[MAXDEVNAME], *s;
     pcibr_hints_t           pcibr_hints;
-    bridgereg_t             b_int_enable;
+    uint64_t              int_enable;
+    bridgereg_t             int_enable_32;
+    picreg_t                int_enable_64;
     unsigned                rrb_fixed = 0;
 
-    iopaddr_t               pci_io_fb, pci_io_fl;
-    iopaddr_t               pci_lo_fb, pci_lo_fl;
-    iopaddr_t               pci_hi_fb, pci_hi_fl;
-
     int                     spl_level;
-#ifdef LATER
-    char		    *nicinfo = (char *)0;
-#endif
 
 #if PCI_FBBE
     int                     fast_back_to_back_enable;
 #endif
-    l1sc_t		    *scp;
     nasid_t		    nasid;
+    int	                    iobrick_type_get_nasid(nasid_t nasid);
+    int                     iobrick_module_get_nasid(nasid_t nasid);
+    extern unsigned char    Is_pic_on_this_nasid[512];
 
-    async_attach_t          aa = NULL;
 
-    aa = async_attach_get_info(xconn_vhdl);
-
-#if DEBUG && ATTACH_DEBUG
-    printk("pcibr_attach: xconn_vhdl=  %p\n", xconn_vhdl);
-    {
-	int pos;
-	char dname[256];
-	pos = devfs_generate_path(xconn_vhdl, dname, 256);
-	printk("%s : path= %s \n", __FUNCTION__, &dname[pos]);
-    }
-#endif
+    async_attach_t          aa = NULL;
 
-    /* Setup the PRB for the bridge in CONVEYOR BELT
-     * mode. PRBs are setup in default FIRE-AND-FORGET
-     * mode during the initialization.
-     */
-    hub_device_flags_set(xconn_vhdl, HUB_PIO_CONVEYOR);
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ATTACH, pcibr_vhdl,
+	        "pcibr_attach2: bridge=0x%p, busnum=%d\n", bridge, busnum));
 
-    bridge = (bridge_t *)
-	xtalk_piotrans_addr(xconn_vhdl, NULL,
-			    0, sizeof(bridge_t), 0);
-
-    /*
-     * Create the vertex for the PCI bus, which we
-     * will also use to hold the pcibr_soft and
-     * which will be the "master" vertex for all the
-     * pciio connection points we will hang off it.
-     * This needs to happen before we call nic_bridge_vertex_info
-     * as we are some of the *_vmc functions need access to the edges.
-     *
-     * Opening this vertex will provide access to
-     * the Bridge registers themselves.
-     */
-    rc = hwgraph_path_add(xconn_vhdl, EDGE_LBL_PCI, &pcibr_vhdl);
-    ASSERT(rc == GRAPH_SUCCESS);
+    aa = async_attach_get_info(xconn_vhdl);
 
     ctlr_vhdl = NULL;
     ctlr_vhdl = hwgraph_register(pcibr_vhdl, EDGE_LBL_CONTROLLER,
@@ -1380,15 +1229,6 @@
     ASSERT(ctlr_vhdl != NULL);
 
     /*
-     * decode the nic, and hang its stuff off our
-     * connection point where other drivers can get
-     * at it.
-     */
-#ifdef LATER
-    nicinfo = BRIDGE_VERTEX_MFG_INFO(xconn_vhdl, (nic_data_t) & bridge->b_nic);
-#endif
-
-    /*
      * Get the hint structure; if some NIC callback
      * marked this vertex as "hands-off" then we
      * just return here, before doing anything else.
@@ -1408,26 +1248,63 @@
      * fields, and hook it up to our vertex.
      */
     NEW(pcibr_soft);
+    if (ret_softp)
+	*ret_softp = pcibr_soft;
     BZERO(pcibr_soft, sizeof *pcibr_soft);
     pcibr_soft_set(pcibr_vhdl, pcibr_soft);
-
     pcibr_soft->bs_conn = xconn_vhdl;
     pcibr_soft->bs_vhdl = pcibr_vhdl;
     pcibr_soft->bs_base = bridge;
     pcibr_soft->bs_rev_num = rev;
-    pcibr_soft->bs_intr_bits = pcibr_intr_bits;
+    pcibr_soft->bs_intr_bits = (pcibr_intr_bits_f *)pcibr_intr_bits;
+
+    pcibr_soft->bs_min_slot = 0;		/* lowest possible slot# */
+    pcibr_soft->bs_max_slot = 7;		/* highest possible slot# */
+    pcibr_soft->bs_busnum = busnum;
     if (is_xbridge(bridge)) {
-	pcibr_soft->bs_int_ate_size = XBRIDGE_INTERNAL_ATES;
-	pcibr_soft->bs_xbridge = 1;
+	pcibr_soft->bs_bridge_type = PCIBR_BRIDGETYPE_XBRIDGE;
+    } else if (is_pic(bridge)) {
+	pcibr_soft->bs_bridge_type = PCIBR_BRIDGETYPE_PIC;
     } else {
+	pcibr_soft->bs_bridge_type = PCIBR_BRIDGETYPE_BRIDGE;
+    }
+    switch(pcibr_soft->bs_bridge_type) {
+    case PCIBR_BRIDGETYPE_BRIDGE:
 	pcibr_soft->bs_int_ate_size = BRIDGE_INTERNAL_ATES;
-	pcibr_soft->bs_xbridge = 0;
+	pcibr_soft->bs_bridge_mode = 0;	/* speed is not available in bridge */
+	break;
+    case PCIBR_BRIDGETYPE_PIC:
+        pcibr_soft->bs_min_slot = 0;
+	pcibr_soft->bs_max_slot = 3;
+	pcibr_soft->bs_int_ate_size = XBRIDGE_INTERNAL_ATES;
+	pcibr_soft->bs_bridge_mode = 
+	   (((bridge->p_wid_stat_64 & PIC_STAT_PCIX_SPEED) >> 33) |
+	    ((bridge->p_wid_stat_64 & PIC_STAT_PCIX_ACTIVE) >> 33));
+
+	/* We have to clear PIC's write request buffer to avoid parity
+	 * errors.  See PV#854845.
+	 */
+	{
+	int i;
+
+	for (i=0; i < PIC_WR_REQ_BUFSIZE; i++) {
+		bridge->p_wr_req_lower[i] = 0;
+		bridge->p_wr_req_upper[i] = 0;
+		bridge->p_wr_req_parity[i] = 0;
+	}
+	}
+
+	break;
+    case PCIBR_BRIDGETYPE_XBRIDGE:
+	pcibr_soft->bs_int_ate_size = XBRIDGE_INTERNAL_ATES;
+	pcibr_soft->bs_bridge_mode = 
+	   ((bridge->b_wid_control & BRIDGE_CTRL_PCI_SPEED) >> 3);
+	break;
     }
 
-    nasid = NASID_GET(bridge);
-    scp = &NODEPDA( NASID_TO_COMPACT_NODEID(nasid) )->module->elsc;
-    pcibr_soft->bs_l1sc = scp;
-    pcibr_soft->bs_moduleid = iobrick_module_get(scp);
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ATTACH, pcibr_vhdl,
+		"pcibr_attach2: pcibr_soft=0x%x, mode=0x%x\n",
+                pcibr_soft, pcibr_soft->bs_bridge_mode));
     pcibr_soft->bsi_err_intr = 0;
 
     /* Bridges up through REV C
@@ -1439,6 +1316,9 @@
 	pcibr_soft->bs_pio_end_mem = PCIIO_WORD_VALUES;
     }
 #if PCIBR_SOFT_LIST
+    /*
+     * link all the pcibr_soft structs
+     */
     {
 	pcibr_list_p            self;
 
@@ -1446,9 +1326,9 @@
 	self->bl_soft = pcibr_soft;
 	self->bl_vhdl = pcibr_vhdl;
 	self->bl_next = pcibr_list;
-	self->bl_next = swap_ptr((void **) &pcibr_list, (void *)self);
+	pcibr_list = self;
     }
-#endif
+#endif /* PCIBR_SOFT_LIST */
 
     /*
      * get the name of this bridge vertex and keep the info. Use this
@@ -1458,45 +1338,114 @@
     pcibr_soft->bs_name = kmalloc(strlen(s) + 1, GFP_KERNEL);
     strcpy(pcibr_soft->bs_name, s);
 
-#if SHOW_REVS || DEBUG
-#if !DEBUG
-    if (kdebug)
-#endif
-	printk("%sBridge ASIC: rev %s (code=0x%x) at %s\n",
-		is_xbridge(bridge) ? "X" : "",
-		(rev == BRIDGE_PART_REV_A) ? "A" :
-		(rev == BRIDGE_PART_REV_B) ? "B" :
-		(rev == BRIDGE_PART_REV_C) ? "C" :
-		(rev == BRIDGE_PART_REV_D) ? "D" :
-		(rev == XBRIDGE_PART_REV_A) ? "A" :
-		(rev == XBRIDGE_PART_REV_B) ? "B" :
-		"unknown",
-		rev, pcibr_soft->bs_name);
-#endif
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ATTACH, pcibr_vhdl,
+		"pcibr_attach2: %s ASIC: rev %s (code=0x%x)\n",
+		IS_XBRIDGE_SOFT(pcibr_soft) ? "XBridge" :
+			IS_PIC_SOFT(pcibr_soft) ? "PIC" : "Bridge", 
+		(rev == BRIDGE_PART_REV_A) ? "A" : 
+                (rev == BRIDGE_PART_REV_B) ? "B" :
+                (rev == BRIDGE_PART_REV_C) ? "C" :
+                (rev == BRIDGE_PART_REV_D) ? "D" :
+                (rev == XBRIDGE_PART_REV_A) ? "A" :
+                (rev == XBRIDGE_PART_REV_B) ? "B" :
+                (IS_PIC_PART_REV_A(rev)) ? "A" : 
+                "unknown", rev, pcibr_soft->bs_name));
 
     info = xwidget_info_get(xconn_vhdl);
     pcibr_soft->bs_xid = xwidget_info_id_get(info);
     pcibr_soft->bs_master = xwidget_info_master_get(info);
     pcibr_soft->bs_mxid = xwidget_info_masterid_get(info);
 
+    pcibr_soft->bs_first_slot = pcibr_soft->bs_min_slot;
+    pcibr_soft->bs_last_slot = pcibr_soft->bs_max_slot;
     /*
-     * Init bridge lock.
+     * Bridge can only reset slots 0, 1, 2, and 3.  Ibrick internal
+     * slots 4, 5, 6, and 7 must be reset as a group, so do not
+     * reset them.
      */
-    spin_lock_init(&pcibr_soft->bs_lock);
+    pcibr_soft->bs_last_reset = 3;
+
+    nasid = NASID_GET(bridge);
+
+    /* set whether it is a PIC or not */
+    Is_pic_on_this_nasid[nasid] = (IS_PIC_SOFT(pcibr_soft)) ? 1 : 0;
+
+
+    if ((pcibr_soft->bs_bricktype = iobrick_type_get_nasid(nasid)) < 0)
+	printk(KERN_WARNING "0x%p: Unknown bricktype : 0x%x\n", (void *)xconn_vhdl,
+				(unsigned int)pcibr_soft->bs_bricktype);
+
+    pcibr_soft->bs_moduleid = iobrick_module_get_nasid(nasid);
+
+    if (pcibr_soft->bs_bricktype > 0) {
+	switch (pcibr_soft->bs_bricktype) {
+	case MODULE_PXBRICK:
+	    pcibr_soft->bs_first_slot = 0;
+	    pcibr_soft->bs_last_slot = 1;
+	    pcibr_soft->bs_last_reset = 1;
+	    break;
+	case MODULE_PEBRICK:
+	case MODULE_PBRICK:
+            pcibr_soft->bs_first_slot = 1;
+            pcibr_soft->bs_last_slot = 2;
+            pcibr_soft->bs_last_reset = 2;
+            break;
+
+        case MODULE_IBRICK:
+	    /*
+	     * Here's the current baseio layout for SN1 style systems:
+	     *
+	     *    0    1    2    3    4    5    6    7		slot#
+	     *
+	     *    x    scsi x    x    ioc3 usb  x    x  	O300 Ibrick
+	     *
+             * x == never occupied
+             * E == external (add-in) slot
+	     *
+	     */
+            pcibr_soft->bs_first_slot = 1;	/* Ibrick first slot == 1 */
+            if (pcibr_soft->bs_xid == 0xe) { 
+                pcibr_soft->bs_last_slot = 2;
+                pcibr_soft->bs_last_reset = 2;
+            } else {
+		pcibr_soft->bs_last_slot = 6;
+	    }
+            break;
+	default:
+	    break;
+        }
+
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ATTACH, pcibr_vhdl,
+		    "pcibr_attach2: %cbrick, slots %d-%d\n",
+		    MODULE_GET_BTCHAR(pcibr_soft->bs_moduleid),
+		    pcibr_soft->bs_first_slot, pcibr_soft->bs_last_slot));
+    }
 
     /*
+     * Initialize bridge and bus locks
+     */
+    spin_lock_init(&pcibr_soft->bs_lock);
+#ifdef PIC_LATER
+    mrinit(pcibr_soft->bs_bus_lock, "bus_lock");
+#endif
+    /*
      * If we have one, process the hints structure.
      */
     if (pcibr_hints) {
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_HINTS, pcibr_vhdl,
+                    "pcibr_attach2: pcibr_hints=0x%x\n", pcibr_hints));
+
 	rrb_fixed = pcibr_hints->ph_rrb_fixed;
 
 	pcibr_soft->bs_rrb_fixed = rrb_fixed;
 
-	if (pcibr_hints->ph_intr_bits)
+	if (pcibr_hints->ph_intr_bits) {
 	    pcibr_soft->bs_intr_bits = pcibr_hints->ph_intr_bits;
+	}
 
-	for (slot = 0; slot < 8; ++slot) {
-	    int                     hslot = pcibr_hints->ph_host_slot[slot] - 1;
+	for (slot = pcibr_soft->bs_min_slot; 
+				slot < PCIBR_NUM_SLOTS(pcibr_soft); ++slot) {
+	    int hslot = pcibr_hints->ph_host_slot[slot] - 1;
 
 	    if (hslot < 0) {
 		pcibr_soft->bs_slot[slot].host_slot = slot;
@@ -1507,13 +1456,16 @@
 	}
     }
     /*
-     * set up initial values for state fields
+     * Set-up initial values for state fields
      */
-    for (slot = 0; slot < 8; ++slot) {
+    for (slot = pcibr_soft->bs_min_slot; 
+				slot < PCIBR_NUM_SLOTS(pcibr_soft); ++slot) {
 	pcibr_soft->bs_slot[slot].bss_devio.bssd_space = PCIIO_SPACE_NONE;
+	pcibr_soft->bs_slot[slot].bss_devio.bssd_ref_cnt = 0;
 	pcibr_soft->bs_slot[slot].bss_d64_base = PCIBR_D64_BASE_UNSET;
 	pcibr_soft->bs_slot[slot].bss_d32_base = PCIBR_D32_BASE_UNSET;
 	pcibr_soft->bs_slot[slot].bss_ext_ates_active = ATOMIC_INIT(0);
+	pcibr_soft->bs_rrb_valid_dflt[slot][VCHAN0] = -1;
     }
 
     for (ibit = 0; ibit < 8; ++ibit) {
@@ -1522,15 +1474,31 @@
 	pcibr_soft->bs_intr[ibit].bsi_pcibr_intr_wrap.iw_list = NULL;
 	pcibr_soft->bs_intr[ibit].bsi_pcibr_intr_wrap.iw_stat = 
 							&(bridge->b_int_status);
+	pcibr_soft->bs_intr[ibit].bsi_pcibr_intr_wrap.iw_ibit = ibit;
 	pcibr_soft->bs_intr[ibit].bsi_pcibr_intr_wrap.iw_hdlrcnt = 0;
 	pcibr_soft->bs_intr[ibit].bsi_pcibr_intr_wrap.iw_shared = 0;
 	pcibr_soft->bs_intr[ibit].bsi_pcibr_intr_wrap.iw_connected = 0;
     }
 
     /*
+     * connect up our error handler.  PIC has 2 busses (thus resulting in 2
+     * pcibr_soft structs under 1 widget), so only register a xwidget error
+     * handler for PIC's bus0.  NOTE: for PIC pcibr_error_handler_wrapper()
+     * is a wrapper routine we register that will call the real error handler
+     * pcibr_error_handler() with the correct pcibr_soft struct.
+     */
+    if (IS_PIC_SOFT(pcibr_soft)) {
+	if (busnum == 0) {
+	    xwidget_error_register(xconn_vhdl, pcibr_error_handler_wrapper, pcibr_soft);
+	}
+    } else {
+	xwidget_error_register(xconn_vhdl, pcibr_error_handler, pcibr_soft);
+    }
+
+    /*
      * Initialize various Bridge registers.
      */
-
+  
     /*
      * On pre-Rev.D bridges, set the PCI_RETRY_CNT
      * to zero to avoid dropping stores. (#475347)
@@ -1543,12 +1511,43 @@
      */
     bridge->b_int_rst_stat = (BRIDGE_IRR_ALL_CLR);
 
+    /* Initialize some PIC specific registers. */
+    if (IS_PIC_SOFT(pcibr_soft)) {
+	picreg_t pic_ctrl_reg = bridge->p_wid_control_64;
+
+	/* Bridges Requester ID: bus = busnum, dev = 0, func = 0 */
+	pic_ctrl_reg &= ~PIC_CTRL_BUS_NUM_MASK;
+	pic_ctrl_reg |= PIC_CTRL_BUS_NUM(busnum);
+	pic_ctrl_reg &= ~PIC_CTRL_DEV_NUM_MASK;
+	pic_ctrl_reg &= ~PIC_CTRL_FUN_NUM_MASK;
+
+	pic_ctrl_reg &= ~PIC_CTRL_NO_SNOOP;
+	pic_ctrl_reg &= ~PIC_CTRL_RELAX_ORDER;
+
+	/* enable parity checking on PICs internal RAM */
+	pic_ctrl_reg |= PIC_CTRL_PAR_EN_RESP;
+	pic_ctrl_reg |= PIC_CTRL_PAR_EN_ATE;
+	/* PIC BRINGUP WAR (PV# 862253): dont enable write request
+	 * parity checking.
+	 */
+	if (!PCIBR_WAR_ENABLED(PV862253, pcibr_soft)) {
+	    pic_ctrl_reg |= PIC_CTRL_PAR_EN_REQ;
+	}
+
+	bridge->p_wid_control_64 = pic_ctrl_reg;
+    }
+
     /*
      * Until otherwise set up,
      * assume all interrupts are
-     * from slot 7.
+     * from slot 7(Bridge/Xbridge) or 3(PIC).
+     * XXX. Not sure why we're doing this, made change for PIC
+     * just to avoid setting reserved bits.
      */
-    bridge->b_int_device = (uint32_t) 0xffffffff;
+    if (IS_PIC_SOFT(pcibr_soft))
+	bridge->b_int_device = (uint32_t) 0x006db6db;
+    else
+	bridge->b_int_device = (uint32_t) 0xffffffff;
 
     {
 	bridgereg_t             dirmap;
@@ -1560,6 +1559,11 @@
 	int                     entry;
 	cnodeid_t		cnodeid;
 	nasid_t			nasid;
+#ifdef PIC_LATER
+	char		       *node_val;
+	devfs_handle_t		node_vhdl;
+	char			vname[MAXDEVNAME];
+#endif
 
 	/* Set the Bridge's 32-bit PCI to XTalk
 	 * Direct Map register to the most useful
@@ -1578,6 +1582,30 @@
 	 */
 
 	cnodeid = 0;  /* default node id */
+	/*
+	 * Determine the base address node id to be used for all 32-bit
+	 * Direct Mapping I/O. The default is node 0, but this can be changed
+	 * via a DEVICE_ADMIN directive and the PCIBUS_DMATRANS_NODE
+	 * attribute in the irix.sm config file. A device driver can obtain
+	 * this node value via a call to pcibr_get_dmatrans_node().
+	 */
+#ifdef PIC_LATER
+// This probably needs to be addressed - pfg
+	node_val = device_admin_info_get(pcibr_vhdl, ADMIN_LBL_DMATRANS_NODE);
+	if (node_val != NULL) {
+	    node_vhdl = hwgraph_path_to_vertex(node_val);
+	    if (node_vhdl != GRAPH_VERTEX_NONE) {
+		cnodeid = nodevertex_to_cnodeid(node_vhdl);
+	    }
+	    if ((node_vhdl == GRAPH_VERTEX_NONE) || (cnodeid == CNODEID_NONE)) {
+		cnodeid = 0;
+		vertex_to_name(pcibr_vhdl, vname, sizeof(vname));
+		printk(KERN_WARNING "Invalid hwgraph node path specified:\n"
+			"    DEVICE_ADMIN: %s %s=%s\n",
+			vname, ADMIN_LBL_DMATRANS_NODE, node_val);
+	    }
+	}
+#endif	/* PIC_LATER */
 	nasid = COMPACT_TO_NASID_NODEID(cnodeid);
 	paddr = NODE_OFFSET(nasid) + 0;
 
@@ -1619,9 +1647,17 @@
 	 */
 	spl_level = splhi();
 #if IOPGSIZE == 4096
-	bridge->b_wid_control &= ~BRIDGE_CTRL_PAGE_SIZE;
+        if (IS_PIC_SOFT(pcibr_soft)) {
+            bridge->p_wid_control_64 &= ~BRIDGE_CTRL_PAGE_SIZE;
+        } else {
+            bridge->b_wid_control &= ~BRIDGE_CTRL_PAGE_SIZE;
+        }
 #elif IOPGSIZE == 16384
-	bridge->b_wid_control |= BRIDGE_CTRL_PAGE_SIZE;
+        if (IS_PIC_SOFT(pcibr_soft)) {
+            bridge->p_wid_control_64 |= BRIDGE_CTRL_PAGE_SIZE;
+        } else {
+            bridge->b_wid_control |= BRIDGE_CTRL_PAGE_SIZE;
+        }
 #else
 	<<<Unable to deal with IOPGSIZE >>>;
 #endif
@@ -1652,7 +1688,8 @@
 	 * recomparing against BRIDGE_INTERNAL_ATES every
 	 * time.
 	 */
-	if (is_xbridge(bridge))
+
+	if (IS_XBRIDGE_OR_PIC_SOFT(pcibr_soft))
 		num_entries = 0;
 	else
 		num_entries = pcibr_init_ext_ate_ram(bridge);
@@ -1662,9 +1699,6 @@
 	 */
 	pcibr_soft->bs_int_ate_map = rmallocmap(pcibr_soft->bs_int_ate_size);
 	pcibr_ate_free(pcibr_soft, 0, pcibr_soft->bs_int_ate_size);
-#if PCIBR_ATE_DEBUG
-	printk("pcibr_attach: %d INTERNAL ATEs\n", pcibr_soft->bs_int_ate_size);
-#endif
 
 	if (num_entries > pcibr_soft->bs_int_ate_size) {
 #if PCIBR_ATE_NOTBOTH			/* for debug -- forces us to use external ates */
@@ -1674,11 +1708,12 @@
 	    pcibr_soft->bs_ext_ate_map = rmallocmap(num_entries);
 	    pcibr_ate_free(pcibr_soft, pcibr_soft->bs_int_ate_size,
 			   num_entries - pcibr_soft->bs_int_ate_size);
-#if PCIBR_ATE_DEBUG
-	    printk("pcibr_attach: %d EXTERNAL ATEs\n",
-		    num_entries - pcibr_soft->bs_int_ate_size);
-#endif
 	}
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ATE, pcibr_vhdl,
+		    "pcibr_attach2: %d ATEs, %d internal & %d external\n",
+		    num_entries ? num_entries : pcibr_soft->bs_int_ate_size,
+		    pcibr_soft->bs_int_ate_size,
+		    num_entries ? num_entries-pcibr_soft->bs_int_ate_size : 0));
     }
 
     {
@@ -1727,7 +1762,7 @@
      * knows to do this.
      */
 
-    xtalk_intr = xtalk_intr_alloc(xconn_vhdl, dev_desc, pcibr_vhdl);
+    xtalk_intr = xtalk_intr_alloc(xconn_vhdl, (device_desc_t)0, pcibr_vhdl);
     ASSERT(xtalk_intr != NULL);
 
     pcibr_soft->bsi_err_intr = xtalk_intr;
@@ -1740,17 +1775,124 @@
      */
     pcibr_clearwidint(bridge);
 
-    xtalk_intr_connect(xtalk_intr, (xtalk_intr_setfunc_t)pcibr_setwidint, (void *)bridge);
+    xtalk_intr_connect(xtalk_intr, (intr_func_t) pcibr_error_intr_handler,
+		(intr_arg_t) pcibr_soft, (xtalk_intr_setfunc_t)pcibr_setwidint, (void *)bridge);
+
+#ifdef BUS_INT_WAR_NOT_YET
+    request_irq(CPU_VECTOR_TO_IRQ(((hub_intr_t)xtalk_intr)->i_cpuid,
+			((hub_intr_t)xtalk_intr)->i_bit),
+				(intr_func_t)pcibr_error_intr_handler, 0, "PCIBR error",
+					(intr_arg_t) pcibr_soft);
+#endif
+
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ALLOC, pcibr_vhdl,
+		"pcibr_setwidint: b_wid_int_upper=0x%x, b_wid_int_lower=0x%x\n",
+		bridge->b_wid_int_upper, bridge->b_wid_int_lower));
 
     /*
      * now we can start handling error interrupts;
      * enable all of them.
      * NOTE: some PCI ints may already be enabled.
      */
-    b_int_enable = bridge->b_int_enable | BRIDGE_ISR_ERRORS;
+    /* We read the INT_ENABLE register as a 64bit picreg_t for PIC and a
+     * 32bit bridgereg_t for BRIDGE, but always process the result as a
+     * 64bit value so the code can be "common" for both PIC and BRIDGE...
+     */
+    if (IS_PIC_SOFT(pcibr_soft)) {
+	int_enable_64 = bridge->p_int_enable_64 | BRIDGE_ISR_ERRORS;
+        int_enable = (uint64_t)int_enable_64;
+    } else {
+	int_enable_32 = bridge->b_int_enable | (BRIDGE_ISR_ERRORS & 0xffffffff);
+	int_enable = ((uint64_t)int_enable_32 & 0xffffffff);
+    }
+#ifdef BUS_INT_WAR_NOT_YET
+    {
+	extern void sn_add_polled_interrupt(int irq, int interval);
+
+        sn_add_polled_interrupt(CPU_VECTOR_TO_IRQ(((hub_intr_t)xtalk_intr)->i_cpuid,
+				((hub_intr_t)xtalk_intr)->i_bit), 20000);
+    }
+#endif
+
+
+#if BRIDGE_ERROR_INTR_WAR
+    if (pcibr_soft->bs_rev_num == BRIDGE_PART_REV_A) {
+	/*
+	 * We commonly get master timeouts when talking to ql.
+	 * We also see RESP_XTALK_ERROR and LLP_TX_RETRY interrupts.
+	 * Insure that these are all disabled for now.
+	 */
+	int_enable &= ~(BRIDGE_IMR_PCI_MST_TIMEOUT |
+			BRIDGE_ISR_RESP_XTLK_ERR |
+			BRIDGE_ISR_LLP_TX_RETRY);
+    }
+    if (pcibr_soft->bs_rev_num < BRIDGE_PART_REV_C) {
+	int_enable &= ~BRIDGE_ISR_BAD_XRESP_PKT;
+    }
+#endif				/* BRIDGE_ERROR_INTR_WAR */
+
+#ifdef QL_SCSI_CTRL_WAR			/* for IP30 only */
+    /* Really a QL rev A issue, but all newer hearts have newer QLs.
+     * Forces all IO6/MSCSI to be new.
+     */
+    if (heart_rev() == HEART_REV_A)
+	int_enable &= ~BRIDGE_IMR_PCI_MST_TIMEOUT;
+#endif
+
+#ifdef BRIDGE1_TIMEOUT_WAR
+    if (pcibr_soft->bs_rev_num == BRIDGE_PART_REV_A) {
+	/*
+	 * Turn off these interrupts.  They can't be trusted in bridge 1
+	 */
+	int_enable &= ~(BRIDGE_IMR_XREAD_REQ_TIMEOUT |
+			BRIDGE_IMR_UNEXP_RESP);
+    }
+#endif
+
+#ifdef BRIDGE_B_DATACORR_WAR
+
+    /* WAR panic for Rev B silent data corruption.
+     * PIOERR turned off here because there is a problem
+     * with not re-arming it in pcibr_error_intr_handler.
+     * We don't get LLP error interrupts if we don't
+     * re-arm PIOERR interrupts! Just disable them here
+     */
+
+    if (pcibr_soft->bs_rev_num == BRIDGE_PART_REV_B) {
+	int_enable |= BRIDGE_IMR_LLP_REC_CBERR;
+	int_enable &= ~BRIDGE_ISR_PCIBUS_PIOERR;
 
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ATTACH, pcibr_vhdl,
+		    "Turning on LLP_REC_CBERR for Rev B Bridge.\n"));
+    }
+#endif
 
-    bridge->b_int_enable = b_int_enable;
+    /* PIC BRINGUP WAR (PV# 856864 & 856865): allow the tnums that are
+     * locked out to be freed up sooner (by timing out) so that the
+     * read tnums are never completely used up.
+     */
+    if (IS_PIC_SOFT(pcibr_soft) && PCIBR_WAR_ENABLED(PV856864, pcibr_soft)) {
+        int_enable &= ~PIC_ISR_PCIX_REQ_TOUT;
+        int_enable &= ~BRIDGE_ISR_XREAD_REQ_TIMEOUT;
+
+        bridge->b_wid_req_timeout = 0x750;
+    }
+
+    /*
+     * PIC BRINGUP WAR (PV# 856866, 859504, 861476, 861478): Don't use
+     * RRB0, RRB8, RRB1, and RRB9.  Assign them to DEVICE[2|3]--VCHAN3
+     * so they are not used
+     */
+    if (IS_PIC_SOFT(pcibr_soft) && PCIBR_WAR_ENABLED(PV856866, pcibr_soft)) {
+        bridge->b_even_resp |= 0x000f000f;
+        bridge->b_odd_resp |= 0x000f000f;
+    }
+
+    if (IS_PIC_SOFT(pcibr_soft)) {
+        bridge->p_int_enable_64 = (picreg_t)int_enable;
+    } else {
+        bridge->b_int_enable = (bridgereg_t)int_enable;
+    }
     bridge->b_int_mode = 0;		/* do not send "clear interrupt" packets */
 
     bridge->b_wid_tflush;		/* wait until Bridge PIO complete */
@@ -1788,20 +1930,59 @@
 		(BRIDGE_WIDGET_PART_NUM << 4 | pcibr_wg_enable_rev))
 	pcibr_soft->bs_dma_flags |= PCIBR_NOWRITE_GATHER;
 
-    pciio_provider_register(pcibr_vhdl, &pcibr_provider);
-    pciio_provider_startup(pcibr_vhdl);
-
-    pci_io_fb = 0x00000004;		/* I/O FreeBlock Base */
-    pci_io_fl = 0xFFFFFFFF;		/* I/O FreeBlock Last */
-
-    pci_lo_fb = 0x00000010;		/* Low Memory FreeBlock Base */
-    pci_lo_fl = 0x001FFFFF;		/* Low Memory FreeBlock Last */
+    /* PIC only supports 64-bit direct mapping in PCI-X mode.  Since
+     * all PCI-X devices that initiate memory transactions must be
+     * capable of generating 64-bit addressed, we force 64-bit DMAs.
+     */
+    if (IS_PCIX(pcibr_soft)) {
+	pcibr_soft->bs_dma_flags |= PCIIO_DMA_A64;
+    }
 
-    pci_hi_fb = 0x00200000;		/* High Memory FreeBlock Base */
-    pci_hi_fl = 0x3FFFFFFF;		/* High Memory FreeBlock Last */
+    {
 
+    pciio_win_map_t         win_map_p;
+    iopaddr_t               prom_base_addr = pcibr_soft->bs_xid << 24;
+    int                     prom_base_size = 0x1000000;
+    iopaddr_t               prom_base_limit = prom_base_addr + prom_base_size; 
+
+    /* Allocate resource maps based on bus page size; for I/O and memory
+     * space, free all pages except those in the base area and in the
+     * range set by the PROM. 
+     *
+     * PROM creates BAR addresses in this format: 0x0ws00000 where w is
+     * the widget number and s is the device register offset for the slot.
+     */
 
-    PCI_ADDR_SPACE_LIMITS_STORE();
+    win_map_p = &pcibr_soft->bs_io_win_map;
+    pciio_device_win_map_new(win_map_p,
+			     PCIBR_BUS_IO_MAX + 1,
+			     PCIBR_BUS_IO_PAGE);
+    pciio_device_win_populate(win_map_p,
+			      PCIBR_BUS_IO_BASE,
+			      prom_base_addr - PCIBR_BUS_IO_BASE);
+    pciio_device_win_populate(win_map_p,
+			      prom_base_limit,
+			      (PCIBR_BUS_IO_MAX + 1) - prom_base_limit);
+
+    win_map_p = &pcibr_soft->bs_swin_map;
+    pciio_device_win_map_new(win_map_p,
+			     PCIBR_BUS_SWIN_MAX + 1,
+			     PCIBR_BUS_SWIN_PAGE);
+    pciio_device_win_populate(win_map_p,
+			      PCIBR_BUS_SWIN_BASE,
+			      (PCIBR_BUS_SWIN_MAX + 1) - PCIBR_BUS_SWIN_PAGE);
+
+    win_map_p = &pcibr_soft->bs_mem_win_map;
+    pciio_device_win_map_new(win_map_p,
+			     PCIBR_BUS_MEM_MAX + 1,
+			     PCIBR_BUS_MEM_PAGE);
+    pciio_device_win_populate(win_map_p,
+			      PCIBR_BUS_MEM_BASE,
+			      prom_base_addr - PCIBR_BUS_MEM_BASE);
+    pciio_device_win_populate(win_map_p,
+			      prom_base_limit,
+			      (PCIBR_BUS_MEM_MAX + 1) - prom_base_limit);
+    }
 
     /* build "no-slot" connection point
      */
@@ -1830,59 +2011,91 @@
     }
 #endif
 
-#ifdef LATER
-    /* If the bridge has been reset then there is no need to reset
-     * the individual PCI slots.
-     */
-    for (slot = 0; slot < 8; ++slot)  
-	/* Reset all the slots */
-	(void)pcibr_slot_reset(pcibr_vhdl, slot);
-#endif
-
-    for (slot = 0; slot < 8; ++slot)
+    for (slot = pcibr_soft->bs_min_slot; 
+				slot < PCIBR_NUM_SLOTS(pcibr_soft); ++slot) {
 	/* Find out what is out there */
 	(void)pcibr_slot_info_init(pcibr_vhdl,slot);
+    }
+    for (slot = pcibr_soft->bs_min_slot; 
+				slot < PCIBR_NUM_SLOTS(pcibr_soft); ++slot)
+	/* Set up the address space for this slot in the PCI land */
+	(void)pcibr_slot_addr_space_init(pcibr_vhdl, slot);
 
-    for (slot = 0; slot < 8; ++slot)  
-	/* Set up the address space for this slot in the pci land */
-	(void)pcibr_slot_addr_space_init(pcibr_vhdl,slot);
-
-    for (slot = 0; slot < 8; ++slot)  
+    for (slot = pcibr_soft->bs_min_slot; 
+				slot < PCIBR_NUM_SLOTS(pcibr_soft); ++slot)
 	/* Setup the device register */
 	(void)pcibr_slot_device_init(pcibr_vhdl, slot);
 
-    for (slot = 0; slot < 8; ++slot)  
-	/* Setup host/guest relations */
-	(void)pcibr_slot_guest_info_init(pcibr_vhdl,slot);
-
-    for (slot = 0; slot < 8; ++slot)  
-	/* Initial RRB management */
-	(void)pcibr_slot_initial_rrb_alloc(pcibr_vhdl,slot);
+    if (IS_PCIX(pcibr_soft)) {
+        pcibr_soft->bs_pcix_rbar_inuse = 0;
+        pcibr_soft->bs_pcix_rbar_avail = NUM_RBAR;
+	pcibr_soft->bs_pcix_rbar_percent_allowed = 
+					pcibr_pcix_rbars_calc(pcibr_soft);
+
+	for (slot = pcibr_soft->bs_min_slot; 
+				slot < PCIBR_NUM_SLOTS(pcibr_soft); ++slot)
+	    /* Setup the PCI-X Read Buffer Attribute Registers (RBARs) */
+	    (void)pcibr_slot_pcix_rbar_init(pcibr_soft, slot);
+    }
+
+    /* Set up convenience links */
+    if (IS_XBRIDGE_OR_PIC_SOFT(pcibr_soft))
+	pcibr_bus_cnvlink(pcibr_soft->bs_vhdl);
 
-    /* driver attach routines should be called out from generic linux code */
-    for (slot = 0; slot < 8; ++slot)  
-	/* Call the device attach */
-	(void)pcibr_slot_call_device_attach(pcibr_vhdl, slot, 0);
+    for (slot = pcibr_soft->bs_min_slot; 
+				slot < PCIBR_NUM_SLOTS(pcibr_soft); ++slot)
+	/* Setup host/guest relations */
+	(void)pcibr_slot_guest_info_init(pcibr_vhdl, slot);
 
+    /* Handle initial RRB management for Bridge and Xbridge */
+    pcibr_initial_rrb(pcibr_vhdl, 
+                      pcibr_soft->bs_first_slot, pcibr_soft->bs_last_slot);
+    
+{  /* Before any drivers get called that may want to re-allocate
+    * RRB's, let's get some special cases pre-allocated. Drivers
+    * may override these pre-allocations, but by doing pre-allocations
+    * now we're assured not to step all over what the driver intended.
+    *
+    * Note: Someday this should probably be moved over to pcibr_rrb.c
+    */
     /*
      * Each Pbrick PCI bus only has slots 1 and 2.   Similarly for
      * widget 0xe on Ibricks.  Allocate RRB's accordingly.
      */
-    if (pcibr_soft->bs_moduleid > 0) {
-	switch (MODULE_GET_BTCHAR(pcibr_soft->bs_moduleid)) {
-	case 'p':		/* Pbrick */
-		do_pcibr_rrb_autoalloc(pcibr_soft, 1, 8);
-		do_pcibr_rrb_autoalloc(pcibr_soft, 2, 8);
+    if (pcibr_soft->bs_bricktype > 0) {
+	switch (pcibr_soft->bs_bricktype) {
+	case MODULE_PXBRICK:
+		/* 
+		 * If the IO9 is in the PXBrick (bus1, slot1) allocate
+                 * RRBs to all the devices
+		 */
+		if ((pcibr_widget_to_bus(pcibr_vhdl) == 1) &&
+		    (pcibr_soft->bs_slot[0].bss_vendor_id == 0x10A9) &&
+		    (pcibr_soft->bs_slot[0].bss_device_id == 0x100A)) {
+			do_pcibr_rrb_autoalloc(pcibr_soft, 0, VCHAN0, 4);
+			do_pcibr_rrb_autoalloc(pcibr_soft, 1, VCHAN0, 4);
+			do_pcibr_rrb_autoalloc(pcibr_soft, 2, VCHAN0, 4);
+			do_pcibr_rrb_autoalloc(pcibr_soft, 3, VCHAN0, 4);
+		} else {
+			do_pcibr_rrb_autoalloc(pcibr_soft, 0, VCHAN0, 8);
+			do_pcibr_rrb_autoalloc(pcibr_soft, 1, VCHAN0, 8);
+		}
+
 		break;
-	case 'i':		/* Ibrick */
+	case MODULE_PEBRICK:
+	case MODULE_PBRICK:
+		do_pcibr_rrb_autoalloc(pcibr_soft, 1, VCHAN0, 8);
+		do_pcibr_rrb_autoalloc(pcibr_soft, 2, VCHAN0, 8);
+		break;
+	case MODULE_IBRICK:
 	  	/* port 0xe on the Ibrick only has slots 1 and 2 */
 		if (pcibr_soft->bs_xid == 0xe) {
-			do_pcibr_rrb_autoalloc(pcibr_soft, 1, 8);
-			do_pcibr_rrb_autoalloc(pcibr_soft, 2, 8);
+			do_pcibr_rrb_autoalloc(pcibr_soft, 1, VCHAN0, 8);
+			do_pcibr_rrb_autoalloc(pcibr_soft, 2, VCHAN0, 8);
 		}
 		else {
 		    	/* allocate one RRB for the serial port */
-			do_pcibr_rrb_autoalloc(pcibr_soft, 0, 1);
+			do_pcibr_rrb_autoalloc(pcibr_soft, 0, VCHAN0, 1);
 		}
 		break;
 	} /* switch */
@@ -1890,33 +2103,80 @@
 
 #ifdef LATER
     if (strstr(nicinfo, XTALK_PCI_PART_NUM)) {
-	do_pcibr_rrb_autoalloc(pcibr_soft, 1, 8);
-#if PCIBR_RRB_DEBUG
-	printf("\n\nFound XTALK_PCI (030-1275) at %v\n", xconn_vhdl);
-
-	printf("pcibr_attach: %v Shoebox RRB MANAGEMENT: %d+%d free\n",
-		pcibr_vhdl,
-		pcibr_soft->bs_rrb_avail[0],
-		pcibr_soft->bs_rrb_avail[1]);
-
-	for (slot = 0; slot < 8; ++slot)
-	    printf("\t%d+%d+%d",
-	    0xFFF & pcibr_soft->bs_rrb_valid[slot],
-	    0xFFF & pcibr_soft->bs_rrb_valid[slot + PCIBR_RRB_SLOT_VIRTUAL],
-	    pcibr_soft->bs_rrb_res[slot]);
-
-	printf("\n");
+	do_pcibr_rrb_autoalloc(pcibr_soft, 1, VCHAN0, 8);
+    }
 #endif
+}  /* OK Special RRB allocations are done. */
+
+    for (slot = pcibr_soft->bs_min_slot; 
+				slot < PCIBR_NUM_SLOTS(pcibr_soft); ++slot)
+	/* Call the device attach */
+	(void)pcibr_slot_call_device_attach(pcibr_vhdl, slot, 0);
+
+#ifdef PIC_LATER
+#if (defined(USS302_TIMEOUT_WAR))
+    /*
+     * If this bridge holds a Lucent USS-302 or USS-312 pci/usb controller,
+     * increase the Bridge PCI retry backoff interval.  This part seems
+     * to go away for long periods of time if a DAC appears on the bus during
+     * a read command that is being retried.
+     */
+
+{
+    ii_ixtt_u_t ixtt;
+
+    for (slot = pcibr_soft->bs_min_slot; 
+				slot < PCIBR_NUM_SLOTS(pcibr_soft); ++slot) {
+	if (pcibr_soft->bs_slot[slot].bss_vendor_id ==
+					LUCENT_USBHC_VENDOR_ID_NUM &&
+	    (pcibr_soft->bs_slot[slot].bss_device_id ==
+					LUCENT_USBHC302_DEVICE_ID_NUM ||
+	     pcibr_soft->bs_slot[slot].bss_device_id ==
+					LUCENT_USBHC312_DEVICE_ID_NUM)) {
+	    printk(KERN_NOTICE
+		    "pcibr_attach: %x Bus holds a usb part - setting"
+		    "bridge PCI_RETRY_HLD to %d\n",
+		    pcibr_vhdl, USS302_BRIDGE_TIMEOUT_HLD);
+
+	    bridge->b_bus_timeout &= ~BRIDGE_BUS_PCI_RETRY_HLD_MASK;
+	    bridge->b_bus_timeout |=
+			BRIDGE_BUS_PCI_RETRY_HLD(USS302_BRIDGE_TIMEOUT_HLD);
+
+	    /*
+	     * Have to consider the read response timer in the hub II as well
+	     */
+
+	    hubii_ixtt_get(xconn_vhdl, &ixtt);
+
+	    /*
+	     * bump rrsp_ps to allow at least 1ms for read
+ 	     * responses from this widget
+	     */
+
+	    ixtt.ii_ixtt_fld_s.i_rrsp_ps = 20000;
+	    hubii_ixtt_set(xconn_vhdl, &ixtt);
+
+	    /*
+	     * print the current setting
+	     */
+
+	    hubii_ixtt_get(xconn_vhdl, &ixtt);
+	    printk( "Setting hub ixtt.rrsp_ps field to 0x%x\n",
+		    ixtt.ii_ixtt_fld_s.i_rrsp_ps);
+
+	    break;	/* only need to do it once */
+	}
     }
+}
+#endif	/* (defined(USS302_TIMEOUT_WAR)) */
 #else
 	FIXME("pcibr_attach: Call do_pcibr_rrb_autoalloc nicinfo\n");
-#endif
+#endif	/* PIC_LATER */
 
     if (aa)
 	    async_attach_add_info(noslot_conn, aa);
 
-    pciio_device_attach(noslot_conn, 0);
-
+    pciio_device_attach(noslot_conn, (int)0);
 
     /* 
      * Tear down pointer to async attach info -- async threads for
@@ -1927,11 +2187,13 @@
 
     return 0;
 }
+
 /*
  * pcibr_detach:
  *	Detach the bridge device from the hwgraph after cleaning out all the 
  *	underlying vertices.
  */
+
 int
 pcibr_detach(devfs_handle_t xconn)
 {
@@ -1939,6 +2201,9 @@
     devfs_handle_t	pcibr_vhdl;
     pcibr_soft_t	pcibr_soft;
     bridge_t		*bridge;
+    unsigned             s;
+
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DETACH, xconn, "pcibr_detach\n"));
 
     /* Get the bridge vertex from its xtalk connection point */
     if (hwgraph_traverse(xconn, EDGE_LBL_PCI, &pcibr_vhdl) != GRAPH_SUCCESS)
@@ -1947,16 +2212,20 @@
     pcibr_soft = pcibr_soft_get(pcibr_vhdl);
     bridge = pcibr_soft->bs_base;
 
+
+    s = pcibr_lock(pcibr_soft);
     /* Disable the interrupts from the bridge */
-    bridge->b_int_enable = 0;
+    if (IS_PIC_SOFT(pcibr_soft)) {
+	bridge->p_int_enable_64 = 0;
+    } else {
+	bridge->b_int_enable = 0;
+    }
+    pcibr_unlock(pcibr_soft, s);
 
     /* Detach all the PCI devices talking to this bridge */
-    for(slot = 0; slot < 8; slot++) {
-#ifdef DEBUG
-	printk("pcibr_device_detach called for %p/%d\n",
-		pcibr_vhdl,slot);
-#endif
-	pcibr_slot_detach(pcibr_vhdl, slot, 0);
+    for (slot = pcibr_soft->bs_min_slot; 
+				slot < PCIBR_NUM_SLOTS(pcibr_soft); ++slot) {
+	pcibr_slot_detach(pcibr_vhdl, slot, 0, (char *)NULL, (int *)NULL);
     }
 
     /* Unregister the no-slot connection point */
@@ -1998,17 +2267,29 @@
 int
 pcibr_asic_rev(devfs_handle_t pconn_vhdl)
 {
-    devfs_handle_t            pcibr_vhdl;
+    devfs_handle_t          pcibr_vhdl;
+    int                     tmp_vhdl;
     arbitrary_info_t        ainfo;
 
     if (GRAPH_SUCCESS !=
 	hwgraph_traverse(pconn_vhdl, EDGE_LBL_MASTER, &pcibr_vhdl))
 	return -1;
 
-    if (GRAPH_SUCCESS !=
-	hwgraph_info_get_LBL(pcibr_vhdl, INFO_LBL_PCIBR_ASIC_REV, &ainfo))
-	return -1;
+    tmp_vhdl = hwgraph_info_get_LBL(pcibr_vhdl, INFO_LBL_PCIBR_ASIC_REV, &ainfo);
 
+    /*
+     * Any hwgraph function that returns a vertex handle will implicity
+     * increment that vertex's reference count.  The caller must explicity
+     * decrement the vertex's referece count after the last reference to
+     * that vertex.
+     *
+     * Decrement reference count incremented by call to hwgraph_traverse().
+     *
+     */
+    hwgraph_vertex_unref(pcibr_vhdl);
+
+    if (tmp_vhdl != GRAPH_SUCCESS) 
+	return -1;
     return (int) ainfo;
 }
 
@@ -2018,7 +2299,7 @@
     pciio_info_t  pciio_info = pciio_info_get(pconn_vhdl);
     pcibr_soft_t  pcibr_soft = (pcibr_soft_t) pciio_info_mfast_get(pciio_info);
     pciio_slot_t  slot;
-    slot = pciio_info_slot_get(pciio_info);
+    slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
     pcibr_device_write_gather_flush(pcibr_soft, slot);
     return 0;
 }
@@ -2048,11 +2329,13 @@
     size_t                  wsize;	/* size of device decode on PCI */
 
     int                     try;	/* DevIO(x) window scanning order control */
+    int			    maxtry, halftry;
     int                     win;	/* which DevIO(x) window is being used */
     pciio_space_t           mspace;	/* target space for devio(x) register */
     iopaddr_t               mbase;	/* base of devio(x) mapped area on PCI */
     size_t                  msize;	/* size of devio(x) mapped area on PCI */
     size_t                  mmask;	/* addr bits stored in Device(x) */
+    char		    tmp_str[512];
 
     unsigned long           s;
 
@@ -2061,6 +2344,17 @@
     if (pcibr_soft->bs_slot[slot].has_host) {
 	slot = pcibr_soft->bs_slot[slot].host_slot;
 	pcibr_info = pcibr_soft->bs_slot[slot].bss_infos[0];
+
+	/*
+	 * Special case for dual-slot pci devices such as ioc3 on IP27
+	 * baseio.  In these cases, pconn_vhdl should never be for a pci
+	 * function on a subordiate PCI bus, so we can safely reset pciio_info
+	 * to be the info struct embedded in pcibr_info.  Failure to do this
+	 * results in using a bogus pciio_info_t for calculations done later
+	 * in this routine.
+	 */
+
+	pciio_info = &pcibr_info->f_c;
     }
     if (space == PCIIO_SPACE_NONE)
 	goto done;
@@ -2080,7 +2374,7 @@
 	 */
 	if (((flags & PCIIO_BYTE_STREAM) == 0) &&
 	    ((pci_addr + req_size) <= BRIDGE_TYPE0_CFG_FUNC_OFF))
-	    xio_addr = pci_addr + BRIDGE_TYPE0_CFG_DEV(slot);
+	    xio_addr = pci_addr + PCIBR_TYPE0_CFG_DEV(pcibr_soft, slot);
 
 	goto done;
     }
@@ -2090,8 +2384,8 @@
 	 * enabling and disabling
 	 * decodes properly.
 	 */
-	wbase = pcibr_info->f_rbase;
-	wsize = pcibr_info->f_rsize;
+	wbase = pciio_info->c_rbase;
+	wsize = pciio_info->c_rsize;
 
 	/*
 	 * While the driver should know better
@@ -2113,13 +2407,13 @@
      */
     bar = space - PCIIO_SPACE_WIN0;
     if (bar < 6) {
-	wspace = pcibr_info->f_window[bar].w_space;
+	wspace = pciio_info->c_window[bar].w_space;
 	if (wspace == PCIIO_SPACE_NONE)
 	    goto done;
 
 	/* get PCI base and size */
-	wbase = pcibr_info->f_window[bar].w_base;
-	wsize = pcibr_info->f_window[bar].w_size;
+	wbase = pciio_info->c_window[bar].w_base;
+	wsize = pciio_info->c_window[bar].w_size;
 
 	/*
 	 * While the driver should know better
@@ -2147,11 +2441,15 @@
      * We will not attempt to satisfy a single request
      * by concatinating multiple windows.
      */
-    for (try = 0; try < 16; ++try) {
+    maxtry = PCIBR_NUM_SLOTS(pcibr_soft) * 2;
+    halftry = PCIBR_NUM_SLOTS(pcibr_soft) - 1;
+    for (try = 0; try < maxtry; ++try) {
 	bridgereg_t             devreg;
 	unsigned                offset;
 
-	win = (try + slot) % 8;
+	/* calculate win based on slot, attempt, and max possible
+	   devices on bus */
+	win = (try + slot) % PCIBR_NUM_SLOTS(pcibr_soft);
 
 	/* If this DevIO(x) mapping area can provide
 	 * a mapping to this address, use it.
@@ -2176,7 +2474,7 @@
 	 * (only check this the second time through)
 	 */
 	mspace = pcibr_soft->bs_slot[win].bss_devio.bssd_space;
-	if ((try > 7) && (mspace == PCIIO_SPACE_NONE)) {
+	if ((try > halftry) && (mspace == PCIIO_SPACE_NONE)) {
 
 	    /* If this is the primary DevIO(x) window
 	     * for some other device, skip it.
@@ -2214,25 +2512,61 @@
 		devreg &= ~BRIDGE_DEV_DEV_SWAP;
 
 	    if (pcibr_soft->bs_slot[win].bss_device != devreg) {
-		bridge->b_device[win].reg = devreg;
-		pcibr_soft->bs_slot[win].bss_device = devreg;
-		bridge->b_wid_tflush;	/* wait until Bridge PIO complete */
+		if ( IS_PIC_SOFT(pcibr_soft) ) {
+			bridge->b_device[win].reg = devreg;
+			pcibr_soft->bs_slot[win].bss_device = devreg;
+			bridge->b_wid_tflush;   /* wait until Bridge PIO complete */
+		}
+		else {
+			if (io_get_sh_swapper(NASID_GET(bridge))) {
+				BRIDGE_REG_SET32((&bridge->b_device[win].reg)) = __swab32(devreg);
+				pcibr_soft->bs_slot[win].bss_device = devreg;
+				BRIDGE_REG_GET32((&bridge->b_wid_tflush)); /* wait until Bridge PIO complete */
+			} else {
+				bridge->b_device[win].reg = devreg;
+				pcibr_soft->bs_slot[win].bss_device = devreg;
+				bridge->b_wid_tflush;   /* wait until Bridge PIO complete */
+			}
+		}
 
-#if DEBUG && PCI_DEBUG
-		printk("pcibr Device(%d): 0x%lx\n", win, bridge->b_device[win].reg);
+#ifdef PCI_LATER
+		PCIBR_DEBUG((PCIBR_DEBUG_DEVREG, pconn_vhdl, 
+			    "pcibr_addr_pci_to_xio: Device(%d): %x\n",
+			    win, devreg, device_bits));
+#else
+	        printk("pcibr_addr_pci_to_xio: Device(%d): %x\n", win, devreg);
 #endif
 	    }
 	    pcibr_soft->bs_slot[win].bss_devio.bssd_space = space;
 	    pcibr_soft->bs_slot[win].bss_devio.bssd_base = mbase;
-	    xio_addr = BRIDGE_DEVIO(win) + (pci_addr - mbase);
+	    xio_addr = PCIBR_BRIDGE_DEVIO(pcibr_soft, win) + (pci_addr - mbase);
 
-#if DEBUG && PCI_DEBUG
-	    printk("%s LINE %d map to space %d space desc 0x%x[%lx..%lx] for slot %d allocates DevIO(%d) devreg 0x%x\n", 
-		    __FUNCTION__, __LINE__, space, space_desc,
-		    pci_addr, pci_addr + req_size - 1,
-		    slot, win, devreg);
-#endif
+            /* Increment this DevIO's use count */
+            pcibr_soft->bs_slot[win].bss_devio.bssd_ref_cnt++;
 
+            /* Save the DevIO register index used to access this BAR */
+            if (bar != -1)
+                pcibr_info->f_window[bar].w_devio_index = win;
+
+	    /*
+	     * The kernel only allows functions to have so many variable args,
+	     * attempting to call PCIBR_DEBUG_ALWAYS() with more than 5 printk
+	     * arguments fails so sprintf() it into a temporary string.
+	     */
+	    if (pcibr_debug_mask & PCIBR_DEBUG_PIOMAP) {
+#ifdef PIC_LATER
+	        sprintf(tmp_str, "pcibr_addr_pci_to_xio: map to %x[%x..%x] for "
+		        "slot %d allocates DevIO(%d) Device(%d) set to %x\n",
+		        space, space_desc, pci_addr, pci_addr + req_size - 1,
+		        slot, win, win, devreg, device_bits);
+#else
+	        sprintf(tmp_str, "pcibr_addr_pci_to_xio: map to [%lx..%lx] for "
+		        "slot %d allocates DevIO(%d) Device(%d) set to %lx\n",
+		        (unsigned long)pci_addr, (unsigned long)(pci_addr + req_size - 1),
+		        (unsigned int)slot, win, win, (unsigned long)devreg);
+#endif
+	        PCIBR_DEBUG((PCIBR_DEBUG_PIOMAP, pconn_vhdl, "%s", tmp_str));
+	    }
 	    goto done;
 	}				/* endif DevIO(x) not pointed */
 	mbase = pcibr_soft->bs_slot[win].bss_devio.bssd_base;
@@ -2251,12 +2585,23 @@
 	 * final XIO address, release the lock and
 	 * return.
 	 */
-	xio_addr = BRIDGE_DEVIO(win) + (pci_addr - mbase);
+	xio_addr = PCIBR_BRIDGE_DEVIO(pcibr_soft, win) + (pci_addr - mbase);
+
+        /* Increment this DevIO's use count */
+        pcibr_soft->bs_slot[win].bss_devio.bssd_ref_cnt++;
 
-#if DEBUG && PCI_DEBUG
-	printk("%s LINE %d map to space %d [0x%p..0x%p] for slot %d uses DevIO(%d)\n",
-		__FUNCTION__, __LINE__, space,  pci_addr, pci_addr + req_size - 1, slot, win);
+        /* Save the DevIO register index used to access this BAR */
+        if (bar != -1)
+            pcibr_info->f_window[bar].w_devio_index = win;
+
+	if (pcibr_debug_mask & PCIBR_DEBUG_PIOMAP) {
+#ifdef PIC_LATER
+	    sprintf(tmp_str, "pcibr_addr_pci_to_xio: map to %x[%x..%x] for "
+		    "slot %d uses DevIO(%d)\n", space, space_desc, pci_addr,
+		    pci_addr + req_size - 1, slot, win);
 #endif
+	    PCIBR_DEBUG((PCIBR_DEBUG_PIOMAP, pconn_vhdl, "%s", tmp_str));
+	}
 	goto done;
     }
 
@@ -2322,33 +2667,55 @@
 	if (bfn == bfo) {		/* we already match. */
 	    ;
 	} else if (bfo != 0) {		/* we have a conflict. */
-#if DEBUG && PCI_DEBUG
-	    printk("pcibr_addr_pci_to_xio: swap conflict in space %d , was%s%s, want%s%s\n",
-		    space, 
-		    bfo & PCIIO_BYTE_STREAM ? " BYTE_STREAM" : "",
-		    bfo & PCIIO_WORD_VALUES ? " WORD_VALUES" : "",
-		    bfn & PCIIO_BYTE_STREAM ? " BYTE_STREAM" : "",
-		    bfn & PCIIO_WORD_VALUES ? " WORD_VALUES" : "");
+	    if (pcibr_debug_mask & PCIBR_DEBUG_PIOMAP) {
+#ifdef PIC_LATER
+	        sprintf(tmp_str, "pcibr_addr_pci_to_xio: swap conflict in %x, "
+		        "was%s%s, want%s%s\n", space, space_desc,
+		        bfo & PCIIO_BYTE_STREAM ? " BYTE_STREAM" : "",
+		        bfo & PCIIO_WORD_VALUES ? " WORD_VALUES" : "",
+		        bfn & PCIIO_BYTE_STREAM ? " BYTE_STREAM" : "",
+		        bfn & PCIIO_WORD_VALUES ? " WORD_VALUES" : "");
 #endif
+	        PCIBR_DEBUG((PCIBR_DEBUG_PIOMAP, pconn_vhdl, "%s", tmp_str));
+	    }
 	    xio_addr = XIO_NOWHERE;
 	} else {			/* OK to make the change. */
-	    bridgereg_t             octl, nctl;
-
 	    swb = (space == PCIIO_SPACE_IO) ? BRIDGE_CTRL_IO_SWAP : BRIDGE_CTRL_MEM_SWAP;
-	    octl = bridge->b_wid_control;
-	    nctl = bst ? octl | swb : octl & ~swb;
+	    if ( IS_PIC_SOFT(pcibr_soft) ) {
+	    	picreg_t             octl, nctl;
+		octl = bridge->p_wid_control_64;
+		nctl = bst ? octl | (uint64_t)swb : octl & ((uint64_t)~swb);
 
-	    if (octl != nctl)		/* make the change if any */
-		bridge->b_wid_control = nctl;
+		if (octl != nctl)		/* make the change if any */
+			bridge->b_wid_control = nctl;
+	    }
+	    else {
+	    	picreg_t             octl, nctl;
+		if (io_get_sh_swapper(NASID_GET(bridge))) {
+			octl = BRIDGE_REG_GET32((&bridge->b_wid_control));
+			nctl = bst ? octl | swb : octl & ~swb;
+
+			if (octl != nctl)           /* make the change if any */
+				BRIDGE_REG_SET32((&bridge->b_wid_control)) = __swab32(nctl);
+		} else {
+			octl = bridge->b_wid_control;
+			nctl = bst ? octl | swb : octl & ~swb;
 
+			if (octl != nctl)           /* make the change if any */
+				bridge->b_wid_control = nctl;
+		}
+	    }
 	    *bfp = bfn;			/* record the assignment */
 
-#if DEBUG && PCI_DEBUG
-	    printk("pcibr_addr_pci_to_xio: swap for space %d  set to%s%s\n",
-		    space, 
-		    bfn & PCIIO_BYTE_STREAM ? " BYTE_STREAM" : "",
-		    bfn & PCIIO_WORD_VALUES ? " WORD_VALUES" : "");
+	    if (pcibr_debug_mask & PCIBR_DEBUG_PIOMAP) {
+#ifdef PIC_LATER
+	        sprintf(tmp_str, "pcibr_addr_pci_to_xio: swap for %x set "
+			"to%s%s\n", space, space_desc,
+		        bfn & PCIIO_BYTE_STREAM ? " BYTE_STREAM" : "",
+		        bfn & PCIIO_WORD_VALUES ? " WORD_VALUES" : "");
 #endif
+	        PCIBR_DEBUG((PCIBR_DEBUG_PIOMAP, pconn_vhdl, "%s", tmp_str));
+	    }
 	}
     }
   done:
@@ -2368,7 +2735,7 @@
 {
     pcibr_info_t	    pcibr_info = pcibr_info_get(pconn_vhdl);
     pciio_info_t            pciio_info = &pcibr_info->f_c;
-    pciio_slot_t            pciio_slot = pciio_info_slot_get(pciio_info);
+    pciio_slot_t            pciio_slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
     pcibr_soft_t            pcibr_soft = (pcibr_soft_t) pciio_info_mfast_get(pciio_info);
     devfs_handle_t            xconn_vhdl = pcibr_soft->bs_conn;
 
@@ -2380,8 +2747,11 @@
     unsigned long           s;
 
     /* Make sure that the req sizes are non-zero */
-    if ((req_size < 1) || (req_size_max < 1))
+    if ((req_size < 1) || (req_size_max < 1)) {
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_PIOMAP, pconn_vhdl,
+		    "pcibr_piomap_alloc: req_size | req_size_max < 1\n"));
 	return NULL;
+    }
 
     /*
      * Code to translate slot/space/addr
@@ -2390,8 +2760,11 @@
      */
     xio_addr = pcibr_addr_pci_to_xio(pconn_vhdl, pciio_slot, space, pci_addr, req_size, flags);
 
-    if (xio_addr == XIO_NOWHERE)
+    if (xio_addr == XIO_NOWHERE) {
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_PIOMAP, pconn_vhdl,
+		    "pcibr_piomap_alloc: xio_addr == XIO_NOWHERE\n"));
 	return NULL;
+    }
 
     /* Check the piomap list to see if there is already an allocated
      * piomap entry but not in use. If so use that one. Otherwise
@@ -2415,7 +2788,7 @@
     }
 
     pcibr_piomap->bp_dev = pconn_vhdl;
-    pcibr_piomap->bp_slot = pciio_slot;
+    pcibr_piomap->bp_slot = PCIBR_DEVICE_TO_SLOT(pcibr_soft, pciio_slot);
     pcibr_piomap->bp_flags = flags;
     pcibr_piomap->bp_space = space;
     pcibr_piomap->bp_pciaddr = pci_addr;
@@ -2446,6 +2819,10 @@
 	    pcibr_piomap = 0;
 	}
     }
+    
+    PCIBR_DEBUG((PCIBR_DEBUG_PIOMAP, pconn_vhdl,
+		"pcibr_piomap_alloc: map=0x%x\n", pcibr_piomap));
+
     return pcibr_piomap;
 }
 
@@ -2453,6 +2830,9 @@
 void
 pcibr_piomap_free(pcibr_piomap_t pcibr_piomap)
 {
+    PCIBR_DEBUG((PCIBR_DEBUG_PIOMAP, pcibr_piomap->bp_dev,
+		"pcibr_piomap_free: map=0x%x\n", pcibr_piomap));
+
     xtalk_piomap_free(pcibr_piomap->bp_xtalk_pio);
     pcibr_piomap->bp_xtalk_pio = 0;
     pcibr_piomap->bp_mapsz = 0;
@@ -2464,16 +2844,24 @@
 		  iopaddr_t pci_addr,
 		  size_t req_size)
 {
-    return xtalk_piomap_addr(pcibr_piomap->bp_xtalk_pio,
+    caddr_t	addr;
+    addr = xtalk_piomap_addr(pcibr_piomap->bp_xtalk_pio,
 			     pcibr_piomap->bp_xtalk_addr +
 			     pci_addr - pcibr_piomap->bp_pciaddr,
 			     req_size);
+    PCIBR_DEBUG((PCIBR_DEBUG_PIOMAP, pcibr_piomap->bp_dev,
+                "pcibr_piomap_free: map=0x%x, addr=0x%x\n", 
+		pcibr_piomap, addr));
+
+    return(addr);
 }
 
 /*ARGSUSED */
 void
 pcibr_piomap_done(pcibr_piomap_t pcibr_piomap)
 {
+    PCIBR_DEBUG((PCIBR_DEBUG_PIOMAP, pcibr_piomap->bp_dev,
+		"pcibr_piomap_done: map=0x%x\n", pcibr_piomap));
     xtalk_piomap_done(pcibr_piomap->bp_xtalk_pio);
 }
 
@@ -2487,26 +2875,34 @@
 		    unsigned flags)
 {
     pciio_info_t            pciio_info = pciio_info_get(pconn_vhdl);
-    pciio_slot_t            pciio_slot = pciio_info_slot_get(pciio_info);
+    pciio_slot_t            pciio_slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
     pcibr_soft_t            pcibr_soft = (pcibr_soft_t) pciio_info_mfast_get(pciio_info);
     devfs_handle_t            xconn_vhdl = pcibr_soft->bs_conn;
 
     iopaddr_t               xio_addr;
+    caddr_t		    addr;
 
     xio_addr = pcibr_addr_pci_to_xio(pconn_vhdl, pciio_slot, space, pci_addr, req_size, flags);
 
-    if (xio_addr == XIO_NOWHERE)
+    if (xio_addr == XIO_NOWHERE) {
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_PIODIR, pconn_vhdl,
+		    "pcibr_piotrans_addr: xio_addr == XIO_NOWHERE\n"));
 	return NULL;
+    }
 
-    return xtalk_piotrans_addr(xconn_vhdl, 0, xio_addr, req_size, flags & PIOMAP_FLAGS);
+    addr = xtalk_piotrans_addr(xconn_vhdl, 0, xio_addr, req_size, flags & PIOMAP_FLAGS);
+    PCIBR_DEBUG((PCIBR_DEBUG_PIODIR, pconn_vhdl,
+		"pcibr_piotrans_addr: xio_addr=0x%x, addr=0x%x\n",
+		xio_addr, addr));
+    return(addr);
 }
 
 /*
  * PIO Space allocation and management.
  *      Allocate and Manage the PCI PIO space (mem and io space)
  *      This routine is pretty simplistic at this time, and
- *      does pretty trivial management of allocation and freeing..
- *      The current scheme is prone for fragmentation..
+ *      does pretty trivial management of allocation and freeing.
+ *      The current scheme is prone for fragmentation.
  *      Change the scheme to use bitmaps.
  */
 
@@ -2525,7 +2921,6 @@
     pciio_piospace_t        piosp;
     unsigned long           s;
 
-    iopaddr_t              *pciaddr, *pcilast;
     iopaddr_t               start_addr;
     size_t                  align_mask;
 
@@ -2559,38 +2954,43 @@
     }
     ASSERT(!piosp);
 
+    /*
+     * Allocate PCI bus address, usually for the Universe chip driver;
+     * do not pass window info since the actual PCI bus address
+     * space will never be freed.  The space may be reused after it
+     * is logically released by pcibr_piospace_free().
+     */
     switch (space) {
     case PCIIO_SPACE_IO:
-	pciaddr = &pcibr_soft->bs_spinfo.pci_io_base;
-	pcilast = &pcibr_soft->bs_spinfo.pci_io_last;
+        start_addr = pcibr_bus_addr_alloc(pcibr_soft, NULL,
+                                          PCIIO_SPACE_IO,
+                                          0, req_size, alignment);
 	break;
+
     case PCIIO_SPACE_MEM:
     case PCIIO_SPACE_MEM32:
-	pciaddr = &pcibr_soft->bs_spinfo.pci_mem_base;
-	pcilast = &pcibr_soft->bs_spinfo.pci_mem_last;
+        start_addr = pcibr_bus_addr_alloc(pcibr_soft, NULL,
+                                          PCIIO_SPACE_MEM32,
+                                          0, req_size, alignment);
 	break;
+
     default:
 	ASSERT(0);
 	pcibr_unlock(pcibr_soft, s);
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_PIOMAP, pconn_vhdl,
+		    "pcibr_piospace_alloc: unknown space %d\n", space));
 	return 0;
     }
 
-    start_addr = *pciaddr;
-
     /*
-     * Align start_addr.
+     * If too big a request, reject it.
      */
-    if (start_addr & align_mask)
-	start_addr = (start_addr + align_mask) & ~align_mask;
-
-    if ((start_addr + req_size) > *pcilast) {
-	/*
-	 * If too big a request, reject it.
-	 */
+    if (!start_addr) {
 	pcibr_unlock(pcibr_soft, s);
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_PIOMAP, pconn_vhdl,
+		    "pcibr_piospace_alloc: request 0x%x to big\n", req_size));
 	return 0;
     }
-    *pciaddr = (start_addr + req_size);
 
     NEW(piosp);
     piosp->free = 0;
@@ -2601,6 +3001,10 @@
     pcibr_info->f_piospace = piosp;
 
     pcibr_unlock(pcibr_soft, s);
+
+    PCIBR_DEBUG((PCIBR_DEBUG_PIOMAP, pconn_vhdl,
+		"pcibr_piospace_alloc: piosp=0x%x\n", piosp));
+
     return start_addr;
 }
 
@@ -2612,7 +3016,9 @@
 		    size_t req_size)
 {
     pcibr_info_t            pcibr_info = pcibr_info_get(pconn_vhdl);
+#ifdef PIC_LATER
     pcibr_soft_t            pcibr_soft = (pcibr_soft_t) pcibr_info->f_mfast;
+#endif
 
     pciio_piospace_t        piosp;
     unsigned long           s;
@@ -2655,6 +3061,9 @@
     }
     piosp->free = 1;
     pcibr_unlock(pcibr_soft, s);
+
+    PCIBR_DEBUG((PCIBR_DEBUG_PIOMAP, pconn_vhdl,
+		"pcibr_piospace_free: piosp=0x%x\n", piosp));
     return;
 }
 
@@ -2713,7 +3122,7 @@
 	attributes &= ~PCI64_ATTR_PREF;
 
     /* the swap bit is in the address attributes for xbridge */
-    if (pcibr_soft->bs_xbridge) {
+    if (IS_XBRIDGE_OR_PIC_SOFT(pcibr_soft)) {
     	if (flags & PCIIO_BYTE_STREAM)
         	attributes |= PCI64_ATTR_SWAP;
     	if (flags & PCIIO_WORD_VALUES)
@@ -2742,6 +3151,11 @@
     if (flags & PCIBR_VCHAN0)
 	attributes &= ~PCI64_ATTR_VIRTUAL;
 
+    /* PIC in PCI-X mode only supports barrier & swap */
+    if (IS_PCIX(pcibr_soft)) {
+	attributes &= (PCI64_ATTR_BAR | PCI64_ATTR_SWAP);
+    }
+
     return (attributes);
 }
 
@@ -2762,6 +3176,7 @@
     pcibr_dmamap_t          pcibr_dmamap;
     int                     ate_count;
     int                     ate_index;
+    int			    vchan = VCHAN0;
 
     /* merge in forced flags */
     flags |= pcibr_soft->bs_dma_flags;
@@ -2778,17 +3193,16 @@
     xtalk_dmamap = xtalk_dmamap_alloc(xconn_vhdl, dev_desc, req_size_max,
 				      flags & DMAMAP_FLAGS);
     if (!xtalk_dmamap) {
-#if PCIBR_ATE_DEBUG
-	printk("pcibr_attach: xtalk_dmamap_alloc failed\n");
-#endif
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DMAMAP, pconn_vhdl,
+		    "pcibr_dmamap_alloc: xtalk_dmamap_alloc failed\n"));
 	free_pciio_dmamap(pcibr_dmamap);
 	return 0;
     }
     xio_port = pcibr_soft->bs_mxid;
-    slot = pciio_info_slot_get(pciio_info);
+    slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
 
     pcibr_dmamap->bd_dev = pconn_vhdl;
-    pcibr_dmamap->bd_slot = slot;
+    pcibr_dmamap->bd_slot = PCIBR_DEVICE_TO_SLOT(pcibr_soft, slot);
     pcibr_dmamap->bd_soft = pcibr_soft;
     pcibr_dmamap->bd_xtalk = xtalk_dmamap;
     pcibr_dmamap->bd_max_size = req_size_max;
@@ -2812,29 +3226,37 @@
 	    pcibr_dmamap->bd_xio_addr = 0;
 	    pcibr_dmamap->bd_pci_addr = pci_addr;
 
-	    /* Make sure we have an RRB (or two).
+	    /* If in PCI mode, make sure we have an RRB (or two). 
 	     */
-	    if (!(pcibr_soft->bs_rrb_fixed & (1 << slot))) {
+	    if (IS_PCI(pcibr_soft) && 
+		!(pcibr_soft->bs_rrb_fixed & (1 << slot))) {
 		if (flags & PCIBR_VCHAN1)
-		    slot += PCIBR_RRB_SLOT_VIRTUAL;
-		have_rrbs = pcibr_soft->bs_rrb_valid[slot];
+		    vchan = VCHAN1;
+		have_rrbs = pcibr_soft->bs_rrb_valid[slot][vchan];
 		if (have_rrbs < 2) {
 		    if (pci_addr & PCI64_ATTR_PREF)
 			min_rrbs = 2;
 		    else
 			min_rrbs = 1;
 		    if (have_rrbs < min_rrbs)
-			do_pcibr_rrb_autoalloc(pcibr_soft, slot, min_rrbs - have_rrbs);
+			do_pcibr_rrb_autoalloc(pcibr_soft, slot, vchan,
+					       min_rrbs - have_rrbs);
 		}
 	    }
-#if PCIBR_ATE_DEBUG
-	    printk("pcibr_dmamap_alloc: using direct64\n");
-#endif
+	    PCIBR_DEBUG((PCIBR_DEBUG_DMAMAP | PCIBR_DEBUG_DMADIR, pconn_vhdl,
+		 	"pcibr_dmamap_alloc: using direct64, map=0x%x\n",
+			pcibr_dmamap));
 	    return pcibr_dmamap;
 	}
-#if PCIBR_ATE_DEBUG
-	printk("pcibr_dmamap_alloc: unable to use direct64\n");
-#endif
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DMAMAP | PCIBR_DEBUG_DMADIR, pconn_vhdl,
+		    "pcibr_dmamap_alloc: unable to use direct64\n"));
+
+	/* PIC only supports 64-bit direct mapping in PCI-X mode. */
+	if (IS_PCIX(pcibr_soft)) {
+	    DEL(pcibr_dmamap);
+	    return 0;
+	}
+
 	flags &= ~PCIIO_DMA_A64;
     }
     if (flags & PCIIO_FIXED) {
@@ -2849,17 +3271,17 @@
 	     * Mapping calls may fail if target
 	     * is outside the direct32 range.
 	     */
-#if PCIBR_ATE_DEBUG
-	    printk("pcibr_dmamap_alloc: using direct32\n");
-#endif
+	    PCIBR_DEBUG((PCIBR_DEBUG_DMAMAP | PCIBR_DEBUG_DMADIR, pconn_vhdl,
+			"pcibr_dmamap_alloc: using direct32, map=0x%x\n", 
+			pcibr_dmamap));
 	    pcibr_dmamap->bd_flags = flags;
 	    pcibr_dmamap->bd_xio_addr = pcibr_soft->bs_dir_xbase;
 	    pcibr_dmamap->bd_pci_addr = PCI32_DIRECT_BASE;
 	    return pcibr_dmamap;
 	}
-#if PCIBR_ATE_DEBUG
-	printk("pcibr_dmamap_alloc: unable to use direct32\n");
-#endif
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DMAMAP | PCIBR_DEBUG_DMADIR, pconn_vhdl,
+		    "pcibr_dmamap_alloc: unable to use direct32\n"));
+
 	/* If the user demands FIXED and we can't
 	 * give it to him, fail.
 	 */
@@ -2892,9 +3314,9 @@
 	    int                     have_rrbs;
 	    int                     min_rrbs;
 
-#if PCIBR_ATE_DEBUG
-	    printk("pcibr_dmamap_alloc: using PMU\n");
-#endif
+	    PCIBR_DEBUG((PCIBR_DEBUG_DMAMAP, pconn_vhdl,
+			"pcibr_dmamap_alloc: using PMU, ate_index=%d, "
+			"pcibr_dmamap=0x%x\n", ate_index, pcibr_dmamap));
 
 	    ate_proto = pcibr_flags_to_ate(flags);
 
@@ -2904,7 +3326,7 @@
 	    /*
 	     * for xbridge the byte-swap bit == bit 29 of PCI address
 	     */
-	    if (pcibr_soft->bs_xbridge) {
+	    if (IS_XBRIDGE_OR_PIC_SOFT(pcibr_soft)) {
 		    if (flags & PCIIO_BYTE_STREAM)
 			    ATE_SWAP_ON(pcibr_dmamap->bd_pci_addr);
 		    /*
@@ -2926,18 +3348,19 @@
 	    /* Make sure we have an RRB (or two).
 	     */
 	    if (!(pcibr_soft->bs_rrb_fixed & (1 << slot))) {
-		have_rrbs = pcibr_soft->bs_rrb_valid[slot];
+		have_rrbs = pcibr_soft->bs_rrb_valid[slot][vchan];
 		if (have_rrbs < 2) {
 		    if (ate_proto & ATE_PREF)
 			min_rrbs = 2;
 		    else
 			min_rrbs = 1;
 		    if (have_rrbs < min_rrbs)
-			do_pcibr_rrb_autoalloc(pcibr_soft, slot, min_rrbs - have_rrbs);
+			do_pcibr_rrb_autoalloc(pcibr_soft, slot, vchan,
+					       min_rrbs - have_rrbs);
 		}
 	    }
 	    if (ate_index >= pcibr_soft->bs_int_ate_size && 
-				!pcibr_soft->bs_xbridge) {
+				!IS_XBRIDGE_OR_PIC_SOFT(pcibr_soft)) {
 		bridge_t               *bridge = pcibr_soft->bs_base;
 		volatile unsigned      *cmd_regp;
 		unsigned                cmd_reg;
@@ -2946,27 +3369,35 @@
 		pcibr_dmamap->bd_flags |= PCIBR_DMAMAP_SSRAM;
 
 		s = pcibr_lock(pcibr_soft);
-		cmd_regp = &(bridge->
-			     b_type0_cfg_dev[slot].
-			     l[PCI_CFG_COMMAND / 4]);
-		cmd_reg = *cmd_regp;
+		cmd_regp = pcibr_slot_config_addr(bridge, slot, 
+						PCI_CFG_COMMAND/4);
+		if ( IS_PIC_SOFT(pcibr_soft) ) {
+			cmd_reg = pcibr_slot_config_get(bridge, slot, PCI_CFG_COMMAND/4);
+		}
+		else {
+			if (io_get_sh_swapper(NASID_GET(bridge))) {
+				BRIDGE_REG_SET32((&cmd_reg)) = __swab32(*cmd_regp);
+			} else {
+				cmd_reg = pcibr_slot_config_get(bridge, slot, PCI_CFG_COMMAND/4);
+			}
+		}
 		pcibr_soft->bs_slot[slot].bss_cmd_pointer = cmd_regp;
 		pcibr_soft->bs_slot[slot].bss_cmd_shadow = cmd_reg;
 		pcibr_unlock(pcibr_soft, s);
 	    }
 	    return pcibr_dmamap;
 	}
-#if PCIBR_ATE_DEBUG
-	printk("pcibr_dmamap_alloc: unable to use PMU\n");
-#endif
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DMAMAP, pconn_vhdl,
+		    "pcibr_dmamap_alloc: PMU use failed, ate_index=%d\n",
+		    ate_index));
+
 	pcibr_ate_free(pcibr_soft, ate_index, ate_count);
     }
     /* total failure: sorry, you just can't
      * get from here to there that way.
      */
-#if PCIBR_ATE_DEBUG
-    printk("pcibr_dmamap_alloc: complete failure.\n");
-#endif
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DMAMAP, pconn_vhdl,
+		"pcibr_dmamap_alloc: complete failure.\n"));
     xtalk_dmamap_free(xtalk_dmamap);
     free_pciio_dmamap(pcibr_dmamap);
     return 0;
@@ -2977,7 +3408,8 @@
 pcibr_dmamap_free(pcibr_dmamap_t pcibr_dmamap)
 {
     pcibr_soft_t            pcibr_soft = pcibr_dmamap->bd_soft;
-    pciio_slot_t            slot = pcibr_dmamap->bd_slot;
+    pciio_slot_t            slot = PCIBR_SLOT_TO_DEVICE(pcibr_soft,
+							pcibr_dmamap->bd_slot);
 
     unsigned                flags = pcibr_dmamap->bd_flags;
 
@@ -3001,6 +3433,9 @@
 	pcibr_release_device(pcibr_soft, slot, BRIDGE_DEV_PMU_BITS);
     }
 
+    PCIBR_DEBUG((PCIBR_DEBUG_DMAMAP, pcibr_dmamap->bd_dev,
+		"pcibr_dmamap_free: pcibr_dmamap=0x%x\n", pcibr_dmamap));
+
     free_pciio_dmamap(pcibr_dmamap);
 }
 
@@ -3029,15 +3464,15 @@
 	pci_addr = xio_addr - BRIDGE_PCI_MEM64_BASE;
 	return pci_addr;
     }
-    for (slot = 0; slot < 8; ++slot)
-	if ((xio_addr >= BRIDGE_DEVIO(slot)) &&
-	    (xio_lim < BRIDGE_DEVIO(slot + 1))) {
+    for (slot = soft->bs_min_slot; slot < PCIBR_NUM_SLOTS(soft); ++slot)
+	if ((xio_addr >= PCIBR_BRIDGE_DEVIO(soft, slot)) &&
+	    (xio_lim < PCIBR_BRIDGE_DEVIO(soft, slot + 1))) {
 	    bridgereg_t             dev;
 
 	    dev = soft->bs_slot[slot].bss_device;
 	    pci_addr = dev & BRIDGE_DEV_OFF_MASK;
 	    pci_addr <<= BRIDGE_DEV_OFF_ADDR_SHFT;
-	    pci_addr += xio_addr - BRIDGE_DEVIO(slot);
+	    pci_addr += xio_addr - PCIBR_BRIDGE_DEVIO(soft, slot);
 	    return (dev & BRIDGE_DEV_DEV_IO_MEM) ? pci_addr : PCI_NOWHERE;
 	}
     return 0;
@@ -3070,7 +3505,7 @@
     } else
 	xio_port = pcibr_dmamap->bd_xio_port;
 
-    /* If this DMA is to an address that
+    /* If this DMA is to an addres that
      * refers back to this Bridge chip,
      * reduce it back to the correct
      * PCI MEM address.
@@ -3099,14 +3534,12 @@
 	if (flags & PCIBR_NOPREFETCH)
 	    pci_addr &= ~PCI64_ATTR_PREF;
 
-#if DEBUG && PCIBR_DMA_DEBUG
-	printk("pcibr_dmamap_addr (direct64):\n"
-		"\twanted paddr [0x%x..0x%x]\n"
-		"\tXIO port 0x%x offset 0x%x\n"
-		"\treturning PCI 0x%x\n",
-		paddr, paddr + req_size - 1,
-		xio_port, xio_addr, pci_addr);
-#endif
+	PCIBR_DEBUG((PCIBR_DEBUG_DMAMAP | PCIBR_DEBUG_DMADIR, 
+		    pcibr_dmamap->bd_dev,
+		    "pcibr_dmamap_addr: (direct64): wanted paddr [0x%x..0x%x] "
+		    "XIO port 0x%x offset 0x%x, returning PCI 0x%x\n",
+		    paddr, paddr + req_size - 1, xio_port, xio_addr, pci_addr));
+
     } else if (flags & PCIIO_FIXED) {
 	/* A32 direct DMA:
 	 * always use 32-bit direct mapping,
@@ -3126,14 +3559,12 @@
 	    pci_addr = pcibr_dmamap->bd_pci_addr +
 		xio_addr - pcibr_dmamap->bd_xio_addr;
 
-#if DEBUG && PCIBR_DMA_DEBUG
-	printk("pcibr_dmamap_addr (direct32):\n"
-		"\twanted paddr [0x%x..0x%x]\n"
-		"\tXIO port 0x%x offset 0x%x\n"
-		"\treturning PCI 0x%x\n",
-		paddr, paddr + req_size - 1,
-		xio_port, xio_addr, pci_addr);
-#endif
+	PCIBR_DEBUG((PCIBR_DEBUG_DMAMAP | PCIBR_DEBUG_DMADIR, 
+		    pcibr_dmamap->bd_dev,
+		    "pcibr_dmamap_addr (direct32): wanted paddr [0x%x..0x%x] "
+		    "XIO port 0x%x offset 0x%x, returning PCI 0x%x\n",
+		    paddr, paddr + req_size - 1, xio_port, xio_addr, pci_addr));
+
     } else {
 	bridge_t               *bridge = pcibr_soft->bs_base;
 	iopaddr_t               offset = IOPGOFF(xio_addr);
@@ -3148,14 +3579,6 @@
 	int                     ate_total = ate_count;
 	unsigned                freeze_time;
 #endif
-
-#if PCIBR_ATE_DEBUG
-	bridge_ate_t            ate_cmp;
-	bridge_ate_p            ate_cptr;
-	unsigned                ate_lo, ate_hi;
-	int                     ate_bad = 0;
-	int                     ate_rbc = 0;
-#endif
 	bridge_ate_p            ate_ptr = pcibr_dmamap->bd_ate_ptr;
 	bridge_ate_t            ate;
 
@@ -3183,7 +3606,21 @@
 		ATE_FREEZE();
 		ATE_WRITE();
 		ATE_THAW();
-		bridge->b_wid_tflush;	/* wait until Bridge PIO complete */
+		if ( IS_PIC_SOFT(pcibr_soft) ) {
+			bridge->b_wid_tflush;	/* wait until Bridge PIO complete */
+		}
+		else {
+			if (io_get_sh_swapper(NASID_GET(bridge))) {
+				BRIDGE_REG_GET32((&bridge->b_wid_tflush));
+			} else {
+				bridge->b_wid_tflush;
+			}
+		}
+		PCIBR_DEBUG((PCIBR_DEBUG_DMAMAP, pcibr_dmamap->bd_dev,
+			    "pcibr_dmamap_addr (PMU) : wanted paddr "
+			    "[0x%x..0x%x] returning PCI 0x%x\n", 
+			    paddr, paddr + req_size - 1, pci_addr));
+
 	} else {
 		/* The number of ATE's required is greater than the number
 		 * allocated for this map. One way this can happen is if
@@ -3193,14 +3630,12 @@
 		 * The other possibility is that the map is just plain too
 		 * small to handle the requested target area.
 		 */
-#if PCIBR_ATE_DEBUG
-		printk(KERN_WARNING "pcibr_dmamap_addr :\n"
-			"\twanted paddr [0x%x..0x%x]\n"
-			"\tate_count 0x%x bd_ate_count 0x%x\n"
-			"\tATE's required > number allocated\n",
-			paddr, paddr + req_size - 1,
-			ate_count, pcibr_dmamap->bd_ate_count);
-#endif
+		PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DMAMAP, pcibr_dmamap->bd_dev, 
+		            "pcibr_dmamap_addr (PMU) : wanted paddr "
+			    "[0x%x..0x%x] ate_count 0x%x bd_ate_count 0x%x "
+			    "ATE's required > number allocated\n",
+			     paddr, paddr + req_size - 1,
+			     ate_count, pcibr_dmamap->bd_ate_count));
 		pci_addr = 0;
 	}
 
@@ -3250,17 +3685,24 @@
 
     xtalk_alenlist = xtalk_dmamap_list(pcibr_dmamap->bd_xtalk, palenlist,
 				       flags & DMAMAP_FLAGS);
-    if (!xtalk_alenlist)
+    if (!xtalk_alenlist) {
+        PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DMAMAP, pcibr_dmamap->bd_dev,
+                    "pcibr_dmamap_list: xtalk_dmamap_list() failed, "
+		    "pcibr_dmamap=0x%x\n", pcibr_dmamap));
 	goto fail;
-
+    }
     alenlist_cursor_init(xtalk_alenlist, 0, NULL);
 
     if (inplace) {
 	pciio_alenlist = xtalk_alenlist;
     } else {
 	pciio_alenlist = alenlist_create(al_flags);
-	if (!pciio_alenlist)
+	if (!pciio_alenlist) {
+	    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DMAMAP, pcibr_dmamap->bd_dev,
+			"pcibr_dmamap_list: alenlist_create() failed, "
+			"pcibr_dmamap=0x%lx\n", (unsigned long)pcibr_dmamap));
 	    goto fail;
+	}
     }
 
     direct64 = pcibr_dmamap->bd_flags & PCIIO_DMA_A64;
@@ -3286,8 +3728,12 @@
 
 	if (xio_port == pcibr_soft->bs_xid) {
 	    new_addr = pcibr_addr_xio_to_pci(pcibr_soft, xio_addr, length);
-	    if (new_addr == PCI_NOWHERE)
+	    if (new_addr == PCI_NOWHERE) {
+                PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DMAMAP, pcibr_dmamap->bd_dev,
+                            "pcibr_dmamap_list: pcibr_addr_xio_to_pci failed, "
+                            "pcibr_dmamap=0x%x\n", pcibr_dmamap));
 		goto fail;
+	    }
 	} else if (direct64) {
 	    new_addr = pci_addr | xio_addr
 		| ((uint64_t) xio_port << PCI64_ATTR_TARG_SHFT);
@@ -3318,9 +3764,8 @@
 		| (xio_port << ATE_TIDSHIFT)
 		| (xio_addr - offset);
 	    if (ate == ate_prev) {
-#if PCIBR_ATE_DEBUG
-		printk("pcibr_dmamap_list: ATE share\n");
-#endif
+		PCIBR_DEBUG((PCIBR_DEBUG_ATE, pcibr_dmamap->bd_dev,
+			    "pcibr_dmamap_list: ATE share\n"));
 		ate_ptr--;
 		ate_index--;
 		pci_addr -= IOPGSIZE;
@@ -3335,14 +3780,13 @@
 
 	    /* Ensure that this map contains enough ATE's */
 	    if (ate_total > pcibr_dmamap->bd_ate_count) {
-#if PCIBR_ATE_DEBUG
-		printk(KERN_WARNING "pcibr_dmamap_list :\n"
-			"\twanted xio_addr [0x%x..0x%x]\n"
-			"\tate_total 0x%x bd_ate_count 0x%x\n"
-			"\tATE's required > number allocated\n",
-			xio_addr, xio_addr + length - 1,
-			ate_total, pcibr_dmamap->bd_ate_count);
-#endif
+		PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ATE, pcibr_dmamap->bd_dev,
+			     "pcibr_dmamap_list :\n"
+			     "\twanted xio_addr [0x%x..0x%x]\n"
+			     "\tate_total 0x%x bd_ate_count 0x%x\n"
+			     "\tATE's required > number allocated\n",
+			     xio_addr, xio_addr + length - 1,
+			     ate_total, pcibr_dmamap->bd_ate_count));
 		goto fail;
 	    }
 
@@ -3362,13 +3806,22 @@
 	if (inplace) {
 	    if (ALENLIST_SUCCESS !=
 		alenlist_replace(pciio_alenlist, NULL,
-				 &new_addr, &length, al_flags))
+				 &new_addr, &length, al_flags)) {
+                PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DMAMAP, pcibr_dmamap->bd_dev,
+                            "pcibr_dmamap_list: alenlist_replace() failed, "
+                            "pcibr_dmamap=0x%x\n", pcibr_dmamap));
+
 		goto fail;
+	    }
 	} else {
 	    if (ALENLIST_SUCCESS !=
 		alenlist_append(pciio_alenlist,
-				new_addr, length, al_flags))
+				new_addr, length, al_flags)) {
+                PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DMAMAP, pcibr_dmamap->bd_dev,
+                            "pcibr_dmamap_list: alenlist_append() failed, "
+                            "pcibr_dmamap=0x%x\n", pcibr_dmamap));
 		goto fail;
+	    }
 	}
     }
     if (!inplace)
@@ -3386,8 +3839,21 @@
      */
     if (ate_freeze_done) {
 	ATE_THAW();
-	bridge->b_wid_tflush;		/* wait until Bridge PIO complete */
+	if ( IS_PIC_SOFT(pcibr_soft) ) {
+		bridge->b_wid_tflush;		/* wait until Bridge PIO complete */
+	}
+	else {
+		if (io_get_sh_swapper(NASID_GET(bridge))) {
+			BRIDGE_REG_GET32((&bridge->b_wid_tflush));
+		} else {
+			bridge->b_wid_tflush;
+		}
+	}
     }
+    PCIBR_DEBUG((PCIBR_DEBUG_DMAMAP, pcibr_dmamap->bd_dev,
+		"pcibr_dmamap_list: pcibr_dmamap=0x%x, pciio_alenlist=0x%x\n",
+		pcibr_dmamap, pciio_alenlist));
+
     return pciio_alenlist;
 
   fail:
@@ -3398,7 +3864,16 @@
      */
     if (ate_freeze_done) {
 	ATE_THAW();
-	bridge->b_wid_tflush;
+	if ( IS_PIC_SOFT(pcibr_soft) ) {
+		bridge->b_wid_tflush;
+	}
+	else {
+		if (io_get_sh_swapper(NASID_GET(bridge))) {
+			BRIDGE_REG_GET32((&bridge->b_wid_tflush));
+		} else {
+			bridge->b_wid_tflush;
+		}
+	}
     }
     if (pciio_alenlist && !inplace)
 	alenlist_destroy(pciio_alenlist);
@@ -3409,6 +3884,10 @@
 void
 pcibr_dmamap_done(pcibr_dmamap_t pcibr_dmamap)
 {
+#ifdef PIC_LATER
+    pcibr_soft_t            pcibr_soft = pcibr_dmamap->bd_soft;
+    pciio_slot_t            slot = PCIBR_SLOT_TO_DEVICE(pcibr_soft,
+#endif
     /*
      * We could go through and invalidate ATEs here;
      * for performance reasons, we don't.
@@ -3423,6 +3902,9 @@
 	    atomic_dec(&(pcibr_dmamap->bd_soft->bs_slot[pcibr_dmamap->bd_slot]. bss_ext_ates_active));
     }
     xtalk_dmamap_done(pcibr_dmamap->bd_xtalk);
+
+    PCIBR_DEBUG((PCIBR_DEBUG_DMAMAP, pcibr_dmamap->bd_dev,
+		"pcibr_dmamap_done: pcibr_dmamap=0x%x\n", pcibr_dmamap));
 }
 
 
@@ -3455,7 +3937,7 @@
     pciio_info_t            pciio_info = pciio_info_get(pconn_vhdl);
     pcibr_soft_t            pcibr_soft = (pcibr_soft_t) pciio_info_mfast_get(pciio_info);
     devfs_handle_t            xconn_vhdl = pcibr_soft->bs_conn;
-    pciio_slot_t            pciio_slot = pciio_info_slot_get(pciio_info);
+    pciio_slot_t            pciio_slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
     pcibr_soft_slot_t       slotp = &pcibr_soft->bs_slot[pciio_slot];
 
     xwidgetnum_t            xio_port;
@@ -3464,24 +3946,18 @@
 
     int                     have_rrbs;
     int                     min_rrbs;
+    int			    vchan = VCHAN0;
 
     /* merge in forced flags */
     flags |= pcibr_soft->bs_dma_flags;
 
     xio_addr = xtalk_dmatrans_addr(xconn_vhdl, 0, paddr, req_size,
 				   flags & DMAMAP_FLAGS);
-
     if (!xio_addr) {
-#if PCIBR_DMA_DEBUG
-	printk("pcibr_dmatrans_addr:\n"
-		"\tpciio connection point %v\n"
-		"\txtalk connection point %v\n"
-		"\twanted paddr [0x%x..0x%x]\n"
-		"\txtalk_dmatrans_addr returned 0x%x\n",
-		pconn_vhdl, xconn_vhdl,
-		paddr, paddr + req_size - 1,
-		xio_addr);
-#endif
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+		    "pcibr_dmatrans_addr: wanted paddr [0x%x..0x%x], "
+		    "xtalk_dmatrans_addr failed with 0x%x\n",
+		    paddr, paddr + req_size - 1, xio_addr));
 	return 0;
     }
     /*
@@ -3489,16 +3965,10 @@
      */
     if (XIO_PACKED(xio_addr)) {
 	if (xio_addr == XIO_NOWHERE) {
-#if PCIBR_DMA_DEBUG
-	    printk("pcibr_dmatrans_addr:\n"
-		    "\tpciio connection point %v\n"
-		    "\txtalk connection point %v\n"
-		    "\twanted paddr [0x%x..0x%x]\n"
-		    "\txtalk_dmatrans_addr returned 0x%x\n",
-		    pconn_vhdl, xconn_vhdl,
-		    paddr, paddr + req_size - 1,
-		    xio_addr);
-#endif
+	    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+		        "pcibr_dmatrans_addr: wanted paddr [0x%x..0x%x], "
+		        "xtalk_dmatrans_addr failed with XIO_NOWHERE\n",
+		        paddr, paddr + req_size - 1));
 	    return 0;
 	}
 	xio_port = XIO_PORT(xio_addr);
@@ -3516,6 +3986,10 @@
      */
     if (xio_port == pcibr_soft->bs_xid) {
 	pci_addr = pcibr_addr_xio_to_pci(pcibr_soft, xio_addr, req_size);
+        PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+		    "pcibr_dmatrans_addr:  wanted paddr [0x%x..0x%x], "
+		    "xio_port=0x%x, pci_addr=0x%x\n",
+		    paddr, paddr + req_size - 1, xio_port, pci_addr));
 	return pci_addr;
     }
     /* If the caller can use A64, try to
@@ -3532,82 +4006,65 @@
 	if ((pci_addr != PCIBR_D64_BASE_UNSET) &&
 	    (flags == slotp->bss_d64_flags)) {
 
-	    pci_addr |= xio_addr
+	    pci_addr |=  xio_addr
 		| ((uint64_t) xio_port << PCI64_ATTR_TARG_SHFT);
 
-#if DEBUG && PCIBR_DMA_DEBUG
 #if HWG_PERF_CHECK
 	    if (xio_addr != 0x20000000)
 #endif
-		printk("pcibr_dmatrans_addr: [reuse]\n"
-			"\tpciio connection point %v\n"
-			"\txtalk connection point %v\n"
-			"\twanted paddr [0x%x..0x%x]\n"
-			"\txtalk_dmatrans_addr returned 0x%x\n"
-			"\tdirect 64bit address is 0x%x\n",
-			pconn_vhdl, xconn_vhdl,
-			paddr, paddr + req_size - 1,
-			xio_addr, pci_addr);
-#endif
+		PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+			    "pcibr_dmatrans_addr:  wanted paddr [0x%x..0x%x], "
+			    "xio_port=0x%x, direct64: pci_addr=0x%x\n",
+			    paddr, paddr + req_size - 1, xio_addr, pci_addr));
 	    return (pci_addr);
 	}
 	if (!pcibr_try_set_device(pcibr_soft, pciio_slot, flags, BRIDGE_DEV_D64_BITS)) {
 	    pci_addr = pcibr_flags_to_d64(flags, pcibr_soft);
 	    slotp->bss_d64_flags = flags;
 	    slotp->bss_d64_base = pci_addr;
-	    pci_addr |= xio_addr
+            pci_addr |= xio_addr
 		| ((uint64_t) xio_port << PCI64_ATTR_TARG_SHFT);
 
-	    /* Make sure we have an RRB (or two).
+	    /* If in PCI mode, make sure we have an RRB (or two).
 	     */
-	    if (!(pcibr_soft->bs_rrb_fixed & (1 << pciio_slot))) {
+	    if (IS_PCI(pcibr_soft) && 
+		!(pcibr_soft->bs_rrb_fixed & (1 << pciio_slot))) {
 		if (flags & PCIBR_VCHAN1)
-		    pciio_slot += PCIBR_RRB_SLOT_VIRTUAL;
-		have_rrbs = pcibr_soft->bs_rrb_valid[pciio_slot];
+		    vchan = VCHAN1;
+		have_rrbs = pcibr_soft->bs_rrb_valid[pciio_slot][vchan];
 		if (have_rrbs < 2) {
 		    if (pci_addr & PCI64_ATTR_PREF)
 			min_rrbs = 2;
 		    else
 			min_rrbs = 1;
 		    if (have_rrbs < min_rrbs)
-			do_pcibr_rrb_autoalloc(pcibr_soft, pciio_slot, min_rrbs - have_rrbs);
+			do_pcibr_rrb_autoalloc(pcibr_soft, pciio_slot, vchan,
+					       min_rrbs - have_rrbs);
 		}
 	    }
-#if PCIBR_DMA_DEBUG
 #if HWG_PERF_CHECK
 	    if (xio_addr != 0x20000000)
 #endif
-		printk("pcibr_dmatrans_addr:\n"
-			"\tpciio connection point %v\n"
-			"\txtalk connection point %v\n"
-			"\twanted paddr [0x%x..0x%x]\n"
-			"\txtalk_dmatrans_addr returned 0x%x\n"
-			"\tdirect 64bit address is 0x%x\n"
-			"\tnew flags: 0x%x\n",
-			pconn_vhdl, xconn_vhdl,
-			paddr, paddr + req_size - 1,
-			xio_addr, pci_addr, (uint64_t) flags);
-#endif
+		PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+			    "pcibr_dmatrans_addr:  wanted paddr [0x%x..0x%x], "
+			    "xio_port=0x%x, direct64: pci_addr=0x%x, "
+			    "new flags: 0x%x\n", paddr, paddr + req_size - 1,
+			    xio_addr, pci_addr, (uint64_t) flags));
 	    return (pci_addr);
 	}
-	/* our flags conflict with Device(x).
-	 */
-	flags = flags
-	    & ~PCIIO_DMA_A64
-	    & ~PCIBR_VCHAN0
-	    ;
 
-#if PCIBR_DMA_DEBUG
-	printk("pcibr_dmatrans_addr:\n"
-		"\tpciio connection point %v\n"
-		"\txtalk connection point %v\n"
-		"\twanted paddr [0x%x..0x%x]\n"
-		"\txtalk_dmatrans_addr returned 0x%x\n"
-		"\tUnable to set Device(x) bits for Direct-64\n",
-		pconn_vhdl, xconn_vhdl,
-		paddr, paddr + req_size - 1,
-		xio_addr);
-#endif
+	PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+		    "pcibr_dmatrans_addr:  wanted paddr [0x%x..0x%x], "
+		    "xio_port=0x%x, Unable to set direct64 Device(x) bits\n",
+		    paddr, paddr + req_size - 1, xio_addr));
+
+	/* PIC only supports 64-bit direct mapping in PCI-X mode */
+	if (IS_PCIX(pcibr_soft)) {
+	    return 0;
+	}
+
+	/* our flags conflict with Device(x). try direct32*/
+	flags = flags & ~(PCIIO_DMA_A64 | PCIBR_VCHAN0);
     }
     /* Try to satisfy the request with the 32-bit direct
      * map. This can fail if the configuration bits in
@@ -3624,17 +4081,11 @@
 	    (xio_addr < xio_base) ||
 	    (xio_port != pcibr_soft->bs_dir_xport) ||
 	    (endoff > map_size)) {
-#if PCIBR_DMA_DEBUG
-	    printk("pcibr_dmatrans_addr:\n"
-		    "\tpciio connection point %v\n"
-		    "\txtalk connection point %v\n"
-		    "\twanted paddr [0x%x..0x%x]\n"
-		    "\txtalk_dmatrans_addr returned 0x%x\n"
-		    "\txio region outside direct32 target\n",
-		    pconn_vhdl, xconn_vhdl,
-		    paddr, paddr + req_size - 1,
-		    xio_addr);
-#endif
+
+	    PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+			"pcibr_dmatrans_addr:  wanted paddr [0x%x..0x%x], "
+			"xio_port=0x%x, xio region outside direct32 target\n",
+			paddr, paddr + req_size - 1, xio_addr));
 	} else {
 	    pci_addr = slotp->bss_d32_base;
 	    if ((pci_addr != PCIBR_D32_BASE_UNSET) &&
@@ -3642,18 +4093,11 @@
 
 		pci_addr |= offset;
 
-#if DEBUG && PCIBR_DMA_DEBUG
-		printk("pcibr_dmatrans_addr: [reuse]\n"
-			"\tpciio connection point %v\n"
-			"\txtalk connection point %v\n"
-			"\twanted paddr [0x%x..0x%x]\n"
-			"\txtalk_dmatrans_addr returned 0x%x\n"
-			"\tmapped via direct32 offset 0x%x\n"
-			"\twill DMA via pci addr 0x%x\n",
-			pconn_vhdl, xconn_vhdl,
-			paddr, paddr + req_size - 1,
-			xio_addr, offset, pci_addr);
-#endif
+		PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+                            "pcibr_dmatrans_addr:  wanted paddr [0x%x..0x%x], "
+                            "xio_port=0x%x, direct32: pci_addr=0x%x\n",
+                            paddr, paddr + req_size - 1, xio_addr, pci_addr));
+
 		return (pci_addr);
 	    }
 	    if (!pcibr_try_set_device(pcibr_soft, pciio_slot, flags, BRIDGE_DEV_D32_BITS)) {
@@ -3666,61 +4110,41 @@
 		/* Make sure we have an RRB (or two).
 		 */
 		if (!(pcibr_soft->bs_rrb_fixed & (1 << pciio_slot))) {
-		    have_rrbs = pcibr_soft->bs_rrb_valid[pciio_slot];
+		    have_rrbs = pcibr_soft->bs_rrb_valid[pciio_slot][vchan];
 		    if (have_rrbs < 2) {
 			if (slotp->bss_device & BRIDGE_DEV_PREF)
 			    min_rrbs = 2;
 			else
 			    min_rrbs = 1;
 			if (have_rrbs < min_rrbs)
-			    do_pcibr_rrb_autoalloc(pcibr_soft, pciio_slot, min_rrbs - have_rrbs);
+			    do_pcibr_rrb_autoalloc(pcibr_soft, pciio_slot, 
+						   vchan, min_rrbs - have_rrbs);
 		    }
 		}
-#if PCIBR_DMA_DEBUG
 #if HWG_PERF_CHECK
 		if (xio_addr != 0x20000000)
 #endif
-		    printk("pcibr_dmatrans_addr:\n"
-			    "\tpciio connection point %v\n"
-			    "\txtalk connection point %v\n"
-			    "\twanted paddr [0x%x..0x%x]\n"
-			    "\txtalk_dmatrans_addr returned 0x%x\n"
-			    "\tmapped via direct32 offset 0x%x\n"
-			    "\twill DMA via pci addr 0x%x\n"
-			    "\tnew flags: 0x%x\n",
-			    pconn_vhdl, xconn_vhdl,
-			    paddr, paddr + req_size - 1,
-			    xio_addr, offset, pci_addr, (uint64_t) flags);
-#endif
+                    PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+                            "pcibr_dmatrans_addr:  wanted paddr [0x%x..0x%x], "
+                            "xio_port=0x%x, direct32: pci_addr=0x%x, "
+			    "new flags: 0x%x\n", paddr, paddr + req_size - 1,
+			    xio_addr, pci_addr, (uint64_t) flags));
+
 		return (pci_addr);
 	    }
 	    /* our flags conflict with Device(x).
 	     */
-#if PCIBR_DMA_DEBUG
-	    printk("pcibr_dmatrans_addr:\n"
-		    "\tpciio connection point %v\n"
-		    "\txtalk connection point %v\n"
-		    "\twanted paddr [0x%x..0x%x]\n"
-		    "\txtalk_dmatrans_addr returned 0x%x\n"
-		    "\tUnable to set Device(x) bits for Direct-32\n",
-		    pconn_vhdl, xconn_vhdl,
-		    paddr, paddr + req_size - 1,
-		    xio_addr);
-#endif
+	    PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+                    "pcibr_dmatrans_addr:  wanted paddr [0x%x..0x%x], "
+                    "xio_port=0x%x, Unable to set direct32 Device(x) bits\n",
+                    paddr, paddr + req_size - 1, xio_port));
 	}
     }
 
-#if PCIBR_DMA_DEBUG
-    printk("pcibr_dmatrans_addr:\n"
-	    "\tpciio connection point %v\n"
-	    "\txtalk connection point %v\n"
-	    "\twanted paddr [0x%x..0x%x]\n"
-	    "\txtalk_dmatrans_addr returned 0x%x\n"
-	    "\tno acceptable PCI address found or constructable\n",
-	    pconn_vhdl, xconn_vhdl,
-	    paddr, paddr + req_size - 1,
-	    xio_addr);
-#endif
+    PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+		"pcibr_dmatrans_addr:  wanted paddr [0x%x..0x%x], "
+		"xio_port=0x%x, No acceptable PCI address found\n",
+		paddr, paddr + req_size - 1, xio_port));
 
     return 0;
 }
@@ -3735,7 +4159,7 @@
     pciio_info_t            pciio_info = pciio_info_get(pconn_vhdl);
     pcibr_soft_t            pcibr_soft = (pcibr_soft_t) pciio_info_mfast_get(pciio_info);
     devfs_handle_t            xconn_vhdl = pcibr_soft->bs_conn;
-    pciio_slot_t            pciio_slot = pciio_info_slot_get(pciio_info);
+    pciio_slot_t            pciio_slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
     pcibr_soft_slot_t       slotp = &pcibr_soft->bs_slot[pciio_slot];
     xwidgetnum_t            xio_port;
 
@@ -3772,6 +4196,9 @@
 	    /* reuse previous base info */
 	} else if (pcibr_try_set_device(pcibr_soft, pciio_slot, flags, BRIDGE_DEV_D64_BITS) < 0) {
 	    /* DMA configuration conflict */
+	    PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+			"pcibr_dmatrans_list: DMA configuration conflict "
+			"for direct64, flags=0x%x\n", flags));
 	    goto fail;
 	} else {
 	    relbits = BRIDGE_DEV_D64_BITS;
@@ -3787,6 +4214,9 @@
 	    /* reuse previous base info */
 	} else if (pcibr_try_set_device(pcibr_soft, pciio_slot, flags, BRIDGE_DEV_D32_BITS) < 0) {
 	    /* DMA configuration conflict */
+	    PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+			"pcibr_dmatrans_list: DMA configuration conflict "
+			"for direct32, flags=0x%x\n", flags));
 	    goto fail;
 	} else {
 	    relbits = BRIDGE_DEV_D32_BITS;
@@ -3796,8 +4226,12 @@
 
     xtalk_alenlist = xtalk_dmatrans_list(xconn_vhdl, 0, palenlist,
 					 flags & DMAMAP_FLAGS);
-    if (!xtalk_alenlist)
+    if (!xtalk_alenlist) {
+	    PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+			"pcibr_dmatrans_list: xtalk_dmatrans_list failed "
+			"xtalk_alenlist=0x%x\n", xtalk_alenlist));
 	goto fail;
+    }
 
     alenlist_cursor_init(xtalk_alenlist, 0, NULL);
 
@@ -3805,8 +4239,12 @@
 	pciio_alenlist = xtalk_alenlist;
     } else {
 	pciio_alenlist = alenlist_create(al_flags);
-	if (!pciio_alenlist)
+	if (!pciio_alenlist) {
+	    PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+			"pcibr_dmatrans_list: alenlist_create failed with "
+			" 0x%x\n", pciio_alenlist));
 	    goto fail;
+	}
     }
 
     while (ALENLIST_SUCCESS ==
@@ -3818,16 +4256,8 @@
 	 */
 	if (XIO_PACKED(xio_addr)) {
 	    if (xio_addr == XIO_NOWHERE) {
-#if PCIBR_DMA_DEBUG
-		printk("pcibr_dmatrans_addr:\n"
-			"\tpciio connection point %v\n"
-			"\txtalk connection point %v\n"
-			"\twanted paddr [0x%x..0x%x]\n"
-			"\txtalk_dmatrans_addr returned 0x%x\n",
-			pconn_vhdl, xconn_vhdl,
-			paddr, paddr + req_size - 1,
-			xio_addr);
-#endif
+	        PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+			"pcibr_dmatrans_list: xio_addr == XIO_NOWHERE\n"));
 		return 0;
 	    }
 	    xio_port = XIO_PORT(xio_addr);
@@ -3844,8 +4274,12 @@
 	 */
 	if (xio_port == pcibr_soft->bs_xid) {
 	    pci_addr = pcibr_addr_xio_to_pci(pcibr_soft, xio_addr, xio_size);
-	    if ( (pci_addr == (alenaddr_t)NULL) )
+	    if (pci_addr == (alenaddr_t)NULL) {
+	        PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+			"pcibr_dmatrans_list: pcibr_addr_xio_to_pci failed "
+			"xio_addr=0x%x, xio_size=0x%x\n", xio_addr, xio_size));
 		goto fail;
+	    }
 	} else if (direct64) {
 	    ASSERT(xio_port != 0);
 	    pci_addr = pci_base | xio_addr
@@ -3857,8 +4291,14 @@
 	    if ((xio_size > map_size) ||
 		(xio_addr < xio_base) ||
 		(xio_port != pcibr_soft->bs_dir_xport) ||
-		(endoff > map_size))
+		(endoff > map_size)) {
+		PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+			    "pcibr_dmatrans_list: xio_size > map_size fail\n"
+			    "xio_addr=0x%x, xio_size=0x%x. map_size=0x%x, "
+			    "xio_port=0x%x, endoff=0x%x\n", 
+			    xio_addr, xio_size, map_size, xio_port, endoff));
 		goto fail;
+	    }
 
 	    pci_addr = pci_base + (xio_addr - xio_base);
 	}
@@ -3869,13 +4309,19 @@
 	if (inplace) {
 	    if (ALENLIST_SUCCESS !=
 		alenlist_replace(pciio_alenlist, NULL,
-				 &pci_addr, &xio_size, al_flags))
+				 &pci_addr, &xio_size, al_flags)) {
+		PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+			    "pcibr_dmatrans_list: alenlist_replace failed\n"));
 		goto fail;
+	    }
 	} else {
 	    if (ALENLIST_SUCCESS !=
 		alenlist_append(pciio_alenlist,
-				pci_addr, xio_size, al_flags))
+				pci_addr, xio_size, al_flags)) {
+		PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+			    "pcibr_dmatrans_list: alenlist_append failed\n"));
 		goto fail;
+	    }
 	}
     }
 
@@ -3895,6 +4341,11 @@
      * to the caller.
      */
     alenlist_cursor_init(pciio_alenlist, 0, NULL);
+
+    PCIBR_DEBUG((PCIBR_DEBUG_DMADIR, pconn_vhdl,
+		"pcibr_dmatrans_list: pciio_alenlist=0x%x\n",
+		 pciio_alenlist));
+
     return pciio_alenlist;
 
   fail:
@@ -3964,8 +4415,9 @@
 int
 pcibr_reset(devfs_handle_t conn)
 {
+#ifdef PIC_LATER
     pciio_info_t            pciio_info = pciio_info_get(conn);
-    pciio_slot_t            pciio_slot = pciio_info_slot_get(pciio_info);
+    pciio_slot_t            pciio_slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
     pcibr_soft_t            pcibr_soft = (pcibr_soft_t) pciio_info_mfast_get(pciio_info);
     bridge_t               *bridge = pcibr_soft->bs_base;
     bridgereg_t             ctlreg;
@@ -3975,42 +4427,59 @@
     pcibr_info_h            pcibr_infoh;
     pcibr_info_t            pcibr_info;
     int                     win;
+    int                     error = 0;
+#endif	/* PIC_LATER */
 
+	BUG();
+#ifdef PIC_LATER
     if (pcibr_soft->bs_slot[pciio_slot].has_host) {
 	pciio_slot = pcibr_soft->bs_slot[pciio_slot].host_slot;
 	pcibr_info = pcibr_soft->bs_slot[pciio_slot].bss_infos[0];
     }
-    if (pciio_slot < 4) {
+
+    if ((pciio_slot >= pcibr_soft->bs_first_slot) &&
+        (pciio_slot <= pcibr_soft->bs_last_reset)) {
 	s = pcibr_lock(pcibr_soft);
 	nf = pcibr_soft->bs_slot[pciio_slot].bss_ninfo;
 	pcibr_infoh = pcibr_soft->bs_slot[pciio_slot].bss_infos;
 	for (f = 0; f < nf; ++f)
 	    if (pcibr_infoh[f])
-		cfgctl[f] = bridge->b_type0_cfg_dev[pciio_slot].f[f].l[PCI_CFG_COMMAND / 4];
+		cfgctl[f] = pcibr_func_config_get(bridge, pciio_slot, f,
+							PCI_CFG_COMMAND/4);
+
+        error = iobrick_pci_slot_rst(pcibr_soft->bs_l1sc,
+                             pcibr_widget_to_bus(pcibr_soft->bs_vhdl),
+                             PCIBR_DEVICE_TO_SLOT(pcibr_soft,pciio_slot),
+                             NULL);
 
 	ctlreg = bridge->b_wid_control;
-	bridge->b_wid_control = ctlreg | BRIDGE_CTRL_RST(pciio_slot);
-	/* XXX delay? */
-	bridge->b_wid_control = ctlreg;
-	/* XXX delay? */
+	bridge->b_wid_control = ctlreg & ~BRIDGE_CTRL_RST_PIN(pciio_slot);
+        nano_delay(&ts);
+	bridge->b_wid_control = ctlreg | BRIDGE_CTRL_RST_PIN(pciio_slot);
+        nano_delay(&ts);
 
 	for (f = 0; f < nf; ++f)
 	    if ((pcibr_info = pcibr_infoh[f]))
 		for (win = 0; win < 6; ++win)
 		    if (pcibr_info->f_window[win].w_base != 0)
-			bridge->b_type0_cfg_dev[pciio_slot].f[f].l[PCI_CFG_BASE_ADDR(win) / 4] =
-			    pcibr_info->f_window[win].w_base;
+			pcibr_func_config_set(bridge, pciio_slot, f,
+					PCI_CFG_BASE_ADDR(win) / 4, 
+					pcibr_info->f_window[win].w_base);
 	for (f = 0; f < nf; ++f)
 	    if (pcibr_infoh[f])
-		bridge->b_type0_cfg_dev[pciio_slot].f[f].l[PCI_CFG_COMMAND / 4] = cfgctl[f];
+		pcibr_func_config_set(bridge, pciio_slot, f,
+					PCI_CFG_COMMAND / 4,
+					cfgctl[f]);
 	pcibr_unlock(pcibr_soft, s);
 
+	if (error)
+            return(-1);
+
 	return 0;
     }
-#ifdef SUPPORT_PRINTING_V_FORMAT
-    printk(KERN_WARNING   "%v: pcibr_reset unimplemented for slot %d\n",
-	    conn, pciio_slot);
-#endif
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DETACH, conn,
+    		"pcibr_reset unimplemented for slot %d\n", conn, pciio_slot));
+#endif	/* PIC_LATER */
     return -1;
 }
 
@@ -4020,7 +4489,7 @@
 		 pciio_endian_t desired_end)
 {
     pciio_info_t            pciio_info = pciio_info_get(pconn_vhdl);
-    pciio_slot_t            pciio_slot = pciio_info_slot_get(pciio_info);
+    pciio_slot_t            pciio_slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
     pcibr_soft_t            pcibr_soft = (pcibr_soft_t) pciio_info_mfast_get(pciio_info);
     bridgereg_t             devreg;
     unsigned long           s;
@@ -4044,16 +4513,32 @@
     if (pcibr_soft->bs_slot[pciio_slot].bss_device != devreg) {
 	bridge_t               *bridge = pcibr_soft->bs_base;
 
-	bridge->b_device[pciio_slot].reg = devreg;
-	pcibr_soft->bs_slot[pciio_slot].bss_device = devreg;
-	bridge->b_wid_tflush;		/* wait until Bridge PIO complete */
+	if ( IS_PIC_SOFT(pcibr_soft) ) {
+		bridge->b_device[pciio_slot].reg = devreg;
+		pcibr_soft->bs_slot[pciio_slot].bss_device = devreg;
+		bridge->b_wid_tflush;		/* wait until Bridge PIO complete */
+	}
+	else {
+		if (io_get_sh_swapper(NASID_GET(bridge))) {
+			BRIDGE_REG_SET32((&bridge->b_device[pciio_slot].reg)) = __swab32(devreg);
+			pcibr_soft->bs_slot[pciio_slot].bss_device = devreg;
+			BRIDGE_REG_GET32((&bridge->b_wid_tflush));/* wait until Bridge PIO complete */
+		} else {
+			bridge->b_device[pciio_slot].reg = devreg;
+			pcibr_soft->bs_slot[pciio_slot].bss_device = devreg;
+			bridge->b_wid_tflush;           /* wait until Bridge PIO complete */
+		}
+	}
     }
     pcibr_unlock(pcibr_soft, s);
 
-#if DEBUG && PCIBR_DEV_DEBUG
-    printk("pcibr Device(%d): 0x%p\n", pciio_slot, bridge->b_device[pciio_slot].reg);
+#ifdef PIC_LATER
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DEVREG, pconn_vhdl,
+    		"pcibr_endian_set: Device(%d): %x\n",
+		pciio_slot, devreg, device_bits));
+#else
+    printk("pcibr_endian_set: Device(%d): %x\n", pciio_slot, devreg);
 #endif
-
     return desired_end;
 }
 
@@ -4121,9 +4606,22 @@
     if (pcibr_soft->bs_slot[pciio_slot].bss_device != devreg) {
 	bridge_t               *bridge = pcibr_soft->bs_base;
 
-	bridge->b_device[pciio_slot].reg = devreg;
-	pcibr_soft->bs_slot[pciio_slot].bss_device = devreg;
-	bridge->b_wid_tflush;		/* wait until Bridge PIO complete */
+	if ( IS_PIC_SOFT(pcibr_soft) ) {
+		bridge->b_device[pciio_slot].reg = devreg;
+		pcibr_soft->bs_slot[pciio_slot].bss_device = devreg;
+		bridge->b_wid_tflush;		/* wait until Bridge PIO complete */
+	}
+	else {
+		if (io_get_sh_swapper(NASID_GET(bridge))) {
+			BRIDGE_REG_SET32((&bridge->b_device[pciio_slot].reg)) = __swab32(devreg);
+			pcibr_soft->bs_slot[pciio_slot].bss_device = devreg;
+			BRIDGE_REG_GET32((&bridge->b_wid_tflush));/* wait until Bridge PIO complete */
+		} else {
+			bridge->b_device[pciio_slot].reg = devreg;
+			pcibr_soft->bs_slot[pciio_slot].bss_device = devreg;
+			bridge->b_wid_tflush;           /* wait until Bridge PIO complete */
+		}
+	}
     }
     pcibr_unlock(pcibr_soft, s);
 
@@ -4135,7 +4633,7 @@
 		   pciio_priority_t device_prio)
 {
     pciio_info_t            pciio_info = pciio_info_get(pconn_vhdl);
-    pciio_slot_t            pciio_slot = pciio_info_slot_get(pciio_info);
+    pciio_slot_t            pciio_slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
     pcibr_soft_t            pcibr_soft = (pcibr_soft_t) pciio_info_mfast_get(pciio_info);
 
     (void) pcibr_priority_bits_set(pcibr_soft, pciio_slot, device_prio);
@@ -4159,7 +4657,7 @@
 		       pcibr_device_flags_t flags)
 {
     pciio_info_t            pciio_info = pciio_info_get(pconn_vhdl);
-    pciio_slot_t            pciio_slot = pciio_info_slot_get(pciio_info);
+    pciio_slot_t            pciio_slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
     pcibr_soft_t            pcibr_soft = (pcibr_soft_t) pciio_info_mfast_get(pciio_info);
     bridgereg_t             set = 0;
     bridgereg_t             clr = 0;
@@ -4206,18 +4704,81 @@
 	if (pcibr_soft->bs_slot[pciio_slot].bss_device != devreg) {
 	    bridge_t               *bridge = pcibr_soft->bs_base;
 
-	    bridge->b_device[pciio_slot].reg = devreg;
-	    pcibr_soft->bs_slot[pciio_slot].bss_device = devreg;
-	    bridge->b_wid_tflush;	/* wait until Bridge PIO complete */
+	    if ( IS_PIC_SOFT(pcibr_soft) ) {
+		bridge->b_device[pciio_slot].reg = devreg;
+		pcibr_soft->bs_slot[pciio_slot].bss_device = devreg;
+		bridge->b_wid_tflush;	/* wait until Bridge PIO complete */
+	    }
+	    else {
+		if (io_get_sh_swapper(NASID_GET(bridge))) {
+			BRIDGE_REG_SET32((&bridge->b_device[pciio_slot].reg)) = __swab32(devreg);
+			pcibr_soft->bs_slot[pciio_slot].bss_device = devreg;
+			BRIDGE_REG_GET32((&bridge->b_wid_tflush));/* wait until Bridge PIO complete */
+		} else {
+			bridge->b_device[pciio_slot].reg = devreg;
+			pcibr_soft->bs_slot[pciio_slot].bss_device = devreg;
+			bridge->b_wid_tflush;       /* wait until Bridge PIO complete */
+		}
+	    }
 	}
 	pcibr_unlock(pcibr_soft, s);
-#if DEBUG && PCIBR_DEV_DEBUG
-	printk("pcibr Device(%d): %R\n", pciio_slot, bridge->b_device[pciio_slot].regbridge->b_device[pciio_slot].reg, device_bits);
+#ifdef PIC_LATER
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DEVREG, pconn_vhdl,
+		    "pcibr_device_flags_set: Device(%d): %x\n",
+		    pciio_slot, devreg, device_bits));
+#else
+	printk("pcibr_device_flags_set: Device(%d): %x\n", pciio_slot, devreg);
 #endif
     }
     return (1);
 }
 
+/*
+ * PIC has 16 RBARs per bus; meaning it can have a total of 16 outstanding 
+ * split transactions.  If the functions on the bus have requested a total 
+ * of 16 or less, then we can give them what they requested (ie. 100%). 
+ * Otherwise we have make sure each function can get at least one buffer
+ * and then divide the rest of the buffers up among the functions as ``A 
+ * PERCENTAGE OF WHAT THEY REQUESTED'' (i.e. 0% - 100% of a function's
+ * pcix_type0_status.max_out_split).  This percentage does not include the
+ * one RBAR that all functions get by default.
+ */
+int
+pcibr_pcix_rbars_calc(pcibr_soft_t pcibr_soft)
+{
+    /* 'percent_allowed' is the percentage of requested RBARs that functions
+     * are allowed, ***less the 1 RBAR that all functions get by default***
+     */
+    int percent_allowed; 
+
+    if (pcibr_soft->bs_pcix_num_funcs) {
+	if (pcibr_soft->bs_pcix_num_funcs > NUM_RBAR) {
+	    printk(KERN_WARNING
+		"%lx: Must oversubscribe Read Buffer Attribute Registers"
+		"(RBAR).  Bus has %d RBARs but %d funcs need them.\n",
+		(unsigned long)pcibr_soft->bs_vhdl, NUM_RBAR, pcibr_soft->bs_pcix_num_funcs);
+	    percent_allowed = 0;
+	} else {
+	    percent_allowed = (((NUM_RBAR-pcibr_soft->bs_pcix_num_funcs)*100) /
+		               pcibr_soft->bs_pcix_split_tot);
+
+	    /* +1 to percentage to solve rounding errors that occur because
+	     * we're not doing fractional math. (ie. ((3 * 66%) / 100) = 1)
+	     * but should be "2" if doing true fractional math.  NOTE: Since
+	     * the greatest number of outstanding transactions a function 
+	     * can request is 32, this "+1" will always work (i.e. we won't
+	     * accidentally oversubscribe the RBARs because of this rounding
+	     * of the percentage).
+	     */
+	    percent_allowed=(percent_allowed > 100) ? 100 : percent_allowed+1;
+	}
+    } else {
+	return(ENODEV);
+    }
+
+    return(percent_allowed);
+}
+
 pciio_provider_t        pcibr_provider =
 {
     (pciio_piomap_alloc_f *) pcibr_piomap_alloc,
@@ -4253,17 +4814,17 @@
     (pciio_priority_set_f *) pcibr_priority_set,
     (pciio_config_get_f *) pcibr_config_get,
     (pciio_config_set_f *) pcibr_config_set,
-
-    (pciio_error_devenable_f *) 0,
-    (pciio_error_extract_f *) 0,
-
-#ifdef LATER
+#ifdef PIC_LATER
+    (pciio_error_devenable_f *) pcibr_error_devenable,
+    (pciio_error_extract_f *) pcibr_error_extract,
     (pciio_driver_reg_callback_f *) pcibr_driver_reg_callback,
     (pciio_driver_unreg_callback_f *) pcibr_driver_unreg_callback,
 #else
+    (pciio_error_devenable_f *) 0,
+    (pciio_error_extract_f *) 0,
     (pciio_driver_reg_callback_f *) 0,
     (pciio_driver_unreg_callback_f *) 0,
-#endif
+#endif	/* PIC_LATER */
     (pciio_device_unregister_f 	*) pcibr_device_unregister,
     (pciio_dma_enabled_f		*) pcibr_dma_enabled,
 };
@@ -4276,4 +4837,84 @@
 	
 
     return xtalk_dma_enabled(pcibr_soft->bs_conn);
+}
+
+
+/*
+ * pcibr_debug() is used to print pcibr debug messages to the console.  A
+ * user enables tracing by setting the following global variables:
+ *
+ *    pcibr_debug_mask 	   -Bitmask of what to trace. see pcibr_private.h
+ *    pcibr_debug_module   -Module to trace.  'all' means trace all modules
+ *    pcibr_debug_widget   -Widget to trace. '-1' means trace all widgets
+ *    pcibr_debug_slot	   -Slot to trace.  '-1' means trace all slots
+ *
+ * 'type' is the type of debugging that the current PCIBR_DEBUG macro is
+ * tracing.  'vhdl' (which can be NULL) is the vhdl associated with the
+ * debug statement.  If there is a 'vhdl' associated with this debug
+ * statement, it is parsed to obtain the module, widget, and slot.  If the
+ * globals above match the PCIBR_DEBUG params, then the debug info in the
+ * parameter 'format' is sent to the console.
+ */
+void
+pcibr_debug(uint32_t type, devfs_handle_t vhdl, char *format, ...)
+{
+    char hwpath[MAXDEVNAME] = "\0";
+    char copy_of_hwpath[MAXDEVNAME];
+    char *module = "all";
+    short widget = -1;
+    short slot = -1;
+    va_list ap;
+    char *strtok_r(char *string, const char *sepset, char **lasts);
+
+    if (pcibr_debug_mask & type) {
+        if (vhdl) {
+            if (!hwgraph_vertex_name_get(vhdl, hwpath, MAXDEVNAME)) {
+                char *cp;
+
+                if (strcmp(module, pcibr_debug_module)) {
+		    /* strtok_r() wipes out string, use a copy */
+                    (void)strcpy(copy_of_hwpath, hwpath);
+                    cp = strstr(copy_of_hwpath, "/module/");
+                    if (cp) {
+                        char *last = NULL;
+                        cp += strlen("/module");
+                        module = strtok_r(cp, "/", &last);
+                    }
+                }
+                if (pcibr_debug_widget != -1) {
+                    cp = strstr(hwpath, "/xtalk/");
+                    if (cp) {
+                        cp += strlen("/xtalk/");
+                        widget = atoi(cp);
+                    }
+                }
+                if (pcibr_debug_slot != -1) {
+                    cp = strstr(hwpath, "/pci/");
+                    if (cp) {
+                        cp += strlen("/pci/");
+                        slot = atoi(cp);
+                    }
+                }
+            }
+        }
+        if ((vhdl == NULL) ||
+            (!strcmp(module, pcibr_debug_module) &&
+             (widget == pcibr_debug_widget) &&
+             (slot == pcibr_debug_slot))) {
+#ifdef LATER
+            printk("PCIBR_DEBUG<%d>\t: %s :", cpuid(), hwpath);
+#else
+            printk("PCIBR_DEBUG\t: %s :", hwpath);
+#endif
+	    /*
+	     * Kernel printk translates to this 3 line sequence.
+	     * Since we have a variable length argument list, we
+	     * need to call printk this way rather than directly
+	     */
+	    va_start(ap, format);
+	    printk(format, ap);
+	    va_end(ap);
+        }
+    }
 }
diff -Nru a/arch/ia64/sn/io/sn2/pcibr/pcibr_error.c b/arch/ia64/sn/io/sn2/pcibr/pcibr_error.c
--- a/arch/ia64/sn/io/sn2/pcibr/pcibr_error.c	Mon Dec 23 21:21:50 2002
+++ b/arch/ia64/sn/io/sn2/pcibr/pcibr_error.c	Mon Dec 23 21:21:50 2002
@@ -39,6 +39,14 @@
 #endif
 
 extern int	hubii_check_widget_disabled(nasid_t, int);
+#ifdef BRIDGE_B_DATACORR_WAR
+extern int              ql_bridge_rev_b_war(devfs_handle_t);
+extern int              bridge_rev_b_data_check_disable;
+char                   *rev_b_datacorr_warning =
+"***************************** WARNING! ******************************\n";
+char                   *rev_b_datacorr_mesg =
+"UNRECOVERABLE IO LINK ERROR. CONTACT SERVICE PROVIDER\n";
+#endif
 
 /* =====================================================================
  *    ERROR HANDLING
@@ -54,15 +62,18 @@
 #define BRIDGE_PIOERR_TIMEOUT	1	/* Timeout in non-debug mode                            */
 #endif
 
+/* PIC has 64bit interrupt error registers, but BRIDGE has 32bit registers.
+ * Thus 'bridge_errors_to_dump needs' to default to the larger of the two.
+ */
 #ifdef  DEBUG
 #ifdef ERROR_DEBUG
-bridgereg_t bridge_errors_to_dump = ~BRIDGE_ISR_INT_MSK;
+uint64_t bridge_errors_to_dump = ~BRIDGE_ISR_INT_MSK;
 #else
-bridgereg_t bridge_errors_to_dump = BRIDGE_ISR_ERROR_DUMP;
+uint64_t bridge_errors_to_dump = BRIDGE_ISR_ERROR_DUMP;
 #endif
 #else
-bridgereg_t bridge_errors_to_dump = BRIDGE_ISR_ERROR_FATAL |
-                                BRIDGE_ISR_PCIBUS_PIOERR;
+uint64_t bridge_errors_to_dump = BRIDGE_ISR_ERROR_FATAL |
+                                   BRIDGE_ISR_PCIBUS_PIOERR;
 #endif
 
 #if defined (PCIBR_LLP_CONTROL_WAR)
@@ -71,8 +82,6 @@
 
 /* FIXME: can these arrays be local ? */
 
-#ifdef LATER
-
 struct reg_values xio_cmd_pactyp[] =
 {
     {0x0, "RdReq"},
@@ -113,7 +122,21 @@
 
 struct reg_desc         bridge_int_status_desc[] =
 {
-    F(31, "MULTI_ERR"),
+    F(45, "PCI_X_SPLIT_MES_PE"),/* PIC ONLY */
+    F(44, "PCI_X_SPLIT_EMES"),	/* PIC ONLY */
+    F(43, "PCI_X_SPLIT_TO"),	/* PIC ONLY */
+    F(42, "PCI_X_UNEX_COMP"),	/* PIC ONLY */
+    F(41, "INT_RAM_PERR"),	/* PIC ONLY */
+    F(40, "PCI_X_ARB_ERR"),	/* PIC ONLY */
+    F(39, "PCI_X_REQ_TOUT"),	/* PIC ONLY */
+    F(38, "PCI_X_TABORT"),	/* PIC ONLY */
+    F(37, "PCI_X_PERR"),	/* PIC ONLY */
+    F(36, "PCI_X_SERR"),	/* PIC ONLY */
+    F(35, "PCI_X_MRETRY"),	/* PIC ONLY */
+    F(34, "PCI_X_MTOUT"),	/* PIC ONLY */
+    F(33, "PCI_X_DA_PARITY"),	/* PIC ONLY */
+    F(32, "PCI_X_AD_PARITY"),	/* PIC ONLY */
+    F(31, "MULTI_ERR"),		/* BRIDGE ONLY */
     F(30, "PMU_ESIZE_EFAULT"),
     F(29, "UNEXPECTED_RESP"),
     F(28, "BAD_XRESP_PACKET"),
@@ -128,7 +151,7 @@
     F(19, "LLP_RCTY"),
     F(18, "LLP_TX_RETRY"),
     F(17, "LLP_TCTY"),
-    F(16, "SSRAM_PERR"),
+    F(16, "SSRAM_PERR"),	/* BRIDGE ONLY */
     F(15, "PCI_ABORT"),
     F(14, "PCI_PARITY"),
     F(13, "PCI_SERR"),
@@ -136,7 +159,7 @@
     F(11, "PCI_MASTER_TOUT"),
     F(10, "PCI_RETRY_CNT"),
     F(9, "XREAD_REQ_TOUT"),
-    F(8, "GIO_BENABLE_ERR"),
+    F(8, "GIO_BENABLE_ERR"),	/* BRIDGE ONLY */
     F(7, "INT7"),
     F(6, "INT6"),
     F(5, "INT5"),
@@ -195,20 +218,17 @@
     {0}
 };
 
-#endif	/* LATER */
-
 void
 print_bridge_errcmd(uint32_t cmdword, char *errtype)
 {
-    printk(
-	    "\t    Bridge %s Error Command Word Register %R\n",
-	    errtype, cmdword, xio_cmd_bits);
+    printk("\t    Bridge %s Error Command Word Register ", errtype);
+    print_register(cmdword, xio_cmd_bits);
 }
 
 char             *pcibr_isr_errs[] =
 {
     "", "", "", "", "", "", "", "",
-    "08: GIO non-contiguous byte enable in crosstalk packet",
+    "08: GIO non-contiguous byte enable in crosstalk packet", /* BRIDGE ONLY */
     "09: PCI to Crosstalk read request timeout",
     "10: PCI retry operation count exhausted.",
     "11: PCI bus device select timeout",
@@ -216,7 +236,7 @@
     "13: PCI Address/Cmd parity error ",
     "14: PCI Bridge detected parity error",
     "15: PCI abort condition",
-    "16: SSRAM parity error",
+    "16: SSRAM parity error", /* BRIDGE ONLY */
     "17: LLP Transmitter Retry count wrapped",
     "18: LLP Transmitter side required Retry",
     "19: LLP Receiver retry count wrapped",
@@ -231,13 +251,29 @@
     "28: Framing error, response cmd data size does not match actual",
     "29: Unexpected response arrived",
     "30: PMU Access Fault",
-    "31: Multiple errors occurred",
+    "31: Multiple errors occurred", /* BRIDGE ONLY */
+    
+    /* bits 32-45 are PIC ONLY */
+    "32: PCI-X address or attribute cycle parity error",
+    "33: PCI-X data cycle parity error",
+    "34: PCI-X master timeout (ie. master abort)",
+    "35: PCI-X pio retry counter exhausted",
+    "36: PCI-X SERR",
+    "37: PCI-X PERR", 
+    "38: PCI-X target abort",
+    "39: PCI-X read request timeout",
+    "40: PCI / PCI-X device requestin arbitration error",
+    "41: internal RAM parity error",
+    "42: PCI-X unexpected completion cycle to master",
+    "43: PCI-X split completion timeout",
+    "44: PCI-X split completion error message",
+    "45: PCI-X split completion message parity error",
 };
 
 #define BEM_ADD_STR(s)  printk("%s", (s))
-#define BEM_ADD_VAR(v)  printk("\t%20s: 0x%x\n", #v, (v))
-#define BEM_ADD_REG(r)  printk("\t%20s: %R\n", #r, (r), r ## _desc)
-#define BEM_ADD_NSPC(n,s)       printk("\t%20s: %R\n", n, s, space_desc)
+#define BEM_ADD_VAR(v)  printk("\t%20s: 0x%llx\n", #v, ((unsigned long long)v))
+#define BEM_ADD_REG(r)  printk("\t%20s: ", #r); print_register((r), r ## _desc)
+#define BEM_ADD_NSPC(n,s)       printk("\t%20s: ", n); print_register(s, space_desc)
 #define BEM_ADD_SPC(s)          BEM_ADD_NSPC(#s, s)
 
 /*
@@ -246,6 +282,7 @@
 void
 pcibr_show_dir_state(paddr_t paddr, char *prefix)
 {
+#ifdef LATER
 	int state;
 	uint64_t vec_ptr;
 	hubreg_t elo;
@@ -254,8 +291,9 @@
 
 	get_dir_ent(paddr, &state, &vec_ptr, &elo);
 
-	printf("%saddr 0x%x: state 0x%x owner 0x%x (%s)\n", 
+	printk("%saddr 0x%lx: state 0x%x owner 0x%lx (%s)\n", 
 		prefix, paddr, state, vec_ptr, dir_state_str[state]);
+#endif
 }
 
 
@@ -267,40 +305,70 @@
 pcibr_error_dump(pcibr_soft_t pcibr_soft)
 {
     bridge_t               *bridge = pcibr_soft->bs_base;
-    bridgereg_t             int_status;
-    bridgereg_t             mult_int;
-    int			    bit;
+    uint64_t		    int_status;
+    bridgereg_t             int_status_32;
+    picreg_t		    int_status_64;
+    uint64_t		    mult_int;
+    bridgereg_t             mult_int_32;
+    picreg_t		    mult_int_64;
+    uint64_t		    bit;
+    int			    number_bits;
     int                     i;
     char		    *reg_desc;
-    paddr_t		    addr;
+    paddr_t		    addr = (paddr_t)0;
+
+    /* We read the INT_STATUS register as a 64bit picreg_t for PIC and a
+     * 32bit bridgereg_t for BRIDGE, but always process the result as a
+     * 64bit value so the code can be "common" for both PIC and BRIDGE...
+     */
+    if (IS_PIC_SOFT(pcibr_soft)) {
+	int_status_64 = (bridge->p_int_status_64 & ~BRIDGE_ISR_INT_MSK);
+	int_status = (uint64_t)int_status_64;
+	number_bits = PCIBR_ISR_MAX_ERRS_PIC;
+    } else {
+	int_status_32 = (bridge->b_int_status & ~BRIDGE_ISR_INT_MSK);
+	int_status = ((uint64_t)int_status_32) & 0xffffffff;
+	number_bits = PCIBR_ISR_MAX_ERRS_BRIDGE;
+    }
 
-    int_status = (bridge->b_int_status & ~BRIDGE_ISR_INT_MSK);
     if (!int_status) {
 	/* No error bits set */
 	return;
     }
 
     /* Check if dumping the same error information multiple times */
-    if (test_and_set_int((int *) &pcibr_soft->bs_errinfo.bserr_intstat,
-	    int_status) == int_status) {
+    if ( pcibr_soft->bs_errinfo.bserr_intstat == int_status )
 	return;
-    }
+    pcibr_soft->bs_errinfo.bserr_intstat = int_status;
 
-    printk(KERN_ALERT "PCI BRIDGE ERROR: int_status is 0x%X for %s\n"
-	"    Dumping relevant %sBridge registers for each bit set...\n",
+    printk(KERN_ALERT "PCI BRIDGE ERROR: int_status is 0x%lx for %s\n"
+	"    Dumping relevant %s registers for each bit set...\n",
 	    int_status, pcibr_soft->bs_name,
-	    (is_xbridge(bridge) ? "X" : ""));
+	    (IS_PIC_SOFT(pcibr_soft) ? "PIC" : 
+	        (IS_BRIDGE_SOFT(pcibr_soft) ? "BRIDGE" : "XBRIDGE")));
 
-    for (i = PCIBR_ISR_ERR_START; i < PCIBR_ISR_MAX_ERRS; i++) {
-	bit = 1 << i;
+    for (i = PCIBR_ISR_ERR_START; i < number_bits; i++) {
+	bit = 1ull << i;
 
 	/*
 	 * A number of int_status bits are only defined for Bridge.
-	 * Ignore them in the case of an XBridge.
+	 * Ignore them in the case of an XBridge or PIC.
 	 */
-	if (is_xbridge(bridge) && ((bit == BRIDGE_ISR_MULTI_ERR) ||
-		(bit == BRIDGE_ISR_SSRAM_PERR) ||
-		(bit == BRIDGE_ISR_GIO_B_ENBL_ERR))) {
+	if ((IS_XBRIDGE_SOFT(pcibr_soft) || IS_PIC_SOFT(pcibr_soft)) &&
+	    ((bit == BRIDGE_ISR_MULTI_ERR) ||
+	     (bit == BRIDGE_ISR_SSRAM_PERR) ||
+	     (bit == BRIDGE_ISR_GIO_B_ENBL_ERR))) {
+	    continue;
+	}
+
+	/* A number of int_status bits are only valid for PIC's bus0 */
+	if ((IS_PIC_SOFT(pcibr_soft) && (pcibr_soft->bs_busnum != 0)) && 
+	    ((bit == BRIDGE_ISR_UNSUPPORTED_XOP) ||
+	     (bit == BRIDGE_ISR_LLP_REC_SNERR) ||
+	     (bit == BRIDGE_ISR_LLP_REC_CBERR) ||
+	     (bit == BRIDGE_ISR_LLP_RCTY) ||
+	     (bit == BRIDGE_ISR_LLP_TX_RETRY) ||
+	     (bit == BRIDGE_ISR_LLP_TCTY))) {
 	    continue;
 	}
 
@@ -308,91 +376,241 @@
 	    printk("\t%s\n", pcibr_isr_errs[i]);
 
 	    switch (bit) {
-	    case BRIDGE_ISR_PAGE_FAULT:		/* PMU_PAGE_FAULT  (XBridge) */
-/*	    case BRIDGE_ISR_PMU_ESIZE_FAULT:	   PMU_ESIZE_FAULT (Bridge) */
-		if (is_xbridge(bridge))
+
+	    case PIC_ISR_INT_RAM_PERR:	    /* bit41	INT_RAM_PERR */
+		/* XXX: should breakdown meaning of bits in reg */
+		printk( "\t	Internal RAM Parity Error: 0x%lx\n",
+		    bridge->p_ate_parity_err_64);
+		break;
+
+	    case PIC_ISR_PCIX_ARB_ERR:	    /* bit40	PCI_X_ARB_ERR */
+		/* XXX: should breakdown meaning of bits in reg */
+		printk( "\t	Arbitration Reg: 0x%x\n",
+		    bridge->b_arb);
+		break;
+
+	    case PIC_ISR_PCIX_REQ_TOUT:	    /* bit39	PCI_X_REQ_TOUT */
+		/* XXX: should breakdown meaning of attribute bit */
+		printk(
+		    "\t	   PCI-X DMA Request Error Address Reg: 0x%lx\n"
+		    "\t	   PCI-X DMA Request Error Attribute Reg: 0x%lx\n",
+		    bridge->p_pcix_dma_req_err_addr_64,
+		    bridge->p_pcix_dma_req_err_attr_64);
+		break;
+
+	    case PIC_ISR_PCIX_SPLIT_MSG_PE: /* bit45	PCI_X_SPLIT_MES_PE */
+	    case PIC_ISR_PCIX_SPLIT_EMSG:   /* bit44	PCI_X_SPLIT_EMESS */
+	    case PIC_ISR_PCIX_SPLIT_TO:	    /* bit43	PCI_X_SPLIT_TO */
+		/* XXX: should breakdown meaning of attribute bit */
+		printk(
+		    "\t	   PCI-X Split Request Address Reg: 0x%lx\n"
+		    "\t	   PCI-X Split Request Attribute Reg: 0x%lx\n",
+		    bridge->p_pcix_pio_split_addr_64,
+		    bridge->p_pcix_pio_split_attr_64);
+		/* FALL THRU */
+
+	    case PIC_ISR_PCIX_UNEX_COMP:    /* bit42	PCI_X_UNEX_COMP */
+	    case PIC_ISR_PCIX_TABORT:	    /* bit38	PCI_X_TABORT */
+	    case PIC_ISR_PCIX_PERR:	    /* bit37	PCI_X_PERR */
+	    case PIC_ISR_PCIX_SERR:	    /* bit36	PCI_X_SERR */
+	    case PIC_ISR_PCIX_MRETRY:	    /* bit35	PCI_X_MRETRY */
+	    case PIC_ISR_PCIX_MTOUT:	    /* bit34	PCI_X_MTOUT */
+	    case PIC_ISR_PCIX_DA_PARITY:    /* bit33	PCI_X_DA_PARITY */
+	    case PIC_ISR_PCIX_AD_PARITY:    /* bit32	PCI_X_AD_PARITY */
+		/* XXX: should breakdown meaning of attribute bit */
+		printk(
+		    "\t	   PCI-X Bus Error Address Reg: 0x%lx\n"
+		    "\t	   PCI-X Bus Error Attribute Reg: 0x%lx\n"
+		    "\t	   PCI-X Bus Error Data Reg: 0x%lx\n",
+		    bridge->p_pcix_bus_err_addr_64,
+		    bridge->p_pcix_bus_err_attr_64,
+		    bridge->p_pcix_bus_err_data_64);
+		break;
+
+	    case BRIDGE_ISR_PAGE_FAULT:	    /* bit30	PMU_PAGE_FAULT */
+/*	    case BRIDGE_ISR_PMU_ESIZE_FAULT:   bit30	PMU_ESIZE_FAULT */
+		if (IS_XBRIDGE_OR_PIC_SOFT(pcibr_soft))
 		    reg_desc = "Map Fault Address";
 		else
 		    reg_desc = "SSRAM Parity Error";
 
-		printk("\t    %s Register: 0x%x\n", reg_desc,
+		printk( "\t    %s Register: 0x%x\n", reg_desc,
 		    bridge->b_ram_perr_or_map_fault);
 		break;
 
-	    case BRIDGE_ISR_UNEXP_RESP:		/* UNEXPECTED_RESP */
-		print_bridge_errcmd(bridge->b_wid_aux_err, "Aux");
-		break;
+	    case BRIDGE_ISR_UNEXP_RESP:    /* bit29	UNEXPECTED_RESP */
+		print_bridge_errcmd(bridge->b_wid_aux_err, "Aux ");
 
-	    case BRIDGE_ISR_BAD_XRESP_PKT:		/* BAD_RESP_PACKET */
-	    case BRIDGE_ISR_RESP_XTLK_ERR:		/* RESP_XTALK_ERROR */
-	    case BRIDGE_ISR_XREAD_REQ_TIMEOUT:		/* XREAD_REQ_TOUT */
+		/* PIC in PCI-X mode, dump the PCIX DMA Request registers */
+		if (IS_PIC_SOFT(pcibr_soft) && IS_PCIX(pcibr_soft)) {
+		    /* XXX: should breakdown meaning of attr bit */
+		    printk( 
+			"\t    PCI-X DMA Request Error Addr Reg: 0x%lx\n"
+			"\t    PCI-X DMA Request Error Attr Reg: 0x%lx\n",
+			bridge->p_pcix_dma_req_err_addr_64,
+			bridge->p_pcix_dma_req_err_attr_64);
+		}
+		break;
 
-		addr = (((uint64_t) (bridge->b_wid_resp_upper & 0xFFFF) << 32)
-			| bridge->b_wid_resp_lower);
-		printk(
-		    "\t    Bridge Response Buffer Error Upper Address Register: 0x%x\n"
-		    "\t    Bridge Response Buffer Error Lower Address Register: 0x%x\n"
-		    "\t    dev-num %d buff-num %d addr 0x%x\n",
-		    bridge->b_wid_resp_upper, bridge->b_wid_resp_lower,
-		    ((bridge->b_wid_resp_upper >> 20) & 0x3),
-		    ((bridge->b_wid_resp_upper >> 16) & 0xF),
-		    addr);
+	    case BRIDGE_ISR_BAD_XRESP_PKT:  /* bit28	BAD_RESP_PACKET */
+	    case BRIDGE_ISR_RESP_XTLK_ERR:  /* bit26	RESP_XTALK_ERROR */
+		if (IS_PIC_SOFT(pcibr_soft)) {
+		    print_bridge_errcmd(bridge->b_wid_aux_err, "Aux ");
+		}
+		 
+		/* If PIC in PCI-X mode, DMA Request Error registers are
+		 * valid.  But PIC in PCI mode, Response Buffer Address 
+		 * register are valid.
+		 */
+		if (IS_PCIX(pcibr_soft)) {
+		    /* XXX: should breakdown meaning of attribute bit */
+		    printk( 
+			"\t    PCI-X DMA Request Error Addr Reg: 0x%lx\n"
+		        "\t    PCI-X DMA Request Error Attribute Reg: 0x%lx\n",
+		        bridge->p_pcix_dma_req_err_addr_64,
+		        bridge->p_pcix_dma_req_err_attr_64);
+		} else {
+		    addr= (((uint64_t)(bridge->b_wid_resp_upper & 0xFFFF)<<32)
+			   | bridge->b_wid_resp_lower);
+		    printk("\t    Bridge Response Buf Error Upper Addr Reg: 0x%x\n"
+		        "\t    Bridge Response Buf Error Lower Addr Reg: 0x%x\n"
+		        "\t    dev-num %d buff-num %d addr 0x%lx\n",
+		        bridge->b_wid_resp_upper, bridge->b_wid_resp_lower,
+		        ((bridge->b_wid_resp_upper >> 20) & 0x3),
+		        ((bridge->b_wid_resp_upper >> 16) & 0xF),
+		        addr);
+		}
 		if (bit == BRIDGE_ISR_RESP_XTLK_ERR) {
 			/* display memory directory associated with cacheline */
 			pcibr_show_dir_state(addr, "\t    ");
 		}
 		break;
 
-	    case BRIDGE_ISR_BAD_XREQ_PKT:		/* BAD_XREQ_PACKET */
-	    case BRIDGE_ISR_REQ_XTLK_ERR:		/* REQ_XTALK_ERROR */
-	    case BRIDGE_ISR_INVLD_ADDR:			/* INVALID_ADDRESS */
-	    case BRIDGE_ISR_UNSUPPORTED_XOP:		/* UNSUPPORTED_XOP */
-		print_bridge_errcmd(bridge->b_wid_aux_err, "");
-		printk("\t    Bridge Error Upper Address Register: 0x%x\n"
-		    "\t    Bridge Error Lower Address Register: 0x%x\n"
-		    "\t    Bridge Error Address: 0x%x\n",
+	    case BRIDGE_ISR_BAD_XREQ_PKT:   /* bit27	BAD_XREQ_PACKET */
+	    case BRIDGE_ISR_REQ_XTLK_ERR:   /* bit25	REQ_XTALK_ERROR */
+	    case BRIDGE_ISR_INVLD_ADDR:	    /* bit24	INVALID_ADDRESS */
+		print_bridge_errcmd(bridge->b_wid_err_cmdword, "");
+		printk( 
+		    "\t    Bridge Error Upper Address Register: 0x%lx\n"
+		    "\t    Bridge Error Lower Address Register: 0x%lx\n"
+		    "\t    Bridge Error Address: 0x%lx\n",
 		    (uint64_t) bridge->b_wid_err_upper,
 		    (uint64_t) bridge->b_wid_err_lower,
 		    (((uint64_t) bridge->b_wid_err_upper << 32) |
 		    bridge->b_wid_err_lower));
 		break;
 
-	    case BRIDGE_ISR_SSRAM_PERR:			/* SSRAM_PERR */
-		if (!is_xbridge(bridge)) {	/* only defined on Bridge */
+	    case BRIDGE_ISR_UNSUPPORTED_XOP:/* bit23	UNSUPPORTED_XOP */
+		if (IS_PIC_SOFT(pcibr_soft)) {
+		    print_bridge_errcmd(bridge->b_wid_aux_err, "Aux ");
+		    printk( 
+			"\t    Address Holding Link Side Error Reg: 0x%lx\n",
+			bridge->p_addr_lkerr_64);
+		} else {
+		    print_bridge_errcmd(bridge->b_wid_err_cmdword, "");
+		    printk( 
+			"\t    Bridge Error Upper Address Register: 0x%lx\n"
+		        "\t    Bridge Error Lower Address Register: 0x%lx\n"
+		        "\t    Bridge Error Address: 0x%lx\n",
+		        (uint64_t) bridge->b_wid_err_upper,
+		        (uint64_t) bridge->b_wid_err_lower,
+		        (((uint64_t) bridge->b_wid_err_upper << 32) |
+		        bridge->b_wid_err_lower));
+		}
+		break;
+
+	    case BRIDGE_ISR_XREQ_FIFO_OFLOW:/* bit22	XREQ_FIFO_OFLOW */
+		/* Link side error registers are only valid for PIC */
+		if (IS_PIC_SOFT(pcibr_soft)) {
+		    print_bridge_errcmd(bridge->b_wid_aux_err, "Aux ");
+		    printk(
+			"\t    Address Holding Link Side Error Reg: 0x%lx\n",
+			bridge->p_addr_lkerr_64);
+		}
+		break;
+
+	    case BRIDGE_ISR_SSRAM_PERR:	    /* bit16	SSRAM_PERR */
+		if (IS_BRIDGE_SOFT(pcibr_soft)) {
 		    printk(
 			"\t    Bridge SSRAM Parity Error Register: 0x%x\n",
 			bridge->b_ram_perr);
 		}
 		break;
 
-	    case BRIDGE_ISR_PCI_ABORT:			/* PCI_ABORT */
-	    case BRIDGE_ISR_PCI_PARITY:			/* PCI_PARITY */
-	    case BRIDGE_ISR_PCI_SERR:			/* PCI_SERR */
-	    case BRIDGE_ISR_PCI_PERR:			/* PCI_PERR */
-	    case BRIDGE_ISR_PCI_MST_TIMEOUT:		/* PCI_MASTER_TOUT */
-	    case BRIDGE_ISR_PCI_RETRY_CNT:		/* PCI_RETRY_CNT */
-	    case BRIDGE_ISR_GIO_B_ENBL_ERR:		/* GIO BENABLE_ERR */
-		printk("\t    PCI Error Upper Address Register: 0x%x\n"
-		    "\t    PCI Error Lower Address Register: 0x%x\n"
-		    "\t    PCI Error Address: 0x%x\n",
+	    case BRIDGE_ISR_PCI_ABORT:	    /* bit15	PCI_ABORT */
+	    case BRIDGE_ISR_PCI_PARITY:	    /* bit14	PCI_PARITY */
+	    case BRIDGE_ISR_PCI_SERR:	    /* bit13	PCI_SERR */
+	    case BRIDGE_ISR_PCI_PERR:	    /* bit12	PCI_PERR */
+	    case BRIDGE_ISR_PCI_MST_TIMEOUT:/* bit11	PCI_MASTER_TOUT */
+	    case BRIDGE_ISR_PCI_RETRY_CNT:  /* bit10	PCI_RETRY_CNT */
+	    case BRIDGE_ISR_GIO_B_ENBL_ERR: /* bit08	GIO BENABLE_ERR */
+		printk( 
+		    "\t    PCI Error Upper Address Register: 0x%lx\n"
+		    "\t    PCI Error Lower Address Register: 0x%lx\n"
+		    "\t    PCI Error Address: 0x%lx\n",
 		    (uint64_t) bridge->b_pci_err_upper,
 		    (uint64_t) bridge->b_pci_err_lower,
 		    (((uint64_t) bridge->b_pci_err_upper << 32) |
 		    bridge->b_pci_err_lower));
 		break;
+
+	    case BRIDGE_ISR_XREAD_REQ_TIMEOUT: /* bit09	XREAD_REQ_TOUT */
+		addr = (((uint64_t)(bridge->b_wid_resp_upper & 0xFFFF) << 32)
+		    | bridge->b_wid_resp_lower);
+		printk(
+		    "\t    Bridge Response Buf Error Upper Addr Reg: 0x%x\n"
+		    "\t    Bridge Response Buf Error Lower Addr Reg: 0x%x\n"
+		    "\t    dev-num %d buff-num %d addr 0x%lx\n",
+		    bridge->b_wid_resp_upper, bridge->b_wid_resp_lower,
+		    ((bridge->b_wid_resp_upper >> 20) & 0x3),
+		    ((bridge->b_wid_resp_upper >> 16) & 0xF),
+		    addr);
+		break;
 	    }
 	}
     }
 
-    if (is_xbridge(bridge) && (bridge->b_mult_int & ~BRIDGE_ISR_INT_MSK)) {
-	mult_int = bridge->b_mult_int;
-	printk("    XBridge Multiple Interrupt Register is 0x%x\n",
-		mult_int);
-	for (i = PCIBR_ISR_ERR_START; i < PCIBR_ISR_MAX_ERRS; i++) {
-	    if (mult_int & (1 << i))
-		printk("\t%s\n", pcibr_isr_errs[i]);
-	    }
+    /* We read the INT_MULT register as a 64bit picreg_t for PIC and a
+     * 32bit bridgereg_t for BRIDGE, but always process the result as a
+     * 64bit value so the code can be "common" for both PIC and BRIDGE...
+     */
+    if (IS_PIC_SOFT(pcibr_soft)) {
+	mult_int_64 = (bridge->p_mult_int_64 & ~BRIDGE_ISR_INT_MSK);
+	mult_int = (uint64_t)mult_int_64;
+	number_bits = PCIBR_ISR_MAX_ERRS_PIC;
+    } else {
+	mult_int_32 = (bridge->b_mult_int & ~BRIDGE_ISR_INT_MSK);
+	mult_int = ((uint64_t)mult_int_32) & 0xffffffff;
+	number_bits = PCIBR_ISR_MAX_ERRS_BRIDGE;
+    }
+
+    if (IS_XBRIDGE_OR_PIC_SOFT(pcibr_soft)&&(mult_int & ~BRIDGE_ISR_INT_MSK)) {
+	printk( "    %s Multiple Interrupt Register is 0x%lx\n",
+		IS_PIC_SOFT(pcibr_soft) ? "PIC" : "XBridge", mult_int);
+	for (i = PCIBR_ISR_ERR_START; i < number_bits; i++) {
+	    if (mult_int & (1ull << i))
+		printk( "\t%s\n", pcibr_isr_errs[i]);
 	}
+    }
+
+#if BRIDGE_ERROR_INTR_WAR
+    if (pcibr_soft->bs_rev_num == BRIDGE_PART_REV_A) {	/* known bridge bug */
+	/*
+	 * Should never receive interrupts for these reasons on Rev 1 bridge
+	 * as they are not enabled. Assert for it.
+	 */
+	ASSERT((int_status & (BRIDGE_IMR_PCI_MST_TIMEOUT |
+			      BRIDGE_ISR_RESP_XTLK_ERR |
+			      BRIDGE_ISR_LLP_TX_RETRY)) == 0);
+    }
+    if (pcibr_soft->bs_rev_num < BRIDGE_PART_REV_C) {	/* known bridge bug */
+	/*
+	 * This interrupt is turned off at init time. So, should never
+	 * see this interrupt.
+	 */
+	ASSERT((int_status & BRIDGE_ISR_BAD_XRESP_PKT) == 0);
+    }
+#endif
 }
 
 #define PCIBR_ERRINTR_GROUP(error)	\
@@ -430,9 +648,11 @@
 pcibr_pioerr_check(pcibr_soft_t soft)
 {
     bridge_t		   *bridge;
-    bridgereg_t		    b_int_status;
-    bridgereg_t		    b_pci_err_lower;
-    bridgereg_t		    b_pci_err_upper;
+    uint64_t              int_status;
+    bridgereg_t             int_status_32;
+    picreg_t                int_status_64;
+    bridgereg_t		    pci_err_lower;
+    bridgereg_t		    pci_err_upper;
     iopaddr_t		    pci_addr;
     pciio_slot_t	    slot;
     pcibr_piomap_t	    map;
@@ -442,40 +662,48 @@
     int			    func;
 
     bridge = soft->bs_base;
-    b_int_status = bridge->b_int_status;
-    if (b_int_status & BRIDGE_ISR_PCIBUS_PIOERR) {
-	b_pci_err_lower = bridge->b_pci_err_lower;
-	b_pci_err_upper = bridge->b_pci_err_upper;
-	b_int_status = bridge->b_int_status;
-	if (b_int_status & BRIDGE_ISR_PCIBUS_PIOERR) {
-
-	    pci_addr = b_pci_err_upper & BRIDGE_ERRUPPR_ADDRMASK;
-	    pci_addr = (pci_addr << 32) | b_pci_err_lower;
-
-	    slot = 8;
-	    while (slot-- > 0) {
-		int 		nfunc = soft->bs_slot[slot].bss_ninfo;
-		pcibr_info_h	pcibr_infoh = soft->bs_slot[slot].bss_infos;
-
-		for (func = 0; func < nfunc; func++) {
-		    pcibr_info_t 	pcibr_info = pcibr_infoh[func];
-
-		    if (!pcibr_info)
-			continue;
-
-		    for (map = pcibr_info->f_piomap;
-			 map != NULL; map = map->bp_next) {
-			base = map->bp_pciaddr;
-			size = map->bp_mapsz;
-			win = map->bp_space - PCIIO_SPACE_WIN(0);
-			if (win < 6)
-			    base += 
-				soft->bs_slot[slot].bss_window[win].bssw_base;
-			else if (map->bp_space == PCIIO_SPACE_ROM)
-			    base += pcibr_info->f_rbase;
-			if ((pci_addr >= base) && (pci_addr < (base + size)))
-			    atomicAddInt(map->bp_toc, 1);
-		    }
+
+    /* We read the INT_STATUS register as a 64bit picreg_t for PIC and a
+     * 32bit bridgereg_t for BRIDGE, but always process the result as a
+     * 64bit value so the code can be "common" for both PIC and BRIDGE...
+     */
+    if (IS_PIC_SOFT(soft)) {
+        int_status_64 = (bridge->p_int_status_64 & ~BRIDGE_ISR_INT_MSK);
+        int_status = (uint64_t)int_status_64;
+    } else {
+        int_status_32 = (bridge->b_int_status & ~BRIDGE_ISR_INT_MSK);
+        int_status = ((uint64_t)int_status_32) & 0xffffffff;
+    }
+
+    if (int_status & BRIDGE_ISR_PCIBUS_PIOERR) {
+	pci_err_lower = bridge->b_pci_err_lower;
+	pci_err_upper = bridge->b_pci_err_upper;
+
+	pci_addr = pci_err_upper & BRIDGE_ERRUPPR_ADDRMASK;
+	pci_addr = (pci_addr << 32) | pci_err_lower;
+
+	slot = PCIBR_NUM_SLOTS(soft);
+	while (slot-- > 0) {
+	    int 		nfunc = soft->bs_slot[slot].bss_ninfo;
+	    pcibr_info_h	pcibr_infoh = soft->bs_slot[slot].bss_infos;
+
+	    for (func = 0; func < nfunc; func++) {
+		pcibr_info_t 	pcibr_info = pcibr_infoh[func];
+
+		if (!pcibr_info)
+		    continue;
+
+		for (map = pcibr_info->f_piomap;
+		        map != NULL; map = map->bp_next) {
+		    base = map->bp_pciaddr;
+		    size = map->bp_mapsz;
+		    win = map->bp_space - PCIIO_SPACE_WIN(0);
+		    if (win < 6)
+			base += soft->bs_slot[slot].bss_window[win].bssw_base;
+		    else if (map->bp_space == PCIIO_SPACE_ROM)
+			base += pcibr_info->f_rbase;
+		    if ((pci_addr >= base) && (pci_addr < (base + size)))
+			atomic_inc(&map->bp_toc[0]);
 		}
 	    }
 	}
@@ -502,25 +730,33 @@
  *                due to read or write error!.
  */
 
-
 void
-pcibr_error_intr_handler(intr_arg_t arg)
+pcibr_error_intr_handler(int irq, void *arg, struct pt_regs *ep)
 {
     pcibr_soft_t            pcibr_soft;
     bridge_t               *bridge;
-    bridgereg_t             int_status;
-    bridgereg_t             err_status;
+    uint64_t              int_status;
+    uint64_t              err_status;
+    bridgereg_t             int_status_32;
+    picreg_t                int_status_64;
+    int			    number_bits;
     int                     i;
 
     /* REFERENCED */
-    bridgereg_t             disable_errintr_mask = 0;
+    uint64_t		    disable_errintr_mask = 0;
+#ifdef EHE_ENABLE
     int 		    rv;
     int 		    error_code = IOECODE_DMA | IOECODE_READ;
     ioerror_mode_t 	    mode = MODE_DEVERROR;
     ioerror_t 	            ioe;
+#endif /* EHE_ENABLE */
     nasid_t		    nasid;
 
+
 #if PCIBR_SOFT_LIST
+    /*
+     * Defensive code for linked pcibr_soft structs
+     */
     {
 	extern pcibr_list_p	pcibr_list;
 	pcibr_list_p            entry;
@@ -528,17 +764,14 @@
 	entry = pcibr_list;
 	while (1) {
 	    if (entry == NULL) {
-		PRINT_PANIC(
-			"pcibr_error_intr_handler:\n"
-			"\tmy parameter (0x%x) is not a pcibr_soft!",
-			arg);
+		PRINT_PANIC("pcibr_error_intr_handler:\tmy parameter (0x%p) is not a pcibr_soft!", arg);
 	    }
 	    if ((intr_arg_t) entry->bl_soft == arg)
 		break;
 	    entry = entry->bl_next;
 	}
     }
-#endif
+#endif /* PCIBR_SOFT_LIST */
     pcibr_soft = (pcibr_soft_t) arg;
     bridge = pcibr_soft->bs_base;
 
@@ -568,16 +801,37 @@
 
     nasid = NASID_GET(bridge);
     if (hubii_check_widget_disabled(nasid, pcibr_soft->bs_xid)) {
-	timeout(pcibr_error_intr_handler, pcibr_soft, BRIDGE_PIOERR_TIMEOUT);
+	DECLARE_WAIT_QUEUE_HEAD(wq);
+	sleep_on_timeout(&wq, BRIDGE_PIOERR_TIMEOUT*HZ );  /* sleep */
 	pcibr_soft->bs_errinfo.bserr_toutcnt++;
+	/* Let's go recursive */
+	return(pcibr_error_intr_handler(irq, arg, ep));
+#ifdef LATER
+	timeout(pcibr_error_intr_handler, pcibr_soft, BRIDGE_PIOERR_TIMEOUT);
+#endif
 	return;
     }
 
+    /* We read the INT_STATUS register as a 64bit picreg_t for PIC and a
+     * 32bit bridgereg_t for BRIDGE, but always process the result as a
+     * 64bit value so the code can be "common" for both PIC and BRIDGE...
+     */
+    if (IS_PIC_SOFT(pcibr_soft)) {
+        int_status_64 = (bridge->p_int_status_64 & ~BRIDGE_ISR_INT_MSK);
+        int_status = (uint64_t)int_status_64;
+        number_bits = PCIBR_ISR_MAX_ERRS_PIC;
+    } else {
+        int_status_32 = (bridge->b_int_status & ~BRIDGE_ISR_INT_MSK);
+        int_status = ((uint64_t)int_status_32) & 0xffffffff;
+        number_bits = PCIBR_ISR_MAX_ERRS_BRIDGE;
+    }
+
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ERROR, pcibr_soft->bs_conn,
+		"pcibr_error_intr_handler: int_status=0x%x\n", int_status));
+
     /* int_status is which bits we have to clear;
      * err_status is the bits we haven't handled yet.
      */
-
-    int_status = bridge->b_int_status &  ~BRIDGE_ISR_INT_MSK;
     err_status = int_status & ~BRIDGE_ISR_MULTI_ERR;
 
     if (!(int_status & ~BRIDGE_ISR_INT_MSK)) {
@@ -593,11 +847,29 @@
 	pcibr_pioerr_check(pcibr_soft);
     }
 
+#ifdef BRIDGE_B_DATACORR_WAR
+    if ((pcibr_soft->bs_rev_num == BRIDGE_PART_REV_B) &&
+	(err_status & BRIDGE_IMR_LLP_REC_CBERR)) {
+	if (bridge_rev_b_data_check_disable)
+	    printk(KERN_WARNING "\n%s%s: %s%s\n", rev_b_datacorr_warning,
+		    pcibr_soft->bs_name, rev_b_datacorr_mesg,
+		    rev_b_datacorr_warning);
+	else {
+	    ql_bridge_rev_b_war(pcibr_soft->bs_vhdl);
+	    PRINT_PANIC( "\n%s%s: %s%s\n", rev_b_datacorr_warning,
+		    pcibr_soft->bs_name, rev_b_datacorr_mesg,
+		    rev_b_datacorr_warning);
+	}
+
+	err_status &= ~BRIDGE_IMR_LLP_REC_CBERR;
+    }
+#endif				/* BRIDGE_B_DATACORR_WAR */
+
     if (err_status) {
 	struct bs_errintr_stat_s *bs_estat = pcibr_soft->bs_errintr_stat;
 
-	for (i = PCIBR_ISR_ERR_START; i < PCIBR_ISR_MAX_ERRS; i++, bs_estat++) {
-	    if (err_status & (1 << i)) {
+	for (i = PCIBR_ISR_ERR_START; i < number_bits; i++, bs_estat++) {
+	    if (err_status & (1ull << i)) {
 		uint32_t              errrate = 0;
 		uint32_t              errcount = 0;
 		uint32_t              errinterval = 0, current_tick = 0;
@@ -606,12 +878,14 @@
 
 		bs_estat->bs_errcount_total++;
 
-		current_tick = lbolt;
+		current_tick = jiffies;
 		errinterval = (current_tick - bs_estat->bs_lasterr_timestamp);
 		errcount = (bs_estat->bs_errcount_total -
 			    bs_estat->bs_lasterr_snapshot);
 
-		is_llp_tx_retry_intr = (BRIDGE_ISR_LLP_TX_RETRY == (1 << i));
+		/* LLP interrrupt errors are only valid on BUS0 of the PIC */
+		if (pcibr_soft->bs_busnum == 0)
+		    is_llp_tx_retry_intr = (BRIDGE_ISR_LLP_TX_RETRY==(1ull << i));
 
 		/* Check for the divide by zero condition while
 		 * calculating the error rates.
@@ -698,6 +972,15 @@
 			    bs_estat->bs_errcount_total;
 		    }
 		}
+		/* PIC BRINGUP WAR (PV# 856155):
+		 * Dont disable PCI_X_ARB_ERR interrupts, we need the
+		 * interrupt inorder to clear the DEV_BROKE bits in
+		 * b_arb register to re-enable the device.
+		 */
+		if (IS_PIC_SOFT(pcibr_soft) &&
+				!(err_status & PIC_ISR_PCIX_ARB_ERR) &&
+				PCIBR_WAR_ENABLED(PV856155, pcibr_soft)) {
+
 		if (bs_estat->bs_errcount_total > PCIBR_ERRINTR_DISABLE_LEVEL) {
 		    /*
 		     * We have seen a fairly large number of errors of
@@ -709,18 +992,26 @@
 			    pcibr_soft->bs_name,
 			    pcibr_isr_errs[i],
 			    bs_estat->bs_errcount_total);
-		    disable_errintr_mask |= (1 << i);
+		    disable_errintr_mask |= (1ull << i);
 		}
+		} /* PIC: WAR for PV 856155 end-of-if */
 	    }
 	}
     }
 
     if (disable_errintr_mask) {
+	unsigned s;
 	/*
 	 * Disable some high frequency errors as they
 	 * could eat up too much cpu time.
 	 */
-	bridge->b_int_enable &= ~disable_errintr_mask;
+	s = pcibr_lock(pcibr_soft);
+	if (IS_PIC_SOFT(pcibr_soft)) {
+	    bridge->p_int_enable_64 &= (picreg_t)(~disable_errintr_mask);
+	} else {
+	    bridge->b_int_enable &= (bridgereg_t)(~disable_errintr_mask);
+	}
+	pcibr_unlock(pcibr_soft, s);
     }
     /*
      * If we leave the PROM cacheable, T5 might
@@ -783,15 +1074,34 @@
     if (rv != IOERROR_HANDLED) {
 #endif /* EHE_ENABLE */
 
+    bridge_errors_to_dump |= BRIDGE_ISR_PCIBUS_PIOERR;
+
     /* Dump/Log Bridge error interrupt info */
     if (err_status & bridge_errors_to_dump) {
-	printk("BRIDGE ERR_STATUS 0x%x\n", err_status);
+	printk("BRIDGE ERR_STATUS 0x%lx\n", err_status);
 	pcibr_error_dump(pcibr_soft);
     }
 
+    /* PIC BRINGUP WAR (PV# 867308):
+     * Make BRIDGE_ISR_LLP_REC_SNERR & BRIDGE_ISR_LLP_REC_CBERR fatal errors
+     * so we know we've hit the problem defined in PV 867308 that we believe
+     * has only been seen in simulation
+     */
+    if (IS_PIC_SOFT(pcibr_soft) && PCIBR_WAR_ENABLED(PV867308, pcibr_soft) &&
+        (err_status & (BRIDGE_ISR_LLP_REC_SNERR | BRIDGE_ISR_LLP_REC_CBERR))) {
+        printk("BRIDGE ERR_STATUS 0x%x\n", err_status);
+        pcibr_error_dump(pcibr_soft);
+#ifdef LATER
+        machine_error_dump("");
+#endif
+        PRINT_PANIC("PCI Bridge Error interrupt killed the system");
+    }
+
     if (err_status & BRIDGE_ISR_ERROR_FATAL) {
+#ifdef LATER
 	machine_error_dump("");
-	cmn_err_tag(14, CE_PANIC, "PCI Bridge Error interrupt killed the system");
+#endif
+	PRINT_PANIC("PCI Bridge Error interrupt killed the system");
 	    /*NOTREACHED */
     }
 
@@ -804,11 +1114,27 @@
      * it would cause problems for devices like IOC3 (Lost
      * interrupts ?.). So, just cleanup the interrupt, and
      * use saved values later..
+     * 
+     * PIC doesn't require groups of interrupts to be cleared...
      */
-    bridge->b_int_rst_stat = pcibr_errintr_group(int_status);
+    if (IS_PIC_SOFT(pcibr_soft)) {
+	bridge->p_int_rst_stat_64 = (picreg_t)(int_status | BRIDGE_IRR_MULTI_CLR);
+    } else {
+	bridge->b_int_rst_stat = (bridgereg_t)pcibr_errintr_group(int_status);
+    }
+
+    /* PIC BRINGUP WAR (PV# 856155):
+     * On a PCI_X_ARB_ERR error interrupt clear the DEV_BROKE bits from
+     * the b_arb register to re-enable the device.
+     */
+    if (IS_PIC_SOFT(pcibr_soft) &&
+		(err_status & PIC_ISR_PCIX_ARB_ERR) &&
+		PCIBR_WAR_ENABLED(PV856155, pcibr_soft)) {
+	bridge->b_arb |= (0xf << 20);
+    }
 
     /* Zero out bserr_intstat field */
-    test_and_set_int((int *) &pcibr_soft->bs_errinfo.bserr_intstat, 0);
+    pcibr_soft->bs_errinfo.bserr_intstat = 0;
 }
 
 /*
@@ -832,7 +1158,7 @@
 		  iopaddr_t *offsetp,
 		  pciio_function_t *funcp)
 {
-    int                     s, f, w;
+    int                     s, f = 0, w;
     iopaddr_t               base;
     size_t                  size;
     pciio_piospace_t        piosp;
@@ -864,7 +1190,7 @@
 
 	return s;
     }
-    for (s = 0; s < 8; s++) {
+    for (s = pcibr_soft->bs_min_slot; s < PCIBR_NUM_SLOTS(pcibr_soft); ++s) {
 	int                     nf = pcibr_soft->bs_slot[s].bss_ninfo;
 	pcibr_info_h            pcibr_infoh = pcibr_soft->bs_slot[s].bss_infos;
 
@@ -874,8 +1200,7 @@
 	    if (!pcibr_info)
 		continue;
 	    for (w = 0; w < 6; w++) {
-		if (pcibr_info->f_window[w].w_space
-		    == PCIIO_SPACE_NONE) {
+		if (pcibr_info->f_window[w].w_space == PCIIO_SPACE_NONE) {
 		    continue;
 		}
 		base = pcibr_info->f_window[w].w_base;
@@ -898,7 +1223,7 @@
      * Check if the address was allocated as part of the
      * pcibr_piospace_alloc calls.
      */
-    for (s = 0; s < 8; s++) {
+    for (s = pcibr_soft->bs_min_slot; s < PCIBR_NUM_SLOTS(pcibr_soft); ++s) {
 	int                     nf = pcibr_soft->bs_slot[s].bss_ninfo;
 	pcibr_info_h            pcibr_infoh = pcibr_soft->bs_slot[s].bss_infos;
 
@@ -950,8 +1275,14 @@
     ASSERT(error_code & IOECODE_PIO);
     error_code = error_code;
 
-    bridge->b_int_rst_stat =
-	(BRIDGE_IRR_PCI_GRP_CLR | BRIDGE_IRR_MULTI_CLR);
+    if (IS_PIC_SOFT(pcibr_soft)) {
+        bridge->p_int_rst_stat_64 = BRIDGE_IRR_PCI_GRP_CLR |
+				    PIC_PCIX_GRP_CLR |
+				    BRIDGE_IRR_MULTI_CLR;
+    } else {
+        bridge->b_int_rst_stat = BRIDGE_IRR_PCI_GRP_CLR | BRIDGE_IRR_MULTI_CLR;
+    }
+
     (void) bridge->b_wid_tflush;	/* flushbus */
 }
 
@@ -1040,13 +1371,6 @@
  *      associated with this device.
  */
 
-#define BEM_ADD_STR(s)	printk("%s", (s))
-#define BEM_ADD_VAR(v)	printk("\t%20s: 0x%x\n", #v, (v))
-#define BEM_ADD_REG(r)	printk("\t%20s: %R\n", #r, (r), r ## _desc)
-
-#define BEM_ADD_NSPC(n,s)	printk("\t%20s: %R\n", n, s, space_desc)
-#define BEM_ADD_SPC(s)		BEM_ADD_NSPC(#s, s)
-
 /* BEM_ADD_IOE doesn't dump the whole ioerror, it just
  * decodes the PCI specific portions -- we count on our
  * callers to dump the raw IOE data.
@@ -1054,40 +1378,38 @@
 #define BEM_ADD_IOE(ioe)						\
 	do {								\
 	    if (IOERROR_FIELDVALID(ioe, busspace)) {			\
-		unsigned		spc;				\
-		unsigned		win;				\
+		iopaddr_t		spc;				\
+		iopaddr_t		win;				\
+		short			widdev;				\
+		iopaddr_t		busaddr;			\
 									\
-		spc = IOERROR_GETVALUE(ioe, busspace);			\
+		IOERROR_GETVALUE(spc, ioe, busspace);			\
 		win = spc - PCIIO_SPACE_WIN(0);				\
+		IOERROR_GETVALUE(busaddr, ioe, busaddr);		\
+		IOERROR_GETVALUE(widdev, ioe, widgetdev);		\
 									\
 		switch (spc) {						\
 		case PCIIO_SPACE_CFG:					\
-		    printk(					\
-			    "\tPCI Slot %d Func %d CFG space Offset 0x%x\n",	\
-	    pciio_widgetdev_slot_get(IOERROR_GETVALUE(ioe, widgetdev)),	\
-	    pciio_widgetdev_func_get(IOERROR_GETVALUE(ioe, widgetdev)),	\
-			    IOERROR_GETVALUE(ioe, busaddr));		\
+		    printk("\tPCI Slot %d Func %d CFG space Offset 0x%lx\n",\
+			    	pciio_widgetdev_slot_get(widdev),	\
+	    			pciio_widgetdev_func_get(widdev),	\
+				busaddr);				\
 		    break;						\
 		case PCIIO_SPACE_IO:					\
-		    printk(					\
-			    "\tPCI I/O space  Offset 0x%x\n",		\
-			    IOERROR_GETVALUE(ioe, busaddr));		\
+		    printk("\tPCI I/O space  Offset 0x%lx\n", busaddr);	\
 		    break;						\
 		case PCIIO_SPACE_MEM:					\
 		case PCIIO_SPACE_MEM32:					\
 		case PCIIO_SPACE_MEM64:					\
-		    printk(					\
-			    "\tPCI MEM space Offset 0x%x\n",		\
-			    IOERROR_GETVALUE(ioe, busaddr));		\
+		    printk("\tPCI MEM space Offset 0x%lx\n", busaddr);	\
 		    break;						\
 		default:						\
 		    if (win < 6) {					\
-		    printk(					\
-			    "\tPCI Slot %d Func %d Window %d Offset 0x%x\n",\
-	    pciio_widgetdev_slot_get(IOERROR_GETVALUE(ioe, widgetdev)),	\
-	    pciio_widgetdev_func_get(IOERROR_GETVALUE(ioe, widgetdev)),	\
-			    win,					\
-			    IOERROR_GETVALUE(ioe, busaddr));		\
+		    printk("\tPCI Slot %d Func %d Window %ld Offset 0x%lx\n",\
+	    			pciio_widgetdev_slot_get(widdev),	\
+	    			pciio_widgetdev_func_get(widdev),	\
+			    	win,					\
+			    	busaddr);				\
 		    }							\
 		    break;						\
 		}							\
@@ -1129,34 +1451,38 @@
      * and need to construct the slot/space/offset.
      */
 
-    bad_xaddr = IOERROR_GETVALUE(ioe, xtalkaddr);
+    IOERROR_GETVALUE(bad_xaddr, ioe, xtalkaddr);
+
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ERROR_HDLR, pcibr_soft->bs_conn,
+                "pcibr_pioerror: pcibr_soft=0x%x, bad_xaddr=0x%x\n",
+		pcibr_soft, bad_xaddr));
 
     slot = PCIIO_SLOT_NONE;
     func = PCIIO_FUNC_NONE;
     raw_space = PCIIO_SPACE_NONE;
     raw_paddr = 0;
 
-    if ((bad_xaddr >= BRIDGE_TYPE0_CFG_DEV0) &&
-	(bad_xaddr < BRIDGE_TYPE1_CFG)) {
-	raw_paddr = bad_xaddr - BRIDGE_TYPE0_CFG_DEV0;
+    if ((bad_xaddr >= PCIBR_BUS_TYPE0_CFG_DEV0(pcibr_soft)) &&
+	(bad_xaddr < PCIBR_TYPE1_CFG(pcibr_soft))) {
+	raw_paddr = bad_xaddr - PCIBR_BUS_TYPE0_CFG_DEV0(pcibr_soft);
 	slot = raw_paddr / BRIDGE_TYPE0_CFG_SLOT_OFF;
 	raw_paddr = raw_paddr % BRIDGE_TYPE0_CFG_SLOT_OFF;
 	raw_space = PCIIO_SPACE_CFG;
     }
-    if ((bad_xaddr >= BRIDGE_TYPE1_CFG) &&
-	(bad_xaddr < (BRIDGE_TYPE1_CFG + 0x1000))) {
+    if ((bad_xaddr >= PCIBR_TYPE1_CFG(pcibr_soft)) &&
+	(bad_xaddr < (PCIBR_TYPE1_CFG(pcibr_soft) + 0x1000))) {
 	/* Type 1 config space:
 	 * slot and function numbers not known.
 	 * Perhaps we can read them back?
 	 */
-	raw_paddr = bad_xaddr - BRIDGE_TYPE1_CFG;
+	raw_paddr = bad_xaddr - PCIBR_TYPE1_CFG(pcibr_soft);
 	raw_space = PCIIO_SPACE_CFG;
     }
-    if ((bad_xaddr >= BRIDGE_DEVIO0) &&
-	(bad_xaddr < BRIDGE_DEVIO(BRIDGE_DEV_CNT))) {
+    if ((bad_xaddr >= PCIBR_BRIDGE_DEVIO0(pcibr_soft)) &&
+	(bad_xaddr < PCIBR_BRIDGE_DEVIO(pcibr_soft, BRIDGE_DEV_CNT))) {
 	int                     x;
 
-	raw_paddr = bad_xaddr - BRIDGE_DEVIO0;
+	raw_paddr = bad_xaddr - PCIBR_BRIDGE_DEVIO0(pcibr_soft);
 	x = raw_paddr / BRIDGE_DEVIO_OFF;
 	raw_paddr %= BRIDGE_DEVIO_OFF;
 	/* first two devio windows are double-sized */
@@ -1223,7 +1549,9 @@
 	 * going on (no guessing).
 	 */
 
-	for (cs = 0; (cs < 8) && (slot == PCIIO_SLOT_NONE); cs++) {
+	for (cs = pcibr_soft->bs_min_slot; 
+		(cs < PCIBR_NUM_SLOTS(pcibr_soft)) && 
+					(slot == PCIIO_SLOT_NONE); cs++) {
 	    int                     nf = pcibr_soft->bs_slot[cs].bss_ninfo;
 	    pcibr_info_h            pcibr_infoh = pcibr_soft->bs_slot[cs].bss_infos;
 
@@ -1283,7 +1611,8 @@
      * strict count, the excess counts are not a
      * problem.
      */
-    for (cs = 0; cs < 8; ++cs) {
+    for (cs = pcibr_soft->bs_min_slot; 
+				cs < PCIBR_NUM_SLOTS(pcibr_soft); ++cs) {
 	int 		nf = pcibr_soft->bs_slot[cs].bss_ninfo;
 	pcibr_info_h	pcibr_infoh = pcibr_soft->bs_slot[cs].bss_infos;
 
@@ -1313,7 +1642,7 @@
 		wx = PCIIO_SPACE_MEM;
 	    wl = wb + ws;
 	    if ((wx == raw_space) && (raw_paddr >= wb) && (raw_paddr < wl)) {
-		atomicAddInt(map->bp_toc, 1);
+		atomic_inc(&map->bp_toc[0]);
 		if (slot == PCIIO_SLOT_NONE) {
 		    slot = cs;
 		    space = map->bp_space;
@@ -1325,15 +1654,21 @@
 	}
     }
 
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ERROR_HDLR, pcibr_soft->bs_conn,
+                "pcibr_pioerror: offset=0x%x, slot=0x%x, func=0x%x\n",
+		offset, slot, func));
+
     if (space != PCIIO_SPACE_NONE) {
-	if (slot != PCIIO_SLOT_NONE) 
-	    if (func != PCIIO_FUNC_NONE)
+	if (slot != PCIIO_SLOT_NONE) {
+	    if (func != PCIIO_FUNC_NONE) {
 		IOERROR_SETVALUE(ioe, widgetdev, 
 				 pciio_widgetdev_create(slot,func));
-	    else
+	    }
+	    else {
     		IOERROR_SETVALUE(ioe, widgetdev, 
 				 pciio_widgetdev_create(slot,0));
-
+	    }
+	}
 	IOERROR_SETVALUE(ioe, busspace, space);
 	IOERROR_SETVALUE(ioe, busaddr, offset);
     }
@@ -1360,7 +1695,7 @@
 
     if (space == PCIIO_SPACE_NONE) {
 	printk("XIO Bus Error at %s\n"
-		"\taccess to XIO bus offset 0x%x\n"
+		"\taccess to XIO bus offset 0x%lx\n"
 		"\tdoes not correspond to any PCI address\n",
 		pcibr_soft->bs_name, bad_xaddr);
 
@@ -1434,17 +1769,21 @@
 	     */
 
 	    BEM_ADD_STR("Raw info from Bridge/PCI layer:\n");
-	    if (bridge->b_int_status & BRIDGE_ISR_PCIBUS_PIOERR)
-		pcibr_error_dump(pcibr_soft);
+	    if (IS_PIC_SOFT(pcibr_soft)) {
+		if (bridge->p_int_status_64 & (picreg_t)BRIDGE_ISR_PCIBUS_PIOERR)
+		    pcibr_error_dump(pcibr_soft);
+	    } else {
+		if (bridge->b_int_status & (bridgereg_t)BRIDGE_ISR_PCIBUS_PIOERR)
+		    pcibr_error_dump(pcibr_soft);
+	    }
 	    BEM_ADD_SPC(raw_space);
 	    BEM_ADD_VAR(raw_paddr);
 	    if (IOERROR_FIELDVALID(ioe, widgetdev)) {
-
-		slot = pciio_widgetdev_slot_get(IOERROR_GETVALUE(ioe, 
-								 widgetdev));
-		func = pciio_widgetdev_func_get(IOERROR_GETVALUE(ioe, 
-								 widgetdev));
-		if (slot < 8) {
+		short widdev;
+		IOERROR_GETVALUE(widdev, ioe, widgetdev);
+		slot = pciio_widgetdev_slot_get(widdev);
+		func = pciio_widgetdev_func_get(widdev);
+		if (slot < PCIBR_NUM_SLOTS(pcibr_soft)) {
 		    bridgereg_t             device = bridge->b_device[slot].reg;
 
 		    BEM_ADD_VAR(slot);
@@ -1472,11 +1811,12 @@
 	 *      Need a way to ensure we don't inadvertently clear some
 	 *      other errors.
 	 */
-	if (IOERROR_FIELDVALID(ioe, widgetdev))
-	    pcibr_device_disable(pcibr_soft, 
-				 pciio_widgetdev_slot_get(
-					  IOERROR_GETVALUE(ioe, widgetdev)));
-
+	if (IOERROR_FIELDVALID(ioe, widgetdev)) {
+		short widdev;
+		IOERROR_GETVALUE(widdev, ioe, widgetdev);
+		pcibr_device_disable(pcibr_soft, 
+				 pciio_widgetdev_slot_get(widdev));
+	}
 	if (mode == MODE_DEVUSERERROR)
 	    pcibr_error_cleanup(pcibr_soft, error_code);
     }
@@ -1490,8 +1830,6 @@
  *      and try to invoke the appropriate bus service to handle this.
  */
 
-#define BRIDGE_DMA_READ_ERROR (BRIDGE_ISR_RESP_XTLK_ERR|BRIDGE_ISR_XREAD_REQ_TIMEOUT)
-
 int
 pcibr_dmard_error(
 		     pcibr_soft_t pcibr_soft,
@@ -1511,7 +1849,11 @@
      * Look up the address, in the bridge error registers, and
      * take appropriate action
      */
-    ASSERT(IOERROR_GETVALUE(ioe, widgetnum) == pcibr_soft->bs_xid);
+    {
+	short tmp;
+	IOERROR_GETVALUE(tmp, ioe, widgetnum);
+	ASSERT(tmp == pcibr_soft->bs_xid);
+    }
     ASSERT(bridge);
 
     /*
@@ -1540,10 +1882,11 @@
      */
 
     retval = pciio_error_handler(pcibr_vhdl, error_code, mode, ioe);
-    if (retval != IOERROR_HANDLED)
-	pcibr_device_disable(pcibr_soft, 
-			     pciio_widgetdev_slot_get(
-				      IOERROR_GETVALUE(ioe,widgetdev)));
+    if (retval != IOERROR_HANDLED) {
+	short tmp;
+	IOERROR_GETVALUE(tmp, ioe, widgetdev);
+	pcibr_device_disable(pcibr_soft, pciio_widgetdev_slot_get(tmp));
+    }
 
     /*
      * Re-enable bridge to interrupt on BRIDGE_IRR_RESP_BUF_GRP_CLR
@@ -1609,10 +1952,10 @@
     retval = pciio_error_handler(pcibr_vhdl, error_code, mode, ioe);
 
     if (retval != IOERROR_HANDLED) {
-	pcibr_device_disable(pcibr_soft, 
-			     pciio_widgetdev_slot_get(
-				      IOERROR_GETVALUE(ioe, widgetdev)));
+	short tmp;
 
+	IOERROR_GETVALUE(tmp, ioe, widgetdev);
+	pcibr_device_disable(pcibr_soft, pciio_widgetdev_slot_get(tmp));
     }
     return retval;
 }
@@ -1646,6 +1989,10 @@
 
     pcibr_soft = (pcibr_soft_t) einfo;
 
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ERROR_HDLR, pcibr_soft->bs_conn,
+		"pcibr_error_handler: pcibr_soft=0x%x, error_code=0x%x\n",
+		pcibr_soft, error_code));
+
 #ifdef EHE_ENABLE
     xconn_vhdl = pcibr_soft->bs_conn;
     pcibr_vhdl = pcibr_soft->bs_vhdl;
@@ -1664,7 +2011,7 @@
 #endif /* EHE_ENABLE */
 
 #if DEBUG && ERROR_DEBUG
-    printk("%s: pcibr_error_handler\n", pcibr_soft->bs_name);
+    printk( "%s: pcibr_error_handler\n", pcibr_soft->bs_name);
 #endif
 
     ASSERT(pcibr_soft != NULL);
@@ -1704,6 +2051,159 @@
 }
 
 /*
+ * PIC has 2 busses under a single widget so pcibr_attach2 registers this
+ * wrapper function rather than pcibr_error_handler() for PIC.  It's upto
+ * this wrapper to call pcibr_error_handler() with the correct pcibr_soft
+ * struct (ie. the pcibr_soft struct for the bus that saw the error).
+ *
+ * NOTE: this wrapper function is only registered for PIC ASICs and will
+ * only be called for a PIC
+ */
+int
+pcibr_error_handler_wrapper(
+		       error_handler_arg_t einfo,
+		       int error_code,
+		       ioerror_mode_t mode,
+		       ioerror_t *ioe)
+{
+    pcibr_soft_t       pcibr_soft = (pcibr_soft_t) einfo;
+    int                pio_retval = -1; 
+    int		       dma_retval = -1;
+
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ERROR_HDLR, pcibr_soft->bs_conn,
+                "pcibr_error_handler_wrapper: pcibr_soft=0x%x, "
+		"error_code=0x%x\n", pcibr_soft, error_code));
+
+    /*
+     * It is possible that both a IOECODE_PIO and a IOECODE_DMA, and both
+     * IOECODE_READ and IOECODE_WRITE could be set in error_code so we must
+     * process all.  Since we are a wrapper for pcibr_error_handler(), and
+     * will be calling it several times within this routine, we turn off the
+     * error_code bits we don't want it to be processing during that call.
+     */
+    /* 
+     * If the error was a result of a PIO, we tell what bus on the PIC saw
+     * the error from the PIO address.
+     */
+
+#if 0
+    if (mode == MODE_DEVPROBE)
+	pio_retval = IOERROR_HANDLED;
+    else {
+#endif
+    if (error_code & IOECODE_PIO) {
+	iopaddr_t               bad_xaddr;
+	/*
+	 * PIC bus0 PIO space 0x000000 - 0x7fffff or 0x40000000 - 0xbfffffff
+	 *     bus1 PIO space 0x800000 - 0xffffff or 0xc0000000 - 0x13fffffff
+	 */
+	IOERROR_GETVALUE(bad_xaddr, ioe, xtalkaddr);
+	if ((bad_xaddr <= 0x7fffff) ||
+	    ((bad_xaddr >= 0x40000000) && (bad_xaddr <= 0xbfffffff))) {
+	    /* bus 0 saw the error */
+	    pio_retval = pcibr_error_handler((error_handler_arg_t)pcibr_soft,
+			 (error_code & ~IOECODE_DMA), mode, ioe);
+	} else if (((bad_xaddr >= 0x800000) && (bad_xaddr <= 0xffffff)) ||
+	    ((bad_xaddr >= 0xc0000000) && (bad_xaddr <= 0x13fffffff))) {
+	    /* bus 1 saw the error */
+	    pcibr_soft = pcibr_soft->bs_peers_soft;
+	    if (!pcibr_soft) {
+#if DEBUG
+		printk(KERN_WARNING "pcibr_error_handler: "
+			"bs_peers_soft==NULL. bad_xaddr= 0x%x mode= 0x%x\n",
+						bad_xaddr, mode);
+#endif
+  		pio_retval = IOERROR_HANDLED;
+	    } else
+	        pio_retval= pcibr_error_handler((error_handler_arg_t)pcibr_soft,
+			 (error_code & ~IOECODE_DMA), mode, ioe);
+	} else {
+	    printk(KERN_WARNING "pcibr_error_handler_wrapper(): IOECODE_PIO: "
+		    "saw an invalid pio address: 0x%lx\n", bad_xaddr);
+	    pio_retval = IOERROR_UNHANDLED;
+	}
+    } 
+#if 0
+    } /* MODE_DEVPROBE */
+#endif
+
+    /* 
+     * If the error was a result of a DMA Write, we tell what bus on the PIC
+     * saw the error by looking at tnum.
+     */
+    if ((error_code & IOECODE_DMA) && (error_code & IOECODE_WRITE)) {
+	short tmp;
+	/*
+         * For DMA writes [X]Bridge encodes the TNUM field of a Xtalk
+         * packet like this:
+         *              bits  value
+         *              4:3   10b
+         *              2:0   device number
+         *
+         * BUT PIC needs the bus number so it does this:
+         *              bits  value
+         *              4:3   10b
+         *              2     busnumber
+         *              1:0   device number
+	 *
+	 * Pull out the bus number from `tnum' and reset the `widgetdev'
+	 * since when hubiio_crb_error_handler() set `widgetdev' it had
+	 * no idea if it was a PIC or a BRIDGE ASIC so it set it based
+	 * off bits 2:0
+	 */
+	IOERROR_GETVALUE(tmp, ioe, tnum);
+	IOERROR_SETVALUE(ioe, widgetdev, (tmp & 0x3));
+	if ((tmp & 0x4) == 0) {
+	    /* bus 0 saw the error. */
+	    dma_retval = pcibr_error_handler((error_handler_arg_t)pcibr_soft,
+			 (error_code & ~(IOECODE_PIO|IOECODE_READ)), mode, ioe);
+	} else {
+	    /* bus 1 saw the error */
+	    pcibr_soft = pcibr_soft->bs_peers_soft;
+	    dma_retval = pcibr_error_handler((error_handler_arg_t)pcibr_soft,
+			 (error_code & ~(IOECODE_PIO|IOECODE_READ)), mode, ioe);
+	}
+    } 
+    
+    /* 
+     * If the error was a result of a DMA READ, XXX ???
+     */
+    if ((error_code & IOECODE_DMA) && (error_code & IOECODE_READ)) {
+	/*
+	 * A DMA Read error will result in a BRIDGE_ISR_RESP_XTLK_ERR
+	 * or BRIDGE_ISR_BAD_XRESP_PKT bridge error interrupt which 
+	 * are fatal interrupts (ie. BRIDGE_ISR_ERROR_FATAL) causing
+	 * pcibr_error_intr_handler() to panic the system.  So is the
+	 * error handler even going to get called???  It appears that
+	 * the pcibr_dmard_error() attempts to clear the interrupts
+	 * so pcibr_error_intr_handler() won't see them, but there
+	 * appears to be nothing to prevent pcibr_error_intr_handler()
+	 * from running before pcibr_dmard_error() has a chance to
+	 * clear the interrupt.
+	 *
+	 * Since we'll be panicing anyways, don't bother handling the
+	 * error for now until we can fix this race condition mentioned
+	 * above.
+	 */
+	dma_retval = IOERROR_UNHANDLED;
+    } 
+    
+    /* XXX: pcibr_error_handler() should probably do the same thing, it over-
+     * write it's return value as it processes the different "error_code"s.
+     */
+    if ((pio_retval == -1) && (dma_retval == -1)) {
+    	return IOERROR_BADERRORCODE;
+    } else if (dma_retval != IOERROR_HANDLED) {
+	return dma_retval;
+    } else if (pio_retval != IOERROR_HANDLED) {
+	return pio_retval;
+    } else {
+	return IOERROR_HANDLED;
+    }
+}
+
+
+/*
  * Reenable a device after handling the error.
  * This is called by the lower layers when they wish to be reenabled
  * after an error.
@@ -1715,7 +2215,7 @@
 pcibr_error_devenable(devfs_handle_t pconn_vhdl, int error_code)
 {
     pciio_info_t            pciio_info = pciio_info_get(pconn_vhdl);
-    pciio_slot_t            pciio_slot = pciio_info_slot_get(pciio_info);
+    pciio_slot_t            pciio_slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
     pcibr_soft_t            pcibr_soft = (pcibr_soft_t) pciio_info_mfast_get(pciio_info);
 
     ASSERT(error_code & IOECODE_PIO);
diff -Nru a/arch/ia64/sn/io/sn2/pcibr/pcibr_hints.c b/arch/ia64/sn/io/sn2/pcibr/pcibr_hints.c
--- a/arch/ia64/sn/io/sn2/pcibr/pcibr_hints.c	Mon Dec 23 21:22:00 2002
+++ b/arch/ia64/sn/io/sn2/pcibr/pcibr_hints.c	Mon Dec 23 21:22:00 2002
@@ -85,11 +85,9 @@
 
     if (hint)
 	hint->ph_rrb_fixed = mask;
-#if DEBUG
     else
-	printk("pcibr_hints_fix_rrbs: pcibr_hints_get failed at\n"
-		"\t%p\n", xconn_vhdl);
-#endif
+        PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_HINTS, xconn_vhdl,
+		    "pcibr_hints_fix_rrbs: pcibr_hints_get failed\n"));
 }
 
 void
@@ -107,11 +105,9 @@
 
     if (hint)
 	hint->ph_host_slot[guest] = host + 1;
-#if DEBUG
     else
-	printk("pcibr_hints_dualslot: pcibr_hints_get failed at\n"
-		"\t%p\n", xconn_vhdl);
-#endif
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_HINTS, xconn_vhdl,
+		    "pcibr_hints_dualslot: pcibr_hints_get failed\n"));
 }
 
 void
@@ -122,11 +118,9 @@
 
     if (hint)
 	hint->ph_intr_bits = xxx_intr_bits;
-#if DEBUG
     else
-	printk("pcibr_hints_intr_bits: pcibr_hints_get failed at\n"
-	       "\t%p\n", xconn_vhdl);
-#endif
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_HINTS, xconn_vhdl,
+		    "pcibr_hints_intr_bits: pcibr_hints_get failed\n"));
 }
 
 void
@@ -145,11 +139,9 @@
 
     if (hint)
 	hint->ph_hands_off = 1;
-#if DEBUG
     else
-	printk("pcibr_hints_handsoff: pcibr_hints_get failed at\n"
-		"\t%p\n", xconn_vhdl);
-#endif
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_HINTS, xconn_vhdl,
+		    "pcibr_hints_handsoff: pcibr_hints_get failed\n"));
 }
 
 void
@@ -161,13 +153,11 @@
     char                    sdname[16];
     devfs_handle_t            pconn_vhdl = GRAPH_VERTEX_NONE;
 
-    sprintf(sdname, "pci/%d", slot);
+    sprintf(sdname, "%s/%d", EDGE_LBL_PCI, slot);
     (void) hwgraph_path_add(xconn_vhdl, sdname, &pconn_vhdl);
     if (pconn_vhdl == GRAPH_VERTEX_NONE) {
-#if DEBUG
-	printk("pcibr_hints_subdevs: hwgraph_path_create failed at\n"
-		"\t%p (seeking %s)\n", xconn_vhdl, sdname);
-#endif
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_HINTS, xconn_vhdl,
+		    "pcibr_hints_subdevs: hwgraph_path_create failed\n"));
 	return;
     }
     hwgraph_info_get_LBL(pconn_vhdl, INFO_LBL_SUBDEVS, &ainfo);
@@ -176,10 +166,8 @@
 
 	NEW(subdevp);
 	if (!subdevp) {
-#if DEBUG
-	    printk("pcibr_hints_subdevs: subdev ptr alloc failed at\n"
-		    "\t%p\n", pconn_vhdl);
-#endif
+	    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_HINTS, xconn_vhdl,
+			"pcibr_hints_subdevs: subdev ptr alloc failed\n"));
 	    return;
 	}
 	*subdevp = subdevs;
@@ -189,16 +177,12 @@
 	    return;
 	DEL(subdevp);
 	if (ainfo == (arbitrary_info_t) NULL) {
-#if DEBUG
-	    printk("pcibr_hints_subdevs: null subdevs ptr at\n"
-		    "\t%p\n", pconn_vhdl);
-#endif
+	    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_HINTS, xconn_vhdl,
+			"pcibr_hints_subdevs: null subdevs ptr\n"));
 	    return;
 	}
-#if DEBUG
-	printk("pcibr_subdevs_get: dup subdev add_LBL at\n"
-		"\t%p\n", pconn_vhdl);
-#endif
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_HINTS, xconn_vhdl,
+		    "pcibr_subdevs_get: dup subdev add_LBL\n"));
     }
     *(uint64_t *) ainfo = subdevs;
 }
diff -Nru a/arch/ia64/sn/io/sn2/pcibr/pcibr_intr.c b/arch/ia64/sn/io/sn2/pcibr/pcibr_intr.c
--- a/arch/ia64/sn/io/sn2/pcibr/pcibr_intr.c	Mon Dec 23 21:21:58 2002
+++ b/arch/ia64/sn/io/sn2/pcibr/pcibr_intr.c	Mon Dec 23 21:21:58 2002
@@ -4,11 +4,10 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (C) 2001 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 2001-2002 Silicon Graphics, Inc. All rights reserved.
  */
 
 #include <linux/types.h>
-#include <linux/config.h>
 #include <linux/slab.h>
 #include <linux/module.h>
 #include <asm/sn/sgi.h>
@@ -39,11 +38,11 @@
 #define rmalloc atealloc
 #endif
 
-unsigned		pcibr_intr_bits(pciio_info_t info, pciio_intr_line_t lines);
+unsigned		pcibr_intr_bits(pciio_info_t info, pciio_intr_line_t lines, int nslots);
 pcibr_intr_t            pcibr_intr_alloc(devfs_handle_t, device_desc_t, pciio_intr_line_t, devfs_handle_t);
 void                    pcibr_intr_free(pcibr_intr_t);
 void              pcibr_setpciint(xtalk_intr_t);
-int                     pcibr_intr_connect(pcibr_intr_t);
+int                     pcibr_intr_connect(pcibr_intr_t, intr_func_t, intr_arg_t);
 void                    pcibr_intr_disconnect(pcibr_intr_t);
 
 devfs_handle_t            pcibr_intr_cpu_get(pcibr_intr_t);
@@ -58,9 +57,9 @@
 
 unsigned
 pcibr_intr_bits(pciio_info_t info,
-		pciio_intr_line_t lines)
+		pciio_intr_line_t lines, int nslots)
 {
-    pciio_slot_t            slot = pciio_info_slot_get(info);
+    pciio_slot_t            slot = PCIBR_INFO_SLOT_GET_INT(info);
     unsigned		    bbits = 0;
 
     /*
@@ -79,7 +78,7 @@
      *      7       7 3 7 3
      */
 
-    if (slot < 8) {
+    if (slot < nslots) {
 	if (lines & (PCIIO_INTR_LINE_A| PCIIO_INTR_LINE_C))
 	    bbits |= 1 << slot;
 	if (lines & (PCIIO_INTR_LINE_B| PCIIO_INTR_LINE_D))
@@ -165,20 +164,26 @@
  *	to check if a specific Bridge b_int_status bit is set, and if so,
  *	cause the setting of the corresponding interrupt bit.
  *
- *	On a XBridge (IP35), we do this by writing the appropriate Bridge Force 
- *	Interrupt register.
+ *	On a XBridge (SN1), we do this by writing the appropriate Bridge Force 
+ *	Interrupt register. On SN0, or SN1 with an older Bridge, the Bridge 
+ *	Force Interrupt register does not exist, so we write the Hub 
+ *	INT_PEND_MOD register directly. Likewise for Octane, where we write the 
+ *	Heart Set Interrupt Status register directly.
  */
 void
 pcibr_force_interrupt(pcibr_intr_wrap_t wrap)
 {
+#ifdef PIC_LATER
 	unsigned	bit;
 	pcibr_soft_t    pcibr_soft = wrap->iw_soft;
 	bridge_t       *bridge = pcibr_soft->bs_base;
-	cpuid_t cpuvertex_to_cpuid(devfs_handle_t vhdl);
 
-	bit = wrap->iw_intr;
+	bit = wrap->iw_ibit;
 
-	if (pcibr_soft->bs_xbridge) {
+	PCIBR_DEBUG((PCIBR_DEBUG_INTR, pcibr_soft->bs_vhdl,
+		    "pcibr_force_interrupt: bit=0x%x\n", bit));
+
+	if (IS_XBRIDGE_OR_PIC_SOFT(pcibr_soft)) {
 	    bridge->b_force_pin[bit].intr = 1;
 	} else if ((1 << bit) & *wrap->iw_stat) {
 	    cpuid_t	    cpu;
@@ -187,11 +192,10 @@
 				pcibr_soft->bs_intr[bit].bsi_xtalk_intr;
 
 	    intr_bit = (short) xtalk_intr_vector_get(xtalk_intr);
-	    cpu = cpuvertex_to_cpuid(xtalk_intr_cpu_get(xtalk_intr));
-#if defined(CONFIG_IA64_SGI_SN1)
+	    cpu = xtalk_intr_cpuid_get(xtalk_intr);
 	    REMOTE_CPU_SEND_INTR(cpu, intr_bit);
-#endif
 	}
+#endif	/* PIC_LATER */
 }
 
 /*ARGSUSED */
@@ -202,12 +206,11 @@
 		 devfs_handle_t owner_dev)
 {
     pcibr_info_t            pcibr_info = pcibr_info_get(pconn_vhdl);
-    pciio_slot_t            pciio_slot = pcibr_info->f_slot;
+    pciio_slot_t            pciio_slot = PCIBR_INFO_SLOT_GET_INT(pcibr_info);
     pcibr_soft_t            pcibr_soft = (pcibr_soft_t) pcibr_info->f_mfast;
     devfs_handle_t            xconn_vhdl = pcibr_soft->bs_conn;
     bridge_t               *bridge = pcibr_soft->bs_base;
     int                     is_threaded = 0;
-    int                     thread_swlevel;
 
     xtalk_intr_t           *xtalk_intr_p;
     pcibr_intr_t           *pcibr_intr_p;
@@ -222,41 +225,32 @@
     pcibr_intr_list_t       intr_list;
     bridgereg_t             int_dev;
 
-#if DEBUG && INTR_DEBUG
-    printk("%v: pcibr_intr_alloc\n"
-	    "%v:%s%s%s%s%s\n",
-	    owner_dev, pconn_vhdl,
-	    !(lines & 15) ? " No INTs?" : "",
-	    lines & 1 ? " INTA" : "",
-	    lines & 2 ? " INTB" : "",
-	    lines & 4 ? " INTC" : "",
-	    lines & 8 ? " INTD" : "");
-#endif
+
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ALLOC, pconn_vhdl,
+    		"pcibr_intr_alloc: %s%s%s%s%s\n",
+		!(lines & 15) ? " No INTs?" : "",
+		lines & 1 ? " INTA" : "",
+		lines & 2 ? " INTB" : "",
+		lines & 4 ? " INTC" : "",
+		lines & 8 ? " INTD" : ""));
 
     NEW(pcibr_intr);
     if (!pcibr_intr)
 	return NULL;
 
-    if (dev_desc) {
-	cpuid_t intr_target_from_desc(device_desc_t, int);
-    } else {
-	extern int default_intr_pri;
-
-	is_threaded = 1; /* PCI interrupts are threaded, by default */
-	thread_swlevel = default_intr_pri;
-    }
-
     pcibr_intr->bi_dev = pconn_vhdl;
     pcibr_intr->bi_lines = lines;
     pcibr_intr->bi_soft = pcibr_soft;
     pcibr_intr->bi_ibits = 0;		/* bits will be added below */
+    pcibr_intr->bi_func = 0;            /* unset until connect */
+    pcibr_intr->bi_arg = 0;             /* unset until connect */
     pcibr_intr->bi_flags = is_threaded ? 0 : PCIIO_INTR_NOTHREAD;
     pcibr_intr->bi_mustruncpu = CPU_NONE;
     pcibr_intr->bi_ibuf.ib_in = 0;
     pcibr_intr->bi_ibuf.ib_out = 0;
     mutex_spinlock_init(&pcibr_intr->bi_ibuf.ib_lock);
-
-    pcibr_int_bits = pcibr_soft->bs_intr_bits((pciio_info_t)pcibr_info, lines);
+    pcibr_int_bits = pcibr_soft->bs_intr_bits((pciio_info_t)pcibr_info, lines, 
+		PCIBR_NUM_SLOTS(pcibr_soft));
 
 
     /*
@@ -265,9 +259,8 @@
      * to, and make sure there are xtalk resources
      * allocated for it.
      */
-#if DEBUG && INTR_DEBUG
-    printk("pcibr_int_bits: 0x%X\n", pcibr_int_bits);
-#endif 
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ALLOC, pconn_vhdl,
+		"pcibr_intr_alloc: pcibr_int_bits: 0x%x\n", pcibr_int_bits));
     for (pcibr_int_bit = 0; pcibr_int_bit < 8; pcibr_int_bit ++) {
 	if (pcibr_int_bits & (1 << pcibr_int_bit)) {
 	    xtalk_intr_p = &pcibr_soft->bs_intr[pcibr_int_bit].bsi_xtalk_intr;
@@ -282,10 +275,9 @@
 		 *    ordering problems with DMA, completion interrupts, and error
 		 *    interrupts. (Use of xconn_vhdl forces this.)
 		 *
-		 * 2) On IP35, addressing constraints on IP35 and Bridge force
+		 * 2) On SN1, addressing constraints on SN1 and Bridge force
 		 *    us to use a single PI number for all interrupts from a
-		 *    single Bridge. (IP35-specific code forces this, and we
-		 *    verify in pcibr_setwidint.)
+		 *    single Bridge. (SN1-specific code forces this).
 		 */
 
 		/*
@@ -298,9 +290,9 @@
 		 */
 		xtalk_intr = xtalk_intr_alloc_nothd(xconn_vhdl, dev_desc, 
 			owner_dev);
-#if DEBUG && INTR_DEBUG
-		printk("%v: xtalk_intr=0x%X\n", xconn_vhdl, xtalk_intr);
-#endif
+
+		PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ALLOC, pconn_vhdl,
+			    "pcibr_intr_alloc: xtalk_intr=0x%x\n", xtalk_intr));
 
 		/* both an assert and a runtime check on this:
 		 * we need to check in non-DEBUG kernels, and
@@ -338,10 +330,9 @@
 		    int_dev |= pciio_slot << BRIDGE_INT_DEV_SHFT(pcibr_int_bit);
 		    bridge->b_int_device = int_dev;	/* XXXMP */
 
-#if DEBUG && INTR_DEBUG
-		    printk("%v: bridge intr bit %d clears my wrb\n",
-			    pconn_vhdl, pcibr_int_bit);
-#endif
+		    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ALLOC, pconn_vhdl,
+		    		"bridge intr bit %d clears my wrb\n",
+				pcibr_int_bit));
 		} else {
 		    /* someone else got one allocated first;
 		     * free the one we just created, and
@@ -373,25 +364,17 @@
 	    intr_entry->il_wrbf = &(bridge->b_wr_req_buf[pciio_slot].reg);
 	    intr_list_p = 
 		&pcibr_soft->bs_intr[pcibr_int_bit].bsi_pcibr_intr_wrap.iw_list;
-#if DEBUG && INTR_DEBUG
-#if defined(SUPPORT_PRINTING_V_FORMAT)
-	    printk("0x%x: Bridge bit %d wrap=0x%x\n",
-		pconn_vhdl, pcibr_int_bit,
-		pcibr_soft->bs_intr[pcibr_int_bit].bsi_pcibr_intr_wrap);
-#else
-	    printk("%v: Bridge bit %d wrap=0x%x\n",
-		pconn_vhdl, pcibr_int_bit,
-		pcibr_soft->bs_intr[pcibr_int_bit].bsi_pcibr_intr_wrap);
-#endif
-#endif
+
+	    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ALLOC, pconn_vhdl,
+			"Bridge bit 0x%x wrap=0x%x\n", pcibr_int_bit,
+			pcibr_soft->bs_intr[pcibr_int_bit].bsi_pcibr_intr_wrap));
 
 	    if (compare_and_swap_ptr((void **) intr_list_p, NULL, intr_entry)) {
 		/* we are the first interrupt on this bridge bit.
 		 */
-#if DEBUG && INTR_DEBUG
-		printk("%v INT 0x%x (bridge bit %d) allocated [FIRST]\n",
-			pconn_vhdl, pcibr_int_bits, pcibr_int_bit);
-#endif
+		PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ALLOC, pconn_vhdl,
+			    "INT 0x%x (bridge bit %d) allocated [FIRST]\n",
+			    pcibr_int_bits, pcibr_int_bit));
 		continue;
 	    }
 	    intr_list = *intr_list_p;
@@ -402,10 +385,9 @@
 		 * don't need our intr_entry.
 		 */
 		DEL(intr_entry);
-#if DEBUG && INTR_DEBUG
-		printk("%v INT 0x%x (bridge bit %d) replaces erased first\n",
-			pconn_vhdl, pcibr_int_bits, pcibr_int_bit);
-#endif
+		PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ALLOC, pconn_vhdl,
+			    "INT 0x%x (bridge bit %d) replaces erased first\n",
+			    pcibr_int_bits, pcibr_int_bit));
 		continue;
 	    }
 	    intr_list_p = &intr_list->il_next;
@@ -413,10 +395,9 @@
 		/* we are the new second interrupt on this bit.
 		 */
 		pcibr_soft->bs_intr[pcibr_int_bit].bsi_pcibr_intr_wrap.iw_shared = 1;
-#if DEBUG && INTR_DEBUG
-		printk("%v INT 0x%x (bridge bit %d) is new SECOND\n",
-			pconn_vhdl, pcibr_int_bits, pcibr_int_bit);
-#endif
+		PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ALLOC, pconn_vhdl,
+			    "INT 0x%x (bridge bit %d) is new SECOND\n",
+			    pcibr_int_bits, pcibr_int_bit));
 		continue;
 	    }
 	    while (1) {
@@ -427,20 +408,19 @@
 		     * don't need our intr_entry.
 		     */
 		    DEL(intr_entry);
-#if DEBUG && INTR_DEBUG
-		    printk("%v INT 0x%x (bridge bit %d) replaces erased Nth\n",
-			    pconn_vhdl, pcibr_int_bits, pcibr_int_bit);
-#endif
+
+		    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ALLOC, pconn_vhdl,
+				"INT 0x%x (bridge bit %d) replaces erase Nth\n",
+				pcibr_int_bits, pcibr_int_bit));
 		    break;
 		}
 		intr_list_p = &intr_list->il_next;
 		if (compare_and_swap_ptr((void **) intr_list_p, NULL, intr_entry)) {
 		    /* entry appended to share list
 		     */
-#if DEBUG && INTR_DEBUG
-		    printk("%v INT 0x%x (bridge bit %d) is new Nth\n",
-			    pconn_vhdl, pcibr_int_bits, pcibr_int_bit);
-#endif
+		    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ALLOC, pconn_vhdl,
+				"INT 0x%x (bridge bit %d) is new Nth\n",
+				pcibr_int_bits, pcibr_int_bit));
 		    break;
 		}
 		/* step to next record in chain
@@ -479,10 +459,11 @@
 		if (compare_and_swap_ptr((void **) &intr_list->il_intr, 
 					 pcibr_intr, 
 					 NULL)) {
-#if DEBUG && INTR_DEBUG
-		    printk("%s: cleared a handler from bit %d\n",
-			    pcibr_soft->bs_name, pcibr_int_bit);
-#endif
+
+		    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ALLOC, 
+				pcibr_intr->bi_dev,
+		    		"pcibr_intr_free: cleared hdlr from bit 0x%x\n",
+				pcibr_int_bit));
 		}
 	    /* If this interrupt line is not being shared between multiple
 	     * devices release the xtalk interrupt resources.
@@ -515,34 +496,49 @@
 void
 pcibr_setpciint(xtalk_intr_t xtalk_intr)
 {
-    iopaddr_t               addr = xtalk_intr_addr_get(xtalk_intr);
-    xtalk_intr_vector_t     vect = xtalk_intr_vector_get(xtalk_intr);
-    bridgereg_t            *int_addr = (bridgereg_t *)
-    xtalk_intr_sfarg_get(xtalk_intr);
-
-    *int_addr = ((BRIDGE_INT_ADDR_HOST & (addr >> 30)) |
-		 (BRIDGE_INT_ADDR_FLD & vect));
+    iopaddr_t		 addr;
+    xtalk_intr_vector_t	 vect;
+    devfs_handle_t	 vhdl;
+    bridge_t		*bridge;
+
+    addr = xtalk_intr_addr_get(xtalk_intr);
+    vect = xtalk_intr_vector_get(xtalk_intr);
+    vhdl = xtalk_intr_dev_get(xtalk_intr);
+    bridge = (bridge_t *)xtalk_piotrans_addr(vhdl, 0, 0, sizeof(bridge_t), 0);
+
+    if (is_pic(bridge)) {
+	picreg_t	*int_addr;
+	int_addr = (picreg_t *)xtalk_intr_sfarg_get(xtalk_intr);
+	*int_addr = ((PIC_INT_ADDR_FLD & ((uint64_t)vect << 48)) |
+		     (PIC_INT_ADDR_HOST & addr));
+    } else {
+	bridgereg_t	*int_addr;
+	int_addr = (bridgereg_t *)xtalk_intr_sfarg_get(xtalk_intr);
+	*int_addr = ((BRIDGE_INT_ADDR_HOST & (addr >> 30)) |
+		     (BRIDGE_INT_ADDR_FLD & vect));
+    }
 }
 
 /*ARGSUSED */
 int
-pcibr_intr_connect(pcibr_intr_t pcibr_intr)
+pcibr_intr_connect(pcibr_intr_t pcibr_intr, intr_func_t intr_func, intr_arg_t intr_arg)
 {
     pcibr_soft_t            pcibr_soft = pcibr_intr->bi_soft;
     bridge_t               *bridge = pcibr_soft->bs_base;
     unsigned                pcibr_int_bits = pcibr_intr->bi_ibits;
     unsigned                pcibr_int_bit;
-    bridgereg_t             b_int_enable;
+    uint64_t		    int_enable;
     unsigned long           s;
 
     if (pcibr_intr == NULL)
 	return -1;
 
-#if DEBUG && INTR_DEBUG
-    printk("%v: pcibr_intr_connect\n",
-	    pcibr_intr->bi_dev);
-#endif
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ALLOC, pcibr_intr->bi_dev,
+		"pcibr_intr_connect: intr_func=0x%x\n",
+		pcibr_intr));
 
+    pcibr_intr->bi_func = intr_func;
+    pcibr_intr->bi_arg = intr_arg;
     *((volatile unsigned *)&pcibr_intr->bi_flags) |= PCIIO_INTR_CONNECTED;
 
     /*
@@ -553,9 +549,12 @@
      */
     for (pcibr_int_bit = 0; pcibr_int_bit < 8; pcibr_int_bit++)
 	if (pcibr_int_bits & (1 << pcibr_int_bit)) {
+            pcibr_intr_wrap_t       intr_wrap;
 	    xtalk_intr_t            xtalk_intr;
+            void                   *int_addr;
 
 	    xtalk_intr = pcibr_soft->bs_intr[pcibr_int_bit].bsi_xtalk_intr;
+	    intr_wrap = &pcibr_soft->bs_intr[pcibr_int_bit].bsi_pcibr_intr_wrap;
 
 	    /*
 	     * If this interrupt line is being shared and the connect has
@@ -569,21 +568,43 @@
 	     * Use the pcibr wrapper function to handle all Bridge interrupts
 	     * regardless of whether the interrupt line is shared or not.
 	     */
-	    xtalk_intr_connect(xtalk_intr, (xtalk_intr_setfunc_t) pcibr_setpciint,
-			       (void *)&(bridge->b_int_addr[pcibr_int_bit].addr));
+	    if (IS_PIC_SOFT(pcibr_soft)) 
+		int_addr = (void *)&(bridge->p_int_addr_64[pcibr_int_bit]);
+	    else
+		int_addr = (void *)&(bridge->b_int_addr[pcibr_int_bit].addr);
+
+	    xtalk_intr_connect(xtalk_intr, pcibr_intr_func, (intr_arg_t) intr_wrap,
+					(xtalk_intr_setfunc_t) pcibr_setpciint,
+			       			(void *)int_addr);
+
 	    pcibr_soft->bs_intr[pcibr_int_bit].bsi_pcibr_intr_wrap.iw_connected = 1;
 
-#if DEBUG && INTR_DEBUG
-	    printk("%v bridge bit %d wrapper connected\n",
-		    pcibr_intr->bi_dev, pcibr_int_bit);
-#endif
+	    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ALLOC, pcibr_intr->bi_dev,
+			"pcibr_setpciint: int_addr=0x%x, *int_addr=0x%x, "
+			"pcibr_int_bit=0x%x\n", int_addr,
+			(is_pic(bridge) ? 
+			 *(picreg_t *)int_addr : *(bridgereg_t *)int_addr),
+			pcibr_int_bit));
 	}
-    s = pcibr_lock(pcibr_soft);
-    b_int_enable = bridge->b_int_enable;
-    b_int_enable |= pcibr_int_bits;
-    bridge->b_int_enable = b_int_enable;
-    bridge->b_wid_tflush;		/* wait until Bridge PIO complete */
-    pcibr_unlock(pcibr_soft, s);
+
+	/* PIC WAR. PV# 854697
+	 * On PIC we must write 64-bit MMRs with 64-bit stores
+	 */
+	s = pcibr_lock(pcibr_soft);
+	if (IS_PIC_SOFT(pcibr_soft) &&
+			PCIBR_WAR_ENABLED(PV854697, pcibr_soft)) {
+	    int_enable = bridge->p_int_enable_64;
+	    int_enable |= pcibr_int_bits;
+	    bridge->p_int_enable_64 = int_enable;
+	} else {
+	    bridgereg_t int_enable;
+
+	    int_enable = bridge->b_int_enable;
+	    int_enable |= pcibr_int_bits;
+	    bridge->b_int_enable = int_enable;
+	}
+	bridge->b_wid_tflush;	/* wait until Bridge PIO complete */
+	pcibr_unlock(pcibr_soft, s);
 
     return 0;
 }
@@ -596,13 +617,15 @@
     bridge_t               *bridge = pcibr_soft->bs_base;
     unsigned                pcibr_int_bits = pcibr_intr->bi_ibits;
     unsigned                pcibr_int_bit;
-    bridgereg_t             b_int_enable;
+    pcibr_intr_wrap_t       intr_wrap;
+    uint64_t                int_enable;
     unsigned long           s;
 
     /* Stop calling the function. Now.
      */
     *((volatile unsigned *)&pcibr_intr->bi_flags) &= ~PCIIO_INTR_CONNECTED;
-
+    pcibr_intr->bi_func = 0;
+    pcibr_intr->bi_arg = 0;
     /*
      * For each PCI interrupt line requested, figure
      * out which Bridge PCI Interrupt Line it maps
@@ -619,15 +642,30 @@
     if (!pcibr_int_bits)
 	return;
 
+    /* PIC WAR. PV# 854697
+     * On PIC we must write 64-bit MMRs with 64-bit stores
+     */
     s = pcibr_lock(pcibr_soft);
-    b_int_enable = bridge->b_int_enable;
-    b_int_enable &= ~pcibr_int_bits;
-    bridge->b_int_enable = b_int_enable;
+    if (IS_PIC_SOFT(pcibr_soft) && PCIBR_WAR_ENABLED(PV854697, pcibr_soft)) {
+	int_enable = bridge->p_int_enable_64;
+	int_enable &= ~pcibr_int_bits;
+	bridge->p_int_enable_64 = int_enable;
+    } else {
+	int_enable = (uint64_t)bridge->b_int_enable;
+	int_enable &= ~pcibr_int_bits;
+	bridge->b_int_enable = (bridgereg_t)int_enable;
+    }
     bridge->b_wid_tflush;		/* wait until Bridge PIO complete */
     pcibr_unlock(pcibr_soft, s);
 
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ALLOC, pcibr_intr->bi_dev,
+		"pcibr_intr_disconnect: disabled int_bits=0x%x\n", 
+		pcibr_int_bits));
+
     for (pcibr_int_bit = 0; pcibr_int_bit < 8; pcibr_int_bit++)
 	if (pcibr_int_bits & (1 << pcibr_int_bit)) {
+            void                   *int_addr;
+
 	    /* if the interrupt line is now shared,
 	     * do not disconnect it.
 	     */
@@ -637,10 +675,9 @@
 	    xtalk_intr_disconnect(pcibr_soft->bs_intr[pcibr_int_bit].bsi_xtalk_intr);
 	    pcibr_soft->bs_intr[pcibr_int_bit].bsi_pcibr_intr_wrap.iw_connected = 0;
 
-#if DEBUG && INTR_DEBUG
-	    printk("%s: xtalk disconnect done for Bridge bit %d\n",
-		pcibr_soft->bs_name, pcibr_int_bit);
-#endif
+	    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ALLOC, pcibr_intr->bi_dev,
+			"pcibr_intr_disconnect: disconnect int_bits=0x%x\n",
+			pcibr_int_bits));
 
 	    /* if we are sharing the interrupt line,
 	     * connect us up; this closes the hole
@@ -650,9 +687,22 @@
 	    if (!pcibr_soft->bs_intr[pcibr_int_bit].bsi_pcibr_intr_wrap.iw_shared)
 		continue;
 
+	    intr_wrap = &pcibr_soft->bs_intr[pcibr_int_bit].bsi_pcibr_intr_wrap;
+            if (!pcibr_soft->bs_intr[pcibr_int_bit].bsi_pcibr_intr_wrap.iw_shared)
+                continue;
+
+            if (IS_PIC_SOFT(pcibr_soft))
+                int_addr = (void *)&(bridge->p_int_addr_64[pcibr_int_bit]);
+            else
+                int_addr = (void *)&(bridge->b_int_addr[pcibr_int_bit].addr);
+
 	    xtalk_intr_connect(pcibr_soft->bs_intr[pcibr_int_bit].bsi_xtalk_intr,
+				pcibr_intr_func, (intr_arg_t) intr_wrap,
 			       (xtalk_intr_setfunc_t)pcibr_setpciint,
-			       (void *) &(bridge->b_int_addr[pcibr_int_bit].addr));
+			       (void *)pcibr_int_bit);
+	    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_INTR_ALLOC, pcibr_intr->bi_dev,
+			"pcibr_intr_disconnect: now-sharing int_bits=0x%x\n",
+			pcibr_int_bit));
 	}
 }
 
@@ -729,6 +779,10 @@
     bridge->b_wid_int_upper = NEW_b_wid_int_upper;
     bridge->b_wid_int_lower = NEW_b_wid_int_lower;
     bridge->b_int_host_err = vect;
+
+printk("pcibr_setwidint: b_wid_int_upper 0x%x b_wid_int_lower 0x%x b_int_host_err 0x%x\n",
+	NEW_b_wid_int_upper, NEW_b_wid_int_lower, vect);
+
 }
 
 /*
@@ -752,6 +806,9 @@
 				   XTALK_ADDR_TO_UPPER(addr));
 	bridge->b_wid_int_lower = XTALK_ADDR_TO_LOWER(addr);
 	bridge->b_int_host_err = vect;
+printk("pcibr_xintr_preset: b_wid_int_upper 0x%lx b_wid_int_lower 0x%lx b_int_host_err 0x%x\n",
+	( (0x000F0000 & (targ << 16)) | XTALK_ADDR_TO_UPPER(addr)),
+	XTALK_ADDR_TO_LOWER(addr), vect);
 
 	/* turn on all interrupts except
 	 * the PCI interrupt requests,
@@ -794,12 +851,37 @@
 {
     pcibr_intr_wrap_t       wrap = (pcibr_intr_wrap_t) arg;
     reg_p                   wrbf;
+    intr_func_t             func;
     pcibr_intr_t            intr;
     pcibr_intr_list_t       list;
     int                     clearit;
     int			    do_nonthreaded = 1;
     int			    is_threaded = 0;
     int			    x = 0;
+    pcibr_soft_t            pcibr_soft = wrap->iw_soft;
+    bridge_t               *bridge = pcibr_soft->bs_base;
+    uint64_t		    p_enable = pcibr_soft->bs_int_enable;
+    int			    bit = wrap->iw_ibit;
+
+	/*
+	 * PIC WAR.  PV#855272
+	 * Early attempt at a workaround for the runaway
+	 * interrupt problem.   Briefly disable the enable bit for
+	 * this device.
+	 */
+	if (IS_PIC_SOFT(pcibr_soft) &&
+			PCIBR_WAR_ENABLED(PV855272, pcibr_soft)) {
+		unsigned s;
+
+		/* disable-enable interrupts for this bridge pin */
+
+		p_enable &= ~(1 << bit);
+	        s = pcibr_lock(pcibr_soft);
+		bridge->p_int_enable_64 = p_enable;
+		p_enable |= (1 << bit);
+		bridge->p_int_enable_64 = p_enable;
+	        pcibr_unlock(pcibr_soft, s);
+	}
 
 	/*
 	 * If any handler is still running from a previous interrupt
@@ -821,35 +903,31 @@
 	clearit = 1;
 	while (do_nonthreaded) {
 	    for (list = wrap->iw_list; list != NULL; list = list->il_next) {
-		if ((intr = list->il_intr) &&
-		    (intr->bi_flags & PCIIO_INTR_CONNECTED)) {
+		if ((intr = list->il_intr) && (intr->bi_flags & PCIIO_INTR_CONNECTED)) {
 
-		/*
-		 * This device may have initiated write
-		 * requests since the bridge last saw
-		 * an edge on this interrupt input; flushing
-		 * the buffer prior to invoking the handler
-		 * should help but may not be sufficient if we 
-		 * get more requests after the flush, followed
-		 * by the card deciding it wants service, before
-		 * the interrupt handler checks to see if things need
-		 * to be done.
-		 *
-		 * There is a similar race condition if
-		 * an interrupt handler loops around and
-		 * notices further service is required.
-		 * Perhaps we need to have an explicit
-		 * call that interrupt handlers need to
-		 * do between noticing that DMA to memory
-		 * has completed, but before observing the
-		 * contents of memory?
-		 */
-
-			if ((do_nonthreaded) && (!is_threaded)) {
-			/* Non-threaded. 
-			 * Call the interrupt handler at interrupt level
-			 */
+		    /*
+		     * This device may have initiated write
+		     * requests since the bridge last saw
+		     * an edge on this interrupt input; flushing
+		     * the buffer prior to invoking the handler
+		     * should help but may not be sufficient if we 
+		     * get more requests after the flush, followed
+		     * by the card deciding it wants service, before
+		     * the interrupt handler checks to see if things need
+		     * to be done.
+		     *
+		     * There is a similar race condition if
+		     * an interrupt handler loops around and
+		     * notices further service is required.
+		     * Perhaps we need to have an explicit
+		     * call that interrupt handlers need to
+		     * do between noticing that DMA to memory
+		     * has completed, but before observing the
+		     * contents of memory?
+		     */
 
+		    if ((do_nonthreaded) && (!is_threaded)) {
+			/* Non-threaded -  Call the interrupt handler at interrupt level */
 			/* Only need to flush write buffers if sharing */
 
 			if ((wrap->iw_shared) && (wrbf = list->il_wrbf)) {
@@ -864,21 +942,23 @@
 				    (void *)list->il_intr->bi_dev, (long) wrbf);
 #endif
 			}
+			func = intr->bi_func;
+			if ( func )
+				func(intr->bi_arg);
 		    }
-
 		    clearit = 0;
 		}
 	    }
+	    do_nonthreaded = 0;
 
-		do_nonthreaded = 0;
-		/*
-		 * If the non-threaded handler was the last to complete,
-		 * (i.e., no threaded handlers still running) force an
-		 * interrupt to avoid a potential deadlock situation.
-		 */
-		if (wrap->iw_hdlrcnt == 0) {
-			pcibr_force_interrupt(wrap);
-		}
+	    /*
+	     * If the non-threaded handler was the last to complete,
+	     * (i.e., no threaded handlers still running) force an
+	     * interrupt to avoid a potential deadlock situation.
+	     */
+	    if (wrap->iw_hdlrcnt == 0) {
+		pcibr_force_interrupt(wrap);
+	    }
 	}
 
 	/* If there were no handlers,
@@ -892,14 +972,24 @@
 	if (clearit) {
 	    pcibr_soft_t            pcibr_soft = wrap->iw_soft;
 	    bridge_t               *bridge = pcibr_soft->bs_base;
-	    bridgereg_t             b_int_enable;
-	    bridgereg_t		    mask = 1 << wrap->iw_intr;
+	    bridgereg_t             int_enable;
+	    bridgereg_t		    mask = 1 << wrap->iw_ibit;
 	    unsigned long           s;
 
+	    /* PIC BRINUGP WAR (PV# 854697):
+	     * On PIC we must write 64-bit MMRs with 64-bit stores
+	     */
 	    s = pcibr_lock(pcibr_soft);
-	    b_int_enable = bridge->b_int_enable;
-	    b_int_enable &= ~mask;
-	    bridge->b_int_enable = b_int_enable;
+	    if (IS_PIC_SOFT(pcibr_soft) &&
+				PCIBR_WAR_ENABLED(PV854697, pcibr_soft)) {
+		int_enable = bridge->p_int_enable_64;
+		int_enable &= ~mask;
+		bridge->p_int_enable_64 = int_enable;
+	    } else {
+		int_enable = (uint64_t)bridge->b_int_enable;
+		int_enable &= ~mask;
+		bridge->b_int_enable = (bridgereg_t)int_enable;
+	    }
 	    bridge->b_wid_tflush;	/* wait until Bridge PIO complete */
 	    pcibr_unlock(pcibr_soft, s);
 	    return;
diff -Nru a/arch/ia64/sn/io/sn2/pcibr/pcibr_rrb.c b/arch/ia64/sn/io/sn2/pcibr/pcibr_rrb.c
--- a/arch/ia64/sn/io/sn2/pcibr/pcibr_rrb.c	Mon Dec 23 21:22:01 2002
+++ b/arch/ia64/sn/io/sn2/pcibr/pcibr_rrb.c	Mon Dec 23 21:22:01 2002
@@ -33,259 +33,478 @@
 
 void              do_pcibr_rrb_clear(bridge_t *, int);
 void              do_pcibr_rrb_flush(bridge_t *, int);
-int               do_pcibr_rrb_count_valid(bridge_t *, pciio_slot_t);
+int               do_pcibr_rrb_count_valid(bridge_t *, pciio_slot_t, int);
 int               do_pcibr_rrb_count_avail(bridge_t *, pciio_slot_t);
-int               do_pcibr_rrb_alloc(bridge_t *, pciio_slot_t, int);
-int               do_pcibr_rrb_free(bridge_t *, pciio_slot_t, int);
+int               do_pcibr_rrb_alloc(bridge_t *, pciio_slot_t, int, int);
+int               do_pcibr_rrb_free(bridge_t *, pciio_slot_t, int, int);
+void		  do_pcibr_rrb_free_all(pcibr_soft_t, bridge_t *, pciio_slot_t);
 
-void              do_pcibr_rrb_autoalloc(pcibr_soft_t, int, int);
+void              do_pcibr_rrb_autoalloc(pcibr_soft_t, int, int, int);
 
 int		  pcibr_wrb_flush(devfs_handle_t);
 int               pcibr_rrb_alloc(devfs_handle_t, int *, int *);
 int               pcibr_rrb_check(devfs_handle_t, int *, int *, int *, int *);
-int               pcibr_alloc_all_rrbs(devfs_handle_t, int, int, int, int, int, int, int, int, int);
 void              pcibr_rrb_flush(devfs_handle_t);
 int		  pcibr_slot_initial_rrb_alloc(devfs_handle_t,pciio_slot_t);
 
-/* 
- *    RRB Management
- */
-
-#define LSBIT(word)		((word) &~ ((word)-1))
-
-void
-do_pcibr_rrb_clear(bridge_t *bridge, int rrb)
-{
-    bridgereg_t             status;
-
-    /* bridge_lock must be held;
-     * this RRB must be disabled.
-     */
-
-    /* wait until RRB has no outstanduing XIO packets. */
-    while ((status = bridge->b_resp_status) & BRIDGE_RRB_INUSE(rrb)) {
-	;				/* XXX- beats on bridge. bad idea? */
-    }
-
-    /* if the RRB has data, drain it. */
-    if (status & BRIDGE_RRB_VALID(rrb)) {
-	bridge->b_resp_clear = BRIDGE_RRB_CLEAR(rrb);
-
-	/* wait until RRB is no longer valid. */
-	while ((status = bridge->b_resp_status) & BRIDGE_RRB_VALID(rrb)) {
-	    ;				/* XXX- beats on bridge. bad idea? */
-	}
-    }
-}
-
-void
-do_pcibr_rrb_flush(bridge_t *bridge, int rrbn)
-{
-    reg_p                   rrbp = &bridge->b_rrb_map[rrbn & 1].reg;
-    bridgereg_t             rrbv;
-    int                     shft = 4 * (rrbn >> 1);
-    unsigned                ebit = BRIDGE_RRB_EN << shft;
-
-    rrbv = *rrbp;
-    if (rrbv & ebit)
-	*rrbp = rrbv & ~ebit;
-
-    do_pcibr_rrb_clear(bridge, rrbn);
-
-    if (rrbv & ebit)
-	*rrbp = rrbv;
-}
+void		  pcibr_rrb_debug(char *, pcibr_soft_t);
 
 /*
- *    pcibr_rrb_count_valid: count how many RRBs are
- *      marked valid for the specified PCI slot on this
- *      bridge.
- *
- *      NOTE: The "slot" parameter for all pcibr_rrb
- *      management routines must include the "virtual"
- *      bit; when manageing both the normal and the
- *      virtual channel, separate calls to these
- *      routines must be made. To denote the virtual
- *      channel, add PCIBR_RRB_SLOT_VIRTUAL to the slot
- *      number.
- *
- *      IMPL NOTE: The obvious algorithm is to iterate
- *      through the RRB fields, incrementing a count if
- *      the RRB is valid and matches the slot. However,
- *      it is much simpler to use an algorithm derived
- *      from the "partitioned add" idea. First, XOR in a
- *      pattern such that the fields that match this
- *      slot come up "all ones" and all other fields
- *      have zeros in the mismatching bits. Then AND
- *      together the bits in the field, so we end up
- *      with one bit turned on for each field that
- *      matched. Now we need to count these bits. This
- *      can be done either with a series of shift/add
- *      instructions or by using "tmp % 15"; I expect
- *      that the cascaded shift/add will be faster.
- */
-
+ * RRB Management
+ *
+ * All the do_pcibr_rrb_ routines manipulate the Read Response Buffer (rrb)
+ * registers within the Bridge.	 Two 32 registers (b_rrb_map[2] also known
+ * as the b_even_resp & b_odd_resp registers) are used to allocate the 16
+ * rrbs to devices.  The b_even_resp register represents even num devices,
+ * and b_odd_resp represent odd number devices.	 Each rrb is represented by
+ * 4-bits within a register.
+ *   BRIDGE & XBRIDGE:	1 enable bit, 1 virtual channel bit, 2 device bits
+ *   PIC:		1 enable bit, 2 virtual channel bits, 1 device bit
+ * PIC has 4 devices per bus, and 4 virtual channels (1 normal & 3 virtual)
+ * per device.	BRIDGE & XBRIDGE have 8 devices per bus and 2 virtual
+ * channels (1 normal & 1 virtual) per device.	See the BRIDGE and PIC ASIC
+ * Programmers Reference guides for more information.
+ */ 
+ 
+#define RRB_MASK (0xf)			/* mask a single rrb within reg */
+#define RRB_SIZE (4)			/* sizeof rrb within reg (bits) */
+ 
+#define RRB_ENABLE_BIT(bridge)		(0x8)  /* [BRIDGE | PIC]_RRB_EN */
+#define NUM_PDEV_BITS(bridge)		(is_pic((bridge)) ? 1 : 2)
+#define NUM_VDEV_BITS(bridge)		(is_pic((bridge)) ? 2 : 1)
+#define NUMBER_VCHANNELS(bridge)	(is_pic((bridge)) ? 4 : 2)
+#define SLOT_2_PDEV(bridge, slot)	((slot) >> 1)
+#define SLOT_2_RRB_REG(bridge, slot)	((slot) & 0x1)
+ 
+/* validate that the slot and virtual channel are valid for a given bridge */
+#define VALIDATE_SLOT_n_VCHAN(bridge, s, v) \
+  (is_pic((bridge)) ? \
+    (((((s) != PCIIO_SLOT_NONE) && ((s) <= (pciio_slot_t)3)) && (((v) >= 0) && ((v) <= 3))) ? 1 : 0) : \
+    (((((s) != PCIIO_SLOT_NONE) && ((s) <= (pciio_slot_t)7)) && (((v) >= 0) && ((v) <= 1))) ? 1 : 0))
+ 
+/*  
+ * Count how many RRBs are marked valid for the specified PCI slot
+ * and virtual channel.	 Return the count.
+ */ 
 int
 do_pcibr_rrb_count_valid(bridge_t *bridge,
-			 pciio_slot_t slot)
+			 pciio_slot_t slot,
+			 int vchan)
 {
-    bridgereg_t             tmp;
+    bridgereg_t tmp;
+    uint16_t enable_bit, vchan_bits, pdev_bits, rrb_bits;
+    int rrb_index, cnt=0;
+
+    if (!VALIDATE_SLOT_n_VCHAN(bridge, slot, vchan)) {
+	printk(KERN_WARNING "do_pcibr_rrb_count_valid() invalid slot/vchan [%d/%d]\n", slot, vchan);
+	return 0;
+    }
+    
+    enable_bit = RRB_ENABLE_BIT(bridge);
+    vchan_bits = vchan << NUM_PDEV_BITS(bridge);
+    pdev_bits = SLOT_2_PDEV(bridge, slot);
+    rrb_bits = enable_bit | vchan_bits | pdev_bits;
+    
+    if ( is_pic(bridge) ) {
+	tmp = bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg;
+    }
+    else {
+	if (io_get_sh_swapper(NASID_GET(bridge))) {
+		tmp = BRIDGE_REG_GET32((&bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg));
+	} else {
+		tmp = bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg;
+	}
+    }
 
-    tmp = bridge->b_rrb_map[slot & 1].reg;
-    tmp ^= 0x11111111 * (7 - slot / 2);
-    tmp &= (0xCCCCCCCC & tmp) >> 2;
-    tmp &= (0x22222222 & tmp) >> 1;
-    tmp += tmp >> 4;
-    tmp += tmp >> 8;
-    tmp += tmp >> 16;
-    return tmp & 15;
+    for (rrb_index = 0; rrb_index < 8; rrb_index++) {
+	if ((tmp & RRB_MASK) == rrb_bits)
+	    cnt++;
+	tmp = (tmp >> RRB_SIZE);
+    }
+    return cnt;
 }
-
-/*
- *    do_pcibr_rrb_count_avail: count how many RRBs are
- *      available to be allocated for the specified slot.
- *
- *      IMPL NOTE: similar to the above, except we are
- *      just counting how many fields have the valid bit
- *      turned off.
- */
+ 
+ 
+/*  
+ * Count how many RRBs are available to be allocated to the specified
+ * slot.  Return the count.
+ */ 
 int
 do_pcibr_rrb_count_avail(bridge_t *bridge,
 			 pciio_slot_t slot)
 {
-    bridgereg_t             tmp;
+    bridgereg_t tmp;
+    uint16_t enable_bit;
+    int rrb_index, cnt=0;
+    
+    if (!VALIDATE_SLOT_n_VCHAN(bridge, slot, 0)) {
+	printk(KERN_WARNING "do_pcibr_rrb_count_avail() invalid slot/vchan");
+	return 0;
+    }
+    
+    enable_bit = RRB_ENABLE_BIT(bridge);
+
+    if ( is_pic(bridge) ) {
+	tmp = bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg;
+    }
+    else {
+	if (io_get_sh_swapper(NASID_GET(bridge))) {
+		tmp = BRIDGE_REG_GET32((&bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg));
+	} else {
+		tmp = bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg;
+	}
+    }
 
-    tmp = bridge->b_rrb_map[slot & 1].reg;
-    tmp = (0x88888888 & ~tmp) >> 3;
-    tmp += tmp >> 4;
-    tmp += tmp >> 8;
-    tmp += tmp >> 16;
-    return tmp & 15;
+    for (rrb_index = 0; rrb_index < 8; rrb_index++) {
+	if ((tmp & enable_bit) != enable_bit)
+	    cnt++;
+	tmp = (tmp >> RRB_SIZE);
+    }
+    return cnt;
 }
-
-/*
- *    do_pcibr_rrb_alloc: allocate some additional RRBs
- *      for the specified slot. Returns -1 if there were
- *      insufficient free RRBs to satisfy the request,
- *      or 0 if the request was fulfilled.
- *
- *      Note that if a request can be partially filled,
- *      it will be, even if we return failure.
- *
- *      IMPL NOTE: again we avoid iterating across all
- *      the RRBs; instead, we form up a word containing
- *      one bit for each free RRB, then peel the bits
- *      off from the low end.
- */
+ 
+ 
+/*  
+ * Allocate some additional RRBs for the specified slot and the specified
+ * virtual channel.  Returns -1 if there were insufficient free RRBs to
+ * satisfy the request, or 0 if the request was fulfilled.
+ *
+ * Note that if a request can be partially filled, it will be, even if
+ * we return failure.
+ */ 
 int
 do_pcibr_rrb_alloc(bridge_t *bridge,
 		   pciio_slot_t slot,
+		   int vchan,
 		   int more)
 {
-    int                     rv = 0;
-    bridgereg_t             reg, tmp, bit;
+    bridgereg_t reg, tmp = (bridgereg_t)0;
+    uint16_t enable_bit, vchan_bits, pdev_bits, rrb_bits;
+    int rrb_index;
+    
+    if (!VALIDATE_SLOT_n_VCHAN(bridge, slot, vchan)) {
+	printk(KERN_WARNING "do_pcibr_rrb_alloc() invalid slot/vchan");
+	return -1;
+    }
+    
+    enable_bit = RRB_ENABLE_BIT(bridge);
+    vchan_bits = vchan << NUM_PDEV_BITS(bridge);
+    pdev_bits = SLOT_2_PDEV(bridge, slot);
+    rrb_bits = enable_bit | vchan_bits | pdev_bits;
+
+    if ( is_pic(bridge) ) {
+	reg = tmp = bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg;
+    }
+    else {
+	if (io_get_sh_swapper(NASID_GET(bridge))) {
+		reg = tmp = BRIDGE_REG_GET32((&bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg));
+	} else {
+		reg = tmp = bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg;
+	}
+    }
+    
+    for (rrb_index = 0; ((rrb_index < 8) && (more > 0)); rrb_index++) {
+	if ((tmp & enable_bit) != enable_bit) {
+	    /* clear the rrb and OR in the new rrb into 'reg' */
+	    reg = reg & ~(RRB_MASK << (RRB_SIZE * rrb_index));
+	    reg = reg | (rrb_bits << (RRB_SIZE * rrb_index));
+	    more--;
+	}
+	tmp = (tmp >> RRB_SIZE);
+    }
 
-    reg = bridge->b_rrb_map[slot & 1].reg;
-    tmp = (0x88888888 & ~reg) >> 3;
-    while (more-- > 0) {
-	bit = LSBIT(tmp);
-	if (!bit) {
-	    rv = -1;
-	    break;
+    if ( is_pic(bridge) ) {
+	bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg = reg;
+    }
+    else {
+	if (io_get_sh_swapper(NASID_GET(bridge))) {
+		BRIDGE_REG_SET32((&bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg)) = reg;
+	} else {
+		bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg = reg;
 	}
-	tmp &= ~bit;
-	reg = ((reg & ~(bit * 15)) | (bit * (8 + slot / 2)));
     }
-    bridge->b_rrb_map[slot & 1].reg = reg;
-    return rv;
+    return (more ? -1 : 0);
 }
-
-/*
- *    do_pcibr_rrb_free: release some of the RRBs that
- *      have been allocated for the specified
- *      slot. Returns zero for success, or negative if
- *      it was unable to free that many RRBs.
- *
- *      IMPL NOTE: We form up a bit for each RRB
- *      allocated to the slot, aligned with the VALID
- *      bitfield this time; then we peel bits off one at
- *      a time, releasing the corresponding RRB.
- */
+ 
+ 
+/*  
+ * Release some of the RRBs that have been allocated for the specified
+ * slot. Returns zero for success, or negative if it was unable to free
+ * that many RRBs.
+ *
+ * Note that if a request can be partially fulfilled, it will be, even
+ * if we return failure.
+ */ 
 int
 do_pcibr_rrb_free(bridge_t *bridge,
 		  pciio_slot_t slot,
+		  int vchan,
 		  int less)
 {
-    int                     rv = 0;
-    bridgereg_t             reg, tmp, clr, bit;
-    int                     i;
+    bridgereg_t reg, tmp = (bridgereg_t)0, clr = 0;
+    uint16_t enable_bit, vchan_bits, pdev_bits, rrb_bits;
+    int rrb_index;
+    
+    if (!VALIDATE_SLOT_n_VCHAN(bridge, slot, vchan)) {
+	printk(KERN_WARNING "do_pcibr_rrb_free() invalid slot/vchan");
+	return -1;
+    }
+    
+    enable_bit = RRB_ENABLE_BIT(bridge);
+    vchan_bits = vchan << NUM_PDEV_BITS(bridge);
+    pdev_bits = SLOT_2_PDEV(bridge, slot);
+    rrb_bits = enable_bit | vchan_bits | pdev_bits;
+
+    if ( is_pic(bridge) ) {
+	reg = tmp = bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg;
+    }
+    else {
+	if (io_get_sh_swapper(NASID_GET(bridge))) {
+		reg = BRIDGE_REG_GET32((&bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg));
+	} else {
+		reg = tmp = bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg;
+	}
+    }
+    
+    for (rrb_index = 0; ((rrb_index < 8) && (less > 0)); rrb_index++) {
+	if ((tmp & RRB_MASK) == rrb_bits) {
+	   /*
+	    * the old do_pcibr_rrb_free() code only clears the enable bit
+	    * but I say we should clear the whole rrb (ie):
+	    *	  reg = reg & ~(RRB_MASK << (RRB_SIZE * rrb_index));
+	    * But to be compatable with old code we'll only clear enable.
+	    */
+	    reg = reg & ~(RRB_ENABLE_BIT(bridge) << (RRB_SIZE * rrb_index));
+	    clr = clr | (enable_bit << (RRB_SIZE * rrb_index));
+	    less--;
+	}
+	tmp = (tmp >> RRB_SIZE);
+    }
 
-    clr = 0;
-    reg = bridge->b_rrb_map[slot & 1].reg;
+    if ( is_pic(bridge) ) {
+	bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg = reg;
+    }
+    else {
+	if (io_get_sh_swapper(NASID_GET(bridge))) {
+		BRIDGE_REG_SET32((&bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg)) = reg;
+	} else {
+		bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg = reg;
+	}
+    }
 
-    /* This needs to be done otherwise the rrb's on the virtual channel
-     * for this slot won't be freed !!
+    /* call do_pcibr_rrb_clear() for all the rrbs we've freed */
+    for (rrb_index = 0; rrb_index < 8; rrb_index++) {
+	int evn_odd = SLOT_2_RRB_REG(bridge, slot);
+	if (clr & (enable_bit << (RRB_SIZE * rrb_index)))
+	    do_pcibr_rrb_clear(bridge, (2 * rrb_index) + evn_odd);
+    }
+    
+    return (less ? -1 : 0);
+}
+ 
+  
+/*  
+ * free all the rrbs (both the normal and virtual channels) for the
+ * specified slot.
+ */ 
+void
+do_pcibr_rrb_free_all(pcibr_soft_t pcibr_soft,
+		      bridge_t *bridge,
+		      pciio_slot_t slot)
+{
+    int vchan;
+    int vchan_total = NUMBER_VCHANNELS(bridge);
+    
+    /* pretend we own all 8 rrbs and just ignore the return value */
+    for (vchan = 0; vchan < vchan_total; vchan++) {
+	    (void)do_pcibr_rrb_free(bridge, slot, vchan, 8);
+	    pcibr_soft->bs_rrb_valid[slot][vchan] = 0;
+    }
+}
+ 
+ 
+/*
+ * Wait for the the specified rrb to have no outstanding XIO pkts
+ * and for all data to be drained.  Mark the rrb as no longer being 
+ * valid.
+ */
+void
+do_pcibr_rrb_clear(bridge_t *bridge, int rrb)
+{
+    bridgereg_t             status;
+
+    /* bridge_lock must be held;
+     * this RRB must be disabled.
      */
-    tmp = reg & 0xbbbbbbbb;
 
-    tmp ^= (0x11111111 * (7 - slot / 2));
-    tmp &= (0x33333333 & tmp) << 2;
-    tmp &= (0x44444444 & tmp) << 1;
-    while (less-- > 0) {
-	bit = LSBIT(tmp);
-	if (!bit) {
-	    rv = -1;
-	    break;
+    if ( is_pic(bridge) ) {
+	/* wait until RRB has no outstanduing XIO packets. */
+	while ((status = bridge->b_resp_status) & BRIDGE_RRB_INUSE(rrb)) {
+		;				/* XXX- beats on bridge. bad idea? */
+	}
+
+	/* if the RRB has data, drain it. */
+	if (status & BRIDGE_RRB_VALID(rrb)) {
+		bridge->b_resp_clear = BRIDGE_RRB_CLEAR(rrb);
+
+		/* wait until RRB is no longer valid. */
+		while ((status = bridge->b_resp_status) & BRIDGE_RRB_VALID(rrb)) {
+			;				/* XXX- beats on bridge. bad idea? */
+		}
+	}
+    }
+    else {
+	if (io_get_sh_swapper(NASID_GET(bridge))) {
+		while ((status = BRIDGE_REG_GET32((&bridge->b_resp_status))) & BRIDGE_RRB_INUSE(rrb)) {
+			;                               /* XXX- beats on bridge. bad idea? */
+		}
+
+		/* if the RRB has data, drain it. */
+		if (status & BRIDGE_RRB_VALID(rrb)) {
+			BRIDGE_REG_SET32((&bridge->b_resp_clear)) = __swab32(BRIDGE_RRB_CLEAR(rrb));
+
+			/* wait until RRB is no longer valid. */
+			while ((status = BRIDGE_REG_GET32((&bridge->b_resp_status))) & BRIDGE_RRB_VALID(rrb)) {
+				;                           /* XXX- beats on bridge. bad idea? */
+			}
+		}
+	} else { /* io_get_sh_swapper(NASID_GET(bridge)) */
+		while ((status = bridge->b_resp_status) & BRIDGE_RRB_INUSE(rrb)) {
+			;                               /* XXX- beats on bridge. bad idea? */
+		}
+
+		/* if the RRB has data, drain it. */
+		if (status & BRIDGE_RRB_VALID(rrb)) {
+			bridge->b_resp_clear = BRIDGE_RRB_CLEAR(rrb);
+			/* wait until RRB is no longer valid. */
+			while ((status = bridge->b_resp_status) & BRIDGE_RRB_VALID(rrb)) {
+				;                           /* XXX- beats on bridge. bad idea? */
+			}
+		}
+	}
+    }
+}
+
+
+/* 
+ * Flush the specified rrb by calling do_pcibr_rrb_clear().  This
+ * routine is just a wrapper to make sure the rrb is disabled 
+ * before calling do_pcibr_rrb_clear().
+ */
+void
+do_pcibr_rrb_flush(bridge_t *bridge, int rrbn)
+{
+    reg_p	 rrbp = &bridge->b_rrb_map[rrbn & 1].reg;
+    bridgereg_t	 rrbv;
+    int		 shft = (RRB_SIZE * (rrbn >> 1));
+    unsigned long	 ebit = RRB_ENABLE_BIT(bridge) << shft;
+
+    if ( is_pic(bridge) ) {
+	rrbv = *rrbp;
+    }
+    else {
+	if (io_get_sh_swapper(NASID_GET(bridge))) {
+		rrbv = BRIDGE_REG_GET32((&rrbp));
+	} else {
+		rrbv = *rrbp;
+	}
+    }
+
+    if (rrbv & ebit) {
+    	if ( is_pic(bridge) ) {
+		*rrbp = rrbv & ~ebit;
+	}
+	else {
+		if (io_get_sh_swapper(NASID_GET(bridge))) {
+			BRIDGE_REG_SET32((&rrbp)) = __swab32((rrbv & ~ebit));
+		} else {
+			*rrbp = rrbv & ~ebit;
+		}
 	}
-	tmp &= ~bit;
-	reg &= ~bit;
-	clr |= bit;
     }
-    bridge->b_rrb_map[slot & 1].reg = reg;
 
-    for (i = 0; i < 8; i++)
-	if (clr & (8 << (4 * i)))
-	    do_pcibr_rrb_clear(bridge, (2 * i) + (slot & 1));
+    do_pcibr_rrb_clear(bridge, rrbn);
 
-    return rv;
+    if (rrbv & ebit) {
+	if ( is_pic(bridge) ) {
+		*rrbp = rrbv;
+	}
+	else {
+		if (io_get_sh_swapper(NASID_GET(bridge))) {
+			BRIDGE_REG_SET32((&rrbp)) = __swab32(rrbv);
+		} else {
+			*rrbp = rrbv;
+		}
+	}
+    }
 }
 
+
 void
 do_pcibr_rrb_autoalloc(pcibr_soft_t pcibr_soft,
 		       int slot,
+		       int vchan, 
 		       int more_rrbs)
 {
     bridge_t               *bridge = pcibr_soft->bs_base;
     int                     got;
 
     for (got = 0; got < more_rrbs; ++got) {
-	if (pcibr_soft->bs_rrb_res[slot & 7] > 0)
-	    pcibr_soft->bs_rrb_res[slot & 7]--;
+	if (pcibr_soft->bs_rrb_res[slot] > 0)
+	    pcibr_soft->bs_rrb_res[slot]--;
 	else if (pcibr_soft->bs_rrb_avail[slot & 1] > 0)
 	    pcibr_soft->bs_rrb_avail[slot & 1]--;
 	else
 	    break;
-	if (do_pcibr_rrb_alloc(bridge, slot, 1) < 0)
+	if (do_pcibr_rrb_alloc(bridge, slot, vchan, 1) < 0)
 	    break;
-#if PCIBR_RRB_DEBUG
-	printk("do_pcibr_rrb_autoalloc: add one to slot %d%s\n",
-		slot & 7, slot & 8 ? "v" : "");
-#endif
-	pcibr_soft->bs_rrb_valid[slot]++;
-    }
-#if PCIBR_RRB_DEBUG
-    printk("%s: %d+%d free RRBs. Allocation list:\n", pcibr_soft->bs_name,
-	    pcibr_soft->bs_rrb_avail[0],
-	    pcibr_soft->bs_rrb_avail[1]);
-    for (slot = 0; slot < 8; ++slot)
-	printk("\t%d+%d+%d",
-		0xFFF & pcibr_soft->bs_rrb_valid[slot],
-		0xFFF & pcibr_soft->bs_rrb_valid[slot + PCIBR_RRB_SLOT_VIRTUAL],
-		pcibr_soft->bs_rrb_res[slot]);
-    printk("\n");
-#endif
+
+	pcibr_soft->bs_rrb_valid[slot][vchan]++;
+    }
+
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_RRB, pcibr_soft->bs_vhdl,
+		"do_pcibr_rrb_autoalloc: added %d (of %d requested) RRBs "
+		"to slot %d, vchan %d\n", got, more_rrbs, 
+		PCIBR_DEVICE_TO_SLOT(pcibr_soft, slot), vchan));
+
+    pcibr_rrb_debug("do_pcibr_rrb_autoalloc", pcibr_soft);
 }
 
+
+/*
+ * Flush all the rrb's assigned to the specified connection point.
+ */
+void
+pcibr_rrb_flush(devfs_handle_t pconn_vhdl)
+{
+    pciio_info_t  pciio_info = pciio_info_get(pconn_vhdl);
+    pcibr_soft_t  pcibr_soft = (pcibr_soft_t)pciio_info_mfast_get(pciio_info);
+    pciio_slot_t  slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
+    bridge_t	 *bridge = pcibr_soft->bs_base;
+
+    bridgereg_t tmp;
+    uint16_t enable_bit, pdev_bits, rrb_bits, rrb_mask;
+    int rrb_index;
+    unsigned long s;
+
+    enable_bit = RRB_ENABLE_BIT(bridge);
+    pdev_bits = SLOT_2_PDEV(bridge, slot);
+    rrb_bits = enable_bit | pdev_bits;
+    rrb_mask = enable_bit | ((NUM_PDEV_BITS(bridge) << 1) - 1);
+
+    tmp = bridge->b_rrb_map[SLOT_2_RRB_REG(bridge, slot)].reg;
+
+    s = pcibr_lock(pcibr_soft);
+    for (rrb_index = 0; rrb_index < 8; rrb_index++) {
+	int evn_odd = SLOT_2_RRB_REG(bridge, slot);
+	if ((tmp & rrb_mask) == rrb_bits)
+	    do_pcibr_rrb_flush(bridge, (2 * rrb_index) + evn_odd);
+	tmp = (tmp >> RRB_SIZE);
+    }
+    pcibr_unlock(pcibr_soft, s);
+}
+
+
 /*
  * Device driver interface to flush the write buffers for a specified
  * device hanging off the bridge.
@@ -294,14 +513,24 @@
 pcibr_wrb_flush(devfs_handle_t pconn_vhdl)
 {
     pciio_info_t            pciio_info = pciio_info_get(pconn_vhdl);
-    pciio_slot_t            pciio_slot = pciio_info_slot_get(pciio_info);
+    pciio_slot_t            pciio_slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
     pcibr_soft_t            pcibr_soft = (pcibr_soft_t) pciio_info_mfast_get(pciio_info);
     bridge_t               *bridge = pcibr_soft->bs_base;
     volatile bridgereg_t   *wrb_flush;
 
     wrb_flush = &(bridge->b_wr_req_buf[pciio_slot].reg);
-    while (*wrb_flush);
-
+    if ( IS_PIC_SOFT(pcibr_soft) ) {
+	while (*wrb_flush)
+		;
+    }
+    else {
+	if (io_get_sh_swapper(NASID_GET(bridge))) {
+		while (BRIDGE_REG_GET32((wrb_flush)));
+	} else {
+		while (*wrb_flush)
+			;
+	}
+    }
     return(0);
 }
 
@@ -322,7 +551,7 @@
 		int *count_vchan1)
 {
     pciio_info_t            pciio_info = pciio_info_get(pconn_vhdl);
-    pciio_slot_t            pciio_slot = pciio_info_slot_get(pciio_info);
+    pciio_slot_t            pciio_slot = PCIBR_INFO_SLOT_GET_INT(pciio_info);
     pcibr_soft_t            pcibr_soft = (pcibr_soft_t) pciio_info_mfast_get(pciio_info);
     bridge_t               *bridge = pcibr_soft->bs_base;
     int                     desired_vchan0;
@@ -335,7 +564,9 @@
     int                     final_vchan1;
     int                     avail_rrbs;
     int                     res_rrbs;
-    unsigned long           s;
+    int			    vchan_total;
+    int			    vchan;
+    unsigned long                s;
     int                     error;
 
     /*
@@ -352,20 +583,21 @@
 
     s = pcibr_lock(pcibr_soft);
 
+    vchan_total = NUMBER_VCHANNELS(bridge);
+
     /* Save the boot-time RRB configuration for this slot */
-    if (pcibr_soft->bs_rrb_valid_dflt[pciio_slot] < 0) {
-        pcibr_soft->bs_rrb_valid_dflt[pciio_slot] =
-                pcibr_soft->bs_rrb_valid[pciio_slot]; 
-        pcibr_soft->bs_rrb_valid_dflt[pciio_slot + PCIBR_RRB_SLOT_VIRTUAL] =
-                pcibr_soft->bs_rrb_valid[pciio_slot + PCIBR_RRB_SLOT_VIRTUAL];
+    if (pcibr_soft->bs_rrb_valid_dflt[pciio_slot][VCHAN0] < 0) {
+	for (vchan = 0; vchan < vchan_total; vchan++) 
+	    pcibr_soft->bs_rrb_valid_dflt[pciio_slot][vchan] =
+		    pcibr_soft->bs_rrb_valid[pciio_slot][vchan];
         pcibr_soft->bs_rrb_res_dflt[pciio_slot] =
                 pcibr_soft->bs_rrb_res[pciio_slot];
                   
     }
 
     /* How many RRBs do we own? */
-    orig_vchan0 = pcibr_soft->bs_rrb_valid[pciio_slot];
-    orig_vchan1 = pcibr_soft->bs_rrb_valid[pciio_slot + PCIBR_RRB_SLOT_VIRTUAL];
+    orig_vchan0 = pcibr_soft->bs_rrb_valid[pciio_slot][VCHAN0];
+    orig_vchan1 = pcibr_soft->bs_rrb_valid[pciio_slot][VCHAN1];
 
     /* How many RRBs do we want? */
     desired_vchan0 = count_vchan0 ? *count_vchan0 : orig_vchan0;
@@ -417,14 +649,14 @@
 	/* Commit the allocations: free, then alloc.
 	 */
 	if (delta_vchan0 < 0)
-	    (void) do_pcibr_rrb_free(bridge, pciio_slot, -delta_vchan0);
+	    (void) do_pcibr_rrb_free(bridge, pciio_slot, VCHAN0, -delta_vchan0);
 	if (delta_vchan1 < 0)
-	    (void) do_pcibr_rrb_free(bridge, PCIBR_RRB_SLOT_VIRTUAL + pciio_slot, -delta_vchan1);
+	    (void) do_pcibr_rrb_free(bridge, pciio_slot, VCHAN1, -delta_vchan1);
 
 	if (delta_vchan0 > 0)
-	    (void) do_pcibr_rrb_alloc(bridge, pciio_slot, delta_vchan0);
+	    (void) do_pcibr_rrb_alloc(bridge, pciio_slot, VCHAN0, delta_vchan0);
 	if (delta_vchan1 > 0)
-	    (void) do_pcibr_rrb_alloc(bridge, PCIBR_RRB_SLOT_VIRTUAL + pciio_slot, delta_vchan1);
+	    (void) do_pcibr_rrb_alloc(bridge, pciio_slot, VCHAN1, delta_vchan1);
 
 	/* Return final values to caller.
 	 */
@@ -442,8 +674,8 @@
 	 * number of available RRBs.
 	 */
 
-	pcibr_soft->bs_rrb_valid[pciio_slot] = final_vchan0;
-	pcibr_soft->bs_rrb_valid[pciio_slot + PCIBR_RRB_SLOT_VIRTUAL] = final_vchan1;
+	pcibr_soft->bs_rrb_valid[pciio_slot][VCHAN0] = final_vchan0;
+	pcibr_soft->bs_rrb_valid[pciio_slot][VCHAN1] = final_vchan1;
 	pcibr_soft->bs_rrb_avail[pciio_slot & 1] =
 	    pcibr_soft->bs_rrb_avail[pciio_slot & 1]
 	    + pcibr_soft->bs_rrb_res[pciio_slot]
@@ -455,34 +687,21 @@
          * Reserve enough RRBs so this slot's RRB configuration can be
          * reset to its boot-time default following a hot-plug shut-down
          */
-        res_rrbs =   (pcibr_soft->bs_rrb_valid_dflt[pciio_slot] -
-                      pcibr_soft->bs_rrb_valid[pciio_slot]) 
-                   + (pcibr_soft->bs_rrb_valid_dflt[pciio_slot +
-                                                    PCIBR_RRB_SLOT_VIRTUAL] -
-                      pcibr_soft->bs_rrb_valid[pciio_slot +
-                                               PCIBR_RRB_SLOT_VIRTUAL])
-                   + (pcibr_soft->bs_rrb_res_dflt[pciio_slot] -
-                      pcibr_soft->bs_rrb_res[pciio_slot]);
-
-         if (res_rrbs > 0) {
-             pcibr_soft->bs_rrb_res[pciio_slot] = res_rrbs;
-             pcibr_soft->bs_rrb_avail[pciio_slot & 1] =
-                 pcibr_soft->bs_rrb_avail[pciio_slot & 1]
-                 - res_rrbs;
-         }
- 
-#if PCIBR_RRB_DEBUG
-	printk("pcibr_rrb_alloc: slot %d set to %d+%d; %d+%d free\n",
-		pciio_slot, final_vchan0, final_vchan1,
-		pcibr_soft->bs_rrb_avail[0],
-		pcibr_soft->bs_rrb_avail[1]);
-	for (pciio_slot = 0; pciio_slot < 8; ++pciio_slot)
-	    printk("\t%d+%d+%d",
-		    0xFFF & pcibr_soft->bs_rrb_valid[pciio_slot],
-		    0xFFF & pcibr_soft->bs_rrb_valid[pciio_slot + PCIBR_RRB_SLOT_VIRTUAL],
+	res_rrbs = (pcibr_soft->bs_rrb_res_dflt[pciio_slot] -
 		    pcibr_soft->bs_rrb_res[pciio_slot]);
-	printk("\n");
-#endif
+	for (vchan = 0; vchan < vchan_total; vchan++) {
+	    res_rrbs += (pcibr_soft->bs_rrb_valid_dflt[pciio_slot][vchan] -
+			 pcibr_soft->bs_rrb_valid[pciio_slot][vchan]);
+	}
+
+	if (res_rrbs > 0) {
+            pcibr_soft->bs_rrb_res[pciio_slot] = res_rrbs;
+            pcibr_soft->bs_rrb_avail[pciio_slot & 1] =
+                pcibr_soft->bs_rrb_avail[pciio_slot & 1]
+                - res_rrbs;
+        }
+ 
+	pcibr_rrb_debug("pcibr_rrb_alloc", pcibr_soft);
 
 	error = 0;
     }
@@ -543,22 +762,22 @@
     pciio_info_t            pciio_info;
     pciio_slot_t            pciio_slot;
     pcibr_soft_t            pcibr_soft;
-    unsigned long           s;
+    unsigned long                s;
     int                     error = -1;
 
     if ((pciio_info = pciio_info_get(pconn_vhdl)) &&
 	(pcibr_soft = (pcibr_soft_t) pciio_info_mfast_get(pciio_info)) &&
-	((pciio_slot = pciio_info_slot_get(pciio_info)) < 8)) {
+	((pciio_slot = PCIBR_INFO_SLOT_GET_INT(pciio_info)) < PCIBR_NUM_SLOTS(pcibr_soft))) {
 
 	s = pcibr_lock(pcibr_soft);
 
 	if (count_vchan0)
 	    *count_vchan0 =
-		pcibr_soft->bs_rrb_valid[pciio_slot];
+		pcibr_soft->bs_rrb_valid[pciio_slot][VCHAN0];
 
 	if (count_vchan1)
 	    *count_vchan1 =
-		pcibr_soft->bs_rrb_valid[pciio_slot + PCIBR_RRB_SLOT_VIRTUAL];
+		pcibr_soft->bs_rrb_valid[pciio_slot][VCHAN1];
 
 	if (count_reserved)
 	    *count_reserved =
@@ -575,159 +794,6 @@
     return error;
 }
 
-/* pcibr_alloc_all_rrbs allocates all the rrbs available in the quantities
- * requested for each of the devices.  The evn_odd argument indicates whether
- * allocation is for the odd or even rrbs. The next group of four argument
- * pairs indicate the amount of rrbs to be assigned to each device. The first
- * argument of each pair indicate the total number of rrbs to allocate for that
- * device. The second argument of each pair indicates how many rrb's from the
- * first argument should be assigned to the virtual channel. The total of all
- * of the first arguments should be <= 8. The second argument should be <= the
- * first argument.
- * if even_odd = 0 the devices in order are 0, 2, 4, 6 
- * if even_odd = 1 the devices in order are 1, 3, 5, 7
- * returns 0 if no errors else returns -1
- */
-
-int
-pcibr_alloc_all_rrbs(devfs_handle_t vhdl, int even_odd,
-		     int dev_1_rrbs, int virt1, int dev_2_rrbs, int virt2,
-		     int dev_3_rrbs, int virt3, int dev_4_rrbs, int virt4)
-{
-    devfs_handle_t          pcibr_vhdl;
-    pcibr_soft_t            pcibr_soft = (pcibr_soft_t)0;
-    bridge_t               *bridge = NULL;
-
-    uint32_t                rrb_setting = 0;
-    int                     rrb_shift = 7;
-    uint32_t                cur_rrb;
-    int                     dev_rrbs[4];
-    int                     virt[4];
-    int                     i, j;
-    unsigned long           s;
-
-    if (GRAPH_SUCCESS ==
-	hwgraph_traverse(vhdl, EDGE_LBL_PCI, &pcibr_vhdl)) {
-	pcibr_soft = pcibr_soft_get(pcibr_vhdl);
-	if (pcibr_soft)
-	    bridge = pcibr_soft->bs_base;
-	hwgraph_vertex_unref(pcibr_vhdl);
-    }
-    if (bridge == NULL)
-	bridge = (bridge_t *) xtalk_piotrans_addr
-	    (vhdl, NULL, 0, sizeof(bridge_t), 0);
-
-    even_odd &= 1;
-
-    dev_rrbs[0] = dev_1_rrbs;
-    dev_rrbs[1] = dev_2_rrbs;
-    dev_rrbs[2] = dev_3_rrbs;
-    dev_rrbs[3] = dev_4_rrbs;
-
-    virt[0] = virt1;
-    virt[1] = virt2;
-    virt[2] = virt3;
-    virt[3] = virt4;
-
-    if ((dev_1_rrbs + dev_2_rrbs + dev_3_rrbs + dev_4_rrbs) > 8) {
-	return -1;
-    }
-    if ((dev_1_rrbs < 0) || (dev_2_rrbs < 0) || (dev_3_rrbs < 0) || (dev_4_rrbs < 0)) {
-	return -1;
-    }
-    /* walk through rrbs */
-    for (i = 0; i < 4; i++) {
-	if (virt[i]) {
-		for( j = 0; j < virt[i]; j++) {
-			cur_rrb = i | 0xc;
-			cur_rrb = cur_rrb << (rrb_shift * 4);
-			rrb_shift--;
-			rrb_setting = rrb_setting | cur_rrb;
-			dev_rrbs[i] = dev_rrbs[i] - 1;
-		}
-	}
-	for (j = 0; j < dev_rrbs[i]; j++) {
-	    cur_rrb = i | 0x8;
-	    cur_rrb = cur_rrb << (rrb_shift * 4);
-	    rrb_shift--;
-	    rrb_setting = rrb_setting | cur_rrb;
-	}
-    }
-
-    if (pcibr_soft)
-	s = pcibr_lock(pcibr_soft);
-
-    bridge->b_rrb_map[even_odd].reg = rrb_setting;
-
-    if (pcibr_soft) {
-
-	pcibr_soft->bs_rrb_fixed |= 0x55 << even_odd;
-
-	/* since we've "FIXED" the allocations
-	 * for these slots, we probably can dispense
-	 * with tracking avail/res/valid data, but
-	 * keeping it up to date helps debugging.
-	 */
-
-	pcibr_soft->bs_rrb_avail[even_odd] =
-	    8 - (dev_1_rrbs + dev_2_rrbs + dev_3_rrbs + dev_4_rrbs);
-
-	pcibr_soft->bs_rrb_res[even_odd + 0] = 0;
-	pcibr_soft->bs_rrb_res[even_odd + 2] = 0;
-	pcibr_soft->bs_rrb_res[even_odd + 4] = 0;
-	pcibr_soft->bs_rrb_res[even_odd + 6] = 0;
-
-	pcibr_soft->bs_rrb_valid[even_odd + 0] = dev_1_rrbs - virt1;
-	pcibr_soft->bs_rrb_valid[even_odd + 2] = dev_2_rrbs - virt2;
-	pcibr_soft->bs_rrb_valid[even_odd + 4] = dev_3_rrbs - virt3;
-	pcibr_soft->bs_rrb_valid[even_odd + 6] = dev_4_rrbs - virt4;
-
-	pcibr_soft->bs_rrb_valid[even_odd + 0 + PCIBR_RRB_SLOT_VIRTUAL] = virt1;
-	pcibr_soft->bs_rrb_valid[even_odd + 2 + PCIBR_RRB_SLOT_VIRTUAL] = virt2;
-	pcibr_soft->bs_rrb_valid[even_odd + 4 + PCIBR_RRB_SLOT_VIRTUAL] = virt3;
-	pcibr_soft->bs_rrb_valid[even_odd + 6 + PCIBR_RRB_SLOT_VIRTUAL] = virt4;
-
-	pcibr_unlock(pcibr_soft, s);
-    }
-    return 0;
-}
-
-/*
- *    pcibr_rrb_flush: chase down all the RRBs assigned
- *      to the specified connection point, and flush
- *      them.
- */
-void
-pcibr_rrb_flush(devfs_handle_t pconn_vhdl)
-{
-    pciio_info_t            pciio_info = pciio_info_get(pconn_vhdl);
-    pcibr_soft_t            pcibr_soft = (pcibr_soft_t) pciio_info_mfast_get(pciio_info);
-    pciio_slot_t            pciio_slot = pciio_info_slot_get(pciio_info);
-    bridge_t               *bridge = pcibr_soft->bs_base;
-    unsigned long           s;
-    reg_p                   rrbp;
-    unsigned                rrbm;
-    int                     i;
-    int                     rrbn;
-    unsigned                sval;
-    unsigned                mask;
-
-    sval = BRIDGE_RRB_EN | (pciio_slot >> 1);
-    mask = BRIDGE_RRB_EN | BRIDGE_RRB_PDEV;
-    rrbn = pciio_slot & 1;
-    rrbp = &bridge->b_rrb_map[rrbn].reg;
-
-    s = pcibr_lock(pcibr_soft);
-    rrbm = *rrbp;
-    for (i = 0; i < 8; ++i) {
-	if ((rrbm & mask) == sval)
-	    do_pcibr_rrb_flush(bridge, rrbn);
-	rrbm >>= 4;
-	rrbn += 2;
-    }
-    pcibr_unlock(pcibr_soft, s);
-}
-
 /*
  * pcibr_slot_initial_rrb_alloc
  *	Allocate a default number of rrbs for this slot on 
@@ -743,75 +809,82 @@
     pcibr_info_h	 pcibr_infoh;
     pcibr_info_t	 pcibr_info;
     bridge_t		*bridge;
-    int                  c0, c1, r;
+    int 		 vchan_total;
+    int			 vchan;
+    int                  chan[4];
 
     pcibr_soft = pcibr_soft_get(pcibr_vhdl);
 
-    if (!pcibr_soft || !PCIBR_VALID_SLOT(slot))
+    if (!pcibr_soft)
 	return(EINVAL);
 
-    bridge = pcibr_soft->bs_base;
+    if (!PCIBR_VALID_SLOT(pcibr_soft, slot))
+	return(EINVAL);
 
-    /* How may RRBs are on this slot?
-     */
-    c0 = do_pcibr_rrb_count_valid(bridge, slot);
-    c1 = do_pcibr_rrb_count_valid(bridge, slot + PCIBR_RRB_SLOT_VIRTUAL);
+    bridge = pcibr_soft->bs_base;
 
-#if PCIBR_RRB_DEBUG
-    printk(
+    /* How many RRBs are on this slot? */
+    vchan_total = NUMBER_VCHANNELS(bridge);
+    for (vchan = 0; vchan < vchan_total; vchan++) 
+        chan[vchan] = do_pcibr_rrb_count_valid(bridge, slot, vchan);
+
+    if (IS_PIC_SOFT(pcibr_soft)) {
+ 	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_RRB, pcibr_vhdl,
+	    "pcibr_slot_initial_rrb_alloc: slot %d started with %d+%d+%d+%d\n",
+	    PCIBR_DEVICE_TO_SLOT(pcibr_soft, slot), 
+	    chan[VCHAN0], chan[VCHAN1], chan[VCHAN2], chan[VCHAN3]));
+    } else {
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_RRB, pcibr_vhdl,
 	    "pcibr_slot_initial_rrb_alloc: slot %d started with %d+%d\n",
-            slot, c0, c1);
-#endif
+	    PCIBR_DEVICE_TO_SLOT(pcibr_soft, slot), 
+	    chan[VCHAN0], chan[VCHAN1]));
+    }
 
     /* Do we really need any?
      */
     pcibr_infoh = pcibr_soft->bs_slot[slot].bss_infos;
     pcibr_info = pcibr_infoh[0];
-    if ((pcibr_info->f_vendor == PCIIO_VENDOR_ID_NONE) &&
-	!pcibr_soft->bs_slot[slot].has_host) {
-	if (c0 > 0)
-	    do_pcibr_rrb_free(bridge, slot, c0);
-	if (c1 > 0)
-	    do_pcibr_rrb_free(bridge, slot + PCIBR_RRB_SLOT_VIRTUAL, c1);
-	pcibr_soft->bs_rrb_valid[slot] = 0x1000;
-	pcibr_soft->bs_rrb_valid[slot + PCIBR_RRB_SLOT_VIRTUAL] = 0x1000;
-	return(ENODEV);
-    }
 
-    pcibr_soft->bs_rrb_avail[slot & 1] -= c0 + c1;
-    pcibr_soft->bs_rrb_valid[slot] = c0;
-    pcibr_soft->bs_rrb_valid[slot + PCIBR_RRB_SLOT_VIRTUAL] = c1;
-
-    pcibr_soft->bs_rrb_avail[0] = do_pcibr_rrb_count_avail(bridge, 0);
-    pcibr_soft->bs_rrb_avail[1] = do_pcibr_rrb_count_avail(bridge, 1);
+    if (PCIBR_WAR_ENABLED(PV856866, pcibr_soft) && IS_PIC_SOFT(pcibr_soft) &&
+                        (slot == 2 || slot == 3) &&
+                        (pcibr_info->f_vendor == PCIIO_VENDOR_ID_NONE) &&
+                        !pcibr_soft->bs_slot[slot].has_host) {
+
+        for (vchan = 0; vchan < 2; vchan++) {
+            do_pcibr_rrb_free(bridge, slot, vchan, 8);
+            pcibr_soft->bs_rrb_valid[slot][vchan] = 0;
+        }
 
-    r = 3 - (c0 + c1);
+        pcibr_soft->bs_rrb_valid[slot][3] = chan[3];
 
-    if (r > 0) {
-	pcibr_soft->bs_rrb_res[slot] = r;
-	pcibr_soft->bs_rrb_avail[slot & 1] -= r;
+        return(ENODEV);
     }
 
-#if PCIBR_RRB_DEBUG
-    printk("\t%d+%d+%d",
-	    0xFFF & pcibr_soft->bs_rrb_valid[slot],
-	    0xFFF & pcibr_soft->bs_rrb_valid[slot + PCIBR_RRB_SLOT_VIRTUAL],
-	    pcibr_soft->bs_rrb_res[slot]);
-    printk("\n");
-#endif
+    for (vchan = 0; vchan < vchan_total; vchan++)
+        pcibr_soft->bs_rrb_valid[slot][vchan] = chan[vchan];
 
     return(0);
 }
 
+void
+rrb_reserved_free(pcibr_soft_t pcibr_soft, int slot)
+{
+        int res = pcibr_soft->bs_rrb_res[slot];
+
+        if (res) {
+                 pcibr_soft->bs_rrb_avail[slot & 1] += res;
+                 pcibr_soft->bs_rrb_res[slot] = 0;
+        }
+}
+
 /*
  * pcibr_initial_rrb
  *      Assign an equal total number of RRBs to all candidate slots, 
  *      where the total is the sum of the number of RRBs assigned to
  *      the normal channel, the number of RRBs assigned to the virtual
- *      channel, and the number of RRBs assigned as reserved. 
+ *      channels, and the number of RRBs assigned as reserved. 
  *
- *      A candidate slot is a populated slot on a non-SN1 system or 
- *      any existing (populated or empty) slot on an SN1 system.
+ *      A candidate slot is any existing (populated or empty) slot.
  *      Empty SN1 slots need RRBs to support hot-plug operations.
  */
 
@@ -822,7 +895,9 @@
     pcibr_soft_t            pcibr_soft = pcibr_soft_get(pcibr_vhdl);
     bridge_t               *bridge = pcibr_soft->bs_base;
     pciio_slot_t            slot;
-    int                     c0, c1;
+    int			    rrb_total;
+    int			    vchan_total;
+    int			    vchan;
     int                     have[2][3];
     int                     res[2];
     int                     eo;
@@ -831,16 +906,21 @@
     have[1][0] = have[1][1] = have[1][2] = 0;
     res[0] = res[1] = 0;
 
-    for (slot = 0; slot < 8; ++slot) {
+    vchan_total = NUMBER_VCHANNELS(bridge);
+
+    for (slot = pcibr_soft->bs_min_slot; 
+			slot < PCIBR_NUM_SLOTS(pcibr_soft); ++slot) {
         /* Initial RRB management; give back RRBs in all non-existent slots */
         (void) pcibr_slot_initial_rrb_alloc(pcibr_vhdl, slot);
 
         /* Base calculations only on existing slots */
         if ((slot >= first) && (slot <= last)) {
-            c0 = pcibr_soft->bs_rrb_valid[slot];
-            c1 = pcibr_soft->bs_rrb_valid[slot + PCIBR_RRB_SLOT_VIRTUAL];
-            if ((c0 + c1) < 3)
-                have[slot & 1][c0 + c1]++;
+	    rrb_total = 0;
+	    for (vchan = 0; vchan < vchan_total; vchan++) 
+		rrb_total += pcibr_soft->bs_rrb_valid[slot][vchan];
+
+            if (rrb_total < 3)
+                have[slot & 1][rrb_total]++;
         }
     }
 
@@ -867,30 +947,70 @@
     for (slot = first; slot <= last; ++slot) {
         int                     r;
 
-        c0 = pcibr_soft->bs_rrb_valid[slot];
-        c1 = pcibr_soft->bs_rrb_valid[slot + PCIBR_RRB_SLOT_VIRTUAL];
-        r = res[slot & 1] - (c0 + c1);
+	rrb_total = 0;
+	for (vchan = 0; vchan < vchan_total; vchan++)
+		rrb_total += pcibr_soft->bs_rrb_valid[slot][vchan];
+
+        r = res[slot & 1] - (rrb_total);
 
         if (r > 0) {
             pcibr_soft->bs_rrb_res[slot] = r;
             pcibr_soft->bs_rrb_avail[slot & 1] -= r;
-            }
+        }
     }
 
-#if PCIBR_RRB_DEBUG
-    printk("%v RRB MANAGEMENT: %d+%d free\n",
-            pcibr_vhdl,
-            pcibr_soft->bs_rrb_avail[0],
-            pcibr_soft->bs_rrb_avail[1]);
-    for (slot = first; slot <= last; ++slot)
-        printk("\tslot %d: %d+%d+%d", slot,
-                0xFFF & pcibr_soft->bs_rrb_valid[slot],
-                0xFFF & pcibr_soft->bs_rrb_valid[slot + PCIBR_RRB_SLOT_VIRTUAL],
-                pcibr_soft->bs_rrb_res[slot]);
-    printk("\n");
-#endif
+    pcibr_rrb_debug("pcibr_initial_rrb", pcibr_soft);
 
     return 0;
 
 }
 
+/*
+ * Dump the pcibr_soft_t RRB state variable
+ */
+void
+pcibr_rrb_debug(char *calling_func, pcibr_soft_t pcibr_soft)
+{
+    pciio_slot_t slot;
+    char tmp_str[256];
+    
+    if (pcibr_debug_mask & PCIBR_DEBUG_RRB) {
+        PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_RRB, pcibr_soft->bs_vhdl,
+                    "%s: rrbs available, even=%d, odd=%d\n", calling_func,
+                    pcibr_soft->bs_rrb_avail[0], pcibr_soft->bs_rrb_avail[1]));
+
+        if (IS_PIC_SOFT(pcibr_soft)) {
+            PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_RRB, pcibr_soft->bs_vhdl,
+                        "\tslot\tvchan0\tvchan1\tvchan2\tvchan3\treserved\n"));
+        } else {
+	    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_RRB, pcibr_soft->bs_vhdl,
+		        "\tslot\tvchan0\tvchan1\treserved\n"));
+        }
+
+        for (slot=0; slot < PCIBR_NUM_SLOTS(pcibr_soft); slot++) {
+	    /*
+             * The kernel only allows functions to have so many variable args,
+             * attempting to call PCIBR_DEBUG_ALWAYS() with more than 5 printf
+             * arguments fails so sprintf() it into a temporary string.
+             */
+	    if (IS_PIC_SOFT(pcibr_soft)) {
+                sprintf(tmp_str, "\t %d\t  %d\t  %d\t  %d\t  %d\t  %d\n", 
+		        PCIBR_DEVICE_TO_SLOT(pcibr_soft, slot),
+                        0xFFF & pcibr_soft->bs_rrb_valid[slot][VCHAN0],
+                        0xFFF & pcibr_soft->bs_rrb_valid[slot][VCHAN1],
+                        0xFFF & pcibr_soft->bs_rrb_valid[slot][VCHAN2],
+                        0xFFF & pcibr_soft->bs_rrb_valid[slot][VCHAN3],
+                        pcibr_soft->bs_rrb_res[slot]);
+	    } else {
+	        sprintf(tmp_str, "\t %d\t  %d\t  %d\t  %d\n", 
+		        PCIBR_DEVICE_TO_SLOT(pcibr_soft, slot),
+		        0xFFF & pcibr_soft->bs_rrb_valid[slot][VCHAN0],
+		        0xFFF & pcibr_soft->bs_rrb_valid[slot][VCHAN1],
+		        pcibr_soft->bs_rrb_res[slot]);
+	    }
+    
+            PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_RRB, pcibr_soft->bs_vhdl,
+                        "%s", tmp_str));
+        }
+    }
+}
diff -Nru a/arch/ia64/sn/io/sn2/pcibr/pcibr_slot.c b/arch/ia64/sn/io/sn2/pcibr/pcibr_slot.c
--- a/arch/ia64/sn/io/sn2/pcibr/pcibr_slot.c	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/sn/io/sn2/pcibr/pcibr_slot.c	Mon Dec 23 21:21:55 2002
@@ -10,6 +10,7 @@
 #include <linux/types.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/pci.h>
 #include <asm/sn/sgi.h>
 #include <asm/sn/sn_cpuid.h>
 #include <asm/sn/addrs.h>
@@ -30,70 +31,90 @@
 #include <asm/sn/eeprom.h>
 #include <asm/sn/io.h>
 #include <asm/sn/sn_private.h>
+#include <asm/sn/ate_utils.h>
+
+#ifdef __ia64
+#define rmallocmap atemapalloc
+#define rmfreemap atemapfree
+#define rmfree atefree
+#define rmalloc atealloc
+#endif
+
 
 extern pcibr_info_t     pcibr_info_get(devfs_handle_t);
-extern int              pcibr_widget_to_bus(int);
+extern int              pcibr_widget_to_bus(devfs_handle_t pcibr_vhdl);
 extern pcibr_info_t     pcibr_device_info_new(pcibr_soft_t, pciio_slot_t, pciio_function_t, pciio_vendor_id_t, pciio_device_id_t);
-extern void             pcibr_freeblock_sub(iopaddr_t *, iopaddr_t *, iopaddr_t, size_t);
 extern int		pcibr_slot_initial_rrb_alloc(devfs_handle_t,pciio_slot_t);
-#if 0
-int pcibr_slot_reset(devfs_handle_t pcibr_vhdl, pciio_slot_t slot);
-#endif
+extern int		pcibr_pcix_rbars_calc(pcibr_soft_t);
 
 int pcibr_slot_info_init(devfs_handle_t pcibr_vhdl, pciio_slot_t slot);
 int pcibr_slot_info_free(devfs_handle_t pcibr_vhdl, pciio_slot_t slot);
 int pcibr_slot_addr_space_init(devfs_handle_t pcibr_vhdl,  pciio_slot_t slot);
+int pcibr_slot_pcix_rbar_init(pcibr_soft_t pcibr_soft,  pciio_slot_t slot);
 int pcibr_slot_device_init(devfs_handle_t pcibr_vhdl,  pciio_slot_t slot);
 int pcibr_slot_guest_info_init(devfs_handle_t pcibr_vhdl,  pciio_slot_t slot);
 int pcibr_slot_call_device_attach(devfs_handle_t pcibr_vhdl,
 		 pciio_slot_t slot, int drv_flags);
 int pcibr_slot_call_device_detach(devfs_handle_t pcibr_vhdl,
 		 pciio_slot_t slot, int drv_flags);
-int pcibr_slot_detach(devfs_handle_t pcibr_vhdl, pciio_slot_t slot, int drv_flags);
+int pcibr_slot_detach(devfs_handle_t pcibr_vhdl, pciio_slot_t slot,
+                 int drv_flags, char *l1_msg, int *sub_errorp);
 int pcibr_is_slot_sys_critical(devfs_handle_t pcibr_vhdl, pciio_slot_t slot);
-int pcibr_probe_slot(bridge_t *, cfg_p, unsigned int *);
-void		 pcibr_device_info_free(devfs_handle_t, pciio_slot_t);
-extern uint64_t  do_pcibr_config_get(cfg_p, unsigned, unsigned);
+static int pcibr_probe_slot(bridge_t *, cfg_p, unsigned int *);
+void pcibr_device_info_free(devfs_handle_t, pciio_slot_t);
+iopaddr_t pcibr_bus_addr_alloc(pcibr_soft_t, pciio_win_info_t, 
+                               pciio_space_t, int, int, int);
+void pciibr_bus_addr_free(pcibr_soft_t, pciio_win_info_t);
+cfg_p pcibr_find_capability(cfg_p, unsigned);
+extern uint64_t  do_pcibr_config_get(int, cfg_p, unsigned, unsigned);
+void do_pcibr_config_set(int, cfg_p, unsigned, unsigned, uint64_t); 
 
-#ifdef LATER
 int pcibr_slot_attach(devfs_handle_t pcibr_vhdl, pciio_slot_t slot,
                 int drv_flags, char *l1_msg, int *sub_errorp);
-int pcibr_slot_pwr(devfs_handle_t, pciio_slot_t, int, char *);
-int pcibr_slot_startup(devfs_handle_t, pcibr_slot_req_t);
-int pcibr_slot_shutdown(devfs_handle_t, pcibr_slot_req_t);
-void pcibr_slot_func_info_return(pcibr_info_h pcibr_infoh, int func,
-                 pcibr_slot_func_info_resp_t funcp);
+
 int pcibr_slot_info_return(pcibr_soft_t pcibr_soft, pciio_slot_t slot,
                  pcibr_slot_info_resp_t respp);
-int pcibr_slot_query(devfs_handle_t, pcibr_slot_req_t);
-#endif	/* LATER */
 
 extern devfs_handle_t baseio_pci_vhdl;
 int scsi_ctlr_nums_add(devfs_handle_t, devfs_handle_t);
 
+
 /* For now .... */
 /*
  * PCI Hot-Plug Capability Flags
+
  */
 #define D_PCI_HOT_PLUG_ATTACH  0x200  /* Driver supports PCI hot-plug attach */
 #define D_PCI_HOT_PLUG_DETACH  0x400  /* Driver supports PCI hot-plug detach */
 
 
+/* 
+ * PCI-X Max Outstanding Split Transactions translation array and Max Memory
+ * Read Byte Count translation array, as defined in the PCI-X Specification.
+ * Section 7.2.3 & 7.2.4 of PCI-X Specification - rev 1.0
+ */
+#define MAX_SPLIT_TABLE 8
+#define MAX_READCNT_TABLE 4
+int max_splittrans_to_numbuf[MAX_SPLIT_TABLE] = {1, 2, 3, 4, 8, 12, 16, 32};
+int max_readcount_to_bufsize[MAX_READCNT_TABLE] = {512, 1024, 2048, 4096 };
+
+
 /*==========================================================================
  *	BRIDGE PCI SLOT RELATED IOCTLs
  */
 
-#ifdef LATER
-
 /*
  * pcibr_slot_startup
  *	Software start-up the PCI slot.
  */
+
+#ifdef PIC_LATER
+
 int
 pcibr_slot_startup(devfs_handle_t pcibr_vhdl, pcibr_slot_req_t reqp)
 {
     pcibr_soft_t                   pcibr_soft = pcibr_soft_get(pcibr_vhdl);
-    pciio_slot_t                   slot = reqp->req_slot;
+    pciio_slot_t                   slot;
     int                            error = 0;
     char                           l1_msg[BRL1_QSIZE+1];
     struct pcibr_slot_up_resp_s    tmp_up_resp;
@@ -103,17 +124,22 @@
         return(PCI_NOT_A_BRIDGE);
     }
 
+    /* req_slot is the 'external' slot number, convert for internal use */
+    slot = PCIBR_SLOT_TO_DEVICE(pcibr_soft, reqp->req_slot);
+
     /* Do not allow start-up of a slot in a shoehorn */
     if(nic_vertex_info_match(pcibr_soft->bs_conn, XTALK_PCI_PART_NUM)) {
        return(PCI_SLOT_IN_SHOEHORN);
     }
  
     /* Check for the valid slot */
-    if (!PCIBR_VALID_SLOT(slot))
+    if (!PCIBR_VALID_SLOT(pcibr_soft, slot))
         return(PCI_NOT_A_SLOT);
 
+#ifdef PIC_LATER
     /* Acquire update access to the bus */
     mrlock(pcibr_soft->bs_bus_lock, MR_UPDATE, PZERO);
+#endif
 
     if (pcibr_soft->bs_slot[slot].slot_status & SLOT_STARTUP_CMPLT) {
         error = PCI_SLOT_ALREADY_UP;
@@ -132,9 +158,10 @@
 
     startup_unlock:
 
+#ifdef PIC_LATER
     /* Release the bus lock */
     mrunlock(pcibr_soft->bs_bus_lock);
-
+#endif
     return(error);
 }
 
@@ -147,7 +174,7 @@
 {
     pcibr_soft_t                   pcibr_soft = pcibr_soft_get(pcibr_vhdl);
     bridge_t                      *bridge;
-    pciio_slot_t                   slot = reqp->req_slot;
+    pciio_slot_t                   slot;
     int                            error = 0;
     char                           l1_msg[BRL1_QSIZE+1];
     struct pcibr_slot_down_resp_s  tmp_down_resp;
@@ -158,10 +185,13 @@
         return(PCI_NOT_A_BRIDGE);
     }
 
+    /* req_slot is the 'external' slot number, convert for internal use */
+    slot = PCIBR_SLOT_TO_DEVICE(pcibr_soft, reqp->req_slot);
+
     bridge = pcibr_soft->bs_base;
 
     /* Check for valid slot */
-    if (!PCIBR_VALID_SLOT(slot))
+    if (!PCIBR_VALID_SLOT(pcibr_soft, slot))
         return(PCI_NOT_A_SLOT);
 
     /* Do not allow shut-down of a slot in a shoehorn */
@@ -169,8 +199,10 @@
        return(PCI_SLOT_IN_SHOEHORN);
     }
 
+#ifdef PIC_LATER
     /* Acquire update access to the bus */
     mrlock(pcibr_soft->bs_bus_lock, MR_UPDATE, PZERO);
+#endif
 
     if ((pcibr_soft->bs_slot[slot].slot_status & SLOT_SHUTDOWN_CMPLT) ||
         ((pcibr_soft->bs_slot[slot].slot_status & SLOT_STATUS_MASK) == 0)) {
@@ -182,6 +214,13 @@
         goto shutdown_unlock;
     }
 
+    /* Do not allow a multi-function card to be hot-plug removed */
+    if (pcibr_soft->bs_slot[slot].bss_ninfo > 1) {
+        tmp_down_resp.resp_sub_errno = EPERM;
+        error = PCI_MULTI_FUNC_ERR;
+        goto shutdown_copyout;
+    }
+
     /* Do not allow the last 33 MHz card to be removed */
     if ((bridge->b_wid_control & BRIDGE_CTRL_BUS_SPEED_MASK) ==
          BRIDGE_CTRL_BUS_SPEED_33) {
@@ -204,17 +243,22 @@
     strncpy(tmp_down_resp.resp_l1_msg, l1_msg, L1_QSIZE);
     tmp_down_resp.resp_l1_msg[L1_QSIZE] = '\0';
 
+    shutdown_copyout:
+
     if (COPYOUT(&tmp_down_resp, reqp->req_respp.down, reqp->req_size)) {
         return(EFAULT);
     }
 
     shutdown_unlock:
 
+#ifdef PIC_LATER
     /* Release the bus lock */
     mrunlock(pcibr_soft->bs_bus_lock);
+#endif
 
     return(error);
 }
+#endif	/* PIC_LATER */
 
 char *pci_space_name[] = {"NONE", 
 			  "ROM",
@@ -240,6 +284,7 @@
 {
     pcibr_info_t                 pcibr_info = pcibr_infoh[func];
     int                          win;
+    boolean_t is_sys_critical_vertex(devfs_handle_t);
 
     funcp->resp_f_status = 0;
 
@@ -248,16 +293,19 @@
     }
 
     funcp->resp_f_status |= FUNC_IS_VALID;
+#if defined(SUPPORT_PRINTING_V_FORMAT)
     sprintf(funcp->resp_f_slot_name, "%v", pcibr_info->f_vertex);
-
+#endif
     if(is_sys_critical_vertex(pcibr_info->f_vertex)) {
         funcp->resp_f_status |= FUNC_IS_SYS_CRITICAL;
     }
 
     funcp->resp_f_bus = pcibr_info->f_bus;
-    funcp->resp_f_slot = pcibr_info->f_slot;
+    funcp->resp_f_slot = PCIBR_INFO_SLOT_GET_EXT(pcibr_info);
     funcp->resp_f_func = pcibr_info->f_func;
+#if defined(SUPPORT_PRINTING_V_FORMAT)
     sprintf(funcp->resp_f_master_name, "%v", pcibr_info->f_master);
+#endif
     funcp->resp_f_pops = pcibr_info->f_pops;
     funcp->resp_f_efunc = pcibr_info->f_efunc;
     funcp->resp_f_einfo = pcibr_info->f_einfo;
@@ -297,20 +345,29 @@
     reg_p                        b_respp;
     pcibr_slot_info_resp_t       slotp;
     pcibr_slot_func_info_resp_t  funcp;
+    boolean_t is_sys_critical_vertex(devfs_handle_t);
+    extern void snia_kmem_free(void *, int);
 
-    slotp = kmem_zalloc(sizeof(*slotp), KM_SLEEP);
+    slotp = snia_kmem_zalloc(sizeof(*slotp), 0);
     if (slotp == NULL) {
         return(ENOMEM);
     }
 
     pss = &pcibr_soft->bs_slot[slot];
 
+    slotp->resp_bs_bridge_mode = pcibr_soft->bs_bridge_mode;
+    slotp->resp_bs_bridge_type = pcibr_soft->bs_bridge_type;
+
     slotp->resp_has_host = pss->has_host;
     slotp->resp_host_slot = pss->host_slot;
+#if defined(SUPPORT_PRINTING_V_FORMAT)
     sprintf(slotp->resp_slot_conn_name, "%v", pss->slot_conn);
+#else
+    sprintf(slotp->resp_slot_conn_name, "%p", (void *)pss->slot_conn);
+#endif
     slotp->resp_slot_status = pss->slot_status;
 
-    slotp->resp_l1_bus_num = io_path_map_widget(pcibr_soft->bs_vhdl);
+    slotp->resp_l1_bus_num = pcibr_widget_to_bus(pcibr_soft->bs_vhdl);
 
     if (is_sys_critical_vertex(pss->slot_conn)) {
         slotp->resp_slot_status |= SLOT_IS_SYS_CRITICAL;
@@ -342,9 +399,10 @@
     slotp->resp_bss_cmd_pointer = pss->bss_cmd_pointer;
     slotp->resp_bss_cmd_shadow = pss->bss_cmd_shadow;
 
-    slotp->resp_bs_rrb_valid = pcibr_soft->bs_rrb_valid[slot];
-    slotp->resp_bs_rrb_valid_v = pcibr_soft->bs_rrb_valid[slot +
-                                                      PCIBR_RRB_SLOT_VIRTUAL];
+    slotp->resp_bs_rrb_valid = pcibr_soft->bs_rrb_valid[slot][VCHAN0];
+    slotp->resp_bs_rrb_valid_v1 = pcibr_soft->bs_rrb_valid[slot][VCHAN1];
+    slotp->resp_bs_rrb_valid_v2 = pcibr_soft->bs_rrb_valid[slot][VCHAN2];
+    slotp->resp_bs_rrb_valid_v3 = pcibr_soft->bs_rrb_valid[slot][VCHAN3];
     slotp->resp_bs_rrb_res = pcibr_soft->bs_rrb_res[slot];
 
     if (slot & 1) {
@@ -355,16 +413,21 @@
 
     slotp->resp_b_resp = *b_respp;
 
-    slotp->resp_b_wid_control = bridge->b_wid_control;
     slotp->resp_b_int_device = bridge->b_int_device;
-    slotp->resp_b_int_enable = bridge->b_int_enable;
-    slotp->resp_b_int_host = bridge->b_int_addr[slot].addr;
+
+    if (IS_PIC_SOFT(pcibr_soft)) {
+	slotp->resp_p_int_enable = bridge->p_int_enable_64;
+	slotp->resp_p_int_host = bridge->p_int_addr_64[slot];
+    } else {
+	slotp->resp_b_int_enable = bridge->b_int_enable;
+	slotp->resp_b_int_host = bridge->b_int_addr[slot].addr;
+    }
 
     if (COPYOUT(slotp, respp, sizeof(*respp))) {
         return(EFAULT);
     }
 
-    kmem_free(slotp, sizeof(*slotp));
+    snia_kmem_free(slotp, sizeof(*slotp));
 
     return(0);
 }
@@ -395,19 +458,26 @@
 pcibr_slot_query(devfs_handle_t pcibr_vhdl, pcibr_slot_req_t reqp)
 {
     pcibr_soft_t            pcibr_soft = pcibr_soft_get(pcibr_vhdl);
-    pciio_slot_t            slot = reqp->req_slot;
+    pciio_slot_t            slot;
     pciio_slot_t            tmp_slot;
     pcibr_slot_info_resp_t  respp = reqp->req_respp.query;
     int                     size = reqp->req_size;
-    int                     error;
+    int                     error = 0;
 
     /* Make sure that we are dealing with a bridge device vertex */
     if (!pcibr_soft) {
         return(PCI_NOT_A_BRIDGE);
     }
 
+    /* req_slot is the 'external' slot number, convert for internal use */
+    slot = PCIBR_SLOT_TO_DEVICE(pcibr_soft, reqp->req_slot);
+
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_HOTPLUG, pcibr_vhdl,
+                "pcibr_slot_query: pcibr_soft=0x%x, slot=%d, reqp=0x%x\n",
+                pcibr_soft, slot, reqp));
+
     /* Make sure that we have a valid PCI slot number or PCIIO_SLOT_NONE */
-    if ((!PCIBR_VALID_SLOT(slot)) && (slot != PCIIO_SLOT_NONE)) {
+    if ((!PCIBR_VALID_SLOT(pcibr_soft, slot)) && (slot != PCIIO_SLOT_NONE)) {
         return(PCI_NOT_A_SLOT);
     }
 
@@ -422,32 +492,37 @@
             return(PCI_RESP_AREA_TOO_SMALL);
         }
 
+#ifdef PIC_LATER
         /* Acquire read access to the bus */
         mrlock(pcibr_soft->bs_bus_lock, MR_ACCESS, PZERO);
-
+#endif
         error = pcibr_slot_info_return(pcibr_soft, slot, respp);
 
+#ifdef PIC_LATER
         /* Release the bus lock */
         mrunlock(pcibr_soft->bs_bus_lock);
-
+#endif
         return(error);
     }
 
     /* Return information for all the slots */
-    for (tmp_slot = 0; tmp_slot < 8; tmp_slot++) {
+    for (tmp_slot = pcibr_soft->bs_min_slot; 
+		tmp_slot < PCIBR_NUM_SLOTS(pcibr_soft); tmp_slot++) {
 
         if (size < sizeof(*respp)) {
             return(PCI_RESP_AREA_TOO_SMALL);
         }
 
+#ifdef PIC_LATER
         /* Acquire read access to the bus */
         mrlock(pcibr_soft->bs_bus_lock, MR_ACCESS, PZERO);
-
+#endif
         error = pcibr_slot_info_return(pcibr_soft, tmp_slot, respp);
 
+#ifdef PCI_LATER
         /* Release the bus lock */
         mrunlock(pcibr_soft->bs_bus_lock);
-
+#endif
         if (error) {
             return(error);
         }
@@ -458,60 +533,92 @@
 
     return(error);
 }
-#endif	/* LATER */
 
-/* FIXME: there should be a better way to do this.
- * pcibr_attach() needs PCI_ADDR_SPACE_LIMITS_STORE
+#if 0
+/*
+ * pcibr_slot_reset
+ *	Reset the PCI device in the particular slot.
+ *
+ *      The Xbridge does not comply with the PCI Specification
+ *      when resetting an indiviaudl slot.  An individual slot is
+ *      is reset by toggling the slot's bit in the Xbridge Control
+ *      Register.  The Xbridge will assert the target slot's 
+ *      (non-bussed) RST signal, but does not assert the (bussed) 
+ *      REQ64 signal as required by the specification.   As
+ *      designed, the Xbridge cannot assert the REQ64 signal
+ *      becuase it may interfere with a bus transaction in progress.
+ *      The practical effects of this Xbridge implementation is
+ *      device dependent;  it probably will not adversely effect
+ *      32-bit cards, but may disable 64-bit data transfers by those
+ *      cards that normally support 64-bit data transfers.  
+ *
+ *      The Xbridge will assert REQ64 when all four slots are reset
+ *      by simultaneously toggling all four slot reset bits in the
+ *      Xbridge Control Register.  This is basically a PCI bus reset
+ *      and asserting the (bussed) REQ64 signal will not interfere
+ *      with any bus transactions in progress.
+ *
+ *      The Xbridge (and the SN0 Bridge) support resetting only
+ *      four PCI bus slots via the (X)bridge Control Register.
+ *
+ *      To reset an individual slot for the PCI Hot-Plug feature
+ *      use the L1 console commands to power-down and then 
+ *      power-up the slot, or use the kernel infrastructure
+ *      functions to power-down/up the slot when they are
+ *      implemented for SN1.
  */
+int
+pcibr_slot_reset(devfs_handle_t pcibr_vhdl, pciio_slot_t slot)
+{
+	pcibr_soft_t		 pcibr_soft = pcibr_soft_get(pcibr_vhdl);
+	bridge_t		*bridge;
+	bridgereg_t		 ctrlreg,tmp;
+	volatile bridgereg_t	*wrb_flush;
 
-/* 
- * PCI_ADDR_SPACE_LIMITS_LOAD
- *	Gets the current values of 
- *		pci io base, 
- *		pci io last,
- *		pci low memory base,
- *		pci low memory last,
- *		pci high memory base,
- * 		pci high memory last
- */
-#define PCI_ADDR_SPACE_LIMITS_LOAD()			\
-    pci_io_fb = pcibr_soft->bs_spinfo.pci_io_base;	\
-    pci_io_fl = pcibr_soft->bs_spinfo.pci_io_last;	\
-    pci_lo_fb = pcibr_soft->bs_spinfo.pci_swin_base;	\
-    pci_lo_fl = pcibr_soft->bs_spinfo.pci_swin_last;	\
-    pci_hi_fb = pcibr_soft->bs_spinfo.pci_mem_base;	\
-    pci_hi_fl = pcibr_soft->bs_spinfo.pci_mem_last;
-/*
- * PCI_ADDR_SPACE_LIMITS_STORE
- *	Sets the current values of
- *		pci io base, 
- *		pci io last,
- *		pci low memory base,
- *		pci low memory last,
- *		pci high memory base,
- * 		pci high memory last
- */
-#define PCI_ADDR_SPACE_LIMITS_STORE()			\
-    pcibr_soft->bs_spinfo.pci_io_base = pci_io_fb;	\
-    pcibr_soft->bs_spinfo.pci_io_last = pci_io_fl;	\
-    pcibr_soft->bs_spinfo.pci_swin_base = pci_lo_fb;	\
-    pcibr_soft->bs_spinfo.pci_swin_last = pci_lo_fl;	\
-    pcibr_soft->bs_spinfo.pci_mem_base = pci_hi_fb;	\
-    pcibr_soft->bs_spinfo.pci_mem_last = pci_hi_fl;
-
-#define PCI_ADDR_SPACE_LIMITS_PRINT()			\
-    printf("+++++++++++++++++++++++\n"			\
-	   "IO base 0x%x last 0x%x\n"			\
-	   "SWIN base 0x%x last 0x%x\n"			\
-	   "MEM base 0x%x last 0x%x\n"			\
-	   "+++++++++++++++++++++++\n",			\
-	   pcibr_soft->bs_spinfo.pci_io_base,		\
-	   pcibr_soft->bs_spinfo.pci_io_last,		\
-	   pcibr_soft->bs_spinfo.pci_swin_base,		\
-	   pcibr_soft->bs_spinfo.pci_swin_last,		\
-	   pcibr_soft->bs_spinfo.pci_mem_base,		\
-	   pcibr_soft->bs_spinfo.pci_mem_last);
+	if (!pcibr_soft)
+		return(EINVAL);
+
+	if (!PCIBR_VALID_SLOT(pcibr_soft, slot))
+		return(EINVAL);
+
+	/* Enable the DMA operations from this device of the xtalk widget
+	 * (PCI host bridge in this case).
+	 */
+	xtalk_widgetdev_enable(pcibr_soft->bs_conn, slot);
+
+	/* Set the reset slot bit in the bridge's wid control register
+	 * to reset the PCI slot 
+	 */
+	bridge = pcibr_soft->bs_base;
+
+	/* Read the bridge widget control and clear out the reset pin
+	 * bit for the corresponding slot. 
+	 */
+	tmp = ctrlreg = bridge->b_wid_control;
+
+	tmp &= ~BRIDGE_CTRL_RST_PIN(slot); 
+
+	bridge->b_wid_control = tmp;
+	tmp = bridge->b_wid_control;
+
+	/* Restore the old control register back.
+	 * NOTE : PCI card gets reset when the reset pin bit
+	 * changes from 0 (set above) to 1 (going to be set now).
+	 */
+
+	bridge->b_wid_control = ctrlreg;
 
+	/* Flush the write buffers if any !! */
+	wrb_flush = &(bridge->b_wr_req_buf[slot].reg);
+	while (*wrb_flush);
+
+	return(0);
+}
+#endif
+
+#define PROBE_LOCK 0	/* FIXME: we're attempting to lock around accesses
+			 * to b_int_enable.   This hangs pcibr_probe_slot()
+			 */
 
 /*
  * pcibr_slot_info_init
@@ -534,12 +641,12 @@
     pciio_vendor_id_t       vendor;
     pciio_device_id_t       device;
     unsigned                htype;
+    unsigned                lt_time;
+    int                     nbars;
     cfg_p                   wptr;
+    cfg_p                   pcix_cap;
     int                     win;
     pciio_space_t           space;
-    iopaddr_t		    pci_io_fb,	pci_io_fl;
-    iopaddr_t		    pci_lo_fb,  pci_lo_fl;
-    iopaddr_t		    pci_hi_fb,  pci_hi_fl;
     int			    nfunc;
     pciio_function_t	    rfunc;
     int			    func;
@@ -552,7 +659,7 @@
 	return(EINVAL);
 
     bridge = pcibr_soft->bs_base;
-    if (!PCIBR_VALID_SLOT(slot))
+    if (!PCIBR_VALID_SLOT(pcibr_soft, slot))
 	return(EINVAL);
 
     /* If we have a host slot (eg:- IOC3 has 2 PCI slots and the initialization
@@ -566,28 +673,35 @@
     if (pcibr_is_slot_sys_critical(pcibr_vhdl, slot))
         return(EPERM);
 
-    /* Load the current values of allocated PCI address spaces */
-    PCI_ADDR_SPACE_LIMITS_LOAD();
-    
     /* Try to read the device-id/vendor-id from the config space */
-    cfgw = bridge->b_type0_cfg_dev[slot].l;
+    cfgw = pcibr_slot_config_addr(bridge, slot, 0);
 
+#if PROBE_LOCK
+    s = pcibr_lock(pcibr_soft);
+#endif
     if (pcibr_probe_slot(bridge, cfgw, &idword)) 
 	return(ENODEV);
+#if PROBE_LOCK
+    pcibr_unlock(pcibr_soft, s);
+#endif
 
     slotp = &pcibr_soft->bs_slot[slot];
     slotp->slot_status |= SLOT_POWER_UP;
 
     vendor = 0xFFFF & idword;
+    device = 0xFFFF & (idword >> 16);
+
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_PROBE, pcibr_vhdl,
+		"pcibr_slot_info_init: slot=%d, vendor=0x%x, device=0x%x\n",
+		PCIBR_DEVICE_TO_SLOT(pcibr_soft, slot), vendor, device));
+
     /* If the vendor id is not valid then the slot is not populated
      * and we are done.
      */
     if (vendor == 0xFFFF) 
 	return(ENODEV);			
     
-    device = 0xFFFF & (idword >> 16);
-    htype = do_pcibr_config_get(cfgw, PCI_CFG_HEADER_TYPE, 1);
-
+    htype = do_pcibr_config_get(IS_PIC_SOFT(pcibr_soft), cfgw, PCI_CFG_HEADER_TYPE, 1);
     nfunc = 1;
     rfunc = PCIIO_FUNC_NONE;
     pfail = 0;
@@ -599,11 +713,17 @@
 
     if (htype & 0x80) {		/* MULTIFUNCTION */
 	for (func = 1; func < 8; ++func) {
-	    cfgw = bridge->b_type0_cfg_dev[slot].f[func].l;
+	    cfgw = pcibr_func_config_addr(bridge, 0, slot, func, 0);
+#if PROBE_LOCK
+            s = pcibr_lock(pcibr_soft);
+#endif
 	    if (pcibr_probe_slot(bridge, cfgw, &idwords[func])) {
 		pfail |= 1 << func;
 		continue;
 	    }
+#if PROBE_LOCK
+            pcibr_unlock(pcibr_soft, s);
+#endif
 	    vendor = 0xFFFF & idwords[func];
 	    if (vendor == 0xFFFF) {
 		pfail |= 1 << func;
@@ -612,7 +732,7 @@
 	    nfunc = func + 1;
 	    rfunc = 0;
 	}
-	cfgw = bridge->b_type0_cfg_dev[slot].l;
+        cfgw = pcibr_slot_config_addr(bridge, slot, 0);
     }
     NEWA(pcibr_infoh, nfunc);
     
@@ -627,39 +747,162 @@
 		continue;
 	    
 	    idword = idwords[func];
-	    cfgw = bridge->b_type0_cfg_dev[slot].f[func].l;
+	    cfgw = pcibr_func_config_addr(bridge, 0, slot, func, 0);
 	    
 	    device = 0xFFFF & (idword >> 16);
-	    htype = do_pcibr_config_get(cfgw, PCI_CFG_HEADER_TYPE, 1);
+	    htype = do_pcibr_config_get(IS_PIC_SOFT(pcibr_soft), cfgw, PCI_CFG_HEADER_TYPE, 1);
 	    rfunc = func;
 	}
 	htype &= 0x7f;
 	if (htype != 0x00) {
-	    printk(KERN_WARNING  "%s pcibr: pci slot %d func %d has strange header type 0x%x\n",
+	    printk(KERN_WARNING 
+		"%s pcibr: pci slot %d func %d has strange header type 0x%x\n",
 		    pcibr_soft->bs_name, slot, func, htype);
-	    continue;
+	    nbars = 2;
+	} else {
+	    nbars = PCI_CFG_BASE_ADDRS;
+	}
+
+	PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_CONFIG, pcibr_vhdl,
+                "pcibr_slot_info_init: slot=%d, func=%d, cfgw=0x%x\n",
+		PCIBR_DEVICE_TO_SLOT(pcibr_soft,slot), func, cfgw));
+
+#ifdef PIC_LATER
+        /*
+         * Check for a Quad ATM PCI "card" and return all the PCI bus
+         * memory and I/O space.  This will work-around an apparent
+         * hardware problem with the Quad ATM XIO card handling large
+         * PIO addresses.  Releasing all the space for use by the card
+         * will lower the PIO addresses with the PCI bus address space.
+         * This is OK since the PROM did not assign any BAR addresses. 
+         *
+         * Only release all the PCI bus addresses once.
+         *
+         */
+        if ((vendor == LINC_VENDOR_ID_NUM) && (device == LINC_DEVICE_ID_NUM)) {
+            iopaddr_t               prom_base_addr = pcibr_soft->bs_xid << 24;
+            int                     prom_base_size = 0x1000000;
+
+            if (!(pcibr_soft->bs_bus_addr_status & PCIBR_BUS_ADDR_MEM_FREED)) {
+		pciio_device_win_populate(&pcibr_soft->bs_mem_win_map,
+					  prom_base_addr, prom_base_size);
+                pcibr_soft->bs_bus_addr_status |= PCIBR_BUS_ADDR_MEM_FREED;
+            }
+
+            if (!(pcibr_soft->bs_bus_addr_status & PCIBR_BUS_ADDR_IO_FREED)) {
+		pciio_device_win_populate(&pcibr_soft->bs_io_win_map,
+					  prom_base_addr, prom_base_size);
+                pcibr_soft->bs_bus_addr_status |= PCIBR_BUS_ADDR_IO_FREED;
+            }
+        }
+#endif	/* PIC_LATER */
+
+	/* 
+	 * If the latency timer has already been set, by prom or by the
+	 * card itself, use that value.  Otherwise look at the device's
+	 * 'min_gnt' and attempt to calculate a latency time. 
+	 *
+	 * NOTE: For now if the device is on the 'real time' arbitration
+	 * ring we dont set the latency timer.  
+	 *
+	 * WAR: SGI's IOC3 and RAD devices target abort if you write a 
+	 * single byte into their config space.  So don't set the Latency
+	 * Timer for these devices
+	 */
+
+	lt_time = do_pcibr_config_get(IS_PIC_SOFT(pcibr_soft), cfgw, PCI_CFG_LATENCY_TIMER, 1);
+
+	if ((lt_time == 0) && !(bridge->b_device[slot].reg & BRIDGE_DEV_RT) &&
+	    !((vendor == IOC3_VENDOR_ID_NUM) && 
+	      (
+#ifdef PIC_LATER
+	       (device == IOC3_DEVICE_ID_NUM) ||
+	       (device == LINC_DEVICE_ID_NUM) ||
+#endif
+	       (device == 0x5 /* RAD_DEV */)))) {
+	     unsigned	min_gnt;
+	     unsigned	min_gnt_mult;
+	    
+	    /* 'min_gnt' indicates how long of a burst period a device
+	     * needs in increments of 250ns.  But latency timer is in
+	     * PCI clock cycles, so a conversion is needed.
+	     */
+	    min_gnt = do_pcibr_config_get(IS_PIC_SOFT(pcibr_soft), cfgw, PCI_MIN_GNT, 1);
+
+	    if (IS_133MHZ(pcibr_soft))
+		min_gnt_mult = 32;	/* 250ns @ 133MHz in clocks */
+	    else if (IS_100MHZ(pcibr_soft))
+		min_gnt_mult = 24;	/* 250ns @ 100MHz in clocks */
+	    else if (IS_66MHZ(pcibr_soft))
+		min_gnt_mult = 16;	/* 250ns @ 66MHz, in clocks */
+	    else
+		min_gnt_mult = 8;	/* 250ns @ 33MHz, in clocks */
+
+	    if ((min_gnt != 0) && ((min_gnt * min_gnt_mult) < 256))
+		lt_time = (min_gnt * min_gnt_mult);
+	    else
+		lt_time = 4 * min_gnt_mult;	  /* 1 micro second */
+
+	    do_pcibr_config_set(IS_PIC_SOFT(pcibr_soft), cfgw, PCI_CFG_LATENCY_TIMER, 1, lt_time);
+
+	    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_CONFIG, pcibr_vhdl,
+                    "pcibr_slot_info_init: set Latency Timer for slot=%d, "
+		    "func=%d, to 0x%x\n", 
+		    PCIBR_DEVICE_TO_SLOT(pcibr_soft, slot), func, lt_time));
+	}
+
+	/* Get the PCI-X capability if running in PCI-X mode.  If the func
+	 * doesnt have a pcix capability, allocate a PCIIO_VENDOR_ID_NONE
+	 * pcibr_info struct so the device driver for that function is not
+	 * called.
+	 */
+	if (IS_PCIX(pcibr_soft)) {
+	    if (!(pcix_cap = pcibr_find_capability(cfgw, PCI_CAP_PCIX))) {
+		printk(KERN_WARNING
+#if defined(SUPPORT_PRINTING_V_FORMAT)
+		        "%v: Bus running in PCI-X mode, But card in slot %d, "
+		        "func %d not PCI-X capable\n", pcibr_vhdl, slot, func);
+#else
+		        "0x%lx: Bus running in PCI-X mode, But card in slot %d, "
+		        "func %d not PCI-X capable\n", (unsigned long)pcibr_vhdl, slot, func);
+#endif
+		pcibr_device_info_new(pcibr_soft, slot, PCIIO_FUNC_NONE,
+		               PCIIO_VENDOR_ID_NONE, PCIIO_DEVICE_ID_NONE);
+		continue;
+	    }
+	    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_CONFIG, pcibr_vhdl,
+                    "pcibr_slot_info_init: PCI-X capability at 0x%x for "
+		    "slot=%d, func=%d\n", 
+		    pcix_cap, PCIBR_DEVICE_TO_SLOT(pcibr_soft, slot), func));
+	} else {
+	    pcix_cap = NULL;
 	}
-#if DEBUG && ATTACH_DEBUG
-	printk(KERN_NOTICE   
-		"%s pcibr: pci slot %d func %d: vendor 0x%x device 0x%x",
-		pcibr_soft->bs_name, slot, func, vendor, device);
-#endif	
 
 	pcibr_info = pcibr_device_info_new
 	    (pcibr_soft, slot, rfunc, vendor, device);
+
+	/* Keep a running total of the number of PIC-X functions on the bus
+         * and the number of max outstanding split trasnactions that they
+	 * have requested.  NOTE: "pcix_cap != NULL" implies IS_PCIX()
+	 */
+	pcibr_info->f_pcix_cap = (cap_pcix_type0_t *)pcix_cap;
+	if (pcibr_info->f_pcix_cap) {
+	    int max_out;      /* max outstanding splittrans from status reg */
+
+	    pcibr_soft->bs_pcix_num_funcs++;
+	    max_out = pcibr_info->f_pcix_cap->pcix_type0_status.max_out_split;
+	    pcibr_soft->bs_pcix_split_tot += max_splittrans_to_numbuf[max_out];
+	}
+
 	conn_vhdl = pciio_device_info_register(pcibr_vhdl, &pcibr_info->f_c);
 	if (func == 0)
 	    slotp->slot_conn = conn_vhdl;
 
-#ifdef LITTLE_ENDIAN
-	cmd_reg = cfgw[(PCI_CFG_COMMAND ^ 4) / 4];
-#else
-	cmd_reg = cfgw[PCI_CFG_COMMAND / 4];
-#endif
+	cmd_reg = do_pcibr_config_get(IS_PIC_SOFT(pcibr_soft), cfgw, PCI_CFG_COMMAND, 4);
 	
 	wptr = cfgw + PCI_CFG_BASE_ADDR_0 / 4;
 
-	for (win = 0; win < PCI_CFG_BASE_ADDRS; ++win) {
+	for (win = 0; win < nbars; ++win) {
 	    iopaddr_t               base, mask, code;
 	    size_t                  size;
 
@@ -706,11 +949,7 @@
 	     * this could be pushed up into pciio, when we
 	     * start supporting more PCI providers.
 	     */
-#ifdef LITTLE_ENDIAN
-	    base = wptr[((win*4)^4)/4];
-#else
-	    base = wptr[win];
-#endif
+	    base = do_pcibr_config_get(IS_PIC_SOFT(pcibr_soft), wptr, (win * 4), 4);
 
 	    if (base & PCI_BA_IO_SPACE) {
 		/* BASE is in I/O space. */
@@ -736,11 +975,7 @@
 		} else if (base & 0xC0000000) {
 		    base = 0;	/* outside permissable range */
 		} else if ((code == PCI_BA_MEM_64BIT) &&
-#ifdef LITTLE_ENDIAN
-			   (wptr[(((win + 1)*4)^4)/4] != 0)) {
-#else 
-			   (wptr[win + 1] != 0)) {
-#endif /* LITTLE_ENDIAN */
+			   (do_pcibr_config_get(IS_PIC_SOFT(pcibr_soft), wptr, ((win + 1)*4), 4) != 0)) {
 		    base = 0;	/* outside permissable range */
 		}
 	    }
@@ -748,13 +983,8 @@
 	    if (base != 0) {	/* estimate size */
 		size = base & -base;
 	    } else {		/* calculate size */
-#ifdef LITTLE_ENDIAN
-		wptr[((win*4)^4)/4] = ~0;	/* turn on all bits */
-		size = wptr[((win*4)^4)/4];	/* get stored bits */
-#else 
-		wptr[win] = ~0;	/* turn on all bits */
-		size = wptr[win];	/* get stored bits */
-#endif /* LITTLE_ENDIAN */
+		do_pcibr_config_set(IS_PIC_SOFT(pcibr_soft), wptr, (win * 4), 4, ~0);    /* write 1's */
+		size = do_pcibr_config_get(IS_PIC_SOFT(pcibr_soft), wptr, (win * 4), 4); /* read back */
 		size &= mask;	/* keep addr */
 		size &= -size;	/* keep lsbit */
 		if (size == 0)
@@ -765,28 +995,6 @@
 	    pcibr_info->f_window[win].w_base = base;
 	    pcibr_info->f_window[win].w_size = size;
 
-	    /*
-	     * If this window already has PCI space
-	     * allocated for it, "subtract" that space from
-	     * our running freeblocks. Don't worry about
-	     * overlaps in existing allocated windows; we
-	     * may be overstating their sizes anyway.
-	     */
-
-	    if (base && size) {
-		if (space == PCIIO_SPACE_IO) {
-		    pcibr_freeblock_sub(&pci_io_fb,
-					&pci_io_fl,
-					base, size);
-		} else {
-		    pcibr_freeblock_sub(&pci_lo_fb,
-					&pci_lo_fl,
-					base, size);
-		    pcibr_freeblock_sub(&pci_hi_fb,
-					&pci_hi_fl,
-					base, size);
-		}	
-	    }
 #if defined(IOC3_VENDOR_ID_NUM) && defined(IOC3_DEVICE_ID_NUM)
 	    /*
 	     * IOC3 BASE_ADDR* BUG WORKAROUND
@@ -825,21 +1033,55 @@
 #endif
 	    if (code == PCI_BA_MEM_64BIT) {
 		win++;		/* skip upper half */
-#ifdef LITTLE_ENDIAN
-		wptr[((win*4)^4)/4] = 0;	/* which must be zero */
-#else 
-		wptr[win] = 0;	/* which must be zero */
-#endif /* LITTLE_ENDIAN */
+		do_pcibr_config_set(IS_PIC_SOFT(pcibr_soft), wptr, (win * 4), 4, 0);  /* must be zero */
 	    }
 	}				/* next win */
     }				/* next func */
 
-    /* Store back the values for allocated PCI address spaces */
-    PCI_ADDR_SPACE_LIMITS_STORE();
     return(0);
 }					
 
 /*
+ * pcibr_find_capability
+ *	Walk the list of capabilities (if it exists) looking for
+ *	the requested capability.  Return a cfg_p pointer to the
+ *	capability if found, else return NULL
+ */
+cfg_p
+pcibr_find_capability(cfg_p	cfgw,
+		      unsigned	capability)
+{
+    unsigned		cap_nxt;
+    unsigned		cap_id;
+    int			defend_against_circular_linkedlist = 0;
+
+    /* Check to see if there is a capabilities pointer in the cfg header */
+    if (!(do_pcibr_config_get(1, cfgw, PCI_CFG_STATUS, 2) & PCI_STAT_CAP_LIST)) {
+	return (NULL);
+    }
+
+    /*
+     * Read up the capabilities head pointer from the configuration header.
+     * Capabilities are stored as a linked list in the lower 48 dwords of
+     * config space and are dword aligned. (Note: spec states the least two
+     * significant bits of the next pointer must be ignored,  so we mask
+     * with 0xfc).
+     */
+    cap_nxt = (do_pcibr_config_get(1, cfgw, PCI_CAPABILITIES_PTR, 1) & 0xfc);
+
+    while (cap_nxt && (defend_against_circular_linkedlist <= 48)) {
+	cap_id = do_pcibr_config_get(1, cfgw, cap_nxt, 1);
+	if (cap_id == capability) {
+	    return ((cfg_p)((char *)cfgw + cap_nxt));
+	}
+	cap_nxt = (do_pcibr_config_get(1, cfgw, cap_nxt+1, 1) & 0xfc);
+	defend_against_circular_linkedlist++;
+    }
+
+    return (NULL);
+}
+
+/*
  * pcibr_slot_info_free
  *	Remove all the PCI infrastructural information associated
  * 	with a particular PCI device.
@@ -854,7 +1096,10 @@
 
     pcibr_soft = pcibr_soft_get(pcibr_vhdl);
 
-    if (!pcibr_soft || !PCIBR_VALID_SLOT(slot))
+    if (!pcibr_soft)
+	return(EINVAL);
+
+    if (!PCIBR_VALID_SLOT(pcibr_soft, slot))
 	return(EINVAL);
 
     nfunc = pcibr_soft->bs_slot[slot].bss_ninfo;
@@ -868,6 +1113,109 @@
     return(0);
 }
 
+/*
+ * pcibr_slot_pcix_rbar_init
+ *	Allocate RBARs to the PCI-X functions on a given device
+ */
+int
+pcibr_slot_pcix_rbar_init(pcibr_soft_t pcibr_soft,
+			    pciio_slot_t slot)
+{
+    pcibr_info_h	 pcibr_infoh;
+    pcibr_info_t	 pcibr_info;
+    char		 tmp_str[256];
+    int		       	 nfunc;
+    int			 func;
+
+    if (!PCIBR_VALID_SLOT(pcibr_soft, slot))
+	return(EINVAL);
+
+    if ((nfunc = pcibr_soft->bs_slot[slot].bss_ninfo) < 1)
+	return(EINVAL);
+
+    if (!(pcibr_infoh = pcibr_soft->bs_slot[slot].bss_infos))
+	return(EINVAL);
+
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_RBAR, pcibr_soft->bs_vhdl,
+		"pcibr_slot_pcix_rbar_init for slot %d\n", 
+		PCIBR_DEVICE_TO_SLOT(pcibr_soft, slot)));
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_RBAR, pcibr_soft->bs_vhdl,
+		"\tslot/func\trequested\tgiven\tinuse\tavail\n"));
+
+    for (func = 0; func < nfunc; ++func) {
+	cap_pcix_type0_t	*pcix_cap_p;
+	cap_pcix_stat_reg_t	*pcix_statreg_p;
+	cap_pcix_cmd_reg_t	*pcix_cmdreg_p;
+	int 			 num_rbar;
+
+	if (!(pcibr_info = pcibr_infoh[func]))
+	    continue;
+
+	if (pcibr_info->f_vendor == PCIIO_VENDOR_ID_NONE)
+	    continue;
+
+	if (!(pcix_cap_p = pcibr_info->f_pcix_cap))
+	    continue;
+
+	pcix_statreg_p = &pcix_cap_p->pcix_type0_status;
+	pcix_cmdreg_p = &pcix_cap_p->pcix_type0_command;
+
+	/* If there are enough RBARs to satify the number of "max outstanding 
+	 * transactions" each function requested (bs_pcix_rbar_percent_allowed
+	 * is 100%), then give each function what it requested, otherwise give 
+	 * the functions a "percentage of what they requested".
+	 */
+	if (pcibr_soft->bs_pcix_rbar_percent_allowed >= 100) {
+	    pcix_cmdreg_p->max_split = pcix_statreg_p->max_out_split;
+	    num_rbar = max_splittrans_to_numbuf[pcix_cmdreg_p->max_split];
+	    pcibr_soft->bs_pcix_rbar_inuse += num_rbar;
+	    pcibr_soft->bs_pcix_rbar_avail -= num_rbar;
+	    pcix_cmdreg_p->max_mem_read_cnt = pcix_statreg_p->max_mem_read_cnt;
+	} else {
+	    int index;	    /* index into max_splittrans_to_numbuf table */
+	    int max_out;    /* max outstanding transactions given to func */
+
+	    /* Calculate the percentage of RBARs this function can have.
+	     * NOTE: Every function gets at least 1 RBAR (thus the "+1").
+	     * bs_pcix_rbar_percent_allowed is the percentage of what was
+	     * requested less this 1 RBAR that all functions automatically 
+	     * gets
+	     */
+	    max_out = ((max_splittrans_to_numbuf[pcix_statreg_p->max_out_split]
+			* pcibr_soft->bs_pcix_rbar_percent_allowed) / 100) + 1;
+
+	    /* round down the newly caclulated max_out to a valid number in
+	     * max_splittrans_to_numbuf[]
+	     */
+	    for (index = 0; index < MAX_SPLIT_TABLE-1; index++)
+		if (max_splittrans_to_numbuf[index + 1] > max_out)
+		    break;
+
+	    pcix_cmdreg_p->max_split = index;
+	    num_rbar = max_splittrans_to_numbuf[pcix_cmdreg_p->max_split];
+	    pcibr_soft->bs_pcix_rbar_inuse += num_rbar;
+            pcibr_soft->bs_pcix_rbar_avail -= num_rbar;
+	    pcix_cmdreg_p->max_mem_read_cnt = pcix_statreg_p->max_mem_read_cnt;
+	}
+        /*
+         * The kernel only allows functions to have so many variable args,
+         * attempting to call PCIBR_DEBUG_ALWAYS() with more than 5 printf
+         * arguments fails so sprintf() it into a temporary string.
+         */
+	if (pcibr_debug_mask & PCIBR_DEBUG_RBAR) {
+            sprintf(tmp_str,"\t  %d/%d   \t    %d    \t  %d  \t  %d  \t  %d\n",
+	            PCIBR_DEVICE_TO_SLOT(pcibr_soft, slot), func,
+	            max_splittrans_to_numbuf[pcix_statreg_p->max_out_split],
+	            max_splittrans_to_numbuf[pcix_cmdreg_p->max_split],
+	            pcibr_soft->bs_pcix_rbar_inuse, 
+		    pcibr_soft->bs_pcix_rbar_avail);
+            PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_RBAR, pcibr_soft->bs_vhdl, 
+		        "%s", tmp_str));
+	}
+    }
+    return(0);
+}
+
 int as_debug = 0;
 /*
  * pcibr_slot_addr_space_init
@@ -878,34 +1226,27 @@
 pcibr_slot_addr_space_init(devfs_handle_t pcibr_vhdl,
 			   pciio_slot_t	slot)
 {
-    pcibr_soft_t	pcibr_soft;
-    pcibr_info_h	pcibr_infoh;
-    pcibr_info_t	pcibr_info;
+    pcibr_soft_t	 pcibr_soft;
+    pcibr_info_h	 pcibr_infoh;
+    pcibr_info_t	 pcibr_info;
     bridge_t		*bridge;
-    iopaddr_t		pci_io_fb, pci_io_fl;
-    iopaddr_t		pci_lo_fb, pci_lo_fl;
-    iopaddr_t		pci_hi_fb, pci_hi_fl;
-    size_t              align;
-    iopaddr_t           mask;
-    int		    	nbars;
-    int		       	nfunc;
-    int			func;
-    int			win;
+    size_t               align_slot;
+    iopaddr_t            mask;
+    int		       	 nbars;
+    int		       	 nfunc;
+    int			 func;
+    int			 win;
+    int                  rc = 0;
 
     pcibr_soft = pcibr_soft_get(pcibr_vhdl);
 
-    if (!pcibr_soft || !PCIBR_VALID_SLOT(slot))
+    if (!pcibr_soft)
 	return(EINVAL);
 
-    bridge = pcibr_soft->bs_base;
-
-    /* Get the current values for the allocated PCI address spaces */
-    PCI_ADDR_SPACE_LIMITS_LOAD();
+    if (!PCIBR_VALID_SLOT(pcibr_soft, slot))
+	return(EINVAL);
 
-    if (as_debug)
-#ifdef LATER
-    PCI_ADDR_SPACE_LIMITS_PRINT();
-#endif
+    bridge = pcibr_soft->bs_base;
 
     /* allocate address space,
      * for windows that have not been
@@ -934,10 +1275,7 @@
      * the entire "lo" area is only a
      * megabyte, total ...
      */
-    align = (slot < 2) ? 0x200000 : 0x100000;
-    mask = -align;
-    pci_io_fb = (pci_io_fb + align - 1) & mask;
-    pci_hi_fb = (pci_hi_fb + align - 1) & mask;
+    align_slot = (slot < 2) ? 0x200000 : 0x100000;
 
     for (func = 0; func < nfunc; ++func) {
 	cfg_p                   cfgw;
@@ -945,7 +1283,9 @@
 	pciio_space_t           space;
 	iopaddr_t               base;
 	size_t                  size;
-	cfg_p                   pci_cfg_cmd_reg_p;
+#ifdef PCI_LATER
+	char			tmp_str[256];
+#endif
 	unsigned                pci_cfg_cmd_reg;
 	unsigned                pci_cfg_cmd_reg_add = 0;
 
@@ -957,13 +1297,15 @@
 	if (pcibr_info->f_vendor == PCIIO_VENDOR_ID_NONE)
 	    continue;
 	
-	cfgw = bridge->b_type0_cfg_dev[slot].f[func].l;
+        cfgw = pcibr_func_config_addr(bridge, 0, slot, func, 0);
 	wptr = cfgw + PCI_CFG_BASE_ADDR_0 / 4;
 
-	nbars = PCI_CFG_BASE_ADDRS;
+	if ((do_pcibr_config_get(IS_PIC_SOFT(pcibr_soft), cfgw, PCI_CFG_HEADER_TYPE, 1) & 0x7f) != 0)
+	    nbars = 2;
+	else
+	    nbars = PCI_CFG_BASE_ADDRS;
 
 	for (win = 0; win < nbars; ++win) {
-
 	    space = pcibr_info->f_window[win].w_space;
 	    base = pcibr_info->f_window[win].w_base;
 	    size = pcibr_info->f_window[win].w_size;
@@ -972,77 +1314,93 @@
 		continue;
 
 	    if (base >= size) {
-#if DEBUG && PCI_DEBUG
-		printk("pcibr: slot %d func %d window %d is in %d[0x%x..0x%x], alloc by prom\n",
-			slot, func, win, space, base, base + size - 1);
-#endif
+		/*
+         	 * The kernel only allows functions to have so many variable
+                 * args attempting to call PCIBR_DEBUG_ALWAYS() with more than
+         	 * 5 printf arguments fails so sprintf() it into a temporary 
+		 * string (tmp_str).
+         	 */
+#if defined(SUPPORT_PRINTING_R_FORMAT)
+		if (pcibr_debug_mask & PCIBR_DEBUG_BAR) {
+		    sprintf(tmp_str, "pcibr_slot_addr_space_init: slot=%d, "
+			"func=%d win %d is in %r [0x%x..0x%x], allocated by "
+			"prom\n", PCIBR_DEVICE_TO_SLOT(pcibr_soft, slot),
+			func, win, space, space_desc, base, base + size - 1);
+		    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_BAR, pcibr_vhdl, 
+				"%s",tmp_str));
+		}
+#endif	/* SUPPORT_PRINTING_R_FORMAT */
 		continue;		/* already allocated */
 	    }
-	    align = size;		/* ie. 0x00001000 */
-	    if (align < _PAGESZ)
-		align = _PAGESZ;	/* ie. 0x00004000 */
-	    mask = -align;		/* ie. 0xFFFFC000 */
 
 	    switch (space) {
 	    case PCIIO_SPACE_IO:
-		base = (pci_io_fb + align - 1) & mask;
-		if ((base + size) > pci_io_fl) {
-		    base = 0;
-		    break;
-		}
-		pci_io_fb = base + size;
+                base = pcibr_bus_addr_alloc(pcibr_soft,
+                                            &pcibr_info->f_window[win],
+                                            PCIIO_SPACE_IO,
+                                            0, size, align_slot);
+                if (!base)
+                    rc = ENOSPC;
 		break;
 		
 	    case PCIIO_SPACE_MEM:
-#ifdef LITTLE_ENDIAN
-		if ((wptr[((win*4)^4)/4] & PCI_BA_MEM_LOCATION) ==
-#else
-		if ((wptr[win] & PCI_BA_MEM_LOCATION) ==
-#endif  /* LITTLE_ENDIAN */
-		    PCI_BA_MEM_1MEG) {
+		if ((do_pcibr_config_get(IS_PIC_SOFT(pcibr_soft), wptr, (win * 4), 4) &
+		     PCI_BA_MEM_LOCATION) == PCI_BA_MEM_1MEG) {
+                    int align = size;           /* ie. 0x00001000 */
+                    
+                    if (align < _PAGESZ)
+                        align = _PAGESZ;        /* ie. 0x00004000 */
+ 
 		    /* allocate from 20-bit PCI space */
-		    base = (pci_lo_fb + align - 1) & mask;
-		    if ((base + size) > pci_lo_fl) {
-			base = 0;
-			break;
-		    }
-		    pci_lo_fb = base + size;
+                    base = pcibr_bus_addr_alloc(pcibr_soft,
+                                                &pcibr_info->f_window[win],
+                                                PCIIO_SPACE_MEM,
+                                                0, size, align);
+                    if (!base)
+                        rc = ENOSPC;
 		} else {
 		    /* allocate from 32-bit or 64-bit PCI space */
-		    base = (pci_hi_fb + align - 1) & mask;
-		    if ((base + size) > pci_hi_fl) {
-			base = 0;
-			break;
-		    }
-		    pci_hi_fb = base + size;
+                    base = pcibr_bus_addr_alloc(pcibr_soft,
+                                                &pcibr_info->f_window[win],
+                                                PCIIO_SPACE_MEM32,
+                                                0, size, align_slot);
+		    if (!base) 
+			rc = ENOSPC;
 		}
 		break;
 		
 	    default:
 		base = 0;
-#if DEBUG && PCI_DEBUG
-		printk("pcibr: slot %d window %d had bad space code %d\n",
-			slot, win, space);
-#endif
+		PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_BAR, pcibr_vhdl,
+			    "pcibr_slot_addr_space_init: slot=%d, window %d "
+			    "had bad space code %d\n", 
+			    PCIBR_DEVICE_TO_SLOT(pcibr_soft,slot), win, space));
 	    }
 	    pcibr_info->f_window[win].w_base = base;
-#ifdef LITTLE_ENDIAN
-	    wptr[((win*4)^4)/4] = base;
-#if DEBUG && PCI_DEBUG
-		printk("Setting base address 0x%p base 0x%x\n", &(wptr[((win*4)^4)/4]), base);
-#endif
-#else
-	    wptr[win] = base;
-#endif  /* LITTLE_ENDIAN */
+	    do_pcibr_config_set(IS_PIC_SOFT(pcibr_soft), wptr, (win * 4), 4, base);
 
-#if DEBUG && PCI_DEBUG
-	    if (base >= size)
-		printk("pcibr: slot %d func %d window %d is in %d [0x%x..0x%x], alloc by pcibr\n",
-			slot, func, win, space, base, base + size - 1);
-	    else
-		printk("pcibr: slot %d func %d window %d, unable to alloc 0x%x in 0x%p\n",
-			slot, func, win, size, space);
-#endif
+#if defined(SUPPORT_PRINTING_R_FORMAT)
+	    if (pcibr_debug_mask & PCIBR_DEBUG_BAR) {
+                if (base >= size) {
+		    sprintf(tmp_str,"pcibr_slot_addr_space_init: slot=%d, func="
+				    "%d, win %d is in %r[0x%x..0x%x], "
+				    "allocated by pcibr\n",
+				    PCIBR_DEVICE_TO_SLOT(pcibr_soft, slot), 
+				    func, win, space, space_desc, base, 
+				    base + size - 1);
+		     PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_BAR, pcibr_vhdl, 
+				 "%s",tmp_str));
+	        }
+		else {
+		    sprintf(tmp_str,"pcibr_slot_addr_space_init: slot=%d, func="
+				    "%d, win %d, unable to alloc 0x%x in %r\n",
+				    PCIBR_DEVICE_TO_SLOT(pcibr_soft, slot), 
+				    func, win, size, space, space_desc);
+		    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_BAR, pcibr_vhdl, 
+				"%s",tmp_str));
+	        }
+	    }
+#endif	/* SUPPORT_PRINTING_R_FORMAT */
 	}				/* next base */
 
 	/*
@@ -1055,34 +1413,23 @@
 	    (pcibr_soft->bs_slot[slot].bss_device_id != IOC3_DEVICE_ID_NUM)) {
 
 	    wptr = cfgw + PCI_EXPANSION_ROM / 4;
-#ifdef LITTLE_ENDIAN
-	    wptr[1] = 0xFFFFF000;
-	    mask = wptr[1];
-#else
-	    *wptr = 0xFFFFF000;
-	    mask = *wptr;
-#endif  /* LITTLE_ENDIAN */
+	    do_pcibr_config_set(IS_PIC_SOFT(pcibr_soft), wptr, 0, 4, 0xFFFFF000);
+	    mask = do_pcibr_config_get(IS_PIC_SOFT(pcibr_soft), wptr, 0, 4);
 	    if (mask & 0xFFFFF000) {
 		size = mask & -mask;
-		align = size;
-		if (align < _PAGESZ)
-		    align = _PAGESZ;
-		mask = -align;
-		base = (pci_hi_fb + align - 1) & mask;
-		if ((base + size) > pci_hi_fl)
-		    base = size = 0;
+                base = pcibr_bus_addr_alloc(pcibr_soft,
+                                            &pcibr_info->f_rwindow,
+                                            PCIIO_SPACE_MEM32, 
+                                            0, size, align_slot);
+		if (!base)
+		    rc = ENOSPC;
 		else {
-		    pci_hi_fb = base + size;
-#ifdef LITTLE_ENDIAN
-		    wptr[1] = base;
-#else
-		    *wptr = base;
-#endif  /* LITTLE_ENDIAN */
-#if DEBUG && PCI_DEBUG
-		    printk("%s/%d ROM in 0x%lx..0x%lx (alloc by pcibr)\n",
-			    pcibr_soft->bs_name, slot,
-			    base, base + size - 1);
-#endif
+		    do_pcibr_config_set(IS_PIC_SOFT(pcibr_soft), wptr, 0, 4, base);
+		    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_BAR, pcibr_vhdl,
+				"pcibr_slot_addr_space_init: slot=%d, func=%d, "
+				"ROM in [0x%X..0x%X], allocated by pcibr\n",
+				PCIBR_DEVICE_TO_SLOT(pcibr_soft, slot), 
+				func, base, base + size - 1));
 		}
 	    }
 	}
@@ -1116,30 +1463,25 @@
 
 	pci_cfg_cmd_reg_add |= PCI_CMD_BUS_MASTER;
 
-	pci_cfg_cmd_reg_p = cfgw + PCI_CFG_COMMAND / 4;
-	pci_cfg_cmd_reg = *pci_cfg_cmd_reg_p;
+	pci_cfg_cmd_reg = do_pcibr_config_get(IS_PIC_SOFT(pcibr_soft), cfgw, PCI_CFG_COMMAND, 4);
+
 #if PCI_FBBE	/* XXX- check here to see if dev can do fast-back-to-back */
 	if (!((pci_cfg_cmd_reg >> 16) & PCI_STAT_F_BK_BK_CAP))
 	    fast_back_to_back_enable = 0;
 #endif
 	pci_cfg_cmd_reg &= 0xFFFF;
 	if (pci_cfg_cmd_reg_add & ~pci_cfg_cmd_reg)
-	    *pci_cfg_cmd_reg_p = pci_cfg_cmd_reg | pci_cfg_cmd_reg_add;
-	
+	    do_pcibr_config_set(IS_PIC_SOFT(pcibr_soft), cfgw, PCI_CFG_COMMAND, 4, 
+				pci_cfg_cmd_reg | pci_cfg_cmd_reg_add);
     }				/* next func */
-
-    /* Now that we have allocated new chunks of PCI address spaces to this
-     * card we need to update the bookkeeping values which indicate
-     * the current PCI address space allocations.
-     */
-    PCI_ADDR_SPACE_LIMITS_STORE();
-    return(0);
+    return(rc);
 }
 
 /*
  * pcibr_slot_device_init
  * 	Setup the device register in the bridge for this PCI slot.
  */
+
 int
 pcibr_slot_device_init(devfs_handle_t pcibr_vhdl,
 		       pciio_slot_t slot)
@@ -1150,7 +1492,10 @@
 
     pcibr_soft = pcibr_soft_get(pcibr_vhdl);
 
-    if (!pcibr_soft || !PCIBR_VALID_SLOT(slot))
+    if (!pcibr_soft)
+	return(EINVAL);
+
+    if (!PCIBR_VALID_SLOT(pcibr_soft, slot))
 	return(EINVAL);
 
     bridge = pcibr_soft->bs_base;
@@ -1161,21 +1506,28 @@
      */
     devreg = bridge->b_device[slot].reg;
     devreg &= ~BRIDGE_DEV_PAGE_CHK_DIS;
-    devreg |= BRIDGE_DEV_COH | BRIDGE_DEV_VIRTUAL_EN;
-#ifdef LITTLE_ENDIAN
-    devreg |= BRIDGE_DEV_DEV_SWAP;
-#endif
+
+    /*
+     * PIC WAR. PV# 855271
+     * Don't enable virtual channels in the PIC by default.
+     * Can cause problems with 32-bit devices. (The bit is only intended
+     * for 64-bit devices).  We set the bit in pcibr_try_set_device()
+     * if we're 64-bit and requesting virtual channels.
+     */
+    if (IS_PIC_SOFT(pcibr_soft) && PCIBR_WAR_ENABLED(PV855271, pcibr_soft))
+	devreg |= BRIDGE_DEV_COH;
+    else
+	devreg |= BRIDGE_DEV_COH | BRIDGE_DEV_VIRTUAL_EN;
     pcibr_soft->bs_slot[slot].bss_device = devreg;
     bridge->b_device[slot].reg = devreg;
 
-#if DEBUG && PCI_DEBUG
-	printk("pcibr Device(%d): 0x%lx\n", slot, bridge->b_device[slot].reg);
-#endif
-
-#if DEBUG && PCI_DEBUG
-    printk("pcibr: PCI space allocation done.\n");
+#ifdef PIC_LATER
+    PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_DEVREG, pcibr_vhdl,
+		"pcibr_slot_device_init: Device(%d): %R\n",
+		slot, devreg, device_bits));
+#else
+    printk("pcibr_slot_device_init: Device(%d) 0x%x\n", slot, devreg);
 #endif
-
     return(0);
 }
 
@@ -1194,7 +1546,10 @@
 
     pcibr_soft = pcibr_soft_get(pcibr_vhdl);
 
-    if (!pcibr_soft || !PCIBR_VALID_SLOT(slot))
+    if (!pcibr_soft)
+	return(EINVAL);
+
+    if (!PCIBR_VALID_SLOT(pcibr_soft, slot))
 	return(EINVAL);
 
     slotp = &pcibr_soft->bs_slot[slot];
@@ -1259,17 +1614,25 @@
     pcibr_info_t	pcibr_info;
     async_attach_t	aa = NULL;
     int			func;
-    devfs_handle_t	xconn_vhdl,conn_vhdl;
+    devfs_handle_t	xconn_vhdl, conn_vhdl;
+#ifdef PIC_LATER
+    devfs_handle_t	scsi_vhdl;
+#endif
     int			nfunc;
     int                 error_func;
     int                 error_slot = 0;
     int                 error = ENODEV;
+#ifdef PIC_LATER
+    int                 hwg_err;
+#endif
 
     pcibr_soft = pcibr_soft_get(pcibr_vhdl);
 
-    if (!pcibr_soft || !PCIBR_VALID_SLOT(slot))
+    if (!pcibr_soft)
 	return(EINVAL);
 
+    if (!PCIBR_VALID_SLOT(pcibr_soft, slot))
+	return(EINVAL);
 
     if (pcibr_soft->bs_slot[slot].has_host) {
         return(EPERM);
@@ -1303,6 +1666,40 @@
 
 	error_func = pciio_device_attach(conn_vhdl, drv_flags);
 
+#ifdef PIC_LATER
+        /*
+         * Try to assign well-known SCSI controller numbers for hot-plug
+         * insert
+         */
+        if (drv_flags) {
+
+            hwg_err = hwgraph_path_lookup(conn_vhdl, EDGE_LBL_SCSI_CTLR "/0",
+                                          &scsi_vhdl, NULL);
+
+            if (hwg_err == GRAPH_SUCCESS)
+                scsi_ctlr_nums_add(baseio_pci_vhdl, scsi_vhdl);
+
+            /* scsi_vhdl will be the final vertex in either the complete path
+             * on success or a partial path on failure;  in either case,
+             * unreference that vertex.
+             */
+            hwgraph_vertex_unref(scsi_vhdl);
+
+            hwg_err = hwgraph_path_lookup(conn_vhdl, EDGE_LBL_SCSI_CTLR "/1",
+                                          &scsi_vhdl, NULL);
+
+            if (hwg_err == GRAPH_SUCCESS)
+                scsi_ctlr_nums_add(baseio_pci_vhdl, scsi_vhdl);
+
+            /* scsi_vhdl will be the final vertex in either the complete path
+             * on success or a partial path on failure;  in either case,
+             * unreference that vertex.
+             */
+            hwgraph_vertex_unref(scsi_vhdl);
+
+        }
+#endif /* PIC_LATER */
+
         pcibr_info->f_att_det_error = error_func;
 
 	if (error_func)
@@ -1313,9 +1710,12 @@
     }				/* next func */
 
     if (error) {
-	if ((error != ENODEV) && (error != EUNATCH))
+	if ((error != ENODEV) && (error != EUNATCH) && (error != EPERM)) {
+	    pcibr_soft->bs_slot[slot].slot_status &= ~SLOT_STATUS_MASK;
 	    pcibr_soft->bs_slot[slot].slot_status |= SLOT_STARTUP_INCMPLT;
+	}
     } else {
+        pcibr_soft->bs_slot[slot].slot_status &= ~SLOT_STATUS_MASK;
         pcibr_soft->bs_slot[slot].slot_status |= SLOT_STARTUP_CMPLT;
     }
         
@@ -1344,16 +1744,15 @@
 
     pcibr_soft = pcibr_soft_get(pcibr_vhdl);
 
-    if (!pcibr_soft || !PCIBR_VALID_SLOT(slot))
+    if (!pcibr_soft)
+	return(EINVAL);
+
+    if (!PCIBR_VALID_SLOT(pcibr_soft, slot))
 	return(EINVAL);
 
     if (pcibr_soft->bs_slot[slot].has_host)
         return(EPERM);
 
-    /* Make sure that we do not detach a system critical function vertex */
-    if(pcibr_is_slot_sys_critical(pcibr_vhdl, slot))
-        return(EPERM);
-
     nfunc = pcibr_soft->bs_slot[slot].bss_ninfo;
     pcibr_infoh = pcibr_soft->bs_slot[slot].bss_infos;
 
@@ -1367,6 +1766,14 @@
 	if (pcibr_info->f_vendor == PCIIO_VENDOR_ID_NONE)
 	    continue;
 
+	if (IS_PCIX(pcibr_soft) && pcibr_info->f_pcix_cap) {
+	    int max_out;
+
+	    pcibr_soft->bs_pcix_num_funcs--;
+	    max_out = pcibr_info->f_pcix_cap->pcix_type0_status.max_out_split;
+	    pcibr_soft->bs_pcix_split_tot -= max_splittrans_to_numbuf[max_out];
+	}
+
 	conn_vhdl = pcibr_info->f_vertex;
 
 	error_func = pciio_device_detach(conn_vhdl, drv_flags);
@@ -1380,22 +1787,22 @@
 
     }				/* next func */
 
-    pcibr_soft->bs_slot[slot].slot_status &= ~SLOT_STATUS_MASK;
 
     if (error) {
-	if ((error != ENODEV) && (error != EUNATCH))
+	if ((error != ENODEV) && (error != EUNATCH) && (error != EPERM)) {
+	    pcibr_soft->bs_slot[slot].slot_status &= ~SLOT_STATUS_MASK;
             pcibr_soft->bs_slot[slot].slot_status |= SLOT_SHUTDOWN_INCMPLT;
+	}
     } else {
         if (conn_vhdl != GRAPH_VERTEX_NONE) 
             pcibr_device_unregister(conn_vhdl);
+        pcibr_soft->bs_slot[slot].slot_status &= ~SLOT_STATUS_MASK;
         pcibr_soft->bs_slot[slot].slot_status |= SLOT_SHUTDOWN_CMPLT;
     }
         
     return(error);
 }
 
-#ifdef LATER
-
 /*
  * pcibr_slot_attach
  *	This is a place holder routine to keep track of all the
@@ -1411,81 +1818,16 @@
                   int         *sub_errorp)
 {
     pcibr_soft_t  pcibr_soft = pcibr_soft_get(pcibr_vhdl);
+#ifdef PIC_LATER
     timespec_t    ts;
-    int		  error;
-
-    if (!(pcibr_soft->bs_slot[slot].slot_status & SLOT_POWER_UP)) { 
-        /* Power-up the slot */
-        error = pcibr_slot_pwr(pcibr_vhdl, slot, L1_REQ_PCI_UP, l1_msg);
-        if (error) {
-            if (sub_errorp)
-                *sub_errorp = error;
-            return(PCI_L1_ERR);
-        } else {
-            pcibr_soft->bs_slot[slot].slot_status &= ~SLOT_POWER_MASK;
-            pcibr_soft->bs_slot[slot].slot_status |= SLOT_POWER_UP;
-        }
-
-#ifdef LATER
-        /*
-         * Allow cards like the Alteon Gigabit Ethernet Adapter to complete
-         * on-card initialization following the slot reset
-         */
-         ts.tv_sec = 0;                      /* 0 secs */
-         ts.tv_nsec = 500 * (1000 * 1000);   /* 500 msecs */
-         nano_delay(&ts);
-#else
 #endif
-#if 0
-        /* Reset the slot */
-        error = pcibr_slot_reset(pcibr_vhdl, slot)
-        if (error) {
-            if (sub_errorp)
-                *sub_errorp = error;
-            return(PCI_SLOT_RESET_ERR);
-        }
-#endif
-
-        /* Find out what is out there */
-        error = pcibr_slot_info_init(pcibr_vhdl, slot);
-        if (error) {
-            if (sub_errorp)
-                *sub_errorp = error;
-            return(PCI_SLOT_INFO_INIT_ERR);
-        }
-
-        /* Set up the address space for this slot in the PCI land */
-        error = pcibr_slot_addr_space_init(pcibr_vhdl, slot);
-        if (error) {
-            if (sub_errorp)
-                *sub_errorp = error;
-            return(PCI_SLOT_ADDR_INIT_ERR);
-        }
-
-        /* Setup the device register */
-        error = pcibr_slot_device_init(pcibr_vhdl, slot);
-        if (error) {
-            if (sub_errorp)
-                *sub_errorp = error;
-            return(PCI_SLOT_DEV_INIT_ERR);
-        }
-
-        /* Setup host/guest relations */
-        error = pcibr_slot_guest_info_init(pcibr_vhdl, slot);
-        if (error) {
-            if (sub_errorp)
-                *sub_errorp = error;
-            return(PCI_SLOT_GUEST_INIT_ERR);
-        }
-
-        /* Initial RRB management */
-        error = pcibr_slot_initial_rrb_alloc(pcibr_vhdl, slot);
-        if (error) {
-            if (sub_errorp)
-                *sub_errorp = error;
-            return(PCI_SLOT_RRB_ALLOC_ERR);
-        }
+    int		  error;
 
+    /* Do not allow a multi-function card to be hot-plug inserted */
+    if (pcibr_soft->bs_slot[slot].bss_ninfo > 1) {
+        if (sub_errorp)
+            *sub_errorp = EPERM;
+        return(PCI_MULTI_FUNC_ERR);
     }
 
     /* Call the device attach */
@@ -1501,7 +1843,6 @@
 
     return(0);
 }
-#endif	/* LATER */
 
 /*
  * pcibr_slot_detach
@@ -1511,13 +1852,42 @@
 int
 pcibr_slot_detach(devfs_handle_t pcibr_vhdl,
 		  pciio_slot_t slot,
-		  int          drv_flags)
+		  int          drv_flags,
+		  char        *l1_msg,
+                  int         *sub_errorp)
 {
+    pcibr_soft_t  pcibr_soft = pcibr_soft_get(pcibr_vhdl);
     int		  error;
     
+    /* Make sure that we do not detach a system critical function vertex */
+    if(pcibr_is_slot_sys_critical(pcibr_vhdl, slot))
+        return(PCI_IS_SYS_CRITICAL);
+
     /* Call the device detach function */
     error = (pcibr_slot_call_device_detach(pcibr_vhdl, slot, drv_flags));
-    return (error);
+    if (error) {
+        if (sub_errorp)
+            *sub_errorp = error;       
+        return(PCI_SLOT_DRV_DETACH_ERR);
+    }
+
+    /* Recalculate the RBARs for all the devices on the bus since we've
+     * just freed some up and some of the devices could use them.
+     */
+    if (IS_PCIX(pcibr_soft)) {
+	int tmp_slot;
+
+	pcibr_soft->bs_pcix_rbar_inuse = 0;
+	pcibr_soft->bs_pcix_rbar_avail = NUM_RBAR;
+	pcibr_soft->bs_pcix_rbar_percent_allowed = 
+					pcibr_pcix_rbars_calc(pcibr_soft);
+
+	for (tmp_slot = pcibr_soft->bs_min_slot;
+			tmp_slot < PCIBR_NUM_SLOTS(pcibr_soft); ++tmp_slot)
+            (void)pcibr_slot_pcix_rbar_init(pcibr_soft, tmp_slot);
+    }
+
+    return (0);
 
 }
 
@@ -1540,11 +1910,14 @@
     devfs_handle_t        conn_vhdl = GRAPH_VERTEX_NONE;
     int                 nfunc;
     int                 func;
-    boolean_t		is_sys_critical_vertex(devfs_handle_t);
+    boolean_t is_sys_critical_vertex(devfs_handle_t);
 
     pcibr_soft = pcibr_soft_get(pcibr_vhdl);
-    if (!pcibr_soft || !PCIBR_VALID_SLOT(slot))
-        return(0);
+    if (!pcibr_soft)
+	return(EINVAL);
+
+    if (!PCIBR_VALID_SLOT(pcibr_soft, slot))
+	return(EINVAL);
 
     nfunc = pcibr_soft->bs_slot[slot].bss_ninfo;
     pcibr_infoh = pcibr_soft->bs_slot[slot].bss_infos;
@@ -1574,57 +1947,112 @@
 }
 
 /*
- * pcibr_probe_slot: read a config space word
- * while trapping any errors; reutrn zero if
+ * pcibr_probe_slot_pic: read a config space word
+ * while trapping any errors; return zero if
  * all went OK, or nonzero if there was an error.
  * The value read, if any, is passed back
  * through the valp parameter.
  */
-int
-pcibr_probe_slot(bridge_t *bridge,
-		 cfg_p cfg,
-		 unsigned *valp)
+static int
+pcibr_probe_slot_pic(bridge_t *bridge,
+                 cfg_p cfg,
+                 unsigned *valp)
 {
-    int                     rv;
-    bridgereg_t             old_enable, new_enable;
-    int badaddr_val(volatile void *, int, volatile void *);
-
-    old_enable = bridge->b_int_enable;
-    new_enable = old_enable & ~BRIDGE_IMR_PCI_MST_TIMEOUT;
+	int rv;
+	picreg_t p_old_enable = (picreg_t)0, p_new_enable;
+	extern int badaddr_val(volatile void *, int, volatile void *);
+
+	p_old_enable = bridge->p_int_enable_64;
+	p_new_enable = p_old_enable & ~(BRIDGE_IMR_PCI_MST_TIMEOUT | PIC_ISR_PCIX_MTOUT);
+	bridge->p_int_enable_64 = p_new_enable;
+
+	if (bridge->p_err_int_view_64 & (BRIDGE_ISR_PCI_MST_TIMEOUT | PIC_ISR_PCIX_MTOUT))
+		bridge->p_int_rst_stat_64 = BRIDGE_IRR_MULTI_CLR;
+
+	if (bridge->p_int_status_64 & (BRIDGE_IRR_PCI_GRP | PIC_PCIX_GRP_CLR)) {
+		bridge->p_int_rst_stat_64 = (BRIDGE_IRR_PCI_GRP_CLR | PIC_PCIX_GRP_CLR);
+		(void) bridge->b_wid_tflush;	/* flushbus */
+	}
+	rv = badaddr_val((void *) cfg, 4, valp);
+	if (bridge->p_err_int_view_64 & (BRIDGE_ISR_PCI_MST_TIMEOUT | PIC_ISR_PCIX_MTOUT)) {
+		bridge->p_int_rst_stat_64 = BRIDGE_IRR_MULTI_CLR;
+		rv = 1;         /* unoccupied slot */
+	}
+	bridge->p_int_enable_64 = p_old_enable;
+	bridge->b_wid_tflush;		/* wait until Bridge PIO complete */
+	return(rv);
+}
 
-    bridge->b_int_enable = new_enable;
+/*
+ * pcibr_probe_slot_non_pic: read a config space word
+ * while trapping any errors; return zero if
+ * all went OK, or nonzero if there was an error.
+ * The value read, if any, is passed back
+ * through the valp parameter.
+ */
+static int
+pcibr_probe_slot_non_pic(bridge_t *bridge,
+                 cfg_p cfg,
+                 unsigned *valp)
+{
+	int                     rv;
+	bridgereg_t             b_old_enable = (bridgereg_t)0, b_new_enable = (bridgereg_t)0;
+	extern int              badaddr_val(volatile void *, int, volatile void *);
+
+        b_old_enable = bridge->b_int_enable;
+        b_new_enable = b_old_enable & ~BRIDGE_IMR_PCI_MST_TIMEOUT;
+        bridge->b_int_enable = b_new_enable;
 
 	/*
 	 * The xbridge doesn't clear b_err_int_view unless
 	 * multi-err is cleared...
 	 */
-	if (is_xbridge(bridge))
-	    if (bridge->b_err_int_view & BRIDGE_ISR_PCI_MST_TIMEOUT) {
+	if (is_xbridge(bridge)) {
+	    if (bridge->b_err_int_view & BRIDGE_ISR_PCI_MST_TIMEOUT)
 		bridge->b_int_rst_stat = BRIDGE_IRR_MULTI_CLR;
-	    }
-
-    if (bridge->b_int_status & BRIDGE_IRR_PCI_GRP) {
-	bridge->b_int_rst_stat = BRIDGE_IRR_PCI_GRP_CLR;
-	(void) bridge->b_wid_tflush;	/* flushbus */
-    }
-    rv = badaddr_val((void *) cfg, 4, valp);
+	}
 
+        if (bridge->b_int_status & BRIDGE_IRR_PCI_GRP) {
+	    bridge->b_int_rst_stat = BRIDGE_IRR_PCI_GRP_CLR;
+	    (void) bridge->b_wid_tflush;	/* flushbus */
+        }
+	rv = badaddr_val((void *) (((uint64_t)cfg) ^ 4), 4, valp);
 	/*
 	 * The xbridge doesn't set master timeout in b_int_status
 	 * here.  Fortunately it's in error_interrupt_view.
 	 */
-	if (is_xbridge(bridge))
+	if (is_xbridge(bridge)) {
 	    if (bridge->b_err_int_view & BRIDGE_ISR_PCI_MST_TIMEOUT) {
 		bridge->b_int_rst_stat = BRIDGE_IRR_MULTI_CLR;
 		rv = 1;		/* unoccupied slot */
 	    }
+	}
+        bridge->b_int_enable = b_old_enable;
+	bridge->b_wid_tflush;		/* wait until Bridge PIO complete */
+
+    	return(rv);
+}
 
-    bridge->b_int_enable = old_enable;
-    bridge->b_wid_tflush;		/* wait until Bridge PIO complete */
 
-    return rv;
+/*
+ * pcibr_probe_slot: read a config space word
+ * while trapping any errors; return zero if
+ * all went OK, or nonzero if there was an error.
+ * The value read, if any, is passed back
+ * through the valp parameter.
+ */
+static int
+pcibr_probe_slot(bridge_t *bridge,
+		 cfg_p cfg,
+		 unsigned *valp)
+{
+    if ( is_pic(bridge) )
+	return(pcibr_probe_slot_pic(bridge, cfg, valp));
+    else
+	return(pcibr_probe_slot_non_pic(bridge, cfg, valp));
 }
 
+
 void
 pcibr_device_info_free(devfs_handle_t pcibr_vhdl, pciio_slot_t slot)
 {
@@ -1632,10 +2060,13 @@
     pcibr_info_t	pcibr_info;
     pciio_function_t	func;
     pcibr_soft_slot_t	slotp = &pcibr_soft->bs_slot[slot];
+    bridge_t           *bridge = pcibr_soft->bs_base; 
+    cfg_p               cfgw;
     int			nfunc = slotp->bss_ninfo;
     int                 bar;
     int                 devio_index;
     int                 s;
+    unsigned            cmd_reg;
 
 
     for (func = 0; func < nfunc; func++) {
@@ -1646,10 +2077,19 @@
 
         s = pcibr_lock(pcibr_soft);
 
+        /* Disable memory and I/O BARs */
+	cfgw = pcibr_func_config_addr(bridge, 0, slot, func, 0);
+	cmd_reg = do_pcibr_config_get(IS_PIC_SOFT(pcibr_soft), cfgw, PCI_CFG_COMMAND, 4);
+	cmd_reg &= (PCI_CMD_MEM_SPACE | PCI_CMD_IO_SPACE);
+	do_pcibr_config_set(IS_PIC_SOFT(pcibr_soft), cfgw, PCI_CFG_COMMAND, 4, cmd_reg);
+
         for (bar = 0; bar < PCI_CFG_BASE_ADDRS; bar++) {
             if (pcibr_info->f_window[bar].w_space == PCIIO_SPACE_NONE)
                 continue;
 
+            /* Free the PCI bus space */
+            pciibr_bus_addr_free(pcibr_soft, &pcibr_info->f_window[bar]);
+
             /* Get index of the DevIO(x) register used to access this BAR */
             devio_index = pcibr_info->f_window[bar].w_devio_index;
 
@@ -1664,6 +2104,11 @@
             }
         }
 
+        /* Free the Expansion ROM PCI bus space */
+	if(pcibr_info->f_rbase && pcibr_info->f_rsize) {
+            pciibr_bus_addr_free(pcibr_soft, &pcibr_info->f_rwindow);
+        }
+
         pcibr_unlock(pcibr_soft, s);
 
 	slotp->bss_infos[func] = 0;
@@ -1689,4 +2134,69 @@
     slotp->bss_cmd_pointer = 0;
     slotp->bss_cmd_shadow = 0;
 
+}
+
+
+iopaddr_t
+pcibr_bus_addr_alloc(pcibr_soft_t pcibr_soft, pciio_win_info_t win_info_p,
+                     pciio_space_t space, int start, int size, int align)
+{
+    pciio_win_map_t win_map_p;
+
+    switch (space) {
+
+        case PCIIO_SPACE_IO:
+            win_map_p = &pcibr_soft->bs_io_win_map;
+            break;
+
+        case PCIIO_SPACE_MEM:
+            win_map_p = &pcibr_soft->bs_swin_map;
+            break;
+
+        case PCIIO_SPACE_MEM32:
+            win_map_p = &pcibr_soft->bs_mem_win_map;
+            break;
+
+        default:
+            return 0;
+
+    }
+    return pciio_device_win_alloc(win_map_p,
+				  win_info_p
+				  ? &win_info_p->w_win_alloc
+				  : NULL,
+				  start, size, align);
+}
+
+
+void
+pciibr_bus_addr_free(pcibr_soft_t pcibr_soft, pciio_win_info_t win_info_p)
+{
+	pciio_device_win_free(&win_info_p->w_win_alloc);
+}
+
+/*
+ * given a vertex_hdl to the pcibr_vhdl, return the brick's bus number
+ * associated with that vertex_hdl.  The true mapping happens from the
+ * io_brick_tab[] array defined in ml/SN/iograph.c
+ */
+int
+pcibr_widget_to_bus(devfs_handle_t pcibr_vhdl) 
+{
+    pcibr_soft_t	pcibr_soft = pcibr_soft_get(pcibr_vhdl);
+    xwidgetnum_t	widget = pcibr_soft->bs_xid;
+    int			bricktype = pcibr_soft->bs_bricktype;
+    int			bus = pcibr_soft->bs_busnum;
+    
+    /* 
+     * For PIC there are 2 busses per widget and pcibr_soft->bs_busnum
+     * will be 0 or 1.  For [X]BRIDGE there is 1 bus per widget and 
+     * pcibr_soft->bs_busnum will always be zero.  So we add bs_busnum
+     * to what io_brick_map_widget returns to get the bus number.
+     */
+    if ((bus += io_brick_map_widget(bricktype, widget)) > 0) {
+	return bus;
+    } else {
+	return 0;
+    }
 }
diff -Nru a/arch/ia64/sn/io/sn2/shub_intr.c b/arch/ia64/sn/io/sn2/shub_intr.c
--- a/arch/ia64/sn/io/sn2/shub_intr.c	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/sn/io/sn2/shub_intr.c	Mon Dec 23 21:21:55 2002
@@ -1,4 +1,4 @@
-/* $Id: shub_intr.c,v 1.2 2001/06/26 14:02:43 pfg Exp $
+/* $Id: shub_intr.c,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
@@ -25,21 +25,13 @@
 #include <asm/sn/intr.h>
 #include <asm/sn/xtalk/xtalkaddrs.h>
 #include <asm/sn/klconfig.h>
+#include <asm/sn/sn2/shub_mmr.h>
 #include <asm/sn/sn_cpuid.h>
 
-extern void hub_device_desc_update(device_desc_t, ilvl_t, cpuid_t);
-
 /* ARGSUSED */
 void
 hub_intr_init(devfs_handle_t hubv)
 {
-	extern void sn_cpei_handler(int, void *, struct pt_regs *);
-	extern void sn_init_cpei_timer(void);
-
-	if (request_irq(SGI_SHUB_ERROR_VECTOR, sn_cpei_handler, 0, "SN hub error", NULL) ) {
-		printk("hub_intr_init: Couldn't register SGI_SHUB_ERROR_VECTOR = %x\n",SGI_SHUB_ERROR_VECTOR);
-	}
-	sn_init_cpei_timer();
 }
 
 xwidgetnum_t
@@ -79,14 +71,12 @@
 	cpuphys = cpu_physical_id(cpu);
 	slice = cpu_physical_id_to_slice(cpuphys);
 	nasid = cpu_physical_id_to_nasid(cpuphys);
-	cnode = cpuid_to_cnodeid(cpu);
+	cnode = cpu_to_node_map[cpu];
 
 	if (slice) {
-		xtalk_addr = SH_II_INT1 | GLOBAL_MMR_SPACE |
-			((unsigned long)nasid << 36) | (1UL << 47);
+		xtalk_addr = SH_II_INT1 | ((unsigned long)nasid << 36) | (1UL << 47);
 	} else {
-		xtalk_addr = SH_II_INT0 | GLOBAL_MMR_SPACE |
-			((unsigned long)nasid << 36) | (1UL << 47);
+		xtalk_addr = SH_II_INT0 | ((unsigned long)nasid << 36) | (1UL << 47);
 	}
 
 	intr_hdl = snia_kmem_alloc_node(sizeof(struct hub_intr_s), KM_NOSLEEP, cnode);
@@ -107,7 +97,6 @@
 	intr_hdl->i_bit = vector;
 	intr_hdl->i_flags |= HUB_INTR_IS_ALLOCED;
 
-	hub_device_desc_update(dev_desc, intr_swlevel, cpu);
 	return(intr_hdl);
 }
 
@@ -136,7 +125,7 @@
 
 	if (intr_hdl->i_flags & HUB_INTR_IS_CONNECTED) {
 		xtalk_info = &intr_hdl->i_xtalk_info;
-		xtalk_info->xi_dev = NODEV;
+		xtalk_info->xi_dev = 0;
 		xtalk_info->xi_vector = 0;
 		xtalk_info->xi_addr = 0;
 		hub_intr_disconnect(intr_hdl);
@@ -150,6 +139,8 @@
 
 int
 hub_intr_connect(hub_intr_t intr_hdl,
+		intr_func_t intr_func,          /* xtalk intr handler */
+		void *intr_arg,                 /* arg to intr handler */
 		xtalk_intr_setfunc_t setfunc,
 		void *setfunc_arg)
 {
@@ -160,7 +151,6 @@
 	ASSERT(intr_hdl->i_flags & HUB_INTR_IS_ALLOCED);
 
 	rv = intr_connect_level(cpu, vector, intr_hdl->i_swlevel, NULL);
-
 	if (rv < 0) {
 		return rv;
 	}
diff -Nru a/arch/ia64/sn/io/sn2/shuberror.c b/arch/ia64/sn/io/sn2/shuberror.c
--- a/arch/ia64/sn/io/sn2/shuberror.c	Mon Dec 23 21:22:00 2002
+++ b/arch/ia64/sn/io/sn2/shuberror.c	Mon Dec 23 21:22:00 2002
@@ -1,4 +1,4 @@
-/* $Id$
+/* $Id: shuberror.c,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
@@ -10,6 +10,8 @@
 
 #include <linux/types.h>
 #include <linux/slab.h>
+#include <linux/irq.h>
+#include <asm/irq.h>
 #include <asm/smp.h>
 #include <asm/sn/sgi.h>
 #include <asm/sn/io.h>
@@ -34,12 +36,18 @@
 extern void hubii_eint_handler (int irq, void *arg, struct pt_regs *ep);
 int hubiio_crb_error_handler(devfs_handle_t hub_v, hubinfo_t hinfo);
 int hubiio_prb_error_handler(devfs_handle_t hub_v, hubinfo_t hinfo);
-extern void bte_crb_error_handler(devfs_handle_t hub_v, int btenum, int crbnum, ioerror_t *ioe);
+extern void bte_crb_error_handler(devfs_handle_t hub_v, int btenum, int crbnum, ioerror_t *ioe, int bteop);
 
 extern int maxcpus;
 
 #define HUB_ERROR_PERIOD        (120 * HZ)      /* 2 minutes */
 
+#ifdef BUS_INT_WAR
+void sn_add_polled_interrupt(int irq, int interval);
+void sn_delete_polled_interrupt(int irq);
+extern int bus_int_war_ide_irq;
+#endif
+
 
 void
 hub_error_clear(nasid_t nasid)
@@ -118,9 +126,7 @@
     hubinfo_t		hinfo; 
     cpuid_t		intr_cpu;
     devfs_handle_t 	hub_v;
-    ii_ilcsr_u_t	ilcsr;
     int bit_pos_to_irq(int bit);
-    int synergy_intr_connect(int bit, int cpuid);
 
 
     hub_v = (devfs_handle_t)cnodeid_to_vertex(cnode);
@@ -130,17 +136,6 @@
     ASSERT(hinfo);
     ASSERT(hinfo->h_cnodeid == cnode);
 
-    ilcsr.ii_ilcsr_regval = REMOTE_HUB_L(hinfo->h_nasid, IIO_ILCSR);
-
-    if ((ilcsr.ii_ilcsr_fld_s.i_llp_stat & 0x2) == 0) {
-	/* 
-	 * HUB II link is not up. 
-	 * Just disable LLP, and don't connect any interrupts.
-	 */
-	ilcsr.ii_ilcsr_fld_s.i_llp_en = 0;
-	REMOTE_HUB_S(hinfo->h_nasid, IIO_ILCSR, ilcsr.ii_ilcsr_regval);
-	return;
-    }
     /* Select a possible interrupt target where there is a free interrupt
      * bit and also reserve the interrupt bit for this IO error interrupt
      */
@@ -152,7 +147,11 @@
     }
 	
     rv = intr_connect_level(intr_cpu, bit, 0, NULL);
-    request_irq(bit + (intr_cpu << 8), hubii_eint_handler, 0, "SN hub error", (void *)hub_v);
+    request_irq(bit + (intr_cpu << 8), hubii_eint_handler, 0, "SN_hub_error", (void *)hub_v);
+    irq_desc(bit + (intr_cpu << 8))->status |= SN2_IRQ_PER_HUB;
+#ifdef BUS_INT_WAR                                              
+    sn_add_polled_interrupt(bit + (intr_cpu << 8), (0.01 * HZ));
+#endif
     ASSERT_ALWAYS(rv >= 0);
     hubio_eint.ii_iidsr_regval = 0;
     hubio_eint.ii_iidsr_fld_s.i_enable = 1;
@@ -257,15 +256,16 @@
 void
 hubiio_crb_free(hubinfo_t hinfo, int crbnum)
 {
-	ii_icrb0_a_u_t         icrba;
+	ii_icrb0_b_u_t         icrbb;
 
 	/*
 	* The hardware does NOT clear the mark bit, so it must get cleared
 	* here to be sure the error is not processed twice.
 	*/
-	icrba.ii_icrb0_a_regval = REMOTE_HUB_L(hinfo->h_nasid, IIO_ICRB_A(crbnum));
-	icrba.a_valid   = 0;
-	REMOTE_HUB_S(hinfo->h_nasid, IIO_ICRB_A(crbnum), icrba.ii_icrb0_a_regval);
+	icrbb.ii_icrb0_b_regval = REMOTE_HUB_L(hinfo->h_nasid, IIO_ICRB_B(crbnum));
+	icrbb.b_mark   = 0;
+	REMOTE_HUB_S(hinfo->h_nasid, IIO_ICRB_B(crbnum), icrbb.ii_icrb0_b_regval);
+
 	/*
 	* Deallocate the register.
 	*/
@@ -325,9 +325,11 @@
 	ii_icrb0_b_u_t		icrbb;		/* II CRB Register B */
 	ii_icrb0_c_u_t		icrbc;		/* II CRB Register C */
 	ii_icrb0_d_u_t		icrbd;		/* II CRB Register D */
+	ii_icrb0_e_u_t		icrbe;		/* II CRB Register D */
 	int		i;
 	int		num_errors = 0;	/* Num of errors handled */
 	ioerror_t	ioerror;
+	int		rc;
 
 	nasid = hinfo->h_nasid;
 	cnode = NASID_TO_COMPACT_NODEID(nasid);
@@ -337,16 +339,24 @@
 	 * in any of the CRBs marked.
 	 */
 	for (i = 0; i < IIO_NUM_CRBS; i++) {
+		/* Check this crb entry to see if it is in error. */
+		icrbb.ii_icrb0_b_regval = REMOTE_HUB_L(nasid, IIO_ICRB_B(i));
+
+		if (icrbb.b_mark == 0) {
+			continue;
+		}
+
 		icrba.ii_icrb0_a_regval = REMOTE_HUB_L(nasid, IIO_ICRB_A(i));
 
 		IOERROR_INIT(&ioerror);
 
 		/* read other CRB error registers. */
-		icrbb.ii_icrb0_b_regval = REMOTE_HUB_L(nasid, IIO_ICRB_B(i));
 		icrbc.ii_icrb0_c_regval = REMOTE_HUB_L(nasid, IIO_ICRB_C(i));
 		icrbd.ii_icrb0_d_regval = REMOTE_HUB_L(nasid, IIO_ICRB_D(i));
+		icrbe.ii_icrb0_e_regval = REMOTE_HUB_L(nasid, IIO_ICRB_E(i));
 
 		IOERROR_SETVALUE(&ioerror,errortype,icrbb.b_ecode);
+
 		/* Check if this error is due to BTE operation,
 		* and handle it separately.
 		*/
@@ -363,8 +373,15 @@
 			else /* b_initiator bit 2 gives BTE number */
 				bte_num = (icrbb.b_initiator & 0x4) >> 2;
 
+			/* >>> bte_crb_error_handler needs to be 
+			 * broken into two parts.  The first should
+			 * cleanup the CRB.  The second should wait
+			 * until all bte related CRB's are complete
+			 * and then do the error reset.
+			 */
 			bte_crb_error_handler(hub_v, bte_num,
-					i, &ioerror);
+					      i, &ioerror,
+					      icrbd.d_bteop);
 			hubiio_crb_free(hinfo, i);
 			num_errors++;
 			continue;
@@ -401,11 +418,142 @@
 			 */
 			IOERROR_SETVALUE(&ioerror,widgetdev,
 					 TNUM_TO_WIDGET_DEV(icrba.a_tnum));
+			/*
+			* The encoding of TNUM (see comments above) is
+			* different for PIC. So we'll save TNUM here and
+			* deal with the differences later when we can
+			* determine if we're using a Bridge or the PIC.
+			*
+			* XXX:  We may be able to remove saving the widgetdev
+			* above and just sort it out of TNUM later.
+			*/
+			IOERROR_SETVALUE(&ioerror, tnum, icrba.a_tnum);
+
+		}
+
+		if (icrbb.b_error) {
+		/* 
+		 * CRB 'i' has some error. Identify the type of error,
+		 * and try to handle it.
+		 */
+		switch(icrbb.b_ecode) {
+		case IIO_ICRB_ECODE_PERR:
+		case IIO_ICRB_ECODE_WERR:
+		case IIO_ICRB_ECODE_AERR:
+		case IIO_ICRB_ECODE_PWERR:
+
+			printk("%s on hub cnodeid: %d",
+				hubiio_crb_errors[icrbb.b_ecode], cnode);
+			/*
+			 * Any sort of write error is mostly due
+			 * bad programming (Note it's not a timeout.)
+			 * So, invoke hub_iio_error_handler with
+			 * appropriate information.
+			 */
+			IOERROR_SETVALUE(&ioerror,errortype,icrbb.b_ecode);
+
+			rc = hub_ioerror_handler(
+					hub_v, 
+					DMA_WRITE_ERROR, 
+					MODE_DEVERROR, 
+					&ioerror);
+
+                        if (rc == IOERROR_HANDLED) {
+                                rc = hub_ioerror_handler(
+                                        hub_v,
+                                        DMA_WRITE_ERROR,
+                                        MODE_DEVREENABLE,
+                                        &ioerror);
+                                ASSERT(rc == IOERROR_HANDLED);
+                        }else {
+
+				panic("Unable to handle %s on hub %d",
+					hubiio_crb_errors[icrbb.b_ecode],
+					cnode);
+				/*NOTREACHED*/
+			}
+			/* Go to Next error */
+			hubiio_crb_free(hinfo, i);
+			continue;
+
+		case IIO_ICRB_ECODE_PRERR:
+
+                case IIO_ICRB_ECODE_TOUT:
+                case IIO_ICRB_ECODE_XTERR:
+
+		case IIO_ICRB_ECODE_DERR:
+			panic("Fatal %s on hub : %d",
+				hubiio_crb_errors[icrbb.b_ecode], cnode);
+			/*NOTREACHED*/
+		
+		default:
+			panic("Fatal error (code : %d) on hub : %d",
+				cnode);
+			/*NOTREACHED*/
+
+		}
+		} 	/* if (icrbb.b_error) */	
 
+		/*
+		 * Error is not indicated via the errcode field 
+		 * Check other error indications in this register.
+		 */
+		
+		if (icrbb.b_xerr) {
+			panic("Xtalk Packet with error bit set to hub %d",
+				cnode);
+			/*NOTREACHED*/
+		}
+
+		if (icrbb.b_lnetuce) {
+			panic("Uncorrectable data error detected on data "
+				" from Craylink to node %d",
+				cnode);
+			/*NOTREACHED*/
 		}
 
 	}
 	return	num_errors;
+}
+
+/*
+ * hubii_check_widget_disabled
+ *
+ *	Check if PIO access to the specified widget is disabled due
+ *	to any II errors that are currently set.
+ *
+ *	The specific error bits checked are:
+ *		IPRBx register: SPUR_RD (51)
+ *				SPUR_WR (50)
+ *				RD_TO (49)
+ *				ERROR (48)
+ *
+ *		WSTAT register: CRAZY (32)
+ */
+
+int
+hubii_check_widget_disabled(nasid_t nasid, int wnum)
+{
+	iprb_t		iprb;
+	ii_wstat_u_t	wstat;
+
+	iprb.iprb_regval = REMOTE_HUB_L(nasid, IIO_IOPRB(wnum));
+	if (iprb.iprb_regval & (IIO_PRB_SPUR_RD | IIO_PRB_SPUR_WR |
+		IIO_PRB_RD_TO | IIO_PRB_ERROR)) {
+#ifdef DEBUG
+	    printk(KERN_WARNING "II error, IPRB%x=0x%lx\n", wnum, iprb.iprb_regval);
+#endif
+	    return(1);
+	}
+
+	wstat.ii_wstat_regval = REMOTE_HUB_L(nasid, IIO_WSTAT);
+	if (wstat.ii_wstat_regval & IIO_WSTAT_ECRAZY) {
+#ifdef DEBUG
+	    printk(KERN_WARNING "II error, WSTAT=0x%lx\n", wstat.ii_wstat_regval);
+#endif
+	    return(1);
+	}
+	return(0);
 }
 
 /*ARGSUSED*/
diff -Nru a/arch/ia64/sn/io/stubs.c b/arch/ia64/sn/io/stubs.c
--- a/arch/ia64/sn/io/stubs.c	Mon Dec 23 21:21:59 2002
+++ b/arch/ia64/sn/io/stubs.c	Mon Dec 23 21:21:59 2002
@@ -9,8 +9,9 @@
 
 #include <linux/types.h>
 #include <linux/ctype.h>
-#include <linux/mm.h>
+#include <linux/mmzone.h>
 #include <linux/slab.h>
+#include <asm/sn/arch.h>
 #include <asm/sn/sgi.h>
 #include <asm/sn/invent.h>
 #include <asm/sn/hcl.h>
@@ -28,8 +29,8 @@
 
 int pcibr_prefetch_enable_rev, pcibr_wg_enable_rev;
 int default_intr_pri;
-int force_fire_and_forget;
-int ignore_conveyor_override;
+int force_fire_and_forget = 1;
+int ignore_conveyor_override = 0;
 
 devfs_handle_t dummy_vrtx;	/* Needed for cpuid_to_vertex() in hack.h */
 
@@ -53,54 +54,24 @@
 	return(0);
 }
 
-char *
-nic_bridge_vertex_info(devfs_handle_t v, nic_data_t mcr)
-{
-	FIXME("nic_bridge_vertex_info : returns NULL");
-	return((char *)0);
-}
-
-void *
-snia_kmem_alloc_node(register size_t size, register int flags, cnodeid_t node)
-{
-        /* Allocates on node 'node' */
-	FIXME("snia_kmem_alloc_node : use kmalloc");
-	return(kmalloc(size, GFP_KERNEL));
-}
-
-void *
-snia_kmem_zalloc_node(register size_t size, register int flags, cnodeid_t node)
-{
-	FIXME("snia_kmem_zalloc_node : use kmalloc");
-	return(kmalloc(size, GFP_KERNEL));
-}
-
-void
-snia_kmem_free(void *where, int size)
-{
-	FIXME("snia_kmem_free : use kfree");
-	return(kfree(where));
-}
-
-
 void *
-snia_kmem_zone_alloc(register zone_t *zone, int flags)
+snia_kmem_zone_alloc(register struct zone *zone, int flags)
 {
 	FIXME("snia_kmem_zone_alloc : return null");
 	return((void *)0);
 }
 
 void
-snia_kmem_zone_free(register zone_t *zone, void *ptr)
+snia_kmem_zone_free(register struct zone *zone, void *ptr)
 {
 	FIXME("snia_kmem_zone_free : no-op");
 }
 
-zone_t *
+struct zone *
 snia_kmem_zone_init(register int size, char *zone_name)
 {
 	FIXME("snia_kmem_zone_free : returns NULL");
-	return((zone_t *)0);
+	return((struct zone *)0);
 }
 
 int
@@ -115,13 +86,6 @@
 		return(0);
 }
 
-void *
-swap_ptr(void **loc, void *new)
-{
-	FIXME("swap_ptr : returns null");
-	return((void *)0);
-}
-
 /* For ml/SN/SN1/slots.c */
 /* ARGSUSED */
 slotid_t get_widget_slotnum(int xbow, int widget)
@@ -153,10 +117,8 @@
 char *
 nic_vertex_info_get(devfs_handle_t v)
 {
-
 	FIXME("nic_vertex_info_get\n");
 	return(NULL);
-
 }
 
 int
diff -Nru a/arch/ia64/sn/io/xswitch.c b/arch/ia64/sn/io/xswitch.c
--- a/arch/ia64/sn/io/xswitch.c	Mon Dec 23 21:21:51 2002
+++ b/arch/ia64/sn/io/xswitch.c	Mon Dec 23 21:21:51 2002
@@ -4,7 +4,7 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (C) 1992 - 1997, 2000-2001 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 1992-1997,2000-2002 Silicon Graphics, Inc. All rights reserved.
  */
 
 #include <linux/types.h>
diff -Nru a/arch/ia64/sn/kernel/Makefile b/arch/ia64/sn/kernel/Makefile
--- a/arch/ia64/sn/kernel/Makefile	Mon Dec 23 21:21:51 2002
+++ b/arch/ia64/sn/kernel/Makefile	Mon Dec 23 21:21:51 2002
@@ -1,4 +1,4 @@
-# arch/ia64/sn/Makefile
+# arch/ia64/sn/kernel/Makefile
 #
 # Copyright (C) 1999,2001-2002 Silicon Graphics, Inc.  All Rights Reserved.
 #
@@ -33,11 +33,17 @@
 
 EXTRA_CFLAGS    := -DLITTLE_ENDIAN
 
-export-objs 	:= sn_ksyms.o
+.S.s:
+	$(CPP) $(AFLAGS) $(AFLAGS_KERNEL) -o $*.s $<
+.S.o:
+	$(CC) $(AFLAGS) $(AFLAGS_KERNEL) -c -o $*.o $<
 
-obj-y		= probe.o setup.o sn_asm.o sv.o bte.o
-obj-$(CONFIG_IA64_SGI_SN1)      += irq.o mca.o sn1/
-obj-$(CONFIG_IA64_SGI_SN2)      += irq.o mca.o sn2/
+export-objs = sn_ksyms.o iomv.o
+
+obj-y		= probe.o setup.o sn_asm.o sv.o bte.o iomv.o
+obj-$(CONFIG_IA64_SGI_SN1)      += irq.o mca.o
+obj-$(CONFIG_IA64_SGI_SN2)      += irq.o mca.o
 obj-$(CONFIG_IA64_SGI_AUTOTEST) += llsc4.o misctest.o
 obj-$(CONFIG_IA64_GENERIC)      += machvec.o
 obj-$(CONFIG_MODULES)           += sn_ksyms.o
+obj-$(CONFIG_IA64_SGI_SN_BRT)	+= bte_regr_test.o
diff -Nru a/arch/ia64/sn/kernel/bte.c b/arch/ia64/sn/kernel/bte.c
--- a/arch/ia64/sn/kernel/bte.c	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/sn/kernel/bte.c	Mon Dec 23 21:21:55 2002
@@ -1,18 +1,49 @@
 /*
- * 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.
+ *
+ *
+ * Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
+ * 
+ * This program is free software; you can redistribute it and/or modify it 
+ * under the terms of version 2 of the GNU General Public License 
+ * as published by the Free Software Foundation.
+ * 
+ * This program is distributed in the hope that it would be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
+ * 
+ * Further, this software is distributed without any warranty that it is 
+ * free of the rightful claim of any third person regarding infringement 
+ * or the like.  Any license provided herein, whether implied or 
+ * otherwise, applies only to this software file.  Patent licenses, if 
+ * any, provided herein do not apply to combinations of this program with 
+ * other software, or any other product whatsoever.
+ * 
+ * You should have received a copy of the GNU General Public 
+ * License along with this program; if not, write the Free Software 
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ * 
+ * Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 
+ * Mountain View, CA  94043, or:
+ * 
+ * http://www.sgi.com 
  * 
- * Copyright (c) 2001-2002 Silicon Graphics, Inc.  All rights reserved.
+ * For further information regarding this notice, see: 
+ * 
+ * http://oss.sgi.com/projects/GenInfo/NoticeExplan
  */
 
+#include <linux/config.h>
 #include <asm/sn/nodepda.h>
 #include <asm/sn/addrs.h>
 #include <asm/sn/arch.h>
 #include <asm/sn/sn_cpuid.h>
 #include <asm/sn/pda.h>
+#ifdef CONFIG_IA64_SGI_SN2
+#include <asm/sn/sn2/shubio.h>
+#endif
 #include <asm/nodedata.h>
 
+#include <linux/bootmem.h>
 #include <linux/string.h>
 #include <linux/sched.h>
 
@@ -26,12 +57,16 @@
  * Initialize the nodepda structure with BTE base addresses and
  * spinlocks.
  *
+ * NOTE: The kernel parameter btetest will cause the initialization
+ * code to reserve blocks of physically contiguous memory to be
+ * used by the bte test module.
  */
 void
-bte_init_node(nodepda_t * mynodepda, cnodeid_t cNode)
+bte_init_node(nodepda_t * mynodepda, cnodeid_t cnode)
 {
 	int i;
 
+
 	/*
 	 * Indicate that all the block transfer engines on this node
 	 * are available.
@@ -39,27 +74,76 @@
 	for (i = 0; i < BTES_PER_NODE; i++) {
 #ifdef CONFIG_IA64_SGI_SN2
 		/* >>> Don't know why the 0x1800000L is here.  Robin */
-		mynodepda->node_bte_info[i].bte_base_addr =
+		mynodepda->bte_if[i].bte_base_addr =
 		    (char *)LOCAL_MMR_ADDR(bte_offsets[i] | 0x1800000L);
+
 #elif CONFIG_IA64_SGI_SN1
-		mynodepda->node_bte_info[i].bte_base_addr =
+		mynodepda->bte_if[i].bte_base_addr =
 		    (char *)LOCAL_HUB_ADDR(bte_offsets[i]);
 #else
 #error BTE Not defined for this hardware platform.
 #endif
 
+		/*
+		 * Initialize the notification and spinlock
+		 * so the first transfer can occur.
+		 */
+		mynodepda->bte_if[i].most_rcnt_na =
+		    &(mynodepda->bte_if[i].notify);
+		mynodepda->bte_if[i].notify = 0L;
 #ifdef CONFIG_IA64_SGI_BTE_LOCKING
-		/* Initialize the notification and spinlock */
-		/* so the first transfer can occur. */
-		mynodepda->node_bte_info[i].mostRecentNotification =
-		    &(mynodepda->node_bte_info[i].notify);
-		mynodepda->node_bte_info[i].notify = 0L;
-		spin_lock_init(&mynodepda->node_bte_info[i].spinlock);
+		spin_lock_init(&mynodepda->bte_if[i].spinlock);
 #endif				/* CONFIG_IA64_SGI_BTE_LOCKING */
 
+		mynodepda->bte_if[i].bte_test_buf =
+			alloc_bootmem_node(NODE_DATA(cnode), BTE_MAX_XFER);
+	}
+
+}
+
+
+/*
+ * bte_reset_nasid(nasid_t)
+ *
+ * Does a soft reset of the BTEs on the specified nasid.
+ * This is followed by a one-line transfer from each of the
+ * virtual interfaces.
+ */
+void
+bte_reset_nasid(nasid_t n)
+{
+	ii_ibcr_u_t	ibcr;
+
+	ibcr.ii_ibcr_regval  = REMOTE_HUB_L(n, IIO_IBCR);
+	ibcr.ii_ibcr_fld_s.i_soft_reset = 1;
+	REMOTE_HUB_S(n, IIO_IBCR, ibcr.ii_ibcr_regval);
+
+	/* One line transfer on virtual interface 0 */
+	REMOTE_HUB_S(n, IIO_IBLS_0, IBLS_BUSY | 1);
+	REMOTE_HUB_S(n, IIO_IBSA_0, TO_PHYS(__pa(&nodepda->bte_cleanup)));
+	REMOTE_HUB_S(n, IIO_IBDA_0,
+		     TO_PHYS(__pa(&nodepda->bte_cleanup[4*L1_CACHE_BYTES])));
+	REMOTE_HUB_S(n, IIO_IBNA_0,
+		     TO_PHYS(__pa(&nodepda->bte_cleanup[4*L1_CACHE_BYTES])));
+	REMOTE_HUB_S(n, IIO_IBCT_0, BTE_NOTIFY);
+	while (REMOTE_HUB_L(n, IIO_IBLS0)) {
+		/* >>> Need some way out in case of hang... */
+	}
+
+	/* One line transfer on virtual interface 1 */
+	REMOTE_HUB_S(n, IIO_IBLS_1, IBLS_BUSY | 1);
+	REMOTE_HUB_S(n, IIO_IBSA_1, TO_PHYS(__pa(nodepda->bte_cleanup)));
+	REMOTE_HUB_S(n, IIO_IBDA_1,
+		     TO_PHYS(__pa(nodepda->bte_cleanup[4 * L1_CACHE_BYTES])));
+	REMOTE_HUB_S(n, IIO_IBNA_1,
+		     TO_PHYS(__pa(nodepda->bte_cleanup[5 * L1_CACHE_BYTES])));
+	REMOTE_HUB_S(n, IIO_IBCT_1, BTE_NOTIFY);
+	while (REMOTE_HUB_L(n, IIO_IBLS1)) {
+		/* >>> Need some way out in case of hang... */
 	}
 }
 
+
 /*
  * bte_init_cpu()
  *
@@ -70,14 +154,8 @@
 void
 bte_init_cpu(void)
 {
-	/* Called by setup.c as each cpu is being added to the nodepda */
-	if (local_node_data->active_cpu_count & 0x1) {
-		pda.cpubte[0] = &(nodepda->node_bte_info[0]);
-		pda.cpubte[1] = &(nodepda->node_bte_info[1]);
-	} else {
-		pda.cpubte[0] = &(nodepda->node_bte_info[1]);
-		pda.cpubte[1] = &(nodepda->node_bte_info[0]);
-	}
+	pda->cpu_bte_if[0] = &(nodepda->bte_if[1]);
+	pda->cpu_bte_if[1] = &(nodepda->bte_if[0]);
 }
 
 
@@ -93,14 +171,12 @@
  *   len - number of bytes to transfer from source to dest.
  *   mode - hardware defined.  See reference information
  *          for IBCT0/1 in the SGI documentation.
- *   bteBlock - kernel virtual address of a temporary
- *              buffer used during unaligned transfers.
  *
  * NOTE: If the source, dest, and len are all cache line aligned,
  * then it would be _FAR_ preferrable to use bte_copy instead.
  */
 bte_result_t
-bte_unaligned_copy(u64 src, u64 dest, u64 len, u64 mode, char *bteBlock)
+bte_unaligned_copy(u64 src, u64 dest, u64 len, u64 mode)
 {
 	int destFirstCacheOffset;
 	u64 headBteSource;
@@ -113,10 +189,18 @@
 	u64 footBcopyDest;
 	u64 footBcopyLen;
 	bte_result_t rv;
+	char *bteBlock;
 
 	if (len == 0) {
 		return (BTE_SUCCESS);
 	}
+
+#ifdef CONFIG_IA64_SGI_BTE_LOCKING
+#error bte_unaligned_copy() assumes single BTE selection in bte_copy().
+#else
+	/* temporary buffer used during unaligned transfers */
+	bteBlock = pda->cpu_bte_if[0]->bte_test_buf;
+#endif
 
 	headBcopySrcOffset = src & L1_CACHE_MASK;
 	destFirstCacheOffset = dest & L1_CACHE_MASK;
diff -Nru a/arch/ia64/sn/kernel/irq.c b/arch/ia64/sn/kernel/irq.c
--- a/arch/ia64/sn/kernel/irq.c	Mon Dec 23 21:21:51 2002
+++ b/arch/ia64/sn/kernel/irq.c	Mon Dec 23 21:21:51 2002
@@ -59,34 +59,33 @@
 #include <asm/sn/addrs.h>
 #include <asm/sn/driver.h>
 #include <asm/sn/arch.h>
+#include <asm/sn/nodepda.h>
 
 int irq_to_bit_pos(int irq);
 
-
-
 static unsigned int
-sn1_startup_irq(unsigned int irq)
+sn_startup_irq(unsigned int irq)
 {
         return(0);
 }
 
 static void
-sn1_shutdown_irq(unsigned int irq)
+sn_shutdown_irq(unsigned int irq)
 {
 }
 
 static void
-sn1_disable_irq(unsigned int irq)
+sn_disable_irq(unsigned int irq)
 {
 }
 
 static void
-sn1_enable_irq(unsigned int irq)
+sn_enable_irq(unsigned int irq)
 {
 }
 
 static void
-sn1_ack_irq(unsigned int irq)
+sn_ack_irq(unsigned int irq)
 {
 #ifdef CONFIG_IA64_SGI_SN1
 	int bit = -1;
@@ -149,7 +148,7 @@
 }
 
 static void
-sn1_end_irq(unsigned int irq)
+sn_end_irq(unsigned int irq)
 {
 #ifdef CONFIG_IA64_SGI_SN1
 	unsigned long long intpend_val, mask = 0x70L;
@@ -187,87 +186,82 @@
 }
 
 static void
-sn1_set_affinity_irq(unsigned int irq, unsigned long mask)
+sn_set_affinity_irq(unsigned int irq, unsigned long mask)
 {
 }
 
 
 struct hw_interrupt_type irq_type_iosapic_level = {
 	"SN hub",
-	sn1_startup_irq,
-	sn1_shutdown_irq,
-	sn1_enable_irq,
-	sn1_disable_irq,
-	sn1_ack_irq, 
-	sn1_end_irq,
-	sn1_set_affinity_irq
+	sn_startup_irq,
+	sn_shutdown_irq,
+	sn_enable_irq,
+	sn_disable_irq,
+	sn_ack_irq, 
+	sn_end_irq,
+	sn_set_affinity_irq
 };
 
 
-#define irq_type_sn1 irq_type_iosapic_level
-struct irq_desc *_sn1_irq_desc[NR_CPUS];
+#define irq_type_sn irq_type_iosapic_level
+struct irq_desc *_sn_irq_desc[NR_CPUS];
 
 struct irq_desc *
-sn1_irq_desc(unsigned int irq) {
+sn_irq_desc(unsigned int irq) {
 	int cpu = irq >> 8;
 
 	irq = irq & 0xff;
 
-	return(_sn1_irq_desc[cpu] + irq);
+	return(_sn_irq_desc[cpu] + irq);
 }
 
 u8
-sn1_irq_to_vector(u8 irq) {
+sn_irq_to_vector(u8 irq) {
 	return(irq & 0xff);
 }
 
-unsigned int
-sn1_local_vector_to_irq(u8 vector) {
-	return ( (smp_processor_id() << 8) + vector);
+int gsi_to_vector(u32 irq) {
+	return irq & 0xff;
 }
 
-int
-sn1_valid_irq(u8 irq) {
+int gsi_to_irq(u32 irq) {
+	return irq & 0xff;
+}
 
-	return( ((irq & 0xff) < NR_IRQS) && ((irq >> 8) < NR_CPUS) );
+unsigned int
+sn_local_vector_to_irq(u8 vector) {
+	return (CPU_VECTOR_TO_IRQ(smp_processor_id(), vector));
 }
 
 void *kmalloc(size_t, int);
 
 void
-sn1_irq_init (void)
+sn_irq_init (void)
 {
 	int i;
 	irq_desc_t *base_desc = _irq_desc;
 
-	for (i=IA64_FIRST_DEVICE_VECTOR; i<NR_IRQS; i++) {
+	for (i=IA64_FIRST_DEVICE_VECTOR; i<NR_IVECS; i++) {
 		if (base_desc[i].handler == &no_irq_type) {
-			base_desc[i].handler = &irq_type_sn1;
+			base_desc[i].handler = &irq_type_sn;
 		}
 	}
 }
 
 void
-sn1_init_irq_desc(void) {
+sn_init_irq_desc(void) {
 	int i;
 	irq_desc_t *base_desc = _irq_desc, *p;
 
 	for (i=0; i < NR_CPUS; i++) {
-		p =  page_address(alloc_pages_node(local_cnodeid(), GFP_KERNEL,
-			get_order(sizeof(struct irq_desc) * NR_IRQS) ) );
+		p =  page_address(alloc_pages_node(local_nodeid, GFP_KERNEL,
+			get_order(sizeof(struct irq_desc) * NR_IVECS) ) );
 		ASSERT(p);
-		memcpy(p, base_desc, sizeof(struct irq_desc) * NR_IRQS);
-		_sn1_irq_desc[i] = p;
+		memcpy(p, base_desc, sizeof(struct irq_desc) * NR_IVECS);
+		_sn_irq_desc[i] = p;
 	}
 }
 
-
-#if !defined(CONFIG_IA64_SGI_SN)
-void
-sn1_pci_fixup(void)
-{
-}
-#endif
 
 int
 bit_pos_to_irq(int bit) {
diff -Nru a/arch/ia64/sn/kernel/llsc4.c b/arch/ia64/sn/kernel/llsc4.c
--- a/arch/ia64/sn/kernel/llsc4.c	Mon Dec 23 21:21:59 2002
+++ b/arch/ia64/sn/kernel/llsc4.c	Mon Dec 23 21:21:59 2002
@@ -4,7 +4,7 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (C) 2000-2001 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 2000-2002 Silicon Graphics, Inc. All rights reserved.
  */
 
 #include <linux/config.h>
@@ -113,7 +113,8 @@
  * PORTING NOTE: revisit this statement. On hardware we put mbase at 0 and
  * the rest of the tables have to start at 1MB to skip PROM tables.
  */
-#define THREADPRIVATE(t)	((threadprivate_t*)(((long)mbase)+1024*1024+t*((sizeof(threadprivate_t)+511)/512*512)))
+#define THREADPRIVATESZ()	((sizeof(threadprivate_t)+511)/512*512)
+#define THREADPRIVATE(t)	((threadprivate_t*)(((long)mbase)+4096+t*THREADPRIVATESZ()))
 
 #define k_capture		mbase->sk_capture
 #define k_go			mbase->sk_go
@@ -797,27 +798,31 @@
 	k_threadprivate[cpuid]->threadstate = state;
 }
 
+#define MINBLK	(16*1024*1024)
 static int
 build_mem_map(unsigned long start, unsigned long end, void *arg)
 {
-	long	lstart;
+	long	lstart, lend;
 	long	align = 8*MB;
 
-	/*
-	 * HACK - skip the kernel on the first node 
-	 */
-
 	printk ("LLSC memmap: start 0x%lx, end 0x%lx, (0x%lx - 0x%lx)\n", 
 		start, end, (long) virt_to_page(start), (long) virt_to_page(end-PAGE_SIZE));
 
-	if (memmapx >= MAPCHUNKS)
+	if (memmapx >= MAPCHUNKS || (end-start) < MINBLK)
 		return 0;
-	while (end > start && (PageReserved(virt_to_page(end-PAGE_SIZE)) || virt_to_page(end-PAGE_SIZE)->count.counter > 0))
-		end -= PAGE_SIZE;
 
-	lstart = end;
-	while (lstart > start && (!PageReserved(virt_to_page(lstart-PAGE_SIZE)) && virt_to_page(lstart-PAGE_SIZE)->count.counter == 0))
+	/*
+	 * Start in the middle of the range & find the first non-free page in both directions
+	 * from the midpoint. This is likely to be the bigest free block.
+	 */
+	lend = lstart = start + (end-start)/2;
+	while (lend < end && !PageReserved(virt_to_page(lend)) && virt_to_page(lend)->count.counter == 0)
+		lend += PAGE_SIZE;
+	lend -= PAGE_SIZE;
+
+	while (lstart >= start && !PageReserved(virt_to_page(lstart)) && virt_to_page(lstart)->count.counter == 0)
 		lstart -= PAGE_SIZE;
+	lstart += PAGE_SIZE;
 
 	lstart = (lstart + align -1) /align * align;
 	end = end / align * align;
@@ -834,7 +839,7 @@
 void int_test(void);
 
 int
-llsc_main (int cpuid, long mbasex)
+llsc_main (int cpuid)
 {
 	int		i, cpu, is_master, repeatcnt=0;
 	unsigned int	preverr=0, errs=0, pass=0;
@@ -856,10 +861,11 @@
 
 
 	if (is_master) {
+		mbase = (control_t*) __get_free_pages(GFP_KERNEL, get_order(4096+THREADPRIVATESZ()*LLSC_MAXCPUS));
+		printk("LLSC: mbase 0x%lx\n", (long)mbase);
 		print_params();
 		if(!IS_RUNNING_ON_SIMULATOR())
 			spin(10);
-		mbase = (control_t*)mbasex;
 		k_currentpass = 0;
 		k_go = ST_IDLE;
 		k_passes = DEF_PASSES;
@@ -882,6 +888,7 @@
 			memset(k_threadprivate[i], 0, sizeof(*k_threadprivate[i]));
 			init_private[i] = i;
 		}
+		mb();
 		initialized = 1;
 	} else {
 		while (initialized == 0)
@@ -1005,15 +1012,14 @@
 
 	printk("Testing cross interrupts\n");
 	
-	while (control_cpu != NR_CPUS) {
-		if (mycpu == control_cpu) {
-			for (cpu=0; cpu<NR_CPUS; cpu++) {
-				if (!cpu_online(cpu)) continue;
-				printk("Sending interrupt from %d to %d\n", mycpu, cpu);
+	while (control_cpu != smp_num_cpus) {
+		if (mycpu == cpu_logical_map(control_cpu)) {
+			for (cpu=0; cpu<smp_num_cpus; cpu++) {
+				printk("Sending interrupt from %d to %d\n", mycpu, cpu_logical_map(cpu));
 				udelay(IS_RUNNING_ON_SIMULATOR ? 10000 : 400000);
-				smp_send_reschedule(cpu);
+				smp_send_reschedule(cpu_logical_map(cpu));
 				udelay(IS_RUNNING_ON_SIMULATOR ? 10000 : 400000);
-				smp_send_reschedule(cpu);
+				smp_send_reschedule(cpu_logical_map(cpu));
 				udelay(IS_RUNNING_ON_SIMULATOR ? 10000 : 400000);
 			}
 			control_cpu++;
@@ -1022,10 +1028,10 @@
 
 	zzzprint_resched = 1;
 
-	if (mycpu == NR_CPUS-1) {
+	if (mycpu == cpu_logical_map(smp_num_cpus-1)) {
 		printk("\nTight loop of cpu %d sending ints to cpu 0 (every 100 us)\n", mycpu);
 		udelay(IS_RUNNING_ON_SIMULATOR ? 1000 : 1000000);
-		local_irq_disable();
+		__cli();
 		while (1) {
 			smp_send_reschedule(0);
 			udelay(100);
diff -Nru a/arch/ia64/sn/kernel/llsc4.h b/arch/ia64/sn/kernel/llsc4.h
--- a/arch/ia64/sn/kernel/llsc4.h	Mon Dec 23 21:21:57 2002
+++ b/arch/ia64/sn/kernel/llsc4.h	Mon Dec 23 21:21:57 2002
@@ -4,7 +4,7 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (C) 2000-2001 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 2000-2002 Silicon Graphics, Inc. All rights reserved.
  */
 
 #ifdef STANDALONE
@@ -103,5 +103,5 @@
 
 
 
-int llsc_main (int cpuid, long mbasex);
+int llsc_main (int cpuid);
 
diff -Nru a/arch/ia64/sn/kernel/machvec.c b/arch/ia64/sn/kernel/machvec.c
--- a/arch/ia64/sn/kernel/machvec.c	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/sn/kernel/machvec.c	Mon Dec 23 21:21:55 2002
@@ -1,18 +1,59 @@
+/*
+ * Copyright (c) 2002 Silicon Graphics, Inc.  All Rights Reserved.
+ * 
+ * This program is free software; you can redistribute it and/or modify it 
+ * under the terms of version 2 of the GNU General Public License 
+ * as published by the Free Software Foundation.
+ * 
+ * This program is distributed in the hope that it would be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
+ * 
+ * Further, this software is distributed without any warranty that it is 
+ * free of the rightful claim of any third person regarding infringement 
+ * or the like.  Any license provided herein, whether implied or 
+ * otherwise, applies only to this software file.  Patent licenses, if 
+ * any, provided herein do not apply to combinations of this program with 
+ * other software, or any other product whatsoever.
+ * 
+ * You should have received a copy of the GNU General Public 
+ * License along with this program; if not, write the Free Software 
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ * 
+ * Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 
+ * Mountain View, CA  94043, or:
+ * 
+ * http://www.sgi.com 
+ * 
+ * For further information regarding this notice, see: 
+ * 
+ * http://oss.sgi.com/projects/GenInfo/NoticeExplan
+ */
+
+#include <linux/config.h>
+
+#ifdef CONFIG_IA64_SGI_SN1
 #define MACHVEC_PLATFORM_NAME	sn1
+#else CONFIG_IA64_SGI_SN1
+#define MACHVEC_PLATFORM_NAME	sn2
+#else
+#error "unknown platform"
+#endif
+
 #include <asm/machvec_init.h>
 #include <asm/io.h>
 #include <linux/pci.h>
 void*
-sn1_mk_io_addr_MACRO
+sn_mk_io_addr_MACRO
 
 dma_addr_t
-sn1_pci_map_single_MACRO
+sn_pci_map_single_MACRO
 
 int
-sn1_pci_map_sg_MACRO
+sn_pci_map_sg_MACRO
 
 unsigned long
-sn1_virt_to_phys_MACRO
+sn_virt_to_phys_MACRO
 
 void *
-sn1_phys_to_virt_MACRO
+sn_phys_to_virt_MACRO
diff -Nru a/arch/ia64/sn/kernel/misctest.c b/arch/ia64/sn/kernel/misctest.c
--- a/arch/ia64/sn/kernel/misctest.c	Mon Dec 23 21:21:59 2002
+++ b/arch/ia64/sn/kernel/misctest.c	Mon Dec 23 21:21:59 2002
@@ -4,119 +4,368 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (C) 2000-2001 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 2000-2002 Silicon Graphics, Inc. All rights reserved.
  */
 
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/interrupt.h>
 #include <asm/sn/sn_sal.h>
 #include <asm/sn/sn_cpuid.h>
 #include <asm/processor.h>
 #include <asm/pgtable.h>
-
+#include <asm/page.h>
+#include <asm/timex.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/sn/intr.h>
+#include <asm/hw_irq.h>
+#include <asm/sn/leds.h>
 
 extern	int autotest_enabled;
-int	mcatest=0;
-
+long	mcatest=0, debug0, debug1, debug2, debug3;
 
+#define HDELAY(t)	(IS_RUNNING_ON_SIMULATOR() ? udelay(1) : udelay(t))
 
 /* 
  * mcatest
- *	1 = expected MCA
- *	2 = unexpected MCA
- *	3 = expected MCA + unexpected MCA
- *	4 = INIT
- *	5 = speculative load to garbage memory address
- *	6 = speculative load with ld8.s (needs poison hack in PROM)
- *	7 = speculative load from mis-predicted branch (needs poison hack in PROM)
+ *	mactest contains a decimal number (RPTT) where
+ *		R - flag, if non zero, run forever
+ *
+ *		P - identifies when to run the test
+ *		    0 execute test at cpu 0 early init
+ *		    1 execute test at cpu 0 idle
+ *		    2 execute test at last (highest numbered) cpu idle
+ *		    3 execute test on all cpus at idle
+ *
+ *		TT- identifies test to run
+ *		    01 = MCA via dup TLB dropin
+ *		    02 = MCA via garbage address
+ *		    03 = lfetch via garbage address
+ *		    05 = INIT self
+ *		    06 = INIT other cpu
+ *		    07 = INIT non-existent cpu
+ *		    10 = IPI stress test. Target cpu 0
+ *		    11 = IPI stress test. Target all cpus
+ *		    12 = TLB stress test
+ *		    13 = Park cpu (spinloop)
+ *		    14 = One shot TLB test with tlb spinlock
+ *		    15 = One shot TLB test
+ *		    16 = One shot TLB test sync'ed with RTC
+ *		    20 = set led to the cpuid & spin.
+ *		    21 = Try mixed cache/uncached refs & see what happens
+ *		    22 = Call SAL reboot
+ *		    23 = Call PAL halt
  */
 static int __init set_mcatest(char *str)
 {
-	get_option(&str, &mcatest);
+	int	val;
+	get_option(&str, &val);
+	mcatest = val;
 	return 1;
 }
-
 __setup("mcatest=", set_mcatest);
 
+static int __init set_debug0(char *str)
+{
+	int	val;
+	get_option(&str, &val);
+	debug0 = val;
+	return 1;
+}
+__setup("debug0=", set_debug0);
+
+static int __init set_debug1(char *str)
+{
+	int	val;
+	get_option(&str, &val);
+	debug1 = val;
+	return 1;
+}
+__setup("debug1=", set_debug1);
+
+static int __init set_debug2(char *str)
+{
+	int	val;
+	get_option(&str, &val);
+	debug2 = val;
+	return 1;
+}
+__setup("debug2=", set_debug2);
+
+static int __init set_debug3(char *str)
+{
+	int	val;
+	get_option(&str, &val);
+	debug3 = val;
+	return 1;
+}
+__setup("debug3=", set_debug3);
+
+static volatile int	go;
+
+static void
+do_sync(int pos) {
+	if (pos != 3)
+		return;
+	else if (smp_processor_id() == 0)
+		go = 1;
+	else
+		while (!go);
+}
+
+static void
+sgi_mcatest_bkpt(void)
+{
+}
+
+
+/*
+ * Optional test
+ *	pos - 0 called from early init
+ *	pos - called when cpu about to go idle (fully initialized
+ */
 void
-sgi_mcatest(void)
+sgi_mcatest(int pos)
 {
-	if (mcatest == 1 || mcatest == 3) {
-		long	*p, result, adrs[] = {0xc0000a000f021004UL, 0xc0000a000f026004UL, 0x800000000, 0x500000, 0};
-		long	size[] = {1,2,4,8};
-		int	r, i, j;
-		p = (long*)0xc000000000000000UL;
-		ia64_fc(p);
-		*p = 0x0123456789abcdefL;
-		for (i=0; i<5; i++) {
-			for (j=0; j<4; j++) {
-				printk("Probing 0x%lx, size %ld\n", adrs[i], size[j]);
-				result = -1;
-				r = ia64_sn_probe_io_slot (adrs[i], size[j], &result);
-				printk("    status %d, val 0x%lx\n", r, result); 
+	long	spos, test, repeat;
+	int	cpu, curcpu, i, n;
+
+	//if (IS_RUNNING_ON_SIMULATOR()) mcatest=1323;
+	repeat = mcatest/1000;
+	spos = (mcatest/100)%10;
+	test = mcatest % 100;
+	curcpu = smp_processor_id();
+
+	if ( mcatest == 0 || !((pos == 0 && spos == 0) ||
+		(pos == 1 && spos == 3) ||
+	        (pos == 1 && spos == 1 && curcpu == 0) ||
+	        (pos == 1 && spos == 2 && curcpu == smp_num_cpus-1)))
+		return;
+	     
+again:
+	if (test == 1 || test == 2 || test == 3) {
+		void zzzmca(int);
+		printk("CPU %d: About to cause unexpected MCA\n", curcpu);
+		HDELAY(100000);
+		sgi_mcatest_bkpt();
+		do_sync(spos);
+
+		zzzmca(test-1);
+	
+		HDELAY(100000);
+	}
+
+	if (test == 4) {
+		long    result, adrs[] = {0xe0021000009821e0UL, 0xc0003f3000000000UL, 0xc0000081101c0000UL, 0xc00000180e021004UL,  0xc00000180e022004UL, 0xc00000180e023004UL };
+		long    size[] = {1,2,4,8};
+		int     r, i, j, k;
+
+		for (k=0; k<2; k++) {
+			for (i=0; i<6; i++) {
+				for (j=0; j<4; j++) {
+					printk("Probing 0x%lx, size %ld\n", adrs[i], size[j]);
+					result = -1;
+					r = ia64_sn_probe_io_slot (adrs[i], size[j], &result);
+					printk("    status %d, val 0x%lx\n", r, result);
+					udelay(100000);
+				}
 			}
 		}
+
 	}
-	if (mcatest == 2 || mcatest == 3) {
-		void zzzmca(int, int, int);
-		printk("About to cause unexpected MCA\n");
-		zzzmca(mcatest, 0x32dead, 0x33dead);
-	}
-	if (mcatest == 4) {
-		long	*p;
-		int	delivery_mode = 5;
-		printk("About to try to cause an INIT on cpu 0\n");
-		p = (long*)((0xc0000a0000000000LL | ((long)get_nasid())<<33) | 0x1800080);
-		*p = (delivery_mode << 8);
-		udelay(10000);
-		printk("Returned from INIT\n");
-	}
-	if (mcatest == 5) {
-		int zzzspec(long);
-		int	i;
-		long	psr, dcr, res, val, addr=0xff00000000UL;
-
-		dcr = ia64_get_dcr();
-		for (i=0; i<5; i++) {
-			printk("Default DCR: 0x%lx\n", ia64_get_dcr());
-			printk("zzzspec: 0x%x\n", zzzspec(addr));
-			ia64_set_dcr(0);
-			printk("New     DCR: 0x%lx\n", ia64_get_dcr());
-			printk("zzzspec: 0x%x\n", zzzspec(addr));
-			ia64_set_dcr(dcr);
-			res = ia64_sn_probe_io_slot(0xff00000000UL, 8, &val);
-			printk("zzzspec: probe %ld, 0x%lx\n", res, val);
-			psr = ia64_clear_ic();
-			ia64_itc(0x2, 0xe00000ff00000000UL,
-			          pte_val(pfn_pte(0xff00000000UL >> PAGE_SHIFT,
-				  __pgprot(__DIRTY_BITS|_PAGE_PL_0|_PAGE_AR_RW))), _PAGE_SIZE_256M);
-			ia64_set_psr(psr);
-			ia64_srlz_i ();
-		}
 
+	if (test == 5) {
+		cpu =  curcpu;
+		printk("CPU %d: About to send INIT to self (cpu %d)\n", curcpu, cpu);
+		HDELAY(100000);
+		sgi_mcatest_bkpt();
+		do_sync(spos);
+
+		platform_send_ipi(cpu, 0, IA64_IPI_DM_INIT, 0);
+		
+		HDELAY(100000);
+		printk("CPU %d: Returned from INIT\n", curcpu);
 	}
-	if (mcatest == 6) {
-		int zzzspec(long);
-		int	i;
-		long	dcr, addr=0xe000000008000000UL;
-
-		dcr = ia64_get_dcr();
-		for (i=0; i<5; i++) {
-			printk("zzzspec: 0x%x\n", zzzspec(addr));
-			ia64_set_dcr(0);
-		}
-		ia64_set_dcr(dcr);
-	}
-	if (mcatest == 7) {
-		int zzzspec2(long, long);
-		int	i;
-		long	addr=0xe000000008000000UL;
-		long	addr2=0xe000000007000000UL;
-
-		for (i=0; i<5; i++) {
-			printk("zzzspec2\n");
-			zzzspec2(addr, addr2);
+
+	if (test == 6) {
+		cpu =  curcpu ^ 1;
+		printk("CPU %d: About to send INIT to other cpu (cpu %d)\n", curcpu, cpu);
+		HDELAY(100000);
+		sgi_mcatest_bkpt();
+		do_sync(spos);
+
+		platform_send_ipi(cpu, 0, IA64_IPI_DM_INIT, 0);
+
+		HDELAY(100000);
+		printk("CPU %d: Done\n", curcpu);
+	}
+
+	if (test == 7) {
+		printk("CPU %d: About to send INIT to non-existent cpu\n", curcpu);
+		HDELAY(100000);
+		sgi_mcatest_bkpt();
+		do_sync(spos);
+
+		sn_send_IPI_phys(0xffff, 0, IA64_IPI_DM_INIT);
+
+		HDELAY(100000);
+		printk("CPU %d: Done\n", curcpu);
+	}
+
+	if (test == 10) {
+		n = IS_RUNNING_ON_SIMULATOR() ? 10 : 10000000;
+		cpu = 0;
+		printk("CPU %d: IPI stress test. Target cpu 0\n", curcpu);
+		HDELAY(100000);
+		sgi_mcatest_bkpt();
+		do_sync(spos);
+
+		for (i=0; i<n; i++)
+			platform_send_ipi(cpu, IA64_IPI_RESCHEDULE, IA64_IPI_DM_INT, 0);
+
+		HDELAY(100000);
+		printk("CPU %d: Done\n", curcpu);
+	}
+
+	if (test == 11) {
+		n = IS_RUNNING_ON_SIMULATOR() ? 100 : 10000000;
+		printk("CPU %d: IPI stress test. Target all cpus\n", curcpu);
+		HDELAY(100000);
+		sgi_mcatest_bkpt();
+		do_sync(spos);
+
+		for (i=0; i<n; i++)
+			for (cpu=0; cpu<smp_num_cpus; cpu++)
+				if (smp_num_cpus > 2 && cpu != curcpu)
+					platform_send_ipi(cpu, IA64_IPI_RESCHEDULE, IA64_IPI_DM_INT, 0);
+
+		HDELAY(100000);
+		printk("CPU %d: Done\n", curcpu);
+	}
+
+	if (test == 12) {
+		long adr = 0xe002200000000000UL;
+		n = IS_RUNNING_ON_SIMULATOR() ? 1000 : 100000;
+		printk("CPU %d: TLB flush stress test\n", curcpu);
+		HDELAY(100000);
+		sgi_mcatest_bkpt();
+		do_sync(spos);
+
+		for (i=0; i<n; i++)
+			platform_global_tlb_purge(adr, adr+25*PAGE_SIZE, 14);
+
+		HDELAY(100000);
+		printk("CPU %d: Done\n", curcpu);
+	}
+	
+	if (test == 13) {
+		printk("CPU %d: Park cpu in spinloop\n", curcpu);
+		while(1);
+	}
+	if (test == 14 || test == 15 || test == 16 || test == 17) {
+		long adr = 0xe002200000000000UL;
+		static int inited=0;
+		if (inited == 0) {
+			if (debug0 == 0) debug0 = 1;
+			repeat = 1;
+			do_sync(spos);
+			if (curcpu >= smp_num_cpus-2) {
+				printk("Parking cpu %d\n", curcpu);
+				local_irq_disable();
+				while(1);
+			} else {
+				printk("Waiting cpu %d\n", curcpu);
+				HDELAY(1000000);
+			}
+			HDELAY(1000000);
+			inited = 1;
+		}
+		if (test == 16 || test == 17) {
+			unsigned long t, shift, mask;
+			mask =  (smp_num_cpus > 16) ? 0x1f : 0xf;
+			shift = 25-debug1;
+			do {
+				t = get_cycles();
+				if (IS_RUNNING_ON_SIMULATOR())
+					t = (t>>8);
+				else
+					t = (t>>shift);
+				t = t & mask;
+			} while (t == curcpu);
+			do {
+				t = get_cycles();
+				if (IS_RUNNING_ON_SIMULATOR())
+					t = (t>>8);
+				else
+					t = (t>>shift);
+				t = t & mask;
+			} while (t != curcpu);
+		}
+		if(debug3) printk("CPU %d: One TLB start\n", curcpu);
+		if (test != 17) platform_global_tlb_purge(adr, adr+PAGE_SIZE*debug0, 14);
+		if(debug3) printk("CPU %d: One TLB flush done\n", curcpu);
+	}
+	if (test == 20) {
+		local_irq_disable();
+		set_led_bits(smp_processor_id(), 0xff);
+		while(1);
+	}
+	if (test == 21) {
+		extern long ia64_mca_stack[];
+		int		i, n;
+		volatile long	*p, *up;
+		p = (volatile long*)__imva(ia64_mca_stack);
+		up = (volatile long*)(__pa(p) | __IA64_UNCACHED_OFFSET);
+
+		if(!IS_RUNNING_ON_SIMULATOR()) printk("ZZZ get data in cache\n");
+		for (n=0, i=0; i<100; i++)
+			n += *(p+i);
+		if(!IS_RUNNING_ON_SIMULATOR()) printk("ZZZ Make uncached refs to same data\n");
+		for (n=0, i=0; i<100; i++)
+			n += *(up+i);
+		if(!IS_RUNNING_ON_SIMULATOR()) printk("ZZZ dirty the data via cached refs\n");
+		for (n=0, i=0; i<100; i++)
+			*(p+i) = i;
+		if(!IS_RUNNING_ON_SIMULATOR()) printk("ZZZ Make uncached refs to same data\n");
+		for (n=0, i=0; i<100; i++)
+			n += *(up+i);
+		if(!IS_RUNNING_ON_SIMULATOR()) printk("ZZZ Flushing cache\n");
+		for (n=0, i=0; i<100; i++)
+			ia64_fc((void*)(p+i));
+		printk("ZZZ done\n");
+	}
+	if (test == 21) {
+		int i;
+		volatile long tb, t[10];
+		for (i=0; i<10; i++) {
+			tb = debug3+ia64_get_itc();
+			sgi_mcatest_bkpt();
+			t[i] = ia64_get_itc() - tb;
+		}
+		for (i=0; i<10; i++) {
+			printk("ZZZ NULL  0x%lx\n", t[i]);
+		}
+		for (i=0; i<10; i++) {
+			tb = debug3+ia64_get_itc();
+			ia64_pal_call_static(PAL_MC_DRAIN, 0, 0, 0, 0);
+			t[i] = ia64_get_itc() - tb;
 		}
+		for (i=0; i<10; i++) {
+			printk("ZZZ DRAIN 0x%lx\n", t[i]);
+		}
+	}
+	if (test == 22) {
+		extern void machine_restart(char*);
+		printk("ZZZ machine_restart\n");
+		machine_restart(0);
 	}
+	if (test == 23) {
+		printk("ZZZ ia64_pal_halt_light\n");
+		ia64_pal_halt_light();
+	}
+	if (repeat)
+		goto again;
+
 }
diff -Nru a/arch/ia64/sn/kernel/setup.c b/arch/ia64/sn/kernel/setup.c
--- a/arch/ia64/sn/kernel/setup.c	Mon Dec 23 21:21:52 2002
+++ b/arch/ia64/sn/kernel/setup.c	Mon Dec 23 21:21:52 2002
@@ -47,15 +47,14 @@
 #include <linux/bootmem.h>
 #include <linux/mmzone.h>
 #include <linux/interrupt.h>
-#include <linux/root_dev.h>
+#include <linux/acpi.h>
+#include <linux/compiler.h>
+#include <linux/sched.h>
 
 #include <asm/io.h>
 #include <asm/sal.h>
 #include <asm/machvec.h>
 #include <asm/system.h>
-#ifdef CONFIG_IA64_MCA
-#include <asm/acpi-ext.h>
-#endif
 #include <asm/processor.h>
 #include <asm/sn/sgi.h>
 #include <asm/sn/io.h>
@@ -68,15 +67,24 @@
 #include <asm/sn/simulator.h>
 #include <asm/sn/leds.h>
 #include <asm/sn/bte.h>
+#include <asm/sn/clksupport.h>
+#include <asm/sn/sn_sal.h>
 
 #ifdef CONFIG_IA64_SGI_SN2
 #include <asm/sn/sn2/shub.h>
 #endif
 
+DEFINE_PER_CPU(struct pda_s, pda_percpu);
+
 extern void bte_init_node (nodepda_t *, cnodeid_t);
 extern void bte_init_cpu (void);
 
-long sn_rtc_cycles_per_second;   
+unsigned long sn_rtc_cycles_per_second;   
+unsigned long sn_rtc_usec_per_cyc;
+
+partid_t sn_partid = -1;
+char sn_system_serial_number_string[128];
+u64 sn_partition_serial_number;
 
 /*
  * This is the address of the RRegs in the HSpace of the global
@@ -88,9 +96,9 @@
  */
 u64 master_node_bedrock_address = 0UL;
 
-static void sn_init_pdas(void);
+static void sn_init_pdas(char **);
 
-extern struct irq_desc *_sn1_irq_desc[];
+extern struct irq_desc *_sn_irq_desc[];
 
 #if defined(CONFIG_IA64_SGI_SN1)
 extern synergy_da_t	*Synergy_da_indr[];
@@ -108,15 +116,15 @@
  * code. This is just enough to make the console code think we're on a
  * VGA color display.
  */
-struct screen_info sn1_screen_info = {
-	.orig_x =		 0,
-	.orig_y =		 0,
-	.orig_video_mode =	 3,
-	.orig_video_cols =	80,
-	.orig_video_ega_bx =	 3,
-	.orig_video_lines =	25,
-	.orig_video_isVGA =	 1,
-	.orig_video_points =	16
+struct screen_info sn_screen_info = {
+	orig_x:			 0,
+	orig_y:			 0,
+	orig_video_mode:	 3,
+	orig_video_cols:	80,
+	orig_video_ega_bx:	 3,
+	orig_video_lines:	25,
+	orig_video_isVGA:	 1,
+	orig_video_points:	16
 };
 
 /*
@@ -130,59 +138,81 @@
 char drive_info[4*16];
 
 /**
- * sn1_map_nr - return the mem_map entry for a given kernel address
+ * sn_map_nr - return the mem_map entry for a given kernel address
  * @addr: kernel address to query
  *
  * Finds the mem_map entry for the kernel address given.  Used by
  * virt_to_page() (asm-ia64/page.h), among other things.
  */
 unsigned long
-sn1_map_nr (unsigned long addr)
+sn_map_nr (unsigned long addr)
 {
-	return MAP_NR_DISCONTIG(addr);
+	return BANK_MAP_NR(addr);
 }
 
 /**
- * early_sn1_setup - early setup routine for SN platforms
+ * early_sn_setup - early setup routine for SN platforms
  *
  * Sets up an intial console to aid debugging.  Intended primarily
  * for bringup, it's only called if %BRINGUP and %CONFIG_IA64_EARLY_PRINTK
  * are turned on.  See start_kernel() in init/main.c.
  */
 #if defined(CONFIG_IA64_EARLY_PRINTK)
+
 void __init
-early_sn1_setup(void)
+early_sn_setup(void)
 {
-#if defined(CONFIG_SERIAL_SGI_L1_PROTOCOL)
-	if ( IS_RUNNING_ON_SIMULATOR() )
-#endif
-	{
-#ifdef CONFIG_IA64_SGI_SN2
-		master_node_bedrock_address = (u64)REMOTE_HUB(get_nasid(), SH_JUNK_BUS_UART0);
-#else
+	void ia64_sal_handler_init (void *entry_point, void *gpval);
+	efi_system_table_t			*efi_systab;
+	efi_config_table_t 			*config_tables;
+	struct ia64_sal_systab			*sal_systab;
+	struct ia64_sal_desc_entry_point	*ep;
+	char					*p;
+	int					i;
+
+	/*
+	 * Parse enough of the SAL tables to locate the SAL entry point. Since, console
+	 * IO on SN2 is done via SAL calls, early_printk wont work without this.
+	 *
+	 * This code duplicates some of the ACPI table parsing that is in efi.c & sal.c.
+	 * Any changes to those file may have to be made hereas well.
+	 */
+	efi_systab = (efi_system_table_t*)__va(ia64_boot_param->efi_systab);
+	config_tables = __va(efi_systab->tables);
+	for (i = 0; i < efi_systab->nr_tables; i++) {
+		if (efi_guidcmp(config_tables[i].guid, SAL_SYSTEM_TABLE_GUID) == 0) {
+			sal_systab = __va(config_tables[i].table);
+			p = (char*)(sal_systab+1);
+			for (i = 0; i < sal_systab->entry_count; i++) {
+				if (*p == SAL_DESC_ENTRY_POINT) {
+					ep = (struct ia64_sal_desc_entry_point *) p;
+					ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
+					break;
+				}
+				p += SAL_DESC_SIZE(*p);
+			}
+		}
+	}
+
+	if ( IS_RUNNING_ON_SIMULATOR() ) {
+#if defined(CONFIG_IA64_SGI_SN1)
 		master_node_bedrock_address = (u64)REMOTE_HSPEC_ADDR(get_nasid(), 0);
+#else
+		master_node_bedrock_address = (u64)REMOTE_HUB(get_nasid(), SH_JUNK_BUS_UART0);
 #endif
-		printk(KERN_DEBUG "early_sn1_setup: setting master_node_bedrock_address to 0x%lx\n", master_node_bedrock_address);
+		printk(KERN_DEBUG "early_sn_setup: setting master_node_bedrock_address to 0x%lx\n", master_node_bedrock_address);
 	}
 }
-#endif /* CONFIG_IA64_EARLY_PRINTK */
+#endif /* CONFIG_IA64_SGI_SN1 */
 
-#ifdef NOT_YET_CONFIG_IA64_MCA
-extern void ia64_mca_cpe_int_handler (int cpe_irq, void *arg, struct pt_regs *ptregs);
-static struct irqaction mca_cpe_irqaction = { 
-	.handler =  ia64_mca_cpe_int_handler,
-	.flags =    SA_INTERRUPT,
-	.name =     "cpe_hndlr"
-};
-#endif
 #ifdef CONFIG_IA64_MCA
-extern int platform_irq_list[];
+extern int platform_intr_list[];
 #endif
 
 extern nasid_t master_nasid;
 
 /**
- * sn1_setup - SN platform setup routine
+ * sn_setup - SN platform setup routine
  * @cmdline_p: kernel command line
  *
  * Handles platform setup for SN machines.  This includes determining
@@ -190,82 +220,77 @@
  * setting up per-node data areas.  The console is also initialized here.
  */
 void __init
-sn1_setup(char **cmdline_p)
+sn_setup(char **cmdline_p)
 {
 	long status, ticks_per_sec, drift;
 	int i;
+	int major = sn_sal_rev_major(), minor = sn_sal_rev_minor();
 
-#if defined(CONFIG_SERIAL) && !defined(CONFIG_SERIAL_SGI_L1_PROTOCOL)
-	struct serial_struct req;
+	printk("SGI SAL version %x.%02x\n", major, minor);
+
+	/*
+	 * Confirm the SAL we're running on is recent enough...
+	 */
+	if ((major < SN_SAL_MIN_MAJOR) || (major == SN_SAL_MIN_MAJOR &&
+					   minor < SN_SAL_MIN_MINOR)) {
+		printk(KERN_ERR "This kernel needs SGI SAL version >= "
+		       "%x.%02x\n", SN_SAL_MIN_MAJOR, SN_SAL_MIN_MINOR);
+		panic("PROM version too old\n");
+	}
+
+#ifdef CONFIG_IA64_SGI_SN2
+	{
+		extern void io_sh_swapper(int, int);
+		io_sh_swapper(get_nasid(), 0);
+	}
 #endif
 
 	master_nasid = get_nasid();
 	(void)get_console_nasid();
+#ifndef CONFIG_IA64_SGI_SN1
+	{
+		extern nasid_t get_master_baseio_nasid(void);
+		(void)get_master_baseio_nasid();
+	}
+#endif
 
 	status = ia64_sal_freq_base(SAL_FREQ_BASE_REALTIME_CLOCK, &ticks_per_sec, &drift);
-	if (status != 0 || ticks_per_sec < 100000)
-		printk(KERN_WARNING "unable to determine platform RTC clock frequency\n");
+	if (status != 0 || ticks_per_sec < 100000) {
+		printk(KERN_WARNING "unable to determine platform RTC clock frequency, guessing.\n");
+		/* PROM gives wrong value for clock freq. so guess */
+		sn_rtc_cycles_per_second = 1000000000000UL/30000UL;
+	}
 	else
 		sn_rtc_cycles_per_second = ticks_per_sec;
+
+#ifdef CONFIG_IA64_SGI_SN1
+	/* PROM has wrong value on SN1 */
+	sn_rtc_cycles_per_second = 990177;
+#endif
+	sn_rtc_usec_per_cyc = ((1000000UL<<IA64_USEC_PER_CYC_SHIFT)
+			       + sn_rtc_cycles_per_second/2) / sn_rtc_cycles_per_second;
 		
 	for (i=0;i<NR_CPUS;i++)
-		_sn1_irq_desc[i] = _irq_desc;
+		_sn_irq_desc[i] = _irq_desc;
 
-#ifdef CONFIG_IA64_MCA
-	platform_irq_list[ACPI20_ENTRY_PIS_CPEI] = IA64_PCE_VECTOR;
-#endif
+	platform_intr_list[ACPI_INTERRUPT_CPEI] = IA64_PCE_VECTOR;
 
 
-#if defined(CONFIG_SERIAL_SGI_L1_PROTOCOL)
 	if ( IS_RUNNING_ON_SIMULATOR() )
-#endif
 	{
 #ifdef CONFIG_IA64_SGI_SN2
 		master_node_bedrock_address = (u64)REMOTE_HUB(get_nasid(), SH_JUNK_BUS_UART0);
 #else
 		master_node_bedrock_address = (u64)REMOTE_HSPEC_ADDR(get_nasid(), 0);
 #endif
-		printk(KERN_DEBUG "sn1_setup: setting master_node_bedrock_address to 0x%lx\n",
+		printk(KERN_DEBUG "sn_setup: setting master_node_bedrock_address to 0x%lx\n",
 		       master_node_bedrock_address);
 	}
 
-#if defined(CONFIG_SERIAL) && !defined(CONFIG_SERIAL_SGI_L1_PROTOCOL)
-	/*
-	 * We do early_serial_setup() to clean out the rs-table[] from the
-	 * statically compiled in version.
-	 */
-	memset(&req, 0, sizeof(struct serial_struct));
-	req.line = 0;
-	req.baud_base = 124800;
-	req.port = 0;
-	req.port_high = 0;
-	req.irq = 0;
-	req.flags = (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST);
-	req.io_type = SERIAL_IO_MEM;
-	req.hub6 = 0;
-#ifdef CONFIG_IA64_SGI_SN2
-	req.iomem_base = (u8 *)(master_node_bedrock_address);
-#else
-	req.iomem_base = (u8 *)(master_node_bedrock_address + 0x80);
-#endif
-	req.iomem_reg_shift = 3;
-	req.type = 0;
-	req.xmit_fifo_size = 0;
-	req.custom_divisor = 0;
-	req.closing_wait = 0;
-	early_serial_setup(&req);
-#endif /* CONFIG_SERIAL && !CONFIG_SERIAL_SGI_L1_PROTOCOL */
-
-	/*
-	 * we set the default root device to /dev/hda
-	 * to make simulation easy
-	 */
-	ROOT_DEV = Root_HDA1;
-
 	/*
 	 * Create the PDAs and NODEPDAs for all the cpus.
 	 */
-	sn_init_pdas();
+	sn_init_pdas(cmdline_p);
 
 
 	/* 
@@ -278,7 +303,7 @@
 #ifdef CONFIG_SMP
 	init_smp_config();
 #endif
-	screen_info = sn1_screen_info;
+	screen_info = sn_screen_info;
 
 	/*
 	 * Turn off "floating-point assist fault" warnings by default.
@@ -289,10 +314,10 @@
 /**
  * sn_init_pdas - setup node data areas
  *
- * One time setup for Node Data Area.  Called by sn1_setup().
+ * One time setup for Node Data Area.  Called by sn_setup().
  */
 void
-sn_init_pdas(void)
+sn_init_pdas(char **cmdline_p)
 {
 	cnodeid_t	cnode;
 
@@ -300,7 +325,7 @@
 	 * Make sure that the PDA fits entirely in the same page as the 
 	 * cpu_data area.
 	 */
-	if ((PDAADDR&~PAGE_MASK)+sizeof(pda_t) > PAGE_SIZE)
+	if ( (((unsigned long)pda & ~PAGE_MASK) + sizeof(pda_t)) > PAGE_SIZE)
 		panic("overflow of cpu_data page");
 
         /*
@@ -348,11 +373,7 @@
 void __init
 sn_cpu_init(void)
 {
-	int	cpuid;
-	int	cpuphyid;
-	int	nasid;
-	int	slice;
-	int	cnode;
+	int cpuid, cpuphyid, nasid, nodeid, slice;
 
 	/*
 	 * The boot cpu makes this call again after platform initialization is
@@ -364,77 +385,104 @@
 	cpuid = smp_processor_id();
 	cpuphyid = ((ia64_get_lid() >> 16) & 0xffff);
 	nasid = cpu_physical_id_to_nasid(cpuphyid);
-	cnode = nasid_to_cnodeid(nasid);
+	nodeid = cpu_to_node_map[cpuphyid];
 	slice = cpu_physical_id_to_slice(cpuphyid);
 
-	pda.p_nodepda = nodepdaindr[cnode];
-	pda.led_address = (long*) (LED0 + (slice<<LED_CPU_SHIFT));
-	pda.led_state = 0;
-	pda.hb_count = HZ/2;
-	pda.hb_state = 0;
-	pda.idle_flag = 0;
-	
-	if (local_node_data->active_cpu_count == 1)
-		nodepda->node_first_cpu = cpuid;
-
-#ifdef CONFIG_IA64_SGI_SN1
-	{
-		int	synergy;
-		synergy = cpu_physical_id_to_synergy(cpuphyid);
-		pda.p_subnodepda = &nodepdaindr[cnode]->snpda[synergy];
+	memset(pda, 0, sizeof(pda_t));
+	pda->p_nodepda = nodepdaindr[nodeid];
+	pda->hb_count = HZ/2;
+	pda->hb_state = 0;
+	pda->idle_flag = 0;
+	pda->pio_write_status_addr = (volatile unsigned long *)
+			LOCAL_MMR_ADDR((slice < 2 ? SH_PIO_WRITE_STATUS_0 : SH_PIO_WRITE_STATUS_1 ) );
+	pda->mem_write_status_addr = (volatile u64 *)
+			LOCAL_MMR_ADDR((slice < 2 ? SH_MEMORY_WRITE_STATUS_0 : SH_MEMORY_WRITE_STATUS_1 ) );
+
+	if (nodepda->node_first_cpu == cpuid) {
+		int	buddy_nasid;
+		buddy_nasid = cnodeid_to_nasid(local_nodeid == numnodes - 1 ? 0 : local_nodeid + 1);
+		pda->pio_shub_war_cam_addr = (volatile unsigned long*)GLOBAL_MMR_ADDR(nasid, SH_PI_CAM_CONTROL);
 	}
-#endif
 
-#ifdef CONFIG_IA64_SGI_SN2
+	bte_init_cpu();
+}
 
-	/*
-	 * We must use different memory allocators for first cpu (bootmem 
-	 * allocator) than for the other cpus (regular allocator).
-	 */
-	if (cpuid == 0)
-		irqpdaindr[cpuid] = alloc_bootmem_node(NODE_DATA(cpuid_to_cnodeid(cpuid)),sizeof(irqpda_t));
-	else
-		irqpdaindr[cpuid] = page_address(alloc_pages_node(local_cnodeid(), GFP_KERNEL, get_order(sizeof(irqpda_t))));
-	memset(irqpdaindr[cpuid], 0, sizeof(irqpda_t));
-	pda.p_irqpda = irqpdaindr[cpuid];
-	pda.pio_write_status_addr = (volatile unsigned long *)LOCAL_MMR_ADDR((slice < 2 ? SH_PIO_WRITE_STATUS_0 : SH_PIO_WRITE_STATUS_1 ) );
+#ifdef II_PRTE_TLB_WAR
+long iiprt_lock[16*64] __cacheline_aligned; /* allow for NASIDs up to 64 */
 #endif
 
-#ifdef CONFIG_IA64_SGI_SN1
-	pda.bedrock_rev_id = (volatile unsigned long *) LOCAL_HUB(LB_REV_ID);
-	if (cpuid_to_synergy(cpuid))
-		/* CPU B */
-		pda.pio_write_status_addr = (volatile unsigned long *) GBL_PERF_B_ADDR;
-	else
-		/* CPU A */
-		pda.pio_write_status_addr = (volatile unsigned long *) GBL_PERF_A_ADDR;
-#endif
+#ifdef BUS_INT_WAR
+
+#include <asm/hw_irq.h>
+#include <asm/sn/pda.h>
+
+void ia64_handle_irq (ia64_vector vector, struct pt_regs *regs);
+
+static spinlock_t irq_lock = SPIN_LOCK_UNLOCKED;
+
+#define IRQCPU(irq)	((irq)>>8)
+
+void
+sn_add_polled_interrupt(int irq, int interval)
+{
+	unsigned long flags, irq_cnt;
+	sn_poll_entry_t	*irq_list;
+
+	irq_list = pdacpu(IRQCPU(irq)).pda_poll_entries;;
+
+	spin_lock_irqsave(&irq_lock, flags);
+	irq_cnt = pdacpu(IRQCPU(irq)).pda_poll_entry_count;
+	irq_list[irq_cnt].irq = irq;
+	irq_list[irq_cnt].interval = interval;
+	irq_list[irq_cnt].tick = interval;
+	pdacpu(IRQCPU(irq)).pda_poll_entry_count++;
+	spin_unlock_irqrestore(&irq_lock, flags);
 
 
-	bte_init_cpu();
 }
 
+void
+sn_delete_polled_interrupt(int irq)
+{
+	unsigned long flags, i, irq_cnt;
+	sn_poll_entry_t	*irq_list;
 
-/**
- * cnodeid_to_cpuid - convert a cnode to a cpuid of a cpu on the node.
- * @cnode: node to get a cpuid from
- *	
- * Returns -1 if no cpus exist on the node.
- * NOTE:BRINGUP ZZZ This is NOT a good way to find cpus on the node.
- * Need a better way!!
- */
-int
-cnodeid_to_cpuid(int cnode) {
-	int cpu;
-
-	for (cpu = 0; cpu < NR_CPUS; cpu++) {
-		if (!cpu_online(cpu)) continue;
-		if (cpuid_to_cnodeid(cpu) == cnode)
+	irq_list = pdacpu(IRQCPU(irq)).pda_poll_entries;
+
+	spin_lock_irqsave(&irq_lock, flags);
+	irq_cnt = pdacpu(IRQCPU(irq)).pda_poll_entry_count;
+	for (i=0; i<irq_cnt; i++) {
+		if (irq_list[i].irq == irq) {
+			irq_list[i] = irq_list[irq_cnt-1];
+			pdacpu(IRQCPU(irq)).pda_poll_entry_count--;
 			break;
+		}
 	}
+	spin_unlock_irqrestore(&irq_lock, flags);
+}
 
-	if (cpu == NR_CPUS) 
-		cpu = -1;
+void
+sn_irq_poll(int cpu, int reason) 
+{
+	unsigned long flags, i;
+	sn_poll_entry_t	*irq_list;
 
-	return cpu;
-}
+
+	ia64_handle_irq(IA64_IPI_VECTOR, 0);
+
+	if (reason == 0)
+		return;
+
+	irq_list = pda->pda_poll_entries;
+
+	for (i=0; i<pda->pda_poll_entry_count; i++, irq_list++) {
+		if (--irq_list->tick <= 0) {
+			irq_list->tick = irq_list->interval;
+			local_irq_save(flags);
+			ia64_handle_irq(irq_to_vector(irq_list->irq), 0);
+			local_irq_restore(flags);
+		}
+	}
+}	
+
+#endif
diff -Nru a/arch/ia64/sn/kernel/sn1/Makefile b/arch/ia64/sn/kernel/sn1/Makefile
--- a/arch/ia64/sn/kernel/sn1/Makefile	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/sn/kernel/sn1/Makefile	Mon Dec 23 21:21:55 2002
@@ -1,5 +1,5 @@
 #
-# ia64/platform/sn/sn1/Makefile
+# arch/ia64/sn/kernel/sn1/Makefile
 #
 # Copyright (C) 1999,2001-2002 Silicon Graphics, Inc. All rights reserved.
 #
@@ -32,6 +32,14 @@
 # http://oss.sgi.com/projects/GenInfo/NoticeExplan
 #
 
-obj-y := cache.o error.o iomv.o synergy.o sn1_smp.o
 
-EXTRA_CFLAGS := -DLITTLE_ENDIAN
+EXTRA_CFLAGS    := -DLITTLE_ENDIAN
+
+.S.s:
+	$(CPP) $(AFLAGS) $(AFLAGS_KERNEL) -o $*.s $<
+.S.o:
+	$(CC) $(AFLAGS) $(AFLAGS_KERNEL) -c -o $*.o $<
+
+O_TARGET        = sn1.o
+
+obj-y          = cache.o error.o iomv.o synergy.o sn1_smp.o
diff -Nru a/arch/ia64/sn/kernel/sn1/iomv.c b/arch/ia64/sn/kernel/sn1/iomv.c
--- a/arch/ia64/sn/kernel/sn1/iomv.c	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/sn/kernel/sn1/iomv.c	Mon Dec 23 21:21:55 2002
@@ -3,17 +3,25 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (C) 2000-2001 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 2000-2002 Silicon Graphics, Inc. All rights reserved.
  */
 
-#include <asm/io.h>
 #include <linux/pci.h>
+#include <asm/io.h>
 #include <asm/sn/simulator.h>
-#include <asm/pio_flush.h>
 #include <asm/delay.h>
+#include <asm/sn/pda.h>
 
-static inline void *
-sn1_io_addr(unsigned long port)
+/**
+ * sn_io_addr - convert an in/out port to an i/o address
+ * @port: port to convert
+ *
+ * Legacy in/out instructions are converted to ld/st instructions
+ * on IA64.  This routine will convert a port number into a valid 
+ * SN i/o address.  Used by sn_in*() and sn_out*().
+ */
+void *
+sn_io_addr(unsigned long port)
 {
 	if (!IS_RUNNING_ON_SIMULATOR()) {
 		return( (void *)  (port | __IA64_UNCACHED_OFFSET));
@@ -38,182 +46,20 @@
 }
 
 /**
- * sn1_inb - read a byte from a port
- * @port: port to read from
- *
- * Reads a byte from @port and returns it to the caller.
- */
-unsigned int
-sn1_inb (unsigned long port)
-{
-return __ia64_inb ( port );
-}
-
-/**
- * sn1_inw - read a word from a port
- * @port: port to read from
+ * sn1_mmiob - I/O space memory barrier
  *
- * Reads a word from @port and returns it to the caller.
- */
-unsigned int
-sn1_inw (unsigned long port)
-{
-return __ia64_inw ( port );
-}
-
-/**
- * sn1_inl - read a word from a port
- * @port: port to read from
- *
- * Reads a word from @port and returns it to the caller.
- */
-unsigned int
-sn1_inl (unsigned long port)
-{
-return __ia64_inl ( port );
-}
-
-/**
- * sn1_outb - write a byte to a port
- * @port: port to write to
- * @val: value to write
- *
- * Writes @val to @port.
- */
-void
-sn1_outb (unsigned char val, unsigned long port)
-{
-return __ia64_outb ( val, port );
-}
-
-/**
- * sn1_outw - write a word to a port
- * @port: port to write to
- * @val: value to write
- *
- * Writes @val to @port.
- */
-void
-sn1_outw (unsigned short val, unsigned long port)
-{
-return __ia64_outw ( val, port );
-}
-
-/**
- * sn1_outl - write a word to a port
- * @port: port to write to
- * @val: value to write
- *
- * Writes @val to @port.
- */
-void
-sn1_outl (unsigned int val, unsigned long port)
-{
-return __ia64_outl ( val, port );
-}
-
-/**
- * sn1_inb - read a byte from a port
- * @port: port to read from
+ * Acts as a memory mapped I/O barrier for platforms that queue writes to 
+ * I/O space.  This ensures that subsequent writes to I/O space arrive after
+ * all previous writes.  For most ia64 platforms, this is a simple
+ * 'mf.a' instruction.  For other platforms, mmiob() may have to read
+ * a chipset register to ensure ordering.
  *
- * Reads a byte from @port and returns it to the caller.
+ * On SN1, we wait for the PIO_WRITE_STATUS Bedrock register to clear.
  */
-unsigned int
-sn1_inb (unsigned long port)
-{
-	volatile unsigned char *addr = sn1_io_addr(port);
-	unsigned char ret;
-
-	ret = *addr;
-	__ia64_mf_a();
-	return ret;
-}
-
-/**
- * sn1_inw - read a word from a port
- * 2port: port to read from
- *
- * Reads a word from @port and returns it to the caller.
- */
-unsigned int
-sn1_inw (unsigned long port)
-{
-	volatile unsigned short *addr = sn1_io_addr(port);
-	unsigned short ret;
-
-	ret = *addr;
-	__ia64_mf_a();
-	return ret;
-}
-
-/**
- * sn1_inl - read a word from a port
- * @port: port to read from
- *
- * Reads a word from @port and returns it to the caller.
- */
-unsigned int
-sn1_inl (unsigned long port)
-{
-	volatile unsigned int *addr = sn1_io_addr(port);
-	unsigned int ret;
-
-	ret = *addr;
-	__ia64_mf_a();
-	return ret;
-}
-
-/**
- * sn1_outb - write a byte to a port
- * @port: port to write to
- * @val: value to write
- *
- * Writes @val to @port.
- */
-void
-sn1_outb (unsigned char val, unsigned long port)
-{
-	volatile unsigned char *addr = sn1_io_addr(port);
-
-	*addr = val;
-	__ia64_mf_a();
-}
-
-/**
- * sn1_outw - write a word to a port
- * @port: port to write to
- * @val: value to write
- *
- * Writes @val to @port.
- */
-void
-sn1_outw (unsigned short val, unsigned long port)
-{
-	volatile unsigned short *addr = sn1_io_addr(port);
-
-	*addr = val;
-	__ia64_mf_a();
-}
-
-/**
- * sn1_outl - write a word to a port
- * @port: port to write to
- * @val: value to write
- *
- * Writes @val to @port.
- */
-void
-sn1_outl (unsigned int val, unsigned long port)
-{
-	volatile unsigned int *addr = sn1_io_addr(port);
-
-	*addr = val;
-	__ia64_mf_a();
-}
-#endif /* SN1_IOPORTS */
-
 void
-sn_mmiob ()
+sn1_mmiob (void)
 {
-	PIO_FLUSH();
+	(volatile unsigned long) (*pda.bedrock_rev_id);
+	while (!(volatile unsigned long) (*pda.pio_write_status_addr))
+		udelay(5);
 }
diff -Nru a/arch/ia64/sn/kernel/sn1/sn1_smp.c b/arch/ia64/sn/kernel/sn1/sn1_smp.c
--- a/arch/ia64/sn/kernel/sn1/sn1_smp.c	Mon Dec 23 21:21:53 2002
+++ b/arch/ia64/sn/kernel/sn1/sn1_smp.c	Mon Dec 23 21:21:53 2002
@@ -59,11 +59,16 @@
  * to other cpus for flushing TLB ranges.
  */
 typedef struct {
-	unsigned long	start;
-	unsigned long	end;
-	unsigned long	nbits;
-	unsigned int	rid;
-	atomic_t	unfinished_count;
+	union {
+		struct {
+			unsigned long	start;
+			unsigned long	end;
+			unsigned long	nbits;
+			unsigned int	rid;
+			atomic_t	unfinished_count;
+		} ptc;
+		char pad[SMP_CACHE_BYTES];
+	};
 } ptc_params_t;
 
 #define NUMPTC	512
@@ -149,11 +154,11 @@
 		return;
 
 	do {
-		start = ptcParams->start;
+		start = ptcParams->ptc.start;
 		saved_rid = (unsigned int) ia64_get_rr(start);
-		end = ptcParams->end;
-		nbits = ptcParams->nbits;
-		rid = ptcParams->rid;
+		end = ptcParams->ptc.end;
+		nbits = ptcParams->ptc.nbits;
+		rid = ptcParams->ptc.rid;
 
 		if (saved_rid != rid) {
 			ia64_set_rr(start, (unsigned long)rid);
@@ -167,7 +172,7 @@
 
 		ia64_srlz_i();
 
-		result = atomic_dec(&ptcParams->unfinished_count);
+		result = atomic_dec(&ptcParams->ptc.unfinished_count);
 #ifdef PTCDEBUG
 		{
 		    int i = ptcParams-&ptcParamArray[0];
@@ -203,7 +208,7 @@
 	int		backlog = 0;
 #endif
 
-	if (num_online_cpus() == 1) {
+	if (smp_num_cpus == 1) {
 		sn1_ptc_l_range(start, end, nbits);
 		return;
 	}
@@ -256,7 +261,7 @@
 		/* check the current pointer to the beginning */
 		ptr = params;
 		while(--ptr >= &ptcParamArray[0]) {
-			if (atomic_read(&ptr->unfinished_count) == 0)
+			if (atomic_read(&ptr->ptc.unfinished_count) == 0)
 				break;
 			++backlog;
 		}
@@ -265,7 +270,7 @@
 			/* check the end of the array */
 			ptr = &ptcParamArray[NUMPTC];
 			while (--ptr > params) {
-				if (atomic_read(&ptr->unfinished_count) == 0)
+				if (atomic_read(&ptr->ptc.unfinished_count) == 0)
 					break;
 				++backlog;
 			}
@@ -275,12 +280,12 @@
 #endif	/* PTCDEBUG */
 
 	/* wait for the next entry to clear...should be rare */
-	if (atomic_read(&next->unfinished_count) > 0) {
+	if (atomic_read(&next->ptc.unfinished_count) > 0) {
 #ifdef PTCDEBUG
 		ptcParamsAllBusy++;
 
-		if (atomic_read(&nextnext->unfinished_count) == 0) {
-		    if (atomic_read(&next->unfinished_count) > 0) {
+		if (atomic_read(&nextnext->ptc.unfinished_count) == 0) {
+		    if (atomic_read(&next->ptc.unfinished_count) > 0) {
 			panic("\nnonzero next zero nextnext %lx %lx\n",
 			    (long)next, (long)nextnext);
 		    }
@@ -293,16 +298,16 @@
 		local_irq_restore(irqflags);
 
 		/* now we know it's not this cpu, so just wait */
-		while (atomic_read(&next->unfinished_count) > 0) {
+		while (atomic_read(&next->ptc.unfinished_count) > 0) {
 			barrier();
 		}
 	}
 
-	params->start = start;
-	params->end = end;
-	params->nbits = nbits;
-	params->rid = (unsigned int) ia64_get_rr(start);
-	atomic_set(&params->unfinished_count, num_online_cpus());
+	params->ptc.start = start;
+	params->ptc.end = end;
+	params->ptc.nbits = nbits;
+	params->ptc.rid = (unsigned int) ia64_get_rr(start);
+	atomic_set(&params->ptc.unfinished_count, smp_num_cpus);
 
 	/* The atomic_set above can hit memory *after* the update
 	 * to ptcParamsEmpty below, which opens a timing window
@@ -335,25 +340,24 @@
 	 * shouldn't be using user TLB entries.  To change this to wait
 	 * for all the flushes to complete, enable the following code.
 	 */
-#ifdef SN1_SYNCHRONOUS_GLOBAL_TLB_PURGE
+#if defined(SN1_SYNCHRONOUS_GLOBAL_TLB_PURGE) || defined(BUS_INT_WAR)
 	/* this code is not tested */
 	/* wait for the flush to complete */
-	while (atomic_read(&params.unfinished_count) > 1)
+	while (atomic_read(&params->ptc.unfinished_count) > 0)
 		barrier();
-
-	atomic_set(&params->unfinished_count, 0);
 #endif
 }
 
 /**
- * sn1_send_IPI - send an IPI to a processor
- * @cpuid: target of the IPI
+ * sn_send_IPI_phys - send an IPI to a Nasid and slice
+ * @physid: physical cpuid to receive the interrupt.
  * @vector: command to send
  * @delivery_mode: delivery mechanism
- * @redirect: redirect the IPI?
  *
  * Sends an IPI (interprocessor interrupt) to the processor specified by
- * @cpuid.  @delivery_mode can be one of the following
+ * @physid
+ *
+ * @delivery_mode can be one of the following
  *
  * %IA64_IPI_DM_INT - pend an interrupt
  * %IA64_IPI_DM_PMI - pend a PMI
@@ -361,30 +365,53 @@
  * %IA64_IPI_DM_INIT - pend an INIT interrupt
  */
 void
-sn1_send_IPI(int cpuid, int vector, int delivery_mode, int redirect)
+sn_send_IPI_phys(long physid, int vector, int delivery_mode)
 {
-	long		*p, nasid, slice;
-	static int 	off[4] = {0x1800080, 0x1800088, 0x1a00080, 0x1a00088};
+	long		*p;
+	long		nasid, slice;
 
-	/*
-	 * ZZZ - Replace with standard macros when available.
-	 */
-	nasid = cpuid_to_nasid(cpuid);
-	slice = cpuid_to_slice(cpuid);
-	p = (long*)(0xc0000a0000000000LL | (nasid<<33) | off[slice]);
+	static int 	off[4] = {0x1800080, 0x1800088, 0x1a00080, 0x1a00088};
 
-#if defined(ZZZBRINGUP)
-	{
-	static int count=0;
-	if (count++ < 10) printk("ZZ sendIPI 0x%x->0x%x, vec %d, nasid 0x%lx, slice %ld, adr 0x%lx\n",
-		smp_processor_id(), cpuid, vector, nasid, slice, (long)p);
+#ifdef BUS_INT_WAR
+	if (vector != ap_wakeup_vector) {
+		return;
 	}
 #endif
+
+	nasid = cpu_physical_id_to_nasid(physid);
+        slice = cpu_physical_id_to_slice(physid);
+
+	p = (long*)(0xc0000a0000000000LL | (nasid<<33) | off[slice]);
+
 	mb();
 	*p = (delivery_mode << 8) | (vector & 0xff);
 }
 
 
+/**
+ * sn1_send_IPI - send an IPI to a processor
+ * @cpuid: target of the IPI
+ * @vector: command to send
+ * @delivery_mode: delivery mechanism
+ * @redirect: redirect the IPI?
+ *
+ * Sends an IPI (interprocessor interrupt) to the processor specified by
+ * @cpuid.  @delivery_mode can be one of the following
+ *
+ * %IA64_IPI_DM_INT - pend an interrupt
+ * %IA64_IPI_DM_PMI - pend a PMI
+ * %IA64_IPI_DM_NMI - pend an NMI
+ * %IA64_IPI_DM_INIT - pend an INIT interrupt
+ */
+void
+sn1_send_IPI(int cpuid, int vector, int delivery_mode, int redirect)
+{
+	long		physid;
+
+	physid = cpu_physical_id(cpuid);
+
+	sn_send_IPI_phys(physid, vector, delivery_mode);
+}
 #ifdef CONFIG_SMP
 
 #ifdef PTC_NOTYET
@@ -425,7 +452,7 @@
 {
 	if (!ia64_ptc_domain_info)  {
 		printk("SMP: Can't find PTC domain info. Forcing UP mode\n");
-		cpu_online_map = 1;
+		smp_num_cpus = 1;
 		return;
 	}
 
diff -Nru a/arch/ia64/sn/kernel/sn1/synergy.c b/arch/ia64/sn/kernel/sn1/synergy.c
--- a/arch/ia64/sn/kernel/sn1/synergy.c	Mon Dec 23 21:22:00 2002
+++ b/arch/ia64/sn/kernel/sn1/synergy.c	Mon Dec 23 21:22:00 2002
@@ -240,6 +240,7 @@
 	synergy_perf_t	*p;
 	int		checked = 0;
 	int		err = 0;
+	unsigned long	flags;
 
 	/* bit 45 is enable */
 	modesel |= (1UL << 45);
@@ -279,7 +280,7 @@
 			memset(p, 0, sizeof(synergy_perf_t));
 			p->modesel = modesel;
 
-			spin_lock_irq(&npdap->synergy_perf_lock);
+			spin_lock_irqsave(&npdap->synergy_perf_lock, flags);
 			if (npdap->synergy_perf_data == NULL) {
 				/* circular list */
 				p->next = p;
@@ -290,7 +291,7 @@
 				p->next = npdap->synergy_perf_data->next;
 				npdap->synergy_perf_data->next = p;
 			}
-			spin_unlock_irq(&npdap->synergy_perf_lock);
+			spin_unlock_irqrestore(&npdap->synergy_perf_lock, flags);
 		}
 	}
 
diff -Nru a/arch/ia64/sn/kernel/sn2/Makefile b/arch/ia64/sn/kernel/sn2/Makefile
--- a/arch/ia64/sn/kernel/sn2/Makefile	Mon Dec 23 21:22:01 2002
+++ b/arch/ia64/sn/kernel/sn2/Makefile	Mon Dec 23 21:22:01 2002
@@ -1,5 +1,5 @@
 #
-# ia64/platform/sn/sn1/Makefile
+# arch/ia64/sn/kernel/sn2/Makefile
 #
 # Copyright (C) 1999,2001-2002 Silicon Graphics, Inc. All rights reserved.
 #
@@ -32,6 +32,5 @@
 # http://oss.sgi.com/projects/GenInfo/NoticeExplan
 #
 
-obj-y := cache.o iomv.o sn2_smp.o
 
 EXTRA_CFLAGS    := -DLITTLE_ENDIAN
diff -Nru a/arch/ia64/sn/kernel/sn2/iomv.c b/arch/ia64/sn/kernel/sn2/iomv.c
--- a/arch/ia64/sn/kernel/sn2/iomv.c	Mon Dec 23 21:21:58 2002
+++ b/arch/ia64/sn/kernel/sn2/iomv.c	Mon Dec 23 21:21:58 2002
@@ -6,22 +6,23 @@
  * Copyright (C) 2000-2002 Silicon Graphics, Inc. All rights reserved.
  */
 
-#include <asm/io.h>
 #include <linux/pci.h>
-#include <asm/sn/sn_cpuid.h>
+#include <asm/io.h>
+#include <asm/delay.h>
 #include <asm/sn/simulator.h>
+#include <asm/sn/pda.h>
+#include <asm/sn/sn_cpuid.h>
 
-#ifdef Colin /* Use the same calls as Generic IA64 defined in io.h */
 /**
- * sn1_io_addr - convert a in/out port to an i/o address
+ * sn_io_addr - convert an in/out port to an i/o address
  * @port: port to convert
  *
  * Legacy in/out instructions are converted to ld/st instructions
  * on IA64.  This routine will convert a port number into a valid 
- * SN i/o address.  Used by sn1_in*() and sn1_out*().
+ * SN i/o address.  Used by sn_in*() and sn_out*().
  */
-static inline void *
-sn1_io_addr(unsigned long port)
+void *
+sn_io_addr(unsigned long port)
 {
 	if (!IS_RUNNING_ON_SIMULATOR()) {
 		return( (void *)  (port | __IA64_UNCACHED_OFFSET));
@@ -46,177 +47,22 @@
 }
 
 /**
- * sn1_inb - read a byte from a port
- * @port: port to read from
- *
- * Reads a byte from @port and returns it to the caller.
- */
-unsigned int
-sn1_inb (unsigned long port)
-{
-return __ia64_inb ( port );
-}
-
-/**
- * sn1_inw - read a word from a port
- * @port: port to read from
- *
- * Reads a word from @port and returns it to the caller.
- */
-unsigned int
-sn1_inw (unsigned long port)
-{
-return __ia64_inw ( port );
-}
-
-/**
- * sn1_inl - read a word from a port
- * @port: port to read from
- *
- * Reads a word from @port and returns it to the caller.
- */
-unsigned int
-sn1_inl (unsigned long port)
-{
-return __ia64_inl ( port );
-}
-
-/**
- * sn1_outb - write a byte to a port
- * @port: port to write to
- * @val: value to write
- *
- * Writes @val to @port.
- */
-void
-sn1_outb (unsigned char val, unsigned long port)
-{
-return __ia64_outb ( val, port );
-}
-
-/**
- * sn1_outw - write a word to a port
- * @port: port to write to
- * @val: value to write
- *
- * Writes @val to @port.
- */
-void
-sn1_outw (unsigned short val, unsigned long port)
-{
-return __ia64_outw ( val, port );
-}
-
-/**
- * sn1_outl - write a word to a port
- * @port: port to write to
- * @val: value to write
- *
- * Writes @val to @port.
- */
-void
-sn1_outl (unsigned int val, unsigned long port)
-{
-return __ia64_outl ( val, port );
-}
-
-/**
- * sn1_inb - read a byte from a port
- * @port: port to read from
- *
- * Reads a byte from @port and returns it to the caller.
- */
-unsigned int
-sn1_inb (unsigned long port)
-{
-	volatile unsigned char *addr = sn1_io_addr(port);
-	unsigned char ret;
-
-	ret = *addr;
-	__ia64_mf_a();
-	return ret;
-}
-
-/**
- * sn1_inw - read a word from a port
- * 2port: port to read from
- *
- * Reads a word from @port and returns it to the caller.
- */
-unsigned int
-sn1_inw (unsigned long port)
-{
-	volatile unsigned short *addr = sn1_io_addr(port);
-	unsigned short ret;
-
-	ret = *addr;
-	__ia64_mf_a();
-	return ret;
-}
-
-/**
- * sn1_inl - read a word from a port
- * @port: port to read from
- *
- * Reads a word from @port and returns it to the caller.
- */
-unsigned int
-sn1_inl (unsigned long port)
-{
-	volatile unsigned int *addr = sn1_io_addr(port);
-	unsigned int ret;
-
-	ret = *addr;
-	__ia64_mf_a();
-	return ret;
-}
-
-/**
- * sn1_outb - write a byte to a port
- * @port: port to write to
- * @val: value to write
+ * sn2_mmiob - I/O space memory barrier
  *
- * Writes @val to @port.
- */
-void
-sn1_outb (unsigned char val, unsigned long port)
-{
-	volatile unsigned char *addr = sn1_io_addr(port);
-
-	*addr = val;
-	__ia64_mf_a();
-}
-
-/**
- * sn1_outw - write a word to a port
- * @port: port to write to
- * @val: value to write
+ * Acts as a memory mapped I/O barrier for platforms that queue writes to 
+ * I/O space.  This ensures that subsequent writes to I/O space arrive after
+ * all previous writes.  For most ia64 platforms, this is a simple
+ * 'mf.a' instruction.  For other platforms, mmiob() may have to read
+ * a chipset register to ensure ordering.
  *
- * Writes @val to @port.
- */
-void
-sn1_outw (unsigned short val, unsigned long port)
-{
-	volatile unsigned short *addr = sn1_io_addr(port);
-
-	*addr = val;
-	__ia64_mf_a();
-}
-
-/**
- * sn1_outl - write a word to a port
- * @port: port to write to
- * @val: value to write
+ * On SN2, we wait for the PIO_WRITE_STATUS SHub register to clear.
+ * See PV 871084 for details about the WAR about zero value.
  *
- * Writes @val to @port.
  */
 void
-sn1_outl (unsigned int val, unsigned long port)
+sn2_mmiob (void)
 {
-	volatile unsigned int *addr = sn1_io_addr(port);
-
-	*addr = val;
-	__ia64_mf_a();
+	while ((((volatile unsigned long) (*pda->pio_write_status_addr)) & SH_PIO_WRITE_STATUS_0_PENDING_WRITE_COUNT_MASK) != 
+				SH_PIO_WRITE_STATUS_0_PENDING_WRITE_COUNT_MASK)
+		udelay(1);
 }
-
-#endif
diff -Nru a/arch/ia64/sn/kernel/sn2/sn2_smp.c b/arch/ia64/sn/kernel/sn2/sn2_smp.c
--- a/arch/ia64/sn/kernel/sn2/sn2_smp.c	Mon Dec 23 21:22:00 2002
+++ b/arch/ia64/sn/kernel/sn2/sn2_smp.c	Mon Dec 23 21:22:00 2002
@@ -46,6 +46,7 @@
 #include <asm/irq.h>
 #include <asm/sal.h>
 #include <asm/system.h>
+#include <asm/delay.h>
 #include <asm/io.h>
 #include <asm/smp.h>
 #include <asm/hw_irq.h>
@@ -53,6 +54,310 @@
 #include <asm/sn/sn_cpuid.h>
 #include <asm/sn/addrs.h>
 #include <asm/sn/sn2/shub_mmr.h>
+#include <asm/sn/nodepda.h>
+#include <asm/sn/rw_mmr.h>
+
+void sn2_ptc_deadlock_recovery(unsigned long data0, unsigned long data1);
+
+
+static spinlock_t sn2_global_ptc_lock __cacheline_aligned = SPIN_LOCK_UNLOCKED;
+
+static unsigned long sn2_ptc_deadlock_count;
+
+
+static inline unsigned long
+wait_piowc(void)
+{
+	volatile unsigned long *piows;
+	unsigned long	ws;
+
+	piows = pda->pio_write_status_addr;
+	do {
+		__asm__ __volatile__ ("mf.a" ::: "memory");
+	} while (((ws = *piows) & SH_PIO_WRITE_STATUS_0_PENDING_WRITE_COUNT_MASK) != 
+			SH_PIO_WRITE_STATUS_0_PENDING_WRITE_COUNT_MASK);
+	return ws;
+}
+
+#ifdef PTCG_WAR
+/*
+ * The following structure is used to pass params thru smp_call_function
+ * to other cpus for flushing TLB ranges.
+ */
+typedef struct {
+	unsigned long	start;
+	unsigned long	end;
+	unsigned long	nbits;
+	unsigned int	rid;
+	atomic_t	unfinished_count;
+	char		fill[96];
+} ptc_params_t;
+
+#define NUMPTC	512
+
+static ptc_params_t	ptcParamArray[NUMPTC] __attribute__((__aligned__(128)));
+
+/* use separate cache lines on ptcParamsNextByCpu to avoid false sharing */
+static ptc_params_t	*ptcParamsNextByCpu[NR_CPUS*16] __attribute__((__aligned__(128)));
+static volatile ptc_params_t	*ptcParamsEmpty __cacheline_aligned;
+
+/*REFERENCED*/
+static spinlock_t ptcParamsLock __cacheline_aligned = SPIN_LOCK_UNLOCKED;
+
+static int ptcInit = 0;
+#ifdef PTCDEBUG
+static int ptcParamsAllBusy = 0;		/* debugging/statistics */
+static int ptcCountBacklog = 0;
+static int ptcBacklog[NUMPTC+1];
+static char ptcParamsCounts[NR_CPUS][NUMPTC] __attribute__((__aligned__(128)));
+static char ptcParamsResults[NR_CPUS][NUMPTC] __attribute__((__aligned__(128)));
+#endif
+
+/*
+ * Make smp_send_flush_tlbsmp_send_flush_tlb() a weak reference,
+ * so that we get a clean compile with the ia64 patch without the
+ * actual SN1 specific code in arch/ia64/kernel/smp.c.
+ */
+extern void smp_send_flush_tlb (void) __attribute((weak));
+
+
+/**
+ * sn1_ptc_l_range - purge local translation cache
+ * @start: start of virtual address range
+ * @end: end of virtual address range
+ * @nbits: specifies number of bytes to purge per instruction (num = 1<<(nbits & 0xfc))
+ *
+ * Purges the range specified from the local processor's translation cache
+ * (as opposed to the translation registers).  Note that more than the specified
+ * range *may* be cleared from the cache by some processors.
+ *
+ * This is probably not good enough, but I don't want to try to make it better 
+ * until I get some statistics on a running system. At a minimum, we should only 
+ * send IPIs to 1 processor in each TLB domain & have it issue a ptc.g on it's 
+ * own FSB. Also, we only have to serialize per FSB, not globally.
+ *
+ * More likely, we will have to do some work to reduce the frequency of calls to
+ * this routine.
+ */
+static inline void
+sn1_ptc_l_range(unsigned long start, unsigned long end, unsigned long nbits)
+{
+	do {
+		__asm__ __volatile__ ("ptc.l %0,%1" :: "r"(start), "r"(nbits<<2) : "memory");
+		start += (1UL << nbits);
+	} while (start < end);
+	ia64_srlz_d();
+}
+
+/**
+ * sn1_received_flush_tlb - cpu tlb flush routine
+ *
+ * Flushes the TLB of a given processor.
+ */
+void
+sn1_received_flush_tlb(void)
+{
+	unsigned long	start, end, nbits;
+	unsigned int	rid, saved_rid;
+	int		cpu = smp_processor_id();
+	int		result;
+	ptc_params_t	*ptcParams;
+
+	ptcParams = ptcParamsNextByCpu[cpu*16];
+	if (ptcParams == ptcParamsEmpty)
+		return;
+
+	do {
+		start = ptcParams->start;
+		saved_rid = (unsigned int) ia64_get_rr(start);
+		end = ptcParams->end;
+		nbits = ptcParams->nbits;
+		rid = ptcParams->rid;
+
+		if (saved_rid != rid) {
+			ia64_set_rr(start, (unsigned long)rid);
+			ia64_srlz_d();
+		}
+
+		sn1_ptc_l_range(start, end, nbits);
+
+		if (saved_rid != rid) 
+			ia64_set_rr(start, (unsigned long)saved_rid);
+
+		ia64_srlz_i();
+
+		result = atomic_dec(&ptcParams->unfinished_count);
+#ifdef PTCDEBUG
+		{
+		    int i = ptcParams-&ptcParamArray[0];
+		    ptcParamsResults[cpu][i] = (char) result;
+		    ptcParamsCounts[cpu][i]++;
+		}
+#endif /* PTCDEBUG */
+
+		if (++ptcParams == &ptcParamArray[NUMPTC])
+			ptcParams = &ptcParamArray[0];
+
+	} while (ptcParams != ptcParamsEmpty);
+
+	ptcParamsNextByCpu[cpu*16] = ptcParams;
+}
+
+/**
+ * sn1_global_tlb_purge - flush a translation cache range on all processors
+ * @start: start of virtual address range to flush
+ * @end: end of virtual address range
+ * @nbits: specifies number of bytes to purge per instruction (num = 1<<(nbits & 0xfc))
+ *
+ * Flushes the translation cache of all processors from @start to @end.
+ */
+void
+sn1_global_tlb_purge (unsigned long start, unsigned long end, unsigned long nbits)
+{
+	ptc_params_t	*params;
+	ptc_params_t	*next;
+	unsigned long	irqflags;
+#ifdef PTCDEBUG
+	ptc_params_t	*nextnext;
+	int		backlog = 0;
+#endif
+
+	if (smp_num_cpus == 1) {
+		sn1_ptc_l_range(start, end, nbits);
+		return;
+	}
+
+	if (in_interrupt()) {
+		/*
+		 *  If at interrupt level and cannot get spinlock, 
+		 *  then do something useful by flushing own tlbflush queue
+		 *  so as to avoid a possible deadlock.
+		 */
+		while (!spin_trylock(&ptcParamsLock)) {
+			local_irq_save(irqflags);
+			sn1_received_flush_tlb();
+			local_irq_restore(irqflags);
+			udelay(10);	/* take it easier on the bus */	
+		}
+	} else {
+		spin_lock(&ptcParamsLock);
+	}
+
+	if (!ptcInit) {
+		int cpu;
+		ptcInit = 1;
+		memset(ptcParamArray, 0, sizeof(ptcParamArray));
+		ptcParamsEmpty = &ptcParamArray[0];
+		for (cpu=0; cpu<NR_CPUS; cpu++)
+			ptcParamsNextByCpu[cpu*16] = &ptcParamArray[0];
+
+#ifdef PTCDEBUG
+		memset(ptcBacklog, 0, sizeof(ptcBacklog));
+		memset(ptcParamsCounts, 0, sizeof(ptcParamsCounts));
+		memset(ptcParamsResults, 0, sizeof(ptcParamsResults));
+#endif	/* PTCDEBUG */
+	}
+
+	params = (ptc_params_t *) ptcParamsEmpty;
+	next = (ptc_params_t *) ptcParamsEmpty + 1;
+	if (next == &ptcParamArray[NUMPTC])
+		next = &ptcParamArray[0];
+
+#ifdef PTCDEBUG
+	nextnext = next + 1;
+	if (nextnext == &ptcParamArray[NUMPTC])
+		nextnext = &ptcParamArray[0];
+
+	if (ptcCountBacklog) {
+		/* quick count of backlog */
+		ptc_params_t *ptr;
+
+		/* check the current pointer to the beginning */
+		ptr = params;
+		while(--ptr >= &ptcParamArray[0]) {
+			if (atomic_read(&ptr->unfinished_count) == 0)
+				break;
+			++backlog;
+		}
+
+		if (backlog) {
+			/* check the end of the array */
+			ptr = &ptcParamArray[NUMPTC];
+			while (--ptr > params) {
+				if (atomic_read(&ptr->unfinished_count) == 0)
+					break;
+				++backlog;
+			}
+		}
+		ptcBacklog[backlog]++;
+	}
+#endif	/* PTCDEBUG */
+
+	/* wait for the next entry to clear...should be rare */
+	if (atomic_read(&next->unfinished_count) > 0) {
+#ifdef PTCDEBUG
+		ptcParamsAllBusy++;
+
+		if (atomic_read(&nextnext->unfinished_count) == 0) {
+		    if (atomic_read(&next->unfinished_count) > 0) {
+			panic("\nnonzero next zero nextnext %lx %lx\n",
+			    (long)next, (long)nextnext);
+		    }
+		}
+#endif
+
+		/* it could be this cpu that is behind */
+		local_irq_save(irqflags);
+		sn1_received_flush_tlb();
+		local_irq_restore(irqflags);
+
+		/* now we know it's not this cpu, so just wait */
+		while (atomic_read(&next->unfinished_count) > 0) {
+			barrier();
+		}
+	}
+
+	params->start = start;
+	params->end = end;
+	params->nbits = nbits;
+	params->rid = (unsigned int) ia64_get_rr(start);
+	atomic_set(&params->unfinished_count, smp_num_cpus);
+
+	/* The atomic_set above can hit memory *after* the update
+	 * to ptcParamsEmpty below, which opens a timing window
+	 * that other cpus can squeeze into!
+	 */
+	mb();
+
+	/* everything is ready to process:
+	 *	-- global lock is held
+	 *	-- new entry + 1 is free
+	 *	-- new entry is set up
+	 * so now:
+	 *	-- update the global next pointer
+	 *	-- unlock the global lock
+	 *	-- send IPI to notify other cpus
+	 *	-- process the data ourselves
+	 */
+	ptcParamsEmpty = next;
+	spin_unlock(&ptcParamsLock);
+	smp_send_flush_tlb();
+
+	local_irq_save(irqflags);
+	sn1_received_flush_tlb();
+	local_irq_restore(irqflags);
+
+	/* 
+	 * Since IPIs are polled event (for now), we need to wait til the
+	 * TLB flush has started.
+	 * wait for the flush to complete 
+	 */ 
+	while (atomic_read(&params->unfinished_count) > 0)
+		barrier();
+}
+
+#endif /* PTCG_WAR */
+
 
 /**
  * sn2_global_tlb_purge - globally purge translation cache of virtual address range
@@ -63,54 +368,111 @@
  * Purges the translation caches of all processors of the given virtual address
  * range.
  */
+
 void
 sn2_global_tlb_purge (unsigned long start, unsigned long end, unsigned long nbits)
 {
-	int		cnode, nasid;
-	volatile long	*ptc0, *ptc1, *piows;
-	unsigned long	ws, next, data0, data1;
-
-	piows = (long*)LOCAL_MMR_ADDR(get_slice() ? SH_PIO_WRITE_STATUS_1 : SH_PIO_WRITE_STATUS_0);
+	int			cnode, mycnode, nasid;
+	volatile unsigned	long	*ptc0, *ptc1;
+	unsigned long		flags=0, data0, data1;
+
+	/*
+	 * Special case 1 cpu & 1 node. Use local purges.
+	 */
+#ifdef PTCG_WAR
+	sn1_global_tlb_purge(start, end, nbits);
+	return;
+#endif /* PTCG_WAR */
+		
 	data0 = (1UL<<SH_PTC_0_A_SHFT) |
 		(nbits<<SH_PTC_0_PS_SHFT) |
 		((ia64_get_rr(start)>>8)<<SH_PTC_0_RID_SHFT) |
 		(1UL<<SH_PTC_0_START_SHFT);
 
-	ptc0 = (long*)GLOBAL_MMR_ADDR(0, SH_PTC_0);
-	ptc1 = (long*)GLOBAL_MMR_ADDR(0, SH_PTC_1);
+	ptc0 = (long*)GLOBAL_MMR_PHYS_ADDR(0, SH_PTC_0);
+	ptc1 = (long*)GLOBAL_MMR_PHYS_ADDR(0, SH_PTC_1);
+
+	mycnode = local_nodeid;
+
+	/* 
+	 * For now, we dont want to spin uninterruptibly waiting
+	 * for the lock. Makes hangs hard to debug.
+	 */
+	local_irq_save(flags);
+	while (!spin_trylock(&sn2_global_ptc_lock)) {
+		local_irq_restore(flags);
+		udelay(1);
+		local_irq_save(flags);
+	}
+
 	do {
-		*(piows+1) = -1;	/* use alias address to clear bits*/
-		next = start;
-		do {
-			for (cnode = 0; cnode < numnodes; cnode++) {
+		data1 = start | (1UL<<SH_PTC_1_START_SHFT);
+		for (cnode = 0; cnode < numnodes; cnode++) {
+			if (is_headless_node(cnode))
+				continue;
+			if (cnode == mycnode) {
+				asm volatile ("ptc.ga %0,%1;;srlz.i;;" :: "r"(start), "r"(nbits<<2) : "memory");
+			} else {
 				nasid = cnodeid_to_nasid(cnode);
 				ptc0 = CHANGE_NASID(nasid, ptc0);
 				ptc1 = CHANGE_NASID(nasid, ptc1);
-				data1 = next | (1UL<<SH_PTC_1_START_SHFT);
-				*ptc0 = data0;
-				*ptc1 = data1;
+				pio_atomic_phys_write_mmrs(ptc0, data0, ptc1, data1);
 			}
-			next += (1UL << nbits);
-		} while (next < end);
+		}
+
+		if (wait_piowc() & SH_PIO_WRITE_STATUS_0_WRITE_DEADLOCK_MASK)
+			sn2_ptc_deadlock_recovery(data0, data1);
 
-		while ((ws = *piows) & SH_PIO_WRITE_STATUS_0_PENDING_WRITE_COUNT_MASK)
-			;
+		start += (1UL << nbits);
 
-	} while (ws & SH_PIO_WRITE_STATUS_0_WRITE_DEADLOCK_MASK);
+	} while (start < end);
 
-	
+	spin_unlock_irqrestore(&sn2_global_ptc_lock, flags);
+
+}
+
+/*
+ * sn2_ptc_deadlock_recovery
+ *
+ * Recover from PTC deadlocks conditions. Recovery requires stepping thru each 
+ * TLB flush transaction.  The recovery sequence is somewhat tricky & is
+ * coded in assembly language.
+ */
+void
+sn2_ptc_deadlock_recovery(unsigned long data0, unsigned long data1)
+{
+	extern void sn2_ptc_deadlock_recovery_core(long*, long, long*, long, long*);
+	int	cnode, mycnode, nasid;
+	long	*ptc0, *ptc1, *piows;
+
+	sn2_ptc_deadlock_count++;
+
+	ptc0 = (long*)GLOBAL_MMR_PHYS_ADDR(0, SH_PTC_0);
+	ptc1 = (long*)GLOBAL_MMR_PHYS_ADDR(0, SH_PTC_1);
+	piows = (long*)pda->pio_write_status_addr;
+
+	mycnode = local_nodeid;
+
+	for (cnode = 0; cnode < numnodes; cnode++) {
+		if (is_headless_node(cnode) || cnode == mycnode)
+			continue;
+		nasid = cnodeid_to_nasid(cnode);
+		ptc0 = CHANGE_NASID(nasid, ptc0);
+		ptc1 = CHANGE_NASID(nasid, ptc1);
+		sn2_ptc_deadlock_recovery_core(ptc0, data0, ptc1, data1, piows);
+	}
 }
 
 /**
- * sn2_send_IPI - send an IPI to a processor
- * @cpuid: target of the IPI
+ * sn_send_IPI_phys - send an IPI to a Nasid and slice
+ * @physid: physical cpuid to receive the interrupt.
  * @vector: command to send
  * @delivery_mode: delivery mechanism
- * @redirect: redirect the IPI?
  *
- * Sends an IPI (InterProcessor Interrupt) to the processor specified by
- * @cpuid.  @vector specifies the command to send, while @delivery_mode can 
- * be one of the following
+ * Sends an IPI (interprocessor interrupt) to the processor specified by
+ * @physid
+ *
+ * @delivery_mode can be one of the following
  *
  * %IA64_IPI_DM_INT - pend an interrupt
  * %IA64_IPI_DM_PMI - pend a PMI
@@ -118,42 +480,60 @@
  * %IA64_IPI_DM_INIT - pend an INIT interrupt
  */
 void
-sn2_send_IPI(int cpuid, int vector, int delivery_mode, int redirect)
+sn_send_IPI_phys(long physid, int vector, int delivery_mode)
 {
-	long		*p, val;
-	long		physid;
 	long		nasid, slice;
+	long		val;
+	volatile long	*p;
+
+#ifdef BUS_INT_WAR
+	if (vector != ap_wakeup_vector && delivery_mode == IA64_IPI_DM_INT) {
+		return;
+	}
+#endif
 
-	physid = cpu_physical_id(cpuid);
 	nasid = cpu_physical_id_to_nasid(physid);
         slice = cpu_physical_id_to_slice(physid);
 
-	p = (long*)GLOBAL_MMR_ADDR(nasid, SH_IPI_INT);
+	p = (long*)GLOBAL_MMR_PHYS_ADDR(nasid, SH_IPI_INT);
 	val =   (1UL<<SH_IPI_INT_SEND_SHFT) | 
 		(physid<<SH_IPI_INT_PID_SHFT) | 
 	        ((long)delivery_mode<<SH_IPI_INT_TYPE_SHFT) | 
 		((long)vector<<SH_IPI_INT_IDX_SHFT) |
 		(0x000feeUL<<SH_IPI_INT_BASE_SHFT);
 
-#if defined(BRINGUP)
-	{
-	static int count=0;
-	if (count++ < 10) printk("ZZ sendIPI 0x%x->0x%x, vec %d, nasid 0x%lx, slice %ld, adr 0x%lx, val 0x%lx\n",
-		smp_processor_id(), cpuid, vector, nasid, slice, (long)p, val);
-	}
-#endif
 	mb();
-	*p = val;
-	
+	pio_phys_write_mmr(p, val);
+
+#ifndef CONFIG_SHUB_1_0_SPECIFIC
+	/* doesnt work on shub 1.0 */
+	wait_piowc();
+#endif
 }
 
 /**
- * init_sn2_smp_config - initialize SN2 smp configuration
+ * sn2_send_IPI - send an IPI to a processor
+ * @cpuid: target of the IPI
+ * @vector: command to send
+ * @delivery_mode: delivery mechanism
+ * @redirect: redirect the IPI?
  *
- * currently a NOP.
+ * Sends an IPI (InterProcessor Interrupt) to the processor specified by
+ * @cpuid.  @vector specifies the command to send, while @delivery_mode can 
+ * be one of the following
+ *
+ * %IA64_IPI_DM_INT - pend an interrupt
+ * %IA64_IPI_DM_PMI - pend a PMI
+ * %IA64_IPI_DM_NMI - pend an NMI
+ * %IA64_IPI_DM_INIT - pend an INIT interrupt
  */
-void __init
-init_sn2_smp_config(void)
+void
+sn2_send_IPI(int cpuid, int vector, int delivery_mode, int redirect)
 {
+	long		physid;
 
+	physid = cpu_physical_id(cpuid);
+
+	sn_send_IPI_phys(physid, vector, delivery_mode);
 }
+
diff -Nru a/arch/ia64/sn/kernel/sn_asm.S b/arch/ia64/sn/kernel/sn_asm.S
--- a/arch/ia64/sn/kernel/sn_asm.S	Mon Dec 23 21:21:51 2002
+++ b/arch/ia64/sn/kernel/sn_asm.S	Mon Dec 23 21:21:51 2002
@@ -1,6 +1,33 @@
-
 /*
- * Copyright (c) 2000-2001 Silicon Graphics, Inc.  All rights reserved.
+ * Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
+ * 
+ * This program is free software; you can redistribute it and/or modify it 
+ * under the terms of version 2 of the GNU General Public License 
+ * as published by the Free Software Foundation.
+ * 
+ * This program is distributed in the hope that it would be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
+ * 
+ * Further, this software is distributed without any warranty that it is 
+ * free of the rightful claim of any third person regarding infringement 
+ * or the like.  Any license provided herein, whether implied or 
+ * otherwise, applies only to this software file.  Patent licenses, if 
+ * any, provided herein do not apply to combinations of this program with 
+ * other software, or any other product whatsoever.
+ * 
+ * You should have received a copy of the GNU General Public 
+ * License along with this program; if not, write the Free Software 
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ * 
+ * Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 
+ * Mountain View, CA  94043, or:
+ * 
+ * http://www.sgi.com 
+ * 
+ * For further information regarding this notice, see: 
+ * 
+ * http://oss.sgi.com/projects/GenInfo/NoticeExplan
  */
 
 #include <linux/config.h>
@@ -8,9 +35,10 @@
 
 // Testing only.
 // Routine will cause MCAs
-//   zzzmsa(n)
+//   zzzmca(n)
 //      n=0 MCA via duplicate TLB dropin
-//      n=0 MCA via read of garbage address
+//      n=1 MCA via read of garbage address
+//      n=2 MCA via lfetch read of garbage address
 //
 
 #define ITIR(key, ps)           ((key<<8) | (ps<<2))
@@ -45,20 +73,30 @@
 
                         rsm      0x2000;;
                         srlz.d;
-                        mov      r11      = 1
+                        mov      r11      = 5
                         mov      r3       = ITIR(0,TLB_PAGESIZE);;
                         mov      cr.itir  = r3
                         mov      r10      = 0;;
                         itr.d    dtr[r11] = r10;;
-                        mov      r11      = 2
+                        mov      r11      = 6
 
                         itr.d    dtr[r11] = r10;;
                         br      9f
 
-1:                      movl    r8=0xfe00000048;;
-                        ld8     r9=[r8];;
+1:
+			cmp.eq	p6,p7=1,r32
+#ifdef CONFIG_IA64_SGI_SN1
+                        movl    r8=0xe00000fe00000048;;
+#else
+                        movl    r8=0xe0007fb000000048;;
+#endif
+                 (p6)   ld8     r9=[r8]
+                 (p7)   lfetch.fault.nt2  [r8]
+			;;
                         mf
+			;;
                         mf.a
+			;;
                         srlz.d
 
 9:                      mov     ar.pfs=loc4
@@ -66,83 +104,4 @@
 
                         .endp   zzzmca
 
-                        .global zzzspec
-                        .proc   zzzspec
-zzzspec:
-			mov	r8=r32
-			movl	r9=0xe000000000000000
-			movl	r10=0x4000;;
-			ld8.s	r16=[r8];;
-			ld8.s	r17=[r9];;
-			add	r8=r8,r10;;
-			ld8.s	r18=[r8];;
-			add	r8=r8,r10;;
-			ld8.s	r19=[r8];;
-			add	r8=r8,r10;;
-			ld8.s	r20=[r8];;
-			mov	r8=r0
-			tnat.nz	p6,p0=r16
-			tnat.nz	p7,p0=r17
-			tnat.nz	p8,p0=r18
-			tnat.nz	p9,p0=r19
-			tnat.nz	p10,p0=r20;;
-		(p6)	dep	r8=-1,r8,0,1;;
-		(p7)	dep	r8=-1,r8,1,1;;
-		(p8)	dep	r8=-1,r8,2,1;;
-		(p9)	dep	r8=-1,r8,3,1;;
-		(p10)	dep	r8=-1,r8,4,1;;
-                        br.ret.sptk     rp
-                        .endp   zzzspec
-
-                        .global zzzspec2
-                        .proc   zzzspec2
-zzzspec2:
-			cmp.eq	p6,p7=r2,r2
-			movl	r16=0xc0000a0001000020
-			;;
-			mf
-			;;
-			ld8	r9=[r16]
-		(p6)	br.spnt	1f
-			ld8	r10=[r32]
-			;;
-		1:	mf.a
-			mf
-
-			ld8	r9=[r16];;
-			cmp.ne	p6,p7=r9,r16
-		(p6)	br.spnt	1f
-			ld8	r10=[r32]
-			;;
-		1:	mf.a
-			mf
-
-			ld8	r9=[r33];;
-			cmp.ne	p6,p7=r9,r33
-		(p6)	br.spnt	1f
-			ld8	r10=[r32]
-			;;
-		1:	mf.a
-			mf
-
-			tpa	r23=r32
-			add	r20=512,r33
-			add	r21=1024,r33;;
-			ld8	r9=[r20]
-			ld8	r10=[r21];;
-			nop.i	0
-			{ .mib
-			nop.m 0
-			cmp.ne	p6,p7=r10,r33
-		(p6)	br.spnt	1f
-			}
-			ld8	r10=[r32]
-			;;
-		1:	mf.a
-			mf
-			br.ret.sptk     rp
-
-                        .endp   zzzspec
-
 #endif
-
diff -Nru a/arch/ia64/sn/kernel/sn_ksyms.c b/arch/ia64/sn/kernel/sn_ksyms.c
--- a/arch/ia64/sn/kernel/sn_ksyms.c	Mon Dec 23 21:21:58 2002
+++ b/arch/ia64/sn/kernel/sn_ksyms.c	Mon Dec 23 21:21:58 2002
@@ -15,15 +15,8 @@
 #include <linux/module.h>
 
 #include <asm/machvec.h>
-
-/*
- * other stuff (more to be added later, cleanup then)
- */
-EXPORT_SYMBOL(sn1_pci_map_sg);
-EXPORT_SYMBOL(sn1_pci_unmap_sg);
-EXPORT_SYMBOL(sn1_pci_alloc_consistent);
-EXPORT_SYMBOL(sn1_pci_free_consistent);
-EXPORT_SYMBOL(sn1_dma_address);
+#include <asm/sn/intr.h>
+#include <asm/sn/arch.h>
 
 #include <linux/mm.h>
 #include <linux/devfs_fs_kernel.h>
@@ -52,13 +45,39 @@
 EXPORT_SYMBOL(hwgraph_edge_add);
 EXPORT_SYMBOL(pciio_info_master_get);
 EXPORT_SYMBOL(pciio_info_get);
+
 #ifdef CONFIG_IA64_SGI_SN_DEBUG
 EXPORT_SYMBOL(__pa_debug);
 EXPORT_SYMBOL(__va_debug);
 #endif
 
+/* Support IPIs for loaded modules. */
+EXPORT_SYMBOL(sn_send_IPI_phys);
+
+/* symbols referenced by partitioning modules */
+#include <asm/sn/bte_copy.h>
+EXPORT_SYMBOL(bte_unaligned_copy);
+#include <asm/sal.h>
+EXPORT_SYMBOL(ia64_sal);
+
+#ifdef CONFIG_IA64_SGI_SN2
+#include <asm/sn/sn_sal.h>
+EXPORT_SYMBOL(sal_lock);
+EXPORT_SYMBOL(sn_partid);
+EXPORT_SYMBOL(sn_local_partid);
+EXPORT_SYMBOL(sn_system_serial_number_string);
+EXPORT_SYMBOL(sn_partition_serial_number);
+#endif
+
 /* added by tduffy 04.08.01 to fix depmod issues */
 #include <linux/mmzone.h>
-EXPORT_SYMBOL(sn1_pci_unmap_single);
-EXPORT_SYMBOL(sn1_pci_map_single);
-EXPORT_SYMBOL(sn1_pci_dma_sync_single);
+
+#ifdef BUS_INT_WAR
+extern void sn_add_polled_interrupt(int, int);
+extern void sn_delete_polled_interrupt(int);
+EXPORT_SYMBOL(sn_add_polled_interrupt);
+EXPORT_SYMBOL(sn_delete_polled_interrupt);
+#endif
+
+extern nasid_t master_nasid;
+EXPORT_SYMBOL(master_nasid);
diff -Nru a/arch/ia64/sn/kernel/sv.c b/arch/ia64/sn/kernel/sv.c
--- a/arch/ia64/sn/kernel/sv.c	Mon Dec 23 21:21:51 2002
+++ b/arch/ia64/sn/kernel/sv.c	Mon Dec 23 21:21:51 2002
@@ -3,7 +3,7 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (C) 2000-2001 Silicon Graphics, Inc.  All rights reserved
+ * Copyright (C) 2000-2002 Silicon Graphics, Inc.  All rights reserved
  *
  * This implemenation of synchronization variables is heavily based on
  * one done by Steve Lord <lord@sgi.com>
@@ -210,7 +210,7 @@
 	 */
 
 	/* don't need the _irqsave part, but there is no wq_write_lock() */
-	wq_write_lock_irqsave(&sv->sv_waiters.lock, flags);
+	write_lock_irqsave(&sv->sv_waiters.lock, flags);
 
 #ifdef EXCLUSIVE_IN_QUEUE
 	wait.flags |= WQ_FLAG_EXCLUSIVE;
@@ -228,7 +228,7 @@
 					(void *)sv, sv->sv_flags);
 		BUG();
 	}
-	wq_write_unlock_irqrestore(&sv->sv_waiters.lock, flags);
+	write_unlock_irqrestore(&sv->sv_waiters.lock, flags);
 
 	if(sv_wait_flags & SV_WAIT_SIG)
 		set_current_state(TASK_EXCLUSIVE | TASK_INTERRUPTIBLE  );
diff -Nru a/arch/ia64/sn/tools/make_textsym b/arch/ia64/sn/tools/make_textsym
--- a/arch/ia64/sn/tools/make_textsym	Mon Dec 23 21:21:50 2002
+++ b/arch/ia64/sn/tools/make_textsym	Mon Dec 23 21:21:50 2002
@@ -44,7 +44,7 @@
 
 [ -f $VMLINUX ] || help
 
-$OBJDUMP -t $LINUX | sort > $TMPSYM
+$OBJDUMP -t $LINUX | egrep -v '__ks' | sort > $TMPSYM
 SN1=`egrep "dig_setup|Synergy_da_indr" $TMPSYM|wc -l`
 
 # Dataprefix and textprefix correspond to the VGLOBAL_BASE and VPERNODE_BASE.
@@ -58,74 +58,74 @@
 # pipe everything thru sort
 echo "TEXTSYM V1.0"
 (cat <<END 
-GLOBAL | ${textprefix}00400000 | CODE | VEC_VHPT_Translation_0000
-GLOBAL | ${textprefix}00400400 | CODE | VEC_ITLB_0400
-GLOBAL | ${textprefix}00400800 | CODE | VEC_DTLB_0800
-GLOBAL | ${textprefix}00400c00 | CODE | VEC_Alt_ITLB_0c00
-GLOBAL | ${textprefix}00401000 | CODE | VEC_Alt_DTLB_1000
-GLOBAL | ${textprefix}00401400 | CODE | VEC_Data_nested_TLB_1400
-GLOBAL | ${textprefix}00401800 | CODE | VEC_Instruction_Key_Miss_1800
-GLOBAL | ${textprefix}00401c00 | CODE | VEC_Data_Key_Miss_1c00
-GLOBAL | ${textprefix}00402000 | CODE | VEC_Dirty-bit_2000
-GLOBAL | ${textprefix}00402400 | CODE | VEC_Instruction_Access-bit_2400
-GLOBAL | ${textprefix}00402800 | CODE | VEC_Data_Access-bit_2800
-GLOBAL | ${textprefix}00402c00 | CODE | VEC_Break_instruction_2c00
-GLOBAL | ${textprefix}00403000 | CODE | VEC_External_Interrupt_3000
-GLOBAL | ${textprefix}00403400 | CODE | VEC_Reserved_3400
-GLOBAL | ${textprefix}00403800 | CODE | VEC_Reserved_3800
-GLOBAL | ${textprefix}00403c00 | CODE | VEC_Reserved_3c00
-GLOBAL | ${textprefix}00404000 | CODE | VEC_Reserved_4000
-GLOBAL | ${textprefix}00404400 | CODE | VEC_Reserved_4400
-GLOBAL | ${textprefix}00404800 | CODE | VEC_Reserved_4800
-GLOBAL | ${textprefix}00404c00 | CODE | VEC_Reserved_4c00
-GLOBAL | ${textprefix}00405000 | CODE | VEC_Page_Not_Present_5000
-GLOBAL | ${textprefix}00405100 | CODE | VEC_Key_Permission_5100
-GLOBAL | ${textprefix}00405200 | CODE | VEC_Instruction_Access_Rights_5200
-GLOBAL | ${textprefix}00405300 | CODE | VEC_Data_Access_Rights_5300
-GLOBAL | ${textprefix}00405400 | CODE | VEC_General_Exception_5400
-GLOBAL | ${textprefix}00405500 | CODE | VEC_Disabled_FP-Register_5500
-GLOBAL | ${textprefix}00405600 | CODE | VEC_Nat_Consumption_5600
-GLOBAL | ${textprefix}00405700 | CODE | VEC_Speculation_5700
-GLOBAL | ${textprefix}00405800 | CODE | VEC_Reserved_5800
-GLOBAL | ${textprefix}00405900 | CODE | VEC_Debug_5900
-GLOBAL | ${textprefix}00405a00 | CODE | VEC_Unaligned_Reference_5a00
-GLOBAL | ${textprefix}00405b00 | CODE | VEC_Unsupported_Data_Reference_5b00
-GLOBAL | ${textprefix}00405c00 | CODE | VEC_Floating-Point_Fault_5c00
-GLOBAL | ${textprefix}00405d00 | CODE | VEC_Floating_Point_Trap_5d00
-GLOBAL | ${textprefix}00405e00 | CODE | VEC_Lower_Privilege_Tranfer_Trap_5e00
-GLOBAL | ${textprefix}00405f00 | CODE | VEC_Taken_Branch_Trap_5f00
-GLOBAL | ${textprefix}00406000 | CODE | VEC_Single_Step_Trap_6000
-GLOBAL | ${textprefix}00406100 | CODE | VEC_Reserved_6100
-GLOBAL | ${textprefix}00406200 | CODE | VEC_Reserved_6200
-GLOBAL | ${textprefix}00406300 | CODE | VEC_Reserved_6300
-GLOBAL | ${textprefix}00406400 | CODE | VEC_Reserved_6400
-GLOBAL | ${textprefix}00406500 | CODE | VEC_Reserved_6500
-GLOBAL | ${textprefix}00406600 | CODE | VEC_Reserved_6600
-GLOBAL | ${textprefix}00406700 | CODE | VEC_Reserved_6700
-GLOBAL | ${textprefix}00406800 | CODE | VEC_Reserved_6800
-GLOBAL | ${textprefix}00406900 | CODE | VEC_IA-32_Exeception_6900
-GLOBAL | ${textprefix}00406a00 | CODE | VEC_IA-32_Intercept_6a00
-GLOBAL | ${textprefix}00406b00 | CODE | VEC_IA-32_Interrupt_6b00
-GLOBAL | ${textprefix}00406c00 | CODE | VEC_Reserved_6c00
-GLOBAL | ${textprefix}00406d00 | CODE | VEC_Reserved_6d00
-GLOBAL | ${textprefix}00406e00 | CODE | VEC_Reserved_6e00
-GLOBAL | ${textprefix}00406f00 | CODE | VEC_Reserved_6f00
-GLOBAL | ${textprefix}00407000 | CODE | VEC_Reserved_7000
-GLOBAL | ${textprefix}00407100 | CODE | VEC_Reserved_7100
-GLOBAL | ${textprefix}00407200 | CODE | VEC_Reserved_7200
-GLOBAL | ${textprefix}00407300 | CODE | VEC_Reserved_7300
-GLOBAL | ${textprefix}00407400 | CODE | VEC_Reserved_7400
-GLOBAL | ${textprefix}00407500 | CODE | VEC_Reserved_7500
-GLOBAL | ${textprefix}00407600 | CODE | VEC_Reserved_7600
-GLOBAL | ${textprefix}00407700 | CODE | VEC_Reserved_7700
-GLOBAL | ${textprefix}00407800 | CODE | VEC_Reserved_7800
-GLOBAL | ${textprefix}00407900 | CODE | VEC_Reserved_7900
-GLOBAL | ${textprefix}00407a00 | CODE | VEC_Reserved_7a00
-GLOBAL | ${textprefix}00407b00 | CODE | VEC_Reserved_7b00
-GLOBAL | ${textprefix}00407c00 | CODE | VEC_Reserved_7c00
-GLOBAL | ${textprefix}00407d00 | CODE | VEC_Reserved_7d00
-GLOBAL | ${textprefix}00407e00 | CODE | VEC_Reserved_7e00
-GLOBAL | ${textprefix}00407f00 | CODE | VEC_Reserved_7f00
+GLOBAL | ${textprefix}00000000 | CODE | VEC_VHPT_Translation_0000
+GLOBAL | ${textprefix}00000400 | CODE | VEC_ITLB_0400
+GLOBAL | ${textprefix}00000800 | CODE | VEC_DTLB_0800
+GLOBAL | ${textprefix}00000c00 | CODE | VEC_Alt_ITLB_0c00
+GLOBAL | ${textprefix}00001000 | CODE | VEC_Alt_DTLB_1000
+GLOBAL | ${textprefix}00001400 | CODE | VEC_Data_nested_TLB_1400
+GLOBAL | ${textprefix}00001800 | CODE | VEC_Instruction_Key_Miss_1800
+GLOBAL | ${textprefix}00001c00 | CODE | VEC_Data_Key_Miss_1c00
+GLOBAL | ${textprefix}00002000 | CODE | VEC_Dirty-bit_2000
+GLOBAL | ${textprefix}00002400 | CODE | VEC_Instruction_Access-bit_2400
+GLOBAL | ${textprefix}00002800 | CODE | VEC_Data_Access-bit_2800
+GLOBAL | ${textprefix}00002c00 | CODE | VEC_Break_instruction_2c00
+GLOBAL | ${textprefix}00003000 | CODE | VEC_External_Interrupt_3000
+GLOBAL | ${textprefix}00003400 | CODE | VEC_Reserved_3400
+GLOBAL | ${textprefix}00003800 | CODE | VEC_Reserved_3800
+GLOBAL | ${textprefix}00003c00 | CODE | VEC_Reserved_3c00
+GLOBAL | ${textprefix}00004000 | CODE | VEC_Reserved_4000
+GLOBAL | ${textprefix}00004400 | CODE | VEC_Reserved_4400
+GLOBAL | ${textprefix}00004800 | CODE | VEC_Reserved_4800
+GLOBAL | ${textprefix}00004c00 | CODE | VEC_Reserved_4c00
+GLOBAL | ${textprefix}00005000 | CODE | VEC_Page_Not_Present_5000
+GLOBAL | ${textprefix}00005100 | CODE | VEC_Key_Permission_5100
+GLOBAL | ${textprefix}00005200 | CODE | VEC_Instruction_Access_Rights_5200
+GLOBAL | ${textprefix}00005300 | CODE | VEC_Data_Access_Rights_5300
+GLOBAL | ${textprefix}00005400 | CODE | VEC_General_Exception_5400
+GLOBAL | ${textprefix}00005500 | CODE | VEC_Disabled_FP-Register_5500
+GLOBAL | ${textprefix}00005600 | CODE | VEC_Nat_Consumption_5600
+GLOBAL | ${textprefix}00005700 | CODE | VEC_Speculation_5700
+GLOBAL | ${textprefix}00005800 | CODE | VEC_Reserved_5800
+GLOBAL | ${textprefix}00005900 | CODE | VEC_Debug_5900
+GLOBAL | ${textprefix}00005a00 | CODE | VEC_Unaligned_Reference_5a00
+GLOBAL | ${textprefix}00005b00 | CODE | VEC_Unsupported_Data_Reference_5b00
+GLOBAL | ${textprefix}00005c00 | CODE | VEC_Floating-Point_Fault_5c00
+GLOBAL | ${textprefix}00005d00 | CODE | VEC_Floating_Point_Trap_5d00
+GLOBAL | ${textprefix}00005e00 | CODE | VEC_Lower_Privilege_Tranfer_Trap_5e00
+GLOBAL | ${textprefix}00005f00 | CODE | VEC_Taken_Branch_Trap_5f00
+GLOBAL | ${textprefix}00006000 | CODE | VEC_Single_Step_Trap_6000
+GLOBAL | ${textprefix}00006100 | CODE | VEC_Reserved_6100
+GLOBAL | ${textprefix}00006200 | CODE | VEC_Reserved_6200
+GLOBAL | ${textprefix}00006300 | CODE | VEC_Reserved_6300
+GLOBAL | ${textprefix}00006400 | CODE | VEC_Reserved_6400
+GLOBAL | ${textprefix}00006500 | CODE | VEC_Reserved_6500
+GLOBAL | ${textprefix}00006600 | CODE | VEC_Reserved_6600
+GLOBAL | ${textprefix}00006700 | CODE | VEC_Reserved_6700
+GLOBAL | ${textprefix}00006800 | CODE | VEC_Reserved_6800
+GLOBAL | ${textprefix}00006900 | CODE | VEC_IA-32_Exeception_6900
+GLOBAL | ${textprefix}00006a00 | CODE | VEC_IA-32_Intercept_6a00
+GLOBAL | ${textprefix}00006b00 | CODE | VEC_IA-32_Interrupt_6b00
+GLOBAL | ${textprefix}00006c00 | CODE | VEC_Reserved_6c00
+GLOBAL | ${textprefix}00006d00 | CODE | VEC_Reserved_6d00
+GLOBAL | ${textprefix}00006e00 | CODE | VEC_Reserved_6e00
+GLOBAL | ${textprefix}00006f00 | CODE | VEC_Reserved_6f00
+GLOBAL | ${textprefix}00007000 | CODE | VEC_Reserved_7000
+GLOBAL | ${textprefix}00007100 | CODE | VEC_Reserved_7100
+GLOBAL | ${textprefix}00007200 | CODE | VEC_Reserved_7200
+GLOBAL | ${textprefix}00007300 | CODE | VEC_Reserved_7300
+GLOBAL | ${textprefix}00007400 | CODE | VEC_Reserved_7400
+GLOBAL | ${textprefix}00007500 | CODE | VEC_Reserved_7500
+GLOBAL | ${textprefix}00007600 | CODE | VEC_Reserved_7600
+GLOBAL | ${textprefix}00007700 | CODE | VEC_Reserved_7700
+GLOBAL | ${textprefix}00007800 | CODE | VEC_Reserved_7800
+GLOBAL | ${textprefix}00007900 | CODE | VEC_Reserved_7900
+GLOBAL | ${textprefix}00007a00 | CODE | VEC_Reserved_7a00
+GLOBAL | ${textprefix}00007b00 | CODE | VEC_Reserved_7b00
+GLOBAL | ${textprefix}00007c00 | CODE | VEC_Reserved_7c00
+GLOBAL | ${textprefix}00007d00 | CODE | VEC_Reserved_7d00
+GLOBAL | ${textprefix}00007e00 | CODE | VEC_Reserved_7e00
+GLOBAL | ${textprefix}00007f00 | CODE | VEC_Reserved_7f00
 END
 
 
@@ -157,10 +157,10 @@
 	print $0
 	if (sn1 != 0) {
 		/* 32 bits of sn1 physical addrs, */
-		print substr($0,1,9) substr($0,18,18) "Phy_" substr($0,36)
+		print substr($0,1,9) "04" substr($0,20,16) "Phy_" substr($0,36)
 	} else {
 		/* 38 bits of sn2 physical addrs, need addr space bits */
-		print substr($0,1,9) "30" substr($0,18,18) "Phy_" substr($0,36)
+		print substr($0,1,9) "3004" substr($0,20,16) "Phy_" substr($0,36)
 	}
 
 } ' | sort -k3
diff -Nru a/arch/ia64/tools/Makefile b/arch/ia64/tools/Makefile
--- a/arch/ia64/tools/Makefile	Mon Dec 23 21:21:55 2002
+++ b/arch/ia64/tools/Makefile	Mon Dec 23 21:21:55 2002
@@ -1,6 +1,6 @@
 CFLAGS	= -g -O2 -Wall $(CPPFLAGS)
 
-TARGET	= $(TOPDIR)/include/asm-ia64/offsets.h
+TARGET	= include/asm-ia64/offsets.h
 
 src = $(obj)
 
diff -Nru a/arch/ia64/vmlinux.lds.S b/arch/ia64/vmlinux.lds.S
--- a/arch/ia64/vmlinux.lds.S	Mon Dec 23 21:21:59 2002
+++ b/arch/ia64/vmlinux.lds.S	Mon Dec 23 21:21:59 2002
@@ -97,6 +97,12 @@
 
   .init.data : AT(ADDR(.init.data) - PAGE_OFFSET)
 	{ *(.init.data) }
+
+  __initramfs_start = .;
+  .init.ramfs : AT(ADDR(.init.ramfs) - PAGE_OFFSET)
+	{ *(.init.ramfs) }
+  __initramfs_end = .;
+
    . = ALIGN(16);
   __setup_start = .;
   .init.setup : AT(ADDR(.init.setup) - PAGE_OFFSET)
diff -Nru a/arch/sparc/kernel/signal.c b/arch/sparc/kernel/signal.c
--- a/arch/sparc/kernel/signal.c	Mon Dec 23 21:21:58 2002
+++ b/arch/sparc/kernel/signal.c	Mon Dec 23 21:21:58 2002
@@ -1171,7 +1171,7 @@
 			case SIGQUIT: case SIGILL: case SIGTRAP:
 			case SIGABRT: case SIGFPE: case SIGSEGV:
 			case SIGBUS: case SIGSYS: case SIGXCPU: case SIGXFSZ:
-				if (do_coredump(signr, regs))
+				if (do_coredump(signr, exit_code, regs))
 					exit_code |= 0x80;
 				/* FALLTHRU */
 
diff -Nru a/arch/sparc64/kernel/ioctl32.c b/arch/sparc64/kernel/ioctl32.c
--- a/arch/sparc64/kernel/ioctl32.c	Mon Dec 23 21:22:00 2002
+++ b/arch/sparc64/kernel/ioctl32.c	Mon Dec 23 21:22:00 2002
@@ -973,8 +973,8 @@
 	mm_segment_t old_fs = get_fs();
 	
 	ret = copy_from_user (&f, (struct fbcursor32 *)arg, 2 * sizeof (short) + 2 * sizeof(struct fbcurpos));
-	ret |= __get_user(f.size.fbx, &(((struct fbcursor32 *)arg)->size.fbx));
-	ret |= __get_user(f.size.fby, &(((struct fbcursor32 *)arg)->size.fby));
+	ret |= __get_user(f.size.x, &(((struct fbcursor32 *)arg)->size.x));
+	ret |= __get_user(f.size.y, &(((struct fbcursor32 *)arg)->size.y));
 	ret |= __get_user(f.cmap.index, &(((struct fbcursor32 *)arg)->cmap.index));
 	ret |= __get_user(f.cmap.count, &(((struct fbcursor32 *)arg)->cmap.count));
 	ret |= __get_user(r, &(((struct fbcursor32 *)arg)->cmap.red));
@@ -985,10 +985,10 @@
 	if (ret)
 		return -EFAULT;
 	if (f.set & FB_CUR_SETCMAP) {
-		if ((uint) f.size.fby > 32)
+		if ((uint) f.size.y > 32)
 			return -EINVAL;
-		ret = copy_from_user (mask, (char *)A(m), f.size.fby * 4);
-		ret |= copy_from_user (image, (char *)A(i), f.size.fby * 4);
+		ret = copy_from_user (mask, (char *)A(m), f.size.y * 4);
+		ret |= copy_from_user (image, (char *)A(i), f.size.y * 4);
 		if (ret)
 			return -EFAULT;
 		f.image = image; f.mask = mask;
@@ -4346,11 +4346,6 @@
 COMPATIBLE_IOCTL(FBIOGET_VSCREENINFO)
 COMPATIBLE_IOCTL(FBIOPUT_VSCREENINFO)
 COMPATIBLE_IOCTL(FBIOPAN_DISPLAY)
-COMPATIBLE_IOCTL(FBIOGET_FCURSORINFO)
-COMPATIBLE_IOCTL(FBIOGET_VCURSORINFO)
-COMPATIBLE_IOCTL(FBIOPUT_VCURSORINFO)
-COMPATIBLE_IOCTL(FBIOGET_CURSORSTATE)
-COMPATIBLE_IOCTL(FBIOPUT_CURSORSTATE)
 COMPATIBLE_IOCTL(FBIOGET_CON2FBMAP)
 COMPATIBLE_IOCTL(FBIOPUT_CON2FBMAP)
 /* Little f */
diff -Nru a/arch/sparc64/kernel/signal.c b/arch/sparc64/kernel/signal.c
--- a/arch/sparc64/kernel/signal.c	Mon Dec 23 21:21:55 2002
+++ b/arch/sparc64/kernel/signal.c	Mon Dec 23 21:21:55 2002
@@ -714,7 +714,7 @@
 			case SIGQUIT: case SIGILL: case SIGTRAP:
 			case SIGABRT: case SIGFPE: case SIGSEGV:
 			case SIGBUS: case SIGSYS: case SIGXCPU: case SIGXFSZ:
-				if (do_coredump(signr, regs))
+				if (do_coredump(signr, exit_code, regs))
 					exit_code |= 0x80;
 				/* FALLTHRU */
 
diff -Nru a/arch/sparc64/kernel/signal32.c b/arch/sparc64/kernel/signal32.c
--- a/arch/sparc64/kernel/signal32.c	Mon Dec 23 21:21:50 2002
+++ b/arch/sparc64/kernel/signal32.c	Mon Dec 23 21:21:50 2002
@@ -1385,7 +1385,7 @@
 			case SIGQUIT: case SIGILL: case SIGTRAP:
 			case SIGABRT: case SIGFPE: case SIGSEGV:
 			case SIGBUS: case SIGSYS: case SIGXCPU: case SIGXFSZ:
-				if (do_coredump(signr, regs))
+				if (do_coredump(signr, exit_code, regs))
 					exit_code |= 0x80;
 				/* FALLTHRU */
 
diff -Nru a/arch/sparc64/kernel/sys_sparc32.c b/arch/sparc64/kernel/sys_sparc32.c
--- a/arch/sparc64/kernel/sys_sparc32.c	Mon Dec 23 21:21:57 2002
+++ b/arch/sparc64/kernel/sys_sparc32.c	Mon Dec 23 21:21:57 2002
@@ -1397,7 +1397,7 @@
 	return ret;
 }
 
-static int cp_new_stat32(struct kstat *stat, struct stat32 *statbuf)
+int cp_compat_stat(struct kstat *stat, struct compat_stat *statbuf)
 {
 	int err;
 
@@ -1425,39 +1425,6 @@
 	return err;
 }
 
-asmlinkage int sys32_newstat(char * filename, struct stat32 *statbuf)
-{
-	struct kstat stat;
-	int error = vfs_stat(filename, &stat);
-
-	if (!error)
-		error = cp_new_stat32(&stat, statbuf);
-
-	return error;
-}
-
-asmlinkage int sys32_newlstat(char * filename, struct stat32 *statbuf)
-{
-	struct kstat stat;
-	int error = vfs_lstat(filename, &stat);
-
-	if (!error)
-		error = cp_new_stat32(&stat, statbuf);
-
-	return error;
-}
-
-asmlinkage int sys32_newfstat(unsigned int fd, struct stat32 *statbuf)
-{
-	struct kstat stat;
-	int error = vfs_fstat(fd, &stat);
-
-	if (!error)
-		error = cp_new_stat32(&stat, statbuf);
-
-	return error;
-}
-
 extern asmlinkage int sys_sysfs(int option, unsigned long arg1, unsigned long arg2);
 
 asmlinkage int sys32_sysfs(int option, u32 arg1, u32 arg2)
@@ -1986,36 +1953,6 @@
 	return ret;
 }
 
-struct tms32 {
-	__kernel_clock_t32 tms_utime;
-	__kernel_clock_t32 tms_stime;
-	__kernel_clock_t32 tms_cutime;
-	__kernel_clock_t32 tms_cstime;
-};
-                                
-extern asmlinkage long sys_times(struct tms * tbuf);
-
-asmlinkage long sys32_times(struct tms32 *tbuf)
-{
-	struct tms t;
-	long ret;
-	mm_segment_t old_fs = get_fs ();
-	int err;
-	
-	set_fs (KERNEL_DS);
-	ret = sys_times(tbuf ? &t : NULL);
-	set_fs (old_fs);
-	if (tbuf) {
-		err = put_user (t.tms_utime, &tbuf->tms_utime);
-		err |= __put_user (t.tms_stime, &tbuf->tms_stime);
-		err |= __put_user (t.tms_cutime, &tbuf->tms_cutime);
-		err |= __put_user (t.tms_cstime, &tbuf->tms_cstime);
-		if (err)
-			ret = -EFAULT;
-	}
-	return ret;
-}
-
 #define RLIM_INFINITY32	0x7fffffff
 #define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x)
 
@@ -3463,8 +3400,6 @@
 	return do_sys_settimeofday(tv ? &ktv : NULL, tz ? &ktz : NULL);
 }
 
-asmlinkage int sys_utimes(char *, struct timeval *);
-
 asmlinkage int sys32_utimes(char *filename, struct compat_timeval *tvs)
 {
 	char *kfilename;
@@ -3483,7 +3418,7 @@
 
 		old_fs = get_fs();
 		set_fs(KERNEL_DS);
-		ret = sys_utimes(kfilename, &ktvs[0]);
+		ret = do_utimes(kfilename, (tvs ? &ktvs[0] : NULL));
 		set_fs(old_fs);
 
 		putname(kfilename);
diff -Nru a/arch/sparc64/kernel/systbls.S b/arch/sparc64/kernel/systbls.S
--- a/arch/sparc64/kernel/systbls.S	Mon Dec 23 21:21:53 2002
+++ b/arch/sparc64/kernel/systbls.S	Mon Dec 23 21:21:53 2002
@@ -26,12 +26,12 @@
 /*20*/	.word sys_getpid, sys_capget, sys_capset, sys32_setuid16, sys32_getuid16
 /*25*/	.word sys_time, sys_ptrace, sys_alarm, sys32_sigaltstack, sys32_pause
 /*30*/	.word compat_sys_utime, sys_lchown, sys_fchown, sys_access, sys_nice
-	.word sys_chown, sys_sync, sys_kill, sys32_newstat, sys32_sendfile
-/*40*/	.word sys32_newlstat, sys_dup, sys_pipe, sys32_times, sys_getuid
+	.word sys_chown, sys_sync, sys_kill, compat_sys_newstat, sys32_sendfile
+/*40*/	.word compat_sys_newlstat, sys_dup, sys_pipe, compat_sys_times, sys_getuid
 	.word sys_umount, sys32_setgid16, sys32_getgid16, sys_signal, sys32_geteuid16
 /*50*/	.word sys32_getegid16, sys_acct, sys_nis_syscall, sys_getgid, sys32_ioctl
 	.word sys_reboot, sys32_mmap2, sys_symlink, sys_readlink, sys32_execve
-/*60*/	.word sys_umask, sys_chroot, sys32_newfstat, sys_fstat64, sys_getpagesize
+/*60*/	.word sys_umask, sys_chroot, compat_sys_newfstat, sys_fstat64, sys_getpagesize
 	.word sys_msync, sys_vfork, sys32_pread64, sys32_pwrite64, sys_geteuid
 /*70*/	.word sys_getegid, sys32_mmap, sys_setreuid, sys_munmap, sys_mprotect
 	.word sys_madvise, sys_vhangup, sys32_truncate64, sys_mincore, sys32_getgroups16
@@ -59,7 +59,7 @@
 	.word sys_setpgid, sys_fremovexattr, sys_tkill, sys_exit_group, sparc64_newuname
 /*190*/	.word sys32_init_module, sparc64_personality, sys_remap_file_pages, sys_epoll_create, sys_epoll_ctl
 	.word sys_epoll_wait, sys_nis_syscall, sys_getppid, sys32_sigaction, sys_sgetmask
-/*200*/	.word sys_ssetmask, sys_sigsuspend, sys32_newlstat, sys_uselib, old32_readdir
+/*200*/	.word sys_ssetmask, sys_sigsuspend, compat_sys_newlstat, sys_uselib, old32_readdir
 	.word sys32_readahead, sys32_socketcall, sys_syslog, sys32_lookup_dcookie, sys_nis_syscall
 /*210*/	.word sys_nis_syscall, sys_nis_syscall, sys_waitpid, sys_swapoff, sys32_sysinfo
 	.word sys32_ipc, sys32_sigreturn, sys_clone, sys_nis_syscall, sys32_adjtimex
@@ -150,8 +150,8 @@
 	.word sunos_nosys, sunos_nosys, sunos_nosys
 	.word sunos_nosys, sunos_nosys, sunos_nosys
 	.word sys_access, sunos_nosys, sunos_nosys
-	.word sys_sync, sys_kill, sys32_newstat
-	.word sunos_nosys, sys32_newlstat, sys_dup
+	.word sys_sync, sys_kill, compat_sys_newstat
+	.word sunos_nosys, compat_sys_newlstat, sys_dup
 	.word sys_pipe, sunos_nosys, sunos_nosys
 	.word sunos_nosys, sunos_nosys, sunos_getgid
 	.word sunos_nosys, sunos_nosys
@@ -159,7 +159,7 @@
 	.word sunos_mctl, sunos_ioctl, sys_reboot
 	.word sunos_nosys, sys_symlink, sys_readlink
 	.word sys32_execve, sys_umask, sys_chroot
-	.word sys32_newfstat, sunos_nosys, sys_getpagesize
+	.word compat_sys_newfstat, sunos_nosys, sys_getpagesize
 	.word sys_msync, sys_vfork, sunos_nosys
 	.word sunos_nosys, sunos_sbrk, sunos_sstk
 	.word sunos_mmap, sunos_vadvise, sys_munmap
diff -Nru a/arch/v850/anna-rom.ld b/arch/v850/anna-rom.ld
--- a/arch/v850/anna-rom.ld	Mon Dec 23 21:21:52 2002
+++ b/arch/v850/anna-rom.ld	Mon Dec 23 21:21:52 2002
@@ -1,132 +1,16 @@
 /* Linker script for the Midas labs Anna V850E2 evaluation board
    (CONFIG_V850E2_ANNA), with kernel in ROM (CONFIG_ROM_KERNEL).  */
 
-/* Note, all symbols are prefixed with an extra `_' for compatibility with
-   the existing linux sources.  */
-
-_jiffies = _jiffies_64 ;
-
 MEMORY {
-       /* 8MB of flash ROM.  */
-       ROM   : ORIGIN = 0,          LENGTH = 0x00800000
+	/* 8MB of flash ROM.  */
+	ROM   : ORIGIN = 0,          LENGTH = 0x00800000
 
-       /* 1MB of static RAM.  This memory is mirrored 64 times.  */
-       SRAM  : ORIGIN = 0x04000000, LENGTH = 0x00100000
-       /* 64MB of DRAM.  */
-       SDRAM : ORIGIN = 0x08000000, LENGTH = 0x04000000
+	/* 1MB of static RAM.  This memory is mirrored 64 times.  */
+	SRAM  : ORIGIN = 0x04000000, LENGTH = 0x00100000
+	/* 64MB of DRAM.  */
+	SDRAM : ORIGIN = 0x08000000, LENGTH = 0x04000000
 }
 
 SECTIONS {
-	.intv : {
-		__intv_start = . ;
-			*(.intv.reset)	/* Reset vector */
-			*(.intv.common)	/* Vectors common to all v850e proc. */
-			*(.intv.mach)	/* Machine-specific int. vectors.  */
-		__intv_end = . ;
-	} > ROM
-
-	.text ALIGN (0x10) : {
-		__stext = . ;
-        	*(.text)
-			*(.exit.text)	/* 2.5 convention */
-			*(.text.exit)	/* 2.4 convention */
-			*(.text.lock)
-			*(.exitcall.exit)
-		__real_etext = . ;	/* There may be data after here.  */
-			*(.rodata)
-
-		. = ALIGN (0x4) ;
-			*(.kstrtab)
-
-		. = ALIGN (4) ;
-		    	*(.call_table_data)
-			*(.call_table_text)
-
-		. = ALIGN (16) ;	/* Exception table.  */
-		___start___ex_table = . ;
-			*(__ex_table)
-		___stop___ex_table = . ;
-
-		___start___ksymtab = . ;/* Kernel symbol table.  */
-			*(__ksymtab)
-		___stop___ksymtab = . ;
-		. = ALIGN (4) ;
-		__etext = . ;
-	} > ROM
-
-	.init_text ALIGN (4096) : {
-			*(.init.text)	/* 2.5 convention */
-			*(.text.init)	/* 2.4 convention */
-		. = ALIGN (16) ;
-		___setup_start = . ;
-			*(.init.setup)	/* 2.5 convention */
-			*(.setup.init)	/* 2.4 convention */
-		___setup_end = . ;
-		___initcall_start = . ;
-			*(.initcall.init)
-			*(.initcall1.init)
-			*(.initcall2.init)
-			*(.initcall3.init)
-			*(.initcall4.init)
-			*(.initcall5.init)
-			*(.initcall6.init)
-			*(.initcall7.init)
-		. = ALIGN (4) ;
-		___initcall_end = . ;
-	} > ROM
-
-	/* Device contents for the root filesystem.  */
-	.root ALIGN (4096) : {
-		__root_fs_image_start = . ;
-		*(.root)
-		__root_fs_image_end = . ;
-
-		. = ALIGN (4) ;
-		___initramfs_start = . ;
-			*(.init.ramfs)
-		___initramfs_end = . ;
-	} > ROM
-
-	__rom_copy_src_start = . ;
-
-	.data : {
-		__kram_start = . ;
-		__rom_copy_dst_start = . ;
-
-		__sdata = . ;
-		___data_start = . ;
-        	*(.data)
-			*(.exit.data)	/* 2.5 convention */
-			*(.data.exit)	/* 2.4 convention */
-		. = ALIGN (16) ;
-		*(.data.cacheline_aligned)
-		. = ALIGN (0x2000) ;
-        	*(.data.init_task)
-		. = ALIGN (0x2000) ;
-		__edata = . ;
-	} > SRAM  AT> ROM
-
-	.init_data ALIGN (4096) : {
-		__init_start = . ;
-			*(.init.data)	/* 2.5 convention */
-			*(.data.init)	/* 2.4 convention */
-		__init_end = . ;
-		__rom_copy_dst_end = . ;
-	} > SRAM  AT> ROM
-
-	.bss ALIGN (4096) : {
-		__sbss = . ;
-			*(.bss)
-			*(COMMON)
-		. = ALIGN (4) ;
-		__init_stack_end = . ;
-		__ebss = . ;
-
-		__kram_end = . ;
-	} > SRAM
-
-	.bootmap ALIGN (4096) : {
-		__bootmap = . ;
-		. = . + 4096 ;		/* enough for 128MB.   */
-	} > SRAM
+	ROMK_SECTIONS(ROM, SRAM)
 }
diff -Nru a/arch/v850/anna.ld b/arch/v850/anna.ld
--- a/arch/v850/anna.ld	Mon Dec 23 21:21:53 2002
+++ b/arch/v850/anna.ld	Mon Dec 23 21:21:53 2002
@@ -1,128 +1,20 @@
 /* Linker script for the Midas labs Anna V850E2 evaluation board
    (CONFIG_V850E2_ANNA).  */
 
-/* Note, all symbols are prefixed with an extra `_' for compatibility with
-   the existing linux sources.  */
-
-_jiffies = _jiffies_64 ;
-
 MEMORY {
-       /* 256KB of internal memory (followed by one mirror).  */
-       iMEM0 : ORIGIN = 0,	    LENGTH = 0x00040000
-       /* 256KB of internal memory (followed by one mirror).  */
-       iMEM1 : ORIGIN = 0x00040000, LENGTH = 0x00040000
-
-       /* 1MB of static RAM.  This memory is mirrored 64 times.  */
-       SRAM  : ORIGIN = 0x04000000, LENGTH = 0x00100000
-       /* 64MB of DRAM.  */
-       SDRAM : ORIGIN = 0x08000000, LENGTH = 0x04000000
+	/* 256KB of internal memory (followed by one mirror).  */
+	iMEM0 : ORIGIN = 0,	    LENGTH = 0x00040000
+	/* 256KB of internal memory (followed by one mirror).  */
+	iMEM1 : ORIGIN = 0x00040000, LENGTH = 0x00040000
+
+	/* 1MB of static RAM.  This memory is mirrored 64 times.  */
+	SRAM  : ORIGIN = 0x04000000, LENGTH = 0x00100000
+	/* 64MB of DRAM.  */
+	SDRAM : ORIGIN = 0x08000000, LENGTH = 0x04000000
 }
 
 SECTIONS {
-	.intv : {
-		__intv_start = . ;
-			*(.intv.reset)	/* Reset vector */
-			*(.intv.common)	/* Vectors common to all v850e proc. */
-			*(.intv.mach)	/* Machine-specific int. vectors.  */
-		__intv_end = . ;
-	} > iMEM0
-
-	.text : {
-		 __kram_start = . ;
-
-		__stext = . ;
-        	*(.text)
-			*(.exit.text)	/* 2.5 convention */
-			*(.text.exit)	/* 2.4 convention */
-			*(.text.lock)
-			*(.exitcall.exit)
-		__real_etext = . ;	/* There may be data after here.  */
-			*(.rodata)
-
-		. = ALIGN (0x4) ;
-			*(.kstrtab)
-
-		. = ALIGN (4) ;
-		    	*(.call_table_data)
-			*(.call_table_text)
-
-		. = ALIGN (16) ;	/* Exception table.  */
-		___start___ex_table = . ;
-			*(__ex_table)
-		___stop___ex_table = . ;
-
-		___start___ksymtab = . ;/* Kernel symbol table.  */
-			*(__ksymtab)
-		___stop___ksymtab = . ;
-		. = ALIGN (4) ;
-		__etext = . ;
-	} > SRAM
-
-	.data ALIGN (0x4) : {
-		__sdata = . ;
-		___data_start = . ;
-        	*(.data)
-			*(.exit.data)	/* 2.5 convention */
-			*(.data.exit)	/* 2.4 convention */
-		. = ALIGN (16) ;
-		*(.data.cacheline_aligned)
-		. = ALIGN (0x2000) ;
-        	*(.data.init_task)
-		. = ALIGN (0x2000) ;
-		__edata = . ;
-	} > SRAM
-
-	.bss ALIGN (0x4) : {
-		__sbss = . ;
-			*(.bss)
-			*(COMMON)
-		. = ALIGN (4) ;
-		__init_stack_end = . ;
-		__ebss = . ;
-	} > SRAM
-
-	.init ALIGN (4096) : {
-		__init_start = . ;
-			*(.init.text)	/* 2.5 convention */
-			*(.init.data)
-			*(.text.init)	/* 2.4 convention */
-			*(.data.init)
-		. = ALIGN (16) ;
-		___setup_start = . ;
-			*(.init.setup)	/* 2.5 convention */
-			*(.setup.init)	/* 2.4 convention */
-		___setup_end = . ;
-		___initcall_start = . ;
-			*(.initcall.init)
-			*(.initcall1.init)
-			*(.initcall2.init)
-			*(.initcall3.init)
-			*(.initcall4.init)
-			*(.initcall5.init)
-			*(.initcall6.init)
-			*(.initcall7.init)
-		. = ALIGN (4) ;
-		___initcall_end = . ;
-
-		. = ALIGN (4) ;
-		___initramfs_start = . ;
-			*(.init.ramfs)
-		___initramfs_end = . ;
-
-		__init_end = . ;
-
-		__kram_end = . ;
-	} > SRAM
-
-	.bootmap ALIGN (4096) : {
-		__bootmap = . ;
-		. = . + 4096 ;		/* enough for 128MB.   */
-	} > SRAM
-
-	/* Device contents for the root filesystem.  */
-	.root : {
-		__root_fs_image_start = . ;
-		*(.root)
-		__root_fs_image_end = . ;
-	} > SDRAM
+	.intv : { INTV_CONTENTS } > iMEM0
+	.sram : { RAMK_KRAM_CONTENTS } > SRAM
+	.root : { ROOT_FS_CONTENTS } > SDRAM
 }
diff -Nru a/arch/v850/as85ep1-rom.ld b/arch/v850/as85ep1-rom.ld
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/arch/v850/as85ep1-rom.ld	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,24 @@
+/* Linker script for the NEC AS85EP1 V850E evaluation board
+   (CONFIG_V850E_AS85EP1), with kernel in ROM (CONFIG_ROM_KERNEL).  */
+
+/* Note, all symbols are prefixed with an extra `_' for compatibility with
+   the existing linux sources.  */
+
+MEMORY {
+	/* 4MB of flash ROM.  */
+	ROM   : ORIGIN = 0,          LENGTH = 0x00400000
+
+	/* 1MB of static RAM.  */
+	SRAM  : ORIGIN = 0x00400000, LENGTH = 0x00100000
+
+	/* About 58MB of DRAM.  This can actually be at one of two
+	   positions, determined by jump JP3; we have to use the first
+	   position because the second is partially out of processor
+	   instruction addressing range (though in the second position
+	   there's actually 64MB available).  */
+	SDRAM : ORIGIN = 0x00600000, LENGTH = 0x039F8000
+}
+
+SECTIONS {
+	ROMK_SECTIONS(ROM, SRAM)
+}
diff -Nru a/arch/v850/as85ep1.ld b/arch/v850/as85ep1.ld
--- a/arch/v850/as85ep1.ld	Mon Dec 23 21:21:58 2002
+++ b/arch/v850/as85ep1.ld	Mon Dec 23 21:21:58 2002
@@ -1,23 +1,19 @@
 /* Linker script for the NEC AS85EP1 V850E evaluation board
    (CONFIG_V850E_AS85EP1).  */
 
-/* Note, all symbols are prefixed with an extra `_' for compatibility with
-   the existing linux sources.  */
-
-_jiffies = _jiffies_64 ;
-
 MEMORY {
-       /* 1MB of internal memory ($BFbB"L?Na(BRAM).  */
-       iMEM0 : ORIGIN = 0,	    LENGTH = 0x00100000
+	/* 1MB of internal memory ($BFbB"L?Na(BRAM).  */
+	iMEM0 : ORIGIN = 0,	    LENGTH = 0x00100000
 
-       /* 1MB of static RAM.  */
-       SRAM  : ORIGIN = 0x00400000, LENGTH = 0x00100000
+	/* 1MB of static RAM.  */
+	SRAM  : ORIGIN = 0x00400000, LENGTH = 0x00100000
 
-       /* About 58MB of DRAM.  This can actually be at one of two positions,
-	  determined by jump JP3; we have to use the first position because the
-	  second is partially out of processor instruction addressing range
-	  (though in the second position there's actually 64MB available).  */
-       SDRAM : ORIGIN = 0x00600000, LENGTH = 0x039F8000
+	/* About 58MB of DRAM.  This can actually be at one of two
+	   positions, determined by jump JP3; we have to use the first
+	   position because the second is partially out of processor
+	   instruction addressing range (though in the second position
+	   there's actually 64MB available).  */
+	SDRAM : ORIGIN = 0x00600000, LENGTH = 0x039F8000
 }
 
 SECTIONS {
@@ -26,87 +22,8 @@
 			*(.intv.reset)	/* Reset vector */
 	} > iMEM0
 
-	.text : {
-		 __kram_start = . ;
-
-		__stext = . ;
-        	*(.text)
-			*(.exit.text)	/* 2.5 convention */
-			*(.text.exit)	/* 2.4 convention */
-			*(.text.lock)
-			*(.exitcall.exit)
-		__real_etext = . ;	/* There may be data after here.  */
-			*(.rodata)
-
-		. = ALIGN (0x4) ;
-			*(.kstrtab)
-
-		. = ALIGN (4) ;
-		    	*(.call_table_data)
-			*(.call_table_text)
-
-		. = ALIGN (16) ;	/* Exception table.  */
-		___start___ex_table = . ;
-			*(__ex_table)
-		___stop___ex_table = . ;
-
-		___start___ksymtab = . ;/* Kernel symbol table.  */
-			*(__ksymtab)
-		___stop___ksymtab = . ;
-		. = ALIGN (4) ;
-		__etext = . ;
-	} > SRAM
-
-	.data ALIGN (0x4) : {
-		__sdata = . ;
-		___data_start = . ;
-        	*(.data)
-			*(.exit.data)	/* 2.5 convention */
-			*(.data.exit)	/* 2.4 convention */
-		. = ALIGN (16) ;
-		*(.data.cacheline_aligned)
-		. = ALIGN (0x2000) ;
-        	*(.data.init_task)
-		. = ALIGN (0x2000) ;
-		__edata = . ;
-	} > SRAM
-
-	.bss ALIGN (0x4) : {
-		__sbss = . ;
-			*(.bss)
-			*(COMMON)
-		. = ALIGN (4) ;
-		__init_stack_end = . ;
-		__ebss = . ;
-	} > SRAM
-
-	.init ALIGN (4096) : {
-		__init_start = . ;
-			*(.init.text)	/* 2.5 convention */
-			*(.init.data)
-			*(.text.init)	/* 2.4 convention */
-			*(.data.init)
-		. = ALIGN (16) ;
-		___setup_start = . ;
-			*(.init.setup)	/* 2.5 convention */
-			*(.setup.init)	/* 2.4 convention */
-		___setup_end = . ;
-		___initcall_start = . ;
-			*(.initcall.init)
-			*(.initcall1.init)
-			*(.initcall2.init)
-			*(.initcall3.init)
-			*(.initcall4.init)
-			*(.initcall5.init)
-			*(.initcall6.init)
-			*(.initcall7.init)
-		. = ALIGN (4) ;
-		___initcall_end = . ;
-
-		. = ALIGN (4) ;
-		___initramfs_start = . ;
-			*(.init.ramfs)
-		___initramfs_end = . ;
+	.sram : {
+		RAMK_KRAM_CONTENTS
 
 		/* We stick most of the interrupt vectors here; they'll be
 		   copied into the proper location by the early init code (we
@@ -121,27 +38,12 @@
 			*(.intv.mach)	/* Machine-specific int. vectors.  */
 		. = ALIGN (0x10) ;
 		__intv_copy_src_end = . ;
-
-		/* This is here so that when we free init memory, the initial
-		   load-area of the interrupt vectors is freed too.  */
-		__init_end = . ;
-		__kram_end = . ;
-		   
-		__bootmap = . ;
-		. = . + 4096 ;		/* enough for 128MB.   */
 	} > SRAM
 
 	/* Where we end up putting the vectors.  */
 	__intv_copy_dst_start = 0x10 ;
 	__intv_copy_dst_end = __intv_copy_dst_start + (__intv_copy_src_end - __intv_copy_src_start) ;
-
 	__intv_end = __intv_copy_dst_end ;
 
-	/* Device contents for the root filesystem.  */
-	.root : {
-		. = ALIGN (4096) ;
-		__root_fs_image_start = . ;
-		*(.root)
-		__root_fs_image_end = . ;
-	} > SDRAM
+	.root : { ROOT_FS_CONTENTS } > SDRAM
 }
diff -Nru a/arch/v850/fpga85e2c.ld b/arch/v850/fpga85e2c.ld
--- a/arch/v850/fpga85e2c.ld	Mon Dec 23 21:21:51 2002
+++ b/arch/v850/fpga85e2c.ld	Mon Dec 23 21:21:51 2002
@@ -1,108 +1,36 @@
 /* Linker script for the FPGA implementation of the V850E2 NA85E2C cpu core
    (CONFIG_V850E2_FPGA85E2C).  */
 
-/* Note, all symbols are prefixed with an extra `_' for compatibility with
-   the existing linux sources.  */
-
-_jiffies = _jiffies_64 ;
-
 MEMORY {
-       /* Reset vector.  */
-       RESET	 : ORIGIN = 0, LENGTH = 0x10
-       /* Interrupt vectors.  */
-       INTV      : ORIGIN = 0x10, LENGTH = 0x470
-       /* The `window' in RAM were we're allowed to load stuff.  */
-       RAM_LOW   : ORIGIN = 0x480, LENGTH = 0x0005FB80
-       /* Some more ram above the window were we can put bss &c.  */
-       RAM_HIGH  : ORIGIN = 0x00060000, LENGTH = 0x000A0000
-       /* This is the area visible from the outside world (we can use
-	  this only for uninitialized data).  */
-       VISIBLE   : ORIGIN = 0x00200000, LENGTH = 0x00060000
+	/* Reset vector.  */
+	RESET	 : ORIGIN = 0, LENGTH = 0x10
+	/* Interrupt vectors.  */
+	INTV      : ORIGIN = 0x10, LENGTH = 0x470
+	/* The `window' in RAM were we're allowed to load stuff.  */
+	RAM_LOW   : ORIGIN = 0x480, LENGTH = 0x0005FB80
+	/* Some more ram above the window were we can put bss &c.  */
+	RAM_HIGH  : ORIGIN = 0x00060000, LENGTH = 0x000A0000
+	/* This is the area visible from the outside world (we can use
+	   this only for uninitialized data).  */
+	VISIBLE   : ORIGIN = 0x00200000, LENGTH = 0x00060000
 }
 
 SECTIONS {
 	.reset : {
-	        __kram_start = . ;
+		__kram_start = . ;
 		__intv_start = . ;
 	        	*(.intv.reset)	/* Reset vector */
 	} > RESET
 
-	.r0_ram : {
-		__r0_ram = . ;
+	.ram_low : {
+		__r0_ram = . ;		/* Must be near address 0.  */
 		. = . + 32 ;
-	} > RAM_LOW
-
-	.text : {
-		__stext = . ;
-        	*(.text)
-			*(.exit.text)	/* 2.5 convention */
-			*(.text.exit)	/* 2.4 convention */
-			*(.text.lock)
-			*(.exitcall.exit)
-		__real_etext = . ;	/* There may be data after here.  */
-			*(.rodata)
-		. = ALIGN (0x4) ;
-			*(.kstrtab)
-
-		. = ALIGN (4) ;
-		    	*(.call_table_data)
-			*(.call_table_text)
-
-		. = ALIGN (16) ;	/* Exception table.  */
-		___start___ex_table = . ;
-			*(__ex_table)
-		___stop___ex_table = . ;
-
-		___start___ksymtab = . ;/* Kernel symbol table.  */
-			*(__ksymtab)
-		___stop___ksymtab = . ;
-		. = ALIGN (4) ;
-		__etext = . ;
-	} > RAM_LOW
-
-	.data : {
-		__sdata = . ;
-        	*(.data)
-			*(.exit.data)	/* 2.5 convention */
-			*(.data.exit)	/* 2.4 convention */
-		. = ALIGN (16) ;
-		*(.data.cacheline_aligned)
-		. = ALIGN (0x2000) ;
-        	*(.data.init_task)
-		. = ALIGN (0x2000) ;
-		__edata = . ;
-	} > RAM_LOW
-
-	/* Device contents for the root filesystem.  */
-	.root : {
-		. =  ALIGN (4096) ;
-		__root_fs_image_start = . ;
-		*(.root)
-		__root_fs_image_end = . ;
-	} > RAM_LOW
 
-	.init ALIGN (4096) : {
-		__init_start = . ;
-			*(.init.text)	/* 2.5 convention */
-			*(.init.data)
-			*(.text.init)	/* 2.4 convention */
-			*(.data.init)
-		. = ALIGN (16) ;
-		___setup_start = . ;
-			*(.init.setup)	/* 2.5 convention */
-			*(.setup.init)	/* 2.4 convention */
-		___setup_end = . ;
-		___initcall_start = . ;
-			*(.initcall.init)
-			*(.initcall1.init)
-			*(.initcall2.init)
-			*(.initcall3.init)
-			*(.initcall4.init)
-			*(.initcall5.init)
-			*(.initcall6.init)
-			*(.initcall7.init)
-		. = ALIGN (4) ;
-		___initcall_end = . ;
+		TEXT_CONTENTS
+		DATA_CONTENTS
+		ROOT_FS_CONTENTS
+		RAMK_INIT_CONTENTS_NO_END
+		INITRAMFS_CONTENTS
 	} > RAM_LOW
 
         /* Where the interrupt vectors are initially loaded.  */
@@ -114,26 +42,16 @@
 		__intv_end = . ;
 	} > INTV  AT> RAM_LOW
 
-	.bss : {
+	.ram_high : {
 		/* This is here so that when we free init memory the
 		   load-time copy of the interrupt vectors and any empty
 		   space at the end of the `RAM_LOW' area is freed too.  */
 		. = ALIGN (4096);
 		__init_end = . ;
 
-		__sbss = . ;
-			*(.bss)
-			*(COMMON)
-		. = ALIGN (4) ;
-		__init_stack_end = . ;
-		__ebss = . ;
-
-	        __kram_end = . ;
-	} > RAM_HIGH
-
-	.bootmap ALIGN (4096) : {
-		__bootmap = . ;
-		. = . + 4096 ;		/* enough for 128MB.   */
+		BSS_CONTENTS
+		__kram_end = . ;
+		BOOTMAP_CONTENTS
 	} > RAM_HIGH
 
 	.visible : {
diff -Nru a/arch/v850/kernel/entry.S b/arch/v850/kernel/entry.S
--- a/arch/v850/kernel/entry.S	Mon Dec 23 21:22:00 2002
+++ b/arch/v850/kernel/entry.S	Mon Dec 23 21:22:00 2002
@@ -781,7 +781,7 @@
 	
 	.align 4
 C_DATA(sys_call_table):
-	.long CSYM(sys_ni_syscall)	// 0  -  old "setup()" system call
+	.long CSYM(sys_restart_syscall)	// 0
 	.long CSYM(sys_exit)
 	.long sys_fork_wrapper
 	.long CSYM(sys_read)
diff -Nru a/arch/v850/kernel/irq.c b/arch/v850/kernel/irq.c
--- a/arch/v850/kernel/irq.c	Mon Dec 23 21:21:59 2002
+++ b/arch/v850/kernel/irq.c	Mon Dec 23 21:21:59 2002
@@ -21,7 +21,6 @@
 #include <linux/slab.h>
 #include <linux/mm.h>
 #include <linux/random.h>
-#include <linux/sched.h>
 #include <linux/seq_file.h>
 
 #include <asm/system.h>
diff -Nru a/arch/v850/kernel/semaphore.c b/arch/v850/kernel/semaphore.c
--- a/arch/v850/kernel/semaphore.c	Mon Dec 23 21:21:59 2002
+++ b/arch/v850/kernel/semaphore.c	Mon Dec 23 21:21:59 2002
@@ -13,6 +13,7 @@
  * which was derived from the i386 version, linux/arch/i386/kernel/semaphore.c
  */
 
+#include <linux/errno.h>
 #include <linux/sched.h>
 
 #include <asm/semaphore.h>
diff -Nru a/arch/v850/kernel/setup.c b/arch/v850/kernel/setup.c
--- a/arch/v850/kernel/setup.c	Mon Dec 23 21:21:53 2002
+++ b/arch/v850/kernel/setup.c	Mon Dec 23 21:21:53 2002
@@ -11,7 +11,6 @@
  * Written by Miles Bader <miles@gnu.org>
  */
 
-#include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/bootmem.h>
 #include <linux/irq.h>
diff -Nru a/arch/v850/kernel/signal.c b/arch/v850/kernel/signal.c
--- a/arch/v850/kernel/signal.c	Mon Dec 23 21:22:02 2002
+++ b/arch/v850/kernel/signal.c	Mon Dec 23 21:22:02 2002
@@ -15,7 +15,6 @@
  * This file was derived from the sh version, arch/sh/kernel/signal.c
  */
 
-#include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/smp.h>
 #include <linux/smp_lock.h>
@@ -147,8 +146,6 @@
 
 struct rt_sigframe
 {
-	struct siginfo *pinfo;
-	void *puc;
 	struct siginfo info;
 	struct ucontext uc;
 	unsigned long tramp[2];	/* signal trampoline */
@@ -330,10 +327,12 @@
 	if (err)
 		goto give_sigsegv;
 
-	/* Set up registers for signal handler */
-	regs->gpr[GPR_SP] = (unsigned long) frame;
-	regs->gpr[GPR_ARG0] = signal; /* Arg for signal handler */
-	regs->pc = (unsigned long) ka->sa.sa_handler;
+	/* Set up registers for signal handler.  */
+	regs->pc = (v850_reg_t) ka->sa.sa_handler;
+	regs->gpr[GPR_SP] = (v850_reg_t)frame;
+	/* Signal handler args:  */
+	regs->gpr[GPR_ARG0] = signal; /* arg 0: signum */
+	regs->gpr[GPR_ARG1] = (v850_reg_t)&frame->sc;/* arg 1: sigcontext */
 
 	set_fs(USER_DS);
 
@@ -368,8 +367,6 @@
 		? current_thread_info()->exec_domain->signal_invmap[sig]
 		: sig;
 
-	err |= __put_user(&frame->info, &frame->pinfo);
-	err |= __put_user(&frame->uc, &frame->puc);
 	err |= copy_siginfo_to_user(&frame->info, info);
 
 	/* Create the ucontext.  */
@@ -406,10 +403,13 @@
 	if (err)
 		goto give_sigsegv;
 
-	/* Set up registers for signal handler */
-	regs->gpr[GPR_SP] = (unsigned long) frame;
-	regs->gpr[GPR_ARG0] = signal; /* Arg for signal handler */
-	regs->pc = (unsigned long) ka->sa.sa_handler;
+	/* Set up registers for signal handler.  */
+	regs->pc = (v850_reg_t) ka->sa.sa_handler;
+	regs->gpr[GPR_SP] = (v850_reg_t)frame;
+	/* Signal handler args:  */
+	regs->gpr[GPR_ARG0] = signal; /* arg 0: signum */
+	regs->gpr[GPR_ARG1] = (v850_reg_t)&frame->info; /* arg 1: siginfo */
+	regs->gpr[GPR_ARG2] = (v850_reg_t)&frame->uc; /* arg 2: ucontext */
 
 	set_fs(USER_DS);
 
@@ -440,19 +440,23 @@
 	if (PT_REGS_SYSCALL (regs)) {
 		/* If so, check system call restarting.. */
 		switch (regs->gpr[GPR_RVAL]) {
-			case -ERESTARTNOHAND:
+		case -ERESTART_RESTARTBLOCK:
+			current_thread_info()->restart_block.fn =
+				do_no_restart_syscall;
+			/* fall through */
+		case -ERESTARTNOHAND:
+			regs->gpr[GPR_RVAL] = -EINTR;
+			break;
+
+		case -ERESTARTSYS:
+			if (!(ka->sa.sa_flags & SA_RESTART)) {
 				regs->gpr[GPR_RVAL] = -EINTR;
 				break;
-
-			case -ERESTARTSYS:
-				if (!(ka->sa.sa_flags & SA_RESTART)) {
-					regs->gpr[GPR_RVAL] = -EINTR;
-					break;
-				}
+			}
 			/* fallthrough */
-			case -ERESTARTNOINTR:
-				regs->gpr[12] = PT_REGS_SYSCALL (regs);
-				regs->pc -= 4; /* Size of `trap 0' insn.  */
+		case -ERESTARTNOINTR:
+			regs->gpr[12] = PT_REGS_SYSCALL (regs);
+			regs->pc -= 4; /* Size of `trap 0' insn.  */
 		}
 
 		PT_REGS_SET_SYSCALL (regs, 0);
@@ -511,12 +515,17 @@
 
 	/* Did we come from a system call? */
 	if (PT_REGS_SYSCALL (regs)) {
+		int rval = (int)regs->gpr[GPR_RVAL];
 		/* Restart the system call - no handlers present */
-		if (regs->gpr[GPR_RVAL] == (v850_reg_t)-ERESTARTNOHAND ||
-		    regs->gpr[GPR_RVAL] == (v850_reg_t)-ERESTARTSYS ||
-		    regs->gpr[GPR_RVAL] == (v850_reg_t)-ERESTARTNOINTR)
+		if (rval == -ERESTARTNOHAND
+		    || rval == -ERESTARTSYS
+		    || rval == -ERESTARTNOINTR)
 		{
 			regs->gpr[12] = PT_REGS_SYSCALL (regs);
+			regs->pc -= 4; /* Size of `trap 0' insn.  */
+		}
+		else if (rval == -ERESTART_RESTARTBLOCK) {
+			regs->gpr[12] = __NR_restart_syscall;
 			regs->pc -= 4; /* Size of `trap 0' insn.  */
 		}
 	}
diff -Nru a/arch/v850/kernel/syscalls.c b/arch/v850/kernel/syscalls.c
--- a/arch/v850/kernel/syscalls.c	Mon Dec 23 21:21:57 2002
+++ b/arch/v850/kernel/syscalls.c	Mon Dec 23 21:21:57 2002
@@ -17,7 +17,6 @@
 
 #include <linux/config.h>
 #include <linux/errno.h>
-#include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/smp.h>
 #include <linux/smp_lock.h>
diff -Nru a/arch/v850/kernel/time.c b/arch/v850/kernel/time.c
--- a/arch/v850/kernel/time.c	Mon Dec 23 21:21:57 2002
+++ b/arch/v850/kernel/time.c	Mon Dec 23 21:21:57 2002
@@ -12,7 +12,6 @@
 
 #include <linux/config.h> /* CONFIG_HEARTBEAT */
 #include <linux/errno.h>
-#include <linux/sched.h>
 #include <linux/kernel.h>
 #include <linux/param.h>
 #include <linux/string.h>
diff -Nru a/arch/v850/rte_ma1_cb-ksram.ld b/arch/v850/rte_ma1_cb-ksram.ld
--- a/arch/v850/rte_ma1_cb-ksram.ld	Mon Dec 23 21:22:02 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,157 +0,0 @@
-/* Linker script for the Midas labs RTE-V850E/MA1-CB evaluation board
-   (CONFIG_RTE_CB_MA1), with kernel in SRAM, under Multi debugger.  */
-
-/* Note, all symbols are prefixed with an extra `_' for compatibility with
-   the existing linux sources.  */
-
-_jiffies = _jiffies_64 ;
-
-MEMORY {
-       /* 1MB of SRAM; we can't use the last 32KB, because it's used by
-          the monitor scratch-RAM.  This memory is mirrored 4 times.  */
-       SRAM  : ORIGIN = 0x00400000, LENGTH = 0x000F8000
-       /* Monitor scratch RAM; only the interrupt vectors should go here.  */
-       MRAM  : ORIGIN = 0x004F8000, LENGTH = 0x00008000
-       /* 32MB of SDRAM.  */
-       SDRAM : ORIGIN = 0x00800000, LENGTH = 0x02000000
-}
-
-SECTIONS {
-	.text : {
-	        __kram_start = . ;
-
-		__stext = . ;
-        	*(.text)
-			*(.exit.text)	/* 2.5 convention */
-			*(.text.exit)	/* 2.4 convention */
-			*(.text.lock)
-			*(.exitcall.exit)
-		__real_etext = . ;	/* There may be data after here.  */
-			*(.rodata)
-
-		. = ALIGN (0x4) ;
-			*(.kstrtab)
-
-		. = ALIGN (4) ;
-		*(.call_table_data)
-		*(.call_table_text)
-
-		. = ALIGN (16) ;	/* Exception table.  */
-		___start___ex_table = . ;
-			*(__ex_table)
-		___stop___ex_table = . ;
-
-		___start___ksymtab = . ;/* Kernel symbol table.  */
-			*(__ksymtab)
-		___stop___ksymtab = . ;
-		. = ALIGN (4) ;
-		__etext = . ;
-	} > SRAM
-
-	.data ALIGN (0x4) : {
-		__sdata = . ;
-		___data_start = . ;
-        	*(.data)
-			*(.exit.data)	/* 2.5 convention */
-			*(.data.exit)	/* 2.4 convention */
-		. = ALIGN (16) ;
-		*(.data.cacheline_aligned)
-		. = ALIGN (0x2000) ;
-        	*(.data.init_task)
-		. = ALIGN (0x2000) ;
-		__edata = . ;
-	} > SRAM
-
-	.bss ALIGN (0x4) : {
-		__sbss = . ;
-			*(.bss)
-			*(COMMON)
-		. = ALIGN (4) ;
-		__init_stack_end = . ;
-		__ebss = . ;
-	} > SRAM
-
-	.init ALIGN (4096) : {
-		__init_start = . ;
-			*(.init.text)	/* 2.5 convention */
-			*(.init.data)
-			*(.text.init)	/* 2.4 convention */
-			*(.data.init)
-		. = ALIGN (16) ;
-		___setup_start = . ;
-			*(.init.setup)	/* 2.5 convention */
-			*(.setup.init)	/* 2.4 convention */
-		___setup_end = . ;
-		___initcall_start = . ;
-			*(.initcall.init)
-			*(.initcall1.init)
-			*(.initcall2.init)
-			*(.initcall3.init)
-			*(.initcall4.init)
-			*(.initcall5.init)
-			*(.initcall6.init)
-			*(.initcall7.init)
-		. = ALIGN (4) ;
-		___initcall_end = . ;
-
-		. = ALIGN (4) ;
-		___initramfs_start = . ;
-			*(.init.ramfs)
-		___initramfs_end = . ;
-	} > SRAM
-
-	/* This provides address at which the interrupt vectors are
-	   initially loaded by the loader.  */
-	__intv_load_start = ALIGN (0x10) ;
-
-	/* Interrupt vector space.  Because we're using the monitor
-	   ROM, Instead of the native interrupt vector, we must use the
-	   `alternate interrupt vector' area.  Note that this is in
-	   `SRAM' space, which is not currently used by the kernel (the
-	   kernel uses `SDRAM' space).  */
-
-	/* We can't load the interrupt vectors directly into their
-	   target location, because the monitor ROM for the GHS Multi
-	   debugger barfs if we try.  Unfortunately, Multi also doesn't
-	   deal correctly with ELF sections where the LMA and VMA differ
-	   (it just ignores the LMA), so we can't use that feature to
-	   work around the problem!  What we do instead is just put the
-	   interrupt vectors into a normal section, and have the
-	   `mach_early_init' function for Midas boards do the necessary
-	   copying and relocation at runtime (this section basically
-	   only contains `jr' instructions, so it's not that hard).
-
-	   This the section structure I initially tried to use (which more
-	   accurately expresses the intent):
-
-		.intv 0x007F8000 : AT (ADDR (.init) + SIZEOF (.init)) {
-		    ...
-		} > MRAM
-	*/
-
-	.intv ALIGN (0x10) : {
-		__intv_start = . ;
-	        	*(.intv.reset)	/* Reset vector */
-			*(.intv.common) /* Vectors common to all v850e proc. */
-			*(.intv.mach)   /* Machine-specific int. vectors.  */
-		__intv_end = . ;
-
-		/* This is here so that when we free init memory, the initial
-		   load-area of the interrupt vectors is freed too.  */
-		__init_end = __intv_end;
-
-		__kram_end = __init_end ;
-	} > SRAM
-
-	.bootmap ALIGN (4096) : {
-		__bootmap = . ;
-		. = . + 4096 ;		/* enough for 128MB.   */
-	} > SRAM
-
-	/* Device contents for the root filesystem.  */
-	.root : {
-		__root_fs_image_start = . ;
-		*(.root)
-		__root_fs_image_end = . ;
-	} > SDRAM
-}
diff -Nru a/arch/v850/rte_ma1_cb-rom.ld b/arch/v850/rte_ma1_cb-rom.ld
--- a/arch/v850/rte_ma1_cb-rom.ld	Mon Dec 23 21:21:57 2002
+++ b/arch/v850/rte_ma1_cb-rom.ld	Mon Dec 23 21:21:57 2002
@@ -1,120 +1,14 @@
 /* Linker script for the Midas labs RTE-V850E/MA1-CB evaluation board
    (CONFIG_RTE_CB_MA1), with kernel in ROM.  */
 
-/* Note, all symbols are prefixed with an extra `_' for compatibility with
-   the existing linux sources.  */
-
-_jiffies = _jiffies_64 ;
-
 MEMORY {
-       ROM   : ORIGIN = 0x00000000, LENGTH = 0x00100000
-       /* 1MB of SRAM.  This memory is mirrored 4 times.  */
-       SRAM  : ORIGIN = 0x00400000, LENGTH = 0x00100000
-       /* 32MB of SDRAM.  */
-       SDRAM : ORIGIN = 0x00800000, LENGTH = 0x02000000
+	ROM   : ORIGIN = 0x00000000, LENGTH = 0x00100000
+	/* 1MB of SRAM.  This memory is mirrored 4 times.  */
+	SRAM  : ORIGIN = 0x00400000, LENGTH = 0x00100000
+	/* 32MB of SDRAM.  */
+	SDRAM : ORIGIN = 0x00800000, LENGTH = 0x02000000
 }
 
 SECTIONS {
-	/* Interrupt vector space.  */
-	.intv {
-		__intv_start = . ;
-	        	*(.intv.reset)	/* Reset vector */
-			*(.intv.common) /* Vectors common to all v850e proc. */
-			*(.intv.mach)   /* Machine-specific int. vectors.  */
-		__intv_end = . ;
-	} > ROM
-
-	.text : {
-		__stext = . ;
-        	*(.text)
-			*(.exit.text)	/* 2.5 convention */
-			*(.text.exit)	/* 2.4 convention */
-			*(.text.lock)
-			*(.exitcall.exit)
-		__real_etext = . ;	/* There may be data after here.  */
-			*(.rodata)
-		. = ALIGN (0x4) ;
-			*(.kstrtab)
-		. = ALIGN (16) ;	/* Exception table.  */
-		___start___ex_table = . ;
-			*(__ex_table)
-		___stop___ex_table = . ;
-
-		___start___ksymtab = . ;/* Kernel symbol table.  */
-			*(__ksymtab)
-		___stop___ksymtab = . ;
-		. = ALIGN (4) ;
-		__etext = . ;
-
-		. = ALIGN (4) ;
-		___initramfs_start = . ;
-			*(.init.ramfs)
-		___initramfs_end = . ;
-	} > ROM
-
-	__rom_copy_src_start = . ;
-
-	.data : {
-	        __kram_start = . ;
-
-		__sdata = . ;
-		___data_start = . ;
-        	*(.data)
-			*(.exit.data)	/* 2.5 convention */
-			*(.data.exit)	/* 2.4 convention */
-		. = ALIGN (16) ;
-		*(.data.cacheline_aligned)
-		. = ALIGN (0x2000) ;
-        	*(.data.init_task)
-		. = ALIGN (0x2000) ;
-		__edata = . ;
-	} > SRAM  AT> ROM
-
-	.bss ALIGN (0x4) : {
-		__sbss = . ;
-			*(.bss)
-			*(COMMON)
-		. = ALIGN (4) ;
-		__init_stack_end = . ;
-		__ebss = . ;
-	} > SRAM
-
-	.init ALIGN (4096) : {
-		__init_start = . ;
-			*(.init.text)	/* 2.5 convention */
-			*(.init.data)
-			*(.text.init)	/* 2.4 convention */
-			*(.data.init)
-		. = ALIGN (16) ;
-		___setup_start = . ;
-			*(.init.setup)	/* 2.5 convention */
-			*(.setup.init)	/* 2.4 convention */
-		___setup_end = . ;
-		___initcall_start = . ;
-			*(.initcall.init)
-			*(.initcall1.init)
-			*(.initcall2.init)
-			*(.initcall3.init)
-			*(.initcall4.init)
-			*(.initcall5.init)
-			*(.initcall6.init)
-			*(.initcall7.init)
-		. = ALIGN (4) ;
-		___initcall_end = . ;
-		__init_end = . ;
-
-		__kram_end = . ;
-	} > SRAM
-
-	.bootmap ALIGN (4096) : {
-		__bootmap = . ;
-		. = . + 4096 ;		/* enough for 128MB.   */
-	} > SRAM
-
-	/* device contents for the root filesystem.  */
-	.root ALIGN (4096) {
-		__root_fs_image_start = . ;
-		*(.root)
-		__root_fs_image_end = . ;
-	} > SDRAM
+	ROMK_SECTIONS(ROM, SRAM)
 }
diff -Nru a/arch/v850/rte_ma1_cb.ld b/arch/v850/rte_ma1_cb.ld
--- a/arch/v850/rte_ma1_cb.ld	Mon Dec 23 21:21:50 2002
+++ b/arch/v850/rte_ma1_cb.ld	Mon Dec 23 21:21:50 2002
@@ -1,157 +1,57 @@
 /* Linker script for the Midas labs RTE-V850E/MA1-CB evaluation board
    (CONFIG_RTE_CB_MA1), with kernel in SDRAM, under Multi debugger.  */
 
-/* Note, all symbols are prefixed with an extra `_' for compatibility with
-   the existing linux sources.  */
-
-_jiffies = _jiffies_64 ;
-
 MEMORY {
-       /* 1MB of SRAM; we can't use the last 32KB, because it's used by
-          the monitor scratch-RAM.  This memory is mirrored 4 times.  */
-       SRAM  : ORIGIN = 0x00400000, LENGTH = 0x000F8000
-       /* Monitor scratch RAM; only the interrupt vectors should go here.  */
-       MRAM  : ORIGIN = 0x004F8000, LENGTH = 0x00008000
-       /* 32MB of SDRAM.  */
-       SDRAM : ORIGIN = 0x00800000, LENGTH = 0x02000000
+	/* 1MB of SRAM; we can't use the last 32KB, because it's used by
+	   the monitor scratch-RAM.  This memory is mirrored 4 times.  */
+	SRAM  : ORIGIN = 0x00400000, LENGTH = 0x000F8000
+	/* Monitor scratch RAM; only the interrupt vectors should go here.  */
+	MRAM  : ORIGIN = 0x004F8000, LENGTH = 0x00008000
+	/* 32MB of SDRAM.  */
+	SDRAM : ORIGIN = 0x00800000, LENGTH = 0x02000000
 }
 
+#ifdef CONFIG_RTE_CB_MA1_KSRAM
+# define KRAM SRAM
+#else
+# define KRAM SDRAM
+#endif
+
 SECTIONS {
-	.bootmap : {
-		__bootmap = . ;
-		. = . + 4096 ;		/* enough for 128MB.   */
-	} > SRAM
+	/* We can't use RAMK_KRAM_CONTENTS because that puts the whole
+	   kernel in a single ELF segment, and the Multi debugger (which
+	   we use to load the kernel) appears to have bizarre problems
+	   dealing with it.  */
 
 	.text : {
-		 __kram_start = . ;
-
-		__stext = . ;
-        	*(.text)
-			*(.exit.text)	/* 2.5 convention */
-			*(.text.exit)	/* 2.4 convention */
-			*(.text.lock)
-			*(.exitcall.exit)
-		__real_etext = . ;	/* There may be data after here.  */
-			*(.rodata)
-
-		. = ALIGN (0x4) ;
-			*(.kstrtab)
-
-		. = ALIGN (4) ;
-		    	*(.call_table_data)
-			*(.call_table_text)
-
-		. = ALIGN (16) ;	/* Exception table.  */
-		___start___ex_table = . ;
-			*(__ex_table)
-		___stop___ex_table = . ;
-
-		___start___ksymtab = . ;/* Kernel symbol table.  */
-			*(__ksymtab)
-		___stop___ksymtab = . ;
-		. = ALIGN (4) ;
-		__etext = . ;
-	} > SDRAM
-
-	.data ALIGN (0x4) : {
-		__sdata = . ;
-		___data_start = . ;
-        	*(.data)
-			*(.exit.data)	/* 2.5 convention */
-			*(.data.exit)	/* 2.4 convention */
-		. = ALIGN (16) ;
-		*(.data.cacheline_aligned)
-		. = ALIGN (0x2000) ;
-        	*(.data.init_task)
-		. = ALIGN (0x2000) ;
-		__edata = . ;
-	} > SDRAM
-
-	.bss ALIGN (0x4) : {
-		__sbss = . ;
-			*(.bss)
-			*(COMMON)
-		. = ALIGN (4) ;
-		__init_stack_end = . ;
-		__ebss = . ;
-	} > SDRAM
-
-	.init ALIGN (4096) : {
-		__init_start = . ;
-			*(.init.text)	/* 2.5 convention */
-			*(.init.data)
-			*(.text.init)	/* 2.4 convention */
-			*(.data.init)
-		. = ALIGN (16) ;
-		___setup_start = . ;
-			*(.init.setup)	/* 2.5 convention */
-			*(.setup.init)	/* 2.4 convention */
-		___setup_end = . ;
-		___initcall_start = . ;
-			*(.initcall.init)
-			*(.initcall1.init)
-			*(.initcall2.init)
-			*(.initcall3.init)
-			*(.initcall4.init)
-			*(.initcall5.init)
-			*(.initcall6.init)
-			*(.initcall7.init)
-		. = ALIGN (4) ;
-		___initcall_end = . ;
-
-		. = ALIGN (4) ;
-		___initramfs_start = . ;
-			*(.init.ramfs)
-		___initramfs_end = . ;
-	} > SDRAM
-
-	/* The address at which the interrupt vectors are initially
-	   loaded by the loader.  */
-	__intv_load_start = ALIGN (0x10) ;
-
-	/* Interrupt vector space.  Because we're using the monitor
-	   ROM, Instead of the native interrupt vector, we must use the
-	   `alternate interrupt vector' area.  Note that this is in
-	   `SRAM' space, which is not currently used by the kernel (the
-	   kernel uses `SDRAM' space).  */
-
-	/* We can't load the interrupt vectors directly into their
-	   target location, because the monitor ROM for the GHS Multi
-	   debugger barfs if we try.  Unfortunately, Multi also doesn't
-	   deal correctly with ELF sections where the LMA and VMA differ
-	   (it just ignores the LMA), so we can't use that feature to
-	   work around the problem!  What we do instead is just put the
-	   interrupt vectors into a normal section, and have the
-	   `mach_early_init' function for Midas boards do the necessary
-	   copying and relocation at runtime (this section basically
-	   only contains `jr' instructions, so it's not that hard).
-
-	   This the section structure I initially tried to use (which more
-	   accurately expresses the intent):
-
-		.intv 0x007F8000 : AT (ADDR (.init) + SIZEOF (.init)) {
-		    ...
-		} > MRAM
-	*/
-
-	.intv ALIGN (0x10) : {
-		__intv_start = . ;
-	        	*(.intv.reset)	/* Reset vector */
-			*(.intv.common) /* Vectors common to all v850e proc. */
-			*(.intv.mach)   /* Machine-specific int. vectors.  */
-		__intv_end = . ;
-
-		/* This is here so that when we free init memory, the initial
-		   load-area of the interrupt vectors is freed too.  */
-		__init_end = __intv_end;
-
+		__kram_start = . ;
+		TEXT_CONTENTS
+	} > KRAM
+
+	.data : {
+		DATA_CONTENTS
+		BSS_CONTENTS
+		RAMK_INIT_CONTENTS
 		__kram_end = . ;
-	} > SDRAM
+		BOOTMAP_CONTENTS
+
+		/* The address at which the interrupt vectors are initially
+		   loaded by the loader.  We can't load the interrupt vectors
+		   directly into their target location, because the monitor
+		   ROM for the GHS Multi debugger barfs if we try.
+		   Unfortunately, Multi also doesn't deal correctly with ELF
+		   sections where the LMA and VMA differ (it just ignores the
+		   LMA), so we can't use that feature to work around the
+		   problem!  What we do instead is just put the interrupt
+		   vectors into a normal section, and have the
+		   `mach_early_init' function for Midas boards do the
+		   necessary copying and relocation at runtime (this section
+		   basically only contains `jr' instructions, so it's not
+		   that hard).  */
+		. = ALIGN (0x10) ;
+		__intv_load_start = . ;
+		INTV_CONTENTS
+	} > KRAM
 
-	/* Device contents for the root filesystem.  */
-	.root ALIGN (4096) : {
-		__root_fs_image_start = . ;
-		*(.root)
-		__root_fs_image_end = . ;
-	} > SDRAM
+	.root ALIGN (4096) : { ROOT_FS_CONTENTS } > SDRAM
 }
diff -Nru a/arch/v850/sim.ld b/arch/v850/sim.ld
--- a/arch/v850/sim.ld	Mon Dec 23 21:21:50 2002
+++ b/arch/v850/sim.ld	Mon Dec 23 21:21:50 2002
@@ -1,114 +1,14 @@
 /* Linker script for the gdb v850e simulator (CONFIG_V850E_SIM).  */
 
-/* Note, all symbols are prefixed with an extra `_' for compatibility with
-   the existing linux sources.  */
-
-_jiffies = _jiffies_64 ;
-
 MEMORY {
-       /* Interrupt vectors.  */
-       INTV  : ORIGIN = 0x0, LENGTH = 0xe0
-       /* 16MB of RAM.
-          This must match RAM_ADDR and RAM_SIZE in include/asm-v580/sim.h  */
-       RAM   : ORIGIN = 0x8F000000, LENGTH = 0x01000000
+	/* Interrupt vectors.  */
+	INTV  : ORIGIN = 0x0, LENGTH = 0xe0
+	/* 16MB of RAM.
+	   This must match RAM_ADDR and RAM_SIZE in include/asm-v850/sim.h  */
+	RAM   : ORIGIN = 0x8F000000, LENGTH = 0x01000000
 }
 
 SECTIONS {
-	.intv : {
-		__intv_start = . ;
-			*(.intv.reset)	/* Reset vector */
-			*(.intv.common)	/* Vectors common to all v850e proc. */
-			*(.intv.mach)	/* Machine-specific int. vectors.  */
-		__intv_end = . ;
-	} > INTV
-
-	.text : {
-		__kram_start = . ;
-
-		__stext = . ;
-        	*(.text)
-			*(.exit.text)	/* 2.5 convention */
-			*(.text.exit)	/* 2.4 convention */
-			*(.text.lock)
-			*(.exitcall.exit)
-		__real_etext = . ;	/* There may be data after here.  */
-			*(.rodata)
-		. = ALIGN (0x4) ;
-			*(.kstrtab)
-
-		. = ALIGN (4) ;
-		    	*(.call_table_data)
-			*(.call_table_text)
-
-		. = ALIGN (16) ;	/* Exception table.  */
-		___start___ex_table = . ;
-			*(__ex_table)
-		___stop___ex_table = . ;
-
-		___start___ksymtab = . ;/* Kernel symbol table.  */
-			*(__ksymtab)
-		___stop___ksymtab = . ;
-		. = ALIGN (4) ;
-		__etext = . ;
-	} > RAM
-
-	.data ALIGN (0x4) : {
-		__sdata = . ;
-        	*(.data)
-			*(.exit.data)	/* 2.5 convention */
-			*(.data.exit)	/* 2.4 convention */
-		. = ALIGN (16) ;
-		*(.data.cacheline_aligned)
-		. = ALIGN (0x2000) ;
-        	*(.data.init_task)
-		. = ALIGN (0x2000) ;
-		__edata = . ;
-	} > RAM
-
-	.bss ALIGN (0x4) : {
-		__sbss = . ;
-			*(.bss)
-			*(COMMON)
-		. = ALIGN (4) ;
-		__init_stack_end = . ;
-		__ebss = . ;
-	} > RAM
-
-	.init ALIGN (4096) : {
-		__init_start = . ;
-			*(.init.text)	/* 2.5 convention */
-			*(.init.data)
-			*(.text.init)	/* 2.4 convention */
-			*(.data.init)
-		. = ALIGN (16) ;
-		___setup_start = . ;
-			*(.init.setup)	/* 2.5 convention */
-			*(.setup.init)	/* 2.4 convention */
-		___setup_end = . ;
-		___initcall_start = . ;
-			*(.initcall.init)
-			*(.initcall1.init)
-			*(.initcall2.init)
-			*(.initcall3.init)
-			*(.initcall4.init)
-			*(.initcall5.init)
-			*(.initcall6.init)
-			*(.initcall7.init)
-		. = ALIGN (4) ;
-		___initcall_end = . ;
-
-		. = ALIGN (4) ;
-		___initramfs_start = . ;
-			*(.init.ramfs)
-		___initramfs_end = . ;
-
-		__init_end = . ;
-
-		__kram_end = . ;
-	} > RAM
-
-	.bootmap ALIGN (4096) : {
-		__bootmap = . ;
-		. = . + 4096 ;		/* enough for 128MB.   */
-	} > RAM
+	.intv : { INTV_CONTENTS } > INTV
+	.ram : { RAMK_KRAM_CONTENTS } > RAM
 }
diff -Nru a/arch/v850/sim85e2c.ld b/arch/v850/sim85e2c.ld
--- a/arch/v850/sim85e2c.ld	Mon Dec 23 21:22:00 2002
+++ b/arch/v850/sim85e2c.ld	Mon Dec 23 21:22:00 2002
@@ -1,141 +1,44 @@
 /* Linker script for the sim85e2c simulator, which is a verilog simulation of
    the V850E2 NA85E2C cpu core (CONFIG_V850E2_SIM85E2C).  */
 
-/* Note, all symbols are prefixed with an extra `_' for compatibility with
-   the existing linux sources.  */
-
-_jiffies = _jiffies_64 ;
-
 MEMORY {
-       /* 1MB of `instruction RAM', starting at 0.
-          Instruction fetches are much faster from IRAM than from DRAM.
-	  This should match IRAM_ADDR in "include/asm-v580/sim85e2c.h".    */
-       IRAM	: ORIGIN = 0x00000000, LENGTH = 0x00100000
-
-       /* 1MB of `data RAM', below and contiguous with the I/O space.
-          Data fetches are much faster from DRAM than from IRAM.
-	  This should match DRAM_ADDR in "include/asm-v580/sim85e2c.h".  */
-       DRAM	: ORIGIN = 0xfff00000, LENGTH = 0x000ff000
-       /* We have to load DRAM at a mirror-address of 0x1ff00000,
-          because the simulator's preprocessing script isn't smart
-          enough to deal with the above LMA.  */
-       DRAM_LOAD : ORIGIN = 0x1ff00000, LENGTH = 0x000ff000
-
-       /* `external ram' (CS1 area), comes after IRAM.
-          This should match ERAM_ADDR in "include/asm-v580/sim85e2c.h".  */
-       ERAM	: ORIGIN = 0x00100000, LENGTH = 0x07f00000
+	/* 1MB of `instruction RAM', starting at 0.
+	   Instruction fetches are much faster from IRAM than from DRAM.
+	   This should match IRAM_ADDR in "include/asm-v580/sim85e2c.h".    */
+	IRAM	: ORIGIN = 0x00000000, LENGTH = 0x00100000
+
+	/* 1MB of `data RAM', below and contiguous with the I/O space.
+	   Data fetches are much faster from DRAM than from IRAM.
+	   This should match DRAM_ADDR in "include/asm-v580/sim85e2c.h".  */
+	DRAM	: ORIGIN = 0xfff00000, LENGTH = 0x000ff000
+	/* We have to load DRAM at a mirror-address of 0x1ff00000,
+	   because the simulator's preprocessing script isn't smart
+	   enough to deal with the above LMA.  */
+	DRAM_LOAD : ORIGIN = 0x1ff00000, LENGTH = 0x000ff000
+
+	/* `external ram' (CS1 area), comes after IRAM.
+	   This should match ERAM_ADDR in "include/asm-v580/sim85e2c.h".  */
+	ERAM	: ORIGIN = 0x00100000, LENGTH = 0x07f00000
 }
 
 SECTIONS {
-	.intv : {
-		__intv_start = . ;
-		*(.intv)		/* Interrupt vectors.  */
-	        	*(.intv.reset)	/* Reset vector */
-			*(.intv.common) /* Vectors common to all v850e proc. */
-			*(.intv.mach)   /* Machine-specific int. vectors.  */
-		__intv_end = . ;
-	} > IRAM
-
-	.text : {
-		__stext = . ;
-        	*(.text)
-			*(.exit.text)	/* 2.5 convention */
-			*(.text.exit)	/* 2.4 convention */
-			*(.text.lock)
-			*(.exitcall.exit)
-		__real_etext = . ;	/* There may be data after here.  */
-			*(.rodata)
-		. = ALIGN (0x4) ;
-			*(.kstrtab)
-
-		. = ALIGN (4) ;
-		    	*(.call_table_data)
-			*(.call_table_text)
-
-		. = ALIGN (16) ;	/* Exception table.  */
-		___start___ex_table = . ;
-			*(__ex_table)
-		___stop___ex_table = . ;
-
-		___start___ksymtab = . ;/* Kernel symbol table.  */
-			*(__ksymtab)
-		___stop___ksymtab = . ;
-		. = ALIGN (4) ;
-		__etext = . ;
+	.iram : {
+		INTV_CONTENTS
+		TEXT_CONTENTS
+		RAMK_INIT_CONTENTS
 	} > IRAM
-
-	.init ALIGN (4096) : {
-		__init_start = . ;
-			*(.init.text)	/* 2.5 convention */
-			*(.init.data)
-			*(.text.init)	/* 2.4 convention */
-			*(.data.init)
-		. = ALIGN (16) ;
-		___setup_start = . ;
-			*(.init.setup)	/* 2.5 convention */
-			*(.setup.init)	/* 2.4 convention */
-		___setup_end = . ;
-		___initcall_start = . ;
-			*(.initcall.init)
-			*(.initcall1.init)
-			*(.initcall2.init)
-			*(.initcall3.init)
-			*(.initcall4.init)
-			*(.initcall5.init)
-			*(.initcall6.init)
-			*(.initcall7.init)
-		. = ALIGN (4) ;
-		___initcall_end = . ;
-
-		. = ALIGN (4) ;
-		___initramfs_start = . ;
-			*(.init.ramfs)
-		___initramfs_end = . ;
-
-		__init_end = . ;
-	} > IRAM
-
 	.data : {
-	        __kram_start = . ;
+		__kram_start = . ;
+		DATA_CONTENTS
+		BSS_CONTENTS
+		ROOT_FS_CONTENTS
 
-		__sdata = . ;
-        	*(.data)
-			*(.exit.data)	/* 2.5 convention */
-			*(.data.exit)	/* 2.4 convention */
-		. = ALIGN (16) ;
-		*(.data.cacheline_aligned)
-		. = ALIGN (0x2000) ;
-        	*(.data.init_task)
-		. = ALIGN (0x2000) ;
-		__edata = . ;
-	} > DRAM  AT> DRAM_LOAD
-
-	.bss ALIGN (0x4) : {
-		__sbss = . ;
-			*(.bss)
-			*(COMMON)
-		. = ALIGN (4) ;
-		__init_stack_end = . ;
-		__ebss = . ;
-	} > DRAM  AT> DRAM_LOAD
-
-	/* Device contents for the root filesystem.  */
-	.root ALIGN (4096) : {
-		__root_fs_image_start = . ;
-		*(.root)
-		__root_fs_image_end = . ;
-	} > DRAM  AT> DRAM_LOAD
-
-	.memcons : {
+		/* We stick console output into a buffer here.  */
 		_memcons_output = . ;
 		. = . + 0x8000 ;
 		_memcons_output_end = . ;
 
-	        __kram_end = . ;
-	} > DRAM  AT> DRAM_LOAD
-
-	.bootmap ALIGN (4096) : {
-		__bootmap = . ;
-		. = . + 4096 ;		/* enough for 128MB.   */
+		__kram_end = . ;
+		BOOTMAP_CONTENTS
 	} > DRAM  AT> DRAM_LOAD
 }
diff -Nru a/arch/v850/vmlinux.lds.S b/arch/v850/vmlinux.lds.S
--- a/arch/v850/vmlinux.lds.S	Mon Dec 23 21:21:57 2002
+++ b/arch/v850/vmlinux.lds.S	Mon Dec 23 21:21:57 2002
@@ -1,5 +1,201 @@
+/*
+ * arch/v850/vmlinux.lds.S -- kernel linker script for v850 platforms
+ *
+ *  Copyright (C) 2002  NEC Electronics Corporation
+ *  Copyright (C) 2002  Miles Bader <miles@gnu.org>
+ *
+ * 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.
+ *
+ * Written by Miles Bader <miles@gnu.org>
+ */
+
 #include <linux/config.h>
 
+
+/* The following macros contain the usual definitions for various data areas.
+   The prefix `RAMK_' is used to indicate macros suitable for kernels loaded
+   into RAM, and similarly `ROMK_' for ROM-resident kernels.  Note that all
+   symbols are prefixed with an extra `_' for compatibility with the v850
+   toolchain.  */
+
+	
+/* Interrupt vectors.  */
+#define INTV_CONTENTS							      \
+		__intv_start = . ;					      \
+			*(.intv.reset)	/* Reset vector */		      \
+			*(.intv.common)	/* Vectors common to all v850e proc */\
+			*(.intv.mach)	/* Machine-specific int. vectors.  */ \
+		__intv_end = . ;
+
+/* Kernel text segment, and some constant data areas.  */
+#define TEXT_CONTENTS							      \
+		__stext = . ;						      \
+        	*(.text)						      \
+			*(.exit.text)	/* 2.5 convention */		      \
+			*(.text.exit)	/* 2.4 convention */		      \
+			*(.text.lock)					      \
+			*(.exitcall.exit)				      \
+		__real_etext = . ;	/* There may be data after here.  */  \
+			*(.rodata)					      \
+		. = ALIGN (0x4) ;					      \
+			*(.kstrtab)					      \
+		. = ALIGN (4) ;						      \
+		    	*(.call_table_data)				      \
+			*(.call_table_text)				      \
+		. = ALIGN (16) ;	/* Exception table.  */		      \
+		___start___ex_table = . ;				      \
+			*(__ex_table)					      \
+		___stop___ex_table = . ;				      \
+		___start___ksymtab = . ;/* Kernel symbol table.  */	      \
+			*(__ksymtab)					      \
+		___stop___ksymtab = . ;					      \
+		. = ALIGN (4) ;						      \
+		__etext = . ;
+
+/* Kernel data segment.  */
+#define DATA_CONTENTS							      \
+		__sdata = . ;						      \
+        	*(.data)						      \
+			*(.exit.data)	/* 2.5 convention */		      \
+			*(.data.exit)	/* 2.4 convention */		      \
+		. = ALIGN (16) ;					      \
+		*(.data.cacheline_aligned)				      \
+		. = ALIGN (0x2000) ;					      \
+        	*(.data.init_task)					      \
+		. = ALIGN (0x2000) ;					      \
+		__edata = . ;
+
+/* Kernel BSS segment.  */
+#define BSS_CONTENTS							      \
+		__sbss = . ;						      \
+			*(.bss)						      \
+			*(COMMON)					      \
+		. = ALIGN (4) ;						      \
+		__init_stack_end = . ;					      \
+		__ebss = . ;
+
+/* `initcall' tables.  */
+#define INITCALL_CONTENTS						      \
+		. = ALIGN (16) ;					      \
+		___setup_start = . ;					      \
+			*(.init.setup)	/* 2.5 convention */		      \
+			*(.setup.init)	/* 2.4 convention */		      \
+		___setup_end = . ;					      \
+		___start___param = . ;					      \
+			*(__param)					      \
+		___stop___param = . ;					      \
+		___initcall_start = . ;					      \
+			*(.initcall.init)				      \
+			*(.initcall1.init)				      \
+			*(.initcall2.init)				      \
+			*(.initcall3.init)				      \
+			*(.initcall4.init)				      \
+			*(.initcall5.init)				      \
+			*(.initcall6.init)				      \
+			*(.initcall7.init)				      \
+		. = ALIGN (4) ;						      \
+		___initcall_end = . ;
+
+/* Contents of `init' section for a kernel that's loaded into RAM.  */
+#define RAMK_INIT_CONTENTS						      \
+		RAMK_INIT_CONTENTS_NO_END				      \
+		__init_end = . ;
+/* Same as RAMK_INIT_CONTENTS, but doesn't define the `__init_end' symbol.  */
+#define RAMK_INIT_CONTENTS_NO_END					      \
+		. = ALIGN (4096) ;					      \
+		__init_start = . ;					      \
+			*(.init.text)	/* 2.5 convention */		      \
+			*(.init.data)					      \
+			*(.text.init)	/* 2.4 convention */		      \
+			*(.data.init)					      \
+		INITCALL_CONTENTS					      \
+		INITRAMFS_CONTENTS
+
+/* The contents of `init' section for a ROM-resident kernel which
+   should go into RAM.  */	
+#define ROMK_INIT_RAM_CONTENTS						      \
+		. = ALIGN (4096) ;					      \
+		__init_start = . ;					      \
+			*(.init.data)	/* 2.5 convention */		      \
+			*(.data.init)	/* 2.4 convention */		      \
+		__init_end = . ;					      \
+		. = ALIGN (4096) ;
+
+/* The contents of `init' section for a ROM-resident kernel which
+   should go into ROM.  */	
+#define ROMK_INIT_ROM_CONTENTS						      \
+			*(.init.text)	/* 2.5 convention */		      \
+			*(.text.init)	/* 2.4 convention */		      \
+		INITCALL_CONTENTS					      \
+		INITRAMFS_CONTENTS
+
+/* A root filesystem image, for kernels with an embedded root filesystem.  */
+#define ROOT_FS_CONTENTS						      \
+		__root_fs_image_start = . ;				      \
+		*(.root)						      \
+		__root_fs_image_end = . ;
+/* The initramfs archive.  */
+#define INITRAMFS_CONTENTS						      \
+		. = ALIGN (4) ;						      \
+		___initramfs_start = . ;				      \
+			*(.init.ramfs)					      \
+		___initramfs_end = . ;
+/* Where the initial bootmap (bitmap for the boot-time memory allocator) 
+   should be place.  */
+#define BOOTMAP_CONTENTS						      \
+		. = ALIGN (4096) ;					      \
+		__bootmap = . ;						      \
+		. = . + 4096 ;		/* enough for 128MB.   */
+
+/* The contents of a `typical' kram area for a kernel in RAM.  */
+#define RAMK_KRAM_CONTENTS						      \
+		__kram_start = . ;					      \
+		TEXT_CONTENTS						      \
+		DATA_CONTENTS						      \
+		BSS_CONTENTS						      \
+		RAMK_INIT_CONTENTS					      \
+		__kram_end = . ;					      \
+		BOOTMAP_CONTENTS
+
+
+/* Define output sections normally used for a ROM-resident kernel.  
+   ROM and RAM should be appropriate memory areas to use for kernel
+   ROM and RAM data.  This assumes that ROM starts at 0 (and thus can
+   hold the interrupt vectors).  */
+#define ROMK_SECTIONS(ROM, RAM)						      \
+	.rom : {							      \
+		INTV_CONTENTS						      \
+		TEXT_CONTENTS						      \
+		ROMK_INIT_ROM_CONTENTS					      \
+		ROOT_FS_CONTENTS					      \
+	} > ROM								      \
+									      \
+	__rom_copy_src_start = . ;					      \
+									      \
+	.data : {							      \
+		__kram_start = . ;					      \
+		__rom_copy_dst_start = . ;				      \
+		DATA_CONTENTS						      \
+		ROMK_INIT_RAM_CONTENTS					      \
+		__rom_copy_dst_end = . ;				      \
+	} > RAM  AT> ROM						      \
+									      \
+	.bss ALIGN (4) : {						      \
+		BSS_CONTENTS						      \
+		__kram_end = . ;					      \
+		BOOTMAP_CONTENTS					      \
+	} > RAM
+
+
+/* The 32-bit variable `jiffies' is just the lower 32-bits of `jiffies_64'.  */
+_jiffies = _jiffies_64 ;
+
+
+/* Include an appropriate platform-dependent linker-script (which
+   usually should use the above macros to do most of the work).  */
+
 #ifdef CONFIG_V850E_SIM
 # include "sim.ld"
 #endif
@@ -21,15 +217,17 @@
 #endif
 
 #ifdef CONFIG_V850E_AS85EP1
-# include "as85ep1.ld"
+# ifdef CONFIG_ROM_KERNEL
+#  include "as85ep1-rom.ld"
+# else
+#  include "as85ep1.ld"
+# endif
 #endif
 
 #ifdef CONFIG_RTE_CB_MA1
 # ifdef CONFIG_ROM_KERNEL
 #  include "rte_ma1_cb-rom.ld"
-# elif CONFIG_RTE_CB_MA1_KSRAM
-#  include "rte_ma1_cb-ksram.ld"
-# else /* !CONFIG_ROM_KERNEL && !CONFIG_RTE_CB_MA1_KSRAM */
+# else
 #  include "rte_ma1_cb.ld"
-# endif /* CONFIG_ROM_KERNEL */
-#endif /* CONFIG_RTE_CB_MA1 */
+# endif
+#endif
diff -Nru a/arch/x86_64/Kconfig b/arch/x86_64/Kconfig
--- a/arch/x86_64/Kconfig	Mon Dec 23 21:21:59 2002
+++ b/arch/x86_64/Kconfig	Mon Dec 23 21:21:59 2002
@@ -175,6 +175,14 @@
 
 	  See <file:Documentation/mtrr.txt> for more information.
 
+config HUGETLB_PAGE
+	bool "Huge TLB Page Support"
+	help
+	  This enables support for huge pages.  User space applications
+	  can make use of this support with the hugetlbfs file system
+	  To actually use it you need to pass an hugepages= argument
+	  to the kernel at boot time.
+
 config SMP
 	bool "Symmetric multi-processing support"
 	---help---
@@ -285,6 +293,35 @@
 	  will issue the hlt instruction if nothing is to be done, thereby
 	  sending the processor to sleep and saving power.
 
+config SOFTWARE_SUSPEND
+	bool "Software Suspend (EXPERIMENTAL)"
+	depends on EXPERIMENTAL && PM
+	---help---
+	  Enable the possibilty of suspendig machine. It doesn't need APM.
+	  You may suspend your machine by 'swsusp' or 'shutdown -z <time>' 
+	  (patch for sysvinit needed). 
+
+	  It creates an image which is saved in your active swaps. By the next
+	  booting the, pass 'resume=/path/to/your/swap/file' and kernel will 
+	  detect the saved image, restore the memory from
+	  it and then it continues to run as before you've suspended.
+	  If you don't want the previous state to continue use the 'noresume'
+	  kernel option. However note that your partitions will be fsck'd and
+	  you must re-mkswap your swap partitions/files.
+
+	  Right now you may boot without resuming and then later resume but
+	  in meantime you cannot use those swap partitions/files which were
+	  involved in suspending. Also in this case there is a risk that buffers
+	  on disk won't match with saved ones.
+
+	  SMP is supported ``as-is''. There's a code for it but doesn't work.
+	  There have been problems reported relating SCSI.
+
+	  This option is about getting stable. However there is still some
+	  absence of features.
+
+	  For more information take a look at Documentation/swsusp.txt.
+
 source "drivers/acpi/Kconfig"
 
 endmenu
@@ -425,6 +462,11 @@
 	  turn this on, unless you're 100% sure that you don't have any 32bit programs
 	  left.
 
+config COMPAT
+	bool
+	depends on IA32_EMULATION
+	default y
+
 endmenu
 
 source "drivers/mtd/Kconfig"
@@ -691,6 +733,16 @@
 	  Say Y here to let the kernel print out symbolic crash information and
 	  symbolic stack backtraces. This increases the size of the kernel
 	  somewhat, as all symbols have to be loaded into the kernel image.
+
+config FRAME_POINTER
+       bool "Compile the kernel with frame pointers"
+       depends on DEBUG_KERNEL	
+       help
+         If you say Y here the resulting kernel image will be slightly larger
+         and slower, but it will give very useful debugging information.
+         If you don't debug the kernel, you can say N, but we may not be able
+         to solve problems without frame pointers.
+	 Note this is normally not needed on x86-64.
 
 endmenu
 
diff -Nru a/arch/x86_64/Makefile b/arch/x86_64/Makefile
--- a/arch/x86_64/Makefile	Mon Dec 23 21:22:00 2002
+++ b/arch/x86_64/Makefile	Mon Dec 23 21:22:00 2002
@@ -36,6 +36,7 @@
 LDFLAGS		:= -m elf_x86_64
 OBJCOPYFLAGS	:= -O binary -R .note -R .comment -S
 LDFLAGS_vmlinux := -e stext
+LDFLAGS_BLOB	:= --format binary --oformat elf64-x86-64
 
 CFLAGS += -mno-red-zone
 CFLAGS += -mcmodel=kernel
@@ -54,8 +55,7 @@
 core-$(CONFIG_IA32_EMULATION)		+= arch/x86_64/ia32/
 drivers-$(CONFIG_PCI)			+= arch/x86_64/pci/
 
-MAKEBOOT = $(MAKE) -C arch/$(ARCH)/boot
-makeboot = $(call descend,arch/x86_64/boot,$(1))
+makeboot =$(Q)$(MAKE) -f scripts/Makefile.build obj=arch/x86_64/boot $(1)
 
 .PHONY: zImage bzImage compressed zlilo bzlilo zdisk bzdisk install \
 		clean archclean archmrproper
@@ -64,21 +64,21 @@
 zImage zlilo zdisk: BOOTIMAGE=arch/x86_64/boot/zImage
 
 zImage bzImage: vmlinux
-	+@$(call makeboot,$(BOOTIMAGE))
+	$(call makeboot,$(BOOTIMAGE))
 
 compressed: zImage
 
 zlilo bzlilo: vmlinux
-	+@$(call makeboot,BOOTIMAGE=$(BOOTIMAGE) zlilo)
+	$(call makeboot,BOOTIMAGE=$(BOOTIMAGE) zlilo)
 
 zdisk bzdisk: vmlinux
-	+@$(call makeboot,BOOTIMAGE=$(BOOTIMAGE) zdisk)
+	$(call makeboot,BOOTIMAGE=$(BOOTIMAGE) zdisk)
 
 install: vmlinux
-	+@$(call makeboot,BOOTIMAGE=$(BOOTIMAGE) install)
+	$(call makeboot,BOOTIMAGE=$(BOOTIMAGE) install)
 
 archclean:
-	+@$(call makeboot,clean)
+	$(call makeboot,clean)
 
 archmrproper:
 
diff -Nru a/arch/x86_64/boot/Makefile b/arch/x86_64/boot/Makefile
--- a/arch/x86_64/boot/Makefile	Mon Dec 23 21:21:53 2002
+++ b/arch/x86_64/boot/Makefile	Mon Dec 23 21:21:53 2002
@@ -32,10 +32,6 @@
 
 host-progs	:= tools/build
 
-# 	Default
-
-boot: bzImage
-
 # ---------------------------------------------------------------------------
 
 $(obj)/zImage:  IMAGE_OFFSET := 0x1000
@@ -62,9 +58,8 @@
 	$(call if_changed,ld)
 
 $(obj)/compressed/vmlinux: FORCE
-	+@$(call descend,$(obj)/compressed,IMAGE_OFFSET=$(IMAGE_OFFSET) \
-		$(obj)/compressed/vmlinux)
-
+	$(Q)$(MAKE) -f scripts/Makefile.build obj=$(obj)/compressed \
+					IMAGE_OFFSET=$(IMAGE_OFFSET) $@
 
 zdisk: $(BOOTIMAGE)
 	dd bs=8192 if=$(BOOTIMAGE) of=/dev/fd0
diff -Nru a/arch/x86_64/boot/compressed/Makefile b/arch/x86_64/boot/compressed/Makefile
--- a/arch/x86_64/boot/compressed/Makefile	Mon Dec 23 21:21:53 2002
+++ b/arch/x86_64/boot/compressed/Makefile	Mon Dec 23 21:21:53 2002
@@ -18,9 +18,9 @@
 
 $(obj)/vmlinux: $(obj)/head.o $(obj)/misc.o $(obj)/piggy.o FORCE
 	$(call if_changed,ld)
+	@:
 
 $(obj)/vmlinux.bin: vmlinux FORCE
-	strip vmlinux
 	$(call if_changed,objcopy)
 
 $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
diff -Nru a/arch/x86_64/boot/compressed/misc.c b/arch/x86_64/boot/compressed/misc.c
--- a/arch/x86_64/boot/compressed/misc.c	Mon Dec 23 21:21:53 2002
+++ b/arch/x86_64/boot/compressed/misc.c	Mon Dec 23 21:21:53 2002
@@ -330,6 +330,8 @@
 void check_cpu(void)
 {
 	int res = 0;
+        int tmp, flags;
+
 	asm volatile( " \n\
 	movl $3,%%edx		# at least 386 \n\
 	pushfl			# push EFLAGS \n\
@@ -395,6 +397,43 @@
 	}
 	if (res !=7)
 		error( "Sorry, your CPU is not capable of running 64-bit kernel." );
+        /* check required feature flags */ 
+        /* see http://www.x86-64.org/lists/discuss/msg02971.html */
+#define REQUIRED_MASK1 ((1<<0)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<8)|(1<<11)| \
+                                           (1<<13)|(1<<15)|(1<<24))
+        
+        asm("cpuid" : "=d" (flags), "=a" (tmp) : "1" (0x80000001) : "ebx", "ecx"); 
+        flags &= REQUIRED_MASK1;
+        flags ^= REQUIRED_MASK1; 
+        if (flags & (1<<0))
+                error("CPU misses x87"); 
+        if (flags & (1<<3)) 
+                error("CPU doesn't support page size extension (PSE)");
+        if (flags & (1<<4))
+                error("CPU misses an time stamp counter"); 
+        if (flags & (1<<5))
+                error("CPU misses AMD style MSRs"); 
+        if (flags & (1<<6))
+                error("CPU misses physical address extension (PAE)"); 
+        if (flags & (1<<8))
+                error("CPU misses cmpxchg8"); 
+        if (flags & (1<<11))
+                error("CPU doesn't support SYSCALL/SYSRET");
+        if (flags & (1<<13))
+                error("CPU doesn't support PGE"); 
+        if (flags & (1<<15))
+                error("CPU doesn't support CMOV"); 
+        if (flags & (1<<24))
+                error("CPU doesn't support FXSAVE/FXRSTOR"); 
+
+#define REQUIRED_MASK2 ((1<<25)|(1<<26))        
+        asm("cpuid" : "=d" (flags), "=a" (tmp) : "1" (1) : "ebx", "ecx"); 
+        flags &= REQUIRED_MASK2; 
+        flags ^= REQUIRED_MASK2; 
+        if (flags & (1<<25))
+                error("CPU doesn't support SSE1");
+        if (flags & (1<<26))
+                error("CPU doesn't support SSE2");
 }
 
 int decompress_kernel(struct moveparams *mv, void *rmode)
diff -Nru a/arch/x86_64/defconfig b/arch/x86_64/defconfig
--- a/arch/x86_64/defconfig	Mon Dec 23 21:21:58 2002
+++ b/arch/x86_64/defconfig	Mon Dec 23 21:21:58 2002
@@ -3,11 +3,10 @@
 #
 CONFIG_X86_64=y
 CONFIG_X86=y
-# CONFIG_ISA is not set
-# CONFIG_SBUS is not set
+CONFIG_MMU=y
+CONFIG_SWAP=y
 CONFIG_UID16=y
 CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
 CONFIG_X86_CMPXCHG=y
 CONFIG_EARLY_PRINTK=y
 CONFIG_GENERIC_ISA_DMA=y
@@ -29,7 +28,9 @@
 # Loadable module support
 #
 CONFIG_MODULES=y
-# CONFIG_MODVERSIONS is not set
+CONFIG_MODULE_UNLOAD=y
+CONFIG_MODULE_FORCE_UNLOAD=y
+CONFIG_OBSOLETE_MODPARM=y
 # CONFIG_KMOD is not set
 
 #
@@ -43,12 +44,10 @@
 CONFIG_X86_GOOD_APIC=y
 CONFIG_X86_MSR=y
 CONFIG_X86_CPUID=y
-# CONFIG_MATH_EMULATION is not set
-# CONFIG_MCA is not set
-# CONFIG_EISA is not set
 CONFIG_X86_IO_APIC=y
 CONFIG_X86_LOCAL_APIC=y
 CONFIG_MTRR=y
+CONFIG_HUGETLB_PAGE=y
 CONFIG_SMP=y
 CONFIG_HAVE_DEC_LOCK=y
 CONFIG_NR_CPUS=8
@@ -66,7 +65,6 @@
 CONFIG_ACPI=y
 # CONFIG_ACPI_HT_ONLY is not set
 CONFIG_ACPI_BOOT=y
-# CONFIG_ACPI_SLEEP is not set
 CONFIG_ACPI_AC=y
 CONFIG_ACPI_BATTERY=y
 CONFIG_ACPI_BUTTON=y
@@ -75,7 +73,6 @@
 CONFIG_ACPI_THERMAL=y
 CONFIG_ACPI_TOSHIBA=y
 CONFIG_ACPI_DEBUG=y
-CONFIG_ACPI_BOOT=y
 CONFIG_ACPI_BUS=y
 CONFIG_ACPI_INTERPRETER=y
 CONFIG_ACPI_EC=y
@@ -90,7 +87,6 @@
 CONFIG_PCI_DIRECT=y
 # CONFIG_PCI_NAMES is not set
 # CONFIG_HOTPLUG is not set
-# CONFIG_PCMCIA is not set
 
 #
 # Executable file formats / Emulations
@@ -99,6 +95,7 @@
 CONFIG_BINFMT_ELF=y
 # CONFIG_BINFMT_MISC is not set
 CONFIG_IA32_EMULATION=y
+CONFIG_COMPAT=y
 
 #
 # Memory Technology Devices (MTD)
@@ -114,11 +111,8 @@
 # Block devices
 #
 CONFIG_BLK_DEV_FD=y
-# CONFIG_BLK_DEV_XD is not set
-# CONFIG_PARIDE is not set
 # CONFIG_BLK_CPQ_DA is not set
 # CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_CISS_SCSI_TAPE is not set
 # CONFIG_BLK_DEV_DAC960 is not set
 # CONFIG_BLK_DEV_UMEM is not set
 CONFIG_BLK_DEV_LOOP=y
@@ -146,51 +140,42 @@
 CONFIG_BLK_DEV_IDEDISK=y
 CONFIG_IDEDISK_MULTI_MODE=y
 # CONFIG_IDEDISK_STROKE is not set
-# CONFIG_BLK_DEV_IDECS is not set
 CONFIG_BLK_DEV_IDECD=y
 # CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
 # CONFIG_IDE_TASK_IOCTL is not set
 
 #
 # IDE chipset support/bugfixes
 #
 # CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_CMD640_ENHANCED is not set
-# CONFIG_BLK_DEV_ISAPNP is not set
 CONFIG_BLK_DEV_IDEPCI=y
 # CONFIG_BLK_DEV_GENERIC is not set
 # CONFIG_IDEPCI_SHARE_IRQ is not set
 CONFIG_BLK_DEV_IDEDMA_PCI=y
 # CONFIG_BLK_DEV_IDE_TCQ is not set
-# CONFIG_BLK_DEV_IDE_TCQ_DEFAULT is not set
 # CONFIG_BLK_DEV_OFFBOARD is not set
 # CONFIG_BLK_DEV_IDEDMA_FORCED is not set
 CONFIG_IDEDMA_PCI_AUTO=y
 # CONFIG_IDEDMA_ONLYDISK is not set
 CONFIG_BLK_DEV_IDEDMA=y
 # CONFIG_IDEDMA_PCI_WIP is not set
-# CONFIG_IDEDMA_NEW_DRIVE_LISTINGS is not set
 CONFIG_BLK_DEV_ADMA=y
 # CONFIG_BLK_DEV_AEC62XX is not set
 # CONFIG_BLK_DEV_ALI15X3 is not set
-# CONFIG_WDC_ALI15X3 is not set
 CONFIG_BLK_DEV_AMD74XX=y
 # CONFIG_AMD74XX_OVERRIDE is not set
 # CONFIG_BLK_DEV_CMD64X is not set
 # CONFIG_BLK_DEV_CY82C693 is not set
-# CONFIG_BLK_DEV_CS5530 is not set
+# CONFIG_BLK_DEV_CS5520 is not set
 # CONFIG_BLK_DEV_HPT34X is not set
-# CONFIG_HPT34X_AUTODMA is not set
 # CONFIG_BLK_DEV_HPT366 is not set
+# CONFIG_BLK_DEV_SC1200 is not set
 # CONFIG_BLK_DEV_PIIX is not set
 # CONFIG_BLK_DEV_NFORCE is not set
 # CONFIG_BLK_DEV_NS87415 is not set
 # CONFIG_BLK_DEV_OPTI621 is not set
 # CONFIG_BLK_DEV_PDC202XX_OLD is not set
-# CONFIG_PDC202XX_BURST is not set
 # CONFIG_BLK_DEV_PDC202XX_NEW is not set
-# CONFIG_PDC202XX_FORCE is not set
 # CONFIG_BLK_DEV_RZ1000 is not set
 # CONFIG_BLK_DEV_SVWKS is not set
 # CONFIG_BLK_DEV_SIIMAGE is not set
@@ -198,10 +183,8 @@
 # CONFIG_BLK_DEV_SLC90E66 is not set
 # CONFIG_BLK_DEV_TRM290 is not set
 # CONFIG_BLK_DEV_VIA82CXXX is not set
-# CONFIG_IDE_CHIPSETS is not set
 CONFIG_IDEDMA_AUTO=y
 # CONFIG_IDEDMA_IVB is not set
-# CONFIG_DMA_NONPCI is not set
 CONFIG_BLK_DEV_IDE_MODES=y
 
 #
@@ -213,29 +196,15 @@
 # Multi-device support (RAID and LVM)
 #
 # CONFIG_MD is not set
-# CONFIG_BLK_DEV_MD is not set
-# CONFIG_MD_LINEAR is not set
-# CONFIG_MD_RAID0 is not set
-# CONFIG_MD_RAID1 is not set
-# CONFIG_MD_RAID5 is not set
-# CONFIG_MD_MULTIPATH is not set
-# CONFIG_BLK_DEV_LVM is not set
 
 #
 # Telephony Support
 #
 # CONFIG_PHONE is not set
-# CONFIG_PHONE_IXJ is not set
-# CONFIG_PHONE_IXJ_PCMCIA is not set
 
 #
 # Fusion MPT device support
 #
-# CONFIG_FUSION is not set
-# CONFIG_FUSION_BOOT is not set
-# CONFIG_FUSION_ISENSE is not set
-# CONFIG_FUSION_CTL is not set
-# CONFIG_FUSION_LAN is not set
 
 #
 # IEEE 1394 (FireWire) support (EXPERIMENTAL)
@@ -251,6 +220,7 @@
 # CONFIG_NETFILTER is not set
 CONFIG_FILTER=y
 CONFIG_UNIX=y
+# CONFIG_NET_KEY is not set
 CONFIG_INET=y
 CONFIG_IP_MULTICAST=y
 # CONFIG_IP_ADVANCED_ROUTER is not set
@@ -261,6 +231,9 @@
 # CONFIG_ARPD is not set
 # CONFIG_INET_ECN is not set
 # CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_XFRM_USER is not set
 # CONFIG_IPV6 is not set
 
 #
@@ -271,9 +244,6 @@
 # CONFIG_ATM is not set
 # CONFIG_VLAN_8021Q is not set
 # CONFIG_LLC is not set
-# CONFIG_IPX is not set
-# CONFIG_ATALK is not set
-# CONFIG_DEV_APPLETALK is not set
 # CONFIG_DECNET is not set
 # CONFIG_BRIDGE is not set
 # CONFIG_X25 is not set
@@ -290,6 +260,11 @@
 # CONFIG_NET_SCHED is not set
 
 #
+# Network testing
+#
+# CONFIG_NET_PKTGEN is not set
+
+#
 # Network device support
 #
 CONFIG_NETDEVICES=y
@@ -308,20 +283,9 @@
 # Ethernet (10 or 100Mbit)
 #
 CONFIG_NET_ETHERNET=y
-# CONFIG_SUNLANCE is not set
 # CONFIG_HAPPYMEAL is not set
-# CONFIG_SUNBMAC is not set
-# CONFIG_SUNQE is not set
 # CONFIG_SUNGEM is not set
-CONFIG_NET_VENDOR_3COM=y
-# CONFIG_EL1 is not set
-# CONFIG_EL2 is not set
-# CONFIG_ELPLUS is not set
-# CONFIG_EL16 is not set
-# CONFIG_ELMC is not set
-# CONFIG_ELMC_II is not set
-CONFIG_VORTEX=y
-# CONFIG_LANCE is not set
+# CONFIG_NET_VENDOR_3COM is not set
 # CONFIG_NET_VENDOR_SMC is not set
 # CONFIG_NET_VENDOR_RACAL is not set
 
@@ -330,8 +294,27 @@
 #
 # CONFIG_NET_TULIP is not set
 # CONFIG_HP100 is not set
-# CONFIG_NET_ISA is not set
-# CONFIG_NET_PCI is not set
+CONFIG_NET_PCI=y
+# CONFIG_PCNET32 is not set
+# CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_B44 is not set
+# CONFIG_DGRS is not set
+# CONFIG_EEPRO100 is not set
+# CONFIG_E100 is not set
+# CONFIG_FEALNX is not set
+# CONFIG_NATSEMI is not set
+# CONFIG_NE2K_PCI is not set
+CONFIG_8139CP=m
+CONFIG_8139TOO=m
+# CONFIG_8139TOO_PIO is not set
+# CONFIG_8139TOO_TUNE_TWISTER is not set
+# CONFIG_8139TOO_8129 is not set
+# CONFIG_8139_OLD_RX_RESET is not set
+# CONFIG_SIS900 is not set
+# CONFIG_EPIC100 is not set
+# CONFIG_SUNDANCE is not set
+# CONFIG_TLAN is not set
+# CONFIG_VIA_RHINE is not set
 # CONFIG_NET_POCKET is not set
 
 #
@@ -339,17 +322,16 @@
 #
 # CONFIG_ACENIC is not set
 # CONFIG_DL2K is not set
-# CONFIG_E1000 is not set
+CONFIG_E1000=m
 # CONFIG_E1000_NAPI is not set
-# CONFIG_MYRI_SBUS is not set
 # CONFIG_NS83820 is not set
 # CONFIG_HAMACHI is not set
 # CONFIG_YELLOWFIN is not set
+# CONFIG_R8169 is not set
 # CONFIG_SK98LIN is not set
 CONFIG_TIGON3=y
 # CONFIG_FDDI is not set
 # CONFIG_HIPPI is not set
-# CONFIG_PLIP is not set
 # CONFIG_PPP is not set
 # CONFIG_SLIP is not set
 
@@ -359,9 +341,8 @@
 # CONFIG_NET_RADIO is not set
 
 #
-# Token Ring devices
+# Token Ring devices (depends on LLC=y)
 #
-# CONFIG_TR is not set
 # CONFIG_NET_FC is not set
 # CONFIG_RCPCI is not set
 # CONFIG_SHAPER is not set
@@ -408,17 +389,10 @@
 #
 # CONFIG_GAMEPORT is not set
 CONFIG_SOUND_GAMEPORT=y
-# CONFIG_GAMEPORT_NS558 is not set
-# CONFIG_GAMEPORT_L4 is not set
-# CONFIG_GAMEPORT_EMU10K1 is not set
-# CONFIG_GAMEPORT_VORTEX is not set
-# CONFIG_GAMEPORT_FM801 is not set
-# CONFIG_GAMEPORT_CS461x is not set
 CONFIG_SERIO=y
 CONFIG_SERIO_I8042=y
 # CONFIG_SERIO_SERPORT is not set
 # CONFIG_SERIO_CT82C710 is not set
-# CONFIG_SERIO_PARKBD is not set
 
 #
 # Input Device Drivers
@@ -431,21 +405,7 @@
 CONFIG_INPUT_MOUSE=y
 CONFIG_MOUSE_PS2=y
 # CONFIG_MOUSE_SERIAL is not set
-# CONFIG_MOUSE_INPORT is not set
-# CONFIG_MOUSE_LOGIBM is not set
-# CONFIG_MOUSE_PC110PAD is not set
 CONFIG_INPUT_JOYSTICK=y
-# CONFIG_JOYSTICK_ANALOG is not set
-# CONFIG_JOYSTICK_A3D is not set
-# CONFIG_JOYSTICK_ADI is not set
-# CONFIG_JOYSTICK_COBRA is not set
-# CONFIG_JOYSTICK_GF2K is not set
-# CONFIG_JOYSTICK_GRIP is not set
-# CONFIG_JOYSTICK_GRIP_MP is not set
-# CONFIG_JOYSTICK_GUILLEMOT is not set
-# CONFIG_JOYSTICK_INTERACT is not set
-# CONFIG_JOYSTICK_SIDEWINDER is not set
-# CONFIG_JOYSTICK_TMDC is not set
 # CONFIG_JOYSTICK_IFORCE is not set
 # CONFIG_JOYSTICK_WARRIOR is not set
 # CONFIG_JOYSTICK_MAGELLAN is not set
@@ -453,15 +413,9 @@
 # CONFIG_JOYSTICK_SPACEBALL is not set
 # CONFIG_JOYSTICK_STINGER is not set
 # CONFIG_JOYSTICK_TWIDDLER is not set
-# CONFIG_JOYSTICK_DB9 is not set
-# CONFIG_JOYSTICK_GAMECON is not set
-# CONFIG_JOYSTICK_TURBOGRAFX is not set
 # CONFIG_INPUT_JOYDUMP is not set
 # CONFIG_INPUT_TOUCHSCREEN is not set
-# CONFIG_TOUCHSCREEN_GUNZE is not set
 # CONFIG_INPUT_MISC is not set
-# CONFIG_INPUT_PCSPKR is not set
-# CONFIG_INPUT_UINPUT is not set
 
 #
 # Character devices
@@ -476,13 +430,7 @@
 #
 CONFIG_SERIAL_8250=y
 CONFIG_SERIAL_8250_CONSOLE=y
-# CONFIG_SERIAL_8250_CS is not set
 # CONFIG_SERIAL_8250_EXTENDED is not set
-# CONFIG_SERIAL_8250_MANY_PORTS is not set
-# CONFIG_SERIAL_8250_SHARE_IRQ is not set
-# CONFIG_SERIAL_8250_DETECT_IRQ is not set
-# CONFIG_SERIAL_8250_MULTIPORT is not set
-# CONFIG_SERIAL_8250_RSA is not set
 
 #
 # Non-8250 serial port support
@@ -520,17 +468,10 @@
 # Ftape, the floppy tape device driver
 #
 # CONFIG_FTAPE is not set
-CONFIG_AGP=y
-# CONFIG_AGP_INTEL is not set
-# CONFIG_AGP_I810 is not set
-# CONFIG_AGP_VIA is not set
-# CONFIG_AGP_AMD is not set
-# CONFIG_AGP_SIS is not set
-# CONFIG_AGP_ALI is not set
-# CONFIG_AGP_SWORKS is not set
+# CONFIG_AGP is not set
+# CONFIG_AGP_GART is not set
 # CONFIG_DRM is not set
 # CONFIG_MWAVE is not set
-# CONFIG_SCx200_GPIO is not set
 CONFIG_RAW_DRIVER=y
 
 #
@@ -546,60 +487,48 @@
 # File systems
 #
 # CONFIG_QUOTA is not set
-# CONFIG_QFMT_V1 is not set
-# CONFIG_QFMT_V2 is not set
 CONFIG_AUTOFS_FS=y
 # CONFIG_AUTOFS4_FS is not set
 CONFIG_REISERFS_FS=y
 # CONFIG_REISERFS_CHECK is not set
 # CONFIG_REISERFS_PROC_INFO is not set
 # CONFIG_ADFS_FS is not set
-# CONFIG_ADFS_FS_RW is not set
 # CONFIG_AFFS_FS is not set
 # CONFIG_HFS_FS is not set
+# CONFIG_BEFS_FS is not set
 # CONFIG_BFS_FS is not set
 CONFIG_EXT3_FS=y
+# CONFIG_EXT3_FS_XATTR is not set
 CONFIG_JBD=y
 # CONFIG_JBD_DEBUG is not set
 # CONFIG_FAT_FS is not set
-# CONFIG_MSDOS_FS is not set
-# CONFIG_UMSDOS_FS is not set
-# CONFIG_VFAT_FS is not set
 # CONFIG_EFS_FS is not set
-# CONFIG_JFFS_FS is not set
-# CONFIG_JFFS2_FS is not set
 # CONFIG_CRAMFS is not set
 CONFIG_TMPFS=y
 CONFIG_RAMFS=y
+CONFIG_HUGETLBFS=y
 CONFIG_ISO9660_FS=y
 # CONFIG_JOLIET is not set
 # CONFIG_ZISOFS is not set
 # CONFIG_JFS_FS is not set
-# CONFIG_JFS_DEBUG is not set
-# CONFIG_JFS_STATISTICS is not set
 # CONFIG_MINIX_FS is not set
 # CONFIG_VXFS_FS is not set
 # CONFIG_NTFS_FS is not set
-# CONFIG_NTFS_DEBUG is not set
-# CONFIG_NTFS_RW is not set
 # CONFIG_HPFS_FS is not set
 CONFIG_PROC_FS=y
 # CONFIG_DEVFS_FS is not set
-# CONFIG_DEVFS_MOUNT is not set
-# CONFIG_DEVFS_DEBUG is not set
 CONFIG_DEVPTS_FS=y
 # CONFIG_QNX4FS_FS is not set
-# CONFIG_QNX4FS_RW is not set
 # CONFIG_ROMFS_FS is not set
 CONFIG_EXT2_FS=y
+# CONFIG_EXT2_FS_XATTR is not set
 # CONFIG_SYSV_FS is not set
 # CONFIG_UDF_FS is not set
-# CONFIG_UDF_RW is not set
 # CONFIG_UFS_FS is not set
-# CONFIG_UFS_FS_WRITE is not set
-# CONFIG_XFS_FS is not set
+CONFIG_XFS_FS=m
 # CONFIG_XFS_RT is not set
 # CONFIG_XFS_QUOTA is not set
+# CONFIG_XFS_POSIX_ACL is not set
 
 #
 # Network File Systems
@@ -609,7 +538,6 @@
 CONFIG_NFS_FS=y
 CONFIG_NFS_V3=y
 # CONFIG_NFS_V4 is not set
-# CONFIG_ROOT_NFS is not set
 CONFIG_NFSD=y
 CONFIG_NFSD_V3=y
 # CONFIG_NFSD_V4 is not set
@@ -621,36 +549,26 @@
 # CONFIG_CIFS is not set
 # CONFIG_SMB_FS is not set
 # CONFIG_NCP_FS is not set
-# CONFIG_NCPFS_PACKET_SIGNING is not set
-# CONFIG_NCPFS_IOCTL_LOCKING is not set
-# CONFIG_NCPFS_STRONG is not set
-# CONFIG_NCPFS_NFS_NS is not set
-# CONFIG_NCPFS_OS2_NS is not set
-# CONFIG_NCPFS_SMALLDOS is not set
-# CONFIG_NCPFS_NLS is not set
-# CONFIG_NCPFS_EXTRAS is not set
 # CONFIG_AFS_FS is not set
-# CONFIG_ZISOFS_FS is not set
 
 #
 # Partition Types
 #
 # CONFIG_PARTITION_ADVANCED is not set
 CONFIG_MSDOS_PARTITION=y
-# CONFIG_SMB_NLS is not set
-# CONFIG_NLS is not set
 
 #
-# Console drivers
+# Graphics support
 #
-CONFIG_VGA_CONSOLE=y
+# CONFIG_FB is not set
 # CONFIG_VIDEO_SELECT is not set
-# CONFIG_MDA_CONSOLE is not set
 
 #
-# Frame-buffer support
+# Console display driver support
 #
-# CONFIG_FB is not set
+CONFIG_VGA_CONSOLE=y
+# CONFIG_MDA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
 
 #
 # Sound
@@ -676,17 +594,20 @@
 # CONFIG_DEBUG_SPINLOCK is not set
 CONFIG_CHECKING=y
 # CONFIG_INIT_DEBUG is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_KALLSYMS is not set
+CONFIG_KALLSYMS=y
+# CONFIG_FRAME_POINTER is not set
 
 #
 # Security options
 #
-CONFIG_SECURITY_CAPABILITIES=y
+# CONFIG_SECURITY is not set
+
+#
+# Cryptographic options
+#
+# CONFIG_CRYPTO is not set
 
 #
 # Library routines
 #
 # CONFIG_CRC32 is not set
-# CONFIG_ZLIB_INFLATE is not set
-# CONFIG_ZLIB_DEFLATE is not set
diff -Nru a/arch/x86_64/ia32/fpu32.c b/arch/x86_64/ia32/fpu32.c
--- a/arch/x86_64/ia32/fpu32.c	Mon Dec 23 21:21:50 2002
+++ b/arch/x86_64/ia32/fpu32.c	Mon Dec 23 21:21:50 2002
@@ -70,6 +70,10 @@
 	return ret;
 }
 
+struct s10 { 
+	u64 a;
+	u16 b;
+} __attribute__((packed)); 
 
 static inline int convert_fxsr_from_user(struct i387_fxsave_struct *fxsave,
 					 struct _fpstate_ia32 *buf)
@@ -94,7 +98,9 @@
 	to = (struct _fpxreg *)&fxsave->st_space[0];
 	from = &buf->_st[0];
 	for (i = 0 ; i < 8 ; i++, to++, from++) {
-		if (__copy_from_user(to, from, sizeof(*from)))
+		struct s10 *top = (void *)to, *fromp = (void *)from; 
+		if (__put_user(fromp->a, &top->a) ||
+		    __put_user(fromp->b, &top->b))
 			return -1;
 	}
 	return 0;
@@ -130,7 +136,9 @@
 	to = &buf->_st[0];
 	from = (struct _fpxreg *) &fxsave->st_space[0];
 	for ( i = 0 ; i < 8 ; i++, to++, from++ ) {
-		if (__copy_to_user(to, from, sizeof(*to)))
+		struct s10 *top = (void *)top, *fromp = (void *)from;
+		if (__get_user(fromp->a, &top->a) || 
+		    __get_user(fromp->b, &top->b))
 			return -1;
 	}
 	return 0;
diff -Nru a/arch/x86_64/ia32/ia32_binfmt.c b/arch/x86_64/ia32/ia32_binfmt.c
--- a/arch/x86_64/ia32/ia32_binfmt.c	Mon Dec 23 21:21:50 2002
+++ b/arch/x86_64/ia32/ia32_binfmt.c	Mon Dec 23 21:21:50 2002
@@ -6,12 +6,13 @@
  * of ugly preprocessor tricks. Talk about very very poor man's inheritance.
  */ 
 #include <linux/types.h>
+#include <linux/compat.h>
 #include <linux/config.h> 
 #include <linux/stddef.h>
-#include <linux/module.h>
 #include <linux/rwsem.h>
 #include <linux/sched.h>
 #include <linux/string.h>
+#include <linux/binfmts.h>
 #include <asm/segment.h> 
 #include <asm/ptrace.h>
 #include <asm/processor.h>
@@ -19,14 +20,14 @@
 #include <asm/sigcontext32.h>
 #include <asm/fpu32.h>
 #include <asm/i387.h>
+#include <asm/uaccess.h>
+#include <asm/ia32.h>
 
 struct file;
 struct elf_phdr; 
 
 #define IA32_EMULATOR 1
 
-#define IA32_PAGE_OFFSET 0xffff0000
-#define IA32_STACK_TOP IA32_PAGE_OFFSET
 #define ELF_ET_DYN_BASE		(IA32_PAGE_OFFSET/3 + 0x1000000)
 
 #undef ELF_ARCH
@@ -53,11 +54,6 @@
 	int	si_errno;			/* errno */
 };
 
-struct timeval32
-{
-    int tv_sec, tv_usec;
-};
-
 #define jiffies_to_timeval(a,b) do { (b)->tv_usec = 0; (b)->tv_sec = (a)/HZ; }while(0)
 
 struct elf_prstatus
@@ -70,10 +66,10 @@
 	pid_t	pr_ppid;
 	pid_t	pr_pgrp;
 	pid_t	pr_sid;
-	struct timeval32 pr_utime;	/* User time */
-	struct timeval32 pr_stime;	/* System time */
-	struct timeval32 pr_cutime;	/* Cumulative user time */
-	struct timeval32 pr_cstime;	/* Cumulative system time */
+	struct compat_timeval pr_utime;	/* User time */
+	struct compat_timeval pr_stime;	/* System time */
+	struct compat_timeval pr_cutime;	/* Cumulative user time */
+	struct compat_timeval pr_cstime;	/* Cumulative system time */
 	elf_gregset_t pr_reg;	/* GP registers */
 	int pr_fpvalid;		/* True if math co-processor being used.  */
 };
@@ -123,15 +119,68 @@
 
 #define user user32
 
-#define dump_fpu dump_fpu_ia32
-
 #define __ASM_X86_64_ELF_H 1
-#include <asm/ia32.h>
+//#include <asm/ia32.h>
 #include <linux/elf.h>
 
 typedef struct user_i387_ia32_struct elf_fpregset_t;
 typedef struct user32_fxsr_struct elf_fpxregset_t;
 
+
+static inline void elf_core_copy_regs(elf_gregset_t *elfregs, struct pt_regs *regs)
+{
+	ELF_CORE_COPY_REGS((*elfregs), regs)
+}
+
+static inline int elf_core_copy_task_regs(struct task_struct *t, elf_gregset_t* elfregs)
+{	
+	struct pt_regs *pp = (struct pt_regs *)(t->thread.rsp0);
+	ELF_CORE_COPY_REGS((*elfregs), pp);
+	/* fix wrong segments */ 
+	(*elfregs)[7] = t->thread.ds; 
+	(*elfregs)[9] = t->thread.fsindex; 
+	(*elfregs)[10] = t->thread.gsindex; 
+	(*elfregs)[8] = t->thread.es; 	
+	return 1; 
+}
+
+static inline int 
+elf_core_copy_task_fpregs(struct task_struct *tsk, elf_fpregset_t *fpu)
+{
+	struct _fpstate_ia32 *fpstate = (void*)fpu; 
+	struct pt_regs *regs = (struct pt_regs *)(tsk->thread.rsp0); 
+	mm_segment_t oldfs = get_fs();
+	int ret;
+
+	if (!tsk->used_math) 
+		return 0;
+	--regs;
+	if (tsk == current)
+		unlazy_fpu(tsk);
+	set_fs(KERNEL_DS); 
+	ret = save_i387_ia32(tsk, fpstate, regs, 1);
+	/* Correct for i386 bug. It puts the fop into the upper 16bits of 
+	   the tag word (like FXSAVE), not into the fcs*/ 
+	fpstate->cssel |= fpstate->tag & 0xffff0000; 
+	set_fs(oldfs); 
+	return ret; 
+}
+
+#define ELF_CORE_COPY_XFPREGS 1
+static inline int 
+elf_core_copy_task_xfpregs(struct task_struct *t, elf_fpxregset_t *xfpu)
+{
+	struct pt_regs *regs = ((struct pt_regs *)(t->thread.rsp0))-1; 
+	if (!t->used_math) 
+		return 0;
+	if (t == current)
+		unlazy_fpu(t); 
+	memcpy(xfpu, &t->thread.i387.fxsave, sizeof(elf_fpxregset_t));
+	xfpu->fcs = regs->cs; 
+	xfpu->fos = t->thread.ds; /* right? */ 
+	return 1;
+}
+
 #undef elf_check_arch
 #define elf_check_arch(x) \
 	((x)->e_machine == EM_386)
@@ -168,9 +217,9 @@
 
 #undef start_thread
 #define start_thread(regs,new_rip,new_rsp) do { \
-	__asm__("movl %0,%%fs": :"r" (0)); \
-	__asm__("movl %0,%%es; movl %0,%%ds": :"r" (__USER32_DS)); \
-	wrmsrl(MSR_KERNEL_GS_BASE, 0); \
+	asm volatile("movl %0,%%fs" :: "r" (0)); \
+	asm volatile("movl %0,%%es; movl %0,%%ds": :"r" (__USER32_DS)); \
+	load_gs_index(0); \
 	(regs)->rip = (new_rip); \
 	(regs)->rsp = (new_rsp); \
 	(regs)->eflags = 0x200; \
@@ -182,6 +231,8 @@
 
 #define elf_map elf32_map
 
+#include <linux/module.h>
+
 MODULE_DESCRIPTION("Binary format loader for compatibility with IA32 ELF binaries."); 
 MODULE_AUTHOR("Eric Youngdale, Andi Kleen");
 
@@ -245,7 +296,7 @@
 		mpnt->vm_mm = mm;
 		mpnt->vm_start = PAGE_MASK & (unsigned long) bprm->p;
 		mpnt->vm_end = IA32_STACK_TOP;
-		mpnt->vm_page_prot = PAGE_COPY;
+		mpnt->vm_page_prot = PAGE_COPY_EXEC;
 		mpnt->vm_flags = VM_STACK_FLAGS;
 		mpnt->vm_ops = NULL;
 		mpnt->vm_pgoff = 0;
@@ -287,23 +338,3 @@
 	return(map_addr);
 }
 
-int dump_fpu_ia32(struct pt_regs *regs, elf_fpregset_t *fp)
-{
-	struct _fpstate_ia32 *fpu = (void*)fp; 
-	struct task_struct *tsk = current;
-	mm_segment_t oldfs = get_fs();
-	int ret;
-
-	if (!tsk->used_math) 
-		return 0;
-	if (!(test_thread_flag(TIF_IA32)))
-		BUG(); 
-	unlazy_fpu(tsk);
-	set_fs(KERNEL_DS); 
-	ret = save_i387_ia32(current, fpu, regs, 1);
-	/* Correct for i386 bug. It puts the fop into the upper 16bits of 
-	   the tag word (like FXSAVE), not into the fcs*/ 
-	fpu->cssel |= fpu->tag & 0xffff0000; 
-	set_fs(oldfs); 
-	return ret; 
-}
diff -Nru a/arch/x86_64/ia32/ia32_ioctl.c b/arch/x86_64/ia32/ia32_ioctl.c
--- a/arch/x86_64/ia32/ia32_ioctl.c	Mon Dec 23 21:21:55 2002
+++ b/arch/x86_64/ia32/ia32_ioctl.c	Mon Dec 23 21:21:55 2002
@@ -11,6 +11,7 @@
 
 #include <linux/config.h>
 #include <linux/types.h>
+#include <linux/compat.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/smp.h>
@@ -405,14 +406,9 @@
 	return err;
 }
 
-struct timeval32 {
-	int tv_sec;
-	int tv_usec;
-};
-
 static int do_siocgstamp(unsigned int fd, unsigned int cmd, unsigned long arg)
 {
-	struct timeval32 *up = (struct timeval32 *)arg;
+	struct compat_timeval *up = (struct compat_timeval *)arg;
 	struct timeval ktv;
 	mm_segment_t old_fs = get_fs();
 	int err;
@@ -1611,8 +1607,8 @@
 #define PPPIOCSCOMPRESS32	_IOW('t', 77, struct ppp_option_data32)
 
 struct ppp_idle32 {
-	__kernel_time_t32 xmit_idle;
-	__kernel_time_t32 recv_idle;
+	compat_time_t xmit_idle;
+	compat_time_t recv_idle;
 };
 #define PPPIOCGIDLE32		_IOR('t', 63, struct ppp_idle32)
 
@@ -1913,9 +1909,9 @@
 
 struct loop_info32 {
 	int			lo_number;      /* ioctl r/o */
-	__kernel_dev_t32	lo_device;      /* ioctl r/o */
+	compat_dev_t	lo_device;      /* ioctl r/o */
 	unsigned int		lo_inode;       /* ioctl r/o */
-	__kernel_dev_t32	lo_rdevice;     /* ioctl r/o */
+	compat_dev_t	lo_rdevice;     /* ioctl r/o */
 	int			lo_offset;
 	int			lo_encrypt_type;
 	int			lo_encrypt_key_size;    /* ioctl w/o */
@@ -2120,7 +2116,7 @@
 	set_fs(old_fs);
 
 	if (err >= 0)
-		err = put_user(kuid, (__kernel_uid_t32 *)arg);
+		err = put_user(kuid, (compat_pid_t *)arg);
 
 	return err;
 }
@@ -2779,543 +2775,6 @@
 }
 #endif
 
-#if defined(CONFIG_DRM) || defined(CONFIG_DRM_MODULE)
-/* This really belongs in include/linux/drm.h -DaveM */
-#include "../../../drivers/char/drm/drm.h"
-
-typedef struct drm32_version {
-	int    version_major;	  /* Major version			    */
-	int    version_minor;	  /* Minor version			    */
-	int    version_patchlevel;/* Patch level			    */
-	int    name_len;	  /* Length of name buffer		    */
-	u32    name;		  /* Name of driver			    */
-	int    date_len;	  /* Length of date buffer		    */
-	u32    date;		  /* User-space buffer to hold date	    */
-	int    desc_len;	  /* Length of desc buffer		    */
-	u32    desc;		  /* User-space buffer to hold desc	    */
-} drm32_version_t;
-#define DRM32_IOCTL_VERSION    DRM_IOWR(0x00, drm32_version_t)
-
-static int drm32_version(unsigned int fd, unsigned int cmd, unsigned long arg)
-{
-	drm32_version_t *uversion = (drm32_version_t *)arg;
-	char *name_ptr, *date_ptr, *desc_ptr;
-	u32 tmp1, tmp2, tmp3;
-	drm_version_t kversion;
-	mm_segment_t old_fs;
-	int ret;
-
-	memset(&kversion, 0, sizeof(kversion));
-	if (get_user(kversion.name_len, &uversion->name_len) ||
-	    get_user(kversion.date_len, &uversion->date_len) ||
-	    get_user(kversion.desc_len, &uversion->desc_len) ||
-	    get_user(tmp1, &uversion->name) ||
-	    get_user(tmp2, &uversion->date) ||
-	    get_user(tmp3, &uversion->desc))
-		return -EFAULT;
-
-	name_ptr = (char *) A(tmp1);
-	date_ptr = (char *) A(tmp2);
-	desc_ptr = (char *) A(tmp3);
-
-	ret = -ENOMEM;
-	if (kversion.name_len && name_ptr) {
-		kversion.name = kmalloc(kversion.name_len, GFP_KERNEL);
-		if (!kversion.name)
-			goto out;
-	}
-	if (kversion.date_len && date_ptr) {
-		kversion.date = kmalloc(kversion.date_len, GFP_KERNEL);
-		if (!kversion.date)
-			goto out;
-	}
-	if (kversion.desc_len && desc_ptr) {
-		kversion.desc = kmalloc(kversion.desc_len, GFP_KERNEL);
-		if (!kversion.desc)
-			goto out;
-	}
-
-        old_fs = get_fs();
-	set_fs(KERNEL_DS);
-        ret = sys_ioctl (fd, DRM_IOCTL_VERSION, (unsigned long)&kversion);
-        set_fs(old_fs);
-
-	if (!ret) {
-		if ((kversion.name &&
-		     copy_to_user(name_ptr, kversion.name, kversion.name_len)) ||
-		    (kversion.date &&
-		     copy_to_user(date_ptr, kversion.date, kversion.date_len)) ||
-		    (kversion.desc &&
-		     copy_to_user(desc_ptr, kversion.desc, kversion.desc_len)))
-			ret = -EFAULT;
-		if (put_user(kversion.version_major, &uversion->version_major) ||
-		    put_user(kversion.version_minor, &uversion->version_minor) ||
-		    put_user(kversion.version_patchlevel, &uversion->version_patchlevel) ||
-		    put_user(kversion.name_len, &uversion->name_len) ||
-		    put_user(kversion.date_len, &uversion->date_len) ||
-		    put_user(kversion.desc_len, &uversion->desc_len))
-			ret = -EFAULT;
-	}
-
-out:
-	if (kversion.name)
-		kfree(kversion.name);
-	if (kversion.date)
-		kfree(kversion.date);
-	if (kversion.desc)
-		kfree(kversion.desc);
-	return ret;
-}
-
-typedef struct drm32_unique {
-	int	unique_len;	  /* Length of unique			    */
-	u32	unique;		  /* Unique name for driver instantiation   */
-} drm32_unique_t;
-#define DRM32_IOCTL_GET_UNIQUE DRM_IOWR(0x01, drm32_unique_t)
-#define DRM32_IOCTL_SET_UNIQUE DRM_IOW( 0x10, drm32_unique_t)
-
-static int drm32_getsetunique(unsigned int fd, unsigned int cmd, unsigned long arg)
-{
-	drm32_unique_t *uarg = (drm32_unique_t *)arg;
-	drm_unique_t karg;
-	mm_segment_t old_fs;
-	char *uptr;
-	u32 tmp;
-	int ret;
-
-	if (get_user(karg.unique_len, &uarg->unique_len))
-		return -EFAULT;
-	karg.unique = NULL;
-
-	if (get_user(tmp, &uarg->unique))
-		return -EFAULT;
-
-	uptr = (char *) A(tmp);
-
-	if (uptr) {
-		karg.unique = kmalloc(karg.unique_len, GFP_KERNEL);
-		if (!karg.unique)
-			return -ENOMEM;
-		if (cmd == DRM32_IOCTL_SET_UNIQUE &&
-		    copy_from_user(karg.unique, uptr, karg.unique_len)) {
-			kfree(karg.unique);
-			return -EFAULT;
-		}
-	}
-
-	old_fs = get_fs();
-	set_fs(KERNEL_DS);
-	if (cmd == DRM32_IOCTL_GET_UNIQUE)
-		ret = sys_ioctl (fd, DRM_IOCTL_GET_UNIQUE, (unsigned long)&karg);
-	else
-		ret = sys_ioctl (fd, DRM_IOCTL_SET_UNIQUE, (unsigned long)&karg);
-        set_fs(old_fs);
-
-	if (!ret) {
-		if (cmd == DRM32_IOCTL_GET_UNIQUE &&
-		    uptr != NULL &&
-		    copy_to_user(uptr, karg.unique, karg.unique_len))
-			ret = -EFAULT;
-		if (put_user(karg.unique_len, &uarg->unique_len))
-			ret = -EFAULT;
-	}
-
-	if (karg.unique != NULL)
-		kfree(karg.unique);
-
-	return ret;
-}
-
-typedef struct drm32_map {
-	u32		offset;	 /* Requested physical address (0 for SAREA)*/
-	u32		size;	 /* Requested physical size (bytes)	    */
-	drm_map_type_t	type;	 /* Type of memory to map		    */
-	drm_map_flags_t flags;	 /* Flags				    */
-	u32		handle;  /* User-space: "Handle" to pass to mmap    */
-				 /* Kernel-space: kernel-virtual address    */
-	int		mtrr;	 /* MTRR slot used			    */
-				 /* Private data			    */
-} drm32_map_t;
-#define DRM32_IOCTL_ADD_MAP    DRM_IOWR(0x15, drm32_map_t)
-
-static int drm32_addmap(unsigned int fd, unsigned int cmd, unsigned long arg)
-{
-	drm32_map_t *uarg = (drm32_map_t *) arg;
-	drm_map_t karg;
-	mm_segment_t old_fs;
-	u32 tmp;
-	int ret;
-
-	ret  = get_user(karg.offset, &uarg->offset);
-	ret |= get_user(karg.size, &uarg->size);
-	ret |= get_user(karg.type, &uarg->type);
-	ret |= get_user(karg.flags, &uarg->flags);
-	ret |= get_user(tmp, &uarg->handle);
-	ret |= get_user(karg.mtrr, &uarg->mtrr);
-	if (ret)
-		return -EFAULT;
-
-	karg.handle = (void *) A(tmp);
-
-	old_fs = get_fs();
-	set_fs(KERNEL_DS);
-	ret = sys_ioctl(fd, DRM_IOCTL_ADD_MAP, (unsigned long) &karg);
-	set_fs(old_fs);
-
-	if (!ret) {
-		ret  = put_user(karg.offset, &uarg->offset);
-		ret |= put_user(karg.size, &uarg->size);
-		ret |= put_user(karg.type, &uarg->type);
-		ret |= put_user(karg.flags, &uarg->flags);
-		tmp = (u32) (long)karg.handle;
-		ret |= put_user(tmp, &uarg->handle);
-		ret |= put_user(karg.mtrr, &uarg->mtrr);
-		if (ret)
-			ret = -EFAULT;
-	}
-
-	return ret;
-}
-
-typedef struct drm32_buf_info {
-	int	       count;	/* Entries in list			     */
-	u32	       list;    /* (drm_buf_desc_t *) */ 
-} drm32_buf_info_t;
-#define DRM32_IOCTL_INFO_BUFS  DRM_IOWR(0x18, drm32_buf_info_t)
-
-static int drm32_info_bufs(unsigned int fd, unsigned int cmd, unsigned long arg)
-{
-	drm32_buf_info_t *uarg = (drm32_buf_info_t *)arg;
-	drm_buf_desc_t *ulist;
-	drm_buf_info_t karg;
-	mm_segment_t old_fs;
-	int orig_count, ret;
-	u32 tmp;
-
-	if (get_user(karg.count, &uarg->count) ||
-	    get_user(tmp, &uarg->list))
-		return -EFAULT;
-
-	ulist = (drm_buf_desc_t *) A(tmp);
-
-	orig_count = karg.count;
-
-	karg.list = kmalloc(karg.count * sizeof(drm_buf_desc_t), GFP_KERNEL);
-	if (!karg.list)
-		return -EFAULT;
-
-	old_fs = get_fs();
-	set_fs(KERNEL_DS);
-	ret = sys_ioctl(fd, DRM_IOCTL_INFO_BUFS, (unsigned long) &karg);
-	set_fs(old_fs);
-
-	if (!ret) {
-		if (karg.count <= orig_count &&
-		    (copy_to_user(ulist, karg.list,
-				  karg.count * sizeof(drm_buf_desc_t))))
-			ret = -EFAULT;
-		if (put_user(karg.count, &uarg->count))
-			ret = -EFAULT;
-	}
-
-	kfree(karg.list);
-
-	return ret;
-}
-
-typedef struct drm32_buf_free {
-	int	       count;
-	u32	       list;	/* (int *) */
-} drm32_buf_free_t;
-#define DRM32_IOCTL_FREE_BUFS  DRM_IOW( 0x1a, drm32_buf_free_t)
-
-static int drm32_free_bufs(unsigned int fd, unsigned int cmd, unsigned long arg)
-{
-	drm32_buf_free_t *uarg = (drm32_buf_free_t *)arg;
-	drm_buf_free_t karg;
-	mm_segment_t old_fs;
-	int *ulist;
-	int ret;
-	u32 tmp;
-
-	if (get_user(karg.count, &uarg->count) ||
-	    get_user(tmp, &uarg->list))
-		return -EFAULT;
-
-	ulist = (int *) A(tmp);
-
-	karg.list = kmalloc(karg.count * sizeof(int), GFP_KERNEL);
-	if (!karg.list)
-		return -ENOMEM;
-
-	ret = -EFAULT;
-	if (copy_from_user(karg.list, ulist, (karg.count * sizeof(int))))
-		goto out;
-
-	old_fs = get_fs();
-	set_fs(KERNEL_DS);
-	ret = sys_ioctl(fd, DRM_IOCTL_FREE_BUFS, (unsigned long) &karg);
-	set_fs(old_fs);
-
-out:
-	kfree(karg.list);
-
-	return ret;
-}
-
-typedef struct drm32_buf_pub {
-	int		  idx;	       /* Index into master buflist	     */
-	int		  total;       /* Buffer size			     */
-	int		  used;	       /* Amount of buffer in use (for DMA)  */
-	u32		  address;     /* Address of buffer (void *)	     */
-} drm32_buf_pub_t;
-
-typedef struct drm32_buf_map {
-	int	      count;	/* Length of buflist			    */
-	u32	      virtual;	/* Mmaped area in user-virtual (void *)	    */
-	u32 	      list;	/* Buffer information (drm_buf_pub_t *)	    */
-} drm32_buf_map_t;
-#define DRM32_IOCTL_MAP_BUFS   DRM_IOWR(0x19, drm32_buf_map_t)
-
-static int drm32_map_bufs(unsigned int fd, unsigned int cmd, unsigned long arg)
-{
-	drm32_buf_map_t *uarg = (drm32_buf_map_t *)arg;
-	drm32_buf_pub_t *ulist;
-	drm_buf_map_t karg;
-	mm_segment_t old_fs;
-	int orig_count, ret, i;
-	u32 tmp1, tmp2;
-
-	if (get_user(karg.count, &uarg->count) ||
-	    get_user(tmp1, &uarg->virtual) ||
-	    get_user(tmp2, &uarg->list))
-		return -EFAULT;
-
-	karg.virtual = (void *) A(tmp1);
-	ulist = (drm32_buf_pub_t *) A(tmp2);
-
-	orig_count = karg.count;
-
-	karg.list = kmalloc(karg.count * sizeof(drm_buf_pub_t), GFP_KERNEL);
-	if (!karg.list)
-		return -ENOMEM;
-
-	ret = -EFAULT;
-	for (i = 0; i < karg.count; i++) {
-		if (get_user(karg.list[i].idx, &ulist[i].idx) ||
-		    get_user(karg.list[i].total, &ulist[i].total) ||
-		    get_user(karg.list[i].used, &ulist[i].used) ||
-		    get_user(tmp1, &ulist[i].address))
-			goto out;
-
-		karg.list[i].address = (void *) A(tmp1);
-	}
-
-	old_fs = get_fs();
-	set_fs(KERNEL_DS);
-	ret = sys_ioctl(fd, DRM_IOCTL_MAP_BUFS, (unsigned long) &karg);
-	set_fs(old_fs);
-
-	if (!ret) {
-		for (i = 0; i < orig_count; i++) {
-			tmp1 = (u32) (long) karg.list[i].address;
-			if (put_user(karg.list[i].idx, &ulist[i].idx) ||
-			    put_user(karg.list[i].total, &ulist[i].total) ||
-			    put_user(karg.list[i].used, &ulist[i].used) ||
-			    put_user(tmp1, &ulist[i].address)) {
-				ret = -EFAULT;
-				goto out;
-			}
-		}
-		if (put_user(karg.count, &uarg->count))
-			ret = -EFAULT;
-	}
-
-out:
-	kfree(karg.list);
-	return ret;
-}
-
-typedef struct drm32_dma {
-				/* Indices here refer to the offset into
-				   buflist in drm_buf_get_t.  */
-	int		context;	  /* Context handle		    */
-	int		send_count;	  /* Number of buffers to send	    */
-	u32		send_indices;	  /* List of handles to buffers (int *) */
-	u32		send_sizes;	  /* Lengths of data to send (int *) */
-	drm_dma_flags_t flags;		  /* Flags			    */
-	int		request_count;	  /* Number of buffers requested    */
-	int		request_size;	  /* Desired size for buffers	    */
-	u32		request_indices;  /* Buffer information (int *)	    */
-	u32		request_sizes;    /* (int *) */
-	int		granted_count;	  /* Number of buffers granted	    */
-} drm32_dma_t;
-#define DRM32_IOCTL_DMA	     DRM_IOWR(0x29, drm32_dma_t)
-
-/* RED PEN	The DRM layer blindly dereferences the send/request
- * 		indice/size arrays even though they are userland
- * 		pointers.  -DaveM
- */
-static int drm32_dma(unsigned int fd, unsigned int cmd, unsigned long arg)
-{
-	drm32_dma_t *uarg = (drm32_dma_t *) arg;
-	int *u_si, *u_ss, *u_ri, *u_rs;
-	drm_dma_t karg;
-	mm_segment_t old_fs;
-	int ret;
-	u32 tmp1, tmp2, tmp3, tmp4;
-
-	karg.send_indices = karg.send_sizes = NULL;
-	karg.request_indices = karg.request_sizes = NULL;
-
-	if (get_user(karg.context, &uarg->context) ||
-	    get_user(karg.send_count, &uarg->send_count) ||
-	    get_user(tmp1, &uarg->send_indices) ||
-	    get_user(tmp2, &uarg->send_sizes) ||
-	    get_user(karg.flags, &uarg->flags) ||
-	    get_user(karg.request_count, &uarg->request_count) ||
-	    get_user(karg.request_size, &uarg->request_size) ||
-	    get_user(tmp3, &uarg->request_indices) ||
-	    get_user(tmp4, &uarg->request_sizes) ||
-	    get_user(karg.granted_count, &uarg->granted_count))
-		return -EFAULT;
-
-	u_si = (int *) A(tmp1);
-	u_ss = (int *) A(tmp2);
-	u_ri = (int *) A(tmp3);
-	u_rs = (int *) A(tmp4);
-
-	if (karg.send_count) {
-		karg.send_indices = kmalloc(karg.send_count * sizeof(int), GFP_KERNEL);
-		karg.send_sizes = kmalloc(karg.send_count * sizeof(int), GFP_KERNEL);
-
-		ret = -ENOMEM;
-		if (!karg.send_indices || !karg.send_sizes)
-			goto out;
-
-		ret = -EFAULT;
-		if (copy_from_user(karg.send_indices, u_si,
-				   (karg.send_count * sizeof(int))) ||
-		    copy_from_user(karg.send_sizes, u_ss,
-				   (karg.send_count * sizeof(int))))
-			goto out;
-	}
-
-	if (karg.request_count) {
-		karg.request_indices = kmalloc(karg.request_count * sizeof(int), GFP_KERNEL);
-		karg.request_sizes = kmalloc(karg.request_count * sizeof(int), GFP_KERNEL);
-
-		ret = -ENOMEM;
-		if (!karg.request_indices || !karg.request_sizes)
-			goto out;
-
-		ret = -EFAULT;
-		if (copy_from_user(karg.request_indices, u_ri,
-				   (karg.request_count * sizeof(int))) ||
-		    copy_from_user(karg.request_sizes, u_rs,
-				   (karg.request_count * sizeof(int))))
-			goto out;
-	}
-
-	old_fs = get_fs();
-	set_fs(KERNEL_DS);
-	ret = sys_ioctl(fd, DRM_IOCTL_DMA, (unsigned long) &karg);
-	set_fs(old_fs);
-
-	if (!ret) {
-		if (put_user(karg.context, &uarg->context) ||
-		    put_user(karg.send_count, &uarg->send_count) ||
-		    put_user(karg.flags, &uarg->flags) ||
-		    put_user(karg.request_count, &uarg->request_count) ||
-		    put_user(karg.request_size, &uarg->request_size) ||
-		    put_user(karg.granted_count, &uarg->granted_count))
-			ret = -EFAULT;
-
-		if (karg.send_count) {
-			if (copy_to_user(u_si, karg.send_indices,
-					 (karg.send_count * sizeof(int))) ||
-			    copy_to_user(u_ss, karg.send_sizes,
-					 (karg.send_count * sizeof(int))))
-				ret = -EFAULT;
-		}
-		if (karg.request_count) {
-			if (copy_to_user(u_ri, karg.request_indices,
-					 (karg.request_count * sizeof(int))) ||
-			    copy_to_user(u_rs, karg.request_sizes,
-					 (karg.request_count * sizeof(int))))
-				ret = -EFAULT;
-		}
-	}
-
-out:
-	if (karg.send_indices)
-		kfree(karg.send_indices);
-	if (karg.send_sizes)
-		kfree(karg.send_sizes);
-	if (karg.request_indices)
-		kfree(karg.request_indices);
-	if (karg.request_sizes)
-		kfree(karg.request_sizes);
-
-	return ret;
-}
-
-typedef struct drm32_ctx_res {
-	int		count;
-	u32		contexts; /* (drm_ctx_t *) */
-} drm32_ctx_res_t;
-#define DRM32_IOCTL_RES_CTX    DRM_IOWR(0x26, drm32_ctx_res_t)
-
-static int drm32_res_ctx(unsigned int fd, unsigned int cmd, unsigned long arg)
-{
-	drm32_ctx_res_t *uarg = (drm32_ctx_res_t *) arg;
-	drm_ctx_t *ulist;
-	drm_ctx_res_t karg;
-	mm_segment_t old_fs;
-	int orig_count, ret;
-	u32 tmp;
-
-	karg.contexts = NULL;
-	if (get_user(karg.count, &uarg->count) ||
-	    get_user(tmp, &uarg->contexts))
-		return -EFAULT;
-
-	ulist = (drm_ctx_t *) A(tmp);
-
-	orig_count = karg.count;
-	if (karg.count && ulist) {
-		karg.contexts = kmalloc((karg.count * sizeof(drm_ctx_t)), GFP_KERNEL);
-		if (!karg.contexts)
-			return -ENOMEM;
-		if (copy_from_user(karg.contexts, ulist,
-				   (karg.count * sizeof(drm_ctx_t)))) {
-			kfree(karg.contexts);
-			return -EFAULT;
-		}
-	}
-
-	old_fs = get_fs();
-	set_fs(KERNEL_DS);
-	ret = sys_ioctl(fd, DRM_IOCTL_RES_CTX, (unsigned long) &karg);
-	set_fs(old_fs);
-
-	if (!ret) {
-		if (orig_count) {
-			if (copy_to_user(ulist, karg.contexts,
-					 (orig_count * sizeof(drm_ctx_t))))
-				ret = -EFAULT;
-		}
-		if (put_user(karg.count, &uarg->count))
-			ret = -EFAULT;
-	}
-
-	if (karg.contexts)
-		kfree(karg.contexts);
-
-	return ret;
-}
-
-#endif
 
 static int ret_einval(unsigned int fd, unsigned int cmd, unsigned long arg)
 {
@@ -3491,7 +2950,7 @@
 
 struct dirent32 {
 	unsigned int		d_ino;
-	__kernel_off_t32	d_off;
+	compat_off_t	d_off;
 	unsigned short	d_reclen;
 	char		d_name[256]; /* We must not include limits.h! */
 };
@@ -4189,11 +3648,6 @@
 COMPATIBLE_IOCTL(FBIOGET_VSCREENINFO)
 COMPATIBLE_IOCTL(FBIOPUT_VSCREENINFO)
 COMPATIBLE_IOCTL(FBIOPAN_DISPLAY)
-COMPATIBLE_IOCTL(FBIOGET_FCURSORINFO)
-COMPATIBLE_IOCTL(FBIOGET_VCURSORINFO)
-COMPATIBLE_IOCTL(FBIOPUT_VCURSORINFO)
-COMPATIBLE_IOCTL(FBIOGET_CURSORSTATE)
-COMPATIBLE_IOCTL(FBIOPUT_CURSORSTATE)
 COMPATIBLE_IOCTL(FBIOGET_CON2FBMAP)
 COMPATIBLE_IOCTL(FBIOPUT_CON2FBMAP)
 /* Little f */
@@ -4696,27 +4150,6 @@
 COMPATIBLE_IOCTL(LV_BMAP)
 COMPATIBLE_IOCTL(LV_SNAPSHOT_USE_RATE)
 #endif /* LVM */
-#if defined(CONFIG_DRM) || defined(CONFIG_DRM_MODULE)
-COMPATIBLE_IOCTL(DRM_IOCTL_GET_MAGIC)
-COMPATIBLE_IOCTL(DRM_IOCTL_IRQ_BUSID)
-COMPATIBLE_IOCTL(DRM_IOCTL_AUTH_MAGIC)
-COMPATIBLE_IOCTL(DRM_IOCTL_BLOCK)
-COMPATIBLE_IOCTL(DRM_IOCTL_UNBLOCK)
-COMPATIBLE_IOCTL(DRM_IOCTL_CONTROL)
-COMPATIBLE_IOCTL(DRM_IOCTL_ADD_BUFS)
-COMPATIBLE_IOCTL(DRM_IOCTL_MARK_BUFS)
-COMPATIBLE_IOCTL(DRM_IOCTL_ADD_CTX)
-COMPATIBLE_IOCTL(DRM_IOCTL_RM_CTX)
-COMPATIBLE_IOCTL(DRM_IOCTL_MOD_CTX)
-COMPATIBLE_IOCTL(DRM_IOCTL_GET_CTX)
-COMPATIBLE_IOCTL(DRM_IOCTL_SWITCH_CTX)
-COMPATIBLE_IOCTL(DRM_IOCTL_NEW_CTX)
-COMPATIBLE_IOCTL(DRM_IOCTL_ADD_DRAW)
-COMPATIBLE_IOCTL(DRM_IOCTL_RM_DRAW)
-COMPATIBLE_IOCTL(DRM_IOCTL_LOCK)
-COMPATIBLE_IOCTL(DRM_IOCTL_UNLOCK)
-COMPATIBLE_IOCTL(DRM_IOCTL_FINISH)
-#endif /* DRM */
 #ifdef CONFIG_AUTOFS_FS
 COMPATIBLE_IOCTL(AUTOFS_IOC_READY)
 COMPATIBLE_IOCTL(AUTOFS_IOC_FAIL)
@@ -4941,7 +4374,7 @@
 HANDLE_IOCTL(VIDIOCGFREQ32, do_video_ioctl)
 HANDLE_IOCTL(VIDIOCSFREQ32, do_video_ioctl)
 /* One SMB ioctl needs translations. */
-#define SMB_IOC_GETMOUNTUID_32 _IOR('u', 1, __kernel_uid_t32)
+#define SMB_IOC_GETMOUNTUID_32 _IOR('u', 1, compat_pid_t)
 HANDLE_IOCTL(SMB_IOC_GETMOUNTUID_32, do_smb_getmountuid)
 HANDLE_IOCTL(ATM_GETLINKRATE32, do_atm_ioctl)
 HANDLE_IOCTL(ATM_GETNAMES32, do_atm_ioctl)
@@ -4984,17 +4417,6 @@
 HANDLE_IOCTL(VG_CREATE_OLD, do_lvm_ioctl)
 HANDLE_IOCTL(LV_STATUS_BYDEV, do_lvm_ioctl)
 #endif /* LVM */
-#if defined(CONFIG_DRM) || defined(CONFIG_DRM_MODULE)
-HANDLE_IOCTL(DRM32_IOCTL_VERSION, drm32_version)
-HANDLE_IOCTL(DRM32_IOCTL_GET_UNIQUE, drm32_getsetunique)
-HANDLE_IOCTL(DRM32_IOCTL_SET_UNIQUE, drm32_getsetunique)
-HANDLE_IOCTL(DRM32_IOCTL_ADD_MAP, drm32_addmap)
-HANDLE_IOCTL(DRM32_IOCTL_INFO_BUFS, drm32_info_bufs)
-HANDLE_IOCTL(DRM32_IOCTL_FREE_BUFS, drm32_free_bufs)
-HANDLE_IOCTL(DRM32_IOCTL_MAP_BUFS, drm32_map_bufs)
-HANDLE_IOCTL(DRM32_IOCTL_DMA, drm32_dma)
-HANDLE_IOCTL(DRM32_IOCTL_RES_CTX, drm32_res_ctx)
-#endif /* DRM */
 /* VFAT */
 HANDLE_IOCTL(VFAT_IOCTL_READDIR_BOTH32, vfat_ioctl32)
 HANDLE_IOCTL(VFAT_IOCTL_READDIR_SHORT32, vfat_ioctl32)
@@ -5179,7 +4601,7 @@
 EXPORT_SYMBOL(register_ioctl32_conversion); 
 EXPORT_SYMBOL(unregister_ioctl32_conversion); 
 
-asmlinkage int sys32_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
+asmlinkage long sys32_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
 {
 	struct file * filp;
 	int error = -EBADF;
diff -Nru a/arch/x86_64/ia32/ia32_signal.c b/arch/x86_64/ia32/ia32_signal.c
--- a/arch/x86_64/ia32/ia32_signal.c	Mon Dec 23 21:22:00 2002
+++ b/arch/x86_64/ia32/ia32_signal.c	Mon Dec 23 21:22:00 2002
@@ -76,7 +76,7 @@
 	}
 }
 
-asmlinkage int
+asmlinkage long
 sys32_sigsuspend(int history0, int history1, old_sigset_t mask, struct pt_regs regs)
 {
 	sigset_t saveset;
@@ -97,7 +97,7 @@
 	}
 }
 
-asmlinkage int
+asmlinkage long
 sys32_sigaltstack(const stack_ia32_t *uss_ptr, stack_ia32_t *uoss_ptr, 
 				  struct pt_regs regs)
 {
@@ -227,7 +227,7 @@
 	return 1;
 }
 
-asmlinkage int sys32_sigreturn(struct pt_regs regs)
+asmlinkage long sys32_sigreturn(struct pt_regs regs)
 {
 	struct sigframe *frame = (struct sigframe *)(regs.rsp - 8);
 	sigset_t set;
@@ -256,7 +256,7 @@
 	return 0;
 }	
 
-asmlinkage int sys32_rt_sigreturn(struct pt_regs regs)
+asmlinkage long sys32_rt_sigreturn(struct pt_regs regs)
 {
 	struct rt_sigframe *frame = (struct rt_sigframe *)(regs.rsp - 4);
 	sigset_t set;
diff -Nru a/arch/x86_64/ia32/ia32entry.S b/arch/x86_64/ia32/ia32entry.S
--- a/arch/x86_64/ia32/ia32entry.S	Mon Dec 23 21:21:54 2002
+++ b/arch/x86_64/ia32/ia32entry.S	Mon Dec 23 21:21:54 2002
@@ -1,7 +1,7 @@
 /*
  * Compatibility mode system call entry point for x86-64. 
  * 		
- * Copyright 2000,2001 Andi Kleen, SuSE Labs.
+ * Copyright 2000-2002 Andi Kleen, SuSE Labs.
  * 
  * $Id: ia32entry.S,v 1.31 2002/03/24 13:01:45 ak Exp $ 		
  */		 
@@ -9,10 +9,11 @@
 #include <asm/calling.h>
 #include <asm/offset.h>
 #include <asm/current.h>
-#include <linux/linkage.h>
 #include <asm/errno.h>
 #include <asm/ia32_unistd.h>	
 #include <asm/thread_info.h>	
+#include <asm/segment.h>
+#include <linux/linkage.h>
 
 	.macro IA32_ARG_FIXUP
 	movl	%edi,%r8d
@@ -23,12 +24,73 @@
 	.endm 
 
 /*
- * 32bit SYSCALL instruction entry. 	
+ * 32bit SYSCALL instruction entry. This is called from the 32bit vsyscall page.
+ *	
+ * Register setup:
+ *
+ * %eax	System call number.
+ * %ebx Arg1
+ * %ecx return EIP 
+ * %edx Arg3
+ * %esi Arg4
+ * %edi Arg5
+ * %ebp Arg2    [note: not saved in the stack frame, should not be touched]
+ * %esp user stack 
+ * 0(%esp) Arg6
+ * 	
+ * Interrupts off.
+ *	
+ * This is purely a fast path. For anything complicated we use the int 0x80
+ * path below.	Set up a complete hardware stack frame to share code
+ * with the int 0x80 path.	
  */ 	
 ENTRY(ia32_cstar_target)
-	movq $-ENOSYS,%rax
+	swapgs
+	movl	%esp,%r8d
+	movq	%gs:pda_kernelstack,%rsp
+	sti
+	SAVE_ARGS 8,1
+	movl 	%eax,%eax	/* zero extension */
+	movq	%rax,ORIG_RAX-ARGOFFSET(%rsp)
+	movq	%rcx,RIP-ARGOFFSET(%rsp)
+	movl	%ebp,%ecx
+	movq	$__USER32_CS,CS-ARGOFFSET(%rsp)
+	movq	$__USER32_DS,SS-ARGOFFSET(%rsp)
+	movq	%r11,EFLAGS-ARGOFFSET(%rsp)
+	movq	%r8,RSP-ARGOFFSET(%rsp)	
+	/* no need to do an access_ok check here because the 32bit
+	   user space cannot set r8 to a value > 4GB and the kernel has no
+	   memory mapping in the first 4GB. */
+	/* hardware stack frame is complete now */	
+1:	movl	(%r8),%ebp
+	.section __ex_table,"a"
+	.quad 1b,cstar_badarg
+	.previous	
+	GET_THREAD_INFO(%r10)
+	bt  $TIF_SYSCALL_TRACE,threadinfo_flags(%r10)
+	jc  ia32_tracesys
+	cmpl $IA32_NR_syscalls,%eax
+	jae  ia32_badsys
+	IA32_ARG_FIXUP
+	call *ia32_sys_call_table(,%rax,8)
+	.globl ia32_sysret
+cstar_sysret:	
+	movq %rax,RAX-ARGOFFSET(%rsp)
+	GET_THREAD_INFO(%r10)
+	cli
+	testl $_TIF_WORK_MASK,threadinfo_flags(%r10)
+	jnz int_ret_from_sys_call
+	RESTORE_ARGS 1,0,1,1	/* could avoid the stack restore here */
+	movl RIP-SWFRAME(%rsp),%ecx
+	movl RSP-SWFRAME(%rsp),%esp
+	movl EFLAGS-SWFRAME(%rsp),%r11d
+	swapgs
 	sysretl
 	
+cstar_badarg:
+	movq $-EFAULT,%rax
+	jmp cstar_sysret
+
 /* 
  * Emulated IA32 system calls via int 0x80. 
  *
@@ -121,7 +183,7 @@
 	.align 8
 	.globl ia32_sys_call_table
 ia32_sys_call_table:
-	.quad ni_syscall	/* 0  -  old "setup" system call*/
+	.quad sys_restart_syscall
 	.quad sys_exit
 	.quad stub32_fork
 	.quad sys_read
@@ -151,7 +213,7 @@
 	.quad sys_alarm		/* XXX sign extension??? */ 
 	.quad ni_syscall	/* (old)fstat */
 	.quad sys_pause
-	.quad sys32_utime	/* 30 */
+	.quad compat_sys_utime	/* 30 */
 	.quad ni_syscall	/* old stty syscall holder */
 	.quad ni_syscall	/* old gtty syscall holder */
 	.quad sys_access
@@ -164,7 +226,7 @@
 	.quad sys_rmdir		/* 40 */
 	.quad sys_dup
 	.quad sys32_pipe
-	.quad sys32_times
+	.quad compat_sys_times
 	.quad ni_syscall			/* old prof syscall holder */
 	.quad sys_brk		/* 45 */
 	.quad sys_setgid16
@@ -225,11 +287,11 @@
 	.quad sys_ioperm
 	.quad sys32_socketcall
 	.quad sys_syslog
-	.quad sys32_setitimer
-	.quad sys32_getitimer	/* 105 */
-	.quad sys32_newstat
-	.quad sys32_newlstat
-	.quad sys32_newfstat
+	.quad compat_sys_setitimer
+	.quad compat_sys_getitimer	/* 105 */
+	.quad compat_sys_newstat
+	.quad compat_sys_newlstat
+	.quad compat_sys_newfstat
 	.quad sys32_uname
 	.quad stub32_iopl		/* 110 */
 	.quad sys_vhangup
@@ -283,7 +345,7 @@
 	.quad sys_sched_get_priority_max
 	.quad sys_sched_get_priority_min  /* 160 */
 	.quad sys_sched_rr_get_interval
-	.quad sys32_nanosleep
+	.quad compat_sys_nanosleep
 	.quad sys_mremap
 	.quad sys_setresuid16
 	.quad sys_getresuid16	/* 165 */
@@ -361,7 +423,7 @@
 	.quad sys_fremovexattr
 	.quad sys_tkill		/* 238 */ 
 	.quad sys_sendfile64 
-	.quad sys_futex		/* 240 */
+	.quad sys32_futex		/* 240 */
         .quad sys32_sched_setaffinity
         .quad sys32_sched_getaffinity
 	.quad sys_set_thread_area
@@ -374,6 +436,14 @@
 	.quad sys_ni_syscall /* 250 alloc_huge_pages */
 	.quad sys_ni_syscall /* free_huge_pages */
 	.quad sys_exit_group /* exit_group */
+	.quad sys_lookup_dcookie
+	.quad sys_epoll_create
+	.quad sys_epoll_ctl
+	.quad sys_epoll_wait
+	.quad sys_remap_file_pages
+	.quad sys_set_tid_address
+	
+	/* don't forget to change IA32_NR_syscalls */
 ia32_syscall_end:		
 	.rept IA32_NR_syscalls-(ia32_syscall_end-ia32_sys_call_table)/8
 		.quad ni_syscall
diff -Nru a/arch/x86_64/ia32/ipc32.c b/arch/x86_64/ia32/ipc32.c
--- a/arch/x86_64/ia32/ipc32.c	Mon Dec 23 21:21:53 2002
+++ b/arch/x86_64/ia32/ipc32.c	Mon Dec 23 21:21:54 2002
@@ -8,6 +8,7 @@
 #include <linux/shm.h>
 #include <linux/slab.h>
 #include <linux/ipc.h>
+#include <linux/compat.h>
 #include <asm/mman.h>
 #include <asm/types.h>
 #include <asm/uaccess.h>
@@ -29,10 +30,10 @@
 
 struct ipc_perm32 {
 	int key;
-	__kernel_uid_t32 uid;
-	__kernel_gid_t32 gid;
-	__kernel_uid_t32 cuid;
-	__kernel_gid_t32 cgid;
+	compat_uid_t uid;
+	compat_gid_t gid;
+	compat_uid_t cuid;
+	compat_gid_t cgid;
 	unsigned short mode;
 	unsigned short seq;
 };
@@ -53,8 +54,8 @@
 
 struct semid_ds32 {
 	struct ipc_perm32 sem_perm;               /* permissions .. see ipc.h */
-	__kernel_time_t32 sem_otime;              /* last semop time */
-	__kernel_time_t32 sem_ctime;              /* last change time */
+	compat_time_t sem_otime;              /* last semop time */
+	compat_time_t sem_ctime;              /* last change time */
 	u32 sem_base;              /* ptr to first semaphore in array */
 	u32 sem_pending;          /* pending operations to be processed */
 	u32 sem_pending_last;    /* last pending operation */
@@ -64,9 +65,9 @@
 
 struct semid64_ds32 {
 	struct ipc64_perm32 sem_perm;
-	__kernel_time_t32 sem_otime;
+	compat_time_t sem_otime;
 	unsigned int __unused1;
-	__kernel_time_t32 sem_ctime;
+	compat_time_t sem_ctime;
 	unsigned int __unused2;
 	unsigned int sem_nsems;
 	unsigned int __unused3;
@@ -77,9 +78,9 @@
 	struct ipc_perm32 msg_perm;
 	u32 msg_first;
 	u32 msg_last;
-	__kernel_time_t32 msg_stime;
-	__kernel_time_t32 msg_rtime;
-	__kernel_time_t32 msg_ctime;
+	compat_time_t msg_stime;
+	compat_time_t msg_rtime;
+	compat_time_t msg_ctime;
 	u32 wwait;
 	u32 rwait;
 	unsigned short msg_cbytes;
@@ -91,17 +92,17 @@
 
 struct msqid64_ds32 {
 	struct ipc64_perm32 msg_perm;
-	__kernel_time_t32 msg_stime;
+	compat_time_t msg_stime;
 	unsigned int __unused1;
-	__kernel_time_t32 msg_rtime;
+	compat_time_t msg_rtime;
 	unsigned int __unused2;
-	__kernel_time_t32 msg_ctime;
+	compat_time_t msg_ctime;
 	unsigned int __unused3;
 	unsigned int msg_cbytes;
 	unsigned int msg_qnum;
 	unsigned int msg_qbytes;
-	__kernel_pid_t32 msg_lspid;
-	__kernel_pid_t32 msg_lrpid;
+	compat_pid_t msg_lspid;
+	compat_pid_t msg_lrpid;
 	unsigned int __unused4;
 	unsigned int __unused5;
 };
@@ -109,9 +110,9 @@
 struct shmid_ds32 {
 	struct ipc_perm32 shm_perm;
 	int shm_segsz;
-	__kernel_time_t32 shm_atime;
-	__kernel_time_t32 shm_dtime;
-	__kernel_time_t32 shm_ctime;
+	compat_time_t shm_atime;
+	compat_time_t shm_dtime;
+	compat_time_t shm_ctime;
 	__kernel_ipc_pid_t32 shm_cpid;
 	__kernel_ipc_pid_t32 shm_lpid;
 	unsigned short shm_nattch;
@@ -119,15 +120,15 @@
 
 struct shmid64_ds32 {
 	struct ipc64_perm32 shm_perm;
-	__kernel_size_t32 shm_segsz;
-	__kernel_time_t32 shm_atime;
+	compat_size_t shm_segsz;
+	compat_time_t shm_atime;
 	unsigned int __unused1;
-	__kernel_time_t32 shm_dtime;
+	compat_time_t shm_dtime;
 	unsigned int __unused2;
-	__kernel_time_t32 shm_ctime;
+	compat_time_t shm_ctime;
 	unsigned int __unused3;
-	__kernel_pid_t32 shm_cpid;
-	__kernel_pid_t32 shm_lpid;
+	compat_pid_t shm_cpid;
+	compat_pid_t shm_lpid;
 	unsigned int shm_nattch;
 	unsigned int __unused4;
 	unsigned int __unused5;
@@ -163,6 +164,7 @@
 #define SEMOP		 1
 #define SEMGET		 2
 #define SEMCTL		 3
+#define TIMEDSEMOP	 4
 #define MSGSND		11
 #define MSGRCV		12
 #define MSGGET		13
@@ -622,7 +624,12 @@
 	switch (call) {
 	      case SEMOP:
 		/* struct sembuf is the same on 32 and 64bit :)) */
-		return sys_semop(first, (struct sembuf *)AA(ptr), second);
+		return sys_semtimedop(first, (struct sembuf *)AA(ptr), second,
+				      NULL);
+	      case TIMEDSEMOP:
+		/* struct sembuf is the same on 32 and 64bit :)) */
+		return sys_semtimedop(first, (struct sembuf *)AA(ptr), second,
+				      (const struct timespec *)AA(fifth));
 	      case SEMGET:
 		return sys_semget(first, second, third);
 	      case SEMCTL:
@@ -646,7 +653,6 @@
 		return sys_shmget(first, second, third);
 	      case SHMCTL:
 		return shmctl32(first, second, (void *)AA(ptr));
-
 	      default:
 		return -EINVAL;
 	}
diff -Nru a/arch/x86_64/ia32/socket32.c b/arch/x86_64/ia32/socket32.c
--- a/arch/x86_64/ia32/socket32.c	Mon Dec 23 21:21:51 2002
+++ b/arch/x86_64/ia32/socket32.c	Mon Dec 23 21:21:51 2002
@@ -19,6 +19,7 @@
 #include <linux/icmpv6.h>
 #include <linux/socket.h>
 #include <linux/filter.h>
+#include <linux/compat.h>
 
 #include <net/scm.h>
 #include <net/sock.h>
@@ -29,6 +30,9 @@
 #define A(__x)		((unsigned long)(__x))
 #define AA(__x)		((unsigned long)(__x))
 
+extern asmlinkage long sys_getsockopt(int fd, int level, int optname,
+				       void * optval, int *optlen);
+
 
 static inline int iov_from_user32_to_kern(struct iovec *kiov,
 					  struct iovec32 *uiov32,
@@ -123,7 +127,7 @@
 {
 	struct cmsghdr32 *ucmsg;
 	struct cmsghdr *kcmsg, *kcmsg_base;
-	__kernel_size_t32 ucmlen;
+	compat_size_t ucmlen;
 	__kernel_size_t kcmlen, tmp;
 
 	kcmlen = 0;
@@ -362,7 +366,7 @@
 	kmsg->msg_control = (void *) orig_cmsg_uptr;
 }
 
-asmlinkage int sys32_sendmsg(int fd, struct msghdr32 *user_msg, unsigned user_flags)
+asmlinkage long sys32_sendmsg(int fd, struct msghdr32 *user_msg, unsigned user_flags)
 {
 	struct socket *sock;
 	char address[MAX_SOCK_ADDR];
@@ -407,7 +411,7 @@
 	return err;
 }
 
-asmlinkage int sys32_recvmsg(int fd, struct msghdr32 *user_msg, unsigned int user_flags)
+asmlinkage long sys32_recvmsg(int fd, struct msghdr32 *user_msg, unsigned int user_flags)
 {
 	struct iovec iovstack[UIO_FASTIOV];
 	struct msghdr kern_msg;
@@ -489,7 +493,7 @@
 		err = move_addr_to_user(addr, kern_msg.msg_namelen, uaddr, uaddr_len);
 	if(cmsg_ptr != 0 && err >= 0) {
 		unsigned long ucmsg_ptr = ((unsigned long)kern_msg.msg_control);
-		__kernel_size_t32 uclen = (__kernel_size_t32) (ucmsg_ptr - cmsg_ptr);
+		compat_size_t uclen = (compat_size_t) (ucmsg_ptr - cmsg_ptr);
 		err |= __put_user(uclen, &user_msg->msg_controllen);
 	}
 	if(err >= 0)
@@ -575,12 +579,34 @@
 	return ret;
 }
 
-asmlinkage int sys32_setsockopt(int fd, int level, int optname,
+static int do_set_sock_timeout(int fd, int level, int optname, char *optval, int optlen)
+{
+	struct compat_timeval *up = (struct compat_timeval *) optval;
+	struct timeval ktime;
+	mm_segment_t old_fs;
+	int err;
+
+	if (optlen < sizeof(*up))
+		return -EINVAL;
+	if (get_user(ktime.tv_sec, &up->tv_sec) ||
+	    __get_user(ktime.tv_usec, &up->tv_usec))
+		return -EFAULT;
+	old_fs = get_fs();
+	set_fs(KERNEL_DS);
+	err = sys_setsockopt(fd, level, optname, (char *) &ktime, sizeof(ktime));
+	set_fs(old_fs);
+
+	return err;
+}
+
+asmlinkage long sys32_setsockopt(int fd, int level, int optname,
 				char *optval, int optlen)
 {
 	if (optname == SO_ATTACH_FILTER)
 		return do_set_attach_filter(fd, level, optname,
 					    optval, optlen);
+	if (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)
+		return do_set_sock_timeout(fd, level, optname, optval, optlen);
 	if (level == SOL_ICMPV6 && optname == ICMPV6_FILTER)
 		return do_set_icmpv6_filter(fd, level, optname,
 					    optval, optlen);
@@ -588,6 +614,39 @@
 	return sys_setsockopt(fd, level, optname, optval, optlen);
 }
 
+static int do_get_sock_timeout(int fd, int level, int optname, char *optval, int *optlen)
+{
+	struct compat_timeval *up = (struct compat_timeval *) optval;
+	struct timeval ktime;
+	mm_segment_t old_fs;
+	int len, err;
+
+	if (get_user(len, optlen))
+		return -EFAULT;
+	if (len < sizeof(*up))
+		return -EINVAL;
+	len = sizeof(ktime);
+	old_fs = get_fs();
+	set_fs(KERNEL_DS);
+	err = sys_getsockopt(fd, level, optname, (char *) &ktime, &len);
+	set_fs(old_fs);
+
+	if (!err) {
+		if (put_user(sizeof(*up), optlen) ||
+		    put_user(ktime.tv_sec, &up->tv_sec) ||
+		    __put_user(ktime.tv_usec, &up->tv_usec))
+			err = -EFAULT;
+	}
+	return err;
+}
+
+asmlinkage long sys32_getsockopt(int fd, int level, int optname,
+				char *optval, int *optlen)
+{
+	if (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)
+		return do_get_sock_timeout(fd, level, optname, optval, optlen);
+	return sys_getsockopt(fd, level, optname, optval, optlen);
+}
 
 /* Argument list sizes for sys_socketcall */
 #define AL(x) ((x) * sizeof(u32))
@@ -606,14 +665,11 @@
 extern asmlinkage long sys_getpeername(int fd, struct sockaddr *usockaddr,
 				      int *usockaddr_len);
 extern asmlinkage long sys_send(int fd, void *buff, size_t len, unsigned flags);
-extern asmlinkage long sys_sendto(int fd, u32 buff, __kernel_size_t32 len,
+extern asmlinkage long sys_sendto(int fd, u32 buff, compat_size_t len,
 				   unsigned flags, u32 addr, int addr_len);
 extern asmlinkage long sys_recv(int fd, void *ubuf, size_t size, unsigned flags);
-extern asmlinkage long sys_recvfrom(int fd, u32 ubuf, __kernel_size_t32 size,
+extern asmlinkage long sys_recvfrom(int fd, u32 ubuf, compat_size_t size,
 				     unsigned flags, u32 addr, u32 addr_len);
-extern asmlinkage long sys_getsockopt(int fd, int level, int optname,
-				       u32 optval, u32 optlen);
-
 extern asmlinkage long sys_socket(int family, int type, int protocol);
 extern asmlinkage long sys_socketpair(int family, int type, int protocol,
 				     int usockvec[2]);
@@ -678,11 +734,11 @@
 			ret = sys_shutdown(a0,a1);
 			break;
 		case SYS_SETSOCKOPT:
-			ret = sys_setsockopt(a0, a1, a[2], (char *)A(a[3]),
+			ret = sys32_setsockopt(a0, a1, a[2], (char *)A(a[3]),
 					      a[4]);
 			break;
 		case SYS_GETSOCKOPT:
-			ret = sys_getsockopt(a0, a1, a[2], a[3], a[4]);
+			ret = sys32_getsockopt(a0, a1, a[2], (char *)(u64)a[3], (int *)(u64)a[4]);
 			break;
 		case SYS_SENDMSG:
 			ret = sys32_sendmsg(a0, (struct msghdr32 *)A(a1),
diff -Nru a/arch/x86_64/ia32/sys_ia32.c b/arch/x86_64/ia32/sys_ia32.c
--- a/arch/x86_64/ia32/sys_ia32.c	Mon Dec 23 21:21:53 2002
+++ b/arch/x86_64/ia32/sys_ia32.c	Mon Dec 23 21:21:53 2002
@@ -26,7 +26,6 @@
 #include <linux/fs.h> 
 #include <linux/file.h> 
 #include <linux/signal.h>
-#include <linux/utime.h>
 #include <linux/resource.h>
 #include <linux/times.h>
 #include <linux/utsname.h>
@@ -58,6 +57,7 @@
 #include <linux/binfmts.h>
 #include <linux/init.h>
 #include <linux/aio_abi.h>
+#include <linux/compat.h>
 #include <asm/mman.h>
 #include <asm/types.h>
 #include <asm/uaccess.h>
@@ -86,78 +86,29 @@
 extern int overflowuid,overflowgid; 
 
 
-static int
-putstat(struct stat32 *ubuf, struct stat *kbuf)
+int cp_compat_stat(struct kstat *kbuf, struct compat_stat *ubuf)
 {
-	if (verify_area(VERIFY_WRITE, ubuf, sizeof(struct stat32)) ||
-	    __put_user (kbuf->st_dev, &ubuf->st_dev) ||
-	    __put_user (kbuf->st_ino, &ubuf->st_ino) ||
-	    __put_user (kbuf->st_mode, &ubuf->st_mode) ||
-	    __put_user (kbuf->st_nlink, &ubuf->st_nlink) ||
-	    __put_user (kbuf->st_uid, &ubuf->st_uid) ||
-	    __put_user (kbuf->st_gid, &ubuf->st_gid) ||
-	    __put_user (kbuf->st_rdev, &ubuf->st_rdev) ||
-	    __put_user (kbuf->st_size, &ubuf->st_size) ||
-	    __put_user (kbuf->st_atime, &ubuf->st_atime) ||
-	    __put_user (kbuf->st_mtime, &ubuf->st_mtime) ||
-	    __put_user (kbuf->st_ctime, &ubuf->st_ctime) ||
-	    __put_user (kbuf->st_blksize, &ubuf->st_blksize) ||
-	    __put_user (kbuf->st_blocks, &ubuf->st_blocks))
+	if (verify_area(VERIFY_WRITE, ubuf, sizeof(struct compat_stat)) ||
+	    __put_user (kbuf->dev, &ubuf->st_dev) ||
+	    __put_user (kbuf->ino, &ubuf->st_ino) ||
+	    __put_user (kbuf->mode, &ubuf->st_mode) ||
+	    __put_user (kbuf->nlink, &ubuf->st_nlink) ||
+	    __put_user (kbuf->uid, &ubuf->st_uid) ||
+	    __put_user (kbuf->gid, &ubuf->st_gid) ||
+	    __put_user (kbuf->rdev, &ubuf->st_rdev) ||
+	    __put_user (kbuf->size, &ubuf->st_size) ||
+	    __put_user (kbuf->atime.tv_sec, &ubuf->st_atime) ||
+	    __put_user (kbuf->atime.tv_nsec, &ubuf->st_atime_nsec) ||
+	    __put_user (kbuf->mtime.tv_sec, &ubuf->st_mtime) ||
+	    __put_user (kbuf->mtime.tv_nsec, &ubuf->st_mtime_nsec) ||
+	    __put_user (kbuf->ctime.tv_sec, &ubuf->st_ctime) ||
+	    __put_user (kbuf->ctime.tv_nsec, &ubuf->st_ctime_nsec) ||
+	    __put_user (kbuf->blksize, &ubuf->st_blksize) ||
+	    __put_user (kbuf->blocks, &ubuf->st_blocks))
 		return -EFAULT;
 	return 0;
 }
 
-extern asmlinkage long sys_newstat(char * filename, struct stat * statbuf);
-
-asmlinkage long
-sys32_newstat(char * filename, struct stat32 *statbuf)
-{
-	int ret;
-	struct stat s;
-	mm_segment_t old_fs = get_fs();
-	
-	set_fs (KERNEL_DS);
-	ret = sys_newstat(filename, &s);
-	set_fs (old_fs);
-	if (putstat (statbuf, &s))
-		return -EFAULT;
-	return ret;
-}
-
-extern asmlinkage long sys_newlstat(char * filename, struct stat * statbuf);
-
-asmlinkage long
-sys32_newlstat(char * filename, struct stat32 *statbuf)
-{
-	int ret;
-	struct stat s;
-	mm_segment_t old_fs = get_fs();
-	
-	set_fs (KERNEL_DS);
-	ret = sys_newlstat(filename, &s);
-	set_fs (old_fs);
-	if (putstat (statbuf, &s))
-		return -EFAULT;
-	return ret;
-}
-
-extern asmlinkage long sys_newfstat(unsigned int fd, struct stat * statbuf);
-
-asmlinkage long
-sys32_newfstat(unsigned int fd, struct stat32 *statbuf)
-{
-	int ret;
-	struct stat s;
-	mm_segment_t old_fs = get_fs();
-	
-	set_fs (KERNEL_DS);
-	ret = sys_newfstat(fd, &s);
-	set_fs (old_fs);
-	if (putstat (statbuf, &s))
-		return -EFAULT;
-	return ret;
-}
-
 /* Another set for IA32/LFS -- x86_64 struct stat is different due to 
    support for 64bit inode numbers. */
 
@@ -175,8 +126,11 @@
 	    __put_user (kbuf->st_rdev, &ubuf->st_rdev) ||
 	    __put_user (kbuf->st_size, &ubuf->st_size) ||
 	    __put_user (kbuf->st_atime, &ubuf->st_atime) ||
+	    __put_user (kbuf->st_atime_nsec, &ubuf->st_atime_nsec) ||
 	    __put_user (kbuf->st_mtime, &ubuf->st_mtime) ||
+	    __put_user (kbuf->st_mtime_nsec, &ubuf->st_mtime_nsec) ||
 	    __put_user (kbuf->st_ctime, &ubuf->st_ctime) ||
+	    __put_user (kbuf->st_ctime_nsec, &ubuf->st_ctime_nsec) ||
 	    __put_user (kbuf->st_blksize, &ubuf->st_blksize) ||
 	    __put_user (kbuf->st_blocks, &ubuf->st_blocks))
 		return -EFAULT;
@@ -245,7 +199,7 @@
 	unsigned int offset;
 };
 
-asmlinkage __u32
+asmlinkage long
 sys32_mmap(struct mmap_arg_struct *arg)
 {
 	struct mmap_arg_struct a;
@@ -265,10 +219,8 @@
 			return -EBADF;
 	}
 	
-#if 0 /* reenable when noexec works */
 	if (a.prot & PROT_READ) 
 		a.prot |= PROT_EXEC; 
-#endif
 
 	a.flags |= MAP_32BIT;
 
@@ -279,7 +231,7 @@
 		fput(file);
 
 	/* Cannot wrap */
-	if (retval+a.len >= 0xFFFFFFFF && (long)retval > 0) { 
+	if (retval+a.len >= IA32_PAGE_OFFSET && (long)retval > 0) { 
 		do_munmap(mm, retval, a.len); 
 		retval = -ENOMEM; 
 	} 
@@ -290,7 +242,8 @@
 
 extern asmlinkage long sys_mprotect(unsigned long start,size_t len,unsigned long prot);
 
-asmlinkage int sys32_mprotect(unsigned long start, size_t len, unsigned long prot)
+asmlinkage long 
+sys32_mprotect(unsigned long start, size_t len, unsigned long prot)
 {
 	if (prot & PROT_READ) 
 		prot |= PROT_EXEC; 
@@ -498,19 +451,8 @@
 	return ret;
 }
 
-struct timeval32
-{
-    int tv_sec, tv_usec;
-};
-
-struct itimerval32
-{
-    struct timeval32 it_interval;
-    struct timeval32 it_value;
-};
-
 static inline long
-get_tv32(struct timeval *o, struct timeval32 *i)
+get_tv32(struct timeval *o, struct compat_timeval *i)
 {
 	int err = -EFAULT; 
 	if (access_ok(VERIFY_READ, i, sizeof(*i))) { 
@@ -521,7 +463,7 @@
 }
 
 static inline long
-put_tv32(struct timeval32 *o, struct timeval *i)
+put_tv32(struct compat_timeval *o, struct timeval *i)
 {
 	int err = -EFAULT;
 	if (access_ok(VERIFY_WRITE, o, sizeof(*o))) { 
@@ -531,71 +473,7 @@
 	return err; 
 }
 
-static inline long
-get_it32(struct itimerval *o, struct itimerval32 *i)
-{
-	int err = -EFAULT; 
-	if (access_ok(VERIFY_READ, i, sizeof(*i))) { 
-		err = __get_user(o->it_interval.tv_sec, &i->it_interval.tv_sec);
-		err |= __get_user(o->it_interval.tv_usec, &i->it_interval.tv_usec);
-		err |= __get_user(o->it_value.tv_sec, &i->it_value.tv_sec);
-		err |= __get_user(o->it_value.tv_usec, &i->it_value.tv_usec);
-	}
-	return err;
-}
-
-static inline long
-put_it32(struct itimerval32 *o, struct itimerval *i)
-{
-	int err = -EFAULT;
-	if (access_ok(VERIFY_WRITE, o, sizeof(*o))) {
-		err = __put_user(i->it_interval.tv_sec, &o->it_interval.tv_sec);
-		err |= __put_user(i->it_interval.tv_usec, &o->it_interval.tv_usec);
-		err |= __put_user(i->it_value.tv_sec, &o->it_value.tv_sec);
-		err |= __put_user(i->it_value.tv_usec, &o->it_value.tv_usec); 
-	} 
-	return err;
-}
-
-extern int do_getitimer(int which, struct itimerval *value);
-
-asmlinkage long
-sys32_getitimer(int which, struct itimerval32 *it)
-{
-	struct itimerval kit;
-	int error;
-
-	error = do_getitimer(which, &kit);
-	if (!error && put_it32(it, &kit))
-		error = -EFAULT;
-
-	return error;
-}
-
-extern int do_setitimer(int which, struct itimerval *, struct itimerval *);
-
 asmlinkage long
-sys32_setitimer(int which, struct itimerval32 *in, struct itimerval32 *out)
-{
-	struct itimerval kin, kout;
-	int error;
-
-	if (in) {
-		if (get_it32(&kin, in))
-			return -EFAULT;
-	} else
-		memset(&kin, 0, sizeof(kin));
-
-	error = do_setitimer(which, &kin, out ? &kout : NULL);
-	if (error || !out)
-		return error;
-	if (put_it32(out, &kout))
-		return -EFAULT;
-
-	return 0;
-
-}
-asmlinkage unsigned long 
 sys32_alarm(unsigned int seconds)
 {
 	struct itimerval it_new, it_old;
@@ -616,45 +494,11 @@
 /* Translations due to time_t size differences.  Which affects all
    sorts of things, like timeval and itimerval.  */
 
-struct utimbuf_32 {
-	int	atime;
-	int	mtime;
-};
-
-extern asmlinkage long sys_utimes(char * filename, struct timeval * utimes);
-extern asmlinkage long sys_gettimeofday (struct timeval *tv, struct timezone *tz);
-
-asmlinkage long
-ia32_utime(char * filename, struct utimbuf_32 *times32)
-{
-	mm_segment_t old_fs = get_fs();
-	struct timeval tv[2];
-	long ret;
-
-	if (times32) {
-		get_user(tv[0].tv_sec, &times32->atime);
-		tv[0].tv_usec = 0;
-		get_user(tv[1].tv_sec, &times32->mtime);
-		tv[1].tv_usec = 0;
-		set_fs (KERNEL_DS);
-	} else {
-		set_fs (KERNEL_DS);
-		ret = sys_gettimeofday(&tv[0], 0);
-		if (ret < 0)
-			goto out;
-		tv[1] = tv[0];
-	}
-	ret = sys_utimes(filename, tv);
-  out:
-	set_fs (old_fs);
-	return ret;
-}
-
 extern struct timezone sys_tz;
 extern int do_sys_settimeofday(struct timeval *tv, struct timezone *tz);
 
 asmlinkage long
-sys32_gettimeofday(struct timeval32 *tv, struct timezone *tz)
+sys32_gettimeofday(struct compat_timeval *tv, struct timezone *tz)
 {
 	if (tv) {
 		struct timeval ktv;
@@ -670,7 +514,7 @@
 }
 
 asmlinkage long
-sys32_settimeofday(struct timeval32 *tv, struct timezone *tz)
+sys32_settimeofday(struct compat_timeval *tv, struct timezone *tz)
 {
 	struct timeval ktv;
 	struct timezone ktz;
@@ -827,7 +671,7 @@
 #define ROUND_UP_TIME(x,y) (((x)+(y)-1)/(y))
 
 asmlinkage long
-sys32_select(int n, fd_set *inp, fd_set *outp, fd_set *exp, struct timeval32 *tvp32)
+sys32_select(int n, fd_set *inp, fd_set *outp, fd_set *exp, struct compat_timeval *tvp32)
 {
 	fd_set_bits fds;
 	char *bits;
@@ -931,37 +775,7 @@
 	if (copy_from_user(&a, arg, sizeof(a)))
 		return -EFAULT;
 	return sys32_select(a.n, (fd_set *)A(a.inp), (fd_set *)A(a.outp), (fd_set *)A(a.exp),
-			    (struct timeval32 *)A(a.tvp));
-}
-
-struct timespec32 {
-	int 	tv_sec;
-	int	tv_nsec;
-};
-
-extern asmlinkage long sys_nanosleep(struct timespec *rqtp, struct timespec *rmtp); 
-
-asmlinkage long
-sys32_nanosleep(struct timespec32 *rqtp, struct timespec32 *rmtp)
-{
-	struct timespec t;
-	int ret;
-	mm_segment_t old_fs = get_fs ();
-	
-	if (verify_area(VERIFY_READ, rqtp, sizeof(struct timespec32)) ||
-	    __get_user (t.tv_sec, &rqtp->tv_sec) ||
-	    __get_user (t.tv_nsec, &rqtp->tv_nsec))
-		return -EFAULT;
-	set_fs (KERNEL_DS);
-	ret = sys_nanosleep(&t, rmtp ? &t : NULL);
-	set_fs (old_fs);
-	if (rmtp && ret == -EINTR) {
-		if (verify_area(VERIFY_WRITE, rmtp, sizeof(struct timespec32)) ||
-		    __put_user (t.tv_sec, &rmtp->tv_sec) ||
-	    	    __put_user (t.tv_nsec, &rmtp->tv_nsec))
-			return -EFAULT;
-	}
-	return ret;
+			    (struct compat_timeval *)A(a.tvp));
 }
 
 asmlinkage ssize_t sys_readv(unsigned long,const struct iovec *,unsigned long);
@@ -1153,8 +967,8 @@
 }
 
 struct rusage32 {
-        struct timeval32 ru_utime;
-        struct timeval32 ru_stime;
+        struct compat_timeval ru_utime;
+        struct compat_timeval ru_stime;
         int    ru_maxrss;
         int    ru_ixrss;
         int    ru_idrss;
@@ -1201,7 +1015,7 @@
 				int options, struct rusage * ru);
 
 asmlinkage long
-sys32_wait4(__kernel_pid_t32 pid, unsigned int *stat_addr, int options,
+sys32_wait4(compat_pid_t pid, unsigned int *stat_addr, int options,
 	    struct rusage32 *ru)
 {
 	if (!ru)
@@ -1223,7 +1037,7 @@
 }
 
 asmlinkage long
-sys32_waitpid(__kernel_pid_t32 pid, unsigned int *stat_addr, int options)
+sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options)
 {
 	return sys32_wait4(pid, stat_addr, options, NULL);
 }
@@ -1246,37 +1060,6 @@
 	return ret;
 }
 
-struct tms32 {
-	__kernel_clock_t32 tms_utime;
-	__kernel_clock_t32 tms_stime;
-	__kernel_clock_t32 tms_cutime;
-	__kernel_clock_t32 tms_cstime;
-};
-                                
-extern int sys_times(struct tms *);
-
-asmlinkage long
-sys32_times(struct tms32 *tbuf)
-{
-	struct tms t;
-	long ret;
-	mm_segment_t old_fs = get_fs ();
-	
-	set_fs (KERNEL_DS);
-	ret = sys_times(tbuf ? &t : NULL);
-	set_fs (old_fs);
-	if (tbuf) {
-		if (verify_area(VERIFY_WRITE, tbuf, sizeof(struct tms32)) ||
-		    __put_user (t.tms_utime, &tbuf->tms_utime) ||
-		    __put_user (t.tms_stime, &tbuf->tms_stime) ||
-		    __put_user (t.tms_cutime, &tbuf->tms_cutime) ||
-		    __put_user (t.tms_cstime, &tbuf->tms_cstime))
-			return -EFAULT;
-	}
-	return ret;
-}
-
-
 static inline int get_flock(struct flock *kfl, struct flock32 *ufl)
 {
 	int err;
@@ -1406,38 +1189,6 @@
 
 /* 32-bit timeval and related flotsam.  */
 
-extern asmlinkage long sys_utime(char * filename, struct utimbuf * times);
-
-struct utimbuf32 {
-	__kernel_time_t32 actime, modtime;
-};
-
-asmlinkage long
-sys32_utime(char * filename, struct utimbuf32 *times)
-{
-	struct utimbuf t;
-	mm_segment_t old_fs;
-	int ret;
-	char *filenam;
-	
-	if (!times)
-		return sys_utime(filename, NULL);
-	if (verify_area(VERIFY_READ, times, sizeof(struct utimbuf32)) ||
-	    __get_user (t.actime, &times->actime) ||
-	    __get_user (t.modtime, &times->modtime))
-		return -EFAULT;
-	filenam = getname (filename);
-	ret = PTR_ERR(filenam);
-	if (!IS_ERR(filenam)) {
-		old_fs = get_fs();
-		set_fs (KERNEL_DS); 
-		ret = sys_utime(filenam, &t);
-		set_fs (old_fs);
-		putname(filenam);
-	}
-	return ret;
-}
-
 extern asmlinkage long sys_sysfs(int option, unsigned long arg1,
 				unsigned long arg2);
 
@@ -1528,7 +1279,7 @@
 						struct timespec *interval);
 
 asmlinkage long
-sys32_sched_rr_get_interval(__kernel_pid_t32 pid, struct timespec32 *interval)
+sys32_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec *interval)
 {
 	struct timespec t;
 	int ret;
@@ -1537,7 +1288,7 @@
 	set_fs (KERNEL_DS);
 	ret = sys_sched_rr_get_interval(pid, &t);
 	set_fs (old_fs);
-	if (verify_area(VERIFY_WRITE, interval, sizeof(struct timespec32)) ||
+	if (verify_area(VERIFY_WRITE, interval, sizeof(struct compat_timespec)) ||
 	    __put_user (t.tv_sec, &interval->tv_sec) ||
 	    __put_user (t.tv_nsec, &interval->tv_nsec))
 		return -EFAULT;
@@ -1582,7 +1333,7 @@
 extern asmlinkage long sys_rt_sigpending(sigset_t *set, size_t sigsetsize);
 
 asmlinkage long
-sys32_rt_sigpending(sigset32_t *set, __kernel_size_t32 sigsetsize)
+sys32_rt_sigpending(sigset32_t *set, compat_size_t sigsetsize)
 {
 	sigset_t s;
 	sigset32_t s32;
@@ -1688,7 +1439,7 @@
 
 asmlinkage long
 sys32_rt_sigtimedwait(sigset32_t *uthese, siginfo_t32 *uinfo,
-		      struct timespec32 *uts, __kernel_size_t32 sigsetsize)
+		      struct compat_timespec *uts, compat_size_t sigsetsize)
 {
 	sigset_t s;
 	sigset32_t s32;
@@ -1707,7 +1458,7 @@
 	case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
 	}
 	if (uts) {
-		if (verify_area(VERIFY_READ, uts, sizeof(struct timespec32)) ||
+		if (verify_area(VERIFY_READ, uts, sizeof(struct compat_timespec)) ||
 		    __get_user (t.tv_sec, &uts->tv_sec) ||
 		    __get_user (t.tv_nsec, &uts->tv_nsec))
 			return -EFAULT;
@@ -1749,7 +1500,7 @@
 asmlinkage long sys_utimes(char *, struct timeval *);
 
 asmlinkage long
-sys32_utimes(char *filename, struct timeval32 *tvs)
+sys32_utimes(char *filename, struct compat_timeval *tvs)
 {
 	char *kfilename;
 	struct timeval ktvs[2];
@@ -1851,21 +1602,16 @@
 extern asmlinkage ssize_t sys_pwrite64(unsigned int fd, const char * buf,
 				     size_t count, loff_t pos);
 
-typedef __kernel_ssize_t32 ssize_t32;
-
-
 /* warning: next two assume little endian */ 
-asmlinkage ssize_t32
-sys32_pread(unsigned int fd, char *ubuf, __kernel_size_t32 count,
-	    u32 poslo, u32 poshi)
+asmlinkage long
+sys32_pread(unsigned int fd, char *ubuf, u32 count, u32 poslo, u32 poshi)
 {
 	return sys_pread64(fd, ubuf, count,
 			 ((loff_t)AA(poshi) << 32) | AA(poslo));
 }
 
-asmlinkage ssize_t32
-sys32_pwrite(unsigned int fd, char *ubuf, __kernel_size_t32 count,
-	     u32 poslo, u32 poshi)
+asmlinkage long
+sys32_pwrite(unsigned int fd, char *ubuf, u32 count, u32 poslo, u32 poshi)
 {
 	return sys_pwrite64(fd, ubuf, count,
 			  ((loff_t)AA(poshi) << 32) | AA(poslo));
@@ -1891,7 +1637,7 @@
 				       size_t count); 
 
 asmlinkage long
-sys32_sendfile(int out_fd, int in_fd, __kernel_off_t32 *offset, s32 count)
+sys32_sendfile(int out_fd, int in_fd, compat_off_t *offset, s32 count)
 {
 	mm_segment_t old_fs = get_fs();
 	int ret;
@@ -1916,7 +1662,7 @@
 	u32 modes;
 	s32 offset, freq, maxerror, esterror;
 	s32 status, constant, precision, tolerance;
-	struct timeval32 time;
+	struct compat_timeval time;
 	s32 tick;
 	s32 ppsfreq, jitter, shift, stabil;
 	s32 jitcnt, calcnt, errcnt, stbcnt;
@@ -2001,14 +1747,15 @@
 			return -EBADF;
 	}
 
-	/* later add PROT_EXEC for PROT_READ here */
+	if (prot & PROT_READ)
+		prot |= PROT_EXEC;
 
 	down_write(&mm->mmap_sem);
 	error = do_mmap_pgoff(file, addr, len, prot, flags|MAP_32BIT, pgoff);
 	up_write(&mm->mmap_sem);
 
 	/* cannot wrap */
-	if (error+len >= 0xFFFFFFFF && (long)error >= 0) { 
+	if (error+len >= IA32_PAGE_OFFSET && (long)error >= 0) { 
 		do_munmap(mm, error, len); 
 		error = -ENOMEM; 
 	} 
@@ -2051,7 +1798,7 @@
 	 return error;
 }
 
-int sys32_uname(struct old_utsname * name)
+long sys32_uname(struct old_utsname * name)
 {
 	int err;
 	if (!name)
@@ -2066,7 +1813,7 @@
 
 extern int sys_ustat(dev_t, struct ustat *);
 
-int sys32_ustat(dev_t dev, struct ustat32 *u32p)
+long sys32_ustat(dev_t dev, struct ustat32 *u32p)
 {
 	struct ustat u;
 	mm_segment_t seg;
@@ -2109,7 +1856,7 @@
 	return cnt; 
 } 
 
-int sys32_execve(char *name, u32 argv, u32 envp, struct pt_regs regs)
+long sys32_execve(char *name, u32 argv, u32 envp, struct pt_regs regs)
 { 
 	mm_segment_t oldseg; 
 	char **buf; 
@@ -2163,20 +1910,22 @@
 	return ret; 
 } 
 
-asmlinkage int sys32_fork(struct pt_regs regs)
+asmlinkage long sys32_fork(struct pt_regs regs)
 {
 	struct task_struct *p;
-	p = do_fork(SIGCHLD, regs.rsp, &regs, 0, NULL);
+	p = do_fork(SIGCHLD, regs.rsp, &regs, 0, NULL, NULL);
 	return IS_ERR(p) ? PTR_ERR(p) : p->pid;
 }
 
-asmlinkage int sys32_clone(unsigned int clone_flags, unsigned int newsp, struct pt_regs regs)
+asmlinkage long sys32_clone(unsigned int clone_flags, unsigned int newsp, struct pt_regs regs)
 {
 	struct task_struct *p;
-	int *user_tid = (int *)regs.rdx;
+	void *parent_tid = (void *)regs.rdx;
+	void *child_tid = (void *)regs.rdi; 
 	if (!newsp)
 		newsp = regs.rsp;
-	p = do_fork(clone_flags & ~CLONE_IDLETASK, newsp, &regs, 0, user_tid);
+	p = do_fork(clone_flags & ~CLONE_IDLETASK, newsp, &regs, 0, 
+		    parent_tid, child_tid);
 	return IS_ERR(p) ? PTR_ERR(p) : p->pid;
 }
 
@@ -2190,10 +1939,10 @@
  * do not have enough call-clobbered registers to hold all
  * the information you need.
  */
-asmlinkage int sys32_vfork(struct pt_regs regs)
+asmlinkage long sys32_vfork(struct pt_regs regs)
 {
 	struct task_struct *p;
-	p = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs.rsp, &regs, 0, NULL);
+	p = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs.rsp, &regs, 0, NULL, NULL);
 	return IS_ERR(p) ? PTR_ERR(p) : p->pid;
 }
 
@@ -2203,14 +1952,14 @@
 
 extern off_t sys_lseek (unsigned int fd, off_t offset, unsigned int origin);
 
-int sys32_lseek (unsigned int fd, int offset, unsigned int whence)
+long sys32_lseek (unsigned int fd, int offset, unsigned int whence)
 {
 	return sys_lseek(fd, offset, whence);
 }
 
 extern int sys_kill(pid_t pid, int sig); 
 
-int sys32_kill(int pid, int sig)
+long sys32_kill(int pid, int sig)
 {
 	return sys_kill(pid, sig);
 }
@@ -2235,27 +1984,27 @@
 struct nfsctl_export32 {
 	s8			ex32_client[NFSCLNT_IDMAX+1];
 	s8			ex32_path[NFS_MAXPATHLEN+1];
-	__kernel_dev_t32	ex32_dev;
-	__kernel_ino_t32	ex32_ino;
+	compat_dev_t	ex32_dev;
+	compat_ino_t	ex32_ino;
 	s32			ex32_flags;
-	__kernel_uid_t32	ex32_anon_uid;
-	__kernel_gid_t32	ex32_anon_gid;
+	compat_pid_t	ex32_anon_uid;
+	compat_gid_t	ex32_anon_gid;
 };
 
 struct nfsctl_uidmap32 {
 	u32			ug32_ident;   /* char * */
-	__kernel_uid_t32	ug32_uidbase;
+	compat_pid_t	ug32_uidbase;
 	s32			ug32_uidlen;
 	u32			ug32_udimap;  /* uid_t * */
-	__kernel_uid_t32	ug32_gidbase;
+	compat_pid_t	ug32_gidbase;
 	s32			ug32_gidlen;
 	u32			ug32_gdimap;  /* gid_t * */
 };
 
 struct nfsctl_fhparm32 {
 	struct sockaddr		gf32_addr;
-	__kernel_dev_t32	gf32_dev;
-	__kernel_ino_t32	gf32_ino;
+	compat_dev_t	gf32_dev;
+	compat_ino_t	gf32_ino;
 	s32			gf32_version;
 };
 
@@ -2384,7 +2133,7 @@
 		return -ENOMEM;
 	for(i = 0; i < karg->ca_umap.ug_uidlen; i++)
 		err |= __get_user(karg->ca_umap.ug_udimap[i],
-			      &(((__kernel_uid_t32 *)A(uaddr))[i]));
+			      &(((compat_pid_t *)A(uaddr))[i]));
 	err |= __get_user(karg->ca_umap.ug_gidbase,
 		      &arg32->ca32_umap.ug32_gidbase);
 	err |= __get_user(karg->ca_umap.ug_uidlen,
@@ -2398,7 +2147,7 @@
 		return -ENOMEM;
 	for(i = 0; i < karg->ca_umap.ug_gidlen; i++)
 		err |= __get_user(karg->ca_umap.ug_gdimap[i],
-			      &(((__kernel_gid_t32 *)A(uaddr))[i]));
+			      &(((compat_gid_t *)A(uaddr))[i]));
 
 	return err;
 }
@@ -2460,7 +2209,7 @@
 	return copy_to_user(res32, kres, sizeof(*res32));
 }
 
-int asmlinkage sys32_nfsservctl(int cmd, struct nfsctl_arg32 *arg32, union nfsctl_res32 *res32)
+long asmlinkage sys32_nfsservctl(int cmd, struct nfsctl_arg32 *arg32, union nfsctl_res32 *res32)
 {
 	struct nfsctl_arg *karg = NULL;
 	union nfsctl_res *kres = NULL;
@@ -2541,13 +2290,13 @@
 }
 #else /* !NFSD */
 extern asmlinkage long sys_ni_syscall(void);
-int asmlinkage sys32_nfsservctl(int cmd, void *notused, void *notused2)
+long asmlinkage sys32_nfsservctl(int cmd, void *notused, void *notused2)
 {
 	return sys_ni_syscall();
 }
 #endif
 
-int sys32_module_warning(void)
+long sys32_module_warning(void)
 { 
 	static long warn_time = -(60*HZ); 
 	if (time_before(warn_time + 60*HZ,jiffies) && strcmp(current->comm,"klogd")) { 
@@ -2562,7 +2311,7 @@
 int sys_sched_setaffinity(pid_t pid, unsigned int len, unsigned long *new_mask_ptr); 
 
 /* only works on LE */
-int sys32_sched_setaffinity(pid_t pid, unsigned int len,
+long sys32_sched_setaffinity(pid_t pid, unsigned int len,
 			    unsigned int *new_mask_ptr)
 {
 	mm_segment_t oldfs = get_fs(); 
@@ -2577,7 +2326,7 @@
 }
 
 /* only works on LE */ 
-int sys32_sched_getaffinity(pid_t pid, unsigned int len,
+long sys32_sched_getaffinity(pid_t pid, unsigned int len,
 			    unsigned int *new_mask_ptr)
 {
 	mm_segment_t oldfs = get_fs(); 
@@ -2587,11 +2336,38 @@
 	set_fs(KERNEL_DS); 
 	err = sys_sched_getaffinity(pid,sizeof(mask),&mask); 	
 	set_fs(oldfs); 
-	if (!err) 
+	if (err > 0) 
 		err = put_user((u32)mask, new_mask_ptr); 
 	return err;
 }
 
+extern int sys_futex(unsigned long uaddr, int op, int val, struct timespec *t); 
+
+asmlinkage long
+sys32_futex(unsigned long uaddr, int op, int val, struct compat_timespec *utime32)
+{
+	struct timespec t;
+	mm_segment_t oldfs = get_fs(); 
+	int err;
+
+	if (utime32) {
+		if (verify_area(VERIFY_READ, utime32, sizeof(*utime32)))
+			return -EFAULT;
+
+		if (__get_user(t.tv_sec, &utime32->tv_sec) ||
+		    __get_user(t.tv_nsec, &utime32->tv_nsec))
+			return -EFAULT;
+		
+	}
+
+	/* the set_fs is safe because futex doesn't use the seg limit 
+	   for valid page checking of uaddr. */ 
+	set_fs(KERNEL_DS); 
+	err = sys_futex(uaddr, op, val, &t);
+	set_fs(oldfs); 
+	return err; 
+}
+
 extern long sys_io_setup(unsigned nr_reqs, aio_context_t *ctx);
 
 long sys32_io_setup(unsigned nr_reqs, u32 *ctx32p)
@@ -2608,8 +2384,53 @@
 	return ret;
 } 
 
+extern asmlinkage long sys_io_submit(aio_context_t ctx_id, long nr,
+				     struct iocb **iocbpp);
+
+long sys32_io_submit(aio_context_t ctx_id, unsigned long nr,
+		   u32 *iocbpp)
+{
+	mm_segment_t oldfs = get_fs(); 
+	int k, err = 0;
+	struct iocb **iocb64; 
+	if (nr > 128) 
+		return -EINVAL; 
+	iocb64 = kmalloc(sizeof(struct iocb *) * nr, GFP_KERNEL);
+	if (!iocb64)
+		return -ENOMEM;
+	for (k = 0; k < nr && !err; k++) { 
+		u64 val1, val2;
+		u32 iocb32;
+		struct iocb *iocb; 	
+		err = get_user(iocb32, (u32 *)(u64)iocbpp[k]); 
+		iocb64[k] = iocb = (void *)(u64)iocb32; 
+		
+		if (get_user(val1, &iocb->aio_buf) ||
+		    get_user(val2, &iocb->aio_nbytes)) 
+			err = -EFAULT; 
+		else if (!val1) /* should check cmd */ 
+			;
+		else if (verify_area(VERIFY_WRITE, (void*)val1, val2))
+			err = -EFAULT; 
+
+		/* paranoia check - remove it when you are sure they
+		   are not pointers */
+		if (get_user(val1, &iocb->aio_reserved2) || val1 ||
+		    get_user(val2, &iocb->aio_reserved2) || val2)
+			err = -EFAULT; 		    		   
+	} 
+	if (!err) {
+		set_fs(KERNEL_DS);
+		err = sys_io_submit(ctx_id, nr, iocb64);
+		set_fs(oldfs); 
+	} 
+	kfree(iocb64);
+	return err;		
+}
+
+/* XXX aio getevents */
 
-int sys32_vm86_warning(void)
+long sys32_vm86_warning(void)
 { 
 	static long warn_time = -(60*HZ); 
 	if (time_before(warn_time + 60*HZ,jiffies)) { 
diff -Nru a/arch/x86_64/kernel/Makefile b/arch/x86_64/kernel/Makefile
--- a/arch/x86_64/kernel/Makefile	Mon Dec 23 21:21:58 2002
+++ b/arch/x86_64/kernel/Makefile	Mon Dec 23 21:21:58 2002
@@ -4,23 +4,30 @@
 
 EXTRA_TARGETS 	:= head.o head64.o init_task.o
 
-export-objs     := mtrr.o x8664_ksyms.o pci-gart.o pci-dma.o
+export-objs     := x8664_ksyms.o pci-gart.o pci-dma.o
 
 obj-y	:= process.o semaphore.o signal.o entry.o traps.o irq.o \
 		ptrace.o i8259.o ioport.o ldt.o setup.o time.o sys_x86_64.o \
 		pci-dma.o x8664_ksyms.o i387.o syscall.o vsyscall.o \
 		setup64.o bluesmoke.o bootflag.o e820.o reboot.o profile.o
 
-obj-$(CONFIG_MTRR)	+= mtrr.o
+obj-$(CONFIG_MTRR)	+= mtrr/
 obj-$(CONFIG_X86_MSR)	+= msr.o
 obj-$(CONFIG_X86_CPUID)	+= cpuid.o
 obj-$(CONFIG_SMP)	+= smp.o smpboot.o trampoline.o
 obj-$(CONFIG_X86_LOCAL_APIC)	+= apic.o  nmi.o
 obj-$(CONFIG_X86_IO_APIC)	+= io_apic.o mpparse.o
+obj-$(CONFIG_SOFTWARE_SUSPEND)	+= suspend.o suspend_asm.o
 obj-$(CONFIG_ACPI)             += acpi.o
 #obj-$(CONFIG_ACPI_SLEEP)       += acpi_wakeup.o
 obj-$(CONFIG_EARLY_PRINTK)    += early_printk.o
 obj-$(CONFIG_GART_IOMMU) += pci-gart.o aperture.o
 obj-$(CONFIG_DUMMY_IOMMU) += pci-nommu.o
+obj-$(CONFIG_MODULES) += module.o
+
+$(obj)/bootflag.c: 
+	@ln -sf ../../i386/kernel/bootflag.c $(obj)/bootflag.c
+
+clean-files += bootflag.c
 
 EXTRA_AFLAGS := -traditional
diff -Nru a/arch/x86_64/kernel/acpi.c b/arch/x86_64/kernel/acpi.c
--- a/arch/x86_64/kernel/acpi.c	Mon Dec 23 21:21:51 2002
+++ b/arch/x86_64/kernel/acpi.c	Mon Dec 23 21:21:51 2002
@@ -443,8 +443,6 @@
 
 #error not ported to x86-64 yet
 
-#define DEBUG
-
 #ifdef DEBUG
 #include <linux/serial.h>
 #endif
diff -Nru a/arch/x86_64/kernel/bootflag.c b/arch/x86_64/kernel/bootflag.c
--- a/arch/x86_64/kernel/bootflag.c	Mon Dec 23 21:21:55 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,254 +0,0 @@
-/*
- *	Implement 'Simple Boot Flag Specification 1.0'
- *
- */
-
-
-#include <linux/config.h>
-#include <linux/types.h>
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/string.h>
-#include <linux/slab.h>
-#include <linux/spinlock.h>
-#include <asm/io.h>
-
-#include <linux/mc146818rtc.h>
-
-
-#define SBF_RESERVED (0x78)
-#define SBF_PNPOS    (1<<0)
-#define SBF_BOOTING  (1<<1)
-#define SBF_DIAG     (1<<2)
-#define SBF_PARITY   (1<<7)
-
-
-struct sbf_boot
-{
-	u8 sbf_signature[4];
-	u32 sbf_len;
-	u8 sbf_revision __attribute((packed));
-	u8 sbf_csum __attribute((packed));
-	u8 sbf_oemid[6] __attribute((packed));
-	u8 sbf_oemtable[8] __attribute((packed));
-	u8 sbf_revdata[4] __attribute((packed));
-	u8 sbf_creator[4] __attribute((packed));
-	u8 sbf_crearev[4] __attribute((packed));
-	u8 sbf_cmos __attribute((packed));
-	u8 sbf_spare[3] __attribute((packed));
-};
-
-
-static int sbf_port __initdata = -1;
-
-static int __init sbf_struct_valid(unsigned long tptr)
-{
-	u8 *ap;
-	u8 v;
-	unsigned int i;
-	struct sbf_boot sb;
-	
-	memcpy_fromio(&sb, (void *)tptr, sizeof(sb));
-
-	if(sb.sbf_len != 40 && sb.sbf_len != 39)
-		// 39 on IBM ThinkPad A21m, BIOS version 1.02b (KXET24WW; 2000-12-19).
-		return 0;
-
-	ap = (u8 *)&sb;
-	v= 0;
-	
-	for(i=0;i<sb.sbf_len;i++)
-		v+=*ap++;
-		
-	if(v)
-		return 0;
-
-	if(memcmp(sb.sbf_signature, "BOOT", 4))
-		return 0;
-
-	if (sb.sbf_len == 39)
-		printk (KERN_WARNING "SBF: ACPI BOOT descriptor is wrong length (%d)\n",
-			sb.sbf_len);
-
-	sbf_port = sb.sbf_cmos;	/* Save CMOS port */
-	return 1;
-}
-
-static int __init parity(u8 v)
-{
-	int x = 0;
-	int i;
-	
-	for(i=0;i<8;i++)
-	{
-		x^=(v&1);
-		v>>=1;
-	}
-	return x;
-}
-
-static void __init sbf_write(u8 v)
-{
-	unsigned long flags;
-	if(sbf_port != -1)
-	{
-		v &= ~SBF_PARITY;
-		if(!parity(v))
-			v|=SBF_PARITY;
-
-		printk(KERN_INFO "SBF: Setting boot flags 0x%x\n",v);
-
-		spin_lock_irqsave(&rtc_lock, flags);
-		CMOS_WRITE(v, sbf_port);
-		spin_unlock_irqrestore(&rtc_lock, flags);
-	}
-}
-
-static u8 __init sbf_read(void)
-{
-	u8 v;
-	unsigned long flags;
-	if(sbf_port == -1)
-		return 0;
-	spin_lock_irqsave(&rtc_lock, flags);
-	v = CMOS_READ(sbf_port);
-	spin_unlock_irqrestore(&rtc_lock, flags);
-	return v;
-}
-
-static int __init sbf_value_valid(u8 v)
-{
-	if(v&SBF_RESERVED)		/* Reserved bits */
-		return 0;
-	if(!parity(v))
-		return 0;
-	return 1;
-}
-
-
-static void __init sbf_bootup(void)
-{
-	u8 v;
-	if(sbf_port == -1)
-		return;
-	v = sbf_read();
-	if(!sbf_value_valid(v))
-		printk(KERN_WARNING "SBF: Simple boot flag value 0x%x read from CMOS RAM was invalid\n",v);
-	v &= ~SBF_RESERVED;
-	v &= ~SBF_BOOTING;
-	v &= ~SBF_DIAG;
-#if defined(CONFIG_ISAPNP)
-	v |= SBF_PNPOS;
-#endif
-	sbf_write(v);
-}
-
-static int __init sbf_init(void)
-{
-	unsigned int i;
-	void *rsdt;
-	u32 rsdtlen = 0;
-	u32 rsdtbase = 0;
-	u8 sum = 0;
-	int n;
-	
-	u8 *p;
-	
-	for(i=0xE0000; i <= 0xFFFE0; i+=16)
-	{
-		p = phys_to_virt(i);
-		
-		if(memcmp(p, "RSD PTR ", 8))
-			continue;
-		
-		sum = 0;
-		for(n=0; n<20; n++)
-			sum+=p[n];
-			
-		if(sum != 0)
-			continue;
-			
-		/* So it says RSD PTR and it checksums... */
-
-		/*
-		 *	Process the RDSP pointer
-		 */
-	 
-		rsdtbase = *(u32 *)(p+16);
-		
-		/*
-		 *	RSDT length is ACPI 2 only, for ACPI 1 we must map
-		 *	and remap.
-		 */
-		 
-		if(p[15]>1)
-			rsdtlen = *(u32 *)(p+20);
-		else
-			rsdtlen = 36;
-
-		if(rsdtlen < 36 || rsdtlen > 1024)
-			continue;
-		break;
-	}
-	if(i>0xFFFE0)
-		return 0;
-		
-		
-	rsdt = ioremap(rsdtbase, rsdtlen);
-	if(rsdt == 0)
-		return 0;
-		
-	i = readl(rsdt + 4);
-	
-	/*
-	 *	Remap if needed
-	 */
-	 
-	if(i > rsdtlen)
-	{
-		rsdtlen = i;
-		iounmap(rsdt);
-		rsdt = ioremap(rsdtbase, rsdtlen);
-		if(rsdt == 0)
-			return 0;
-	}
-	
-	for(n = 0; n < i; n++)
-		sum += readb(rsdt + n);
-		
-	if(sum)
-	{
-		iounmap(rsdt);
-		return 0;
-	}
-	
-	/* Ok the RSDT checksums too */
-	
-	for(n = 36; n+3 < i; n += 4)
-	{
-		unsigned long rp = readl(rsdt+n);
-		int len = 4096;
-
-		if(rp > 0xFFFFFFFFUL - len)
-			len = 0xFFFFFFFFUL - rp;
-			
-		/* Too close to the end!! */
-		if(len < 20)
-			continue;
-		rp = (unsigned long)ioremap(rp, 4096);
-		if(rp == 0)
-			continue;
-		
-		if(sbf_struct_valid(rp))
-		{
-			/* Found the BOOT table and processed it */
-			printk(KERN_INFO "SBF: Simple Boot Flag extension found and enabled.\n");
-		}
-		iounmap((void *)rp);
-	}
-	iounmap(rsdt);
-	sbf_bootup();
-	return 0;
-}
-
-module_init(sbf_init);
diff -Nru a/arch/x86_64/kernel/entry.S b/arch/x86_64/kernel/entry.S
--- a/arch/x86_64/kernel/entry.S	Mon Dec 23 21:21:53 2002
+++ b/arch/x86_64/kernel/entry.S	Mon Dec 23 21:21:53 2002
@@ -605,6 +605,9 @@
 	movq $-1, %rsi
 	movq %rsp, %rdx
 
+	xorl %r8d,%r8d
+	xorl %r9d,%r9d
+	
 	# clone now
 	call do_fork
 
diff -Nru a/arch/x86_64/kernel/head.S b/arch/x86_64/kernel/head.S
--- a/arch/x86_64/kernel/head.S	Mon Dec 23 21:21:58 2002
+++ b/arch/x86_64/kernel/head.S	Mon Dec 23 21:21:58 2002
@@ -79,13 +79,11 @@
 	/* Enable System Call */
 	btsl	$_EFER_SCE, %eax
 
-#if 0
 	/* No Execute supported? */	
 	btl	$20,%edi
 	jnc     1f
 	btsl	$_EFER_NX, %eax
 1:	
-#endif
 				
 	/* Make changes effective */
 	wrmsr
diff -Nru a/arch/x86_64/kernel/i387.c b/arch/x86_64/kernel/i387.c
--- a/arch/x86_64/kernel/i387.c	Mon Dec 23 21:21:52 2002
+++ b/arch/x86_64/kernel/i387.c	Mon Dec 23 21:21:52 2002
@@ -127,3 +127,24 @@
 	memcpy(fpu, &tsk->thread.i387.fxsave, sizeof(struct user_i387_struct)); 
 	return 1; 
 }
+
+int dump_task_fpu(struct task_struct *tsk, struct user_i387_struct *fpu)
+{
+	int fpvalid = tsk->used_math;
+
+	if (fpvalid) {
+		if (tsk == current)
+			unlazy_fpu(tsk);
+		memcpy(fpu, &tsk->thread.i387.fxsave, sizeof(struct user_i387_struct)); 	
+}
+	return fpvalid;
+}
+
+#ifdef CONFIG_SMP
+void dump_smp_unlazy_fpu(void)
+{
+	unlazy_fpu(current);
+	return;
+}
+#endif
+
diff -Nru a/arch/x86_64/kernel/i8259.c b/arch/x86_64/kernel/i8259.c
--- a/arch/x86_64/kernel/i8259.c	Mon Dec 23 21:21:51 2002
+++ b/arch/x86_64/kernel/i8259.c	Mon Dec 23 21:21:51 2002
@@ -404,6 +404,45 @@
 void call_function_interrupt(void);
 void invalidate_interrupt(void);
 
+static void setup_timer(void)
+{
+	outb_p(0x34,0x43);		/* binary, mode 2, LSB/MSB, ch 0 */
+	udelay(10);
+	outb_p(LATCH & 0xff , 0x40);	/* LSB */
+	udelay(10);
+	outb(LATCH >> 8 , 0x40);	/* MSB */
+}
+
+static int timer_resume(struct device *dev, u32 level)
+{
+	if (level == RESUME_POWER_ON)
+		setup_timer();
+	return 0;
+}
+
+static struct device_driver timer_driver = {
+	.name		= "timer",
+	.bus		= &system_bus_type,
+	.resume		= timer_resume,
+};
+
+static struct sys_device device_timer = {
+	.name		= "timer",
+	.id		= 0,
+	.dev		= {
+		.name	= "timer",
+		.driver	= &timer_driver,
+	},
+};
+
+static int __init init_timer_devicefs(void)
+{
+	driver_register(&timer_driver);
+	return sys_device_register(&device_timer);
+}
+
+device_initcall(init_timer_devicefs);
+
 void __init init_IRQ(void)
 {
 	int i;
@@ -454,9 +493,7 @@
 	 * Set the clock to HZ Hz, we already have a valid
 	 * vector now:
 	 */
-	outb_p(0x34,0x43);		/* binary, mode 2, LSB/MSB, ch 0 */
-	outb_p(LATCH & 0xff , 0x40);	/* LSB */
-	outb(LATCH >> 8 , 0x40);	/* MSB */
+	setup_timer();
 
 	setup_irq(2, &irq2);
 }
diff -Nru a/arch/x86_64/kernel/io_apic.c b/arch/x86_64/kernel/io_apic.c
--- a/arch/x86_64/kernel/io_apic.c	Mon Dec 23 21:21:55 2002
+++ b/arch/x86_64/kernel/io_apic.c	Mon Dec 23 21:21:55 2002
@@ -35,6 +35,8 @@
 #include <asm/smp.h>
 #include <asm/desc.h>
 
+int sis_apic_bug; /* not actually supported, dummy for compile */
+
 #undef APIC_LOCKUP_DEBUG
 
 #define APIC_LOCKUP_DEBUG
diff -Nru a/arch/x86_64/kernel/ldt.c b/arch/x86_64/kernel/ldt.c
--- a/arch/x86_64/kernel/ldt.c	Mon Dec 23 21:22:00 2002
+++ b/arch/x86_64/kernel/ldt.c	Mon Dec 23 21:22:00 2002
@@ -108,13 +108,12 @@
 }
 
 /*
- * No need to lock the MM as we are the last user
+ * 
+ * Don't touch the LDT register - we're already in the next thread.
  */
-void release_segments(struct mm_struct *mm)
+void destroy_context(struct mm_struct *mm)
 {
 	if (mm->context.size) {
-		if (mm == current->active_mm)
-			clear_LDT();
 		if (mm->context.size*LDT_ENTRY_SIZE > PAGE_SIZE)
 			vfree(mm->context.ldt);
 		else
@@ -187,11 +186,6 @@
 		if (ldt_info.seg_not_present == 0)
 			goto out;
 	}
-
-	me->thread.fsindex = 0; 
-	me->thread.gsindex = 0; 
-	me->thread.gs = 0; 
-	me->thread.fs = 0; 
 
 	down(&mm->context.sem);
 	if (ldt_info.entry_number >= mm->context.size) {
diff -Nru a/arch/x86_64/kernel/module.c b/arch/x86_64/kernel/module.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/arch/x86_64/kernel/module.c	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,134 @@
+/*  Kernel module help for x86-64
+    Copyright (C) 2001 Rusty Russell.
+    Copyright (C) 2002 Andi Kleen, SuSE Labs.
+
+    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 <linux/moduleloader.h>
+#include <linux/elf.h>
+#include <linux/vmalloc.h>
+#include <linux/fs.h>
+#include <linux/string.h>
+#include <linux/kernel.h>
+
+#define DEBUGP(fmt...) 
+ 
+/* We don't need anything special. */
+long module_core_size(const Elf64_Ehdr *hdr,
+		      const Elf64_Shdr *sechdrs,
+		      const char *secstrings,
+		      struct module *module)
+{
+	return module->core_size;
+}
+
+long module_init_size(const Elf64_Ehdr *hdr,
+		      const Elf64_Shdr *sechdrs,
+		      const char *secstrings,
+		      struct module *module)
+{
+	return module->init_size;
+}
+
+int apply_relocate_add(Elf64_Shdr *sechdrs,
+		   const char *strtab,
+		   unsigned int symindex,
+		   unsigned int relsec,
+		   struct module *me)
+{
+	unsigned int i;
+	Elf64_Rela *rel = (void *)sechdrs[relsec].sh_offset;
+	Elf64_Sym *sym;
+	void *loc;
+	u64 val; 
+
+	DEBUGP("Applying relocate section %u to %u\n", relsec,
+	       sechdrs[relsec].sh_info);
+	for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
+		/* This is where to make the change */
+		loc = (void *)sechdrs[sechdrs[relsec].sh_info].sh_offset
+			+ rel[i].r_offset;
+
+		/* This is the symbol it is referring to */
+		sym = (Elf64_Sym *)sechdrs[symindex].sh_offset
+			+ ELF64_R_SYM(rel[i].r_info);
+		if (!sym->st_value) {
+			printk(KERN_WARNING "%s: Unknown symbol %s\n",
+			       me->name, strtab + sym->st_name);
+			return -ENOENT;
+		}
+
+	        DEBUGP("type %d st_value %Lx r_addend %Lx loc %Lx\n",
+		       (int)ELF64_R_TYPE(rel[i].r_info), 
+		       sym->st_value, rel[i].r_addend, (u64)loc);
+
+		val = sym->st_value + rel[i].r_addend; 
+
+		switch (ELF64_R_TYPE(rel[i].r_info)) {
+		case R_X86_64_NONE:
+			break;
+		case R_X86_64_64:
+			*(u64 *)loc = val;
+			break;
+		case R_X86_64_32:
+			*(u32 *)loc = val;
+			if (val != *(u32 *)loc)
+				goto overflow;
+			break;
+		case R_X86_64_32S:
+			*(s32 *)loc = val;
+			if ((s64)val != *(s32 *)loc)
+				goto overflow;
+			break;
+		case R_X86_64_PC32: 
+			val -= (u64)loc;
+			*(u32 *)loc = val;
+#if 0
+			if ((s64)val != *(s32 *)loc)
+				goto overflow; 
+#endif
+			break;
+		default:
+			printk(KERN_ERR "module %s: Unknown rela relocation: %Lu\n",
+			       me->name, ELF64_R_TYPE(rel[i].r_info));
+			return -ENOEXEC;
+		}
+	}
+	return 0;
+
+overflow:
+	printk(KERN_ERR "overflow in relocation type %d val %Lx\n", 
+	       (int)ELF64_R_TYPE(rel[i].r_info), val);
+	printk(KERN_ERR "`%s' likely not compiled with -mcmodel=kernel\n",
+	       me->name);
+	return -ENOEXEC;
+}
+
+int apply_relocate(Elf_Shdr *sechdrs,
+		   const char *strtab,
+		   unsigned int symindex,
+		   unsigned int relsec,
+		   struct module *me)
+{
+	printk("non add relocation not supported\n");
+	return -ENOSYS;
+} 
+
+int module_finalize(const Elf_Ehdr *hdr,
+		    const Elf_Shdr *sechdrs,
+		    struct module *me)
+{
+	return 0;
+}
diff -Nru a/arch/x86_64/kernel/mtrr/Makefile b/arch/x86_64/kernel/mtrr/Makefile
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/arch/x86_64/kernel/mtrr/Makefile	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,30 @@
+#
+# Reuse the i386 MTRR driver.
+#
+
+obj-y		:= main.o if.o generic.o state.o
+obj-y		+= amd.o
+obj-y		+= cyrix.o
+obj-y		+= centaur.o
+
+export-objs	:= main.o
+
+$(obj)/main.c: $(obj)/mtrr.h
+	@ln -sf ../../../i386/kernel/cpu/mtrr/main.c $(obj)/main.c
+$(obj)/if.c: $(obj)/mtrr.h
+	@ln -sf ../../../i386/kernel/cpu/mtrr/if.c $(obj)/if.c
+$(obj)/generic.c: $(obj)/mtrr.h
+	@ln -sf ../../../i386/kernel/cpu/mtrr/generic.c $(obj)/generic.c
+$(obj)/state.c: $(obj)/mtrr.h
+	@ln -sf ../../../i386/kernel/cpu/mtrr/state.c $(obj)/state.c
+$(obj)/amd.c: $(obj)/mtrr.h
+	@ln -sf ../../../i386/kernel/cpu/mtrr/amd.c $(obj)/amd.c
+$(obj)/cyrix.c: $(obj)/mtrr.h
+	@ln -sf ../../../i386/kernel/cpu/mtrr/cyrix.c $(obj)/cyrix.c
+$(obj)/centaur.c: $(obj)/mtrr.h
+	@ln -sf ../../../i386/kernel/cpu/mtrr/centaur.c $(obj)/centaur.c
+$(obj)/mtrr.h:
+	@ln -sf ../../../i386/kernel/cpu/mtrr/mtrr.h $(obj)/mtrr.h
+
+clean-files += main.c if.c generic.c state.c amd.c cyrix.c centaur.c mtrr.h
+
diff -Nru a/arch/x86_64/kernel/mtrr.c b/arch/x86_64/kernel/mtrr.c
--- a/arch/x86_64/kernel/mtrr.c	Mon Dec 23 21:21:52 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,1303 +0,0 @@
-/*  x86-64 MTRR (Memory Type Range Register) driver.
-	Based largely upon arch/i386/kernel/mtrr.c
-
-	Copyright (C) 1997-2000  Richard Gooch
-	Copyright (C) 2002 Dave Jones.
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Library General Public
-    License as published by the Free Software Foundation; either
-    version 2 of the License, or (at your option) any later version.
-
-    This library 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
-    Library General Public License for more details.
-
-    You should have received a copy of the GNU Library General Public
-    License along with this library; if not, write to the Free
-    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-	(For earlier history, see arch/i386/kernel/mtrr.c)
-	v2.00	September 2001	Dave Jones <davej@suse.de>
-	  Initial rewrite for x86-64.
-	  Removal of non-Intel style MTRR code.
-	v2.01  June 2002  Dave Jones <davej@suse.de>
-	  Removal of redundant abstraction layer.
-	  64-bit fixes.
-	v2.02  July 2002  Dave Jones <davej@suse.de>
-	  Fix gentry inconsistencies between kernel/userspace.
-	  More casts to clean up warnings.
-	Andi Kleen - rework initialization.
-*/
-
-#include <linux/types.h>
-#include <linux/errno.h>
-#include <linux/sched.h>
-#include <linux/tty.h>
-#include <linux/timer.h>
-#include <linux/config.h>
-#include <linux/kernel.h>
-#include <linux/wait.h>
-#include <linux/string.h>
-#include <linux/slab.h>
-#include <linux/ioport.h>
-#include <linux/delay.h>
-#include <linux/fs.h>
-#include <linux/ctype.h>
-#include <linux/proc_fs.h>
-#include <linux/devfs_fs_kernel.h>
-#include <linux/mm.h>
-#include <linux/module.h>
-#define MTRR_NEED_STRINGS
-#include <asm/mtrr.h>
-#include <linux/init.h>
-#include <linux/smp.h>
-#include <linux/smp_lock.h>
-#include <linux/agp_backend.h>
-
-#include <asm/uaccess.h>
-#include <asm/io.h>
-#include <asm/processor.h>
-#include <asm/system.h>
-#include <asm/pgtable.h>
-#include <asm/segment.h>
-#include <asm/bitops.h>
-#include <asm/atomic.h>
-#include <asm/msr.h>
-
-#include <asm/hardirq.h>
-#include <linux/irq.h>
-
-#define MTRR_VERSION "2.02 (20020716)"
-
-#define TRUE  1
-#define FALSE 0
-
-#define MSR_MTRRphysBase(reg) (0x200 + 2 * (reg))
-#define MSR_MTRRphysMask(reg) (0x200 + 2 * (reg) + 1)
-
-#define NUM_FIXED_RANGES 88
-
-#define MTRR_CHANGE_MASK_FIXED     0x01
-#define MTRR_CHANGE_MASK_VARIABLE  0x02
-#define MTRR_CHANGE_MASK_DEFTYPE   0x04
-
-typedef u8 mtrr_type;
-
-#define LINE_SIZE 80
-
-#ifdef CONFIG_SMP
-#define set_mtrr(reg,base,size,type) set_mtrr_smp (reg, base, size, type)
-#else
-#define set_mtrr(reg,base,size,type) set_mtrr_up (reg, base, size, type, TRUE)
-#endif
-
-#if defined(CONFIG_PROC_FS) || defined(CONFIG_DEVFS_FS)
-#define USERSPACE_INTERFACE
-#endif
-
-#ifdef USERSPACE_INTERFACE
-static char *ascii_buffer;
-static unsigned int ascii_buf_bytes;
-static void compute_ascii (void);
-#else
-#define compute_ascii() while (0)
-#endif
-
-static unsigned int *usage_table;
-static DECLARE_MUTEX (mtrr_lock);
-
-struct set_mtrr_context {
-	u32 deftype_lo;
-	u32 deftype_hi;
-	unsigned long flags;
-	u64 cr4val;
-};
-
-
-/*  Put the processor into a state where MTRRs can be safely set  */
-static void set_mtrr_prepare (struct set_mtrr_context *ctxt)
-{
-	u64 cr0;
-
-	/* Disable interrupts locally */
-	local_irq_save(ctxt->flags);
-	local_irq_disable();
-
-	/* Save value of CR4 and clear Page Global Enable (bit 7)  */
-	if (cpu_has_pge) { 
-	 ctxt->cr4val = read_cr4();
-		write_cr4(ctxt->cr4val & ~(1UL << 7));
-	}
-
-	/* Disable and flush caches. Note that wbinvd flushes the TLBs as
-	   a side-effect */
-	cr0 = read_cr0() | 0x40000000;
-	wbinvd();
-	write_cr0(cr0);
-	wbinvd();
-
-	/* Disable MTRRs, and set the default type to uncached */
-	rdmsr(MSR_MTRRdefType, ctxt->deftype_lo, ctxt->deftype_hi);
-	wrmsr(MSR_MTRRdefType, ctxt->deftype_lo & 0xf300UL, ctxt->deftype_hi);
-}
-
-
-/* Restore the processor after a set_mtrr_prepare */
-static void set_mtrr_done (struct set_mtrr_context *ctxt)
-{
-	/* Flush caches and TLBs */
-	wbinvd();
-
-	/* Restore MTRRdefType */
-	wrmsr(MSR_MTRRdefType, ctxt->deftype_lo, ctxt->deftype_hi);
-
-	/* Enable caches */
-	write_cr0(read_cr0() & 0xbfffffff);
-
-	/* Restore value of CR4 */
-	if (cpu_has_pge)
-		write_cr4 (ctxt->cr4val);
-
-	/* Re-enable interrupts locally (if enabled previously) */
-	local_irq_restore(ctxt->flags);
-}
-
-
-/*  This function returns the number of variable MTRRs  */
-static unsigned int get_num_var_ranges (void)
-{
-	u32 config, dummy;
-
-	rdmsr (MSR_MTRRcap, config, dummy);
-	return (config & 0xff);
-}
-
-
-/*  Returns non-zero if we have the write-combining memory type  */
-static int have_wrcomb (void)
-{
-	u32 config, dummy;
-
-	rdmsr (MSR_MTRRcap, config, dummy);
-	return (config & (1 << 10));
-}
-
-
-static u64 size_or_mask, size_and_mask;
-
-static void get_mtrr (unsigned int reg, u64 *base, u32 *size, mtrr_type * type)
-{
-	u32 mask_lo, mask_hi, base_lo, base_hi;
-	u64 newsize;
-
-	rdmsr (MSR_MTRRphysMask(reg), mask_lo, mask_hi);
-	if ((mask_lo & 0x800) == 0) {
-		/*  Invalid (i.e. free) range  */
-		*base = 0;
-		*size = 0;
-		*type = 0;
-		return;
-	}
-
-	rdmsr (MSR_MTRRphysBase(reg), base_lo, base_hi);
-
-	/* Work out the shifted address mask. */
-	newsize = (u64) mask_hi << 32 | (mask_lo & ~0x800);
-	newsize = ~newsize+1;
-	*size = (u32) newsize >> PAGE_SHIFT;
-	*base = base_hi << (32 - PAGE_SHIFT) | base_lo >> PAGE_SHIFT;
-	*type = base_lo & 0xff;
-}
-
-
-
-/*
- * Set variable MTRR register on the local CPU.
- *  <reg> The register to set.
- *  <base> The base address of the region.
- *  <size> The size of the region. If this is 0 the region is disabled.
- *  <type> The type of the region.
- *  <do_safe> If TRUE, do the change safely. If FALSE, safety measures should
- *  be done externally.
- */
-static void set_mtrr_up (unsigned int reg, u64 base,
-		   u32 size, mtrr_type type, int do_safe)
-{
-	struct set_mtrr_context ctxt;
-	u64 base64;
-	u64 size64;
-
-	if (do_safe)
-		set_mtrr_prepare (&ctxt);
-
-	if (size == 0) {
-		/* The invalid bit is kept in the mask, so we simply clear the
-		   relevant mask register to disable a range. */
-		wrmsr (MSR_MTRRphysMask(reg), 0, 0);
-	} else {
-		base64 = (base << PAGE_SHIFT) & size_and_mask;
-		wrmsr (MSR_MTRRphysBase(reg), base64 | type, base64 >> 32);
-
-		size64 = ~((size << PAGE_SHIFT) - 1);
-		size64 = size64 & size_and_mask;
-		wrmsr (MSR_MTRRphysMask(reg), (u32) (size64 | 0x800), (u32) (size64 >> 32));
-	}
-	if (do_safe)
-		set_mtrr_done (&ctxt);
-}
-
-
-#ifdef CONFIG_SMP
-
-struct mtrr_var_range {
-	u32 base_lo;
-	u32 base_hi;
-	u32 mask_lo;
-	u32 mask_hi;
-};
-
-/*  Get the MSR pair relating to a var range  */
-static void __init get_mtrr_var_range (unsigned int index,
-		struct mtrr_var_range *vr)
-{
-	rdmsr (MSR_MTRRphysBase(index), vr->base_lo, vr->base_hi);
-	rdmsr (MSR_MTRRphysMask(index), vr->mask_lo, vr->mask_hi);
-}
-
-
-/*  Set the MSR pair relating to a var range. Returns TRUE if
-    changes are made  */
-static int __init set_mtrr_var_range_testing (unsigned int index,
-		struct mtrr_var_range *vr)
-{
-	u32 lo, hi;
-	int changed = FALSE;
-
-	rdmsr (MSR_MTRRphysBase(index), lo, hi);
-	if ((vr->base_lo & 0xfffff0ff) != (lo & 0xfffff0ff) ||
-		(vr->base_hi & 0x000fffff) != (hi & 0x000fffff)) {
-		wrmsr (MSR_MTRRphysBase(index), vr->base_lo, vr->base_hi);
-		changed = TRUE;
-	}
-
-	rdmsr (MSR_MTRRphysMask(index), lo, hi);
-	if ((vr->mask_lo & 0xfffff800) != (lo & 0xfffff800) ||
-		(vr->mask_hi & 0x000fffff) != (hi & 0x000fffff)) {
-		wrmsr (MSR_MTRRphysMask(index), vr->mask_lo, vr->mask_hi);
-		changed = TRUE;
-	}
-	return changed;
-}
-
-
-static void __init get_fixed_ranges (mtrr_type * frs)
-{
-	u32 *p = (u32 *) frs;
-	int i;
-
-	rdmsr (MSR_MTRRfix64K_00000, p[0], p[1]);
-
-	for (i = 0; i < 2; i++)
-		rdmsr (MSR_MTRRfix16K_80000 + i, p[2 + i * 2], p[3 + i * 2]);
-	for (i = 0; i < 8; i++)
-		rdmsr (MSR_MTRRfix4K_C0000 + i, p[6 + i * 2], p[7 + i * 2]);
-}
-
-
-static int __init set_fixed_ranges_testing (mtrr_type * frs)
-{
-	u32 *p = (u32 *) frs;
-	int changed = FALSE;
-	int i;
-	u32 lo, hi;
-
-	printk (KERN_INFO "mtrr: rdmsr 64K_00000\n");
-	rdmsr (MSR_MTRRfix64K_00000, lo, hi);
-	if (p[0] != lo || p[1] != hi) {
-		printk (KERN_INFO "mtrr: Writing %x:%x to 64K MSR. lohi were %x:%x\n", p[0], p[1], lo, hi);
-		wrmsr (MSR_MTRRfix64K_00000, p[0], p[1]);
-		changed = TRUE;
-	}
-
-	printk (KERN_INFO "mtrr: rdmsr 16K_80000\n");
-	for (i = 0; i < 2; i++) {
-		rdmsr (MSR_MTRRfix16K_80000 + i, lo, hi);
-		if (p[2 + i * 2] != lo || p[3 + i * 2] != hi) {
-			printk (KERN_INFO "mtrr: Writing %x:%x to 16K MSR%d. lohi were %x:%x\n", p[2 + i * 2], p[3 + i * 2], i, lo, hi );
-			wrmsr (MSR_MTRRfix16K_80000 + i, p[2 + i * 2], p[3 + i * 2]);
-			changed = TRUE;
-		}
-	}
-
-	printk (KERN_INFO "mtrr: rdmsr 4K_C0000\n");
-	for (i = 0; i < 8; i++) {
-		rdmsr (MSR_MTRRfix4K_C0000 + i, lo, hi);
-		printk (KERN_INFO "mtrr: MTRRfix4K_C0000+%d = %x:%x\n", i, lo, hi);
-		if (p[6 + i * 2] != lo || p[7 + i * 2] != hi) {
-			printk (KERN_INFO "mtrr: Writing %x:%x to 4K MSR%d. lohi were %x:%x\n", p[6 + i * 2], p[7 + i * 2], i, lo, hi);
-			wrmsr (MSR_MTRRfix4K_C0000 + i, p[6 + i * 2], p[7 + i * 2]);
-			changed = TRUE;
-		}
-	}
-	return changed;
-}
-
-
-struct mtrr_state {
-	unsigned int num_var_ranges;
-	struct mtrr_var_range *var_ranges;
-	mtrr_type fixed_ranges[NUM_FIXED_RANGES];
-	mtrr_type def_type;
-	unsigned char enabled;
-};
-
-
-/*  Grab all of the MTRR state for this CPU into *state  */
-static void __init get_mtrr_state (struct mtrr_state *state)
-{
-	unsigned int nvrs, i;
-	struct mtrr_var_range *vrs;
-	u32 lo, dummy;
-
-	nvrs = state->num_var_ranges = get_num_var_ranges();
-	vrs = state->var_ranges
-	    = kmalloc (nvrs * sizeof (struct mtrr_var_range), GFP_KERNEL);
-	if (vrs == NULL)
-		nvrs = state->num_var_ranges = 0;
-
-	for (i = 0; i < nvrs; i++)
-		get_mtrr_var_range (i, &vrs[i]);
-	get_fixed_ranges (state->fixed_ranges);
-
-	rdmsr (MSR_MTRRdefType, lo, dummy);
-	state->def_type = (lo & 0xff);
-	state->enabled = (lo & 0xc00) >> 10;
-}
-
-
-/*  Free resources associated with a struct mtrr_state  */
-static void __init finalize_mtrr_state (struct mtrr_state *state)
-{
-	if (state->var_ranges)
-		kfree (state->var_ranges);
-}
-
-
-/*
- * Set the MTRR state for this CPU.
- *  <state> The MTRR state information to read.
- *  <ctxt> Some relevant CPU context.
- *  [NOTE] The CPU must already be in a safe state for MTRR changes.
- *  [RETURNS] 0 if no changes made, else a mask indication what was changed.
- */
-static u64 __init set_mtrr_state (struct mtrr_state *state,
-		struct set_mtrr_context *ctxt)
-{
-	unsigned int i;
-	u64 change_mask = 0;
-
-	for (i = 0; i < state->num_var_ranges; i++)
-		if (set_mtrr_var_range_testing (i, &state->var_ranges[i]))
-			change_mask |= MTRR_CHANGE_MASK_VARIABLE;
-
-	if (set_fixed_ranges_testing (state->fixed_ranges))
-		change_mask |= MTRR_CHANGE_MASK_FIXED;
-	/* Set_mtrr_restore restores the old value of MTRRdefType,
-	   so to set it we fiddle with the saved value  */
-	if ((ctxt->deftype_lo & 0xff) != state->def_type
-	    || ((ctxt->deftype_lo & 0xc00) >> 10) != state->enabled) {
-		ctxt->deftype_lo |= (state->def_type | state->enabled << 10);
-		change_mask |= MTRR_CHANGE_MASK_DEFTYPE;
-	}
-
-	return change_mask;
-}
-
-
-static atomic_t undone_count;
-static volatile int wait_barrier_execute = FALSE;
-static volatile int wait_barrier_cache_enable = FALSE;
-
-struct set_mtrr_data {
-	u64 smp_base;
-	u32 smp_size;
-	unsigned int smp_reg;
-	mtrr_type smp_type;
-};
-
-/*
- * Synchronisation handler. Executed by "other" CPUs.
- */
-static void ipi_handler (void *info)
-{
-	struct set_mtrr_data *data = info;
-	struct set_mtrr_context ctxt;
-
-	set_mtrr_prepare (&ctxt);
-	/* Notify master that I've flushed and disabled my cache  */
-	atomic_dec (&undone_count);
-	while (wait_barrier_execute)
-		barrier ();
-
-	/* The master has cleared me to execute  */
-	set_mtrr_up (data->smp_reg, data->smp_base, data->smp_size,
-			data->smp_type, FALSE);
-
-	/* Notify master CPU that I've executed the function  */
-	atomic_dec (&undone_count);
-
-	/* Wait for master to clear me to enable cache and return  */
-	while (wait_barrier_cache_enable)
-		barrier ();
-	set_mtrr_done (&ctxt);
-}
-
-
-static void set_mtrr_smp (unsigned int reg, u64 base, u32 size, mtrr_type type)
-{
-	struct set_mtrr_data data;
-	struct set_mtrr_context ctxt;
-
-	data.smp_reg = reg;
-	data.smp_base = base;
-	data.smp_size = size;
-	data.smp_type = type;
-	wait_barrier_execute = TRUE;
-	wait_barrier_cache_enable = TRUE;
-	atomic_set (&undone_count, num_online_cpus() - 1);
-
-	/*  Start the ball rolling on other CPUs  */
-	if (smp_call_function (ipi_handler, &data, 1, 0) != 0)
-		panic ("mtrr: timed out waiting for other CPUs\n");
-
-	/* Flush and disable the local CPU's cache */
-	set_mtrr_prepare (&ctxt);
-
-	/*  Wait for all other CPUs to flush and disable their caches  */
-	while (atomic_read (&undone_count) > 0)
-		barrier ();
-
-	/* Set up for completion wait and then release other CPUs to change MTRRs */
-	atomic_set (&undone_count, num_online_cpus() - 1);
-	wait_barrier_execute = FALSE;
-	set_mtrr_up (reg, base, size, type, FALSE);
-
-	/*  Now wait for other CPUs to complete the function  */
-	while (atomic_read (&undone_count) > 0)
-		barrier ();
-
-	/*  Now all CPUs should have finished the function. Release the barrier to
-	   allow them to re-enable their caches and return from their interrupt,
-	   then enable the local cache and return  */
-	wait_barrier_cache_enable = FALSE;
-	set_mtrr_done (&ctxt);
-}
-
-
-/*  Some BIOS's are fucked and don't set all MTRRs the same!  */
-static void __init mtrr_state_warn (u32 mask)
-{
-	if (!mask)
-		return;
-	if (mask & MTRR_CHANGE_MASK_FIXED)
-		printk ("mtrr: your CPUs had inconsistent fixed MTRR settings\n");
-	if (mask & MTRR_CHANGE_MASK_VARIABLE)
-		printk ("mtrr: your CPUs had inconsistent variable MTRR settings\n");
-	if (mask & MTRR_CHANGE_MASK_DEFTYPE)
-		printk ("mtrr: your CPUs had inconsistent MTRRdefType settings\n");
-	printk ("mtrr: probably your BIOS does not setup all CPUs\n");
-}
-
-#endif	/*  CONFIG_SMP  */
-
-
-static inline char * attrib_to_str (int x)
-{
-	return (x <= 6) ? mtrr_strings[x] : "?";
-}
-
-
-static void __init init_table (void)
-{
-	int i, max;
-
-	max = get_num_var_ranges ();
-	if ((usage_table = kmalloc (max * sizeof *usage_table, GFP_KERNEL))==NULL) {
-		printk ("mtrr: could not allocate\n");
-		return;
-	}
-
-	for (i = 0; i < max; i++)
-		usage_table[i] = 1;
-
-#ifdef USERSPACE_INTERFACE
-	if ((ascii_buffer = kmalloc (max * LINE_SIZE, GFP_KERNEL)) == NULL) {
-		printk ("mtrr: could not allocate\n");
-		return;
-	}
-	ascii_buf_bytes = 0;
-	compute_ascii ();
-#endif
-}
-
-
-/*
- * Get a free MTRR.
- * returns the index of the region on success, else -1 on error.
-*/
-static int get_free_region(void)
-{
-	int i, max;
-	mtrr_type ltype;
-	u64 lbase;
-	u32 lsize;
-
-	max = get_num_var_ranges ();
-	for (i = 0; i < max; ++i) {
-		get_mtrr (i, &lbase, &lsize, &ltype);
-		if (lsize == 0)
-			return i;
-	}
-	return -ENOSPC;
-}
-
-
-/**
- *	mtrr_add_page - Add a memory type region
- *	@base: Physical base address of region in pages (4 KB)
- *	@size: Physical size of region in pages (4 KB)
- *	@type: Type of MTRR desired
- *	@increment: If this is true do usage counting on the region
- *	Returns The MTRR register on success, else a negative number
- *	indicating the error code.
- *
- *	Memory type region registers control the caching on newer
- *	processors. This function allows drivers to request an MTRR is added.
- *	The caller should expect to need to provide a power of two size on
- *	an equivalent power of two boundary.
- *
- *	If the region cannot be added either because all regions are in use
- *	or the CPU cannot support it a negative value is returned. On success
- *	the register number for this entry is returned, but should be treated
- *	as a cookie only.
- *
- *	On a multiprocessor machine the changes are made to all processors.
- *
- *	The available types are
- *
- *	%MTRR_TYPE_UNCACHABLE	-	No caching
- *	%MTRR_TYPE_WRBACK	-	Write data back in bursts whenever
- *	%MTRR_TYPE_WRCOMB	-	Write data back soon but allow bursts
- *	%MTRR_TYPE_WRTHROUGH	-	Cache reads but not writes
- *
- *	BUGS: Needs a quiet flag for the cases where drivers do not mind
- *	failures and do not wish system log messages to be sent.
- */
-
-int mtrr_add_page (u64 base, u32 size, unsigned int type, char increment)
-{
-	int i, max;
-	mtrr_type ltype;
-	u64 lbase, last;
-	u32 lsize;
-
-	if (base + size < 0x100) {
-		printk (KERN_WARNING
-			"mtrr: cannot set region below 1 MiB (0x%Lx000,0x%x000)\n",
-			base, size);
-		return -EINVAL;
-	}
-
-	/*  Check upper bits of base and last are equal and lower bits are 0
-	   for base and 1 for last  */
-	last = base + size - 1;
-	for (lbase = base; !(lbase & 1) && (last & 1);
-	     lbase = lbase >> 1, last = last >> 1) ;
-
-	if (lbase != last) {
-		printk (KERN_WARNING
-			"mtrr: base(0x%Lx000) is not aligned on a size(0x%x000) boundary\n",
-			base, size);
-		return -EINVAL;
-	}
-
-	if (type >= MTRR_NUM_TYPES) {
-		printk ("mtrr: type: %u illegal\n", type);
-		return -EINVAL;
-	}
-
-	/*  If the type is WC, check that this processor supports it  */
-	if ((type == MTRR_TYPE_WRCOMB) && !have_wrcomb()) {
-		printk (KERN_WARNING
-			"mtrr: your processor doesn't support write-combining\n");
-		return -ENOSYS;
-	}
-
-	if (base & (size_or_mask>>PAGE_SHIFT)) {
-		printk (KERN_WARNING "mtrr: base(%lx) exceeds the MTRR width(%lx)\n",
-				(unsigned long) base,
-				(unsigned long) (size_or_mask>>PAGE_SHIFT));
-		return -EINVAL;
-	}
-
-	if (size & (size_or_mask>>PAGE_SHIFT)) {
-		printk (KERN_WARNING "mtrr: size exceeds the MTRR width\n");
-		return -EINVAL;
-	}
-
-	increment = increment ? 1 : 0;
-	max = get_num_var_ranges ();
-	/*  Search for existing MTRR  */
-	down (&mtrr_lock);
-	for (i = 0; i < max; ++i) {
-		get_mtrr (i, &lbase, &lsize, &ltype);
-		if (base >= lbase + lsize)
-			continue;
-		if ((base < lbase) && (base + size <= lbase))
-			continue;
-
-		/*  At this point we know there is some kind of overlap/enclosure  */
-		if ((base < lbase) || (base + size > lbase + lsize)) {
-			up (&mtrr_lock);
-			printk (KERN_WARNING
-				"mtrr: 0x%Lx000,0x%x000 overlaps existing"
-				" 0x%Lx000,0x%x000\n", base, size, lbase, lsize);
-			return -EINVAL;
-		}
-		/*  New region is enclosed by an existing region  */
-		if (ltype != type) {
-			if (type == MTRR_TYPE_UNCACHABLE)
-				continue;
-			up (&mtrr_lock);
-			printk
-			    ("mtrr: type mismatch for %Lx000,%x000 old: %s new: %s\n",
-			     base, size,
-				 attrib_to_str (ltype),
-			     attrib_to_str (type));
-			return -EINVAL;
-		}
-		if (increment)
-			++usage_table[i];
-		compute_ascii ();
-		up (&mtrr_lock);
-		return i;
-	}
-	/*  Search for an empty MTRR  */
-	i = get_free_region();
-	if (i < 0) {
-		up (&mtrr_lock);
-		printk ("mtrr: no more MTRRs available\n");
-		return i;
-	}
-	set_mtrr (i, base, size, type);
-	usage_table[i] = 1;
-	compute_ascii ();
-	up (&mtrr_lock);
-	return i;
-}
-
-
-/**
- *	mtrr_add - Add a memory type region
- *	@base: Physical base address of region
- *	@size: Physical size of region
- *	@type: Type of MTRR desired
- *	@increment: If this is true do usage counting on the region
- *	Return the MTRR register on success, else a negative numbe
- *	indicating the error code.
- *
- *	Memory type region registers control the caching on newer processors.
- *	This function allows drivers to request an MTRR is added.
- *	The caller should expect to need to provide a power of two size on
- *	an equivalent power of two boundary.
- *
- *	If the region cannot be added either because all regions are in use
- *	or the CPU cannot support it a negative value is returned. On success
- *	the register number for this entry is returned, but should be treated
- *	as a cookie only.
- *
- *	On a multiprocessor machine the changes are made to all processors.
- *	This is required on x86 by the Intel processors.
- *
- *	The available types are
- *
- *	%MTRR_TYPE_UNCACHABLE	-	No caching
- *	%MTRR_TYPE_WRBACK	-	Write data back in bursts whenever
- *	%MTRR_TYPE_WRCOMB	-	Write data back soon but allow bursts
- *	%MTRR_TYPE_WRTHROUGH	-	Cache reads but not writes
- *
- *	BUGS: Needs a quiet flag for the cases where drivers do not mind
- *	failures and do not wish system log messages to be sent.
- */
-
-int mtrr_add (u64 base, u32 size, unsigned int type, char increment)
-{
-	if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1))) {
-		printk ("mtrr: size and base must be multiples of 4 kiB\n");
-		printk ("mtrr: size: 0x%x  base: 0x%Lx\n", size, base);
-		return -EINVAL;
-	}
-	return mtrr_add_page (base >> PAGE_SHIFT, size >> PAGE_SHIFT, type,
-			      increment);
-}
-
-
-/**
- *	mtrr_del_page - delete a memory type region
- *	@reg: Register returned by mtrr_add
- *	@base: Physical base address
- *	@size: Size of region
- *
- *	If register is supplied then base and size are ignored. This is
- *	how drivers should call it.
- *
- *	Releases an MTRR region. If the usage count drops to zero the 
- *	register is freed and the region returns to default state.
- *	On success the register is returned, on failure a negative error
- *	code.
- */
-
-int mtrr_del_page (int reg, u64 base, u32 size)
-{
-	int i, max;
-	mtrr_type ltype;
-	u64 lbase;
-	u32 lsize;
-
-	max = get_num_var_ranges ();
-	down (&mtrr_lock);
-	if (reg < 0) {
-		/*  Search for existing MTRR  */
-		for (i = 0; i < max; ++i) {
-			get_mtrr (i, &lbase, &lsize, &ltype);
-			if (lbase == base && lsize == size) {
-				reg = i;
-				break;
-			}
-		}
-		if (reg < 0) {
-			up (&mtrr_lock);
-			printk ("mtrr: no MTRR for %Lx000,%x000 found\n", base, size);
-			return -EINVAL;
-		}
-	}
-
-	if (reg >= max) {
-		up (&mtrr_lock);
-		printk ("mtrr: register: %d too big\n", reg);
-		return -EINVAL;
-	}
-	get_mtrr (reg, &lbase, &lsize, &ltype);
-
-	if (lsize < 1) {
-		up (&mtrr_lock);
-		printk ("mtrr: MTRR %d not used\n", reg);
-		return -EINVAL;
-	}
-
-	if (usage_table[reg] < 1) {
-		up (&mtrr_lock);
-		printk ("mtrr: reg: %d has count=0\n", reg);
-		return -EINVAL;
-	}
-
-	if (--usage_table[reg] < 1)
-		set_mtrr (reg, 0, 0, 0);
-	compute_ascii ();
-	up (&mtrr_lock);
-	return reg;
-}
-
-
-/**
- *	mtrr_del - delete a memory type region
- *	@reg: Register returned by mtrr_add
- *	@base: Physical base address
- *	@size: Size of region
- *
- *	If register is supplied then base and size are ignored. This is
- *	how drivers should call it.
- *
- *	Releases an MTRR region. If the usage count drops to zero the 
- *	register is freed and the region returns to default state.
- *	On success the register is returned, on failure a negative error
- *	code.
- */
-
-int mtrr_del (int reg, u64 base, u32 size)
-{
-	if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1))) {
-		printk ("mtrr: size and base must be multiples of 4 kiB\n");
-		printk ("mtrr: size: 0x%x  base: 0x%Lx\n", size, base);
-		return -EINVAL;
-	}
-	return mtrr_del_page (reg, base >> PAGE_SHIFT, size >> PAGE_SHIFT);
-}
-
-
-#ifdef USERSPACE_INTERFACE
-
-static int mtrr_file_add (u64 base, u32 size, unsigned int type,
-		struct file *file, int page)
-{
-	int reg, max;
-	unsigned int *fcount = file->private_data;
-
-	max = get_num_var_ranges ();
-	if (fcount == NULL) {
-		if ((fcount =
-		     kmalloc (max * sizeof *fcount, GFP_KERNEL)) == NULL) {
-			printk ("mtrr: could not allocate\n");
-			return -ENOMEM;
-		}
-		memset (fcount, 0, max * sizeof *fcount);
-		file->private_data = fcount;
-	}
-
-	if (!page) {
-		if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1))) {
-			printk
-			    ("mtrr: size and base must be multiples of 4 kiB\n");
-			printk ("mtrr: size: 0x%x  base: 0x%Lx\n", size, base);
-			return -EINVAL;
-		}
-		base >>= PAGE_SHIFT;
-		size >>= PAGE_SHIFT;
-	}
-
-	reg = mtrr_add_page (base, size, type, 1);
-
-	if (reg >= 0)
-		++fcount[reg];
-	return reg;
-}
-
-
-static int mtrr_file_del (u64 base, u32 size,
-		struct file *file, int page)
-{
-	int reg;
-	unsigned int *fcount = file->private_data;
-
-	if (!page) {
-		if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1))) {
-			printk
-			    ("mtrr: size and base must be multiples of 4 kiB\n");
-			printk ("mtrr: size: 0x%x  base: 0x%Lx\n", size, base);
-			return -EINVAL;
-		}
-		base >>= PAGE_SHIFT;
-		size >>= PAGE_SHIFT;
-	}
-	reg = mtrr_del_page (-1, base, size);
-	if (reg < 0)
-		return reg;
-	if (fcount == NULL)
-		return reg;
-	if (fcount[reg] < 1)
-		return -EINVAL;
-	--fcount[reg];
-	return reg;
-}
-
-
-static ssize_t mtrr_read (struct file *file, char *buf, size_t len,
-		loff_t * ppos)
-{
-	if (*ppos >= ascii_buf_bytes)
-		return 0;
-
-	if (*ppos + len > ascii_buf_bytes)
-		len = ascii_buf_bytes - *ppos;
-
-	if (copy_to_user (buf, ascii_buffer + *ppos, len))
-		return -EFAULT;
-
-	*ppos += len;
-	return len;
-}
-
-
-static ssize_t mtrr_write (struct file *file, const char *buf,
-		size_t len, loff_t * ppos)
-/*  Format of control line:
-    "base=%Lx size=%Lx type=%s"     OR:
-    "disable=%d"
-*/
-{
-	int i, err, reg;
-	u64 base;
-	u32 size;
-	char *ptr;
-	char line[LINE_SIZE];
-
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
-
-	/*  Can't seek (pwrite) on this device  */
-	if (ppos != &file->f_pos)
-		return -ESPIPE;
-	memset (line, 0, LINE_SIZE);
-
-	if (len > LINE_SIZE)
-		len = LINE_SIZE;
-
-	if (copy_from_user (line, buf, len - 1))
-		return -EFAULT;
-	ptr = line + strlen (line) - 1;
-
-	if (*ptr == '\n')
-		*ptr = '\0';
-
-	if (!strncmp (line, "disable=", 8)) {
-		reg = simple_strtoul (line + 8, &ptr, 0);
-		err = mtrr_del_page (reg, 0, 0);
-		if (err < 0)
-			return err;
-		return len;
-	}
-
-	if (strncmp (line, "base=", 5)) {
-		printk ("mtrr: no \"base=\" in line: \"%s\"\n", line);
-		return -EINVAL;
-	}
-
-	base = simple_strtoull (line + 5, &ptr, 0);
-
-	for (; isspace (*ptr); ++ptr) ;
-
-	if (strncmp (ptr, "size=", 5)) {
-		printk ("mtrr: no \"size=\" in line: \"%s\"\n", line);
-		return -EINVAL;
-	}
-
-	size = simple_strtoull (ptr + 5, &ptr, 0);
-
-	if ((base & 0xfff) || (size & 0xfff)) {
-		printk ("mtrr: size and base must be multiples of 4 kiB\n");
-		printk ("mtrr: size: 0x%x  base: 0x%Lx\n", size, base);
-		return -EINVAL;
-	}
-
-	for (; isspace (*ptr); ++ptr) ;
-
-	if (strncmp (ptr, "type=", 5)) {
-		printk ("mtrr: no \"type=\" in line: \"%s\"\n", line);
-		return -EINVAL;
-	}
-	ptr += 5;
-
-	for (; isspace (*ptr); ++ptr) ;
-
-	for (i = 0; i < MTRR_NUM_TYPES; ++i) {
-		if (strcmp (ptr, mtrr_strings[i]))
-			continue;
-		base >>= PAGE_SHIFT;
-		size >>= PAGE_SHIFT;
-		err = mtrr_add_page ((u64) base, size, i, 1);
-		if (err < 0)
-			return err;
-		return len;
-	}
-	printk ("mtrr: illegal type: \"%s\"\n", ptr);
-	return -EINVAL;
-}
-
-
-static int mtrr_ioctl (struct inode *inode, struct file *file,
-		unsigned int cmd, unsigned long arg)
-{
-	int err;
-	mtrr_type type;
-	struct mtrr_sentry sentry;
-	struct mtrr_gentry gentry;
-
-	switch (cmd) {
-	default:
-		return -ENOIOCTLCMD;
-
-	case MTRRIOC_ADD_ENTRY:
-		if (!capable(CAP_SYS_ADMIN))
-			return -EPERM;
-		if (copy_from_user (&sentry, (void *) arg, sizeof sentry))
-			return -EFAULT;
-		err = mtrr_file_add (sentry.base, sentry.size, sentry.type,
-				   file, 0);
-		if (err < 0)
-			return err;
-		break;
-
-	case MTRRIOC_SET_ENTRY:
-		if (!capable(CAP_SYS_ADMIN))
-			return -EPERM;
-		if (copy_from_user (&sentry, (void *) arg, sizeof sentry))
-			return -EFAULT;
-		err = mtrr_add (sentry.base, sentry.size, sentry.type, 0);
-		if (err < 0)
-			return err;
-		break;
-
-	case MTRRIOC_DEL_ENTRY:
-		if (!capable(CAP_SYS_ADMIN))
-			return -EPERM;
-		if (copy_from_user (&sentry, (void *) arg, sizeof sentry))
-			return -EFAULT;
-		err = mtrr_file_del (sentry.base, sentry.size, file, 0);
-		if (err < 0)
-			return err;
-		break;
-
-	case MTRRIOC_KILL_ENTRY:
-		if (!capable(CAP_SYS_ADMIN))
-			return -EPERM;
-		if (copy_from_user (&sentry, (void *) arg, sizeof sentry))
-			return -EFAULT;
-		err = mtrr_del (-1, sentry.base, sentry.size);
-		if (err < 0)
-			return err;
-		break;
-
-	case MTRRIOC_GET_ENTRY:
-		if (copy_from_user (&gentry, (void *) arg, sizeof gentry))
-			return -EFAULT;
-		if (gentry.regnum >= get_num_var_ranges ())
-			return -EINVAL;
-		get_mtrr (gentry.regnum, (u64*) &gentry.base, &gentry.size, &type);
-
-		/* Hide entries that go above 4GB */
-		if (gentry.base + gentry.size > 0x100000
-		    || gentry.size == 0x100000)
-			gentry.base = gentry.size = gentry.type = 0;
-		else {
-			gentry.base <<= PAGE_SHIFT;
-			gentry.size <<= PAGE_SHIFT;
-			gentry.type = type;
-		}
-
-		if (copy_to_user ((void *) arg, &gentry, sizeof gentry))
-			return -EFAULT;
-		break;
-
-	case MTRRIOC_ADD_PAGE_ENTRY:
-		if (!capable(CAP_SYS_ADMIN))
-			return -EPERM;
-		if (copy_from_user (&sentry, (void *) arg, sizeof sentry))
-			return -EFAULT;
-		err = mtrr_file_add (sentry.base, sentry.size, sentry.type, file, 1);
-		if (err < 0)
-			return err;
-		break;
-
-	case MTRRIOC_SET_PAGE_ENTRY:
-		if (!capable(CAP_SYS_ADMIN))
-			return -EPERM;
-		if (copy_from_user (&sentry, (void *) arg, sizeof sentry))
-			return -EFAULT;
-		err = mtrr_add_page (sentry.base, sentry.size, sentry.type, 0);
-		if (err < 0)
-			return err;
-		break;
-
-	case MTRRIOC_DEL_PAGE_ENTRY:
-		if (!capable(CAP_SYS_ADMIN))
-			return -EPERM;
-		if (copy_from_user (&sentry, (void *) arg, sizeof sentry))
-			return -EFAULT;
-		err = mtrr_file_del (sentry.base, sentry.size, file, 1);
-		if (err < 0)
-			return err;
-		break;
-
-	case MTRRIOC_KILL_PAGE_ENTRY:
-		if (!capable(CAP_SYS_ADMIN))
-			return -EPERM;
-		if (copy_from_user (&sentry, (void *) arg, sizeof sentry))
-			return -EFAULT;
-		err = mtrr_del_page (-1, sentry.base, sentry.size);
-		if (err < 0)
-			return err;
-		break;
-
-	case MTRRIOC_GET_PAGE_ENTRY:
-		if (copy_from_user (&gentry, (void *) arg, sizeof gentry))
-			return -EFAULT;
-		if (gentry.regnum >= get_num_var_ranges ())
-			return -EINVAL;
-		get_mtrr (gentry.regnum, (u64*) &gentry.base, &gentry.size, &type);
-		gentry.type = type;
-
-		if (copy_to_user ((void *) arg, &gentry, sizeof gentry))
-			return -EFAULT;
-		break;
-	}
-	return 0;
-}
-
-
-static int mtrr_close (struct inode *ino, struct file *file)
-{
-	int i, max;
-	unsigned int *fcount = file->private_data;
-
-	if (fcount == NULL)
-		return 0;
-
-	lock_kernel ();
-	max = get_num_var_ranges ();
-	for (i = 0; i < max; ++i) {
-		while (fcount[i] > 0) {
-			if (mtrr_del (i, 0, 0) < 0)
-				printk ("mtrr: reg %d not used\n", i);
-			--fcount[i];
-		}
-	}
-	unlock_kernel ();
-	kfree (fcount);
-	file->private_data = NULL;
-	return 0;
-}
-
-
-static struct file_operations mtrr_fops = {
-	.owner   = THIS_MODULE,
-	.read    = mtrr_read,
-	.write   = mtrr_write,
-	.ioctl   = mtrr_ioctl,
-	.release = mtrr_close,
-};
-
-#ifdef CONFIG_PROC_FS
-static struct proc_dir_entry *proc_root_mtrr;
-#endif
-
-static devfs_handle_t devfs_handle;
-
-static void compute_ascii (void)
-{
-	char factor;
-	int i, max;
-	mtrr_type type;
-	u64 base;
-	u32 size;
-
-	ascii_buf_bytes = 0;
-	max = get_num_var_ranges ();
-	for (i = 0; i < max; i++) {
-		get_mtrr (i, &base, &size, &type);
-		if (size == 0)
-			usage_table[i] = 0;
-		else {
-			if (size < (0x100000 >> PAGE_SHIFT)) {
-				/* less than 1MB */
-				factor = 'K';
-				size <<= PAGE_SHIFT - 10;
-			} else {
-				factor = 'M';
-				size >>= 20 - PAGE_SHIFT;
-			}
-			sprintf (ascii_buffer + ascii_buf_bytes,
-				"reg%02i: base=0x%05Lx000 (%4iMB), size=%4i%cB: %s, count=%d\n",
-				i, base, (u32) base >> (20 - PAGE_SHIFT), size, factor,
-				attrib_to_str (type), usage_table[i]);
-			ascii_buf_bytes += strlen (ascii_buffer + ascii_buf_bytes);
-		}
-	}
-	devfs_set_file_size (devfs_handle, ascii_buf_bytes);
-#ifdef CONFIG_PROC_FS
-	if (proc_root_mtrr)
-		proc_root_mtrr->size = ascii_buf_bytes;
-#endif
-}
-
-#endif	/*  USERSPACE_INTERFACE  */
-
-EXPORT_SYMBOL (mtrr_add);
-EXPORT_SYMBOL (mtrr_del);
-
-static void __init mtrr_setup (void)
-{
-	/* If you want to use other vendors please port over the modular
-	   framework from i386 first. */
-	if (!cpu_has_mtrr || boot_cpu_data.x86_vendor != X86_VENDOR_AMD) 
-		return; 
-
-		 /* Query the width (in bits) of the physical
-		   addressable memory on the Hammer family. */
-		if ((cpuid_eax (0x80000000) >= 0x80000008)) {
-			u32 phys_addr;
-			phys_addr = cpuid_eax (0x80000008) & 0xff;
-			size_or_mask = ~((1L << phys_addr) - 1);
-			/*
-			 * top bits MBZ as its beyond the addressable range.
-			 * bottom bits MBZ as we don't care about lower 12 bits of addr.
-			 */
-			size_and_mask = (~size_or_mask) & 0x000ffffffffff000L;
-	}
-}
-
-#ifdef CONFIG_SMP
-
-static volatile u32 smp_changes_mask __initdata = 0;
-static struct mtrr_state smp_mtrr_state __initdata = { 0, 0 };
-
-#endif	/*  CONFIG_SMP  */
-
-void mtrr_init_cpu(int cpu)
-{
-#ifndef CONFIG_SMP
-	if (cpu == 0) 
-		mtrr_setup();
-#else
-	if (cpu == 0) { 
-	mtrr_setup();
-	get_mtrr_state (&smp_mtrr_state);
-	} else { 
-	u64 mask;
-	int count;
-	struct set_mtrr_context ctxt;
-
-		/* Note that this is not ideal, since the cache is
-		   only flushed/disabled for this CPU while the MTRRs
-		   are changed, but changing this requires more
-		   invasive changes to the way the kernel boots  */
-	set_mtrr_prepare (&ctxt);
-	mask = set_mtrr_state (&smp_mtrr_state, &ctxt);
-	set_mtrr_done (&ctxt);
-
-	/*  Use the atomic bitops to update the global mask  */
-		for (count = 0; count < (sizeof mask) * 8; ++count) {
-			if (mask & 1)
-			set_bit (count, &smp_changes_mask);
-		mask >>= 1;
-	}
-	} 
-#endif
-}
-
-static int __init mtrr_init (void)
-{
-#ifdef CONFIG_PROC_FS
-	proc_root_mtrr = create_proc_entry ("mtrr", S_IWUSR | S_IRUGO, &proc_root);
-	if (proc_root_mtrr) {
-		proc_root_mtrr->owner = THIS_MODULE;
-		proc_root_mtrr->proc_fops = &mtrr_fops;
-	}
-#endif
-#ifdef CONFIG_DEVFS_FS
-	devfs_handle = devfs_register (NULL, "cpu/mtrr", DEVFS_FL_DEFAULT, 0, 0,
-				S_IFREG | S_IRUGO | S_IWUSR,
-				&mtrr_fops, NULL);
-#endif
-	init_table ();
-
-#ifdef CONFIG_SMP
-	finalize_mtrr_state (&smp_mtrr_state);
-	mtrr_state_warn (smp_changes_mask);
-#endif
-
-	return 0;
-}
-
-__initcall(mtrr_init);
diff -Nru a/arch/x86_64/kernel/nmi.c b/arch/x86_64/kernel/nmi.c
--- a/arch/x86_64/kernel/nmi.c	Mon Dec 23 21:21:54 2002
+++ b/arch/x86_64/kernel/nmi.c	Mon Dec 23 21:21:54 2002
@@ -300,12 +300,18 @@
  
 asmlinkage void do_nmi(struct pt_regs * regs, long error_code)
 {
-	int cpu = smp_processor_id();
+	int cpu;
+
+	nmi_enter();
+
+	cpu = smp_processor_id(); 
 
 	add_pda(__nmi_count,1);
 
 	if (!nmi_callback(regs, cpu))
 		default_do_nmi(regs);
+	
+	nmi_exit();
 }
 
 void set_nmi_callback(nmi_callback_t callback)
diff -Nru a/arch/x86_64/kernel/pci-gart.c b/arch/x86_64/kernel/pci-gart.c
--- a/arch/x86_64/kernel/pci-gart.c	Mon Dec 23 21:21:53 2002
+++ b/arch/x86_64/kernel/pci-gart.c	Mon Dec 23 21:21:53 2002
@@ -245,7 +245,7 @@
 	
 	printk(KERN_ERR 
   "PCI-DMA: Error: ran out out IOMMU space for %p size %lu at device %s[%s]\n",
-	       addr,size, dev ? dev->name : "?", dev ? dev->slot_name : "?");
+	       addr,size, dev ? dev->dev.name : "?", dev ? dev->slot_name : "?");
 
 	if (size > PAGE_SIZE*EMERGENCY_PAGES) {
 		if (dir == PCI_DMA_FROMDEVICE || dir == PCI_DMA_BIDIRECTIONAL)
@@ -286,7 +286,7 @@
 	if (!need_iommu(dev, phys_mem, size))
 		return phys_mem; 
 
-	npages = round_up(size, PAGE_SIZE) >> PAGE_SHIFT;
+	npages = round_up(size + ((u64)addr & ~PAGE_MASK), PAGE_SIZE) >> PAGE_SHIFT;
 
 	iommu_page = alloc_iommu(npages); 
 	if (iommu_page == -1) {
@@ -328,7 +328,7 @@
 	    dma_addr > iommu_bus_base + iommu_size)
 		return;
 	iommu_page = (dma_addr - iommu_bus_base)>>PAGE_SHIFT;	
-	npages = round_up(size, PAGE_SIZE) >> PAGE_SHIFT;
+	npages = round_up(size + (dma_addr & ~PAGE_MASK), PAGE_SIZE) >> PAGE_SHIFT;
 	for (i = 0; i < npages; i++) { 
 		iommu_gatt_base[iommu_page + i] = 0; 
 #ifdef CONFIG_IOMMU_LEAK
diff -Nru a/arch/x86_64/kernel/process.c b/arch/x86_64/kernel/process.c
--- a/arch/x86_64/kernel/process.c	Mon Dec 23 21:21:50 2002
+++ b/arch/x86_64/kernel/process.c	Mon Dec 23 21:21:50 2002
@@ -24,6 +24,7 @@
 #include <linux/sched.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
+#include <linux/elfcore.h>
 #include <linux/smp.h>
 #include <linux/smp_lock.h>
 #include <linux/stddef.h>
@@ -223,6 +224,7 @@
 	struct task_struct *tsk = current;
 
 	memset(tsk->thread.debugreg, 0, sizeof(unsigned long)*8);
+	memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));	
 	/*
 	 * Forget coprocessor state..
 	 */
@@ -259,7 +261,7 @@
 	if (rsp == ~0) {
 		childregs->rsp = (unsigned long)childregs;
 	}
-	p->user_tid = NULL;
+	p->set_child_tid = p->clear_child_tid = NULL;
 
 	p->thread.rsp = (unsigned long) childregs;
 	p->thread.rsp0 = (unsigned long) (childregs+1);
@@ -322,10 +324,6 @@
 /*
  *	switch_to(x,y) should switch tasks from x to y.
  *
- * We fsave/fwait so that an exception goes off at the right time
- * (as a call from the fsave or fwait in effect) rather than to
- * the wrong process. 
- * 
  * This could still be optimized: 
  * - fold all the options into a flag word and test it with a single test.
  * - could test fs/gs bitsliced
@@ -356,44 +354,37 @@
 	if (unlikely(next->ds | prev->ds))
 		loadsegment(ds, next->ds);
 
+	load_TLS(next, cpu);
+
 	/* 
 	 * Switch FS and GS.
-	 * XXX Check if this is safe on SMP (!= -> |)
-	 * Need to simplify this.
 	 */
 	{ 
-		unsigned int fsindex;
-		unsigned int gsindex;
-
+		unsigned fsindex;
 		asm volatile("movl %%fs,%0" : "=g" (fsindex)); 
-		asm volatile("movl %%gs,%0" : "=g" (gsindex)); 
-
-		/*
-		 * Load the per-thread Thread-Local Storage descriptor.
-		 */
-		if (load_TLS(next, cpu)) {
-			loadsegment(fs,next->fsindex);
-			/* should find a way to optimize this away - it is
-			   slow */
-			goto loadgs;    
-		} else { 
-			if (fsindex  != next->fsindex)
-				loadsegment(fs,next->fsindex); 
-			if (gsindex != next->gsindex) {
-			loadgs:
-				load_gs_index(next->gsindex); 
-			} 	
-		}
-				
+		/* segment register != 0 always requires a reload. 
+		   also reload when it has changed. 
+		   when prev process used 64bit base always reload
+		   to avoid an information leak. */
+		if (unlikely((fsindex | next->fsindex) || prev->fs))
+			loadsegment(fs, next->fsindex);
+		/* check if the user changed the selector
+		   if yes clear 64bit base. */
 		if (unlikely(fsindex != prev->fsindex))
 			prev->fs = 0;				
-		if ((fsindex != prev->fsindex) || (prev->fs != next->fs))
+		/* when next process has a 64bit base use it */
+		if (next->fs) 
 			wrmsrl(MSR_FS_BASE, next->fs); 
 		prev->fsindex = fsindex;
-
+	}
+	{ 
+		unsigned gsindex;
+		asm volatile("movl %%gs,%0" : "=g" (gsindex)); 
+		if (unlikely((gsindex | next->gsindex) || prev->gs))
+			load_gs_index(next->gsindex);
 		if (unlikely(gsindex != prev->gsindex)) 
 			prev->gs = 0;				
-		if (gsindex != prev->gsindex || prev->gs != next->gs)
+		if (next->gs)
 			wrmsrl(MSR_KERNEL_GS_BASE, next->gs); 
 		prev->gsindex = gsindex;
 	}
@@ -477,16 +468,17 @@
 asmlinkage long sys_fork(struct pt_regs regs)
 {
 	struct task_struct *p;
-	p = do_fork(SIGCHLD, regs.rsp, &regs, 0, NULL);
+	p = do_fork(SIGCHLD, regs.rsp, &regs, 0, NULL, NULL);
 	return IS_ERR(p) ? PTR_ERR(p) : p->pid;
 }
 
-asmlinkage long sys_clone(unsigned long clone_flags, unsigned long newsp, void *user_tid, struct pt_regs regs)
+asmlinkage long sys_clone(unsigned long clone_flags, unsigned long newsp, void *parent_tid, void *child_tid, struct pt_regs regs)
 {
 	struct task_struct *p;
 	if (!newsp)
 		newsp = regs.rsp;
-	p = do_fork(clone_flags & ~CLONE_IDLETASK, newsp, &regs, 0, user_tid);
+	p = do_fork(clone_flags & ~CLONE_IDLETASK, newsp, &regs, 0, 
+		    parent_tid, child_tid);
 	return IS_ERR(p) ? PTR_ERR(p) : p->pid;
 }
 
@@ -503,7 +495,8 @@
 asmlinkage long sys_vfork(struct pt_regs regs)
 {
 	struct task_struct *p;
-	p = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs.rsp, &regs, 0, NULL);
+	p = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs.rsp, &regs, 0, 
+		    NULL, NULL);
 	return IS_ERR(p) ? PTR_ERR(p) : p->pid;
 }
 
@@ -547,7 +540,8 @@
 	case ARCH_SET_GS:
 		if (addr >= TASK_SIZE) 
 			return -EPERM; 
-		asm volatile("movw %%gs,%0" : "=g" (current->thread.gsindex)); 
+		load_gs_index(0);
+		current->thread.gsindex = 0;
 		current->thread.gs = addr;
 		ret = checking_wrmsrl(MSR_KERNEL_GS_BASE, addr); 
 		break;
@@ -556,7 +550,8 @@
 		   with gs */
 		if (addr >= TASK_SIZE)
 			return -EPERM; 
-		asm volatile("movw %%fs,%0" : "=g" (current->thread.fsindex)); 
+		asm volatile("movl %0,%%fs" :: "r" (0));
+		current->thread.fsindex = 0;
 		current->thread.fs = addr;
 		ret = checking_wrmsrl(MSR_FS_BASE, addr); 
 		break;
@@ -690,4 +685,23 @@
 	if (copy_to_user(u_info, &info, sizeof(info)))
 		return -EFAULT;
 	return 0;
+}
+
+/* 
+ * Capture the user space registers if the task is not running (in user space)
+ */
+int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs)
+{
+	struct pt_regs *pp, ptregs;
+
+	pp = (struct pt_regs *)(tsk->thread.rsp0);
+	--pp; 
+
+	ptregs = *pp; 
+	ptregs.cs &= 0xffff;
+	ptregs.ss &= 0xffff;
+
+	elf_core_copy_regs(regs, &ptregs);
+ 
+	return 1;
 }
diff -Nru a/arch/x86_64/kernel/profile.c b/arch/x86_64/kernel/profile.c
--- a/arch/x86_64/kernel/profile.c	Mon Dec 23 21:21:55 2002
+++ b/arch/x86_64/kernel/profile.c	Mon Dec 23 21:21:55 2002
@@ -1,5 +1,5 @@
 /*
- *	linux/arch/i386/kernel/profile.c
+ *	linux/arch/x86_64/kernel/profile.c
  *
  *	(C) 2002 John Levon <levon@movementarian.org>
  *
diff -Nru a/arch/x86_64/kernel/setup64.c b/arch/x86_64/kernel/setup64.c
--- a/arch/x86_64/kernel/setup64.c	Mon Dec 23 21:21:52 2002
+++ b/arch/x86_64/kernel/setup64.c	Mon Dec 23 21:21:52 2002
@@ -41,6 +41,23 @@
 
 char boot_cpu_stack[IRQSTACKSIZE] __cacheline_aligned;
 
+unsigned long __supported_pte_mask = ~0UL;
+static int do_not_nx = 0;
+
+static int __init nonx_setup(char *str)
+{
+        if (!strncmp(str,"off",3)) { 
+                __supported_pte_mask &= ~_PAGE_NX; 
+                do_not_nx = 1; 
+        } else if (!strncmp(str, "on",3)) { 
+                do_not_nx = 0; 
+                __supported_pte_mask |= _PAGE_NX; 
+        } 
+        return 1;
+} 
+
+__setup("noexec=", nonx_setup); 
+
 #ifndef  __GENERIC_PER_CPU
 
 unsigned long __per_cpu_offset[NR_CPUS];
@@ -127,7 +144,7 @@
 	int cpu = smp_processor_id();
 #endif
 	struct tss_struct * t = &init_tss[cpu];
-	unsigned long v; 
+	unsigned long v, efer; 
 	char *estacks; 
 	struct task_struct *me;
 
@@ -188,6 +205,11 @@
 	wrmsrl(MSR_FS_BASE, 0);
 	wrmsrl(MSR_KERNEL_GS_BASE, 0);
 	barrier(); 
+
+	rdmsrl(MSR_EFER, efer); 
+        if (!(efer & EFER_NX) || do_not_nx) { 
+                __supported_pte_mask &= ~_PAGE_NX; 
+        }       
 
 	/*
 	 * set up and load the per-CPU TSS
diff -Nru a/arch/x86_64/kernel/signal.c b/arch/x86_64/kernel/signal.c
--- a/arch/x86_64/kernel/signal.c	Mon Dec 23 21:21:58 2002
+++ b/arch/x86_64/kernel/signal.c	Mon Dec 23 21:21:58 2002
@@ -24,9 +24,11 @@
 #include <linux/stddef.h>
 #include <linux/personality.h>
 #include <linux/compiler.h>
+#include <linux/suspend.h>
 #include <asm/ucontext.h>
 #include <asm/uaccess.h>
 #include <asm/i387.h>
+#include <asm/proto.h>
 
 /* #define DEBUG_SIG 1 */
 
@@ -184,11 +186,10 @@
  * Set up a signal frame.
  */
 
-static int
-setup_sigcontext(struct sigcontext *sc, struct pt_regs *regs, unsigned long mask)
+static inline int
+setup_sigcontext(struct sigcontext *sc, struct pt_regs *regs, unsigned long mask, struct task_struct *me)
 {
 	int tmp, err = 0;
-	struct task_struct *me = current;
 
 	tmp = 0;
 	__asm__("movl %%gs,%0" : "=r"(tmp): "0"(tmp));
@@ -226,8 +227,6 @@
  * Determine which stack to use..
  */
 
-#define round_down(p, r) ((void *)  ((unsigned long)((p) - (r) + 1) & ~((r)-1)))
-
 static void *
 get_stack(struct k_sigaction *ka, struct pt_regs *regs, unsigned long size)
 {
@@ -242,19 +241,20 @@
 			rsp = current->sas_ss_sp + current->sas_ss_size;
 	}
 
-	return round_down(rsp - size, 16); 
+	return (void *)round_down(rsp - size, 16); 
 }
 
 static void setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
 			   sigset_t *set, struct pt_regs * regs)
 {
-	struct rt_sigframe *frame = NULL;
+	struct rt_sigframe *frame;
 	struct _fpstate *fp = NULL; 
 	int err = 0;
+	struct task_struct *me = current;
 
-	if (current->used_math) {
+	if (me->used_math) {
 		fp = get_stack(ka, regs, sizeof(struct _fpstate)); 
-		frame = round_down((char *)fp - sizeof(struct rt_sigframe), 16) - 8;
+		frame = (void *)round_down((u64)fp - sizeof(struct rt_sigframe), 16) - 8;
 
 		if (!access_ok(VERIFY_WRITE, fp, sizeof(struct _fpstate))) { 
 		goto give_sigsegv;
@@ -262,10 +262,9 @@
 
 		if (save_i387(fp) < 0) 
 			err |= -1; 
-	}
-
-	if (!frame)
+	} else {
 		frame = get_stack(ka, regs, sizeof(struct rt_sigframe)) - 8;
+	}
 
 	if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) {
 		goto give_sigsegv;
@@ -281,13 +280,18 @@
 	/* Create the ucontext.  */
 	err |= __put_user(0, &frame->uc.uc_flags);
 	err |= __put_user(0, &frame->uc.uc_link);
-	err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
+	err |= __put_user(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
 	err |= __put_user(sas_ss_flags(regs->rsp),
 			  &frame->uc.uc_stack.ss_flags);
-	err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
-	err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0]);
+	err |= __put_user(me->sas_ss_size, &frame->uc.uc_stack.ss_size);
+	err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0], me);
 	err |= __put_user(fp, &frame->uc.uc_mcontext.fpstate);
+	if (sizeof(*set) == 16) { 
+		__put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]);
+		__put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]); 
+	} else { 		
 	err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
+	}
 
 	/* Set up to return from userspace.  If provided, use a stub
 	   already in userspace.  */
@@ -295,7 +299,7 @@
 	if (ka->sa.sa_flags & SA_RESTORER) {
 		err |= __put_user(ka->sa.sa_restorer, &frame->pretcode);
 	} else {
-		printk("%s forgot to set SA_RESTORER for signal %d.\n", current->comm, sig); 
+		printk("%s forgot to set SA_RESTORER for signal %d.\n", me->comm, sig); 
 		goto give_sigsegv; 
 	}
 
@@ -338,7 +342,7 @@
 give_sigsegv:
 	if (sig == SIGSEGV)
 		ka->sa.sa_handler = SIG_DFL;
-	signal_fault(regs,frame,"signal setup");
+	signal_fault(regs,frame,"signal deliver");
 }
 
 /*
@@ -360,6 +364,9 @@
 	if (regs->orig_rax >= 0) {
 		/* If so, check system call restarting.. */
 		switch (regs->rax) {
+		        case -ERESTART_RESTARTBLOCK:
+				current_thread_info()->restart_block.fn = do_no_restart_syscall;
+				/* FALL THROUGH */
 			case -ERESTARTNOHAND:
 				regs->rax = -EINTR;
 				break;
@@ -374,6 +381,10 @@
 				regs->rax = regs->orig_rax;
 				regs->rip -= 2;
 		}
+		if (regs->rax == -ERESTART_RESTARTBLOCK){
+			regs->rax = __NR_restart_syscall;
+ 			regs->rip -= 2;
+ 		}		
 	}
 
 #ifdef CONFIG_IA32_EMULATION
@@ -418,6 +429,11 @@
 		return 1;
 	} 	
 
+	if (current->flags & PF_FREEZE) {
+		refrigerator(0);
+		goto no_signal;
+	}
+
 	if (!oldset)
 		oldset = &current->blocked;
 
@@ -435,6 +451,7 @@
 		return 1;
 	}
 
+ no_signal:
 	/* Did we come from a system call? */
 	if (regs->orig_rax >= 0) {
 		/* Restart the system call - no handlers present */
diff -Nru a/arch/x86_64/kernel/smp.c b/arch/x86_64/kernel/smp.c
--- a/arch/x86_64/kernel/smp.c	Mon Dec 23 21:21:52 2002
+++ b/arch/x86_64/kernel/smp.c	Mon Dec 23 21:21:52 2002
@@ -18,11 +18,11 @@
 #include <linux/smp.h>
 #include <linux/kernel_stat.h>
 #include <linux/mc146818rtc.h>
+#include <linux/interrupt.h>
 
 #include <asm/mtrr.h>
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
-#include <asm/hardirq.h>
 
 /*
  * the following functions deal with sending IPIs between CPUs.
diff -Nru a/arch/x86_64/kernel/smpboot.c b/arch/x86_64/kernel/smpboot.c
--- a/arch/x86_64/kernel/smpboot.c	Mon Dec 23 21:22:02 2002
+++ b/arch/x86_64/kernel/smpboot.c	Mon Dec 23 21:22:02 2002
@@ -323,12 +323,6 @@
 
 	local_irq_enable();
 
-#ifdef CONFIG_MTRR
-	/*
-	 * Must be done before calibration delay is computed
-	 */
-	mtrr_init_cpu (cpuid);
-#endif
 	/*
 	 * Get our bogomips.
 	 */
@@ -344,6 +338,8 @@
 
 	notify_die(DIE_CPUINIT, "cpuinit", NULL, 0);
 
+	local_irq_disable();
+
 	/*
 	 * Allow the master to continue.
 	 */
@@ -436,7 +432,7 @@
 	 * don't care about the rip and regs settings since
 	 * we'll never reschedule the forked task.
 	 */
-	return do_fork(CLONE_VM|CLONE_IDLETASK, 0, &regs, 0, NULL);
+	return do_fork(CLONE_VM|CLONE_IDLETASK, 0, &regs, 0, NULL, NULL);
 }
 
 #if APIC_DEBUG
@@ -969,12 +965,17 @@
 int __devinit __cpu_up(unsigned int cpu)
 {
 	/* This only works at boot for x86.  See "rewrite" above. */
-	if (test_bit(cpu, &smp_commenced_mask))
+	if (test_bit(cpu, &smp_commenced_mask)) { 
+		local_irq_enable();
 		return -ENOSYS;
+	}
 
 	/* In case one didn't come up */
-	if (!test_bit(cpu, &cpu_callin_map))
+	if (!test_bit(cpu, &cpu_callin_map)) { 
+		local_irq_enable();
 		return -EIO;
+	}
+	local_irq_enable();
 
 	/* Unleash the CPU! */
 	Dprintk("waiting for cpu %d\n", cpu);
diff -Nru a/arch/x86_64/kernel/suspend.c b/arch/x86_64/kernel/suspend.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/arch/x86_64/kernel/suspend.c	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,143 @@
+/*
+ * Suspend support specific for i386.
+ *
+ * Distribute under GPLv2
+ *
+ * Copyright (c) 2002 Pavel Machek <pavel@suse.cz>
+ * Copyright (c) 2001 Patrick Mochel <mochel@osdl.org>
+ */
+
+#include <linux/config.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/spinlock.h>
+#include <linux/poll.h>
+#include <linux/delay.h>
+#include <linux/sysrq.h>
+#include <linux/compatmac.h>
+#include <linux/proc_fs.h>
+#include <linux/irq.h>
+#include <linux/pm.h>
+#include <linux/device.h>
+#include <linux/suspend.h>
+#include <asm/uaccess.h>
+#include <asm/acpi.h>
+#include <asm/tlbflush.h>
+#include <asm/io.h>
+
+static struct saved_context saved_context;
+
+unsigned long saved_context_eax, saved_context_ebx, saved_context_ecx, saved_context_edx;
+unsigned long saved_context_esp, saved_context_ebp, saved_context_esi, saved_context_edi;
+unsigned long saved_context_r08, saved_context_r09, saved_context_r10, saved_context_r11;
+unsigned long saved_context_r12, saved_context_r13, saved_context_r14, saved_context_r15;
+unsigned long saved_context_eflags;
+
+void save_processor_state (void)
+{
+	kernel_fpu_begin();
+
+	/*
+	 * descriptor tables
+	 */
+	asm volatile ("sgdt %0" : "=m" (saved_context.gdt_limit));
+	asm volatile ("sidt %0" : "=m" (saved_context.idt_limit));
+	asm volatile ("sldt %0" : "=m" (saved_context.ldt));
+	asm volatile ("str %0"  : "=m" (saved_context.tr));
+
+	/* XMM0..XMM15 should be handled by kernel_fpu_begin(). */
+	/* EFER should be constant for kernel version, no need to handle it. */
+	/*
+	 * segment registers
+	 */
+	asm volatile ("movw %%ds, %0" : "=m" (saved_context.ds));
+	asm volatile ("movw %%es, %0" : "=m" (saved_context.es));
+	asm volatile ("movw %%fs, %0" : "=m" (saved_context.fs));
+	asm volatile ("movw %%gs, %0" : "=m" (saved_context.gs));
+	asm volatile ("movw %%ss, %0" : "=m" (saved_context.ss));
+
+	asm volatile ("swapgs");
+	rdmsrl(0xc0000100, saved_context.fs_base);
+	rdmsrl(0xc0000101, saved_context.gs_base);
+	asm volatile ("swapgs");
+
+	/*
+	 * control registers 
+	 */
+	asm volatile ("movq %%cr0, %0" : "=r" (saved_context.cr0));
+	asm volatile ("movq %%cr2, %0" : "=r" (saved_context.cr2));
+	asm volatile ("movq %%cr3, %0" : "=r" (saved_context.cr3));
+	asm volatile ("movq %%cr4, %0" : "=r" (saved_context.cr4));
+}
+
+static void
+do_fpu_end(void)
+{
+        /* restore FPU regs if necessary */
+	/* Do it out of line so that gcc does not move cr0 load to some stupid place */
+        kernel_fpu_end();
+}
+
+void restore_processor_state(void)
+{
+	/*
+	 * control registers
+	 */
+	asm volatile ("movq %0, %%cr4" :: "r" (saved_context.cr4));
+	asm volatile ("movq %0, %%cr3" :: "r" (saved_context.cr3));
+	asm volatile ("movq %0, %%cr2" :: "r" (saved_context.cr2));
+	asm volatile ("movq %0, %%cr0" :: "r" (saved_context.cr0));
+
+	/*
+	 * segment registers
+	 */
+	asm volatile ("movw %0, %%ds" :: "r" (saved_context.ds));
+	asm volatile ("movw %0, %%es" :: "r" (saved_context.es));
+	asm volatile ("movw %0, %%fs" :: "r" (saved_context.fs));
+	load_gs_index(saved_context.gs);
+	asm volatile ("movw %0, %%ss" :: "r" (saved_context.ss));
+
+	asm volatile ("swapgs");
+	wrmsrl(0xc0000100, saved_context.fs_base);
+	wrmsrl(0xc0000101, saved_context.gs_base);
+	asm volatile ("swapgs");
+
+	/*
+	 * now restore the descriptor tables to their proper values
+	 * ltr is done i fix_processor_context().
+	 */
+	asm volatile ("lgdt %0" :: "m" (saved_context.gdt_limit));
+	asm volatile ("lidt %0" :: "m" (saved_context.idt_limit));
+	asm volatile ("lldt %0" :: "m" (saved_context.ldt));
+
+	fix_processor_context();
+
+	do_fpu_end();
+}
+
+void fix_processor_context(void)
+{
+	int cpu = smp_processor_id();
+	struct tss_struct * t = init_tss + cpu;
+
+	printk("Should fix processor context!\n");
+	load_LDT(&current->mm->context);	/* This does lldt */
+
+	/*
+	 * Now maybe reload the debug registers
+	 */
+	if (current->thread.debugreg[7]){
+                loaddebug(&current->thread, 0);
+                loaddebug(&current->thread, 1);
+                loaddebug(&current->thread, 2);
+                loaddebug(&current->thread, 3);
+                /* no 4 and 5 */
+                loaddebug(&current->thread, 6);
+                loaddebug(&current->thread, 7);
+	}
+
+}
+
+
diff -Nru a/arch/x86_64/kernel/suspend_asm.S b/arch/x86_64/kernel/suspend_asm.S
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/arch/x86_64/kernel/suspend_asm.S	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,125 @@
+/* originally gcc generated, but now changed. don't overwrite. */
+	
+	.text
+#include <linux/linkage.h>
+#include <asm/segment.h>
+#include <asm/page.h>
+
+/* Input:
+ * rdi	resume flag 
+ */	
+			
+ENTRY(do_magic)
+.LFB5:
+	subq	$8, %rsp
+.LCFI2:
+	testl	%edi, %edi
+	jne	.L90
+	call	do_magic_suspend_1
+	call	save_processor_state
+
+	movq %rsp, saved_context_esp(%rip)
+	movq %rax, saved_context_eax(%rip)
+	movq %rbx, saved_context_ebx(%rip)
+	movq %rcx, saved_context_ecx(%rip)
+	movq %rdx, saved_context_edx(%rip)
+	movq %rbp, saved_context_ebp(%rip)
+	movq %rsi, saved_context_esi(%rip)
+	movq %rdi, saved_context_edi(%rip)
+	movq %r8,  saved_context_r08(%rip)
+	movq %r9,  saved_context_r09(%rip)
+	movq %r10, saved_context_r10(%rip)
+	movq %r11, saved_context_r11(%rip)
+	movq %r12, saved_context_r12(%rip)
+	movq %r13, saved_context_r13(%rip)
+	movq %r14, saved_context_r14(%rip)
+	movq %r15, saved_context_r15(%rip)
+	pushfq ; popq saved_context_eflags(%rip)
+
+	addq	$8, %rsp
+	jmp	do_magic_suspend_2
+.L90:
+	/* set up cr3 */	
+	leaq	init_level4_pgt(%rip),%rax
+	subq	$__START_KERNEL_map,%rax
+	movq %rax,%cr3
+
+	movq	mmu_cr4_features(%rip), %rax
+	movq	%rax, %rdx
+	
+	andq	$~(1<<7), %rdx	# PGE
+	movq %rdx, %cr4;  # turn off PGE     
+	movq %cr3, %rcx;  # flush TLB        
+	movq %rcx, %cr3;                     
+	movq %rax, %cr4;  # turn PGE back on 
+
+	call	do_magic_resume_1
+	movl	nr_copy_pages(%rip), %eax
+	xorl	%ecx, %ecx
+	movq	$0, loop(%rip)
+	testl	%eax, %eax
+	je	.L108
+.L105:
+	xorl	%esi, %esi
+	movq	$0, loop2(%rip)
+	jmp	.L104
+	.p2align 4,,7
+.L111:
+	movq	loop(%rip), %rcx
+.L104:
+	movq	pagedir_nosave(%rip), %rdx
+	movq	%rcx, %rax
+	salq	$5, %rax
+	movq	8(%rdx,%rax), %rcx
+	movq	(%rdx,%rax), %rax
+	movzbl	(%rsi,%rax), %eax
+	movb	%al, (%rsi,%rcx)
+
+	movq %cr3, %rax;  # flush TLB 
+	movq %rax, %cr3;              
+
+	movq	loop2(%rip), %rax
+	incq	%rax
+	cmpq	$4095, %rax
+	movq	%rax, %rsi
+	movq	%rax, loop2(%rip)
+	jbe	.L111
+	movq	loop(%rip), %rax
+	incq	%rax
+	movq	%rax, %rcx
+	movq	%rax, loop(%rip)
+	mov	nr_copy_pages(%rip), %eax
+	cmpq	%rax, %rcx
+	jb	.L105
+.L108:
+	.align 4
+	movl	$24, %eax
+
+	movl %eax, %ds
+	movq saved_context_esp(%rip), %rsp
+	movq saved_context_ebp(%rip), %rbp
+	movq saved_context_eax(%rip), %rax
+	movq saved_context_ebx(%rip), %rbx
+	movq saved_context_ecx(%rip), %rcx
+	movq saved_context_edx(%rip), %rdx
+	movq saved_context_esi(%rip), %rsi
+	movq saved_context_edi(%rip), %rdi
+	movq saved_context_r08(%rip), %r8
+	movq saved_context_r09(%rip), %r9
+	movq saved_context_r10(%rip), %r10
+	movq saved_context_r11(%rip), %r11
+	movq saved_context_r12(%rip), %r12
+	movq saved_context_r13(%rip), %r13
+	movq saved_context_r14(%rip), %r14
+	movq saved_context_r15(%rip), %r15
+	pushq saved_context_eflags(%rip) ; popfq
+	call	restore_processor_state
+	addq	$8, %rsp
+	jmp	do_magic_resume_2
+
+	.section .data.nosave
+loop:
+	.quad 0
+loop2:	
+	.quad 0		
+	.previous
\ No newline at end of file
diff -Nru a/arch/x86_64/kernel/traps.c b/arch/x86_64/kernel/traps.c
--- a/arch/x86_64/kernel/traps.c	Mon Dec 23 21:21:50 2002
+++ b/arch/x86_64/kernel/traps.c	Mon Dec 23 21:21:50 2002
@@ -83,22 +83,18 @@
 #include <linux/kallsyms.h> 
 int printk_address(unsigned long address)
 { 
-	unsigned long dummy; 
-	const char *modname, *secname, *symname;
-	unsigned long symstart; 
+	unsigned long offset = 0, symsize;
+	const char *symname;
+	char *modname;
 	char *delim = ":"; 
 
-	/* What a function call! */
-	if (!kallsyms_address_to_symbol(address, 
-					&modname, &dummy, &dummy, 
-					&secname, &dummy, &dummy,
-					&symname, &symstart, &dummy)) {
+	symname = kallsyms_lookup(address, &symsize, &offset, &modname); 
+	if (!symname) 
 		return printk("[<%016lx>]", address);
-	} 
-	if (!strcmp(modname, "kernel"))
+	if (!modname) 
 		modname = delim = ""; 		
         return printk("<%016lx>{%s%s%s%s%+ld}",
-		      address,delim,modname,delim,symname,address-symstart); 
+		      address,delim,modname,delim,symname,offset); 
 } 
 #else
 int printk_address(unsigned long address)
@@ -110,7 +106,8 @@
 
 #ifdef CONFIG_MODULES
 
-extern struct module kernel_module;
+/* FIXME: Accessed without a lock --RR */
+extern struct list_head modules;
 
 static inline int kernel_text_address(unsigned long addr)
 {
@@ -121,11 +118,11 @@
        addr <= (unsigned long) &_etext)
        return 1;
 
-   for (mod = module_list; mod != &kernel_module; mod = mod->next) {
+   list_for_each_entry(mod, &modules, list) { 	
        /* mod_bound tests for addr being inside the vmalloc'ed
         * module area. Of course it'd be better to test only
         * for the .text subset... */
-       if (mod_bound(addr, 0, mod)) {
+       if (mod_bound((void *)addr, 0, mod)) {
            retval = 1;
            break;
        }
@@ -173,7 +170,7 @@
 	int i;
 
 	printk("\nCall Trace:");
-	i = 12; 
+	i = 0; 
 	
 	estack_end = in_exception_stack(cpu, (unsigned long)stack); 
 	if (estack_end) { 
diff -Nru a/arch/x86_64/kernel/x8664_ksyms.c b/arch/x86_64/kernel/x8664_ksyms.c
--- a/arch/x86_64/kernel/x8664_ksyms.c	Mon Dec 23 21:21:51 2002
+++ b/arch/x86_64/kernel/x8664_ksyms.c	Mon Dec 23 21:21:51 2002
@@ -2,7 +2,6 @@
 #include <linux/module.h>
 #include <linux/smp.h>
 #include <linux/user.h>
-#include <linux/mca.h>
 #include <linux/sched.h>
 #include <linux/in6.h>
 #include <linux/interrupt.h>
@@ -46,7 +45,7 @@
 
 /* platform dependent support */
 EXPORT_SYMBOL(boot_cpu_data);
-EXPORT_SYMBOL(dump_fpu);
+//EXPORT_SYMBOL(dump_fpu);
 EXPORT_SYMBOL(__ioremap);
 EXPORT_SYMBOL(ioremap_nocache);
 EXPORT_SYMBOL(iounmap);
@@ -120,10 +119,6 @@
 
 #endif
 
-#ifdef CONFIG_MCA
-EXPORT_SYMBOL(machine_id);
-#endif
-
 #ifdef CONFIG_VT
 EXPORT_SYMBOL(screen_info);
 #endif
@@ -199,3 +194,6 @@
 EXPORT_SYMBOL(out_of_line_bug);
 
 EXPORT_SYMBOL(init_level4_pgt);
+
+extern unsigned long __supported_pte_mask;
+EXPORT_SYMBOL(__supported_pte_mask);
diff -Nru a/arch/x86_64/lib/io.c b/arch/x86_64/lib/io.c
--- a/arch/x86_64/lib/io.c	Mon Dec 23 21:21:51 2002
+++ b/arch/x86_64/lib/io.c	Mon Dec 23 21:21:51 2002
@@ -2,12 +2,12 @@
 #include <asm/io.h>
 #include <linux/module.h>
 
-void *memcpy_toio(void *dst,void*src,unsigned len)
+void *memcpy_toio(void *dst,const void*src,unsigned len)
 {
 	return __inline_memcpy(__io_virt(dst),src,len);
 }
 
-void *memcpy_fromio(void *dst,void*src,unsigned len)
+void *memcpy_fromio(void *dst,const void*src,unsigned len)
 {
 	return __inline_memcpy(dst,__io_virt(src),len);
 }
diff -Nru a/arch/x86_64/lib/usercopy.c b/arch/x86_64/lib/usercopy.c
--- a/arch/x86_64/lib/usercopy.c	Mon Dec 23 21:21:51 2002
+++ b/arch/x86_64/lib/usercopy.c	Mon Dec 23 21:21:51 2002
@@ -30,7 +30,7 @@
 		"	jmp 2b\n"					   \
 		".previous\n"						   \
 		".section __ex_table,\"a\"\n"				   \
-		"	.align 4\n"					   \
+		"	.align 8\n"					   \
 		"	.quad 0b,3b\n"					   \
 		".previous"						   \
 		: "=r"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1),	   \
diff -Nru a/arch/x86_64/mm/Makefile b/arch/x86_64/mm/Makefile
--- a/arch/x86_64/mm/Makefile	Mon Dec 23 21:21:58 2002
+++ b/arch/x86_64/mm/Makefile	Mon Dec 23 21:21:58 2002
@@ -5,3 +5,4 @@
 export-objs := pageattr.o
 
 obj-y	 := init.o fault.o ioremap.o extable.o modutil.o pageattr.o
+obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
diff -Nru a/arch/x86_64/mm/extable.c b/arch/x86_64/mm/extable.c
--- a/arch/x86_64/mm/extable.c	Mon Dec 23 21:22:00 2002
+++ b/arch/x86_64/mm/extable.c	Mon Dec 23 21:22:00 2002
@@ -62,14 +62,16 @@
 	return search_one_table(__start___ex_table, __stop___ex_table-1, addr);
 #else
 	/* The kernel is the last "module" -- no need to treat it special.  */
-	struct module *mp;
+	struct list_head *i;
 
 	spin_lock_irqsave(&modlist_lock, flags);
-	for (mp = module_list; mp != NULL; mp = mp->next) {
-		if (mp->ex_table_start == NULL || !(mp->flags&(MOD_RUNNING|MOD_INITIALIZING)))
+	list_for_each(i, &extables) { 
+		struct exception_table *ex = 
+			list_entry(i,struct exception_table, list); 
+		if (ex->num_entries == 0) 
 			continue;
-		ret = search_one_table(mp->ex_table_start,
-				       mp->ex_table_end - 1, addr);
+		ret = search_one_table(ex->entry,
+				       ex->entry + ex->num_entries - 1, addr);
 		if (ret)
 			break;
 	}
diff -Nru a/arch/x86_64/mm/fault.c b/arch/x86_64/mm/fault.c
--- a/arch/x86_64/mm/fault.c	Mon Dec 23 21:21:50 2002
+++ b/arch/x86_64/mm/fault.c	Mon Dec 23 21:21:50 2002
@@ -300,6 +300,9 @@
 		pmd_t *pmd;
 		pte_t *pte; 
 
+		printk("vmalloc_fault err %lx addr %lx rip %lx\n", 
+		       error_code, address, regs->rip);
+
 		/*
 		 * x86-64 has the same kernel 3rd level pages for all CPUs.
 		 * But for vmalloc/modules the TLB synchronization works lazily,
diff -Nru a/arch/x86_64/mm/hugetlbpage.c b/arch/x86_64/mm/hugetlbpage.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/arch/x86_64/mm/hugetlbpage.c	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,360 @@
+/*
+ * x86-64 Huge TLB Page Support for Kernel.
+ *
+ * Copyright (C) 2002, Rohit Seth <rohit.seth@intel.com>
+ * Minor hacks by Andi Kleen for x86-64
+ */
+
+#include <linux/config.h>
+#include <linux/init.h>
+#include <linux/fs.h>
+#include <linux/mm.h>
+#include <linux/hugetlb.h>
+#include <linux/pagemap.h>
+#include <linux/smp_lock.h>
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/sysctl.h>
+#include <asm/mman.h>
+#include <asm/pgalloc.h>
+#include <asm/tlb.h>
+#include <asm/tlbflush.h>
+
+static long    htlbpagemem;
+int     htlbpage_max;
+static long    htlbzone_pages;
+
+struct vm_operations_struct hugetlb_vm_ops;
+static LIST_HEAD(htlbpage_freelist);
+static spinlock_t htlbpage_lock = SPIN_LOCK_UNLOCKED;
+
+static struct page *alloc_hugetlb_page(void)
+{
+	int i;
+	struct page *page;
+
+	spin_lock(&htlbpage_lock);
+	if (list_empty(&htlbpage_freelist)) {
+		spin_unlock(&htlbpage_lock);
+		return NULL;
+	}
+
+	page = list_entry(htlbpage_freelist.next, struct page, list);
+	list_del(&page->list);
+	htlbpagemem--;
+	spin_unlock(&htlbpage_lock);
+	set_page_count(page, 1);
+	for (i = 0; i < (HPAGE_SIZE/PAGE_SIZE); ++i)
+		clear_highpage(&page[i]);
+	return page;
+}
+
+static pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr)
+{
+	pgd_t *pgd;
+	pmd_t *pmd = NULL;
+
+	pgd = pgd_offset(mm, addr);
+	pmd = pmd_alloc(mm, pgd, addr);
+	return (pte_t *) pmd;
+}
+
+static pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
+{
+	pgd_t *pgd;
+	pmd_t *pmd = NULL;
+
+	pgd = pgd_offset(mm, addr);
+	pmd = pmd_offset(pgd, addr);
+	return (pte_t *) pmd;
+}
+
+#define mk_pte_huge(entry) {pte_val(entry) |= (_PAGE_PRESENT | _PAGE_PSE);}
+
+static void set_huge_pte(struct mm_struct *mm, struct vm_area_struct *vma, struct page *page, pte_t * page_table, int write_access)
+{
+	pte_t entry;
+
+	mm->rss += (HPAGE_SIZE / PAGE_SIZE);
+	if (write_access) {
+		entry =
+		    pte_mkwrite(pte_mkdirty(mk_pte(page, vma->vm_page_prot)));
+	} else
+		entry = pte_wrprotect(mk_pte(page, vma->vm_page_prot));
+	entry = pte_mkyoung(entry);
+	mk_pte_huge(entry);
+	set_pte(page_table, entry);
+}
+
+int
+copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
+			struct vm_area_struct *vma)
+{
+	pte_t *src_pte, *dst_pte, entry;
+	struct page *ptepage;
+	unsigned long addr = vma->vm_start;
+	unsigned long end = vma->vm_end;
+
+	while (addr < end) {
+		dst_pte = huge_pte_alloc(dst, addr);
+		if (!dst_pte)
+			goto nomem;
+		src_pte = huge_pte_offset(src, addr);
+		entry = *src_pte;
+		ptepage = pte_page(entry);
+		get_page(ptepage);
+		set_pte(dst_pte, entry);
+		dst->rss += (HPAGE_SIZE / PAGE_SIZE);
+		addr += HPAGE_SIZE;
+	}
+	return 0;
+
+nomem:
+	return -ENOMEM;
+}
+
+int
+follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma,
+		    struct page **pages, struct vm_area_struct **vmas,
+		    unsigned long *st, int *length, int i)
+{
+	pte_t *ptep, pte;
+	unsigned long start = *st;
+	unsigned long pstart;
+	int len = *length;
+	struct page *page;
+
+	do {
+		pstart = start;
+		ptep = huge_pte_offset(mm, start);
+		pte = *ptep;
+
+back1:
+		page = pte_page(pte);
+		if (pages) {
+			page += ((start & ~HPAGE_MASK) >> PAGE_SHIFT);
+			pages[i] = page;
+		}
+		if (vmas)
+			vmas[i] = vma;
+		i++;
+		len--;
+		start += PAGE_SIZE;
+		if (((start & HPAGE_MASK) == pstart) && len &&
+				(start < vma->vm_end))
+			goto back1;
+	} while (len && start < vma->vm_end);
+	*length = len;
+	*st = start;
+	return i;
+}
+
+void free_huge_page(struct page *page)
+{
+	BUG_ON(page_count(page));
+	BUG_ON(page->mapping);
+
+	INIT_LIST_HEAD(&page->list);
+
+	spin_lock(&htlbpage_lock);
+	list_add(&page->list, &htlbpage_freelist);
+	htlbpagemem++;
+	spin_unlock(&htlbpage_lock);
+}
+
+void huge_page_release(struct page *page)
+{
+	if (!put_page_testzero(page))
+		return;
+
+	free_huge_page(page);
+}
+
+void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
+{
+	struct mm_struct *mm = vma->vm_mm;
+	unsigned long address;
+	pte_t *pte;
+	struct page *page;
+
+	BUG_ON(start & (HPAGE_SIZE - 1));
+	BUG_ON(end & (HPAGE_SIZE - 1));
+
+	spin_lock(&htlbpage_lock);
+	spin_unlock(&htlbpage_lock);
+	for (address = start; address < end; address += HPAGE_SIZE) {
+		pte = huge_pte_offset(mm, address);
+		page = pte_page(*pte);
+		huge_page_release(page);
+		pte_clear(pte);
+	}
+	mm->rss -= (end - start) >> PAGE_SHIFT;
+	flush_tlb_range(vma, start, end);
+}
+
+void zap_hugepage_range(struct vm_area_struct *vma, unsigned long start, unsigned long length)
+{
+	struct mm_struct *mm = vma->vm_mm;
+	spin_lock(&mm->page_table_lock);
+	unmap_hugepage_range(vma, start, start + length);
+	spin_unlock(&mm->page_table_lock);
+}
+
+int hugetlb_prefault(struct address_space *mapping, struct vm_area_struct *vma)
+{
+	struct mm_struct *mm = current->mm;
+	unsigned long addr;
+	int ret = 0;
+
+	BUG_ON(vma->vm_start & ~HPAGE_MASK);
+	BUG_ON(vma->vm_end & ~HPAGE_MASK);
+
+	spin_lock(&mm->page_table_lock);
+	for (addr = vma->vm_start; addr < vma->vm_end; addr += HPAGE_SIZE) {
+		unsigned long idx;
+		pte_t *pte = huge_pte_alloc(mm, addr);
+		struct page *page;
+
+		if (!pte) {
+			ret = -ENOMEM;
+			goto out;
+		}
+		if (!pte_none(*pte))
+			continue;
+
+		idx = ((addr - vma->vm_start) >> HPAGE_SHIFT)
+			+ (vma->vm_pgoff >> (HPAGE_SHIFT - PAGE_SHIFT));
+		page = find_get_page(mapping, idx);
+		if (!page) {
+			page = alloc_hugetlb_page();
+			if (!page) {
+				ret = -ENOMEM;
+				goto out;
+			}
+			add_to_page_cache(page, mapping, idx);
+			unlock_page(page);
+		}
+		set_huge_pte(mm, vma, page, pte, vma->vm_flags & VM_WRITE);
+	}
+out:
+	spin_unlock(&mm->page_table_lock);
+	return ret;
+}
+
+int set_hugetlb_mem_size(int count)
+{
+	int j, lcount;
+	struct page *page, *map;
+	extern long htlbzone_pages;
+	extern struct list_head htlbpage_freelist;
+
+	if (count < 0)
+		lcount = count;
+	else
+		lcount = count - htlbzone_pages;
+
+	if (lcount > 0) {	/* Increase the mem size. */
+		while (lcount--) {
+			page = alloc_pages(__GFP_HIGHMEM, HUGETLB_PAGE_ORDER);
+			if (page == NULL)
+				break;
+			map = page;
+			for (j = 0; j < (HPAGE_SIZE / PAGE_SIZE); j++) {
+				SetPageReserved(map);
+				map++;
+			}
+			spin_lock(&htlbpage_lock);
+			list_add(&page->list, &htlbpage_freelist);
+			htlbpagemem++;
+			htlbzone_pages++;
+			spin_unlock(&htlbpage_lock);
+		}
+		return (int) htlbzone_pages;
+	}
+	/* Shrink the memory size. */
+	while (lcount++) {
+		page = alloc_hugetlb_page();
+		if (page == NULL)
+			break;
+		spin_lock(&htlbpage_lock);
+		htlbzone_pages--;
+		spin_unlock(&htlbpage_lock);
+		map = page;
+		for (j = 0; j < (HPAGE_SIZE / PAGE_SIZE); j++) {
+			map->flags &= ~(1 << PG_locked | 1 << PG_error | 1 << PG_referenced |
+					1 << PG_dirty | 1 << PG_active | 1 << PG_reserved |
+					1 << PG_private | 1<< PG_writeback);
+			set_page_count(map, 0);
+			map++;
+		}
+		set_page_count(page, 1);
+		__free_pages(page, HUGETLB_PAGE_ORDER);
+	}
+	return (int) htlbzone_pages;
+}
+
+/* This will likely not work because of fragmentation. */ 
+int hugetlb_sysctl_handler(ctl_table *table, int write, struct file *file, void *buffer, size_t *length)
+{
+	proc_dointvec(table, write, file, buffer, length);
+	htlbpage_max = set_hugetlb_mem_size(htlbpage_max);
+	return 0;
+}
+
+static int __init hugetlb_setup(char *s)
+{
+	if (sscanf(s, "%d", &htlbpage_max) <= 0)
+		htlbpage_max = 0;
+	return 1;
+}
+__setup("hugepages=", hugetlb_setup);
+
+static int __init hugetlb_init(void)
+{
+	int i, j;
+	struct page *page;
+
+	for (i = 0; i < htlbpage_max; ++i) {
+		page = alloc_pages(__GFP_HIGHMEM, HUGETLB_PAGE_ORDER);
+		if (!page)
+			break;
+		for (j = 0; j < HPAGE_SIZE/PAGE_SIZE; ++j)
+			SetPageReserved(&page[j]);
+		spin_lock(&htlbpage_lock);
+		list_add(&page->list, &htlbpage_freelist);
+		spin_unlock(&htlbpage_lock);
+	}
+	htlbpage_max = htlbpagemem = htlbzone_pages = i;
+	printk("Total HugeTLB memory allocated, %ld\n", htlbpagemem);
+	return 0;
+}
+module_init(hugetlb_init);
+
+int hugetlb_report_meminfo(char *buf)
+{
+	return sprintf(buf,
+			"HugePages_Total: %5lu\n"
+			"HugePages_Free:  %5lu\n"
+			"Hugepagesize:    %5lu kB\n",
+			htlbzone_pages,
+			htlbpagemem,
+			HPAGE_SIZE/1024);
+}
+
+static struct page * hugetlb_nopage(struct vm_area_struct * area, unsigned long address, int unused)
+{
+	BUG();
+	return NULL;
+}
+
+struct vm_operations_struct hugetlb_vm_ops = {
+	.nopage = hugetlb_nopage,
+};
+
+int is_hugepage_mem_enough(size_t size)
+{
+       if (size > (htlbpagemem << HPAGE_SHIFT))
+               return 0;
+       return 1;
+}
diff -Nru a/arch/x86_64/mm/init.c b/arch/x86_64/mm/init.c
--- a/arch/x86_64/mm/init.c	Mon Dec 23 21:21:51 2002
+++ b/arch/x86_64/mm/init.c	Mon Dec 23 21:21:51 2002
@@ -223,7 +223,8 @@
 					set_pmd(pmd,  __pmd(0)); 
 				break;
 		}
-			pe = _PAGE_PSE | _KERNPG_TABLE | _PAGE_GLOBAL | paddr;
+			pe = _PAGE_NX|_PAGE_PSE | _KERNPG_TABLE | _PAGE_GLOBAL | paddr;
+			pe &= __supported_pte_mask;
 			set_pmd(pmd, __pmd(pe));
 		}
 		unmap_low_page(map);
diff -Nru a/arch/x86_64/mm/modutil.c b/arch/x86_64/mm/modutil.c
--- a/arch/x86_64/mm/modutil.c	Mon Dec 23 21:21:50 2002
+++ b/arch/x86_64/mm/modutil.c	Mon Dec 23 21:21:50 2002
@@ -10,32 +10,38 @@
  
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
+#include <linux/module.h>
+#include <linux/err.h>
 
 #include <asm/uaccess.h>
 #include <asm/system.h>
 #include <asm/page.h>
 #include <asm/pgtable.h>
 
-static struct vm_struct * modvmlist = NULL;
-
-void module_unmap (void * addr)
+/* FIXME: If module_region == mod->init_region, trim exception
+   table entries. */
+void module_free(struct module *mod, void *module_region)
 {
 	struct vm_struct **p, *tmp;
 	int i;
+	unsigned long addr = (unsigned long)module_region;
 
 	if (!addr)
 		return;
-	if ((PAGE_SIZE-1) & (unsigned long) addr) {
-		printk("Trying to unmap module with bad address (%p)\n", addr);
+	if ((PAGE_SIZE-1) & addr) {
+		printk("Trying to unmap module with bad address (%lx)\n", addr);
 		return;
 	}
-	for (p = &modvmlist ; (tmp = *p) ; p = &tmp->next) {
-		if (tmp->addr == addr) {
+	write_lock(&vmlist_lock); 
+	for (p = &vmlist ; (tmp = *p) ; p = &tmp->next) {
+		if ((unsigned long)tmp->addr == addr) {
 			*p = tmp->next;
+			write_unlock(&vmlist_lock); 
 			goto found;
 		}
 	}
-	printk("Trying to unmap nonexistent module vm area (%p)\n", addr);
+	write_unlock(&vmlist_lock); 
+	printk("Trying to unmap nonexistent module vm area (%lx)\n", addr);
 	return;
  found:
 	unmap_vm_area(tmp);
@@ -49,29 +55,31 @@
 	kfree(tmp);					
 }
 
-void * module_map (unsigned long size)
+void * module_alloc (unsigned long size)
 {
 	struct vm_struct **p, *tmp, *area;
 	struct page **pages;
 	void * addr;
 	unsigned int nr_pages, array_size, i;
 
-	size = PAGE_ALIGN(size);
-	if (!size || size > MODULES_LEN)
+	if (!size)
 		return NULL;
+	size = PAGE_ALIGN(size);
+	if (size > MODULES_LEN)
+		return ERR_PTR(-ENOMEM);
 		
 	addr = (void *) MODULES_VADDR;
-	for (p = &modvmlist; (tmp = *p) ; p = &tmp->next) {
+	for (p = &vmlist; (tmp = *p) ; p = &tmp->next) {
 		if (size + (unsigned long) addr < (unsigned long) tmp->addr)
 			break;
 		addr = (void *) (tmp->size + (unsigned long) tmp->addr);
 	}
 	if ((unsigned long) addr + size >= MODULES_END)
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 	
 	area = (struct vm_struct *) kmalloc(sizeof(*area), GFP_KERNEL);
 	if (!area)
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 	area->size = size + PAGE_SIZE;
 	area->addr = addr;
 	area->next = *p;
@@ -96,11 +104,12 @@
 			goto fail;
 	}
 	
-	if (map_vm_area(area, PAGE_KERNEL, &pages)) {
+	if (map_vm_area(area, PAGE_KERNEL_EXECUTABLE, &pages)) {
 		unmap_vm_area(area);
 		goto fail;
 	}
 
+	memset(area->addr, 0, size);
 	return area->addr;
 
 fail:
@@ -113,6 +122,6 @@
 	}
 	kfree(area);
 
-	return NULL;
+	return ERR_PTR(-ENOMEM);
 }
 
diff -Nru a/arch/x86_64/pci/common.c b/arch/x86_64/pci/common.c
--- a/arch/x86_64/pci/common.c	Mon Dec 23 21:21:51 2002
+++ b/arch/x86_64/pci/common.c	Mon Dec 23 21:21:51 2002
@@ -94,6 +94,11 @@
 	}
 }
 
+void __devinit
+pcibios_fixup_pbus_ranges (struct pci_bus *bus, struct pbus_set_ranges_data *ranges)
+{
+}
+
 /*
  *  Called after each bus is probed, but before its children
  *  are examined.
diff -Nru a/arch/x86_64/pci/irq.c b/arch/x86_64/pci/irq.c
--- a/arch/x86_64/pci/irq.c	Mon Dec 23 21:21:56 2002
+++ b/arch/x86_64/pci/irq.c	Mon Dec 23 21:21:56 2002
@@ -151,30 +151,7 @@
 	pci_write_config_byte(router, reg, x);
 }
 
-/*
- * ALI pirq entries are damn ugly, and completely undocumented.
- * This has been figured out from pirq tables, and it's not a pretty
- * picture.
- */
-static int pirq_ali_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
-{
-	static unsigned char irqmap[16] = { 0, 9, 3, 10, 4, 5, 7, 6, 1, 11, 0, 12, 0, 14, 0, 15 };
-
-	return irqmap[read_config_nybble(router, 0x48, pirq-1)];
-}
-
-static int pirq_ali_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
-{
-	static unsigned char irqmap[16] = { 0, 8, 0, 2, 4, 5, 7, 6, 0, 1, 3, 9, 11, 0, 13, 15 };
-	unsigned int val = irqmap[irq];
-		
-	if (val) {
-		write_config_nybble(router, 0x48, pirq-1, val);
-		return 1;
-	}
-	return 0;
-}
-
+#if 0 /* enable when pci ids ae known */
 /*
  * The VIA pirq rules are nibble-based, like ALI,
  * but without the ugly irq number munging.
@@ -296,6 +273,8 @@
 	return 1;
 }
 
+#endif
+
 /* Support for AMD756 PCI IRQ Routing
  * Jhon H. Caicedo <jhcaiced@osso.org.co>
  * Jun/21/2001 0.2.0 Release, fixed to use "nybble" functions... (jhcaiced)
@@ -529,7 +508,7 @@
 	return 1;
 }
 
-static void __init pcibios_fixup_irqs(void)
+void __init pcibios_fixup_irqs(void)
 {
 	struct pci_dev *dev;
 	u8 pin;
@@ -641,7 +620,6 @@
 	u8 pin;
 	pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
 	if (pin && !pcibios_lookup_irq(dev, 1) && !dev->irq) {
-		char *msg;
 		printk(KERN_WARNING "PCI: No IRQ known for interrupt pin %c of device %s.\n",
 		       'A' + pin - 1, dev->slot_name);
 	}
diff -Nru a/arch/x86_64/vmlinux.lds.S b/arch/x86_64/vmlinux.lds.S
--- a/arch/x86_64/vmlinux.lds.S	Mon Dec 23 21:21:51 2002
+++ b/arch/x86_64/vmlinux.lds.S	Mon Dec 23 21:21:51 2002
@@ -26,6 +26,7 @@
   __ex_table : { *(__ex_table) }
   __stop___ex_table = .;
 
+  . = ALIGN(64); 
   __start___ksymtab = .;	/* Kernel symbol table */
   __ksymtab : { *(__ksymtab) }
   __stop___ksymtab = .;
@@ -79,6 +80,11 @@
   . = ALIGN(4096); 
   .data.boot_pgt : { *(.data.boot_pgt) }
 
+  . = ALIGN(4096);
+  __initramfs_start = .;
+  .init.ramfs : { *(.init.ramfs) }
+  __initramfs_end = .;
+	
   . = ALIGN(4096);		/* Init code and data */
   __init_begin = .;
   .init.text : { *(.init.text) }
@@ -87,6 +93,9 @@
   __setup_start = .;
   .init.setup : { *(.init.setup) }
   __setup_end = .;
+  __start___param = .;
+  __param : { *(__param) }
+  __stop___param = .;
   __initcall_start = .;
   .initcall.init : {
 	*(.initcall1.init) 
@@ -104,6 +113,12 @@
   __per_cpu_end = .;
   . = ALIGN(4096);
   __init_end = .;
+
+  . = ALIGN(4096);
+  __nosave_begin = .;
+  .data_nosave : { *(.data.nosave) }
+  . = ALIGN(4096);
+  __nosave_end = .;
 
   _end = . ;
 
diff -Nru a/drivers/acpi/ac.c b/drivers/acpi/ac.c
--- a/drivers/acpi/ac.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/acpi/ac.c	Mon Dec 23 21:21:53 2002
@@ -183,8 +183,10 @@
 {
 	ACPI_FUNCTION_TRACE("acpi_ac_remove_fs");
 
-	if (acpi_device_dir(device))
+	if (acpi_device_dir(device)) {
 		remove_proc_entry(acpi_device_bid(device), acpi_ac_dir);
+		acpi_device_dir(device) = NULL;
+	}
 
 	return_VALUE(0);
 }
diff -Nru a/drivers/acpi/battery.c b/drivers/acpi/battery.c
--- a/drivers/acpi/battery.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/acpi/battery.c	Mon Dec 23 21:21:59 2002
@@ -669,8 +669,10 @@
 {
 	ACPI_FUNCTION_TRACE("acpi_battery_remove_fs");
 
-	if (acpi_device_dir(device))
+	if (acpi_device_dir(device)) {
 		remove_proc_entry(acpi_device_bid(device), acpi_battery_dir);
+		acpi_device_dir(device) = NULL;
+	}
 
 	return_VALUE(0);
 }
diff -Nru a/drivers/acpi/button.c b/drivers/acpi/button.c
--- a/drivers/acpi/button.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/acpi/button.c	Mon Dec 23 21:21:50 2002
@@ -179,8 +179,10 @@
 {
 	ACPI_FUNCTION_TRACE("acpi_button_remove_fs");
 
-	if (acpi_device_dir(device))
+	if (acpi_device_dir(device)) {
 		remove_proc_entry(acpi_device_bid(device), acpi_button_dir);
+		acpi_device_dir(device) = NULL;
+	}
 
 	return_VALUE(0);
 }
diff -Nru a/drivers/acpi/dispatcher/dsfield.c b/drivers/acpi/dispatcher/dsfield.c
--- a/drivers/acpi/dispatcher/dsfield.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/dispatcher/dsfield.c	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: dsfield - Dispatcher field routines
- *              $Revision: 70 $
  *
  *****************************************************************************/
 
@@ -38,21 +37,21 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_create_buffer_field
+ * FUNCTION:    acpi_ds_create_buffer_field
  *
  * PARAMETERS:  Opcode              - The opcode to be executed
  *              Operands            - List of operands for the opcode
- *              Walk_state          - Current state
+ *              walk_state          - Current state
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Execute the Create_field operators:
- *              Create_bit_field_op,
- *              Create_byte_field_op,
- *              Create_word_field_op,
- *              Create_dWord_field_op,
- *              Create_qWord_field_op,
- *              Create_field_op     (all of which define fields in buffers)
+ * DESCRIPTION: Execute the create_field operators:
+ *              create_bit_field_op,
+ *              create_byte_field_op,
+ *              create_word_field_op,
+ *              create_dword_field_op,
+ *              create_qword_field_op,
+ *              create_field_op     (all of which define fields in buffers)
  *
  ******************************************************************************/
 
@@ -69,10 +68,10 @@
 	u32                     flags;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_create_buffer_field");
+	ACPI_FUNCTION_TRACE ("ds_create_buffer_field");
 
 
-	/* Get the Name_string argument */
+	/* Get the name_string argument */
 
 	if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
 		arg = acpi_ps_get_arg (op, 3);
@@ -100,7 +99,7 @@
 	}
 
 	/*
-	 * Enter the Name_string into the namespace
+	 * Enter the name_string into the namespace
 	 */
 	status = acpi_ns_lookup (walk_state->scope_info, arg->common.value.string,
 			 ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS1,
@@ -168,10 +167,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_get_field_names
+ * FUNCTION:    acpi_ds_get_field_names
  *
- * PARAMETERS:  Info            - Create_field info structure
- *  `           Walk_state      - Current method state
+ * PARAMETERS:  Info            - create_field info structure
+ *  `           walk_state      - Current method state
  *              Arg             - First parser arg for the field name list
  *
  * RETURN:      Status
@@ -183,7 +182,7 @@
 
 acpi_status
 acpi_ds_get_field_names (
-	ACPI_CREATE_FIELD_INFO  *info,
+	acpi_create_field_info  *info,
 	acpi_walk_state         *walk_state,
 	acpi_parse_object       *arg)
 {
@@ -191,7 +190,7 @@
 	acpi_integer            position;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_get_field_names", info);
+	ACPI_FUNCTION_TRACE_PTR ("ds_get_field_names", info);
 
 
 	/* First field starts at bit zero */
@@ -204,7 +203,7 @@
 		/*
 		 * Three types of field elements are handled:
 		 * 1) Offset - specifies a bit offset
-		 * 2) Access_as - changes the access mode
+		 * 2) access_as - changes the access mode
 		 * 3) Name - Enters a new named field into the namespace
 		 */
 		switch (arg->common.aml_opcode) {
@@ -225,10 +224,10 @@
 		case AML_INT_ACCESSFIELD_OP:
 
 			/*
-			 * Get a new Access_type and Access_attribute -- to be used for all
-			 * field units that follow, until field end or another Access_as keyword.
+			 * Get a new access_type and access_attribute -- to be used for all
+			 * field units that follow, until field end or another access_as keyword.
 			 *
-			 * In Field_flags, preserve the flag bits other than the ACCESS_TYPE bits
+			 * In field_flags, preserve the flag bits other than the ACCESS_TYPE bits
 			 */
 			info->field_flags = (u8) ((info->field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
 					  ((u8) (arg->common.value.integer32 >> 8)));
@@ -296,11 +295,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_create_field
+ * FUNCTION:    acpi_ds_create_field
  *
  * PARAMETERS:  Op              - Op containing the Field definition and args
- *              Region_node     - Object for the containing Operation Region
- *  `           Walk_state      - Current method state
+ *              region_node     - Object for the containing Operation Region
+ *  `           walk_state      - Current method state
  *
  * RETURN:      Status
  *
@@ -316,13 +315,13 @@
 {
 	acpi_status             status;
 	acpi_parse_object       *arg;
-	ACPI_CREATE_FIELD_INFO  info;
+	acpi_create_field_info  info;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_create_field", op);
+	ACPI_FUNCTION_TRACE_PTR ("ds_create_field", op);
 
 
-	/* First arg is the name of the parent Op_region (must already exist) */
+	/* First arg is the name of the parent op_region (must already exist) */
 
 	arg = op->common.value.arg;
 	if (!region_node) {
@@ -354,10 +353,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_init_field_objects
+ * FUNCTION:    acpi_ds_init_field_objects
  *
  * PARAMETERS:  Op              - Op containing the Field definition and args
- *  `           Walk_state      - Current method state
+ *  `           walk_state      - Current method state
  *
  * RETURN:      Status
  *
@@ -378,7 +377,7 @@
 	u8                      type = 0;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_init_field_objects", op);
+	ACPI_FUNCTION_TRACE_PTR ("ds_init_field_objects", op);
 
 
 	switch (walk_state->opcode) {
@@ -402,7 +401,7 @@
 	}
 
 	/*
-	 * Walk the list of entries in the Field_list
+	 * Walk the list of entries in the field_list
 	 */
 	while (arg) {
 		/* Ignore OFFSET and ACCESSAS terms here */
@@ -438,11 +437,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_create_bank_field
+ * FUNCTION:    acpi_ds_create_bank_field
  *
  * PARAMETERS:  Op              - Op containing the Field definition and args
- *              Region_node     - Object for the containing Operation Region
- *  `           Walk_state      - Current method state
+ *              region_node     - Object for the containing Operation Region
+ *  `           walk_state      - Current method state
  *
  * RETURN:      Status
  *
@@ -458,13 +457,13 @@
 {
 	acpi_status             status;
 	acpi_parse_object       *arg;
-	ACPI_CREATE_FIELD_INFO  info;
+	acpi_create_field_info  info;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_create_bank_field", op);
+	ACPI_FUNCTION_TRACE_PTR ("ds_create_bank_field", op);
 
 
-	/* First arg is the name of the parent Op_region (must already exist) */
+	/* First arg is the name of the parent op_region (must already exist) */
 
 	arg = op->common.value.arg;
 	if (!region_node) {
@@ -488,7 +487,7 @@
 		return_ACPI_STATUS (status);
 	}
 
-	/* Third arg is the Bank_value */
+	/* Third arg is the bank_value */
 
 	arg = arg->common.next;
 	info.bank_value = arg->common.value.integer32;
@@ -511,11 +510,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_create_index_field
+ * FUNCTION:    acpi_ds_create_index_field
  *
  * PARAMETERS:  Op              - Op containing the Field definition and args
- *              Region_node     - Object for the containing Operation Region
- *  `           Walk_state      - Current method state
+ *              region_node     - Object for the containing Operation Region
+ *  `           walk_state      - Current method state
  *
  * RETURN:      Status
  *
@@ -531,10 +530,10 @@
 {
 	acpi_status             status;
 	acpi_parse_object       *arg;
-	ACPI_CREATE_FIELD_INFO  info;
+	acpi_create_field_info  info;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_create_index_field", op);
+	ACPI_FUNCTION_TRACE_PTR ("ds_create_index_field", op);
 
 
 	/* First arg is the name of the Index register (must already exist) */
diff -Nru a/drivers/acpi/dispatcher/dsinit.c b/drivers/acpi/dispatcher/dsinit.c
--- a/drivers/acpi/dispatcher/dsinit.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/acpi/dispatcher/dsinit.c	Mon Dec 23 21:22:00 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: dsinit - Object initialization namespace walk
- *              $Revision: 4 $
  *
  *****************************************************************************/
 
@@ -37,16 +36,16 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_init_one_object
+ * FUNCTION:    acpi_ds_init_one_object
  *
- * PARAMETERS:  Obj_handle      - Node
+ * PARAMETERS:  obj_handle      - Node
  *              Level           - Current nesting level
  *              Context         - Points to a init info struct
- *              Return_value    - Not used
+ *              return_value    - Not used
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Callback from Acpi_walk_namespace. Invoked for every object
+ * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
  *              within the namespace.
  *
  *              Currently, the only objects that require initialization are:
@@ -67,7 +66,7 @@
 	acpi_init_walk_info     *info = (acpi_init_walk_info *) context;
 
 
-	ACPI_FUNCTION_NAME ("Ds_init_one_object");
+	ACPI_FUNCTION_NAME ("ds_init_one_object");
 
 
 	/*
@@ -163,14 +162,14 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_initialize_objects
+ * FUNCTION:    acpi_ds_initialize_objects
  *
- * PARAMETERS:  Table_desc      - Descriptor for parent ACPI table
- *              Start_node      - Root of subtree to be initialized.
+ * PARAMETERS:  table_desc      - Descriptor for parent ACPI table
+ *              start_node      - Root of subtree to be initialized.
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Walk the namespace starting at "Start_node" and perform any
+ * DESCRIPTION: Walk the namespace starting at "start_node" and perform any
  *              necessary initialization on the objects found therein
  *
  ******************************************************************************/
@@ -184,7 +183,7 @@
 	acpi_init_walk_info     info;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_initialize_objects");
+	ACPI_FUNCTION_TRACE ("ds_initialize_objects");
 
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
@@ -202,7 +201,7 @@
 	status = acpi_walk_namespace (ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX,
 			  acpi_ds_init_one_object, &info, NULL);
 	if (ACPI_FAILURE (status)) {
-		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Walk_namespace failed, %s\n",
+		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "walk_namespace failed, %s\n",
 			acpi_format_exception (status)));
 	}
 
diff -Nru a/drivers/acpi/dispatcher/dsmethod.c b/drivers/acpi/dispatcher/dsmethod.c
--- a/drivers/acpi/dispatcher/dsmethod.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/acpi/dispatcher/dsmethod.c	Mon Dec 23 21:21:55 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: dsmethod - Parser/Interpreter interface - control method parsing
- *              $Revision: 89 $
  *
  *****************************************************************************/
 
@@ -38,12 +37,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_parse_method
+ * FUNCTION:    acpi_ds_parse_method
  *
- * PARAMETERS:  Obj_handle      - Node of the method
+ * PARAMETERS:  obj_handle      - Node of the method
  *              Level           - Current nesting level
  *              Context         - Points to a method counter
- *              Return_value    - Not used
+ *              return_value    - Not used
  *
  * RETURN:      Status
  *
@@ -66,7 +65,7 @@
 	acpi_walk_state         *walk_state;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_parse_method", obj_handle);
+	ACPI_FUNCTION_TRACE_PTR ("ds_parse_method", obj_handle);
 
 
 	/* Parameter Validation */
@@ -75,7 +74,7 @@
 		return_ACPI_STATUS (AE_NULL_ENTRY);
 	}
 
-	ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Parsing [%4.4s] **** Named_obj=%p\n",
+	ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Parsing [%4.4s] **** named_obj=%p\n",
 		((acpi_namespace_node *) obj_handle)->name.ascii, obj_handle));
 
 	/* Extract the method object from the method Node */
@@ -113,7 +112,7 @@
 	op->common.node = node;
 
 	/*
-	 * Get a new Owner_id for objects created by this method. Namespace
+	 * Get a new owner_id for objects created by this method. Namespace
 	 * objects (such as Operation Regions) can be created during the
 	 * first pass parse.
 	 */
@@ -150,7 +149,7 @@
 	}
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
-		"**** [%4.4s] Parsed **** Named_obj=%p Op=%p\n",
+		"**** [%4.4s] Parsed **** named_obj=%p Op=%p\n",
 		((acpi_namespace_node *) obj_handle)->name.ascii, obj_handle, op));
 
 	acpi_ps_delete_parse_tree (op);
@@ -160,11 +159,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_begin_method_execution
+ * FUNCTION:    acpi_ds_begin_method_execution
  *
- * PARAMETERS:  Method_node         - Node of the method
- *              Obj_desc            - The method object
- *              Calling_method_node - Caller of this method (if non-null)
+ * PARAMETERS:  method_node         - Node of the method
+ *              obj_desc            - The method object
+ *              calling_method_node - Caller of this method (if non-null)
  *
  * RETURN:      Status
  *
@@ -185,7 +184,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_begin_method_execution", method_node);
+	ACPI_FUNCTION_TRACE_PTR ("ds_begin_method_execution", method_node);
 
 
 	if (!method_node) {
@@ -199,7 +198,7 @@
 	if (obj_desc->method.semaphore) {
 		/*
 		 * Allow recursive method calls, up to the reentrancy/concurrency
-		 * limit imposed by the SERIALIZED rule and the Sync_level method
+		 * limit imposed by the SERIALIZED rule and the sync_level method
 		 * parameter.
 		 *
 		 * The point of this code is to avoid permanently blocking a
@@ -230,9 +229,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_call_control_method
+ * FUNCTION:    acpi_ds_call_control_method
  *
- * PARAMETERS:  Walk_state          - Current state of the walk
+ * PARAMETERS:  walk_state          - Current state of the walk
  *              Op                  - Current Op to be walked
  *
  * RETURN:      Status
@@ -243,7 +242,7 @@
 
 acpi_status
 acpi_ds_call_control_method (
-	ACPI_THREAD_STATE       *thread,
+	acpi_thread_state       *thread,
 	acpi_walk_state         *this_walk_state,
 	acpi_parse_object       *op)
 {
@@ -254,7 +253,7 @@
 	u32                     i;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_call_control_method", this_walk_state);
+	ACPI_FUNCTION_TRACE_PTR ("ds_call_control_method", this_walk_state);
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Execute method %p, currentstate=%p\n",
 		this_walk_state->prev_op, this_walk_state));
@@ -364,9 +363,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_restart_control_method
+ * FUNCTION:    acpi_ds_restart_control_method
  *
- * PARAMETERS:  Walk_state          - State of the method when it was preempted
+ * PARAMETERS:  walk_state          - State of the method when it was preempted
  *              Op                  - Pointer to new current op
  *
  * RETURN:      Status
@@ -383,7 +382,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_restart_control_method", walk_state);
+	ACPI_FUNCTION_TRACE_PTR ("ds_restart_control_method", walk_state);
 
 
 	if (return_desc) {
@@ -408,7 +407,7 @@
 	}
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-		"Method=%p Return=%p Return_used?=%X Res_stack=%p State=%p\n",
+		"Method=%p Return=%p return_used?=%X res_stack=%p State=%p\n",
 		walk_state->method_call_op, return_desc, walk_state->return_used,
 		walk_state->results, walk_state));
 
@@ -418,9 +417,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_terminate_control_method
+ * FUNCTION:    acpi_ds_terminate_control_method
  *
- * PARAMETERS:  Walk_state          - State of the method
+ * PARAMETERS:  walk_state          - State of the method
  *
  * RETURN:      Status
  *
@@ -439,7 +438,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_terminate_control_method", walk_state);
+	ACPI_FUNCTION_TRACE_PTR ("ds_terminate_control_method", walk_state);
 
 
 	if (!walk_state) {
diff -Nru a/drivers/acpi/dispatcher/dsmthdat.c b/drivers/acpi/dispatcher/dsmthdat.c
--- a/drivers/acpi/dispatcher/dsmthdat.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/acpi/dispatcher/dsmthdat.c	Mon Dec 23 21:21:53 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: dsmthdat - control method arguments and local variables
- *              $Revision: 68 $
  *
  ******************************************************************************/
 
@@ -37,22 +36,22 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_method_data_init
+ * FUNCTION:    acpi_ds_method_data_init
  *
- * PARAMETERS:  Walk_state          - Current walk state object
+ * PARAMETERS:  walk_state          - Current walk state object
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Initialize the data structures that hold the method's arguments
  *              and locals.  The data struct is an array of NTEs for each.
- *              This allows Ref_of and De_ref_of to work properly for these
+ *              This allows ref_of and de_ref_of to work properly for these
  *              special data types.
  *
- * NOTES:       Walk_state fields are initialized to zero by the
+ * NOTES:       walk_state fields are initialized to zero by the
  *              ACPI_MEM_CALLOCATE().
  *
  *              A pseudo-Namespace Node is assigned to each argument and local
- *              so that Ref_of() can return a pointer to the Node.
+ *              so that ref_of() can return a pointer to the Node.
  *
  ******************************************************************************/
 
@@ -63,7 +62,7 @@
 	u32                     i;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_method_data_init");
+	ACPI_FUNCTION_TRACE ("ds_method_data_init");
 
 
 	/* Init the method arguments */
@@ -95,9 +94,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_method_data_delete_all
+ * FUNCTION:    acpi_ds_method_data_delete_all
  *
- * PARAMETERS:  Walk_state          - Current walk state object
+ * PARAMETERS:  walk_state          - Current walk state object
  *
  * RETURN:      None
  *
@@ -113,7 +112,7 @@
 	u32                     index;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_method_data_delete_all");
+	ACPI_FUNCTION_TRACE ("ds_method_data_delete_all");
 
 
 	/* Detach the locals */
@@ -148,17 +147,17 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_method_data_init_args
+ * FUNCTION:    acpi_ds_method_data_init_args
  *
  * PARAMETERS:  *Params         - Pointer to a parameter list for the method
- *              Max_param_count - The arg count for this method
- *              Walk_state      - Current walk state object
+ *              max_param_count - The arg count for this method
+ *              walk_state      - Current walk state object
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Initialize arguments for a method.  The parameter list is a list
  *              of ACPI operand objects, either null terminated or whose length
- *              is defined by Max_param_count.
+ *              is defined by max_param_count.
  *
  ******************************************************************************/
 
@@ -172,7 +171,7 @@
 	u32                     index = 0;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_method_data_init_args", params);
+	ACPI_FUNCTION_TRACE_PTR ("ds_method_data_init_args", params);
 
 
 	if (!params) {
@@ -203,12 +202,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_method_data_get_node
+ * FUNCTION:    acpi_ds_method_data_get_node
  *
  * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
- *              Index               - Which local_var or argument whose type
+ *              Index               - which local_var or argument whose type
  *                                      to get
- *              Walk_state          - Current walk state object
+ *              walk_state          - Current walk state object
  *
  * RETURN:      Get the Node associated with a local or arg.
  *
@@ -221,7 +220,7 @@
 	acpi_walk_state         *walk_state,
 	acpi_namespace_node     **node)
 {
-	ACPI_FUNCTION_TRACE ("Ds_method_data_get_node");
+	ACPI_FUNCTION_TRACE ("ds_method_data_get_node");
 
 
 	/*
@@ -265,12 +264,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_method_data_set_value
+ * FUNCTION:    acpi_ds_method_data_set_value
  *
  * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
- *              Index               - Which local_var or argument to get
+ *              Index               - which local_var or argument to get
  *              Object              - Object to be inserted into the stack entry
- *              Walk_state          - Current walk state object
+ *              walk_state          - Current walk state object
  *
  * RETURN:      Status
  *
@@ -291,7 +290,7 @@
 	acpi_operand_object     *new_desc = object;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_method_data_set_value");
+	ACPI_FUNCTION_TRACE ("ds_method_data_set_value");
 
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
@@ -335,12 +334,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_method_data_get_type
+ * FUNCTION:    acpi_ds_method_data_get_type
  *
  * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
- *              Index               - Which local_var or argument whose type
+ *              Index               - which local_var or argument whose type
  *                                      to get
- *              Walk_state          - Current walk state object
+ *              walk_state          - Current walk state object
  *
  * RETURN:      Data type of current value of the selected Arg or Local
  *
@@ -357,7 +356,7 @@
 	acpi_operand_object     *object;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_method_data_get_type");
+	ACPI_FUNCTION_TRACE ("ds_method_data_get_type");
 
 
 	/* Get the namespace node for the arg/local */
@@ -384,19 +383,19 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_method_data_get_value
+ * FUNCTION:    acpi_ds_method_data_get_value
  *
  * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
- *              Index               - Which local_var or argument to get
- *              Walk_state          - Current walk state object
- *              *Dest_desc          - Ptr to Descriptor into which selected Arg
+ *              Index               - which local_var or argument to get
+ *              walk_state          - Current walk state object
+ *              *dest_desc          - Ptr to Descriptor into which selected Arg
  *                                    or Local value should be copied
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Retrieve value of selected Arg or Local from the method frame
  *              at the current top of the method stack.
- *              Used only in Acpi_ex_resolve_to_value().
+ *              Used only in acpi_ex_resolve_to_value().
  *
  ******************************************************************************/
 
@@ -412,7 +411,7 @@
 	acpi_operand_object     *object;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_method_data_get_value");
+	ACPI_FUNCTION_TRACE ("ds_method_data_get_value");
 
 
 	/* Validate the object descriptor */
@@ -476,11 +475,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_method_data_delete_value
+ * FUNCTION:    acpi_ds_method_data_delete_value
  *
  * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
- *              Index               - Which local_var or argument to delete
- *              Walk_state          - Current walk state object
+ *              Index               - which local_var or argument to delete
+ *              walk_state          - Current walk state object
  *
  * RETURN:      None
  *
@@ -500,7 +499,7 @@
 	acpi_operand_object     *object;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_method_data_delete_value");
+	ACPI_FUNCTION_TRACE ("ds_method_data_delete_value");
 
 
 	/* Get the namespace node for the arg/local */
@@ -537,18 +536,18 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_store_object_to_local
+ * FUNCTION:    acpi_ds_store_object_to_local
  *
  * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
- *              Index               - Which local_var or argument to set
- *              Obj_desc            - Value to be stored
- *              Walk_state          - Current walk state
+ *              Index               - which local_var or argument to set
+ *              obj_desc            - Value to be stored
+ *              walk_state          - Current walk state
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Store a value in an Arg or Local.  The Obj_desc is installed
+ * DESCRIPTION: Store a value in an Arg or Local.  The obj_desc is installed
  *              as the new value for the Arg or Local and the reference count
- *              for Obj_desc is incremented.
+ *              for obj_desc is incremented.
  *
  ******************************************************************************/
 
@@ -564,7 +563,7 @@
 	acpi_operand_object     *current_obj_desc;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_store_object_to_local");
+	ACPI_FUNCTION_TRACE ("ds_store_object_to_local");
 	ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode=%d Idx=%d Obj=%p\n",
 		opcode, index, obj_desc));
 
@@ -603,12 +602,12 @@
 		 * locals, since a store to a local should overwrite
 		 * anything there, including an object reference.
 		 *
-		 * If both Arg0 and Local0 contain Ref_of (Local4):
+		 * If both Arg0 and Local0 contain ref_of (Local4):
 		 *
 		 * Store (1, Arg0)             - Causes indirect store to local4
 		 * Store (1, Local0)           - Stores 1 in local0, overwriting
 		 *                                  the reference to local4
-		 * Store (1, De_refof (Local0)) - Causes indirect store to local4
+		 * Store (1, de_refof (Local0)) - Causes indirect store to local4
 		 *
 		 * Weird, but true.
 		 */
@@ -625,13 +624,13 @@
 			}
 
 			/*
-			 * If we have a valid reference object that came from Ref_of(), do the
+			 * If we have a valid reference object that came from ref_of(), do the
 			 * indirect store
 			 */
 			if ((current_obj_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) &&
 				(current_obj_desc->reference.opcode == AML_REF_OF_OP)) {
 				ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-					"Arg (%p) is an Obj_ref(Node), storing in node %p\n",
+					"Arg (%p) is an obj_ref(Node), storing in node %p\n",
 					obj_desc, current_obj_desc));
 
 				/*
@@ -652,7 +651,7 @@
 	}
 
 	/*
-	 * Install the Obj_stack descriptor (*Obj_desc) into
+	 * Install the obj_stack descriptor (*obj_desc) into
 	 * the descriptor for the Arg or Local.
 	 * Install the new object in the stack entry
 	 * (increments the object reference count by one)
diff -Nru a/drivers/acpi/dispatcher/dsobject.c b/drivers/acpi/dispatcher/dsobject.c
--- a/drivers/acpi/dispatcher/dsobject.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/acpi/dispatcher/dsobject.c	Mon Dec 23 21:21:50 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: dsobject - Dispatcher object management routines
- *              $Revision: 112 $
  *
  *****************************************************************************/
 
@@ -38,11 +37,11 @@
 #ifndef ACPI_NO_METHOD_EXECUTION
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_build_internal_object
+ * FUNCTION:    acpi_ds_build_internal_object
  *
- * PARAMETERS:  Walk_state      - Current walk state
+ * PARAMETERS:  walk_state      - Current walk state
  *              Op              - Parser object to be translated
- *              Obj_desc_ptr    - Where the ACPI internal object is returned
+ *              obj_desc_ptr    - Where the ACPI internal object is returned
  *
  * RETURN:      Status
  *
@@ -61,7 +60,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_build_internal_object");
+	ACPI_FUNCTION_TRACE ("ds_build_internal_object");
 
 
 	*obj_desc_ptr = NULL;
@@ -104,12 +103,12 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_build_internal_buffer_obj
+ * FUNCTION:    acpi_ds_build_internal_buffer_obj
  *
- * PARAMETERS:  Walk_state      - Current walk state
+ * PARAMETERS:  walk_state      - Current walk state
  *              Op              - Parser object to be translated
- *              Buffer_length   - Length of the buffer
- *              Obj_desc_ptr    - Where the ACPI internal object is returned
+ *              buffer_length   - Length of the buffer
+ *              obj_desc_ptr    - Where the ACPI internal object is returned
  *
  * RETURN:      Status
  *
@@ -131,7 +130,7 @@
 	u32                     byte_list_length = 0;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_build_internal_buffer_obj");
+	ACPI_FUNCTION_TRACE ("ds_build_internal_buffer_obj");
 
 
 	obj_desc = *obj_desc_ptr;
@@ -152,9 +151,9 @@
 	}
 
 	/*
-	 * Second arg is the buffer data (optional) Byte_list can be either
+	 * Second arg is the buffer data (optional) byte_list can be either
 	 * individual bytes or a string initializer.  In either case, a
-	 * Byte_list appears in the AML.
+	 * byte_list appears in the AML.
 	 */
 	arg = op->common.value.arg;         /* skip first arg */
 
@@ -196,7 +195,7 @@
 			return_ACPI_STATUS (AE_NO_MEMORY);
 		}
 
-		/* Initialize buffer from the Byte_list (if present) */
+		/* Initialize buffer from the byte_list (if present) */
 
 		if (byte_list) {
 			ACPI_MEMCPY (obj_desc->buffer.pointer, byte_list->named.data,
@@ -212,12 +211,12 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_build_internal_package_obj
+ * FUNCTION:    acpi_ds_build_internal_package_obj
  *
- * PARAMETERS:  Walk_state      - Current walk state
+ * PARAMETERS:  walk_state      - Current walk state
  *              Op              - Parser object to be translated
- *              Package_length  - Number of elements in the package
- *              Obj_desc_ptr    - Where the ACPI internal object is returned
+ *              package_length  - Number of elements in the package
+ *              obj_desc_ptr    - Where the ACPI internal object is returned
  *
  * RETURN:      Status
  *
@@ -241,7 +240,7 @@
 	u32                     i;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_build_internal_package_obj");
+	ACPI_FUNCTION_TRACE ("ds_build_internal_package_obj");
 
 
 	/* Find the parent of a possibly nested package */
@@ -295,7 +294,7 @@
 	 * that the list is always null terminated.
 	 */
 	obj_desc->package.elements = ACPI_MEM_CALLOCATE (
-			 ((ACPI_SIZE) obj_desc->package.count + 1) * sizeof (void *));
+			 ((acpi_size) obj_desc->package.count + 1) * sizeof (void *));
 
 	if (!obj_desc->package.elements) {
 		acpi_ut_delete_object_desc (obj_desc);
@@ -331,9 +330,9 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_create_node
+ * FUNCTION:    acpi_ds_create_node
  *
- * PARAMETERS:  Walk_state      - Current walk state
+ * PARAMETERS:  walk_state      - Current walk state
  *              Node            - NS Node to be initialized
  *              Op              - Parser object to be translated
  *
@@ -353,7 +352,7 @@
 	acpi_operand_object     *obj_desc;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_create_node", op);
+	ACPI_FUNCTION_TRACE_PTR ("ds_create_node", op);
 
 
 	/*
@@ -397,12 +396,12 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_init_object_from_op
+ * FUNCTION:    acpi_ds_init_object_from_op
  *
- * PARAMETERS:  Walk_state      - Current walk state
+ * PARAMETERS:  walk_state      - Current walk state
  *              Op              - Parser op used to init the internal object
  *              Opcode          - AML opcode associated with the object
- *              Ret_obj_desc    - Namespace object to be initialized
+ *              ret_obj_desc    - Namespace object to be initialized
  *
  * RETURN:      Status
  *
@@ -424,7 +423,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_init_object_from_op");
+	ACPI_FUNCTION_TRACE ("ds_init_object_from_op");
 
 
 	obj_desc = *ret_obj_desc;
@@ -441,7 +440,7 @@
 	case ACPI_TYPE_BUFFER:
 
 		/*
-		 * Defer evaluation of Buffer Term_arg operand
+		 * Defer evaluation of Buffer term_arg operand
 		 */
 		obj_desc->buffer.node     = (acpi_namespace_node *) walk_state->operands[0];
 		obj_desc->buffer.aml_start = op->named.data;
@@ -452,7 +451,7 @@
 	case ACPI_TYPE_PACKAGE:
 
 		/*
-		 * Defer evaluation of Package Term_arg operand
+		 * Defer evaluation of Package term_arg operand
 		 */
 		obj_desc->package.node     = (acpi_namespace_node *) walk_state->operands[0];
 		obj_desc->package.aml_start = op->named.data;
@@ -469,7 +468,7 @@
 			 * All constants are integers.
 			 * We mark the integer with a flag that indicates that it started life
 			 * as a constant -- so that stores to constants will perform as expected (noop).
-			 * (Zero_op is used as a placeholder for optional target operands.)
+			 * (zero_op is used as a placeholder for optional target operands.)
 			 */
 			obj_desc->common.flags = AOPOBJ_AML_CONSTANT;
 
diff -Nru a/drivers/acpi/dispatcher/dsopcode.c b/drivers/acpi/dispatcher/dsopcode.c
--- a/drivers/acpi/dispatcher/dsopcode.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/acpi/dispatcher/dsopcode.c	Mon Dec 23 21:21:59 2002
@@ -2,7 +2,6 @@
  *
  * Module Name: dsopcode - Dispatcher Op Region support and handling of
  *                         "control" opcodes
- *              $Revision: 84 $
  *
  *****************************************************************************/
 
@@ -39,11 +38,11 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_execute_arguments
+ * FUNCTION:    acpi_ds_execute_arguments
  *
  * PARAMETERS:  Node                - Parent NS node
- *              Aml_length          - Length of executable AML
- *              Aml_start           - Pointer to the AML
+ *              aml_length          - Length of executable AML
+ *              aml_start           - Pointer to the AML
  *
  * RETURN:      Status.
  *
@@ -64,7 +63,7 @@
 	acpi_parse_object       *arg;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_ds_execute_arguments");
+	ACPI_FUNCTION_TRACE ("acpi_ds_execute_arguments");
 
 
 	/*
@@ -75,7 +74,7 @@
 		return_ACPI_STATUS (AE_NO_MEMORY);
 	}
 
-	/* Save the Node for use in Acpi_ps_parse_aml */
+	/* Save the Node for use in acpi_ps_parse_aml */
 
 	op->common.node = scope_node;
 
@@ -141,13 +140,13 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_get_buffer_field_arguments
+ * FUNCTION:    acpi_ds_get_buffer_field_arguments
  *
- * PARAMETERS:  Obj_desc        - A valid Buffer_field object
+ * PARAMETERS:  obj_desc        - A valid buffer_field object
  *
  * RETURN:      Status.
  *
- * DESCRIPTION: Get Buffer_field Buffer and Index. This implements the late
+ * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late
  *              evaluation of these field attributes.
  *
  ****************************************************************************/
@@ -161,23 +160,23 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_get_buffer_field_arguments", obj_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ds_get_buffer_field_arguments", obj_desc);
 
 
 	if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
 		return_ACPI_STATUS (AE_OK);
 	}
 
-	/* Get the AML pointer (method object) and Buffer_field node */
+	/* Get the AML pointer (method object) and buffer_field node */
 
 	extra_desc = acpi_ns_get_secondary_object (obj_desc);
 	node = obj_desc->buffer_field.node;
 
 	ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname (ACPI_TYPE_BUFFER_FIELD, node, NULL));
-	ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] Buffer_field JIT Init\n",
+	ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] buffer_field JIT Init\n",
 		node->name.ascii));
 
-	/* Execute the AML code for the Term_arg arguments */
+	/* Execute the AML code for the term_arg arguments */
 
 	status = acpi_ds_execute_arguments (node, acpi_ns_get_parent_node (node),
 			 extra_desc->extra.aml_length, extra_desc->extra.aml_start);
@@ -187,9 +186,9 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_get_buffer_arguments
+ * FUNCTION:    acpi_ds_get_buffer_arguments
  *
- * PARAMETERS:  Obj_desc        - A valid Bufferobject
+ * PARAMETERS:  obj_desc        - A valid Bufferobject
  *
  * RETURN:      Status.
  *
@@ -206,7 +205,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_get_buffer_arguments", obj_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ds_get_buffer_arguments", obj_desc);
 
 
 	if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
@@ -224,7 +223,7 @@
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Buffer JIT Init\n"));
 
-	/* Execute the AML code for the Term_arg arguments */
+	/* Execute the AML code for the term_arg arguments */
 
 	status = acpi_ds_execute_arguments (node, node,
 			 obj_desc->buffer.aml_length, obj_desc->buffer.aml_start);
@@ -234,9 +233,9 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_get_package_arguments
+ * FUNCTION:    acpi_ds_get_package_arguments
  *
- * PARAMETERS:  Obj_desc        - A valid Packageobject
+ * PARAMETERS:  obj_desc        - A valid Packageobject
  *
  * RETURN:      Status.
  *
@@ -253,7 +252,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_get_package_arguments", obj_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ds_get_package_arguments", obj_desc);
 
 
 	if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
@@ -271,7 +270,7 @@
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Package JIT Init\n"));
 
-	/* Execute the AML code for the Term_arg arguments */
+	/* Execute the AML code for the term_arg arguments */
 
 	status = acpi_ds_execute_arguments (node, node,
 			 obj_desc->package.aml_length, obj_desc->package.aml_start);
@@ -281,9 +280,9 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_get_region_arguments
+ * FUNCTION:    acpi_ds_get_region_arguments
  *
- * PARAMETERS:  Obj_desc        - A valid region object
+ * PARAMETERS:  obj_desc        - A valid region object
  *
  * RETURN:      Status.
  *
@@ -301,7 +300,7 @@
 	acpi_operand_object     *extra_desc;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_get_region_arguments", obj_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ds_get_region_arguments", obj_desc);
 
 
 	if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
@@ -319,7 +318,7 @@
 
 	ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname (ACPI_TYPE_REGION, node, NULL));
 
-	ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] Op_region Init at AML %p\n",
+	ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] op_region Init at AML %p\n",
 		node->name.ascii, extra_desc->extra.aml_start));
 
 
@@ -331,13 +330,13 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_initialize_region
+ * FUNCTION:    acpi_ds_initialize_region
  *
  * PARAMETERS:  Op              - A valid region Op object
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Front end to Ev_initialize_region
+ * DESCRIPTION: Front end to ev_initialize_region
  *
  ****************************************************************************/
 
@@ -360,12 +359,12 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_init_buffer_field
+ * FUNCTION:    acpi_ds_init_buffer_field
  *
- * PARAMETERS:  Aml_opcode      - Create_xxx_field
- *              Obj_desc        - Buffer_field object
- *              Buffer_desc     - Host Buffer
- *              Offset_desc     - Offset into buffer
+ * PARAMETERS:  aml_opcode      - create_xxx_field
+ *              obj_desc        - buffer_field object
+ *              buffer_desc     - Host Buffer
+ *              offset_desc     - Offset into buffer
  *              Length          - Length of field (CREATE_FIELD_OP only)
  *              Result          - Where to store the result
  *
@@ -391,7 +390,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_init_buffer_field", obj_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ds_init_buffer_field", obj_desc);
 
 
 	/* Host object must be a Buffer */
@@ -406,9 +405,9 @@
 	}
 
 	/*
-	 * The last parameter to all of these opcodes (Result_desc) started
-	 * out as a Name_string, and should therefore now be a NS node
-	 * after resolution in Acpi_ex_resolve_operands().
+	 * The last parameter to all of these opcodes (result_desc) started
+	 * out as a name_string, and should therefore now be a NS node
+	 * after resolution in acpi_ex_resolve_operands().
 	 */
 	if (ACPI_GET_DESCRIPTOR_TYPE (result_desc) != ACPI_DESC_TYPE_NAMED) {
 		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(%s) destination must be a NS Node\n",
@@ -501,7 +500,7 @@
 
 	/*
 	 * Initialize areas of the field object that are common to all fields
-	 * For Field_flags, use LOCK_RULE = 0 (NO_LOCK), UPDATE_RULE = 0 (UPDATE_PRESERVE)
+	 * For field_flags, use LOCK_RULE = 0 (NO_LOCK), UPDATE_RULE = 0 (UPDATE_PRESERVE)
 	 */
 	status = acpi_ex_prep_common_field_object (obj_desc, field_flags, 0,
 			  bit_offset, bit_count);
@@ -511,7 +510,7 @@
 
 	obj_desc->buffer_field.buffer_obj = buffer_desc;
 
-	/* Reference count for Buffer_desc inherits Obj_desc count */
+	/* Reference count for buffer_desc inherits obj_desc count */
 
 	buffer_desc->common.reference_count = (u16) (buffer_desc->common.reference_count +
 			  obj_desc->common.reference_count);
@@ -534,7 +533,7 @@
 		acpi_ut_remove_reference (result_desc); /* Result descriptor */
 	}
 	else {
-		/* Now the address and length are valid for this Buffer_field */
+		/* Now the address and length are valid for this buffer_field */
 
 		obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
 	}
@@ -545,15 +544,15 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_eval_buffer_field_operands
+ * FUNCTION:    acpi_ds_eval_buffer_field_operands
  *
- * PARAMETERS:  Walk_state      - Current walk
- *              Op              - A valid Buffer_field Op object
+ * PARAMETERS:  walk_state      - Current walk
+ *              Op              - A valid buffer_field Op object
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Get Buffer_field Buffer and Index
- *              Called from Acpi_ds_exec_end_op during Buffer_field parse tree walk
+ * DESCRIPTION: Get buffer_field Buffer and Index
+ *              Called from acpi_ds_exec_end_op during buffer_field parse tree walk
  *
  ****************************************************************************/
 
@@ -568,16 +567,16 @@
 	acpi_parse_object       *next_op;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_eval_buffer_field_operands", op);
+	ACPI_FUNCTION_TRACE_PTR ("ds_eval_buffer_field_operands", op);
 
 
 	/*
 	 * This is where we evaluate the address and length fields of the
-	 * Create_xxx_field declaration
+	 * create_xxx_field declaration
 	 */
 	node =  op->common.node;
 
-	/* Next_op points to the op that holds the Buffer */
+	/* next_op points to the op that holds the Buffer */
 
 	next_op = op->common.value.arg;
 
@@ -600,7 +599,7 @@
 
 	ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
 			  acpi_ps_get_opcode_name (op->common.aml_opcode),
-			  walk_state->num_operands, "after Acpi_ex_resolve_operands");
+			  walk_state->num_operands, "after acpi_ex_resolve_operands");
 
 	if (ACPI_FAILURE (status)) {
 		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(%s) bad operand(s) (%X)\n",
@@ -619,7 +618,7 @@
 				 walk_state->operands[2], walk_state->operands[3]);
 	}
 	else {
-		/* All other, Create_xxx_field opcodes */
+		/* All other, create_xxx_field opcodes */
 
 		status = acpi_ds_init_buffer_field (op->common.aml_opcode, obj_desc,
 				 walk_state->operands[0], walk_state->operands[1],
@@ -632,15 +631,15 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_eval_region_operands
+ * FUNCTION:    acpi_ds_eval_region_operands
  *
- * PARAMETERS:  Walk_state      - Current walk
+ * PARAMETERS:  walk_state      - Current walk
  *              Op              - A valid region Op object
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Get region address and length
- *              Called from Acpi_ds_exec_end_op during Op_region parse tree walk
+ *              Called from acpi_ds_exec_end_op during op_region parse tree walk
  *
  ****************************************************************************/
 
@@ -656,19 +655,19 @@
 	acpi_parse_object       *next_op;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_eval_region_operands", op);
+	ACPI_FUNCTION_TRACE_PTR ("ds_eval_region_operands", op);
 
 
 	/*
-	 * This is where we evaluate the address and length fields of the Op_region declaration
+	 * This is where we evaluate the address and length fields of the op_region declaration
 	 */
 	node =  op->common.node;
 
-	/* Next_op points to the op that holds the Space_iD */
+	/* next_op points to the op that holds the space_iD */
 
 	next_op = op->common.value.arg;
 
-	/* Next_op points to address op */
+	/* next_op points to address op */
 
 	next_op = next_op->common.next;
 
@@ -688,7 +687,7 @@
 
 	ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
 			  acpi_ps_get_opcode_name (op->common.aml_opcode),
-			  1, "after Acpi_ex_resolve_operands");
+			  1, "after acpi_ex_resolve_operands");
 
 	obj_desc = acpi_ns_get_attached_object (node);
 	if (!obj_desc) {
@@ -710,10 +709,10 @@
 	 */
 	operand_desc = walk_state->operands[walk_state->num_operands - 2];
 
-	obj_desc->region.address = (ACPI_PHYSICAL_ADDRESS) operand_desc->integer.value;
+	obj_desc->region.address = (acpi_physical_address) operand_desc->integer.value;
 	acpi_ut_remove_reference (operand_desc);
 
-	ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Rgn_obj %p Addr %8.8X%8.8X Len %X\n",
+	ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "rgn_obj %p Addr %8.8X%8.8X Len %X\n",
 		obj_desc,
 		ACPI_HIDWORD (obj_desc->region.address), ACPI_LODWORD (obj_desc->region.address),
 		obj_desc->region.length));
@@ -728,11 +727,11 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_eval_data_object_operands
+ * FUNCTION:    acpi_ds_eval_data_object_operands
  *
- * PARAMETERS:  Walk_state      - Current walk
- *              Op              - A valid Data_object Op object
- *              Obj_desc        - Data_object
+ * PARAMETERS:  walk_state      - Current walk
+ *              Op              - A valid data_object Op object
+ *              obj_desc        - data_object
  *
  * RETURN:      Status
  *
@@ -753,7 +752,7 @@
 	u32                     length;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_eval_data_object_operands");
+	ACPI_FUNCTION_TRACE ("ds_eval_data_object_operands");
 
 
 	/* The first operand (for all of these data objects) is the length */
@@ -805,7 +804,7 @@
 
 	if (ACPI_SUCCESS (status)) {
 		/*
-		 * Return the object in the Walk_state, unless the parent is a package --
+		 * Return the object in the walk_state, unless the parent is a package --
 		 * in this case, the return object will be stored in the parse tree
 		 * for the package.
 		 */
@@ -823,9 +822,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_exec_begin_control_op
+ * FUNCTION:    acpi_ds_exec_begin_control_op
  *
- * PARAMETERS:  Walk_list       - The list that owns the walk stack
+ * PARAMETERS:  walk_list       - The list that owns the walk stack
  *              Op              - The control Op
  *
  * RETURN:      Status
@@ -844,7 +843,7 @@
 	acpi_generic_state      *control_state;
 
 
-	ACPI_FUNCTION_NAME ("Ds_exec_begin_control_op");
+	ACPI_FUNCTION_NAME ("ds_exec_begin_control_op");
 
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", op,
@@ -903,9 +902,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_exec_end_control_op
+ * FUNCTION:    acpi_ds_exec_end_control_op
  *
- * PARAMETERS:  Walk_list       - The list that owns the walk stack
+ * PARAMETERS:  walk_list       - The list that owns the walk stack
  *              Op              - The control Op
  *
  * RETURN:      Status
@@ -924,7 +923,7 @@
 	acpi_generic_state      *control_state;
 
 
-	ACPI_FUNCTION_NAME ("Ds_exec_end_control_op");
+	ACPI_FUNCTION_NAME ("ds_exec_end_control_op");
 
 
 	switch (op->common.aml_opcode) {
@@ -1004,7 +1003,7 @@
 
 			/*
 			 * Get the return value and save as the last result
-			 * value.  This is the only place where Walk_state->Return_desc
+			 * value.  This is the only place where walk_state->return_desc
 			 * is set to anything other than zero!
 			 */
 			walk_state->return_desc = walk_state->operands[0];
@@ -1045,7 +1044,7 @@
 
 
 		ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-			"Completed RETURN_OP State=%p, Ret_val=%p\n",
+			"Completed RETURN_OP State=%p, ret_val=%p\n",
 			walk_state, walk_state->return_desc));
 
 		/* End the control method execution right now */
@@ -1089,7 +1088,7 @@
 			return (AE_AML_NO_WHILE);
 		}
 
-		/* Was: Walk_state->Aml_last_while = Walk_state->Control_state->Control.Aml_predicate_start; */
+		/* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */
 
 		walk_state->aml_last_while = walk_state->control_state->control.package_end;
 
diff -Nru a/drivers/acpi/dispatcher/dsutils.c b/drivers/acpi/dispatcher/dsutils.c
--- a/drivers/acpi/dispatcher/dsutils.c	Mon Dec 23 21:21:54 2002
+++ b/drivers/acpi/dispatcher/dsutils.c	Mon Dec 23 21:21:54 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: dsutils - Dispatcher utilities
- *              $Revision: 98 $
  *
  ******************************************************************************/
 
@@ -39,11 +38,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_is_result_used
+ * FUNCTION:    acpi_ds_is_result_used
  *
  * PARAMETERS:  Op
- *              Result_obj
- *              Walk_state
+ *              result_obj
+ *              walk_state
  *
  * RETURN:      Status
  *
@@ -59,7 +58,7 @@
 	const acpi_opcode_info  *parent_info;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_is_result_used", op);
+	ACPI_FUNCTION_TRACE_PTR ("ds_is_result_used", op);
 
 
 	/* Must have both an Op and a Result Object */
@@ -130,7 +129,7 @@
 	case AML_CLASS_CREATE:
 
 		/*
-		 * These opcodes allow Term_arg(s) as operands and therefore
+		 * These opcodes allow term_arg(s) as operands and therefore
 		 * the operands can be method calls.  The result is used.
 		 */
 		goto result_used;
@@ -145,7 +144,7 @@
 			(op->common.parent->common.aml_opcode == AML_BUFFER_OP)      ||
 			(op->common.parent->common.aml_opcode == AML_INT_EVAL_SUBTREE_OP)) {
 			/*
-			 * These opcodes allow Term_arg(s) as operands and therefore
+			 * These opcodes allow term_arg(s) as operands and therefore
 			 * the operands can be method calls.  The result is used.
 			 */
 			goto result_used;
@@ -184,11 +183,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_delete_result_if_not_used
+ * FUNCTION:    acpi_ds_delete_result_if_not_used
  *
  * PARAMETERS:  Op
- *              Result_obj
- *              Walk_state
+ *              result_obj
+ *              walk_state
  *
  * RETURN:      Status
  *
@@ -209,7 +208,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_delete_result_if_not_used", result_obj);
+	ACPI_FUNCTION_TRACE_PTR ("ds_delete_result_if_not_used", result_obj);
 
 
 	if (!op) {
@@ -224,7 +223,7 @@
 
 	if (!acpi_ds_is_result_used (op, walk_state)) {
 		/*
-		 * Must pop the result stack (Obj_desc should be equal to Result_obj)
+		 * Must pop the result stack (obj_desc should be equal to result_obj)
 		 */
 		status = acpi_ds_result_pop (&obj_desc, walk_state);
 		if (ACPI_SUCCESS (status)) {
@@ -238,9 +237,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_resolve_operands
+ * FUNCTION:    acpi_ds_resolve_operands
  *
- * PARAMETERS:  Walk_state          - Current walk state with operands on stack
+ * PARAMETERS:  walk_state          - Current walk state with operands on stack
  *
  * RETURN:      Status
  *
@@ -258,7 +257,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_resolve_operands", walk_state);
+	ACPI_FUNCTION_TRACE_PTR ("ds_resolve_operands", walk_state);
 
 
 	/*
@@ -278,9 +277,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_clear_operands
+ * FUNCTION:    acpi_ds_clear_operands
  *
- * PARAMETERS:  Walk_state          - Current walk state with operands on stack
+ * PARAMETERS:  walk_state          - Current walk state with operands on stack
  *
  * RETURN:      None
  *
@@ -295,7 +294,7 @@
 	u32                     i;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Acpi_ds_clear_operands", walk_state);
+	ACPI_FUNCTION_TRACE_PTR ("acpi_ds_clear_operands", walk_state);
 
 
 	/*
@@ -318,9 +317,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_create_operand
+ * FUNCTION:    acpi_ds_create_operand
  *
- * PARAMETERS:  Walk_state
+ * PARAMETERS:  walk_state
  *              Arg
  *
  * RETURN:      Status
@@ -348,7 +347,7 @@
 	const acpi_opcode_info  *op_info;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_create_operand", arg);
+	ACPI_FUNCTION_TRACE_PTR ("ds_create_operand", arg);
 
 
 	/* A valid name must be looked up in the namespace */
@@ -368,7 +367,7 @@
 
 		/*
 		 * All prefixes have been handled, and the name is
-		 * in Name_string
+		 * in name_string
 		 */
 
 		/*
@@ -401,7 +400,7 @@
 				 ACPI_CAST_INDIRECT_PTR (acpi_namespace_node, &obj_desc));
 		/*
 		 * The only case where we pass through (ignore) a NOT_FOUND
-		 * error is for the Cond_ref_of opcode.
+		 * error is for the cond_ref_of opcode.
 		 */
 		if (status == AE_NOT_FOUND) {
 			if (parent_op->common.aml_opcode == AML_COND_REF_OF_OP) {
@@ -530,9 +529,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_create_operands
+ * FUNCTION:    acpi_ds_create_operands
  *
- * PARAMETERS:  First_arg           - First argument of a parser argument tree
+ * PARAMETERS:  first_arg           - First argument of a parser argument tree
  *
  * RETURN:      Status
  *
@@ -552,7 +551,7 @@
 	u32                     arg_count = 0;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_create_operands", first_arg);
+	ACPI_FUNCTION_TRACE_PTR ("ds_create_operands", first_arg);
 
 
 	/* For all arguments in the list... */
diff -Nru a/drivers/acpi/dispatcher/dswexec.c b/drivers/acpi/dispatcher/dswexec.c
--- a/drivers/acpi/dispatcher/dswexec.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/acpi/dispatcher/dswexec.c	Mon Dec 23 21:22:00 2002
@@ -2,7 +2,6 @@
  *
  * Module Name: dswexec - Dispatcher method execution callbacks;
  *                        dispatch to interpreter.
- *              $Revision: 97 $
  *
  *****************************************************************************/
 
@@ -55,9 +54,9 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_get_predicate_value
+ * FUNCTION:    acpi_ds_get_predicate_value
  *
- * PARAMETERS:  Walk_state      - Current state of the parse tree walk
+ * PARAMETERS:  walk_state      - Current state of the parse tree walk
  *
  * RETURN:      Status
  *
@@ -73,7 +72,7 @@
 	acpi_operand_object     *obj_desc;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_get_predicate_value", walk_state);
+	ACPI_FUNCTION_TRACE_PTR ("ds_get_predicate_value", walk_state);
 
 
 	walk_state->control_state->common.state = 0;
@@ -103,7 +102,7 @@
 	}
 
 	if (!obj_desc) {
-		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No predicate Obj_desc=%p State=%p\n",
+		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No predicate obj_desc=%p State=%p\n",
 			obj_desc, walk_state));
 
 		return_ACPI_STATUS (AE_AML_NO_OPERAND);
@@ -115,7 +114,7 @@
 	 */
 	if (ACPI_GET_OBJECT_TYPE (obj_desc) != ACPI_TYPE_INTEGER) {
 		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
-			"Bad predicate (not a number) Obj_desc=%p State=%p Type=%X\n",
+			"Bad predicate (not a number) obj_desc=%p State=%p Type=%X\n",
 			obj_desc, walk_state, ACPI_GET_OBJECT_TYPE (obj_desc)));
 
 		status = AE_AML_OPERAND_TYPE;
@@ -165,10 +164,10 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_exec_begin_op
+ * FUNCTION:    acpi_ds_exec_begin_op
  *
- * PARAMETERS:  Walk_state      - Current state of the parse tree walk
- *              Out_op          - Return op if a new one is created
+ * PARAMETERS:  walk_state      - Current state of the parse tree walk
+ *              out_op          - Return op if a new one is created
  *
  * RETURN:      Status
  *
@@ -188,7 +187,7 @@
 	u32                     opcode_class;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_exec_begin_op", walk_state);
+	ACPI_FUNCTION_TRACE_PTR ("ds_exec_begin_op", walk_state);
 
 
 	op = walk_state->op;
@@ -305,9 +304,9 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ds_exec_end_op
+ * FUNCTION:    acpi_ds_exec_end_op
  *
- * PARAMETERS:  Walk_state      - Current state of the parse tree walk
+ * PARAMETERS:  walk_state      - Current state of the parse tree walk
  *              Op              - Op that has been just been completed in the
  *                                walk;  Arguments have now been evaluated.
  *
@@ -331,7 +330,7 @@
 	acpi_parse_object       *first_arg;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_exec_end_op", walk_state);
+	ACPI_FUNCTION_TRACE_PTR ("ds_exec_end_op", walk_state);
 
 
 	op      = walk_state->op;
@@ -387,7 +386,7 @@
 		if (ACPI_SUCCESS (status)) {
 			ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
 					  acpi_ps_get_opcode_name (walk_state->opcode),
-					  walk_state->num_operands, "after Ex_resolve_operands");
+					  walk_state->num_operands, "after ex_resolve_operands");
 
 			/*
 			 * Dispatch the request to the appropriate interpreter handler
@@ -424,7 +423,7 @@
 		switch (op_type) {
 		case AML_TYPE_CONTROL:    /* Type 1 opcode, IF/ELSE/WHILE/NOOP */
 
-			/* 1 Operand, 0 External_result, 0 Internal_result */
+			/* 1 Operand, 0 external_result, 0 internal_result */
 
 			status = acpi_ds_exec_end_control_op (walk_state, op);
 			if (ACPI_FAILURE (status)) {
@@ -443,11 +442,11 @@
 			 * (AML_METHODCALL) Op->Value->Arg->Node contains
 			 * the method Node pointer
 			 */
-			/* Next_op points to the op that holds the method name */
+			/* next_op points to the op that holds the method name */
 
 			next_op = first_arg;
 
-			/* Next_op points to first argument op */
+			/* next_op points to first argument op */
 
 			next_op = next_op->common.next;
 
@@ -488,7 +487,7 @@
 		case AML_TYPE_CREATE_FIELD:
 
 			ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-				"Executing Create_field Buffer/Index Op=%p\n", op));
+				"Executing create_field Buffer/Index Op=%p\n", op));
 
 			status = acpi_ds_load2_end_op (walk_state);
 			if (ACPI_FAILURE (status)) {
@@ -502,7 +501,7 @@
 		case AML_TYPE_CREATE_OBJECT:
 
 			ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-				"Executing Create_object (Buffer/Package) Op=%p\n", op));
+				"Executing create_object (Buffer/Package) Op=%p\n", op));
 
 			switch (op->common.parent->common.aml_opcode) {
 			case AML_NAME_OP:
@@ -557,7 +556,7 @@
 
 			if (op->common.aml_opcode == AML_REGION_OP) {
 				ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-					"Executing Op_region Address/Length Op=%p\n", op));
+					"Executing op_region Address/Length Op=%p\n", op));
 
 				status = acpi_ds_eval_region_operands (walk_state, op);
 				if (ACPI_FAILURE (status)) {
diff -Nru a/drivers/acpi/dispatcher/dswload.c b/drivers/acpi/dispatcher/dswload.c
--- a/drivers/acpi/dispatcher/dswload.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/dispatcher/dswload.c	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: dswload - Dispatcher namespace load callbacks
- *              $Revision: 82 $
  *
  *****************************************************************************/
 
@@ -39,10 +38,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_init_callbacks
+ * FUNCTION:    acpi_ds_init_callbacks
  *
- * PARAMETERS:  Walk_state      - Current state of the parse tree walk
- *              Pass_number     - 1, 2, or 3
+ * PARAMETERS:  walk_state      - Current state of the parse tree walk
+ *              pass_number     - 1, 2, or 3
  *
  * RETURN:      Status
  *
@@ -87,9 +86,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_load1_begin_op
+ * FUNCTION:    acpi_ds_load1_begin_op
  *
- * PARAMETERS:  Walk_state      - Current state of the parse tree walk
+ * PARAMETERS:  walk_state      - Current state of the parse tree walk
  *              Op              - Op that has been just been reached in the
  *                                walk;  Arguments have not been evaluated yet.
  *
@@ -112,7 +111,7 @@
 	u32                     flags;
 
 
-	ACPI_FUNCTION_NAME ("Ds_load1_begin_op");
+	ACPI_FUNCTION_NAME ("ds_load1_begin_op");
 
 
 	op = walk_state->op;
@@ -226,8 +225,8 @@
 		 * already exists:
 		 *    1) the Scope() operator can reopen a scoping object that was
 		 *       previously defined (Scope, Method, Device, etc.)
-		 *    2) Whenever we are parsing a deferred opcode (Op_region, Buffer,
-		 *       Buffer_field, or Package), the name of the object is already
+		 *    2) Whenever we are parsing a deferred opcode (op_region, Buffer,
+		 *       buffer_field, or Package), the name of the object is already
 		 *       in the namespace.
 		 */
 		flags = ACPI_NS_NO_UPSEARCH;
@@ -289,9 +288,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_load1_end_op
+ * FUNCTION:    acpi_ds_load1_end_op
  *
- * PARAMETERS:  Walk_state      - Current state of the parse tree walk
+ * PARAMETERS:  walk_state      - Current state of the parse tree walk
  *              Op              - Op that has been just been completed in the
  *                                walk;  Arguments have now been evaluated.
  *
@@ -311,7 +310,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_NAME ("Ds_load1_end_op");
+	ACPI_FUNCTION_NAME ("ds_load1_end_op");
 
 
 	op = walk_state->op;
@@ -340,7 +339,7 @@
 
 	if (op->common.aml_opcode == AML_REGION_OP) {
 		status = acpi_ex_create_region (op->named.data, op->named.length,
-				   (ACPI_ADR_SPACE_TYPE) ((op->common.value.arg)->common.value.integer), walk_state);
+				   (acpi_adr_space_type) ((op->common.value.arg)->common.value.integer), walk_state);
 		if (ACPI_FAILURE (status)) {
 			return (status);
 		}
@@ -358,7 +357,7 @@
 
 	if (op->common.aml_opcode == AML_METHOD_OP) {
 		/*
-		 * Method_op Pkg_length Name_string Method_flags Term_list
+		 * method_op pkg_length name_string method_flags term_list
 		 *
 		 * Note: We must create the method node/object pair as soon as we
 		 * see the method declaration.  This allows later pass1 parsing
@@ -366,7 +365,7 @@
 		 * arguments.)
 		 */
 		ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-			"LOADING-Method: State=%p Op=%p Named_obj=%p\n",
+			"LOADING-Method: State=%p Op=%p named_obj=%p\n",
 			walk_state, op, op->named.node));
 
 		if (!acpi_ns_get_attached_object (op->named.node)) {
@@ -402,9 +401,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_load2_begin_op
+ * FUNCTION:    acpi_ds_load2_begin_op
  *
- * PARAMETERS:  Walk_state      - Current state of the parse tree walk
+ * PARAMETERS:  walk_state      - Current state of the parse tree walk
  *              Op              - Op that has been just been reached in the
  *                                walk;  Arguments have not been evaluated yet.
  *
@@ -426,7 +425,7 @@
 	char                    *buffer_ptr;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_load2_begin_op");
+	ACPI_FUNCTION_TRACE ("ds_load2_begin_op");
 
 
 	op = walk_state->op;
@@ -485,7 +484,7 @@
 	case AML_INT_NAMEPATH_OP:
 
 		/*
-		 * The Name_path is an object reference to an existing object. Don't enter the
+		 * The name_path is an object reference to an existing object. Don't enter the
 		 * name into the namespace, but look it up for use later
 		 */
 		status = acpi_ns_lookup (walk_state->scope_info, buffer_ptr, object_type,
@@ -613,9 +612,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_load2_end_op
+ * FUNCTION:    acpi_ds_load2_end_op
  *
- * PARAMETERS:  Walk_state      - Current state of the parse tree walk
+ * PARAMETERS:  walk_state      - Current state of the parse tree walk
  *              Op              - Op that has been just been completed in the
  *                                walk;  Arguments have now been evaluated.
  *
@@ -641,7 +640,7 @@
 #endif
 
 
-	ACPI_FUNCTION_TRACE ("Ds_load2_end_op");
+	ACPI_FUNCTION_TRACE ("ds_load2_end_op");
 
 	op = walk_state->op;
 	ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
@@ -715,7 +714,7 @@
 	 */
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-		"Create-Load [%s] State=%p Op=%p Named_obj=%p\n",
+		"Create-Load [%s] State=%p Op=%p named_obj=%p\n",
 		acpi_ps_get_opcode_name (op->common.aml_opcode), walk_state, op, node));
 
 	/* Decode the opcode */
@@ -822,7 +821,7 @@
 #ifndef ACPI_NO_METHOD_EXECUTION
 		case AML_REGION_OP:
 			/*
-			 * The Op_region is not fully parsed at this time. Only valid argument is the Space_id.
+			 * The op_region is not fully parsed at this time. Only valid argument is the space_id.
 			 * (We must save the address of the AML of the address and length operands)
 			 */
 			/*
@@ -867,7 +866,7 @@
 	case AML_CLASS_METHOD_CALL:
 
 		ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
-			"RESOLVING-Method_call: State=%p Op=%p Named_obj=%p\n",
+			"RESOLVING-method_call: State=%p Op=%p named_obj=%p\n",
 			walk_state, op, node));
 
 		/*
diff -Nru a/drivers/acpi/dispatcher/dswscope.c b/drivers/acpi/dispatcher/dswscope.c
--- a/drivers/acpi/dispatcher/dswscope.c	Mon Dec 23 21:22:01 2002
+++ b/drivers/acpi/dispatcher/dswscope.c	Mon Dec 23 21:22:01 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: dswscope - Scope stack manipulation
- *              $Revision: 56 $
  *
  *****************************************************************************/
 
@@ -37,7 +36,7 @@
 
 /****************************************************************************
  *
- * FUNCTION:    Acpi_ds_scope_stack_clear
+ * FUNCTION:    acpi_ds_scope_stack_clear
  *
  * PARAMETERS:  None
  *
@@ -52,7 +51,7 @@
 {
 	acpi_generic_state      *scope_info;
 
-	ACPI_FUNCTION_NAME ("Ds_scope_stack_clear");
+	ACPI_FUNCTION_NAME ("ds_scope_stack_clear");
 
 
 	while (walk_state->scope_info) {
@@ -70,7 +69,7 @@
 
 /****************************************************************************
  *
- * FUNCTION:    Acpi_ds_scope_stack_push
+ * FUNCTION:    acpi_ds_scope_stack_push
  *
  * PARAMETERS:  *Node,              - Name to be made current
  *              Type,               - Type of frame being pushed
@@ -90,20 +89,20 @@
 	acpi_generic_state      *old_scope_info;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_scope_stack_push");
+	ACPI_FUNCTION_TRACE ("ds_scope_stack_push");
 
 
 	if (!node) {
 		/* Invalid scope   */
 
-		ACPI_REPORT_ERROR (("Ds_scope_stack_push: null scope passed\n"));
+		ACPI_REPORT_ERROR (("ds_scope_stack_push: null scope passed\n"));
 		return_ACPI_STATUS (AE_BAD_PARAMETER);
 	}
 
 	/* Make sure object type is valid */
 
 	if (!acpi_ut_valid_object_type (type)) {
-		ACPI_REPORT_WARNING (("Ds_scope_stack_push: type code out of range\n"));
+		ACPI_REPORT_WARNING (("ds_scope_stack_push: type code out of range\n"));
 	}
 
 
@@ -152,7 +151,7 @@
 
 /****************************************************************************
  *
- * FUNCTION:    Acpi_ds_scope_stack_pop
+ * FUNCTION:    acpi_ds_scope_stack_pop
  *
  * PARAMETERS:  Type                - The type of frame to be found
  *
@@ -175,7 +174,7 @@
 	acpi_generic_state      *new_scope_info;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_scope_stack_pop");
+	ACPI_FUNCTION_TRACE ("ds_scope_stack_pop");
 
 
 	/*
diff -Nru a/drivers/acpi/dispatcher/dswstate.c b/drivers/acpi/dispatcher/dswstate.c
--- a/drivers/acpi/dispatcher/dswstate.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/acpi/dispatcher/dswstate.c	Mon Dec 23 21:22:00 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: dswstate - Dispatcher parse tree walk management routines
- *              $Revision: 73 $
  *
  *****************************************************************************/
 
@@ -35,10 +34,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_result_insert
+ * FUNCTION:    acpi_ds_result_insert
  *
  * PARAMETERS:  Object              - Object to push
- *              Walk_state          - Current Walk state
+ *              walk_state          - Current Walk state
  *
  * RETURN:      Status
  *
@@ -55,7 +54,7 @@
 	acpi_generic_state      *state;
 
 
-	ACPI_FUNCTION_NAME ("Ds_result_insert");
+	ACPI_FUNCTION_NAME ("ds_result_insert");
 
 
 	state = walk_state->results;
@@ -93,10 +92,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_result_remove
+ * FUNCTION:    acpi_ds_result_remove
  *
  * PARAMETERS:  Object              - Where to return the popped object
- *              Walk_state          - Current Walk state
+ *              walk_state          - Current Walk state
  *
  * RETURN:      Status
  *
@@ -114,7 +113,7 @@
 	acpi_generic_state      *state;
 
 
-	ACPI_FUNCTION_NAME ("Ds_result_remove");
+	ACPI_FUNCTION_NAME ("ds_result_remove");
 
 
 	state = walk_state->results;
@@ -157,10 +156,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_result_pop
+ * FUNCTION:    acpi_ds_result_pop
  *
  * PARAMETERS:  Object              - Where to return the popped object
- *              Walk_state          - Current Walk state
+ *              walk_state          - Current Walk state
  *
  * RETURN:      Status
  *
@@ -174,11 +173,11 @@
 	acpi_operand_object     **object,
 	acpi_walk_state         *walk_state)
 {
-	NATIVE_UINT             index;
+	acpi_native_uint        index;
 	acpi_generic_state      *state;
 
 
-	ACPI_FUNCTION_NAME ("Ds_result_pop");
+	ACPI_FUNCTION_NAME ("ds_result_pop");
 
 
 	state = walk_state->results;
@@ -217,10 +216,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_result_pop_from_bottom
+ * FUNCTION:    acpi_ds_result_pop_from_bottom
  *
  * PARAMETERS:  Object              - Where to return the popped object
- *              Walk_state          - Current Walk state
+ *              walk_state          - Current Walk state
  *
  * RETURN:      Status
  *
@@ -234,11 +233,11 @@
 	acpi_operand_object     **object,
 	acpi_walk_state         *walk_state)
 {
-	NATIVE_UINT             index;
+	acpi_native_uint        index;
 	acpi_generic_state      *state;
 
 
-	ACPI_FUNCTION_NAME ("Ds_result_pop_from_bottom");
+	ACPI_FUNCTION_NAME ("ds_result_pop_from_bottom");
 
 
 	state = walk_state->results;
@@ -284,10 +283,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_result_push
+ * FUNCTION:    acpi_ds_result_push
  *
  * PARAMETERS:  Object              - Where to return the popped object
- *              Walk_state          - Current Walk state
+ *              walk_state          - Current Walk state
  *
  * RETURN:      Status
  *
@@ -303,7 +302,7 @@
 	acpi_generic_state      *state;
 
 
-	ACPI_FUNCTION_NAME ("Ds_result_push");
+	ACPI_FUNCTION_NAME ("ds_result_push");
 
 
 	state = walk_state->results;
@@ -338,14 +337,14 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_result_stack_push
+ * FUNCTION:    acpi_ds_result_stack_push
  *
  * PARAMETERS:  Object              - Object to push
- *              Walk_state          - Current Walk state
+ *              walk_state          - Current Walk state
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Push an object onto the Walk_state result stack.
+ * DESCRIPTION: Push an object onto the walk_state result stack.
  *
  ******************************************************************************/
 
@@ -355,7 +354,7 @@
 {
 	acpi_generic_state      *state;
 
-	ACPI_FUNCTION_NAME ("Ds_result_stack_push");
+	ACPI_FUNCTION_NAME ("ds_result_stack_push");
 
 
 	state = acpi_ut_create_generic_state ();
@@ -375,13 +374,13 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_result_stack_pop
+ * FUNCTION:    acpi_ds_result_stack_pop
  *
- * PARAMETERS:  Walk_state          - Current Walk state
+ * PARAMETERS:  walk_state          - Current Walk state
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Pop an object off of the Walk_state result stack.
+ * DESCRIPTION: Pop an object off of the walk_state result stack.
  *
  ******************************************************************************/
 
@@ -391,7 +390,7 @@
 {
 	acpi_generic_state      *state;
 
-	ACPI_FUNCTION_NAME ("Ds_result_stack_pop");
+	ACPI_FUNCTION_NAME ("ds_result_stack_pop");
 
 
 	/* Check for stack underflow */
@@ -406,7 +405,7 @@
 	state = acpi_ut_pop_generic_state (&walk_state->results);
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
-		"Result=%p Remaining_results=%X State=%p\n",
+		"Result=%p remaining_results=%X State=%p\n",
 		state, state->results.num_results, walk_state));
 
 	acpi_ut_delete_generic_state (state);
@@ -417,9 +416,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_obj_stack_delete_all
+ * FUNCTION:    acpi_ds_obj_stack_delete_all
  *
- * PARAMETERS:  Walk_state          - Current Walk state
+ * PARAMETERS:  walk_state          - Current Walk state
  *
  * RETURN:      Status
  *
@@ -435,7 +434,7 @@
 	u32                     i;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_obj_stack_delete_all", walk_state);
+	ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_delete_all", walk_state);
 
 
 	/* The stack size is configurable, but fixed */
@@ -453,10 +452,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_obj_stack_push
+ * FUNCTION:    acpi_ds_obj_stack_push
  *
  * PARAMETERS:  Object              - Object to push
- *              Walk_state          - Current Walk state
+ *              walk_state          - Current Walk state
  *
  * RETURN:      Status
  *
@@ -469,7 +468,7 @@
 	void                    *object,
 	acpi_walk_state         *walk_state)
 {
-	ACPI_FUNCTION_NAME ("Ds_obj_stack_push");
+	ACPI_FUNCTION_NAME ("ds_obj_stack_push");
 
 
 	/* Check for stack overflow */
@@ -497,10 +496,10 @@
 #if 0
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_obj_stack_pop_object
+ * FUNCTION:    acpi_ds_obj_stack_pop_object
  *
- * PARAMETERS:  Pop_count           - Number of objects/entries to pop
- *              Walk_state          - Current Walk state
+ * PARAMETERS:  pop_count           - Number of objects/entries to pop
+ *              walk_state          - Current Walk state
  *
  * RETURN:      Status
  *
@@ -514,7 +513,7 @@
 	acpi_operand_object     **object,
 	acpi_walk_state         *walk_state)
 {
-	ACPI_FUNCTION_NAME ("Ds_obj_stack_pop_object");
+	ACPI_FUNCTION_NAME ("ds_obj_stack_pop_object");
 
 
 	/* Check for stack underflow */
@@ -556,10 +555,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_obj_stack_pop
+ * FUNCTION:    acpi_ds_obj_stack_pop
  *
- * PARAMETERS:  Pop_count           - Number of objects/entries to pop
- *              Walk_state          - Current Walk state
+ * PARAMETERS:  pop_count           - Number of objects/entries to pop
+ *              walk_state          - Current Walk state
  *
  * RETURN:      Status
  *
@@ -575,7 +574,7 @@
 {
 	u32                     i;
 
-	ACPI_FUNCTION_NAME ("Ds_obj_stack_pop");
+	ACPI_FUNCTION_NAME ("ds_obj_stack_pop");
 
 
 	for (i = 0; i < pop_count; i++) {
@@ -603,10 +602,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_obj_stack_pop_and_delete
+ * FUNCTION:    acpi_ds_obj_stack_pop_and_delete
  *
- * PARAMETERS:  Pop_count           - Number of objects/entries to pop
- *              Walk_state          - Current Walk state
+ * PARAMETERS:  pop_count           - Number of objects/entries to pop
+ *              walk_state          - Current Walk state
  *
  * RETURN:      Status
  *
@@ -623,7 +622,7 @@
 	u32                     i;
 	acpi_operand_object     *obj_desc;
 
-	ACPI_FUNCTION_NAME ("Ds_obj_stack_pop_and_delete");
+	ACPI_FUNCTION_NAME ("ds_obj_stack_pop_and_delete");
 
 
 	for (i = 0; i < pop_count; i++) {
@@ -655,11 +654,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_obj_stack_get_value
+ * FUNCTION:    acpi_ds_obj_stack_get_value
  *
  * PARAMETERS:  Index               - Stack index whose value is desired.  Based
  *                                    on the top of the stack (index=0 == top)
- *              Walk_state          - Current Walk state
+ *              walk_state          - Current Walk state
  *
  * RETURN:      Status
  *
@@ -674,7 +673,7 @@
 	acpi_walk_state         *walk_state)
 {
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_obj_stack_get_value", walk_state);
+	ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_get_value", walk_state);
 
 
 	/* Can't do it if the stack is empty */
@@ -689,14 +688,14 @@
 		return_PTR (NULL);
 	}
 
-	return_PTR (walk_state->operands[(NATIVE_UINT)(walk_state->num_operands - 1) -
+	return_PTR (walk_state->operands[(acpi_native_uint)(walk_state->num_operands - 1) -
 			  index]);
 }
 
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_get_current_walk_state
+ * FUNCTION:    acpi_ds_get_current_walk_state
  *
  * PARAMETERS:  Thread          - Get current active state for this Thread
  *
@@ -709,17 +708,17 @@
 
 acpi_walk_state *
 acpi_ds_get_current_walk_state (
-	ACPI_THREAD_STATE       *thread)
+	acpi_thread_state       *thread)
 
 {
-	ACPI_FUNCTION_NAME ("Ds_get_current_walk_state");
+	ACPI_FUNCTION_NAME ("ds_get_current_walk_state");
 
 
 	if (!thread) {
 		return (NULL);
 	}
 
-	ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Current Walk_state %p\n",
+	ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Current walk_state %p\n",
 		thread->walk_state_list));
 
 	return (thread->walk_state_list);
@@ -728,23 +727,23 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_push_walk_state
+ * FUNCTION:    acpi_ds_push_walk_state
  *
- * PARAMETERS:  Walk_state      - State to push
- *              Walk_list       - The list that owns the walk stack
+ * PARAMETERS:  walk_state      - State to push
+ *              walk_list       - The list that owns the walk stack
  *
  * RETURN:      None
  *
- * DESCRIPTION: Place the Walk_state at the head of the state list.
+ * DESCRIPTION: Place the walk_state at the head of the state list.
  *
  ******************************************************************************/
 
 void
 acpi_ds_push_walk_state (
 	acpi_walk_state         *walk_state,
-	ACPI_THREAD_STATE       *thread)
+	acpi_thread_state       *thread)
 {
-	ACPI_FUNCTION_TRACE ("Ds_push_walk_state");
+	ACPI_FUNCTION_TRACE ("ds_push_walk_state");
 
 
 	walk_state->next      = thread->walk_state_list;
@@ -756,11 +755,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_pop_walk_state
+ * FUNCTION:    acpi_ds_pop_walk_state
  *
- * PARAMETERS:  Walk_list       - The list that owns the walk stack
+ * PARAMETERS:  walk_list       - The list that owns the walk stack
  *
- * RETURN:      A Walk_state object popped from the stack
+ * RETURN:      A walk_state object popped from the stack
  *
  * DESCRIPTION: Remove and return the walkstate object that is at the head of
  *              the walk stack for the given walk list.  NULL indicates that
@@ -770,12 +769,12 @@
 
 acpi_walk_state *
 acpi_ds_pop_walk_state (
-	ACPI_THREAD_STATE       *thread)
+	acpi_thread_state       *thread)
 {
 	acpi_walk_state         *walk_state;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_pop_walk_state");
+	ACPI_FUNCTION_TRACE ("ds_pop_walk_state");
 
 
 	walk_state = thread->walk_state_list;
@@ -788,7 +787,7 @@
 		/*
 		 * Don't clear the NEXT field, this serves as an indicator
 		 * that there is a parent WALK STATE
-		 *     NO: Walk_state->Next = NULL;
+		 *     NO: walk_state->Next = NULL;
 		 */
 	}
 
@@ -798,7 +797,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_create_walk_state
+ * FUNCTION:    acpi_ds_create_walk_state
  *
  * PARAMETERS:  Origin          - Starting point for this walk
  *              Thread          - Current thread state
@@ -815,13 +814,13 @@
 	acpi_owner_id           owner_id,
 	acpi_parse_object       *origin,
 	acpi_operand_object     *mth_desc,
-	ACPI_THREAD_STATE       *thread)
+	acpi_thread_state       *thread)
 {
 	acpi_walk_state         *walk_state;
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_create_walk_state");
+	ACPI_FUNCTION_TRACE ("ds_create_walk_state");
 
 
 	walk_state = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_WALK);
@@ -862,9 +861,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_init_aml_walk
+ * FUNCTION:    acpi_ds_init_aml_walk
  *
- * PARAMETERS:  Walk_state      - New state to be initialized
+ * PARAMETERS:  walk_state      - New state to be initialized
  *
  * RETURN:      None
  *
@@ -888,7 +887,7 @@
 	acpi_parse_object       *extra_op;
 
 
-	ACPI_FUNCTION_TRACE ("Ds_init_aml_walk");
+	ACPI_FUNCTION_TRACE ("ds_init_aml_walk");
 
 
 	walk_state->parser_state.aml    =
@@ -896,7 +895,7 @@
 	walk_state->parser_state.aml_end =
 	walk_state->parser_state.pkg_end = aml_start + aml_length;
 
-	/* The Next_op of the Next_walk will be the beginning of the method */
+	/* The next_op of the next_walk will be the beginning of the method */
 
 	walk_state->next_op             = NULL;
 	walk_state->params              = params;
@@ -963,9 +962,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ds_delete_walk_state
+ * FUNCTION:    acpi_ds_delete_walk_state
  *
- * PARAMETERS:  Walk_state      - State to delete
+ * PARAMETERS:  walk_state      - State to delete
  *
  * RETURN:      Status
  *
@@ -980,7 +979,7 @@
 	acpi_generic_state      *state;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ds_delete_walk_state", walk_state);
+	ACPI_FUNCTION_TRACE_PTR ("ds_delete_walk_state", walk_state);
 
 
 	if (!walk_state) {
@@ -1030,7 +1029,7 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_ds_delete_walk_state_cache
+ * FUNCTION:    acpi_ds_delete_walk_state_cache
  *
  * PARAMETERS:  None
  *
@@ -1045,7 +1044,7 @@
 acpi_ds_delete_walk_state_cache (
 	void)
 {
-	ACPI_FUNCTION_TRACE ("Ds_delete_walk_state_cache");
+	ACPI_FUNCTION_TRACE ("ds_delete_walk_state_cache");
 
 
 	acpi_ut_delete_generic_cache (ACPI_MEM_LIST_WALK);
diff -Nru a/drivers/acpi/ec.c b/drivers/acpi/ec.c
--- a/drivers/acpi/ec.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/acpi/ec.c	Mon Dec 23 21:21:55 2002
@@ -422,7 +422,7 @@
 static acpi_status
 acpi_ec_space_handler (
 	u32			function,
-	ACPI_PHYSICAL_ADDRESS	address,
+	acpi_physical_address	address,
 	u32			bit_width,
 	acpi_integer		*value,
 	void			*handler_context,
diff -Nru a/drivers/acpi/events/evevent.c b/drivers/acpi/events/evevent.c
--- a/drivers/acpi/events/evevent.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/acpi/events/evevent.c	Mon Dec 23 21:21:59 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: evevent - Fixed Event handling and dispatch
- *              $Revision: 104 $
  *
  *****************************************************************************/
 
@@ -25,7 +24,6 @@
 
 #include "acpi.h"
 #include "acevents.h"
-#include "acnamesp.h"
 
 #define _COMPONENT          ACPI_EVENTS
 	 ACPI_MODULE_NAME    ("evevent")
@@ -33,7 +31,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_initialize
+ * FUNCTION:    acpi_ev_initialize
  *
  * PARAMETERS:  None
  *
@@ -50,7 +48,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_initialize");
+	ACPI_FUNCTION_TRACE ("ev_initialize");
 
 
 	/* Make sure we have ACPI tables */
@@ -61,7 +59,7 @@
 	}
 
 	/*
-	 * Initialize the Fixed and General Purpose Acpi_events prior. This is
+	 * Initialize the Fixed and General Purpose acpi_events prior. This is
 	 * done prior to enabling SCIs to prevent interrupts from occuring
 	 * before handers are installed.
 	 */
@@ -87,7 +85,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_handler_initialize
+ * FUNCTION:    acpi_ev_handler_initialize
  *
  * PARAMETERS:  None
  *
@@ -104,7 +102,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_handler_initialize");
+	ACPI_FUNCTION_TRACE ("ev_handler_initialize");
 
 
 	/* Install the SCI handler */
@@ -144,7 +142,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_fixed_event_initialize
+ * FUNCTION:    acpi_ev_fixed_event_initialize
  *
  * PARAMETERS:  None
  *
@@ -158,7 +156,7 @@
 acpi_ev_fixed_event_initialize (
 	void)
 {
-	NATIVE_UINT             i;
+	acpi_native_uint        i;
 	acpi_status             status;
 
 
@@ -187,7 +185,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_fixed_event_detect
+ * FUNCTION:    acpi_ev_fixed_event_detect
  *
  * PARAMETERS:  None
  *
@@ -204,10 +202,10 @@
 	u32                     int_status = ACPI_INTERRUPT_NOT_HANDLED;
 	u32                     fixed_status;
 	u32                     fixed_enable;
-	NATIVE_UINT_MAX32       i;
+	acpi_native_uint        i;
 
 
-	ACPI_FUNCTION_NAME ("Ev_fixed_event_detect");
+	ACPI_FUNCTION_NAME ("ev_fixed_event_detect");
 
 
 	/*
@@ -218,7 +216,7 @@
 	(void) acpi_hw_register_read (ACPI_MTX_DO_NOT_LOCK, ACPI_REGISTER_PM1_ENABLE, &fixed_enable);
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
-		"Fixed Acpi_event Block: Enable %08X Status %08X\n",
+		"Fixed acpi_event Block: Enable %08X Status %08X\n",
 		fixed_enable, fixed_status));
 
 	/*
@@ -231,7 +229,7 @@
 			(fixed_enable & acpi_gbl_fixed_event_info[i].enable_bit_mask)) {
 			/* Found an active (signalled) event */
 
-			int_status |= acpi_ev_fixed_event_dispatch (i);
+			int_status |= acpi_ev_fixed_event_dispatch ((u32) i);
 		}
 	}
 
@@ -241,7 +239,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_fixed_event_dispatch
+ * FUNCTION:    acpi_ev_fixed_event_dispatch
  *
  * PARAMETERS:  Event               - Event type
  *
@@ -275,7 +273,7 @@
 				0, ACPI_MTX_DO_NOT_LOCK);
 
 		ACPI_REPORT_ERROR (
-			("Ev_gpe_dispatch: No installed handler for fixed event [%08X]\n",
+			("ev_gpe_dispatch: No installed handler for fixed event [%08X]\n",
 			event));
 
 		return (ACPI_INTERRUPT_NOT_HANDLED);
diff -Nru a/drivers/acpi/events/evgpe.c b/drivers/acpi/events/evgpe.c
--- a/drivers/acpi/events/evgpe.c	Mon Dec 23 21:21:56 2002
+++ b/drivers/acpi/events/evgpe.c	Mon Dec 23 21:21:56 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: evgpe - General Purpose Event handling and dispatch
- *              $Revision: 3 $
  *
  *****************************************************************************/
 
@@ -33,7 +32,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_gpe_initialize
+ * FUNCTION:    acpi_ev_gpe_initialize
  *
  * PARAMETERS:  None
  *
@@ -46,17 +45,17 @@
 acpi_status
 acpi_ev_gpe_initialize (void)
 {
-	NATIVE_UINT_MAX32       i;
-	NATIVE_UINT_MAX32       j;
+	acpi_native_uint        i;
+	acpi_native_uint        j;
 	u32                     gpe_block;
 	u32                     gpe_register;
 	u32                     gpe_number_index;
 	u32                     gpe_number;
-	ACPI_GPE_REGISTER_INFO  *gpe_register_info;
+	acpi_gpe_register_info  *gpe_register_info;
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_gpe_initialize");
+	ACPI_FUNCTION_TRACE ("ev_gpe_initialize");
 
 
 	/*
@@ -77,8 +76,8 @@
 	acpi_gbl_gpe_block_info[0].register_count = 0;
 	acpi_gbl_gpe_block_info[1].register_count = 0;
 
-	acpi_gbl_gpe_block_info[0].block_address = &acpi_gbl_FADT->Xgpe0_blk;
-	acpi_gbl_gpe_block_info[1].block_address = &acpi_gbl_FADT->Xgpe1_blk;
+	acpi_gbl_gpe_block_info[0].block_address = &acpi_gbl_FADT->xgpe0_blk;
+	acpi_gbl_gpe_block_info[1].block_address = &acpi_gbl_FADT->xgpe1_blk;
 
 	acpi_gbl_gpe_block_info[0].block_base_number = 0;
 	acpi_gbl_gpe_block_info[1].block_base_number = acpi_gbl_FADT->gpe1_base;
@@ -92,17 +91,17 @@
 	 * If EITHER the register length OR the block address are zero, then that
 	 * particular block is not supported.
 	 */
-	if (acpi_gbl_FADT->Xgpe0_blk.register_bit_width && acpi_gbl_FADT->Xgpe0_blk.address) {
+	if (acpi_gbl_FADT->xgpe0_blk.register_bit_width && acpi_gbl_FADT->xgpe0_blk.address) {
 		/* GPE block 0 exists (has both length and address > 0) */
 
-		acpi_gbl_gpe_block_info[0].register_count = (u16) (acpi_gbl_FADT->Xgpe0_blk.register_bit_width / (ACPI_GPE_REGISTER_WIDTH * 2));
+		acpi_gbl_gpe_block_info[0].register_count = (u16) (acpi_gbl_FADT->xgpe0_blk.register_bit_width / (ACPI_GPE_REGISTER_WIDTH * 2));
 		acpi_gbl_gpe_number_max               = (acpi_gbl_gpe_block_info[0].register_count * ACPI_GPE_REGISTER_WIDTH) - 1;
 	}
 
-	if (acpi_gbl_FADT->Xgpe1_blk.register_bit_width && acpi_gbl_FADT->Xgpe1_blk.address) {
+	if (acpi_gbl_FADT->xgpe1_blk.register_bit_width && acpi_gbl_FADT->xgpe1_blk.address) {
 		/* GPE block 1 exists (has both length and address > 0) */
 
-		acpi_gbl_gpe_block_info[1].register_count = (u16) (acpi_gbl_FADT->Xgpe1_blk.register_bit_width / (ACPI_GPE_REGISTER_WIDTH * 2));
+		acpi_gbl_gpe_block_info[1].register_count = (u16) (acpi_gbl_FADT->xgpe1_blk.register_bit_width / (ACPI_GPE_REGISTER_WIDTH * 2));
 
 		/* Check for GPE0/GPE1 overlap (if both banks exist) */
 
@@ -149,27 +148,27 @@
 	/* Allocate the GPE number-to-index translation table */
 
 	acpi_gbl_gpe_number_to_index = ACPI_MEM_CALLOCATE (
-			   sizeof (ACPI_GPE_INDEX_INFO) *
-			   ((ACPI_SIZE) acpi_gbl_gpe_number_max + 1));
+			   sizeof (acpi_gpe_index_info) *
+			   ((acpi_size) acpi_gbl_gpe_number_max + 1));
 	if (!acpi_gbl_gpe_number_to_index) {
 		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
-			"Could not allocate the Gpe_number_to_index table\n"));
+			"Could not allocate the gpe_number_to_index table\n"));
 		return_ACPI_STATUS (AE_NO_MEMORY);
 	}
 
 	/* Set the Gpe index table to GPE_INVALID */
 
 	ACPI_MEMSET (acpi_gbl_gpe_number_to_index, (int) ACPI_GPE_INVALID,
-			sizeof (ACPI_GPE_INDEX_INFO) * ((ACPI_SIZE) acpi_gbl_gpe_number_max + 1));
+			sizeof (acpi_gpe_index_info) * ((acpi_size) acpi_gbl_gpe_number_max + 1));
 
 	/* Allocate the GPE register information block */
 
 	acpi_gbl_gpe_register_info = ACPI_MEM_CALLOCATE (
-			  (ACPI_SIZE) acpi_gbl_gpe_register_count *
-			  sizeof (ACPI_GPE_REGISTER_INFO));
+			  (acpi_size) acpi_gbl_gpe_register_count *
+			  sizeof (acpi_gpe_register_info));
 	if (!acpi_gbl_gpe_register_info) {
 		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
-			"Could not allocate the Gpe_register_info table\n"));
+			"Could not allocate the gpe_register_info table\n"));
 		goto error_exit1;
 	}
 
@@ -178,10 +177,10 @@
 	 * per register.  Initialization to zeros is sufficient.
 	 */
 	acpi_gbl_gpe_number_info = ACPI_MEM_CALLOCATE (
-			  (ACPI_SIZE) (acpi_gbl_gpe_register_count * ACPI_GPE_REGISTER_WIDTH) *
-			  sizeof (ACPI_GPE_NUMBER_INFO));
+			  ((acpi_size) acpi_gbl_gpe_register_count * ACPI_GPE_REGISTER_WIDTH) *
+			  sizeof (acpi_gpe_number_info));
 	if (!acpi_gbl_gpe_number_info) {
-		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not allocate the Gpe_number_info table\n"));
+		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not allocate the gpe_number_info table\n"));
 		goto error_exit2;
 	}
 
@@ -223,7 +222,7 @@
 			/* Init the Index mapping info for each GPE number within this register */
 
 			for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
-				gpe_number = gpe_register_info->base_gpe_number + j;
+				gpe_number = gpe_register_info->base_gpe_number + (u32) j;
 				acpi_gbl_gpe_number_to_index[gpe_number].number_index = (u8) gpe_number_index;
 
 				acpi_gbl_gpe_number_info[gpe_number_index].bit_mask = acpi_gbl_decode_to8bit[j];
@@ -280,13 +279,13 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_save_method_info
+ * FUNCTION:    acpi_ev_save_method_info
  *
  * PARAMETERS:  None
  *
  * RETURN:      None
  *
- * DESCRIPTION: Called from Acpi_walk_namespace. Expects each object to be a
+ * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
  *              control method under the _GPE portion of the namespace.
  *              Extract the name and GPE type from the object, saving this
  *              information for quick lookup during GPE dispatch
@@ -314,7 +313,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_NAME ("Ev_save_method_info");
+	ACPI_FUNCTION_NAME ("ev_save_method_info");
 
 
 	/* Extract the name from the object and convert to a string */
@@ -366,7 +365,7 @@
 	}
 
 	/*
-	 * Now we can add this information to the Gpe_info block
+	 * Now we can add this information to the gpe_info block
 	 * for use during dispatch of this GPE.
 	 */
 	acpi_gbl_gpe_number_info [gpe_number_index].type  = type;
@@ -388,7 +387,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_init_gpe_control_methods
+ * FUNCTION:    acpi_ev_init_gpe_control_methods
  *
  * PARAMETERS:  None
  *
@@ -405,7 +404,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_init_gpe_control_methods");
+	ACPI_FUNCTION_TRACE ("ev_init_gpe_control_methods");
 
 
 	/* Get a permanent handle to the _GPE object */
@@ -427,7 +426,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_gpe_detect
+ * FUNCTION:    acpi_ev_gpe_detect
  *
  * PARAMETERS:  None
  *
@@ -446,12 +445,12 @@
 	u32                     j;
 	u8                      enabled_status_byte;
 	u8                      bit_mask;
-	ACPI_GPE_REGISTER_INFO  *gpe_register_info;
+	acpi_gpe_register_info  *gpe_register_info;
 	u32                     in_value;
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_NAME ("Ev_gpe_detect");
+	ACPI_FUNCTION_NAME ("ev_gpe_detect");
 
 
 	/*
@@ -513,14 +512,14 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_asynch_execute_gpe_method
+ * FUNCTION:    acpi_ev_asynch_execute_gpe_method
  *
- * PARAMETERS:  Gpe_number      - The 0-based GPE number
+ * PARAMETERS:  gpe_number      - The 0-based GPE number
  *
  * RETURN:      None
  *
  * DESCRIPTION: Perform the actual execution of a GPE control method.  This
- *              function is called from an invocation of Acpi_os_queue_for_execution
+ *              function is called from an invocation of acpi_os_queue_for_execution
  *              (and therefore does NOT execute at interrupt level) so that
  *              the control method itself is not executed in the context of
  *              the SCI interrupt handler.
@@ -533,11 +532,11 @@
 {
 	u32                     gpe_number = (u32) ACPI_TO_INTEGER (context);
 	u32                     gpe_number_index;
-	ACPI_GPE_NUMBER_INFO    gpe_info;
+	acpi_gpe_number_info    gpe_info;
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_asynch_execute_gpe_method");
+	ACPI_FUNCTION_TRACE ("ev_asynch_execute_gpe_method");
 
 
 	gpe_number_index = acpi_ev_get_gpe_number_index (gpe_number);
@@ -547,7 +546,7 @@
 
 	/*
 	 * Take a snapshot of the GPE info for this level - we copy the
-	 * info to prevent a race condition with Remove_handler.
+	 * info to prevent a race condition with remove_handler.
 	 */
 	status = acpi_ut_acquire_mutex (ACPI_MTX_EVENTS);
 	if (ACPI_FAILURE (status)) {
@@ -594,9 +593,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_gpe_dispatch
+ * FUNCTION:    acpi_ev_gpe_dispatch
  *
- * PARAMETERS:  Gpe_number      - The 0-based GPE number
+ * PARAMETERS:  gpe_number      - The 0-based GPE number
  *
  * RETURN:      INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
  *
@@ -611,11 +610,11 @@
 	u32                     gpe_number)
 {
 	u32                     gpe_number_index;
-	ACPI_GPE_NUMBER_INFO    *gpe_info;
+	acpi_gpe_number_info    *gpe_info;
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_gpe_dispatch");
+	ACPI_FUNCTION_TRACE ("ev_gpe_dispatch");
 
 
 	gpe_number_index = acpi_ev_get_gpe_number_index (gpe_number);
@@ -625,7 +624,7 @@
 	}
 
 	/*
-	 * We don't have to worry about mutex on Gpe_info because we are
+	 * We don't have to worry about mutex on gpe_info because we are
 	 * executing at interrupt level.
 	 */
 	gpe_info = &acpi_gbl_gpe_number_info [gpe_number_index];
@@ -637,7 +636,7 @@
 	if (gpe_info->type & ACPI_EVENT_EDGE_TRIGGERED) {
 		status = acpi_hw_clear_gpe (gpe_number);
 		if (ACPI_FAILURE (status)) {
-			ACPI_REPORT_ERROR (("Acpi_ev_gpe_dispatch: Unable to clear GPE[%2.2X]\n", gpe_number));
+			ACPI_REPORT_ERROR (("acpi_ev_gpe_dispatch: Unable to clear GPE[%2.2X]\n", gpe_number));
 			return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
 		}
 	}
@@ -661,7 +660,7 @@
 		 */
 		status = acpi_hw_disable_gpe (gpe_number);
 		if (ACPI_FAILURE (status)) {
-			ACPI_REPORT_ERROR (("Acpi_ev_gpe_dispatch: Unable to disable GPE[%2.2X]\n", gpe_number));
+			ACPI_REPORT_ERROR (("acpi_ev_gpe_dispatch: Unable to disable GPE[%2.2X]\n", gpe_number));
 			return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
 		}
 
@@ -671,13 +670,13 @@
 		if (ACPI_FAILURE (acpi_os_queue_for_execution (OSD_PRIORITY_GPE,
 				 acpi_ev_asynch_execute_gpe_method,
 				 ACPI_TO_POINTER (gpe_number)))) {
-			ACPI_REPORT_ERROR (("Acpi_ev_gpe_dispatch: Unable to queue handler for GPE[%2.2X], event is disabled\n", gpe_number));
+			ACPI_REPORT_ERROR (("acpi_ev_gpe_dispatch: Unable to queue handler for GPE[%2.2X], event is disabled\n", gpe_number));
 		}
 	}
 	else {
 		/* No handler or method to run! */
 
-		ACPI_REPORT_ERROR (("Acpi_ev_gpe_dispatch: No handler or method for GPE[%2.2X], disabling event\n", gpe_number));
+		ACPI_REPORT_ERROR (("acpi_ev_gpe_dispatch: No handler or method for GPE[%2.2X], disabling event\n", gpe_number));
 
 		/*
 		 * Disable the GPE.  The GPE will remain disabled until the ACPI
@@ -685,7 +684,7 @@
 		 */
 		status = acpi_hw_disable_gpe (gpe_number);
 		if (ACPI_FAILURE (status)) {
-			ACPI_REPORT_ERROR (("Acpi_ev_gpe_dispatch: Unable to disable GPE[%2.2X]\n", gpe_number));
+			ACPI_REPORT_ERROR (("acpi_ev_gpe_dispatch: Unable to disable GPE[%2.2X]\n", gpe_number));
 			return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
 		}
 	}
@@ -696,7 +695,7 @@
 	if (gpe_info->type & ACPI_EVENT_LEVEL_TRIGGERED) {
 		status = acpi_hw_clear_gpe (gpe_number);
 		if (ACPI_FAILURE (status)) {
-			ACPI_REPORT_ERROR (("Acpi_ev_gpe_dispatch: Unable to clear GPE[%2.2X]\n", gpe_number));
+			ACPI_REPORT_ERROR (("acpi_ev_gpe_dispatch: Unable to clear GPE[%2.2X]\n", gpe_number));
 			return_VALUE (ACPI_INTERRUPT_NOT_HANDLED);
 		}
 	}
diff -Nru a/drivers/acpi/events/evmisc.c b/drivers/acpi/events/evmisc.c
--- a/drivers/acpi/events/evmisc.c	Mon Dec 23 21:21:56 2002
+++ b/drivers/acpi/events/evmisc.c	Mon Dec 23 21:21:56 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: evmisc - Miscellaneous event manager support functions
- *              $Revision: 60 $
  *
  *****************************************************************************/
 
@@ -34,7 +33,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_is_notify_object
+ * FUNCTION:    acpi_ev_is_notify_object
  *
  * PARAMETERS:  Node            - Node to check
  *
@@ -68,9 +67,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_get_gpe_register_index
+ * FUNCTION:    acpi_ev_get_gpe_register_index
  *
- * PARAMETERS:  Gpe_number      - Raw GPE number
+ * PARAMETERS:  gpe_number      - Raw GPE number
  *
  * RETURN:      None.
  *
@@ -94,9 +93,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_get_gpe_number_index
+ * FUNCTION:    acpi_ev_get_gpe_number_index
  *
- * PARAMETERS:  Gpe_number      - Raw GPE number
+ * PARAMETERS:  gpe_number      - Raw GPE number
  *
  * RETURN:      None.
  *
@@ -120,7 +119,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_queue_notify_request
+ * FUNCTION:    acpi_ev_queue_notify_request
  *
  * PARAMETERS:
  *
@@ -142,7 +141,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_NAME ("Ev_queue_notify_request");
+	ACPI_FUNCTION_NAME ("ev_queue_notify_request");
 
 
 	/*
@@ -238,7 +237,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_notify_dispatch
+ * FUNCTION:    acpi_ev_notify_dispatch
  *
  * PARAMETERS:
  *
@@ -305,7 +304,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_global_lock_thread
+ * FUNCTION:    acpi_ev_global_lock_thread
  *
  * RETURN:      None
  *
@@ -338,7 +337,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_global_lock_handler
+ * FUNCTION:    acpi_ev_global_lock_handler
  *
  * RETURN:      Status
  *
@@ -385,7 +384,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_init_global_lock_handler
+ * FUNCTION:    acpi_ev_init_global_lock_handler
  *
  * RETURN:      Status
  *
@@ -399,7 +398,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_init_global_lock_handler");
+	ACPI_FUNCTION_TRACE ("ev_init_global_lock_handler");
 
 
 	acpi_gbl_global_lock_present = TRUE;
@@ -424,7 +423,7 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_ev_acquire_global_lock
+ * FUNCTION:    acpi_ev_acquire_global_lock
  *
  * RETURN:      Status
  *
@@ -440,7 +439,7 @@
 	u8                      acquired = FALSE;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_acquire_global_lock");
+	ACPI_FUNCTION_TRACE ("ev_acquire_global_lock");
 
 
 #ifndef ACPI_APPLICATION
@@ -491,7 +490,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_release_global_lock
+ * FUNCTION:    acpi_ev_release_global_lock
  *
  * DESCRIPTION: Releases ownership of the Global Lock.
  *
@@ -504,7 +503,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_release_global_lock");
+	ACPI_FUNCTION_TRACE ("ev_release_global_lock");
 
 
 	if (!acpi_gbl_global_lock_thread_count) {
@@ -542,7 +541,7 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_ev_terminate
+ * FUNCTION:    acpi_ev_terminate
  *
  * PARAMETERS:  none
  *
@@ -555,11 +554,11 @@
 void
 acpi_ev_terminate (void)
 {
-	NATIVE_UINT_MAX32       i;
+	acpi_native_uint        i;
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_terminate");
+	ACPI_FUNCTION_TRACE ("ev_terminate");
 
 
 	if (acpi_gbl_events_initialized) {
@@ -572,9 +571,9 @@
 		 * Disable all fixed events
 		 */
 		for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
-			status = acpi_disable_event(i, ACPI_EVENT_FIXED, 0);
+			status = acpi_disable_event ((u32) i, ACPI_EVENT_FIXED, 0);
 			if (ACPI_FAILURE (status)) {
-				ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not disable fixed event %d\n", i));
+				ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not disable fixed event %d\n", (u32) i));
 			}
 		}
 
@@ -582,10 +581,10 @@
 		 * Disable all GPEs
 		 */
 		for (i = 0; i < acpi_gbl_gpe_number_max; i++) {
-			if (acpi_ev_get_gpe_number_index(i) != ACPI_GPE_INVALID) {
-				status = acpi_hw_disable_gpe(i);
+			if (acpi_ev_get_gpe_number_index ((u32)i) != ACPI_GPE_INVALID) {
+				status = acpi_hw_disable_gpe((u32) i);
 				if (ACPI_FAILURE (status)) {
-					ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not disable GPE %d\n", i));
+					ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not disable GPE %d\n", (u32) i));
 				}
 			}
 		}
@@ -593,7 +592,7 @@
 		/*
 		 * Remove SCI handler
 		 */
-		status = acpi_ev_remove_sci_handler();
+		status = acpi_ev_remove_sci_handler ();
 		if (ACPI_FAILURE(status)) {
 			ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not remove SCI handler\n"));
 		}
@@ -605,7 +604,7 @@
 	if (acpi_gbl_original_mode == ACPI_SYS_MODE_LEGACY) {
 		status = acpi_disable ();
 		if (ACPI_FAILURE (status)) {
-			ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Acpi_disable failed\n"));
+			ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "acpi_disable failed\n"));
 		}
 	}
 
diff -Nru a/drivers/acpi/events/evregion.c b/drivers/acpi/events/evregion.c
--- a/drivers/acpi/events/evregion.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/events/evregion.c	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
- * Module Name: evregion - ACPI Address_space (Op_region) handler dispatch
- *              $Revision: 136 $
+ * Module Name: evregion - ACPI address_space (op_region) handler dispatch
  *
  *****************************************************************************/
 
@@ -35,7 +34,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_init_address_spaces
+ * FUNCTION:    acpi_ev_init_address_spaces
  *
  * PARAMETERS:
  *
@@ -52,7 +51,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_init_address_spaces");
+	ACPI_FUNCTION_TRACE ("ev_init_address_spaces");
 
 
 	/*
@@ -68,7 +67,7 @@
 	 * near ready to find the PCI root buses at this point.
 	 *
 	 * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
-	 * has already been installed (via Acpi_install_address_space_handler)
+	 * has already been installed (via acpi_install_address_space_handler)
 	 */
 
 	status = acpi_install_address_space_handler ((acpi_handle) acpi_gbl_root_node,
@@ -109,9 +108,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_execute_reg_method
+ * FUNCTION:    acpi_ev_execute_reg_method
  *
- * PARAMETERS:  Region_obj          - Object structure
+ * PARAMETERS:  region_obj          - Object structure
  *              Function            - On (1) or Off (0)
  *
  * RETURN:      Status
@@ -130,7 +129,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_execute_reg_method");
+	ACPI_FUNCTION_TRACE ("ev_execute_reg_method");
 
 
 	region_obj2 = acpi_ns_get_secondary_object (region_obj);
@@ -145,7 +144,7 @@
 	/*
 	 *  _REG method has two arguments
 	 *  Arg0:   Integer: Operation region space ID
-	 *          Same value as Region_obj->Region.Space_id
+	 *          Same value as region_obj->Region.space_id
 	 *  Arg1:   Integer: connection status
 	 *          1 for connecting the handler,
 	 *          0 for disconnecting the handler
@@ -186,13 +185,13 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_address_space_dispatch
+ * FUNCTION:    acpi_ev_address_space_dispatch
  *
- * PARAMETERS:  Region_obj          - internal region object
- *              Space_id            - ID of the address space (0-255)
+ * PARAMETERS:  region_obj          - internal region object
+ *              space_id            - ID of the address space (0-255)
  *              Function            - Read or Write operation
  *              Address             - Where in the space to read or write
- *              Bit_width           - Field width in bits (8, 16, 32, or 64)
+ *              bit_width           - Field width in bits (8, 16, 32, or 64)
  *              Value               - Pointer to in or out value
  *
  * RETURN:      Status
@@ -206,7 +205,7 @@
 acpi_ev_address_space_dispatch (
 	acpi_operand_object     *region_obj,
 	u32                     function,
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	u32                     bit_width,
 	void                    *value)
 {
@@ -219,7 +218,7 @@
 	void                    *region_context = NULL;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_address_space_dispatch");
+	ACPI_FUNCTION_TRACE ("ev_address_space_dispatch");
 
 
 	region_obj2 = acpi_ns_get_secondary_object (region_obj);
@@ -339,10 +338,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_detach_region
+ * FUNCTION:    acpi_ev_detach_region
  *
- * PARAMETERS:  Region_obj      - Region Object
- *              Acpi_ns_is_locked - Namespace Region Already Locked?
+ * PARAMETERS:  region_obj      - Region Object
+ *              acpi_ns_is_locked - Namespace Region Already Locked?
  *
  * RETURN:      None
  *
@@ -365,7 +364,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_detach_region");
+	ACPI_FUNCTION_TRACE ("ev_detach_region");
 
 
 	region_obj2 = acpi_ns_get_secondary_object (region_obj);
@@ -484,11 +483,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_attach_region
+ * FUNCTION:    acpi_ev_attach_region
  *
- * PARAMETERS:  Handler_obj     - Handler Object
- *              Region_obj      - Region Object
- *              Acpi_ns_is_locked - Namespace Region Already Locked?
+ * PARAMETERS:  handler_obj     - Handler Object
+ *              region_obj      - Region Object
+ *              acpi_ns_is_locked - Namespace Region Already Locked?
  *
  * RETURN:      None
  *
@@ -507,7 +506,7 @@
 	acpi_status             status2;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_attach_region");
+	ACPI_FUNCTION_TRACE ("ev_attach_region");
 
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
@@ -552,11 +551,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_addr_handler_helper
+ * FUNCTION:    acpi_ev_addr_handler_helper
  *
  * PARAMETERS:  Handle              - Node to be dumped
  *              Level               - Nesting level of the handle
- *              Context             - Passed into Acpi_ns_walk_namespace
+ *              Context             - Passed into acpi_ns_walk_namespace
  *
  * DESCRIPTION: This routine installs an address handler into objects that are
  *              of type Region.
@@ -583,7 +582,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_NAME ("Ev_addr_handler_helper");
+	ACPI_FUNCTION_NAME ("ev_addr_handler_helper");
 
 
 	handler_obj = (acpi_operand_object *) context;
diff -Nru a/drivers/acpi/events/evrgnini.c b/drivers/acpi/events/evrgnini.c
--- a/drivers/acpi/events/evrgnini.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/events/evrgnini.c	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
- * Module Name: evrgnini- ACPI Address_space (Op_region) init
- *              $Revision: 64 $
+ * Module Name: evrgnini- ACPI address_space (op_region) init
  *
  *****************************************************************************/
 
@@ -34,12 +33,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_system_memory_region_setup
+ * FUNCTION:    acpi_ev_system_memory_region_setup
  *
- * PARAMETERS:  Region_obj          - Region we are interested in
+ * PARAMETERS:  region_obj          - Region we are interested in
  *              Function            - Start or stop
- *              Handler_context     - Address space handler context
- *              Region_context      - Region specific context
+ *              handler_context     - Address space handler context
+ *              region_context      - Region specific context
  *
  * RETURN:      Status
  *
@@ -58,7 +57,7 @@
 	acpi_mem_space_context  *local_region_context;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_system_memory_region_setup");
+	ACPI_FUNCTION_TRACE ("ev_system_memory_region_setup");
 
 
 	if (function == ACPI_REGION_DEACTIVATE) {
@@ -88,12 +87,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_io_space_region_setup
+ * FUNCTION:    acpi_ev_io_space_region_setup
  *
- * PARAMETERS:  Region_obj          - Region we are interested in
+ * PARAMETERS:  region_obj          - Region we are interested in
  *              Function            - Start or stop
- *              Handler_context     - Address space handler context
- *              Region_context      - Region specific context
+ *              handler_context     - Address space handler context
+ *              region_context      - Region specific context
  *
  * RETURN:      Status
  *
@@ -108,7 +107,7 @@
 	void                    *handler_context,
 	void                    **region_context)
 {
-	ACPI_FUNCTION_TRACE ("Ev_io_space_region_setup");
+	ACPI_FUNCTION_TRACE ("ev_io_space_region_setup");
 
 
 	if (function == ACPI_REGION_DEACTIVATE) {
@@ -124,12 +123,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_pci_config_region_setup
+ * FUNCTION:    acpi_ev_pci_config_region_setup
  *
- * PARAMETERS:  Region_obj          - Region we are interested in
+ * PARAMETERS:  region_obj          - Region we are interested in
  *              Function            - Start or stop
- *              Handler_context     - Address space handler context
- *              Region_context      - Region specific context
+ *              handler_context     - Address space handler context
+ *              region_context      - Region specific context
  *
  * RETURN:      Status
  *
@@ -155,7 +154,7 @@
 	acpi_device_id          object_hID;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_pci_config_region_setup");
+	ACPI_FUNCTION_TRACE ("ev_pci_config_region_setup");
 
 
 	handler_obj = region_obj->region.addr_handler;
@@ -218,8 +217,8 @@
 	 */
 
 	/*
-	 * If the Addr_handler.Node is still pointing to the root, we need
-	 * to scan upward for a PCI Root bridge and re-associate the Op_region
+	 * If the addr_handler.Node is still pointing to the root, we need
+	 * to scan upward for a PCI Root bridge and re-associate the op_region
 	 * handlers with that device.
 	 */
 	if (handler_obj->addr_handler.node == acpi_gbl_root_node) {
@@ -239,7 +238,7 @@
 							   ACPI_ADR_SPACE_PCI_CONFIG,
 							   ACPI_DEFAULT_HANDLER, NULL, NULL);
 					if (ACPI_FAILURE (status)) {
-						ACPI_REPORT_ERROR (("Could not install Pci_config handler for %4.4s, %s\n",
+						ACPI_REPORT_ERROR (("Could not install pci_config handler for %4.4s, %s\n",
 							node->name.ascii, acpi_format_exception (status)));
 					}
 					break;
@@ -270,7 +269,7 @@
 	}
 
 	/*
-	 * Complete this device's Pci_id
+	 * Complete this device's pci_id
 	 */
 	acpi_os_derive_pci_id (node, region_obj->region.node, &pci_id);
 
@@ -281,12 +280,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_pci_bar_region_setup
+ * FUNCTION:    acpi_ev_pci_bar_region_setup
  *
- * PARAMETERS:  Region_obj          - Region we are interested in
+ * PARAMETERS:  region_obj          - Region we are interested in
  *              Function            - Start or stop
- *              Handler_context     - Address space handler context
- *              Region_context      - Region specific context
+ *              handler_context     - Address space handler context
+ *              region_context      - Region specific context
  *
  * RETURN:      Status
  *
@@ -303,7 +302,7 @@
 	void                    *handler_context,
 	void                    **region_context)
 {
-	ACPI_FUNCTION_TRACE ("Ev_pci_bar_region_setup");
+	ACPI_FUNCTION_TRACE ("ev_pci_bar_region_setup");
 
 
 	return_ACPI_STATUS (AE_OK);
@@ -312,12 +311,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_cmos_region_setup
+ * FUNCTION:    acpi_ev_cmos_region_setup
  *
- * PARAMETERS:  Region_obj          - Region we are interested in
+ * PARAMETERS:  region_obj          - Region we are interested in
  *              Function            - Start or stop
- *              Handler_context     - Address space handler context
- *              Region_context      - Region specific context
+ *              handler_context     - Address space handler context
+ *              region_context      - Region specific context
  *
  * RETURN:      Status
  *
@@ -334,7 +333,7 @@
 	void                    *handler_context,
 	void                    **region_context)
 {
-	ACPI_FUNCTION_TRACE ("Ev_cmos_region_setup");
+	ACPI_FUNCTION_TRACE ("ev_cmos_region_setup");
 
 
 	return_ACPI_STATUS (AE_OK);
@@ -343,12 +342,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_default_region_setup
+ * FUNCTION:    acpi_ev_default_region_setup
  *
- * PARAMETERS:  Region_obj          - Region we are interested in
+ * PARAMETERS:  region_obj          - Region we are interested in
  *              Function            - Start or stop
- *              Handler_context     - Address space handler context
- *              Region_context      - Region specific context
+ *              handler_context     - Address space handler context
+ *              region_context      - Region specific context
  *
  * RETURN:      Status
  *
@@ -363,7 +362,7 @@
 	void                    *handler_context,
 	void                    **region_context)
 {
-	ACPI_FUNCTION_TRACE ("Ev_default_region_setup");
+	ACPI_FUNCTION_TRACE ("ev_default_region_setup");
 
 
 	if (function == ACPI_REGION_DEACTIVATE) {
@@ -379,10 +378,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_initialize_region
+ * FUNCTION:    acpi_ev_initialize_region
  *
- * PARAMETERS:  Region_obj      - Region we are initializing
- *              Acpi_ns_locked  - Is namespace locked?
+ * PARAMETERS:  region_obj      - Region we are initializing
+ *              acpi_ns_locked  - Is namespace locked?
  *
  * RETURN:      Status
  *
@@ -406,7 +405,7 @@
 {
 	acpi_operand_object     *handler_obj;
 	acpi_operand_object     *obj_desc;
-	ACPI_ADR_SPACE_TYPE     space_id;
+	acpi_adr_space_type     space_id;
 	acpi_namespace_node     *node;
 	acpi_status             status;
 	acpi_namespace_node     *method_node;
@@ -414,7 +413,7 @@
 	acpi_operand_object     *region_obj2;
 
 
-	ACPI_FUNCTION_TRACE_U32 ("Ev_initialize_region", acpi_ns_locked);
+	ACPI_FUNCTION_TRACE_U32 ("ev_initialize_region", acpi_ns_locked);
 
 
 	if (!region_obj) {
@@ -454,7 +453,7 @@
 
 	/*
 	 * The following loop depends upon the root Node having no parent
-	 * ie: Acpi_gbl_Root_node->Parent_entry being set to NULL
+	 * ie: acpi_gbl_root_node->parent_entry being set to NULL
 	 */
 	while (node) {
 		/*
@@ -520,7 +519,7 @@
 	 * If we get here, there is no handler for this region
 	 */
 	ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
-		"No handler for Region_type %s(%X) (Region_obj %p)\n",
+		"No handler for region_type %s(%X) (region_obj %p)\n",
 		acpi_ut_get_region_name (space_id), space_id, region_obj));
 
 	return_ACPI_STATUS (AE_NOT_EXIST);
diff -Nru a/drivers/acpi/events/evsci.c b/drivers/acpi/events/evsci.c
--- a/drivers/acpi/events/evsci.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/acpi/events/evsci.c	Mon Dec 23 21:21:58 2002
@@ -2,7 +2,6 @@
  *
  * Module Name: evsci - System Control Interrupt configuration and
  *                      legacy to ACPI mode state transition functions
- *              $Revision: 86 $
  *
  ******************************************************************************/
 
@@ -34,7 +33,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ev_sci_handler
+ * FUNCTION:    acpi_ev_sci_handler
  *
  * PARAMETERS:  Context   - Calling Context
  *
@@ -55,7 +54,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE("Ev_sci_handler");
+	ACPI_FUNCTION_TRACE("ev_sci_handler");
 
 
 	/*
@@ -74,9 +73,9 @@
 	}
 
 	/*
-	 * Fixed Acpi_events:
+	 * Fixed acpi_events:
 	 * -------------
-	 * Check for and dispatch any Fixed Acpi_events that have occurred
+	 * Check for and dispatch any Fixed acpi_events that have occurred
 	 */
 	interrupt_handled |= acpi_ev_fixed_event_detect ();
 
@@ -93,7 +92,7 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_ev_install_sci_handler
+ * FUNCTION:    acpi_ev_install_sci_handler
  *
  * PARAMETERS:  none
  *
@@ -109,7 +108,7 @@
 	u32                     status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_install_sci_handler");
+	ACPI_FUNCTION_TRACE ("ev_install_sci_handler");
 
 
 	status = acpi_os_install_interrupt_handler ((u32) acpi_gbl_FADT->sci_int,
@@ -120,7 +119,7 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_ev_remove_sci_handler
+ * FUNCTION:    acpi_ev_remove_sci_handler
  *
  * PARAMETERS:  none
  *
@@ -143,7 +142,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ev_remove_sci_handler");
+	ACPI_FUNCTION_TRACE ("ev_remove_sci_handler");
 
 
 	/* Just let the OS remove the handler and disable the level */
diff -Nru a/drivers/acpi/events/evxface.c b/drivers/acpi/events/evxface.c
--- a/drivers/acpi/events/evxface.c	Mon Dec 23 21:21:56 2002
+++ b/drivers/acpi/events/evxface.c	Mon Dec 23 21:21:56 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: evxface - External interfaces for ACPI events
- *              $Revision: 132 $
  *
  *****************************************************************************/
 
@@ -35,7 +34,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_install_fixed_event_handler
+ * FUNCTION:    acpi_install_fixed_event_handler
  *
  * PARAMETERS:  Event           - Event type to enable.
  *              Handler         - Pointer to the handler function for the
@@ -58,7 +57,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_install_fixed_event_handler");
+	ACPI_FUNCTION_TRACE ("acpi_install_fixed_event_handler");
 
 
 	/* Parameter validation */
@@ -107,7 +106,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_remove_fixed_event_handler
+ * FUNCTION:    acpi_remove_fixed_event_handler
  *
  * PARAMETERS:  Event           - Event type to disable.
  *              Handler         - Address of the handler
@@ -126,7 +125,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_remove_fixed_event_handler");
+	ACPI_FUNCTION_TRACE ("acpi_remove_fixed_event_handler");
 
 
 	/* Parameter validation */
@@ -164,12 +163,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_install_notify_handler
+ * FUNCTION:    acpi_install_notify_handler
  *
  * PARAMETERS:  Device          - The device for which notifies will be handled
- *              Handler_type    - The type of handler:
- *                                  ACPI_SYSTEM_NOTIFY: System_handler (00-7f)
- *                                  ACPI_DEVICE_NOTIFY: Driver_handler (80-ff)
+ *              handler_type    - The type of handler:
+ *                                  ACPI_SYSTEM_NOTIFY: system_handler (00-7f)
+ *                                  ACPI_DEVICE_NOTIFY: driver_handler (80-ff)
  *              Handler         - Address of the handler
  *              Context         - Value passed to the handler on each GPE
  *
@@ -192,7 +191,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_install_notify_handler");
+	ACPI_FUNCTION_TRACE ("acpi_install_notify_handler");
 
 
 	/* Parameter validation */
@@ -321,12 +320,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_remove_notify_handler
+ * FUNCTION:    acpi_remove_notify_handler
  *
  * PARAMETERS:  Device          - The device for which notifies will be handled
- *              Handler_type    - The type of handler:
- *                                  ACPI_SYSTEM_NOTIFY: System_handler (00-7f)
- *                                  ACPI_DEVICE_NOTIFY: Driver_handler (80-ff)
+ *              handler_type    - The type of handler:
+ *                                  ACPI_SYSTEM_NOTIFY: system_handler (00-7f)
+ *                                  ACPI_DEVICE_NOTIFY: driver_handler (80-ff)
  *              Handler         - Address of the handler
  * RETURN:      Status
  *
@@ -346,7 +345,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_remove_notify_handler");
+	ACPI_FUNCTION_TRACE ("acpi_remove_notify_handler");
 
 
 	/* Parameter validation */
@@ -451,9 +450,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_install_gpe_handler
+ * FUNCTION:    acpi_install_gpe_handler
  *
- * PARAMETERS:  Gpe_number      - The GPE number.  The numbering scheme is
+ * PARAMETERS:  gpe_number      - The GPE number.  The numbering scheme is
  *                                bank 0 first, then bank 1.
  *              Type            - Whether this GPE should be treated as an
  *                                edge- or level-triggered interrupt.
@@ -477,7 +476,7 @@
 	u32                     gpe_number_index;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_install_gpe_handler");
+	ACPI_FUNCTION_TRACE ("acpi_install_gpe_handler");
 
 
 	/* Parameter validation */
@@ -529,14 +528,14 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_remove_gpe_handler
+ * FUNCTION:    acpi_remove_gpe_handler
  *
- * PARAMETERS:  Gpe_number      - The event to remove a handler
+ * PARAMETERS:  gpe_number      - The event to remove a handler
  *              Handler         - Address of the handler
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Remove a handler for a General Purpose Acpi_event.
+ * DESCRIPTION: Remove a handler for a General Purpose acpi_event.
  *
  ******************************************************************************/
 
@@ -549,7 +548,7 @@
 	u32                     gpe_number_index;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_remove_gpe_handler");
+	ACPI_FUNCTION_TRACE ("acpi_remove_gpe_handler");
 
 
 	/* Parameter validation */
@@ -599,10 +598,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_acquire_global_lock
+ * FUNCTION:    acpi_acquire_global_lock
  *
  * PARAMETERS:  Timeout         - How long the caller is willing to wait
- *              Out_handle      - A handle to the lock if acquired
+ *              out_handle      - A handle to the lock if acquired
  *
  * RETURN:      Status
  *
@@ -641,9 +640,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_release_global_lock
+ * FUNCTION:    acpi_release_global_lock
  *
- * PARAMETERS:  Handle      - Returned from Acpi_acquire_global_lock
+ * PARAMETERS:  Handle      - Returned from acpi_acquire_global_lock
  *
  * RETURN:      Status
  *
diff -Nru a/drivers/acpi/events/evxfevnt.c b/drivers/acpi/events/evxfevnt.c
--- a/drivers/acpi/events/evxfevnt.c	Mon Dec 23 21:21:52 2002
+++ b/drivers/acpi/events/evxfevnt.c	Mon Dec 23 21:21:52 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
- *              $Revision: 59 $
  *
  *****************************************************************************/
 
@@ -33,7 +32,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_enable
+ * FUNCTION:    acpi_enable
  *
  * PARAMETERS:  None
  *
@@ -49,7 +48,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_enable");
+	ACPI_FUNCTION_TRACE ("acpi_enable");
 
 
 	/* Make sure we have the FADT*/
@@ -80,7 +79,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_disable
+ * FUNCTION:    acpi_disable
  *
  * PARAMETERS:  None
  *
@@ -96,7 +95,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_disable");
+	ACPI_FUNCTION_TRACE ("acpi_disable");
 
 	if (!acpi_gbl_FADT) {
 		ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No FADT information present!\n"));
@@ -125,7 +124,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_enable_event
+ * FUNCTION:    acpi_enable_event
  *
  * PARAMETERS:  Event           - The fixed event or GPE to be enabled
  *              Type            - The type of event
@@ -147,7 +146,7 @@
 	u32                     value;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_enable_event");
+	ACPI_FUNCTION_TRACE ("acpi_enable_event");
 
 
 	/* The Type must be either Fixed Event or GPE */
@@ -219,7 +218,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_disable_event
+ * FUNCTION:    acpi_disable_event
  *
  * PARAMETERS:  Event           - The fixed event or GPE to be enabled
  *              Type            - The type of event, fixed or general purpose
@@ -241,7 +240,7 @@
 	u32                     value;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_disable_event");
+	ACPI_FUNCTION_TRACE ("acpi_disable_event");
 
 
 	/* The Type must be either Fixed Event or GPE */
@@ -311,7 +310,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_clear_event
+ * FUNCTION:    acpi_clear_event
  *
  * PARAMETERS:  Event           - The fixed event or GPE to be cleared
  *              Type            - The type of event
@@ -330,7 +329,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_clear_event");
+	ACPI_FUNCTION_TRACE ("acpi_clear_event");
 
 
 	/* The Type must be either Fixed Event or GPE */
@@ -376,7 +375,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_get_event_status
+ * FUNCTION:    acpi_get_event_status
  *
  * PARAMETERS:  Event           - The fixed event or GPE
  *              Type            - The type of event
@@ -399,7 +398,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_get_event_status");
+	ACPI_FUNCTION_TRACE ("acpi_get_event_status");
 
 
 	if (!event_status) {
diff -Nru a/drivers/acpi/events/evxfregn.c b/drivers/acpi/events/evxfregn.c
--- a/drivers/acpi/events/evxfregn.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/events/evxfregn.c	Mon Dec 23 21:21:51 2002
@@ -2,7 +2,6 @@
  *
  * Module Name: evxfregn - External Interfaces, ACPI Operation Regions and
  *                         Address Spaces.
- *              $Revision: 52 $
  *
  *****************************************************************************/
 
@@ -36,24 +35,24 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_install_address_space_handler
+ * FUNCTION:    acpi_install_address_space_handler
  *
  * PARAMETERS:  Device          - Handle for the device
- *              Space_id        - The address space ID
+ *              space_id        - The address space ID
  *              Handler         - Address of the handler
  *              Setup           - Address of the setup function
  *              Context         - Value passed to the handler on each access
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Install a handler for all Op_regions of a given Space_id.
+ * DESCRIPTION: Install a handler for all op_regions of a given space_id.
  *
  ******************************************************************************/
 
 acpi_status
 acpi_install_address_space_handler (
 	acpi_handle             device,
-	ACPI_ADR_SPACE_TYPE     space_id,
+	acpi_adr_space_type     space_id,
 	acpi_adr_space_handler  handler,
 	acpi_adr_space_setup    setup,
 	void                    *context)
@@ -66,7 +65,7 @@
 	u16                     flags = 0;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_install_address_space_handler");
+	ACPI_FUNCTION_TRACE ("acpi_install_address_space_handler");
 
 
 	/* Parameter validation */
@@ -181,7 +180,7 @@
 		ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
 			"Creating object on Device %p while installing handler\n", node));
 
-		/* Obj_desc does not exist, create one */
+		/* obj_desc does not exist, create one */
 
 		if (node->type == ACPI_TYPE_ANY) {
 			type = ACPI_TYPE_DEVICE;
@@ -269,9 +268,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_remove_address_space_handler
+ * FUNCTION:    acpi_remove_address_space_handler
  *
- * PARAMETERS:  Space_id        - The address space ID
+ * PARAMETERS:  space_id        - The address space ID
  *              Handler         - Address of the handler
  *
  * RETURN:      Status
@@ -283,7 +282,7 @@
 acpi_status
 acpi_remove_address_space_handler (
 	acpi_handle             device,
-	ACPI_ADR_SPACE_TYPE     space_id,
+	acpi_adr_space_type     space_id,
 	acpi_adr_space_handler  handler)
 {
 	acpi_operand_object     *obj_desc;
@@ -294,7 +293,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_remove_address_space_handler");
+	ACPI_FUNCTION_TRACE ("acpi_remove_address_space_handler");
 
 
 	/* Parameter validation */
@@ -391,7 +390,7 @@
 	 * The handler does not exist
 	 */
 	ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
-		"Unable to remove address handler %p for %s(%X), Dev_node %p, obj %p\n",
+		"Unable to remove address handler %p for %s(%X), dev_node %p, obj %p\n",
 		handler, acpi_ut_get_region_name (space_id), space_id, node, obj_desc));
 
 	status = AE_NOT_EXIST;
diff -Nru a/drivers/acpi/executer/exconfig.c b/drivers/acpi/executer/exconfig.c
--- a/drivers/acpi/executer/exconfig.c	Mon Dec 23 21:21:56 2002
+++ b/drivers/acpi/executer/exconfig.c	Mon Dec 23 21:21:56 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
- *              $Revision: 69 $
  *
  *****************************************************************************/
 
@@ -38,11 +37,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_add_table
+ * FUNCTION:    acpi_ex_add_table
  *
  * PARAMETERS:  Table               - Pointer to raw table
- *              Parent_node         - Where to load the table (scope)
- *              Ddb_handle          - Where to return the table handle.
+ *              parent_node         - Where to load the table (scope)
+ *              ddb_handle          - Where to return the table handle.
  *
  * RETURN:      Status
  *
@@ -62,7 +61,7 @@
 	acpi_operand_object     *obj_desc;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_add_table");
+	ACPI_FUNCTION_TRACE ("ex_add_table");
 
 
 	/* Create an object to be the table handle */
@@ -75,7 +74,7 @@
 	/* Install the new table into the local data structures */
 
 	table_info.pointer     = table;
-	table_info.length      = (ACPI_SIZE) table->length;
+	table_info.length      = (acpi_size) table->length;
 	table_info.allocation  = ACPI_MEM_ALLOCATED;
 
 	status = acpi_tb_install_table (&table_info);
@@ -109,10 +108,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_load_table_op
+ * FUNCTION:    acpi_ex_load_table_op
  *
- * PARAMETERS:  Walk_state          - Current state with operands
- *              Return_desc         - Where to store the return object
+ * PARAMETERS:  walk_state          - Current state with operands
+ *              return_desc         - Where to store the return object
  *
  * RETURN:      Status
  *
@@ -134,7 +133,7 @@
 	acpi_operand_object     *ddb_handle;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_load_table_op");
+	ACPI_FUNCTION_TRACE ("ex_load_table_op");
 
 
 #if 0
@@ -178,11 +177,11 @@
 	start_node = walk_state->scope_info->scope.node;
 	parent_node = acpi_gbl_root_node;
 
-	/* Root_path (optional parameter) */
+	/* root_path (optional parameter) */
 
 	if (operand[3]->string.length > 0) {
 		/*
-		 * Find the node referenced by the Root_path_string. This is the
+		 * Find the node referenced by the root_path_string. This is the
 		 * location within the namespace where the table will be loaded.
 		 */
 		status = acpi_ns_get_node_by_path (operand[3]->string.pointer, start_node,
@@ -192,20 +191,20 @@
 		}
 	}
 
-	/* Parameter_path (optional parameter) */
+	/* parameter_path (optional parameter) */
 
 	if (operand[4]->string.length > 0) {
 		if ((operand[4]->string.pointer[0] != '\\') &&
 			(operand[4]->string.pointer[0] != '^')) {
 			/*
 			 * Path is not absolute, so it will be relative to the node
-			 * referenced by the Root_path_string (or the NS root if omitted)
+			 * referenced by the root_path_string (or the NS root if omitted)
 			 */
 			start_node = parent_node;
 		}
 
 		/*
-		 * Find the node referenced by the Parameter_path_string
+		 * Find the node referenced by the parameter_path_string
 		 */
 		status = acpi_ns_get_node_by_path (operand[4]->string.pointer, start_node,
 				   ACPI_NS_SEARCH_PARENT, &parameter_node);
@@ -239,12 +238,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_load_op
+ * FUNCTION:    acpi_ex_load_op
  *
- * PARAMETERS:  Obj_desc        - Region or Field where the table will be
+ * PARAMETERS:  obj_desc        - Region or Field where the table will be
  *                                obtained
  *              Target          - Where a handle to the table will be stored
- *              Walk_state      - Current state
+ *              walk_state      - Current state
  *
  * RETURN:      Status
  *
@@ -266,10 +265,10 @@
 	acpi_table_header       table_header;
 	u32                     i;
 
-	ACPI_FUNCTION_TRACE ("Ex_load_op");
+	ACPI_FUNCTION_TRACE ("ex_load_op");
 
 
-	/* Object can be either an Op_region or a Field */
+	/* Object can be either an op_region or a Field */
 
 	switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
 	case ACPI_TYPE_REGION:
@@ -282,7 +281,7 @@
 		table_header.length = 0;
 		for (i = 0; i < sizeof (acpi_table_header); i++) {
 			status = acpi_ev_address_space_dispatch (obj_desc, ACPI_READ,
-					   (ACPI_PHYSICAL_ADDRESS) i, 8,
+					   (acpi_physical_address) i, 8,
 					   ((u8 *) &table_header) + i);
 			if (ACPI_FAILURE (status)) {
 				return_ACPI_STATUS (status);
@@ -305,7 +304,7 @@
 
 		for (i = 0; i < table_header.length; i++) {
 			status = acpi_ev_address_space_dispatch (obj_desc, ACPI_READ,
-					   (ACPI_PHYSICAL_ADDRESS) i, 8,
+					   (acpi_physical_address) i, 8,
 					   ((u8 *) table_data_ptr + i));
 			if (ACPI_FAILURE (status)) {
 				goto cleanup;
@@ -362,7 +361,7 @@
 		goto cleanup;
 	}
 
-	/* Store the Ddb_handle into the Target operand */
+	/* Store the ddb_handle into the Target operand */
 
 	status = acpi_ex_store (ddb_handle, target, walk_state);
 	if (ACPI_FAILURE (status)) {
@@ -386,9 +385,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_unload_table
+ * FUNCTION:    acpi_ex_unload_table
  *
- * PARAMETERS:  Ddb_handle          - Handle to a previously loaded table
+ * PARAMETERS:  ddb_handle          - Handle to a previously loaded table
  *
  * RETURN:      Status
  *
@@ -405,13 +404,13 @@
 	acpi_table_desc         *table_info;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_unload_table");
+	ACPI_FUNCTION_TRACE ("ex_unload_table");
 
 
 	/*
 	 * Validate the handle
-	 * Although the handle is partially validated in Acpi_ex_reconfiguration(),
-	 * when it calls Acpi_ex_resolve_operands(), the handle is more completely
+	 * Although the handle is partially validated in acpi_ex_reconfiguration(),
+	 * when it calls acpi_ex_resolve_operands(), the handle is more completely
 	 * validated here.
 	 */
 	if ((!ddb_handle) ||
@@ -420,13 +419,13 @@
 		return_ACPI_STATUS (AE_BAD_PARAMETER);
 	}
 
-	/* Get the actual table descriptor from the Ddb_handle */
+	/* Get the actual table descriptor from the ddb_handle */
 
 	table_info = (acpi_table_desc *) table_desc->reference.object;
 
 	/*
 	 * Delete the entire namespace under this table Node
-	 * (Offset contains the Table_id)
+	 * (Offset contains the table_id)
 	 */
 	acpi_ns_delete_namespace_by_owner (table_info->table_id);
 
@@ -434,7 +433,7 @@
 
 	(void) acpi_tb_uninstall_table (table_info->installed_desc);
 
-	/* Delete the table descriptor (Ddb_handle) */
+	/* Delete the table descriptor (ddb_handle) */
 
 	acpi_ut_remove_reference (table_desc);
 	return_ACPI_STATUS (status);
diff -Nru a/drivers/acpi/executer/exconvrt.c b/drivers/acpi/executer/exconvrt.c
--- a/drivers/acpi/executer/exconvrt.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/acpi/executer/exconvrt.c	Mon Dec 23 21:21:50 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: exconvrt - Object conversion routines
- *              $Revision: 47 $
  *
  *****************************************************************************/
 
@@ -35,11 +34,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_convert_to_integer
+ * FUNCTION:    acpi_ex_convert_to_integer
  *
- * PARAMETERS:  *Obj_desc       - Object to be converted.  Must be an
+ * PARAMETERS:  *obj_desc       - Object to be converted.  Must be an
  *                                Integer, Buffer, or String
- *              Walk_state      - Current method state
+ *              walk_state      - Current method state
  *
  * RETURN:      Status
  *
@@ -61,7 +60,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_convert_to_integer", obj_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ex_convert_to_integer", obj_desc);
 
 
 	switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
@@ -169,11 +168,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_convert_to_buffer
+ * FUNCTION:    acpi_ex_convert_to_buffer
  *
- * PARAMETERS:  *Obj_desc       - Object to be converted.  Must be an
+ * PARAMETERS:  *obj_desc       - Object to be converted.  Must be an
  *                                Integer, Buffer, or String
- *              Walk_state      - Current method state
+ *              walk_state      - Current method state
  *
  * RETURN:      Status
  *
@@ -192,7 +191,7 @@
 	u8                      *new_buf;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_convert_to_buffer", obj_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ex_convert_to_buffer", obj_desc);
 
 
 	switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
@@ -230,7 +229,7 @@
 		 * Create a new Buffer object
 		 * Size will be the string length
 		 */
-		ret_desc = acpi_ut_create_buffer_object ((ACPI_SIZE) obj_desc->string.length);
+		ret_desc = acpi_ut_create_buffer_object ((acpi_size) obj_desc->string.length);
 		if (!ret_desc) {
 			return_ACPI_STATUS (AE_NO_MEMORY);
 		}
@@ -269,12 +268,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_convert_ascii
+ * FUNCTION:    acpi_ex_convert_ascii
  *
  * PARAMETERS:  Integer         - Value to be converted
  *              Base            - 10 or 16
  *              String          - Where the string is returned
- *              Data_width      - Size of data item to be converted
+ *              data_width      - Size of data item to be converted
  *
  * RETURN:      Actual string length
  *
@@ -376,11 +375,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_convert_to_string
+ * FUNCTION:    acpi_ex_convert_to_string
  *
- * PARAMETERS:  *Obj_desc       - Object to be converted.  Must be an
+ * PARAMETERS:  *obj_desc       - Object to be converted.  Must be an
  *                                Integer, Buffer, or String
- *              Walk_state      - Current method state
+ *              walk_state      - Current method state
  *
  * RETURN:      Status
  *
@@ -398,13 +397,12 @@
 {
 	acpi_operand_object     *ret_desc;
 	u32                     i;
-	u32                     index;
 	u32                     string_length;
 	u8                      *new_buf;
 	u8                      *pointer;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_convert_to_string", obj_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ex_convert_to_string", obj_desc);
 
 
 	switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
@@ -438,10 +436,10 @@
 
 		/* Need enough space for one ASCII integer plus null terminator */
 
-		new_buf = ACPI_MEM_CALLOCATE ((ACPI_SIZE) string_length + 1);
+		new_buf = ACPI_MEM_CALLOCATE ((acpi_size) string_length + 1);
 		if (!new_buf) {
 			ACPI_REPORT_ERROR
-				(("Ex_convert_to_string: Buffer allocation failure\n"));
+				(("ex_convert_to_string: Buffer allocation failure\n"));
 			acpi_ut_remove_reference (ret_desc);
 			return_ACPI_STATUS (AE_NO_MEMORY);
 		}
@@ -467,9 +465,15 @@
 
 	case ACPI_TYPE_BUFFER:
 
-		string_length = obj_desc->buffer.length * 3;
-		if (base == 10) {
-			string_length = obj_desc->buffer.length * 4;
+		/* Find the string length */
+
+		pointer = obj_desc->buffer.pointer;
+		for (string_length = 0; string_length < obj_desc->buffer.length; string_length++) {
+			/* Exit on null terminator */
+
+			if (!pointer[string_length]) {
+				break;
+			}
 		}
 
 		if (max_length > ACPI_MAX_STRING_CONVERSION) {
@@ -492,31 +496,23 @@
 			string_length = max_length;
 		}
 
-		new_buf = ACPI_MEM_CALLOCATE ((ACPI_SIZE) string_length + 1);
+		new_buf = ACPI_MEM_CALLOCATE ((acpi_size) string_length + 1);
 		if (!new_buf) {
 			ACPI_REPORT_ERROR
-				(("Ex_convert_to_string: Buffer allocation failure\n"));
+				(("ex_convert_to_string: Buffer allocation failure\n"));
 			acpi_ut_remove_reference (ret_desc);
 			return_ACPI_STATUS (AE_NO_MEMORY);
 		}
 
-		/*
-		 * Convert each byte of the buffer to two ASCII characters plus a space.
-		 */
-		pointer = obj_desc->buffer.pointer;
-		index = 0;
-		for (i = 0, index = 0; i < obj_desc->buffer.length; i++) {
-			index += acpi_ex_convert_to_ascii ((acpi_integer) pointer[i], base, &new_buf[index], 1);
+		/* Copy the appropriate number of buffer characters */
 
-			new_buf[index] = ' ';
-			index++;
-		}
+		ACPI_MEMCPY (new_buf, pointer, string_length);
 
 		/* Null terminate */
 
-		new_buf [index-1] = 0;
+		new_buf [string_length] = 0;
 		ret_desc->buffer.pointer = new_buf;
-		ret_desc->string.length = (u32) ACPI_STRLEN ((char *) new_buf);
+		ret_desc->string.length = string_length;
 		break;
 
 
@@ -543,11 +539,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_convert_to_target_type
+ * FUNCTION:    acpi_ex_convert_to_target_type
  *
- * PARAMETERS:  Destination_type    - Current type of the destination
- *              Source_desc         - Source object to be converted.
- *              Walk_state          - Current method state
+ * PARAMETERS:  destination_type    - Current type of the destination
+ *              source_desc         - Source object to be converted.
+ *              walk_state          - Current method state
  *
  * RETURN:      Status
  *
@@ -565,7 +561,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_convert_to_target_type");
+	ACPI_FUNCTION_TRACE ("ex_convert_to_target_type");
 
 
 	/* Default behavior */
@@ -646,14 +642,14 @@
 
 	case ARGI_REFERENCE:
 		/*
-		 * Create_xxxx_field cases - we are storing the field object into the name
+		 * create_xxxx_field cases - we are storing the field object into the name
 		 */
 		break;
 
 
 	default:
 		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
-			"Unknown Target type ID 0x%X Op %s Dest_type %s\n",
+			"Unknown Target type ID 0x%X Op %s dest_type %s\n",
 			GET_CURRENT_ARG_TYPE (walk_state->op_info->runtime_args),
 			walk_state->op_info->name, acpi_ut_get_type_name (destination_type)));
 
diff -Nru a/drivers/acpi/executer/excreate.c b/drivers/acpi/executer/excreate.c
--- a/drivers/acpi/executer/excreate.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/acpi/executer/excreate.c	Mon Dec 23 21:22:00 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: excreate - Named object creation
- *              $Revision: 98 $
  *
  *****************************************************************************/
 
@@ -39,9 +38,9 @@
 #ifndef ACPI_NO_METHOD_EXECUTION
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ex_create_alias
+ * FUNCTION:    acpi_ex_create_alias
  *
- * PARAMETERS:  Walk_state           - Current state, contains operands
+ * PARAMETERS:  walk_state           - Current state, contains operands
  *
  * RETURN:      Status
  *
@@ -58,7 +57,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_create_alias");
+	ACPI_FUNCTION_TRACE ("ex_create_alias");
 
 
 	/* Get the source/alias operands (both namespace nodes) */
@@ -123,9 +122,9 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ex_create_event
+ * FUNCTION:    acpi_ex_create_event
  *
- * PARAMETERS:  Walk_state          - Current state
+ * PARAMETERS:  walk_state          - Current state
  *
  * RETURN:      Status
  *
@@ -141,7 +140,7 @@
 	acpi_operand_object     *obj_desc;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_create_event");
+	ACPI_FUNCTION_TRACE ("ex_create_event");
 
 
 	obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_EVENT);
@@ -177,15 +176,15 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ex_create_mutex
+ * FUNCTION:    acpi_ex_create_mutex
  *
- * PARAMETERS:  Walk_state          - Current state
+ * PARAMETERS:  walk_state          - Current state
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Create a new mutex object
  *
- *              Mutex (Name[0], Sync_level[1])
+ *              Mutex (Name[0], sync_level[1])
  *
  ****************************************************************************/
 
@@ -197,7 +196,7 @@
 	acpi_operand_object     *obj_desc;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_create_mutex", ACPI_WALK_OPERANDS);
+	ACPI_FUNCTION_TRACE_PTR ("ex_create_mutex", ACPI_WALK_OPERANDS);
 
 
 	/* Create the new mutex object */
@@ -239,12 +238,12 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ex_create_region
+ * FUNCTION:    acpi_ex_create_region
  *
- * PARAMETERS:  Aml_start           - Pointer to the region declaration AML
- *              Aml_length          - Max length of the declaration AML
+ * PARAMETERS:  aml_start           - Pointer to the region declaration AML
+ *              aml_length          - Max length of the declaration AML
  *              Operands            - List of operands for the opcode
- *              Walk_state          - Current state
+ *              walk_state          - Current state
  *
  * RETURN:      Status
  *
@@ -265,7 +264,7 @@
 	acpi_operand_object     *region_obj2;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_create_region");
+	ACPI_FUNCTION_TRACE ("ex_create_region");
 
 
 	/* Get the Node from the object stack  */
@@ -286,7 +285,7 @@
 	 */
 	if ((region_space >= ACPI_NUM_PREDEFINED_REGIONS) &&
 		(region_space < ACPI_USER_REGION_BEGIN)) {
-		ACPI_REPORT_ERROR (("Invalid Address_space type %X\n", region_space));
+		ACPI_REPORT_ERROR (("Invalid address_space type %X\n", region_space));
 		return_ACPI_STATUS (AE_AML_INVALID_SPACE_ID);
 	}
 
@@ -333,13 +332,13 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ex_create_table_region
+ * FUNCTION:    acpi_ex_create_table_region
  *
- * PARAMETERS:  Walk_state          - Current state
+ * PARAMETERS:  walk_state          - Current state
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Create a new Data_table_region object
+ * DESCRIPTION: Create a new data_table_region object
  *
  ****************************************************************************/
 
@@ -355,7 +354,7 @@
 	acpi_operand_object     *region_obj2;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_create_table_region");
+	ACPI_FUNCTION_TRACE ("ex_create_table_region");
 
 	/* Get the Node from the object stack  */
 
@@ -392,7 +391,7 @@
 	/* Init the region from the operands */
 
 	obj_desc->region.space_id = REGION_DATA_TABLE;
-	obj_desc->region.address = (ACPI_PHYSICAL_ADDRESS) ACPI_TO_INTEGER (table);
+	obj_desc->region.address = (acpi_physical_address) ACPI_TO_INTEGER (table);
 	obj_desc->region.length = table->length;
 	obj_desc->region.node   = node;
 	obj_desc->region.flags  = AOPOBJ_DATA_VALID;
@@ -428,15 +427,15 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ex_create_processor
+ * FUNCTION:    acpi_ex_create_processor
  *
- * PARAMETERS:  Walk_state          - Current state
+ * PARAMETERS:  walk_state          - Current state
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Create a new processor object and populate the fields
  *
- *              Processor (Name[0], Cpu_iD[1], Pblock_addr[2], Pblock_length[3])
+ *              Processor (Name[0], cpu_iD[1], pblock_addr[2], pblock_length[3])
  *
  ****************************************************************************/
 
@@ -449,7 +448,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_create_processor", walk_state);
+	ACPI_FUNCTION_TRACE_PTR ("ex_create_processor", walk_state);
 
 
 	/* Create the processor object */
@@ -463,7 +462,7 @@
 	 * Initialize the processor object from the operands
 	 */
 	obj_desc->processor.proc_id = (u8)          operand[1]->integer.value;
-	obj_desc->processor.address = (ACPI_IO_ADDRESS) operand[2]->integer.value;
+	obj_desc->processor.address = (acpi_io_address) operand[2]->integer.value;
 	obj_desc->processor.length = (u8)           operand[3]->integer.value;
 
 	/* Install the processor object in the parent Node */
@@ -481,15 +480,15 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ex_create_power_resource
+ * FUNCTION:    acpi_ex_create_power_resource
  *
- * PARAMETERS:  Walk_state          - Current state
+ * PARAMETERS:  walk_state          - Current state
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Create a new Power_resource object and populate the fields
+ * DESCRIPTION: Create a new power_resource object and populate the fields
  *
- *              Power_resource (Name[0], System_level[1], Resource_order[2])
+ *              power_resource (Name[0], system_level[1], resource_order[2])
  *
  ****************************************************************************/
 
@@ -502,7 +501,7 @@
 	acpi_operand_object     *obj_desc;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_create_power_resource", walk_state);
+	ACPI_FUNCTION_TRACE_PTR ("ex_create_power_resource", walk_state);
 
 
 	/* Create the power resource object */
@@ -533,11 +532,11 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ex_create_method
+ * FUNCTION:    acpi_ex_create_method
  *
- * PARAMETERS:  Aml_start       - First byte of the method's AML
- *              Aml_length      - AML byte count for this method
- *              Walk_state      - Current state
+ * PARAMETERS:  aml_start       - First byte of the method's AML
+ *              aml_length      - AML byte count for this method
+ *              walk_state      - Current state
  *
  * RETURN:      Status
  *
@@ -557,7 +556,7 @@
 	u8                      method_flags;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_create_method", walk_state);
+	ACPI_FUNCTION_TRACE_PTR ("ex_create_method", walk_state);
 
 
 	/* Create a new method object */
@@ -586,7 +585,7 @@
 	if (method_flags & METHOD_FLAGS_SERIALIZED) {
 		/*
 		 * ACPI 1.0: Concurrency = 1
-		 * ACPI 2.0: Concurrency = (Sync_level (in method declaration) + 1)
+		 * ACPI 2.0: Concurrency = (sync_level (in method declaration) + 1)
 		 */
 		obj_desc->method.concurrency = (u8)
 				  (((method_flags & METHOD_FLAGS_SYNCH_LEVEL) >> 4) + 1);
diff -Nru a/drivers/acpi/executer/exdump.c b/drivers/acpi/executer/exdump.c
--- a/drivers/acpi/executer/exdump.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/executer/exdump.c	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: exdump - Interpreter debug output routines
- *              $Revision: 164 $
  *
  *****************************************************************************/
 
@@ -42,9 +41,9 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ex_dump_operand
+ * FUNCTION:    acpi_ex_dump_operand
  *
- * PARAMETERS:  *Obj_desc         - Pointer to entry to be dumped
+ * PARAMETERS:  *obj_desc         - Pointer to entry to be dumped
  *
  * RETURN:      Status
  *
@@ -62,7 +61,7 @@
 	u16                     element_index;
 
 
-	ACPI_FUNCTION_NAME ("Ex_dump_operand")
+	ACPI_FUNCTION_NAME ("ex_dump_operand")
 
 
 	if (!((ACPI_LV_EXEC & acpi_dbg_level) && (_COMPONENT & acpi_dbg_layer))) {
@@ -91,7 +90,7 @@
 		return;
 	}
 
-	/*  Obj_desc is a valid object */
+	/*  obj_desc is a valid object */
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%p ", obj_desc));
 
@@ -122,7 +121,7 @@
 
 		case AML_REF_OF_OP:
 
-			acpi_os_printf ("Reference: (Ref_of) %p\n",
+			acpi_os_printf ("Reference: (ref_of) %p\n",
 					 obj_desc->reference.object);
 			break;
 
@@ -271,14 +270,14 @@
 
 	case ACPI_TYPE_LOCAL_BANK_FIELD:
 
-		acpi_os_printf ("Bank_field\n");
+		acpi_os_printf ("bank_field\n");
 		break;
 
 
 	case ACPI_TYPE_LOCAL_REGION_FIELD:
 
 		acpi_os_printf (
-			"Region_field: Bits=%X Acc_width=%X Lock=%X Update=%X at byte=%X bit=%X of below:\n",
+			"region_field: Bits=%X acc_width=%X Lock=%X Update=%X at byte=%X bit=%X of below:\n",
 			obj_desc->field.bit_length, obj_desc->field.access_byte_width,
 			obj_desc->field.field_flags & AML_FIELD_LOCK_RULE_MASK,
 			obj_desc->field.field_flags & AML_FIELD_UPDATE_RULE_MASK,
@@ -289,14 +288,14 @@
 
 	case ACPI_TYPE_LOCAL_INDEX_FIELD:
 
-		acpi_os_printf ("Index_field\n");
+		acpi_os_printf ("index_field\n");
 		break;
 
 
 	case ACPI_TYPE_BUFFER_FIELD:
 
 		acpi_os_printf (
-			"Buffer_field: %X bits at byte %X bit %X of \n",
+			"buffer_field: %X bits at byte %X bit %X of \n",
 			obj_desc->buffer_field.bit_length, obj_desc->buffer_field.base_byte_offset,
 			obj_desc->buffer_field.start_field_bit_offset);
 
@@ -371,11 +370,11 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ex_dump_operands
+ * FUNCTION:    acpi_ex_dump_operands
  *
- * PARAMETERS:  Interpreter_mode     - Load or Exec
+ * PARAMETERS:  interpreter_mode     - Load or Exec
  *              *Ident              - Identification
- *              Num_levels          - # of stack entries to dump above line
+ *              num_levels          - # of stack entries to dump above line
  *              *Note               - Output notation
  *
  * DESCRIPTION: Dump the object stack
@@ -392,11 +391,11 @@
 	char                    *module_name,
 	u32                     line_number)
 {
-	NATIVE_UINT             i;
+	acpi_native_uint        i;
 	acpi_operand_object     **obj_desc;
 
 
-	ACPI_FUNCTION_NAME ("Ex_dump_operands");
+	ACPI_FUNCTION_NAME ("ex_dump_operands");
 
 
 	if (!ident) {
@@ -431,7 +430,7 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ex_out*
+ * FUNCTION:    acpi_ex_out*
  *
  * PARAMETERS:  Title               - Descriptive text
  *              Value               - Value to be displayed
@@ -469,7 +468,7 @@
 void
 acpi_ex_out_address (
 	char                    *title,
-	ACPI_PHYSICAL_ADDRESS   value)
+	acpi_physical_address   value)
 {
 
 #if ACPI_MACHINE_WIDTH == 16
@@ -483,7 +482,7 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ex_dump_node
+ * FUNCTION:    acpi_ex_dump_node
  *
  * PARAMETERS:  *Node           - Descriptor to dump
  *              Flags               - Force display
@@ -513,15 +512,15 @@
 	acpi_ex_out_integer ("Owner Id",      node->owner_id);
 	acpi_ex_out_integer ("Reference Count", node->reference_count);
 	acpi_ex_out_pointer ("Attached Object", acpi_ns_get_attached_object (node));
-	acpi_ex_out_pointer ("Child_list",    node->child);
-	acpi_ex_out_pointer ("Next_peer",     node->peer);
+	acpi_ex_out_pointer ("child_list",    node->child);
+	acpi_ex_out_pointer ("next_peer",     node->peer);
 	acpi_ex_out_pointer ("Parent",        acpi_ns_get_parent_node (node));
 }
 
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ex_dump_object_descriptor
+ * FUNCTION:    acpi_ex_dump_object_descriptor
  *
  * PARAMETERS:  *Object             - Descriptor to dump
  *              Flags               - Force display
@@ -538,7 +537,7 @@
 	u32                     i;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_dump_object_descriptor");
+	ACPI_FUNCTION_TRACE ("ex_dump_object_descriptor");
 
 
 	if (!flags) {
@@ -555,7 +554,7 @@
 	}
 
 	if (ACPI_GET_DESCRIPTOR_TYPE (obj_desc) != ACPI_DESC_TYPE_OPERAND) {
-		acpi_os_printf ("Ex_dump_object_descriptor: %p is not a valid ACPI object\n", obj_desc);
+		acpi_os_printf ("ex_dump_object_descriptor: %p is not a valid ACPI object\n", obj_desc);
 		return_VOID;
 	}
 
@@ -617,9 +616,9 @@
 
 	case ACPI_TYPE_DEVICE:
 
-		acpi_ex_out_pointer ("Addr_handler", obj_desc->device.addr_handler);
-		acpi_ex_out_pointer ("Sys_handler",  obj_desc->device.sys_handler);
-		acpi_ex_out_pointer ("Drv_handler",  obj_desc->device.drv_handler);
+		acpi_ex_out_pointer ("addr_handler", obj_desc->device.addr_handler);
+		acpi_ex_out_pointer ("sys_handler",  obj_desc->device.sys_handler);
+		acpi_ex_out_pointer ("drv_handler",  obj_desc->device.drv_handler);
 		break;
 
 
@@ -631,41 +630,41 @@
 
 	case ACPI_TYPE_METHOD:
 
-		acpi_ex_out_integer ("Param_count",  obj_desc->method.param_count);
+		acpi_ex_out_integer ("param_count",  obj_desc->method.param_count);
 		acpi_ex_out_integer ("Concurrency",  obj_desc->method.concurrency);
 		acpi_ex_out_pointer ("Semaphore",    obj_desc->method.semaphore);
-		acpi_ex_out_integer ("Owning_id",    obj_desc->method.owning_id);
-		acpi_ex_out_integer ("Aml_length",   obj_desc->method.aml_length);
-		acpi_ex_out_pointer ("Aml_start",    obj_desc->method.aml_start);
+		acpi_ex_out_integer ("owning_id",    obj_desc->method.owning_id);
+		acpi_ex_out_integer ("aml_length",   obj_desc->method.aml_length);
+		acpi_ex_out_pointer ("aml_start",    obj_desc->method.aml_start);
 		break;
 
 
 	case ACPI_TYPE_MUTEX:
 
-		acpi_ex_out_integer ("Sync_level",   obj_desc->mutex.sync_level);
-		acpi_ex_out_pointer ("Owner_thread", obj_desc->mutex.owner_thread);
-		acpi_ex_out_integer ("Acquisition_depth",obj_desc->mutex.acquisition_depth);
+		acpi_ex_out_integer ("sync_level",   obj_desc->mutex.sync_level);
+		acpi_ex_out_pointer ("owner_thread", obj_desc->mutex.owner_thread);
+		acpi_ex_out_integer ("acquisition_depth",obj_desc->mutex.acquisition_depth);
 		acpi_ex_out_pointer ("Semaphore",    obj_desc->mutex.semaphore);
 		break;
 
 
 	case ACPI_TYPE_REGION:
 
-		acpi_ex_out_integer ("Space_id",     obj_desc->region.space_id);
+		acpi_ex_out_integer ("space_id",     obj_desc->region.space_id);
 		acpi_ex_out_integer ("Flags",        obj_desc->region.flags);
 		acpi_ex_out_address ("Address",      obj_desc->region.address);
 		acpi_ex_out_integer ("Length",       obj_desc->region.length);
-		acpi_ex_out_pointer ("Addr_handler", obj_desc->region.addr_handler);
+		acpi_ex_out_pointer ("addr_handler", obj_desc->region.addr_handler);
 		acpi_ex_out_pointer ("Next",         obj_desc->region.next);
 		break;
 
 
 	case ACPI_TYPE_POWER:
 
-		acpi_ex_out_integer ("System_level", obj_desc->power_resource.system_level);
-		acpi_ex_out_integer ("Resource_order", obj_desc->power_resource.resource_order);
-		acpi_ex_out_pointer ("Sys_handler",  obj_desc->power_resource.sys_handler);
-		acpi_ex_out_pointer ("Drv_handler",  obj_desc->power_resource.drv_handler);
+		acpi_ex_out_integer ("system_level", obj_desc->power_resource.system_level);
+		acpi_ex_out_integer ("resource_order", obj_desc->power_resource.resource_order);
+		acpi_ex_out_pointer ("sys_handler",  obj_desc->power_resource.sys_handler);
+		acpi_ex_out_pointer ("drv_handler",  obj_desc->power_resource.drv_handler);
 		break;
 
 
@@ -673,18 +672,18 @@
 
 		acpi_ex_out_integer ("Processor ID", obj_desc->processor.proc_id);
 		acpi_ex_out_integer ("Length",       obj_desc->processor.length);
-		acpi_ex_out_address ("Address",      (ACPI_PHYSICAL_ADDRESS) obj_desc->processor.address);
-		acpi_ex_out_pointer ("Sys_handler",  obj_desc->processor.sys_handler);
-		acpi_ex_out_pointer ("Drv_handler",  obj_desc->processor.drv_handler);
-		acpi_ex_out_pointer ("Addr_handler", obj_desc->processor.addr_handler);
+		acpi_ex_out_address ("Address",      (acpi_physical_address) obj_desc->processor.address);
+		acpi_ex_out_pointer ("sys_handler",  obj_desc->processor.sys_handler);
+		acpi_ex_out_pointer ("drv_handler",  obj_desc->processor.drv_handler);
+		acpi_ex_out_pointer ("addr_handler", obj_desc->processor.addr_handler);
 		break;
 
 
 	case ACPI_TYPE_THERMAL:
 
-		acpi_ex_out_pointer ("Sys_handler",  obj_desc->thermal_zone.sys_handler);
-		acpi_ex_out_pointer ("Drv_handler",  obj_desc->thermal_zone.drv_handler);
-		acpi_ex_out_pointer ("Addr_handler", obj_desc->thermal_zone.addr_handler);
+		acpi_ex_out_pointer ("sys_handler",  obj_desc->thermal_zone.sys_handler);
+		acpi_ex_out_pointer ("drv_handler",  obj_desc->thermal_zone.drv_handler);
+		acpi_ex_out_pointer ("addr_handler", obj_desc->thermal_zone.addr_handler);
 		break;
 
 
@@ -693,29 +692,29 @@
 	case ACPI_TYPE_LOCAL_BANK_FIELD:
 	case ACPI_TYPE_LOCAL_INDEX_FIELD:
 
-		acpi_ex_out_integer ("Field_flags",  obj_desc->common_field.field_flags);
-		acpi_ex_out_integer ("Access_byte_width", obj_desc->common_field.access_byte_width);
-		acpi_ex_out_integer ("Bit_length",   obj_desc->common_field.bit_length);
-		acpi_ex_out_integer ("Fld_bit_offset", obj_desc->common_field.start_field_bit_offset);
-		acpi_ex_out_integer ("Base_byte_offset", obj_desc->common_field.base_byte_offset);
-		acpi_ex_out_integer ("Datum_valid_bits", obj_desc->common_field.datum_valid_bits);
-		acpi_ex_out_integer ("End_fld_valid_bits", obj_desc->common_field.end_field_valid_bits);
-		acpi_ex_out_integer ("End_buf_valid_bits", obj_desc->common_field.end_buffer_valid_bits);
-		acpi_ex_out_pointer ("Parent_node",  obj_desc->common_field.node);
+		acpi_ex_out_integer ("field_flags",  obj_desc->common_field.field_flags);
+		acpi_ex_out_integer ("access_byte_width", obj_desc->common_field.access_byte_width);
+		acpi_ex_out_integer ("bit_length",   obj_desc->common_field.bit_length);
+		acpi_ex_out_integer ("fld_bit_offset", obj_desc->common_field.start_field_bit_offset);
+		acpi_ex_out_integer ("base_byte_offset", obj_desc->common_field.base_byte_offset);
+		acpi_ex_out_integer ("datum_valid_bits", obj_desc->common_field.datum_valid_bits);
+		acpi_ex_out_integer ("end_fld_valid_bits", obj_desc->common_field.end_field_valid_bits);
+		acpi_ex_out_integer ("end_buf_valid_bits", obj_desc->common_field.end_buffer_valid_bits);
+		acpi_ex_out_pointer ("parent_node",  obj_desc->common_field.node);
 
 		switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
 		case ACPI_TYPE_BUFFER_FIELD:
-			acpi_ex_out_pointer ("Buffer_obj",   obj_desc->buffer_field.buffer_obj);
+			acpi_ex_out_pointer ("buffer_obj",   obj_desc->buffer_field.buffer_obj);
 			break;
 
 		case ACPI_TYPE_LOCAL_REGION_FIELD:
-			acpi_ex_out_pointer ("Region_obj",   obj_desc->field.region_obj);
+			acpi_ex_out_pointer ("region_obj",   obj_desc->field.region_obj);
 			break;
 
 		case ACPI_TYPE_LOCAL_BANK_FIELD:
 			acpi_ex_out_integer ("Value",        obj_desc->bank_field.value);
-			acpi_ex_out_pointer ("Region_obj",   obj_desc->bank_field.region_obj);
-			acpi_ex_out_pointer ("Bank_obj",     obj_desc->bank_field.bank_obj);
+			acpi_ex_out_pointer ("region_obj",   obj_desc->bank_field.region_obj);
+			acpi_ex_out_pointer ("bank_obj",     obj_desc->bank_field.bank_obj);
 			break;
 
 		case ACPI_TYPE_LOCAL_INDEX_FIELD:
@@ -733,10 +732,10 @@
 
 	case ACPI_TYPE_LOCAL_REFERENCE:
 
-		acpi_ex_out_integer ("Target_type",  obj_desc->reference.target_type);
+		acpi_ex_out_integer ("target_type",  obj_desc->reference.target_type);
 		acpi_ex_out_string ("Opcode",        (acpi_ps_get_opcode_info (obj_desc->reference.opcode))->name);
 		acpi_ex_out_integer ("Offset",       obj_desc->reference.offset);
-		acpi_ex_out_pointer ("Obj_desc",     obj_desc->reference.object);
+		acpi_ex_out_pointer ("obj_desc",     obj_desc->reference.object);
 		acpi_ex_out_pointer ("Node",         obj_desc->reference.node);
 		acpi_ex_out_pointer ("Where",        obj_desc->reference.where);
 		break;
@@ -744,9 +743,9 @@
 
 	case ACPI_TYPE_LOCAL_ADDRESS_HANDLER:
 
-		acpi_ex_out_integer ("Space_id",     obj_desc->addr_handler.space_id);
+		acpi_ex_out_integer ("space_id",     obj_desc->addr_handler.space_id);
 		acpi_ex_out_pointer ("Next",         obj_desc->addr_handler.next);
-		acpi_ex_out_pointer ("Region_list",  obj_desc->addr_handler.region_list);
+		acpi_ex_out_pointer ("region_list",  obj_desc->addr_handler.region_list);
 		acpi_ex_out_pointer ("Node",         obj_desc->addr_handler.node);
 		acpi_ex_out_pointer ("Context",      obj_desc->addr_handler.context);
 		break;
@@ -764,7 +763,7 @@
 	case ACPI_TYPE_LOCAL_DATA:
 	default:
 
-		acpi_os_printf ("Ex_dump_object_descriptor: Display not implemented for object type %s\n",
+		acpi_os_printf ("ex_dump_object_descriptor: Display not implemented for object type %s\n",
 			acpi_ut_get_object_type_name (obj_desc));
 		break;
 	}
diff -Nru a/drivers/acpi/executer/exfield.c b/drivers/acpi/executer/exfield.c
--- a/drivers/acpi/executer/exfield.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/acpi/executer/exfield.c	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: exfield - ACPI AML (p-code) execution - field manipulation
- *              $Revision: 117 $
  *
  *****************************************************************************/
 
@@ -35,11 +34,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_read_data_from_field
+ * FUNCTION:    acpi_ex_read_data_from_field
  *
- * PARAMETERS:  Walk_state          - Current execution state
- *              Obj_desc            - The named field
- *              Ret_buffer_desc     - Where the return data object is stored
+ * PARAMETERS:  walk_state          - Current execution state
+ *              obj_desc            - The named field
+ *              ret_buffer_desc     - Where the return data object is stored
  *
  * RETURN:      Status
  *
@@ -56,12 +55,12 @@
 {
 	acpi_status             status;
 	acpi_operand_object     *buffer_desc;
-	ACPI_SIZE               length;
+	acpi_size               length;
 	void                    *buffer;
 	u8                      locked;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_read_data_from_field", obj_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ex_read_data_from_field", obj_desc);
 
 
 	/* Parameter validation */
@@ -72,7 +71,7 @@
 
 	if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_BUFFER_FIELD) {
 		/*
-		 * If the Buffer_field arguments have not been previously evaluated,
+		 * If the buffer_field arguments have not been previously evaluated,
 		 * evaluate them now and save the results.
 		 */
 		if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
@@ -118,7 +117,7 @@
 	 *
 	 * Note: Field.length is in bits.
 	 */
-	length = (ACPI_SIZE) ACPI_ROUND_BITS_UP_TO_BYTES (obj_desc->field.bit_length);
+	length = (acpi_size) ACPI_ROUND_BITS_UP_TO_BYTES (obj_desc->field.bit_length);
 	if (length > acpi_gbl_integer_byte_width) {
 		/* Field is too large for an Integer, create a Buffer instead */
 
@@ -145,7 +144,7 @@
 		"Obj=%p Type=%X Buf=%p Len=%X\n",
 		obj_desc, ACPI_GET_OBJECT_TYPE (obj_desc), buffer, (u32) length));
 	ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
-		"Field_write: Bit_len=%X Bit_off=%X Byte_off=%X\n",
+		"field_write: bit_len=%X bit_off=%X byte_off=%X\n",
 		obj_desc->common_field.bit_length,
 		obj_desc->common_field.start_field_bit_offset,
 		obj_desc->common_field.base_byte_offset));
@@ -174,10 +173,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_write_data_to_field
+ * FUNCTION:    acpi_ex_write_data_to_field
  *
- * PARAMETERS:  Source_desc         - Contains data to write
- *              Obj_desc            - The named field
+ * PARAMETERS:  source_desc         - Contains data to write
+ *              obj_desc            - The named field
  *
  * RETURN:      Status
  *
@@ -200,7 +199,7 @@
 	acpi_operand_object     *buffer_desc;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_write_data_to_field", obj_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ex_write_data_to_field", obj_desc);
 
 
 	/* Parameter validation */
@@ -211,7 +210,7 @@
 
 	if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_BUFFER_FIELD) {
 		/*
-		 * If the Buffer_field arguments have not been previously evaluated,
+		 * If the buffer_field arguments have not been previously evaluated,
 		 * evaluate them now and save the results.
 		 */
 		if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
@@ -320,7 +319,7 @@
 		"Obj=%p Type=%X Buf=%p Len=%X\n",
 		obj_desc, ACPI_GET_OBJECT_TYPE (obj_desc), buffer, length));
 	ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
-		"Field_read: Bit_len=%X Bit_off=%X Byte_off=%X\n",
+		"field_read: bit_len=%X bit_off=%X byte_off=%X\n",
 		obj_desc->common_field.bit_length,
 		obj_desc->common_field.start_field_bit_offset,
 		obj_desc->common_field.base_byte_offset));
diff -Nru a/drivers/acpi/executer/exfldio.c b/drivers/acpi/executer/exfldio.c
--- a/drivers/acpi/executer/exfldio.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/acpi/executer/exfldio.c	Mon Dec 23 21:21:53 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: exfldio - Aml Field I/O
- *              $Revision: 91 $
  *
  *****************************************************************************/
 
@@ -37,16 +36,16 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_setup_region
+ * FUNCTION:    acpi_ex_setup_region
  *
- * PARAMETERS:  *Obj_desc               - Field to be read or written
- *              Field_datum_byte_offset - Byte offset of this datum within the
+ * PARAMETERS:  *obj_desc               - Field to be read or written
+ *              field_datum_byte_offset - Byte offset of this datum within the
  *                                        parent field
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Common processing for Acpi_ex_extract_from_field and
- *              Acpi_ex_insert_into_field. Initialize the
+ * DESCRIPTION: Common processing for acpi_ex_extract_from_field and
+ *              acpi_ex_insert_into_field. Initialize the
  *
  ******************************************************************************/
 
@@ -59,7 +58,7 @@
 	acpi_operand_object     *rgn_desc;
 
 
-	ACPI_FUNCTION_TRACE_U32 ("Ex_setup_region", field_datum_byte_offset);
+	ACPI_FUNCTION_TRACE_U32 ("ex_setup_region", field_datum_byte_offset);
 
 
 	rgn_desc = obj_desc->common_field.region_obj;
@@ -101,7 +100,7 @@
 			   + obj_desc->common_field.access_byte_width)) {
 		if (rgn_desc->region.length < obj_desc->common_field.access_byte_width) {
 			/*
-			 * This is the case where the Access_type (Acc_word, etc.) is wider
+			 * This is the case where the access_type (acc_word, etc.) is wider
 			 * than the region itself.  For example, a region of length one
 			 * byte, and a field with Dword access specified.
 			 */
@@ -130,10 +129,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_access_region
+ * FUNCTION:    acpi_ex_access_region
  *
- * PARAMETERS:  *Obj_desc               - Field to be read
- *              Field_datum_byte_offset - Byte offset of this datum within the
+ * PARAMETERS:  *obj_desc               - Field to be read
+ *              field_datum_byte_offset - Byte offset of this datum within the
  *                                        parent field
  *              *Value                  - Where to store value (must at least
  *                                        the size of acpi_integer)
@@ -155,10 +154,10 @@
 {
 	acpi_status             status;
 	acpi_operand_object     *rgn_desc;
-	ACPI_PHYSICAL_ADDRESS   address;
+	acpi_physical_address   address;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_access_region");
+	ACPI_FUNCTION_TRACE ("ex_access_region");
 
 
 	/*
@@ -198,7 +197,7 @@
 		field_datum_byte_offset,
 		ACPI_HIDWORD (address), ACPI_LODWORD (address)));
 
-	/* Invoke the appropriate Address_space/Op_region handler */
+	/* Invoke the appropriate address_space/op_region handler */
 
 	status = acpi_ev_address_space_dispatch (rgn_desc, function,
 			  address, ACPI_MUL_8 (obj_desc->common_field.access_byte_width), value);
@@ -224,9 +223,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_register_overflow
+ * FUNCTION:    acpi_ex_register_overflow
  *
- * PARAMETERS:  *Obj_desc               - Register(Field) to be written
+ * PARAMETERS:  *obj_desc               - Register(Field) to be written
  *              Value                   - Value to be stored
  *
  * RETURN:      TRUE if value overflows the field, FALSE otherwise
@@ -269,19 +268,19 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_field_datum_io
+ * FUNCTION:    acpi_ex_field_datum_io
  *
- * PARAMETERS:  *Obj_desc               - Field to be read
- *              Field_datum_byte_offset - Byte offset of this datum within the
+ * PARAMETERS:  *obj_desc               - Field to be read
+ *              field_datum_byte_offset - Byte offset of this datum within the
  *                                        parent field
  *              *Value                  - Where to store value (must be 64 bits)
- *              Read_write              - Read or Write flag
+ *              read_write              - Read or Write flag
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Read or Write a single datum of a field.  The Field_type is
+ * DESCRIPTION: Read or Write a single datum of a field.  The field_type is
  *              demultiplexed here to handle the different types of fields
- *              (Buffer_field, Region_field, Index_field, Bank_field)
+ *              (buffer_field, region_field, index_field, bank_field)
  *
  ******************************************************************************/
 
@@ -296,7 +295,7 @@
 	acpi_integer            local_value;
 
 
-	ACPI_FUNCTION_TRACE_U32 ("Ex_field_datum_io", field_datum_byte_offset);
+	ACPI_FUNCTION_TRACE_U32 ("ex_field_datum_io", field_datum_byte_offset);
 
 
 	if (read_write == ACPI_READ) {
@@ -313,15 +312,15 @@
 	/*
 	 * The four types of fields are:
 	 *
-	 * Buffer_fields - Read/write from/to a Buffer
-	 * Region_fields - Read/write from/to a Operation Region.
-	 * Bank_fields  - Write to a Bank Register, then read/write from/to an Op_region
-	 * Index_fields - Write to an Index Register, then read/write from/to a Data Register
+	 * buffer_fields - Read/write from/to a Buffer
+	 * region_fields - Read/write from/to a Operation Region.
+	 * bank_fields  - Write to a Bank Register, then read/write from/to an op_region
+	 * index_fields - Write to an Index Register, then read/write from/to a Data Register
 	 */
 	switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
 	case ACPI_TYPE_BUFFER_FIELD:
 		/*
-		 * If the Buffer_field arguments have not been previously evaluated,
+		 * If the buffer_field arguments have not been previously evaluated,
 		 * evaluate them now and save the results.
 		 */
 		if (!(obj_desc->common.flags & AOPOBJ_DATA_VALID)) {
@@ -358,7 +357,7 @@
 
 	case ACPI_TYPE_LOCAL_BANK_FIELD:
 
-		/* Ensure that the Bank_value is not beyond the capacity of the register */
+		/* Ensure that the bank_value is not beyond the capacity of the register */
 
 		if (acpi_ex_register_overflow (obj_desc->bank_field.bank_obj,
 				  (acpi_integer) obj_desc->bank_field.value)) {
@@ -366,8 +365,8 @@
 		}
 
 		/*
-		 * For Bank_fields, we must write the Bank_value to the Bank_register
-		 * (itself a Region_field) before we can access the data.
+		 * For bank_fields, we must write the bank_value to the bank_register
+		 * (itself a region_field) before we can access the data.
 		 */
 		status = acpi_ex_insert_into_field (obj_desc->bank_field.bank_obj,
 				 &obj_desc->bank_field.value,
@@ -378,7 +377,7 @@
 
 		/*
 		 * Now that the Bank has been selected, fall through to the
-		 * Region_field case and write the datum to the Operation Region
+		 * region_field case and write the datum to the Operation Region
 		 */
 
 		/*lint -fallthrough */
@@ -386,7 +385,7 @@
 
 	case ACPI_TYPE_LOCAL_REGION_FIELD:
 		/*
-		 * For simple Region_fields, we just directly access the owning
+		 * For simple region_fields, we just directly access the owning
 		 * Operation Region.
 		 */
 		status = acpi_ex_access_region (obj_desc, field_datum_byte_offset, value,
@@ -397,14 +396,14 @@
 	case ACPI_TYPE_LOCAL_INDEX_FIELD:
 
 
-		/* Ensure that the Index_value is not beyond the capacity of the register */
+		/* Ensure that the index_value is not beyond the capacity of the register */
 
 		if (acpi_ex_register_overflow (obj_desc->index_field.index_obj,
 				  (acpi_integer) obj_desc->index_field.value)) {
 			return_ACPI_STATUS (AE_AML_REGISTER_LIMIT);
 		}
 
-		/* Write the index value to the Index_register (itself a Region_field) */
+		/* Write the index value to the index_register (itself a region_field) */
 
 		status = acpi_ex_insert_into_field (obj_desc->index_field.index_obj,
 				 &obj_desc->index_field.value,
@@ -414,7 +413,7 @@
 		}
 
 		if (read_write == ACPI_READ) {
-			/* Read the datum from the Data_register */
+			/* Read the datum from the data_register */
 
 			status = acpi_ex_extract_from_field (obj_desc->index_field.data_obj,
 					  value, obj_desc->common_field.access_byte_width);
@@ -453,9 +452,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_write_with_update_rule
+ * FUNCTION:    acpi_ex_write_with_update_rule
  *
- * PARAMETERS:  *Obj_desc           - Field to be set
+ * PARAMETERS:  *obj_desc           - Field to be set
  *              Value               - Value to store
  *
  * RETURN:      Status
@@ -476,7 +475,7 @@
 	acpi_integer            current_value;
 
 
-	ACPI_FUNCTION_TRACE_U32 ("Ex_write_with_update_rule", mask);
+	ACPI_FUNCTION_TRACE_U32 ("ex_write_with_update_rule", mask);
 
 
 	/* Start with the new bits  */
@@ -522,7 +521,7 @@
 
 		default:
 			ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
-				"Write_with_update_rule: Unknown Update_rule setting: %X\n",
+				"write_with_update_rule: Unknown update_rule setting: %X\n",
 				(obj_desc->common_field.field_flags & AML_FIELD_UPDATE_RULE_MASK)));
 			return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
 		}
@@ -534,7 +533,7 @@
 			  &merged_value, ACPI_WRITE);
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
-		"Mask %8.8X%8.8X Datum_offset %X Value %8.8X%8.8X, Merged_value %8.8X%8.8X\n",
+		"Mask %8.8X%8.8X datum_offset %X Value %8.8X%8.8X, merged_value %8.8X%8.8X\n",
 		ACPI_HIDWORD (mask), ACPI_LODWORD (mask),
 		field_datum_byte_offset,
 		ACPI_HIDWORD (field_value), ACPI_LODWORD (field_value),
@@ -546,11 +545,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_get_buffer_datum
+ * FUNCTION:    acpi_ex_get_buffer_datum
  *
  * PARAMETERS:  Datum               - Where the Datum is returned
  *              Buffer              - Raw field buffer
- *              Byte_granularity    - 1/2/4/8 Granularity of the field
+ *              byte_granularity    - 1/2/4/8 Granularity of the field
  *                                    (aka Datum Size)
  *              Offset              - Datum offset into the buffer
  *
@@ -602,11 +601,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_set_buffer_datum
+ * FUNCTION:    acpi_ex_set_buffer_datum
  *
- * PARAMETERS:  Merged_datum        - Value to store
+ * PARAMETERS:  merged_datum        - Value to store
  *              Buffer              - Receiving buffer
- *              Byte_granularity    - 1/2/4/8 Granularity of the field
+ *              byte_granularity    - 1/2/4/8 Granularity of the field
  *                                    (aka Datum Size)
  *              Offset              - Datum offset into the buffer
  *
@@ -658,9 +657,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_extract_from_field
+ * FUNCTION:    acpi_ex_extract_from_field
  *
- * PARAMETERS:  *Obj_desc           - Field to be read
+ * PARAMETERS:  *obj_desc           - Field to be read
  *              *Value              - Where to store value
  *
  * RETURN:      Status
@@ -685,7 +684,7 @@
 	u32                     datum_count;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_extract_from_field");
+	ACPI_FUNCTION_TRACE ("ex_extract_from_field");
 
 
 	/*
@@ -706,7 +705,7 @@
 			   obj_desc->common_field.access_byte_width);
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
-		"Byte_len=%X, Datum_len=%X, Byte_gran=%X\n",
+		"byte_len=%X, datum_len=%X, byte_gran=%X\n",
 		byte_field_length, datum_count,obj_desc->common_field.access_byte_width));
 
 	/*
@@ -834,9 +833,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_insert_into_field
+ * FUNCTION:    acpi_ex_insert_into_field
  *
- * PARAMETERS:  *Obj_desc           - Field to be set
+ * PARAMETERS:  *obj_desc           - Field to be set
  *              Buffer              - Value to store
  *
  * RETURN:      Status
@@ -862,7 +861,7 @@
 	u32                     datum_count;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_insert_into_field");
+	ACPI_FUNCTION_TRACE ("ex_insert_into_field");
 
 
 	/*
@@ -884,7 +883,7 @@
 	datum_count = ACPI_ROUND_UP_TO (byte_field_length, obj_desc->common_field.access_byte_width);
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
-		"Byte_len=%X, Datum_len=%X, Byte_gran=%X\n",
+		"byte_len=%X, datum_len=%X, byte_gran=%X\n",
 		byte_field_length, datum_count, obj_desc->common_field.access_byte_width));
 
 	/*
@@ -907,7 +906,7 @@
 	 * Note: The code in this section also handles the aligned case
 	 *
 	 * Construct Mask with 1 bits where the field is, 0 bits elsewhere
-	 * (Only the bottom 5 bits of Bit_length are valid for a shift operation)
+	 * (Only the bottom 5 bits of bit_length are valid for a shift operation)
 	 *
 	 * Mask off bits that are "below" the field (if any)
 	 */
diff -Nru a/drivers/acpi/executer/exmisc.c b/drivers/acpi/executer/exmisc.c
--- a/drivers/acpi/executer/exmisc.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/acpi/executer/exmisc.c	Mon Dec 23 21:21:59 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Module Name: exmisc - ACPI AML (p-code) execution - specific opcodes
- *              $Revision: 114 $
  *
  *****************************************************************************/
 
@@ -36,16 +35,16 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_get_object_reference
+ * FUNCTION:    acpi_ex_get_object_reference
  *
- * PARAMETERS:  Obj_desc            - Create a reference to this object
- *              Return_desc         - Where to store the reference
- *              Walk_state          - Current state
+ * PARAMETERS:  obj_desc            - Create a reference to this object
+ *              return_desc         - Where to store the reference
+ *              walk_state          - Current state
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Obtain and return a "reference" to the target object
- *              Common code for the Ref_of_op and the Cond_ref_of_op.
+ *              Common code for the ref_of_op and the cond_ref_of_op.
  *
  ******************************************************************************/
 
@@ -59,7 +58,7 @@
 	acpi_operand_object     *referenced_obj;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_get_object_reference", obj_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ex_get_object_reference", obj_desc);
 
 
 	*return_desc = NULL;
@@ -129,11 +128,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_concat_template
+ * FUNCTION:    acpi_ex_concat_template
  *
- * PARAMETERS:  *Obj_desc           - Object to be converted.  Must be an
+ * PARAMETERS:  *obj_desc           - Object to be converted.  Must be an
  *                                    Integer, Buffer, or String
- *              Walk_state          - Current walk state
+ *              walk_state          - Current walk state
  *
  * RETURN:      Status
  *
@@ -152,14 +151,14 @@
 	u8                      *new_buf;
 	u8                      *end_tag1;
 	u8                      *end_tag2;
-	ACPI_SIZE               length1;
-	ACPI_SIZE               length2;
+	acpi_size               length1;
+	acpi_size               length2;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_concat_template");
+	ACPI_FUNCTION_TRACE ("ex_concat_template");
 
 
-	/* Find the End_tags in each resource template */
+	/* Find the end_tags in each resource template */
 
 	end_tag1 = acpi_ut_get_resource_end_tag (obj_desc1);
 	end_tag2 = acpi_ut_get_resource_end_tag (obj_desc2);
@@ -201,12 +200,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_do_concatenate
+ * FUNCTION:    acpi_ex_do_concatenate
  *
- * PARAMETERS:  Obj_desc1           - First source object
- *              Obj_desc2           - Second source object
- *              Actual_return_desc  - Where to place the return object
- *              Walk_state          - Current walk state
+ * PARAMETERS:  obj_desc1           - First source object
+ *              obj_desc2           - Second source object
+ *              actual_return_desc  - Where to place the return object
+ *              walk_state          - Current walk state
  *
  * RETURN:      Status
  *
@@ -281,11 +280,11 @@
 
 		/* Operand0 is string  */
 
-		new_buf = ACPI_MEM_CALLOCATE ((ACPI_SIZE) obj_desc1->string.length +
-				   (ACPI_SIZE) obj_desc2->string.length + 1);
+		new_buf = ACPI_MEM_CALLOCATE ((acpi_size) obj_desc1->string.length +
+				   (acpi_size) obj_desc2->string.length + 1);
 		if (!new_buf) {
 			ACPI_REPORT_ERROR
-				(("Ex_do_concatenate: String allocation failure\n"));
+				(("ex_do_concatenate: String allocation failure\n"));
 			status = AE_NO_MEMORY;
 			goto cleanup;
 		}
@@ -309,8 +308,8 @@
 		/* Result of two Buffers is a Buffer */
 
 		return_desc = acpi_ut_create_buffer_object (
-				   (ACPI_SIZE) obj_desc1->buffer.length +
-				   (ACPI_SIZE) obj_desc2->buffer.length);
+				   (acpi_size) obj_desc1->buffer.length +
+				   (acpi_size) obj_desc2->buffer.length);
 		if (!return_desc) {
 			return (AE_NO_MEMORY);
 		}
@@ -348,7 +347,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_do_math_op
+ * FUNCTION:    acpi_ex_do_math_op
  *
  * PARAMETERS:  Opcode              - AML opcode
  *              Operand0            - Integer operand #0
@@ -406,12 +405,12 @@
 		return (operand0 * operand1);
 
 
-	case AML_SHIFT_LEFT_OP:         /* Shift_left (Operand, Shift_count, Result) */
+	case AML_SHIFT_LEFT_OP:         /* shift_left (Operand, shift_count, Result) */
 
 		return (operand0 << operand1);
 
 
-	case AML_SHIFT_RIGHT_OP:        /* Shift_right (Operand, Shift_count, Result) */
+	case AML_SHIFT_RIGHT_OP:        /* shift_right (Operand, shift_count, Result) */
 
 		return (operand0 >> operand1);
 
@@ -429,7 +428,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_do_logical_op
+ * FUNCTION:    acpi_ex_do_logical_op
  *
  * PARAMETERS:  Opcode              - AML opcode
  *              Operand0            - Integer operand #0
diff -Nru a/drivers/acpi/executer/exmutex.c b/drivers/acpi/executer/exmutex.c
--- a/drivers/acpi/executer/exmutex.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/acpi/executer/exmutex.c	Mon Dec 23 21:21:59 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Module Name: exmutex - ASL Mutex Acquire/Release functions
- *              $Revision: 17 $
  *
  *****************************************************************************/
 
@@ -34,13 +33,13 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_unlink_mutex
+ * FUNCTION:    acpi_ex_unlink_mutex
  *
- * PARAMETERS:  *Obj_desc           - The mutex to be unlinked
+ * PARAMETERS:  *obj_desc           - The mutex to be unlinked
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Remove a mutex from the "Acquired_mutex" list
+ * DESCRIPTION: Remove a mutex from the "acquired_mutex" list
  *
  ******************************************************************************/
 
@@ -48,7 +47,7 @@
 acpi_ex_unlink_mutex (
 	acpi_operand_object     *obj_desc)
 {
-	ACPI_THREAD_STATE       *thread = obj_desc->mutex.owner_thread;
+	acpi_thread_state       *thread = obj_desc->mutex.owner_thread;
 
 
 	if (!thread) {
@@ -70,21 +69,21 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_link_mutex
+ * FUNCTION:    acpi_ex_link_mutex
  *
- * PARAMETERS:  *Obj_desc           - The mutex to be linked
- *              *List_head          - head of the "Acquired_mutex" list
+ * PARAMETERS:  *obj_desc           - The mutex to be linked
+ *              *list_head          - head of the "acquired_mutex" list
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Add a mutex to the "Acquired_mutex" list for this walk
+ * DESCRIPTION: Add a mutex to the "acquired_mutex" list for this walk
  *
  ******************************************************************************/
 
 void
 acpi_ex_link_mutex (
 	acpi_operand_object     *obj_desc,
-	ACPI_THREAD_STATE       *thread)
+	acpi_thread_state       *thread)
 {
 	acpi_operand_object     *list_head;
 
@@ -110,10 +109,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_acquire_mutex
+ * FUNCTION:    acpi_ex_acquire_mutex
  *
- * PARAMETERS:  *Time_desc          - The 'time to delay' object descriptor
- *              *Obj_desc           - The object descriptor for this op
+ * PARAMETERS:  *time_desc          - The 'time to delay' object descriptor
+ *              *obj_desc           - The object descriptor for this op
  *
  * RETURN:      Status
  *
@@ -130,7 +129,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_acquire_mutex", obj_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ex_acquire_mutex", obj_desc);
 
 
 	if (!obj_desc) {
@@ -150,7 +149,7 @@
 	 * mutex.  This mechanism provides some deadlock prevention
 	 */
 	if (walk_state->thread->current_sync_level > obj_desc->mutex.sync_level) {
-		ACPI_REPORT_ERROR (("Cannot acquire Mutex [%4.4s], incorrect Sync_level\n",
+		ACPI_REPORT_ERROR (("Cannot acquire Mutex [%4.4s], incorrect sync_level\n",
 				obj_desc->mutex.node->name.ascii));
 		return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
 	}
@@ -173,7 +172,7 @@
 
 	status = acpi_ex_system_acquire_mutex (time_desc, obj_desc);
 	if (ACPI_FAILURE (status)) {
-		/* Includes failure from a timeout on Time_desc */
+		/* Includes failure from a timeout on time_desc */
 
 		return_ACPI_STATUS (status);
 	}
@@ -195,9 +194,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_release_mutex
+ * FUNCTION:    acpi_ex_release_mutex
  *
- * PARAMETERS:  *Obj_desc           - The object descriptor for this op
+ * PARAMETERS:  *obj_desc           - The object descriptor for this op
  *
  * RETURN:      Status
  *
@@ -213,7 +212,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_release_mutex");
+	ACPI_FUNCTION_TRACE ("ex_release_mutex");
 
 
 	if (!obj_desc) {
@@ -252,7 +251,7 @@
 	 * equal to the current sync level
 	 */
 	if (obj_desc->mutex.sync_level > walk_state->thread->current_sync_level) {
-		ACPI_REPORT_ERROR (("Cannot release Mutex [%4.4s], incorrect Sync_level\n",
+		ACPI_REPORT_ERROR (("Cannot release Mutex [%4.4s], incorrect sync_level\n",
 				obj_desc->mutex.node->name.ascii));
 		return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
 	}
@@ -286,9 +285,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_release_all_mutexes
+ * FUNCTION:    acpi_ex_release_all_mutexes
  *
- * PARAMETERS:  *Mutex_list           - Head of the mutex list
+ * PARAMETERS:  *mutex_list           - Head of the mutex list
  *
  * RETURN:      Status
  *
@@ -298,7 +297,7 @@
 
 void
 acpi_ex_release_all_mutexes (
-	ACPI_THREAD_STATE       *thread)
+	acpi_thread_state       *thread)
 {
 	acpi_operand_object     *next = thread->acquired_mutex_list;
 	acpi_operand_object     *this;
diff -Nru a/drivers/acpi/executer/exnames.c b/drivers/acpi/executer/exnames.c
--- a/drivers/acpi/executer/exnames.c	Mon Dec 23 21:21:52 2002
+++ b/drivers/acpi/executer/exnames.c	Mon Dec 23 21:21:52 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Module Name: exnames - interpreter/scanner name load/execute
- *              $Revision: 93 $
  *
  *****************************************************************************/
 
@@ -43,11 +42,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_allocate_name_string
+ * FUNCTION:    acpi_ex_allocate_name_string
  *
- * PARAMETERS:  Prefix_count        - Count of parent levels. Special cases:
+ * PARAMETERS:  prefix_count        - Count of parent levels. Special cases:
  *                                    (-1) = root,  0 = none
- *              Num_name_segs       - count of 4-character name segments
+ *              num_name_segs       - count of 4-character name segments
  *
  * RETURN:      A pointer to the allocated string segment.  This segment must
  *              be deleted by the caller.
@@ -66,11 +65,11 @@
 	char                    *name_string;
 	u32                      size_needed;
 
-	ACPI_FUNCTION_TRACE ("Ex_allocate_name_string");
+	ACPI_FUNCTION_TRACE ("ex_allocate_name_string");
 
 
 	/*
-	 * Allow room for all \ and ^ prefixes, all segments, and a Multi_name_prefix.
+	 * Allow room for all \ and ^ prefixes, all segments, and a multi_name_prefix.
 	 * Also, one byte for the null terminator.
 	 * This may actually be somewhat longer than needed.
 	 */
@@ -89,7 +88,7 @@
 	 */
 	name_string = ACPI_MEM_ALLOCATE (size_needed);
 	if (!name_string) {
-		ACPI_REPORT_ERROR (("Ex_allocate_name_string: Could not allocate size %d\n", size_needed));
+		ACPI_REPORT_ERROR (("ex_allocate_name_string: Could not allocate size %d\n", size_needed));
 		return_PTR (NULL);
 	}
 
@@ -122,7 +121,7 @@
 	}
 
 	/*
-	 * Terminate string following prefixes. Acpi_ex_name_segment() will
+	 * Terminate string following prefixes. acpi_ex_name_segment() will
 	 * append the segment(s)
 	 */
 	*temp_ptr = 0;
@@ -132,9 +131,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_name_segment
+ * FUNCTION:    acpi_ex_name_segment
  *
- * PARAMETERS:  Interpreter_mode    - Current running mode (load1/Load2/Exec)
+ * PARAMETERS:  interpreter_mode    - Current running mode (load1/Load2/Exec)
  *
  * RETURN:      Status
  *
@@ -153,7 +152,7 @@
 	char                    char_buf[5];
 
 
-	ACPI_FUNCTION_TRACE ("Ex_name_segment");
+	ACPI_FUNCTION_TRACE ("ex_name_segment");
 
 
 	/*
@@ -219,9 +218,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_get_name_string
+ * FUNCTION:    acpi_ex_get_name_string
  *
- * PARAMETERS:  Data_type           - Data type to be associated with this name
+ * PARAMETERS:  data_type           - Data type to be associated with this name
  *
  * RETURN:      Status
  *
@@ -244,13 +243,13 @@
 	u8                      has_prefix = FALSE;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_get_name_string", aml_address);
+	ACPI_FUNCTION_TRACE_PTR ("ex_get_name_string", aml_address);
 
 
 	if (ACPI_TYPE_LOCAL_REGION_FIELD == data_type  ||
 		ACPI_TYPE_LOCAL_BANK_FIELD == data_type    ||
 		ACPI_TYPE_LOCAL_INDEX_FIELD == data_type) {
-		/* Disallow prefixes for types associated with Field_unit names */
+		/* Disallow prefixes for types associated with field_unit names */
 
 		name_string = acpi_ex_allocate_name_string (0, 1);
 		if (!name_string) {
@@ -262,17 +261,17 @@
 	}
 	else {
 		/*
-		 * Data_type is not a field name.
+		 * data_type is not a field name.
 		 * Examine first character of name for root or parent prefix operators
 		 */
 		switch (*aml_address) {
 		case AML_ROOT_PREFIX:
 
-			ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Root_prefix(\\) at %p\n", aml_address));
+			ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "root_prefix(\\) at %p\n", aml_address));
 
 			/*
-			 * Remember that we have a Root_prefix --
-			 * see comment in Acpi_ex_allocate_name_string()
+			 * Remember that we have a root_prefix --
+			 * see comment in acpi_ex_allocate_name_string()
 			 */
 			aml_address++;
 			prefix_count = ACPI_UINT32_MAX;
@@ -285,7 +284,7 @@
 			/* Increment past possibly multiple parent prefixes */
 
 			do {
-				ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Parent_prefix (^) at %p\n", aml_address));
+				ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "parent_prefix (^) at %p\n", aml_address));
 
 				aml_address++;
 				prefix_count++;
@@ -309,7 +308,7 @@
 		switch (*aml_address) {
 		case AML_DUAL_NAME_PREFIX:
 
-			ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Dual_name_prefix at %p\n", aml_address));
+			ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "dual_name_prefix at %p\n", aml_address));
 
 			aml_address++;
 			name_string = acpi_ex_allocate_name_string (prefix_count, 2);
@@ -331,7 +330,7 @@
 
 		case AML_MULTI_NAME_PREFIX_OP:
 
-			ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Multi_name_prefix at %p\n", aml_address));
+			ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "multi_name_prefix at %p\n", aml_address));
 
 			/* Fetch count of segments remaining in name path */
 
@@ -359,10 +358,10 @@
 
 		case 0:
 
-			/* Null_name valid as of 8-12-98 ASL/AML Grammar Update */
+			/* null_name valid as of 8-12-98 ASL/AML Grammar Update */
 
 			if (prefix_count == ACPI_UINT32_MAX) {
-				ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Name_seg is \"\\\" followed by NULL\n"));
+				ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "name_seg is \"\\\" followed by NULL\n"));
 			}
 
 			/* Consume the NULL byte */
@@ -396,7 +395,7 @@
 		/* Ran out of segments after processing a prefix */
 
 		ACPI_REPORT_ERROR (
-			("Ex_do_name: Malformed Name at %p\n", name_string));
+			("ex_do_name: Malformed Name at %p\n", name_string));
 		status = AE_AML_BAD_NAME;
 	}
 
diff -Nru a/drivers/acpi/executer/exoparg1.c b/drivers/acpi/executer/exoparg1.c
--- a/drivers/acpi/executer/exoparg1.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/acpi/executer/exoparg1.c	Mon Dec 23 21:22:00 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Module Name: exoparg1 - AML execution - opcodes with 1 argument
- *              $Revision: 146 $
  *
  *****************************************************************************/
 
@@ -61,9 +60,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_opcode_1A_0T_0R
+ * FUNCTION:    acpi_ex_opcode_1A_0T_0R
  *
- * PARAMETERS:  Walk_state          - Current state (contains AML opcode)
+ * PARAMETERS:  walk_state          - Current state (contains AML opcode)
  *
  * RETURN:      Status
  *
@@ -80,37 +79,37 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE_STR ("Ex_opcode_1A_0T_0R", acpi_ps_get_opcode_name (walk_state->opcode));
+	ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_0T_0R", acpi_ps_get_opcode_name (walk_state->opcode));
 
 
 	/* Examine the AML opcode */
 
 	switch (walk_state->opcode) {
-	case AML_RELEASE_OP:    /*  Release (Mutex_object) */
+	case AML_RELEASE_OP:    /*  Release (mutex_object) */
 
 		status = acpi_ex_release_mutex (operand[0], walk_state);
 		break;
 
 
-	case AML_RESET_OP:      /*  Reset (Event_object) */
+	case AML_RESET_OP:      /*  Reset (event_object) */
 
 		status = acpi_ex_system_reset_event (operand[0]);
 		break;
 
 
-	case AML_SIGNAL_OP:     /*  Signal (Event_object) */
+	case AML_SIGNAL_OP:     /*  Signal (event_object) */
 
 		status = acpi_ex_system_signal_event (operand[0]);
 		break;
 
 
-	case AML_SLEEP_OP:      /*  Sleep (Msec_time) */
+	case AML_SLEEP_OP:      /*  Sleep (msec_time) */
 
 		status = acpi_ex_system_do_suspend ((u32) operand[0]->integer.value);
 		break;
 
 
-	case AML_STALL_OP:      /*  Stall (Usec_time) */
+	case AML_STALL_OP:      /*  Stall (usec_time) */
 
 		status = acpi_ex_system_do_stall ((u32) operand[0]->integer.value);
 		break;
@@ -124,7 +123,7 @@
 
 	default:                /*  Unknown opcode  */
 
-		ACPI_REPORT_ERROR (("Acpi_ex_opcode_1A_0T_0R: Unknown opcode %X\n",
+		ACPI_REPORT_ERROR (("acpi_ex_opcode_1A_0T_0R: Unknown opcode %X\n",
 			walk_state->opcode));
 		status = AE_AML_BAD_OPCODE;
 		break;
@@ -136,9 +135,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_opcode_1A_1T_0R
+ * FUNCTION:    acpi_ex_opcode_1A_1T_0R
  *
- * PARAMETERS:  Walk_state          - Current state (contains AML opcode)
+ * PARAMETERS:  walk_state          - Current state (contains AML opcode)
  *
  * RETURN:      Status
  *
@@ -155,7 +154,7 @@
 	acpi_operand_object     **operand = &walk_state->operands[0];
 
 
-	ACPI_FUNCTION_TRACE_STR ("Ex_opcode_1A_1T_0R", acpi_ps_get_opcode_name (walk_state->opcode));
+	ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_1T_0R", acpi_ps_get_opcode_name (walk_state->opcode));
 
 
 	/* Examine the AML opcode */
@@ -168,7 +167,7 @@
 
 	default:                        /* Unknown opcode */
 
-		ACPI_REPORT_ERROR (("Acpi_ex_opcode_1A_1T_0R: Unknown opcode %X\n",
+		ACPI_REPORT_ERROR (("acpi_ex_opcode_1A_1T_0R: Unknown opcode %X\n",
 			walk_state->opcode));
 		status = AE_AML_BAD_OPCODE;
 		goto cleanup;
@@ -183,9 +182,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_opcode_1A_1T_1R
+ * FUNCTION:    acpi_ex_opcode_1A_1T_1R
  *
- * PARAMETERS:  Walk_state          - Current state (contains AML opcode)
+ * PARAMETERS:  walk_state          - Current state (contains AML opcode)
  *
  * RETURN:      Status
  *
@@ -208,7 +207,7 @@
 	acpi_integer            digit;
 
 
-	ACPI_FUNCTION_TRACE_STR ("Ex_opcode_1A_1T_1R", acpi_ps_get_opcode_name (walk_state->opcode));
+	ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_1T_1R", acpi_ps_get_opcode_name (walk_state->opcode));
 
 
 	/* Examine the AML opcode */
@@ -236,7 +235,7 @@
 			break;
 
 
-		case AML_FIND_SET_LEFT_BIT_OP:  /* Find_set_left_bit (Operand, Result) */
+		case AML_FIND_SET_LEFT_BIT_OP:  /* find_set_left_bit (Operand, Result) */
 
 			return_desc->integer.value = operand[0]->integer.value;
 
@@ -252,7 +251,7 @@
 			break;
 
 
-		case AML_FIND_SET_RIGHT_BIT_OP: /* Find_set_right_bit (Operand, Result) */
+		case AML_FIND_SET_RIGHT_BIT_OP: /* find_set_right_bit (Operand, Result) */
 
 			return_desc->integer.value = operand[0]->integer.value;
 
@@ -270,7 +269,7 @@
 			break;
 
 
-		case AML_FROM_BCD_OP:           /* From_bcd (BCDValue, Result) */
+		case AML_FROM_BCD_OP:           /* from_bcd (BCDValue, Result) */
 
 			/*
 			 * The 64-bit ACPI integer can hold 16 4-bit BCD integers
@@ -303,7 +302,7 @@
 			break;
 
 
-		case AML_TO_BCD_OP:             /* To_bcd (Operand, Result) */
+		case AML_TO_BCD_OP:             /* to_bcd (Operand, Result) */
 
 			if (operand[0]->integer.value > ACPI_MAX_BCD_VALUE) {
 				ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "BCD overflow: %8.8X%8.8X\n",
@@ -332,7 +331,7 @@
 			break;
 
 
-		case AML_COND_REF_OF_OP:        /* Cond_ref_of (Source_object, Result) */
+		case AML_COND_REF_OF_OP:        /* cond_ref_of (source_object, Result) */
 
 			/*
 			 * This op is a little strange because the internal return value is
@@ -407,32 +406,32 @@
 		break;
 
 
-	case AML_TO_DECSTRING_OP:       /* To_decimal_string (Data, Result) */
+	case AML_TO_DECSTRING_OP:       /* to_decimal_string (Data, Result) */
 
 		status = acpi_ex_convert_to_string (operand[0], &return_desc, 10, ACPI_UINT32_MAX, walk_state);
 		break;
 
 
-	case AML_TO_HEXSTRING_OP:       /* To_hex_string (Data, Result) */
+	case AML_TO_HEXSTRING_OP:       /* to_hex_string (Data, Result) */
 
 		status = acpi_ex_convert_to_string (operand[0], &return_desc, 16, ACPI_UINT32_MAX, walk_state);
 		break;
 
 
-	case AML_TO_BUFFER_OP:          /* To_buffer (Data, Result) */
+	case AML_TO_BUFFER_OP:          /* to_buffer (Data, Result) */
 
 		status = acpi_ex_convert_to_buffer (operand[0], &return_desc, walk_state);
 		break;
 
 
-	case AML_TO_INTEGER_OP:         /* To_integer (Data, Result) */
+	case AML_TO_INTEGER_OP:         /* to_integer (Data, Result) */
 
 		status = acpi_ex_convert_to_integer (operand[0], &return_desc, walk_state);
 		break;
 
 
-	case AML_SHIFT_LEFT_BIT_OP:     /*  Shift_left_bit (Source, Bit_num) */
-	case AML_SHIFT_RIGHT_BIT_OP:    /*  Shift_right_bit (Source, Bit_num) */
+	case AML_SHIFT_LEFT_BIT_OP:     /*  shift_left_bit (Source, bit_num) */
+	case AML_SHIFT_RIGHT_BIT_OP:    /*  shift_right_bit (Source, bit_num) */
 
 		/*
 		 * These are two obsolete opcodes
@@ -445,7 +444,7 @@
 
 	default:                        /* Unknown opcode */
 
-		ACPI_REPORT_ERROR (("Acpi_ex_opcode_1A_1T_1R: Unknown opcode %X\n",
+		ACPI_REPORT_ERROR (("acpi_ex_opcode_1A_1T_1R: Unknown opcode %X\n",
 			walk_state->opcode));
 		status = AE_AML_BAD_OPCODE;
 		goto cleanup;
@@ -475,9 +474,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_opcode_1A_0T_1R
+ * FUNCTION:    acpi_ex_opcode_1A_0T_1R
  *
- * PARAMETERS:  Walk_state          - Current state (contains AML opcode)
+ * PARAMETERS:  walk_state          - Current state (contains AML opcode)
  *
  * RETURN:      Status
  *
@@ -497,7 +496,7 @@
 	acpi_integer            value;
 
 
-	ACPI_FUNCTION_TRACE_STR ("Ex_opcode_1A_0T_0R", acpi_ps_get_opcode_name (walk_state->opcode));
+	ACPI_FUNCTION_TRACE_STR ("ex_opcode_1A_0T_0R", acpi_ps_get_opcode_name (walk_state->opcode));
 
 
 	/* Examine the AML opcode */
@@ -530,8 +529,8 @@
 		}
 
 		/*
-		 * Convert the Return_desc Reference to a Number
-		 * (This removes a reference on the Return_desc object)
+		 * Convert the return_desc Reference to a Number
+		 * (This removes a reference on the return_desc object)
 		 */
 		status = acpi_ex_resolve_operands (AML_LNOT_OP, &return_desc, walk_state);
 		if (ACPI_FAILURE (status)) {
@@ -542,7 +541,7 @@
 		}
 
 		/*
-		 * Return_desc is now guaranteed to be an Integer object
+		 * return_desc is now guaranteed to be an Integer object
 		 * Do the actual increment or decrement
 		 */
 		if (AML_INCREMENT_OP == walk_state->opcode) {
@@ -558,7 +557,7 @@
 		break;
 
 
-	case AML_TYPE_OP:               /* Object_type (Source_object) */
+	case AML_TYPE_OP:               /* object_type (source_object) */
 
 		/* Get the type of the base object */
 
@@ -579,7 +578,7 @@
 		break;
 
 
-	case AML_SIZE_OF_OP:            /* Size_of (Source_object) */
+	case AML_SIZE_OF_OP:            /* size_of (source_object) */
 
 		/* Get the base object */
 
@@ -607,7 +606,7 @@
 			break;
 
 		default:
-			ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Size_of, Not Buf/Str/Pkg - found type %s\n",
+			ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "size_of, Not Buf/Str/Pkg - found type %s\n",
 				acpi_ut_get_type_name (type)));
 			status = AE_AML_OPERAND_TYPE;
 			goto cleanup;
@@ -627,7 +626,7 @@
 		break;
 
 
-	case AML_REF_OF_OP:             /* Ref_of (Source_object) */
+	case AML_REF_OF_OP:             /* ref_of (source_object) */
 
 		status = acpi_ex_get_object_reference (operand[0], &return_desc, walk_state);
 		if (ACPI_FAILURE (status)) {
@@ -636,7 +635,7 @@
 		break;
 
 
-	case AML_DEREF_OF_OP:           /* Deref_of (Obj_reference | String) */
+	case AML_DEREF_OF_OP:           /* deref_of (obj_reference | String) */
 
 		/* Check for a method local or argument, or standalone String */
 
@@ -644,7 +643,7 @@
 			switch (ACPI_GET_OBJECT_TYPE (operand[0])) {
 			case ACPI_TYPE_LOCAL_REFERENCE:
 				/*
-				 * This is a Deref_of (Local_x | Arg_x)
+				 * This is a deref_of (local_x | arg_x)
 				 *
 				 * Must resolve/dereference the local/arg reference first
 				 */
@@ -688,7 +687,7 @@
 			case ACPI_TYPE_STRING:
 
 				/*
-				 * This is a Deref_of (String). The string is a reference to a named ACPI object.
+				 * This is a deref_of (String). The string is a reference to a named ACPI object.
 				 *
 				 * 1) Find the owning Node
 				 * 2) Dereference the node to an actual object.  Could be a Field, so we nee
@@ -717,16 +716,16 @@
 
 		if (ACPI_GET_DESCRIPTOR_TYPE (operand[0]) == ACPI_DESC_TYPE_NAMED) {
 			/*
-			 * This is a Deref_of (Object_reference)
+			 * This is a deref_of (object_reference)
 			 * Get the actual object from the Node (This is the dereference).
-			 * -- This case may only happen when a Local_x or Arg_x is dereferenced above.
+			 * -- This case may only happen when a local_x or arg_x is dereferenced above.
 			 */
 			return_desc = acpi_ns_get_attached_object ((acpi_namespace_node *) operand[0]);
 		}
 		else {
 			/*
 			 * This must be a reference object produced by either the Index() or
-			 * Ref_of() operator
+			 * ref_of() operator
 			 */
 			switch (operand[0]->reference.opcode) {
 			case AML_INDEX_OP:
@@ -789,7 +788,7 @@
 
 				default:
 
-					ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Index Target_type %X in obj %p\n",
+					ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Index target_type %X in obj %p\n",
 						operand[0]->reference.target_type, operand[0]));
 					status = AE_AML_OPERAND_TYPE;
 					goto cleanup;
@@ -825,7 +824,7 @@
 
 	default:
 
-		ACPI_REPORT_ERROR (("Acpi_ex_opcode_1A_0T_1R: Unknown opcode %X\n",
+		ACPI_REPORT_ERROR (("acpi_ex_opcode_1A_0T_1R: Unknown opcode %X\n",
 			walk_state->opcode));
 		status = AE_AML_BAD_OPCODE;
 		goto cleanup;
diff -Nru a/drivers/acpi/executer/exoparg2.c b/drivers/acpi/executer/exoparg2.c
--- a/drivers/acpi/executer/exoparg2.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/acpi/executer/exoparg2.c	Mon Dec 23 21:21:55 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: exoparg2 - AML execution - opcodes with 2 arguments
- *              $Revision: 116 $
  *
  *****************************************************************************/
 
@@ -60,9 +59,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_opcode_2A_0T_0R
+ * FUNCTION:    acpi_ex_opcode_2A_0T_0R
  *
- * PARAMETERS:  Walk_state          - Current walk state
+ * PARAMETERS:  walk_state          - Current walk state
  *
  * RETURN:      Status
  *
@@ -82,14 +81,14 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE_STR ("Ex_opcode_2A_0T_0R",
+	ACPI_FUNCTION_TRACE_STR ("ex_opcode_2A_0T_0R",
 			acpi_ps_get_opcode_name (walk_state->opcode));
 
 
 	/* Examine the opcode */
 
 	switch (walk_state->opcode) {
-	case AML_NOTIFY_OP:         /* Notify (Notify_object, Notify_value) */
+	case AML_NOTIFY_OP:         /* Notify (notify_object, notify_value) */
 
 		/* The first operand is a namespace node */
 
@@ -119,7 +118,7 @@
 
 	default:
 
-		ACPI_REPORT_ERROR (("Acpi_ex_opcode_2A_0T_0R: Unknown opcode %X\n",
+		ACPI_REPORT_ERROR (("acpi_ex_opcode_2A_0T_0R: Unknown opcode %X\n",
 				walk_state->opcode));
 		status = AE_AML_BAD_OPCODE;
 	}
@@ -130,9 +129,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_opcode_2A_2T_1R
+ * FUNCTION:    acpi_ex_opcode_2A_2T_1R
  *
- * PARAMETERS:  Walk_state          - Current walk state
+ * PARAMETERS:  walk_state          - Current walk state
  *
  * RETURN:      Status
  *
@@ -151,14 +150,14 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE_STR ("Ex_opcode_2A_2T_1R", acpi_ps_get_opcode_name (walk_state->opcode));
+	ACPI_FUNCTION_TRACE_STR ("ex_opcode_2A_2T_1R", acpi_ps_get_opcode_name (walk_state->opcode));
 
 
 	/*
 	 * Execute the opcode
 	 */
 	switch (walk_state->opcode) {
-	case AML_DIVIDE_OP:             /* Divide (Dividend, Divisor, Remainder_result Quotient_result) */
+	case AML_DIVIDE_OP:             /* Divide (Dividend, Divisor, remainder_result quotient_result) */
 
 		return_desc1 = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
 		if (!return_desc1) {
@@ -172,7 +171,7 @@
 			goto cleanup;
 		}
 
-		/* Quotient to Return_desc1, remainder to Return_desc2 */
+		/* Quotient to return_desc1, remainder to return_desc2 */
 
 		status = acpi_ut_divide (&operand[0]->integer.value, &operand[1]->integer.value,
 				   &return_desc1->integer.value, &return_desc2->integer.value);
@@ -184,7 +183,7 @@
 
 	default:
 
-		ACPI_REPORT_ERROR (("Acpi_ex_opcode_2A_2T_1R: Unknown opcode %X\n",
+		ACPI_REPORT_ERROR (("acpi_ex_opcode_2A_2T_1R: Unknown opcode %X\n",
 				walk_state->opcode));
 		status = AE_AML_BAD_OPCODE;
 		goto cleanup;
@@ -227,9 +226,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_opcode_2A_1T_1R
+ * FUNCTION:    acpi_ex_opcode_2A_1T_1R
  *
- * PARAMETERS:  Walk_state          - Current walk state
+ * PARAMETERS:  walk_state          - Current walk state
  *
  * RETURN:      Status
  *
@@ -247,10 +246,10 @@
 	acpi_operand_object     *temp_desc = NULL;
 	u32                     index;
 	acpi_status             status = AE_OK;
-	ACPI_SIZE               length;
+	acpi_size               length;
 
 
-	ACPI_FUNCTION_TRACE_STR ("Ex_opcode_2A_1T_1R", acpi_ps_get_opcode_name (walk_state->opcode));
+	ACPI_FUNCTION_TRACE_STR ("ex_opcode_2A_1T_1R", acpi_ps_get_opcode_name (walk_state->opcode));
 
 
 	/*
@@ -273,7 +272,7 @@
 
 
 	switch (walk_state->opcode) {
-	case AML_MOD_OP:                /* Mod (Dividend, Divisor, Remainder_result (ACPI 2.0) */
+	case AML_MOD_OP:                /* Mod (Dividend, Divisor, remainder_result (ACPI 2.0) */
 
 		return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
 		if (!return_desc) {
@@ -281,7 +280,7 @@
 			goto cleanup;
 		}
 
-		/* Return_desc will contain the remainder */
+		/* return_desc will contain the remainder */
 
 		status = acpi_ut_divide (&operand[0]->integer.value, &operand[1]->integer.value,
 				  NULL, &return_desc->integer.value);
@@ -330,7 +329,7 @@
 		break;
 
 
-	case AML_TO_STRING_OP:          /* To_string (Buffer, Length, Result) (ACPI 2.0) */
+	case AML_TO_STRING_OP:          /* to_string (Buffer, Length, Result) (ACPI 2.0) */
 
 		/*
 		 * Input object is guaranteed to be a buffer at this point (it may have
@@ -383,7 +382,7 @@
 		break;
 
 
-	case AML_CONCAT_RES_OP:         /* Concatenate_res_template (Buffer, Buffer, Result) (ACPI 2.0) */
+	case AML_CONCAT_RES_OP:         /* concatenate_res_template (Buffer, Buffer, Result) (ACPI 2.0) */
 
 		status = acpi_ex_concat_template (operand[0], operand[1], &return_desc, walk_state);
 		break;
@@ -449,7 +448,7 @@
 
 	default:
 
-		ACPI_REPORT_ERROR (("Acpi_ex_opcode_2A_1T_1R: Unknown opcode %X\n",
+		ACPI_REPORT_ERROR (("acpi_ex_opcode_2A_1T_1R: Unknown opcode %X\n",
 				walk_state->opcode));
 		status = AE_AML_BAD_OPCODE;
 		break;
@@ -460,7 +459,7 @@
 
 	if (ACPI_SUCCESS (status)) {
 		/*
-		 * Store the result of the operation (which is now in Return_desc) into
+		 * Store the result of the operation (which is now in return_desc) into
 		 * the Target descriptor.
 		 */
 		status = acpi_ex_store (return_desc, operand[2], walk_state);
@@ -488,9 +487,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_opcode_2A_0T_1R
+ * FUNCTION:    acpi_ex_opcode_2A_0T_1R
  *
- * PARAMETERS:  Walk_state          - Current walk state
+ * PARAMETERS:  walk_state          - Current walk state
  *
  * RETURN:      Status
  *
@@ -508,7 +507,7 @@
 	u8                      logical_result = FALSE;
 
 
-	ACPI_FUNCTION_TRACE_STR ("Ex_opcode_2A_0T_1R", acpi_ps_get_opcode_name (walk_state->opcode));
+	ACPI_FUNCTION_TRACE_STR ("ex_opcode_2A_0T_1R", acpi_ps_get_opcode_name (walk_state->opcode));
 
 
 	/* Create the internal return object */
@@ -522,7 +521,7 @@
 	/*
 	 * Execute the Opcode
 	 */
-	if (walk_state->op_info->flags & AML_LOGICAL) /* Logical_op (Operand0, Operand1) */ {
+	if (walk_state->op_info->flags & AML_LOGICAL) /* logical_op (Operand0, Operand1) */ {
 		logical_result = acpi_ex_do_logical_op (walk_state->opcode,
 				 operand[0]->integer.value,
 				 operand[1]->integer.value);
@@ -531,7 +530,7 @@
 
 
 	switch (walk_state->opcode) {
-	case AML_ACQUIRE_OP:            /* Acquire (Mutex_object, Timeout) */
+	case AML_ACQUIRE_OP:            /* Acquire (mutex_object, Timeout) */
 
 		status = acpi_ex_acquire_mutex (operand[1], operand[0], walk_state);
 		if (status == AE_TIME) {
@@ -541,7 +540,7 @@
 		break;
 
 
-	case AML_WAIT_OP:               /* Wait (Event_object, Timeout) */
+	case AML_WAIT_OP:               /* Wait (event_object, Timeout) */
 
 		status = acpi_ex_system_wait_event (operand[1], operand[0]);
 		if (status == AE_TIME) {
@@ -553,7 +552,7 @@
 
 	default:
 
-		ACPI_REPORT_ERROR (("Acpi_ex_opcode_2A_0T_1R: Unknown opcode %X\n",
+		ACPI_REPORT_ERROR (("acpi_ex_opcode_2A_0T_1R: Unknown opcode %X\n",
 			walk_state->opcode));
 		status = AE_AML_BAD_OPCODE;
 		goto cleanup;
@@ -562,7 +561,7 @@
 
 store_logical_result:
 	/*
-	 * Set return value to according to Logical_result. logical TRUE (all ones)
+	 * Set return value to according to logical_result. logical TRUE (all ones)
 	 * Default is FALSE (zero)
 	 */
 	if (logical_result) {
diff -Nru a/drivers/acpi/executer/exoparg3.c b/drivers/acpi/executer/exoparg3.c
--- a/drivers/acpi/executer/exoparg3.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/acpi/executer/exoparg3.c	Mon Dec 23 21:21:50 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Module Name: exoparg3 - AML execution - opcodes with 3 arguments
- *              $Revision: 15 $
  *
  *****************************************************************************/
 
@@ -60,9 +59,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_opcode_3A_0T_0R
+ * FUNCTION:    acpi_ex_opcode_3A_0T_0R
  *
- * PARAMETERS:  Walk_state          - Current walk state
+ * PARAMETERS:  walk_state          - Current walk state
  *
  * RETURN:      Status
  *
@@ -75,24 +74,24 @@
 	acpi_walk_state         *walk_state)
 {
 	acpi_operand_object     **operand = &walk_state->operands[0];
-	ACPI_SIGNAL_FATAL_INFO  *fatal;
+	acpi_signal_fatal_info  *fatal;
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE_STR ("Ex_opcode_3A_0T_0R", acpi_ps_get_opcode_name (walk_state->opcode));
+	ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_0T_0R", acpi_ps_get_opcode_name (walk_state->opcode));
 
 
 	switch (walk_state->opcode) {
 
-	case AML_FATAL_OP:          /* Fatal (Fatal_type Fatal_code Fatal_arg)   */
+	case AML_FATAL_OP:          /* Fatal (fatal_type fatal_code fatal_arg)   */
 
 		ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
-			"Fatal_op: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
+			"fatal_op: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
 			(u32) operand[0]->integer.value, (u32) operand[1]->integer.value,
 			(u32) operand[2]->integer.value));
 
 
-		fatal = ACPI_MEM_ALLOCATE (sizeof (ACPI_SIGNAL_FATAL_INFO));
+		fatal = ACPI_MEM_ALLOCATE (sizeof (acpi_signal_fatal_info));
 		if (fatal) {
 			fatal->type     = (u32) operand[0]->integer.value;
 			fatal->code     = (u32) operand[1]->integer.value;
@@ -112,7 +111,7 @@
 
 	default:
 
-		ACPI_REPORT_ERROR (("Acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n",
+		ACPI_REPORT_ERROR (("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n",
 				walk_state->opcode));
 		status = AE_AML_BAD_OPCODE;
 		goto cleanup;
@@ -127,9 +126,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_opcode_3A_1T_1R
+ * FUNCTION:    acpi_ex_opcode_3A_1T_1R
  *
- * PARAMETERS:  Walk_state          - Current walk state
+ * PARAMETERS:  walk_state          - Current walk state
  *
  * RETURN:      Status
  *
@@ -145,11 +144,11 @@
 	acpi_operand_object     *return_desc = NULL;
 	char                    *buffer;
 	acpi_status             status = AE_OK;
-	NATIVE_UINT             index;
-	ACPI_SIZE               length;
+	acpi_native_uint        index;
+	acpi_size               length;
 
 
-	ACPI_FUNCTION_TRACE_STR ("Ex_opcode_3A_1T_1R", acpi_ps_get_opcode_name (walk_state->opcode));
+	ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_1T_1R", acpi_ps_get_opcode_name (walk_state->opcode));
 
 
 	switch (walk_state->opcode) {
@@ -167,8 +166,8 @@
 
 		/* Get the Integer values from the objects */
 
-		index = (NATIVE_UINT) operand[1]->integer.value;
-		length = (ACPI_SIZE) operand[2]->integer.value;
+		index = (acpi_native_uint) operand[1]->integer.value;
+		length = (acpi_size) operand[2]->integer.value;
 
 		/*
 		 * If the index is beyond the length of the String/Buffer, or if the
@@ -180,12 +179,12 @@
 
 			if ((index + length) >
 				operand[0]->string.length) {
-				length = (ACPI_SIZE) operand[0]->string.length - index;
+				length = (acpi_size) operand[0]->string.length - index;
 			}
 
 			/* Allocate a new buffer for the String/Buffer */
 
-			buffer = ACPI_MEM_CALLOCATE ((ACPI_SIZE) length + 1);
+			buffer = ACPI_MEM_CALLOCATE ((acpi_size) length + 1);
 			if (!buffer) {
 				status = AE_NO_MEMORY;
 				goto cleanup;
@@ -206,7 +205,7 @@
 
 	default:
 
-		ACPI_REPORT_ERROR (("Acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n",
+		ACPI_REPORT_ERROR (("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n",
 				walk_state->opcode));
 		status = AE_AML_BAD_OPCODE;
 		goto cleanup;
diff -Nru a/drivers/acpi/executer/exoparg6.c b/drivers/acpi/executer/exoparg6.c
--- a/drivers/acpi/executer/exoparg6.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/acpi/executer/exoparg6.c	Mon Dec 23 21:21:58 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Module Name: exoparg6 - AML execution - opcodes with 6 arguments
- *              $Revision: 11 $
  *
  *****************************************************************************/
 
@@ -60,11 +59,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_do_match
+ * FUNCTION:    acpi_ex_do_match
  *
- * PARAMETERS:  Match_op        - The AML match operand
- *              Package_value   - Value from the target package
- *              Match_value     - Value to be matched
+ * PARAMETERS:  match_op        - The AML match operand
+ *              package_value   - Value from the target package
+ *              match_value     - Value to be matched
  *
  * RETURN:      TRUE if the match is successful, FALSE otherwise
  *
@@ -137,9 +136,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_opcode_6A_0T_1R
+ * FUNCTION:    acpi_ex_opcode_6A_0T_1R
  *
- * PARAMETERS:  Walk_state          - Current walk state
+ * PARAMETERS:  walk_state          - Current walk state
  *
  * RETURN:      Status
  *
@@ -158,14 +157,14 @@
 	acpi_operand_object     *this_element;
 
 
-	ACPI_FUNCTION_TRACE_STR ("Ex_opcode_6A_0T_1R", acpi_ps_get_opcode_name (walk_state->opcode));
+	ACPI_FUNCTION_TRACE_STR ("ex_opcode_6A_0T_1R", acpi_ps_get_opcode_name (walk_state->opcode));
 
 
 	switch (walk_state->opcode) {
 	case AML_MATCH_OP:
 		/*
-		 * Match (Search_package[0], Match_op1[1], Match_object1[2],
-		 *                          Match_op2[3], Match_object2[4], Start_index[5])
+		 * Match (search_package[0], match_op1[1], match_object1[2],
+		 *                          match_op2[3], match_object2[4], start_index[5])
 		 */
 
 		/* Validate match comparison sub-opcodes */
@@ -201,7 +200,7 @@
 		 * and the next should be examined.
 		 *
 		 * Upon finding a match, the loop will terminate via "break" at
-		 * the bottom.  If it terminates "normally", Match_value will be -1
+		 * the bottom.  If it terminates "normally", match_value will be -1
 		 * (its initial value) indicating that no match was found.  When
 		 * returned as a Number, this will produce the Ones value as specified.
 		 */
@@ -247,7 +246,7 @@
 
 	default:
 
-		ACPI_REPORT_ERROR (("Acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n",
+		ACPI_REPORT_ERROR (("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n",
 				walk_state->opcode));
 		status = AE_AML_BAD_OPCODE;
 		goto cleanup;
diff -Nru a/drivers/acpi/executer/exprep.c b/drivers/acpi/executer/exprep.c
--- a/drivers/acpi/executer/exprep.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/executer/exprep.c	Mon Dec 23 21:21:51 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Module Name: exprep - ACPI AML (p-code) execution - field prep utilities
- *              $Revision: 121 $
  *
  *****************************************************************************/
 
@@ -37,15 +36,15 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_decode_field_access
+ * FUNCTION:    acpi_ex_decode_field_access
  *
  * PARAMETERS:  Access          - Encoded field access bits
  *              Length          - Field length.
  *
  * RETURN:      Field granularity (8, 16, 32 or 64) and
- *              Byte_alignment (1, 2, 3, or 4)
+ *              byte_alignment (1, 2, 3, or 4)
  *
- * DESCRIPTION: Decode the Access_type bits of a field definition.
+ * DESCRIPTION: Decode the access_type bits of a field definition.
  *
  ******************************************************************************/
 
@@ -61,7 +60,7 @@
 /*    u32                     Length; */
 
 
-	ACPI_FUNCTION_NAME ("Ex_decode_field_access");
+	ACPI_FUNCTION_NAME ("ex_decode_field_access");
 
 
 	access = (field_flags & AML_FIELD_ACCESS_TYPE_MASK);
@@ -138,8 +137,8 @@
 
 	if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_BUFFER_FIELD) {
 		/*
-		 * Buffer_field access can be on any byte boundary, so the
-		 * Byte_alignment is always 1 byte -- regardless of any Byte_alignment
+		 * buffer_field access can be on any byte boundary, so the
+		 * byte_alignment is always 1 byte -- regardless of any byte_alignment
 		 * implied by the field access type.
 		 */
 		byte_alignment = 1;
@@ -152,14 +151,14 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_prep_common_field_object
+ * FUNCTION:    acpi_ex_prep_common_field_object
  *
- * PARAMETERS:  Obj_desc            - The field object
- *              Field_flags         - Access, Lock_rule, and Update_rule.
- *                                    The format of a Field_flag is described
+ * PARAMETERS:  obj_desc            - The field object
+ *              field_flags         - Access, lock_rule, and update_rule.
+ *                                    The format of a field_flag is described
  *                                    in the ACPI specification
- *              Field_bit_position  - Field start position
- *              Field_bit_length    - Field length in number of bits
+ *              field_bit_position  - Field start position
+ *              field_bit_length    - Field length in number of bits
  *
  * RETURN:      Status
  *
@@ -183,7 +182,7 @@
 	u32                     nearest_byte_address;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_prep_common_field_object");
+	ACPI_FUNCTION_TRACE ("ex_prep_common_field_object");
 
 
 	/*
@@ -198,17 +197,17 @@
 	/*
 	 * Decode the access type so we can compute offsets.  The access type gives
 	 * two pieces of information - the width of each field access and the
-	 * necessary Byte_alignment (address granularity) of the access.
+	 * necessary byte_alignment (address granularity) of the access.
 	 *
-	 * For Any_acc, the Access_bit_width is the largest width that is both
+	 * For any_acc, the access_bit_width is the largest width that is both
 	 * necessary and possible in an attempt to access the whole field in one
-	 * I/O operation.  However, for Any_acc, the Byte_alignment is always one
+	 * I/O operation.  However, for any_acc, the byte_alignment is always one
 	 * byte.
 	 *
-	 * For all Buffer Fields, the Byte_alignment is always one byte.
+	 * For all Buffer Fields, the byte_alignment is always one byte.
 	 *
 	 * For all other access types (Byte, Word, Dword, Qword), the Bitwidth is
-	 * the same (equivalent) as the Byte_alignment.
+	 * the same (equivalent) as the byte_alignment.
 	 */
 	access_bit_width = acpi_ex_decode_field_access (obj_desc, field_flags,
 			  &byte_alignment);
@@ -222,12 +221,12 @@
 			ACPI_DIV_8 (access_bit_width); /* 1, 2, 4,  8 */
 
 	/*
-	 * Base_byte_offset is the address of the start of the field within the
+	 * base_byte_offset is the address of the start of the field within the
 	 * region.  It is the byte address of the first *datum* (field-width data
 	 * unit) of the field. (i.e., the first datum that contains at least the
 	 * first *bit* of the field.)
 	 *
-	 * Note: Byte_alignment is always either equal to the Access_bit_width or 8
+	 * Note: byte_alignment is always either equal to the access_bit_width or 8
 	 * (Byte access), and it defines the addressing granularity of the parent
 	 * region or buffer.
 	 */
@@ -237,7 +236,7 @@
 			ACPI_ROUND_DOWN (nearest_byte_address, byte_alignment);
 
 	/*
-	 * Start_field_bit_offset is the offset of the first bit of the field within
+	 * start_field_bit_offset is the offset of the first bit of the field within
 	 * a field datum.
 	 */
 	obj_desc->common_field.start_field_bit_offset = (u8)
@@ -253,13 +252,13 @@
 	obj_desc->common_field.end_field_valid_bits = (u8)
 		((obj_desc->common_field.start_field_bit_offset + field_bit_length) %
 				  access_bit_width);
-	/* Start_buffer_bit_offset always = 0 */
+	/* start_buffer_bit_offset always = 0 */
 
 	obj_desc->common_field.end_buffer_valid_bits = (u8)
 		(field_bit_length % access_bit_width);
 
 	/*
-	 * Datum_valid_bits is the number of valid field bits in the first
+	 * datum_valid_bits is the number of valid field bits in the first
 	 * field datum.
 	 */
 	obj_desc->common_field.datum_valid_bits  = (u8)
@@ -280,38 +279,38 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_prep_field_value
+ * FUNCTION:    acpi_ex_prep_field_value
  *
  * PARAMETERS:  Node                - Owning Node
- *              Region_node         - Region in which field is being defined
- *              Field_flags         - Access, Lock_rule, and Update_rule.
- *              Field_bit_position  - Field start position
- *              Field_bit_length    - Field length in number of bits
+ *              region_node         - Region in which field is being defined
+ *              field_flags         - Access, lock_rule, and update_rule.
+ *              field_bit_position  - Field start position
+ *              field_bit_length    - Field length in number of bits
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Construct an acpi_operand_object of type Def_field and
+ * DESCRIPTION: Construct an acpi_operand_object of type def_field and
  *              connect it to the parent Node.
  *
  ******************************************************************************/
 
 acpi_status
 acpi_ex_prep_field_value (
-	ACPI_CREATE_FIELD_INFO  *info)
+	acpi_create_field_info  *info)
 {
 	acpi_operand_object     *obj_desc;
 	u32                     type;
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_prep_field_value");
+	ACPI_FUNCTION_TRACE ("ex_prep_field_value");
 
 
 	/* Parameter validation */
 
 	if (info->field_type != ACPI_TYPE_LOCAL_INDEX_FIELD) {
 		if (!info->region_node) {
-			ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null Region_node\n"));
+			ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null region_node\n"));
 			return_ACPI_STATUS (AE_AML_NO_OPERAND);
 		}
 
@@ -354,7 +353,7 @@
 		acpi_ut_add_reference (obj_desc->field.region_obj);
 
 		ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
-			"Region_field: Bitoff=%X Off=%X Gran=%X Region %p\n",
+			"region_field: Bitoff=%X Off=%X Gran=%X Region %p\n",
 			obj_desc->field.start_field_bit_offset, obj_desc->field.base_byte_offset,
 			obj_desc->field.access_byte_width, obj_desc->field.region_obj));
 		break;
@@ -372,7 +371,7 @@
 		acpi_ut_add_reference (obj_desc->bank_field.bank_obj);
 
 		ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
-			"Bank Field: Bit_off=%X Off=%X Gran=%X Region %p Bank_reg %p\n",
+			"Bank Field: bit_off=%X Off=%X Gran=%X Region %p bank_reg %p\n",
 			obj_desc->bank_field.start_field_bit_offset,
 			obj_desc->bank_field.base_byte_offset,
 			obj_desc->field.access_byte_width,
@@ -399,7 +398,7 @@
 		acpi_ut_add_reference (obj_desc->index_field.index_obj);
 
 		ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
-			"Index_field: bitoff=%X off=%X gran=%X Index %p Data %p\n",
+			"index_field: bitoff=%X off=%X gran=%X Index %p Data %p\n",
 			obj_desc->index_field.start_field_bit_offset,
 			obj_desc->index_field.base_byte_offset,
 			obj_desc->field.access_byte_width,
@@ -413,13 +412,13 @@
 	}
 
 	/*
-	 * Store the constructed descriptor (Obj_desc) into the parent Node,
-	 * preserving the current type of that Named_obj.
+	 * Store the constructed descriptor (obj_desc) into the parent Node,
+	 * preserving the current type of that named_obj.
 	 */
 	status = acpi_ns_attach_object (info->field_node, obj_desc,
 			  acpi_ns_get_type (info->field_node));
 
-	ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "set Named_obj %p (%4.4s) val = %p\n",
+	ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "set named_obj %p (%4.4s) val = %p\n",
 			info->field_node, info->field_node->name.ascii, obj_desc));
 
 	/* Remove local reference to the object */
diff -Nru a/drivers/acpi/executer/exregion.c b/drivers/acpi/executer/exregion.c
--- a/drivers/acpi/executer/exregion.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/executer/exregion.c	Mon Dec 23 21:21:51 2002
@@ -1,8 +1,7 @@
 
 /******************************************************************************
  *
- * Module Name: exregion - ACPI default Op_region (address space) handlers
- *              $Revision: 81 $
+ * Module Name: exregion - ACPI default op_region (address space) handlers
  *
  *****************************************************************************/
 
@@ -35,14 +34,14 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_system_memory_space_handler
+ * FUNCTION:    acpi_ex_system_memory_space_handler
  *
  * PARAMETERS:  Function            - Read or Write operation
  *              Address             - Where in the space to read or write
- *              Bit_width           - Field width in bits (8, 16, or 32)
+ *              bit_width           - Field width in bits (8, 16, or 32)
  *              Value               - Pointer to in or out value
- *              Handler_context     - Pointer to Handler's context
- *              Region_context      - Pointer to context specific to the
+ *              handler_context     - Pointer to Handler's context
+ *              region_context      - Pointer to context specific to the
  *                                    accessed region
  *
  * RETURN:      Status
@@ -54,7 +53,7 @@
 acpi_status
 acpi_ex_system_memory_space_handler (
 	u32                     function,
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	u32                     bit_width,
 	acpi_integer            *value,
 	void                    *handler_context,
@@ -64,12 +63,12 @@
 	void                    *logical_addr_ptr = NULL;
 	acpi_mem_space_context  *mem_info = region_context;
 	u32                     length;
-	ACPI_SIZE               window_size;
+	acpi_size               window_size;
 #ifndef _HW_ALIGNMENT_SUPPORT
 	u32                     remainder;
 #endif
 
-	ACPI_FUNCTION_TRACE ("Ex_system_memory_space_handler");
+	ACPI_FUNCTION_TRACE ("ex_system_memory_space_handler");
 
 
 	/* Validate and translate the bit width */
@@ -92,7 +91,7 @@
 		break;
 
 	default:
-		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid System_memory width %d\n",
+		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid system_memory width %d\n",
 			bit_width));
 		return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
 	}
@@ -132,7 +131,7 @@
 		 * Don't attempt to map memory beyond the end of the region, and
 		 * constrain the maximum mapping size to something reasonable.
 		 */
-		window_size = (ACPI_SIZE) ((mem_info->address + mem_info->length) - address);
+		window_size = (acpi_size) ((mem_info->address + mem_info->length) - address);
 		if (window_size > ACPI_SYSMEM_REGION_WINDOW_SIZE) {
 			window_size = ACPI_SYSMEM_REGION_WINDOW_SIZE;
 		}
@@ -162,7 +161,7 @@
 			  ((acpi_integer) address - (acpi_integer) mem_info->mapped_physical_address);
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
-		"System_memory %d (%d width) Address=%8.8X%8.8X\n", function, bit_width,
+		"system_memory %d (%d width) Address=%8.8X%8.8X\n", function, bit_width,
 		ACPI_HIDWORD (address), ACPI_LODWORD (address)));
 
    /*
@@ -196,7 +195,7 @@
 			break;
 #endif
 		default:
-			/* Bit_width was already validated */
+			/* bit_width was already validated */
 			break;
 		}
 		break;
@@ -223,7 +222,7 @@
 #endif
 
 		default:
-			/* Bit_width was already validated */
+			/* bit_width was already validated */
 			break;
 		}
 		break;
@@ -239,14 +238,14 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_system_io_space_handler
+ * FUNCTION:    acpi_ex_system_io_space_handler
  *
  * PARAMETERS:  Function            - Read or Write operation
  *              Address             - Where in the space to read or write
- *              Bit_width           - Field width in bits (8, 16, or 32)
+ *              bit_width           - Field width in bits (8, 16, or 32)
  *              Value               - Pointer to in or out value
- *              Handler_context     - Pointer to Handler's context
- *              Region_context      - Pointer to context specific to the
+ *              handler_context     - Pointer to Handler's context
+ *              region_context      - Pointer to context specific to the
  *                                    accessed region
  *
  * RETURN:      Status
@@ -258,7 +257,7 @@
 acpi_status
 acpi_ex_system_io_space_handler (
 	u32                     function,
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	u32                     bit_width,
 	acpi_integer            *value,
 	void                    *handler_context,
@@ -267,11 +266,11 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_system_io_space_handler");
+	ACPI_FUNCTION_TRACE ("ex_system_io_space_handler");
 
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
-		"System_iO %d (%d width) Address=%8.8X%8.8X\n", function, bit_width,
+		"system_iO %d (%d width) Address=%8.8X%8.8X\n", function, bit_width,
 		ACPI_HIDWORD (address), ACPI_LODWORD (address)));
 
 	/* Decode the function parameter */
@@ -280,12 +279,12 @@
 	case ACPI_READ:
 
 		*value = 0;
-		status = acpi_os_read_port ((ACPI_IO_ADDRESS) address, value, bit_width);
+		status = acpi_os_read_port ((acpi_io_address) address, value, bit_width);
 		break;
 
 	case ACPI_WRITE:
 
-		status = acpi_os_write_port ((ACPI_IO_ADDRESS) address, *value, bit_width);
+		status = acpi_os_write_port ((acpi_io_address) address, *value, bit_width);
 		break;
 
 	default:
@@ -299,14 +298,14 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_pci_config_space_handler
+ * FUNCTION:    acpi_ex_pci_config_space_handler
  *
  * PARAMETERS:  Function            - Read or Write operation
  *              Address             - Where in the space to read or write
- *              Bit_width           - Field width in bits (8, 16, or 32)
+ *              bit_width           - Field width in bits (8, 16, or 32)
  *              Value               - Pointer to in or out value
- *              Handler_context     - Pointer to Handler's context
- *              Region_context      - Pointer to context specific to the
+ *              handler_context     - Pointer to Handler's context
+ *              region_context      - Pointer to context specific to the
  *                                    accessed region
  *
  * RETURN:      Status
@@ -318,7 +317,7 @@
 acpi_status
 acpi_ex_pci_config_space_handler (
 	u32                     function,
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	u32                     bit_width,
 	acpi_integer            *value,
 	void                    *handler_context,
@@ -329,17 +328,17 @@
 	u16                     pci_register;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_pci_config_space_handler");
+	ACPI_FUNCTION_TRACE ("ex_pci_config_space_handler");
 
 
 	/*
-	 *  The arguments to Acpi_os(Read|Write)Pci_configuration are:
+	 *  The arguments to acpi_os(Read|Write)pci_configuration are:
 	 *
-	 *  Pci_segment is the PCI bus segment range 0-31
-	 *  Pci_bus     is the PCI bus number range 0-255
-	 *  Pci_device  is the PCI device number range 0-31
-	 *  Pci_function is the PCI device function number
-	 *  Pci_register is the Config space register range 0-255 bytes
+	 *  pci_segment is the PCI bus segment range 0-31
+	 *  pci_bus     is the PCI bus number range 0-255
+	 *  pci_device  is the PCI device number range 0-31
+	 *  pci_function is the PCI device function number
+	 *  pci_register is the Config space register range 0-255 bytes
 	 *
 	 *  Value - input value for write, output address for read
 	 *
@@ -348,7 +347,7 @@
 	pci_register = (u16) (u32) address;
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
-		"Pci_config %d (%d) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x)\n",
+		"pci_config %d (%d) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x)\n",
 		function, bit_width, pci_id->segment, pci_id->bus, pci_id->device,
 		pci_id->function, pci_register));
 
@@ -376,14 +375,14 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_cmos_space_handler
+ * FUNCTION:    acpi_ex_cmos_space_handler
  *
  * PARAMETERS:  Function            - Read or Write operation
  *              Address             - Where in the space to read or write
- *              Bit_width           - Field width in bits (8, 16, or 32)
+ *              bit_width           - Field width in bits (8, 16, or 32)
  *              Value               - Pointer to in or out value
- *              Handler_context     - Pointer to Handler's context
- *              Region_context      - Pointer to context specific to the
+ *              handler_context     - Pointer to Handler's context
+ *              region_context      - Pointer to context specific to the
  *                                    accessed region
  *
  * RETURN:      Status
@@ -395,7 +394,7 @@
 acpi_status
 acpi_ex_cmos_space_handler (
 	u32                     function,
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	u32                     bit_width,
 	acpi_integer            *value,
 	void                    *handler_context,
@@ -404,7 +403,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_cmos_space_handler");
+	ACPI_FUNCTION_TRACE ("ex_cmos_space_handler");
 
 
 	return_ACPI_STATUS (status);
@@ -413,26 +412,26 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_pci_bar_space_handler
+ * FUNCTION:    acpi_ex_pci_bar_space_handler
  *
  * PARAMETERS:  Function            - Read or Write operation
  *              Address             - Where in the space to read or write
- *              Bit_width           - Field width in bits (8, 16, or 32)
+ *              bit_width           - Field width in bits (8, 16, or 32)
  *              Value               - Pointer to in or out value
- *              Handler_context     - Pointer to Handler's context
- *              Region_context      - Pointer to context specific to the
+ *              handler_context     - Pointer to Handler's context
+ *              region_context      - Pointer to context specific to the
  *                                    accessed region
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Handler for the PCI Bar_target address space (Op Region)
+ * DESCRIPTION: Handler for the PCI bar_target address space (Op Region)
  *
  ******************************************************************************/
 
 acpi_status
 acpi_ex_pci_bar_space_handler (
 	u32                     function,
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	u32                     bit_width,
 	acpi_integer            *value,
 	void                    *handler_context,
@@ -441,7 +440,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_pci_bar_space_handler");
+	ACPI_FUNCTION_TRACE ("ex_pci_bar_space_handler");
 
 
 	return_ACPI_STATUS (status);
@@ -450,14 +449,14 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_data_table_space_handler
+ * FUNCTION:    acpi_ex_data_table_space_handler
  *
  * PARAMETERS:  Function            - Read or Write operation
  *              Address             - Where in the space to read or write
- *              Bit_width           - Field width in bits (8, 16, or 32)
+ *              bit_width           - Field width in bits (8, 16, or 32)
  *              Value               - Pointer to in or out value
- *              Handler_context     - Pointer to Handler's context
- *              Region_context      - Pointer to context specific to the
+ *              handler_context     - Pointer to Handler's context
+ *              region_context      - Pointer to context specific to the
  *                                    accessed region
  *
  * RETURN:      Status
@@ -469,7 +468,7 @@
 acpi_status
 acpi_ex_data_table_space_handler (
 	u32                     function,
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	u32                     bit_width,
 	acpi_integer            *value,
 	void                    *handler_context,
@@ -481,7 +480,7 @@
 	char                    *logical_addr_ptr;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_data_table_space_handler");
+	ACPI_FUNCTION_TRACE ("ex_data_table_space_handler");
 
 
 	logical_addr_ptr = ACPI_PHYSADDR_TO_PTR (address);
diff -Nru a/drivers/acpi/executer/exresnte.c b/drivers/acpi/executer/exresnte.c
--- a/drivers/acpi/executer/exresnte.c	Mon Dec 23 21:21:52 2002
+++ b/drivers/acpi/executer/exresnte.c	Mon Dec 23 21:21:52 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Module Name: exresnte - AML Interpreter object resolution
- *              $Revision: 61 $
  *
  *****************************************************************************/
 
@@ -37,12 +36,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_resolve_node_to_value
+ * FUNCTION:    acpi_ex_resolve_node_to_value
  *
- * PARAMETERS:  Object_ptr      - Pointer to a location that contains
+ * PARAMETERS:  object_ptr      - Pointer to a location that contains
  *                                a pointer to a NS node, and will receive a
  *                                pointer to the resolved object.
- *              Walk_state      - Current state.  Valid only if executing AML
+ *              walk_state      - Current state.  Valid only if executing AML
  *                                code.  NULL if simply resolving an object
  *
  * RETURN:      Status
@@ -74,7 +73,7 @@
 	acpi_object_type        entry_type;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_resolve_node_to_value");
+	ACPI_FUNCTION_TRACE ("ex_resolve_node_to_value");
 
 
 	/*
@@ -85,7 +84,7 @@
 	source_desc = acpi_ns_get_attached_object (node);
 	entry_type = acpi_ns_get_type ((acpi_handle) node);
 
-	ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Entry=%p Source_desc=%p [%s]\n",
+	ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Entry=%p source_desc=%p [%s]\n",
 		 node, source_desc, acpi_ut_get_type_name (entry_type)));
 
 	if (entry_type == ACPI_TYPE_LOCAL_ALIAS) {
@@ -189,7 +188,7 @@
 	case ACPI_TYPE_LOCAL_BANK_FIELD:
 	case ACPI_TYPE_LOCAL_INDEX_FIELD:
 
-		ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Field_read Node=%p Source_desc=%p Type=%X\n",
+		ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "field_read Node=%p source_desc=%p Type=%X\n",
 			node, source_desc, entry_type));
 
 		status = acpi_ex_read_data_from_field (walk_state, source_desc, &obj_desc);
@@ -242,7 +241,7 @@
 
 		return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
 
-	} /* switch (Entry_type) */
+	} /* switch (entry_type) */
 
 
 	/* Put the object descriptor on the stack */
diff -Nru a/drivers/acpi/executer/exresolv.c b/drivers/acpi/executer/exresolv.c
--- a/drivers/acpi/executer/exresolv.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/acpi/executer/exresolv.c	Mon Dec 23 21:21:53 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Module Name: exresolv - AML Interpreter object resolution
- *              $Revision: 118 $
  *
  *****************************************************************************/
 
@@ -38,12 +37,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_resolve_to_value
+ * FUNCTION:    acpi_ex_resolve_to_value
  *
- * PARAMETERS:  **Stack_ptr         - Points to entry on Obj_stack, which can
+ * PARAMETERS:  **stack_ptr         - Points to entry on obj_stack, which can
  *                                    be either an (acpi_operand_object *)
  *                                    or an acpi_handle.
- *              Walk_state          - Current method state
+ *              walk_state          - Current method state
  *
  * RETURN:      Status
  *
@@ -59,7 +58,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_resolve_to_value", stack_ptr);
+	ACPI_FUNCTION_TRACE_PTR ("ex_resolve_to_value", stack_ptr);
 
 
 	if (!stack_ptr || !*stack_ptr) {
@@ -68,9 +67,9 @@
 	}
 
 	/*
-	 * The entity pointed to by the Stack_ptr can be either
+	 * The entity pointed to by the stack_ptr can be either
 	 * 1) A valid acpi_operand_object, or
-	 * 2) A acpi_namespace_node (Named_obj)
+	 * 2) A acpi_namespace_node (named_obj)
 	 */
 	if (ACPI_GET_DESCRIPTOR_TYPE (*stack_ptr) == ACPI_DESC_TYPE_OPERAND) {
 		status = acpi_ex_resolve_object_to_value (stack_ptr, walk_state);
@@ -80,7 +79,7 @@
 	}
 
 	/*
-	 * Object on the stack may have changed if Acpi_ex_resolve_object_to_value()
+	 * Object on the stack may have changed if acpi_ex_resolve_object_to_value()
 	 * was called (i.e., we can't use an _else_ here.)
 	 */
 	if (ACPI_GET_DESCRIPTOR_TYPE (*stack_ptr) == ACPI_DESC_TYPE_NAMED) {
@@ -99,11 +98,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_resolve_object_to_value
+ * FUNCTION:    acpi_ex_resolve_object_to_value
  *
- * PARAMETERS:  Stack_ptr       - Pointer to a stack location that contains a
+ * PARAMETERS:  stack_ptr       - Pointer to a stack location that contains a
  *                                ptr to an internal object.
- *              Walk_state      - Current method state
+ *              walk_state      - Current method state
  *
  * RETURN:      Status
  *
@@ -124,7 +123,7 @@
 	u16                     opcode;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_resolve_object_to_value");
+	ACPI_FUNCTION_TRACE ("ex_resolve_object_to_value");
 
 
 	stack_desc = *stack_ptr;
@@ -141,7 +140,7 @@
 
 			/*
 			 * Convert indirect name ptr to a direct name ptr.
-			 * Then, Acpi_ex_resolve_node_to_value can be used to get the value
+			 * Then, acpi_ex_resolve_node_to_value can be used to get the value
 			 */
 			temp_node = stack_desc->reference.object;
 
@@ -175,7 +174,7 @@
 			acpi_ut_remove_reference (stack_desc);
 			*stack_ptr = obj_desc;
 
-			ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Arg/Local %d] Value_obj is %p\n",
+			ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Arg/Local %d] value_obj is %p\n",
 				stack_desc->reference.offset, obj_desc));
 			break;
 
@@ -220,7 +219,7 @@
 				/* Invalid reference object */
 
 				ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
-					"Unknown Target_type %X in Index/Reference obj %p\n",
+					"Unknown target_type %X in Index/Reference obj %p\n",
 					stack_desc->reference.target_type, stack_desc));
 				status = AE_AML_INTERNAL;
 				break;
@@ -266,7 +265,7 @@
 	case ACPI_TYPE_LOCAL_BANK_FIELD:
 	case ACPI_TYPE_LOCAL_INDEX_FIELD:
 
-		ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Field_read Source_desc=%p Type=%X\n",
+		ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "field_read source_desc=%p Type=%X\n",
 			stack_desc, ACPI_GET_OBJECT_TYPE (stack_desc)));
 
 		status = acpi_ex_read_data_from_field (walk_state, stack_desc, &obj_desc);
@@ -283,12 +282,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_resolve_multiple
+ * FUNCTION:    acpi_ex_resolve_multiple
  *
- * PARAMETERS:  Walk_state          - Current state (contains AML opcode)
+ * PARAMETERS:  walk_state          - Current state (contains AML opcode)
  *              Operand             - Starting point for resolution
- *              Return_type         - Where the object type is returned
- *              Return_desc         - Where the resolved object is returned
+ *              return_type         - Where the object type is returned
+ *              return_desc         - Where the resolved object is returned
  *
  * RETURN:      Status
  *
@@ -309,13 +308,13 @@
 	acpi_object_type        type;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_ex_resolve_multiple");
+	ACPI_FUNCTION_TRACE ("acpi_ex_resolve_multiple");
 
 
 	/*
-	 * For reference objects created via the Ref_of or Index operators,
+	 * For reference objects created via the ref_of or Index operators,
 	 * we need to get to the base object (as per the ACPI specification
-	 * of the Object_type and Size_of operators). This means traversing
+	 * of the object_type and size_of operators). This means traversing
 	 * the list of possibly many nested references.
 	 */
 	while (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_LOCAL_REFERENCE) {
@@ -402,7 +401,7 @@
 
 		case AML_DEBUG_OP:
 
-			/* The Debug Object is of type "Debug_object" */
+			/* The Debug Object is of type "debug_object" */
 
 			type = ACPI_TYPE_DEBUG_OBJECT;
 			goto exit;
@@ -410,7 +409,7 @@
 
 		default:
 
-			ACPI_REPORT_ERROR (("Acpi_ex_resolve_multiple: Unknown Reference subtype %X\n",
+			ACPI_REPORT_ERROR (("acpi_ex_resolve_multiple: Unknown Reference subtype %X\n",
 				obj_desc->reference.opcode));
 			return_ACPI_STATUS (AE_AML_INTERNAL);
 		}
@@ -418,7 +417,7 @@
 
 	/*
 	 * Now we are guaranteed to have an object that has not been created
-	 * via the Ref_of or Index operators.
+	 * via the ref_of or Index operators.
 	 */
 	type = ACPI_GET_OBJECT_TYPE (obj_desc);
 
diff -Nru a/drivers/acpi/executer/exresop.c b/drivers/acpi/executer/exresop.c
--- a/drivers/acpi/executer/exresop.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/acpi/executer/exresop.c	Mon Dec 23 21:22:00 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Module Name: exresop - AML Interpreter operand/object resolution
- *              $Revision: 60 $
  *
  *****************************************************************************/
 
@@ -37,10 +36,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_check_object_type
+ * FUNCTION:    acpi_ex_check_object_type
  *
- * PARAMETERS:  Type_needed         Object type needed
- *              This_type           Actual object type
+ * PARAMETERS:  type_needed         Object type needed
+ *              this_type           Actual object type
  *              Object              Object pointer
  *
  * RETURN:      Status
@@ -55,7 +54,7 @@
 	acpi_object_type        this_type,
 	void                    *object)
 {
-	ACPI_FUNCTION_NAME ("Ex_check_object_type");
+	ACPI_FUNCTION_NAME ("ex_check_object_type");
 
 
 	if (type_needed == ACPI_TYPE_ANY) {
@@ -91,19 +90,19 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_resolve_operands
+ * FUNCTION:    acpi_ex_resolve_operands
  *
  * PARAMETERS:  Opcode              - Opcode being interpreted
- *              Stack_ptr           - Pointer to the operand stack to be
+ *              stack_ptr           - Pointer to the operand stack to be
  *                                    resolved
- *              Walk_state          - Current state
+ *              walk_state          - Current state
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Convert multiple input operands to the types required by the
  *              target operator.
  *
- *      Each 5-bit group in Arg_types represents one required
+ *      Each 5-bit group in arg_types represents one required
  *      operand and indicates the required Type. The corresponding operand
  *      will be converted to the required type if possible, otherwise we
  *      abort with an exception.
@@ -126,7 +125,7 @@
 	acpi_object_type        type_needed;
 
 
-	ACPI_FUNCTION_TRACE_U32 ("Ex_resolve_operands", opcode);
+	ACPI_FUNCTION_TRACE_U32 ("ex_resolve_operands", opcode);
 
 
 	op_info = acpi_ps_get_opcode_info (opcode);
@@ -142,11 +141,11 @@
 		return_ACPI_STATUS (AE_AML_INTERNAL);
 	}
 
-	ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode %X [%s] Operand_types=%X \n",
+	ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode %X [%s] operand_types=%X \n",
 		opcode, op_info->name, arg_types));
 
 	/*
-	 * Normal exit is with (Arg_types == 0) at end of argument list.
+	 * Normal exit is with (arg_types == 0) at end of argument list.
 	 * Function will return an exception from within the loop upon
 	 * finding an entry which is not (or cannot be converted
 	 * to) the required type; if stack underflows; or upon
@@ -294,8 +293,8 @@
 		case ARGI_ANYTYPE:
 
 			/*
-			 * We don't want to resolve Index_op reference objects during
-			 * a store because this would be an implicit De_ref_of operation.
+			 * We don't want to resolve index_op reference objects during
+			 * a store because this would be an implicit de_ref_of operation.
 			 * Instead, we just want to store the reference object.
 			 * -- All others must be resolved below.
 			 */
@@ -461,8 +460,8 @@
 
 		case ARGI_DATAOBJECT:
 			/*
-			 * ARGI_DATAOBJECT is only used by the Size_of operator.
-			 * Need a buffer, string, package, or Ref_of reference.
+			 * ARGI_DATAOBJECT is only used by the size_of operator.
+			 * Need a buffer, string, package, or ref_of reference.
 			 *
 			 * The only reference allowed here is a direct reference to
 			 * a namespace node.
@@ -531,7 +530,7 @@
 
 next_operand:
 		/*
-		 * If more operands needed, decrement Stack_ptr to point
+		 * If more operands needed, decrement stack_ptr to point
 		 * to next operand on stack
 		 */
 		if (GET_CURRENT_ARG_TYPE (arg_types)) {
diff -Nru a/drivers/acpi/executer/exstore.c b/drivers/acpi/executer/exstore.c
--- a/drivers/acpi/executer/exstore.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/acpi/executer/exstore.c	Mon Dec 23 21:21:53 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Module Name: exstore - AML Interpreter object store support
- *              $Revision: 174 $
  *
  *****************************************************************************/
 
@@ -38,18 +37,18 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_store
+ * FUNCTION:    acpi_ex_store
  *
- * PARAMETERS:  *Source_desc        - Value to be stored
- *              *Dest_desc          - Where to store it.  Must be an NS node
+ * PARAMETERS:  *source_desc        - Value to be stored
+ *              *dest_desc          - Where to store it.  Must be an NS node
  *                                    or an acpi_operand_object of type
  *                                    Reference;
- *              Walk_state          - Current walk state
+ *              walk_state          - Current walk state
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Store the value described by Source_desc into the location
- *              described by Dest_desc. Called by various interpreter
+ * DESCRIPTION: Store the value described by source_desc into the location
+ *              described by dest_desc. Called by various interpreter
  *              functions to store the result of an operation into
  *              the destination operand -- not just simply the actual "Store"
  *              ASL operator.
@@ -66,7 +65,7 @@
 	acpi_operand_object     *ref_desc = dest_desc;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_store", dest_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ex_store", dest_desc);
 
 
 	/* Validate parameters */
@@ -76,7 +75,7 @@
 		return_ACPI_STATUS (AE_AML_NO_OPERAND);
 	}
 
-	/* Dest_desc can be either a namespace node or an ACPI object */
+	/* dest_desc can be either a namespace node or an ACPI object */
 
 	if (ACPI_GET_DESCRIPTOR_TYPE (dest_desc) == ACPI_DESC_TYPE_NAMED) {
 		/*
@@ -114,7 +113,7 @@
 
 		ACPI_DUMP_STACK_ENTRY (source_desc);
 		ACPI_DUMP_STACK_ENTRY (dest_desc);
-		ACPI_DUMP_OPERANDS (&dest_desc, ACPI_IMODE_EXECUTE, "Ex_store",
+		ACPI_DUMP_OPERANDS (&dest_desc, ACPI_IMODE_EXECUTE, "ex_store",
 				  2, "Target is not a Reference or Constant object");
 
 		return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
@@ -224,11 +223,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_store_object_to_index
+ * FUNCTION:    acpi_ex_store_object_to_index
  *
- * PARAMETERS:  *Source_desc            - Value to be stored
- *              *Dest_desc              - Named object to receive the value
- *              Walk_state              - Current walk state
+ * PARAMETERS:  *source_desc            - Value to be stored
+ *              *dest_desc              - Named object to receive the value
+ *              walk_state              - Current walk state
  *
  * RETURN:      Status
  *
@@ -248,7 +247,7 @@
 	u8                      value = 0;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_store_object_to_index");
+	ACPI_FUNCTION_TRACE ("ex_store_object_to_index");
 
 
 	/*
@@ -264,7 +263,7 @@
 		 * source object.
 		 */
 		/*
-		 * The object at *(Index_desc->Reference.Where) is the
+		 * The object at *(index_desc->Reference.Where) is the
 		 * element within the package that is to be modified.
 		 */
 		obj_desc = *(index_desc->reference.where);
@@ -299,7 +298,7 @@
 	case ACPI_TYPE_BUFFER_FIELD:
 
 		/*
-		 * Store into a Buffer (not actually a real Buffer_field) at a
+		 * Store into a Buffer (not actually a real buffer_field) at a
 		 * location defined by an Index.
 		 *
 		 * The first 8-bit element of the source object is written to the
@@ -355,7 +354,7 @@
 
 	default:
 		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
-			"Target is not a Package or Buffer_field\n"));
+			"Target is not a Package or buffer_field\n"));
 		status = AE_AML_OPERAND_TYPE;
 		break;
 	}
@@ -366,11 +365,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_store_object_to_node
+ * FUNCTION:    acpi_ex_store_object_to_node
  *
- * PARAMETERS:  Source_desc             - Value to be stored
+ * PARAMETERS:  source_desc             - Value to be stored
  *              Node                    - Named object to receive the value
- *              Walk_state              - Current walk state
+ *              walk_state              - Current walk state
  *
  * RETURN:      Status
  *
@@ -401,7 +400,7 @@
 	acpi_object_type        target_type;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_store_object_to_node", source_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ex_store_object_to_node", source_desc);
 
 
 	/*
@@ -456,9 +455,9 @@
 
 		if (new_desc != target_desc) {
 			/*
-			 * Store the new New_desc as the new value of the Name, and set
+			 * Store the new new_desc as the new value of the Name, and set
 			 * the Name's type to that of the value being stored in it.
-			 * Source_desc reference count is incremented by Attach_object.
+			 * source_desc reference count is incremented by attach_object.
 			 *
 			 * Note: This may change the type of the node if an explicit store
 			 * has been performed such that the node/object type has been
diff -Nru a/drivers/acpi/executer/exstoren.c b/drivers/acpi/executer/exstoren.c
--- a/drivers/acpi/executer/exstoren.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/executer/exstoren.c	Mon Dec 23 21:21:51 2002
@@ -3,7 +3,6 @@
  *
  * Module Name: exstoren - AML Interpreter object store support,
  *                        Store to Node (namespace object)
- *              $Revision: 54 $
  *
  *****************************************************************************/
 
@@ -36,16 +35,16 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_resolve_object
+ * FUNCTION:    acpi_ex_resolve_object
  *
- * PARAMETERS:  Source_desc_ptr     - Pointer to the source object
- *              Target_type         - Current type of the target
- *              Walk_state          - Current walk state
+ * PARAMETERS:  source_desc_ptr     - Pointer to the source object
+ *              target_type         - Current type of the target
+ *              walk_state          - Current walk state
  *
- * RETURN:      Status, resolved object in Source_desc_ptr.
+ * RETURN:      Status, resolved object in source_desc_ptr.
  *
  * DESCRIPTION: Resolve an object.  If the object is a reference, dereference
- *              it and return the actual object in the Source_desc_ptr.
+ *              it and return the actual object in the source_desc_ptr.
  *
  ******************************************************************************/
 
@@ -59,7 +58,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_resolve_object");
+	ACPI_FUNCTION_TRACE ("ex_resolve_object");
 
 
 	/*
@@ -114,7 +113,7 @@
 	case ACPI_TYPE_LOCAL_ALIAS:
 
 		/*
-		 * Aliases are resolved by Acpi_ex_prep_operands
+		 * Aliases are resolved by acpi_ex_prep_operands
 		 */
 		ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Store into Alias - should never happen\n"));
 		status = AE_AML_INTERNAL;
@@ -137,12 +136,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_store_object_to_object
+ * FUNCTION:    acpi_ex_store_object_to_object
  *
- * PARAMETERS:  Source_desc         - Object to store
- *              Dest_desc           - Object to receive a copy of the source
- *              New_desc            - New object if Dest_desc is obsoleted
- *              Walk_state          - Current walk state
+ * PARAMETERS:  source_desc         - Object to store
+ *              dest_desc           - Object to receive a copy of the source
+ *              new_desc            - New object if dest_desc is obsoleted
+ *              walk_state          - Current walk state
  *
  * RETURN:      Status
  *
@@ -164,7 +163,7 @@
  *              This module allows destination types of Number, String,
  *              Buffer, and Package.
  *
- *              Assumes parameters are already validated.  NOTE: Source_desc
+ *              Assumes parameters are already validated.  NOTE: source_desc
  *              resolution (from a reference object) must be performed by
  *              the caller if necessary.
  *
@@ -181,7 +180,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_store_object_to_object", source_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ex_store_object_to_object", source_desc);
 
 
 	actual_src_desc = source_desc;
@@ -201,8 +200,8 @@
 		 * Perform the "implicit conversion" of the source to the current type
 		 * of the target as per the ACPI specification.
 		 *
-		 * If no conversion performed, Actual_src_desc = Source_desc.
-		 * Otherwise, Actual_src_desc is a temporary object to hold the
+		 * If no conversion performed, actual_src_desc = source_desc.
+		 * Otherwise, actual_src_desc is a temporary object to hold the
 		 * converted object.
 		 */
 		status = acpi_ex_convert_to_target_type (ACPI_GET_OBJECT_TYPE (dest_desc), source_desc,
@@ -213,7 +212,7 @@
 
 		if (source_desc == actual_src_desc) {
 			/*
-			 * No conversion was performed.  Return the Source_desc as the
+			 * No conversion was performed.  Return the source_desc as the
 			 * new object.
 			 */
 			*new_desc = source_desc;
diff -Nru a/drivers/acpi/executer/exstorob.c b/drivers/acpi/executer/exstorob.c
--- a/drivers/acpi/executer/exstorob.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/acpi/executer/exstorob.c	Mon Dec 23 21:22:00 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Module Name: exstorob - AML Interpreter object store support, store to object
- *              $Revision: 49 $
  *
  *****************************************************************************/
 
@@ -35,10 +34,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_store_buffer_to_buffer
+ * FUNCTION:    acpi_ex_store_buffer_to_buffer
  *
- * PARAMETERS:  Source_desc         - Source object to copy
- *              Target_desc         - Destination object of the copy
+ * PARAMETERS:  source_desc         - Source object to copy
+ *              target_desc         - Destination object of the copy
  *
  * RETURN:      Status
  *
@@ -55,11 +54,11 @@
 	u8                      *buffer;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_store_buffer_to_buffer", source_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ex_store_buffer_to_buffer", source_desc);
 
 
 	/*
-	 * We know that Source_desc is a buffer by now
+	 * We know that source_desc is a buffer by now
 	 */
 	buffer = (u8 *) source_desc->buffer.pointer;
 	length = source_desc->buffer.length;
@@ -109,10 +108,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_store_string_to_string
+ * FUNCTION:    acpi_ex_store_string_to_string
  *
- * PARAMETERS:  Source_desc         - Source object to copy
- *              Target_desc         - Destination object of the copy
+ * PARAMETERS:  source_desc         - Source object to copy
+ *              target_desc         - Destination object of the copy
  *
  * RETURN:      Status
  *
@@ -129,11 +128,11 @@
 	u8                      *buffer;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_store_string_to_string", source_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ex_store_string_to_string", source_desc);
 
 
 	/*
-	 * We know that Source_desc is a string by now.
+	 * We know that source_desc is a string by now.
 	 */
 	buffer = (u8 *) source_desc->string.pointer;
 	length = source_desc->string.length;
@@ -148,7 +147,7 @@
 		 * String will fit in existing non-static buffer.
 		 * Clear old string and copy in the new one
 		 */
-		ACPI_MEMSET (target_desc->string.pointer, 0, (ACPI_SIZE) target_desc->string.length + 1);
+		ACPI_MEMSET (target_desc->string.pointer, 0, (acpi_size) target_desc->string.length + 1);
 		ACPI_MEMCPY (target_desc->string.pointer, buffer, length);
 	}
 	else {
@@ -164,7 +163,7 @@
 			ACPI_MEM_FREE (target_desc->string.pointer);
 		}
 
-		target_desc->string.pointer = ACPI_MEM_CALLOCATE ((ACPI_SIZE) length + 1);
+		target_desc->string.pointer = ACPI_MEM_CALLOCATE ((acpi_size) length + 1);
 		if (!target_desc->string.pointer) {
 			return_ACPI_STATUS (AE_NO_MEMORY);
 		}
diff -Nru a/drivers/acpi/executer/exsystem.c b/drivers/acpi/executer/exsystem.c
--- a/drivers/acpi/executer/exsystem.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/acpi/executer/exsystem.c	Mon Dec 23 21:21:58 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Module Name: exsystem - Interface to OS services
- *              $Revision: 74 $
  *
  *****************************************************************************/
 
@@ -35,7 +34,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_system_wait_semaphore
+ * FUNCTION:    acpi_ex_system_wait_semaphore
  *
  * PARAMETERS:  Semaphore           - OSD semaphore to wait on
  *              Timeout             - Max time to wait
@@ -57,7 +56,7 @@
 	acpi_status             status2;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_system_wait_semaphore");
+	ACPI_FUNCTION_TRACE ("ex_system_wait_semaphore");
 
 
 	status = acpi_os_wait_semaphore (semaphore, 1, 0);
@@ -91,9 +90,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_system_do_stall
+ * FUNCTION:    acpi_ex_system_do_stall
  *
- * PARAMETERS:  How_long            - The amount of time to stall
+ * PARAMETERS:  how_long            - The amount of time to stall
  *
  * RETURN:      Status
  *
@@ -133,9 +132,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_system_do_suspend
+ * FUNCTION:    acpi_ex_system_do_suspend
  *
- * PARAMETERS:  How_long            - The amount of time to suspend
+ * PARAMETERS:  how_long            - The amount of time to suspend
  *
  * RETURN:      None
  *
@@ -169,16 +168,16 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_system_acquire_mutex
+ * FUNCTION:    acpi_ex_system_acquire_mutex
  *
- * PARAMETERS:  *Time_desc          - The 'time to delay' object descriptor
- *              *Obj_desc           - The object descriptor for this op
+ * PARAMETERS:  *time_desc          - The 'time to delay' object descriptor
+ *              *obj_desc           - The object descriptor for this op
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Provides an access point to perform synchronization operations
  *              within the AML.  This function will cause a lock to be generated
- *              for the Mutex pointed to by Obj_desc.
+ *              for the Mutex pointed to by obj_desc.
  *
  ******************************************************************************/
 
@@ -190,7 +189,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ex_system_acquire_mutex", obj_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ex_system_acquire_mutex", obj_desc);
 
 
 	if (!obj_desc) {
@@ -213,9 +212,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_system_release_mutex
+ * FUNCTION:    acpi_ex_system_release_mutex
  *
- * PARAMETERS:  *Obj_desc           - The object descriptor for this op
+ * PARAMETERS:  *obj_desc           - The object descriptor for this op
  *
  * RETURN:      Status
  *
@@ -233,7 +232,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_system_release_mutex");
+	ACPI_FUNCTION_TRACE ("ex_system_release_mutex");
 
 
 	if (!obj_desc) {
@@ -255,9 +254,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_system_signal_event
+ * FUNCTION:    acpi_ex_system_signal_event
  *
- * PARAMETERS:  *Obj_desc           - The object descriptor for this op
+ * PARAMETERS:  *obj_desc           - The object descriptor for this op
  *
  * RETURN:      AE_OK
  *
@@ -273,7 +272,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_system_signal_event");
+	ACPI_FUNCTION_TRACE ("ex_system_signal_event");
 
 
 	if (obj_desc) {
@@ -286,10 +285,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_system_wait_event
+ * FUNCTION:    acpi_ex_system_wait_event
  *
- * PARAMETERS:  *Time_desc          - The 'time to delay' object descriptor
- *              *Obj_desc           - The object descriptor for this op
+ * PARAMETERS:  *time_desc          - The 'time to delay' object descriptor
+ *              *obj_desc           - The object descriptor for this op
  *
  * RETURN:      Status
  *
@@ -307,7 +306,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_system_wait_event");
+	ACPI_FUNCTION_TRACE ("ex_system_wait_event");
 
 
 	if (obj_desc) {
@@ -321,9 +320,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_system_reset_event
+ * FUNCTION:    acpi_ex_system_reset_event
  *
- * PARAMETERS:  *Obj_desc           - The object descriptor for this op
+ * PARAMETERS:  *obj_desc           - The object descriptor for this op
  *
  * RETURN:      Status
  *
diff -Nru a/drivers/acpi/executer/exutils.c b/drivers/acpi/executer/exutils.c
--- a/drivers/acpi/executer/exutils.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/executer/exutils.c	Mon Dec 23 21:21:51 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Module Name: exutils - interpreter/scanner utilities
- *              $Revision: 107 $
  *
  *****************************************************************************/
 
@@ -54,7 +53,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_enter_interpreter
+ * FUNCTION:    acpi_ex_enter_interpreter
  *
  * PARAMETERS:  None
  *
@@ -68,7 +67,7 @@
 {
 	acpi_status             status;
 
-	ACPI_FUNCTION_TRACE ("Ex_enter_interpreter");
+	ACPI_FUNCTION_TRACE ("ex_enter_interpreter");
 
 
 	status = acpi_ut_acquire_mutex (ACPI_MTX_EXECUTE);
@@ -82,7 +81,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_exit_interpreter
+ * FUNCTION:    acpi_ex_exit_interpreter
  *
  * PARAMETERS:  None
  *
@@ -106,7 +105,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_exit_interpreter");
+	ACPI_FUNCTION_TRACE ("ex_exit_interpreter");
 
 
 	status = acpi_ut_release_mutex (ACPI_MTX_EXECUTE);
@@ -120,9 +119,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_truncate_for32bit_table
+ * FUNCTION:    acpi_ex_truncate_for32bit_table
  *
- * PARAMETERS:  Obj_desc        - Object to be truncated
+ * PARAMETERS:  obj_desc        - Object to be truncated
  *
  * RETURN:      none
  *
@@ -160,10 +159,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_acquire_global_lock
+ * FUNCTION:    acpi_ex_acquire_global_lock
  *
- * PARAMETERS:  Field_flags           - Flags with Lock rule:
- *                                      Always_lock or Never_lock
+ * PARAMETERS:  field_flags           - Flags with Lock rule:
+ *                                      always_lock or never_lock
  *
  * RETURN:      TRUE/FALSE indicating whether the lock was actually acquired
  *
@@ -181,10 +180,10 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_acquire_global_lock");
+	ACPI_FUNCTION_TRACE ("ex_acquire_global_lock");
 
 
-	/* Only attempt lock if the Always_lock bit is set */
+	/* Only attempt lock if the always_lock bit is set */
 
 	if (field_flags & AML_FIELD_LOCK_RULE_MASK) {
 		/* We should attempt to get the lock, wait forever */
@@ -205,10 +204,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_release_global_lock
+ * FUNCTION:    acpi_ex_release_global_lock
  *
- * PARAMETERS:  Locked_by_me    - Return value from corresponding call to
- *                                Acquire_global_lock.
+ * PARAMETERS:  locked_by_me    - Return value from corresponding call to
+ *                                acquire_global_lock.
  *
  * RETURN:      Status
  *
@@ -223,7 +222,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_release_global_lock");
+	ACPI_FUNCTION_TRACE ("ex_release_global_lock");
 
 
 	/* Only attempt unlock if the caller locked it */
@@ -246,7 +245,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_digits_needed
+ * FUNCTION:    acpi_ex_digits_needed
  *
  * PARAMETERS:  Value           - Value to be represented
  *              Base            - Base of representation
@@ -265,7 +264,7 @@
 	acpi_integer            quotient;
 
 
-	ACPI_FUNCTION_TRACE ("Ex_digits_needed");
+	ACPI_FUNCTION_TRACE ("ex_digits_needed");
 
 
 	/*
@@ -286,10 +285,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_eisa_id_to_string
+ * FUNCTION:    acpi_ex_eisa_id_to_string
  *
- * PARAMETERS:  Numeric_id      - EISA ID to be converted
- *              Out_string      - Where to put the converted string (8 bytes)
+ * PARAMETERS:  numeric_id      - EISA ID to be converted
+ *              out_string      - Where to put the converted string (8 bytes)
  *
  * DESCRIPTION: Convert a numeric EISA ID to string representation
  *
@@ -323,10 +322,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ex_unsigned_integer_to_string
+ * FUNCTION:    acpi_ex_unsigned_integer_to_string
  *
  * PARAMETERS:  Value           - Value to be converted
- *              Out_string      - Where to put the converted string (8 bytes)
+ *              out_string      - Where to put the converted string (8 bytes)
  *
  * RETURN:      Convert a number to string representation
  *
diff -Nru a/drivers/acpi/fan.c b/drivers/acpi/fan.c
--- a/drivers/acpi/fan.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/fan.c	Mon Dec 23 21:21:51 2002
@@ -181,8 +181,10 @@
 {
 	ACPI_FUNCTION_TRACE("acpi_fan_remove_fs");
 
-	if (acpi_device_dir(device))
+	if (acpi_device_dir(device)) {
 		remove_proc_entry(acpi_device_bid(device), acpi_fan_dir);
+		acpi_device_dir(device) = NULL;
+	}
 
 	return_VALUE(0);
 }
diff -Nru a/drivers/acpi/hardware/hwacpi.c b/drivers/acpi/hardware/hwacpi.c
--- a/drivers/acpi/hardware/hwacpi.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/acpi/hardware/hwacpi.c	Mon Dec 23 21:21:50 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Module Name: hwacpi - ACPI Hardware Initialization/Mode Interface
- *              $Revision: 61 $
  *
  *****************************************************************************/
 
@@ -34,7 +33,7 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_hw_initialize
+ * FUNCTION:    acpi_hw_initialize
  *
  * PARAMETERS:  None
  *
@@ -51,7 +50,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Hw_initialize");
+	ACPI_FUNCTION_TRACE ("hw_initialize");
 
 
 	/* We must have the ACPI tables by the time we get here */
@@ -75,7 +74,7 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_hw_set_mode
+ * FUNCTION:    acpi_hw_set_mode
  *
  * PARAMETERS:  Mode            - SYS_MODE_ACPI or SYS_MODE_LEGACY
  *
@@ -94,7 +93,7 @@
 	u32                     retry;
 
 
-	ACPI_FUNCTION_TRACE ("Hw_set_mode");
+	ACPI_FUNCTION_TRACE ("hw_set_mode");
 
 	/*
 	 * ACPI 2.0 clarified that if SMI_CMD in FADT is zero,
@@ -170,7 +169,7 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_hw_get_mode
+ * FUNCTION:    acpi_hw_get_mode
  *
  * PARAMETERS:  none
  *
@@ -188,7 +187,7 @@
 	u32                     value;
 
 
-	ACPI_FUNCTION_TRACE ("Hw_get_mode");
+	ACPI_FUNCTION_TRACE ("hw_get_mode");
 
 	status = acpi_get_register (ACPI_BITREG_SCI_ENABLE, &value, ACPI_MTX_LOCK);
 	if (ACPI_FAILURE (status)) {
diff -Nru a/drivers/acpi/hardware/hwgpe.c b/drivers/acpi/hardware/hwgpe.c
--- a/drivers/acpi/hardware/hwgpe.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/acpi/hardware/hwgpe.c	Mon Dec 23 21:21:50 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Module Name: hwgpe - Low level GPE enable/disable/clear functions
- *              $Revision: 42 $
  *
  *****************************************************************************/
 
@@ -33,9 +32,9 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_hw_get_gpe_bit_mask
+ * FUNCTION:    acpi_hw_get_gpe_bit_mask
  *
- * PARAMETERS:  Gpe_number      - The GPE
+ * PARAMETERS:  gpe_number      - The GPE
  *
  * RETURN:      Gpe register bitmask for this gpe level
  *
@@ -53,9 +52,9 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_hw_enable_gpe
+ * FUNCTION:    acpi_hw_enable_gpe
  *
- * PARAMETERS:  Gpe_number      - The GPE
+ * PARAMETERS:  gpe_number      - The GPE
  *
  * RETURN:      None
  *
@@ -103,9 +102,9 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_hw_enable_gpe_for_wakeup
+ * FUNCTION:    acpi_hw_enable_gpe_for_wakeup
  *
- * PARAMETERS:  Gpe_number      - The GPE
+ * PARAMETERS:  gpe_number      - The GPE
  *
  * RETURN:      None
  *
@@ -142,9 +141,9 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_hw_disable_gpe
+ * FUNCTION:    acpi_hw_disable_gpe
  *
- * PARAMETERS:  Gpe_number      - The GPE
+ * PARAMETERS:  gpe_number      - The GPE
  *
  * RETURN:      None
  *
@@ -196,9 +195,9 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_hw_disable_gpe_for_wakeup
+ * FUNCTION:    acpi_hw_disable_gpe_for_wakeup
  *
- * PARAMETERS:  Gpe_number      - The GPE
+ * PARAMETERS:  gpe_number      - The GPE
  *
  * RETURN:      None
  *
@@ -235,9 +234,9 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_hw_clear_gpe
+ * FUNCTION:    acpi_hw_clear_gpe
  *
- * PARAMETERS:  Gpe_number      - The GPE
+ * PARAMETERS:  gpe_number      - The GPE
  *
  * RETURN:      None
  *
@@ -278,9 +277,9 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_hw_get_gpe_status
+ * FUNCTION:    acpi_hw_get_gpe_status
  *
- * PARAMETERS:  Gpe_number      - The GPE
+ * PARAMETERS:  gpe_number      - The GPE
  *
  * RETURN:      None
  *
@@ -296,7 +295,7 @@
 	u32                     in_byte = 0;
 	u32                     register_index = 0;
 	u8                      bit_mask = 0;
-	ACPI_GPE_REGISTER_INFO  *gpe_register_info;
+	acpi_gpe_register_info  *gpe_register_info;
 	acpi_status             status;
 
 
@@ -351,7 +350,7 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_hw_disable_non_wakeup_gpes
+ * FUNCTION:    acpi_hw_disable_non_wakeup_gpes
  *
  * PARAMETERS:  None
  *
@@ -359,7 +358,7 @@
  *
  * DESCRIPTION: Disable all non-wakeup GPEs
  *              Call with interrupts disabled. The interrupt handler also
- *              modifies Acpi_gbl_Gpe_register_info[i].Enable, so it should not be
+ *              modifies acpi_gbl_gpe_register_info[i].Enable, so it should not be
  *              given the chance to run until after non-wake GPEs are
  *              re-enabled.
  *
@@ -370,7 +369,7 @@
 	void)
 {
 	u32                     i;
-	ACPI_GPE_REGISTER_INFO  *gpe_register_info;
+	acpi_gpe_register_info  *gpe_register_info;
 	u32                     in_value;
 	acpi_status             status;
 
@@ -408,7 +407,7 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_hw_enable_non_wakeup_gpes
+ * FUNCTION:    acpi_hw_enable_non_wakeup_gpes
  *
  * PARAMETERS:  None
  *
@@ -423,7 +422,7 @@
 	void)
 {
 	u32                     i;
-	ACPI_GPE_REGISTER_INFO  *gpe_register_info;
+	acpi_gpe_register_info  *gpe_register_info;
 	acpi_status             status;
 
 
diff -Nru a/drivers/acpi/hardware/hwregs.c b/drivers/acpi/hardware/hwregs.c
--- a/drivers/acpi/hardware/hwregs.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/acpi/hardware/hwregs.c	Mon Dec 23 21:21:59 2002
@@ -3,7 +3,6 @@
  *
  * Module Name: hwregs - Read/write access functions for the various ACPI
  *                       control and status registers.
- *              $Revision: 138 $
  *
  ******************************************************************************/
 
@@ -35,7 +34,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_hw_clear_acpi_status
+ * FUNCTION:    acpi_hw_clear_acpi_status
  *
  * PARAMETERS:  none
  *
@@ -48,17 +47,17 @@
 acpi_status
 acpi_hw_clear_acpi_status (void)
 {
-	NATIVE_UINT_MAX32       i;
-	NATIVE_UINT             gpe_block;
+	acpi_native_uint        i;
+	acpi_native_uint        gpe_block;
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Hw_clear_acpi_status");
+	ACPI_FUNCTION_TRACE ("hw_clear_acpi_status");
 
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %04X to %04X\n",
 		ACPI_BITMASK_ALL_FIXED_STATUS,
-		(u16) acpi_gbl_FADT->Xpm1a_evt_blk.address));
+		(u16) acpi_gbl_FADT->xpm1a_evt_blk.address));
 
 
 	status = acpi_ut_acquire_mutex (ACPI_MTX_HARDWARE);
@@ -74,9 +73,9 @@
 
 	/* Clear the fixed events */
 
-	if (acpi_gbl_FADT->Xpm1b_evt_blk.address) {
+	if (acpi_gbl_FADT->xpm1b_evt_blk.address) {
 		status = acpi_hw_low_level_write (16, ACPI_BITMASK_ALL_FIXED_STATUS,
-				 &acpi_gbl_FADT->Xpm1b_evt_blk, 0);
+				 &acpi_gbl_FADT->xpm1b_evt_blk, 0);
 		if (ACPI_FAILURE (status)) {
 			goto unlock_and_exit;
 		}
@@ -87,7 +86,7 @@
 	for (gpe_block = 0; gpe_block < ACPI_MAX_GPE_BLOCKS; gpe_block++) {
 		for (i = 0; i < acpi_gbl_gpe_block_info[gpe_block].register_count; i++) {
 			status = acpi_hw_low_level_write (8, 0xFF,
-					 acpi_gbl_gpe_block_info[gpe_block].block_address, i);
+					 acpi_gbl_gpe_block_info[gpe_block].block_address, (u32) i);
 			if (ACPI_FAILURE (status)) {
 				goto unlock_and_exit;
 			}
@@ -102,11 +101,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_get_sleep_type_data
+ * FUNCTION:    acpi_get_sleep_type_data
  *
- * PARAMETERS:  Sleep_state         - Numeric sleep state
- *              *Sleep_type_a        - Where SLP_TYPa is returned
- *              *Sleep_type_b        - Where SLP_TYPb is returned
+ * PARAMETERS:  sleep_state         - Numeric sleep state
+ *              *sleep_type_a        - Where SLP_TYPa is returned
+ *              *sleep_type_b        - Where SLP_TYPb is returned
  *
  * RETURN:      Status - ACPI status
  *
@@ -125,7 +124,7 @@
 	acpi_operand_object     *obj_desc;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_get_sleep_type_data");
+	ACPI_FUNCTION_TRACE ("acpi_get_sleep_type_data");
 
 
 	/*
@@ -142,7 +141,7 @@
 	status = acpi_ns_evaluate_by_name ((char *) acpi_gbl_db_sleep_states[sleep_state],
 			  NULL, &obj_desc);
 	if (ACPI_FAILURE (status)) {
-		ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s while evaluating Sleep_state [%s]\n",
+		ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s while evaluating sleep_state [%s]\n",
 			acpi_format_exception (status), acpi_gbl_db_sleep_states[sleep_state]));
 
 		return_ACPI_STATUS (status);
@@ -187,7 +186,7 @@
 	}
 
 	if (ACPI_FAILURE (status)) {
-		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "While evaluating Sleep_state [%s], bad Sleep object %p type %s\n",
+		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "While evaluating sleep_state [%s], bad Sleep object %p type %s\n",
 			acpi_gbl_db_sleep_states[sleep_state], obj_desc, acpi_ut_get_object_type_name (obj_desc)));
 	}
 
@@ -198,25 +197,25 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_hw_get_register_bit_mask
+ * FUNCTION:    acpi_hw_get_register_bit_mask
  *
- * PARAMETERS:  Register_id         - Index of ACPI Register to access
+ * PARAMETERS:  register_id         - Index of ACPI Register to access
  *
  * RETURN:      The bit mask to be used when accessing the register
  *
- * DESCRIPTION: Map Register_id into a register bit mask.
+ * DESCRIPTION: Map register_id into a register bit mask.
  *
  ******************************************************************************/
 
-ACPI_BIT_REGISTER_INFO *
+acpi_bit_register_info *
 acpi_hw_get_bit_register_info (
 	u32                     register_id)
 {
-	ACPI_FUNCTION_NAME ("Hw_get_bit_register_info");
+	ACPI_FUNCTION_NAME ("hw_get_bit_register_info");
 
 
 	if (register_id > ACPI_BITREG_MAX) {
-		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid Bit_register ID: %X\n", register_id));
+		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid bit_register ID: %X\n", register_id));
 		return (NULL);
 	}
 
@@ -226,15 +225,15 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_get_register
+ * FUNCTION:    acpi_get_register
  *
- * PARAMETERS:  Register_id         - Index of ACPI Register to access
- *              Use_lock            - Lock the hardware
+ * PARAMETERS:  register_id         - Index of ACPI Register to access
+ *              use_lock            - Lock the hardware
  *
  * RETURN:      Value is read from specified Register.  Value returned is
  *              normalized to bit0 (is shifted all the way right)
  *
- * DESCRIPTION: ACPI Bit_register read function.
+ * DESCRIPTION: ACPI bit_register read function.
  *
  ******************************************************************************/
 
@@ -245,11 +244,11 @@
 	u32                     flags)
 {
 	u32                     register_value = 0;
-	ACPI_BIT_REGISTER_INFO  *bit_reg_info;
+	acpi_bit_register_info  *bit_reg_info;
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_get_register");
+	ACPI_FUNCTION_TRACE ("acpi_get_register");
 
 
 	/* Get the info structure corresponding to the requested ACPI Register */
@@ -290,9 +289,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_set_register
+ * FUNCTION:    acpi_set_register
  *
- * PARAMETERS:  Register_id     - ID of ACPI Bit_register to access
+ * PARAMETERS:  register_id     - ID of ACPI bit_register to access
  *              Value           - (only used on write) value to write to the
  *                                Register, NOT pre-normalized to the bit pos.
  *              Flags           - Lock the hardware or not
@@ -310,18 +309,18 @@
 	u32                     flags)
 {
 	u32                     register_value = 0;
-	ACPI_BIT_REGISTER_INFO  *bit_reg_info;
+	acpi_bit_register_info  *bit_reg_info;
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE_U32 ("Acpi_set_register", register_id);
+	ACPI_FUNCTION_TRACE_U32 ("acpi_set_register", register_id);
 
 
 	/* Get the info structure corresponding to the requested ACPI Register */
 
 	bit_reg_info = acpi_hw_get_bit_register_info (register_id);
 	if (!bit_reg_info) {
-		ACPI_REPORT_ERROR (("Bad ACPI HW Register_id: %X\n", register_id));
+		ACPI_REPORT_ERROR (("Bad ACPI HW register_id: %X\n", register_id));
 		return_ACPI_STATUS (AE_BAD_PARAMETER);
 	}
 
@@ -403,16 +402,16 @@
 
 		ACPI_DEBUG_PRINT ((ACPI_DB_IO, "PM2 control: Read %X from %8.8X%8.8X\n",
 			register_value,
-			ACPI_HIDWORD (acpi_gbl_FADT->Xpm2_cnt_blk.address),
-			ACPI_LODWORD (acpi_gbl_FADT->Xpm2_cnt_blk.address)));
+			ACPI_HIDWORD (acpi_gbl_FADT->xpm2_cnt_blk.address),
+			ACPI_LODWORD (acpi_gbl_FADT->xpm2_cnt_blk.address)));
 
 		ACPI_REGISTER_INSERT_VALUE (register_value, bit_reg_info->bit_position,
 				bit_reg_info->access_bit_mask, value);
 
 		ACPI_DEBUG_PRINT ((ACPI_DB_IO, "About to write %4.4X to %8.8X%8.8X\n",
 			register_value,
-			ACPI_HIDWORD (acpi_gbl_FADT->Xpm2_cnt_blk.address),
-			ACPI_LODWORD (acpi_gbl_FADT->Xpm2_cnt_blk.address)));
+			ACPI_HIDWORD (acpi_gbl_FADT->xpm2_cnt_blk.address),
+			ACPI_LODWORD (acpi_gbl_FADT->xpm2_cnt_blk.address)));
 
 		status = acpi_hw_register_write (ACPI_MTX_DO_NOT_LOCK,
 				   ACPI_REGISTER_PM2_CONTROL, (u8) (register_value));
@@ -441,10 +440,10 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_hw_register_read
+ * FUNCTION:    acpi_hw_register_read
  *
- * PARAMETERS:  Use_lock               - Mutex hw access.
- *              Register_id            - Register_iD + Offset.
+ * PARAMETERS:  use_lock               - Mutex hw access.
+ *              register_id            - register_iD + Offset.
  *
  * RETURN:      Value read or written.
  *
@@ -465,7 +464,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Hw_register_read");
+	ACPI_FUNCTION_TRACE ("hw_register_read");
 
 
 	if (ACPI_MTX_LOCK == use_lock) {
@@ -478,12 +477,12 @@
 	switch (register_id) {
 	case ACPI_REGISTER_PM1_STATUS:           /* 16-bit access */
 
-		status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_FADT->Xpm1a_evt_blk, 0);
+		status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_FADT->xpm1a_evt_blk, 0);
 		if (ACPI_FAILURE (status)) {
 			goto unlock_and_exit;
 		}
 
-		status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_FADT->Xpm1b_evt_blk, 0);
+		status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_FADT->xpm1b_evt_blk, 0);
 		value1 |= value2;
 		break;
 
@@ -491,37 +490,37 @@
 	case ACPI_REGISTER_PM1_ENABLE:           /* 16-bit access*/
 
 		bank_offset = ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len);
-		status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_FADT->Xpm1a_evt_blk, bank_offset);
+		status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_FADT->xpm1a_evt_blk, bank_offset);
 		if (ACPI_FAILURE (status)) {
 			goto unlock_and_exit;
 		}
 
-		status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_FADT->Xpm1b_evt_blk, bank_offset);
+		status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_FADT->xpm1b_evt_blk, bank_offset);
 		value1 |= value2;
 		break;
 
 
 	case ACPI_REGISTER_PM1_CONTROL:          /* 16-bit access */
 
-		status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_FADT->Xpm1a_cnt_blk, 0);
+		status = acpi_hw_low_level_read (16, &value1, &acpi_gbl_FADT->xpm1a_cnt_blk, 0);
 		if (ACPI_FAILURE (status)) {
 			goto unlock_and_exit;
 		}
 
-		status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_FADT->Xpm1b_cnt_blk, 0);
+		status = acpi_hw_low_level_read (16, &value2, &acpi_gbl_FADT->xpm1b_cnt_blk, 0);
 		value1 |= value2;
 		break;
 
 
 	case ACPI_REGISTER_PM2_CONTROL:          /* 8-bit access */
 
-		status = acpi_hw_low_level_read (8, &value1, &acpi_gbl_FADT->Xpm2_cnt_blk, 0);
+		status = acpi_hw_low_level_read (8, &value1, &acpi_gbl_FADT->xpm2_cnt_blk, 0);
 		break;
 
 
 	case ACPI_REGISTER_PM_TIMER:             /* 32-bit access */
 
-		status = acpi_hw_low_level_read (32, &value1, &acpi_gbl_FADT->Xpm_tmr_blk, 0);
+		status = acpi_hw_low_level_read (32, &value1, &acpi_gbl_FADT->xpm_tmr_blk, 0);
 		break;
 
 	case ACPI_REGISTER_SMI_COMMAND_BLOCK:    /* 8-bit access */
@@ -550,10 +549,10 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_hw_register_write
+ * FUNCTION:    acpi_hw_register_write
  *
- * PARAMETERS:  Use_lock               - Mutex hw access.
- *              Register_id            - Register_iD + Offset.
+ * PARAMETERS:  use_lock               - Mutex hw access.
+ *              register_id            - register_iD + Offset.
  *
  * RETURN:      Value read or written.
  *
@@ -572,7 +571,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Hw_register_write");
+	ACPI_FUNCTION_TRACE ("hw_register_write");
 
 
 	if (ACPI_MTX_LOCK == use_lock) {
@@ -585,59 +584,59 @@
 	switch (register_id) {
 	case ACPI_REGISTER_PM1_STATUS:           /* 16-bit access */
 
-		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->Xpm1a_evt_blk, 0);
+		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1a_evt_blk, 0);
 		if (ACPI_FAILURE (status)) {
 			goto unlock_and_exit;
 		}
 
-		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->Xpm1b_evt_blk, 0);
+		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1b_evt_blk, 0);
 		break;
 
 
 	case ACPI_REGISTER_PM1_ENABLE:           /* 16-bit access*/
 
 		bank_offset = ACPI_DIV_2 (acpi_gbl_FADT->pm1_evt_len);
-		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->Xpm1a_evt_blk, bank_offset);
+		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1a_evt_blk, bank_offset);
 		if (ACPI_FAILURE (status)) {
 			goto unlock_and_exit;
 		}
 
-		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->Xpm1b_evt_blk, bank_offset);
+		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1b_evt_blk, bank_offset);
 		break;
 
 
 	case ACPI_REGISTER_PM1_CONTROL:          /* 16-bit access */
 
-		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->Xpm1a_cnt_blk, 0);
+		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1a_cnt_blk, 0);
 		if (ACPI_FAILURE (status)) {
 			goto unlock_and_exit;
 		}
 
-		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->Xpm1b_cnt_blk, 0);
+		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1b_cnt_blk, 0);
 		break;
 
 
 	case ACPI_REGISTER_PM1A_CONTROL:         /* 16-bit access */
 
-		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->Xpm1a_cnt_blk, 0);
+		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1a_cnt_blk, 0);
 		break;
 
 
 	case ACPI_REGISTER_PM1B_CONTROL:         /* 16-bit access */
 
-		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->Xpm1b_cnt_blk, 0);
+		status = acpi_hw_low_level_write (16, value, &acpi_gbl_FADT->xpm1b_cnt_blk, 0);
 		break;
 
 
 	case ACPI_REGISTER_PM2_CONTROL:          /* 8-bit access */
 
-		status = acpi_hw_low_level_write (8, value, &acpi_gbl_FADT->Xpm2_cnt_blk, 0);
+		status = acpi_hw_low_level_write (8, value, &acpi_gbl_FADT->xpm2_cnt_blk, 0);
 		break;
 
 
 	case ACPI_REGISTER_PM_TIMER:             /* 32-bit access */
 
-		status = acpi_hw_low_level_write (32, value, &acpi_gbl_FADT->Xpm_tmr_blk, 0);
+		status = acpi_hw_low_level_write (32, value, &acpi_gbl_FADT->xpm_tmr_blk, 0);
 		break;
 
 
@@ -665,7 +664,7 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_hw_low_level_read
+ * FUNCTION:    acpi_hw_low_level_read
  *
  * PARAMETERS:  Register            - GAS register structure
  *              Offset              - Offset from the base address in the GAS
@@ -684,14 +683,14 @@
 	acpi_generic_address    *reg,
 	u32                     offset)
 {
-	ACPI_PHYSICAL_ADDRESS   mem_address;
-	ACPI_IO_ADDRESS         io_address;
+	acpi_physical_address   mem_address;
+	acpi_io_address         io_address;
 	acpi_pci_id             pci_id;
 	u16                     pci_register;
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_NAME ("Hw_low_level_read");
+	ACPI_FUNCTION_NAME ("hw_low_level_read");
 
 
 	/*
@@ -713,7 +712,7 @@
 	case ACPI_ADR_SPACE_SYSTEM_MEMORY:
 
 		mem_address = (reg->address
-				  + (ACPI_PHYSICAL_ADDRESS) offset);
+				  + (acpi_physical_address) offset);
 
 		status = acpi_os_read_memory (mem_address, value, width);
 		break;
@@ -721,8 +720,8 @@
 
 	case ACPI_ADR_SPACE_SYSTEM_IO:
 
-		io_address = (ACPI_IO_ADDRESS) (reg->address
-				   + (ACPI_PHYSICAL_ADDRESS) offset);
+		io_address = (acpi_io_address) (reg->address
+				   + (acpi_physical_address) offset);
 
 		status = acpi_os_read_port (io_address, value, width);
 		break;
@@ -753,7 +752,7 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_hw_low_level_write
+ * FUNCTION:    acpi_hw_low_level_write
  *
  * PARAMETERS:  Width               - 8, 16, or 32
  *              Value               - To be written
@@ -774,14 +773,14 @@
 	acpi_generic_address    *reg,
 	u32                     offset)
 {
-	ACPI_PHYSICAL_ADDRESS   mem_address;
-	ACPI_IO_ADDRESS         io_address;
+	acpi_physical_address   mem_address;
+	acpi_io_address         io_address;
 	acpi_pci_id             pci_id;
 	u16                     pci_register;
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_NAME ("Hw_low_level_write");
+	ACPI_FUNCTION_NAME ("hw_low_level_write");
 
 
 	/*
@@ -801,7 +800,7 @@
 	case ACPI_ADR_SPACE_SYSTEM_MEMORY:
 
 		mem_address = (reg->address
-				  + (ACPI_PHYSICAL_ADDRESS) offset);
+				  + (acpi_physical_address) offset);
 
 		status = acpi_os_write_memory (mem_address, (acpi_integer) value, width);
 		break;
@@ -809,8 +808,8 @@
 
 	case ACPI_ADR_SPACE_SYSTEM_IO:
 
-		io_address = (ACPI_IO_ADDRESS) (reg->address
-				   + (ACPI_PHYSICAL_ADDRESS) offset);
+		io_address = (acpi_io_address) (reg->address
+				   + (acpi_physical_address) offset);
 
 		status = acpi_os_write_port (io_address, (acpi_integer) value, width);
 		break;
diff -Nru a/drivers/acpi/hardware/hwsleep.c b/drivers/acpi/hardware/hwsleep.c
--- a/drivers/acpi/hardware/hwsleep.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/hardware/hwsleep.c	Mon Dec 23 21:21:51 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Name: hwsleep.c - ACPI Hardware Sleep/Wake Interface
- *              $Revision: 48 $
  *
  *****************************************************************************/
 
@@ -32,23 +31,23 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_set_firmware_waking_vector
+ * FUNCTION:    acpi_set_firmware_waking_vector
  *
- * PARAMETERS:  Physical_address    - Physical address of ACPI real mode
+ * PARAMETERS:  physical_address    - Physical address of ACPI real mode
  *                                    entry point.
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Access function for d_firmware_waking_vector field in FACS
+ * DESCRIPTION: access function for d_firmware_waking_vector field in FACS
  *
  ******************************************************************************/
 
 acpi_status
 acpi_set_firmware_waking_vector (
-	ACPI_PHYSICAL_ADDRESS physical_address)
+	acpi_physical_address physical_address)
 {
 
-	ACPI_FUNCTION_TRACE ("Acpi_set_firmware_waking_vector");
+	ACPI_FUNCTION_TRACE ("acpi_set_firmware_waking_vector");
 
 
 	/* Set the vector */
@@ -68,24 +67,24 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_get_firmware_waking_vector
+ * FUNCTION:    acpi_get_firmware_waking_vector
  *
- * PARAMETERS:  *Physical_address   - Output buffer where contents of
- *                                    the Firmware_waking_vector field of
+ * PARAMETERS:  *physical_address   - Output buffer where contents of
+ *                                    the firmware_waking_vector field of
  *                                    the FACS will be stored.
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Access function for Firmware_waking_vector field in FACS
+ * DESCRIPTION: Access function for firmware_waking_vector field in FACS
  *
  ******************************************************************************/
 
 acpi_status
 acpi_get_firmware_waking_vector (
-	ACPI_PHYSICAL_ADDRESS *physical_address)
+	acpi_physical_address *physical_address)
 {
 
-	ACPI_FUNCTION_TRACE ("Acpi_get_firmware_waking_vector");
+	ACPI_FUNCTION_TRACE ("acpi_get_firmware_waking_vector");
 
 
 	if (!physical_address) {
@@ -95,7 +94,7 @@
 	/* Get the vector */
 
 	if (acpi_gbl_common_fACS.vector_width == 32) {
-		*physical_address = (ACPI_PHYSICAL_ADDRESS)
+		*physical_address = (acpi_physical_address)
 			*(ACPI_CAST_PTR (u32, acpi_gbl_common_fACS.firmware_waking_vector));
 	}
 	else {
@@ -109,9 +108,9 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_enter_sleep_state_prep
+ * FUNCTION:    acpi_enter_sleep_state_prep
  *
- * PARAMETERS:  Sleep_state         - Which sleep state to enter
+ * PARAMETERS:  sleep_state         - Which sleep state to enter
  *
  * RETURN:      Status
  *
@@ -131,7 +130,7 @@
 	acpi_object         arg;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_enter_sleep_state_prep");
+	ACPI_FUNCTION_TRACE ("acpi_enter_sleep_state_prep");
 
 
 	/*
@@ -169,9 +168,9 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_enter_sleep_state
+ * FUNCTION:    acpi_enter_sleep_state
  *
- * PARAMETERS:  Sleep_state         - Which sleep state to enter
+ * PARAMETERS:  sleep_state         - Which sleep state to enter
  *
  * RETURN:      Status
  *
@@ -186,13 +185,13 @@
 {
 	u32                     PM1Acontrol;
 	u32                     PM1Bcontrol;
-	ACPI_BIT_REGISTER_INFO  *sleep_type_reg_info;
-	ACPI_BIT_REGISTER_INFO  *sleep_enable_reg_info;
+	acpi_bit_register_info  *sleep_type_reg_info;
+	acpi_bit_register_info  *sleep_enable_reg_info;
 	u32                     in_value;
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_enter_sleep_state");
+	ACPI_FUNCTION_TRACE ("acpi_enter_sleep_state");
 
 
 	if ((acpi_gbl_sleep_type_a > ACPI_SLEEP_TYPE_MAX) ||
@@ -319,9 +318,9 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_leave_sleep_state
+ * FUNCTION:    acpi_leave_sleep_state
  *
- * PARAMETERS:  Sleep_state         - Which sleep state we just exited
+ * PARAMETERS:  sleep_state         - Which sleep state we just exited
  *
  * RETURN:      Status
  *
@@ -338,10 +337,10 @@
 	acpi_status         status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_leave_sleep_state");
+	ACPI_FUNCTION_TRACE ("acpi_leave_sleep_state");
 
 
-	/* Ensure Enter_sleep_state_prep -> Enter_sleep_state ordering */
+	/* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */
 
 	acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID;
 
diff -Nru a/drivers/acpi/hardware/hwtimer.c b/drivers/acpi/hardware/hwtimer.c
--- a/drivers/acpi/hardware/hwtimer.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/hardware/hwtimer.c	Mon Dec 23 21:21:51 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Name: hwtimer.c - ACPI Power Management Timer Interface
- *              $Revision: 21 $
  *
  *****************************************************************************/
 
@@ -32,7 +31,7 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_get_timer_resolution
+ * FUNCTION:    acpi_get_timer_resolution
  *
  * PARAMETERS:  none
  *
@@ -46,7 +45,7 @@
 acpi_get_timer_resolution (
 	u32                     *resolution)
 {
-	ACPI_FUNCTION_TRACE ("Acpi_get_timer_resolution");
+	ACPI_FUNCTION_TRACE ("acpi_get_timer_resolution");
 
 
 	if (!resolution) {
@@ -66,7 +65,7 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_get_timer
+ * FUNCTION:    acpi_get_timer
  *
  * PARAMETERS:  none
  *
@@ -83,14 +82,14 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_get_timer");
+	ACPI_FUNCTION_TRACE ("acpi_get_timer");
 
 
 	if (!ticks) {
 		return_ACPI_STATUS (AE_BAD_PARAMETER);
 	}
 
-	status = acpi_hw_low_level_read (32, ticks, &acpi_gbl_FADT->Xpm_tmr_blk, 0);
+	status = acpi_hw_low_level_read (32, ticks, &acpi_gbl_FADT->xpm_tmr_blk, 0);
 
 	return_ACPI_STATUS (status);
 }
@@ -98,13 +97,13 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_get_timer_duration
+ * FUNCTION:    acpi_get_timer_duration
  *
- * PARAMETERS:  Start_ticks
- *              End_ticks
- *              Time_elapsed
+ * PARAMETERS:  start_ticks
+ *              end_ticks
+ *              time_elapsed
  *
- * RETURN:      Time_elapsed
+ * RETURN:      time_elapsed
  *
  * DESCRIPTION: Computes the time elapsed (in microseconds) between two
  *              PM Timer time stamps, taking into account the possibility of
@@ -134,7 +133,7 @@
 	acpi_integer            out_quotient;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_get_timer_duration");
+	ACPI_FUNCTION_TRACE ("acpi_get_timer_duration");
 
 
 	if (!time_elapsed) {
@@ -172,7 +171,7 @@
 	 *
 	 * Requires a 64-bit divide:
 	 *
-	 * Time_elapsed = (Delta_ticks * 1000000) / PM_TIMER_FREQUENCY;
+	 * time_elapsed = (delta_ticks * 1000000) / PM_TIMER_FREQUENCY;
 	 */
 	normalized_ticks.full = ((u64) delta_ticks) * 1000000;
 
diff -Nru a/drivers/acpi/include/acconfig.h b/drivers/acpi/include/acconfig.h
--- a/drivers/acpi/include/acconfig.h	Mon Dec 23 21:21:58 2002
+++ b/drivers/acpi/include/acconfig.h	Mon Dec 23 21:21:58 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: acconfig.h - Global configuration constants
- *       $Revision: 123 $
  *
  *****************************************************************************/
 
@@ -54,7 +53,7 @@
 
 /* Version string */
 
-#define ACPI_CA_VERSION                 0x20021212
+#define ACPI_CA_VERSION                 0x20021217
 
 /* Version of ACPI supported */
 
@@ -149,7 +148,7 @@
 #define ACPI_NUM_PREDEFINED_REGIONS     8
 #define ACPI_USER_REGION_BEGIN          0x80
 
-/* Maximum Space_ids for Operation Regions */
+/* Maximum space_ids for Operation Regions */
 
 #define ACPI_MAX_ADDRESS_SPACE          255
 
diff -Nru a/drivers/acpi/include/acdebug.h b/drivers/acpi/include/acdebug.h
--- a/drivers/acpi/include/acdebug.h	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/include/acdebug.h	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: acdebug.h - ACPI/AML debugger
- *       $Revision: 65 $
  *
  *****************************************************************************/
 
diff -Nru a/drivers/acpi/include/acdispat.h b/drivers/acpi/include/acdispat.h
--- a/drivers/acpi/include/acdispat.h	Mon Dec 23 21:21:58 2002
+++ b/drivers/acpi/include/acdispat.h	Mon Dec 23 21:21:58 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: acdispat.h - dispatcher (parser to interpreter interface)
- *       $Revision: 55 $
  *
  *****************************************************************************/
 
@@ -146,7 +145,7 @@
 
 acpi_status
 acpi_ds_get_field_names (
-	ACPI_CREATE_FIELD_INFO  *info,
+	acpi_create_field_info  *info,
 	acpi_walk_state         *walk_state,
 	acpi_parse_object       *arg);
 
@@ -282,7 +281,7 @@
 
 acpi_status
 acpi_ds_call_control_method (
-	ACPI_THREAD_STATE       *thread,
+	acpi_thread_state       *thread,
 	acpi_walk_state         *walk_state,
 	acpi_parse_object       *op);
 
@@ -410,7 +409,7 @@
 	acpi_owner_id           owner_id,
 	acpi_parse_object       *origin,
 	acpi_operand_object     *mth_desc,
-	ACPI_THREAD_STATE       *thread);
+	acpi_thread_state       *thread);
 
 acpi_status
 acpi_ds_init_aml_walk (
@@ -438,12 +437,12 @@
 
 acpi_walk_state *
 acpi_ds_pop_walk_state (
-	ACPI_THREAD_STATE       *thread);
+	acpi_thread_state       *thread);
 
 void
 acpi_ds_push_walk_state (
 	acpi_walk_state         *walk_state,
-	ACPI_THREAD_STATE       *thread);
+	acpi_thread_state       *thread);
 
 acpi_status
 acpi_ds_result_stack_pop (
@@ -459,7 +458,7 @@
 
 acpi_walk_state *
 acpi_ds_get_current_walk_state (
-	ACPI_THREAD_STATE       *thread);
+	acpi_thread_state       *thread);
 
 void
 acpi_ds_delete_walk_state_cache (
diff -Nru a/drivers/acpi/include/acevents.h b/drivers/acpi/include/acevents.h
--- a/drivers/acpi/include/acevents.h	Mon Dec 23 21:21:56 2002
+++ b/drivers/acpi/include/acevents.h	Mon Dec 23 21:21:56 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: acevents.h - Event subcomponent prototypes and defines
- *       $Revision: 80 $
  *
  *****************************************************************************/
 
@@ -123,7 +122,7 @@
 acpi_ev_address_space_dispatch (
 	acpi_operand_object    *region_obj,
 	u32                     function,
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	u32                     bit_width,
 	void                    *value);
 
diff -Nru a/drivers/acpi/include/acexcep.h b/drivers/acpi/include/acexcep.h
--- a/drivers/acpi/include/acexcep.h	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/include/acexcep.h	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: acexcep.h - Exception codes returned by the ACPI subsystem
- *       $Revision: 66 $
  *
  *****************************************************************************/
 
diff -Nru a/drivers/acpi/include/acglobal.h b/drivers/acpi/include/acglobal.h
--- a/drivers/acpi/include/acglobal.h	Mon Dec 23 21:21:50 2002
+++ b/drivers/acpi/include/acglobal.h	Mon Dec 23 21:21:50 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: acglobal.h - Declarations for global variables
- *       $Revision: 135 $
  *
  *****************************************************************************/
 
@@ -64,7 +63,7 @@
 
 /*
  * Table pointers.
- * Although these pointers are somewhat redundant with the global Acpi_table,
+ * Although these pointers are somewhat redundant with the global acpi_table,
  * they are convenient because they are typed pointers.
  *
  * These tables are single-table only; meaning that there can be at most one
@@ -73,7 +72,7 @@
  */
 ACPI_EXTERN u32                         acpi_gbl_table_flags;
 ACPI_EXTERN u32                         acpi_gbl_rsdt_table_count;
-ACPI_EXTERN RSDP_DESCRIPTOR            *acpi_gbl_RSDP;
+ACPI_EXTERN rsdp_descriptor            *acpi_gbl_RSDP;
 ACPI_EXTERN xsdt_descriptor            *acpi_gbl_XSDT;
 ACPI_EXTERN FADT_DESCRIPTOR            *acpi_gbl_FADT;
 ACPI_EXTERN acpi_table_header          *acpi_gbl_DSDT;
@@ -115,10 +114,10 @@
  ****************************************************************************/
 
 
-ACPI_EXTERN ACPI_MEMORY_LIST            acpi_gbl_memory_lists[ACPI_NUM_MEM_LISTS];
-ACPI_EXTERN ACPI_OBJECT_NOTIFY_HANDLER  acpi_gbl_drv_notify;
-ACPI_EXTERN ACPI_OBJECT_NOTIFY_HANDLER  acpi_gbl_sys_notify;
-ACPI_EXTERN ACPI_INIT_HANDLER           acpi_gbl_init_handler;
+ACPI_EXTERN acpi_memory_list            acpi_gbl_memory_lists[ACPI_NUM_MEM_LISTS];
+ACPI_EXTERN acpi_object_notify_handler  acpi_gbl_drv_notify;
+ACPI_EXTERN acpi_object_notify_handler  acpi_gbl_sys_notify;
+ACPI_EXTERN acpi_init_handler           acpi_gbl_init_handler;
 ACPI_EXTERN acpi_walk_state            *acpi_gbl_breakpoint_walk;
 ACPI_EXTERN acpi_handle                 acpi_gbl_global_lock_semaphore;
 
@@ -170,8 +169,8 @@
 ACPI_EXTERN u32                         acpi_gbl_current_node_count;
 ACPI_EXTERN u32                         acpi_gbl_current_node_size;
 ACPI_EXTERN u32                         acpi_gbl_max_concurrent_node_count;
-ACPI_EXTERN ACPI_SIZE                   acpi_gbl_entry_stack_pointer;
-ACPI_EXTERN ACPI_SIZE                   acpi_gbl_lowest_stack_pointer;
+ACPI_EXTERN acpi_size                   acpi_gbl_entry_stack_pointer;
+ACPI_EXTERN acpi_size                   acpi_gbl_lowest_stack_pointer;
 ACPI_EXTERN u32                         acpi_gbl_deepest_nesting;
 #endif
 
@@ -182,7 +181,7 @@
  ****************************************************************************/
 
 
-ACPI_EXTERN ACPI_THREAD_STATE           *acpi_gbl_current_walk_list;
+ACPI_EXTERN acpi_thread_state           *acpi_gbl_current_walk_list;
 
 /* Control method single step flag */
 
@@ -203,7 +202,7 @@
  *
  ****************************************************************************/
 
-extern      ACPI_BIT_REGISTER_INFO      acpi_gbl_bit_register_info[ACPI_NUM_BITREG];
+extern      acpi_bit_register_info      acpi_gbl_bit_register_info[ACPI_NUM_BITREG];
 ACPI_EXTERN u8                          acpi_gbl_sleep_type_a;
 ACPI_EXTERN u8                          acpi_gbl_sleep_type_b;
 
@@ -215,14 +214,14 @@
  ****************************************************************************/
 
 extern      acpi_fixed_event_info       acpi_gbl_fixed_event_info[ACPI_NUM_FIXED_EVENTS];
-ACPI_EXTERN ACPI_FIXED_EVENT_HANDLER    acpi_gbl_fixed_event_handlers[ACPI_NUM_FIXED_EVENTS];
+ACPI_EXTERN acpi_fixed_event_handler    acpi_gbl_fixed_event_handlers[ACPI_NUM_FIXED_EVENTS];
 
 ACPI_EXTERN acpi_handle                 acpi_gbl_gpe_obj_handle;
 ACPI_EXTERN u32                         acpi_gbl_gpe_register_count;
 ACPI_EXTERN u32                         acpi_gbl_gpe_number_max;
-ACPI_EXTERN ACPI_GPE_REGISTER_INFO     *acpi_gbl_gpe_register_info;
-ACPI_EXTERN ACPI_GPE_NUMBER_INFO       *acpi_gbl_gpe_number_info;
-ACPI_EXTERN ACPI_GPE_BLOCK_INFO         acpi_gbl_gpe_block_info[ACPI_MAX_GPE_BLOCKS];
+ACPI_EXTERN acpi_gpe_register_info     *acpi_gbl_gpe_register_info;
+ACPI_EXTERN acpi_gpe_number_info       *acpi_gbl_gpe_number_info;
+ACPI_EXTERN acpi_gpe_block_info         acpi_gbl_gpe_block_info[ACPI_MAX_GPE_BLOCKS];
 
 /*
  * GPE translation table
@@ -231,7 +230,7 @@
  * This table is needed because the GPE numbers supported by block 1 do not
  * have to be contiguous with the GPE numbers supported by block 0.
  */
-ACPI_EXTERN ACPI_GPE_INDEX_INFO        *acpi_gbl_gpe_number_to_index;
+ACPI_EXTERN acpi_gpe_index_info        *acpi_gbl_gpe_number_to_index;
 
 
 /*****************************************************************************
diff -Nru a/drivers/acpi/include/achware.h b/drivers/acpi/include/achware.h
--- a/drivers/acpi/include/achware.h	Mon Dec 23 21:21:56 2002
+++ b/drivers/acpi/include/achware.h	Mon Dec 23 21:21:56 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: achware.h -- hardware specific interfaces
- *       $Revision: 60 $
  *
  *****************************************************************************/
 
@@ -60,7 +59,7 @@
 
 /* Register I/O Prototypes */
 
-ACPI_BIT_REGISTER_INFO *
+acpi_bit_register_info *
 acpi_hw_get_bit_register_info (
 	u32                     register_id);
 
diff -Nru a/drivers/acpi/include/acinterp.h b/drivers/acpi/include/acinterp.h
--- a/drivers/acpi/include/acinterp.h	Mon Dec 23 21:22:00 2002
+++ b/drivers/acpi/include/acinterp.h	Mon Dec 23 21:22:00 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: acinterp.h - Interpreter subcomponent prototypes and defines
- *       $Revision: 144 $
  *
  *****************************************************************************/
 
@@ -310,7 +309,7 @@
 
 void
 acpi_ex_release_all_mutexes (
-	ACPI_THREAD_STATE       *thread);
+	acpi_thread_state       *thread);
 
 void
 acpi_ex_unlink_mutex (
@@ -319,7 +318,7 @@
 void
 acpi_ex_link_mutex (
 	acpi_operand_object     *obj_desc,
-	ACPI_THREAD_STATE       *thread);
+	acpi_thread_state       *thread);
 
 /*
  * exprep - ACPI AML (p-code) execution - prep utilities
@@ -335,7 +334,7 @@
 
 acpi_status
 acpi_ex_prep_field_value (
-	ACPI_CREATE_FIELD_INFO  *info);
+	acpi_create_field_info  *info);
 
 /*
  * exsystem - Interface to OS services
@@ -489,7 +488,7 @@
 void
 acpi_ex_out_address (
 	char                    *title,
-	ACPI_PHYSICAL_ADDRESS   value);
+	acpi_physical_address   value);
 
 
 /*
@@ -639,13 +638,13 @@
 
 
 /*
- * exregion - default Op_region handlers
+ * exregion - default op_region handlers
  */
 
 acpi_status
 acpi_ex_system_memory_space_handler (
 	u32                     function,
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	u32                     bit_width,
 	acpi_integer            *value,
 	void                    *handler_context,
@@ -654,7 +653,7 @@
 acpi_status
 acpi_ex_system_io_space_handler (
 	u32                     function,
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	u32                     bit_width,
 	acpi_integer            *value,
 	void                    *handler_context,
@@ -663,7 +662,7 @@
 acpi_status
 acpi_ex_pci_config_space_handler (
 	u32                     function,
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	u32                     bit_width,
 	acpi_integer            *value,
 	void                    *handler_context,
@@ -672,7 +671,7 @@
 acpi_status
 acpi_ex_cmos_space_handler (
 	u32                     function,
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	u32                     bit_width,
 	acpi_integer            *value,
 	void                    *handler_context,
@@ -681,7 +680,7 @@
 acpi_status
 acpi_ex_pci_bar_space_handler (
 	u32                     function,
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	u32                     bit_width,
 	acpi_integer            *value,
 	void                    *handler_context,
@@ -690,7 +689,7 @@
 acpi_status
 acpi_ex_embedded_controller_space_handler (
 	u32                     function,
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	u32                     bit_width,
 	acpi_integer            *value,
 	void                    *handler_context,
@@ -699,7 +698,7 @@
 acpi_status
 acpi_ex_sm_bus_space_handler (
 	u32                     function,
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	u32                     bit_width,
 	acpi_integer            *value,
 	void                    *handler_context,
@@ -709,7 +708,7 @@
 acpi_status
 acpi_ex_data_table_space_handler (
 	u32                     function,
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	u32                     bit_width,
 	acpi_integer            *value,
 	void                    *handler_context,
diff -Nru a/drivers/acpi/include/aclocal.h b/drivers/acpi/include/aclocal.h
--- a/drivers/acpi/include/aclocal.h	Mon Dec 23 21:21:57 2002
+++ b/drivers/acpi/include/aclocal.h	Mon Dec 23 21:21:57 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: aclocal.h - Internal data types used across the ACPI subsystem
- *       $Revision: 183 $
  *
  *****************************************************************************/
 
@@ -30,7 +29,7 @@
 #define ACPI_WAIT_FOREVER               0xFFFF  /* u16, as per ACPI spec */
 
 typedef void*                           acpi_mutex;
-typedef u32                             ACPI_MUTEX_HANDLE;
+typedef u32                             acpi_mutex_handle;
 
 
 /* Total number of aml opcodes defined */
@@ -47,12 +46,12 @@
 
 /*
  * Predefined handles for the mutex objects used within the subsystem
- * All mutex objects are automatically created by Acpi_ut_mutex_initialize.
+ * All mutex objects are automatically created by acpi_ut_mutex_initialize.
  *
  * The acquire/release ordering protocol is implied via this list.  Mutexes
  * with a lower value must be acquired before mutexes with a higher value.
  *
- * NOTE: any changes here must be reflected in the Acpi_gbl_Mutex_names table also!
+ * NOTE: any changes here must be reflected in the acpi_gbl_mutex_names table also!
  */
 
 #define ACPI_MTX_EXECUTE                0
@@ -85,14 +84,14 @@
 	"ACPI_MTX_Parser",
 	"ACPI_MTX_Dispatcher",
 	"ACPI_MTX_Tables",
-	"ACPI_MTX_Op_regions",
+	"ACPI_MTX_op_regions",
 	"ACPI_MTX_Namespace",
 	"ACPI_MTX_Events",
 	"ACPI_MTX_Hardware",
 	"ACPI_MTX_Caches",
 	"ACPI_MTX_Memory",
-	"ACPI_MTX_Debug_cmd_complete",
-	"ACPI_MTX_Debug_cmd_ready",
+	"ACPI_MTX_debug_cmd_complete",
+	"ACPI_MTX_debug_cmd_ready",
 };
 
 #endif
@@ -158,9 +157,9 @@
 
 /*
  * The Node describes a named object that appears in the AML
- * An Acpi_node is used to store Nodes.
+ * An acpi_node is used to store Nodes.
  *
- * Data_type is used to differentiate between internal descriptors, and MUST
+ * data_type is used to differentiate between internal descriptors, and MUST
  * be the first byte in this structure.
  */
 
@@ -168,14 +167,14 @@
 {
 	u32                     integer;
 	char                    ascii[4];
-} ACPI_NAME_UNION;
+} acpi_name_union;
 
 typedef struct acpi_node
 {
 	u8                      descriptor;     /* Used to differentiate object descriptor types */
 	u8                      type;           /* Type associated with this name */
 	u16                     owner_id;
-	ACPI_NAME_UNION         name;           /* ACPI Name, always 4 chars per ACPI spec */
+	acpi_name_union         name;           /* ACPI Name, always 4 chars per ACPI spec */
 
 
 	union acpi_operand_obj  *object;        /* Pointer to attached ACPI object (optional) */
@@ -215,7 +214,7 @@
 	u8                      *aml_start;
 	u64                     physical_address;
 	u32                     aml_length;
-	ACPI_SIZE               length;
+	acpi_size               length;
 	u32                     count;
 	acpi_owner_id           table_id;
 	u8                      type;
@@ -288,7 +287,7 @@
 	u8                      attribute;
 	u8                      field_type;
 
-} ACPI_CREATE_FIELD_INFO;
+} acpi_create_field_info;
 
 
 /*****************************************************************************
@@ -305,7 +304,7 @@
 	u16                     register_count;
 	u8                      block_base_number;
 
-} ACPI_GPE_BLOCK_INFO;
+} acpi_gpe_block_info;
 
 /* Information about a particular GPE register pair */
 
@@ -318,7 +317,7 @@
 	u8                      wake_enable;    /* Mask of bits to keep enabled when sleeping */
 	u8                      base_gpe_number; /* Base GPE number for this register */
 
-} ACPI_GPE_REGISTER_INFO;
+} acpi_gpe_register_info;
 
 
 #define ACPI_GPE_LEVEL_TRIGGERED        1
@@ -336,14 +335,14 @@
 	u8                      bit_mask;
 
 
-} ACPI_GPE_NUMBER_INFO;
+} acpi_gpe_number_info;
 
 
 typedef struct
 {
 	u8                      number_index;
 
-} ACPI_GPE_INDEX_INFO;
+} acpi_gpe_index_info;
 
 /* Information about each particular fixed event */
 
@@ -352,7 +351,7 @@
 	acpi_event_handler      handler;        /* Address of handler. */
 	void                    *context;       /* Context to be passed to handler */
 
-} ACPI_FIXED_EVENT_HANDLER;
+} acpi_fixed_event_handler;
 
 
 typedef struct
@@ -481,12 +480,12 @@
 typedef struct acpi_thread_state
 {
 	ACPI_STATE_COMMON
-	struct acpi_walk_state  *walk_state_list;       /* Head of list of Walk_states for this thread */
+	struct acpi_walk_state  *walk_state_list;       /* Head of list of walk_states for this thread */
 	union acpi_operand_obj  *acquired_mutex_list;   /* List of all currently acquired mutexes */
 	u32                     thread_id;              /* Running thread ID */
 	u16                     current_sync_level;     /* Mutex Sync (nested acquire) level */
 
-} ACPI_THREAD_STATE;
+} acpi_thread_state;
 
 
 /*
@@ -536,7 +535,7 @@
 	acpi_scope_state        scope;
 	acpi_pscope_state       parse_scope;
 	acpi_pkg_state          pkg;
-	ACPI_THREAD_STATE       thread;
+	acpi_thread_state       thread;
 	acpi_result_values      results;
 	acpi_notify_info        notify;
 
@@ -622,11 +621,11 @@
 typedef struct acpi_parseobj_common
 {
 	ACPI_PARSE_COMMON
-} ACPI_PARSE_OBJ_COMMON;
+} acpi_parse_obj_common;
 
 
 /*
- * Extended Op for named ops (Scope, Method, etc.), deferred ops (Methods and Op_regions),
+ * Extended Op for named ops (Scope, Method, etc.), deferred ops (Methods and op_regions),
  * and bytelists.
  */
 typedef struct acpi_parseobj_named
@@ -637,7 +636,7 @@
 	u32                     length;         /* AML length */
 	u32                     name;           /* 4-byte name or zero if no name */
 
-} ACPI_PARSE_OBJ_NAMED;
+} acpi_parse_obj_named;
 
 
 /* The parse node is the fundamental element of the parse tree */
@@ -673,14 +672,14 @@
 	u8                          extra;
 	char                        parse_op_name[12];
 
-} ACPI_PARSE_OBJ_ASL;
+} acpi_parse_obj_asl;
 
 
 typedef union acpi_parse_obj
 {
-	ACPI_PARSE_OBJ_COMMON       common;
-	ACPI_PARSE_OBJ_NAMED        named;
-	ACPI_PARSE_OBJ_ASL          asl;
+	acpi_parse_obj_common       common;
+	acpi_parse_obj_named        named;
+	acpi_parse_obj_asl          asl;
 
 } acpi_parse_object;
 
@@ -713,7 +712,7 @@
 #define ACPI_PARSEOP_BYTELIST                   0x08
 #define ACPI_PARSEOP_IN_CACHE                   0x80
 
-/* Parse object Disasm_flags */
+/* Parse object disasm_flags */
 
 #define ACPI_PARSEOP_IGNORE                     0x01
 #define ACPI_PARSEOP_PARAMLIST                  0x02
@@ -735,7 +734,7 @@
 	u8                      bit_position;
 	u16                     access_bit_mask;
 
-} ACPI_BIT_REGISTER_INFO;
+} acpi_bit_register_info;
 
 
 /*
@@ -753,7 +752,7 @@
 #define ACPI_REGISTER_SMI_COMMAND_BLOCK         0x09
 
 
-/* Masks used to access the Bit_registers */
+/* Masks used to access the bit_registers */
 
 #define ACPI_BITMASK_TIMER_STATUS               0x0001
 #define ACPI_BITMASK_BUS_MASTER_STATUS          0x0010
@@ -786,7 +785,7 @@
 #define ACPI_BITMASK_ARB_DISABLE                0x0001
 
 
-/* Raw bit position of each Bit_register */
+/* Raw bit position of each bit_register */
 
 #define ACPI_BITPOSITION_TIMER_STATUS           0x00
 #define ACPI_BITPOSITION_BUS_MASTER_STATUS      0x04
@@ -818,7 +817,7 @@
  ****************************************************************************/
 
 
-/* Resource_type values */
+/* resource_type values */
 
 #define ACPI_RESOURCE_TYPE_MEMORY_RANGE         0
 #define ACPI_RESOURCE_TYPE_IO_RANGE             1
@@ -981,7 +980,7 @@
 	char                        *list_name;
 #endif
 
-} ACPI_MEMORY_LIST;
+} acpi_memory_list;
 
 
 #endif /* __ACLOCAL_H__ */
diff -Nru a/drivers/acpi/include/acmacros.h b/drivers/acpi/include/acmacros.h
--- a/drivers/acpi/include/acmacros.h	Mon Dec 23 21:21:55 2002
+++ b/drivers/acpi/include/acmacros.h	Mon Dec 23 21:21:55 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: acmacros.h - C macros for the entire subsystem.
- *       $Revision: 135 $
  *
  *****************************************************************************/
 
@@ -71,7 +70,7 @@
 #define ACPI_HIDWORD(l)                 ((u32)(((*(uint64_struct *)(void *)(&l))).hi))
 
 #define ACPI_GET_ADDRESS(a)             (a)
-#define ACPI_STORE_ADDRESS(a,b)         ((a)=(ACPI_PHYSICAL_ADDRESS)(b))
+#define ACPI_STORE_ADDRESS(a,b)         ((a)=(acpi_physical_address)(b))
 #define ACPI_VALID_ADDRESS(a)           (a)
 #endif
 #endif
@@ -84,14 +83,14 @@
 
 /* Pointer arithmetic */
 
-#define ACPI_PTR_ADD(t,a,b)             (t *) (void *)((char *)(a) + (NATIVE_UINT)(b))
-#define ACPI_PTR_DIFF(a,b)              (NATIVE_UINT) ((char *)(a) - (char *)(b))
+#define ACPI_PTR_ADD(t,a,b)             (t *) (void *)((char *)(a) + (acpi_native_uint)(b))
+#define ACPI_PTR_DIFF(a,b)              (acpi_native_uint) ((char *)(a) - (char *)(b))
 
 /* Pointer/Integer type conversions */
 
-#define ACPI_TO_POINTER(i)              ACPI_PTR_ADD (void, (void *) NULL,(NATIVE_UINT)i)
+#define ACPI_TO_POINTER(i)              ACPI_PTR_ADD (void, (void *) NULL,(acpi_native_uint)i)
 #define ACPI_TO_INTEGER(p)              ACPI_PTR_DIFF (p,(void *) NULL)
-#define ACPI_OFFSET(d,f)                (ACPI_SIZE) ACPI_PTR_DIFF (&(((d *)0)->f),(void *) NULL)
+#define ACPI_OFFSET(d,f)                (acpi_size) ACPI_PTR_DIFF (&(((d *)0)->f),(void *) NULL)
 #define ACPI_FADT_OFFSET(f)             ACPI_OFFSET (FADT_DESCRIPTOR, f)
 
 #define ACPI_CAST_PTR(t, p)             ((t *)(void *)(p))
@@ -178,15 +177,15 @@
 /*
  * Rounding macros (Power of two boundaries only)
  */
-#define ACPI_ROUND_DOWN(value,boundary)      (((NATIVE_UINT)(value)) & (~(((NATIVE_UINT) boundary)-1)))
-#define ACPI_ROUND_UP(value,boundary)        ((((NATIVE_UINT)(value)) + (((NATIVE_UINT) boundary)-1)) & (~(((NATIVE_UINT) boundary)-1)))
+#define ACPI_ROUND_DOWN(value,boundary)      (((acpi_native_uint)(value)) & (~(((acpi_native_uint) boundary)-1)))
+#define ACPI_ROUND_UP(value,boundary)        ((((acpi_native_uint)(value)) + (((acpi_native_uint) boundary)-1)) & (~(((acpi_native_uint) boundary)-1)))
 
 #define ACPI_ROUND_DOWN_TO_32_BITS(a)        ACPI_ROUND_DOWN(a,4)
 #define ACPI_ROUND_DOWN_TO_64_BITS(a)        ACPI_ROUND_DOWN(a,8)
 #define ACPI_ROUND_DOWN_TO_NATIVE_WORD(a)    ACPI_ROUND_DOWN(a,ALIGNED_ADDRESS_BOUNDARY)
 
-#define ACPI_ROUND_UP_TO_32_bITS(a)          ACPI_ROUND_UP(a,4)
-#define ACPI_ROUND_UP_TO_64_bITS(a)          ACPI_ROUND_UP(a,8)
+#define ACPI_ROUND_UP_to_32_bITS(a)          ACPI_ROUND_UP(a,4)
+#define ACPI_ROUND_UP_to_64_bITS(a)          ACPI_ROUND_UP(a,8)
 #define ACPI_ROUND_UP_TO_NATIVE_WORD(a)      ACPI_ROUND_UP(a,ALIGNED_ADDRESS_BOUNDARY)
 
 
@@ -256,8 +255,8 @@
  *
  * The "Descriptor" field is the first field in both structures.
  */
-#define ACPI_GET_DESCRIPTOR_TYPE(d)     (((ACPI_DESCRIPTOR *)(void *)(d))->descriptor_id)
-#define ACPI_SET_DESCRIPTOR_TYPE(d,t)   (((ACPI_DESCRIPTOR *)(void *)(d))->descriptor_id = t)
+#define ACPI_GET_DESCRIPTOR_TYPE(d)     (((acpi_descriptor *)(void *)(d))->descriptor_id)
+#define ACPI_SET_DESCRIPTOR_TYPE(d,t)   (((acpi_descriptor *)(void *)(d))->descriptor_id = t)
 
 
 /* Macro to test the object type */
@@ -269,32 +268,16 @@
 #define ACPI_IS_SINGLE_TABLE(x)         (((x) & 0x01) == ACPI_TABLE_SINGLE ? 1 : 0)
 
 /*
- * Macro to check if a pointer is within an ACPI table.
- * Parameter (a) is the pointer to check.  Parameter (b) must be defined
- * as a pointer to an acpi_table_header.  (b+1) then points past the header,
- * and ((u8 *)b+b->Length) points one byte past the end of the table.
- */
-#if ACPI_MACHINE_WIDTH != 16
-#define ACPI_IS_IN_ACPI_TABLE(a,b)      (((u8 *)(a) >= (u8 *)(b + 1)) &&\
-							 ((u8 *)(a) < ((u8 *)b + b->length)))
-
-#else
-#define ACPI_IS_IN_ACPI_TABLE(a,b)      (_segment)(a) == (_segment)(b) &&\
-									 (((u8 *)(a) >= (u8 *)(b + 1)) &&\
-									 ((u8 *)(a) < ((u8 *)b + b->length)))
-#endif
-
-/*
  * Macros for the master AML opcode table
  */
 #if defined(ACPI_DISASSEMBLER) || defined (ACPI_DEBUG_OUTPUT)
-#define ACPI_OP(name,Pargs,Iargs,obj_type,class,type,flags)    {name,Pargs,Iargs,flags,obj_type,class,type}
+#define ACPI_OP(name,Pargs,Iargs,obj_type,class,type,flags)    {name,(u32)(Pargs),(u32)(Iargs),(u32)(flags),obj_type,class,type}
 #else
-#define ACPI_OP(name,Pargs,Iargs,obj_type,class,type,flags)    {Pargs,Iargs,flags,obj_type,class,type}
+#define ACPI_OP(name,Pargs,Iargs,obj_type,class,type,flags)    {(u32)(Pargs),(u32)(Iargs),(u32)(flags),obj_type,class,type}
 #endif
 
 #ifdef ACPI_DISASSEMBLER
-#define ACPI_DISASM_ONLY_MEMBERS(a)      a;
+#define ACPI_DISASM_ONLY_MEMBERS(a)     a;
 #else
 #define ACPI_DISASM_ONLY_MEMBERS(a)
 #endif
@@ -335,10 +318,10 @@
  * 5) Expand address to 64 bits
  */
 #define ASL_BUILD_GAS_FROM_ENTRY(a,b,c,d)   do {a.address_space_id = (u8) d;\
-											 a.register_bit_width = (u8) ACPI_MUL_8 (b);\
-											 a.register_bit_offset = 0;\
-											 a.reserved = 0;\
-											 ACPI_STORE_ADDRESS (a.address,(ACPI_PHYSICAL_ADDRESS) c);} while (0)
+							  a.register_bit_width = (u8) ACPI_MUL_8 (b);\
+							  a.register_bit_offset = 0;\
+							  a.reserved = 0;\
+							  ACPI_STORE_ADDRESS (a.address,(acpi_physical_address) c);} while (0)
 
 /* ACPI V1.0 entries -- address space is always I/O */
 
@@ -360,9 +343,9 @@
 #ifdef ACPI_DEBUG_OUTPUT
 
 #define ACPI_REPORT_INFO(fp)                {acpi_ut_report_info(_THIS_MODULE,__LINE__,_COMPONENT); \
-												acpi_os_printf ACPI_PARAM_LIST(fp);}
+									   acpi_os_printf ACPI_PARAM_LIST(fp);}
 #define ACPI_REPORT_ERROR(fp)               {acpi_ut_report_error(_THIS_MODULE,__LINE__,_COMPONENT); \
-												acpi_os_printf ACPI_PARAM_LIST(fp);}
+											 acpi_os_printf ACPI_PARAM_LIST(fp);}
 #define ACPI_REPORT_WARNING(fp)             {acpi_ut_report_warning(_THIS_MODULE,__LINE__,_COMPONENT); \
 												acpi_os_printf ACPI_PARAM_LIST(fp);}
 #define ACPI_REPORT_NSERROR(s,e)            acpi_ns_report_error(_THIS_MODULE,__LINE__,_COMPONENT, s, e);
@@ -403,7 +386,7 @@
 /*
  * Function entry tracing.
  * The first parameter should be the procedure name as a quoted string.  This is declared
- * as a local string ("_Proc_name) so that it can be also used by the function exit macros below.
+ * as a local string ("_proc_name) so that it can be also used by the function exit macros below.
  */
 
 #define ACPI_FUNCTION_NAME(a)           acpi_debug_print_info _dbg;     \
@@ -427,7 +410,7 @@
  * WARNING: These macros include a return statement.  This is usually considered
  * bad form, but having a separate exit macro is very ugly and difficult to maintain.
  * One of the FUNCTION_TRACE macros above must be used in conjunction with these macros
- * so that "_Proc_name" is defined.
+ * so that "_proc_name" is defined.
  */
 #ifdef ACPI_USE_DO_WHILE_0
 #define ACPI_DO_WHILE0(a)               do a while(0)
@@ -572,8 +555,8 @@
 
 /* Memory allocation */
 
-#define ACPI_MEM_ALLOCATE(a)            acpi_ut_allocate((ACPI_SIZE)(a),_COMPONENT,_THIS_MODULE,__LINE__)
-#define ACPI_MEM_CALLOCATE(a)           acpi_ut_callocate((ACPI_SIZE)(a), _COMPONENT,_THIS_MODULE,__LINE__)
+#define ACPI_MEM_ALLOCATE(a)            acpi_ut_allocate((acpi_size)(a),_COMPONENT,_THIS_MODULE,__LINE__)
+#define ACPI_MEM_CALLOCATE(a)           acpi_ut_callocate((acpi_size)(a), _COMPONENT,_THIS_MODULE,__LINE__)
 #define ACPI_MEM_FREE(a)                acpi_os_free(a)
 #define ACPI_MEM_TRACKING(a)
 
@@ -582,8 +565,8 @@
 
 /* Memory allocation */
 
-#define ACPI_MEM_ALLOCATE(a)            acpi_ut_allocate_and_track((ACPI_SIZE)(a),_COMPONENT,_THIS_MODULE,__LINE__)
-#define ACPI_MEM_CALLOCATE(a)           acpi_ut_callocate_and_track((ACPI_SIZE)(a), _COMPONENT,_THIS_MODULE,__LINE__)
+#define ACPI_MEM_ALLOCATE(a)            acpi_ut_allocate_and_track((acpi_size)(a),_COMPONENT,_THIS_MODULE,__LINE__)
+#define ACPI_MEM_CALLOCATE(a)           acpi_ut_callocate_and_track((acpi_size)(a), _COMPONENT,_THIS_MODULE,__LINE__)
 #define ACPI_MEM_FREE(a)                acpi_ut_free_and_track(a,_COMPONENT,_THIS_MODULE,__LINE__)
 #define ACPI_MEM_TRACKING(a)            a
 
diff -Nru a/drivers/acpi/include/acnamesp.h b/drivers/acpi/include/acnamesp.h
--- a/drivers/acpi/include/acnamesp.h	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/include/acnamesp.h	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: acnamesp.h - Namespace subcomponent prototypes and defines
- *       $Revision: 132 $
  *
  *****************************************************************************/
 
@@ -27,12 +26,12 @@
 #define __ACNAMESP_H__
 
 
-/* To search the entire name space, pass this as Search_base */
+/* To search the entire name space, pass this as search_base */
 
 #define ACPI_NS_ALL                 ((acpi_handle)0)
 
 /*
- * Elements of Acpi_ns_properties are bit significant
+ * Elements of acpi_ns_properties are bit significant
  * and should be one-to-one with values of acpi_object_type
  */
 #define ACPI_NS_NORMAL              0
@@ -50,7 +49,7 @@
 #define ACPI_NS_SYSTEM_BUS          "_SB_"
 
 
-/* Flags for Acpi_ns_lookup, Acpi_ns_search_and_enter */
+/* Flags for acpi_ns_lookup, acpi_ns_search_and_enter */
 
 #define ACPI_NS_NO_UPSEARCH         0
 #define ACPI_NS_SEARCH_PARENT       0x01
@@ -304,7 +303,7 @@
 void
 acpi_ns_build_external_path (
 	acpi_namespace_node     *node,
-	ACPI_SIZE               size,
+	acpi_size               size,
 	char                    *name_buffer);
 
 char *
@@ -332,7 +331,7 @@
 	u32                     flags,
 	acpi_namespace_node     **out_node);
 
-ACPI_SIZE
+acpi_size
 acpi_ns_get_pathname_length (
 	acpi_namespace_node     *node);
 
@@ -358,18 +357,18 @@
 acpi_status
 acpi_ns_attach_data (
 	acpi_namespace_node     *node,
-	ACPI_OBJECT_HANDLER     handler,
+	acpi_object_handler     handler,
 	void                    *data);
 
 acpi_status
 acpi_ns_detach_data (
 	acpi_namespace_node     *node,
-	ACPI_OBJECT_HANDLER     handler);
+	acpi_object_handler     handler);
 
 acpi_status
 acpi_ns_get_attached_data (
 	acpi_namespace_node     *node,
-	ACPI_OBJECT_HANDLER     handler,
+	acpi_object_handler     handler,
 	void                    **data);
 
 
diff -Nru a/drivers/acpi/include/acobject.h b/drivers/acpi/include/acobject.h
--- a/drivers/acpi/include/acobject.h	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/include/acobject.h	Mon Dec 23 21:21:51 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Name: acobject.h - Definition of acpi_operand_object  (Internal object only)
- *       $Revision: 115 $
  *
  *****************************************************************************/
 
@@ -44,7 +43,7 @@
 /*
  * Common area for all objects.
  *
- * Data_type is used to differentiate between internal descriptors, and MUST
+ * data_type is used to differentiate between internal descriptors, and MUST
  * be the first byte in this structure.
  */
 #define ACPI_OBJECT_COMMON_HEADER           /* SIZE/ALIGNMENT: 32 bits, one ptr plus trailing 8-bit flag */\
@@ -71,7 +70,7 @@
  */
 #define ACPI_COMMON_FIELD_INFO              /* SIZE/ALIGNMENT: 24 bits + three 32-bit values */\
 	u8                          field_flags;        /* Access, update, and lock bits */\
-	u8                          attribute;          /* From Access_as keyword */\
+	u8                          attribute;          /* From access_as keyword */\
 	u8                          access_byte_width;  /* Read/Write size in bytes */\
 	u32                         bit_length;         /* Length of field in bits */\
 	u32                         base_byte_offset;   /* Byte offset within containing object */\
@@ -109,7 +108,7 @@
 {
 	ACPI_OBJECT_COMMON_HEADER
 
-} ACPI_OBJECT_COMMON;
+} acpi_object_common;
 
 
 typedef struct acpi_object_integer
@@ -118,7 +117,7 @@
 
 	acpi_integer                value;
 
-} ACPI_OBJECT_INTEGER;
+} acpi_object_integer;
 
 
 typedef struct acpi_object_string                   /* Null terminated, ASCII characters only */
@@ -127,7 +126,7 @@
 	ACPI_COMMON_BUFFER_INFO
 	char                        *pointer;           /* String in AML stream or allocated string */
 
-} ACPI_OBJECT_STRING;
+} acpi_object_string;
 
 
 typedef struct acpi_object_buffer
@@ -139,7 +138,7 @@
 	u8                          *aml_start;
 	u32                         aml_length;
 
-} ACPI_OBJECT_BUFFER;
+} acpi_object_buffer;
 
 
 typedef struct acpi_object_package
@@ -150,9 +149,9 @@
 	u32                         aml_length;
 	u8                          *aml_start;
 	acpi_namespace_node         *node;              /* Link back to parent node */
-	union acpi_operand_obj      **elements;         /* Array of pointers to Acpi_objects */
+	union acpi_operand_obj      **elements;         /* Array of pointers to acpi_objects */
 
-} ACPI_OBJECT_PACKAGE;
+} acpi_object_package;
 
 
 /******************************************************************************
@@ -166,7 +165,7 @@
 	ACPI_OBJECT_COMMON_HEADER
 	void                        *semaphore;
 
-} ACPI_OBJECT_EVENT;
+} acpi_object_event;
 
 
 #define INFINITE_CONCURRENCY        0xFF
@@ -186,7 +185,7 @@
 	u8                          thread_count;
 	acpi_owner_id               owning_id;
 
-} ACPI_OBJECT_METHOD;
+} acpi_object_method;
 
 
 typedef struct acpi_object_mutex
@@ -201,7 +200,7 @@
 	union acpi_operand_obj      *next;              /* Link for list of acquired mutexes */
 	acpi_namespace_node         *node;              /* containing object */
 
-} ACPI_OBJECT_MUTEX;
+} acpi_object_mutex;
 
 
 typedef struct acpi_object_region
@@ -214,14 +213,14 @@
 	acpi_namespace_node         *node;              /* containing object */
 	union acpi_operand_obj      *next;
 	u32                         length;
-	ACPI_PHYSICAL_ADDRESS       address;
+	acpi_physical_address       address;
 
-} ACPI_OBJECT_REGION;
+} acpi_object_region;
 
 
 /******************************************************************************
  *
- * Objects that can be notified.  All share a common Notify_info area.
+ * Objects that can be notified.  All share a common notify_info area.
  *
  *****************************************************************************/
 
@@ -230,7 +229,7 @@
 	ACPI_OBJECT_COMMON_HEADER
 	ACPI_COMMON_NOTIFY_INFO
 
-} ACPI_OBJECT_NOTIFY_COMMON;
+} acpi_object_notify_common;
 
 
 typedef struct acpi_object_device
@@ -238,7 +237,7 @@
 	ACPI_OBJECT_COMMON_HEADER
 	ACPI_COMMON_NOTIFY_INFO
 
-} ACPI_OBJECT_DEVICE;
+} acpi_object_device;
 
 
 typedef struct acpi_object_power_resource
@@ -249,7 +248,7 @@
 	u32                         system_level;
 	u32                         resource_order;
 
-} ACPI_OBJECT_POWER_RESOURCE;
+} acpi_object_power_resource;
 
 
 typedef struct acpi_object_processor
@@ -259,9 +258,9 @@
 
 	u32                         proc_id;
 	u32                         length;
-	ACPI_IO_ADDRESS             address;
+	acpi_io_address             address;
 
-} ACPI_OBJECT_PROCESSOR;
+} acpi_object_processor;
 
 
 typedef struct acpi_object_thermal_zone
@@ -270,7 +269,7 @@
 	ACPI_COMMON_NOTIFY_INFO
 
 
-} ACPI_OBJECT_THERMAL_ZONE;
+} acpi_object_thermal_zone;
 
 
 /******************************************************************************
@@ -285,16 +284,16 @@
 	ACPI_COMMON_FIELD_INFO
 	union acpi_operand_obj      *region_obj;        /* Containing Operation Region object */
 			 /* (REGION/BANK fields only) */
-} ACPI_OBJECT_FIELD_COMMON;
+} acpi_object_field_common;
 
 
 typedef struct acpi_object_region_field
 {
 	ACPI_OBJECT_COMMON_HEADER
 	ACPI_COMMON_FIELD_INFO
-	union acpi_operand_obj      *region_obj;        /* Containing Op_region object */
+	union acpi_operand_obj      *region_obj;        /* Containing op_region object */
 
-} ACPI_OBJECT_REGION_FIELD;
+} acpi_object_region_field;
 
 
 typedef struct acpi_object_bank_field
@@ -302,10 +301,10 @@
 	ACPI_OBJECT_COMMON_HEADER
 	ACPI_COMMON_FIELD_INFO
 
-	union acpi_operand_obj      *region_obj;        /* Containing Op_region object */
-	union acpi_operand_obj      *bank_obj;          /* Bank_select Register object */
+	union acpi_operand_obj      *region_obj;        /* Containing op_region object */
+	union acpi_operand_obj      *bank_obj;          /* bank_select Register object */
 
-} ACPI_OBJECT_BANK_FIELD;
+} acpi_object_bank_field;
 
 
 typedef struct acpi_object_index_field
@@ -314,17 +313,17 @@
 	ACPI_COMMON_FIELD_INFO
 
 	/*
-	 * No "Region_obj" pointer needed since the Index and Data registers
+	 * No "region_obj" pointer needed since the Index and Data registers
 	 * are each field definitions unto themselves.
 	 */
 	union acpi_operand_obj      *index_obj;         /* Index register */
 	union acpi_operand_obj      *data_obj;          /* Data register */
 
 
-} ACPI_OBJECT_INDEX_FIELD;
+} acpi_object_index_field;
 
 
-/* The Buffer_field is different in that it is part of a Buffer, not an Op_region */
+/* The buffer_field is different in that it is part of a Buffer, not an op_region */
 
 typedef struct acpi_object_buffer_field
 {
@@ -333,7 +332,7 @@
 
 	union acpi_operand_obj      *buffer_obj;        /* Containing Buffer object */
 
-} ACPI_OBJECT_BUFFER_FIELD;
+} acpi_object_buffer_field;
 
 
 /******************************************************************************
@@ -350,7 +349,7 @@
 	acpi_notify_handler         handler;
 	void                        *context;
 
-} ACPI_OBJECT_NOTIFY_HANDLER;
+} acpi_object_notify_handler;
 
 
 /* Flags for address handler */
@@ -372,7 +371,7 @@
 	union acpi_operand_obj      *region_list;       /* regions using this handler */
 	union acpi_operand_obj      *next;
 
-} ACPI_OBJECT_ADDR_HANDLER;
+} acpi_object_addr_handler;
 
 
 /******************************************************************************
@@ -383,29 +382,29 @@
 
 /*
  * The Reference object type is used for these opcodes:
- * Arg[0-6], Local[0-7], Index_op, Name_op, Zero_op, One_op, Ones_op, Debug_op
+ * Arg[0-6], Local[0-7], index_op, name_op, zero_op, one_op, ones_op, debug_op
  */
 typedef struct acpi_object_reference
 {
 	ACPI_OBJECT_COMMON_HEADER
 
-	u8                          target_type;        /* Used for Index_op */
+	u8                          target_type;        /* Used for index_op */
 	u16                         opcode;
-	u32                         offset;             /* Used for Arg_op, Local_op, and Index_op */
+	u32                         offset;             /* Used for arg_op, local_op, and index_op */
 
-	void                        *object;            /* Name_op=>HANDLE to obj, Index_op=>acpi_operand_object */
+	void                        *object;            /* name_op=>HANDLE to obj, index_op=>acpi_operand_object */
 	acpi_namespace_node         *node;
 	union acpi_operand_obj      **where;
 
-} ACPI_OBJECT_REFERENCE;
+} acpi_object_reference;
 
 
 /*
  * Extra object is used as additional storage for types that
- * have AML code in their declarations (Term_args) that must be
+ * have AML code in their declarations (term_args) that must be
  * evaluated at run time.
  *
- * Currently: Region and Field_unit types
+ * Currently: Region and field_unit types
  */
 typedef struct acpi_object_extra
 {
@@ -417,7 +416,7 @@
 	acpi_namespace_node         *method_REG;        /* _REG method for this region (if any) */
 	void                        *region_context;    /* Region-specific data */
 
-} ACPI_OBJECT_EXTRA;
+} acpi_object_extra;
 
 
 /* Additional data that can be attached to namespace nodes */
@@ -425,10 +424,10 @@
 typedef struct acpi_object_data
 {
 	ACPI_OBJECT_COMMON_HEADER
-	ACPI_OBJECT_HANDLER         handler;
+	acpi_object_handler         handler;
 	void                        *pointer;
 
-} ACPI_OBJECT_DATA;
+} acpi_object_data;
 
 
 /* Structure used when objects are cached for reuse */
@@ -438,7 +437,7 @@
 	ACPI_OBJECT_COMMON_HEADER
 	union acpi_operand_obj      *next;              /* Link for object cache and internal lists*/
 
-} ACPI_OBJECT_CACHE_LIST;
+} acpi_object_cache_list;
 
 
 /******************************************************************************
@@ -449,44 +448,44 @@
 
 typedef union acpi_operand_obj
 {
-	ACPI_OBJECT_COMMON          common;
+	acpi_object_common          common;
 
-	ACPI_OBJECT_INTEGER         integer;
-	ACPI_OBJECT_STRING          string;
-	ACPI_OBJECT_BUFFER          buffer;
-	ACPI_OBJECT_PACKAGE         package;
-
-	ACPI_OBJECT_EVENT           event;
-	ACPI_OBJECT_METHOD          method;
-	ACPI_OBJECT_MUTEX           mutex;
-	ACPI_OBJECT_REGION          region;
-
-	ACPI_OBJECT_NOTIFY_COMMON   common_notify;
-	ACPI_OBJECT_DEVICE          device;
-	ACPI_OBJECT_POWER_RESOURCE  power_resource;
-	ACPI_OBJECT_PROCESSOR       processor;
-	ACPI_OBJECT_THERMAL_ZONE    thermal_zone;
-
-	ACPI_OBJECT_FIELD_COMMON    common_field;
-	ACPI_OBJECT_REGION_FIELD    field;
-	ACPI_OBJECT_BUFFER_FIELD    buffer_field;
-	ACPI_OBJECT_BANK_FIELD      bank_field;
-	ACPI_OBJECT_INDEX_FIELD     index_field;
-
-	ACPI_OBJECT_NOTIFY_HANDLER  notify_handler;
-	ACPI_OBJECT_ADDR_HANDLER    addr_handler;
-
-	ACPI_OBJECT_REFERENCE       reference;
-	ACPI_OBJECT_EXTRA           extra;
-	ACPI_OBJECT_DATA            data;
-	ACPI_OBJECT_CACHE_LIST      cache;
+	acpi_object_integer         integer;
+	acpi_object_string          string;
+	acpi_object_buffer          buffer;
+	acpi_object_package         package;
+
+	acpi_object_event           event;
+	acpi_object_method          method;
+	acpi_object_mutex           mutex;
+	acpi_object_region          region;
+
+	acpi_object_notify_common   common_notify;
+	acpi_object_device          device;
+	acpi_object_power_resource  power_resource;
+	acpi_object_processor       processor;
+	acpi_object_thermal_zone    thermal_zone;
+
+	acpi_object_field_common    common_field;
+	acpi_object_region_field    field;
+	acpi_object_buffer_field    buffer_field;
+	acpi_object_bank_field      bank_field;
+	acpi_object_index_field     index_field;
+
+	acpi_object_notify_handler  notify_handler;
+	acpi_object_addr_handler    addr_handler;
+
+	acpi_object_reference       reference;
+	acpi_object_extra           extra;
+	acpi_object_data            data;
+	acpi_object_cache_list      cache;
 
 } acpi_operand_object;
 
 
 /******************************************************************************
  *
- * ACPI_DESCRIPTOR - objects that share a common descriptor identifier
+ * acpi_descriptor - objects that share a common descriptor identifier
  *
  *****************************************************************************/
 
@@ -517,7 +516,7 @@
 	acpi_namespace_node         node;
 	acpi_parse_object           op;
 
-} ACPI_DESCRIPTOR;
+} acpi_descriptor;
 
 
 #endif /* _ACOBJECT_H */
diff -Nru a/drivers/acpi/include/acoutput.h b/drivers/acpi/include/acoutput.h
--- a/drivers/acpi/include/acoutput.h	Mon Dec 23 21:21:53 2002
+++ b/drivers/acpi/include/acoutput.h	Mon Dec 23 21:21:53 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: acoutput.h -- debug output
- *       $Revision: 91 $
  *
  *****************************************************************************/
 
@@ -32,7 +31,7 @@
  * component basis and a per-exception-type basis.
  */
 
-/* Component IDs are used in the global "Debug_layer" */
+/* Component IDs are used in the global "debug_layer" */
 
 #define ACPI_UTILITIES              0x00000001
 #define ACPI_HARDWARE               0x00000002
@@ -105,7 +104,7 @@
 #define ACPI_LV_INTERRUPTS          0x08000000
 #define ACPI_LV_VERBOSITY3          0x0F000000 | ACPI_LV_VERBOSITY2
 
-/* Exceptionally verbose output -- also used in the global "Debug_level" */
+/* Exceptionally verbose output -- also used in the global "debug_level" */
 
 #define ACPI_LV_AML_DISASSEMBLE     0x10000000
 #define ACPI_LV_VERBOSE_INFO        0x20000000
@@ -118,9 +117,9 @@
 /*
  * Debug level macros that are used in the DEBUG_PRINT macros
  */
-#define ACPI_DEBUG_LEVEL(dl)       dl,__LINE__,&_dbg
+#define ACPI_DEBUG_LEVEL(dl)        (u32) dl,__LINE__,&_dbg
 
-/* Exception level -- used in the global "Debug_level" */
+/* Exception level -- used in the global "debug_level" */
 
 #define ACPI_DB_ERROR               ACPI_DEBUG_LEVEL (ACPI_LV_ERROR)
 #define ACPI_DB_WARN                ACPI_DEBUG_LEVEL (ACPI_LV_WARN)
@@ -130,7 +129,7 @@
 #define ACPI_DB_ALL_EXCEPTIONS      ACPI_DEBUG_LEVEL (ACPI_LV_ALL_EXCEPTIONS)
 
 
-/* Trace level -- also used in the global "Debug_level" */
+/* Trace level -- also used in the global "debug_level" */
 
 #define ACPI_DB_INIT_NAMES          ACPI_DEBUG_LEVEL (ACPI_LV_INIT_NAMES)
 #define ACPI_DB_THREADS             ACPI_DEBUG_LEVEL (ACPI_LV_THREADS)
@@ -157,7 +156,7 @@
 #define ACPI_DB_ALL                 ACPI_DEBUG_LEVEL (ACPI_LV_ALL)
 
 
-/* Defaults for Debug_level, debug and normal */
+/* Defaults for debug_level, debug and normal */
 
 #define ACPI_DEBUG_DEFAULT          (ACPI_LV_INIT | ACPI_LV_WARN | ACPI_LV_ERROR | ACPI_LV_DEBUG_OBJECT)
 #define ACPI_NORMAL_DEFAULT         (ACPI_LV_INIT | ACPI_LV_WARN | ACPI_LV_ERROR | ACPI_LV_DEBUG_OBJECT)
diff -Nru a/drivers/acpi/include/acparser.h b/drivers/acpi/include/acparser.h
--- a/drivers/acpi/include/acparser.h	Mon Dec 23 21:21:58 2002
+++ b/drivers/acpi/include/acparser.h	Mon Dec 23 21:21:58 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: acparser.h - AML Parser subcomponent prototypes and defines
- *       $Revision: 64 $
  *
  *****************************************************************************/
 
diff -Nru a/drivers/acpi/include/acpi.h b/drivers/acpi/include/acpi.h
--- a/drivers/acpi/include/acpi.h	Mon Dec 23 21:21:55 2002
+++ b/drivers/acpi/include/acpi.h	Mon Dec 23 21:21:55 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: acpi.h - Master include file, Publics and external data.
- *       $Revision: 55 $
  *
  *****************************************************************************/
 
diff -Nru a/drivers/acpi/include/acpiosxf.h b/drivers/acpi/include/acpiosxf.h
--- a/drivers/acpi/include/acpiosxf.h	Mon Dec 23 21:21:50 2002
+++ b/drivers/acpi/include/acpiosxf.h	Mon Dec 23 21:21:50 2002
@@ -33,7 +33,7 @@
 #include "actypes.h"
 
 
-/* Priorities for Acpi_os_queue_for_execution */
+/* Priorities for acpi_os_queue_for_execution */
 
 #define OSD_PRIORITY_GPE            1
 #define OSD_PRIORITY_HIGH           2
@@ -44,7 +44,7 @@
 #define ACPI_MUTEX_SEM              1
 
 
-/* Functions for Acpi_os_signal */
+/* Functions for acpi_os_signal */
 
 #define ACPI_SIGNAL_FATAL           0
 #define ACPI_SIGNAL_BREAKPOINT      1
@@ -55,7 +55,7 @@
 	u32                     code;
 	u32                     argument;
 
-} ACPI_SIGNAL_FATAL_INFO;
+} acpi_signal_fatal_info;
 
 
 /*
@@ -91,7 +91,7 @@
 acpi_status
 acpi_os_get_root_pointer (
 	u32                     flags,
-	ACPI_POINTER            *address);
+	acpi_pointer            *address);
 
 acpi_status
 acpi_os_table_override (
@@ -131,7 +131,7 @@
 
 void *
 acpi_os_allocate (
-	ACPI_SIZE               size);
+	acpi_size               size);
 
 void
 acpi_os_free (
@@ -139,19 +139,19 @@
 
 acpi_status
 acpi_os_map_memory (
-	ACPI_PHYSICAL_ADDRESS   physical_address,
-	ACPI_SIZE               size,
+	acpi_physical_address   physical_address,
+	acpi_size               size,
 	void                    **logical_address);
 
 void
 acpi_os_unmap_memory (
 	void                    *logical_address,
-	ACPI_SIZE               size);
+	acpi_size               size);
 
 acpi_status
 acpi_os_get_physical_address (
 	void                    *logical_address,
-	ACPI_PHYSICAL_ADDRESS   *physical_address);
+	acpi_physical_address   *physical_address);
 
 
 /*
@@ -200,13 +200,13 @@
 
 acpi_status
 acpi_os_read_port (
-	ACPI_IO_ADDRESS         address,
+	acpi_io_address         address,
 	void                    *value,
 	u32                     width);
 
 acpi_status
 acpi_os_write_port (
-	ACPI_IO_ADDRESS         address,
+	acpi_io_address         address,
 	acpi_integer            value,
 	u32                     width);
 
@@ -217,13 +217,13 @@
 
 acpi_status
 acpi_os_read_memory (
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	void                    *value,
 	u32                     width);
 
 acpi_status
 acpi_os_write_memory (
-	ACPI_PHYSICAL_ADDRESS   address,
+	acpi_physical_address   address,
 	acpi_integer            value,
 	u32                     width);
 
diff -Nru a/drivers/acpi/include/acpixf.h b/drivers/acpi/include/acpixf.h
--- a/drivers/acpi/include/acpixf.h	Mon Dec 23 21:21:50 2002
+++ b/drivers/acpi/include/acpixf.h	Mon Dec 23 21:21:50 2002
@@ -77,7 +77,7 @@
 
 acpi_status
 acpi_install_initialization_handler (
-	ACPI_INIT_HANDLER       handler,
+	acpi_init_handler       handler,
 	u32                     function);
 
 /*
@@ -104,7 +104,7 @@
 acpi_status
 acpi_find_root_pointer (
 	u32                     flags,
-	ACPI_POINTER            *rsdp_address);
+	acpi_pointer            *rsdp_address);
 
 acpi_status
 acpi_load_tables (
@@ -173,18 +173,18 @@
 acpi_status
 acpi_attach_data (
 	acpi_handle             obj_handle,
-	ACPI_OBJECT_HANDLER     handler,
+	acpi_object_handler     handler,
 	void                    *data);
 
 acpi_status
 acpi_detach_data (
 	acpi_handle             obj_handle,
-	ACPI_OBJECT_HANDLER     handler);
+	acpi_object_handler     handler);
 
 acpi_status
 acpi_get_data (
 	acpi_handle             obj_handle,
-	ACPI_OBJECT_HANDLER     handler,
+	acpi_object_handler     handler,
 	void                    **data);
 
 
@@ -261,7 +261,7 @@
 acpi_status
 acpi_install_address_space_handler (
 	acpi_handle             device,
-	ACPI_ADR_SPACE_TYPE     space_id,
+	acpi_adr_space_type     space_id,
 	acpi_adr_space_handler  handler,
 	acpi_adr_space_setup    setup,
 	void                    *context);
@@ -269,7 +269,7 @@
 acpi_status
 acpi_remove_address_space_handler (
 	acpi_handle             device,
-	ACPI_ADR_SPACE_TYPE     space_id,
+	acpi_adr_space_type     space_id,
 	acpi_adr_space_handler  handler);
 
 acpi_status
@@ -359,11 +359,11 @@
 
 acpi_status
 acpi_set_firmware_waking_vector (
-	ACPI_PHYSICAL_ADDRESS   physical_address);
+	acpi_physical_address   physical_address);
 
 acpi_status
 acpi_get_firmware_waking_vector (
-	ACPI_PHYSICAL_ADDRESS   *physical_address);
+	acpi_physical_address   *physical_address);
 
 acpi_status
 acpi_get_sleep_type_data (
diff -Nru a/drivers/acpi/include/acresrc.h b/drivers/acpi/include/acresrc.h
--- a/drivers/acpi/include/acresrc.h	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/include/acresrc.h	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: acresrc.h - Resource Manager function prototypes
- *       $Revision: 34 $
  *
  *****************************************************************************/
 
@@ -69,7 +68,7 @@
 
 
 /*
- * Function prototypes called from Acpi_rs_create*
+ * Function prototypes called from acpi_rs_create*
  */
 void
 acpi_rs_dump_irq (
@@ -141,17 +140,17 @@
 acpi_rs_get_list_length (
 	u8                      *byte_stream_buffer,
 	u32                     byte_stream_buffer_length,
-	ACPI_SIZE               *size_needed);
+	acpi_size               *size_needed);
 
 acpi_status
 acpi_rs_get_byte_stream_length (
 	acpi_resource           *linked_list_buffer,
-	ACPI_SIZE               *size_needed);
+	acpi_size               *size_needed);
 
 acpi_status
 acpi_rs_get_pci_routing_table_length (
 	acpi_operand_object     *package_object,
-	ACPI_SIZE               *buffer_size_needed);
+	acpi_size               *buffer_size_needed);
 
 acpi_status
 acpi_rs_byte_stream_to_list (
@@ -162,203 +161,203 @@
 acpi_status
 acpi_rs_list_to_byte_stream (
 	acpi_resource           *linked_list,
-	ACPI_SIZE               byte_stream_size_needed,
+	acpi_size               byte_stream_size_needed,
 	u8                      *output_buffer);
 
 acpi_status
 acpi_rs_io_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size);
+	acpi_size               *structure_size);
 
 acpi_status
 acpi_rs_fixed_io_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size);
+	acpi_size               *structure_size);
 
 acpi_status
 acpi_rs_io_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed);
+	acpi_size               *bytes_consumed);
 
 acpi_status
 acpi_rs_fixed_io_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed);
+	acpi_size               *bytes_consumed);
 
 acpi_status
 acpi_rs_irq_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size);
+	acpi_size               *structure_size);
 
 acpi_status
 acpi_rs_irq_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed);
+	acpi_size               *bytes_consumed);
 
 acpi_status
 acpi_rs_dma_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size);
+	acpi_size               *structure_size);
 
 acpi_status
 acpi_rs_dma_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed);
+	acpi_size               *bytes_consumed);
 
 acpi_status
 acpi_rs_address16_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size);
+	acpi_size               *structure_size);
 
 acpi_status
 acpi_rs_address16_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed);
+	acpi_size               *bytes_consumed);
 
 acpi_status
 acpi_rs_address32_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size);
+	acpi_size               *structure_size);
 
 acpi_status
 acpi_rs_address32_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed);
+	acpi_size               *bytes_consumed);
 
 acpi_status
 acpi_rs_address64_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size);
+	acpi_size               *structure_size);
 
 acpi_status
 acpi_rs_address64_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed);
+	acpi_size               *bytes_consumed);
 
 acpi_status
 acpi_rs_start_depend_fns_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size);
+	acpi_size               *structure_size);
 
 acpi_status
 acpi_rs_end_depend_fns_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size);
+	acpi_size               *structure_size);
 
 acpi_status
 acpi_rs_start_depend_fns_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed);
+	acpi_size               *bytes_consumed);
 
 acpi_status
 acpi_rs_end_depend_fns_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed);
+	acpi_size               *bytes_consumed);
 
 acpi_status
 acpi_rs_memory24_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size);
+	acpi_size               *structure_size);
 
 acpi_status
 acpi_rs_memory24_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed);
+	acpi_size               *bytes_consumed);
 
 acpi_status
 acpi_rs_memory32_range_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size);
+	acpi_size               *structure_size);
 
 acpi_status
 acpi_rs_fixed_memory32_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size);
+	acpi_size               *structure_size);
 
 acpi_status
 acpi_rs_memory32_range_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed);
+	acpi_size               *bytes_consumed);
 
 acpi_status
 acpi_rs_fixed_memory32_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed);
+	acpi_size               *bytes_consumed);
 
 acpi_status
 acpi_rs_extended_irq_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size);
+	acpi_size               *structure_size);
 
 acpi_status
 acpi_rs_extended_irq_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed);
+	acpi_size               *bytes_consumed);
 
 acpi_status
 acpi_rs_end_tag_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size);
+	acpi_size               *structure_size);
 
 acpi_status
 acpi_rs_end_tag_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed);
+	acpi_size               *bytes_consumed);
 
 acpi_status
 acpi_rs_vendor_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size);
+	acpi_size               *structure_size);
 
 acpi_status
 acpi_rs_vendor_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed);
+	acpi_size               *bytes_consumed);
 
 u8
 acpi_rs_get_resource_type (
diff -Nru a/drivers/acpi/include/acstruct.h b/drivers/acpi/include/acstruct.h
--- a/drivers/acpi/include/acstruct.h	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/include/acstruct.h	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: acstruct.h - Internal structs
- *       $Revision: 22 $
  *
  *****************************************************************************/
 
@@ -54,7 +53,7 @@
 	acpi_owner_id           owner_id;                           /* Owner of objects created during the walk */
 	u8                      last_predicate;                     /* Result of last predicate */
 	u8                      current_result;                     /* */
-	u8                      next_op_info;                       /* Info about Next_op */
+	u8                      next_op_info;                       /* Info about next_op */
 	u8                      num_operands;                       /* Stack pointer for Operands[] array */
 	u8                      return_used;
 	u8                      walk_type;
@@ -76,7 +75,7 @@
 	acpi_generic_state      *control_state;                     /* List of control states (nested IFs) */
 	struct acpi_node        local_variables[ACPI_METHOD_NUM_LOCALS];    /* Control method locals */
 	struct acpi_node        *method_call_node;                  /* Called method Node*/
-	acpi_parse_object       *method_call_op;                    /* Method_call Op if running a method */
+	acpi_parse_object       *method_call_op;                    /* method_call Op if running a method */
 	union acpi_operand_obj  *method_desc;                       /* Method descriptor if running a method */
 	struct acpi_node        *method_node;                       /* Method Node if running a method */
 	acpi_parse_object       *op;                                /* Current parser op */
@@ -94,14 +93,14 @@
 	acpi_parse_object       *next_op;                           /* next op to be processed */
 	acpi_parse_downwards    descending_callback;
 	acpi_parse_upwards      ascending_callback;
-	ACPI_THREAD_STATE       *thread;
-	struct acpi_walk_state  *next;                              /* Next Walk_state in list */
+	acpi_thread_state       *thread;
+	struct acpi_walk_state  *next;                              /* Next walk_state in list */
 
 
 } acpi_walk_state;
 
 
-/* Info used by Acpi_ps_init_objects */
+/* Info used by acpi_ps_init_objects */
 
 typedef struct acpi_init_walk_info
 {
@@ -121,7 +120,7 @@
 } acpi_init_walk_info;
 
 
-/* Info used by Acpi_ns_initialize_devices */
+/* Info used by acpi_ns_initialize_devices */
 
 typedef struct acpi_device_walk_info
 {
@@ -163,16 +162,16 @@
 
 	struct
 	{
-		ACPI_OBJECT_INTEGER     *type;
-		ACPI_OBJECT_INTEGER     *code;
-		ACPI_OBJECT_INTEGER     *argument;
+		acpi_object_integer     *type;
+		acpi_object_integer     *code;
+		acpi_object_integer     *argument;
 
 	} fatal;
 
 	struct
 	{
 		acpi_operand_object     *source;
-		ACPI_OBJECT_INTEGER     *index;
+		acpi_object_integer     *index;
 		acpi_operand_object     *target;
 
 	} index;
@@ -180,13 +179,13 @@
 	struct
 	{
 		acpi_operand_object     *source;
-		ACPI_OBJECT_INTEGER     *index;
-		ACPI_OBJECT_INTEGER     *length;
+		acpi_object_integer     *index;
+		acpi_object_integer     *length;
 		acpi_operand_object     *target;
 
 	} mid;
 
-} ACPI_AML_OPERANDS;
+} acpi_aml_operands;
 
 
 #endif
diff -Nru a/drivers/acpi/include/actables.h b/drivers/acpi/include/actables.h
--- a/drivers/acpi/include/actables.h	Mon Dec 23 21:21:52 2002
+++ b/drivers/acpi/include/actables.h	Mon Dec 23 21:21:52 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: actables.h - ACPI table management
- *       $Revision: 43 $
  *
  *****************************************************************************/
 
@@ -27,7 +26,7 @@
 #define __ACTABLES_H__
 
 
-/* Used in Acpi_tb_map_acpi_table for size parameter if table header is to be used */
+/* Used in acpi_tb_map_acpi_table for size parameter if table header is to be used */
 
 #define SIZE_IN_HEADER          0
 
@@ -55,7 +54,7 @@
 
 u32
 acpi_tb_get_table_count (
-	RSDP_DESCRIPTOR         *RSDP,
+	rsdp_descriptor         *RSDP,
 	acpi_table_header       *RSDT);
 
 /*
@@ -64,23 +63,23 @@
 
 acpi_status
 acpi_tb_get_table (
-	ACPI_POINTER            *address,
+	acpi_pointer            *address,
 	acpi_table_desc         *table_info);
 
 acpi_status
 acpi_tb_get_table_header (
-	ACPI_POINTER            *address,
+	acpi_pointer            *address,
 	acpi_table_header       *return_header);
 
 acpi_status
 acpi_tb_get_table_body (
-	ACPI_POINTER            *address,
+	acpi_pointer            *address,
 	acpi_table_header       *header,
 	acpi_table_desc         *table_info);
 
 acpi_status
 acpi_tb_get_this_table (
-	ACPI_POINTER            *address,
+	acpi_pointer            *address,
 	acpi_table_header       *header,
 	acpi_table_desc         *table_info);
 
@@ -97,11 +96,11 @@
 
 acpi_status
 acpi_tb_verify_rsdp (
-	ACPI_POINTER            *address);
+	acpi_pointer            *address);
 
 void
 acpi_tb_get_rsdt_address (
-	ACPI_POINTER            *out_address);
+	acpi_pointer            *out_address);
 
 acpi_status
 acpi_tb_validate_rsdt (
@@ -113,12 +112,12 @@
 
 acpi_status
 acpi_tb_get_primary_table (
-	ACPI_POINTER            *address,
+	acpi_pointer            *address,
 	acpi_table_desc         *table_info);
 
 acpi_status
 acpi_tb_get_secondary_table (
-	ACPI_POINTER            *address,
+	acpi_pointer            *address,
 	acpi_string             signature,
 	acpi_table_desc         *table_info);
 
diff -Nru a/drivers/acpi/include/actbl.h b/drivers/acpi/include/actbl.h
--- a/drivers/acpi/include/actbl.h	Mon Dec 23 21:21:55 2002
+++ b/drivers/acpi/include/actbl.h	Mon Dec 23 21:21:55 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: actbl.h - Table data structures defined in ACPI specification
- *       $Revision: 54 $
  *
  *****************************************************************************/
 
@@ -86,7 +85,7 @@
 	u8                      extended_checksum;      /* Checksum of entire table */
 	char                    reserved [3];           /* Reserved field must be 0 */
 
-} RSDP_DESCRIPTOR;
+} rsdp_descriptor;
 
 
 typedef struct  /* ACPI common table header */
diff -Nru a/drivers/acpi/include/actbl1.h b/drivers/acpi/include/actbl1.h
--- a/drivers/acpi/include/actbl1.h	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/include/actbl1.h	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: actbl1.h - ACPI 1.0 tables
- *       $Revision: 22 $
  *
  *****************************************************************************/
 
@@ -72,16 +71,16 @@
 	u8                      acpi_disable;           /* Value to write to smi_cmd to disable ACPI */
 	u8                      S4bios_req;             /* Value to write to SMI CMD to enter S4BIOS state */
 	u8                      reserved2;              /* Reserved - must be zero */
-	u32                     pm1a_evt_blk;           /* Port address of Power Mgt 1a Acpi_event Reg Blk */
-	u32                     pm1b_evt_blk;           /* Port address of Power Mgt 1b Acpi_event Reg Blk */
+	u32                     pm1a_evt_blk;           /* Port address of Power Mgt 1a acpi_event Reg Blk */
+	u32                     pm1b_evt_blk;           /* Port address of Power Mgt 1b acpi_event Reg Blk */
 	u32                     pm1a_cnt_blk;           /* Port address of Power Mgt 1a Control Reg Blk */
 	u32                     pm1b_cnt_blk;           /* Port address of Power Mgt 1b Control Reg Blk */
 	u32                     pm2_cnt_blk;            /* Port address of Power Mgt 2 Control Reg Blk */
 	u32                     pm_tmr_blk;             /* Port address of Power Mgt Timer Ctrl Reg Blk */
-	u32                     gpe0_blk;               /* Port addr of General Purpose Acpi_event 0 Reg Blk */
-	u32                     gpe1_blk;               /* Port addr of General Purpose Acpi_event 1 Reg Blk */
-	u8                      pm1_evt_len;            /* Byte Length of ports at pm1_x_evt_blk */
-	u8                      pm1_cnt_len;            /* Byte Length of ports at pm1_x_cnt_blk */
+	u32                     gpe0_blk;               /* Port addr of General Purpose acpi_event 0 Reg Blk */
+	u32                     gpe1_blk;               /* Port addr of General Purpose acpi_event 1 Reg Blk */
+	u8                      pm1_evt_len;            /* Byte length of ports at pm1_x_evt_blk */
+	u8                      pm1_cnt_len;            /* Byte length of ports at pm1_x_cnt_blk */
 	u8                      pm2_cnt_len;            /* Byte Length of ports at pm2_cnt_blk */
 	u8                      pm_tm_len;              /* Byte Length of ports at pm_tm_blk */
 	u8                      gpe0_blk_len;           /* Byte Length of ports at gpe0_blk */
diff -Nru a/drivers/acpi/include/actbl2.h b/drivers/acpi/include/actbl2.h
--- a/drivers/acpi/include/actbl2.h	Mon Dec 23 21:21:57 2002
+++ b/drivers/acpi/include/actbl2.h	Mon Dec 23 21:21:57 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: actbl2.h - ACPI Specification Revision 2.0 Tables
- *       $Revision: 29 $
  *
  *****************************************************************************/
 
@@ -82,7 +81,7 @@
 	u32                     global_lock;            /* Global Lock used to synchronize access to shared hardware resources */
 	u32                     S4bios_f        : 1;    /* S4Bios_f - Indicates if S4BIOS support is present */
 	u32                     reserved1       : 31;   /* Must be 0 */
-	u64                     Xfirmware_waking_vector; /* 64bit physical address of the Firmware Waking Vector. */
+	u64                     xfirmware_waking_vector; /* 64bit physical address of the Firmware Waking Vector. */
 	u8                      version;                /* Version of this table */
 	u8                      reserved3 [31];         /* Reserved - must be zero */
 
@@ -119,16 +118,16 @@
 	u8                      acpi_disable;       /* Value to write to smi_cmd to disable ACPI */
 	u8                      S4bios_req;         /* Value to write to SMI CMD to enter S4BIOS state */
 	u8                      pstate_cnt;         /* Processor performance state control*/
-	u32                     V1_pm1a_evt_blk;    /* Port address of Power Mgt 1a Acpi_event Reg Blk */
-	u32                     V1_pm1b_evt_blk;    /* Port address of Power Mgt 1b Acpi_event Reg Blk */
+	u32                     V1_pm1a_evt_blk;    /* Port address of Power Mgt 1a acpi_event Reg Blk */
+	u32                     V1_pm1b_evt_blk;    /* Port address of Power Mgt 1b acpi_event Reg Blk */
 	u32                     V1_pm1a_cnt_blk;    /* Port address of Power Mgt 1a Control Reg Blk */
 	u32                     V1_pm1b_cnt_blk;    /* Port address of Power Mgt 1b Control Reg Blk */
 	u32                     V1_pm2_cnt_blk;     /* Port address of Power Mgt 2 Control Reg Blk */
 	u32                     V1_pm_tmr_blk;      /* Port address of Power Mgt Timer Ctrl Reg Blk */
-	u32                     V1_gpe0_blk;        /* Port addr of General Purpose Acpi_event 0 Reg Blk */
-	u32                     V1_gpe1_blk;        /* Port addr of General Purpose Acpi_event 1 Reg Blk */
-	u8                      pm1_evt_len;        /* Byte Length of ports at pm1_x_evt_blk */
-	u8                      pm1_cnt_len;        /* Byte Length of ports at pm1_x_cnt_blk */
+	u32                     V1_gpe0_blk;        /* Port addr of General Purpose acpi_event 0 Reg Blk */
+	u32                     V1_gpe1_blk;        /* Port addr of General Purpose acpi_event 1 Reg Blk */
+	u8                      pm1_evt_len;        /* Byte length of ports at pm1_x_evt_blk */
+	u8                      pm1_cnt_len;        /* Byte length of ports at pm1_x_cnt_blk */
 	u8                      pm2_cnt_len;        /* Byte Length of ports at pm2_cnt_blk */
 	u8                      pm_tm_len;          /* Byte Length of ports at pm_tm_blk */
 	u8                      gpe0_blk_len;       /* Byte Length of ports at gpe0_blk */
@@ -164,18 +163,18 @@
 	u32                     reserved6   : 18;   /* Reserved - must be zero */
 
 	acpi_generic_address    reset_register;     /* Reset register address in GAS format */
-	u8                      reset_value;        /* Value to write to the Reset_register port to reset the system. */
+	u8                      reset_value;        /* Value to write to the reset_register port to reset the system. */
 	u8                      reserved7[3];       /* These three bytes must be zero */
-	u64                     Xfirmware_ctrl;     /* 64-bit physical address of FACS */
+	u64                     xfirmware_ctrl;     /* 64-bit physical address of FACS */
 	u64                     Xdsdt;              /* 64-bit physical address of DSDT */
-	acpi_generic_address    Xpm1a_evt_blk;      /* Extended Power Mgt 1a Acpi_event Reg Blk address */
-	acpi_generic_address    Xpm1b_evt_blk;      /* Extended Power Mgt 1b Acpi_event Reg Blk address */
-	acpi_generic_address    Xpm1a_cnt_blk;      /* Extended Power Mgt 1a Control Reg Blk address */
-	acpi_generic_address    Xpm1b_cnt_blk;      /* Extended Power Mgt 1b Control Reg Blk address */
-	acpi_generic_address    Xpm2_cnt_blk;       /* Extended Power Mgt 2 Control Reg Blk address */
-	acpi_generic_address    Xpm_tmr_blk;        /* Extended Power Mgt Timer Ctrl Reg Blk address */
-	acpi_generic_address    Xgpe0_blk;          /* Extended General Purpose Acpi_event 0 Reg Blk address */
-	acpi_generic_address    Xgpe1_blk;          /* Extended General Purpose Acpi_event 1 Reg Blk address */
+	acpi_generic_address    xpm1a_evt_blk;      /* Extended Power Mgt 1a acpi_event Reg Blk address */
+	acpi_generic_address    xpm1b_evt_blk;      /* Extended Power Mgt 1b acpi_event Reg Blk address */
+	acpi_generic_address    xpm1a_cnt_blk;      /* Extended Power Mgt 1a Control Reg Blk address */
+	acpi_generic_address    xpm1b_cnt_blk;      /* Extended Power Mgt 1b Control Reg Blk address */
+	acpi_generic_address    xpm2_cnt_blk;       /* Extended Power Mgt 2 Control Reg Blk address */
+	acpi_generic_address    xpm_tmr_blk;        /* Extended Power Mgt Timer Ctrl Reg Blk address */
+	acpi_generic_address    xgpe0_blk;          /* Extended General Purpose acpi_event 0 Reg Blk address */
+	acpi_generic_address    xgpe1_blk;          /* Extended General Purpose acpi_event 1 Reg Blk address */
 
 }  fadt_descriptor_rev2;
 
diff -Nru a/drivers/acpi/include/actbl71.h b/drivers/acpi/include/actbl71.h
--- a/drivers/acpi/include/actbl71.h	Mon Dec 23 21:21:54 2002
+++ b/drivers/acpi/include/actbl71.h	Mon Dec 23 21:21:54 2002
@@ -3,7 +3,6 @@
  * Name: actbl71.h - IA-64 Extensions to the ACPI Spec Rev. 0.71
  *                   This file includes tables specific to this
  *                   specification revision.
- *       $Revision: 12 $
  *
  *****************************************************************************/
 
@@ -29,7 +28,7 @@
 #define __ACTBL71_H__
 
 
-/* 0.71 FADT Address_space data item bitmasks defines */
+/* 0.71 FADT address_space data item bitmasks defines */
 /* If the associated bit is zero then it is in memory space else in io space */
 
 #define SMI_CMD_ADDRESS_SPACE       0x01
@@ -105,16 +104,16 @@
 	u8                  S4bios_req;         /* Value to write to SMI CMD to enter S4BIOS state */
 	u8                  reserved2;          /* reserved - must be zero */
 	u64                 smi_cmd;            /* Port address of SMI command port */
-	u64                 pm1a_evt_blk;       /* Port address of Power Mgt 1a Acpi_event Reg Blk */
-	u64                 pm1b_evt_blk;       /* Port address of Power Mgt 1b Acpi_event Reg Blk */
+	u64                 pm1a_evt_blk;       /* Port address of Power Mgt 1a acpi_event Reg Blk */
+	u64                 pm1b_evt_blk;       /* Port address of Power Mgt 1b acpi_event Reg Blk */
 	u64                 pm1a_cnt_blk;       /* Port address of Power Mgt 1a Control Reg Blk */
 	u64                 pm1b_cnt_blk;       /* Port address of Power Mgt 1b Control Reg Blk */
 	u64                 pm2_cnt_blk;        /* Port address of Power Mgt 2 Control Reg Blk */
 	u64                 pm_tmr_blk;         /* Port address of Power Mgt Timer Ctrl Reg Blk */
-	u64                 gpe0_blk;           /* Port addr of General Purpose Acpi_event 0 Reg Blk */
-	u64                 gpe1_blk;           /* Port addr of General Purpose Acpi_event 1 Reg Blk */
-	u8                  pm1_evt_len;        /* Byte Length of ports at pm1_x_evt_blk */
-	u8                  pm1_cnt_len;        /* Byte Length of ports at pm1_x_cnt_blk */
+	u64                 gpe0_blk;           /* Port addr of General Purpose acpi_event 0 Reg Blk */
+	u64                 gpe1_blk;           /* Port addr of General Purpose acpi_event 1 Reg Blk */
+	u8                  pm1_evt_len;        /* Byte length of ports at pm1_x_evt_blk */
+	u8                  pm1_cnt_len;        /* Byte length of ports at pm1_x_cnt_blk */
 	u8                  pm2_cnt_len;        /* Byte Length of ports at pm2_cnt_blk */
 	u8                  pm_tm_len;          /* Byte Length of ports at pm_tm_blk */
 	u8                  gpe0_blk_len;       /* Byte Length of ports at gpe0_blk */
diff -Nru a/drivers/acpi/include/actypes.h b/drivers/acpi/include/actypes.h
--- a/drivers/acpi/include/actypes.h	Mon Dec 23 21:21:56 2002
+++ b/drivers/acpi/include/actypes.h	Mon Dec 23 21:21:56 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: actypes.h - Common data types for the entire ACPI subsystem
- *       $Revision: 244 $
  *
  *****************************************************************************/
 
@@ -40,21 +39,34 @@
 #define ACPI_ASCII_MAX                  0x7F
 
 
+#ifdef DEFINE_ALTERNATE_TYPES
+/*
+ * Types used only in translated source, defined here to enable
+ * cross-platform compilation only.
+ */
+typedef int                             s32;
+typedef unsigned char                   u8;
+typedef unsigned short                  u16;
+typedef unsigned int                    u32;
+typedef COMPILER_DEPENDENT_UINT64       u64;
+
+#endif
+
 
 /*
  * Data types - Fixed across all compilation models (16/32/64)
  *
- * BOOLEAN      Logical Boolean.
- * INT8         8-bit  (1 byte) signed value
- * UINT8        8-bit  (1 byte) unsigned value
- * INT16        16-bit (2 byte) signed value
- * UINT16       16-bit (2 byte) unsigned value
- * INT32        32-bit (4 byte) signed value
- * UINT32       32-bit (4 byte) unsigned value
- * INT64        64-bit (8 byte) signed value
- * UINT64       64-bit (8 byte) unsigned value
- * NATIVE_INT   32-bit on IA-32, 64-bit on IA-64 signed value
- * NATIVE_UINT  32-bit on IA-32, 64-bit on IA-64 unsigned value
+ * BOOLEAN          Logical Boolean.
+ * INT8             8-bit  (1 byte) signed value
+ * UINT8            8-bit  (1 byte) unsigned value
+ * INT16            16-bit (2 byte) signed value
+ * UINT16           16-bit (2 byte) unsigned value
+ * INT32            32-bit (4 byte) signed value
+ * UINT32           32-bit (4 byte) unsigned value
+ * INT64            64-bit (8 byte) signed value
+ * UINT64           64-bit (8 byte) unsigned value
+ * ACPI_NATIVE_INT  32-bit on IA-32, 64-bit on IA-64 signed value
+ * ACPI_NATIVE_UINT 32-bit on IA-32, 64-bit on IA-64 unsigned value
  */
 
 #ifndef ACPI_MACHINE_WIDTH
@@ -62,6 +74,9 @@
 #endif
 
 #if ACPI_MACHINE_WIDTH == 64
+
+/*! [Begin] no source code translation (keep the typedefs) */
+
 /*
  * 64-bit type definitions
  */
@@ -73,16 +88,15 @@
 typedef COMPILER_DEPENDENT_INT64        INT64;
 typedef COMPILER_DEPENDENT_UINT64       UINT64;
 
-typedef INT64                           NATIVE_INT;
-typedef UINT64                          NATIVE_UINT;
+/*! [End] no source code translation !*/
 
-typedef UINT32                          NATIVE_UINT_MAX32;
-typedef UINT64                          NATIVE_UINT_MIN32;
+typedef s64                             acpi_native_int;
+typedef u64                             acpi_native_uint;
 
-typedef UINT64                          ACPI_TBLPTR;
-typedef UINT64                          ACPI_IO_ADDRESS;
-typedef UINT64                          ACPI_PHYSICAL_ADDRESS;
-typedef UINT64                          ACPI_SIZE;
+typedef u64                             acpi_table_ptr;
+typedef u64                             acpi_io_address;
+typedef u64                             acpi_physical_address;
+typedef u64                             acpi_size;
 
 #define ALIGNED_ADDRESS_BOUNDARY        0x00000008      /* No hardware alignment support in IA64 */
 #define ACPI_USE_NATIVE_DIVIDE                          /* Native 64-bit integer support */
@@ -92,6 +106,8 @@
 
 #elif ACPI_MACHINE_WIDTH == 16
 
+/*! [Begin] no source code translation (keep the typedefs) */
+
 /*
  * 16-bit type definitions
  */
@@ -109,16 +125,15 @@
 
 } UINT64;
 
-typedef UINT16                          NATIVE_UINT;
-typedef INT16                           NATIVE_INT;
+/*! [End] no source code translation !*/
 
-typedef UINT16                          NATIVE_UINT_MAX32;
-typedef UINT32                          NATIVE_UINT_MIN32;
+typedef u16                             acpi_native_uint;
+typedef s16                             acpi_native_int;
 
-typedef UINT32                          ACPI_TBLPTR;
-typedef UINT32                          ACPI_IO_ADDRESS;
-typedef char                            *ACPI_PHYSICAL_ADDRESS;
-typedef UINT16                          ACPI_SIZE;
+typedef u32                             acpi_table_ptr;
+typedef u32                             acpi_io_address;
+typedef char                            *acpi_physical_address;
+typedef u16                             acpi_size;
 
 #define ALIGNED_ADDRESS_BOUNDARY        0x00000002
 #define _HW_ALIGNMENT_SUPPORT
@@ -135,6 +150,8 @@
 
 #elif ACPI_MACHINE_WIDTH == 32
 
+/*! [Begin] no source code translation (keep the typedefs) */
+
 /*
  * 32-bit type definitions (default)
  */
@@ -146,16 +163,15 @@
 typedef COMPILER_DEPENDENT_INT64        INT64;
 typedef COMPILER_DEPENDENT_UINT64       UINT64;
 
-typedef INT32                           NATIVE_INT;
-typedef UINT32                          NATIVE_UINT;
+/*! [End] no source code translation !*/
 
-typedef UINT32                          NATIVE_UINT_MAX32;
-typedef UINT32                          NATIVE_UINT_MIN32;
+typedef s32                             acpi_native_int;
+typedef u32                             acpi_native_uint;
 
-typedef UINT64                          ACPI_TBLPTR;
-typedef UINT32                          ACPI_IO_ADDRESS;
-typedef UINT64                          ACPI_PHYSICAL_ADDRESS;
-typedef UINT32                          ACPI_SIZE;
+typedef u64                             acpi_table_ptr;
+typedef u32                             acpi_io_address;
+typedef u64                             acpi_physical_address;
+typedef u32                             acpi_size;
 
 #define ALIGNED_ADDRESS_BOUNDARY        0x00000004
 #define _HW_ALIGNMENT_SUPPORT
@@ -170,24 +186,8 @@
 /*
  * Miscellaneous common types
  */
-typedef UINT32                          UINT32_BIT;
-typedef NATIVE_UINT                     ACPI_PTRDIFF;
-typedef char                            NATIVE_CHAR;
-
-
-#ifdef DEFINE_ALTERNATE_TYPES
-/*
- * Types used only in translated source, defined here to enable
- * cross-platform compilation only.
- */
-typedef INT32                           s32;
-typedef UINT8                           u8;
-typedef UINT16                          u16;
-typedef UINT32                          u32;
-typedef UINT64                          u64;
-#endif
-/*! [End] no source code translation !*/
-
+typedef u32                             UINT32_BIT;
+typedef acpi_native_uint                ACPI_PTRDIFF;
 
 /*
  * Pointer overlays to avoid lots of typecasting for
@@ -195,20 +195,20 @@
  */
 typedef union acpi_ptrs
 {
-	ACPI_PHYSICAL_ADDRESS       physical;
+	acpi_physical_address       physical;
 	void                        *logical;
-	ACPI_TBLPTR                 value;
+	acpi_table_ptr              value;
 
-} ACPI_POINTERS;
+} acpi_pointers;
 
 typedef struct acpi_pointer
 {
 	u32                         pointer_type;
 	union acpi_ptrs             pointer;
 
-} ACPI_POINTER;
+} acpi_pointer;
 
-/* Pointer_types for above */
+/* pointer_types for above */
 
 #define ACPI_PHYSICAL_POINTER           0x01
 #define ACPI_LOGICAL_POINTER            0x02
@@ -269,7 +269,7 @@
 	u32                         lo;
 	u32                         hi;
 
-} UINT32_STRUCT;
+} uint32_struct;
 
 
 /*
@@ -400,11 +400,11 @@
 /*
  * Types associated with ACPI names and objects.  The first group of
  * values (up to ACPI_TYPE_EXTERNAL_MAX) correspond to the definition
- * of the ACPI Object_type() operator (See the ACPI Spec). Therefore,
+ * of the ACPI object_type() operator (See the ACPI Spec). Therefore,
  * only add to the first group if the spec changes.
  *
- * Types must be kept in sync with the global Acpi_ns_properties
- * and Acpi_ns_type_names arrays.
+ * Types must be kept in sync with the global acpi_ns_properties
+ * and acpi_ns_type_names arrays.
  */
 typedef u32                             acpi_object_type;
 
@@ -412,15 +412,15 @@
 #define ACPI_TYPE_INTEGER               0x01  /* Byte/Word/Dword/Zero/One/Ones */
 #define ACPI_TYPE_STRING                0x02
 #define ACPI_TYPE_BUFFER                0x03
-#define ACPI_TYPE_PACKAGE               0x04  /* Byte_const, multiple Data_term/Constant/Super_name */
+#define ACPI_TYPE_PACKAGE               0x04  /* byte_const, multiple data_term/Constant/super_name */
 #define ACPI_TYPE_FIELD_UNIT            0x05
 #define ACPI_TYPE_DEVICE                0x06  /* Name, multiple Node */
 #define ACPI_TYPE_EVENT                 0x07
-#define ACPI_TYPE_METHOD                0x08  /* Name, Byte_const, multiple Code */
+#define ACPI_TYPE_METHOD                0x08  /* Name, byte_const, multiple Code */
 #define ACPI_TYPE_MUTEX                 0x09
 #define ACPI_TYPE_REGION                0x0A
-#define ACPI_TYPE_POWER                 0x0B  /* Name,Byte_const,Word_const,multi Node */
-#define ACPI_TYPE_PROCESSOR             0x0C  /* Name,Byte_const,DWord_const,Byte_const,multi Nm_o */
+#define ACPI_TYPE_POWER                 0x0B  /* Name,byte_const,word_const,multi Node */
+#define ACPI_TYPE_PROCESSOR             0x0C  /* Name,byte_const,Dword_const,byte_const,multi nm_o */
 #define ACPI_TYPE_THERMAL               0x0D  /* Name, multiple Node */
 #define ACPI_TYPE_BUFFER_FIELD          0x0E
 #define ACPI_TYPE_DDB_HANDLE            0x0F
@@ -430,7 +430,7 @@
 
 /*
  * These are object types that do not map directly to the ACPI
- * Object_type() operator. They are used for various internal purposes only.
+ * object_type() operator. They are used for various internal purposes only.
  * If new predefined ACPI_TYPEs are added (via the ACPI specification), these
  * internal types must move upwards. (There is code that depends on these
  * values being contiguous with the external types above.)
@@ -438,13 +438,13 @@
 #define ACPI_TYPE_LOCAL_REGION_FIELD    0x11
 #define ACPI_TYPE_LOCAL_BANK_FIELD      0x12
 #define ACPI_TYPE_LOCAL_INDEX_FIELD     0x13
-#define ACPI_TYPE_LOCAL_REFERENCE       0x14  /* Arg#, Local#, Name, Debug, Ref_of, Index */
+#define ACPI_TYPE_LOCAL_REFERENCE       0x14  /* Arg#, Local#, Name, Debug, ref_of, Index */
 #define ACPI_TYPE_LOCAL_ALIAS           0x15
 #define ACPI_TYPE_LOCAL_NOTIFY          0x16
 #define ACPI_TYPE_LOCAL_ADDRESS_HANDLER 0x17
 #define ACPI_TYPE_LOCAL_RESOURCE        0x18
 #define ACPI_TYPE_LOCAL_RESOURCE_FIELD  0x19
-#define ACPI_TYPE_LOCAL_SCOPE           0x1A  /* 1 Name, multiple Object_list Nodes */
+#define ACPI_TYPE_LOCAL_SCOPE           0x1A  /* 1 Name, multiple object_list Nodes */
 
 #define ACPI_TYPE_NS_NODE_MAX           0x1A  /* Last typecode used within a NS Node */
 
@@ -503,7 +503,7 @@
 
 
 /*
- * Acpi_event Types: Fixed & General Purpose
+ * acpi_event Types: Fixed & General Purpose
  */
 typedef u32                             acpi_event_type;
 
@@ -536,7 +536,7 @@
 
 
 /*
- * Acpi_event Status:
+ * acpi_event Status:
  * -------------
  * The encoding of acpi_event_status is illustrated below.
  * Note that a set bit (1) indicates the property is TRUE
@@ -569,20 +569,20 @@
 
 /* Address Space (Operation Region) Types */
 
-typedef u8                              ACPI_ADR_SPACE_TYPE;
+typedef u8                              acpi_adr_space_type;
 
-#define ACPI_ADR_SPACE_SYSTEM_MEMORY    (ACPI_ADR_SPACE_TYPE) 0
-#define ACPI_ADR_SPACE_SYSTEM_IO        (ACPI_ADR_SPACE_TYPE) 1
-#define ACPI_ADR_SPACE_PCI_CONFIG       (ACPI_ADR_SPACE_TYPE) 2
-#define ACPI_ADR_SPACE_EC               (ACPI_ADR_SPACE_TYPE) 3
-#define ACPI_ADR_SPACE_SMBUS            (ACPI_ADR_SPACE_TYPE) 4
-#define ACPI_ADR_SPACE_CMOS             (ACPI_ADR_SPACE_TYPE) 5
-#define ACPI_ADR_SPACE_PCI_BAR_TARGET   (ACPI_ADR_SPACE_TYPE) 6
-#define ACPI_ADR_SPACE_DATA_TABLE       (ACPI_ADR_SPACE_TYPE) 7
+#define ACPI_ADR_SPACE_SYSTEM_MEMORY    (acpi_adr_space_type) 0
+#define ACPI_ADR_SPACE_SYSTEM_IO        (acpi_adr_space_type) 1
+#define ACPI_ADR_SPACE_PCI_CONFIG       (acpi_adr_space_type) 2
+#define ACPI_ADR_SPACE_EC               (acpi_adr_space_type) 3
+#define ACPI_ADR_SPACE_SMBUS            (acpi_adr_space_type) 4
+#define ACPI_ADR_SPACE_CMOS             (acpi_adr_space_type) 5
+#define ACPI_ADR_SPACE_PCI_BAR_TARGET   (acpi_adr_space_type) 6
+#define ACPI_ADR_SPACE_DATA_TABLE       (acpi_adr_space_type) 7
 
 
 /*
- * Bit_register IDs
+ * bit_register IDs
  * These are bitfields defined within the full ACPI registers
  */
 #define ACPI_BITREG_TIMER_STATUS                0x00
@@ -618,7 +618,7 @@
  */
 typedef union acpi_obj
 {
-	acpi_object_type            type;   /* See definition of Acpi_ns_type for values */
+	acpi_object_type            type;   /* See definition of acpi_ns_type for values */
 	struct
 	{
 		acpi_object_type            type;
@@ -657,7 +657,7 @@
 	{
 		acpi_object_type            type;
 		u32                         proc_id;
-		ACPI_IO_ADDRESS             pblk_address;
+		acpi_io_address             pblk_address;
 		u32                         pblk_length;
 	} processor;
 
@@ -686,19 +686,19 @@
  * Miscellaneous common Data Structures used by the interfaces
  */
 #define ACPI_NO_BUFFER              0
-#define ACPI_ALLOCATE_BUFFER        (ACPI_SIZE) (-1)
-#define ACPI_ALLOCATE_LOCAL_BUFFER  (ACPI_SIZE) (-2)
+#define ACPI_ALLOCATE_BUFFER        (acpi_size) (-1)
+#define ACPI_ALLOCATE_LOCAL_BUFFER  (acpi_size) (-2)
 
 typedef struct
 {
-	ACPI_SIZE                   length;         /* Length in bytes of the buffer */
+	acpi_size                   length;         /* Length in bytes of the buffer */
 	void                        *pointer;       /* pointer to buffer */
 
 } acpi_buffer;
 
 
 /*
- * Name_type for Acpi_get_name
+ * name_type for acpi_get_name
  */
 #define ACPI_FULL_PATHNAME              0
 #define ACPI_SINGLE_NAME                1
@@ -706,7 +706,7 @@
 
 
 /*
- * Structure and flags for Acpi_get_system_info
+ * Structure and flags for acpi_get_system_info
  */
 #define ACPI_SYS_MODE_UNKNOWN           0x0000
 #define ACPI_SYS_MODE_ACPI              0x0001
@@ -725,7 +725,7 @@
 
 
 /*
- * System info returned by Acpi_get_system_info()
+ * System info returned by acpi_get_system_info()
  */
 typedef struct _acpi_sys_info
 {
@@ -760,13 +760,13 @@
 	void                        *context);
 
 typedef
-void (*ACPI_OBJECT_HANDLER) (
+void (*acpi_object_handler) (
 	acpi_handle                 object,
 	u32                         function,
 	void                        *data);
 
 typedef
-acpi_status (*ACPI_INIT_HANDLER) (
+acpi_status (*acpi_init_handler) (
 	acpi_handle                 object,
 	u32                         function);
 
@@ -778,7 +778,7 @@
 typedef
 acpi_status (*acpi_adr_space_handler) (
 	u32                         function,
-	ACPI_PHYSICAL_ADDRESS       address,
+	acpi_physical_address       address,
 	u32                         bit_width,
 	acpi_integer                *value,
 	void                        *handler_context,
@@ -811,7 +811,7 @@
 #define ACPI_INTERRUPT_HANDLED          0x01
 
 
-/* Structure and flags for Acpi_get_device_info */
+/* Structure and flags for acpi_get_device_info */
 
 #define ACPI_VALID_HID                  0x1
 #define ACPI_VALID_UID                  0x2
@@ -856,10 +856,10 @@
 typedef struct
 {
 	u32                         length;
-	ACPI_PHYSICAL_ADDRESS       address;
-	ACPI_PHYSICAL_ADDRESS       mapped_physical_address;
+	acpi_physical_address       address;
+	acpi_physical_address       mapped_physical_address;
 	u8                          *mapped_logical_address;
-	ACPI_SIZE                   mapped_length;
+	acpi_size                   mapped_length;
 } acpi_mem_space_context;
 
 
@@ -880,8 +880,8 @@
 
 /*
  *  IO Attributes
- *  The ISA IO ranges are:     n000-n0_fFh, n400-n4_fFh, n800-n8_fFh, n_c00-n_cFFh.
- *  The non-ISA IO ranges are: n100-n3_fFh, n500-n7_fFh, n900-n_bFFh, n_cD0-n_fFFh.
+ *  The ISA Io ranges are:     n000-n0_ffh, n400-n4_ffh, n800-n8_ffh, n_c00-n_cFFh.
+ *  The non-ISA Io ranges are: n100-n3_ffh, n500-n7_ffh, n900-n_bFfh, n_cd0-n_fFFh.
  */
 #define ACPI_NON_ISA_ONLY_RANGES        (u8) 0x01
 #define ACPI_ISA_ONLY_RANGES            (u8) 0x02
@@ -1007,7 +1007,7 @@
 {
 	u8                          checksum;
 
-} ACPI_RESOURCE_END_TAG;
+} acpi_resource_end_tag;
 
 typedef struct
 {
@@ -1166,7 +1166,7 @@
 	acpi_resource_io            io;
 	acpi_resource_fixed_io      fixed_io;
 	acpi_resource_vendor        vendor_specific;
-	ACPI_RESOURCE_END_TAG       end_tag;
+	acpi_resource_end_tag       end_tag;
 	acpi_resource_mem24         memory24;
 	acpi_resource_mem32         memory32;
 	acpi_resource_fixed_mem32   fixed_memory32;
diff -Nru a/drivers/acpi/include/acutils.h b/drivers/acpi/include/acutils.h
--- a/drivers/acpi/include/acutils.h	Mon Dec 23 21:21:50 2002
+++ b/drivers/acpi/include/acutils.h	Mon Dec 23 21:21:50 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: acutils.h -- prototypes for the common (subsystem-wide) procedures
- *       $Revision: 150 $
  *
  *****************************************************************************/
 
@@ -28,7 +27,7 @@
 
 
 typedef
-acpi_status (*ACPI_PKG_CALLBACK) (
+acpi_status (*acpi_pkg_callback) (
 	u8                      object_type,
 	acpi_operand_object     *source_object,
 	acpi_generic_state      *state,
@@ -39,14 +38,14 @@
 acpi_ut_walk_package_tree (
 	acpi_operand_object     *source_object,
 	void                    *target_object,
-	ACPI_PKG_CALLBACK       walk_callback,
+	acpi_pkg_callback       walk_callback,
 	void                    *context);
 
 
 typedef struct acpi_pkg_info
 {
 	u8                      *free_space;
-	ACPI_SIZE               length;
+	acpi_size               length;
 	u32                     object_space;
 	u32                     num_packages;
 } acpi_pkg_info;
@@ -55,7 +54,7 @@
 #define REF_DECREMENT       (u16) 1
 #define REF_FORCE_DELETE    (u16) 2
 
-/* Acpi_ut_dump_buffer */
+/* acpi_ut_dump_buffer */
 
 #define DB_BYTE_DISPLAY     1
 #define DB_WORD_DISPLAY     2
@@ -75,7 +74,7 @@
 
 
 /*
- * Ut_init - miscellaneous initialization and shutdown
+ * ut_init - miscellaneous initialization and shutdown
  */
 
 acpi_status
@@ -91,7 +90,7 @@
 	void);
 
 /*
- * Ut_global - Global data structures and procedures
+ * ut_global - Global data structures and procedures
  */
 
 #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
@@ -133,12 +132,12 @@
 
 
 /*
- * Ut_clib - Local implementations of C library functions
+ * ut_clib - Local implementations of C library functions
  */
 
 #ifndef ACPI_USE_SYSTEM_CLIBRARY
 
-ACPI_SIZE
+acpi_size
 acpi_ut_strlen (
 	const char              *string);
 
@@ -151,13 +150,13 @@
 acpi_ut_strncpy (
 	char                    *dst_string,
 	const char              *src_string,
-	ACPI_SIZE               count);
+	acpi_size               count);
 
 int
 acpi_ut_strncmp (
 	const char              *string1,
 	const char              *string2,
-	ACPI_SIZE               count);
+	acpi_size               count);
 
 int
 acpi_ut_strcmp (
@@ -173,7 +172,7 @@
 acpi_ut_strncat (
 	char                    *dst_string,
 	const char              *src_string,
-	ACPI_SIZE               count);
+	acpi_size               count);
 
 u32
 acpi_ut_strtoul (
@@ -190,13 +189,13 @@
 acpi_ut_memcpy (
 	void                    *dest,
 	const void              *src,
-	ACPI_SIZE               count);
+	acpi_size               count);
 
 void *
 acpi_ut_memset (
 	void                    *dest,
-	NATIVE_UINT             value,
-	ACPI_SIZE               count);
+	acpi_native_uint        value,
+	acpi_size               count);
 
 int
 acpi_ut_to_upper (
@@ -231,7 +230,7 @@
 #endif /* ACPI_USE_SYSTEM_CLIBRARY */
 
 /*
- * Ut_copy - Object construction and conversion interfaces
+ * ut_copy - Object construction and conversion interfaces
  */
 
 acpi_status
@@ -300,7 +299,7 @@
 
 
 /*
- * Ut_create - Object creation
+ * ut_create - Object creation
  */
 
 acpi_status
@@ -310,7 +309,7 @@
 
 
 /*
- * Ut_debug - Debug interfaces
+ * ut_debug - Debug interfaces
  */
 
 void
@@ -410,7 +409,7 @@
 
 
 /*
- * Ut_delete - Object deletion
+ * ut_delete - Object deletion
  */
 
 void
@@ -431,7 +430,7 @@
 
 
 /*
- * Ut_eval - object evaluation
+ * ut_eval - object evaluation
  */
 
 /* Method name strings */
@@ -482,7 +481,7 @@
 
 
 /*
- * Ut_mutex - mutual exclusion interfaces
+ * ut_mutex - mutual exclusion interfaces
  */
 
 acpi_status
@@ -495,23 +494,23 @@
 
 acpi_status
 acpi_ut_create_mutex (
-	ACPI_MUTEX_HANDLE       mutex_id);
+	acpi_mutex_handle       mutex_id);
 
 acpi_status
 acpi_ut_delete_mutex (
-	ACPI_MUTEX_HANDLE       mutex_id);
+	acpi_mutex_handle       mutex_id);
 
 acpi_status
 acpi_ut_acquire_mutex (
-	ACPI_MUTEX_HANDLE       mutex_id);
+	acpi_mutex_handle       mutex_id);
 
 acpi_status
 acpi_ut_release_mutex (
-	ACPI_MUTEX_HANDLE       mutex_id);
+	acpi_mutex_handle       mutex_id);
 
 
 /*
- * Ut_object - internal object create/delete/cache routines
+ * ut_object - internal object create/delete/cache routines
  */
 
 acpi_operand_object  *
@@ -540,11 +539,11 @@
 
 acpi_operand_object *
 acpi_ut_create_buffer_object (
-	ACPI_SIZE               buffer_size);
+	acpi_size               buffer_size);
 
 
 /*
- * Ut_ref_cnt - Object reference count management
+ * ut_ref_cnt - Object reference count management
  */
 
 void
@@ -556,23 +555,23 @@
 	acpi_operand_object     *object);
 
 /*
- * Ut_size - Object size routines
+ * ut_size - Object size routines
  */
 
 acpi_status
 acpi_ut_get_simple_object_size (
 	acpi_operand_object     *obj,
-	ACPI_SIZE               *obj_length);
+	acpi_size               *obj_length);
 
 acpi_status
 acpi_ut_get_package_object_size (
 	acpi_operand_object     *obj,
-	ACPI_SIZE               *obj_length);
+	acpi_size               *obj_length);
 
 acpi_status
 acpi_ut_get_object_size(
 	acpi_operand_object     *obj,
-	ACPI_SIZE               *obj_length);
+	acpi_size               *obj_length);
 
 acpi_status
 acpi_ut_get_element_length (
@@ -583,7 +582,7 @@
 
 
 /*
- * Ut_state - Generic state creation/cache routines
+ * ut_state - Generic state creation/cache routines
  */
 
 void
@@ -600,7 +599,7 @@
 acpi_ut_create_generic_state (
 	void);
 
-ACPI_THREAD_STATE *
+acpi_thread_state *
 acpi_ut_create_thread_state (
 	void);
 
@@ -736,21 +735,21 @@
 acpi_status
 acpi_ut_initialize_buffer (
 	acpi_buffer             *buffer,
-	ACPI_SIZE               required_length);
+	acpi_size               required_length);
 
 
 /* Memory allocation functions */
 
 void *
 acpi_ut_allocate (
-	ACPI_SIZE               size,
+	acpi_size               size,
 	u32                     component,
 	char                    *module,
 	u32                     line);
 
 void *
 acpi_ut_callocate (
-	ACPI_SIZE               size,
+	acpi_size               size,
 	u32                     component,
 	char                    *module,
 	u32                     line);
@@ -760,14 +759,14 @@
 
 void *
 acpi_ut_allocate_and_track (
-	ACPI_SIZE               size,
+	acpi_size               size,
 	u32                     component,
 	char                    *module,
 	u32                     line);
 
 void *
 acpi_ut_callocate_and_track (
-	ACPI_SIZE               size,
+	acpi_size               size,
 	u32                     component,
 	char                    *module,
 	u32                     line);
@@ -788,7 +787,7 @@
 acpi_ut_track_allocation (
 	u32                     list_id,
 	acpi_debug_mem_block    *address,
-	ACPI_SIZE               size,
+	acpi_size               size,
 	u8                      alloc_type,
 	u32                     component,
 	char                    *module,
diff -Nru a/drivers/acpi/include/amlcode.h b/drivers/acpi/include/amlcode.h
--- a/drivers/acpi/include/amlcode.h	Mon Dec 23 21:21:58 2002
+++ b/drivers/acpi/include/amlcode.h	Mon Dec 23 21:21:58 2002
@@ -3,7 +3,6 @@
  * Name: amlcode.h - Definitions for AML, as included in "definition blocks"
  *                   Declarations and definitions contained herein are derived
  *                   directly from the ACPI specification.
- *       $Revision: 71 $
  *
  *****************************************************************************/
 
@@ -191,7 +190,7 @@
 
 /*
  * Argument types for the AML Parser
- * Each field in the Arg_types u32 is 5 bits, allowing for a maximum of 6 arguments.
+ * Each field in the arg_types u32 is 5 bits, allowing for a maximum of 6 arguments.
  * There can be up to 31 unique argument types
  */
 
@@ -216,7 +215,7 @@
 
 /*
  * Resolved argument types for the AML Interpreter
- * Each field in the Arg_types u32 is 5 bits, allowing for a maximum of 6 arguments.
+ * Each field in the arg_types u32 is 5 bits, allowing for a maximum of 6 arguments.
  * There can be up to 31 unique argument types (0 is end-of-arg-list indicator)
  *
  * Note: If and when 5 bits becomes insufficient, it would probably be best
@@ -240,7 +239,7 @@
 #define ARGI_ANYOBJECT              0x11
 #define ARGI_ANYTYPE                0x12
 #define ARGI_COMPUTEDATA            0x13     /* Buffer, String, or Integer */
-#define ARGI_DATAOBJECT             0x14     /* Buffer, String, package or reference to a Node - Used only by Size_of operator*/
+#define ARGI_DATAOBJECT             0x14     /* Buffer, String, package or reference to a Node - Used only by size_of operator*/
 #define ARGI_COMPLEXOBJ             0x15     /* Buffer, String, or package (Used by INDEX op only) */
 #define ARGI_INTEGER_REF            0x16
 #define ARGI_OBJECT_REF             0x17
@@ -296,10 +295,10 @@
 #define AML_FLAGS_EXEC_1A_0T_0R     AML_HAS_ARGS                                   /* Monadic1  */
 #define AML_FLAGS_EXEC_1A_0T_1R     AML_HAS_ARGS |                  AML_HAS_RETVAL /* Monadic2  */
 #define AML_FLAGS_EXEC_1A_1T_0R     AML_HAS_ARGS | AML_HAS_TARGET
-#define AML_FLAGS_EXEC_1A_1T_1R     AML_HAS_ARGS | AML_HAS_TARGET | AML_HAS_RETVAL /* Monadic2_r */
+#define AML_FLAGS_EXEC_1A_1T_1R     AML_HAS_ARGS | AML_HAS_TARGET | AML_HAS_RETVAL /* monadic2_r */
 #define AML_FLAGS_EXEC_2A_0T_0R     AML_HAS_ARGS                                   /* Dyadic1   */
 #define AML_FLAGS_EXEC_2A_0T_1R     AML_HAS_ARGS |                  AML_HAS_RETVAL /* Dyadic2   */
-#define AML_FLAGS_EXEC_2A_1T_1R     AML_HAS_ARGS | AML_HAS_TARGET | AML_HAS_RETVAL /* Dyadic2_r  */
+#define AML_FLAGS_EXEC_2A_1T_1R     AML_HAS_ARGS | AML_HAS_TARGET | AML_HAS_RETVAL /* dyadic2_r  */
 #define AML_FLAGS_EXEC_2A_2T_1R     AML_HAS_ARGS | AML_HAS_TARGET | AML_HAS_RETVAL
 #define AML_FLAGS_EXEC_3A_0T_0R     AML_HAS_ARGS
 #define AML_FLAGS_EXEC_3A_1T_1R     AML_HAS_ARGS | AML_HAS_TARGET | AML_HAS_RETVAL
@@ -313,10 +312,10 @@
 #define AML_TYPE_EXEC_1A_0T_0R      0x00 /* Monadic1  */
 #define AML_TYPE_EXEC_1A_0T_1R      0x01 /* Monadic2  */
 #define AML_TYPE_EXEC_1A_1T_0R      0x02
-#define AML_TYPE_EXEC_1A_1T_1R      0x03 /* Monadic2_r */
+#define AML_TYPE_EXEC_1A_1T_1R      0x03 /* monadic2_r */
 #define AML_TYPE_EXEC_2A_0T_0R      0x04 /* Dyadic1   */
 #define AML_TYPE_EXEC_2A_0T_1R      0x05 /* Dyadic2   */
-#define AML_TYPE_EXEC_2A_1T_1R      0x06 /* Dyadic2_r  */
+#define AML_TYPE_EXEC_2A_1T_1R      0x06 /* dyadic2_r  */
 #define AML_TYPE_EXEC_2A_2T_1R      0x07
 #define AML_TYPE_EXEC_3A_0T_0R      0x08
 #define AML_TYPE_EXEC_3A_1T_1R      0x09
@@ -364,7 +363,7 @@
 #define AML_CLASS_UNKNOWN           0x0A
 
 
-/* Predefined Operation Region Space_iDs */
+/* Predefined Operation Region space_iDs */
 
 typedef enum
 {
@@ -381,7 +380,7 @@
 } AML_REGION_TYPES;
 
 
-/* Comparison operation codes for Match_op operator */
+/* Comparison operation codes for match_op operator */
 
 typedef enum
 {
@@ -398,7 +397,7 @@
 
 
 /*
- * Field_flags
+ * field_flags
  *
  * This byte is extracted from the AML and includes three separate
  * pieces of information about the field:
@@ -406,9 +405,9 @@
  * 2) The field update rule
  * 3) The lock rule for the field
  *
- * Bits 00 - 03 : Access_type (Any_acc, Byte_acc, etc.)
- *      04      : Lock_rule (1 == Lock)
- *      05 - 06 : Update_rule
+ * Bits 00 - 03 : access_type (any_acc, byte_acc, etc.)
+ *      04      : lock_rule (1 == Lock)
+ *      05 - 06 : update_rule
  */
 #define AML_FIELD_ACCESS_TYPE_MASK  0x0F
 #define AML_FIELD_LOCK_RULE_MASK    0x10
@@ -453,7 +452,7 @@
 /*
  * Field Access Attributes.
  * This byte is extracted from the AML via the
- * Access_as keyword
+ * access_as keyword
  */
 typedef enum
 {
@@ -468,7 +467,7 @@
 } AML_ACCESS_ATTRIBUTE;
 
 
-/* bit fields in Method_flags byte */
+/* bit fields in method_flags byte */
 
 #define METHOD_FLAGS_ARG_COUNT      0x07
 #define METHOD_FLAGS_SERIALIZED     0x08
diff -Nru a/drivers/acpi/include/amlresrc.h b/drivers/acpi/include/amlresrc.h
--- a/drivers/acpi/include/amlresrc.h	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/include/amlresrc.h	Mon Dec 23 21:21:51 2002
@@ -2,7 +2,6 @@
 /******************************************************************************
  *
  * Module Name: amlresrc.h - AML resource descriptors
- *              $Revision: 22 $
  *
  *****************************************************************************/
 
@@ -39,12 +38,12 @@
 #define ASL_RESNAME_DMATYPE                     "_TYP"  /* Compatible(0), A(1), B(2), F(3) */
 #define ASL_RESNAME_GRANULARITY                 "_GRA"
 #define ASL_RESNAME_INTERRUPT                   "_INT"
-#define ASL_RESNAME_INTERRUPTLEVEL              "_LL_"  /* Active_lo(1), Active_hi(0) */
-#define ASL_RESNAME_INTERRUPTSHARE              "_SHR"  /* Shareable(1), No_share(0) */
+#define ASL_RESNAME_INTERRUPTLEVEL              "_LL_"  /* active_lo(1), active_hi(0) */
+#define ASL_RESNAME_INTERRUPTSHARE              "_SHR"  /* Shareable(1), no_share(0) */
 #define ASL_RESNAME_INTERRUPTTYPE               "_HE_"  /* Edge(1), Level(0) */
 #define ASL_RESNAME_LENGTH                      "_LEN"
 #define ASL_RESNAME_MEMATTRIBUTES               "_MTP"  /* Memory(0), Reserved(1), ACPI(2), NVS(3) */
-#define ASL_RESNAME_MEMTYPE                     "_MEM"  /* Non_cache(0), Cacheable(1) Cache+combine(2), Cache+prefetch(3) */
+#define ASL_RESNAME_MEMTYPE                     "_MEM"  /* non_cache(0), Cacheable(1) Cache+combine(2), Cache+prefetch(3) */
 #define ASL_RESNAME_MAXADDR                     "_MAX"
 #define ASL_RESNAME_MINADDR                     "_MIN"
 #define ASL_RESNAME_MAXTYPE                     "_MAF"
@@ -52,11 +51,11 @@
 #define ASL_RESNAME_REGISTERBITOFFSET           "_RBO"
 #define ASL_RESNAME_REGISTERBITWIDTH            "_RBW"
 #define ASL_RESNAME_RANGETYPE                   "_RNG"
-#define ASL_RESNAME_READWRITETYPE               "_RW_"  /* Read_only(0), Writeable (1) */
+#define ASL_RESNAME_READWRITETYPE               "_RW_"  /* read_only(0), Writeable (1) */
 #define ASL_RESNAME_TRANSLATION                 "_TRA"
 #define ASL_RESNAME_TRANSTYPE                   "_TRS"  /* Sparse(1), Dense(0) */
 #define ASL_RESNAME_TYPE                        "_TTP"  /* Translation(1), Static (0) */
-#define ASL_RESNAME_XFERTYPE                    "_SIZ"  /* 8(0), 8_and16(1), 16(2) */
+#define ASL_RESNAME_XFERTYPE                    "_SIz"  /* 8(0), 8_and16(1), 16(2) */
 
 
 /* Default sizes for "small" resource descriptors */
@@ -76,7 +75,7 @@
 	void                        *buffer;
 	struct asl_resource_node    *next;
 
-} ASL_RESOURCE_NODE;
+} asl_resource_node;
 
 
 /*
@@ -93,7 +92,7 @@
 	u16                         irq_mask;
 	u8                          flags;
 
-} ASL_IRQ_FORMAT_DESC;
+} asl_irq_format_desc;
 
 
 typedef struct asl_irq_noflags_desc
@@ -101,7 +100,7 @@
 	u8                          descriptor_type;
 	u16                         irq_mask;
 
-} ASL_IRQ_NOFLAGS_DESC;
+} asl_irq_noflags_desc;
 
 
 typedef struct asl_dma_format_desc
@@ -110,7 +109,7 @@
 	u8                          dma_channel_mask;
 	u8                          flags;
 
-} ASL_DMA_FORMAT_DESC;
+} asl_dma_format_desc;
 
 
 typedef struct asl_start_dependent_desc
@@ -118,21 +117,21 @@
 	u8                          descriptor_type;
 	u8                          flags;
 
-} ASL_START_DEPENDENT_DESC;
+} asl_start_dependent_desc;
 
 
 typedef struct asl_start_dependent_noprio_desc
 {
 	u8                          descriptor_type;
 
-} ASL_START_DEPENDENT_NOPRIO_DESC;
+} asl_start_dependent_noprio_desc;
 
 
 typedef struct asl_end_dependent_desc
 {
 	u8                          descriptor_type;
 
-} ASL_END_DEPENDENT_DESC;
+} asl_end_dependent_desc;
 
 
 typedef struct asl_io_port_desc
@@ -144,7 +143,7 @@
 	u8                          alignment;
 	u8                          length;
 
-} ASL_IO_PORT_DESC;
+} asl_io_port_desc;
 
 
 typedef struct asl_fixed_io_port_desc
@@ -153,7 +152,7 @@
 	u16                         base_address;
 	u8                          length;
 
-} ASL_FIXED_IO_PORT_DESC;
+} asl_fixed_io_port_desc;
 
 
 typedef struct asl_small_vendor_desc
@@ -161,7 +160,7 @@
 	u8                          descriptor_type;
 	u8                          vendor_defined[7];
 
-} ASL_SMALL_VENDOR_DESC;
+} asl_small_vendor_desc;
 
 
 typedef struct asl_end_tag_desc
@@ -169,7 +168,7 @@
 	u8                          descriptor_type;
 	u8                          checksum;
 
-} ASL_END_TAG_DESC;
+} asl_end_tag_desc;
 
 
 /* LARGE descriptors */
@@ -184,7 +183,7 @@
 	u16                         alignment;
 	u16                         range_length;
 
-} ASL_MEMORY_24_DESC;
+} asl_memory_24_desc;
 
 
 typedef struct asl_large_vendor_desc
@@ -193,7 +192,7 @@
 	u16                         length;
 	u8                          vendor_defined[1];
 
-} ASL_LARGE_VENDOR_DESC;
+} asl_large_vendor_desc;
 
 
 typedef struct asl_memory_32_desc
@@ -206,7 +205,7 @@
 	u32                         alignment;
 	u32                         range_length;
 
-} ASL_MEMORY_32_DESC;
+} asl_memory_32_desc;
 
 
 typedef struct asl_fixed_memory_32_desc
@@ -217,7 +216,7 @@
 	u32                         base_address;
 	u32                         range_length;
 
-} ASL_FIXED_MEMORY_32_DESC;
+} asl_fixed_memory_32_desc;
 
 
 typedef struct asl_qword_address_desc
@@ -234,7 +233,7 @@
 	u64                         address_length;
 	u8                          optional_fields[2];
 
-} ASL_QWORD_ADDRESS_DESC;
+} asl_qword_address_desc;
 
 
 typedef struct asl_dword_address_desc
@@ -251,7 +250,7 @@
 	u32                         address_length;
 	u8                          optional_fields[2];
 
-} ASL_DWORD_ADDRESS_DESC;
+} asl_dword_address_desc;
 
 
 typedef struct asl_word_address_desc
@@ -268,7 +267,7 @@
 	u16                         address_length;
 	u8                          optional_fields[2];
 
-} ASL_WORD_ADDRESS_DESC;
+} asl_word_address_desc;
 
 
 typedef struct asl_extended_xrupt_desc
@@ -278,9 +277,9 @@
 	u8                          flags;
 	u8                          table_length;
 	u32                         interrupt_number[1];
-	/* Res_source_index, Res_source optional fields follow */
+	/* res_source_index, res_source optional fields follow */
 
-} ASL_EXTENDED_XRUPT_DESC;
+} asl_extended_xrupt_desc;
 
 
 typedef struct asl_general_register_desc
@@ -293,7 +292,7 @@
 	u8                          reserved;
 	u64                         address;
 
-} ASL_GENERAL_REGISTER_DESC;
+} asl_general_register_desc;
 
 /* restore default alignment */
 
@@ -303,29 +302,29 @@
 
 typedef union asl_resource_desc
 {
-	ASL_IRQ_FORMAT_DESC         irq;
-	ASL_DMA_FORMAT_DESC         dma;
-	ASL_START_DEPENDENT_DESC    std;
-	ASL_END_DEPENDENT_DESC      end;
-	ASL_IO_PORT_DESC            iop;
-	ASL_FIXED_IO_PORT_DESC      fio;
-	ASL_SMALL_VENDOR_DESC       smv;
-	ASL_END_TAG_DESC            et;
-
-	ASL_MEMORY_24_DESC          M24;
-	ASL_LARGE_VENDOR_DESC       lgv;
-	ASL_MEMORY_32_DESC          M32;
-	ASL_FIXED_MEMORY_32_DESC    F32;
-	ASL_QWORD_ADDRESS_DESC      qas;
-	ASL_DWORD_ADDRESS_DESC      das;
-	ASL_WORD_ADDRESS_DESC       was;
-	ASL_EXTENDED_XRUPT_DESC     exx;
-	ASL_GENERAL_REGISTER_DESC   grg;
-	u32                         U32_item;
-	u16                         U16_item;
+	asl_irq_format_desc         irq;
+	asl_dma_format_desc         dma;
+	asl_start_dependent_desc    std;
+	asl_end_dependent_desc      end;
+	asl_io_port_desc            iop;
+	asl_fixed_io_port_desc      fio;
+	asl_small_vendor_desc       smv;
+	asl_end_tag_desc            et;
+
+	asl_memory_24_desc          M24;
+	asl_large_vendor_desc       lgv;
+	asl_memory_32_desc          M32;
+	asl_fixed_memory_32_desc    F32;
+	asl_qword_address_desc      qas;
+	asl_dword_address_desc      das;
+	asl_word_address_desc       was;
+	asl_extended_xrupt_desc     exx;
+	asl_general_register_desc   grg;
+	u32                         u32_item;
+	u16                         u16_item;
 	u8                          U8item;
 
-} ASL_RESOURCE_DESC;
+} asl_resource_desc;
 
 
 #endif
diff -Nru a/drivers/acpi/include/platform/acenv.h b/drivers/acpi/include/platform/acenv.h
--- a/drivers/acpi/include/platform/acenv.h	Mon Dec 23 21:21:52 2002
+++ b/drivers/acpi/include/platform/acenv.h	Mon Dec 23 21:21:52 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: acenv.h - Generation environment specific items
- *       $Revision: 101 $
  *
  *****************************************************************************/
 
@@ -206,16 +205,16 @@
 
 #define ACPI_STRSTR(s1,s2)      strstr((s1), (s2))
 #define ACPI_STRUPR(s)          (void) acpi_ut_strupr ((s))
-#define ACPI_STRLEN(s)          (ACPI_SIZE) strlen((s))
+#define ACPI_STRLEN(s)          (acpi_size) strlen((s))
 #define ACPI_STRCPY(d,s)        (void) strcpy((d), (s))
-#define ACPI_STRNCPY(d,s,n)     (void) strncpy((d), (s), (ACPI_SIZE)(n))
-#define ACPI_STRNCMP(d,s,n)     strncmp((d), (s), (ACPI_SIZE)(n))
+#define ACPI_STRNCPY(d,s,n)     (void) strncpy((d), (s), (acpi_size)(n))
+#define ACPI_STRNCMP(d,s,n)     strncmp((d), (s), (acpi_size)(n))
 #define ACPI_STRCMP(d,s)        strcmp((d), (s))
 #define ACPI_STRCAT(d,s)        (void) strcat((d), (s))
-#define ACPI_STRNCAT(d,s,n)     strncat((d), (s), (ACPI_SIZE)(n))
-#define ACPI_STRTOUL(d,s,n)     strtoul((d), (s), (ACPI_SIZE)(n))
-#define ACPI_MEMCPY(d,s,n)      (void) memcpy((d), (s), (ACPI_SIZE)(n))
-#define ACPI_MEMSET(d,s,n)      (void) memset((d), (s), (ACPI_SIZE)(n))
+#define ACPI_STRNCAT(d,s,n)     strncat((d), (s), (acpi_size)(n))
+#define ACPI_STRTOUL(d,s,n)     strtoul((d), (s), (acpi_size)(n))
+#define ACPI_MEMCPY(d,s,n)      (void) memcpy((d), (s), (acpi_size)(n))
+#define ACPI_MEMSET(d,s,n)      (void) memset((d), (s), (acpi_size)(n))
 
 #define ACPI_TOUPPER            toupper
 #define ACPI_TOLOWER            tolower
@@ -252,8 +251,8 @@
  * Storage alignment properties
  */
 
-#define  _AUPBND                (sizeof (NATIVE_INT) - 1)
-#define  _ADNBND                (sizeof (NATIVE_INT) - 1)
+#define  _AUPBND                (sizeof (acpi_native_int) - 1)
+#define  _ADNBND                (sizeof (acpi_native_int) - 1)
 
 /*
  * Variable argument list macro definitions
@@ -269,16 +268,16 @@
 
 #define ACPI_STRSTR(s1,s2)      acpi_ut_strstr ((s1), (s2))
 #define ACPI_STRUPR(s)          (void) acpi_ut_strupr ((s))
-#define ACPI_STRLEN(s)          (ACPI_SIZE) acpi_ut_strlen ((s))
+#define ACPI_STRLEN(s)          (acpi_size) acpi_ut_strlen ((s))
 #define ACPI_STRCPY(d,s)        (void) acpi_ut_strcpy ((d), (s))
-#define ACPI_STRNCPY(d,s,n)     (void) acpi_ut_strncpy ((d), (s), (ACPI_SIZE)(n))
-#define ACPI_STRNCMP(d,s,n)     acpi_ut_strncmp ((d), (s), (ACPI_SIZE)(n))
+#define ACPI_STRNCPY(d,s,n)     (void) acpi_ut_strncpy ((d), (s), (acpi_size)(n))
+#define ACPI_STRNCMP(d,s,n)     acpi_ut_strncmp ((d), (s), (acpi_size)(n))
 #define ACPI_STRCMP(d,s)        acpi_ut_strcmp ((d), (s))
 #define ACPI_STRCAT(d,s)        (void) acpi_ut_strcat ((d), (s))
-#define ACPI_STRNCAT(d,s,n)     acpi_ut_strncat ((d), (s), (ACPI_SIZE)(n))
-#define ACPI_STRTOUL(d,s,n)     acpi_ut_strtoul ((d), (s), (ACPI_SIZE)(n))
-#define ACPI_MEMCPY(d,s,n)      (void) acpi_ut_memcpy ((d), (s), (ACPI_SIZE)(n))
-#define ACPI_MEMSET(d,v,n)      (void) acpi_ut_memset ((d), (v), (ACPI_SIZE)(n))
+#define ACPI_STRNCAT(d,s,n)     acpi_ut_strncat ((d), (s), (acpi_size)(n))
+#define ACPI_STRTOUL(d,s,n)     acpi_ut_strtoul ((d), (s), (acpi_size)(n))
+#define ACPI_MEMCPY(d,s,n)      (void) acpi_ut_memcpy ((d), (s), (acpi_size)(n))
+#define ACPI_MEMSET(d,v,n)      (void) acpi_ut_memset ((d), (v), (acpi_size)(n))
 #define ACPI_TOUPPER            acpi_ut_to_upper
 #define ACPI_TOLOWER            acpi_ut_to_lower
 
diff -Nru a/drivers/acpi/include/platform/acgcc.h b/drivers/acpi/include/platform/acgcc.h
--- a/drivers/acpi/include/platform/acgcc.h	Mon Dec 23 21:22:00 2002
+++ b/drivers/acpi/include/platform/acgcc.h	Mon Dec 23 21:22:00 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: acgcc.h - GCC specific defines, etc.
- *       $Revision: 24 $
  *
  *****************************************************************************/
 
diff -Nru a/drivers/acpi/include/platform/aclinux.h b/drivers/acpi/include/platform/aclinux.h
--- a/drivers/acpi/include/platform/aclinux.h	Mon Dec 23 21:21:59 2002
+++ b/drivers/acpi/include/platform/aclinux.h	Mon Dec 23 21:21:59 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Name: aclinux.h - OS specific defines, etc.
- *       $Revision: 29 $
  *
  *****************************************************************************/
 
diff -Nru a/drivers/acpi/namespace/nsaccess.c b/drivers/acpi/namespace/nsaccess.c
--- a/drivers/acpi/namespace/nsaccess.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/acpi/namespace/nsaccess.c	Mon Dec 23 21:22:00 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: nsaccess - Top-level functions for accessing ACPI namespace
- *              $Revision: 167 $
  *
  ******************************************************************************/
 
@@ -36,7 +35,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_root_initialize
+ * FUNCTION:    acpi_ns_root_initialize
  *
  * PARAMETERS:  None
  *
@@ -57,7 +56,7 @@
 	acpi_operand_object         *obj_desc;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_root_initialize");
+	ACPI_FUNCTION_TRACE ("ns_root_initialize");
 
 
 	status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
@@ -67,7 +66,7 @@
 
 	/*
 	 * The global root ptr is initially NULL, so a non-NULL value indicates
-	 * that Acpi_ns_root_initialize() has already been called; just return.
+	 * that acpi_ns_root_initialize() has already been called; just return.
 	 */
 	if (acpi_gbl_root_node) {
 		status = AE_OK;
@@ -97,7 +96,7 @@
 
 		/*
 		 * Name entered successfully.
-		 * If entry in Pre_defined_names[] specifies an
+		 * If entry in pre_defined_names[] specifies an
 		 * initial value, create the initial value.
 		 */
 		if (init_val->val) {
@@ -124,7 +123,7 @@
 
 #if defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY)
 
-				/* Compiler cheats by putting parameter count in the Owner_iD */
+				/* Compiler cheats by putting parameter count in the owner_iD */
 
 				new_node->owner_id = obj_desc->method.param_count;
 #endif
@@ -210,16 +209,16 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_lookup
+ * FUNCTION:    acpi_ns_lookup
  *
- * PARAMETERS:  Prefix_node     - Search scope if name is not fully qualified
+ * PARAMETERS:  prefix_node     - Search scope if name is not fully qualified
  *              Pathname        - Search pathname, in internal format
  *                                (as represented in the AML stream)
  *              Type            - Type associated with name
- *              Interpreter_mode - IMODE_LOAD_PASS2 => add name if not found
+ *              interpreter_mode - IMODE_LOAD_PASS2 => add name if not found
  *              Flags           - Flags describing the search restrictions
- *              Walk_state      - Current state of the walk
- *              Return_node     - Where the Node is placed (if found
+ *              walk_state      - Current state of the walk
+ *              return_node     - Where the Node is placed (if found
  *                                or created successfully)
  *
  * RETURN:      Status
@@ -256,7 +255,7 @@
 			   ACPI_NS_SEARCH_PARENT);
 
 
-	ACPI_FUNCTION_TRACE ("Ns_lookup");
+	ACPI_FUNCTION_TRACE ("ns_lookup");
 
 
 	if (!return_node) {
@@ -309,7 +308,7 @@
 	 * Begin examination of the actual pathname
 	 */
 	if (!pathname) {
-		/* A Null Name_path is allowed and refers to the root */
+		/* A Null name_path is allowed and refers to the root */
 
 		num_segments = 0;
 		this_node    = acpi_gbl_root_node;
@@ -393,8 +392,8 @@
 		 *
 		 * The segment part consists of either:
 		 *  - A Null name segment (0)
-		 *  - A Dual_name_prefix followed by two 4-byte name segments
-		 *  - A Multi_name_prefix followed by a byte indicating the
+		 *  - A dual_name_prefix followed by two 4-byte name segments
+		 *  - A multi_name_prefix followed by a byte indicating the
 		 *      number of segments and the segments themselves.
 		 *  - A single 4-byte name segment
 		 *
@@ -416,7 +415,7 @@
 
 		case AML_DUAL_NAME_PREFIX:
 
-			/* More than one Name_seg, search rules do not apply */
+			/* More than one name_seg, search rules do not apply */
 
 			search_parent_flag = ACPI_NS_NO_UPSEARCH;
 
@@ -431,7 +430,7 @@
 
 		case AML_MULTI_NAME_PREFIX_OP:
 
-			/* More than one Name_seg, search rules do not apply */
+			/* More than one name_seg, search rules do not apply */
 
 			search_parent_flag = ACPI_NS_NO_UPSEARCH;
 
@@ -482,7 +481,7 @@
 
 			/*
 			 * Only allow automatic parent search (search rules) if the caller
-			 * requested it AND we have a single, non-fully-qualified Name_seg
+			 * requested it AND we have a single, non-fully-qualified name_seg
 			 */
 			if ((search_parent_flag != ACPI_NS_NO_UPSEARCH) &&
 				(flags & ACPI_NS_SEARCH_PARENT)) {
@@ -521,7 +520,7 @@
 		/*
 		 * Sanity typecheck of the target object:
 		 *
-		 * If 1) This is the last segment (Num_segments == 0)
+		 * If 1) This is the last segment (num_segments == 0)
 		 *    2) And we are looking for a specific type
 		 *       (Not checking for TYPE_ANY)
 		 *    3) Which is not an alias
@@ -540,7 +539,7 @@
 			/* Complain about a type mismatch */
 
 			ACPI_REPORT_WARNING (
-				("Ns_lookup: Type mismatch on %4.4s (%s), searching for (%s)\n",
+				("ns_lookup: Type mismatch on %4.4s (%s), searching for (%s)\n",
 				(char *) &simple_name, acpi_ut_get_type_name (this_node->type),
 				acpi_ut_get_type_name (type_to_check_for)));
 		}
diff -Nru a/drivers/acpi/namespace/nsalloc.c b/drivers/acpi/namespace/nsalloc.c
--- a/drivers/acpi/namespace/nsalloc.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/acpi/namespace/nsalloc.c	Mon Dec 23 21:21:55 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: nsalloc - Namespace allocation and deletion utilities
- *              $Revision: 78 $
  *
  ******************************************************************************/
 
@@ -34,9 +33,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_create_node
+ * FUNCTION:    acpi_ns_create_node
  *
- * PARAMETERS:  Acpi_name       - Name of the new node
+ * PARAMETERS:  acpi_name       - Name of the new node
  *
  * RETURN:      None
  *
@@ -51,7 +50,7 @@
 	acpi_namespace_node     *node;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_create_node");
+	ACPI_FUNCTION_TRACE ("ns_create_node");
 
 
 	node = ACPI_MEM_CALLOCATE (sizeof (acpi_namespace_node));
@@ -71,7 +70,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_delete_node
+ * FUNCTION:    acpi_ns_delete_node
  *
  * PARAMETERS:  Node            - Node to be deleted
  *
@@ -90,7 +89,7 @@
 	acpi_namespace_node     *next_node;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ns_delete_node", node);
+	ACPI_FUNCTION_TRACE_PTR ("ns_delete_node", node);
 
 
 	parent_node = acpi_ns_get_parent_node (node);
@@ -128,7 +127,7 @@
 #ifdef ACPI_ALPHABETIC_NAMESPACE
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_compare_names
+ * FUNCTION:    acpi_ns_compare_names
  *
  * PARAMETERS:  Name1           - First name to compare
  *              Name2           - Second name to compare
@@ -178,10 +177,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_install_node
+ * FUNCTION:    acpi_ns_install_node
  *
- * PARAMETERS:  Walk_state      - Current state of the walk
- *              Parent_node     - The parent of the new Node
+ * PARAMETERS:  walk_state      - Current state of the walk
+ *              parent_node     - The parent of the new Node
  *              Node            - The new Node to install
  *              Type            - ACPI object type of the new Node
  *
@@ -212,7 +211,7 @@
 #endif
 
 
-	ACPI_FUNCTION_TRACE ("Ns_install_node");
+	ACPI_FUNCTION_TRACE ("ns_install_node");
 
 
 	/*
@@ -320,9 +319,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_delete_children
+ * FUNCTION:    acpi_ns_delete_children
  *
- * PARAMETERS:  Parent_node     - Delete this objects children
+ * PARAMETERS:  parent_node     - Delete this objects children
  *
  * RETURN:      None.
  *
@@ -340,7 +339,7 @@
 	u8                      flags;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ns_delete_children", parent_node);
+	ACPI_FUNCTION_TRACE_PTR ("ns_delete_children", parent_node);
 
 
 	if (!parent_node) {
@@ -400,9 +399,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_delete_namespace_subtree
+ * FUNCTION:    acpi_ns_delete_namespace_subtree
  *
- * PARAMETERS:  Parent_node     - Root of the subtree to be deleted
+ * PARAMETERS:  parent_node     - Root of the subtree to be deleted
  *
  * RETURN:      None.
  *
@@ -419,7 +418,7 @@
 	u32                     level = 1;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_delete_namespace_subtree");
+	ACPI_FUNCTION_TRACE ("ns_delete_namespace_subtree");
 
 
 	if (!parent_node) {
@@ -481,7 +480,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_remove_reference
+ * FUNCTION:    acpi_ns_remove_reference
  *
  * PARAMETERS:  Node           - Named node whose reference count is to be
  *                               decremented
@@ -535,9 +534,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_delete_namespace_by_owner
+ * FUNCTION:    acpi_ns_delete_namespace_by_owner
  *
- * PARAMETERS:  Owner_id    - All nodes with this owner will be deleted
+ * PARAMETERS:  owner_id    - All nodes with this owner will be deleted
  *
  * RETURN:      Status
  *
@@ -557,7 +556,7 @@
 	acpi_namespace_node     *parent_node;
 
 
-	ACPI_FUNCTION_TRACE_U32 ("Ns_delete_namespace_by_owner", owner_id);
+	ACPI_FUNCTION_TRACE_U32 ("ns_delete_namespace_by_owner", owner_id);
 
 
 	parent_node   = acpi_gbl_root_node;
@@ -571,7 +570,7 @@
 	 */
 	while (level > 0) {
 		/*
-		 * Get the next child of this parent node. When Child_node is NULL,
+		 * Get the next child of this parent node. When child_node is NULL,
 		 * the first child of the parent is returned
 		 */
 		child_node = acpi_ns_get_next_node (ACPI_TYPE_ANY, parent_node, child_node);
diff -Nru a/drivers/acpi/namespace/nsdump.c b/drivers/acpi/namespace/nsdump.c
--- a/drivers/acpi/namespace/nsdump.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/acpi/namespace/nsdump.c	Mon Dec 23 21:22:00 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: nsdump - table dumping routines for debug
- *              $Revision: 150 $
  *
  *****************************************************************************/
 
@@ -37,9 +36,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_print_pathname
+ * FUNCTION:    acpi_ns_print_pathname
  *
- * PARAMETERS:  Num_segment         - Number of ACPI name segments
+ * PARAMETERS:  num_segment         - Number of ACPI name segments
  *              Pathname            - The compressed (internal) path
  *
  * DESCRIPTION: Print an object's full namespace pathname
@@ -51,7 +50,7 @@
 	u32                     num_segments,
 	char                    *pathname)
 {
-	ACPI_FUNCTION_NAME ("Ns_print_pathname");
+	ACPI_FUNCTION_NAME ("ns_print_pathname");
 
 
 	if (!(acpi_dbg_level & ACPI_LV_NAMES) || !(acpi_dbg_layer & ACPI_NAMESPACE)) {
@@ -78,7 +77,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_dump_pathname
+ * FUNCTION:    acpi_ns_dump_pathname
  *
  * PARAMETERS:  Handle              - Object
  *              Msg                 - Prefix message
@@ -98,7 +97,7 @@
 	u32                     component)
 {
 
-	ACPI_FUNCTION_TRACE ("Ns_dump_pathname");
+	ACPI_FUNCTION_TRACE ("ns_dump_pathname");
 
 
 	/* Do this only if the requested debug level and component are enabled */
@@ -117,14 +116,14 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_dump_one_object
+ * FUNCTION:    acpi_ns_dump_one_object
  *
  * PARAMETERS:  Handle              - Node to be dumped
  *              Level               - Nesting level of the handle
- *              Context             - Passed into Walk_namespace
+ *              Context             - Passed into walk_namespace
  *
  * DESCRIPTION: Dump a single Node
- *              This procedure is a User_function called by Acpi_ns_walk_namespace.
+ *              This procedure is a user_function called by acpi_ns_walk_namespace.
  *
  ******************************************************************************/
 
@@ -145,7 +144,7 @@
 	u32                     i;
 
 
-	ACPI_FUNCTION_NAME ("Ns_dump_one_object");
+	ACPI_FUNCTION_NAME ("ns_dump_one_object");
 
 
 	/* Is output enabled? */
@@ -531,17 +530,17 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_dump_objects
+ * FUNCTION:    acpi_ns_dump_objects
  *
  * PARAMETERS:  Type                - Object type to be dumped
- *              Max_depth           - Maximum depth of dump.  Use ACPI_UINT32_MAX
+ *              max_depth           - Maximum depth of dump.  Use ACPI_UINT32_MAX
  *                                    for an effectively unlimited depth.
- *              Owner_id            - Dump only objects owned by this ID.  Use
+ *              owner_id            - Dump only objects owned by this ID.  Use
  *                                    ACPI_UINT32_MAX to match all owners.
- *              Start_handle        - Where in namespace to start/end search
+ *              start_handle        - Where in namespace to start/end search
  *
  * DESCRIPTION: Dump typed objects within the loaded namespace.
- *              Uses Acpi_ns_walk_namespace in conjunction with Acpi_ns_dump_one_object.
+ *              Uses acpi_ns_walk_namespace in conjunction with acpi_ns_dump_one_object.
  *
  ******************************************************************************/
 
@@ -572,11 +571,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_dump_tables
+ * FUNCTION:    acpi_ns_dump_tables
  *
- * PARAMETERS:  Search_base         - Root of subtree to be dumped, or
+ * PARAMETERS:  search_base         - Root of subtree to be dumped, or
  *                                    NS_ALL to dump the entire namespace
- *              Max_depth           - Maximum depth of dump.  Use INT_MAX
+ *              max_depth           - Maximum depth of dump.  Use INT_MAX
  *                                    for an effectively unlimited depth.
  *
  * DESCRIPTION: Dump the name space, or a portion of it.
@@ -591,7 +590,7 @@
 	acpi_handle             search_handle = search_base;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_dump_tables");
+	ACPI_FUNCTION_TRACE ("ns_dump_tables");
 
 
 	if (!acpi_gbl_root_node) {
@@ -619,10 +618,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_dump_entry
+ * FUNCTION:    acpi_ns_dump_entry
  *
  * PARAMETERS:  Handle              - Node to be dumped
- *              Debug_level         - Output level
+ *              debug_level         - Output level
  *
  * DESCRIPTION: Dump a single Node
  *
diff -Nru a/drivers/acpi/namespace/nsdumpdv.c b/drivers/acpi/namespace/nsdumpdv.c
--- a/drivers/acpi/namespace/nsdumpdv.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/acpi/namespace/nsdumpdv.c	Mon Dec 23 21:21:50 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: nsdump - table dumping routines for debug
- *              $Revision: 4 $
  *
  *****************************************************************************/
 
@@ -36,14 +35,14 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_dump_one_device
+ * FUNCTION:    acpi_ns_dump_one_device
  *
  * PARAMETERS:  Handle              - Node to be dumped
  *              Level               - Nesting level of the handle
- *              Context             - Passed into Walk_namespace
+ *              Context             - Passed into walk_namespace
  *
  * DESCRIPTION: Dump a single Node that represents a device
- *              This procedure is a User_function called by Acpi_ns_walk_namespace.
+ *              This procedure is a user_function called by acpi_ns_walk_namespace.
  *
  ******************************************************************************/
 
@@ -59,7 +58,7 @@
 	u32                     i;
 
 
-	ACPI_FUNCTION_NAME ("Ns_dump_one_device");
+	ACPI_FUNCTION_NAME ("ns_dump_one_device");
 
 
 	status = acpi_ns_dump_one_object (obj_handle, level, context, return_value);
@@ -82,7 +81,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_dump_root_devices
+ * FUNCTION:    acpi_ns_dump_root_devices
  *
  * PARAMETERS:  None
  *
@@ -97,7 +96,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_NAME ("Ns_dump_root_devices");
+	ACPI_FUNCTION_NAME ("ns_dump_root_devices");
 
 
 	/* Only dump the table if tracing is enabled */
diff -Nru a/drivers/acpi/namespace/nseval.c b/drivers/acpi/namespace/nseval.c
--- a/drivers/acpi/namespace/nseval.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/acpi/namespace/nseval.c	Mon Dec 23 21:21:53 2002
@@ -2,7 +2,6 @@
  *
  * Module Name: nseval - Object evaluation interfaces -- includes control
  *                       method lookup and execution.
- *              $Revision: 120 $
  *
  ******************************************************************************/
 
@@ -37,7 +36,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_evaluate_relative
+ * FUNCTION:    acpi_ns_evaluate_relative
  *
  * PARAMETERS:  Handle              - The relative containing object
  *              Pathname            - Name of method to execute, If NULL, the
@@ -45,7 +44,7 @@
  *              Params              - List of parameters to pass to the method,
  *                                    terminated by NULL.  Params itself may be
  *                                    NULL if no parameters are being passed.
- *              Return_object       - Where to put method's return value (if
+ *              return_object       - Where to put method's return value (if
  *                                    any).  If NULL, no value is returned.
  *
  * RETURN:      Status
@@ -71,7 +70,7 @@
 	acpi_generic_state      scope_info;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_evaluate_relative");
+	ACPI_FUNCTION_TRACE ("ns_evaluate_relative");
 
 
 	/*
@@ -138,10 +137,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_evaluate_by_name
+ * FUNCTION:    acpi_ns_evaluate_by_name
  *
  * PARAMETERS:  Pathname            - Fully qualified pathname to the object
- *              Return_object       - Where to put method's return value (if
+ *              return_object       - Where to put method's return value (if
  *                                    any).  If NULL, no value is returned.
  *              Params              - List of parameters to pass to the method,
  *                                    terminated by NULL.  Params itself may be
@@ -167,7 +166,7 @@
 	char                    *internal_path = NULL;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_evaluate_by_name");
+	ACPI_FUNCTION_TRACE ("ns_evaluate_by_name");
 
 
 	/* Build an internal name string for the method */
@@ -223,13 +222,13 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_evaluate_by_handle
+ * FUNCTION:    acpi_ns_evaluate_by_handle
  *
  * PARAMETERS:  Handle              - Method Node to execute
  *              Params              - List of parameters to pass to the method,
  *                                    terminated by NULL.  Params itself may be
  *                                    NULL if no parameters are being passed.
- *              Return_object       - Where to put method's return value (if
+ *              return_object       - Where to put method's return value (if
  *                                    any).  If NULL, no value is returned.
  *
  * RETURN:      Status
@@ -251,7 +250,7 @@
 	acpi_operand_object     *local_return_object;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_evaluate_by_handle");
+	ACPI_FUNCTION_TRACE ("ns_evaluate_by_handle");
 
 
 	/* Check if namespace has been initialized */
@@ -292,7 +291,7 @@
 	 *      value
 	 *
 	 * In both cases, the namespace is unlocked by the
-	 *  Acpi_ns* procedure
+	 *  acpi_ns* procedure
 	 */
 	if (acpi_ns_get_type (node) == ACPI_TYPE_METHOD) {
 		/*
@@ -334,7 +333,7 @@
 	}
 
 	/*
-	 * Namespace was unlocked by the handling Acpi_ns* function,
+	 * Namespace was unlocked by the handling acpi_ns* function,
 	 * so we just return
 	 */
 	return_ACPI_STATUS (status);
@@ -343,13 +342,13 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_execute_control_method
+ * FUNCTION:    acpi_ns_execute_control_method
  *
- * PARAMETERS:  Method_node         - The method to execute
+ * PARAMETERS:  method_node         - The method to execute
  *              Params              - List of parameters to pass to the method,
  *                                    terminated by NULL.  Params itself may be
  *                                    NULL if no parameters are being passed.
- *              Return_obj_desc     - List of result objects to be returned
+ *              return_obj_desc     - List of result objects to be returned
  *                                    from the method.
  *
  * RETURN:      Status
@@ -370,7 +369,7 @@
 	acpi_operand_object     *obj_desc;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_execute_control_method");
+	ACPI_FUNCTION_TRACE ("ns_execute_control_method");
 
 
 	/* Verify that there is a method associated with this object */
@@ -419,10 +418,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_get_object_value
+ * FUNCTION:    acpi_ns_get_object_value
  *
  * PARAMETERS:  Node                - The object
- *              Return_obj_desc     - Where the objects value is returned
+ *              return_obj_desc     - Where the objects value is returned
  *
  * RETURN:      Status
  *
@@ -441,7 +440,7 @@
 	acpi_namespace_node     *resolved_node = node;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_get_object_value");
+	ACPI_FUNCTION_TRACE ("ns_get_object_value");
 
 
 	/*
@@ -451,13 +450,13 @@
 	 */
 
 	/*
-	 * Use Resolve_node_to_value() to get the associated value. This call
-	 * always deletes Obj_desc (allocated above).
+	 * Use resolve_node_to_value() to get the associated value. This call
+	 * always deletes obj_desc (allocated above).
 	 *
 	 * NOTE: we can get away with passing in NULL for a walk state
-	 * because Obj_desc is guaranteed to not be a reference to either
+	 * because obj_desc is guaranteed to not be a reference to either
 	 * a method local or a method argument (because this interface can only be
-	 * called from the Acpi_evaluate external interface, never called from
+	 * called from the acpi_evaluate external interface, never called from
 	 * a running control method.)
 	 *
 	 * Even though we do not directly invoke the interpreter
@@ -477,8 +476,8 @@
 	if (ACPI_SUCCESS (status)) {
 		status = acpi_ex_resolve_node_to_value (&resolved_node, NULL);
 		/*
-		 * If Acpi_ex_resolve_node_to_value() succeeded, the return value was
-		 * placed in Resolved_node.
+		 * If acpi_ex_resolve_node_to_value() succeeded, the return value was
+		 * placed in resolved_node.
 		 */
 		acpi_ex_exit_interpreter ();
 
diff -Nru a/drivers/acpi/namespace/nsinit.c b/drivers/acpi/namespace/nsinit.c
--- a/drivers/acpi/namespace/nsinit.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/acpi/namespace/nsinit.c	Mon Dec 23 21:21:53 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: nsinit - namespace initialization
- *              $Revision: 54 $
  *
  *****************************************************************************/
 
@@ -35,7 +34,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_initialize_objects
+ * FUNCTION:    acpi_ns_initialize_objects
  *
  * PARAMETERS:  None
  *
@@ -54,7 +53,7 @@
 	acpi_init_walk_info     info;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_initialize_objects");
+	ACPI_FUNCTION_TRACE ("ns_initialize_objects");
 
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
@@ -71,7 +70,7 @@
 			  ACPI_UINT32_MAX, acpi_ns_init_one_object,
 			  &info, NULL);
 	if (ACPI_FAILURE (status)) {
-		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Walk_namespace failed! %s\n",
+		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "walk_namespace failed! %s\n",
 			acpi_format_exception (status)));
 	}
 
@@ -93,7 +92,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_initialize_devices
+ * FUNCTION:    acpi_ns_initialize_devices
  *
  * PARAMETERS:  None
  *
@@ -115,7 +114,7 @@
 	acpi_device_walk_info   info;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_initialize_devices");
+	ACPI_FUNCTION_TRACE ("ns_initialize_devices");
 
 
 	/* Init counters */
@@ -132,7 +131,7 @@
 			  ACPI_UINT32_MAX, FALSE, acpi_ns_init_one_device, &info, NULL);
 
 	if (ACPI_FAILURE (status)) {
-		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Walk_namespace failed! %s\n",
+		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "walk_namespace failed! %s\n",
 			acpi_format_exception (status)));
 	}
 
@@ -146,16 +145,16 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_init_one_object
+ * FUNCTION:    acpi_ns_init_one_object
  *
- * PARAMETERS:  Obj_handle      - Node
+ * PARAMETERS:  obj_handle      - Node
  *              Level           - Current nesting level
  *              Context         - Points to a init info struct
- *              Return_value    - Not used
+ *              return_value    - Not used
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Callback from Acpi_walk_namespace. Invoked for every object
+ * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
  *              within the  namespace.
  *
  *              Currently, the only objects that require initialization are:
@@ -178,7 +177,7 @@
 	acpi_operand_object     *obj_desc;
 
 
-	ACPI_FUNCTION_NAME ("Ns_init_one_object");
+	ACPI_FUNCTION_NAME ("ns_init_one_object");
 
 
 	info->object_count++;
@@ -292,7 +291,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_init_one_device
+ * FUNCTION:    acpi_ns_init_one_device
  *
  * PARAMETERS:  acpi_walk_callback
  *
@@ -317,7 +316,7 @@
 	acpi_device_walk_info  *info = (acpi_device_walk_info *) context;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_init_one_device");
+	ACPI_FUNCTION_TRACE ("ns_init_one_device");
 
 
 	if ((acpi_dbg_level <= ACPI_LV_ALL_EXCEPTIONS) && (!(acpi_dbg_level & ACPI_LV_INFO))) {
diff -Nru a/drivers/acpi/namespace/nsload.c b/drivers/acpi/namespace/nsload.c
--- a/drivers/acpi/namespace/nsload.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/acpi/namespace/nsload.c	Mon Dec 23 21:22:00 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: nsload - namespace loading/expanding/contracting procedures
- *              $Revision: 61 $
  *
  *****************************************************************************/
 
@@ -26,7 +25,6 @@
 
 #include "acpi.h"
 #include "acnamesp.h"
-#include "acparser.h"
 #include "acdispat.h"
 
 
@@ -38,9 +36,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_load_table
+ * FUNCTION:    acpi_ns_load_table
  *
- * PARAMETERS:  Table_desc      - Descriptor for table to be loaded
+ * PARAMETERS:  table_desc      - Descriptor for table to be loaded
  *              Node            - Owning NS node
  *
  * RETURN:      Status
@@ -57,7 +55,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_load_table");
+	ACPI_FUNCTION_TRACE ("ns_load_table");
 
 
 	/* Check if table contains valid AML (must be DSDT, PSDT, SSDT, etc.) */
@@ -125,9 +123,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_load_table_by_type
+ * FUNCTION:    acpi_ns_load_table_by_type
  *
- * PARAMETERS:  Table_type          - Id of the table type to load
+ * PARAMETERS:  table_type          - Id of the table type to load
  *
  * RETURN:      Status
  *
@@ -146,7 +144,7 @@
 	acpi_table_desc         *table_desc;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_load_table_by_type");
+	ACPI_FUNCTION_TRACE ("ns_load_table_by_type");
 
 
 	status = acpi_ut_acquire_mutex (ACPI_MTX_TABLES);
@@ -253,7 +251,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_load_namespace
+ * FUNCTION:    acpi_load_namespace
  *
  * PARAMETERS:  None
  *
@@ -271,7 +269,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_load_name_space");
+	ACPI_FUNCTION_TRACE ("acpi_load_name_space");
 
 
 	/* There must be at least a DSDT installed */
@@ -305,9 +303,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_delete_subtree
+ * FUNCTION:    acpi_ns_delete_subtree
  *
- * PARAMETERS:  Start_handle        - Handle in namespace where search begins
+ * PARAMETERS:  start_handle        - Handle in namespace where search begins
  *
  * RETURNS      Status
  *
@@ -331,7 +329,7 @@
 	u32                     level;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_delete_subtree");
+	ACPI_FUNCTION_TRACE ("ns_delete_subtree");
 
 
 	parent_handle = start_handle;
@@ -395,7 +393,7 @@
 
 /*******************************************************************************
  *
- *  FUNCTION:       Acpi_ns_unload_name_space
+ *  FUNCTION:       acpi_ns_unload_name_space
  *
  *  PARAMETERS:     Handle          - Root of namespace subtree to be deleted
  *
@@ -414,7 +412,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_unload_name_space");
+	ACPI_FUNCTION_TRACE ("ns_unload_name_space");
 
 
 	/* Parameter validation */
diff -Nru a/drivers/acpi/namespace/nsnames.c b/drivers/acpi/namespace/nsnames.c
--- a/drivers/acpi/namespace/nsnames.c	Mon Dec 23 21:22:02 2002
+++ b/drivers/acpi/namespace/nsnames.c	Mon Dec 23 21:22:02 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: nsnames - Name manipulation and search
- *              $Revision: 81 $
  *
  ******************************************************************************/
 
@@ -35,13 +34,13 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_build_external_path
+ * FUNCTION:    acpi_ns_build_external_path
  *
  * PARAMETERS:  Node            - NS node whose pathname is needed
  *              Size            - Size of the pathname
- *              *Name_buffer    - Where to return the pathname
+ *              *name_buffer    - Where to return the pathname
  *
- * RETURN:      Places the pathname into the Name_buffer, in external format
+ * RETURN:      Places the pathname into the name_buffer, in external format
  *              (name segments separated by path separators)
  *
  * DESCRIPTION: Generate a full pathaname
@@ -51,14 +50,14 @@
 void
 acpi_ns_build_external_path (
 	acpi_namespace_node     *node,
-	ACPI_SIZE               size,
+	acpi_size               size,
 	char                    *name_buffer)
 {
-	ACPI_SIZE               index;
+	acpi_size               index;
 	acpi_namespace_node     *parent_node;
 
 
-	ACPI_FUNCTION_NAME ("Ns_build_external_path");
+	ACPI_FUNCTION_NAME ("ns_build_external_path");
 
 
 	/* Special case for root */
@@ -106,7 +105,7 @@
 #ifdef ACPI_DEBUG_OUTPUT
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_get_external_pathname
+ * FUNCTION:    acpi_ns_get_external_pathname
  *
  * PARAMETERS:  Node            - NS node whose pathname is needed
  *
@@ -114,7 +113,7 @@
  *              the node, In external format (name segments separated by path
  *              separators.)
  *
- * DESCRIPTION: Used for debug printing in Acpi_ns_search_table().
+ * DESCRIPTION: Used for debug printing in acpi_ns_search_table().
  *
  ******************************************************************************/
 
@@ -123,10 +122,10 @@
 	acpi_namespace_node     *node)
 {
 	char                    *name_buffer;
-	ACPI_SIZE               size;
+	acpi_size               size;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ns_get_external_pathname", node);
+	ACPI_FUNCTION_TRACE_PTR ("ns_get_external_pathname", node);
 
 
 	/* Calculate required buffer size based on depth below root */
@@ -137,7 +136,7 @@
 
 	name_buffer = ACPI_MEM_CALLOCATE (size);
 	if (!name_buffer) {
-		ACPI_REPORT_ERROR (("Ns_get_table_pathname: allocation failure\n"));
+		ACPI_REPORT_ERROR (("ns_get_table_pathname: allocation failure\n"));
 		return_PTR (NULL);
 	}
 
@@ -151,7 +150,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_get_pathname_length
+ * FUNCTION:    acpi_ns_get_pathname_length
  *
  * PARAMETERS:  Node        - Namespace node
  *
@@ -161,11 +160,11 @@
  *
  ******************************************************************************/
 
-ACPI_SIZE
+acpi_size
 acpi_ns_get_pathname_length (
 	acpi_namespace_node     *node)
 {
-	ACPI_SIZE               size;
+	acpi_size               size;
 	acpi_namespace_node     *next_node;
 
 
@@ -190,9 +189,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_handle_to_pathname
+ * FUNCTION:    acpi_ns_handle_to_pathname
  *
- * PARAMETERS:  Target_handle           - Handle of named object whose name is
+ * PARAMETERS:  target_handle           - Handle of named object whose name is
  *                                        to be found
  *              Buffer                  - Where the pathname is returned
  *
@@ -209,10 +208,10 @@
 {
 	acpi_status             status;
 	acpi_namespace_node     *node;
-	ACPI_SIZE               required_size;
+	acpi_size               required_size;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ns_handle_to_pathname", target_handle);
+	ACPI_FUNCTION_TRACE_PTR ("ns_handle_to_pathname", target_handle);
 
 
 	node = acpi_ns_map_handle_to_node (target_handle);
diff -Nru a/drivers/acpi/namespace/nsobject.c b/drivers/acpi/namespace/nsobject.c
--- a/drivers/acpi/namespace/nsobject.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/acpi/namespace/nsobject.c	Mon Dec 23 21:21:53 2002
@@ -2,7 +2,6 @@
  *
  * Module Name: nsobject - Utilities for objects attached to namespace
  *                         table entries
- *              $Revision: 86 $
  *
  ******************************************************************************/
 
@@ -35,7 +34,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_attach_object
+ * FUNCTION:    acpi_ns_attach_object
  *
  * PARAMETERS:  Node                - Parent Node
  *              Object              - Object to be attached
@@ -63,7 +62,7 @@
 	acpi_object_type        object_type = ACPI_TYPE_ANY;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_attach_object");
+	ACPI_FUNCTION_TRACE ("ns_attach_object");
 
 
 	/*
@@ -72,28 +71,28 @@
 	if (!node) {
 		/* Invalid handle */
 
-		ACPI_REPORT_ERROR (("Ns_attach_object: Null Named_obj handle\n"));
+		ACPI_REPORT_ERROR (("ns_attach_object: Null named_obj handle\n"));
 		return_ACPI_STATUS (AE_BAD_PARAMETER);
 	}
 
 	if (!object && (ACPI_TYPE_ANY != type)) {
 		/* Null object */
 
-		ACPI_REPORT_ERROR (("Ns_attach_object: Null object, but type not ACPI_TYPE_ANY\n"));
+		ACPI_REPORT_ERROR (("ns_attach_object: Null object, but type not ACPI_TYPE_ANY\n"));
 		return_ACPI_STATUS (AE_BAD_PARAMETER);
 	}
 
 	if (ACPI_GET_DESCRIPTOR_TYPE (node) != ACPI_DESC_TYPE_NAMED) {
 		/* Not a name handle */
 
-		ACPI_REPORT_ERROR (("Ns_attach_object: Invalid handle\n"));
+		ACPI_REPORT_ERROR (("ns_attach_object: Invalid handle\n"));
 		return_ACPI_STATUS (AE_BAD_PARAMETER);
 	}
 
 	/* Check if this object is already attached */
 
 	if (node->object == object) {
-		ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj %p already installed in Name_obj %p\n",
+		ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj %p already installed in name_obj %p\n",
 			object, node));
 
 		return_ACPI_STATUS (AE_OK);
@@ -171,7 +170,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_detach_object
+ * FUNCTION:    acpi_ns_detach_object
  *
  * PARAMETERS:  Node           - An node whose object will be detached
  *
@@ -190,7 +189,7 @@
 	acpi_operand_object     *obj_desc;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_detach_object");
+	ACPI_FUNCTION_TRACE ("ns_detach_object");
 
 
 	obj_desc = node->object;
@@ -227,7 +226,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_get_attached_object
+ * FUNCTION:    acpi_ns_get_attached_object
  *
  * PARAMETERS:  Node             - Parent Node to be examined
  *
@@ -242,7 +241,7 @@
 acpi_ns_get_attached_object (
 	acpi_namespace_node     *node)
 {
-	ACPI_FUNCTION_TRACE_PTR ("Ns_get_attached_object", node);
+	ACPI_FUNCTION_TRACE_PTR ("ns_get_attached_object", node);
 
 
 	if (!node) {
@@ -263,7 +262,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_get_secondary_object
+ * FUNCTION:    acpi_ns_get_secondary_object
  *
  * PARAMETERS:  Node             - Parent Node to be examined
  *
@@ -278,7 +277,7 @@
 acpi_ns_get_secondary_object (
 	acpi_operand_object     *obj_desc)
 {
-	ACPI_FUNCTION_TRACE_PTR ("Ns_get_secondary_object", obj_desc);
+	ACPI_FUNCTION_TRACE_PTR ("ns_get_secondary_object", obj_desc);
 
 
 	if ((!obj_desc)                                               ||
@@ -294,7 +293,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_attach_data
+ * FUNCTION:    acpi_ns_attach_data
  *
  * PARAMETERS:  Node            - Namespace node
  *              Handler         - Handler to be associated with the data
@@ -309,7 +308,7 @@
 acpi_status
 acpi_ns_attach_data (
 	acpi_namespace_node     *node,
-	ACPI_OBJECT_HANDLER     handler,
+	acpi_object_handler     handler,
 	void                    *data)
 {
 	acpi_operand_object     *prev_obj_desc;
@@ -356,7 +355,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_detach_data
+ * FUNCTION:    acpi_ns_detach_data
  *
  * PARAMETERS:  Node            - Namespace node
  *              Handler         - Handler associated with the data
@@ -371,7 +370,7 @@
 acpi_status
 acpi_ns_detach_data (
 	acpi_namespace_node     *node,
-	ACPI_OBJECT_HANDLER     handler)
+	acpi_object_handler     handler)
 {
 	acpi_operand_object     *obj_desc;
 	acpi_operand_object     *prev_obj_desc;
@@ -403,7 +402,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_get_attached_data
+ * FUNCTION:    acpi_ns_get_attached_data
  *
  * PARAMETERS:  Node            - Namespace node
  *              Handler         - Handler associated with the data
@@ -419,7 +418,7 @@
 acpi_status
 acpi_ns_get_attached_data (
 	acpi_namespace_node     *node,
-	ACPI_OBJECT_HANDLER     handler,
+	acpi_object_handler     handler,
 	void                    **data)
 {
 	acpi_operand_object     *obj_desc;
diff -Nru a/drivers/acpi/namespace/nsparse.c b/drivers/acpi/namespace/nsparse.c
--- a/drivers/acpi/namespace/nsparse.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/namespace/nsparse.c	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: nsparse - namespace interface to AML parser
- *              $Revision: 2 $
  *
  *****************************************************************************/
 
@@ -36,10 +35,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Ns_one_complete_parse
+ * FUNCTION:    ns_one_complete_parse
  *
- * PARAMETERS:  Pass_number             - 1 or 2
- *              Table_desc              - The table to be parsed.
+ * PARAMETERS:  pass_number             - 1 or 2
+ *              table_desc              - The table to be parsed.
  *
  * RETURN:      Status
  *
@@ -57,7 +56,7 @@
 	acpi_walk_state         *walk_state;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_one_complete_parse");
+	ACPI_FUNCTION_TRACE ("ns_one_complete_parse");
 
 
 	/* Create and init a Root Node */
@@ -96,10 +95,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_parse_table
+ * FUNCTION:    acpi_ns_parse_table
  *
- * PARAMETERS:  Table_desc      - An ACPI table descriptor for table to parse
- *              Start_node      - Where to enter the table into the namespace
+ * PARAMETERS:  table_desc      - An ACPI table descriptor for table to parse
+ *              start_node      - Where to enter the table into the namespace
  *
  * RETURN:      Status
  *
@@ -115,7 +114,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_parse_table");
+	ACPI_FUNCTION_TRACE ("ns_parse_table");
 
 
 	/*
diff -Nru a/drivers/acpi/namespace/nssearch.c b/drivers/acpi/namespace/nssearch.c
--- a/drivers/acpi/namespace/nssearch.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/acpi/namespace/nssearch.c	Mon Dec 23 21:22:00 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: nssearch - Namespace search
- *              $Revision: 94 $
  *
  ******************************************************************************/
 
@@ -34,12 +33,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_search_node
+ * FUNCTION:    acpi_ns_search_node
  *
- * PARAMETERS:  *Target_name        - Ascii ACPI name to search for
+ * PARAMETERS:  *target_name        - Ascii ACPI name to search for
  *              *Node               - Starting node where search will begin
  *              Type                - Object type to match
- *              **Return_node       - Where the matched Named obj is returned
+ *              **return_node       - Where the matched Named obj is returned
  *
  * RETURN:      Status
  *
@@ -69,7 +68,7 @@
 	acpi_namespace_node     *next_node;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_search_node");
+	ACPI_FUNCTION_TRACE ("ns_search_node");
 
 
 #ifdef ACPI_DEBUG_OUTPUT
@@ -132,18 +131,18 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_search_parent_tree
+ * FUNCTION:    acpi_ns_search_parent_tree
  *
- * PARAMETERS:  *Target_name        - Ascii ACPI name to search for
+ * PARAMETERS:  *target_name        - Ascii ACPI name to search for
  *              *Node               - Starting node where search will begin
  *              Type                - Object type to match
- *              **Return_node       - Where the matched Named Obj is returned
+ *              **return_node       - Where the matched Named Obj is returned
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Called when a name has not been found in the current namespace
  *              level.  Before adding it or giving up, ACPI scope rules require
- *              searching enclosing scopes in cases identified by Acpi_ns_local().
+ *              searching enclosing scopes in cases identified by acpi_ns_local().
  *
  *              "A name is located by finding the matching name in the current
  *              name space, and then in the parent name space. If the parent
@@ -166,7 +165,7 @@
 	acpi_namespace_node     *parent_node;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_search_parent_tree");
+	ACPI_FUNCTION_TRACE ("ns_search_parent_tree");
 
 
 	parent_node = acpi_ns_get_parent_node (node);
@@ -223,16 +222,16 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_search_and_enter
+ * FUNCTION:    acpi_ns_search_and_enter
  *
- * PARAMETERS:  Target_name         - Ascii ACPI name to search for (4 chars)
- *              Walk_state          - Current state of the walk
+ * PARAMETERS:  target_name         - Ascii ACPI name to search for (4 chars)
+ *              walk_state          - Current state of the walk
  *              *Node               - Starting node where search will begin
- *              Interpreter_mode    - Add names only in ACPI_MODE_LOAD_PASS_x.
+ *              interpreter_mode    - Add names only in ACPI_MODE_LOAD_PASS_x.
  *                                    Otherwise,search only.
  *              Type                - Object type to match
  *              Flags               - Flags describing the search restrictions
- *              **Return_node       - Where the Node is returned
+ *              **return_node       - Where the Node is returned
  *
  * RETURN:      Status
  *
@@ -260,23 +259,23 @@
 	acpi_namespace_node     *new_node;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_search_and_enter");
+	ACPI_FUNCTION_TRACE ("ns_search_and_enter");
 
 
 	/* Parameter validation */
 
 	if (!node || !target_name || !return_node) {
-		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null param: Node %p Name %X Return_node %p\n",
+		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null param: Node %p Name %X return_node %p\n",
 			node, target_name, return_node));
 
-		ACPI_REPORT_ERROR (("Ns_search_and_enter: Null parameter\n"));
+		ACPI_REPORT_ERROR (("ns_search_and_enter: Null parameter\n"));
 		return_ACPI_STATUS (AE_BAD_PARAMETER);
 	}
 
 	/* Name must consist of printable characters */
 
 	if (!acpi_ut_valid_acpi_name (target_name)) {
-		ACPI_REPORT_ERROR (("Ns_search_and_enter: Bad character in ACPI Name: %X\n",
+		ACPI_REPORT_ERROR (("ns_search_and_enter: Bad character in ACPI Name: %X\n",
 			target_name));
 		return_ACPI_STATUS (AE_BAD_CHARACTER);
 	}
diff -Nru a/drivers/acpi/namespace/nsutils.c b/drivers/acpi/namespace/nsutils.c
--- a/drivers/acpi/namespace/nsutils.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/acpi/namespace/nsutils.c	Mon Dec 23 21:21:55 2002
@@ -2,7 +2,6 @@
  *
  * Module Name: nsutils - Utilities for accessing ACPI namespace, accessing
  *                        parents and siblings and Scope manipulation
- *              $Revision: 120 $
  *
  *****************************************************************************/
 
@@ -36,11 +35,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_report_error
+ * FUNCTION:    acpi_ns_report_error
  *
- * PARAMETERS:  Module_name         - Caller's module name (for error output)
- *              Line_number         - Caller's line number (for error output)
- *              Component_id        - Caller's component ID (for error output)
+ * PARAMETERS:  module_name         - Caller's module name (for error output)
+ *              line_number         - Caller's line number (for error output)
+ *              component_id        - Caller's component ID (for error output)
  *              Message             - Error message to use on failure
  *
  * RETURN:      None
@@ -88,11 +87,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_report_method_error
+ * FUNCTION:    acpi_ns_report_method_error
  *
- * PARAMETERS:  Module_name         - Caller's module name (for error output)
- *              Line_number         - Caller's line number (for error output)
- *              Component_id        - Caller's component ID (for error output)
+ * PARAMETERS:  module_name         - Caller's module name (for error output)
+ *              line_number         - Caller's line number (for error output)
+ *              component_id        - Caller's component ID (for error output)
  *              Message             - Error message to use on failure
  *
  * RETURN:      None
@@ -118,7 +117,7 @@
 	if (path) {
 		status = acpi_ns_get_node_by_path (path, prefix_node, ACPI_NS_NO_UPSEARCH, &node);
 		if (ACPI_FAILURE (status)) {
-			acpi_os_printf ("Report_method_error: Could not get node\n");
+			acpi_os_printf ("report_method_error: Could not get node\n");
 			return;
 		}
 	}
@@ -131,7 +130,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_print_node_pathname
+ * FUNCTION:    acpi_ns_print_node_pathname
  *
  * PARAMETERS:  Node                - Object
  *              Msg                 - Prefix message
@@ -164,7 +163,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_valid_root_prefix
+ * FUNCTION:    acpi_ns_valid_root_prefix
  *
  * PARAMETERS:  Prefix          - Character to be checked
  *
@@ -185,7 +184,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_valid_path_separator
+ * FUNCTION:    acpi_ns_valid_path_separator
  *
  * PARAMETERS:  Sep              - Character to be checked
  *
@@ -206,7 +205,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_get_type
+ * FUNCTION:    acpi_ns_get_type
  *
  * PARAMETERS:  Handle              - Parent Node to be examined
  *
@@ -218,11 +217,11 @@
 acpi_ns_get_type (
 	acpi_namespace_node     *node)
 {
-	ACPI_FUNCTION_TRACE ("Ns_get_type");
+	ACPI_FUNCTION_TRACE ("ns_get_type");
 
 
 	if (!node) {
-		ACPI_REPORT_WARNING (("Ns_get_type: Null Node ptr"));
+		ACPI_REPORT_WARNING (("ns_get_type: Null Node ptr"));
 		return_VALUE (ACPI_TYPE_ANY);
 	}
 
@@ -232,7 +231,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_local
+ * FUNCTION:    acpi_ns_local
  *
  * PARAMETERS:  Type            - A namespace object type
  *
@@ -245,13 +244,13 @@
 acpi_ns_local (
 	acpi_object_type        type)
 {
-	ACPI_FUNCTION_TRACE ("Ns_local");
+	ACPI_FUNCTION_TRACE ("ns_local");
 
 
 	if (!acpi_ut_valid_object_type (type)) {
 		/* Type code out of range  */
 
-		ACPI_REPORT_WARNING (("Ns_local: Invalid Object Type\n"));
+		ACPI_REPORT_WARNING (("ns_local: Invalid Object Type\n"));
 		return_VALUE (ACPI_NS_NORMAL);
 	}
 
@@ -261,7 +260,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_get_internal_name_length
+ * FUNCTION:    acpi_ns_get_internal_name_length
  *
  * PARAMETERS:  Info            - Info struct initialized with the
  *                                external name pointer.
@@ -291,11 +290,11 @@
 
 	/*
 	 * For the internal name, the required length is 4 bytes
-	 * per segment, plus 1 each for Root_prefix, Multi_name_prefix_op,
+	 * per segment, plus 1 each for root_prefix, multi_name_prefix_op,
 	 * segment count, trailing null (which is not really needed,
 	 * but no there's harm in putting it there)
 	 *
-	 * strlen() + 1 covers the first Name_seg, which has no
+	 * strlen() + 1 covers the first name_seg, which has no
 	 * path separator
 	 */
 	if (acpi_ns_valid_root_prefix (next_external_char[0])) {
@@ -336,7 +335,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_build_internal_name
+ * FUNCTION:    acpi_ns_build_internal_name
  *
  * PARAMETERS:  Info            - Info struct fully initialized
  *
@@ -355,10 +354,10 @@
 	char                    *internal_name = info->internal_name;
 	char                    *external_name = info->next_external_char;
 	char                    *result = NULL;
-	NATIVE_UINT             i;
+	acpi_native_uint        i;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_build_internal_name");
+	ACPI_FUNCTION_TRACE ("ns_build_internal_name");
 
 
 	/* Setup the correct prefixes, counts, and pointers */
@@ -396,12 +395,12 @@
 		}
 		else if (num_segments == 2) {
 			internal_name[i] = AML_DUAL_NAME_PREFIX;
-			result = &internal_name[i+1];
+			result = &internal_name[(acpi_native_uint) (i+1)];
 		}
 		else {
 			internal_name[i] = AML_MULTI_NAME_PREFIX_OP;
-			internal_name[i+1] = (char) num_segments;
-			result = &internal_name[i+2];
+			internal_name[(acpi_native_uint) (i+1)] = (char) num_segments;
+			result = &internal_name[(acpi_native_uint) (i+2)];
 		}
 	}
 
@@ -455,9 +454,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_internalize_name
+ * FUNCTION:    acpi_ns_internalize_name
  *
- * PARAMETERS:  *External_name          - External representation of name
+ * PARAMETERS:  *external_name          - External representation of name
  *              **Converted Name        - Where to return the resulting
  *                                        internal represention of the name
  *
@@ -478,7 +477,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_internalize_name");
+	ACPI_FUNCTION_TRACE ("ns_internalize_name");
 
 
 	if ((!external_name)     ||
@@ -515,10 +514,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_externalize_name
+ * FUNCTION:    acpi_ns_externalize_name
  *
- * PARAMETERS:  *Internal_name         - Internal representation of name
- *              **Converted_name       - Where to return the resulting
+ * PARAMETERS:  *internal_name         - Internal representation of name
+ *              **converted_name       - Where to return the resulting
  *                                       external representation of name
  *
  * RETURN:      Status
@@ -535,15 +534,15 @@
 	u32                     *converted_name_length,
 	char                    **converted_name)
 {
-	NATIVE_UINT_MIN32       prefix_length = 0;
-	NATIVE_UINT_MIN32       names_index = 0;
-	NATIVE_UINT_MIN32       num_segments = 0;
-	NATIVE_UINT_MIN32       i = 0;
-	NATIVE_UINT_MIN32       j = 0;
-	NATIVE_UINT_MIN32       required_length;
+	acpi_native_uint        names_index = 0;
+	acpi_native_uint        num_segments = 0;
+	acpi_native_uint        required_length;
+	acpi_native_uint        prefix_length = 0;
+	acpi_native_uint        i = 0;
+	acpi_native_uint        j = 0;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_externalize_name");
+	ACPI_FUNCTION_TRACE ("ns_externalize_name");
 
 
 	if (!internal_name_length   ||
@@ -591,7 +590,7 @@
 			/* <count> 4-byte names */
 
 			names_index = prefix_length + 2;
-			num_segments = (u32) (u8) internal_name[prefix_length + 1];
+			num_segments = (u32) (u8) internal_name[(acpi_native_uint) (prefix_length + 1)];
 			break;
 
 		case AML_DUAL_NAME_PREFIX:
@@ -604,7 +603,7 @@
 
 		case 0:
 
-			/* Null_name */
+			/* null_name */
 
 			names_index = 0;
 			num_segments = 0;
@@ -621,7 +620,7 @@
 	}
 
 	/*
-	 * Calculate the length of Converted_name, which equals the length
+	 * Calculate the length of converted_name, which equals the length
 	 * of the prefix, length of all object names, length of any required
 	 * punctuation ('.') between object names, plus the NULL terminator.
 	 */
@@ -630,15 +629,15 @@
 
 	/*
 	 * Check to see if we're still in bounds.  If not, there's a problem
-	 * with Internal_name (invalid format).
+	 * with internal_name (invalid format).
 	 */
 	if (required_length > internal_name_length) {
-		ACPI_REPORT_ERROR (("Ns_externalize_name: Invalid internal name\n"));
+		ACPI_REPORT_ERROR (("ns_externalize_name: Invalid internal name\n"));
 		return_ACPI_STATUS (AE_BAD_PATHNAME);
 	}
 
 	/*
-	 * Build Converted_name...
+	 * Build converted_name...
 	 */
 	*converted_name = ACPI_MEM_CALLOCATE (required_length);
 	if (!(*converted_name)) {
@@ -674,7 +673,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_map_handle_to_node
+ * FUNCTION:    acpi_ns_map_handle_to_node
  *
  * PARAMETERS:  Handle          - Handle to be converted to an Node
  *
@@ -718,7 +717,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_convert_entry_to_handle
+ * FUNCTION:    acpi_ns_convert_entry_to_handle
  *
  * PARAMETERS:  Node          - Node to be converted to a Handle
  *
@@ -747,7 +746,7 @@
 		return (NULL);
 	}
 
-	if (Node == Acpi_gbl_Root_node)
+	if (Node == acpi_gbl_root_node)
 	{
 		return (ACPI_ROOT_OBJECT);
 	}
@@ -760,7 +759,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_terminate
+ * FUNCTION:    acpi_ns_terminate
  *
  * PARAMETERS:  none
  *
@@ -777,7 +776,7 @@
 	acpi_namespace_node     *this_node;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_terminate");
+	ACPI_FUNCTION_TRACE ("ns_terminate");
 
 
 	this_node = acpi_gbl_root_node;
@@ -814,7 +813,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_opens_scope
+ * FUNCTION:    acpi_ns_opens_scope
  *
  * PARAMETERS:  Type        - A valid namespace type
  *
@@ -827,13 +826,13 @@
 acpi_ns_opens_scope (
 	acpi_object_type        type)
 {
-	ACPI_FUNCTION_TRACE_STR ("Ns_opens_scope", acpi_ut_get_type_name (type));
+	ACPI_FUNCTION_TRACE_STR ("ns_opens_scope", acpi_ut_get_type_name (type));
 
 
 	if (!acpi_ut_valid_object_type (type)) {
 		/* type code out of range  */
 
-		ACPI_REPORT_WARNING (("Ns_opens_scope: Invalid Object Type %X\n", type));
+		ACPI_REPORT_WARNING (("ns_opens_scope: Invalid Object Type %X\n", type));
 		return_VALUE (ACPI_NS_NORMAL);
 	}
 
@@ -843,18 +842,18 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_get_node_by_path
+ * FUNCTION:    acpi_ns_get_node_by_path
  *
  * PARAMETERS:  *Pathname   - Name to be found, in external (ASL) format. The
  *                            \ (backslash) and ^ (carat) prefixes, and the
  *                            . (period) to separate segments are supported.
- *              Start_node  - Root of subtree to be searched, or NS_ALL for the
+ *              start_node  - Root of subtree to be searched, or NS_ALL for the
  *                            root of the name space.  If Name is fully
  *                            qualified (first s8 is '\'), the passed value
  *                            of Scope will not be accessed.
  *              Flags       - Used to indicate whether to perform upsearch or
  *                            not.
- *              Return_node - Where the Node is returned
+ *              return_node - Where the Node is returned
  *
  * DESCRIPTION: Look up a name relative to a given scope and return the
  *              corresponding Node.  NOTE: Scope can be null.
@@ -875,7 +874,7 @@
 	char                    *internal_path = NULL;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ns_get_node_by_path", pathname);
+	ACPI_FUNCTION_TRACE_PTR ("ns_get_node_by_path", pathname);
 
 
 	if (pathname) {
@@ -922,9 +921,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_find_parent_name
+ * FUNCTION:    acpi_ns_find_parent_name
  *
- * PARAMETERS:  *Child_node            - Named Obj whose name is to be found
+ * PARAMETERS:  *child_node            - Named Obj whose name is to be found
  *
  * RETURN:      The ACPI name
  *
@@ -941,7 +940,7 @@
 	acpi_namespace_node     *parent_node;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_find_parent_name");
+	ACPI_FUNCTION_TRACE ("ns_find_parent_name");
 
 
 	if (child_node) {
@@ -968,7 +967,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_get_parent_node
+ * FUNCTION:    acpi_ns_get_parent_node
  *
  * PARAMETERS:  Node       - Current table entry
  *
@@ -1008,7 +1007,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_get_next_valid_node
+ * FUNCTION:    acpi_ns_get_next_valid_node
  *
  * PARAMETERS:  Node       - Current table entry
  *
diff -Nru a/drivers/acpi/namespace/nswalk.c b/drivers/acpi/namespace/nswalk.c
--- a/drivers/acpi/namespace/nswalk.c	Mon Dec 23 21:22:02 2002
+++ b/drivers/acpi/namespace/nswalk.c	Mon Dec 23 21:22:02 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: nswalk - Functions for walking the ACPI namespace
- *              $Revision: 33 $
  *
  *****************************************************************************/
 
@@ -34,12 +33,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_get_next_node
+ * FUNCTION:    acpi_ns_get_next_node
  *
  * PARAMETERS:  Type                - Type of node to be searched for
- *              Parent_node         - Parent node whose children we are
+ *              parent_node         - Parent node whose children we are
  *                                     getting
- *              Child_node          - Previous child that was found.
+ *              child_node          - Previous child that was found.
  *                                    The NEXT child will be returned
  *
  * RETURN:      acpi_namespace_node - Pointer to the NEXT child or NULL if
@@ -80,7 +79,7 @@
 	/* If any type is OK, we are done */
 
 	if (type == ACPI_TYPE_ANY) {
-		/* Next_node is NULL if we are at the end-of-list */
+		/* next_node is NULL if we are at the end-of-list */
 
 		return (next_node);
 	}
@@ -107,22 +106,22 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_walk_namespace
+ * FUNCTION:    acpi_ns_walk_namespace
  *
  * PARAMETERS:  Type                - acpi_object_type to search for
- *              Start_node          - Handle in namespace where search begins
- *              Max_depth           - Depth to which search is to reach
- *              Unlock_before_callback- Whether to unlock the NS before invoking
+ *              start_node          - Handle in namespace where search begins
+ *              max_depth           - Depth to which search is to reach
+ *              unlock_before_callback- Whether to unlock the NS before invoking
  *                                    the callback routine
- *              User_function       - Called when an object of "Type" is found
+ *              user_function       - Called when an object of "Type" is found
  *              Context             - Passed to user function
- *              Return_value        - from the User_function if terminated early.
+ *              return_value        - from the user_function if terminated early.
  *                                    Otherwise, returns NULL.
  * RETURNS:     Status
  *
  * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
- *              starting (and ending) at the node specified by Start_handle.
- *              The User_function is called whenever a node that matches
+ *              starting (and ending) at the node specified by start_handle.
+ *              The user_function is called whenever a node that matches
  *              the type parameter is found.  If the user function returns
  *              a non-zero value, the search is terminated immediately and this
  *              value is returned to the caller.
@@ -152,7 +151,7 @@
 	u32                     level;
 
 
-	ACPI_FUNCTION_TRACE ("Ns_walk_namespace");
+	ACPI_FUNCTION_TRACE ("ns_walk_namespace");
 
 
 	/* Special case for the namespace Root Node */
@@ -171,7 +170,7 @@
 	/*
 	 * Traverse the tree of nodes until we bubble back up to where we
 	 * started. When Level is zero, the loop is done because we have
-	 * bubbled up to (and passed) the original parent handle (Start_entry)
+	 * bubbled up to (and passed) the original parent handle (start_entry)
 	 */
 	while (level > 0) {
 		/* Get the next node in this scope.  Null if not found */
@@ -252,7 +251,7 @@
 		}
 		else {
 			/*
-			 * No more children of this node (Acpi_ns_get_next_node
+			 * No more children of this node (acpi_ns_get_next_node
 			 * failed), go back upwards in the namespace tree to
 			 * the node's parent.
 			 */
diff -Nru a/drivers/acpi/namespace/nsxfeval.c b/drivers/acpi/namespace/nsxfeval.c
--- a/drivers/acpi/namespace/nsxfeval.c	Mon Dec 23 21:22:01 2002
+++ b/drivers/acpi/namespace/nsxfeval.c	Mon Dec 23 21:22:01 2002
@@ -2,7 +2,6 @@
  *
  * Module Name: nsxfeval - Public interfaces to the ACPI subsystem
  *                         ACPI Object evaluation interfaces
- *              $Revision: 6 $
  *
  ******************************************************************************/
 
@@ -35,16 +34,16 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_evaluate_object_typed
+ * FUNCTION:    acpi_evaluate_object_typed
  *
  * PARAMETERS:  Handle              - Object handle (optional)
  *              *Pathname           - Object pathname (optional)
- *              **External_params   - List of parameters to pass to method,
+ *              **external_params   - List of parameters to pass to method,
  *                                    terminated by NULL.  May be NULL
  *                                    if no parameters are being passed.
- *              *Return_buffer      - Where to put method's return value (if
+ *              *return_buffer      - Where to put method's return value (if
  *                                    any).  If NULL, no value is returned.
- *              Return_type         - Expected type of return object
+ *              return_type         - Expected type of return object
  *
  * RETURN:      Status
  *
@@ -66,7 +65,7 @@
 	u8                      must_free = FALSE;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_evaluate_object_typed");
+	ACPI_FUNCTION_TRACE ("acpi_evaluate_object_typed");
 
 
 	/* Return buffer must be valid */
@@ -101,7 +100,7 @@
 		return_ACPI_STATUS (AE_NULL_OBJECT);
 	}
 
-	/* Examine the object type returned from Evaluate_object */
+	/* Examine the object type returned from evaluate_object */
 
 	if (((acpi_object *) return_buffer->pointer)->type == return_type) {
 		return_ACPI_STATUS (AE_OK);
@@ -128,14 +127,14 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_evaluate_object
+ * FUNCTION:    acpi_evaluate_object
  *
  * PARAMETERS:  Handle              - Object handle (optional)
  *              *Pathname           - Object pathname (optional)
- *              **External_params   - List of parameters to pass to method,
+ *              **external_params   - List of parameters to pass to method,
  *                                    terminated by NULL.  May be NULL
  *                                    if no parameters are being passed.
- *              *Return_buffer      - Where to put method's return value (if
+ *              *return_buffer      - Where to put method's return value (if
  *                                    any).  If NULL, no value is returned.
  *
  * RETURN:      Status
@@ -156,11 +155,11 @@
 	acpi_status             status;
 	acpi_operand_object     **internal_params = NULL;
 	acpi_operand_object     *internal_return_obj = NULL;
-	ACPI_SIZE               buffer_space_needed;
+	acpi_size               buffer_space_needed;
 	u32                     i;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_evaluate_object");
+	ACPI_FUNCTION_TRACE ("acpi_evaluate_object");
 
 
 	/*
@@ -173,7 +172,7 @@
 		 * Allocate a new parameter block for the internal objects
 		 * Add 1 to count to allow for null terminated internal list
 		 */
-		internal_params = ACPI_MEM_CALLOCATE (((ACPI_SIZE) external_params->count + 1) *
+		internal_params = ACPI_MEM_CALLOCATE (((acpi_size) external_params->count + 1) *
 				  sizeof (void *));
 		if (!internal_params) {
 			return_ACPI_STATUS (AE_NO_MEMORY);
@@ -328,22 +327,22 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_walk_namespace
+ * FUNCTION:    acpi_walk_namespace
  *
  * PARAMETERS:  Type                - acpi_object_type to search for
- *              Start_object        - Handle in namespace where search begins
- *              Max_depth           - Depth to which search is to reach
- *              User_function       - Called when an object of "Type" is found
+ *              start_object        - Handle in namespace where search begins
+ *              max_depth           - Depth to which search is to reach
+ *              user_function       - Called when an object of "Type" is found
  *              Context             - Passed to user function
- *              Return_value        - Location where return value of
- *                                    User_function is put if terminated early
+ *              return_value        - Location where return value of
+ *                                    user_function is put if terminated early
  *
- * RETURNS      Return value from the User_function if terminated early.
+ * RETURNS      Return value from the user_function if terminated early.
  *              Otherwise, returns NULL.
  *
  * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
- *              starting (and ending) at the object specified by Start_handle.
- *              The User_function is called whenever an object that matches
+ *              starting (and ending) at the object specified by start_handle.
+ *              The user_function is called whenever an object that matches
  *              the type parameter is found.  If the user function returns
  *              a non-zero value, the search is terminated immediately and this
  *              value is returned to the caller.
@@ -368,7 +367,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_walk_namespace");
+	ACPI_FUNCTION_TRACE ("acpi_walk_namespace");
 
 
 	/* Parameter validation */
@@ -400,13 +399,13 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ns_get_device_callback
+ * FUNCTION:    acpi_ns_get_device_callback
  *
- * PARAMETERS:  Callback from Acpi_get_device
+ * PARAMETERS:  Callback from acpi_get_device
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Takes callbacks from Walk_namespace and filters out all non-
+ * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non-
  *              present devices, or if they specified a HID, it filters based
  *              on that.
  *
@@ -493,26 +492,26 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_get_devices
+ * FUNCTION:    acpi_get_devices
  *
  * PARAMETERS:  HID                 - HID to search for. Can be NULL.
- *              User_function       - Called when a matching object is found
+ *              user_function       - Called when a matching object is found
  *              Context             - Passed to user function
- *              Return_value        - Location where return value of
- *                                    User_function is put if terminated early
+ *              return_value        - Location where return value of
+ *                                    user_function is put if terminated early
  *
- * RETURNS      Return value from the User_function if terminated early.
+ * RETURNS      Return value from the user_function if terminated early.
  *              Otherwise, returns NULL.
  *
  * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
- *              starting (and ending) at the object specified by Start_handle.
- *              The User_function is called whenever an object that matches
+ *              starting (and ending) at the object specified by start_handle.
+ *              The user_function is called whenever an object that matches
  *              the type parameter is found.  If the user function returns
  *              a non-zero value, the search is terminated immediately and this
  *              value is returned to the caller.
  *
- *              This is a wrapper for Walk_namespace, but the callback performs
- *              additional filtering. Please see Acpi_get_device_callback.
+ *              This is a wrapper for walk_namespace, but the callback performs
+ *              additional filtering. Please see acpi_get_device_callback.
  *
  ******************************************************************************/
 
@@ -527,7 +526,7 @@
 	acpi_get_devices_info   info;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_get_devices");
+	ACPI_FUNCTION_TRACE ("acpi_get_devices");
 
 
 	/* Parameter validation */
@@ -568,9 +567,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_attach_data
+ * FUNCTION:    acpi_attach_data
  *
- * PARAMETERS:  Obj_handle          - Namespace node
+ * PARAMETERS:  obj_handle          - Namespace node
  *              Handler             - Handler for this attachment
  *              Data                - Pointer to data to be attached
  *
@@ -583,7 +582,7 @@
 acpi_status
 acpi_attach_data (
 	acpi_handle             obj_handle,
-	ACPI_OBJECT_HANDLER     handler,
+	acpi_object_handler     handler,
 	void                    *data)
 {
 	acpi_namespace_node     *node;
@@ -621,10 +620,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_detach_data
+ * FUNCTION:    acpi_detach_data
  *
- * PARAMETERS:  Obj_handle          - Namespace node handle
- *              Handler             - Handler used in call to Acpi_attach_data
+ * PARAMETERS:  obj_handle          - Namespace node handle
+ *              Handler             - Handler used in call to acpi_attach_data
  *
  * RETURN:      Status
  *
@@ -635,7 +634,7 @@
 acpi_status
 acpi_detach_data (
 	acpi_handle             obj_handle,
-	ACPI_OBJECT_HANDLER     handler)
+	acpi_object_handler     handler)
 {
 	acpi_namespace_node     *node;
 	acpi_status             status;
@@ -671,10 +670,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_get_data
+ * FUNCTION:    acpi_get_data
  *
- * PARAMETERS:  Obj_handle          - Namespace node
- *              Handler             - Handler used in call to Attach_data
+ * PARAMETERS:  obj_handle          - Namespace node
+ *              Handler             - Handler used in call to attach_data
  *              Data                - Where the data is returned
  *
  * RETURN:      Status
@@ -686,7 +685,7 @@
 acpi_status
 acpi_get_data (
 	acpi_handle             obj_handle,
-	ACPI_OBJECT_HANDLER     handler,
+	acpi_object_handler     handler,
 	void                    **data)
 {
 	acpi_namespace_node     *node;
diff -Nru a/drivers/acpi/namespace/nsxfname.c b/drivers/acpi/namespace/nsxfname.c
--- a/drivers/acpi/namespace/nsxfname.c	Mon Dec 23 21:21:52 2002
+++ b/drivers/acpi/namespace/nsxfname.c	Mon Dec 23 21:21:52 2002
@@ -2,7 +2,6 @@
  *
  * Module Name: nsxfname - Public interfaces to the ACPI subsystem
  *                         ACPI Namespace oriented interfaces
- *              $Revision: 93 $
  *
  *****************************************************************************/
 
@@ -35,12 +34,12 @@
 
 /****************************************************************************
  *
- * FUNCTION:    Acpi_get_handle
+ * FUNCTION:    acpi_get_handle
  *
  * PARAMETERS:  Parent          - Object to search under (search scope).
- *              Path_name       - Pointer to an asciiz string containing the
+ *              path_name       - Pointer to an asciiz string containing the
  *                                  name
- *              Ret_handle      - Where the return handle is placed
+ *              ret_handle      - Where the return handle is placed
  *
  * RETURN:      Status
  *
@@ -114,16 +113,16 @@
 
 /****************************************************************************
  *
- * FUNCTION:    Acpi_get_name
+ * FUNCTION:    acpi_get_name
  *
  * PARAMETERS:  Handle          - Handle to be converted to a pathname
- *              Name_type       - Full pathname or single segment
+ *              name_type       - Full pathname or single segment
  *              Buffer          - Buffer for returned path
  *
  * RETURN:      Pointer to a string containing the fully qualified Name.
  *
  * DESCRIPTION: This routine returns the fully qualified name associated with
- *              the Handle parameter.  This and the Acpi_pathname_to_handle are
+ *              the Handle parameter.  This and the acpi_pathname_to_handle are
  *              complementary functions.
  *
  ******************************************************************************/
@@ -195,7 +194,7 @@
 
 /****************************************************************************
  *
- * FUNCTION:    Acpi_get_object_info
+ * FUNCTION:    acpi_get_object_info
  *
  * PARAMETERS:  Handle          - Object Handle
  *              Info            - Where the info is returned
diff -Nru a/drivers/acpi/namespace/nsxfobj.c b/drivers/acpi/namespace/nsxfobj.c
--- a/drivers/acpi/namespace/nsxfobj.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/acpi/namespace/nsxfobj.c	Mon Dec 23 21:21:50 2002
@@ -2,7 +2,6 @@
  *
  * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
  *                         ACPI Object oriented interfaces
- *              $Revision: 114 $
  *
  ******************************************************************************/
 
@@ -34,10 +33,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_get_type
+ * FUNCTION:    acpi_get_type
  *
  * PARAMETERS:  Handle          - Handle of object whose type is desired
- *              *Ret_type       - Where the type will be placed
+ *              *ret_type       - Where the type will be placed
  *
  * RETURN:      Status
  *
@@ -92,10 +91,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_get_parent
+ * FUNCTION:    acpi_get_parent
  *
  * PARAMETERS:  Handle          - Handle of object whose parent is desired
- *              Ret_handle      - Where the parent handle will be placed
+ *              ret_handle      - Where the parent handle will be placed
  *
  * RETURN:      Status
  *
@@ -157,13 +156,13 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_get_next_object
+ * FUNCTION:    acpi_get_next_object
  *
  * PARAMETERS:  Type            - Type of object to be searched for
  *              Parent          - Parent object whose children we are getting
- *              Last_child      - Previous child that was found.
+ *              last_child      - Previous child that was found.
  *                                The NEXT child will be returned
- *              Ret_handle      - Where handle to the next object is placed
+ *              ret_handle      - Where handle to the next object is placed
  *
  * RETURN:      Status
  *
diff -Nru a/drivers/acpi/osl.c b/drivers/acpi/osl.c
--- a/drivers/acpi/osl.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/acpi/osl.c	Mon Dec 23 21:21:59 2002
@@ -61,7 +61,7 @@
 #include <linux/kdb.h>
 /* stuff for debugger support */
 int acpi_in_debugger = 0;
-extern NATIVE_CHAR line_buf[80];
+extern char line_buf[80];
 #endif /*ENABLE_DEBUGGER*/
 
 static int acpi_irq_irq = 0;
@@ -99,7 +99,7 @@
 }
 
 void
-acpi_os_printf(const NATIVE_CHAR *fmt,...)
+acpi_os_printf(const char *fmt,...)
 {
 	va_list args;
 	va_start(args, fmt);
@@ -108,7 +108,7 @@
 }
 
 void
-acpi_os_vprintf(const NATIVE_CHAR *fmt, va_list args)
+acpi_os_vprintf(const char *fmt, va_list args)
 {
 	static char buffer[512];
 	
@@ -126,7 +126,7 @@
 }
 
 void *
-acpi_os_allocate(ACPI_SIZE size)
+acpi_os_allocate(acpi_size size)
 {
 	return kmalloc(size, GFP_KERNEL);
 }
@@ -138,7 +138,7 @@
 }
 
 acpi_status
-acpi_os_get_root_pointer(u32 flags, ACPI_POINTER *addr)
+acpi_os_get_root_pointer(u32 flags, acpi_pointer *addr)
 {
 #ifdef CONFIG_ACPI_EFI
 	addr->pointer_type = ACPI_PHYSICAL_POINTER;
@@ -161,7 +161,7 @@
 }
 
 acpi_status
-acpi_os_map_memory(ACPI_PHYSICAL_ADDRESS phys, ACPI_SIZE size, void **virt)
+acpi_os_map_memory(acpi_physical_address phys, acpi_size size, void **virt)
 {
 #ifdef CONFIG_ACPI_EFI
 	if (EFI_MEMORY_WB & efi_mem_attributes(phys)) {
@@ -187,13 +187,13 @@
 }
 
 void
-acpi_os_unmap_memory(void *virt, ACPI_SIZE size)
+acpi_os_unmap_memory(void *virt, acpi_size size)
 {
 	iounmap(virt);
 }
 
 acpi_status
-acpi_os_get_physical_address(void *virt, ACPI_PHYSICAL_ADDRESS *phys)
+acpi_os_get_physical_address(void *virt, acpi_physical_address *phys)
 {
 	if(!phys || !virt)
 		return AE_BAD_PARAMETER;
@@ -274,7 +274,7 @@
 
 acpi_status
 acpi_os_read_port(
-	ACPI_IO_ADDRESS	port,
+	acpi_io_address	port,
 	void		*value,
 	u32		width)
 {
@@ -303,7 +303,7 @@
 
 acpi_status
 acpi_os_write_port(
-	ACPI_IO_ADDRESS	port,
+	acpi_io_address	port,
 	acpi_integer	value,
 	u32		width)
 {
@@ -327,7 +327,7 @@
 
 acpi_status
 acpi_os_read_memory(
-	ACPI_PHYSICAL_ADDRESS	phys_addr,
+	acpi_physical_address	phys_addr,
 	void			*value,
 	u32			width)
 {
@@ -373,7 +373,7 @@
 
 acpi_status
 acpi_os_write_memory(
-	ACPI_PHYSICAL_ADDRESS	phys_addr,
+	acpi_physical_address	phys_addr,
 	acpi_integer		value,
 	u32			width)
 {
@@ -843,7 +843,7 @@
 }
 
 u32
-acpi_os_get_line(NATIVE_CHAR *buffer)
+acpi_os_get_line(char *buffer)
 {
 
 #ifdef ENABLE_DEBUGGER
diff -Nru a/drivers/acpi/parser/psargs.c b/drivers/acpi/parser/psargs.c
--- a/drivers/acpi/parser/psargs.c	Mon Dec 23 21:21:52 2002
+++ b/drivers/acpi/parser/psargs.c	Mon Dec 23 21:21:52 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: psargs - Parse AML opcode arguments
- *              $Revision: 67 $
  *
  *****************************************************************************/
 
@@ -35,9 +34,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_get_next_package_length
+ * FUNCTION:    acpi_ps_get_next_package_length
  *
- * PARAMETERS:  Parser_state        - Current parser state object
+ * PARAMETERS:  parser_state        - Current parser state object
  *
  * RETURN:      Decoded package length.  On completion, the AML pointer points
  *              past the length byte or bytes.
@@ -54,7 +53,7 @@
 	u32                     length = 0;
 
 
-	ACPI_FUNCTION_TRACE ("Ps_get_next_package_length");
+	ACPI_FUNCTION_TRACE ("ps_get_next_package_length");
 
 
 	encoded_length = (u32) ACPI_GET8 (parser_state->aml);
@@ -106,9 +105,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_get_next_package_end
+ * FUNCTION:    acpi_ps_get_next_package_end
  *
- * PARAMETERS:  Parser_state        - Current parser state object
+ * PARAMETERS:  parser_state        - Current parser state object
  *
  * RETURN:      Pointer to end-of-package +1
  *
@@ -122,15 +121,15 @@
 	acpi_parse_state        *parser_state)
 {
 	u8                      *start = parser_state->aml;
-	NATIVE_UINT             length;
+	acpi_native_uint        length;
 
 
-	ACPI_FUNCTION_TRACE ("Ps_get_next_package_end");
+	ACPI_FUNCTION_TRACE ("ps_get_next_package_end");
 
 
-	/* Function below changes Parser_state->Aml */
+	/* Function below changes parser_state->Aml */
 
-	length = (NATIVE_UINT) acpi_ps_get_next_package_length (parser_state);
+	length = (acpi_native_uint) acpi_ps_get_next_package_length (parser_state);
 
 	return_PTR (start + length); /* end of package */
 }
@@ -138,9 +137,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_get_next_namestring
+ * FUNCTION:    acpi_ps_get_next_namestring
  *
- * PARAMETERS:  Parser_state        - Current parser state object
+ * PARAMETERS:  parser_state        - Current parser state object
  *
  * RETURN:      Pointer to the start of the name string (pointer points into
  *              the AML.
@@ -159,7 +158,7 @@
 	u8                      *end = parser_state->aml;
 
 
-	ACPI_FUNCTION_TRACE ("Ps_get_next_namestring");
+	ACPI_FUNCTION_TRACE ("ps_get_next_namestring");
 
 
 	/* Handle multiple prefix characters */
@@ -175,7 +174,7 @@
 	switch (ACPI_GET8 (end)) {
 	case 0:
 
-		/* Null_name */
+		/* null_name */
 
 		if (end == start) {
 			start = NULL;
@@ -194,7 +193,7 @@
 
 		/* Multiple name segments, 4 chars each */
 
-		end += 2 + ((ACPI_SIZE) ACPI_GET8 (end + 1) * ACPI_NAME_SIZE);
+		end += 2 + ((acpi_size) ACPI_GET8 (end + 1) * ACPI_NAME_SIZE);
 		break;
 
 	default:
@@ -212,13 +211,13 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_get_next_namepath
+ * FUNCTION:    acpi_ps_get_next_namepath
  *
- * PARAMETERS:  Parser_state        - Current parser state object
+ * PARAMETERS:  parser_state        - Current parser state object
  *              Arg                 - Where the namepath will be stored
- *              Arg_count           - If the namepath points to a control method
+ *              arg_count           - If the namepath points to a control method
  *                                    the method's argument is returned here.
- *              Method_call         - Whether the namepath can possibly be the
+ *              method_call         - Whether the namepath can possibly be the
  *                                    start of a method call
  *
  * RETURN:      Status
@@ -246,7 +245,7 @@
 	acpi_generic_state      scope_info;
 
 
-	ACPI_FUNCTION_TRACE ("Ps_get_next_namepath");
+	ACPI_FUNCTION_TRACE ("ps_get_next_namepath");
 
 
 	path = acpi_ps_get_next_namestring (parser_state);
@@ -324,7 +323,7 @@
 			/*
 			 * 1) Any error other than NOT_FOUND is always severe
 			 * 2) NOT_FOUND is only important if we are executing a method.
-			 * 3) If executing a Cond_ref_of opcode, NOT_FOUND is ok.
+			 * 3) If executing a cond_ref_of opcode, NOT_FOUND is ok.
 			 */
 			if ((((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) == ACPI_PARSE_EXECUTE) &&
 				(status == AE_NOT_FOUND)                                                &&
@@ -336,7 +335,7 @@
 			else {
 				/*
 				 * We got a NOT_FOUND during table load or we encountered
-				 * a Cond_ref_of(x) where the target does not exist.
+				 * a cond_ref_of(x) where the target does not exist.
 				 * -- either case is ok
 				 */
 				status = AE_OK;
@@ -357,10 +356,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_get_next_simple_arg
+ * FUNCTION:    acpi_ps_get_next_simple_arg
  *
- * PARAMETERS:  Parser_state        - Current parser state object
- *              Arg_type            - The argument type (AML_*_ARG)
+ * PARAMETERS:  parser_state        - Current parser state object
+ *              arg_type            - The argument type (AML_*_ARG)
  *              Arg                 - Where the argument is returned
  *
  * RETURN:      None
@@ -376,7 +375,7 @@
 	acpi_parse_object       *arg)
 {
 
-	ACPI_FUNCTION_TRACE_U32 ("Ps_get_next_simple_arg", arg_type);
+	ACPI_FUNCTION_TRACE_U32 ("ps_get_next_simple_arg", arg_type);
 
 
 	switch (arg_type) {
@@ -443,7 +442,7 @@
 
 	default:
 
-		ACPI_REPORT_ERROR (("Invalid Arg_type %X\n", arg_type));
+		ACPI_REPORT_ERROR (("Invalid arg_type %X\n", arg_type));
 		break;
 	}
 
@@ -453,13 +452,13 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_get_next_field
+ * FUNCTION:    acpi_ps_get_next_field
  *
- * PARAMETERS:  Parser_state        - Current parser state object
+ * PARAMETERS:  parser_state        - Current parser state object
  *
  * RETURN:      A newly allocated FIELD op
  *
- * DESCRIPTION: Get next field (Named_field, Reserved_field, or Access_field)
+ * DESCRIPTION: Get next field (named_field, reserved_field, or access_field)
  *
  ******************************************************************************/
 
@@ -474,7 +473,7 @@
 	u32                     name;
 
 
-	ACPI_FUNCTION_TRACE ("Ps_get_next_field");
+	ACPI_FUNCTION_TRACE ("ps_get_next_field");
 
 
 	/* determine field type */
@@ -536,8 +535,8 @@
 	case AML_INT_ACCESSFIELD_OP:
 
 		/*
-		 * Get Access_type and Access_attrib and merge into the field Op
-		 * Access_type is first operand, Access_attribute is second
+		 * Get access_type and access_attrib and merge into the field Op
+		 * access_type is first operand, access_attribute is second
 		 */
 		field->common.value.integer32 = (ACPI_GET8 (parser_state->aml) << 8);
 		parser_state->aml++;
@@ -557,11 +556,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_get_next_arg
+ * FUNCTION:    acpi_ps_get_next_arg
  *
- * PARAMETERS:  Parser_state        - Current parser state object
- *              Arg_type            - The argument type (AML_*_ARG)
- *              Arg_count           - If the argument points to a control method
+ * PARAMETERS:  parser_state        - Current parser state object
+ *              arg_type            - The argument type (AML_*_ARG)
+ *              arg_count           - If the argument points to a control method
  *                                    the method's argument is returned here.
  *
  * RETURN:      Status, and an op object containing the next argument.
@@ -585,7 +584,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ps_get_next_arg", parser_state);
+	ACPI_FUNCTION_TRACE_PTR ("ps_get_next_arg", parser_state);
 
 
 	switch (arg_type) {
@@ -673,7 +672,7 @@
 		if (subop == 0                  ||
 			acpi_ps_is_leading_char (subop) ||
 			acpi_ps_is_prefix_char (subop)) {
-			/* Null_name or Name_string */
+			/* null_name or name_string */
 
 			arg = acpi_ps_alloc_op (AML_INT_NAMEPATH_OP);
 			if (!arg) {
@@ -713,7 +712,7 @@
 
 	default:
 
-		ACPI_REPORT_ERROR (("Invalid Arg_type: %X\n", arg_type));
+		ACPI_REPORT_ERROR (("Invalid arg_type: %X\n", arg_type));
 		status = AE_AML_OPERAND_TYPE;
 		break;
 	}
diff -Nru a/drivers/acpi/parser/psopcode.c b/drivers/acpi/parser/psopcode.c
--- a/drivers/acpi/parser/psopcode.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/parser/psopcode.c	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: psopcode - Parser/Interpreter opcode information table
- *              $Revision: 75 $
  *
  *****************************************************************************/
 
@@ -52,7 +51,7 @@
 
 /*******************************************************************************
  *
- * NAME:        Acpi_gbl_Aml_op_info
+ * NAME:        acpi_gbl_aml_op_info
  *
  * DESCRIPTION: Opcode table. Each entry contains <opcode, type, name, operands>
  *              The name is a simple ascii string, the operand specifier is an
@@ -195,7 +194,7 @@
  * All AML opcodes and the runtime arguments for each.  Used by the AML interpreter  Each list is compressed
  * into a 32-bit number and stored in the master opcode table at the end of this file.
  *
- * (Used by Prep_operands procedure and the ASL Compiler)
+ * (Used by prep_operands procedure and the ASL Compiler)
  */
 
 
@@ -664,7 +663,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_get_opcode_info
+ * FUNCTION:    acpi_ps_get_opcode_info
  *
  * PARAMETERS:  Opcode              - The AML opcode
  *
@@ -680,7 +679,7 @@
 acpi_ps_get_opcode_info (
 	u16                     opcode)
 {
-	ACPI_FUNCTION_NAME ("Ps_get_opcode_info");
+	ACPI_FUNCTION_NAME ("ps_get_opcode_info");
 
 
 	/*
@@ -719,7 +718,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_get_opcode_name
+ * FUNCTION:    acpi_ps_get_opcode_name
  *
  * PARAMETERS:  Opcode              - The AML opcode
  *
diff -Nru a/drivers/acpi/parser/psparse.c b/drivers/acpi/parser/psparse.c
--- a/drivers/acpi/parser/psparse.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/parser/psparse.c	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: psparse - Parser top level AML parse routines
- *              $Revision: 138 $
  *
  *****************************************************************************/
 
@@ -30,7 +29,7 @@
  * generated parser to tightly constrain stack and dynamic memory
  * usage.  At the same time, parsing is kept flexible and the code
  * fairly compact by parsing based on a list of AML opcode
- * templates in Aml_op_info[]
+ * templates in aml_op_info[]
  */
 
 #include "acpi.h"
@@ -49,7 +48,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_get_opcode_size
+ * FUNCTION:    acpi_ps_get_opcode_size
  *
  * PARAMETERS:  Opcode          - An AML opcode
  *
@@ -78,9 +77,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_peek_opcode
+ * FUNCTION:    acpi_ps_peek_opcode
  *
- * PARAMETERS:  Parser_state        - A parser state object
+ * PARAMETERS:  parser_state        - A parser state object
  *
  * RETURN:      Status
  *
@@ -113,9 +112,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_complete_this_op
+ * FUNCTION:    acpi_ps_complete_this_op
  *
- * PARAMETERS:  Walk_state      - Current State
+ * PARAMETERS:  walk_state      - Current State
  *              Op              - Op to complete
  *
  * RETURN:      None.
@@ -135,7 +134,7 @@
 	acpi_parse_object       *replacement_op = NULL;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ps_complete_this_op", op);
+	ACPI_FUNCTION_TRACE_PTR ("ps_complete_this_op", op);
 
 
 	/* Check for null Op, can happen if AML code is corrupt */
@@ -164,7 +163,7 @@
 			case AML_CLASS_CREATE:
 
 				/*
-				 * These opcodes contain Term_arg operands. The current
+				 * These opcodes contain term_arg operands. The current
 				 * op must be replaced by a placeholder return op
 				 */
 				replacement_op = acpi_ps_alloc_op (AML_INT_RETURN_VALUE_OP);
@@ -176,7 +175,7 @@
 			case AML_CLASS_NAMED_OBJECT:
 
 				/*
-				 * These opcodes contain Term_arg operands. The current
+				 * These opcodes contain term_arg operands. The current
 				 * op must be replaced by a placeholder return op
 				 */
 				if ((op->common.parent->common.aml_opcode == AML_REGION_OP)      ||
@@ -269,9 +268,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_next_parse_state
+ * FUNCTION:    acpi_ps_next_parse_state
  *
- * PARAMETERS:  Parser_state        - Current parser state object
+ * PARAMETERS:  parser_state        - Current parser state object
  *
  * RETURN:      Status
  *
@@ -290,7 +289,7 @@
 	acpi_status             status = AE_CTRL_PENDING;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ps_next_parse_state", op);
+	ACPI_FUNCTION_TRACE_PTR ("ps_next_parse_state", op);
 
 
 	switch (callback_status) {
@@ -390,9 +389,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_parse_loop
+ * FUNCTION:    acpi_ps_parse_loop
  *
- * PARAMETERS:  Parser_state        - Current parser state object
+ * PARAMETERS:  parser_state        - Current parser state object
  *
  * RETURN:      Status
  *
@@ -413,7 +412,7 @@
 	u8                      *aml_op_start = NULL;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ps_parse_loop", walk_state);
+	ACPI_FUNCTION_TRACE_PTR ("ps_parse_loop", walk_state);
 
 	if (walk_state->descending_callback == NULL) {
 		return_ACPI_STATUS (AE_BAD_PARAMETER);
@@ -452,7 +451,7 @@
 							acpi_format_exception (status)));
 
 					}
-					ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Get_predicate Failed, %s\n",
+					ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "get_predicate Failed, %s\n",
 						acpi_format_exception (status)));
 					return_ACPI_STATUS (status);
 				}
@@ -591,10 +590,10 @@
 
 				if (op->common.aml_opcode == AML_REGION_OP) {
 					/*
-					 * Defer final parsing of an Operation_region body,
+					 * Defer final parsing of an operation_region body,
 					 * because we don't have enough info in the first pass
 					 * to parse it correctly (i.e., there may be method
-					 * calls within the Term_arg elements of the body.)
+					 * calls within the term_arg elements of the body.)
 					 *
 					 * However, we must continue parsing because
 					 * the opregion is not a standalone package --
@@ -617,8 +616,8 @@
 
 				if (walk_state->op_info->flags & AML_CREATE) {
 					/*
-					 * Backup to beginning of Create_xXXfield declaration
-					 * Body_length is unknown until we parse the body
+					 * Backup to beginning of create_xXXfield declaration
+					 * body_length is unknown until we parse the body
 					 */
 					op->named.data    = aml_op_start;
 					op->named.length  = 0;
@@ -650,14 +649,14 @@
 
 			if (walk_state->op_info) {
 				ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
-					"Opcode %4.4X [%s] Op %p Aml %p Aml_offset %5.5X\n",
+					"Opcode %4.4X [%s] Op %p Aml %p aml_offset %5.5X\n",
 					 (u32) op->common.aml_opcode, walk_state->op_info->name,
 					 op, parser_state->aml, op->common.aml_offset));
 			}
 		}
 
 
-		/* Start Arg_count at zero because we don't know if there are any args yet */
+		/* Start arg_count at zero because we don't know if there are any args yet */
 
 		walk_state->arg_count = 0;
 
@@ -722,7 +721,7 @@
 					op->named.data   = parser_state->aml;
 					op->named.length = (u32) (parser_state->pkg_end - parser_state->aml);
 					/*
-					 * Skip body of method.  For Op_regions, we must continue
+					 * Skip body of method.  For op_regions, we must continue
 					 * parsing because the opregion is not a standalone
 					 * package (We don't know where the end is).
 					 */
@@ -795,7 +794,7 @@
 				 * because we don't have enough info in the first pass
 				 * to parse them correctly.
 				 *
-				 * Completed parsing an Op_region declaration, we now
+				 * Completed parsing an op_region declaration, we now
 				 * know the length.
 				 */
 				op->named.length = (u32) (parser_state->aml - op->named.data);
@@ -804,10 +803,10 @@
 
 		if (walk_state->op_info->flags & AML_CREATE) {
 			/*
-			 * Backup to beginning of Create_xXXfield declaration (1 for
+			 * Backup to beginning of create_xXXfield declaration (1 for
 			 * Opcode)
 			 *
-			 * Body_length is unknown until we parse the body
+			 * body_length is unknown until we parse the body
 			 */
 			op->named.length = (u32) (parser_state->aml - op->named.data);
 		}
@@ -953,7 +952,7 @@
 			op = NULL;
 		}
 
-	} /* while Parser_state->Aml */
+	} /* while parser_state->Aml */
 
 
 	/*
@@ -1014,12 +1013,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_parse_aml
+ * FUNCTION:    acpi_ps_parse_aml
  *
- * PARAMETERS:  Start_scope     - The starting point of the parse.  Becomes the
+ * PARAMETERS:  start_scope     - The starting point of the parse.  Becomes the
  *                                root of the parsed op tree.
  *              Aml             - Pointer to the raw AML code to parse
- *              Aml_size        - Length of the AML to parse
+ *              aml_size        - Length of the AML to parse
  *
  *
  * RETURN:      Status
@@ -1034,14 +1033,14 @@
 {
 	acpi_status             status;
 	acpi_status             terminate_status;
-	ACPI_THREAD_STATE       *thread;
-	ACPI_THREAD_STATE       *prev_walk_list = acpi_gbl_current_walk_list;
+	acpi_thread_state       *thread;
+	acpi_thread_state       *prev_walk_list = acpi_gbl_current_walk_list;
 	acpi_walk_state         *previous_walk_state;
 
 
-	ACPI_FUNCTION_TRACE ("Ps_parse_aml");
+	ACPI_FUNCTION_TRACE ("ps_parse_aml");
 
-	ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Entered with Walk_state=%p Aml=%p size=%X\n",
+	ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Entered with walk_state=%p Aml=%p size=%X\n",
 		walk_state, walk_state->parser_state.aml, walk_state->parser_state.aml_size));
 
 
@@ -1071,7 +1070,7 @@
 	while (walk_state) {
 		if (ACPI_SUCCESS (status)) {
 			/*
-			 * The Parse_loop executes AML until the method terminates
+			 * The parse_loop executes AML until the method terminates
 			 * or calls another method.
 			 */
 			status = acpi_ps_parse_loop (walk_state);
@@ -1131,7 +1130,7 @@
 
 		previous_walk_state = walk_state;
 
-		ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Return_value=%p, State=%p\n",
+		ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "return_value=%p, State=%p\n",
 			walk_state->return_desc, walk_state));
 
 		/* Check if we have restarted a preempted walk */
diff -Nru a/drivers/acpi/parser/psscope.c b/drivers/acpi/parser/psscope.c
--- a/drivers/acpi/parser/psscope.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/parser/psscope.c	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: psscope - Parser scope stack management routines
- *              $Revision: 35 $
  *
  *****************************************************************************/
 
@@ -33,9 +32,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_get_parent_scope
+ * FUNCTION:    acpi_ps_get_parent_scope
  *
- * PARAMETERS:  Parser_state        - Current parser state object
+ * PARAMETERS:  parser_state        - Current parser state object
  *
  * RETURN:      Pointer to an Op object
  *
@@ -53,9 +52,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_has_completed_scope
+ * FUNCTION:    acpi_ps_has_completed_scope
  *
- * PARAMETERS:  Parser_state        - Current parser state object
+ * PARAMETERS:  parser_state        - Current parser state object
  *
  * RETURN:      Boolean, TRUE = scope completed.
  *
@@ -76,9 +75,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_init_scope
+ * FUNCTION:    acpi_ps_init_scope
  *
- * PARAMETERS:  Parser_state        - Current parser state object
+ * PARAMETERS:  parser_state        - Current parser state object
  *              Root                - the Root Node of this new scope
  *
  * RETURN:      Status
@@ -95,7 +94,7 @@
 	acpi_generic_state      *scope;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ps_init_scope", root_op);
+	ACPI_FUNCTION_TRACE_PTR ("ps_init_scope", root_op);
 
 
 	scope = acpi_ut_create_generic_state ();
@@ -118,12 +117,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_push_scope
+ * FUNCTION:    acpi_ps_push_scope
  *
- * PARAMETERS:  Parser_state        - Current parser state object
+ * PARAMETERS:  parser_state        - Current parser state object
  *              Op                  - Current op to be pushed
- *              Remaining_args      - List of args remaining
- *              Arg_count           - Fixed or variable number of args
+ *              remaining_args      - List of args remaining
+ *              arg_count           - Fixed or variable number of args
  *
  * RETURN:      Status
  *
@@ -141,7 +140,7 @@
 	acpi_generic_state      *scope;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ps_push_scope", op);
+	ACPI_FUNCTION_TRACE_PTR ("ps_push_scope", op);
 
 
 	scope = acpi_ut_create_generic_state ();
@@ -179,13 +178,13 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_pop_scope
+ * FUNCTION:    acpi_ps_pop_scope
  *
- * PARAMETERS:  Parser_state        - Current parser state object
+ * PARAMETERS:  parser_state        - Current parser state object
  *              Op                  - Where the popped op is returned
- *              Arg_list            - Where the popped "next argument" is
+ *              arg_list            - Where the popped "next argument" is
  *                                    returned
- *              Arg_count           - Count of objects in Arg_list
+ *              arg_count           - Count of objects in arg_list
  *
  * RETURN:      Status
  *
@@ -203,7 +202,7 @@
 	acpi_generic_state      *scope = parser_state->scope;
 
 
-	ACPI_FUNCTION_TRACE ("Ps_pop_scope");
+	ACPI_FUNCTION_TRACE ("ps_pop_scope");
 
 
 	/*
@@ -240,9 +239,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_cleanup_scope
+ * FUNCTION:    acpi_ps_cleanup_scope
  *
- * PARAMETERS:  Parser_state        - Current parser state object
+ * PARAMETERS:  parser_state        - Current parser state object
  *
  * RETURN:      Status
  *
@@ -257,7 +256,7 @@
 {
 	acpi_generic_state      *scope;
 
-	ACPI_FUNCTION_TRACE_PTR ("Ps_cleanup_scope", parser_state);
+	ACPI_FUNCTION_TRACE_PTR ("ps_cleanup_scope", parser_state);
 
 
 	if (!parser_state) {
diff -Nru a/drivers/acpi/parser/pstree.c b/drivers/acpi/parser/pstree.c
--- a/drivers/acpi/parser/pstree.c	Mon Dec 23 21:21:52 2002
+++ b/drivers/acpi/parser/pstree.c	Mon Dec 23 21:21:52 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: pstree - Parser op tree manipulation/traversal/search
- *              $Revision: 40 $
  *
  *****************************************************************************/
 
@@ -34,7 +33,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_get_arg
+ * FUNCTION:    acpi_ps_get_arg
  *
  * PARAMETERS:  Op              - Get an argument for this op
  *              Argn            - Nth argument to get
@@ -88,7 +87,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_append_arg
+ * FUNCTION:    acpi_ps_append_arg
  *
  * PARAMETERS:  Op              - Append an argument to this Op.
  *              Arg             - Argument Op to append
@@ -121,7 +120,7 @@
 	if (op_info->class == AML_CLASS_UNKNOWN) {
 		/* Invalid opcode */
 
-		ACPI_REPORT_ERROR (("Ps_append_arg: Invalid AML Opcode: 0x%2.2X\n",
+		ACPI_REPORT_ERROR (("ps_append_arg: Invalid AML Opcode: 0x%2.2X\n",
 			op->common.aml_opcode));
 		return;
 	}
@@ -165,7 +164,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_get_child
+ * FUNCTION:    acpi_ps_get_child
  *
  * PARAMETERS:  Op              - Get the child of this Op
  *
@@ -232,7 +231,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_get_depth_next
+ * FUNCTION:    acpi_ps_get_depth_next
  *
  * PARAMETERS:  Origin          - Root of subtree to search
  *              Op              - Last (previous) Op that was found
diff -Nru a/drivers/acpi/parser/psutils.c b/drivers/acpi/parser/psutils.c
--- a/drivers/acpi/parser/psutils.c	Mon Dec 23 21:21:56 2002
+++ b/drivers/acpi/parser/psutils.c	Mon Dec 23 21:21:56 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: psutils - Parser miscellaneous utilities (Parser only)
- *              $Revision: 54 $
  *
  *****************************************************************************/
 
@@ -35,11 +34,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_create_scope_op
+ * FUNCTION:    acpi_ps_create_scope_op
  *
  * PARAMETERS:  None
  *
- * RETURN:      Scope_op
+ * RETURN:      scope_op
  *
  * DESCRIPTION: Create a Scope and associated namepath op with the root name
  *
@@ -65,7 +64,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_init_op
+ * FUNCTION:    acpi_ps_init_op
  *
  * PARAMETERS:  Op              - A newly allocated Op object
  *              Opcode          - Opcode to store in the Op
@@ -95,7 +94,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_alloc_op
+ * FUNCTION:    acpi_ps_alloc_op
  *
  * PARAMETERS:  Opcode          - Opcode that will be stored in the new Op
  *
@@ -125,23 +124,23 @@
 	/* Allocate the minimum required size object */
 
 	if (op_info->flags & AML_DEFER) {
-		size = sizeof (ACPI_PARSE_OBJ_NAMED);
+		size = sizeof (acpi_parse_obj_named);
 		flags = ACPI_PARSEOP_DEFERRED;
 	}
 	else if (op_info->flags & AML_NAMED) {
-		size = sizeof (ACPI_PARSE_OBJ_NAMED);
+		size = sizeof (acpi_parse_obj_named);
 		flags = ACPI_PARSEOP_NAMED;
 	}
 	else if (opcode == AML_INT_BYTELIST_OP) {
-		size = sizeof (ACPI_PARSE_OBJ_NAMED);
+		size = sizeof (acpi_parse_obj_named);
 		flags = ACPI_PARSEOP_BYTELIST;
 	}
 	else {
-		size = sizeof (ACPI_PARSE_OBJ_COMMON);
+		size = sizeof (acpi_parse_obj_common);
 		flags = ACPI_PARSEOP_GENERIC;
 	}
 
-	if (size == sizeof (ACPI_PARSE_OBJ_COMMON)) {
+	if (size == sizeof (acpi_parse_obj_common)) {
 		/*
 		 * The generic op is by far the most common (16 to 1)
 		 */
@@ -164,7 +163,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_free_op
+ * FUNCTION:    acpi_ps_free_op
  *
  * PARAMETERS:  Op              - Op to be freed
  *
@@ -179,7 +178,7 @@
 acpi_ps_free_op (
 	acpi_parse_object       *op)
 {
-	ACPI_FUNCTION_NAME ("Ps_free_op");
+	ACPI_FUNCTION_NAME ("ps_free_op");
 
 
 	if (op->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
@@ -197,7 +196,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_delete_parse_cache
+ * FUNCTION:    acpi_ps_delete_parse_cache
  *
  * PARAMETERS:  None
  *
@@ -211,7 +210,7 @@
 acpi_ps_delete_parse_cache (
 	void)
 {
-	ACPI_FUNCTION_TRACE ("Ps_delete_parse_cache");
+	ACPI_FUNCTION_TRACE ("ps_delete_parse_cache");
 
 
 	acpi_ut_delete_generic_cache (ACPI_MEM_LIST_PSNODE);
diff -Nru a/drivers/acpi/parser/pswalk.c b/drivers/acpi/parser/pswalk.c
--- a/drivers/acpi/parser/pswalk.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/acpi/parser/pswalk.c	Mon Dec 23 21:21:58 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: pswalk - Parser routines to walk parsed op tree(s)
- *              $Revision: 67 $
  *
  *****************************************************************************/
 
@@ -34,11 +33,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_get_next_walk_op
+ * FUNCTION:    acpi_ps_get_next_walk_op
  *
- * PARAMETERS:  Walk_state          - Current state of the walk
+ * PARAMETERS:  walk_state          - Current state of the walk
  *              Op                  - Current Op to be walked
- *              Ascending_callback  - Procedure called when Op is complete
+ *              ascending_callback  - Procedure called when Op is complete
  *
  * RETURN:      Status
  *
@@ -58,7 +57,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ps_get_next_walk_op", op);
+	ACPI_FUNCTION_TRACE_PTR ("ps_get_next_walk_op", op);
 
 
 	/* Check for a argument only if we are descending in the tree */
@@ -194,15 +193,15 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_delete_completed_op
+ * FUNCTION:    acpi_ps_delete_completed_op
  *
  * PARAMETERS:  State           - Walk state
  *              Op              - Completed op
  *
  * RETURN:      AE_OK
  *
- * DESCRIPTION: Callback function for Acpi_ps_get_next_walk_op(). Used during
- *              Acpi_ps_delete_parse tree to delete Op objects when all sub-objects
+ * DESCRIPTION: Callback function for acpi_ps_get_next_walk_op(). Used during
+ *              acpi_ps_delete_parse tree to delete Op objects when all sub-objects
  *              have been visited (and deleted.)
  *
  ******************************************************************************/
@@ -219,9 +218,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ps_delete_parse_tree
+ * FUNCTION:    acpi_ps_delete_parse_tree
  *
- * PARAMETERS:  Subtree_root        - Root of tree (or subtree) to delete
+ * PARAMETERS:  subtree_root        - Root of tree (or subtree) to delete
  *
  * RETURN:      None
  *
@@ -234,11 +233,11 @@
 	acpi_parse_object       *subtree_root)
 {
 	acpi_walk_state         *walk_state;
-	ACPI_THREAD_STATE       *thread;
+	acpi_thread_state       *thread;
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ps_delete_parse_tree", subtree_root);
+	ACPI_FUNCTION_TRACE_PTR ("ps_delete_parse_tree", subtree_root);
 
 
 	if (!subtree_root) {
diff -Nru a/drivers/acpi/parser/psxface.c b/drivers/acpi/parser/psxface.c
--- a/drivers/acpi/parser/psxface.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/acpi/parser/psxface.c	Mon Dec 23 21:21:59 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: psxface - Parser external interfaces
- *              $Revision: 66 $
  *
  *****************************************************************************/
 
@@ -37,14 +36,14 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_psx_execute
+ * FUNCTION:    acpi_psx_execute
  *
- * PARAMETERS:  Method_node         - A method object containing both the AML
+ * PARAMETERS:  method_node         - A method object containing both the AML
  *                                    address and length.
  *              **Params            - List of parameters to pass to method,
  *                                    terminated by NULL. Params itself may be
  *                                    NULL if no parameters are being passed.
- *              **Return_obj_desc   - Return object from execution of the
+ *              **return_obj_desc   - Return object from execution of the
  *                                    method.
  *
  * RETURN:      Status
@@ -66,7 +65,7 @@
 	acpi_walk_state         *walk_state;
 
 
-	ACPI_FUNCTION_TRACE ("Psx_execute");
+	ACPI_FUNCTION_TRACE ("psx_execute");
 
 
 	/* Validate the Node and get the attached object */
@@ -113,7 +112,7 @@
 	}
 
 	/*
-	 * Get a new Owner_id for objects created by this method. Namespace
+	 * Get a new owner_id for objects created by this method. Namespace
 	 * objects (such as Operation Regions) can be created during the
 	 * first pass parse.
 	 */
@@ -193,7 +192,7 @@
 	 * a control exception code
 	 */
 	if (*return_obj_desc) {
-		ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Method returned Obj_desc=%p\n",
+		ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Method returned obj_desc=%p\n",
 			*return_obj_desc));
 		ACPI_DUMP_STACK_ENTRY (*return_obj_desc);
 
diff -Nru a/drivers/acpi/power.c b/drivers/acpi/power.c
--- a/drivers/acpi/power.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/acpi/power.c	Mon Dec 23 21:21:55 2002
@@ -467,8 +467,10 @@
 {
 	ACPI_FUNCTION_TRACE("acpi_power_remove_fs");
 
-	if (acpi_device_dir(device))
+	if (acpi_device_dir(device)) {
 		remove_proc_entry(acpi_device_bid(device), acpi_power_dir);
+		acpi_device_dir(device) = NULL;
+	}
 
 	return_VALUE(0);
 }
diff -Nru a/drivers/acpi/processor.c b/drivers/acpi/processor.c
--- a/drivers/acpi/processor.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/acpi/processor.c	Mon Dec 23 21:21:58 2002
@@ -549,13 +549,13 @@
 
 	case ACPI_STATE_C2:
 		/* Get start time (ticks) */
-		t1 = inl(acpi_fadt.Xpm_tmr_blk.address);
+		t1 = inl(acpi_fadt.xpm_tmr_blk.address);
 		/* Invoke C2 */
 		inb(pr->power.states[ACPI_STATE_C2].address);
 		/* Dummy op - must do something useless after P_LVL2 read */
-		t2 = inl(acpi_fadt.Xpm_tmr_blk.address);
+		t2 = inl(acpi_fadt.xpm_tmr_blk.address);
 		/* Get end time (ticks) */
-		t2 = inl(acpi_fadt.Xpm_tmr_blk.address);
+		t2 = inl(acpi_fadt.xpm_tmr_blk.address);
 		/* Re-enable interrupts */
 		local_irq_enable();
 		/* Compute time (ticks) that we were actually asleep */
@@ -566,13 +566,13 @@
 		/* Disable bus master arbitration */
 		acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1, ACPI_MTX_DO_NOT_LOCK);
 		/* Get start time (ticks) */
-		t1 = inl(acpi_fadt.Xpm_tmr_blk.address);
+		t1 = inl(acpi_fadt.xpm_tmr_blk.address);
 		/* Invoke C3 */
 		inb(pr->power.states[ACPI_STATE_C3].address);
 		/* Dummy op - must do something useless after P_LVL3 read */
-		t2 = inl(acpi_fadt.Xpm_tmr_blk.address);
+		t2 = inl(acpi_fadt.xpm_tmr_blk.address);
 		/* Get end time (ticks) */
-		t2 = inl(acpi_fadt.Xpm_tmr_blk.address);
+		t2 = inl(acpi_fadt.xpm_tmr_blk.address);
 		/* Enable bus master arbitration */
 		acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0, ACPI_MTX_DO_NOT_LOCK);
 		/* Re-enable interrupts */
@@ -2348,8 +2348,10 @@
 {
 	ACPI_FUNCTION_TRACE("acpi_processor_remove_fs");
 
-	if (acpi_device_dir(device))
+	if (acpi_device_dir(device)) {
 		remove_proc_entry(acpi_device_bid(device), acpi_processor_dir);
+		acpi_device_dir(device) = NULL;
+	}
 
 	return_VALUE(0);
 }
diff -Nru a/drivers/acpi/resources/rsaddr.c b/drivers/acpi/resources/rsaddr.c
--- a/drivers/acpi/resources/rsaddr.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/acpi/resources/rsaddr.c	Mon Dec 23 21:21:55 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: rsaddr - Address resource descriptors (16/32/64)
- *              $Revision: 27 $
  *
  ******************************************************************************/
 
@@ -33,21 +32,21 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_address16_resource
+ * FUNCTION:    acpi_rs_address16_resource
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
  *                                        stream
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        consumed the Byte_stream_buffer is
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        consumed the byte_stream_buffer is
  *                                        returned
- *              Output_buffer           - Pointer to the return data buffer
- *              Structure_size          - Pointer to where the number of bytes
+ *              output_buffer           - Pointer to the return data buffer
+ *              structure_size          - Pointer to where the number of bytes
  *                                        in the return data struct is returned
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
- *              structure pointed to by the Output_buffer. Return the
+ *              structure pointed to by the output_buffer. Return the
  *              number of bytes consumed from the byte stream.
  *
  ******************************************************************************/
@@ -55,20 +54,20 @@
 acpi_status
 acpi_rs_address16_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size)
+	acpi_size               *structure_size)
 {
 	u8                      *buffer = byte_stream_buffer;
 	acpi_resource           *output_struct = (void *) *output_buffer;
 	u8                      *temp_ptr;
-	ACPI_SIZE               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_address16);
+	acpi_size               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_address16);
 	u32                     index;
 	u16                     temp16;
 	u8                      temp8;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_address16_resource");
+	ACPI_FUNCTION_TRACE ("rs_address16_resource");
 
 	/*
 	 * Point past the Descriptor to get the number of bytes consumed
@@ -133,7 +132,7 @@
 				(u16) (temp8 & 0x03);
 		}
 		else {
-			/* BUS_NUMBER_RANGE == Address16.Data->Resource_type */
+			/* BUS_NUMBER_RANGE == Address16.Data->resource_type */
 			/* Nothing needs to be filled in */
 		}
 	}
@@ -146,28 +145,28 @@
 			 buffer);
 
 	/*
-	 * Get Min_address_range (Bytes 8-9)
+	 * Get min_address_range (Bytes 8-9)
 	 */
 	buffer += 2;
 	ACPI_MOVE_UNALIGNED16_TO_16 (&output_struct->data.address16.min_address_range,
 			 buffer);
 
 	/*
-	 * Get Max_address_range (Bytes 10-11)
+	 * Get max_address_range (Bytes 10-11)
 	 */
 	buffer += 2;
 	ACPI_MOVE_UNALIGNED16_TO_16 (&output_struct->data.address16.max_address_range,
 			 buffer);
 
 	/*
-	 * Get Address_translation_offset (Bytes 12-13)
+	 * Get address_translation_offset (Bytes 12-13)
 	 */
 	buffer += 2;
 	ACPI_MOVE_UNALIGNED16_TO_16 (&output_struct->data.address16.address_translation_offset,
 			 buffer);
 
 	/*
-	 * Get Address_length (Bytes 14-15)
+	 * Get address_length (Bytes 14-15)
 	 */
 	buffer += 2;
 	ACPI_MOVE_UNALIGNED16_TO_16 (&output_struct->data.address16.address_length,
@@ -222,12 +221,12 @@
 		output_struct->data.address16.resource_source.string_length = index + 1;
 
 		/*
-		 * In order for the Struct_size to fall on a 32-bit boundary,
+		 * In order for the struct_size to fall on a 32-bit boundary,
 		 * calculate the length of the string and expand the
-		 * Struct_size to the next 32-bit boundary.
+		 * struct_size to the next 32-bit boundary.
 		 */
 		temp8 = (u8) (index + 1);
-		struct_size += ACPI_ROUND_UP_TO_32_bITS (temp8);
+		struct_size += ACPI_ROUND_UP_to_32_bITS (temp8);
 	}
 	else {
 		output_struct->data.address16.resource_source.index = 0x00;
@@ -250,12 +249,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_address16_stream
+ * FUNCTION:    acpi_rs_address16_stream
  *
- * PARAMETERS:  Linked_list             - Pointer to the resource linked list
- *              Output_buffer           - Pointer to the user's return buffer
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        used in the Output_buffer is returned
+ * PARAMETERS:  linked_list             - Pointer to the resource linked list
+ *              output_buffer           - Pointer to the user's return buffer
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        used in the output_buffer is returned
  *
  * RETURN:      Status
  *
@@ -268,16 +267,16 @@
 acpi_rs_address16_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed)
+	acpi_size               *bytes_consumed)
 {
 	u8                      *buffer = *output_buffer;
 	u8                      *length_field;
 	u8                      temp8;
 	char                    *temp_pointer = NULL;
-	ACPI_SIZE               actual_bytes;
+	acpi_size               actual_bytes;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_address16_stream");
+	ACPI_FUNCTION_TRACE ("rs_address16_stream");
 
 
 	/*
@@ -293,7 +292,7 @@
 	buffer += 2;
 
 	/*
-	 * Set the Resource Type (Memory, Io, Bus_number)
+	 * Set the Resource Type (Memory, Io, bus_number)
 	 */
 	temp8 = (u8) (linked_list->data.address16.resource_type & 0x03);
 	*buffer = temp8;
@@ -411,21 +410,21 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_address32_resource
+ * FUNCTION:    acpi_rs_address32_resource
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
  *                                        stream
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        consumed the Byte_stream_buffer is
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        consumed the byte_stream_buffer is
  *                                        returned
- *              Output_buffer           - Pointer to the return data buffer
- *              Structure_size          - Pointer to where the number of bytes
+ *              output_buffer           - Pointer to the return data buffer
+ *              structure_size          - Pointer to where the number of bytes
  *                                        in the return data struct is returned
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
- *              structure pointed to by the Output_buffer. Return the
+ *              structure pointed to by the output_buffer. Return the
  *              number of bytes consumed from the byte stream.
  *
  ******************************************************************************/
@@ -433,20 +432,20 @@
 acpi_status
 acpi_rs_address32_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size)
+	acpi_size               *structure_size)
 {
 	u8                      *buffer;
 	acpi_resource           *output_struct= (void *) *output_buffer;
 	u16                     temp16;
 	u8                      temp8;
 	u8                      *temp_ptr;
-	ACPI_SIZE               struct_size;
+	acpi_size               struct_size;
 	u32                     index;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_address32_resource");
+	ACPI_FUNCTION_TRACE ("rs_address32_resource");
 
 
 	buffer = byte_stream_buffer;
@@ -519,7 +518,7 @@
 				(u16) (temp8 & 0x03);
 		}
 		else {
-			/* BUS_NUMBER_RANGE == Output_struct->Data.Address32.Resource_type */
+			/* BUS_NUMBER_RANGE == output_struct->Data.Address32.resource_type */
 			/* Nothing needs to be filled in */
 		}
 	}
@@ -532,28 +531,28 @@
 			 buffer);
 
 	/*
-	 * Get Min_address_range (Bytes 10-13)
+	 * Get min_address_range (Bytes 10-13)
 	 */
 	buffer += 4;
 	ACPI_MOVE_UNALIGNED32_TO_32 (&output_struct->data.address32.min_address_range,
 			 buffer);
 
 	/*
-	 * Get Max_address_range (Bytes 14-17)
+	 * Get max_address_range (Bytes 14-17)
 	 */
 	buffer += 4;
 	ACPI_MOVE_UNALIGNED32_TO_32 (&output_struct->data.address32.max_address_range,
 			 buffer);
 
 	/*
-	 * Get Address_translation_offset (Bytes 18-21)
+	 * Get address_translation_offset (Bytes 18-21)
 	 */
 	buffer += 4;
 	ACPI_MOVE_UNALIGNED32_TO_32 (&output_struct->data.address32.address_translation_offset,
 			 buffer);
 
 	/*
-	 * Get Address_length (Bytes 22-25)
+	 * Get address_length (Bytes 22-25)
 	 */
 	buffer += 4;
 	ACPI_MOVE_UNALIGNED32_TO_32 (&output_struct->data.address32.address_length,
@@ -605,12 +604,12 @@
 		output_struct->data.address32.resource_source.string_length = index + 1;
 
 		/*
-		 * In order for the Struct_size to fall on a 32-bit boundary,
+		 * In order for the struct_size to fall on a 32-bit boundary,
 		 *  calculate the length of the string and expand the
-		 *  Struct_size to the next 32-bit boundary.
+		 *  struct_size to the next 32-bit boundary.
 		 */
 		temp8 = (u8) (index + 1);
-		struct_size += ACPI_ROUND_UP_TO_32_bITS (temp8);
+		struct_size += ACPI_ROUND_UP_to_32_bITS (temp8);
 	}
 	else {
 		output_struct->data.address32.resource_source.index = 0x00;
@@ -633,12 +632,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_address32_stream
+ * FUNCTION:    acpi_rs_address32_stream
  *
- * PARAMETERS:  Linked_list             - Pointer to the resource linked list
- *              Output_buffer           - Pointer to the user's return buffer
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        used in the Output_buffer is returned
+ * PARAMETERS:  linked_list             - Pointer to the resource linked list
+ *              output_buffer           - Pointer to the user's return buffer
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        used in the output_buffer is returned
  *
  * RETURN:      Status
  *
@@ -651,7 +650,7 @@
 acpi_rs_address32_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed)
+	acpi_size               *bytes_consumed)
 {
 	u8                      *buffer;
 	u16                     *length_field;
@@ -659,7 +658,7 @@
 	char                    *temp_pointer;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_address32_stream");
+	ACPI_FUNCTION_TRACE ("rs_address32_stream");
 
 
 	buffer = *output_buffer;
@@ -677,7 +676,7 @@
 	buffer += 2;
 
 	/*
-	 * Set the Resource Type (Memory, Io, Bus_number)
+	 * Set the Resource Type (Memory, Io, bus_number)
 	 */
 	temp8 = (u8) (linked_list->data.address32.resource_type & 0x03);
 
@@ -793,21 +792,21 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_address64_resource
+ * FUNCTION:    acpi_rs_address64_resource
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
  *                                        stream
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        consumed the Byte_stream_buffer is
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        consumed the byte_stream_buffer is
  *                                        returned
- *              Output_buffer           - Pointer to the return data buffer
- *              Structure_size          - Pointer to where the number of bytes
+ *              output_buffer           - Pointer to the return data buffer
+ *              structure_size          - Pointer to where the number of bytes
  *                                        in the return data struct is returned
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
- *              structure pointed to by the Output_buffer. Return the
+ *              structure pointed to by the output_buffer. Return the
  *              number of bytes consumed from the byte stream.
  *
  ******************************************************************************/
@@ -815,20 +814,20 @@
 acpi_status
 acpi_rs_address64_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size)
+	acpi_size               *structure_size)
 {
 	u8                      *buffer;
 	acpi_resource           *output_struct = (void *) *output_buffer;
 	u16                     temp16;
 	u8                      temp8;
 	u8                      *temp_ptr;
-	ACPI_SIZE               struct_size;
+	acpi_size               struct_size;
 	u32                     index;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_address64_resource");
+	ACPI_FUNCTION_TRACE ("rs_address64_resource");
 
 
 	buffer = byte_stream_buffer;
@@ -902,7 +901,7 @@
 				(u16) (temp8 & 0x03);
 		}
 		else {
-			/* BUS_NUMBER_RANGE == Output_struct->Data.Address64.Resource_type */
+			/* BUS_NUMBER_RANGE == output_struct->Data.Address64.resource_type */
 			/* Nothing needs to be filled in */
 		}
 	}
@@ -915,28 +914,28 @@
 			 buffer);
 
 	/*
-	 * Get Min_address_range (Bytes 14-21)
+	 * Get min_address_range (Bytes 14-21)
 	 */
 	buffer += 8;
 	ACPI_MOVE_UNALIGNED64_TO_64 (&output_struct->data.address64.min_address_range,
 			 buffer);
 
 	/*
-	 * Get Max_address_range (Bytes 22-29)
+	 * Get max_address_range (Bytes 22-29)
 	 */
 	buffer += 8;
 	ACPI_MOVE_UNALIGNED64_TO_64 (&output_struct->data.address64.max_address_range,
 			 buffer);
 
 	/*
-	 * Get Address_translation_offset (Bytes 30-37)
+	 * Get address_translation_offset (Bytes 30-37)
 	 */
 	buffer += 8;
 	ACPI_MOVE_UNALIGNED64_TO_64 (&output_struct->data.address64.address_translation_offset,
 			 buffer);
 
 	/*
-	 * Get Address_length (Bytes 38-45)
+	 * Get address_length (Bytes 38-45)
 	 */
 	buffer += 8;
 	ACPI_MOVE_UNALIGNED64_TO_64 (&output_struct->data.address64.address_length,
@@ -991,12 +990,12 @@
 		output_struct->data.address64.resource_source.string_length = index + 1;
 
 		/*
-		 * In order for the Struct_size to fall on a 32-bit boundary,
+		 * In order for the struct_size to fall on a 32-bit boundary,
 		 * calculate the length of the string and expand the
-		 * Struct_size to the next 32-bit boundary.
+		 * struct_size to the next 32-bit boundary.
 		 */
 		temp8 = (u8) (index + 1);
-		struct_size += ACPI_ROUND_UP_TO_32_bITS (temp8);
+		struct_size += ACPI_ROUND_UP_to_32_bITS (temp8);
 	}
 	else {
 		output_struct->data.address64.resource_source.index = 0x00;
@@ -1019,12 +1018,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_address64_stream
+ * FUNCTION:    acpi_rs_address64_stream
  *
- * PARAMETERS:  Linked_list             - Pointer to the resource linked list
- *              Output_buffer           - Pointer to the user's return buffer
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        used in the Output_buffer is returned
+ * PARAMETERS:  linked_list             - Pointer to the resource linked list
+ *              output_buffer           - Pointer to the user's return buffer
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        used in the output_buffer is returned
  *
  * RETURN:      Status
  *
@@ -1037,7 +1036,7 @@
 acpi_rs_address64_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed)
+	acpi_size               *bytes_consumed)
 {
 	u8                      *buffer;
 	u16                     *length_field;
@@ -1045,7 +1044,7 @@
 	char                    *temp_pointer;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_address64_stream");
+	ACPI_FUNCTION_TRACE ("rs_address64_stream");
 
 
 	buffer = *output_buffer;
@@ -1064,7 +1063,7 @@
 	buffer += 2;
 
 	/*
-	 * Set the Resource Type (Memory, Io, Bus_number)
+	 * Set the Resource Type (Memory, Io, bus_number)
 	 */
 	temp8 = (u8) (linked_list->data.address64.resource_type & 0x03);
 
diff -Nru a/drivers/acpi/resources/rscalc.c b/drivers/acpi/resources/rscalc.c
--- a/drivers/acpi/resources/rscalc.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/acpi/resources/rscalc.c	Mon Dec 23 21:21:55 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: rscalc - Calculate stream and list lengths
- *              $Revision: 45 $
  *
  ******************************************************************************/
 
@@ -35,10 +34,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_get_byte_stream_length
+ * FUNCTION:    acpi_rs_get_byte_stream_length
  *
- * PARAMETERS:  Linked_list         - Pointer to the resource linked list
- *              Size_needed         - u32 pointer of the size buffer needed
+ * PARAMETERS:  linked_list         - Pointer to the resource linked list
+ *              size_needed         - u32 pointer of the size buffer needed
  *                                    to properly return the parsed data
  *
  * RETURN:      Status
@@ -52,15 +51,15 @@
 acpi_status
 acpi_rs_get_byte_stream_length (
 	acpi_resource           *linked_list,
-	ACPI_SIZE               *size_needed)
+	acpi_size               *size_needed)
 {
-	ACPI_SIZE               byte_stream_size_needed = 0;
-	ACPI_SIZE               segment_size;
+	acpi_size               byte_stream_size_needed = 0;
+	acpi_size               segment_size;
 	acpi_resource_ext_irq   *ex_irq = NULL;
 	u8                      done = FALSE;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_get_byte_stream_length");
+	ACPI_FUNCTION_TRACE ("rs_get_byte_stream_length");
 
 
 	while (!done) {
@@ -90,7 +89,7 @@
 		case ACPI_RSTYPE_START_DPF:
 			/*
 			 * Start Dependent Functions Resource
-			 * For a Start_dependent_functions Resource, Byte 1,
+			 * For a start_dependent_functions Resource, Byte 1,
 			 * although optional, will always be created.
 			 */
 			segment_size = 2;
@@ -229,7 +228,7 @@
 			 * Resource Source + 1 for the null.
 			 */
 			segment_size = 9 +
-				(((ACPI_SIZE) linked_list->data.extended_irq.number_of_interrupts - 1) * 4);
+				(((acpi_size) linked_list->data.extended_irq.number_of_interrupts - 1) * 4);
 
 			if (ex_irq && ex_irq->resource_source.string_ptr) {
 				segment_size += linked_list->data.extended_irq.resource_source.string_length;
@@ -244,7 +243,7 @@
 			 */
 			return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
 
-		} /* switch (Linked_list->Id) */
+		} /* switch (linked_list->Id) */
 
 		/*
 		 * Update the total
@@ -268,11 +267,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_get_list_length
+ * FUNCTION:    acpi_rs_get_list_length
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource byte stream
- *              Byte_stream_buffer_length - Size of Byte_stream_buffer
- *              Size_needed             - u32 pointer of the size buffer
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource byte stream
+ *              byte_stream_buffer_length - Size of byte_stream_buffer
+ *              size_needed             - u32 pointer of the size buffer
  *                                        needed to properly return the
  *                                        parsed data
  *
@@ -288,7 +287,7 @@
 acpi_rs_get_list_length (
 	u8                      *byte_stream_buffer,
 	u32                     byte_stream_buffer_length,
-	ACPI_SIZE               *size_needed)
+	acpi_size               *size_needed)
 {
 	u32                     buffer_size = 0;
 	u32                     bytes_parsed = 0;
@@ -304,7 +303,7 @@
 	u8                      additional_bytes;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_get_list_length");
+	ACPI_FUNCTION_TRACE ("rs_get_list_length");
 
 
 	while (bytes_parsed < byte_stream_buffer_length) {
@@ -337,7 +336,7 @@
 			/*
 			 * Ensure a 32-bit boundary for the structure
 			 */
-			temp16 = (u16) ACPI_ROUND_UP_TO_32_bITS (temp16);
+			temp16 = (u16) ACPI_ROUND_UP_to_32_bITS (temp16);
 
 			structure_size = ACPI_SIZEOF_RESOURCE (acpi_resource_vendor) +
 					   (temp16 * sizeof (u8));
@@ -396,7 +395,7 @@
 			/*
 			 * Ensure a 64-bit boundary for the structure
 			 */
-			temp8 = (u8) ACPI_ROUND_UP_TO_64_bITS (temp8);
+			temp8 = (u8) ACPI_ROUND_UP_to_64_bITS (temp8);
 
 			structure_size = ACPI_SIZEOF_RESOURCE (acpi_resource_address64) +
 					   (temp8 * sizeof (u8));
@@ -434,7 +433,7 @@
 			/*
 			 * Ensure a 32-bit boundary for the structure
 			 */
-			temp8 = (u8) ACPI_ROUND_UP_TO_32_bITS (temp8);
+			temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8);
 
 			structure_size = ACPI_SIZEOF_RESOURCE (acpi_resource_address32) +
 					   (temp8 * sizeof (u8));
@@ -472,7 +471,7 @@
 			/*
 			 * Ensure a 32-bit boundary for the structure
 			 */
-			temp8 = (u8) ACPI_ROUND_UP_TO_32_bITS (temp8);
+			temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8);
 
 			structure_size = ACPI_SIZEOF_RESOURCE (acpi_resource_address16) +
 					   (temp8 * sizeof (u8));
@@ -524,7 +523,7 @@
 			/*
 			 * Ensure a 32-bit boundary for the structure
 			 */
-			temp8 = (u8) ACPI_ROUND_UP_TO_32_bITS (temp8);
+			temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8);
 
 			structure_size = ACPI_SIZEOF_RESOURCE (acpi_resource_ext_irq) +
 					   (additional_bytes * sizeof (u8)) +
@@ -659,7 +658,7 @@
 			/*
 			 * Ensure a 32-bit boundary for the structure
 			 */
-			temp8 = (u8) ACPI_ROUND_UP_TO_32_bITS (temp8);
+			temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8);
 			structure_size = ACPI_SIZEOF_RESOURCE (acpi_resource_vendor) +
 					   (temp8 * sizeof (u8));
 			break;
@@ -705,10 +704,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_get_pci_routing_table_length
+ * FUNCTION:    acpi_rs_get_pci_routing_table_length
  *
- * PARAMETERS:  Package_object          - Pointer to the package object
- *              Buffer_size_needed      - u32 pointer of the size buffer
+ * PARAMETERS:  package_object          - Pointer to the package object
+ *              buffer_size_needed      - u32 pointer of the size buffer
  *                                        needed to properly return the
  *                                        parsed data
  *
@@ -723,10 +722,10 @@
 acpi_status
 acpi_rs_get_pci_routing_table_length (
 	acpi_operand_object     *package_object,
-	ACPI_SIZE               *buffer_size_needed)
+	acpi_size               *buffer_size_needed)
 {
 	u32                     number_of_elements;
-	ACPI_SIZE               temp_size_needed = 0;
+	acpi_size               temp_size_needed = 0;
 	acpi_operand_object     **top_object_list;
 	u32                     index;
 	acpi_operand_object     *package_element;
@@ -735,7 +734,7 @@
 	u32                     table_index;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_get_pci_routing_table_length");
+	ACPI_FUNCTION_TRACE ("rs_get_pci_routing_table_length");
 
 
 	number_of_elements = package_object->package.count;
@@ -759,13 +758,13 @@
 		package_element = *top_object_list;
 
 		/*
-		 * The Sub_object_list will now point to an array of the
-		 * four IRQ elements: Address, Pin, Source and Source_index
+		 * The sub_object_list will now point to an array of the
+		 * four IRQ elements: Address, Pin, Source and source_index
 		 */
 		sub_object_list = package_element->package.elements;
 
 		/*
-		 * Scan the Irq_table_elements for the Source Name String
+		 * Scan the irq_table_elements for the Source Name String
 		 */
 		name_found = FALSE;
 
@@ -811,7 +810,7 @@
 
 		/* Round up the size since each element must be aligned */
 
-		temp_size_needed = ACPI_ROUND_UP_TO_64_bITS (temp_size_needed);
+		temp_size_needed = ACPI_ROUND_UP_to_64_bITS (temp_size_needed);
 
 		/*
 		 * Point to the next acpi_operand_object
diff -Nru a/drivers/acpi/resources/rscreate.c b/drivers/acpi/resources/rscreate.c
--- a/drivers/acpi/resources/rscreate.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/acpi/resources/rscreate.c	Mon Dec 23 21:21:53 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: rscreate - Create resource lists/tables
- *              $Revision: 63 $
  *
  ******************************************************************************/
 
@@ -35,15 +34,15 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_create_resource_list
+ * FUNCTION:    acpi_rs_create_resource_list
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource byte stream
- *              Output_buffer           - Pointer to the user's buffer
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource byte stream
+ *              output_buffer           - Pointer to the user's buffer
  *
  * RETURN:      Status  - AE_OK if okay, else a valid acpi_status code
- *              If Output_buffer is not large enough, Output_buffer_length
- *              indicates how large Output_buffer should be, else it
- *              indicates how may u8 elements of Output_buffer are valid.
+ *              If output_buffer is not large enough, output_buffer_length
+ *              indicates how large output_buffer should be, else it
+ *              indicates how may u8 elements of output_buffer are valid.
  *
  * DESCRIPTION: Takes the byte stream returned from a _CRS, _PRS control method
  *              execution and parses the stream to create a linked list
@@ -59,14 +58,14 @@
 
 	acpi_status             status;
 	u8                      *byte_stream_start;
-	ACPI_SIZE               list_size_needed = 0;
+	acpi_size               list_size_needed = 0;
 	u32                     byte_stream_buffer_length;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_create_resource_list");
+	ACPI_FUNCTION_TRACE ("rs_create_resource_list");
 
 
-	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Byte_stream_buffer = %p\n",
+	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "byte_stream_buffer = %p\n",
 		byte_stream_buffer));
 
 	/*
@@ -76,13 +75,13 @@
 	byte_stream_start = byte_stream_buffer->buffer.pointer;
 
 	/*
-	 * Pass the Byte_stream_buffer into a module that can calculate
+	 * Pass the byte_stream_buffer into a module that can calculate
 	 * the buffer size needed for the linked list
 	 */
 	status = acpi_rs_get_list_length (byte_stream_start, byte_stream_buffer_length,
 			 &list_size_needed);
 
-	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Status=%X List_size_needed=%X\n",
+	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Status=%X list_size_needed=%X\n",
 		status, (u32) list_size_needed));
 	if (ACPI_FAILURE (status)) {
 		return_ACPI_STATUS (status);
@@ -103,7 +102,7 @@
 		return_ACPI_STATUS (status);
 	}
 
-	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Output_buffer %p Length %X\n",
+	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "output_buffer %p Length %X\n",
 			output_buffer->pointer, (u32) output_buffer->length));
 	return_ACPI_STATUS (AE_OK);
 }
@@ -111,15 +110,15 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_create_pci_routing_table
+ * FUNCTION:    acpi_rs_create_pci_routing_table
  *
- * PARAMETERS:  Package_object          - Pointer to an acpi_operand_object
+ * PARAMETERS:  package_object          - Pointer to an acpi_operand_object
  *                                        package
- *              Output_buffer           - Pointer to the user's buffer
+ *              output_buffer           - Pointer to the user's buffer
  *
  * RETURN:      Status  AE_OK if okay, else a valid acpi_status code.
- *              If the Output_buffer is too small, the error will be
- *              AE_BUFFER_OVERFLOW and Output_buffer->Length will point
+ *              If the output_buffer is too small, the error will be
+ *              AE_BUFFER_OVERFLOW and output_buffer->Length will point
  *              to the size buffer needed.
  *
  * DESCRIPTION: Takes the acpi_operand_object  package and creates a
@@ -139,7 +138,7 @@
 	acpi_operand_object     **top_object_list;
 	acpi_operand_object     **sub_object_list;
 	acpi_operand_object     *obj_desc;
-	ACPI_SIZE               buffer_size_needed = 0;
+	acpi_size               buffer_size_needed = 0;
 	u32                     number_of_elements;
 	u32                     index;
 	acpi_pci_routing_table  *user_prt;
@@ -148,7 +147,7 @@
 	acpi_buffer             path_buffer;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_create_pci_routing_table");
+	ACPI_FUNCTION_TRACE ("rs_create_pci_routing_table");
 
 
 	/* Params already validated, so we don't re-validate here */
@@ -162,7 +161,7 @@
 		return_ACPI_STATUS (status);
 	}
 
-	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Buffer_size_needed = %X\n",
+	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "buffer_size_needed = %X\n",
 		(u32) buffer_size_needed));
 
 	/* Validate/Allocate/Clear caller buffer */
@@ -175,7 +174,7 @@
 	/*
 	 * Loop through the ACPI_INTERNAL_OBJECTS - Each object
 	 * should be a package that in turn contains an
-	 * acpi_integer Address, a u8 Pin, a Name and a u8 Source_index.
+	 * acpi_integer Address, a u8 Pin, a Name and a u8 source_index.
 	 */
 	top_object_list  = package_object->package.elements;
 	number_of_elements = package_object->package.count;
@@ -184,9 +183,9 @@
 
 	for (index = 0; index < number_of_elements; index++) {
 		/*
-		 * Point User_prt past this current structure
+		 * Point user_prt past this current structure
 		 *
-		 * NOTE: On the first iteration, User_prt->Length will
+		 * NOTE: On the first iteration, user_prt->Length will
 		 * be zero because we cleared the return buffer earlier
 		 */
 		buffer += user_prt->length;
@@ -220,8 +219,8 @@
 
 		/*
 		 * Dereference the sub-package.
-		 * The Sub_object_list will now point to an array of the four IRQ
-		 * elements: [Address, Pin, Source, Source_index]
+		 * The sub_object_list will now point to an array of the four IRQ
+		 * elements: [Address, Pin, Source, source_index]
 		 */
 		sub_object_list = (*top_object_list)->package.elements;
 
@@ -254,7 +253,7 @@
 		}
 
 		/*
-		 * 3) Third subobject: Dereference the PRT.Source_name
+		 * 3) Third subobject: Dereference the PRT.source_name
 		 */
 		obj_desc = sub_object_list[2];
 		switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
@@ -313,10 +312,10 @@
 
 		/* Now align the current length */
 
-		user_prt->length = ACPI_ROUND_UP_TO_64_bITS (user_prt->length);
+		user_prt->length = ACPI_ROUND_UP_to_64_bITS (user_prt->length);
 
 		/*
-		 * 4) Fourth subobject: Dereference the PRT.Source_index
+		 * 4) Fourth subobject: Dereference the PRT.source_index
 		 */
 		obj_desc = sub_object_list[3];
 		if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) {
@@ -324,7 +323,7 @@
 		}
 		else {
 			ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
-				"(PRT[%X].Source_index) Need Integer, found %s\n",
+				"(PRT[%X].source_index) Need Integer, found %s\n",
 				index, acpi_ut_get_object_type_name (obj_desc)));
 			return_ACPI_STATUS (AE_BAD_DATA);
 		}
@@ -334,7 +333,7 @@
 		top_object_list++;
 	}
 
-	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Output_buffer %p Length %X\n",
+	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "output_buffer %p Length %X\n",
 			output_buffer->pointer, (u32) output_buffer->length));
 	return_ACPI_STATUS (AE_OK);
 }
@@ -342,14 +341,14 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_create_byte_stream
+ * FUNCTION:    acpi_rs_create_byte_stream
  *
- * PARAMETERS:  Linked_list_buffer      - Pointer to the resource linked list
- *              Output_buffer           - Pointer to the user's buffer
+ * PARAMETERS:  linked_list_buffer      - Pointer to the resource linked list
+ *              output_buffer           - Pointer to the user's buffer
  *
  * RETURN:      Status  AE_OK if okay, else a valid acpi_status code.
- *              If the Output_buffer is too small, the error will be
- *              AE_BUFFER_OVERFLOW and Output_buffer->Length will point
+ *              If the output_buffer is too small, the error will be
+ *              AE_BUFFER_OVERFLOW and output_buffer->Length will point
  *              to the size buffer needed.
  *
  * DESCRIPTION: Takes the linked list of device resources and
@@ -364,25 +363,25 @@
 	acpi_buffer             *output_buffer)
 {
 	acpi_status             status;
-	ACPI_SIZE               byte_stream_size_needed = 0;
+	acpi_size               byte_stream_size_needed = 0;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_create_byte_stream");
+	ACPI_FUNCTION_TRACE ("rs_create_byte_stream");
 
 
-	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Linked_list_buffer = %p\n",
+	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "linked_list_buffer = %p\n",
 		linked_list_buffer));
 
 	/*
 	 * Params already validated, so we don't re-validate here
 	 *
-	 * Pass the Linked_list_buffer into a module that calculates
+	 * Pass the linked_list_buffer into a module that calculates
 	 * the buffer size needed for the byte stream.
 	 */
 	status = acpi_rs_get_byte_stream_length (linked_list_buffer,
 			 &byte_stream_size_needed);
 
-	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Byte_stream_size_needed=%X, %s\n",
+	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "byte_stream_size_needed=%X, %s\n",
 		(u32) byte_stream_size_needed, acpi_format_exception (status)));
 	if (ACPI_FAILURE (status)) {
 		return_ACPI_STATUS (status);
@@ -403,7 +402,7 @@
 		return_ACPI_STATUS (status);
 	}
 
-	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Output_buffer %p Length %X\n",
+	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "output_buffer %p Length %X\n",
 			output_buffer->pointer, (u32) output_buffer->length));
 	return_ACPI_STATUS (AE_OK);
 }
diff -Nru a/drivers/acpi/resources/rsdump.c b/drivers/acpi/resources/rsdump.c
--- a/drivers/acpi/resources/rsdump.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/acpi/resources/rsdump.c	Mon Dec 23 21:21:55 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: rsdump - Functions to display the resource structures.
- *              $Revision: 34 $
  *
  ******************************************************************************/
 
@@ -35,7 +34,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_dump_irq
+ * FUNCTION:    acpi_rs_dump_irq
  *
  * PARAMETERS:  Data            - pointer to the resource structure to dump.
  *
@@ -80,7 +79,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_dump_dma
+ * FUNCTION:    acpi_rs_dump_dma
  *
  * PARAMETERS:  Data            - pointer to the resource structure to dump.
  *
@@ -160,7 +159,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_dump_start_depend_fns
+ * FUNCTION:    acpi_rs_dump_start_depend_fns
  *
  * PARAMETERS:  Data            - pointer to the resource structure to dump.
  *
@@ -225,7 +224,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_dump_io
+ * FUNCTION:    acpi_rs_dump_io
  *
  * PARAMETERS:  Data            - pointer to the resource structure to dump.
  *
@@ -268,7 +267,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_dump_fixed_io
+ * FUNCTION:    acpi_rs_dump_fixed_io
  *
  * PARAMETERS:  Data            - pointer to the resource structure to dump.
  *
@@ -301,7 +300,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_dump_vendor_specific
+ * FUNCTION:    acpi_rs_dump_vendor_specific
  *
  * PARAMETERS:  Data            - pointer to the resource structure to dump.
  *
@@ -337,7 +336,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_dump_memory24
+ * FUNCTION:    acpi_rs_dump_memory24
  *
  * PARAMETERS:  Data            - pointer to the resource structure to dump.
  *
@@ -382,7 +381,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_dump_memory32
+ * FUNCTION:    acpi_rs_dump_memory32
  *
  * PARAMETERS:  Data            - pointer to the resource structure to dump.
  *
@@ -427,7 +426,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_dump_fixed_memory32
+ * FUNCTION:    acpi_rs_dump_fixed_memory32
  *
  * PARAMETERS:  Data            - pointer to the resource structure to dump.
  *
@@ -466,7 +465,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_dump_address16
+ * FUNCTION:    acpi_rs_dump_address16
  *
  * PARAMETERS:  Data            - pointer to the resource structure to dump.
  *
@@ -609,7 +608,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_dump_address32
+ * FUNCTION:    acpi_rs_dump_address32
  *
  * PARAMETERS:  Data            - pointer to the resource structure to dump.
  *
@@ -751,7 +750,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_dump_address64
+ * FUNCTION:    acpi_rs_dump_address64
  *
  * PARAMETERS:  Data            - pointer to the resource structure to dump.
  *
@@ -898,7 +897,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_dump_extended_irq
+ * FUNCTION:    acpi_rs_dump_extended_irq
  *
  * PARAMETERS:  Data            - pointer to the resource structure to dump.
  *
@@ -959,7 +958,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_dump_resource_list
+ * FUNCTION:    acpi_rs_dump_resource_list
  *
  * PARAMETERS:  Data            - pointer to the resource structure to dump.
  *
@@ -998,8 +997,8 @@
 				break;
 
 			case ACPI_RSTYPE_END_DPF:
-				acpi_os_printf ("End_dependent_functions Resource\n");
-				/* Acpi_rs_dump_end_dependent_functions (Resource->Data);*/
+				acpi_os_printf ("end_dependent_functions Resource\n");
+				/* acpi_rs_dump_end_dependent_functions (Resource->Data);*/
 				break;
 
 			case ACPI_RSTYPE_IO:
@@ -1015,8 +1014,8 @@
 				break;
 
 			case ACPI_RSTYPE_END_TAG:
-				/*Rs_dump_end_tag (Resource->Data);*/
-				acpi_os_printf ("End_tag Resource\n");
+				/*rs_dump_end_tag (Resource->Data);*/
+				acpi_os_printf ("end_tag Resource\n");
 				done = TRUE;
 				break;
 
@@ -1063,7 +1062,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_dump_irq_list
+ * FUNCTION:    acpi_rs_dump_irq_list
  *
  * PARAMETERS:  Data            - pointer to the routing table to dump.
  *
@@ -1100,7 +1099,7 @@
 
 			acpi_os_printf ("  Source: %s\n", prt_element->source);
 
-			acpi_os_printf ("  Source_index: %X\n",
+			acpi_os_printf ("  source_index: %X\n",
 					 prt_element->source_index);
 
 			buffer += prt_element->length;
diff -Nru a/drivers/acpi/resources/rsio.c b/drivers/acpi/resources/rsio.c
--- a/drivers/acpi/resources/rsio.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/acpi/resources/rsio.c	Mon Dec 23 21:21:50 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: rsio - IO and DMA resource descriptors
- *              $Revision: 22 $
  *
  ******************************************************************************/
 
@@ -33,21 +32,21 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_io_resource
+ * FUNCTION:    acpi_rs_io_resource
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
  *                                        stream
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        consumed the Byte_stream_buffer is
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        consumed the byte_stream_buffer is
  *                                        returned
- *              Output_buffer           - Pointer to the return data buffer
- *              Structure_size          - Pointer to where the number of bytes
+ *              output_buffer           - Pointer to the return data buffer
+ *              structure_size          - Pointer to where the number of bytes
  *                                        in the return data struct is returned
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
- *              structure pointed to by the Output_buffer. Return the
+ *              structure pointed to by the output_buffer. Return the
  *              number of bytes consumed from the byte stream.
  *
  ******************************************************************************/
@@ -55,18 +54,18 @@
 acpi_status
 acpi_rs_io_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size)
+	acpi_size               *structure_size)
 {
 	u8                      *buffer = byte_stream_buffer;
 	acpi_resource           *output_struct = (void *) *output_buffer;
 	u16                     temp16 = 0;
 	u8                      temp8 = 0;
-	ACPI_SIZE               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_io);
+	acpi_size               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_io);
 
 
-	ACPI_FUNCTION_TRACE ("Rs_io_resource");
+	ACPI_FUNCTION_TRACE ("rs_io_resource");
 
 
 	/*
@@ -85,7 +84,7 @@
 	output_struct->data.io.io_decode = temp8 & 0x01;
 
 	/*
-	 * Check Min_base Address
+	 * Check min_base Address
 	 */
 	buffer += 1;
 	ACPI_MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
@@ -93,7 +92,7 @@
 	output_struct->data.io.min_base_address = temp16;
 
 	/*
-	 * Check Max_base Address
+	 * Check max_base Address
 	 */
 	buffer += 2;
 	ACPI_MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
@@ -109,7 +108,7 @@
 	output_struct->data.io.alignment = temp8;
 
 	/*
-	 * Check Range_length
+	 * Check range_length
 	 */
 	buffer += 1;
 	temp8 = *buffer;
@@ -131,21 +130,21 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_fixed_io_resource
+ * FUNCTION:    acpi_rs_fixed_io_resource
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
  *                                        stream
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        consumed the Byte_stream_buffer is
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        consumed the byte_stream_buffer is
  *                                        returned
- *              Output_buffer           - Pointer to the return data buffer
- *              Structure_size          - Pointer to where the number of bytes
+ *              output_buffer           - Pointer to the return data buffer
+ *              structure_size          - Pointer to where the number of bytes
  *                                        in the return data struct is returned
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
- *              structure pointed to by the Output_buffer. Return the
+ *              structure pointed to by the output_buffer. Return the
  *              number of bytes consumed from the byte stream.
  *
  ******************************************************************************/
@@ -153,18 +152,18 @@
 acpi_status
 acpi_rs_fixed_io_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size)
+	acpi_size               *structure_size)
 {
 	u8                      *buffer = byte_stream_buffer;
 	acpi_resource           *output_struct = (void *) *output_buffer;
 	u16                     temp16 = 0;
 	u8                      temp8 = 0;
-	ACPI_SIZE               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_fixed_io);
+	acpi_size               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_fixed_io);
 
 
-	ACPI_FUNCTION_TRACE ("Rs_fixed_io_resource");
+	ACPI_FUNCTION_TRACE ("rs_fixed_io_resource");
 
 
 	/*
@@ -183,7 +182,7 @@
 	output_struct->data.fixed_io.base_address = temp16;
 
 	/*
-	 * Check Range_length
+	 * Check range_length
 	 */
 	buffer += 2;
 	temp8 = *buffer;
@@ -205,12 +204,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_io_stream
+ * FUNCTION:    acpi_rs_io_stream
  *
- * PARAMETERS:  Linked_list             - Pointer to the resource linked list
- *              Output_buffer           - Pointer to the user's return buffer
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        used in the Output_buffer is returned
+ * PARAMETERS:  linked_list             - Pointer to the resource linked list
+ *              output_buffer           - Pointer to the user's return buffer
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        used in the output_buffer is returned
  *
  * RETURN:      Status
  *
@@ -223,14 +222,14 @@
 acpi_rs_io_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed)
+	acpi_size               *bytes_consumed)
 {
 	u8                      *buffer = *output_buffer;
 	u16                     temp16 = 0;
 	u8                      temp8 = 0;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_io_stream");
+	ACPI_FUNCTION_TRACE ("rs_io_stream");
 
 
 	/*
@@ -289,12 +288,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_fixed_io_stream
+ * FUNCTION:    acpi_rs_fixed_io_stream
  *
- * PARAMETERS:  Linked_list             - Pointer to the resource linked list
- *              Output_buffer           - Pointer to the user's return buffer
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        used in the Output_buffer is returned
+ * PARAMETERS:  linked_list             - Pointer to the resource linked list
+ *              output_buffer           - Pointer to the user's return buffer
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        used in the output_buffer is returned
  *
  * RETURN:      Status
  *
@@ -307,14 +306,14 @@
 acpi_rs_fixed_io_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed)
+	acpi_size               *bytes_consumed)
 {
 	u8                      *buffer = *output_buffer;
 	u16                     temp16 = 0;
 	u8                      temp8 = 0;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_fixed_io_stream");
+	ACPI_FUNCTION_TRACE ("rs_fixed_io_stream");
 
 
 	/*
@@ -350,21 +349,21 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_dma_resource
+ * FUNCTION:    acpi_rs_dma_resource
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
  *                                        stream
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        consumed the Byte_stream_buffer is
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        consumed the byte_stream_buffer is
  *                                        returned
- *              Output_buffer           - Pointer to the return data buffer
- *              Structure_size          - Pointer to where the number of bytes
+ *              output_buffer           - Pointer to the return data buffer
+ *              structure_size          - Pointer to where the number of bytes
  *                                        in the return data struct is returned
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
- *              structure pointed to by the Output_buffer. Return the
+ *              structure pointed to by the output_buffer. Return the
  *              number of bytes consumed from the byte stream.
  *
  ******************************************************************************/
@@ -372,19 +371,19 @@
 acpi_status
 acpi_rs_dma_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size)
+	acpi_size               *structure_size)
 {
 	u8                      *buffer = byte_stream_buffer;
 	acpi_resource           *output_struct = (void *) *output_buffer;
 	u8                      temp8 = 0;
 	u8                      index;
 	u8                      i;
-	ACPI_SIZE               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_dma);
+	acpi_size               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_dma);
 
 
-	ACPI_FUNCTION_TRACE ("Rs_dma_resource");
+	ACPI_FUNCTION_TRACE ("rs_dma_resource");
 
 
 	/*
@@ -415,7 +414,7 @@
 		/*
 		 * Calculate the structure size based upon the number of interrupts
 		 */
-		struct_size += ((ACPI_SIZE) i - 1) * 4;
+		struct_size += ((acpi_size) i - 1) * 4;
 	}
 
 	/*
@@ -459,12 +458,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_dma_stream
+ * FUNCTION:    acpi_rs_dma_stream
  *
- * PARAMETERS:  Linked_list             - Pointer to the resource linked list
- *              Output_buffer           - Pointer to the user's return buffer
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        used in the Output_buffer is returned
+ * PARAMETERS:  linked_list             - Pointer to the resource linked list
+ *              output_buffer           - Pointer to the user's return buffer
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        used in the output_buffer is returned
  *
  * RETURN:      Status
  *
@@ -477,7 +476,7 @@
 acpi_rs_dma_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed)
+	acpi_size               *bytes_consumed)
 {
 	u8                      *buffer = *output_buffer;
 	u16                     temp16 = 0;
@@ -485,7 +484,7 @@
 	u8                      index;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_dma_stream");
+	ACPI_FUNCTION_TRACE ("rs_dma_stream");
 
 
 	/*
diff -Nru a/drivers/acpi/resources/rsirq.c b/drivers/acpi/resources/rsirq.c
--- a/drivers/acpi/resources/rsirq.c	Mon Dec 23 21:22:02 2002
+++ b/drivers/acpi/resources/rsirq.c	Mon Dec 23 21:22:02 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: rsirq - IRQ resource descriptors
- *              $Revision: 31 $
  *
  ******************************************************************************/
 
@@ -33,21 +32,21 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_irq_resource
+ * FUNCTION:    acpi_rs_irq_resource
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
  *                                        stream
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        consumed the Byte_stream_buffer is
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        consumed the byte_stream_buffer is
  *                                        returned
- *              Output_buffer           - Pointer to the return data buffer
- *              Structure_size          - Pointer to where the number of bytes
+ *              output_buffer           - Pointer to the return data buffer
+ *              structure_size          - Pointer to where the number of bytes
  *                                        in the return data struct is returned
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
- *              structure pointed to by the Output_buffer. Return the
+ *              structure pointed to by the output_buffer. Return the
  *              number of bytes consumed from the byte stream.
  *
  ******************************************************************************/
@@ -55,9 +54,9 @@
 acpi_status
 acpi_rs_irq_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size)
+	acpi_size               *structure_size)
 {
 	u8                      *buffer = byte_stream_buffer;
 	acpi_resource           *output_struct = (void *) *output_buffer;
@@ -65,10 +64,10 @@
 	u8                      temp8 = 0;
 	u8                      index;
 	u8                      i;
-	ACPI_SIZE               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_irq);
+	acpi_size               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_irq);
 
 
-	ACPI_FUNCTION_TRACE ("Rs_irq_resource");
+	ACPI_FUNCTION_TRACE ("rs_irq_resource");
 
 
 	/*
@@ -103,7 +102,7 @@
 		/*
 		 * Calculate the structure size based upon the number of interrupts
 		 */
-		struct_size += ((ACPI_SIZE) i - 1) * 4;
+		struct_size += ((acpi_size) i - 1) * 4;
 	}
 
 	/*
@@ -166,12 +165,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_irq_stream
+ * FUNCTION:    acpi_rs_irq_stream
  *
- * PARAMETERS:  Linked_list             - Pointer to the resource linked list
- *              Output_buffer           - Pointer to the user's return buffer
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        used in the Output_buffer is returned
+ * PARAMETERS:  linked_list             - Pointer to the resource linked list
+ *              output_buffer           - Pointer to the user's return buffer
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        used in the output_buffer is returned
  *
  * RETURN:      Status
  *
@@ -184,16 +183,16 @@
 acpi_rs_irq_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed)
+	acpi_size               *bytes_consumed)
 {
 	u8                      *buffer = *output_buffer;
 	u16                     temp16 = 0;
 	u8                      temp8 = 0;
 	u8                      index;
-	u8                      IRQinfo_byte_needed;
+	u8                      IRqinfo_byte_needed;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_irq_stream");
+	ACPI_FUNCTION_TRACE ("rs_irq_stream");
 
 
 	/*
@@ -204,11 +203,11 @@
 		ACPI_ACTIVE_HIGH == linked_list->data.irq.active_high_low &&
 		ACPI_EXCLUSIVE == linked_list->data.irq.shared_exclusive) {
 		*buffer = 0x22;
-		IRQinfo_byte_needed = FALSE;
+		IRqinfo_byte_needed = FALSE;
 	}
 	else {
 		*buffer = 0x23;
-		IRQinfo_byte_needed = TRUE;
+		IRqinfo_byte_needed = TRUE;
 	}
 
 	buffer += 1;
@@ -230,7 +229,7 @@
 	/*
 	 * Set the IRQ Info byte if needed.
 	 */
-	if (IRQinfo_byte_needed) {
+	if (IRqinfo_byte_needed) {
 		temp8 = 0;
 		temp8 = (u8) ((linked_list->data.irq.shared_exclusive &
 				 0x01) << 4);
@@ -257,21 +256,21 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_extended_irq_resource
+ * FUNCTION:    acpi_rs_extended_irq_resource
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
  *                                        stream
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        consumed the Byte_stream_buffer is
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        consumed the byte_stream_buffer is
  *                                        returned
- *              Output_buffer           - Pointer to the return data buffer
- *              Structure_size          - Pointer to where the number of bytes
+ *              output_buffer           - Pointer to the return data buffer
+ *              structure_size          - Pointer to where the number of bytes
  *                                        in the return data struct is returned
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
- *              structure pointed to by the Output_buffer. Return the
+ *              structure pointed to by the output_buffer. Return the
  *              number of bytes consumed from the byte stream.
  *
  ******************************************************************************/
@@ -279,9 +278,9 @@
 acpi_status
 acpi_rs_extended_irq_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size)
+	acpi_size               *structure_size)
 {
 	u8                      *buffer = byte_stream_buffer;
 	acpi_resource           *output_struct = (void *) *output_buffer;
@@ -289,10 +288,10 @@
 	u8                      temp8 = 0;
 	u8                      *temp_ptr;
 	u8                      index;
-	ACPI_SIZE               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_ext_irq);
+	acpi_size               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_ext_irq);
 
 
-	ACPI_FUNCTION_TRACE ("Rs_extended_irq_resource");
+	ACPI_FUNCTION_TRACE ("rs_extended_irq_resource");
 
 
 	/*
@@ -372,7 +371,7 @@
 	 * stream that are default.
 	 */
 	if (*bytes_consumed >
-		((ACPI_SIZE) output_struct->data.extended_irq.number_of_interrupts * 4) + 5) {
+		((acpi_size) output_struct->data.extended_irq.number_of_interrupts * 4) + 5) {
 		/* Dereference the Index */
 
 		temp8 = *buffer;
@@ -408,12 +407,12 @@
 		output_struct->data.extended_irq.resource_source.string_length = index + 1;
 
 		/*
-		 * In order for the Struct_size to fall on a 32-bit boundary,
+		 * In order for the struct_size to fall on a 32-bit boundary,
 		 * calculate the length of the string and expand the
-		 * Struct_size to the next 32-bit boundary.
+		 * struct_size to the next 32-bit boundary.
 		 */
 		temp8 = (u8) (index + 1);
-		struct_size += ACPI_ROUND_UP_TO_32_bITS (temp8);
+		struct_size += ACPI_ROUND_UP_to_32_bITS (temp8);
 	}
 	else {
 		output_struct->data.extended_irq.resource_source.index = 0x00;
@@ -436,12 +435,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_extended_irq_stream
+ * FUNCTION:    acpi_rs_extended_irq_stream
  *
- * PARAMETERS:  Linked_list             - Pointer to the resource linked list
- *              Output_buffer           - Pointer to the user's return buffer
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        used in the Output_buffer is returned
+ * PARAMETERS:  linked_list             - Pointer to the resource linked list
+ *              output_buffer           - Pointer to the user's return buffer
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        used in the output_buffer is returned
  *
  * RETURN:      Status
  *
@@ -454,7 +453,7 @@
 acpi_rs_extended_irq_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed)
+	acpi_size               *bytes_consumed)
 {
 	u8                      *buffer = *output_buffer;
 	u16                     *length_field;
@@ -463,7 +462,7 @@
 	char                    *temp_pointer = NULL;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_extended_irq_stream");
+	ACPI_FUNCTION_TRACE ("rs_extended_irq_stream");
 
 
 	/*
diff -Nru a/drivers/acpi/resources/rslist.c b/drivers/acpi/resources/rslist.c
--- a/drivers/acpi/resources/rslist.c	Mon Dec 23 21:22:02 2002
+++ b/drivers/acpi/resources/rslist.c	Mon Dec 23 21:22:02 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: rslist - Linked list utilities
- *              $Revision: 31 $
  *
  ******************************************************************************/
 
@@ -33,9 +32,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_get_resource_type
+ * FUNCTION:    acpi_rs_get_resource_type
  *
- * PARAMETERS:  Resource_start_byte     - Byte 0 of a resource descriptor
+ * PARAMETERS:  resource_start_byte     - Byte 0 of a resource descriptor
  *
  * RETURN:      The Resource Type (Name) with no extraneous bits
  *
@@ -83,11 +82,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_byte_stream_to_list
+ * FUNCTION:    acpi_rs_byte_stream_to_list
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource byte stream
- *              Byte_stream_buffer_length - Length of Byte_stream_buffer
- *              Output_buffer           - Pointer to the buffer that will
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource byte stream
+ *              byte_stream_buffer_length - Length of byte_stream_buffer
+ *              output_buffer           - Pointer to the buffer that will
  *                                        contain the output structures
  *
  * RETURN:      Status
@@ -104,15 +103,15 @@
 	u8                      *output_buffer)
 {
 	acpi_status             status;
-	ACPI_SIZE               bytes_parsed = 0;
+	acpi_size               bytes_parsed = 0;
 	u8                      resource_type = 0;
-	ACPI_SIZE               bytes_consumed = 0;
+	acpi_size               bytes_consumed = 0;
 	u8                      *buffer = output_buffer;
-	ACPI_SIZE               structure_size = 0;
+	acpi_size               structure_size = 0;
 	u8                      end_tag_processed = FALSE;
 	acpi_resource           *resource;
 
-	ACPI_FUNCTION_TRACE ("Rs_byte_stream_to_list");
+	ACPI_FUNCTION_TRACE ("rs_byte_stream_to_list");
 
 
 	while (bytes_parsed < byte_stream_buffer_length &&
@@ -312,16 +311,16 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_list_to_byte_stream
+ * FUNCTION:    acpi_rs_list_to_byte_stream
  *
- * PARAMETERS:  Linked_list             - Pointer to the resource linked list
- *              Byte_steam_size_needed  - Calculated size of the byte stream
+ * PARAMETERS:  linked_list             - Pointer to the resource linked list
+ *              byte_steam_size_needed  - Calculated size of the byte stream
  *                                        needed from calling
- *                                        Acpi_rs_get_byte_stream_length()
- *                                        The size of the Output_buffer is
+ *                                        acpi_rs_get_byte_stream_length()
+ *                                        The size of the output_buffer is
  *                                        guaranteed to be >=
- *                                        Byte_stream_size_needed
- *              Output_buffer           - Pointer to the buffer that will
+ *                                        byte_stream_size_needed
+ *              output_buffer           - Pointer to the buffer that will
  *                                        contain the byte stream
  *
  * RETURN:      Status
@@ -334,16 +333,16 @@
 acpi_status
 acpi_rs_list_to_byte_stream (
 	acpi_resource           *linked_list,
-	ACPI_SIZE               byte_stream_size_needed,
+	acpi_size               byte_stream_size_needed,
 	u8                      *output_buffer)
 {
 	acpi_status             status;
 	u8                      *buffer = output_buffer;
-	ACPI_SIZE               bytes_consumed = 0;
+	acpi_size               bytes_consumed = 0;
 	u8                      done = FALSE;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_list_to_byte_stream");
+	ACPI_FUNCTION_TRACE ("rs_list_to_byte_stream");
 
 
 	while (!done) {
@@ -476,7 +475,7 @@
 			status = AE_BAD_DATA;
 			break;
 
-		} /* switch (Linked_list->Id) */
+		} /* switch (linked_list->Id) */
 
 		if (ACPI_FAILURE (status)) {
 			return_ACPI_STATUS (status);
diff -Nru a/drivers/acpi/resources/rsmemory.c b/drivers/acpi/resources/rsmemory.c
--- a/drivers/acpi/resources/rsmemory.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/acpi/resources/rsmemory.c	Mon Dec 23 21:21:59 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: rsmem24 - Memory resource descriptors
- *              $Revision: 20 $
  *
  ******************************************************************************/
 
@@ -33,21 +32,21 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_memory24_resource
+ * FUNCTION:    acpi_rs_memory24_resource
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
  *                                        stream
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        consumed the Byte_stream_buffer is
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        consumed the byte_stream_buffer is
  *                                        returned
- *              Output_buffer           - Pointer to the return data buffer
- *              Structure_size          - Pointer to where the number of bytes
+ *              output_buffer           - Pointer to the return data buffer
+ *              structure_size          - Pointer to where the number of bytes
  *                                        in the return data struct is returned
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
- *              structure pointed to by the Output_buffer. Return the
+ *              structure pointed to by the output_buffer. Return the
  *              number of bytes consumed from the byte stream.
  *
  ******************************************************************************/
@@ -55,18 +54,18 @@
 acpi_status
 acpi_rs_memory24_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size)
+	acpi_size               *structure_size)
 {
 	u8                      *buffer = byte_stream_buffer;
 	acpi_resource           *output_struct = (void *) *output_buffer;
 	u16                     temp16 = 0;
 	u8                      temp8 = 0;
-	ACPI_SIZE               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_mem24);
+	acpi_size               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_mem24);
 
 
-	ACPI_FUNCTION_TRACE ("Rs_memory24_resource");
+	ACPI_FUNCTION_TRACE ("rs_memory24_resource");
 
 
 	/*
@@ -76,7 +75,7 @@
 
 	ACPI_MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
 	buffer += 2;
-	*bytes_consumed = (ACPI_SIZE) temp16 + 3;
+	*bytes_consumed = (acpi_size) temp16 + 3;
 	output_struct->id = ACPI_RSTYPE_MEM24;
 
 	/*
@@ -87,14 +86,14 @@
 	output_struct->data.memory24.read_write_attribute = temp8 & 0x01;
 
 	/*
-	 * Get Min_base_address (Bytes 4-5)
+	 * Get min_base_address (Bytes 4-5)
 	 */
 	ACPI_MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
 	buffer += 2;
 	output_struct->data.memory24.min_base_address = temp16;
 
 	/*
-	 * Get Max_base_address (Bytes 6-7)
+	 * Get max_base_address (Bytes 6-7)
 	 */
 	ACPI_MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
 	buffer += 2;
@@ -108,7 +107,7 @@
 	output_struct->data.memory24.alignment = temp16;
 
 	/*
-	 * Get Range_length (Bytes 10-11)
+	 * Get range_length (Bytes 10-11)
 	 */
 	ACPI_MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
 	output_struct->data.memory24.range_length = temp16;
@@ -128,12 +127,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_memory24_stream
+ * FUNCTION:    acpi_rs_memory24_stream
  *
- * PARAMETERS:  Linked_list             - Pointer to the resource linked list
- *              Output_buffer           - Pointer to the user's return buffer
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        used in the Output_buffer is returned
+ * PARAMETERS:  linked_list             - Pointer to the resource linked list
+ *              output_buffer           - Pointer to the user's return buffer
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        used in the output_buffer is returned
  *
  * RETURN:      Status
  *
@@ -146,14 +145,14 @@
 acpi_rs_memory24_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed)
+	acpi_size               *bytes_consumed)
 {
 	u8                      *buffer = *output_buffer;
 	u16                     temp16 = 0;
 	u8                      temp8 = 0;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_memory24_stream");
+	ACPI_FUNCTION_TRACE ("rs_memory24_stream");
 
 
 	/*
@@ -210,21 +209,21 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_memory32_range_resource
+ * FUNCTION:    acpi_rs_memory32_range_resource
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
  *                                        stream
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        consumed the Byte_stream_buffer is
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        consumed the byte_stream_buffer is
  *                                        returned
- *              Output_buffer           - Pointer to the return data buffer
- *              Structure_size          - Pointer to where the number of bytes
+ *              output_buffer           - Pointer to the return data buffer
+ *              structure_size          - Pointer to where the number of bytes
  *                                        in the return data struct is returned
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
- *              structure pointed to by the Output_buffer. Return the
+ *              structure pointed to by the output_buffer. Return the
  *              number of bytes consumed from the byte stream.
  *
  ******************************************************************************/
@@ -232,18 +231,18 @@
 acpi_status
 acpi_rs_memory32_range_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size)
+	acpi_size               *structure_size)
 {
 	u8                      *buffer = byte_stream_buffer;
 	acpi_resource           *output_struct = (void *) *output_buffer;
 	u16                     temp16 = 0;
 	u8                      temp8 = 0;
-	ACPI_SIZE               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_mem32);
+	acpi_size               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_mem32);
 
 
-	ACPI_FUNCTION_TRACE ("Rs_memory32_range_resource");
+	ACPI_FUNCTION_TRACE ("rs_memory32_range_resource");
 
 
 	/*
@@ -253,7 +252,7 @@
 
 	ACPI_MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
 	buffer += 2;
-	*bytes_consumed = (ACPI_SIZE) temp16 + 3;
+	*bytes_consumed = (acpi_size) temp16 + 3;
 
 	output_struct->id = ACPI_RSTYPE_MEM32;
 
@@ -263,7 +262,7 @@
 	 *  1. Set the RESOURCE_DATA * Data to point to it's own address, then
 	 *  2. Set the pointer to the next address.
 	 *
-	 *  NOTE: Output_struct->Data is cast to u8, otherwise, this addition adds
+	 *  NOTE: output_struct->Data is cast to u8, otherwise, this addition adds
 	 *  4 * sizeof(RESOURCE_DATA) instead of 4 * sizeof(u8)
 	 */
 
@@ -276,14 +275,14 @@
 	output_struct->data.memory32.read_write_attribute = temp8 & 0x01;
 
 	/*
-	 * Get Min_base_address (Bytes 4-7)
+	 * Get min_base_address (Bytes 4-7)
 	 */
 	ACPI_MOVE_UNALIGNED32_TO_32 (&output_struct->data.memory32.min_base_address,
 			 buffer);
 	buffer += 4;
 
 	/*
-	 * Get Max_base_address (Bytes 8-11)
+	 * Get max_base_address (Bytes 8-11)
 	 */
 	ACPI_MOVE_UNALIGNED32_TO_32 (&output_struct->data.memory32.max_base_address,
 			 buffer);
@@ -296,7 +295,7 @@
 	buffer += 4;
 
 	/*
-	 * Get Range_length (Bytes 16-19)
+	 * Get range_length (Bytes 16-19)
 	 */
 	ACPI_MOVE_UNALIGNED32_TO_32 (&output_struct->data.memory32.range_length, buffer);
 
@@ -315,21 +314,21 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_fixed_memory32_resource
+ * FUNCTION:    acpi_rs_fixed_memory32_resource
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
  *                                        stream
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        consumed the Byte_stream_buffer is
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        consumed the byte_stream_buffer is
  *                                        returned
- *              Output_buffer           - Pointer to the return data buffer
- *              Structure_size          - Pointer to where the number of bytes
+ *              output_buffer           - Pointer to the return data buffer
+ *              structure_size          - Pointer to where the number of bytes
  *                                        in the return data struct is returned
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
- *              structure pointed to by the Output_buffer. Return the
+ *              structure pointed to by the output_buffer. Return the
  *              number of bytes consumed from the byte stream.
  *
  ******************************************************************************/
@@ -337,18 +336,18 @@
 acpi_status
 acpi_rs_fixed_memory32_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size)
+	acpi_size               *structure_size)
 {
 	u8                      *buffer = byte_stream_buffer;
 	acpi_resource           *output_struct = (void *) *output_buffer;
 	u16                     temp16 = 0;
 	u8                      temp8 = 0;
-	ACPI_SIZE               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_fixed_mem32);
+	acpi_size               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_fixed_mem32);
 
 
-	ACPI_FUNCTION_TRACE ("Rs_fixed_memory32_resource");
+	ACPI_FUNCTION_TRACE ("rs_fixed_memory32_resource");
 
 
 	/*
@@ -358,7 +357,7 @@
 	ACPI_MOVE_UNALIGNED16_TO_16 (&temp16, buffer);
 
 	buffer += 2;
-	*bytes_consumed = (ACPI_SIZE) temp16 + 3;
+	*bytes_consumed = (acpi_size) temp16 + 3;
 
 	output_struct->id = ACPI_RSTYPE_FIXED_MEM32;
 
@@ -370,14 +369,14 @@
 	output_struct->data.fixed_memory32.read_write_attribute = temp8 & 0x01;
 
 	/*
-	 * Get Range_base_address (Bytes 4-7)
+	 * Get range_base_address (Bytes 4-7)
 	 */
 	ACPI_MOVE_UNALIGNED32_TO_32 (&output_struct->data.fixed_memory32.range_base_address,
 			 buffer);
 	buffer += 4;
 
 	/*
-	 * Get Range_length (Bytes 8-11)
+	 * Get range_length (Bytes 8-11)
 	 */
 	ACPI_MOVE_UNALIGNED32_TO_32 (&output_struct->data.fixed_memory32.range_length,
 			 buffer);
@@ -397,12 +396,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_memory32_range_stream
+ * FUNCTION:    acpi_rs_memory32_range_stream
  *
- * PARAMETERS:  Linked_list             - Pointer to the resource linked list
- *              Output_buffer           - Pointer to the user's return buffer
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        used in the Output_buffer is returned
+ * PARAMETERS:  linked_list             - Pointer to the resource linked list
+ *              output_buffer           - Pointer to the user's return buffer
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        used in the output_buffer is returned
  *
  * RETURN:      Status
  *
@@ -415,14 +414,14 @@
 acpi_rs_memory32_range_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed)
+	acpi_size               *bytes_consumed)
 {
 	u8                      *buffer = *output_buffer;
 	u16                     temp16 = 0;
 	u8                      temp8 = 0;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_memory32_range_stream");
+	ACPI_FUNCTION_TRACE ("rs_memory32_range_stream");
 
 
 	/*
@@ -480,12 +479,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_fixed_memory32_stream
+ * FUNCTION:    acpi_rs_fixed_memory32_stream
  *
- * PARAMETERS:  Linked_list             - Pointer to the resource linked list
- *              Output_buffer           - Pointer to the user's return buffer
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        used in the Output_buffer is returned
+ * PARAMETERS:  linked_list             - Pointer to the resource linked list
+ *              output_buffer           - Pointer to the user's return buffer
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        used in the output_buffer is returned
  *
  * RETURN:      Status
  *
@@ -498,14 +497,14 @@
 acpi_rs_fixed_memory32_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed)
+	acpi_size               *bytes_consumed)
 {
 	u8                      *buffer = *output_buffer;
 	u16                     temp16 = 0;
 	u8                      temp8 = 0;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_fixed_memory32_stream");
+	ACPI_FUNCTION_TRACE ("rs_fixed_memory32_stream");
 
 
 	/*
diff -Nru a/drivers/acpi/resources/rsmisc.c b/drivers/acpi/resources/rsmisc.c
--- a/drivers/acpi/resources/rsmisc.c	Mon Dec 23 21:21:52 2002
+++ b/drivers/acpi/resources/rsmisc.c	Mon Dec 23 21:21:52 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: rsmisc - Miscellaneous resource descriptors
- *              $Revision: 24 $
  *
  ******************************************************************************/
 
@@ -33,21 +32,21 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_end_tag_resource
+ * FUNCTION:    acpi_rs_end_tag_resource
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
  *                                        stream
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        consumed the Byte_stream_buffer is
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        consumed the byte_stream_buffer is
  *                                        returned
- *              Output_buffer           - Pointer to the return data buffer
- *              Structure_size          - Pointer to where the number of bytes
+ *              output_buffer           - Pointer to the return data buffer
+ *              structure_size          - Pointer to where the number of bytes
  *                                        in the return data struct is returned
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
- *              structure pointed to by the Output_buffer. Return the
+ *              structure pointed to by the output_buffer. Return the
  *              number of bytes consumed from the byte stream.
  *
  ******************************************************************************/
@@ -55,15 +54,15 @@
 acpi_status
 acpi_rs_end_tag_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size)
+	acpi_size               *structure_size)
 {
 	acpi_resource           *output_struct = (void *) *output_buffer;
-	ACPI_SIZE               struct_size = ACPI_RESOURCE_LENGTH;
+	acpi_size               struct_size = ACPI_RESOURCE_LENGTH;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_end_tag_resource");
+	ACPI_FUNCTION_TRACE ("rs_end_tag_resource");
 
 
 	/*
@@ -91,12 +90,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_end_tag_stream
+ * FUNCTION:    acpi_rs_end_tag_stream
  *
- * PARAMETERS:  Linked_list             - Pointer to the resource linked list
- *              Output_buffer           - Pointer to the user's return buffer
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        used in the Output_buffer is returned
+ * PARAMETERS:  linked_list             - Pointer to the resource linked list
+ *              output_buffer           - Pointer to the user's return buffer
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        used in the output_buffer is returned
  *
  * RETURN:      Status
  *
@@ -109,13 +108,13 @@
 acpi_rs_end_tag_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed)
+	acpi_size               *bytes_consumed)
 {
 	u8                      *buffer = *output_buffer;
 	u8                      temp8 = 0;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_end_tag_stream");
+	ACPI_FUNCTION_TRACE ("rs_end_tag_stream");
 
 
 	/*
@@ -143,21 +142,21 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_vendor_resource
+ * FUNCTION:    acpi_rs_vendor_resource
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
  *                                        stream
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        consumed the Byte_stream_buffer is
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        consumed the byte_stream_buffer is
  *                                        returned
- *              Output_buffer           - Pointer to the return data buffer
- *              Structure_size          - Pointer to where the number of bytes
+ *              output_buffer           - Pointer to the return data buffer
+ *              structure_size          - Pointer to where the number of bytes
  *                                        in the return data struct is returned
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
- *              structure pointed to by the Output_buffer. Return the
+ *              structure pointed to by the output_buffer. Return the
  *              number of bytes consumed from the byte stream.
  *
  ******************************************************************************/
@@ -165,19 +164,19 @@
 acpi_status
 acpi_rs_vendor_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size)
+	acpi_size               *structure_size)
 {
 	u8                      *buffer = byte_stream_buffer;
 	acpi_resource           *output_struct = (void *) *output_buffer;
 	u16                     temp16 = 0;
 	u8                      temp8 = 0;
 	u8                      index;
-	ACPI_SIZE               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_vendor);
+	acpi_size               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_vendor);
 
 
-	ACPI_FUNCTION_TRACE ("Rs_vendor_resource");
+	ACPI_FUNCTION_TRACE ("rs_vendor_resource");
 
 
 	/*
@@ -197,7 +196,7 @@
 
 		/* Calculate bytes consumed */
 
-		*bytes_consumed = (ACPI_SIZE) temp16 + 3;
+		*bytes_consumed = (acpi_size) temp16 + 3;
 
 		/* Point to the first vendor byte */
 
@@ -211,7 +210,7 @@
 
 		/* Calculate bytes consumed */
 
-		*bytes_consumed = (ACPI_SIZE) temp16 + 1;
+		*bytes_consumed = (acpi_size) temp16 + 1;
 
 		/* Point to the first vendor byte */
 
@@ -227,11 +226,11 @@
 	}
 
 	/*
-	 * In order for the Struct_size to fall on a 32-bit boundary,
+	 * In order for the struct_size to fall on a 32-bit boundary,
 	 * calculate the length of the vendor string and expand the
-	 * Struct_size to the next 32-bit boundary.
+	 * struct_size to the next 32-bit boundary.
 	 */
-	struct_size += ACPI_ROUND_UP_TO_32_bITS (temp16);
+	struct_size += ACPI_ROUND_UP_to_32_bITS (temp16);
 
 	/*
 	 * Set the Length parameter
@@ -248,12 +247,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_vendor_stream
+ * FUNCTION:    acpi_rs_vendor_stream
  *
- * PARAMETERS:  Linked_list             - Pointer to the resource linked list
- *              Output_buffer           - Pointer to the user's return buffer
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        used in the Output_buffer is returned
+ * PARAMETERS:  linked_list             - Pointer to the resource linked list
+ *              output_buffer           - Pointer to the user's return buffer
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        used in the output_buffer is returned
  *
  * RETURN:      Status
  *
@@ -266,7 +265,7 @@
 acpi_rs_vendor_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed)
+	acpi_size               *bytes_consumed)
 {
 	u8                      *buffer = *output_buffer;
 	u16                     temp16 = 0;
@@ -274,7 +273,7 @@
 	u8                      index;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_vendor_stream");
+	ACPI_FUNCTION_TRACE ("rs_vendor_stream");
 
 
 	/*
@@ -323,21 +322,21 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_start_depend_fns_resource
+ * FUNCTION:    acpi_rs_start_depend_fns_resource
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
  *                                        stream
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        consumed the Byte_stream_buffer is
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        consumed the byte_stream_buffer is
  *                                        returned
- *              Output_buffer           - Pointer to the return data buffer
- *              Structure_size          - Pointer to where the number of bytes
+ *              output_buffer           - Pointer to the return data buffer
+ *              structure_size          - Pointer to where the number of bytes
  *                                        in the return data struct is returned
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
- *              structure pointed to by the Output_buffer. Return the
+ *              structure pointed to by the output_buffer. Return the
  *              number of bytes consumed from the byte stream.
  *
  ******************************************************************************/
@@ -345,17 +344,17 @@
 acpi_status
 acpi_rs_start_depend_fns_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size)
+	acpi_size               *structure_size)
 {
 	u8                      *buffer = byte_stream_buffer;
 	acpi_resource           *output_struct = (void *) *output_buffer;
 	u8                      temp8 = 0;
-	ACPI_SIZE               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_start_dpf);
+	acpi_size               struct_size = ACPI_SIZEOF_RESOURCE (acpi_resource_start_dpf);
 
 
-	ACPI_FUNCTION_TRACE ("Rs_start_depend_fns_resource");
+	ACPI_FUNCTION_TRACE ("rs_start_depend_fns_resource");
 
 
 	/*
@@ -415,21 +414,21 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_end_depend_fns_resource
+ * FUNCTION:    acpi_rs_end_depend_fns_resource
  *
- * PARAMETERS:  Byte_stream_buffer      - Pointer to the resource input byte
+ * PARAMETERS:  byte_stream_buffer      - Pointer to the resource input byte
  *                                        stream
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        consumed the Byte_stream_buffer is
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        consumed the byte_stream_buffer is
  *                                        returned
- *              Output_buffer           - Pointer to the return data buffer
- *              Structure_size          - Pointer to where the number of bytes
+ *              output_buffer           - Pointer to the return data buffer
+ *              structure_size          - Pointer to where the number of bytes
  *                                        in the return data struct is returned
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
- *              structure pointed to by the Output_buffer. Return the
+ *              structure pointed to by the output_buffer. Return the
  *              number of bytes consumed from the byte stream.
  *
  ******************************************************************************/
@@ -437,15 +436,15 @@
 acpi_status
 acpi_rs_end_depend_fns_resource (
 	u8                      *byte_stream_buffer,
-	ACPI_SIZE               *bytes_consumed,
+	acpi_size               *bytes_consumed,
 	u8                      **output_buffer,
-	ACPI_SIZE               *structure_size)
+	acpi_size               *structure_size)
 {
 	acpi_resource           *output_struct = (void *) *output_buffer;
-	ACPI_SIZE               struct_size = ACPI_RESOURCE_LENGTH;
+	acpi_size               struct_size = ACPI_RESOURCE_LENGTH;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_end_depend_fns_resource");
+	ACPI_FUNCTION_TRACE ("rs_end_depend_fns_resource");
 
 
 	/*
@@ -473,13 +472,13 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_start_depend_fns_stream
+ * FUNCTION:    acpi_rs_start_depend_fns_stream
  *
- * PARAMETERS:  Linked_list             - Pointer to the resource linked list
- *              Output_buffer           - Pointer to the user's return buffer
- *              Bytes_consumed          - u32 pointer that is filled with
+ * PARAMETERS:  linked_list             - Pointer to the resource linked list
+ *              output_buffer           - Pointer to the user's return buffer
+ *              bytes_consumed          - u32 pointer that is filled with
  *                                        the number of bytes of the
- *                                        Output_buffer used
+ *                                        output_buffer used
  *
  * RETURN:      Status
  *
@@ -492,13 +491,13 @@
 acpi_rs_start_depend_fns_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed)
+	acpi_size               *bytes_consumed)
 {
 	u8                      *buffer = *output_buffer;
 	u8                      temp8 = 0;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_start_depend_fns_stream");
+	ACPI_FUNCTION_TRACE ("rs_start_depend_fns_stream");
 
 
 	/*
@@ -538,12 +537,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_end_depend_fns_stream
+ * FUNCTION:    acpi_rs_end_depend_fns_stream
  *
- * PARAMETERS:  Linked_list             - Pointer to the resource linked list
- *              Output_buffer           - Pointer to the user's return buffer
- *              Bytes_consumed          - Pointer to where the number of bytes
- *                                        used in the Output_buffer is returned
+ * PARAMETERS:  linked_list             - Pointer to the resource linked list
+ *              output_buffer           - Pointer to the user's return buffer
+ *              bytes_consumed          - Pointer to where the number of bytes
+ *                                        used in the output_buffer is returned
  *
  * RETURN:      Status
  *
@@ -556,12 +555,12 @@
 acpi_rs_end_depend_fns_stream (
 	acpi_resource           *linked_list,
 	u8                      **output_buffer,
-	ACPI_SIZE               *bytes_consumed)
+	acpi_size               *bytes_consumed)
 {
 	u8                      *buffer = *output_buffer;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_end_depend_fns_stream");
+	ACPI_FUNCTION_TRACE ("rs_end_depend_fns_stream");
 
 
 	/*
diff -Nru a/drivers/acpi/resources/rsutils.c b/drivers/acpi/resources/rsutils.c
--- a/drivers/acpi/resources/rsutils.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/resources/rsutils.c	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: rsutils - Utilities for the resource manager
- *              $Revision: 34 $
  *
  ******************************************************************************/
 
@@ -35,10 +34,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_get_prt_method_data
+ * FUNCTION:    acpi_rs_get_prt_method_data
  *
  * PARAMETERS:  Handle          - a handle to the containing object
- *              Ret_buffer      - a pointer to a buffer structure for the
+ *              ret_buffer      - a pointer to a buffer structure for the
  *                                  results
  *
  * RETURN:      Status
@@ -60,7 +59,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_get_prt_method_data");
+	ACPI_FUNCTION_TRACE ("rs_get_prt_method_data");
 
 
 	/* Parameters guaranteed valid by caller */
@@ -79,7 +78,7 @@
 	 */
 	status = acpi_rs_create_pci_routing_table (obj_desc, ret_buffer);
 
-	/* On exit, we must delete the object returned by Evaluate_object */
+	/* On exit, we must delete the object returned by evaluate_object */
 
 	acpi_ut_remove_reference (obj_desc);
 	return_ACPI_STATUS (status);
@@ -88,10 +87,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_get_crs_method_data
+ * FUNCTION:    acpi_rs_get_crs_method_data
  *
  * PARAMETERS:  Handle          - a handle to the containing object
- *              Ret_buffer      - a pointer to a buffer structure for the
+ *              ret_buffer      - a pointer to a buffer structure for the
  *                                  results
  *
  * RETURN:      Status
@@ -113,7 +112,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_get_crs_method_data");
+	ACPI_FUNCTION_TRACE ("rs_get_crs_method_data");
 
 
 	/* Parameters guaranteed valid by caller */
@@ -133,7 +132,7 @@
 	 */
 	status = acpi_rs_create_resource_list (obj_desc, ret_buffer);
 
-	/* On exit, we must delete the object returned by evaluate_object */
+	/* on exit, we must delete the object returned by evaluate_object */
 
 	acpi_ut_remove_reference (obj_desc);
 	return_ACPI_STATUS (status);
@@ -142,10 +141,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_get_prs_method_data
+ * FUNCTION:    acpi_rs_get_prs_method_data
  *
  * PARAMETERS:  Handle          - a handle to the containing object
- *              Ret_buffer      - a pointer to a buffer structure for the
+ *              ret_buffer      - a pointer to a buffer structure for the
  *                                  results
  *
  * RETURN:      Status
@@ -167,7 +166,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_get_prs_method_data");
+	ACPI_FUNCTION_TRACE ("rs_get_prs_method_data");
 
 
 	/* Parameters guaranteed valid by caller */
@@ -187,7 +186,7 @@
 	 */
 	status = acpi_rs_create_resource_list (obj_desc, ret_buffer);
 
-	/* On exit, we must delete the object returned by evaluate_object */
+	/* on exit, we must delete the object returned by evaluate_object */
 
 	acpi_ut_remove_reference (obj_desc);
 	return_ACPI_STATUS (status);
@@ -196,10 +195,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_rs_set_srs_method_data
+ * FUNCTION:    acpi_rs_set_srs_method_data
  *
  * PARAMETERS:  Handle          - a handle to the containing object
- *              In_buffer       - a pointer to a buffer structure of the
+ *              in_buffer       - a pointer to a buffer structure of the
  *                                  parameter
  *
  * RETURN:      Status
@@ -222,13 +221,13 @@
 	acpi_buffer             buffer;
 
 
-	ACPI_FUNCTION_TRACE ("Rs_set_srs_method_data");
+	ACPI_FUNCTION_TRACE ("rs_set_srs_method_data");
 
 
 	/* Parameters guaranteed valid by caller */
 
 	/*
-	 * The In_buffer parameter will point to a linked list of
+	 * The in_buffer parameter will point to a linked list of
 	 * resource parameters.  It needs to be formatted into a
 	 * byte stream to be sent in as an input parameter to _SRS
 	 *
@@ -263,7 +262,7 @@
 	status = acpi_ns_evaluate_relative (handle, "_SRS", params, NULL);
 
 	/*
-	 * Clean up and return the status from Acpi_ns_evaluate_relative
+	 * Clean up and return the status from acpi_ns_evaluate_relative
 	 */
 	acpi_ut_remove_reference (params[0]);
 	return_ACPI_STATUS (status);
diff -Nru a/drivers/acpi/resources/rsxface.c b/drivers/acpi/resources/rsxface.c
--- a/drivers/acpi/resources/rsxface.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/acpi/resources/rsxface.c	Mon Dec 23 21:21:58 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: rsxface - Public interfaces to the resource manager
- *              $Revision: 19 $
  *
  ******************************************************************************/
 
@@ -33,10 +32,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_get_irq_routing_table
+ * FUNCTION:    acpi_get_irq_routing_table
  *
- * PARAMETERS:  Device_handle   - a handle to the Bus device we are querying
- *              Ret_buffer      - a pointer to a buffer to receive the
+ * PARAMETERS:  device_handle   - a handle to the Bus device we are querying
+ *              ret_buffer      - a pointer to a buffer to receive the
  *                                current resources for the device
  *
  * RETURN:      Status
@@ -44,13 +43,13 @@
  * DESCRIPTION: This function is called to get the IRQ routing table for a
  *              specific bus.  The caller must first acquire a handle for the
  *              desired bus.  The routine table is placed in the buffer pointed
- *              to by the Ret_buffer variable parameter.
+ *              to by the ret_buffer variable parameter.
  *
  *              If the function fails an appropriate status will be returned
- *              and the value of Ret_buffer is undefined.
+ *              and the value of ret_buffer is undefined.
  *
  *              This function attempts to execute the _PRT method contained in
- *              the object indicated by the passed Device_handle.
+ *              the object indicated by the passed device_handle.
  *
  ******************************************************************************/
 
@@ -62,7 +61,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_get_irq_routing_table ");
+	ACPI_FUNCTION_TRACE ("acpi_get_irq_routing_table ");
 
 
 	/*
@@ -87,11 +86,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_get_current_resources
+ * FUNCTION:    acpi_get_current_resources
  *
- * PARAMETERS:  Device_handle   - a handle to the device object for the
+ * PARAMETERS:  device_handle   - a handle to the device object for the
  *                                device we are querying
- *              Ret_buffer      - a pointer to a buffer to receive the
+ *              ret_buffer      - a pointer to a buffer to receive the
  *                                current resources for the device
  *
  * RETURN:      Status
@@ -99,13 +98,13 @@
  * DESCRIPTION: This function is called to get the current resources for a
  *              specific device.  The caller must first acquire a handle for
  *              the desired device.  The resource data is placed in the buffer
- *              pointed to by the Ret_buffer variable parameter.
+ *              pointed to by the ret_buffer variable parameter.
  *
  *              If the function fails an appropriate status will be returned
- *              and the value of Ret_buffer is undefined.
+ *              and the value of ret_buffer is undefined.
  *
  *              This function attempts to execute the _CRS method contained in
- *              the object indicated by the passed Device_handle.
+ *              the object indicated by the passed device_handle.
  *
  ******************************************************************************/
 
@@ -117,7 +116,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_get_current_resources");
+	ACPI_FUNCTION_TRACE ("acpi_get_current_resources");
 
 
 	/*
@@ -142,11 +141,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_get_possible_resources
+ * FUNCTION:    acpi_get_possible_resources
  *
- * PARAMETERS:  Device_handle   - a handle to the device object for the
+ * PARAMETERS:  device_handle   - a handle to the device object for the
  *                                device we are querying
- *              Ret_buffer      - a pointer to a buffer to receive the
+ *              ret_buffer      - a pointer to a buffer to receive the
  *                                resources for the device
  *
  * RETURN:      Status
@@ -154,10 +153,10 @@
  * DESCRIPTION: This function is called to get a list of the possible resources
  *              for a specific device.  The caller must first acquire a handle
  *              for the desired device.  The resource data is placed in the
- *              buffer pointed to by the Ret_buffer variable.
+ *              buffer pointed to by the ret_buffer variable.
  *
  *              If the function fails an appropriate status will be returned
- *              and the value of Ret_buffer is undefined.
+ *              and the value of ret_buffer is undefined.
  *
  ******************************************************************************/
 
@@ -169,7 +168,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_get_possible_resources");
+	ACPI_FUNCTION_TRACE ("acpi_get_possible_resources");
 
 
 	/*
@@ -194,11 +193,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_set_current_resources
+ * FUNCTION:    acpi_set_current_resources
  *
- * PARAMETERS:  Device_handle   - a handle to the device object for the
+ * PARAMETERS:  device_handle   - a handle to the device object for the
  *                                device we are changing the resources of
- *              In_buffer       - a pointer to a buffer containing the
+ *              in_buffer       - a pointer to a buffer containing the
  *                                resources to be set for the device
  *
  * RETURN:      Status
@@ -206,7 +205,7 @@
  * DESCRIPTION: This function is called to set the current resources for a
  *              specific device.  The caller must first acquire a handle for
  *              the desired device.  The resource data is passed to the routine
- *              the buffer pointed to by the In_buffer variable.
+ *              the buffer pointed to by the in_buffer variable.
  *
  ******************************************************************************/
 
@@ -218,7 +217,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_set_current_resources");
+	ACPI_FUNCTION_TRACE ("acpi_set_current_resources");
 
 
 	/*
diff -Nru a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
--- a/drivers/acpi/sleep.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/acpi/sleep.c	Mon Dec 23 21:21:50 2002
@@ -256,7 +256,7 @@
 	if (state == ACPI_STATE_S2 || state == ACPI_STATE_S3) {
 		if (!acpi_wakeup_address)
 			return AE_ERROR;
-		acpi_set_firmware_waking_vector((ACPI_PHYSICAL_ADDRESS) acpi_wakeup_address);
+		acpi_set_firmware_waking_vector((acpi_physical_address) acpi_wakeup_address);
 	}
 
 	acpi_enter_sleep_state_prep(state);
@@ -283,7 +283,7 @@
 	ACPI_ENABLE_IRQS();
 
 	/* reset firmware waking vector */
-	acpi_set_firmware_waking_vector((ACPI_PHYSICAL_ADDRESS) 0);
+	acpi_set_firmware_waking_vector((acpi_physical_address) 0);
 	thaw_processes();
 
 	return status;
diff -Nru a/drivers/acpi/tables/tbconvrt.c b/drivers/acpi/tables/tbconvrt.c
--- a/drivers/acpi/tables/tbconvrt.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/acpi/tables/tbconvrt.c	Mon Dec 23 21:21:53 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: tbconvrt - ACPI Table conversion utilities
- *              $Revision: 45 $
  *
  *****************************************************************************/
 
@@ -34,7 +33,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_get_table_count
+ * FUNCTION:    acpi_tb_get_table_count
  *
  * PARAMETERS:  RSDP            - Pointer to the RSDP
  *              RSDT            - Pointer to the RSDT/XSDT
@@ -48,7 +47,7 @@
 
 u32
 acpi_tb_get_table_count (
-	RSDP_DESCRIPTOR         *RSDP,
+	rsdp_descriptor         *RSDP,
 	acpi_table_header       *RSDT)
 {
 	u32                     pointer_size;
@@ -80,9 +79,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_convert_to_xsdt
+ * FUNCTION:    acpi_tb_convert_to_xsdt
  *
- * PARAMETERS:  Table_info      - Info about the RSDT
+ * PARAMETERS:  table_info      - Info about the RSDT
  *
  * RETURN:      Status
  *
@@ -94,7 +93,7 @@
 acpi_tb_convert_to_xsdt (
 	acpi_table_desc         *table_info)
 {
-	ACPI_SIZE               table_size;
+	acpi_size               table_size;
 	u32                     i;
 	xsdt_descriptor         *new_table;
 
@@ -104,7 +103,7 @@
 
 	/* Compute size of the converted XSDT */
 
-	table_size = ((ACPI_SIZE) acpi_gbl_rsdt_table_count * sizeof (u64)) +
+	table_size = ((acpi_size) acpi_gbl_rsdt_table_count * sizeof (u64)) +
 			  sizeof (acpi_table_header);
 
 	/* Allocate an XSDT */
@@ -148,12 +147,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_convert_fadt1
+ * FUNCTION:    acpi_tb_convert_fadt1
  *
- * PARAMETERS:  Local_fadt      - Pointer to new FADT
- *              Original_fadt   - Pointer to old FADT
+ * PARAMETERS:  local_fadt      - Pointer to new FADT
+ *              original_fadt   - Pointer to old FADT
  *
- * RETURN:      Populates Local_fadt
+ * RETURN:      Populates local_fadt
  *
  * DESCRIPTION: Convert an ACPI 1.0 FADT to common internal format
  *
@@ -179,11 +178,11 @@
 
 	/* Convert table pointers to 64-bit fields */
 
-	ACPI_STORE_ADDRESS (local_fadt->Xfirmware_ctrl, local_fadt->V1_firmware_ctrl);
+	ACPI_STORE_ADDRESS (local_fadt->xfirmware_ctrl, local_fadt->V1_firmware_ctrl);
 	ACPI_STORE_ADDRESS (local_fadt->Xdsdt, local_fadt->V1_dsdt);
 
 	/*
-	 * System Interrupt Model isn't used in ACPI 2.0 (Local_fadt->Reserved1 = 0;)
+	 * System Interrupt Model isn't used in ACPI 2.0 (local_fadt->Reserved1 = 0;)
 	 */
 
 	/*
@@ -215,26 +214,26 @@
 	/*
 	 * Convert the V1.0 block addresses to V2.0 GAS structures
 	 */
-	ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->Xpm1a_evt_blk, local_fadt->pm1_evt_len, local_fadt->V1_pm1a_evt_blk);
-	ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->Xpm1b_evt_blk, local_fadt->pm1_evt_len, local_fadt->V1_pm1b_evt_blk);
-	ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->Xpm1a_cnt_blk, local_fadt->pm1_cnt_len, local_fadt->V1_pm1a_cnt_blk);
-	ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->Xpm1b_cnt_blk, local_fadt->pm1_cnt_len, local_fadt->V1_pm1b_cnt_blk);
-	ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->Xpm2_cnt_blk, local_fadt->pm2_cnt_len, local_fadt->V1_pm2_cnt_blk);
-	ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->Xpm_tmr_blk, local_fadt->pm_tm_len, local_fadt->V1_pm_tmr_blk);
-	ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->Xgpe0_blk,  local_fadt->gpe0_blk_len, local_fadt->V1_gpe0_blk);
-	ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->Xgpe1_blk,  local_fadt->gpe1_blk_len, local_fadt->V1_gpe1_blk);
+	ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->xpm1a_evt_blk, local_fadt->pm1_evt_len, local_fadt->V1_pm1a_evt_blk);
+	ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->xpm1b_evt_blk, local_fadt->pm1_evt_len, local_fadt->V1_pm1b_evt_blk);
+	ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->xpm1a_cnt_blk, local_fadt->pm1_cnt_len, local_fadt->V1_pm1a_cnt_blk);
+	ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->xpm1b_cnt_blk, local_fadt->pm1_cnt_len, local_fadt->V1_pm1b_cnt_blk);
+	ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->xpm2_cnt_blk, local_fadt->pm2_cnt_len, local_fadt->V1_pm2_cnt_blk);
+	ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->xpm_tmr_blk, local_fadt->pm_tm_len, local_fadt->V1_pm_tmr_blk);
+	ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->xgpe0_blk,  local_fadt->gpe0_blk_len, local_fadt->V1_gpe0_blk);
+	ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->xgpe1_blk,  local_fadt->gpe1_blk_len, local_fadt->V1_gpe1_blk);
 
 }
 
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_convert_fadt2
+ * FUNCTION:    acpi_tb_convert_fadt2
  *
- * PARAMETERS:  Local_fadt      - Pointer to new FADT
- *              Original_fadt   - Pointer to old FADT
+ * PARAMETERS:  local_fadt      - Pointer to new FADT
+ *              original_fadt   - Pointer to old FADT
  *
- * RETURN:      Populates Local_fadt
+ * RETURN:      Populates local_fadt
  *
  * DESCRIPTION: Convert an ACPI 2.0 FADT to common internal format.
  *              Handles optional "X" fields.
@@ -256,58 +255,58 @@
 	 * we must selectively expand V1.0 fields if the corresponding X field
 	 * is zero.
 	 */
-	if (!(local_fadt->Xfirmware_ctrl)) {
-		ACPI_STORE_ADDRESS (local_fadt->Xfirmware_ctrl, local_fadt->V1_firmware_ctrl);
+	if (!(local_fadt->xfirmware_ctrl)) {
+		ACPI_STORE_ADDRESS (local_fadt->xfirmware_ctrl, local_fadt->V1_firmware_ctrl);
 	}
 
 	if (!(local_fadt->Xdsdt)) {
 		ACPI_STORE_ADDRESS (local_fadt->Xdsdt, local_fadt->V1_dsdt);
 	}
 
-	if (!(local_fadt->Xpm1a_evt_blk.address)) {
-		ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->Xpm1a_evt_blk,
+	if (!(local_fadt->xpm1a_evt_blk.address)) {
+		ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->xpm1a_evt_blk,
 			local_fadt->pm1_evt_len, local_fadt->V1_pm1a_evt_blk);
 	}
 
-	if (!(local_fadt->Xpm1b_evt_blk.address)) {
-		ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->Xpm1b_evt_blk,
+	if (!(local_fadt->xpm1b_evt_blk.address)) {
+		ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->xpm1b_evt_blk,
 			local_fadt->pm1_evt_len, local_fadt->V1_pm1b_evt_blk);
 	}
 
-	if (!(local_fadt->Xpm1a_cnt_blk.address)) {
-		ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->Xpm1a_cnt_blk,
+	if (!(local_fadt->xpm1a_cnt_blk.address)) {
+		ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->xpm1a_cnt_blk,
 			local_fadt->pm1_cnt_len, local_fadt->V1_pm1a_cnt_blk);
 	}
 
-	if (!(local_fadt->Xpm1b_cnt_blk.address)) {
-		ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->Xpm1b_cnt_blk,
+	if (!(local_fadt->xpm1b_cnt_blk.address)) {
+		ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->xpm1b_cnt_blk,
 			local_fadt->pm1_cnt_len, local_fadt->V1_pm1b_cnt_blk);
 	}
 
-	if (!(local_fadt->Xpm2_cnt_blk.address)) {
-		ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->Xpm2_cnt_blk,
+	if (!(local_fadt->xpm2_cnt_blk.address)) {
+		ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->xpm2_cnt_blk,
 			local_fadt->pm2_cnt_len, local_fadt->V1_pm2_cnt_blk);
 	}
 
-	if (!(local_fadt->Xpm_tmr_blk.address)) {
-		ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->Xpm_tmr_blk,
+	if (!(local_fadt->xpm_tmr_blk.address)) {
+		ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->xpm_tmr_blk,
 			local_fadt->pm_tm_len, local_fadt->V1_pm_tmr_blk);
 	}
 
-	if (!(local_fadt->Xgpe0_blk.address)) {
-		ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->Xgpe0_blk,
+	if (!(local_fadt->xgpe0_blk.address)) {
+		ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->xgpe0_blk,
 			local_fadt->gpe0_blk_len, local_fadt->V1_gpe0_blk);
 	}
 
-	if (!(local_fadt->Xgpe1_blk.address)) {
-		ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->Xgpe1_blk,
+	if (!(local_fadt->xgpe1_blk.address)) {
+		ASL_BUILD_GAS_FROM_V1_ENTRY (local_fadt->xgpe1_blk,
 			local_fadt->gpe1_blk_len, local_fadt->V1_gpe1_blk);
 	}
 }
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_convert_table_fadt
+ * FUNCTION:    acpi_tb_convert_table_fadt
  *
  * PARAMETERS:  None
  *
@@ -328,11 +327,11 @@
 	acpi_table_desc        *table_desc;
 
 
-	ACPI_FUNCTION_TRACE ("Tb_convert_table_fadt");
+	ACPI_FUNCTION_TRACE ("tb_convert_table_fadt");
 
 
 	/*
-	 * Acpi_gbl_FADT is valid
+	 * acpi_gbl_FADT is valid
 	 * Allocate and zero the 2.0 FADT buffer
 	 */
 	local_fadt = ACPI_MEM_CALLOCATE (sizeof (fadt_descriptor_rev2));
@@ -400,9 +399,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_convert_table_facs
+ * FUNCTION:    acpi_tb_convert_table_facs
  *
- * PARAMETERS:  Table_info      - Info for currently installad FACS
+ * PARAMETERS:  table_info      - Info for currently installad FACS
  *
  * RETURN:      Status
  *
@@ -416,7 +415,7 @@
 	acpi_table_desc         *table_info)
 {
 
-	ACPI_FUNCTION_TRACE ("Tb_build_common_facs");
+	ACPI_FUNCTION_TRACE ("tb_build_common_facs");
 
 
 	/* Absolute minimum length is 24, but the ACPI spec says 64 */
@@ -437,7 +436,7 @@
 
 	if ((acpi_gbl_RSDP->revision < 2) ||
 		(acpi_gbl_FACS->length < 32) ||
-		(!(acpi_gbl_FACS->Xfirmware_waking_vector))) {
+		(!(acpi_gbl_FACS->xfirmware_waking_vector))) {
 		/* ACPI 1.0 FACS or short table or optional X_ field is zero */
 
 		acpi_gbl_common_fACS.firmware_waking_vector = ACPI_CAST_PTR (u64, &(acpi_gbl_FACS->firmware_waking_vector));
@@ -446,7 +445,7 @@
 	else {
 		/* ACPI 2.0 FACS with valid X_ field */
 
-		acpi_gbl_common_fACS.firmware_waking_vector = &acpi_gbl_FACS->Xfirmware_waking_vector;
+		acpi_gbl_common_fACS.firmware_waking_vector = &acpi_gbl_FACS->xfirmware_waking_vector;
 		acpi_gbl_common_fACS.vector_width = 64;
 	}
 
diff -Nru a/drivers/acpi/tables/tbget.c b/drivers/acpi/tables/tbget.c
--- a/drivers/acpi/tables/tbget.c	Mon Dec 23 21:21:57 2002
+++ b/drivers/acpi/tables/tbget.c	Mon Dec 23 21:21:58 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: tbget - ACPI Table get* routines
- *              $Revision: 82 $
  *
  *****************************************************************************/
 
@@ -34,11 +33,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_get_table
+ * FUNCTION:    acpi_tb_get_table
  *
  * PARAMETERS:  Address             - Address of table to retrieve.  Can be
  *                                    Logical or Physical
- *              Table_info          - Where table info is returned
+ *              table_info          - Where table info is returned
  *
  * RETURN:      None
  *
@@ -48,14 +47,14 @@
 
 acpi_status
 acpi_tb_get_table (
-	ACPI_POINTER            *address,
+	acpi_pointer            *address,
 	acpi_table_desc         *table_info)
 {
 	acpi_status             status;
 	acpi_table_header       header;
 
 
-	ACPI_FUNCTION_TRACE ("Tb_get_table");
+	ACPI_FUNCTION_TRACE ("tb_get_table");
 
 
 	/*
@@ -81,11 +80,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_get_table_header
+ * FUNCTION:    acpi_tb_get_table_header
  *
  * PARAMETERS:  Address             - Address of table to retrieve.  Can be
  *                                    Logical or Physical
- *              Return_header       - Where the table header is returned
+ *              return_header       - Where the table header is returned
  *
  * RETURN:      Status
  *
@@ -98,19 +97,19 @@
 
 acpi_status
 acpi_tb_get_table_header (
-	ACPI_POINTER            *address,
+	acpi_pointer            *address,
 	acpi_table_header       *return_header)
 {
 	acpi_status             status = AE_OK;
 	acpi_table_header       *header = NULL;
 
 
-	ACPI_FUNCTION_TRACE ("Tb_get_table_header");
+	ACPI_FUNCTION_TRACE ("tb_get_table_header");
 
 
 	/*
 	 * Flags contains the current processor mode (Virtual or Physical addressing)
-	 * The Pointer_type is either Logical or Physical
+	 * The pointer_type is either Logical or Physical
 	 */
 	switch (address->pointer_type) {
 	case ACPI_PHYSMODE_PHYSPTR:
@@ -156,12 +155,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_get_table_body
+ * FUNCTION:    acpi_tb_get_table_body
  *
  * PARAMETERS:  Address             - Address of table to retrieve.  Can be
  *                                    Logical or Physical
  *              Header              - Header of the table to retrieve
- *              Table_info          - Where the table info is returned
+ *              table_info          - Where the table info is returned
  *
  * RETURN:      Status
  *
@@ -176,14 +175,14 @@
 
 acpi_status
 acpi_tb_get_table_body (
-	ACPI_POINTER            *address,
+	acpi_pointer            *address,
 	acpi_table_header       *header,
 	acpi_table_desc         *table_info)
 {
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Tb_get_table_body");
+	ACPI_FUNCTION_TRACE ("tb_get_table_body");
 
 
 	if (!table_info || !address) {
@@ -209,10 +208,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_table_override
+ * FUNCTION:    acpi_tb_table_override
  *
  * PARAMETERS:  Header              - Pointer to table header
- *              Table_info          - Return info if table is overridden
+ *              table_info          - Return info if table is overridden
  *
  * RETURN:      None
  *
@@ -228,15 +227,15 @@
 {
 	acpi_table_header       *new_table;
 	acpi_status             status;
-	ACPI_POINTER            address;
+	acpi_pointer            address;
 
 
-	ACPI_FUNCTION_TRACE ("Tb_table_override");
+	ACPI_FUNCTION_TRACE ("tb_table_override");
 
 
 	/*
 	 * The OSL will examine the header and decide whether to override this
-	 * table.  If it decides to override, a table will be returned in New_table,
+	 * table.  If it decides to override, a table will be returned in new_table,
 	 * which we will then copy.
 	 */
 	status = acpi_os_table_override (header, &new_table);
@@ -279,12 +278,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_get_this_table
+ * FUNCTION:    acpi_tb_get_this_table
  *
  * PARAMETERS:  Address             - Address of table to retrieve.  Can be
  *                                    Logical or Physical
  *              Header              - Header of the table to retrieve
- *              Table_info          - Where the table info is returned
+ *              table_info          - Where the table info is returned
  *
  * RETURN:      Status
  *
@@ -297,7 +296,7 @@
 
 acpi_status
 acpi_tb_get_this_table (
-	ACPI_POINTER            *address,
+	acpi_pointer            *address,
 	acpi_table_header       *header,
 	acpi_table_desc         *table_info)
 {
@@ -306,12 +305,12 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Tb_get_this_table");
+	ACPI_FUNCTION_TRACE ("tb_get_this_table");
 
 
 	/*
 	 * Flags contains the current processor mode (Virtual or Physical addressing)
-	 * The Pointer_type is either Logical or Physical
+	 * The pointer_type is either Logical or Physical
 	 */
 	switch (address->pointer_type) {
 	case ACPI_PHYSMODE_PHYSPTR:
@@ -342,7 +341,7 @@
 		 * Just map the table's physical memory
 		 * into our address space.
 		 */
-		status = acpi_os_map_memory (address->pointer.physical, (ACPI_SIZE) header->length,
+		status = acpi_os_map_memory (address->pointer.physical, (acpi_size) header->length,
 				  (void **) &full_table);
 		if (ACPI_FAILURE (status)) {
 			ACPI_REPORT_ERROR (("Could not map memory for table [%4.4s] at %8.8X%8.8X for length %X\n",
@@ -384,7 +383,7 @@
 	/* Return values */
 
 	table_info->pointer     = full_table;
-	table_info->length      = (ACPI_SIZE) header->length;
+	table_info->length      = (acpi_size) header->length;
 	table_info->allocation  = allocation;
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
@@ -399,11 +398,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_get_table_ptr
+ * FUNCTION:    acpi_tb_get_table_ptr
  *
- * PARAMETERS:  Table_type      - one of the defined table types
+ * PARAMETERS:  table_type      - one of the defined table types
  *              Instance        - Which table of this type
- *              Table_ptr_loc   - pointer to location to place the pointer for
+ *              table_ptr_loc   - pointer to location to place the pointer for
  *                                return
  *
  * RETURN:      Status
@@ -422,7 +421,7 @@
 	u32                     i;
 
 
-	ACPI_FUNCTION_TRACE ("Tb_get_table_ptr");
+	ACPI_FUNCTION_TRACE ("tb_get_table_ptr");
 
 
 	if (!acpi_gbl_DSDT) {
@@ -455,7 +454,7 @@
 
 	/* Walk the list to get the desired table
 	 * Since the if (Instance == 1) check above checked for the
-	 * first table, setting Table_desc equal to the .Next member
+	 * first table, setting table_desc equal to the .Next member
 	 * is actually pointing to the second table.  Therefore, we
 	 * need to walk from the 2nd table until we reach the Instance
 	 * that the user is looking for and return its table pointer.
diff -Nru a/drivers/acpi/tables/tbgetall.c b/drivers/acpi/tables/tbgetall.c
--- a/drivers/acpi/tables/tbgetall.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/acpi/tables/tbgetall.c	Mon Dec 23 21:21:58 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: tbgetall - Get all required ACPI tables
- *              $Revision: 4 $
  *
  *****************************************************************************/
 
@@ -34,10 +33,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_get_primary_table
+ * FUNCTION:    acpi_tb_get_primary_table
  *
  * PARAMETERS:  Address             - Physical address of table to retrieve
- *              *Table_info         - Where the table info is returned
+ *              *table_info         - Where the table info is returned
  *
  * RETURN:      Status
  *
@@ -47,14 +46,14 @@
 
 acpi_status
 acpi_tb_get_primary_table (
-	ACPI_POINTER            *address,
+	acpi_pointer            *address,
 	acpi_table_desc         *table_info)
 {
 	acpi_status             status;
 	acpi_table_header       header;
 
 
-	ACPI_FUNCTION_TRACE ("Tb_get_primary_table");
+	ACPI_FUNCTION_TRACE ("tb_get_primary_table");
 
 
 	/* Ignore a NULL address in the RSDT */
@@ -71,7 +70,7 @@
 		return_ACPI_STATUS (status);
 	}
 
-	/* Clear the Table_info */
+	/* Clear the table_info */
 
 	ACPI_MEMSET (table_info, 0, sizeof (acpi_table_desc));
 
@@ -101,10 +100,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_get_secondary_table
+ * FUNCTION:    acpi_tb_get_secondary_table
  *
  * PARAMETERS:  Address             - Physical address of table to retrieve
- *              *Table_info         - Where the table info is returned
+ *              *table_info         - Where the table info is returned
  *
  * RETURN:      Status
  *
@@ -114,7 +113,7 @@
 
 acpi_status
 acpi_tb_get_secondary_table (
-	ACPI_POINTER            *address,
+	acpi_pointer            *address,
 	acpi_string             signature,
 	acpi_table_desc         *table_info)
 {
@@ -122,7 +121,7 @@
 	acpi_table_header       header;
 
 
-	ACPI_FUNCTION_TRACE_STR ("Tb_get_secondary_table", signature);
+	ACPI_FUNCTION_TRACE_STR ("tb_get_secondary_table", signature);
 
 
 	/* Get the header in order to match the signature */
@@ -166,7 +165,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_get_required_tables
+ * FUNCTION:    acpi_tb_get_required_tables
  *
  * PARAMETERS:  None
  *
@@ -190,10 +189,10 @@
 	acpi_status             status = AE_OK;
 	u32                     i;
 	acpi_table_desc         table_info;
-	ACPI_POINTER            address;
+	acpi_pointer            address;
 
 
-	ACPI_FUNCTION_TRACE ("Tb_get_required_tables");
+	ACPI_FUNCTION_TRACE ("tb_get_required_tables");
 
 	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "%d ACPI tables in RSDT\n",
 		acpi_gbl_rsdt_table_count));
@@ -247,7 +246,7 @@
 	/*
 	 * Get the FACS (Pointed to by the FADT)
 	 */
-	address.pointer.value = acpi_gbl_FADT->Xfirmware_ctrl;
+	address.pointer.value = acpi_gbl_FADT->xfirmware_ctrl;
 
 	status = acpi_tb_get_secondary_table (&address, FACS_SIG, &table_info);
 	if (ACPI_FAILURE (status)) {
diff -Nru a/drivers/acpi/tables/tbinstal.c b/drivers/acpi/tables/tbinstal.c
--- a/drivers/acpi/tables/tbinstal.c	Mon Dec 23 21:21:52 2002
+++ b/drivers/acpi/tables/tbinstal.c	Mon Dec 23 21:21:52 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: tbinstal - ACPI table installation and removal
- *              $Revision: 65 $
  *
  *****************************************************************************/
 
@@ -34,15 +33,15 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_match_signature
+ * FUNCTION:    acpi_tb_match_signature
  *
  * PARAMETERS:  Signature           - Table signature to match
- *              Table_info          - Return data
+ *              table_info          - Return data
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Compare signature against the list of "ACPI-subsystem-owned"
- *              tables (DSDT/FADT/SSDT, etc.) Returns the Table_type_iD on match.
+ *              tables (DSDT/FADT/SSDT, etc.) Returns the table_type_iD on match.
  *
  ******************************************************************************/
 
@@ -52,10 +51,10 @@
 	acpi_table_desc         *table_info,
 	u8                      search_type)
 {
-	NATIVE_UINT             i;
+	acpi_native_uint        i;
 
 
-	ACPI_FUNCTION_TRACE ("Tb_match_signature");
+	ACPI_FUNCTION_TRACE ("tb_match_signature");
 
 
 	/*
@@ -92,9 +91,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_install_table
+ * FUNCTION:    acpi_tb_install_table
  *
- * PARAMETERS:  Table_info          - Return value from Acpi_tb_get_table_body
+ * PARAMETERS:  table_info          - Return value from acpi_tb_get_table_body
  *
  * RETURN:      Status
  *
@@ -110,7 +109,7 @@
 {
 	acpi_status             status;
 
-	ACPI_FUNCTION_TRACE ("Tb_install_table");
+	ACPI_FUNCTION_TRACE ("tb_install_table");
 
 
 	/* Lock tables while installing */
@@ -140,9 +139,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_recognize_table
+ * FUNCTION:    acpi_tb_recognize_table
  *
- * PARAMETERS:  Table_info          - Return value from Acpi_tb_get_table_body
+ * PARAMETERS:  table_info          - Return value from acpi_tb_get_table_body
  *
  * RETURN:      Status
  *
@@ -167,7 +166,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Tb_recognize_table");
+	ACPI_FUNCTION_TRACE ("tb_recognize_table");
 
 
 	/* Ensure that we have a valid table pointer */
@@ -197,7 +196,7 @@
 
 	/* Return the table type and length via the info struct */
 
-	table_info->length = (ACPI_SIZE) table_header->length;
+	table_info->length = (acpi_size) table_header->length;
 
 	return_ACPI_STATUS (status);
 }
@@ -205,10 +204,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_init_table_descriptor
+ * FUNCTION:    acpi_tb_init_table_descriptor
  *
- * PARAMETERS:  Table_type          - The type of the table
- *              Table_info          - A table info struct
+ * PARAMETERS:  table_type          - The type of the table
+ *              table_info          - A table info struct
  *
  * RETURN:      None.
  *
@@ -225,7 +224,7 @@
 	acpi_table_desc         *table_desc;
 
 
-	ACPI_FUNCTION_TRACE_U32 ("Tb_init_table_descriptor", table_type);
+	ACPI_FUNCTION_TRACE_U32 ("tb_init_table_descriptor", table_type);
 
 	/*
 	 * Install the table into the global data structure
@@ -313,7 +312,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_delete_acpi_tables
+ * FUNCTION:    acpi_tb_delete_acpi_tables
  *
  * PARAMETERS:  None.
  *
@@ -341,7 +340,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_delete_acpi_table
+ * FUNCTION:    acpi_tb_delete_acpi_table
  *
  * PARAMETERS:  Type                - The table type to be deleted
  *
@@ -357,7 +356,7 @@
 	acpi_table_type             type)
 {
 
-	ACPI_FUNCTION_TRACE_U32 ("Tb_delete_acpi_table", type);
+	ACPI_FUNCTION_TRACE_U32 ("tb_delete_acpi_table", type);
 
 
 	if (type > ACPI_TABLE_MAX) {
@@ -408,9 +407,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_free_acpi_tables_of_type
+ * FUNCTION:    acpi_tb_free_acpi_tables_of_type
  *
- * PARAMETERS:  Table_info          - A table info struct
+ * PARAMETERS:  table_info          - A table info struct
  *
  * RETURN:      None.
  *
@@ -428,7 +427,7 @@
 	u32                     i;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Tb_free_acpi_tables_of_type", list_head);
+	ACPI_FUNCTION_TRACE_PTR ("tb_free_acpi_tables_of_type", list_head);
 
 
 	/* Get the head of the list */
@@ -450,9 +449,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_delete_single_table
+ * FUNCTION:    acpi_tb_delete_single_table
  *
- * PARAMETERS:  Table_info          - A table info struct
+ * PARAMETERS:  table_info          - A table info struct
  *
  * RETURN:      None.
  *
@@ -496,9 +495,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_uninstall_table
+ * FUNCTION:    acpi_tb_uninstall_table
  *
- * PARAMETERS:  Table_info          - A table info struct
+ * PARAMETERS:  table_info          - A table info struct
  *
  * RETURN:      Pointer to the next table in the list (of same type)
  *
@@ -515,7 +514,7 @@
 	acpi_table_desc         *next_desc;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Acpi_tb_uninstall_table", table_desc);
+	ACPI_FUNCTION_TRACE_PTR ("acpi_tb_uninstall_table", table_desc);
 
 
 	if (!table_desc) {
diff -Nru a/drivers/acpi/tables/tbrsdt.c b/drivers/acpi/tables/tbrsdt.c
--- a/drivers/acpi/tables/tbrsdt.c	Mon Dec 23 21:21:57 2002
+++ b/drivers/acpi/tables/tbrsdt.c	Mon Dec 23 21:21:57 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: tbrsdt - ACPI RSDT table utilities
- *              $Revision: 5 $
  *
  *****************************************************************************/
 
@@ -34,7 +33,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_verify_rsdp
+ * FUNCTION:    acpi_tb_verify_rsdp
  *
  * PARAMETERS:  Address         - RSDP (Pointer to RSDT)
  *
@@ -46,14 +45,14 @@
 
 acpi_status
 acpi_tb_verify_rsdp (
-	ACPI_POINTER            *address)
+	acpi_pointer            *address)
 {
 	acpi_table_desc         table_info;
 	acpi_status             status;
-	RSDP_DESCRIPTOR         *rsdp;
+	rsdp_descriptor         *rsdp;
 
 
-	ACPI_FUNCTION_TRACE ("Tb_verify_rsdp");
+	ACPI_FUNCTION_TRACE ("tb_verify_rsdp");
 
 
 	switch (address->pointer_type) {
@@ -66,7 +65,7 @@
 		/*
 		 * Obtain access to the RSDP structure
 		 */
-		status = acpi_os_map_memory (address->pointer.physical, sizeof (RSDP_DESCRIPTOR),
+		status = acpi_os_map_memory (address->pointer.physical, sizeof (rsdp_descriptor),
 				  (void **) &rsdp);
 		if (ACPI_FAILURE (status)) {
 			return_ACPI_STATUS (status);
@@ -106,7 +105,7 @@
 	/* The RSDP supplied is OK */
 
 	table_info.pointer     = ACPI_CAST_PTR (acpi_table_header, rsdp);
-	table_info.length      = sizeof (RSDP_DESCRIPTOR);
+	table_info.length      = sizeof (rsdp_descriptor);
 	table_info.allocation  = ACPI_MEM_MAPPED;
 
 	/* Save the table pointers and allocation info */
@@ -118,7 +117,7 @@
 
 	/* Save the RSDP in a global for easy access */
 
-	acpi_gbl_RSDP = ACPI_CAST_PTR (RSDP_DESCRIPTOR, table_info.pointer);
+	acpi_gbl_RSDP = ACPI_CAST_PTR (rsdp_descriptor, table_info.pointer);
 	return_ACPI_STATUS (status);
 
 
@@ -126,7 +125,7 @@
 cleanup:
 
 	if (acpi_gbl_table_flags & ACPI_PHYSICAL_POINTER) {
-		acpi_os_unmap_memory (rsdp, sizeof (RSDP_DESCRIPTOR));
+		acpi_os_unmap_memory (rsdp, sizeof (rsdp_descriptor));
 	}
 	return_ACPI_STATUS (status);
 }
@@ -134,7 +133,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_get_rsdt_address
+ * FUNCTION:    acpi_tb_get_rsdt_address
  *
  * PARAMETERS:  None
  *
@@ -147,7 +146,7 @@
 
 void
 acpi_tb_get_rsdt_address (
-	ACPI_POINTER            *out_address)
+	acpi_pointer            *out_address)
 {
 
 	ACPI_FUNCTION_ENTRY ();
@@ -170,9 +169,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_validate_rsdt
+ * FUNCTION:    acpi_tb_validate_rsdt
  *
- * PARAMETERS:  Table_ptr       - Addressable pointer to the RSDT.
+ * PARAMETERS:  table_ptr       - Addressable pointer to the RSDT.
  *
  * RETURN:      Status
  *
@@ -187,7 +186,7 @@
 	int                     no_match;
 
 
-	ACPI_FUNCTION_NAME ("Tb_validate_rsdt");
+	ACPI_FUNCTION_NAME ("tb_validate_rsdt");
 
 
 	/*
@@ -213,7 +212,7 @@
 		ACPI_DEBUG_PRINT_RAW ((ACPI_DB_ERROR,
 			"RSDT/XSDT signature at %X (%p) is invalid\n",
 			acpi_gbl_RSDP->rsdt_physical_address,
-			(void *) (NATIVE_UINT) acpi_gbl_RSDP->rsdt_physical_address));
+			(void *) (acpi_native_uint) acpi_gbl_RSDP->rsdt_physical_address));
 
 		return (AE_BAD_SIGNATURE);
 	}
@@ -224,7 +223,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_get_table_rsdt
+ * FUNCTION:    acpi_tb_get_table_rsdt
  *
  * PARAMETERS:  None
  *
@@ -240,10 +239,10 @@
 {
 	acpi_table_desc         table_info;
 	acpi_status             status;
-	ACPI_POINTER            address;
+	acpi_pointer            address;
 
 
-	ACPI_FUNCTION_TRACE ("Tb_get_table_rsdt");
+	ACPI_FUNCTION_TRACE ("tb_get_table_rsdt");
 
 
 	/* Get the RSDT/XSDT via the RSDP */
diff -Nru a/drivers/acpi/tables/tbutils.c b/drivers/acpi/tables/tbutils.c
--- a/drivers/acpi/tables/tbutils.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/acpi/tables/tbutils.c	Mon Dec 23 21:21:59 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: tbutils - Table manipulation utilities
- *              $Revision: 57 $
  *
  *****************************************************************************/
 
@@ -34,13 +33,13 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_handle_to_object
+ * FUNCTION:    acpi_tb_handle_to_object
  *
- * PARAMETERS:  Table_id            - Id for which the function is searching
- *              Table_desc          - Pointer to return the matching table
+ * PARAMETERS:  table_id            - Id for which the function is searching
+ *              table_desc          - Pointer to return the matching table
  *                                      descriptor.
  *
- * RETURN:      Search the tables to find one with a matching Table_id and
+ * RETURN:      Search the tables to find one with a matching table_id and
  *              return a pointer to that table descriptor.
  *
  ******************************************************************************/
@@ -54,7 +53,7 @@
 	acpi_table_desc         *list_head;
 
 
-	ACPI_FUNCTION_NAME ("Tb_handle_to_object");
+	ACPI_FUNCTION_NAME ("tb_handle_to_object");
 
 
 	for (i = 0; i < ACPI_TABLE_MAX; i++) {
@@ -70,16 +69,16 @@
 		} while (list_head != &acpi_gbl_acpi_tables[i]);
 	}
 
-	ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Table_id=%X does not exist\n", table_id));
+	ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "table_id=%X does not exist\n", table_id));
 	return (AE_BAD_PARAMETER);
 }
 
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_validate_table_header
+ * FUNCTION:    acpi_tb_validate_table_header
  *
- * PARAMETERS:  Table_header        - Logical pointer to the table
+ * PARAMETERS:  table_header        - Logical pointer to the table
  *
  * RETURN:      Status
  *
@@ -102,7 +101,7 @@
 	acpi_name               signature;
 
 
-	ACPI_FUNCTION_NAME ("Tb_validate_table_header");
+	ACPI_FUNCTION_NAME ("tb_validate_table_header");
 
 
 	/* Verify that this is a valid address */
@@ -146,9 +145,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_verify_table_checksum
+ * FUNCTION:    acpi_tb_verify_table_checksum
  *
- * PARAMETERS:  *Table_header           - ACPI table to verify
+ * PARAMETERS:  *table_header           - ACPI table to verify
  *
  * RETURN:      8 bit checksum of table
  *
@@ -165,7 +164,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Tb_verify_table_checksum");
+	ACPI_FUNCTION_TRACE ("tb_verify_table_checksum");
 
 
 	/* Compute the checksum on the table */
@@ -186,7 +185,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_checksum
+ * FUNCTION:    acpi_tb_checksum
  *
  * PARAMETERS:  Buffer              - Buffer to checksum
  *              Length              - Size of the buffer
diff -Nru a/drivers/acpi/tables/tbxface.c b/drivers/acpi/tables/tbxface.c
--- a/drivers/acpi/tables/tbxface.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/acpi/tables/tbxface.c	Mon Dec 23 21:22:00 2002
@@ -2,7 +2,6 @@
  *
  * Module Name: tbxface - Public interfaces to the ACPI subsystem
  *                         ACPI table oriented interfaces
- *              $Revision: 60 $
  *
  *****************************************************************************/
 
@@ -36,7 +35,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_load_tables
+ * FUNCTION:    acpi_load_tables
  *
  * PARAMETERS:  None
  *
@@ -50,11 +49,11 @@
 acpi_status
 acpi_load_tables (void)
 {
-	ACPI_POINTER            rsdp_address;
+	acpi_pointer            rsdp_address;
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_load_tables");
+	ACPI_FUNCTION_TRACE ("acpi_load_tables");
 
 
 	/* Get the RSDP */
@@ -62,7 +61,7 @@
 	status = acpi_os_get_root_pointer (ACPI_LOGICAL_ADDRESSING,
 			  &rsdp_address);
 	if (ACPI_FAILURE (status)) {
-		ACPI_REPORT_ERROR (("Acpi_load_tables: Could not get RSDP, %s\n",
+		ACPI_REPORT_ERROR (("acpi_load_tables: Could not get RSDP, %s\n",
 				  acpi_format_exception (status)));
 		goto error_exit;
 	}
@@ -73,7 +72,7 @@
 
 	status = acpi_tb_verify_rsdp (&rsdp_address);
 	if (ACPI_FAILURE (status)) {
-		ACPI_REPORT_ERROR (("Acpi_load_tables: RSDP Failed validation: %s\n",
+		ACPI_REPORT_ERROR (("acpi_load_tables: RSDP Failed validation: %s\n",
 				  acpi_format_exception (status)));
 		goto error_exit;
 	}
@@ -82,7 +81,7 @@
 
 	status = acpi_tb_get_table_rsdt ();
 	if (ACPI_FAILURE (status)) {
-		ACPI_REPORT_ERROR (("Acpi_load_tables: Could not load RSDT: %s\n",
+		ACPI_REPORT_ERROR (("acpi_load_tables: Could not load RSDT: %s\n",
 				  acpi_format_exception (status)));
 		goto error_exit;
 	}
@@ -91,7 +90,7 @@
 
 	status = acpi_tb_get_required_tables ();
 	if (ACPI_FAILURE (status)) {
-		ACPI_REPORT_ERROR (("Acpi_load_tables: Error getting required tables (DSDT/FADT/FACS): %s\n",
+		ACPI_REPORT_ERROR (("acpi_load_tables: Error getting required tables (DSDT/FADT/FACS): %s\n",
 				  acpi_format_exception (status)));
 		goto error_exit;
 	}
@@ -103,7 +102,7 @@
 
 	status = acpi_ns_load_namespace ();
 	if (ACPI_FAILURE (status)) {
-		ACPI_REPORT_ERROR (("Acpi_load_tables: Could not load namespace: %s\n",
+		ACPI_REPORT_ERROR (("acpi_load_tables: Could not load namespace: %s\n",
 				  acpi_format_exception (status)));
 		goto error_exit;
 	}
@@ -112,7 +111,7 @@
 
 
 error_exit:
-	ACPI_REPORT_ERROR (("Acpi_load_tables: Could not load tables: %s\n",
+	ACPI_REPORT_ERROR (("acpi_load_tables: Could not load tables: %s\n",
 			  acpi_format_exception (status)));
 
 	return_ACPI_STATUS (status);
@@ -121,9 +120,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_load_table
+ * FUNCTION:    acpi_load_table
  *
- * PARAMETERS:  Table_ptr       - pointer to a buffer containing the entire
+ * PARAMETERS:  table_ptr       - pointer to a buffer containing the entire
  *                                table to be loaded
  *
  * RETURN:      Status
@@ -141,10 +140,10 @@
 {
 	acpi_status             status;
 	acpi_table_desc         table_info;
-	ACPI_POINTER            address;
+	acpi_pointer            address;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_load_table");
+	ACPI_FUNCTION_TRACE ("acpi_load_table");
 
 
 	if (!table_ptr) {
@@ -165,7 +164,7 @@
 
 	status = acpi_tb_install_table (&table_info);
 	if (ACPI_FAILURE (status)) {
-		/* Free table allocated by Acpi_tb_get_table_body */
+		/* Free table allocated by acpi_tb_get_table_body */
 
 		acpi_tb_delete_single_table (&table_info);
 		return_ACPI_STATUS (status);
@@ -203,9 +202,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_unload_table
+ * FUNCTION:    acpi_unload_table
  *
- * PARAMETERS:  Table_type    - Type of table to be unloaded
+ * PARAMETERS:  table_type    - Type of table to be unloaded
  *
  * RETURN:      Status
  *
@@ -220,7 +219,7 @@
 	acpi_table_desc         *list_head;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_unload_table");
+	ACPI_FUNCTION_TRACE ("acpi_unload_table");
 
 
 	/* Parameter validation */
@@ -254,13 +253,13 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_get_table_header
+ * FUNCTION:    acpi_get_table_header
  *
- * PARAMETERS:  Table_type      - one of the defined table types
+ * PARAMETERS:  table_type      - one of the defined table types
  *              Instance        - the non zero instance of the table, allows
  *                                support for multiple tables of the same type
- *                                see Acpi_gbl_Acpi_table_flag
- *              Out_table_header - pointer to the acpi_table_header if successful
+ *                                see acpi_gbl_acpi_table_flag
+ *              out_table_header - pointer to the acpi_table_header if successful
  *
  * DESCRIPTION: This function is called to get an ACPI table header.  The caller
  *              supplies an pointer to a data area sufficient to contain an ACPI
@@ -283,7 +282,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_get_table_header");
+	ACPI_FUNCTION_TRACE ("acpi_get_table_header");
 
 
 	if ((instance == 0)                 ||
@@ -327,23 +326,23 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_get_table
+ * FUNCTION:    acpi_get_table
  *
- * PARAMETERS:  Table_type      - one of the defined table types
+ * PARAMETERS:  table_type      - one of the defined table types
  *              Instance        - the non zero instance of the table, allows
  *                                support for multiple tables of the same type
- *                                see Acpi_gbl_Acpi_table_flag
- *              Ret_buffer      - pointer to a structure containing a buffer to
+ *                                see acpi_gbl_acpi_table_flag
+ *              ret_buffer      - pointer to a structure containing a buffer to
  *                                receive the table
  *
  * RETURN:      Status
  *
  * DESCRIPTION: This function is called to get an ACPI table.  The caller
- *              supplies an Out_buffer large enough to contain the entire ACPI
- *              table.  The caller should call the Acpi_get_table_header function
+ *              supplies an out_buffer large enough to contain the entire ACPI
+ *              table.  The caller should call the acpi_get_table_header function
  *              first to determine the buffer size needed.  Upon completion
- *              the Out_buffer->Length field will indicate the number of bytes
- *              copied into the Out_buffer->Buf_ptr buffer. This table will be
+ *              the out_buffer->Length field will indicate the number of bytes
+ *              copied into the out_buffer->buf_ptr buffer. This table will be
  *              a complete table including the header.
  *
  ******************************************************************************/
@@ -356,10 +355,10 @@
 {
 	acpi_table_header       *tbl_ptr;
 	acpi_status             status;
-	ACPI_SIZE               table_length;
+	acpi_size               table_length;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_get_table");
+	ACPI_FUNCTION_TRACE ("acpi_get_table");
 
 
 	/* Parameter validation */
@@ -390,7 +389,7 @@
 	}
 
 	/*
-	 * Acpi_tb_get_table_ptr will return a NULL pointer if the
+	 * acpi_tb_get_table_ptr will return a NULL pointer if the
 	 * table is not loaded.
 	 */
 	if (tbl_ptr == NULL) {
@@ -403,10 +402,10 @@
 		/*
 		 *  RSD PTR is the only "table" without a header
 		 */
-		table_length = sizeof (RSDP_DESCRIPTOR);
+		table_length = sizeof (rsdp_descriptor);
 	}
 	else {
-		table_length = (ACPI_SIZE) tbl_ptr->length;
+		table_length = (acpi_size) tbl_ptr->length;
 	}
 
 	/* Validate/Allocate/Clear caller buffer */
diff -Nru a/drivers/acpi/tables/tbxfroot.c b/drivers/acpi/tables/tbxfroot.c
--- a/drivers/acpi/tables/tbxfroot.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/acpi/tables/tbxfroot.c	Mon Dec 23 21:21:58 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: tbxfroot - Find the root ACPI table (RSDT)
- *              $Revision: 67 $
  *
  *****************************************************************************/
 
@@ -34,11 +33,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_find_table
+ * FUNCTION:    acpi_tb_find_table
  *
  * PARAMETERS:  Signature           - String with ACPI table signature
- *              Oem_id              - String with the table OEM ID
- *              Oem_table_id        - String with the OEM Table ID.
+ *              oem_id              - String with the table OEM ID
+ *              oem_table_id        - String with the OEM Table ID.
  *
  * RETURN:      Status
  *
@@ -58,7 +57,7 @@
 	acpi_table_header       *table;
 
 
-	ACPI_FUNCTION_TRACE ("Tb_find_table");
+	ACPI_FUNCTION_TRACE ("tb_find_table");
 
 
 	/* Validate string lengths */
@@ -77,7 +76,7 @@
 		return_ACPI_STATUS (status);
 	}
 
-	/* Check Oem_id and Oem_table_id */
+	/* Check oem_id and oem_table_id */
 
 	if ((oem_id[0]     && ACPI_STRCMP (oem_id, table->oem_id)) ||
 		(oem_table_id[0] && ACPI_STRCMP (oem_table_id, table->oem_table_id))) {
@@ -91,22 +90,22 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_get_firmware_table
+ * FUNCTION:    acpi_get_firmware_table
  *
  * PARAMETERS:  Signature       - Any ACPI table signature
  *              Instance        - the non zero instance of the table, allows
  *                                support for multiple tables of the same type
  *              Flags           - Physical/Virtual support
- *              Ret_buffer      - pointer to a structure containing a buffer to
+ *              ret_buffer      - pointer to a structure containing a buffer to
  *                                receive the table
  *
  * RETURN:      Status
  *
  * DESCRIPTION: This function is called to get an ACPI table.  The caller
- *              supplies an Out_buffer large enough to contain the entire ACPI
+ *              supplies an out_buffer large enough to contain the entire ACPI
  *              table.  Upon completion
- *              the Out_buffer->Length field will indicate the number of bytes
- *              copied into the Out_buffer->Buf_ptr buffer. This table will be
+ *              the out_buffer->Length field will indicate the number of bytes
+ *              copied into the out_buffer->buf_ptr buffer. This table will be
  *              a complete table including the header.
  *
  ******************************************************************************/
@@ -118,8 +117,8 @@
 	u32                     flags,
 	acpi_table_header       **table_pointer)
 {
-	ACPI_POINTER            rsdp_address;
-	ACPI_POINTER            address;
+	acpi_pointer            rsdp_address;
+	acpi_pointer            address;
 	acpi_status             status;
 	acpi_table_header       header;
 	acpi_table_desc         table_info;
@@ -129,7 +128,7 @@
 	u32                     j;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_get_firmware_table");
+	ACPI_FUNCTION_TRACE ("acpi_get_firmware_table");
 
 
 	/*
@@ -160,7 +159,7 @@
 		/* Map and validate the RSDP */
 
 		if ((flags & ACPI_MEMORY_MODE) == ACPI_LOGICAL_ADDRESSING) {
-			status = acpi_os_map_memory (rsdp_address.pointer.physical, sizeof (RSDP_DESCRIPTOR),
+			status = acpi_os_map_memory (rsdp_address.pointer.physical, sizeof (rsdp_descriptor),
 					  (void **) &acpi_gbl_RSDP);
 			if (ACPI_FAILURE (status)) {
 				return_ACPI_STATUS (status);
@@ -196,7 +195,7 @@
 		ACPI_HIDWORD (address.pointer.value),
 		ACPI_LODWORD (address.pointer.value)));
 
-	/* Insert Processor_mode flags */
+	/* Insert processor_mode flags */
 
 	address.pointer_type |= flags;
 
@@ -264,7 +263,7 @@
 
 
 cleanup:
-	acpi_os_unmap_memory (rsdt_info.pointer, (ACPI_SIZE) rsdt_info.pointer->length);
+	acpi_os_unmap_memory (rsdt_info.pointer, (acpi_size) rsdt_info.pointer->length);
 	return_ACPI_STATUS (status);
 }
 
@@ -275,9 +274,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_find_root_pointer
+ * FUNCTION:    acpi_find_root_pointer
  *
- * PARAMETERS:  **Rsdp_address          - Where to place the RSDP address
+ * PARAMETERS:  **rsdp_address          - Where to place the RSDP address
  *              Flags                   - Logical/Physical addressing
  *
  * RETURN:      Status, Physical address of the RSDP
@@ -289,13 +288,13 @@
 acpi_status
 acpi_find_root_pointer (
 	u32                     flags,
-	ACPI_POINTER            *rsdp_address)
+	acpi_pointer            *rsdp_address)
 {
 	acpi_table_desc         table_info;
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_find_root_pointer");
+	ACPI_FUNCTION_TRACE ("acpi_find_root_pointer");
 
 
 	/* Get the RSDP */
@@ -315,9 +314,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_scan_memory_for_rsdp
+ * FUNCTION:    acpi_tb_scan_memory_for_rsdp
  *
- * PARAMETERS:  Start_address       - Starting pointer for search
+ * PARAMETERS:  start_address       - Starting pointer for search
  *              Length              - Maximum length to search
  *
  * RETURN:      Pointer to the RSDP if found, otherwise NULL.
@@ -335,7 +334,7 @@
 	u8                      *mem_rover;
 
 
-	ACPI_FUNCTION_TRACE ("Tb_scan_memory_for_rsdp");
+	ACPI_FUNCTION_TRACE ("tb_scan_memory_for_rsdp");
 
 
 	/* Search from given start addr for the requested length  */
@@ -366,18 +365,18 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_tb_find_rsdp
+ * FUNCTION:    acpi_tb_find_rsdp
  *
- * PARAMETERS:  *Table_info             - Where the table info is returned
+ * PARAMETERS:  *table_info             - Where the table info is returned
  *              Flags                   - Current memory mode (logical vs.
  *                                        physical addressing)
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Search lower 1_mbyte of memory for the root system descriptor
+ * DESCRIPTION: search lower 1_mbyte of memory for the root system descriptor
  *              pointer structure.  If it is found, set *RSDP to point to it.
  *
- *              NOTE: The RSDP must be either in the first 1_k of the Extended
+ *              NOTE: The RSDp must be either in the first 1_k of the Extended
  *              BIOS Data Area or between E0000 and FFFFF (ACPI 1.0 section
  *              5.2.2; assertion #421).
  *
@@ -394,7 +393,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Tb_find_rsdp");
+	ACPI_FUNCTION_TRACE ("tb_find_rsdp");
 
 
 	/*
diff -Nru a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
--- a/drivers/acpi/thermal.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/acpi/thermal.c	Mon Dec 23 21:22:00 2002
@@ -1123,8 +1123,10 @@
 {
 	ACPI_FUNCTION_TRACE("acpi_thermal_remove_fs");
 
-	if (acpi_device_dir(device))
+	if (acpi_device_dir(device)) {
 		remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
+		acpi_device_dir(device) = NULL;
+	}
 
 	return_VALUE(0);
 }
diff -Nru a/drivers/acpi/utilities/utalloc.c b/drivers/acpi/utilities/utalloc.c
--- a/drivers/acpi/utilities/utalloc.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/utilities/utalloc.c	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: utalloc - local cache and memory allocation routines
- *              $Revision: 130 $
  *
  *****************************************************************************/
 
@@ -32,9 +31,9 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_ut_release_to_cache
+ * FUNCTION:    acpi_ut_release_to_cache
  *
- * PARAMETERS:  List_id             - Memory list/cache ID
+ * PARAMETERS:  list_id             - Memory list/cache ID
  *              Object              - The object to be released
  *
  * RETURN:      None
@@ -49,7 +48,7 @@
 	u32                     list_id,
 	void                    *object)
 {
-	ACPI_MEMORY_LIST        *cache_info;
+	acpi_memory_list        *cache_info;
 
 
 	ACPI_FUNCTION_ENTRY ();
@@ -88,9 +87,9 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_ut_acquire_from_cache
+ * FUNCTION:    acpi_ut_acquire_from_cache
  *
- * PARAMETERS:  List_id             - Memory list ID
+ * PARAMETERS:  list_id             - Memory list ID
  *
  * RETURN:      A requested object.  NULL if the object could not be
  *              allocated.
@@ -104,11 +103,11 @@
 acpi_ut_acquire_from_cache (
 	u32                     list_id)
 {
-	ACPI_MEMORY_LIST        *cache_info;
+	acpi_memory_list        *cache_info;
 	void                    *object;
 
 
-	ACPI_FUNCTION_NAME ("Ut_acquire_from_cache");
+	ACPI_FUNCTION_NAME ("ut_acquire_from_cache");
 
 
 	cache_info = &acpi_gbl_memory_lists[list_id];
@@ -162,9 +161,9 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_ut_delete_generic_cache
+ * FUNCTION:    acpi_ut_delete_generic_cache
  *
- * PARAMETERS:  List_id         - Memory list ID
+ * PARAMETERS:  list_id         - Memory list ID
  *
  * RETURN:      None
  *
@@ -176,7 +175,7 @@
 acpi_ut_delete_generic_cache (
 	u32                     list_id)
 {
-	ACPI_MEMORY_LIST        *cache_info;
+	acpi_memory_list        *cache_info;
 	char                    *next;
 
 
@@ -198,7 +197,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_validate_buffer
+ * FUNCTION:    acpi_ut_validate_buffer
  *
  * PARAMETERS:  Buffer              - Buffer descriptor to be validated
  *
@@ -239,9 +238,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_initialize_buffer
+ * FUNCTION:    acpi_ut_initialize_buffer
  *
- * PARAMETERS:  Required_length     - Length needed
+ * PARAMETERS:  required_length     - Length needed
  *              Buffer              - Buffer to be validated
  *
  * RETURN:      Status
@@ -254,7 +253,7 @@
 acpi_status
 acpi_ut_initialize_buffer (
 	acpi_buffer             *buffer,
-	ACPI_SIZE               required_length)
+	acpi_size               required_length)
 {
 	acpi_status             status = AE_OK;
 
@@ -315,7 +314,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_allocate
+ * FUNCTION:    acpi_ut_allocate
  *
  * PARAMETERS:  Size                - Size of the allocation
  *              Component           - Component type of caller
@@ -330,7 +329,7 @@
 
 void *
 acpi_ut_allocate (
-	ACPI_SIZE               size,
+	acpi_size               size,
 	u32                     component,
 	char                    *module,
 	u32                     line)
@@ -338,14 +337,14 @@
 	void                    *allocation;
 
 
-	ACPI_FUNCTION_TRACE_U32 ("Ut_allocate", size);
+	ACPI_FUNCTION_TRACE_U32 ("ut_allocate", size);
 
 
 	/* Check for an inadvertent size of zero bytes */
 
 	if (!size) {
 		_ACPI_REPORT_ERROR (module, line, component,
-				("Ut_allocate: Attempt to allocate zero bytes\n"));
+				("ut_allocate: Attempt to allocate zero bytes\n"));
 		size = 1;
 	}
 
@@ -354,7 +353,7 @@
 		/* Report allocation error */
 
 		_ACPI_REPORT_ERROR (module, line, component,
-				("Ut_allocate: Could not allocate size %X\n", (u32) size));
+				("ut_allocate: Could not allocate size %X\n", (u32) size));
 
 		return_PTR (NULL);
 	}
@@ -365,7 +364,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_callocate
+ * FUNCTION:    acpi_ut_callocate
  *
  * PARAMETERS:  Size                - Size of the allocation
  *              Component           - Component type of caller
@@ -380,7 +379,7 @@
 
 void *
 acpi_ut_callocate (
-	ACPI_SIZE               size,
+	acpi_size               size,
 	u32                     component,
 	char                    *module,
 	u32                     line)
@@ -388,14 +387,14 @@
 	void                    *allocation;
 
 
-	ACPI_FUNCTION_TRACE_U32 ("Ut_callocate", size);
+	ACPI_FUNCTION_TRACE_U32 ("ut_callocate", size);
 
 
 	/* Check for an inadvertent size of zero bytes */
 
 	if (!size) {
 		_ACPI_REPORT_ERROR (module, line, component,
-				("Ut_callocate: Attempt to allocate zero bytes\n"));
+				("ut_callocate: Attempt to allocate zero bytes\n"));
 		return_PTR (NULL);
 	}
 
@@ -404,7 +403,7 @@
 		/* Report allocation error */
 
 		_ACPI_REPORT_ERROR (module, line, component,
-				("Ut_callocate: Could not allocate size %X\n", (u32) size));
+				("ut_callocate: Could not allocate size %X\n", (u32) size));
 		return_PTR (NULL);
 	}
 
@@ -422,15 +421,15 @@
  *
  * Each memory allocation is tracked via a doubly linked list.  Each
  * element contains the caller's component, module name, function name, and
- * line number.  Acpi_ut_allocate and Acpi_ut_callocate call
- * Acpi_ut_track_allocation to add an element to the list; deletion
- * occurs in the body of Acpi_ut_free.
+ * line number.  acpi_ut_allocate and acpi_ut_callocate call
+ * acpi_ut_track_allocation to add an element to the list; deletion
+ * occurs in the body of acpi_ut_free.
  */
 
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_allocate_and_track
+ * FUNCTION:    acpi_ut_allocate_and_track
  *
  * PARAMETERS:  Size                - Size of the allocation
  *              Component           - Component type of caller
@@ -445,7 +444,7 @@
 
 void *
 acpi_ut_allocate_and_track (
-	ACPI_SIZE               size,
+	acpi_size               size,
 	u32                     component,
 	char                    *module,
 	u32                     line)
@@ -476,7 +475,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_callocate_and_track
+ * FUNCTION:    acpi_ut_callocate_and_track
  *
  * PARAMETERS:  Size                - Size of the allocation
  *              Component           - Component type of caller
@@ -491,7 +490,7 @@
 
 void *
 acpi_ut_callocate_and_track (
-	ACPI_SIZE               size,
+	acpi_size               size,
 	u32                     component,
 	char                    *module,
 	u32                     line)
@@ -506,7 +505,7 @@
 		/* Report allocation error */
 
 		_ACPI_REPORT_ERROR (module, line, component,
-				("Ut_callocate: Could not allocate size %X\n", (u32) size));
+				("ut_callocate: Could not allocate size %X\n", (u32) size));
 		return (NULL);
 	}
 
@@ -526,7 +525,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_free_and_track
+ * FUNCTION:    acpi_ut_free_and_track
  *
  * PARAMETERS:  Allocation          - Address of the memory to deallocate
  *              Component           - Component type of caller
@@ -550,12 +549,12 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ut_free", allocation);
+	ACPI_FUNCTION_TRACE_PTR ("ut_free", allocation);
 
 
 	if (NULL == allocation) {
 		_ACPI_REPORT_ERROR (module, line, component,
-			("Acpi_ut_free: Attempt to delete a NULL address\n"));
+			("acpi_ut_free: Attempt to delete a NULL address\n"));
 
 		return_VOID;
 	}
@@ -583,7 +582,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_find_allocation
+ * FUNCTION:    acpi_ut_find_allocation
  *
  * PARAMETERS:  Allocation             - Address of allocated memory
  *
@@ -626,11 +625,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_track_allocation
+ * FUNCTION:    acpi_ut_track_allocation
  *
  * PARAMETERS:  Allocation          - Address of allocated memory
  *              Size                - Size of the allocation
- *              Alloc_type          - MEM_MALLOC or MEM_CALLOC
+ *              alloc_type          - MEM_MALLOC or MEM_CALLOC
  *              Component           - Component type of caller
  *              Module              - Source file name of caller
  *              Line                - Line number of caller
@@ -645,18 +644,18 @@
 acpi_ut_track_allocation (
 	u32                     list_id,
 	acpi_debug_mem_block    *allocation,
-	ACPI_SIZE               size,
+	acpi_size               size,
 	u8                      alloc_type,
 	u32                     component,
 	char                    *module,
 	u32                     line)
 {
-	ACPI_MEMORY_LIST        *mem_list;
+	acpi_memory_list        *mem_list;
 	acpi_debug_mem_block    *element;
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ut_track_allocation", allocation);
+	ACPI_FUNCTION_TRACE_PTR ("ut_track_allocation", allocation);
 
 
 	if (list_id > ACPI_MEM_LIST_MAX) {
@@ -676,7 +675,7 @@
 
 	element = acpi_ut_find_allocation (list_id, allocation);
 	if (element) {
-		ACPI_REPORT_ERROR (("Ut_track_allocation: Allocation already present in list! (%p)\n",
+		ACPI_REPORT_ERROR (("ut_track_allocation: Allocation already present in list! (%p)\n",
 			allocation));
 
 		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Element %p Address %p\n", element, allocation));
@@ -713,7 +712,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_remove_allocation
+ * FUNCTION:    acpi_ut_remove_allocation
  *
  * PARAMETERS:  Allocation          - Address of allocated memory
  *              Component           - Component type of caller
@@ -734,11 +733,11 @@
 	char                    *module,
 	u32                     line)
 {
-	ACPI_MEMORY_LIST        *mem_list;
+	acpi_memory_list        *mem_list;
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_remove_allocation");
+	ACPI_FUNCTION_TRACE ("ut_remove_allocation");
 
 
 	if (list_id > ACPI_MEM_LIST_MAX) {
@@ -750,7 +749,7 @@
 		/* No allocations! */
 
 		_ACPI_REPORT_ERROR (module, line, component,
-				("Ut_remove_allocation: Empty allocation list, nothing to free!\n"));
+				("ut_remove_allocation: Empty allocation list, nothing to free!\n"));
 
 		return_ACPI_STATUS (AE_OK);
 	}
@@ -786,7 +785,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_dump_allocation_info
+ * FUNCTION:    acpi_ut_dump_allocation_info
  *
  * PARAMETERS:
  *
@@ -801,43 +800,43 @@
 	void)
 {
 /*
-	ACPI_MEMORY_LIST        *Mem_list;
+	acpi_memory_list        *mem_list;
 */
 
-	ACPI_FUNCTION_TRACE ("Ut_dump_allocation_info");
+	ACPI_FUNCTION_TRACE ("ut_dump_allocation_info");
 
 /*
 	ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
 			  ("%30s: %4d (%3d Kb)\n", "Current allocations",
-			  Mem_list->Current_count,
-			  ROUND_UP_TO_1K (Mem_list->Current_size)));
+			  mem_list->current_count,
+			  ROUND_UP_TO_1K (mem_list->current_size)));
 
 	ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
 			  ("%30s: %4d (%3d Kb)\n", "Max concurrent allocations",
-			  Mem_list->Max_concurrent_count,
-			  ROUND_UP_TO_1K (Mem_list->Max_concurrent_size)));
+			  mem_list->max_concurrent_count,
+			  ROUND_UP_TO_1K (mem_list->max_concurrent_size)));
 
 
 	ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
 			  ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects",
-			  Running_object_count,
-			  ROUND_UP_TO_1K (Running_object_size)));
+			  running_object_count,
+			  ROUND_UP_TO_1K (running_object_size)));
 
 	ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
 			  ("%30s: %4d (%3d Kb)\n", "Total (all) allocations",
-			  Running_alloc_count,
-			  ROUND_UP_TO_1K (Running_alloc_size)));
+			  running_alloc_count,
+			  ROUND_UP_TO_1K (running_alloc_size)));
 
 
 	ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
 			  ("%30s: %4d (%3d Kb)\n", "Current Nodes",
-			  Acpi_gbl_Current_node_count,
-			  ROUND_UP_TO_1K (Acpi_gbl_Current_node_size)));
+			  acpi_gbl_current_node_count,
+			  ROUND_UP_TO_1K (acpi_gbl_current_node_size)));
 
 	ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
 			  ("%30s: %4d (%3d Kb)\n", "Max Nodes",
-			  Acpi_gbl_Max_concurrent_node_count,
-			  ROUND_UP_TO_1K ((Acpi_gbl_Max_concurrent_node_count * sizeof (acpi_namespace_node)))));
+			  acpi_gbl_max_concurrent_node_count,
+			  ROUND_UP_TO_1K ((acpi_gbl_max_concurrent_node_count * sizeof (acpi_namespace_node)))));
 */
 	return_VOID;
 }
@@ -845,7 +844,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_dump_allocations
+ * FUNCTION:    acpi_ut_dump_allocations
  *
  * PARAMETERS:  Component           - Component(s) to dump info for.
  *              Module              - Module to dump info for.  NULL means all.
@@ -862,11 +861,11 @@
 	char                    *module)
 {
 	acpi_debug_mem_block    *element;
-	ACPI_DESCRIPTOR         *descriptor;
+	acpi_descriptor         *descriptor;
 	u32                     num_outstanding = 0;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_dump_allocations");
+	ACPI_FUNCTION_TRACE ("ut_dump_allocations");
 
 
 	/*
@@ -882,7 +881,7 @@
 			((module == NULL) || (0 == ACPI_STRCMP (module, element->module)))) {
 			/* Ignore allocated objects that are in a cache */
 
-			descriptor = ACPI_CAST_PTR (ACPI_DESCRIPTOR, &element->user_space);
+			descriptor = ACPI_CAST_PTR (acpi_descriptor, &element->user_space);
 			if (descriptor->descriptor_id != ACPI_DESC_TYPE_CACHED) {
 				acpi_os_printf ("%p Len %04X %9.9s-%d ",
 						 descriptor, element->size, element->module,
@@ -892,13 +891,13 @@
 
 				switch (ACPI_GET_DESCRIPTOR_TYPE (descriptor)) {
 				case ACPI_DESC_TYPE_OPERAND:
-					acpi_os_printf ("Obj_type %12.12s R%hd",
+					acpi_os_printf ("obj_type %12.12s R%hd",
 							acpi_ut_get_type_name (descriptor->object.common.type),
 							descriptor->object.common.reference_count);
 					break;
 
 				case ACPI_DESC_TYPE_PARSER:
-					acpi_os_printf ("Parse_obj Aml_opcode %04hX",
+					acpi_os_printf ("parse_obj aml_opcode %04hX",
 							descriptor->op.asl.aml_opcode);
 					break;
 
@@ -908,43 +907,43 @@
 					break;
 
 				case ACPI_DESC_TYPE_STATE:
-					acpi_os_printf ("Untyped State_obj");
+					acpi_os_printf ("Untyped state_obj");
 					break;
 
 				case ACPI_DESC_TYPE_STATE_UPDATE:
-					acpi_os_printf ("UPDATE State_obj");
+					acpi_os_printf ("UPDATE state_obj");
 					break;
 
 				case ACPI_DESC_TYPE_STATE_PACKAGE:
-					acpi_os_printf ("PACKAGE State_obj");
+					acpi_os_printf ("PACKAGE state_obj");
 					break;
 
 				case ACPI_DESC_TYPE_STATE_CONTROL:
-					acpi_os_printf ("CONTROL State_obj");
+					acpi_os_printf ("CONTROL state_obj");
 					break;
 
 				case ACPI_DESC_TYPE_STATE_RPSCOPE:
-					acpi_os_printf ("ROOT-PARSE-SCOPE State_obj");
+					acpi_os_printf ("ROOT-PARSE-SCOPE state_obj");
 					break;
 
 				case ACPI_DESC_TYPE_STATE_PSCOPE:
-					acpi_os_printf ("PARSE-SCOPE State_obj");
+					acpi_os_printf ("PARSE-SCOPE state_obj");
 					break;
 
 				case ACPI_DESC_TYPE_STATE_WSCOPE:
-					acpi_os_printf ("WALK-SCOPE State_obj");
+					acpi_os_printf ("WALK-SCOPE state_obj");
 					break;
 
 				case ACPI_DESC_TYPE_STATE_RESULT:
-					acpi_os_printf ("RESULT State_obj");
+					acpi_os_printf ("RESULT state_obj");
 					break;
 
 				case ACPI_DESC_TYPE_STATE_NOTIFY:
-					acpi_os_printf ("NOTIFY State_obj");
+					acpi_os_printf ("NOTIFY state_obj");
 					break;
 
 				case ACPI_DESC_TYPE_STATE_THREAD:
-					acpi_os_printf ("THREAD State_obj");
+					acpi_os_printf ("THREAD state_obj");
 					break;
 
 				default:
diff -Nru a/drivers/acpi/utilities/utcopy.c b/drivers/acpi/utilities/utcopy.c
--- a/drivers/acpi/utilities/utcopy.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/acpi/utilities/utcopy.c	Mon Dec 23 21:21:53 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: utcopy - Internal to external object translation utilities
- *              $Revision: 109 $
  *
  *****************************************************************************/
 
@@ -34,11 +33,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_copy_isimple_to_esimple
+ * FUNCTION:    acpi_ut_copy_isimple_to_esimple
  *
- * PARAMETERS:  *Internal_object    - Pointer to the object we are examining
+ * PARAMETERS:  *internal_object    - Pointer to the object we are examining
  *              *Buffer             - Where the object is returned
- *              *Space_used         - Where the data length is returned
+ *              *space_used         - Where the data length is returned
  *
  * RETURN:      Status
  *
@@ -54,12 +53,12 @@
 	acpi_operand_object     *internal_object,
 	acpi_object             *external_object,
 	u8                      *data_space,
-	ACPI_SIZE               *buffer_space_used)
+	acpi_size               *buffer_space_used)
 {
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_copy_isimple_to_esimple");
+	ACPI_FUNCTION_TRACE ("ut_copy_isimple_to_esimple");
 
 
 	*buffer_space_used = 0;
@@ -89,10 +88,10 @@
 
 		external_object->string.pointer = (char *) data_space;
 		external_object->string.length = internal_object->string.length;
-		*buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD ((ACPI_SIZE) internal_object->string.length + 1);
+		*buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD ((acpi_size) internal_object->string.length + 1);
 
 		ACPI_MEMCPY ((void *) data_space, (void *) internal_object->string.pointer,
-				 (ACPI_SIZE) internal_object->string.length + 1);
+				 (acpi_size) internal_object->string.length + 1);
 		break;
 
 
@@ -166,9 +165,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_copy_ielement_to_eelement
+ * FUNCTION:    acpi_ut_copy_ielement_to_eelement
  *
- * PARAMETERS:  ACPI_PKG_CALLBACK
+ * PARAMETERS:  acpi_pkg_callback
  *
  * RETURN:      Status
  *
@@ -185,7 +184,7 @@
 {
 	acpi_status             status = AE_OK;
 	acpi_pkg_info           *info = (acpi_pkg_info *) context;
-	ACPI_SIZE               object_space;
+	acpi_size               object_space;
 	u32                     this_index;
 	acpi_object             *target_object;
 
@@ -230,7 +229,7 @@
 		 * update the buffer length counter
 		 */
 		object_space = ACPI_ROUND_UP_TO_NATIVE_WORD (
-				   (ACPI_SIZE) target_object->package.count * sizeof (acpi_object));
+				   (acpi_size) target_object->package.count * sizeof (acpi_object));
 		break;
 
 
@@ -246,11 +245,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_copy_ipackage_to_epackage
+ * FUNCTION:    acpi_ut_copy_ipackage_to_epackage
  *
- * PARAMETERS:  *Internal_object    - Pointer to the object we are returning
+ * PARAMETERS:  *internal_object    - Pointer to the object we are returning
  *              *Buffer             - Where the object is returned
- *              *Space_used         - Where the object length is returned
+ *              *space_used         - Where the object length is returned
  *
  * RETURN:      Status
  *
@@ -259,7 +258,7 @@
  *
  *              The buffer is assumed to have sufficient space for the object.
  *              The caller must have verified the buffer length needed using the
- *              Acpi_ut_get_object_size function before calling this function.
+ *              acpi_ut_get_object_size function before calling this function.
  *
  ******************************************************************************/
 
@@ -267,14 +266,14 @@
 acpi_ut_copy_ipackage_to_epackage (
 	acpi_operand_object     *internal_object,
 	u8                      *buffer,
-	ACPI_SIZE               *space_used)
+	acpi_size               *space_used)
 {
 	acpi_object             *external_object;
 	acpi_status             status;
 	acpi_pkg_info           info;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_copy_ipackage_to_epackage");
+	ACPI_FUNCTION_TRACE ("ut_copy_ipackage_to_epackage");
 
 
 	/*
@@ -298,7 +297,7 @@
 	 * Leave room for an array of ACPI_OBJECTS in the buffer
 	 * and move the free space past it
 	 */
-	info.length    += (ACPI_SIZE) external_object->package.count *
+	info.length    += (acpi_size) external_object->package.count *
 			 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (acpi_object));
 	info.free_space += external_object->package.count *
 			 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (acpi_object));
@@ -313,10 +312,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_copy_iobject_to_eobject
+ * FUNCTION:    acpi_ut_copy_iobject_to_eobject
  *
- * PARAMETERS:  *Internal_object    - The internal object to be converted
- *              *Buffer_ptr         - Where the object is returned
+ * PARAMETERS:  *internal_object    - The internal object to be converted
+ *              *buffer_ptr         - Where the object is returned
  *
  * RETURN:      Status
  *
@@ -333,7 +332,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_copy_iobject_to_eobject");
+	ACPI_FUNCTION_TRACE ("ut_copy_iobject_to_eobject");
 
 
 	if (ACPI_GET_OBJECT_TYPE (internal_object) == ACPI_TYPE_PACKAGE) {
@@ -366,10 +365,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_copy_esimple_to_isimple
+ * FUNCTION:    acpi_ut_copy_esimple_to_isimple
  *
- * PARAMETERS:  *External_object   - The external object to be converted
- *              *Internal_object   - Where the internal object is returned
+ * PARAMETERS:  *external_object   - The external object to be converted
+ *              *internal_object   - Where the internal object is returned
  *
  * RETURN:      Status
  *
@@ -388,7 +387,7 @@
 	acpi_operand_object     *internal_object;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_copy_esimple_to_isimple");
+	ACPI_FUNCTION_TRACE ("ut_copy_esimple_to_isimple");
 
 
 	/*
@@ -420,7 +419,7 @@
 	case ACPI_TYPE_STRING:
 
 		internal_object->string.pointer =
-			ACPI_MEM_CALLOCATE ((ACPI_SIZE) external_object->string.length + 1);
+			ACPI_MEM_CALLOCATE ((acpi_size) external_object->string.length + 1);
 		if (!internal_object->string.pointer) {
 			return_ACPI_STATUS (AE_NO_MEMORY);
 		}
@@ -470,11 +469,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_copy_epackage_to_ipackage
+ * FUNCTION:    acpi_ut_copy_epackage_to_ipackage
  *
- * PARAMETERS:  *Internal_object   - Pointer to the object we are returning
+ * PARAMETERS:  *internal_object   - Pointer to the object we are returning
  *              *Buffer            - Where the object is returned
- *              *Space_used        - Where the length of the object is returned
+ *              *space_used        - Where the length of the object is returned
  *
  * RETURN:      Status
  *
@@ -483,7 +482,7 @@
  *
  *              The buffer is assumed to have sufficient space for the object.
  *              The caller must have verified the buffer length needed using the
- *              Acpi_ut_get_object_size function before calling this function.
+ *              acpi_ut_get_object_size function before calling this function.
  *
  ******************************************************************************/
 
@@ -502,7 +501,7 @@
 	acpi_object             *this_external_obj;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_copy_epackage_to_ipackage");
+	ACPI_FUNCTION_TRACE ("ut_copy_epackage_to_ipackage");
 
 
 	/*
@@ -527,7 +526,7 @@
 	free_space += external_object->package.count * sizeof(acpi_object);
 
 
-	/* Call Walk_package */
+	/* Call walk_package */
 
 }
 
@@ -536,10 +535,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_copy_eobject_to_iobject
+ * FUNCTION:    acpi_ut_copy_eobject_to_iobject
  *
- * PARAMETERS:  *Internal_object   - The external object to be converted
- *              *Buffer_ptr     - Where the internal object is returned
+ * PARAMETERS:  *internal_object   - The external object to be converted
+ *              *buffer_ptr     - Where the internal object is returned
  *
  * RETURN:      Status          - the status of the call
  *
@@ -555,7 +554,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_copy_eobject_to_iobject");
+	ACPI_FUNCTION_TRACE ("ut_copy_eobject_to_iobject");
 
 
 	if (external_object->type == ACPI_TYPE_PACKAGE) {
@@ -581,10 +580,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_copy_simple_object
+ * FUNCTION:    acpi_ut_copy_simple_object
  *
- * PARAMETERS:  Source_desc         - The internal object to be copied
- *              Dest_desc           - New target object
+ * PARAMETERS:  source_desc         - The internal object to be copied
+ *              dest_desc           - New target object
  *
  * RETURN:      Status
  *
@@ -674,9 +673,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_copy_ielement_to_ielement
+ * FUNCTION:    acpi_ut_copy_ielement_to_ielement
  *
- * PARAMETERS:  ACPI_PKG_CALLBACK
+ * PARAMETERS:  acpi_pkg_callback
  *
  * RETURN:      Status
  *
@@ -752,7 +751,7 @@
 		 * Create the object array
 		 */
 		target_object->package.elements =
-			ACPI_MEM_CALLOCATE (((ACPI_SIZE) source_object->package.count + 1) *
+			ACPI_MEM_CALLOCATE (((acpi_size) source_object->package.count + 1) *
 					 sizeof (void *));
 		if (!target_object->package.elements) {
 			ACPI_MEM_FREE (target_object);
@@ -781,10 +780,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_copy_ipackage_to_ipackage
+ * FUNCTION:    acpi_ut_copy_ipackage_to_ipackage
  *
- * PARAMETERS:  *Source_obj     - Pointer to the source package object
- *              *Dest_obj       - Where the internal object is returned
+ * PARAMETERS:  *source_obj     - Pointer to the source package object
+ *              *dest_obj       - Where the internal object is returned
  *
  * RETURN:      Status          - the status of the call
  *
@@ -802,7 +801,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_copy_ipackage_to_ipackage");
+	ACPI_FUNCTION_TRACE ("ut_copy_ipackage_to_ipackage");
 
 
 	dest_obj->common.type   = ACPI_GET_OBJECT_TYPE (source_obj);
@@ -813,11 +812,11 @@
 	 * Create the object array and walk the source package tree
 	 */
 	dest_obj->package.elements = ACPI_MEM_CALLOCATE (
-			   ((ACPI_SIZE) source_obj->package.count + 1) *
+			   ((acpi_size) source_obj->package.count + 1) *
 			   sizeof (void *));
 	if (!dest_obj->package.elements) {
 		ACPI_REPORT_ERROR (
-			("Aml_build_copy_internal_package_object: Package allocation failure\n"));
+			("aml_build_copy_internal_package_object: Package allocation failure\n"));
 		return_ACPI_STATUS (AE_NO_MEMORY);
 	}
 
@@ -839,11 +838,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_copy_iobject_to_iobject
+ * FUNCTION:    acpi_ut_copy_iobject_to_iobject
  *
- * PARAMETERS:  Walk_state          - Current walk state
- *              Source_desc         - The internal object to be copied
- *              Dest_desc           - Where the copied object is returned
+ * PARAMETERS:  walk_state          - Current walk state
+ *              source_desc         - The internal object to be copied
+ *              dest_desc           - Where the copied object is returned
  *
  * RETURN:      Status
  *
@@ -860,7 +859,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_copy_iobject_to_iobject");
+	ACPI_FUNCTION_TRACE ("ut_copy_iobject_to_iobject");
 
 
 	/* Create the top level object */
diff -Nru a/drivers/acpi/utilities/utdebug.c b/drivers/acpi/utilities/utdebug.c
--- a/drivers/acpi/utilities/utdebug.c	Mon Dec 23 21:21:57 2002
+++ b/drivers/acpi/utilities/utdebug.c	Mon Dec 23 21:21:57 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: utdebug - Debug print routines
- *              $Revision: 106 $
  *
  *****************************************************************************/
 
@@ -39,7 +38,7 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_init_stack_ptr_trace
+ * FUNCTION:    acpi_ut_init_stack_ptr_trace
  *
  * PARAMETERS:  None
  *
@@ -62,7 +61,7 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_track_stack_ptr
+ * FUNCTION:    acpi_ut_track_stack_ptr
  *
  * PARAMETERS:  None
  *
@@ -76,7 +75,7 @@
 acpi_ut_track_stack_ptr (
 	void)
 {
-	ACPI_SIZE           current_sp;
+	acpi_size           current_sp;
 
 
 	current_sp = ACPI_PTR_DIFF (&current_sp, NULL);
@@ -93,13 +92,13 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_debug_print
+ * FUNCTION:    acpi_ut_debug_print
  *
- * PARAMETERS:  Debug_level         - Requested debug print level
- *              Proc_name           - Caller's procedure name
- *              Module_name         - Caller's module name (for error output)
- *              Line_number         - Caller's line number (for error output)
- *              Component_id        - Caller's component ID (for error output)
+ * PARAMETERS:  debug_level         - Requested debug print level
+ *              proc_name           - Caller's procedure name
+ *              module_name         - Caller's module name (for error output)
+ *              line_number         - Caller's line number (for error output)
+ *              component_id        - Caller's component ID (for error output)
  *
  *              Format              - Printf format field
  *              ...                 - Optional printf arguments
@@ -164,21 +163,21 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_debug_print_raw
+ * FUNCTION:    acpi_ut_debug_print_raw
  *
- * PARAMETERS:  Requested_debug_level - Requested debug print level
- *              Line_number         - Caller's line number
- *              Dbg_info            - Contains:
- *                  Proc_name           - Caller's procedure name
- *                  Module_name         - Caller's module name
- *                  Component_id        - Caller's component ID
+ * PARAMETERS:  requested_debug_level - Requested debug print level
+ *              line_number         - Caller's line number
+ *              dbg_info            - Contains:
+ *                  proc_name           - Caller's procedure name
+ *                  module_name         - Caller's module name
+ *                  component_id        - Caller's component ID
  *              Format              - Printf format field
  *              ...                 - Optional printf arguments
  *
  * RETURN:      None
  *
  * DESCRIPTION: Print message with no headers.  Has same interface as
- *              Debug_print so that the same macros can be used.
+ *              debug_print so that the same macros can be used.
  *
  ****************************************************************************/
 
@@ -205,18 +204,18 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_trace
+ * FUNCTION:    acpi_ut_trace
  *
- * PARAMETERS:  Line_number         - Caller's line number
- *              Dbg_info            - Contains:
- *                  Proc_name           - Caller's procedure name
- *                  Module_name         - Caller's module name
- *                  Component_id        - Caller's component ID
+ * PARAMETERS:  line_number         - Caller's line number
+ *              dbg_info            - Contains:
+ *                  proc_name           - Caller's procedure name
+ *                  module_name         - Caller's module name
+ *                  component_id        - Caller's component ID
  *
  * RETURN:      None
  *
  * DESCRIPTION: Function entry trace.  Prints only if TRACE_FUNCTIONS bit is
- *              set in Debug_level
+ *              set in debug_level
  *
  ****************************************************************************/
 
@@ -236,19 +235,19 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_trace_ptr
+ * FUNCTION:    acpi_ut_trace_ptr
  *
- * PARAMETERS:  Line_number         - Caller's line number
- *              Dbg_info            - Contains:
- *                  Proc_name           - Caller's procedure name
- *                  Module_name         - Caller's module name
- *                  Component_id        - Caller's component ID
+ * PARAMETERS:  line_number         - Caller's line number
+ *              dbg_info            - Contains:
+ *                  proc_name           - Caller's procedure name
+ *                  module_name         - Caller's module name
+ *                  component_id        - Caller's component ID
  *              Pointer             - Pointer to display
  *
  * RETURN:      None
  *
  * DESCRIPTION: Function entry trace.  Prints only if TRACE_FUNCTIONS bit is
- *              set in Debug_level
+ *              set in debug_level
  *
  ****************************************************************************/
 
@@ -268,19 +267,19 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_trace_str
+ * FUNCTION:    acpi_ut_trace_str
  *
- * PARAMETERS:  Line_number         - Caller's line number
- *              Dbg_info            - Contains:
- *                  Proc_name           - Caller's procedure name
- *                  Module_name         - Caller's module name
- *                  Component_id        - Caller's component ID
+ * PARAMETERS:  line_number         - Caller's line number
+ *              dbg_info            - Contains:
+ *                  proc_name           - Caller's procedure name
+ *                  module_name         - Caller's module name
+ *                  component_id        - Caller's component ID
  *              String              - Additional string to display
  *
  * RETURN:      None
  *
  * DESCRIPTION: Function entry trace.  Prints only if TRACE_FUNCTIONS bit is
- *              set in Debug_level
+ *              set in debug_level
  *
  ****************************************************************************/
 
@@ -301,19 +300,19 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_trace_u32
+ * FUNCTION:    acpi_ut_trace_u32
  *
- * PARAMETERS:  Line_number         - Caller's line number
- *              Dbg_info            - Contains:
- *                  Proc_name           - Caller's procedure name
- *                  Module_name         - Caller's module name
- *                  Component_id        - Caller's component ID
+ * PARAMETERS:  line_number         - Caller's line number
+ *              dbg_info            - Contains:
+ *                  proc_name           - Caller's procedure name
+ *                  module_name         - Caller's module name
+ *                  component_id        - Caller's component ID
  *              Integer             - Integer to display
  *
  * RETURN:      None
  *
  * DESCRIPTION: Function entry trace.  Prints only if TRACE_FUNCTIONS bit is
- *              set in Debug_level
+ *              set in debug_level
  *
  ****************************************************************************/
 
@@ -334,18 +333,18 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_exit
+ * FUNCTION:    acpi_ut_exit
  *
- * PARAMETERS:  Line_number         - Caller's line number
- *              Dbg_info            - Contains:
- *                  Proc_name           - Caller's procedure name
- *                  Module_name         - Caller's module name
- *                  Component_id        - Caller's component ID
+ * PARAMETERS:  line_number         - Caller's line number
+ *              dbg_info            - Contains:
+ *                  proc_name           - Caller's procedure name
+ *                  module_name         - Caller's module name
+ *                  component_id        - Caller's component ID
  *
  * RETURN:      None
  *
  * DESCRIPTION: Function exit trace.  Prints only if TRACE_FUNCTIONS bit is
- *              set in Debug_level
+ *              set in debug_level
  *
  ****************************************************************************/
 
@@ -364,19 +363,19 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_status_exit
+ * FUNCTION:    acpi_ut_status_exit
  *
- * PARAMETERS:  Line_number         - Caller's line number
- *              Dbg_info            - Contains:
- *                  Proc_name           - Caller's procedure name
- *                  Module_name         - Caller's module name
- *                  Component_id        - Caller's component ID
+ * PARAMETERS:  line_number         - Caller's line number
+ *              dbg_info            - Contains:
+ *                  proc_name           - Caller's procedure name
+ *                  module_name         - Caller's module name
+ *                  component_id        - Caller's component ID
  *              Status              - Exit status code
  *
  * RETURN:      None
  *
  * DESCRIPTION: Function exit trace.  Prints only if TRACE_FUNCTIONS bit is
- *              set in Debug_level. Prints exit status also.
+ *              set in debug_level. Prints exit status also.
  *
  ****************************************************************************/
 
@@ -404,19 +403,19 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_value_exit
+ * FUNCTION:    acpi_ut_value_exit
  *
- * PARAMETERS:  Line_number         - Caller's line number
- *              Dbg_info            - Contains:
- *                  Proc_name           - Caller's procedure name
- *                  Module_name         - Caller's module name
- *                  Component_id        - Caller's component ID
+ * PARAMETERS:  line_number         - Caller's line number
+ *              dbg_info            - Contains:
+ *                  proc_name           - Caller's procedure name
+ *                  module_name         - Caller's module name
+ *                  component_id        - Caller's component ID
  *              Value               - Value to be printed with exit msg
  *
  * RETURN:      None
  *
  * DESCRIPTION: Function exit trace.  Prints only if TRACE_FUNCTIONS bit is
- *              set in Debug_level. Prints exit value also.
+ *              set in debug_level. Prints exit value also.
  *
  ****************************************************************************/
 
@@ -437,19 +436,19 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_ptr_exit
+ * FUNCTION:    acpi_ut_ptr_exit
  *
- * PARAMETERS:  Line_number         - Caller's line number
- *              Dbg_info            - Contains:
- *                  Proc_name           - Caller's procedure name
- *                  Module_name         - Caller's module name
- *                  Component_id        - Caller's component ID
+ * PARAMETERS:  line_number         - Caller's line number
+ *              dbg_info            - Contains:
+ *                  proc_name           - Caller's procedure name
+ *                  module_name         - Caller's module name
+ *                  component_id        - Caller's component ID
  *              Value               - Value to be printed with exit msg
  *
  * RETURN:      None
  *
  * DESCRIPTION: Function exit trace.  Prints only if TRACE_FUNCTIONS bit is
- *              set in Debug_level. Prints exit value also.
+ *              set in debug_level. Prints exit value also.
  *
  ****************************************************************************/
 
@@ -471,12 +470,12 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_dump_buffer
+ * FUNCTION:    acpi_ut_dump_buffer
  *
  * PARAMETERS:  Buffer              - Buffer to dump
  *              Count               - Amount to dump, in bytes
  *              Display             - BYTE, WORD, DWORD, or QWORD display
- *              Component_iD        - Caller's component ID
+ *              component_iD        - Caller's component ID
  *
  * RETURN:      None
  *
@@ -491,8 +490,8 @@
 	u32                     display,
 	u32                     component_id)
 {
-	NATIVE_UINT             i = 0;
-	NATIVE_UINT             j;
+	acpi_native_uint        i = 0;
+	acpi_native_uint        j;
 	u32                     temp32;
 	u8                      buf_char;
 
diff -Nru a/drivers/acpi/utilities/utdelete.c b/drivers/acpi/utilities/utdelete.c
--- a/drivers/acpi/utilities/utdelete.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/acpi/utilities/utdelete.c	Mon Dec 23 21:21:55 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: utdelete - object deletion and reference count utilities
- *              $Revision: 94 $
  *
  ******************************************************************************/
 
@@ -34,7 +33,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_delete_internal_obj
+ * FUNCTION:    acpi_ut_delete_internal_obj
  *
  * PARAMETERS:  *Object        - Pointer to the list to be deleted
  *
@@ -54,7 +53,7 @@
 	acpi_operand_object     *second_desc;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ut_delete_internal_obj", object);
+	ACPI_FUNCTION_TRACE_PTR ("ut_delete_internal_obj", object);
 
 
 	if (!object) {
@@ -152,7 +151,7 @@
 		second_desc = acpi_ns_get_secondary_object (object);
 		if (second_desc) {
 			/*
-			 * Free the Region_context if and only if the handler is one of the
+			 * Free the region_context if and only if the handler is one of the
 			 * default handlers -- and therefore, we created the context object
 			 * locally, it was not created by an external caller.
 			 */
@@ -205,9 +204,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_delete_internal_object_list
+ * FUNCTION:    acpi_ut_delete_internal_object_list
  *
- * PARAMETERS:  *Obj_list       - Pointer to the list to be deleted
+ * PARAMETERS:  *obj_list       - Pointer to the list to be deleted
  *
  * RETURN:      None
  *
@@ -223,7 +222,7 @@
 	acpi_operand_object     **internal_obj;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_delete_internal_object_list");
+	ACPI_FUNCTION_TRACE ("ut_delete_internal_object_list");
 
 
 	/* Walk the null-terminated internal list */
@@ -241,7 +240,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_update_ref_count
+ * FUNCTION:    acpi_ut_update_ref_count
  *
  * PARAMETERS:  *Object         - Object whose ref count is to be updated
  *              Action          - What to do
@@ -261,7 +260,7 @@
 	u16                     new_count;
 
 
-	ACPI_FUNCTION_NAME ("Ut_update_ref_count");
+	ACPI_FUNCTION_NAME ("ut_update_ref_count");
 
 
 	if (!object) {
@@ -348,7 +347,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_update_object_reference
+ * FUNCTION:    acpi_ut_update_object_reference
  *
  * PARAMETERS:  *Object             - Increment ref count for this object
  *                                    and all sub-objects
@@ -381,7 +380,7 @@
 	acpi_generic_state       *state;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ut_update_object_reference", object);
+	ACPI_FUNCTION_TRACE_PTR ("ut_update_object_reference", object);
 
 
 	/* Ignore a null object ptr */
@@ -544,7 +543,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_add_reference
+ * FUNCTION:    acpi_ut_add_reference
  *
  * PARAMETERS:  *Object        - Object whose reference count is to be
  *                                  incremented
@@ -560,7 +559,7 @@
 	acpi_operand_object     *object)
 {
 
-	ACPI_FUNCTION_TRACE_PTR ("Ut_add_reference", object);
+	ACPI_FUNCTION_TRACE_PTR ("ut_add_reference", object);
 
 
 	/*
@@ -580,7 +579,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_remove_reference
+ * FUNCTION:    acpi_ut_remove_reference
  *
  * PARAMETERS:  *Object        - Object whose ref count will be decremented
  *
@@ -595,7 +594,7 @@
 	acpi_operand_object     *object)
 {
 
-	ACPI_FUNCTION_TRACE_PTR ("Ut_remove_reference", object);
+	ACPI_FUNCTION_TRACE_PTR ("ut_remove_reference", object);
 
 	/*
 	 * Allow a NULL pointer to be passed in, just ignore it.  This saves
diff -Nru a/drivers/acpi/utilities/uteval.c b/drivers/acpi/utilities/uteval.c
--- a/drivers/acpi/utilities/uteval.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/utilities/uteval.c	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: uteval - Object evaluation
- *              $Revision: 44 $
  *
  *****************************************************************************/
 
@@ -35,12 +34,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_evaluate_object
+ * FUNCTION:    acpi_ut_evaluate_object
  *
- * PARAMETERS:  Prefix_node         - Starting node
+ * PARAMETERS:  prefix_node         - Starting node
  *              Path                - Path to object from starting node
- *              Expected_return_types - Bitmap of allowed return types
- *              Return_desc         - Where a return value is stored
+ *              expected_return_types - Bitmap of allowed return types
+ *              return_desc         - Where a return value is stored
  *
  * RETURN:      Status
  *
@@ -64,7 +63,7 @@
 	u32                     return_btype;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_evaluate_object");
+	ACPI_FUNCTION_TRACE ("ut_evaluate_object");
 
 
 	/* Evaluate the object/method */
@@ -145,10 +144,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_evaluate_numeric_object
+ * FUNCTION:    acpi_ut_evaluate_numeric_object
  *
- * PARAMETERS:  *Object_name        - Object name to be evaluated
- *              Device_node         - Node for the device
+ * PARAMETERS:  *object_name        - Object name to be evaluated
+ *              device_node         - Node for the device
  *              *Address            - Where the value is returned
  *
  * RETURN:      Status
@@ -170,7 +169,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_evaluate_numeric_object");
+	ACPI_FUNCTION_TRACE ("ut_evaluate_numeric_object");
 
 
 	status = acpi_ut_evaluate_object (device_node, object_name,
@@ -192,9 +191,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_execute_HID
+ * FUNCTION:    acpi_ut_execute_HID
  *
- * PARAMETERS:  Device_node         - Node for the device
+ * PARAMETERS:  device_node         - Node for the device
  *              *Hid                - Where the HID is returned
  *
  * RETURN:      Status
@@ -215,7 +214,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_execute_HID");
+	ACPI_FUNCTION_TRACE ("ut_execute_HID");
 
 
 	status = acpi_ut_evaluate_object (device_node, METHOD_NAME__HID,
@@ -244,9 +243,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_execute_CID
+ * FUNCTION:    acpi_ut_execute_CID
  *
- * PARAMETERS:  Device_node         - Node for the device
+ * PARAMETERS:  device_node         - Node for the device
  *              *Cid                - Where the CID is returned
  *
  * RETURN:      Status
@@ -267,7 +266,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_execute_CID");
+	ACPI_FUNCTION_TRACE ("ut_execute_CID");
 
 
 	status = acpi_ut_evaluate_object (device_node, METHOD_NAME__CID,
@@ -318,9 +317,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_execute_UID
+ * FUNCTION:    acpi_ut_execute_UID
  *
- * PARAMETERS:  Device_node         - Node for the device
+ * PARAMETERS:  device_node         - Node for the device
  *              *Uid                - Where the UID is returned
  *
  * RETURN:      Status
@@ -341,7 +340,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_execute_UID");
+	ACPI_FUNCTION_TRACE ("ut_execute_UID");
 
 
 	status = acpi_ut_evaluate_object (device_node, METHOD_NAME__UID,
@@ -370,9 +369,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_execute_STA
+ * FUNCTION:    acpi_ut_execute_STA
  *
- * PARAMETERS:  Device_node         - Node for the device
+ * PARAMETERS:  device_node         - Node for the device
  *              *Flags              - Where the status flags are returned
  *
  * RETURN:      Status
@@ -393,7 +392,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_execute_STA");
+	ACPI_FUNCTION_TRACE ("ut_execute_STA");
 
 
 	status = acpi_ut_evaluate_object (device_node, METHOD_NAME__STA,
diff -Nru a/drivers/acpi/utilities/utglobal.c b/drivers/acpi/utilities/utglobal.c
--- a/drivers/acpi/utilities/utglobal.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/utilities/utglobal.c	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: utglobal - Global variables for the ACPI subsystem
- *              $Revision: 177 $
  *
  *****************************************************************************/
 
@@ -34,7 +33,7 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_format_exception
+ * FUNCTION:    acpi_format_exception
  *
  * PARAMETERS:  Status       - The acpi_status code to be formatted
  *
@@ -52,7 +51,7 @@
 	acpi_status             sub_status;
 
 
-	ACPI_FUNCTION_NAME ("Format_exception");
+	ACPI_FUNCTION_NAME ("format_exception");
 
 
 	sub_status = (status & ~AE_CODE_MASK);
@@ -209,7 +208,7 @@
 	ACPI_NS_NORMAL,                     /* 02 String           */
 	ACPI_NS_NORMAL,                     /* 03 Buffer           */
 	ACPI_NS_NORMAL,                     /* 04 Package          */
-	ACPI_NS_NORMAL,                     /* 05 Field_unit       */
+	ACPI_NS_NORMAL,                     /* 05 field_unit       */
 	ACPI_NS_NEWSCOPE,                   /* 06 Device           */
 	ACPI_NS_NORMAL,                     /* 07 Event            */
 	ACPI_NS_NEWSCOPE,                   /* 08 Method           */
@@ -218,12 +217,12 @@
 	ACPI_NS_NEWSCOPE,                   /* 11 Power            */
 	ACPI_NS_NEWSCOPE,                   /* 12 Processor        */
 	ACPI_NS_NEWSCOPE,                   /* 13 Thermal          */
-	ACPI_NS_NORMAL,                     /* 14 Buffer_field     */
-	ACPI_NS_NORMAL,                     /* 15 Ddb_handle       */
+	ACPI_NS_NORMAL,                     /* 14 buffer_field     */
+	ACPI_NS_NORMAL,                     /* 15 ddb_handle       */
 	ACPI_NS_NORMAL,                     /* 16 Debug Object     */
-	ACPI_NS_NORMAL,                     /* 17 Def_field        */
-	ACPI_NS_NORMAL,                     /* 18 Bank_field       */
-	ACPI_NS_NORMAL,                     /* 19 Index_field      */
+	ACPI_NS_NORMAL,                     /* 17 def_field        */
+	ACPI_NS_NORMAL,                     /* 18 bank_field       */
+	ACPI_NS_NORMAL,                     /* 19 index_field      */
 	ACPI_NS_NORMAL,                     /* 20 Reference        */
 	ACPI_NS_NORMAL,                     /* 21 Alias            */
 	ACPI_NS_NORMAL,                     /* 22 Notify           */
@@ -245,7 +244,7 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_hex_to_ascii_char
+ * FUNCTION:    acpi_ut_hex_to_ascii_char
  *
  * PARAMETERS:  Integer             - Contains the hex digit
  *              Position            - bit position of the digit within the
@@ -304,7 +303,7 @@
  *
  ******************************************************************************/
 
-ACPI_BIT_REGISTER_INFO      acpi_gbl_bit_register_info[ACPI_NUM_BITREG] =
+acpi_bit_register_info      acpi_gbl_bit_register_info[ACPI_NUM_BITREG] =
 {
 	/* Name                                     Parent Register             Register Bit Position                   Register Bit Mask       */
 
@@ -345,7 +344,7 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_get_region_name
+ * FUNCTION:    acpi_ut_get_region_name
  *
  * PARAMETERS:  None.
  *
@@ -359,14 +358,14 @@
 
 const char        *acpi_gbl_region_types[ACPI_NUM_PREDEFINED_REGIONS] =
 {
-	"System_memory",
-	"System_iO",
+	"system_memory",
+	"system_iO",
 	"PCI_Config",
-	"Embedded_control",
+	"embedded_control",
 	"SMBus",
 	"CMOS",
 	"PCIBARTarget",
-	"Data_table",
+	"data_table",
 };
 
 
@@ -377,12 +376,12 @@
 
 	if (space_id >= ACPI_USER_REGION_BEGIN)
 	{
-		return ("User_defined_region");
+		return ("user_defined_region");
 	}
 
 	else if (space_id >= ACPI_NUM_PREDEFINED_REGIONS)
 	{
-		return ("Invalid_space_iD");
+		return ("invalid_space_iD");
 	}
 
 	return ((char *) acpi_gbl_region_types[space_id]);
@@ -391,7 +390,7 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_get_event_name
+ * FUNCTION:    acpi_ut_get_event_name
  *
  * PARAMETERS:  None.
  *
@@ -406,10 +405,10 @@
 static const char        *acpi_gbl_event_types[ACPI_NUM_FIXED_EVENTS] =
 {
 	"PM_Timer",
-	"Global_lock",
-	"Power_button",
-	"Sleep_button",
-	"Real_time_clock",
+	"global_lock",
+	"power_button",
+	"sleep_button",
+	"real_time_clock",
 };
 
 
@@ -420,7 +419,7 @@
 
 	if (event_id > ACPI_EVENT_MAX)
 	{
-		return ("Invalid_event_iD");
+		return ("invalid_event_iD");
 	}
 
 	return ((char *) acpi_gbl_event_types[event_id]);
@@ -429,7 +428,7 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_get_type_name
+ * FUNCTION:    acpi_ut_get_type_name
  *
  * PARAMETERS:  None.
  *
@@ -440,7 +439,7 @@
  ****************************************************************************/
 
 /*
- * Elements of Acpi_gbl_Ns_type_names below must match
+ * Elements of acpi_gbl_ns_type_names below must match
  * one-to-one with values of acpi_object_type
  *
  * The type ACPI_TYPE_ANY (Untyped) is used as a "don't care" when searching; when
@@ -458,7 +457,7 @@
 	/* 02 */ "String",
 	/* 03 */ "Buffer",
 	/* 04 */ "Package",
-	/* 05 */ "Field_unit",
+	/* 05 */ "field_unit",
 	/* 06 */ "Device",
 	/* 07 */ "Event",
 	/* 08 */ "Method",
@@ -467,18 +466,18 @@
 	/* 11 */ "Power",
 	/* 12 */ "Processor",
 	/* 13 */ "Thermal",
-	/* 14 */ "Buffer_field",
-	/* 15 */ "Ddb_handle",
-	/* 16 */ "Debug_object",
-	/* 17 */ "Region_field",
-	/* 18 */ "Bank_field",
-	/* 19 */ "Index_field",
+	/* 14 */ "buffer_field",
+	/* 15 */ "ddb_handle",
+	/* 16 */ "debug_object",
+	/* 17 */ "region_field",
+	/* 18 */ "bank_field",
+	/* 19 */ "index_field",
 	/* 20 */ "Reference",
 	/* 21 */ "Alias",
 	/* 22 */ "Notify",
-	/* 23 */ "Addr_handler",
-	/* 24 */ "Resource_desc",
-	/* 25 */ "Resource_fld",
+	/* 23 */ "addr_handler",
+	/* 24 */ "resource_desc",
+	/* 25 */ "resource_fld",
 	/* 26 */ "Scope",
 	/* 27 */ "Extra",
 	/* 28 */ "Data",
@@ -523,7 +522,7 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_get_mutex_name
+ * FUNCTION:    acpi_ut_get_mutex_name
  *
  * PARAMETERS:  None.
  *
@@ -552,7 +551,7 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_ut_valid_object_type
+ * FUNCTION:    acpi_ut_valid_object_type
  *
  * PARAMETERS:  Type            - Object type to be validated
  *
@@ -580,9 +579,9 @@
 
 /****************************************************************************
  *
- * FUNCTION:    Acpi_ut_allocate_owner_id
+ * FUNCTION:    acpi_ut_allocate_owner_id
  *
- * PARAMETERS:  Id_type         - Type of ID (method or table)
+ * PARAMETERS:  id_type         - Type of ID (method or table)
  *
  * DESCRIPTION: Allocate a table or method owner id
  *
@@ -595,7 +594,7 @@
 	acpi_owner_id           owner_id = 0xFFFF;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_allocate_owner_id");
+	ACPI_FUNCTION_TRACE ("ut_allocate_owner_id");
 
 
 	if (ACPI_FAILURE (acpi_ut_acquire_mutex (ACPI_MTX_CACHES)))
@@ -639,7 +638,7 @@
 
 /****************************************************************************
  *
- * FUNCTION:    Acpi_ut_init_globals
+ * FUNCTION:    acpi_ut_init_globals
  *
  * PARAMETERS:  none
  *
@@ -655,11 +654,11 @@
 	u32                     i;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_init_globals");
+	ACPI_FUNCTION_TRACE ("ut_init_globals");
 
 	/* Memory allocation and cache lists */
 
-	ACPI_MEMSET (acpi_gbl_memory_lists, 0, sizeof (ACPI_MEMORY_LIST) * ACPI_NUM_MEM_LISTS);
+	ACPI_MEMSET (acpi_gbl_memory_lists, 0, sizeof (acpi_memory_list) * ACPI_NUM_MEM_LISTS);
 
 	acpi_gbl_memory_lists[ACPI_MEM_LIST_STATE].link_offset      = (u16) ACPI_PTR_DIFF (&(((acpi_generic_state *) NULL)->common.next), NULL);
 	acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE].link_offset     = (u16) ACPI_PTR_DIFF (&(((acpi_parse_object *) NULL)->common.next), NULL);
@@ -669,8 +668,8 @@
 
 	acpi_gbl_memory_lists[ACPI_MEM_LIST_NSNODE].object_size     = sizeof (acpi_namespace_node);
 	acpi_gbl_memory_lists[ACPI_MEM_LIST_STATE].object_size      = sizeof (acpi_generic_state);
-	acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE].object_size     = sizeof (ACPI_PARSE_OBJ_COMMON);
-	acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE_EXT].object_size = sizeof (ACPI_PARSE_OBJ_NAMED);
+	acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE].object_size     = sizeof (acpi_parse_obj_common);
+	acpi_gbl_memory_lists[ACPI_MEM_LIST_PSNODE_EXT].object_size = sizeof (acpi_parse_obj_named);
 	acpi_gbl_memory_lists[ACPI_MEM_LIST_OPERAND].object_size    = sizeof (acpi_operand_object);
 	acpi_gbl_memory_lists[ACPI_MEM_LIST_WALK].object_size       = sizeof (acpi_walk_state);
 
diff -Nru a/drivers/acpi/utilities/utinit.c b/drivers/acpi/utilities/utinit.c
--- a/drivers/acpi/utilities/utinit.c	Mon Dec 23 21:21:56 2002
+++ b/drivers/acpi/utilities/utinit.c	Mon Dec 23 21:21:56 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: utinit - Common ACPI subsystem initialization
- *              $Revision: 115 $
  *
  *****************************************************************************/
 
@@ -34,12 +33,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_fadt_register_error
+ * FUNCTION:    acpi_ut_fadt_register_error
  *
- * PARAMETERS:  *Register_name          - Pointer to string identifying register
+ * PARAMETERS:  *register_name          - Pointer to string identifying register
  *              Value                   - Actual register contents value
- *              Acpi_test_spec_section  - TDS section containing assertion
- *              Acpi_assertion          - Assertion number being tested
+ *              acpi_test_spec_section  - TDS section containing assertion
+ *              acpi_assertion          - Assertion number being tested
  *
  * RETURN:      AE_BAD_VALUE
  *
@@ -51,7 +50,7 @@
 acpi_ut_fadt_register_error (
 	char                    *register_name,
 	u32                     value,
-	ACPI_SIZE               offset)
+	acpi_size               offset)
 {
 
 	ACPI_REPORT_WARNING (
@@ -62,7 +61,7 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_ut_validate_fadt
+ * FUNCTION:    acpi_ut_validate_fadt
  *
  * PARAMETERS:  None
  *
@@ -92,22 +91,22 @@
 				  ACPI_FADT_OFFSET (pm1_cnt_len));
 	}
 
-	if (!acpi_gbl_FADT->Xpm1a_evt_blk.address) {
+	if (!acpi_gbl_FADT->xpm1a_evt_blk.address) {
 		acpi_ut_fadt_register_error ("X_PM1a_EVT_BLK", 0,
-				  ACPI_FADT_OFFSET (Xpm1a_evt_blk.address));
+				  ACPI_FADT_OFFSET (xpm1a_evt_blk.address));
 	}
 
-	if (!acpi_gbl_FADT->Xpm1a_cnt_blk.address) {
+	if (!acpi_gbl_FADT->xpm1a_cnt_blk.address) {
 		acpi_ut_fadt_register_error ("X_PM1a_CNT_BLK", 0,
-				  ACPI_FADT_OFFSET (Xpm1a_cnt_blk.address));
+				  ACPI_FADT_OFFSET (xpm1a_cnt_blk.address));
 	}
 
-	if (!acpi_gbl_FADT->Xpm_tmr_blk.address) {
+	if (!acpi_gbl_FADT->xpm_tmr_blk.address) {
 		acpi_ut_fadt_register_error ("X_PM_TMR_BLK", 0,
-				  ACPI_FADT_OFFSET (Xpm_tmr_blk.address));
+				  ACPI_FADT_OFFSET (xpm_tmr_blk.address));
 	}
 
-	if ((acpi_gbl_FADT->Xpm2_cnt_blk.address &&
+	if ((acpi_gbl_FADT->xpm2_cnt_blk.address &&
 		!acpi_gbl_FADT->pm2_cnt_len)) {
 		acpi_ut_fadt_register_error ("PM2_CNT_LEN",
 				  (u32) acpi_gbl_FADT->pm2_cnt_len,
@@ -122,14 +121,14 @@
 
 	/* Length of GPE blocks must be a multiple of 2 */
 
-	if (acpi_gbl_FADT->Xgpe0_blk.address &&
+	if (acpi_gbl_FADT->xgpe0_blk.address &&
 		(acpi_gbl_FADT->gpe0_blk_len & 1)) {
 		acpi_ut_fadt_register_error ("(x)GPE0_BLK_LEN",
 				  (u32) acpi_gbl_FADT->gpe0_blk_len,
 				  ACPI_FADT_OFFSET (gpe0_blk_len));
 	}
 
-	if (acpi_gbl_FADT->Xgpe1_blk.address &&
+	if (acpi_gbl_FADT->xgpe1_blk.address &&
 		(acpi_gbl_FADT->gpe1_blk_len & 1)) {
 		acpi_ut_fadt_register_error ("(x)GPE1_BLK_LEN",
 				  (u32) acpi_gbl_FADT->gpe1_blk_len,
@@ -142,7 +141,7 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_ut_terminate
+ * FUNCTION:    acpi_ut_terminate
  *
  * PARAMETERS:  none
  *
@@ -156,7 +155,7 @@
 acpi_ut_terminate (void)
 {
 
-	ACPI_FUNCTION_TRACE ("Ut_terminate");
+	ACPI_FUNCTION_TRACE ("ut_terminate");
 
 
 	/* Free global tables, etc. */
@@ -169,7 +168,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_subsystem_shutdown
+ * FUNCTION:    acpi_ut_subsystem_shutdown
  *
  * PARAMETERS:  none
  *
@@ -184,7 +183,7 @@
 acpi_ut_subsystem_shutdown (void)
 {
 
-	ACPI_FUNCTION_TRACE ("Ut_subsystem_shutdown");
+	ACPI_FUNCTION_TRACE ("ut_subsystem_shutdown");
 
 	/* Just exit if subsystem is already shutdown */
 
@@ -198,7 +197,7 @@
 	acpi_gbl_shutdown = TRUE;
 	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Shutting down ACPI Subsystem...\n"));
 
-	/* Close the Acpi_event Handling */
+	/* Close the acpi_event Handling */
 
 	acpi_ev_terminate ();
 
diff -Nru a/drivers/acpi/utilities/utmath.c b/drivers/acpi/utilities/utmath.c
--- a/drivers/acpi/utilities/utmath.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/acpi/utilities/utmath.c	Mon Dec 23 21:22:00 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: utmath - Integer math support routines
- *              $Revision: 11 $
  *
  ******************************************************************************/
 
@@ -39,12 +38,12 @@
 #ifndef ACPI_USE_NATIVE_DIVIDE
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_short_divide
+ * FUNCTION:    acpi_ut_short_divide
  *
- * PARAMETERS:  In_dividend         - Pointer to the dividend
+ * PARAMETERS:  in_dividend         - Pointer to the dividend
  *              Divisor             - 32-bit divisor
- *              Out_quotient        - Pointer to where the quotient is returned
- *              Out_remainder       - Pointer to where the remainder is returned
+ *              out_quotient        - Pointer to where the quotient is returned
+ *              out_remainder       - Pointer to where the remainder is returned
  *
  * RETURN:      Status (Checks for divide-by-zero)
  *
@@ -66,14 +65,14 @@
 	u32                     remainder32;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_short_divide");
+	ACPI_FUNCTION_TRACE ("ut_short_divide");
 
 	dividend.full = *in_dividend;
 
 	/* Always check for a zero divisor */
 
 	if (divisor == 0) {
-		ACPI_REPORT_ERROR (("Acpi_ut_short_divide: Divide by zero\n"));
+		ACPI_REPORT_ERROR (("acpi_ut_short_divide: Divide by zero\n"));
 		return_ACPI_STATUS (AE_AML_DIVIDE_BY_ZERO);
 	}
 
@@ -101,12 +100,12 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_divide
+ * FUNCTION:    acpi_ut_divide
  *
- * PARAMETERS:  In_dividend         - Pointer to the dividend
- *              In_divisor          - Pointer to the divisor
- *              Out_quotient        - Pointer to where the quotient is returned
- *              Out_remainder       - Pointer to where the remainder is returned
+ * PARAMETERS:  in_dividend         - Pointer to the dividend
+ *              in_divisor          - Pointer to the divisor
+ *              out_quotient        - Pointer to where the quotient is returned
+ *              out_remainder       - Pointer to where the remainder is returned
  *
  * RETURN:      Status (Checks for divide-by-zero)
  *
@@ -132,13 +131,13 @@
 	uint64_overlay          partial3;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_divide");
+	ACPI_FUNCTION_TRACE ("ut_divide");
 
 
 	/* Always check for a zero divisor */
 
 	if (*in_divisor == 0) {
-		ACPI_REPORT_ERROR (("Acpi_ut_divide: Divide by zero\n"));
+		ACPI_REPORT_ERROR (("acpi_ut_divide: Divide by zero\n"));
 		return_ACPI_STATUS (AE_AML_DIVIDE_BY_ZERO);
 	}
 
@@ -238,9 +237,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_short_divide, Acpi_ut_divide
+ * FUNCTION:    acpi_ut_short_divide, acpi_ut_divide
  *
- * DESCRIPTION: Native versions of the Ut_divide functions. Use these if either
+ * DESCRIPTION: Native versions of the ut_divide functions. Use these if either
  *              1) The target is a 64-bit platform and therefore 64-bit
  *                 integer math is supported directly by the machine.
  *              2) The target is a 32-bit or 16-bit platform, and the
@@ -257,13 +256,13 @@
 	u32                     *out_remainder)
 {
 
-	ACPI_FUNCTION_TRACE ("Ut_short_divide");
+	ACPI_FUNCTION_TRACE ("ut_short_divide");
 
 
 	/* Always check for a zero divisor */
 
 	if (divisor == 0) {
-		ACPI_REPORT_ERROR (("Acpi_ut_short_divide: Divide by zero\n"));
+		ACPI_REPORT_ERROR (("acpi_ut_short_divide: Divide by zero\n"));
 		return_ACPI_STATUS (AE_AML_DIVIDE_BY_ZERO);
 	}
 
@@ -286,13 +285,13 @@
 	acpi_integer            *out_quotient,
 	acpi_integer            *out_remainder)
 {
-	ACPI_FUNCTION_TRACE ("Ut_divide");
+	ACPI_FUNCTION_TRACE ("ut_divide");
 
 
 	/* Always check for a zero divisor */
 
 	if (*in_divisor == 0) {
-		ACPI_REPORT_ERROR (("Acpi_ut_divide: Divide by zero\n"));
+		ACPI_REPORT_ERROR (("acpi_ut_divide: Divide by zero\n"));
 		return_ACPI_STATUS (AE_AML_DIVIDE_BY_ZERO);
 	}
 
diff -Nru a/drivers/acpi/utilities/utmisc.c b/drivers/acpi/utilities/utmisc.c
--- a/drivers/acpi/utilities/utmisc.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/utilities/utmisc.c	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /*******************************************************************************
  *
  * Module Name: utmisc - common utility procedures
- *              $Revision: 92 $
  *
  ******************************************************************************/
 
@@ -34,7 +33,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_print_string
+ * FUNCTION:    acpi_ut_print_string
  *
  * PARAMETERS:  String          - Null terminated ASCII string
  *
@@ -126,7 +125,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_dword_byte_swap
+ * FUNCTION:    acpi_ut_dword_byte_swap
  *
  * PARAMETERS:  Value           - Value to be converted
  *
@@ -165,7 +164,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_set_integer_width
+ * FUNCTION:    acpi_ut_set_integer_width
  *
  * PARAMETERS:  Revision            From DSDT header
  *
@@ -197,9 +196,9 @@
 #ifdef ACPI_DEBUG_OUTPUT
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_display_init_pathname
+ * FUNCTION:    acpi_ut_display_init_pathname
  *
- * PARAMETERS:  Obj_handle          - Handle whose pathname will be displayed
+ * PARAMETERS:  obj_handle          - Handle whose pathname will be displayed
  *              Path                - Additional path string to be appended.
  *                                      (NULL if no extra path)
  *
@@ -266,7 +265,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_valid_acpi_name
+ * FUNCTION:    acpi_ut_valid_acpi_name
  *
  * PARAMETERS:  Character           - The character to be examined
  *
@@ -304,7 +303,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_valid_acpi_character
+ * FUNCTION:    acpi_ut_valid_acpi_character
  *
  * PARAMETERS:  Character           - The character to be examined
  *
@@ -329,7 +328,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_strtoul64
+ * FUNCTION:    acpi_ut_strtoul64
  *
  * PARAMETERS:  String          - Null terminated string
  *              Terminater      - Where a pointer to the terminating byte is returned
@@ -475,11 +474,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_strupr
+ * FUNCTION:    acpi_ut_strupr
  *
- * PARAMETERS:  Src_string      - The source string to convert to
+ * PARAMETERS:  src_string      - The source string to convert to
  *
- * RETURN:      Src_string
+ * RETURN:      src_string
  *
  * DESCRIPTION: Convert string to uppercase
  *
@@ -507,7 +506,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_mutex_initialize
+ * FUNCTION:    acpi_ut_mutex_initialize
  *
  * PARAMETERS:  None.
  *
@@ -525,7 +524,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_mutex_initialize");
+	ACPI_FUNCTION_TRACE ("ut_mutex_initialize");
 
 
 	/*
@@ -544,7 +543,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_mutex_terminate
+ * FUNCTION:    acpi_ut_mutex_terminate
  *
  * PARAMETERS:  None.
  *
@@ -561,7 +560,7 @@
 	u32                     i;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_mutex_terminate");
+	ACPI_FUNCTION_TRACE ("ut_mutex_terminate");
 
 
 	/*
@@ -577,9 +576,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_create_mutex
+ * FUNCTION:    acpi_ut_create_mutex
  *
- * PARAMETERS:  Mutex_iD        - ID of the mutex to be created
+ * PARAMETERS:  mutex_iD        - ID of the mutex to be created
  *
  * RETURN:      Status
  *
@@ -589,12 +588,12 @@
 
 acpi_status
 acpi_ut_create_mutex (
-	ACPI_MUTEX_HANDLE       mutex_id)
+	acpi_mutex_handle       mutex_id)
 {
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE_U32 ("Ut_create_mutex", mutex_id);
+	ACPI_FUNCTION_TRACE_U32 ("ut_create_mutex", mutex_id);
 
 
 	if (mutex_id > MAX_MTX) {
@@ -614,9 +613,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_delete_mutex
+ * FUNCTION:    acpi_ut_delete_mutex
  *
- * PARAMETERS:  Mutex_iD        - ID of the mutex to be deleted
+ * PARAMETERS:  mutex_iD        - ID of the mutex to be deleted
  *
  * RETURN:      Status
  *
@@ -626,12 +625,12 @@
 
 acpi_status
 acpi_ut_delete_mutex (
-	ACPI_MUTEX_HANDLE       mutex_id)
+	acpi_mutex_handle       mutex_id)
 {
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE_U32 ("Ut_delete_mutex", mutex_id);
+	ACPI_FUNCTION_TRACE_U32 ("ut_delete_mutex", mutex_id);
 
 
 	if (mutex_id > MAX_MTX) {
@@ -649,9 +648,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_acquire_mutex
+ * FUNCTION:    acpi_ut_acquire_mutex
  *
- * PARAMETERS:  Mutex_iD        - ID of the mutex to be acquired
+ * PARAMETERS:  mutex_iD        - ID of the mutex to be acquired
  *
  * RETURN:      Status
  *
@@ -661,14 +660,14 @@
 
 acpi_status
 acpi_ut_acquire_mutex (
-	ACPI_MUTEX_HANDLE       mutex_id)
+	acpi_mutex_handle       mutex_id)
 {
 	acpi_status             status;
 	u32                     i;
 	u32                     this_thread_id;
 
 
-	ACPI_FUNCTION_NAME ("Ut_acquire_mutex");
+	ACPI_FUNCTION_NAME ("ut_acquire_mutex");
 
 
 	if (mutex_id > MAX_MTX) {
@@ -727,9 +726,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_release_mutex
+ * FUNCTION:    acpi_ut_release_mutex
  *
- * PARAMETERS:  Mutex_iD        - ID of the mutex to be released
+ * PARAMETERS:  mutex_iD        - ID of the mutex to be released
  *
  * RETURN:      Status
  *
@@ -739,14 +738,14 @@
 
 acpi_status
 acpi_ut_release_mutex (
-	ACPI_MUTEX_HANDLE       mutex_id)
+	acpi_mutex_handle       mutex_id)
 {
 	acpi_status             status;
 	u32                     i;
 	u32                     this_thread_id;
 
 
-	ACPI_FUNCTION_NAME ("Ut_release_mutex");
+	ACPI_FUNCTION_NAME ("ut_release_mutex");
 
 
 	this_thread_id = acpi_os_get_thread_id ();
@@ -811,11 +810,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_create_update_state_and_push
+ * FUNCTION:    acpi_ut_create_update_state_and_push
  *
  * PARAMETERS:  *Object         - Object to be added to the new state
  *              Action          - Increment/Decrement
- *              State_list      - List the state will be added to
+ *              state_list      - List the state will be added to
  *
  * RETURN:      None
  *
@@ -853,11 +852,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_create_pkg_state_and_push
+ * FUNCTION:    acpi_ut_create_pkg_state_and_push
  *
  * PARAMETERS:  *Object         - Object to be added to the new state
  *              Action          - Increment/Decrement
- *              State_list      - List the state will be added to
+ *              state_list      - List the state will be added to
  *
  * RETURN:      None
  *
@@ -890,9 +889,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_push_generic_state
+ * FUNCTION:    acpi_ut_push_generic_state
  *
- * PARAMETERS:  List_head           - Head of the state stack
+ * PARAMETERS:  list_head           - Head of the state stack
  *              State               - State object to push
  *
  * RETURN:      Status
@@ -906,7 +905,7 @@
 	acpi_generic_state      **list_head,
 	acpi_generic_state      *state)
 {
-	ACPI_FUNCTION_TRACE ("Ut_push_generic_state");
+	ACPI_FUNCTION_TRACE ("ut_push_generic_state");
 
 
 	/* Push the state object onto the front of the list (stack) */
@@ -920,9 +919,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_pop_generic_state
+ * FUNCTION:    acpi_ut_pop_generic_state
  *
- * PARAMETERS:  List_head           - Head of the state stack
+ * PARAMETERS:  list_head           - Head of the state stack
  *
  * RETURN:      Status
  *
@@ -937,7 +936,7 @@
 	acpi_generic_state      *state;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_pop_generic_state");
+	ACPI_FUNCTION_TRACE ("ut_pop_generic_state");
 
 
 	/* Remove the state object at the head of the list (stack) */
@@ -955,7 +954,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_create_generic_state
+ * FUNCTION:    acpi_ut_create_generic_state
  *
  * PARAMETERS:  None
  *
@@ -989,7 +988,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_create_thread_state
+ * FUNCTION:    acpi_ut_create_thread_state
  *
  * PARAMETERS:  None
  *
@@ -1000,14 +999,14 @@
  *
  ******************************************************************************/
 
-ACPI_THREAD_STATE *
+acpi_thread_state *
 acpi_ut_create_thread_state (
 	void)
 {
 	acpi_generic_state      *state;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_create_thread_state");
+	ACPI_FUNCTION_TRACE ("ut_create_thread_state");
 
 
 	/* Create the generic state object */
@@ -1022,13 +1021,13 @@
 	state->common.data_type = ACPI_DESC_TYPE_STATE_THREAD;
 	state->thread.thread_id = acpi_os_get_thread_id ();
 
-	return_PTR ((ACPI_THREAD_STATE *) state);
+	return_PTR ((acpi_thread_state *) state);
 }
 
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_create_update_state
+ * FUNCTION:    acpi_ut_create_update_state
  *
  * PARAMETERS:  Object              - Initial Object to be installed in the
  *                                    state
@@ -1050,7 +1049,7 @@
 	acpi_generic_state      *state;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ut_create_update_state", object);
+	ACPI_FUNCTION_TRACE_PTR ("ut_create_update_state", object);
 
 
 	/* Create the generic state object */
@@ -1072,7 +1071,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_create_pkg_state
+ * FUNCTION:    acpi_ut_create_pkg_state
  *
  * PARAMETERS:  Object              - Initial Object to be installed in the
  *                                    state
@@ -1093,7 +1092,7 @@
 	acpi_generic_state      *state;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ut_create_pkg_state", internal_object);
+	ACPI_FUNCTION_TRACE_PTR ("ut_create_pkg_state", internal_object);
 
 
 	/* Create the generic state object */
@@ -1117,7 +1116,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_create_control_state
+ * FUNCTION:    acpi_ut_create_control_state
  *
  * PARAMETERS:  None
  *
@@ -1135,7 +1134,7 @@
 	acpi_generic_state      *state;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_create_control_state");
+	ACPI_FUNCTION_TRACE ("ut_create_control_state");
 
 
 	/* Create the generic state object */
@@ -1156,7 +1155,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_delete_generic_state
+ * FUNCTION:    acpi_ut_delete_generic_state
  *
  * PARAMETERS:  State               - The state object to be deleted
  *
@@ -1171,7 +1170,7 @@
 acpi_ut_delete_generic_state (
 	acpi_generic_state      *state)
 {
-	ACPI_FUNCTION_TRACE ("Ut_delete_generic_state");
+	ACPI_FUNCTION_TRACE ("ut_delete_generic_state");
 
 
 	acpi_ut_release_to_cache (ACPI_MEM_LIST_STATE, state);
@@ -1181,7 +1180,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_delete_generic_state_cache
+ * FUNCTION:    acpi_ut_delete_generic_state_cache
  *
  * PARAMETERS:  None
  *
@@ -1196,7 +1195,7 @@
 acpi_ut_delete_generic_state_cache (
 	void)
 {
-	ACPI_FUNCTION_TRACE ("Ut_delete_generic_state_cache");
+	ACPI_FUNCTION_TRACE ("ut_delete_generic_state_cache");
 
 
 	acpi_ut_delete_generic_cache (ACPI_MEM_LIST_STATE);
@@ -1206,9 +1205,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_walk_package_tree
+ * FUNCTION:    acpi_ut_walk_package_tree
  *
- * PARAMETERS:  Obj_desc        - The Package object on which to resolve refs
+ * PARAMETERS:  obj_desc        - The Package object on which to resolve refs
  *
  * RETURN:      Status
  *
@@ -1220,7 +1219,7 @@
 acpi_ut_walk_package_tree (
 	acpi_operand_object     *source_object,
 	void                    *target_object,
-	ACPI_PKG_CALLBACK       walk_callback,
+	acpi_pkg_callback       walk_callback,
 	void                    *context)
 {
 	acpi_status             status = AE_OK;
@@ -1230,7 +1229,7 @@
 	acpi_operand_object     *this_source_obj;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_walk_package_tree");
+	ACPI_FUNCTION_TRACE ("ut_walk_package_tree");
 
 
 	state = acpi_ut_create_pkg_state (source_object, target_object, 0);
@@ -1322,7 +1321,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_generate_checksum
+ * FUNCTION:    acpi_ut_generate_checksum
  *
  * PARAMETERS:  Buffer          - Buffer to be scanned
  *              Length          - number of bytes to examine
@@ -1352,9 +1351,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_get_resource_end_tag
+ * FUNCTION:    acpi_ut_get_resource_end_tag
  *
- * PARAMETERS:  Obj_desc        - The resource template buffer object
+ * PARAMETERS:  obj_desc        - The resource template buffer object
  *
  * RETURN:      Pointer to the end tag
  *
@@ -1405,11 +1404,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_report_error
+ * FUNCTION:    acpi_ut_report_error
  *
- * PARAMETERS:  Module_name         - Caller's module name (for error output)
- *              Line_number         - Caller's line number (for error output)
- *              Component_id        - Caller's component ID (for error output)
+ * PARAMETERS:  module_name         - Caller's module name (for error output)
+ *              line_number         - Caller's line number (for error output)
+ *              component_id        - Caller's component ID (for error output)
  *              Message             - Error message to use on failure
  *
  * RETURN:      None
@@ -1432,11 +1431,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_report_warning
+ * FUNCTION:    acpi_ut_report_warning
  *
- * PARAMETERS:  Module_name         - Caller's module name (for error output)
- *              Line_number         - Caller's line number (for error output)
- *              Component_id        - Caller's component ID (for error output)
+ * PARAMETERS:  module_name         - Caller's module name (for error output)
+ *              line_number         - Caller's line number (for error output)
+ *              component_id        - Caller's component ID (for error output)
  *              Message             - Error message to use on failure
  *
  * RETURN:      None
@@ -1458,11 +1457,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_report_info
+ * FUNCTION:    acpi_ut_report_info
  *
- * PARAMETERS:  Module_name         - Caller's module name (for error output)
- *              Line_number         - Caller's line number (for error output)
- *              Component_id        - Caller's component ID (for error output)
+ * PARAMETERS:  module_name         - Caller's module name (for error output)
+ *              line_number         - Caller's line number (for error output)
+ *              component_id        - Caller's component ID (for error output)
  *              Message             - Error message to use on failure
  *
  * RETURN:      None
diff -Nru a/drivers/acpi/utilities/utobject.c b/drivers/acpi/utilities/utobject.c
--- a/drivers/acpi/utilities/utobject.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/acpi/utilities/utobject.c	Mon Dec 23 21:21:58 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: utobject - ACPI object create/delete/size/cache routines
- *              $Revision: 81 $
  *
  *****************************************************************************/
 
@@ -35,11 +34,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_create_internal_object_dbg
+ * FUNCTION:    acpi_ut_create_internal_object_dbg
  *
- * PARAMETERS:  Module_name         - Source file name of caller
- *              Line_number         - Line number of caller
- *              Component_id        - Component type of caller
+ * PARAMETERS:  module_name         - Source file name of caller
+ *              line_number         - Line number of caller
+ *              component_id        - Component type of caller
  *              Type                - ACPI Type of the new object
  *
  * RETURN:      Object              - The new object.  Null on failure
@@ -65,7 +64,7 @@
 	acpi_operand_object     *second_object;
 
 
-	ACPI_FUNCTION_TRACE_STR ("Ut_create_internal_object_dbg", acpi_ut_get_type_name (type));
+	ACPI_FUNCTION_TRACE_STR ("ut_create_internal_object_dbg", acpi_ut_get_type_name (type));
 
 
 	/* Allocate the raw object descriptor */
@@ -116,9 +115,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_create_buffer_object
+ * FUNCTION:    acpi_ut_create_buffer_object
  *
- * PARAMETERS:  Buffer_size            - Size of buffer to be created
+ * PARAMETERS:  buffer_size            - Size of buffer to be created
  *
  * RETURN:      Pointer to a new Buffer object
  *
@@ -128,13 +127,13 @@
 
 acpi_operand_object *
 acpi_ut_create_buffer_object (
-	ACPI_SIZE               buffer_size)
+	acpi_size               buffer_size)
 {
 	acpi_operand_object     *buffer_desc;
 	u8                      *buffer;
 
 
-	ACPI_FUNCTION_TRACE_U32 ("Ut_create_buffer_object", buffer_size);
+	ACPI_FUNCTION_TRACE_U32 ("ut_create_buffer_object", buffer_size);
 
 
 	/*
@@ -149,7 +148,7 @@
 
 	buffer = ACPI_MEM_CALLOCATE (buffer_size);
 	if (!buffer) {
-		ACPI_REPORT_ERROR (("Create_buffer: could not allocate size %X\n",
+		ACPI_REPORT_ERROR (("create_buffer: could not allocate size %X\n",
 			(u32) buffer_size));
 		acpi_ut_remove_reference (buffer_desc);
 		return_PTR (NULL);
@@ -169,7 +168,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_valid_internal_object
+ * FUNCTION:    acpi_ut_valid_internal_object
  *
  * PARAMETERS:  Object              - Object to be validated
  *
@@ -182,7 +181,7 @@
 	void                    *object)
 {
 
-	ACPI_FUNCTION_NAME ("Ut_valid_internal_object");
+	ACPI_FUNCTION_NAME ("ut_valid_internal_object");
 
 
 	/* Check for a null pointer */
@@ -233,11 +232,11 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_allocate_object_desc_dbg
+ * FUNCTION:    acpi_ut_allocate_object_desc_dbg
  *
- * PARAMETERS:  Module_name         - Caller's module name (for error output)
- *              Line_number         - Caller's line number (for error output)
- *              Component_id        - Caller's component ID (for error output)
+ * PARAMETERS:  module_name         - Caller's module name (for error output)
+ *              line_number         - Caller's line number (for error output)
+ *              component_id        - Caller's component ID (for error output)
  *
  * RETURN:      Pointer to newly allocated object descriptor.  Null on error
  *
@@ -255,7 +254,7 @@
 	acpi_operand_object     *object;
 
 
-	ACPI_FUNCTION_TRACE ("Ut_allocate_object_desc_dbg");
+	ACPI_FUNCTION_TRACE ("ut_allocate_object_desc_dbg");
 
 
 	object = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_OPERAND);
@@ -279,7 +278,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_delete_object_desc
+ * FUNCTION:    acpi_ut_delete_object_desc
  *
  * PARAMETERS:  Object          - An Acpi internal object to be deleted
  *
@@ -293,7 +292,7 @@
 acpi_ut_delete_object_desc (
 	acpi_operand_object     *object)
 {
-	ACPI_FUNCTION_TRACE_PTR ("Ut_delete_object_desc", object);
+	ACPI_FUNCTION_TRACE_PTR ("ut_delete_object_desc", object);
 
 
 	/* Object must be an acpi_operand_object  */
@@ -312,7 +311,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_delete_object_cache
+ * FUNCTION:    acpi_ut_delete_object_cache
  *
  * PARAMETERS:  None
  *
@@ -327,7 +326,7 @@
 acpi_ut_delete_object_cache (
 	void)
 {
-	ACPI_FUNCTION_TRACE ("Ut_delete_object_cache");
+	ACPI_FUNCTION_TRACE ("ut_delete_object_cache");
 
 
 	acpi_ut_delete_generic_cache (ACPI_MEM_LIST_OPERAND);
@@ -337,10 +336,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_get_simple_object_size
+ * FUNCTION:    acpi_ut_get_simple_object_size
  *
- * PARAMETERS:  *Internal_object    - Pointer to the object we are examining
- *              *Obj_length         - Where the length is returned
+ * PARAMETERS:  *internal_object    - Pointer to the object we are examining
+ *              *obj_length         - Where the length is returned
  *
  * RETURN:      Status
  *
@@ -355,13 +354,13 @@
 acpi_status
 acpi_ut_get_simple_object_size (
 	acpi_operand_object     *internal_object,
-	ACPI_SIZE               *obj_length)
+	acpi_size               *obj_length)
 {
-	ACPI_SIZE               length;
+	acpi_size               length;
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ut_get_simple_object_size", internal_object);
+	ACPI_FUNCTION_TRACE_PTR ("ut_get_simple_object_size", internal_object);
 
 
 	/* Handle a null object (Could be a uninitialized package element -- which is legal) */
@@ -391,13 +390,13 @@
 	switch (ACPI_GET_OBJECT_TYPE (internal_object)) {
 	case ACPI_TYPE_STRING:
 
-		length += (ACPI_SIZE) internal_object->string.length + 1;
+		length += (acpi_size) internal_object->string.length + 1;
 		break;
 
 
 	case ACPI_TYPE_BUFFER:
 
-		length += (ACPI_SIZE) internal_object->buffer.length;
+		length += (acpi_size) internal_object->buffer.length;
 		break;
 
 
@@ -460,9 +459,9 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_get_element_length
+ * FUNCTION:    acpi_ut_get_element_length
  *
- * PARAMETERS:  ACPI_PKG_CALLBACK
+ * PARAMETERS:  acpi_pkg_callback
  *
  * RETURN:      Status
  *
@@ -479,7 +478,7 @@
 {
 	acpi_status             status = AE_OK;
 	acpi_pkg_info           *info = (acpi_pkg_info *) context;
-	ACPI_SIZE               object_space;
+	acpi_size               object_space;
 
 
 	switch (object_type) {
@@ -520,10 +519,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_get_package_object_size
+ * FUNCTION:    acpi_ut_get_package_object_size
  *
- * PARAMETERS:  *Internal_object    - Pointer to the object we are examining
- *              *Obj_length         - Where the length is returned
+ * PARAMETERS:  *internal_object    - Pointer to the object we are examining
+ *              *obj_length         - Where the length is returned
  *
  * RETURN:      Status
  *
@@ -538,13 +537,13 @@
 acpi_status
 acpi_ut_get_package_object_size (
 	acpi_operand_object     *internal_object,
-	ACPI_SIZE               *obj_length)
+	acpi_size               *obj_length)
 {
 	acpi_status             status;
 	acpi_pkg_info           info;
 
 
-	ACPI_FUNCTION_TRACE_PTR ("Ut_get_package_object_size", internal_object);
+	ACPI_FUNCTION_TRACE_PTR ("ut_get_package_object_size", internal_object);
 
 
 	info.length      = 0;
@@ -563,7 +562,7 @@
 	 * Round up to the next machine word.
 	 */
 	info.length += ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (acpi_object)) *
-			  (ACPI_SIZE) info.num_packages;
+			  (acpi_size) info.num_packages;
 
 	/* Return the total package length */
 
@@ -574,10 +573,10 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_ut_get_object_size
+ * FUNCTION:    acpi_ut_get_object_size
  *
- * PARAMETERS:  *Internal_object    - Pointer to the object we are examining
- *              *Obj_length         - Where the length will be returned
+ * PARAMETERS:  *internal_object    - Pointer to the object we are examining
+ *              *obj_length         - Where the length will be returned
  *
  * RETURN:      Status
  *
@@ -589,7 +588,7 @@
 acpi_status
 acpi_ut_get_object_size(
 	acpi_operand_object     *internal_object,
-	ACPI_SIZE               *obj_length)
+	acpi_size               *obj_length)
 {
 	acpi_status             status;
 
diff -Nru a/drivers/acpi/utilities/utxface.c b/drivers/acpi/utilities/utxface.c
--- a/drivers/acpi/utilities/utxface.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/acpi/utilities/utxface.c	Mon Dec 23 21:21:51 2002
@@ -1,7 +1,6 @@
 /******************************************************************************
  *
  * Module Name: utxface - External interfaces for "global" ACPI functions
- *              $Revision: 100 $
  *
  *****************************************************************************/
 
@@ -37,7 +36,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_initialize_subsystem
+ * FUNCTION:    acpi_initialize_subsystem
  *
  * PARAMETERS:  None
  *
@@ -54,7 +53,7 @@
 {
 	acpi_status             status;
 
-	ACPI_FUNCTION_TRACE ("Acpi_initialize_subsystem");
+	ACPI_FUNCTION_TRACE ("acpi_initialize_subsystem");
 
 
 	ACPI_DEBUG_EXEC (acpi_ut_init_stack_ptr_trace ());
@@ -105,7 +104,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_enable_subsystem
+ * FUNCTION:    acpi_enable_subsystem
  *
  * PARAMETERS:  Flags           - Init/enable Options
  *
@@ -123,13 +122,13 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_enable_subsystem");
+	ACPI_FUNCTION_TRACE ("acpi_enable_subsystem");
 
 
 	/*
-	 * Install the default Op_region handlers. These are installed unless
+	 * Install the default op_region handlers. These are installed unless
 	 * other handlers have already been installed via the
-	 * Install_address_space_handler interface
+	 * install_address_space_handler interface
 	 */
 	if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) {
 		ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Installing default address space handlers\n"));
@@ -163,7 +162,7 @@
 
 		status = acpi_enable ();
 		if (ACPI_FAILURE (status)) {
-			ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Acpi_enable failed.\n"));
+			ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "acpi_enable failed.\n"));
 			return_ACPI_STATUS (status);
 		}
 	}
@@ -199,7 +198,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_initialize_objects
+ * FUNCTION:    acpi_initialize_objects
  *
  * PARAMETERS:  Flags           - Init/enable Options
  *
@@ -217,7 +216,7 @@
 	acpi_status             status = AE_OK;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_initialize_objects");
+	ACPI_FUNCTION_TRACE ("acpi_initialize_objects");
 
 	/*
 	 * Initialize all device objects in the namespace
@@ -234,7 +233,7 @@
 
 	/*
 	 * Initialize the objects that remain uninitialized.  This
-	 * runs the executable AML that is part of the declaration of Op_regions
+	 * runs the executable AML that is part of the declaration of op_regions
 	 * and Fields.
 	 */
 	if (!(flags & ACPI_NO_OBJECT_INIT)) {
@@ -260,7 +259,7 @@
 
 /*******************************************************************************
  *
- * FUNCTION:    Acpi_terminate
+ * FUNCTION:    acpi_terminate
  *
  * PARAMETERS:  None
  *
@@ -276,7 +275,7 @@
 	acpi_status         status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_terminate");
+	ACPI_FUNCTION_TRACE ("acpi_terminate");
 
 
 	/* Terminate the AML Debugger if present */
@@ -309,7 +308,7 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_subsystem_status
+ * FUNCTION:    acpi_subsystem_status
  *
  * PARAMETERS:  None
  *
@@ -335,20 +334,20 @@
 
 /******************************************************************************
  *
- * FUNCTION:    Acpi_get_system_info
+ * FUNCTION:    acpi_get_system_info
  *
- * PARAMETERS:  Out_buffer      - a pointer to a buffer to receive the
+ * PARAMETERS:  out_buffer      - a pointer to a buffer to receive the
  *                                resources for the device
- *              Buffer_length   - the number of bytes available in the buffer
+ *              buffer_length   - the number of bytes available in the buffer
  *
  * RETURN:      Status          - the status of the call
  *
  * DESCRIPTION: This function is called to get information about the current
  *              state of the ACPI subsystem.  It will return system information
- *              in the Out_buffer.
+ *              in the out_buffer.
  *
  *              If the function fails an appropriate status will be returned
- *              and the value of Out_buffer is undefined.
+ *              and the value of out_buffer is undefined.
  *
  ******************************************************************************/
 
@@ -361,7 +360,7 @@
 	acpi_status             status;
 
 
-	ACPI_FUNCTION_TRACE ("Acpi_get_system_info");
+	ACPI_FUNCTION_TRACE ("acpi_get_system_info");
 
 
 	/* Parameter validation */
@@ -424,7 +423,7 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_install_initialization_handler
+ * FUNCTION:    acpi_install_initialization_handler
  *
  * PARAMETERS:  Handler             - Callback procedure
  *
@@ -438,7 +437,7 @@
 
 acpi_status
 acpi_install_initialization_handler (
-	ACPI_INIT_HANDLER       handler,
+	acpi_init_handler       handler,
 	u32                     function)
 {
 
@@ -457,7 +456,7 @@
 
 /*****************************************************************************
  *
- * FUNCTION:    Acpi_purge_cached_objects
+ * FUNCTION:    acpi_purge_cached_objects
  *
  * PARAMETERS:  None
  *
@@ -470,7 +469,7 @@
 acpi_status
 acpi_purge_cached_objects (void)
 {
-	ACPI_FUNCTION_TRACE ("Acpi_purge_cached_objects");
+	ACPI_FUNCTION_TRACE ("acpi_purge_cached_objects");
 
 
 	acpi_ut_delete_generic_state_cache ();
diff -Nru a/drivers/char/agp/Kconfig b/drivers/char/agp/Kconfig
--- a/drivers/char/agp/Kconfig	Mon Dec 23 21:21:56 2002
+++ b/drivers/char/agp/Kconfig	Mon Dec 23 21:21:56 2002
@@ -29,8 +29,11 @@
 	bool "/dev/agpgart (AGP Support)"
 	depends on GART_IOMMU
 
+config AGP3
+	bool "AGP 3.0 compliance (EXPERIMENTAL)"
+
 config AGP_INTEL
-	bool "Intel 440LX/BX/GX and I815/I820/I830M/I830MP/I840/I845/I850/I860 support"
+	tristate "Intel 440LX/BX/GX and I815/I820/I830M/I830MP/I840/I845/I850/I860 support"
 	depends on AGP
 	help
 	  This option gives you AGP support for the GLX component of the
@@ -40,7 +43,7 @@
 	  use GLX or DRI.  If unsure, say N.
 
 #config AGP_I810
-#	bool "Intel I810/I815/I830M (on-board) support"
+#	tristate "Intel I810/I815/I830M (on-board) support"
 #	depends on AGP
 #	help
 #	  This option gives you AGP support for the Xserver on the Intel 810
@@ -48,7 +51,7 @@
 #	  is required to do any useful video modes with these boards.
 
 config AGP_VIA
-	bool "VIA chipset support"
+	tristate "VIA chipset support"
 	depends on AGP
 	help
 	  This option gives you AGP support for the GLX component of the
@@ -58,7 +61,7 @@
 	  use GLX or DRI.  If unsure, say N.
 
 config AGP_AMD
-	bool "AMD Irongate, 761, and 762 support"
+	tristate "AMD Irongate, 761, and 762 support"
 	depends on AGP
 	help
 	  This option gives you AGP support for the GLX component of the
@@ -68,7 +71,7 @@
 	  use GLX or DRI.  If unsure, say N.
 
 config AGP_SIS
-	bool "Generic SiS support"
+	tristate "Generic SiS support"
 	depends on AGP
 	help
 	  This option gives you AGP support for the GLX component of the "soon
@@ -81,7 +84,7 @@
 	  use GLX or DRI.  If unsure, say N.
 
 config AGP_ALI
-	bool "ALI chipset support"
+	tristate "ALI chipset support"
 	depends on AGP
 	---help---
 	  This option gives you AGP support for the GLX component of the
@@ -99,14 +102,14 @@
 	  use GLX or DRI.  If unsure, say N.
 
 config AGP_SWORKS
-	bool "Serverworks LE/HE support"
+	tristate "Serverworks LE/HE support"
 	depends on AGP
 	help
 	  Say Y here to support the Serverworks AGP card.  See 
 	  <http://www.serverworks.com/> for product descriptions and images.
 
 config AGP_AMD_8151
-	bool "AMD 8151 support"
+	tristate "AMD 8151 support"
 	depends on AGP
 	default GART_IOMMU
 	help
@@ -114,16 +117,28 @@
 	  GART on the AMD Athlon64/Opteron ("Hammer") CPUs.
 
 config AGP_I460
-	bool "Intel 460GX support"
+	tristate "Intel 460GX support"
 	depends on AGP && IA64
 	help
 	  This option gives you AGP GART support for the Intel 460GX chipset
 	  for IA64 processors.
 
 config AGP_HP_ZX1
-	bool "HP ZX1 AGP support"
+	tristate "HP ZX1 AGP support"
 	depends on AGP && IA64
 	help
 	  This option gives you AGP GART support for the HP ZX1 chipset
 	  for IA64 processors.
+
+# Put AGP 3.0 entries below here.
+
+config AGP_I7505
+	tristate "Intel 7205/7505 support (AGP 3.0)"
+	depends on AGP3
+	help
+	  This option gives you AGP support for the GLX component of the
+	  XFree86 4.x on Intel I7505 chipsets.
+
+	  You should say Y here if you use XFree86 3.3.6 or 4.x and want to
+	  use GLX or DRI.  If unsure, say N
 
diff -Nru a/drivers/char/agp/Makefile b/drivers/char/agp/Makefile
--- a/drivers/char/agp/Makefile	Mon Dec 23 21:21:53 2002
+++ b/drivers/char/agp/Makefile	Mon Dec 23 21:21:53 2002
@@ -6,6 +6,7 @@
 export-objs := backend.o
 
 agpgart-y := backend.o frontend.o generic.o
+agpgart-$(CONFIG_AGP3) += generic-3.0.o
 agpgart-objs := $(agpgart-y)
 obj-$(CONFIG_AGP) += agpgart.o
 
@@ -18,4 +19,6 @@
 obj-$(CONFIG_AGP_I460)		+= i460-agp.o
 obj-$(CONFIG_AGP_HP_ZX1)	+= hp-agp.o
 obj-$(CONFIG_AGP_AMD_8151)	+= amd-k8-agp.o
+
+obj-$(CONFIG_AGP_I7x05)		+= i7x05-agp.o
 
diff -Nru a/drivers/char/agp/agp.h b/drivers/char/agp/agp.h
--- a/drivers/char/agp/agp.h	Mon Dec 23 21:21:53 2002
+++ b/drivers/char/agp/agp.h	Mon Dec 23 21:21:53 2002
@@ -33,6 +33,7 @@
 
 /* Generic routines. */
 void agp_generic_agp_enable(u32 mode);
+int agp_generic_agp_3_0_enable(u32 mode);
 int agp_generic_create_gatt_table(void);
 int agp_generic_free_gatt_table(void);
 agp_memory *agp_create_memory(int scratch_pages);
@@ -46,28 +47,6 @@
 void agp_generic_resume(void);
 void agp_free_key(int key);
 
-/* chipset specific init routines. */
-/*
-int __init ali_generic_setup (struct pci_dev *pdev);
-int __init amd_irongate_setup (struct pci_dev *pdev);
-int __init amd_8151_setup (struct pci_dev *pdev);
-int __init hp_zx1_setup (struct pci_dev *pdev);
-int __init intel_i460_setup (struct pci_dev *pdev);
-int __init intel_generic_setup (struct pci_dev *pdev);
-int __init intel_i810_setup(struct pci_dev *i810_dev);
-int __init intel_815_setup(struct pci_dev *pdev);
-int __init intel_i830_setup(struct pci_dev *i830_dev);
-int __init intel_820_setup (struct pci_dev *pdev);
-int __init intel_830mp_setup (struct pci_dev *pdev);
-int __init intel_840_setup (struct pci_dev *pdev);
-int __init intel_845_setup (struct pci_dev *pdev);
-int __init intel_850_setup (struct pci_dev *pdev);
-int __init intel_860_setup (struct pci_dev *pdev);
-int __init serverworks_setup (struct pci_dev *pdev);
-int __init sis_generic_setup (struct pci_dev *pdev);
-int __init via_generic_setup (struct pci_dev *pdev);
-*/
-
 #define PFX "agpgart: "
 
 int agp_register_driver (struct pci_dev *dev);
@@ -311,6 +290,9 @@
 #define VIA_GARTCTRL	0x80
 #define VIA_APSIZE	0x84
 #define VIA_ATTBASE	0x88
+
+/* VIA KT400 */
+#define VIA_AGPSEL	0xfd
 
 /* SiS registers */
 #define SIS_APBASE	0x10
diff -Nru a/drivers/char/agp/ali-agp.c b/drivers/char/agp/ali-agp.c
--- a/drivers/char/agp/ali-agp.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/char/agp/ali-agp.c	Mon Dec 23 21:21:58 2002
@@ -195,7 +195,7 @@
 	{4, 1024, 0, 3}
 };
 
-int __init ali_generic_setup (struct pci_dev *pdev)
+static int __init ali_generic_setup (struct pci_dev *pdev)
 {
 	agp_bridge.masks = ali_generic_masks;
 	agp_bridge.num_of_masks = 1;
@@ -338,17 +338,20 @@
 }
 
 
-
-
-static int agp_ali_probe (struct pci_dev *dev, const struct pci_device_id *ent)
+static int __init agp_ali_probe (struct pci_dev *dev, const struct pci_device_id *ent)
 {
-	if (pci_find_capability(dev, PCI_CAP_ID_AGP)==0)
-		return -ENODEV;
+	u8 cap_ptr = 0;
 
-	agp_bridge.dev = dev;
+	cap_ptr = pci_find_capability(dev, PCI_CAP_ID_AGP);
+	if (cap_ptr == 0)
+		return -ENODEV;
 
 	/* probe for known chipsets */
-	if (agp_lookup_host_bridge (dev) != -ENODEV ) {
+	if (agp_lookup_host_bridge(dev) != -ENODEV) {
+		agp_bridge.dev = dev;
+		agp_bridge.capndx = cap_ptr;
+		/* Fill in the mode register */
+		pci_read_config_dword(agp_bridge.dev, agp_bridge.capndx+4, &agp_bridge.mode);
 		agp_register_driver(dev);
 		return 0;
 	}
@@ -369,7 +372,7 @@
 
 MODULE_DEVICE_TABLE(pci, agp_ali_pci_table);
 
-static struct pci_driver agp_ali_pci_driver = {
+static struct __initdata pci_driver agp_ali_pci_driver = {
 	.name		= "agpgart-ali",
 	.id_table	= agp_ali_pci_table,
 	.probe		= agp_ali_probe,
diff -Nru a/drivers/char/agp/amd-k7-agp.c b/drivers/char/agp/amd-k7-agp.c
--- a/drivers/char/agp/amd-k7-agp.c	Mon Dec 23 21:22:02 2002
+++ b/drivers/char/agp/amd-k7-agp.c	Mon Dec 23 21:22:02 2002
@@ -138,8 +138,8 @@
 		return retval;
 	}
 
-	agp_bridge.gatt_table_real = (u32 *)page_dir.real;
-	agp_bridge.gatt_table = (u32 *)page_dir.remapped;
+	agp_bridge.gatt_table_real = (unsigned long *)page_dir.real;
+	agp_bridge.gatt_table = (unsigned long *)page_dir.remapped;
 	agp_bridge.gatt_bus_addr = virt_to_phys(page_dir.real);
 
 	/* Get the address for the gart region.
@@ -165,8 +165,8 @@
 {
 	struct amd_page_map page_dir;
    
-	page_dir.real = (u32 *)agp_bridge.gatt_table_real;
-	page_dir.remapped = (u32 *)agp_bridge.gatt_table;
+	page_dir.real = (unsigned long *)agp_bridge.gatt_table_real;
+	page_dir.remapped = (unsigned long *)agp_bridge.gatt_table;
 
 	amd_free_gatt_pages();
 	amd_free_page_map(&page_dir);
@@ -351,7 +351,7 @@
 	{.mask = 0x00000001, .type = 0}
 };
 
-int __init amd_irongate_setup (struct pci_dev *pdev)
+static int __init amd_irongate_setup (struct pci_dev *pdev)
 {
 	agp_bridge.masks = amd_irongate_masks;
 	agp_bridge.num_of_masks = 1;
@@ -439,25 +439,23 @@
 
 /* Supported Device Scanning routine */
 
-static int __init agp_find_supported_device(struct pci_dev *dev)
+static int __init agp_amdk7_probe (struct pci_dev *dev, const struct pci_device_id *ent)
 {
-	agp_bridge.dev = dev;
+	u8 cap_ptr = 0;
 
-	if (pci_find_capability(dev, PCI_CAP_ID_AGP)==0)
+	cap_ptr = pci_find_capability(dev, PCI_CAP_ID_AGP);
+	if (cap_ptr == 0)
 		return -ENODEV;
 
-	/* probe for known chipsets */
-	return agp_lookup_host_bridge (dev);
-}
-
-
-static int agp_amdk7_probe (struct pci_dev *dev, const struct pci_device_id *ent)
-{
-	if (agp_find_supported_device(dev) == 0) {
+	if (agp_lookup_host_bridge(dev) != -ENODEV) {
+		agp_bridge.dev = dev;
+		agp_bridge.capndx = cap_ptr;
+		/* Fill in the mode register */
+		pci_read_config_dword(agp_bridge.dev, agp_bridge.capndx+4, &agp_bridge.mode);
 		agp_register_driver(dev);
 		return 0;
 	}
-	return -ENODEV;	
+	return -ENODEV;
 }
 
 static struct pci_device_id agp_amdk7_pci_table[] __initdata = {
@@ -474,7 +472,7 @@
 
 MODULE_DEVICE_TABLE(pci, agp_amdk7_pci_table);
 
-static struct pci_driver agp_amdk7_pci_driver = {
+static struct __initdata pci_driver agp_amdk7_pci_driver = {
 	.name		= "agpgart-amdk7",
 	.id_table	= agp_amdk7_pci_table,
 	.probe		= agp_amdk7_probe,
diff -Nru a/drivers/char/agp/amd-k8-agp.c b/drivers/char/agp/amd-k8-agp.c
--- a/drivers/char/agp/amd-k8-agp.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/char/agp/amd-k8-agp.c	Mon Dec 23 21:21:58 2002
@@ -151,7 +151,7 @@
 }
 
 
-static void inline flush_x86_64_tlb(struct pci_dev *dev)
+static void flush_x86_64_tlb(struct pci_dev *dev)
 {
 	u32 tmp;
 
@@ -370,7 +370,7 @@
 	}
 
 
-	pci_read_config_dword(agp_bridge.dev, agp_bridge.capndx + 4, &command);
+	pci_read_config_dword(agp_bridge.dev, agp_bridge.capndx+4, &command);
 
 	/*
 	 * PASS2: go through all devices that claim to be
@@ -429,7 +429,7 @@
 
 	command |= 0x100;
 
-	pci_write_config_dword(agp_bridge.dev, agp_bridge.capndx + 8, command);
+	pci_write_config_dword(agp_bridge.dev, agp_bridge.capndx+8, command);
 
 	/*
 	 * PASS4: Go through all AGP devices and update the
@@ -475,11 +475,19 @@
 }
 
 
-static int agp_amdk8_probe (struct pci_dev *dev, const struct pci_device_id *ent)
+static int __init agp_amdk8_probe (struct pci_dev *dev, const struct pci_device_id *ent)
 {
-	if (pci_find_capability(dev, PCI_CAP_ID_AGP)==0)
+	u8 cap_ptr = 0;
+
+	cap_ptr = pci_find_capability(dev, PCI_CAP_ID_AGP);
+	if (cap_ptr == 0)
 		return -ENODEV;
 
+	agp_bridge.dev = dev;
+	agp_bridge.capndx = cap_ptr;
+
+	/* Fill in the mode register */
+	pci_read_config_dword(agp_bridge.dev, agp_bridge.capndx+4, &agp_bridge.mode);
 	amd_8151_setup(dev);
 	agp_register_driver(dev);
 	return 0;
@@ -499,7 +507,7 @@
 
 MODULE_DEVICE_TABLE(pci, agp_amdk8_pci_table);
 
-static struct pci_driver agp_amdk8_pci_driver = {
+static struct __initdata pci_driver agp_amdk8_pci_driver = {
 	.name		= "agpgart-amd-k8",
 	.id_table	= agp_amdk8_pci_table,
 	.probe		= agp_amdk8_probe,
diff -Nru a/drivers/char/agp/backend.c b/drivers/char/agp/backend.c
--- a/drivers/char/agp/backend.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/char/agp/backend.c	Mon Dec 23 21:21:58 2002
@@ -36,8 +36,11 @@
 #include <linux/agp_backend.h>
 #include "agp.h"
 
-#define AGPGART_VERSION_MAJOR 1
-#define AGPGART_VERSION_MINOR 0
+/* Due to XFree86 brain-damage, we can't go to 1.0 until they
+ * fix some real stupidity. It's only by chance we can bump
+ * past 0.99 at all due to some boolean logic error. */
+#define AGPGART_VERSION_MAJOR 0
+#define AGPGART_VERSION_MINOR 100
 
 struct agp_bridge_data agp_bridge = { .type = NOT_SUPPORTED };
 
@@ -109,23 +112,13 @@
 	.minor = AGPGART_VERSION_MINOR,
 };
 
-static int __init agp_backend_initialize(struct pci_dev *dev)
+static int agp_backend_initialize(struct pci_dev *dev)
 {
 	int size_value, rc, got_gatt=0, got_keylist=0;
-	u8 cap_ptr = 0;
 
 	agp_bridge.max_memory_agp = agp_find_max();
 	agp_bridge.version = &agp_current_version;
 
-	cap_ptr = pci_find_capability(dev, PCI_CAP_ID_AGP);
-	if (cap_ptr == 0)
-		return -ENODEV;
-	agp_bridge.capndx = cap_ptr;
-
-	/* Fill in the mode register */
-	pci_read_config_dword(agp_bridge.dev, agp_bridge.capndx + 4, &agp_bridge.mode);
-
-
 	if (agp_bridge.needs_scratch_page == TRUE) {
 		void *addr;
 		addr = agp_bridge.agp_alloc_page();
@@ -251,14 +244,14 @@
 	}
 
 	inter_module_register("drm_agp", THIS_MODULE, &drm_agp);
-	
+
 	pm_register(PM_PCI_DEV, PM_PCI_ID(agp_bridge.dev), agp_power);
 
 	agp_count++;
 	return 0;
 }
 
-int __exit agp_unregister_driver(void)
+int agp_unregister_driver(void)
 {
 	agp_bridge.type = NOT_SUPPORTED;
 	pm_unregister_all(agp_power);
@@ -269,8 +262,16 @@
 	return 0;
 }
 
+
 int __init agp_init(void)
 {
+	static int already_initialised=0;
+
+	if (already_initialised!=0)
+		return 0;
+
+	already_initialised = 1;
+
 	memset(&agp_bridge, 0, sizeof(struct agp_bridge_data));
 	agp_bridge.type = NOT_SUPPORTED;
 
@@ -279,13 +280,21 @@
 	return 0;
 }
 
+void __exit agp_exit(void)
+{
+	if (agp_count!=0)
+		BUG();
+}
+
 #ifndef CONFIG_GART_IOMMU
 module_init(agp_init);
+module_exit(agp_exit);
 #endif
 
 EXPORT_SYMBOL(agp_backend_acquire);
 EXPORT_SYMBOL(agp_backend_release);
 EXPORT_SYMBOL_GPL(agp_register_driver);
+EXPORT_SYMBOL_GPL(agp_unregister_driver);
 
 MODULE_AUTHOR("Dave Jones <davej@codemonkey.org.uk>");
 MODULE_LICENSE("GPL and additional rights");
diff -Nru a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
--- a/drivers/char/agp/frontend.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/char/agp/frontend.c	Mon Dec 23 21:21:51 2002
@@ -1062,12 +1062,12 @@
 
 static struct miscdevice agp_miscdev =
 {
-	AGPGART_MINOR,
-	"agpgart",
-	&agp_fops
+	.minor	= AGPGART_MINOR,
+	.name	= "agpgart",
+	.fops	= &agp_fops
 };
 
-int __init agp_frontend_initialize(void)
+int agp_frontend_initialize(void)
 {
 	memset(&agp_fe, 0, sizeof(struct agp_front_data));
 	AGP_LOCK_INIT();
@@ -1079,7 +1079,7 @@
 	return 0;
 }
 
-void __exit agp_frontend_cleanup(void)
+void agp_frontend_cleanup(void)
 {
 	misc_deregister(&agp_miscdev);
 }
diff -Nru a/drivers/char/agp/generic-3.0.c b/drivers/char/agp/generic-3.0.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/char/agp/generic-3.0.c	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,554 @@
+#include <linux/list.h>
+#include <linux/pci.h>
+#include <linux/agp_backend.h>
+#include <linux/module.h>
+
+#include "agp.h"
+
+/* Generic AGP 3.0 enabling routines */
+
+struct agp_3_0_dev {
+	struct list_head list;
+	u8 capndx;
+	u32 maxbw;
+	struct pci_dev *dev;
+};
+
+static int agp_3_0_dev_list_insert(struct list_head *head, struct list_head *new)
+{
+	struct agp_3_0_dev *cur, *n = list_entry(new, struct agp_3_0_dev, list);
+	struct list_head *pos;
+
+	list_for_each(pos, head) {
+		cur = list_entry(pos, struct agp_3_0_dev, list);
+		if(cur->maxbw > n->maxbw)
+			break;
+	}
+	list_add_tail(new, pos);
+
+	return 0;
+}
+
+static int agp_3_0_dev_list_sort(struct agp_3_0_dev *list, unsigned int ndevs)
+{
+	struct agp_3_0_dev *cur;
+	struct pci_dev *dev;
+	struct list_head *pos, *tmp, *head = &list->list, *start = head->next;
+	u32 nistat;
+
+	INIT_LIST_HEAD(head);
+
+	for(pos = start; pos != head;) {
+		cur = list_entry(pos, struct agp_3_0_dev, list);
+		dev = cur->dev;
+
+		pci_read_config_dword(dev, cur->capndx + 0x0c, &nistat);
+		cur->maxbw = (nistat >> 16) & 0xff;
+
+		tmp = pos;
+		pos = pos->next;
+		agp_3_0_dev_list_insert(head, tmp);
+	}
+	return 0;
+}
+
+/* 
+ * Initialize all isochronous transfer parameters for an AGP 3.0 
+ * node (i.e. a host bridge in combination with the adapters 
+ * lying behind it...)
+ */
+
+static int agp_3_0_isochronous_node_enable(struct agp_3_0_dev *dev_list, unsigned int ndevs)
+{
+	/*
+	 * Convenience structure to make the calculations clearer
+	 * here.  The field names come straight from the AGP 3.0 spec.
+	 */
+	struct isoch_data {
+		u32 maxbw;
+		u32 n;
+		u32 y;
+		u32 l;
+		u32 rq;
+		struct agp_3_0_dev *dev;
+	};
+
+	struct pci_dev *td = agp_bridge.dev, *dev;
+	struct list_head *head = &dev_list->list, *pos;
+	struct agp_3_0_dev *cur;
+	struct isoch_data *master, target;
+	unsigned int cdev = 0;
+	u32 mnistat, tnistat, tstatus, mcmd;
+	u16 tnicmd, mnicmd;
+	u8 mcapndx;
+	u32 tot_bw = 0, tot_n = 0, tot_rq = 0, y_max, rq_isoch, rq_async;
+	u32 step, rem, rem_isoch, rem_async;
+	int ret = 0;
+
+	/*
+	 * We'll work with an array of isoch_data's (one for each
+	 * device in dev_list) throughout this function.
+	 */
+	if((master = kmalloc(ndevs * sizeof(*master), GFP_KERNEL)) == NULL) {
+		ret = -ENOMEM;
+		goto get_out;
+	}
+
+	/*
+	 * Sort the device list by maxbw.  We need to do this because the
+	 * spec suggests that the devices with the smallest requirements
+	 * have their resources allocated first, with all remaining resources
+	 * falling to the device with the largest requirement.
+	 *
+	 * We don't exactly do this, we divide target resources by ndevs
+	 * and split them amongst the AGP 3.0 devices.  The remainder of such
+	 * division operations are dropped on the last device, sort of like
+	 * the spec mentions it should be done.
+	 *
+	 * We can't do this sort when we initially construct the dev_list
+	 * because we don't know until this function whether isochronous
+	 * transfers are enabled and consequently whether maxbw will mean
+	 * anything.
+	 */
+	if((ret = agp_3_0_dev_list_sort(dev_list, ndevs)) != 0)
+		goto free_and_exit;
+
+	pci_read_config_dword(td, agp_bridge.capndx + 0x0c, &tnistat);
+	pci_read_config_dword(td, agp_bridge.capndx + 0x04, &tstatus);
+
+	/* Extract power-on defaults from the target */
+	target.maxbw = (tnistat >> 16) & 0xff;
+	target.n     = (tnistat >> 8)  & 0xff;
+	target.y     = (tnistat >> 6)  & 0x3;
+	target.l     = (tnistat >> 3)  & 0x7;
+	target.rq    = (tstatus >> 24) & 0xff;
+
+	y_max = target.y;
+
+	/*
+	 * Extract power-on defaults for each device in dev_list.  Along
+	 * the way, calculate the total isochronous bandwidth required
+	 * by these devices and the largest requested payload size.
+	 */
+	list_for_each(pos, head) {
+		cur = list_entry(pos, struct agp_3_0_dev, list);
+		dev = cur->dev;
+
+		mcapndx = cur->capndx;
+
+		pci_read_config_dword(dev, cur->capndx + 0x0c, &mnistat);
+
+		master[cdev].maxbw = (mnistat >> 16) & 0xff;
+		master[cdev].n     = (mnistat >> 8)  & 0xff;
+		master[cdev].y     = (mnistat >> 6)  & 0x3;
+		master[cdev].dev   = cur;
+
+		tot_bw += master[cdev].maxbw;
+		y_max = max(y_max, master[cdev].y);
+
+		cdev++;
+	}
+
+	/* Check if this configuration has any chance of working */
+	if(tot_bw > target.maxbw) {
+		printk(KERN_ERR PFX "isochronous bandwidth required "
+			"by AGP 3.0 devices exceeds that which is supported by "
+			"the AGP 3.0 bridge!\n");
+		ret = -ENODEV;
+		goto free_and_exit;
+	}
+
+	target.y = y_max;
+
+	/*
+	 * Write the calculated payload size into the target's NICMD
+	 * register.  Doing this directly effects the ISOCH_N value
+	 * in the target's NISTAT register, so we need to do this now
+	 * to get an accurate value for ISOCH_N later.
+	 */
+	pci_read_config_word(td, agp_bridge.capndx + 0x20, &tnicmd);
+	tnicmd &= ~(0x3 << 6);
+	tnicmd |= target.y << 6;
+	pci_write_config_word(td, agp_bridge.capndx + 0x20, tnicmd);
+
+	/* Reread the target's ISOCH_N */
+	pci_read_config_dword(td, agp_bridge.capndx + 0x0c, &tnistat);
+	target.n = (tnistat >> 8) & 0xff;
+
+	/* Calculate the minimum ISOCH_N needed by each master */
+	for(cdev = 0; cdev < ndevs; cdev++) {
+		master[cdev].y = target.y;
+		master[cdev].n = master[cdev].maxbw / (master[cdev].y + 1);
+
+		tot_n += master[cdev].n;
+	}
+
+	/* Exit if the minimal ISOCH_N allocation among the masters is more
+	 * than the target can handle. */
+	if(tot_n > target.n) {
+		printk(KERN_ERR PFX "number of isochronous "
+			"transactions per period required by AGP 3.0 devices "
+			"exceeds that which is supported by the AGP 3.0 "
+			"bridge!\n");
+		ret = -ENODEV;
+		goto free_and_exit;
+	}
+
+	/* Calculate left over ISOCH_N capability in the target.  We'll give
+	 * this to the hungriest device (as per the spec) */
+	rem  = target.n - tot_n;
+
+	/* 
+	 * Calculate the minimum isochronous RQ depth needed by each master.
+	 * Along the way, distribute the extra ISOCH_N capability calculated
+	 * above.
+	 */
+	for(cdev = 0; cdev < ndevs; cdev++) {
+		/*
+		 * This is a little subtle.  If ISOCH_Y > 64B, then ISOCH_Y
+		 * byte isochronous writes will be broken into 64B pieces.
+		 * This means we need to budget more RQ depth to account for
+		 * these kind of writes (each isochronous write is actually
+		 * many writes on the AGP bus).
+		 */
+		master[cdev].rq = master[cdev].n;
+		if(master[cdev].y > 0x1) {
+			master[cdev].rq *= (1 << (master[cdev].y - 1));
+		}
+
+		tot_rq += master[cdev].rq;
+
+		if(cdev == ndevs - 1)
+			master[cdev].n += rem;
+	}
+
+	/* Figure the number of isochronous and asynchronous RQ slots the
+	 * target is providing. */
+	rq_isoch = (target.y > 0x1) ? target.n * (1 << (target.y - 1)) : target.n;
+	rq_async = target.rq - rq_isoch;
+
+	/* Exit if the minimal RQ needs of the masters exceeds what the target
+	 * can provide. */
+	if(tot_rq > rq_isoch) {
+		printk(KERN_ERR PFX "number of request queue slots "
+			"required by the isochronous bandwidth requested by "
+			"AGP 3.0 devices exceeds the number provided by the "
+			"AGP 3.0 bridge!\n");
+		ret = -ENODEV;
+		goto free_and_exit;
+	}
+
+	/* Calculate asynchronous RQ capability in the target (per master) as
+	 * well as the total number of leftover isochronous RQ slots. */
+	step      = rq_async / ndevs;
+	rem_async = step + (rq_async % ndevs);
+	rem_isoch = rq_isoch - tot_rq;
+
+	/* Distribute the extra RQ slots calculated above and write our
+	 * isochronous settings out to the actual devices. */
+	for(cdev = 0; cdev < ndevs; cdev++) {
+		cur = master[cdev].dev;
+		dev = cur->dev;
+
+		mcapndx = cur->capndx;
+
+		master[cdev].rq += (cdev == ndevs - 1)
+		              ? (rem_async + rem_isoch) : step;
+
+		pci_read_config_word(dev, cur->capndx + 0x20, &mnicmd);
+		pci_read_config_dword(dev, cur->capndx + 0x08, &mcmd);
+
+		mnicmd &= ~(0xff << 8);
+		mnicmd &= ~(0x3  << 6);
+		mcmd   &= ~(0xff << 24);
+
+		mnicmd |= master[cdev].n  << 8;
+		mnicmd |= master[cdev].y  << 6;
+		mcmd   |= master[cdev].rq << 24;
+
+		pci_write_config_dword(dev, cur->capndx + 0x08, mcmd);
+		pci_write_config_word(dev, cur->capndx + 0x20, mnicmd);
+	}
+
+free_and_exit:
+	kfree(master);
+
+get_out:
+	return ret;
+}
+
+/*
+ * This function basically allocates request queue slots among the
+ * AGP 3.0 systems in nonisochronous nodes.  The algorithm is
+ * pretty stupid, divide the total number of RQ slots provided by the
+ * target by ndevs.  Distribute this many slots to each AGP 3.0 device,
+ * giving any left over slots to the last device in dev_list.
+ */
+static int agp_3_0_nonisochronous_node_enable(struct agp_3_0_dev *dev_list, unsigned int ndevs)
+{
+	struct agp_3_0_dev *cur;
+	struct list_head *head = &dev_list->list, *pos;
+	u32 tstatus, mcmd;
+	u32 trq, mrq, rem;
+	unsigned int cdev = 0;
+
+	pci_read_config_dword(agp_bridge.dev, agp_bridge.capndx + 0x04, &tstatus);
+
+	trq = (tstatus >> 24) & 0xff;
+	mrq = trq / ndevs;
+
+	rem = mrq + (trq % ndevs);
+
+	for(pos = head->next; cdev < ndevs; cdev++, pos = pos->next) {
+		cur = list_entry(pos, struct agp_3_0_dev, list);
+
+		pci_read_config_dword(cur->dev, cur->capndx + 0x08, &mcmd);
+		mcmd &= ~(0xff << 24);
+		mcmd |= ((cdev == ndevs - 1) ? rem : mrq) << 24;
+		pci_write_config_dword(cur->dev, cur->capndx + 0x08, mcmd);
+	}
+
+	return 0;
+}
+
+/*
+ * Fully configure and enable an AGP 3.0 host bridge and all the devices
+ * lying behind it.
+ */
+static int agp_3_0_node_enable(u32 mode, u32 minor)
+{
+	struct pci_dev *td = agp_bridge.dev, *dev;
+	u8 bus_num, mcapndx;
+	u32 isoch, arqsz, cal_cycle, tmp, rate;
+	u32 tstatus, tcmd, mcmd, mstatus, ncapid;
+	u32 mmajor, mminor;
+	u16 mpstat;
+	struct agp_3_0_dev *dev_list, *cur;
+	struct list_head *head, *pos;
+	unsigned int ndevs = 0;
+	int ret = 0;
+
+	/* 
+	 * Allocate a head for our AGP 3.0 device list (multiple AGP 3.0
+	 * devices are allowed behind a single bridge). 
+	 */
+	if((dev_list = kmalloc(sizeof(*dev_list), GFP_KERNEL)) == NULL) {
+		ret = -ENOMEM;
+		goto get_out;
+	}
+	head = &dev_list->list;
+	INIT_LIST_HEAD(head);
+
+	/* 
+	 * Find all the devices on this bridge's secondary bus and add them
+	 * to dev_list. 
+	 */
+	pci_read_config_byte(td, PCI_SECONDARY_BUS, &bus_num);
+	pci_for_each_dev(dev) {
+		if(dev->bus->number == bus_num) {
+			if((cur = kmalloc(sizeof(*cur), GFP_KERNEL)) == NULL) {
+				ret = -ENOMEM;
+				goto free_and_exit;
+			}
+			
+			cur->dev = dev;
+
+			pos = &cur->list;
+			list_add(pos, head);
+			ndevs++;
+		}
+	}
+
+	/* Extract some power-on defaults from the target */
+	pci_read_config_dword(td, agp_bridge.capndx + 0x04, &tstatus);
+	isoch     = (tstatus >> 17) & 0x1;
+	arqsz     = (tstatus >> 13) & 0x7;
+	cal_cycle = (tstatus >> 10) & 0x7;
+	rate      = tstatus & 0x7;
+
+	/*
+	 * Take an initial pass through the devices lying behind our host
+	 * bridge.  Make sure each one is actually an AGP 3.0 device, otherwise
+	 * exit with an error message.  Along the way store the AGP 3.0
+	 * cap_ptr for each device, the minimum supported cal_cycle, and the
+	 * minimum supported data rate.
+	 */
+	list_for_each(pos, head) {
+		cur = list_entry(pos, struct agp_3_0_dev, list);
+		dev = cur->dev;
+		
+		pci_read_config_word(dev, PCI_STATUS, &mpstat);
+		if((mpstat & PCI_STATUS_CAP_LIST) == 0)
+			continue;
+
+		pci_read_config_byte(dev, PCI_CAPABILITY_LIST, &mcapndx);
+		if (mcapndx != 0x00) {
+			do {
+				pci_read_config_dword(dev, mcapndx, &ncapid);
+				if ((ncapid & 0xff) != 0x02)
+					mcapndx = (ncapid >> 8) & 0xff;
+			}
+			while (((ncapid & 0xff) != 0x02) && (mcapndx != 0x00));
+		}
+
+		if(mcapndx == 0) {
+			printk(KERN_ERR PFX "woah!  Non-AGP device "
+				"found on the secondary bus of an AGP 3.0 "
+				"bridge!\n");
+			ret = -ENODEV;
+			goto free_and_exit;
+		}
+
+		mmajor = (ncapid >> 20) & 0xf;
+		mminor = (ncapid >> 16) & 0xf;
+
+		if(mmajor < 3) {
+			printk(KERN_ERR PFX "woah!  AGP 2.0 device "
+				"found on the secondary bus of an AGP 3.0 "
+				"bridge operating with AGP 3.0 electricals!\n");
+			ret = -ENODEV;
+			goto free_and_exit;
+		}
+
+		cur->capndx = mcapndx;
+
+		pci_read_config_dword(dev, cur->capndx + 0x04, &mstatus);
+
+		if(((mstatus >> 3) & 0x1) == 0) {
+			printk(KERN_ERR PFX "woah!  AGP 3.0 device "
+				"not operating in AGP 3.0 mode found on the "
+				"secondary bus of an AGP 3.0 bridge operating "
+				"with AGP 3.0 electricals!\n");
+			ret = -ENODEV;
+			goto free_and_exit;
+		}
+
+		tmp = (mstatus >> 10) & 0x7;
+		cal_cycle = min(cal_cycle, tmp);
+
+		/* figure the lesser rate */
+		tmp = mstatus & 0x7;
+		if(tmp < rate) 
+			rate = tmp;
+			
+	}		
+
+	/* Turn rate into something we can actually write out to AGPCMD */
+	switch(rate) {
+	case 0x1:
+	case 0x2:
+		break;
+	case 0x3:
+		rate = 0x2;
+		break;
+	default:
+		printk(KERN_ERR PFX "woah!  Bogus AGP rate "
+			"value found advertised behind an AGP 3.0 "
+			"bridge!\n");
+		ret = -ENODEV;
+		goto free_and_exit;
+	}
+
+	/*
+	 * Call functions to divide target resources amongst the AGP 3.0
+	 * masters.  This process is dramatically different depending on
+	 * whether isochronous transfers are supported.
+	 */
+	if(isoch != 0) {
+		if((ret = agp_3_0_isochronous_node_enable(dev_list,
+		                                          ndevs)) != 0)
+			goto free_and_exit;
+	} else {
+		if((ret = agp_3_0_nonisochronous_node_enable(dev_list,
+		                                             ndevs)) != 0)
+			goto free_and_exit;
+	}
+
+	/*
+	 * Set the calculated minimum supported cal_cycle and minimum
+	 * supported transfer rate in the target's AGPCMD register.
+	 * Also set the AGP_ENABLE bit, effectively 'turning on' the
+	 * target (this has to be done _before_ turning on the masters).
+	 */
+	pci_read_config_dword(td, agp_bridge.capndx + 0x08, &tcmd);
+
+	tcmd &= ~(0x7 << 10);
+	tcmd &= ~0x7;
+
+	tcmd |= cal_cycle << 10;
+	tcmd |= 0x1 << 8;
+	tcmd |= rate;
+
+	pci_write_config_dword(td, agp_bridge.capndx + 0x08, tcmd);
+
+	/*
+	 * Set the target's advertised arqsz value, the minimum supported
+	 * transfer rate, and the AGP_ENABLE bit in each master's AGPCMD
+	 * register.
+	 */
+	list_for_each(pos, head) {
+		cur = list_entry(pos, struct agp_3_0_dev, list);
+		dev = cur->dev;
+
+		mcapndx = cur->capndx;
+
+		pci_read_config_dword(dev, cur->capndx + 0x08, &mcmd);
+
+		mcmd &= ~(0x7 << 13);
+		mcmd &= ~0x7;
+
+		mcmd |= arqsz << 13;
+		mcmd |= 0x1 << 8;
+		mcmd |= rate;
+
+		pci_write_config_dword(dev, cur->capndx + 0x08, mcmd);
+	}
+
+free_and_exit:
+	/* Be sure to free the dev_list */
+	for(pos = head->next; pos != head;) {
+		cur = list_entry(pos, struct agp_3_0_dev, list);
+
+		pos = pos->next;
+		kfree(cur);
+	}
+	kfree(dev_list);
+
+get_out:
+	return ret;
+}
+
+/* 
+ * Entry point to AGP 3.0 host bridge init.  Check to see if we 
+ * have an AGP 3.0 device operating in 3.0 mode.  Call 
+ * agp_3_0_node_enable or agp_generic_agp_enable if we don't 
+ * (AGP 3.0 devices are required to operate as AGP 2.0 devices 
+ * when not using 3.0 electricals.
+ */
+int agp_generic_agp_3_0_enable(u32 mode)
+{
+	u32 ncapid, major, minor, agp_3_0;
+
+	pci_read_config_dword(agp_bridge.dev, agp_bridge.capndx, &ncapid);
+
+	major = (ncapid >> 20) & 0xf;
+	minor = (ncapid >> 16) & 0xf;
+
+	printk(KERN_INFO PFX "Found an AGP %d.%d compliant device.\n",
+		  major, minor);
+
+	if(major >= 3) {
+		pci_read_config_dword(agp_bridge.dev, agp_bridge.capndx + 0x4, &agp_3_0);
+		/* 
+		 * Check to see if we are operating in 3.0 mode 
+		 */
+		if((agp_3_0 >> 3) & 0x1) {
+			agp_3_0_node_enable(mode, minor);
+			return TRUE;
+		}
+	}
+	return FALSE;
+}
+
+EXPORT_SYMBOL(agp_generic_agp_3_0_enable);
+
diff -Nru a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
--- a/drivers/char/agp/generic.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/char/agp/generic.c	Mon Dec 23 21:21:53 2002
@@ -469,7 +469,7 @@
 	for (page = virt_to_page(table); page <= virt_to_page(table_end); page++)
 		SetPageReserved(page);
 
-	agp_bridge.gatt_table_real = (u32 *) table;
+	agp_bridge.gatt_table_real = (unsigned long *) table;
 	agp_gatt_table = (void *)table; 
 	CACHE_FLUSH();
 	agp_bridge.gatt_table = ioremap_nocache(virt_to_phys(table),
@@ -693,7 +693,23 @@
 EXPORT_SYMBOL(agp_free_memory);
 EXPORT_SYMBOL(agp_allocate_memory);
 EXPORT_SYMBOL(agp_copy_info);
+EXPORT_SYMBOL(agp_create_memory);
 EXPORT_SYMBOL(agp_bind_memory);
 EXPORT_SYMBOL(agp_unbind_memory);
+EXPORT_SYMBOL(agp_free_key);
 EXPORT_SYMBOL(agp_enable);
+EXPORT_SYMBOL(agp_bridge);
+
+EXPORT_SYMBOL(agp_generic_alloc_page);
+EXPORT_SYMBOL(agp_generic_destroy_page);
+EXPORT_SYMBOL(agp_generic_suspend);
+EXPORT_SYMBOL(agp_generic_resume);
+EXPORT_SYMBOL(agp_generic_agp_enable);
+EXPORT_SYMBOL(agp_generic_create_gatt_table);
+EXPORT_SYMBOL(agp_generic_free_gatt_table);
+EXPORT_SYMBOL(agp_generic_insert_memory);
+EXPORT_SYMBOL(agp_generic_remove_memory);
+EXPORT_SYMBOL(agp_generic_alloc_by_type);
+EXPORT_SYMBOL(agp_generic_free_by_type);
+EXPORT_SYMBOL(global_cache_flush);
 
diff -Nru a/drivers/char/agp/hp-agp.c b/drivers/char/agp/hp-agp.c
--- a/drivers/char/agp/hp-agp.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/char/agp/hp-agp.c	Mon Dec 23 21:21:59 2002
@@ -18,8 +18,7 @@
 #define HP_ZX1_SBA_IOMMU_COOKIE	0x0000badbadc0ffeeUL
 
 #define HP_ZX1_PDIR_VALID_BIT	0x8000000000000000UL
-#define HP_ZX1_IOVA_TO_PDIR(va)	((va - hp_private.iova_base) >> \
-					hp_private.io_tlb_shift)
+#define HP_ZX1_IOVA_TO_PDIR(va)	((va - hp_private.iova_base) >> hp_private.io_tlb_shift)
 
 static struct aper_size_info_fixed hp_zx1_sizes[] =
 {
@@ -217,8 +216,7 @@
 {
 	struct _hp_private *hp = &hp_private;
 
-	OUTREG64(hp->registers, HP_ZX1_PCOM, 
-		hp->gart_base | log2(hp->gart_size));
+	OUTREG64(hp->registers, HP_ZX1_PCOM, hp->gart_base | log2(hp->gart_size));
 	INREG64(hp->registers, HP_ZX1_PCOM);
 }
 
@@ -252,7 +250,7 @@
 static int hp_zx1_free_gatt_table(void)
 {
 	struct _hp_private *hp = &hp_private;
-	
+
 	if (hp->io_pdir_owner)
 		free_pages((unsigned long) hp->io_pdir,
 			    get_order(hp->io_pdir_size));
@@ -330,12 +328,7 @@
 	return HP_ZX1_PDIR_VALID_BIT | addr;
 }
 
-static unsigned long hp_zx1_unmask_memory(unsigned long addr)
-{
-	return addr & ~(HP_ZX1_PDIR_VALID_BIT);
-}
-
-int __init hp_zx1_setup (struct pci_dev *pdev)
+static int __init hp_zx1_setup (struct pci_dev *pdev __attribute__((unused)))
 {
 	agp_bridge.masks = hp_zx1_masks;
 	agp_bridge.num_of_masks = 1;
@@ -347,7 +340,6 @@
 	agp_bridge.cleanup = hp_zx1_cleanup;
 	agp_bridge.tlb_flush = hp_zx1_tlbflush;
 	agp_bridge.mask_memory = hp_zx1_mask_memory;
-	agp_bridge.unmask_memory = hp_zx1_unmask_memory;
 	agp_bridge.agp_enable = agp_generic_agp_enable;
 	agp_bridge.cache_flush = global_cache_flush;
 	agp_bridge.create_gatt_table = hp_zx1_create_gatt_table;
@@ -377,21 +369,20 @@
 	return -ENODEV;
 }
 
-
-static int agp_hp_probe (struct pci_dev *dev, const struct pci_device_id *ent)
+static int __init agp_hp_probe (struct pci_dev *dev, const struct pci_device_id *ent)
 {
 	if (agp_find_supported_device(dev) == 0) {
 		agp_register_driver(dev);
 		return 0;
 	}
-	return -ENODEV;	
+	return -ENODEV;
 }
 
 static struct pci_device_id agp_hp_pci_table[] __initdata = {
 	{
 	.class		= (PCI_CLASS_BRIDGE_HOST << 8),
 	.class_mask	= ~0,
-	.vendor_id	= PCI_VENDOR_ID_HP,
+	.vendor		= PCI_VENDOR_ID_HP,
 	.device		= PCI_DEVICE_ID_HP_ZX1_LBA,
 	.subvendor	= PCI_ANY_ID,
 	.subdevice	= PCI_ANY_ID,
@@ -401,7 +392,7 @@
 
 MODULE_DEVICE_TABLE(pci, agp_pci_table);
 
-static struct pci_driver agp_hp_pci_driver = {
+static struct __initdata pci_driver agp_hp_pci_driver = {
 	.name		= "agpgart-hp",
 	.id_table	= agp_hp_pci_table,
 	.probe		= agp_hp_probe,
@@ -421,7 +412,7 @@
 static void __exit agp_hp_cleanup(void)
 {
 	agp_unregister_driver();
-	pci_unregister_driver(&agp_pci_driver);
+	pci_unregister_driver(&agp_hp_pci_driver);
 }
 
 module_init(agp_hp_init);
diff -Nru a/drivers/char/agp/i460-agp.c b/drivers/char/agp/i460-agp.c
--- a/drivers/char/agp/i460-agp.c	Mon Dec 23 21:21:56 2002
+++ b/drivers/char/agp/i460-agp.c	Mon Dec 23 21:21:56 2002
@@ -1,47 +1,95 @@
 /*
- * FIXME: Nothing ever calls this stuff!
+ * For documentation on the i460 AGP interface, see Chapter 7 (AGP Subsystem) of
+ * the "Intel 460GTX Chipset Software Developer's Manual":
+ * http://developer.intel.com/design/itanium/downloads/24870401s.htm
+ */
+/*
+ * 460GX support by Chris Ahna <christopher.j.ahna@intel.com>
+ * Clean up & simplification by David Mosberger-Tang <davidm@hpl.hp.com>
  */
-
 #include <linux/module.h>
 #include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/agp_backend.h>
-#include "agp.h"
 
-/* BIOS configures the chipset so that one of two apbase registers are used */
-static u8 intel_i460_dynamic_apbase = 0x10;
+#include "agp.h"
 
-/* 460 supports multiple GART page sizes, so GART pageshift is dynamic */
-static u8 intel_i460_pageshift = 12;
-static u32 intel_i460_pagesize;
-
-/* Keep track of which is larger, chipset or kernel page size. */
-static u32 intel_i460_cpk = 1;
-
-/* Structure for tracking partial use of 4MB GART pages */
-static u32 **i460_pg_detail = NULL;
-static u32 *i460_pg_count = NULL;
+/*
+ * The i460 can operate with large (4MB) pages, but there is no sane way to support this
+ * within the current kernel/DRM environment, so we disable the relevant code for now.
+ * See also comments in ia64_alloc_page()...
+ */
+#define I460_LARGE_IO_PAGES		0
 
-#define I460_CPAGES_PER_KPAGE (PAGE_SIZE >> intel_i460_pageshift)
-#define I460_KPAGES_PER_CPAGE ((1 << intel_i460_pageshift) >> PAGE_SHIFT)
+#if I460_LARGE_IO_PAGES
+# define I460_IO_PAGE_SHIFT		i460.io_page_shift
+#else
+# define I460_IO_PAGE_SHIFT		12
+#endif
 
+#define I460_IOPAGES_PER_KPAGE		(PAGE_SIZE >> I460_IO_PAGE_SHIFT)
+#define I460_KPAGES_PER_IOPAGE		(1 << (I460_IO_PAGE_SHIFT - PAGE_SHIFT))
 #define I460_SRAM_IO_DISABLE		(1 << 4)
 #define I460_BAPBASE_ENABLE		(1 << 3)
 #define I460_AGPSIZ_MASK		0x7
 #define I460_4M_PS			(1 << 1)
 
-#define log2(x)				ffz(~(x))
+/* Control bits for Out-Of-GART coherency and Burst Write Combining */
+#define I460_GXBCTL_OOG		(1UL << 0)
+#define I460_GXBCTL_BWC		(1UL << 2)
+
+/*
+ * gatt_table entries are 32-bits wide on the i460; the generic code ought to declare the
+ * gatt_table and gatt_table_real pointers a "void *"...
+ */
+#define RD_GATT(index)		readl((u32 *) i460.gatt + (index))
+#define WR_GATT(index, val)	writel((val), (u32 *) i460.gatt + (index))
+/*
+ * The 460 spec says we have to read the last location written to make sure that all
+ * writes have taken effect
+ */
+#define WR_FLUSH_GATT(index)	RD_GATT(index)
+
+#define log2(x)			ffz(~(x))
+
+static struct {
+	void *gatt;				/* ioremap'd GATT area */
+
+	/* i460 supports multiple GART page sizes, so GART pageshift is dynamic: */
+	u8 io_page_shift;
+
+	/* BIOS configures chipset to one of 2 possible apbase values: */
+	u8 dynamic_apbase;
 
-static inline void intel_i460_read_back (volatile u32 *entry)
+	/* structure for tracking partial use of 4MB GART pages: */
+	struct lp_desc {
+		unsigned long *alloced_map;	/* bitmap of kernel-pages in use */
+		int refcount;			/* number of kernel pages using the large page */
+		u64 paddr;			/* physical address of large page */
+	} *lp_desc;
+} i460;
+
+static const struct aper_size_info_8 i460_sizes[3] =
 {
 	/*
-	 * The 460 spec says we have to read the last location written to
-	 * make sure that all writes have taken effect
+	 * The 32GB aperture is only available with a 4M GART page size.  Due to the
+	 * dynamic GART page size, we can't figure out page_order or num_entries until
+	 * runtime.
 	 */
-	*entry;
-}
+	{32768, 0, 0, 4},
+	{1024, 0, 0, 2},
+	{256, 0, 0, 1}
+};
 
-static int intel_i460_fetch_size(void)
+static struct gatt_mask i460_masks[] =
+{
+	{
+	  .mask = INTEL_I460_GATT_VALID | INTEL_I460_GATT_COHERENT,
+	  .type = 0
+	}
+};
+
+static int i460_fetch_size (void)
 {
 	int i;
 	u8 temp;
@@ -49,8 +97,15 @@
 
 	/* Determine the GART page size */
 	pci_read_config_byte(agp_bridge.dev, INTEL_I460_GXBCTL, &temp);
-	intel_i460_pageshift = (temp & I460_4M_PS) ? 22 : 12;
-	intel_i460_pagesize = 1UL << intel_i460_pageshift;
+	i460.io_page_shift = (temp & I460_4M_PS) ? 22 : 12;
+	pr_debug("i460_fetch_size: io_page_shift=%d\n", i460.io_page_shift);
+
+	if (i460.io_page_shift != I460_IO_PAGE_SHIFT) {
+		printk(KERN_ERR PFX
+		       "I/O (GART) page-size %ZuKB doesn't match expected size %ZuKB\n",
+		       1UL << (i460.io_page_shift - 10), 1UL << (I460_IO_PAGE_SHIFT));
+		return 0;
+	}
 
 	values = A_SIZE_8(agp_bridge.aperture_sizes);
 
@@ -64,16 +119,16 @@
 	}
 
 	/* Make sure we don't try to create an 2 ^ 23 entry GATT */
-	if ((intel_i460_pageshift == 0) && ((temp & I460_AGPSIZ_MASK) == 4)) {
+	if ((i460.io_page_shift == 0) && ((temp & I460_AGPSIZ_MASK) == 4)) {
 		printk(KERN_ERR PFX "We can't have a 32GB aperture with 4KB GART pages\n");
 		return 0;
 	}
 
 	/* Determine the proper APBASE register */
 	if (temp & I460_BAPBASE_ENABLE)
-		intel_i460_dynamic_apbase = INTEL_I460_BAPBASE;
+		i460.dynamic_apbase = INTEL_I460_BAPBASE;
 	else
-		intel_i460_dynamic_apbase = INTEL_I460_APBASE;
+		i460.dynamic_apbase = INTEL_I460_APBASE;
 
 	for (i = 0; i < agp_bridge.num_aperture_sizes; i++) {
 		/*
@@ -81,7 +136,7 @@
 		 * the define aperture sizes. Take care not to shift off the end of
 		 * values[i].size.
 		 */
-		values[i].num_entries = (values[i].size << 8) >> (intel_i460_pageshift - 12);
+		values[i].num_entries = (values[i].size << 8) >> (I460_IO_PAGE_SHIFT - 12);
 		values[i].page_order = log2((sizeof(u32)*values[i].num_entries) >> PAGE_SHIFT);
 	}
 
@@ -98,7 +153,7 @@
 }
 
 /* There isn't anything to do here since 460 has no GART TLB. */
-static void intel_i460_tlb_flush(agp_memory * mem)
+static void i460_tlb_flush (agp_memory * mem)
 {
 	return;
 }
@@ -107,7 +162,7 @@
  * This utility function is needed to prevent corruption of the control bits
  * which are stored along with the aperture size in 460's AGPSIZ register
  */
-static void intel_i460_write_agpsiz(u8 size_value)
+static void i460_write_agpsiz (u8 size_value)
 {
 	u8 temp;
 
@@ -116,47 +171,39 @@
 			      ((temp & ~I460_AGPSIZ_MASK) | size_value));
 }
 
-static void intel_i460_cleanup(void)
+static void i460_cleanup (void)
 {
 	struct aper_size_info_8 *previous_size;
 
 	previous_size = A_SIZE_8(agp_bridge.previous_size);
-	intel_i460_write_agpsiz(previous_size->size_value);
+	i460_write_agpsiz(previous_size->size_value);
 
-	if (intel_i460_cpk == 0) {
-		vfree(i460_pg_detail);
-		vfree(i460_pg_count);
-	}
+	if (I460_IO_PAGE_SHIFT > PAGE_SHIFT)
+		kfree(i460.lp_desc);
 }
 
-
-/* Control bits for Out-Of-GART coherency and Burst Write Combining */
-#define I460_GXBCTL_OOG		(1UL << 0)
-#define I460_GXBCTL_BWC		(1UL << 2)
-
-static int intel_i460_configure(void)
+static int i460_configure (void)
 {
 	union {
 		u32 small[2];
 		u64 large;
 	} temp;
+	size_t size;
 	u8 scratch;
-	int i;
-
 	struct aper_size_info_8 *current_size;
 
 	temp.large = 0;
 
 	current_size = A_SIZE_8(agp_bridge.current_size);
-	intel_i460_write_agpsiz(current_size->size_value);
+	i460_write_agpsiz(current_size->size_value);
 
 	/*
 	 * Do the necessary rigmarole to read all eight bytes of APBASE.
 	 * This has to be done since the AGP aperture can be above 4GB on
 	 * 460 based systems.
 	 */
-	pci_read_config_dword(agp_bridge.dev, intel_i460_dynamic_apbase, &(temp.small[0]));
-	pci_read_config_dword(agp_bridge.dev, intel_i460_dynamic_apbase + 4, &(temp.small[1]));
+	pci_read_config_dword(agp_bridge.dev, i460.dynamic_apbase, &(temp.small[0]));
+	pci_read_config_dword(agp_bridge.dev, i460.dynamic_apbase + 4, &(temp.small[1]));
 
 	/* Clear BAR control bits */
 	agp_bridge.gart_bus_addr = temp.large & ~((1UL << 3) - 1);
@@ -166,459 +213,407 @@
 			      (scratch & 0x02) | I460_GXBCTL_OOG | I460_GXBCTL_BWC);
 
 	/*
-	 * Initialize partial allocation trackers if a GART page is bigger than
-	 * a kernel page.
+	 * Initialize partial allocation trackers if a GART page is bigger than a kernel
+	 * page.
 	 */
-	if (I460_CPAGES_PER_KPAGE >= 1) {
-		intel_i460_cpk = 1;
-	} else {
-		intel_i460_cpk = 0;
-
-		i460_pg_detail = vmalloc(sizeof(*i460_pg_detail) * current_size->num_entries);
-		i460_pg_count = vmalloc(sizeof(*i460_pg_count) * current_size->num_entries);
-
-		for (i = 0; i < current_size->num_entries; i++) {
-			i460_pg_count[i] = 0;
-			i460_pg_detail[i] = NULL;
-		}
+	if (I460_IO_PAGE_SHIFT > PAGE_SHIFT) {
+		size = current_size->num_entries * sizeof(i460.lp_desc[0]);
+		i460.lp_desc = kmalloc(size, GFP_KERNEL);
+		if (!i460.lp_desc)
+			return -ENOMEM;
+		memset(i460.lp_desc, 0, size);
 	}
 	return 0;
 }
 
-static int intel_i460_create_gatt_table(void)
+static int i460_create_gatt_table (void)
 {
-	char *table;
-	int i;
-	int page_order;
-	int num_entries;
+	int page_order, num_entries, i;
 	void *temp;
 
 	/*
-	 * Load up the fixed address of the GART SRAMS which hold our
-	 * GATT table.
+	 * Load up the fixed address of the GART SRAMS which hold our GATT table.
 	 */
-	table = (char *) __va(INTEL_I460_ATTBASE);
-
 	temp = agp_bridge.current_size;
 	page_order = A_SIZE_8(temp)->page_order;
 	num_entries = A_SIZE_8(temp)->num_entries;
 
-	agp_bridge.gatt_table_real = (u32 *) table;
-	agp_bridge.gatt_table = ioremap_nocache(virt_to_phys(table),
-						(PAGE_SIZE * (1 << page_order)));
-	agp_bridge.gatt_bus_addr = virt_to_phys(agp_bridge.gatt_table_real);
-
-	for (i = 0; i < num_entries; i++) {
-		agp_bridge.gatt_table[i] = 0;
-	}
+	i460.gatt = ioremap(INTEL_I460_ATTBASE, PAGE_SIZE << page_order);
 
-	intel_i460_read_back(agp_bridge.gatt_table + i - 1);
+	/* These are no good, the should be removed from the agp_bridge strucure... */
+	agp_bridge.gatt_table_real = NULL;
+	agp_bridge.gatt_table = NULL;
+	agp_bridge.gatt_bus_addr = 0;
+
+	for (i = 0; i < num_entries; ++i)
+		WR_GATT(i, 0);
+	WR_FLUSH_GATT(i - 1);
 	return 0;
 }
 
-static int intel_i460_free_gatt_table(void)
+static int i460_free_gatt_table (void)
 {
-	int num_entries;
-	int i;
+	int num_entries, i;
 	void *temp;
 
 	temp = agp_bridge.current_size;
 
 	num_entries = A_SIZE_8(temp)->num_entries;
 
-	for (i = 0; i < num_entries; i++) {
-		agp_bridge.gatt_table[i] = 0;
-	}
-
-	intel_i460_read_back(agp_bridge.gatt_table + i - 1);
+	for (i = 0; i < num_entries; ++i)
+		WR_GATT(i, 0);
+	WR_FLUSH_GATT(num_entries - 1);
 
-	iounmap(agp_bridge.gatt_table);
+	iounmap(i460.gatt);
 	return 0;
 }
 
-/* These functions are called when PAGE_SIZE exceeds the GART page size */
+/*
+ * The following functions are called when the I/O (GART) page size is smaller than
+ * PAGE_SIZE.
+ */
 
-static int intel_i460_insert_memory_cpk(agp_memory * mem, off_t pg_start, int type)
+static int i460_insert_memory_small_io_page (agp_memory *mem, off_t pg_start, int type)
 {
+	unsigned long paddr, io_pg_start, io_page_size;
 	int i, j, k, num_entries;
 	void *temp;
-	unsigned long paddr;
 
-	/*
-	 * The rest of the kernel will compute page offsets in terms of
-	 * PAGE_SIZE.
-	 */
-	pg_start = I460_CPAGES_PER_KPAGE * pg_start;
+	pr_debug("i460_insert_memory_small_io_page(mem=%p, pg_start=%ld, type=%d, paddr0=0x%lx)\n",
+		 mem, pg_start, type, mem->memory[0]);
+
+	io_pg_start = I460_IOPAGES_PER_KPAGE * pg_start;
 
 	temp = agp_bridge.current_size;
 	num_entries = A_SIZE_8(temp)->num_entries;
 
-	if ((pg_start + I460_CPAGES_PER_KPAGE * mem->page_count) > num_entries) {
+	if ((io_pg_start + I460_IOPAGES_PER_KPAGE * mem->page_count) > num_entries) {
 		printk(KERN_ERR PFX "Looks like we're out of AGP memory\n");
 		return -EINVAL;
 	}
 
-	j = pg_start;
-	while (j < (pg_start + I460_CPAGES_PER_KPAGE * mem->page_count)) {
-		if (!PGE_EMPTY(agp_bridge.gatt_table[j])) {
+	j = io_pg_start;
+	while (j < (io_pg_start + I460_IOPAGES_PER_KPAGE * mem->page_count)) {
+		if (!PGE_EMPTY(RD_GATT(j))) {
+			pr_debug("i460_insert_memory_small_io_page: GATT[%d]=0x%x is busy\n",
+				 j, RD_GATT(j));
 			return -EBUSY;
 		}
 		j++;
 	}
 
-#if 0
-	/* not necessary since 460 GART is operated in coherent mode... */
-	if (mem->is_flushed == FALSE) {
-		CACHE_FLUSH();
-		mem->is_flushed = TRUE;
-	}
-#endif
-
-	for (i = 0, j = pg_start; i < mem->page_count; i++) {
+	io_page_size = 1UL << I460_IO_PAGE_SHIFT;
+	for (i = 0, j = io_pg_start; i < mem->page_count; i++) {
 		paddr = mem->memory[i];
-		for (k = 0; k < I460_CPAGES_PER_KPAGE; k++, j++, paddr += intel_i460_pagesize)
-			agp_bridge.gatt_table[j] = (u32) agp_bridge.mask_memory(paddr, mem->type);
+		for (k = 0; k < I460_IOPAGES_PER_KPAGE; k++, j++, paddr += io_page_size)
+			WR_GATT(j, agp_bridge.mask_memory(paddr, mem->type));
 	}
-
-	intel_i460_read_back(agp_bridge.gatt_table + j - 1);
+	WR_FLUSH_GATT(j - 1);
 	return 0;
 }
 
-static int intel_i460_remove_memory_cpk(agp_memory * mem, off_t pg_start, int type)
+static int i460_remove_memory_small_io_page(agp_memory * mem, off_t pg_start, int type)
 {
 	int i;
 
-	pg_start = I460_CPAGES_PER_KPAGE * pg_start;
+	pr_debug("i460_remove_memory_small_io_page(mem=%p, pg_start=%ld, type=%d)\n",
+		 mem, pg_start, type);
 
-	for (i = pg_start; i < (pg_start + I460_CPAGES_PER_KPAGE * mem->page_count); i++)
-		agp_bridge.gatt_table[i] = 0;
+	pg_start = I460_IOPAGES_PER_KPAGE * pg_start;
 
-	intel_i460_read_back(agp_bridge.gatt_table + i - 1);
+	for (i = pg_start; i < (pg_start + I460_IOPAGES_PER_KPAGE * mem->page_count); i++)
+		WR_GATT(i, 0);
+	WR_FLUSH_GATT(i - 1);
 	return 0;
 }
 
+#if I460_LARGE_IO_PAGES
+
 /*
- * These functions are called when the GART page size exceeds PAGE_SIZE.
+ * These functions are called when the I/O (GART) page size exceeds PAGE_SIZE.
  *
- * This situation is interesting since AGP memory allocations that are
- * smaller than a single GART page are possible.  The structures i460_pg_count
- * and i460_pg_detail track partial allocation of the large GART pages to
- * work around this issue.
+ * This situation is interesting since AGP memory allocations that are smaller than a
+ * single GART page are possible.  The i460.lp_desc array tracks partial allocation of the
+ * large GART pages to work around this issue.
  *
- * i460_pg_count[pg_num] tracks the number of kernel pages in use within
- * GART page pg_num.  i460_pg_detail[pg_num] is an array containing a
- * psuedo-GART entry for each of the aforementioned kernel pages.  The whole
- * of i460_pg_detail is equivalent to a giant GATT with page size equal to
- * that of the kernel.
+ * i460.lp_desc[pg_num].refcount tracks the number of kernel pages in use within GART page
+ * pg_num.  i460.lp_desc[pg_num].paddr is the physical address of the large page and
+ * i460.lp_desc[pg_num].alloced_map is a bitmap of kernel pages that are in use (allocated).
  */
 
-static void *intel_i460_alloc_large_page(int pg_num)
+static int i460_alloc_large_page (struct lp_desc *lp)
 {
-	int i;
-	void *bp, *bp_end;
-	struct page *page;
-
-	i460_pg_detail[pg_num] = (void *) vmalloc(sizeof(u32) * I460_KPAGES_PER_CPAGE);
-	if (i460_pg_detail[pg_num] == NULL) {
-		printk(KERN_ERR PFX "Out of memory, we're in trouble...\n");
-		return NULL;
-	}
-
-	for (i = 0; i < I460_KPAGES_PER_CPAGE; i++)
-		i460_pg_detail[pg_num][i] = 0;
+	unsigned long order = I460_IO_PAGE_SHIFT - PAGE_SHIFT;
+	size_t map_size;
+	void *lpage;
 
-	bp = (void *) __get_free_pages(GFP_KERNEL, intel_i460_pageshift - PAGE_SHIFT);
-	if (bp == NULL) {
+	lpage = (void *) __get_free_pages(GFP_KERNEL, order);
+	if (!lpage) {
 		printk(KERN_ERR PFX "Couldn't alloc 4M GART page...\n");
-		return NULL;
+		return -ENOMEM;
 	}
 
-	bp_end = bp + ((PAGE_SIZE * (1 << (intel_i460_pageshift - PAGE_SHIFT))) - 1);
-
-	for (page = virt_to_page(bp); page <= virt_to_page(bp_end); page++) {
-		atomic_inc(&agp_bridge.current_memory_agp);
+	map_size = ((I460_KPAGES_PER_IOPAGE + BITS_PER_LONG - 1) & -BITS_PER_LONG)/8;
+	lp->alloced_map = kmalloc(map_size, GFP_KERNEL);
+	if (!lp->alloced_map) {
+		free_pages((unsigned long) lpage, order);
+		printk(KERN_ERR PFX "Out of memory, we're in trouble...\n");
+		return -ENOMEM;
 	}
-	return bp;
+	memset(lp->alloced_map, 0, map_size);
+
+	lp->paddr = virt_to_phys(lpage);
+	lp->refcount = 0;
+	atomic_add(I460_KPAGES_PER_IOPAGE, &agp_bridge.current_memory_agp);
+	return 0;
 }
 
-static void intel_i460_free_large_page(int pg_num, unsigned long addr)
+static void i460_free_large_page (struct lp_desc *lp)
 {
-	struct page *page;
-	void *bp, *bp_end;
-
-	bp = (void *) __va(addr);
-	bp_end = bp + (PAGE_SIZE * (1 << (intel_i460_pageshift - PAGE_SHIFT)));
+	kfree(lp->alloced_map);
+	lp->alloced_map = NULL;
 
-	vfree(i460_pg_detail[pg_num]);
-	i460_pg_detail[pg_num] = NULL;
-
-	for (page = virt_to_page(bp); page < virt_to_page(bp_end); page++) {
-		atomic_dec(&agp_bridge.current_memory_agp);
-	}
-
-	free_pages((unsigned long) bp, intel_i460_pageshift - PAGE_SHIFT);
+	free_pages((unsigned long) phys_to_virt(lp->paddr), I460_IO_PAGE_SHIFT - PAGE_SHIFT);
+	atomic_sub(I460_KPAGES_PER_IOPAGE, &agp_bridge.current_memory_agp);
 }
 
-static int intel_i460_insert_memory_kpc(agp_memory * mem, off_t pg_start, int type)
+static int i460_insert_memory_large_io_page (agp_memory * mem, off_t pg_start, int type)
 {
-	int i, pg, start_pg, end_pg, start_offset, end_offset, idx;
-	int num_entries;
+	int i, start_offset, end_offset, idx, pg, num_entries;
+	struct lp_desc *start, *end, *lp;
 	void *temp;
-	unsigned long paddr;
 
 	temp = agp_bridge.current_size;
 	num_entries = A_SIZE_8(temp)->num_entries;
 
 	/* Figure out what pg_start means in terms of our large GART pages */
-	start_pg 	= pg_start / I460_KPAGES_PER_CPAGE;
-	start_offset 	= pg_start % I460_KPAGES_PER_CPAGE;
-	end_pg 		= (pg_start + mem->page_count - 1) / I460_KPAGES_PER_CPAGE;
-	end_offset 	= (pg_start + mem->page_count - 1) % I460_KPAGES_PER_CPAGE;
+	start	 	= &i460.lp_desc[pg_start / I460_KPAGES_PER_IOPAGE];
+	end 		= &i460.lp_desc[(pg_start + mem->page_count - 1) / I460_KPAGES_PER_IOPAGE];
+	start_offset 	= pg_start % I460_KPAGES_PER_IOPAGE;
+	end_offset 	= (pg_start + mem->page_count - 1) % I460_KPAGES_PER_IOPAGE;
 
-	if (end_pg > num_entries) {
+	if (end > i460.lp_desc + num_entries) {
 		printk(KERN_ERR PFX "Looks like we're out of AGP memory\n");
 		return -EINVAL;
 	}
 
 	/* Check if the requested region of the aperture is free */
-	for (pg = start_pg; pg <= end_pg; pg++) {
-		/* Allocate new GART pages if necessary */
-		if (i460_pg_detail[pg] == NULL) {
-			temp = intel_i460_alloc_large_page(pg);
-			if (temp == NULL)
-				return -ENOMEM;
-			agp_bridge.gatt_table[pg] = agp_bridge.mask_memory((unsigned long) temp,
-									   0);
-			intel_i460_read_back(agp_bridge.gatt_table + pg);
-		}
+	for (lp = start; lp <= end; ++lp) {
+		if (!lp->alloced_map)
+			continue;	/* OK, the entire large page is available... */
 
-		for (idx = ((pg == start_pg) ? start_offset : 0);
-		     idx < ((pg == end_pg) ? (end_offset + 1) : I460_KPAGES_PER_CPAGE);
+		for (idx = ((lp == start) ? start_offset : 0);
+		     idx < ((lp == end) ? (end_offset + 1) : I460_KPAGES_PER_IOPAGE);
 		     idx++)
 		{
-			if (i460_pg_detail[pg][idx] != 0)
+			if (test_bit(idx, lp->alloced_map))
 				return -EBUSY;
 		}
 	}
 
-#if 0
-	/* not necessary since 460 GART is operated in coherent mode... */
-	if (mem->is_flushed == FALSE) {
-		CACHE_FLUSH();
-		mem->is_flushed = TRUE;
-	}
-#endif
+	for (lp = start, i = 0; lp <= end; ++lp) {
+		if (!lp->alloced_map) {
+			/* Allocate new GART pages... */
+			if (i460_alloc_large_page(lp) < 0)
+				return -ENOMEM;
+			pg = lp - i460.lp_desc;
+			WR_GATT(pg, agp_bridge.mask_memory(lp->paddr, 0));
+			WR_FLUSH_GATT(pg);
+		}
 
-	for (pg = start_pg, i = 0; pg <= end_pg; pg++) {
-		paddr = agp_bridge.unmask_memory(agp_bridge.gatt_table[pg]);
-		for (idx = ((pg == start_pg) ? start_offset : 0);
-		     idx < ((pg == end_pg) ? (end_offset + 1) : I460_KPAGES_PER_CPAGE);
+		for (idx = ((lp == start) ? start_offset : 0);
+		     idx < ((lp == end) ? (end_offset + 1) : I460_KPAGES_PER_IOPAGE);
 		     idx++, i++)
 		{
-			mem->memory[i] = paddr + (idx * PAGE_SIZE);
-			i460_pg_detail[pg][idx] = agp_bridge.mask_memory(mem->memory[i],
-									 mem->type);
-			i460_pg_count[pg]++;
+			mem->memory[i] = lp->paddr + idx*PAGE_SIZE;
+			__set_bit(idx, lp->alloced_map);
+			++lp->refcount;
 		}
 	}
-
 	return 0;
 }
 
-static int intel_i460_remove_memory_kpc(agp_memory * mem, off_t pg_start, int type)
+static int i460_remove_memory_large_io_page (agp_memory * mem, off_t pg_start, int type)
 {
-	int i, pg, start_pg, end_pg, start_offset, end_offset, idx;
-	int num_entries;
+	int i, pg, start_offset, end_offset, idx, num_entries;
+	struct lp_desc *start, *end, *lp;
 	void *temp;
-	unsigned long paddr;
 
 	temp = agp_bridge.current_size;
 	num_entries = A_SIZE_8(temp)->num_entries;
 
 	/* Figure out what pg_start means in terms of our large GART pages */
-	start_pg 	= pg_start / I460_KPAGES_PER_CPAGE;
-	start_offset 	= pg_start % I460_KPAGES_PER_CPAGE;
-	end_pg 		= (pg_start + mem->page_count - 1) / I460_KPAGES_PER_CPAGE;
-	end_offset 	= (pg_start + mem->page_count - 1) % I460_KPAGES_PER_CPAGE;
-
-	for (i = 0, pg = start_pg; pg <= end_pg; pg++) {
-		for (idx = ((pg == start_pg) ? start_offset : 0);
-		    idx < ((pg == end_pg) ? (end_offset + 1) : I460_KPAGES_PER_CPAGE);
-		    idx++, i++)
+	start	 	= &i460.lp_desc[pg_start / I460_KPAGES_PER_IOPAGE];
+	end 		= &i460.lp_desc[(pg_start + mem->page_count - 1) / I460_KPAGES_PER_IOPAGE];
+	start_offset 	= pg_start % I460_KPAGES_PER_IOPAGE;
+	end_offset 	= (pg_start + mem->page_count - 1) % I460_KPAGES_PER_IOPAGE;
+
+	for (i = 0, lp = start; lp <= end; ++lp) {
+		for (idx = ((lp == start) ? start_offset : 0);
+		     idx < ((lp == end) ? (end_offset + 1) : I460_KPAGES_PER_IOPAGE);
+		     idx++, i++)
 		{
 			mem->memory[i] = 0;
-			i460_pg_detail[pg][idx] = 0;
-			i460_pg_count[pg]--;
+			__clear_bit(idx, lp->alloced_map);
+			--lp->refcount;
 		}
 
 		/* Free GART pages if they are unused */
-		if (i460_pg_count[pg] == 0) {
-			paddr = agp_bridge.unmask_memory(agp_bridge.gatt_table[pg]);
-			agp_bridge.gatt_table[pg] = agp_bridge.scratch_page;
-			intel_i460_read_back(agp_bridge.gatt_table + pg);
-			intel_i460_free_large_page(pg, paddr);
+		if (lp->refcount == 0) {
+			pg = lp - i460.lp_desc;
+			WR_GATT(pg, 0);
+			WR_FLUSH_GATT(pg);
+			i460_free_large_page(lp);
 		}
 	}
 	return 0;
 }
 
-/* Dummy routines to call the approriate {cpk,kpc} function */
+/* Wrapper routines to call the approriate {small_io_page,large_io_page} function */
 
-static int intel_i460_insert_memory(agp_memory * mem, off_t pg_start, int type)
+static int i460_insert_memory (agp_memory * mem, off_t pg_start, int type)
 {
-	if (intel_i460_cpk)
-		return intel_i460_insert_memory_cpk(mem, pg_start, type);
+	if (I460_IO_PAGE_SHIFT <= PAGE_SHIFT)
+		return i460_insert_memory_small_io_page(mem, pg_start, type);
 	else
-		return intel_i460_insert_memory_kpc(mem, pg_start, type);
+		return i460_insert_memory_large_io_page(mem, pg_start, type);
 }
 
-static int intel_i460_remove_memory(agp_memory * mem, off_t pg_start, int type)
+static int i460_remove_memory (agp_memory * mem, off_t pg_start, int type)
 {
-	if (intel_i460_cpk)
-		return intel_i460_remove_memory_cpk(mem, pg_start, type);
+	if (I460_IO_PAGE_SHIFT <= PAGE_SHIFT)
+		return i460_remove_memory_small_io_page(mem, pg_start, type);
 	else
-		return intel_i460_remove_memory_kpc(mem, pg_start, type);
+		return i460_remove_memory_large_io_page(mem, pg_start, type);
 }
 
 /*
- * If the kernel page size is smaller that the chipset page size, we don't
- * want to allocate memory until we know where it is to be bound in the
- * aperture (a multi-kernel-page alloc might fit inside of an already
- * allocated GART page).  Consequently, don't allocate or free anything
- * if i460_cpk (meaning chipset pages per kernel page) isn't set.
+ * If the I/O (GART) page size is bigger than the kernel page size, we don't want to
+ * allocate memory until we know where it is to be bound in the aperture (a
+ * multi-kernel-page alloc might fit inside of an already allocated GART page).
  *
- * Let's just hope nobody counts on the allocated AGP memory being there
- * before bind time (I don't think current drivers do)...
+ * Let's just hope nobody counts on the allocated AGP memory being there before bind time
+ * (I don't think current drivers do)...
  */
-static void * intel_i460_alloc_page(void)
+static void *i460_alloc_page (void)
 {
-	if (intel_i460_cpk)
-		return agp_generic_alloc_page();
+	void *page;
 
-	/* Returning NULL would cause problems */
-	/* AK: really dubious code. */
-	return (void *)~0UL;
+	if (I460_IO_PAGE_SHIFT <= PAGE_SHIFT)
+		page = agp_generic_alloc_page();
+	else
+		/* Returning NULL would cause problems */
+		/* AK: really dubious code. */
+		page = (void *)~0UL;
+	return page;
 }
 
-static void intel_i460_destroy_page(void *page)
+static void i460_destroy_page (void *page)
 {
-	if (intel_i460_cpk)
+	if (I460_IO_PAGE_SHIFT <= PAGE_SHIFT)
 		agp_generic_destroy_page(page);
 }
 
-static struct gatt_mask intel_i460_masks[] =
-{
-	{
-	  .mask = INTEL_I460_GATT_VALID | INTEL_I460_GATT_COHERENT,
-	  .type = 0
-	}
-};
+#endif /* I460_LARGE_IO_PAGES */
 
-static unsigned long intel_i460_mask_memory(unsigned long addr, int type)
+static unsigned long i460_mask_memory (unsigned long addr, int type)
 {
 	/* Make sure the returned address is a valid GATT entry */
 	return (agp_bridge.masks[0].mask
-		| (((addr & ~((1 << intel_i460_pageshift) - 1)) & 0xffffff000) >> 12));
-}
-
-static unsigned long intel_i460_unmask_memory(unsigned long addr)
-{
-	/* Turn a GATT entry into a physical address */
-	return ((addr & 0xffffff) << 12);
+		| (((addr & ~((1 << I460_IO_PAGE_SHIFT) - 1)) & 0xffffff000) >> 12));
 }
 
-static struct aper_size_info_8 intel_i460_sizes[3] =
+static int __init intel_i460_setup (struct pci_dev *pdev __attribute__((unused)))
 {
-	/*
-	 * The 32GB aperture is only available with a 4M GART page size.
-	 * Due to the dynamic GART page size, we can't figure out page_order
-	 * or num_entries until runtime.
-	 */
-	{32768, 0, 0, 4},
-	{1024, 0, 0, 2},
-	{256, 0, 0, 1}
-};
-
-int __init intel_i460_setup (struct pci_dev *pdev __attribute__((unused)))
-{
-	agp_bridge.masks = intel_i460_masks;
-	agp_bridge.aperture_sizes = (void *) intel_i460_sizes;
+	agp_bridge.num_of_masks = 1;
+	agp_bridge.masks = i460_masks;
+	agp_bridge.aperture_sizes = (void *) i460_sizes;
 	agp_bridge.size_type = U8_APER_SIZE;
 	agp_bridge.num_aperture_sizes = 3;
 	agp_bridge.dev_private_data = NULL;
 	agp_bridge.needs_scratch_page = FALSE;
-	agp_bridge.configure = intel_i460_configure;
-	agp_bridge.fetch_size = intel_i460_fetch_size;
-	agp_bridge.cleanup = intel_i460_cleanup;
-	agp_bridge.tlb_flush = intel_i460_tlb_flush;
-	agp_bridge.mask_memory = intel_i460_mask_memory;
-	agp_bridge.unmask_memory = intel_i460_unmask_memory;
+	agp_bridge.configure = i460_configure;
+	agp_bridge.fetch_size = i460_fetch_size;
+	agp_bridge.cleanup = i460_cleanup;
+	agp_bridge.tlb_flush = i460_tlb_flush;
+	agp_bridge.mask_memory = i460_mask_memory;
 	agp_bridge.agp_enable = agp_generic_agp_enable;
 	agp_bridge.cache_flush = global_cache_flush;
-	agp_bridge.create_gatt_table = intel_i460_create_gatt_table;
-	agp_bridge.free_gatt_table = intel_i460_free_gatt_table;
-	agp_bridge.insert_memory = intel_i460_insert_memory;
-	agp_bridge.remove_memory = intel_i460_remove_memory;
+	agp_bridge.create_gatt_table = i460_create_gatt_table;
+	agp_bridge.free_gatt_table = i460_free_gatt_table;
+#if I460_LARGE_IO_PAGES
+	agp_bridge.insert_memory = i460_insert_memory;
+	agp_bridge.remove_memory = i460_remove_memory;
+	agp_bridge.agp_alloc_page = i460_alloc_page;
+	agp_bridge.agp_destroy_page = i460_destroy_page;
+#else
+	agp_bridge.insert_memory = i460_insert_memory_small_io_page;
+	agp_bridge.remove_memory = i460_remove_memory_small_io_page;
+	agp_bridge.agp_alloc_page = agp_generic_alloc_page;
+	agp_bridge.agp_destroy_page = agp_generic_destroy_page;
+#endif
 	agp_bridge.alloc_by_type = agp_generic_alloc_by_type;
 	agp_bridge.free_by_type = agp_generic_free_by_type;
-	agp_bridge.agp_alloc_page = intel_i460_alloc_page;
-	agp_bridge.agp_destroy_page = intel_i460_destroy_page;
 	agp_bridge.suspend = agp_generic_suspend;
 	agp_bridge.resume = agp_generic_resume;
 	agp_bridge.cant_use_aperture = 1;
 	return 0;
 }
 
-static int agp_intel_i460_probe (struct pci_dev *dev, const struct pci_device_id *ent)
+static int __init agp_intel_i460_probe (struct pci_dev *dev, const struct pci_device_id *ent)
 {
-	if (pci_find_capability(dev, PCI_CAP_ID_AGP)==0)
+	u8 cap_ptr = 0;
+
+	cap_ptr = pci_find_capability(dev, PCI_CAP_ID_AGP);
+	if (cap_ptr == 0)
 		return -ENODEV;
 
+	agp_bridge.dev = dev;
+	agp_bridge.capndx = cap_ptr;
 	intel_i460_setup(dev);
 	agp_register_driver(dev);
 	return 0;
 }
 
-static struct pci_device_id agp_i460_pci_table[] __initdata = {
+static struct pci_device_id agp_intel_i460_pci_table[] __initdata = {
 	{
 	.class		= (PCI_CLASS_BRIDGE_HOST << 8),
 	.class_mask	= ~0,
 	.vendor		= PCI_VENDOR_ID_INTEL,
-	.device		= PCI_DEVICE_ID_INTEL_460GX,
+	.device		= PCI_DEVICE_ID_INTEL_84460GX,
 	.subvendor	= PCI_ANY_ID,
 	.subdevice	= PCI_ANY_ID,
 	},
 	{ }
 };
 
-MODULE_DEVICE_TABLE(pci, agp_i460_pci_table);
+MODULE_DEVICE_TABLE(pci, agp_intel_i460_pci_table);
 
-static struct pci_driver agp_i460_pci_driver = {
+static struct __initdata pci_driver agp_intel_i460_pci_driver = {
 	.name		= "agpgart-intel-i460",
-	.id_table	= agp_i460_pci_table,
-	.probe		= agp_i460_probe,
+	.id_table	= agp_intel_i460_pci_table,
+	.probe		= agp_intel_i460_probe,
 };
 
-static int __init agp_i460_init(void)
+static int __init agp_intel_i460_init(void)
 {
 	int ret_val;
 
-	ret_val = pci_module_init(&agp_i460_pci_driver);
+	ret_val = pci_module_init(&agp_intel_i460_pci_driver);
 	if (ret_val)
 		agp_bridge.type = NOT_SUPPORTED;
 
 	return ret_val;
 }
 
-static void __exit agp_i460_cleanup(void)
+static void __exit agp_intel_i460_cleanup(void)
 {
 	agp_unregister_driver();
-	pci_unregister_driver(&agp_i460_pci_driver);
+	pci_unregister_driver(&agp_intel_i460_pci_driver);
 }
 
-module_init(agp_i460_init);
-module_exit(agp_i460_cleanup);
+module_init(agp_intel_i460_init);
+module_exit(agp_intel_i460_cleanup);
 
-MODULE_AUTHOR("Bjorn Helgaas <helgaas@fc.hp.com>");
+MODULE_AUTHOR("Chris Ahna <Christopher.J.Ahna@intel.com>");
 MODULE_LICENSE("GPL and additional rights");
-
diff -Nru a/drivers/char/agp/i7x05-agp.c b/drivers/char/agp/i7x05-agp.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/char/agp/i7x05-agp.c	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,231 @@
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/init.h>
+#include <linux/agp_backend.h>
+#include "agp.h"
+
+static int intel_7505_fetch_size(void)
+{
+	int i;
+	u16 tmp;
+	aper_size_info_16 *values;
+
+	/* 
+	 * For AGP 3.0 APSIZE is now 16 bits
+	 */
+	pci_read_config_word (agp_bridge.dev, INTEL_I7505_APSIZE, &tmp);
+	tmp = (tmp & 0xfff);
+	
+	values = A_SIZE_16(agp_bridge.aperture_sizes);
+
+	for (i=0; i < agp_bridge.num_aperture_sizes; i++) {
+		if (tmp == values[i].size_value) {
+			agp_bridge.previous_size = agp_bridge.current_size =
+					(void *)(values + i);
+			agp_bridge.aperture_size_idx = i;
+			return values[i].size;
+		}
+	}
+	return 0;
+}
+
+
+static void intel_7505_tlbflush(agp_memory *mem)
+{
+	u32 temp;
+	pci_read_config_dword(agp_bridge.dev, INTEL_I7505_AGPCTRL, &temp);
+	pci_write_config_dword(agp_bridge.dev, INTEL_I7505_AGPCTRL, temp & ~(1 << 7));
+	pci_read_config_dword(agp_bridge.dev, INTEL_I7505_AGPCTRL, &temp);
+	pci_write_config_dword(agp_bridge.dev, INTEL_I7505_AGPCTRL, temp | (1 << 7));
+}
+
+static void intel_7505_cleanup(void)
+{
+	aper_size_info_16 *previous_size;
+
+	previous_size = A_SIZE_16(agp_bridge.previous_size);
+	pci_write_config_byte(agp_bridge.dev, INTEL_I7505_APSIZE,
+			      previous_size->size_value);
+}
+
+
+static int intel_7505_configure(void)
+{
+	u32 temp;
+	aper_size_info_16 *current_size;
+	
+	current_size = A_SIZE_16(agp_bridge.current_size);
+
+	/* aperture size */
+	pci_write_config_word(agp_bridge.dev, INTEL_I7505_APSIZE,
+			      current_size->size_value);
+
+	/* address to map to */
+	pci_read_config_dword(agp_bridge.dev, INTEL_I7505_NAPBASELO, &temp);
+	agp_bridge.gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
+
+	/* attbase */ 
+	pci_write_config_dword(agp_bridge.dev, INTEL_I7505_ATTBASE,
+			       agp_bridge.gatt_bus_addr);
+
+	/* agpctrl */
+	pci_write_config_dword(agp_bridge.dev, INTEL_I7505_AGPCTRL, 0x0000);
+
+	/* clear error registers */
+	pci_write_config_byte(agp_bridge.dev, INTEL_I7505_ERRSTS, 0xff);
+	return 0;
+}
+
+static aper_size_info_16 intel_7505_sizes[7] =
+{
+	{256, 65536, 6, 0xf00},
+	{128, 32768, 5, 0xf20},
+	{64, 16384, 4, 0xf30},
+	{32, 8192, 3, 0xf38},
+	{16, 4096, 2, 0xf3c},
+	{8, 2048, 1, 0xf3e},
+	{4, 1024, 0, 0xf3f}
+};
+
+static void i7505_setup (u32 mode)
+{
+	if ((agp_generic_agp_3_0_enable)==FALSE)
+		agp_generic_agp_enable(mode);
+}
+
+static int __init intel_7505_setup (struct pci_dev *pdev)
+{
+	agp_bridge.masks = intel_generic_masks;
+	agp_bridge.num_of_masks = 1;
+	agp_bridge.aperture_sizes = (void *) intel_7505_sizes;
+	agp_bridge.size_type = U16_APER_SIZE;
+	agp_bridge.num_aperture_sizes = 7;
+	agp_bridge.dev_private_data = NULL;
+	agp_bridge.needs_scratch_page = FALSE;
+	agp_bridge.configure = intel_7505_configure;
+	agp_bridge.fetch_size = intel_7505_fetch_size;
+	agp_bridge.cleanup = intel_7505_cleanup;
+	agp_bridge.tlb_flush = intel_7505_tlbflush;
+	agp_bridge.mask_memory = intel_mask_memory;
+	agp_bridge.agp_enable = i7505_enable;
+	agp_bridge.cache_flush = global_cache_flush;
+	agp_bridge.create_gatt_table = agp_generic_create_gatt_table;
+	agp_bridge.free_gatt_table = agp_generic_free_gatt_table;
+	agp_bridge.insert_memory = agp_generic_insert_memory;
+	agp_bridge.remove_memory = agp_generic_remove_memory;
+	agp_bridge.alloc_by_type = agp_generic_alloc_by_type;
+	agp_bridge.free_by_type = agp_generic_free_by_type;
+	agp_bridge.agp_alloc_page = agp_generic_alloc_page;
+	agp_bridge.agp_destroy_page = agp_generic_destroy_page;
+	agp_bridge.suspend = agp_generic_suspend;
+	agp_bridge.resume = agp_generic_resume;
+	agp_bridge.cant_use_aperture = 0;
+	return 0;
+}
+
+struct agp_device_ids i7x05_agp_device_ids[] __initdata =
+{
+	{
+		.device_id	= PCI_DEVICE_ID_INTEL_7505_0,
+		.chipset	= INTEL_I7505,
+		.chipset_name	= "i7505",
+	},
+	{
+		.device_id	= PCI_DEVICE_ID_INTEL_7205_0,
+		.chipset	= INTEL_I7505,
+		.chipset_name	= "i7205",
+	},
+	{ }, /* dummy final entry, always present */
+};
+
+/* scan table above for supported devices */
+static int __init agp_lookup_host_bridge (struct pci_dev *pdev)
+{
+	int j=0;
+	struct agp_device_ids *devs;
+	
+	devs = i7x05_agp_device_ids;
+
+	while (devs[j].chipset_name != NULL) {
+		if (pdev->device == devs[j].device_id) {
+			printk (KERN_INFO PFX "Detected Intel %s chipset\n",
+				devs[j].chipset_name);
+			agp_bridge.type = devs[j].chipset;
+
+			if (devs[j].chipset_setup != NULL)
+				return devs[j].chipset_setup(pdev);
+			else
+				return intel_7505_setup(pdev);
+		}
+		j++;
+	}
+
+	printk(KERN_ERR PFX "Unsupported Intel chipset (device id: %04x),",
+		pdev->device);
+	return -ENODEV;
+}
+
+
+static int __init agp_i7x05_probe (struct pci_dev *dev, const struct pci_device_id *ent)
+{
+	u8 cap_ptr = 0;
+
+	cap_ptr = pci_find_capability(dev, PCI_CAP_ID_AGP);
+	if (cap_ptr == 0)
+		return -ENODEV;
+
+	if (agp_lookup_host_bridge(dev) != -ENODEV) {
+		agp_bridge.dev = dev;
+		agp_bridge.capndx = cap_ptr;
+		/* Fill in the mode register */
+		pci_read_config_dword(agp_bridge.dev, agp_bridge.capndx+4, &agp_bridge.mode)
+		agp_register_driver(dev);
+		return 0;
+	}
+	return -ENODEV;
+}
+
+
+static struct pci_device_id agp_i7x05_pci_table[] __initdata = {
+	{
+	.class		= (PCI_CLASS_BRIDGE_HOST << 8),
+	.class_mask	= ~0,
+	.vendor		= PCI_VENDOR_ID_INTEL,
+	.device		= PCI_ANY_ID,
+	.subvendor	= PCI_ANY_ID,
+	.subdevice	= PCI_ANY_ID,
+	},
+	{ }
+};
+
+MODULE_DEVICE_TABLE(pci, agp_i7x05_pci_table);
+
+static struct __initdata pci_driver agp_i7x05_pci_driver = {
+	.name		= "agpgart-i7x05",
+	.id_table	= agp_i7x05_pci_table,
+	.probe		= agp_i7x05_probe,
+};
+
+int __init agp_i7x05_init(void)
+{
+	int ret_val;
+
+	ret_val = pci_module_init(&agp_i7x05_pci_driver);
+	if (ret_val)
+		agp_bridge.type = NOT_SUPPORTED;
+
+	return ret_val;
+}
+
+static void __exit agp_i7x05_cleanup(void)
+{
+	agp_unregister_driver();
+	pci_unregister_driver(&agp_i7x05_pci_driver);
+}
+
+module_init(agp_i7x05_init);
+module_exit(agp_i7x05_cleanup);
+
+MODULE_AUTHOR("Matthew E Tolentino <matthew.e.tolentino@intel.com>");
+MODULE_LICENSE("GPL and additional rights");
+
diff -Nru a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
--- a/drivers/char/agp/intel-agp.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/char/agp/intel-agp.c	Mon Dec 23 21:21:55 2002
@@ -14,12 +14,12 @@
 static struct aper_size_info_fixed intel_i810_sizes[] =
 {
 	{64, 16384, 4},
-     /* The 32M mode still requires a 64k gatt */
+	/* The 32M mode still requires a 64k gatt */
 	{32, 8192, 4}
 };
 
-#define AGP_DCACHE_MEMORY 1
-#define AGP_PHYS_MEMORY   2
+#define AGP_DCACHE_MEMORY	1
+#define AGP_PHYS_MEMORY		2
 
 static struct gatt_mask intel_i810_masks[] =
 {
@@ -48,12 +48,12 @@
 	}
 	if ((smram_miscc & I810_GFX_MEM_WIN_SIZE) == I810_GFX_MEM_WIN_32M) {
 		agp_bridge.previous_size =
-		    agp_bridge.current_size = (void *) (values + 1);
+			agp_bridge.current_size = (void *) (values + 1);
 		agp_bridge.aperture_size_idx = 1;
 		return values[1].size;
 	} else {
 		agp_bridge.previous_size =
-		    agp_bridge.current_size = (void *) (values);
+			agp_bridge.current_size = (void *) (values);
 		agp_bridge.aperture_size_idx = 0;
 		return values[0].size;
 	}
@@ -72,11 +72,10 @@
 	pci_read_config_dword(intel_i810_private.i810_dev, I810_MMADDR, &temp);
 	temp &= 0xfff80000;
 
-	intel_i810_private.registers =
-	    (volatile u8 *) ioremap(temp, 128 * 4096);
+	intel_i810_private.registers = (volatile u8 *) ioremap(temp, 128 * 4096);
 
 	if ((INREG32(intel_i810_private.registers, I810_DRAM_CTL)
-	     & I810_DRAM_ROW_0) == I810_DRAM_ROW_0_SDRAM) {
+		& I810_DRAM_ROW_0) == I810_DRAM_ROW_0_SDRAM) {
 		/* This will need to be dynamically assigned */
 		printk(KERN_INFO PFX "detected 4MB dedicated video ram.\n");
 		intel_i810_private.num_dcache_entries = 1024;
@@ -114,7 +113,7 @@
 }
 
 static int intel_i810_insert_entries(agp_memory * mem, off_t pg_start,
-				     int type)
+				int type)
 {
 	int i, j, num_entries;
 	void *temp;
@@ -132,12 +131,10 @@
 	}
 
 	if (type != 0 || mem->type != 0) {
-		if ((type == AGP_DCACHE_MEMORY) &&
-		    (mem->type == AGP_DCACHE_MEMORY)) {
+		if ((type == AGP_DCACHE_MEMORY) && (mem->type == AGP_DCACHE_MEMORY)) {
 			/* special insert */
 			CACHE_FLUSH();
-			for (i = pg_start;
-			     i < (pg_start + mem->page_count); i++) {
+			for (i = pg_start; i < (pg_start + mem->page_count); i++) {
 				OUTREG32(intel_i810_private.registers,
 					 I810_PTE_BASE + (i * 4),
 					 (i * 4096) | I810_PTE_LOCAL |
@@ -147,15 +144,13 @@
 			agp_bridge.tlb_flush(mem);
 			return 0;
 		}
-	        if((type == AGP_PHYS_MEMORY) &&
-		   (mem->type == AGP_PHYS_MEMORY)) {
-		   goto insert;
-		}
+		if((type == AGP_PHYS_MEMORY) && (mem->type == AGP_PHYS_MEMORY))
+			goto insert;
 		return -EINVAL;
 	}
 
 insert:
-   	CACHE_FLUSH();
+	CACHE_FLUSH();
 	for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
 		OUTREG32(intel_i810_private.registers,
 			 I810_PTE_BASE + (j * 4), mem->memory[i]);
@@ -167,7 +162,7 @@
 }
 
 static int intel_i810_remove_entries(agp_memory * mem, off_t pg_start,
-				     int type)
+				int type)
 {
 	int i;
 
@@ -199,7 +194,7 @@
 		new->page_count = pg_count;
 		new->num_scratch_pages = 0;
 		vfree(new->memory);
-	   	MOD_INC_USE_COUNT;
+		MOD_INC_USE_COUNT;
 		return new;
 	}
 	if(type == AGP_PHYS_MEMORY) {
@@ -209,15 +204,14 @@
 		 * Xserver still writes to it through the agp
 		 * aperture
 		 */
-	   	if (pg_count != 1) {
-		   	return NULL;
-		}
-	   	new = agp_create_memory(1);
+		if (pg_count != 1)
+			return NULL;
 
-		if (new == NULL) {
+		new = agp_create_memory(1);
+		if (new == NULL)
 			return NULL;
-		}
-	   	MOD_INC_USE_COUNT;
+
+		MOD_INC_USE_COUNT;
 		addr = agp_bridge.agp_alloc_page();
 
 		if (addr == NULL) {
@@ -227,25 +221,23 @@
 		}
 		new->memory[0] = agp_bridge.mask_memory(virt_to_phys(addr), type);
 		new->page_count = 1;
-	   	new->num_scratch_pages = 1;
-	   	new->type = AGP_PHYS_MEMORY;
-	        new->physical = virt_to_phys((void *) new->memory[0]);
-	   	return new;
+		new->num_scratch_pages = 1;
+		new->type = AGP_PHYS_MEMORY;
+		new->physical = virt_to_phys((void *) new->memory[0]);
+		return new;
 	}
-   
 	return NULL;
 }
 
 static void intel_i810_free_by_type(agp_memory * curr)
 {
 	agp_free_key(curr->key);
-   	if(curr->type == AGP_PHYS_MEMORY) {
-	   	agp_bridge.agp_destroy_page(
-				 phys_to_virt(curr->memory[0]));
+	if(curr->type == AGP_PHYS_MEMORY) {
+		agp_bridge.agp_destroy_page(phys_to_virt(curr->memory[0]));
 		vfree(curr->memory);
 	}
 	kfree(curr);
-   	MOD_DEC_USE_COUNT;
+	MOD_DEC_USE_COUNT;
 }
 
 static unsigned long intel_i810_mask_memory(unsigned long addr, int type)
@@ -254,7 +246,7 @@
 	return addr | agp_bridge.masks[type].mask;
 }
 
-int __init intel_i810_setup(struct pci_dev *i810_dev)
+static int __init intel_i810_setup(struct pci_dev *i810_dev)
 {
 	intel_i810_private.i810_dev = i810_dev;
 
@@ -295,7 +287,7 @@
 };
 
 static struct _intel_i830_private {
-	struct pci_dev *i830_dev;   /* device one */
+	struct pci_dev *i830_dev;		/* device one */
 	volatile u8 *registers;
 	int gtt_entries;
 } intel_i830_private;
@@ -533,7 +525,7 @@
 	return(NULL);
 }
 
-int __init intel_i830_setup(struct pci_dev *i830_dev)
+static int __init intel_i830_setup(struct pci_dev *i830_dev)
 {
 	intel_i830_private.i830_dev = i830_dev;
 
@@ -581,8 +573,7 @@
 
 	for (i = 0; i < agp_bridge.num_aperture_sizes; i++) {
 		if (temp == values[i].size_value) {
-			agp_bridge.previous_size =
-			    agp_bridge.current_size = (void *) (values + i);
+			agp_bridge.previous_size = agp_bridge.current_size = (void *) (values + i);
 			agp_bridge.aperture_size_idx = i;
 			return values[i].size;
 		}
@@ -627,11 +618,11 @@
 
 static void intel_8xx_tlbflush(agp_memory * mem)
 {
-  u32 temp;
-  pci_read_config_dword(agp_bridge.dev, INTEL_AGPCTRL, &temp);
-  pci_write_config_dword(agp_bridge.dev, INTEL_AGPCTRL, temp & ~(1 << 7));
-  pci_read_config_dword(agp_bridge.dev, INTEL_AGPCTRL, &temp);
-  pci_write_config_dword(agp_bridge.dev, INTEL_AGPCTRL, temp | (1 << 7));
+	u32 temp;
+	pci_read_config_dword(agp_bridge.dev, INTEL_AGPCTRL, &temp);
+	pci_write_config_dword(agp_bridge.dev, INTEL_AGPCTRL, temp & ~(1 << 7));
+	pci_read_config_dword(agp_bridge.dev, INTEL_AGPCTRL, &temp);
+	pci_write_config_dword(agp_bridge.dev, INTEL_AGPCTRL, temp | (1 << 7));
 }
 
 
@@ -683,7 +674,7 @@
 	/* paccfg/nbxcfg */
 	pci_read_config_word(agp_bridge.dev, INTEL_NBXCFG, &temp2);
 	pci_write_config_word(agp_bridge.dev, INTEL_NBXCFG,
-			      (temp2 & ~(1 << 10)) | (1 << 9));
+			(temp2 & ~(1 << 10)) | (1 << 9));
 	/* clear any possible error conditions */
 	pci_write_config_byte(agp_bridge.dev, INTEL_ERRSTS + 1, 7);
 	return 0;
@@ -708,7 +699,7 @@
 	/* attbase - aperture base */
 	/* the Intel 815 chipset spec. says that bits 29-31 in the
 	* ATTBASE register are reserved -> try not to write them */
-	if (agp_bridge.gatt_bus_addr &  INTEL_815_ATTBASE_MASK)
+	if (agp_bridge.gatt_bus_addr & INTEL_815_ATTBASE_MASK)
 		panic("gatt bus addr too high");
 	pci_read_config_dword(agp_bridge.dev, INTEL_ATTBASE, &addr);
 	addr &= INTEL_815_ATTBASE_MASK;
@@ -729,7 +720,7 @@
 
 static void intel_820_tlbflush(agp_memory * mem)
 {
-  return;
+	return;
 }
 
 static void intel_820_cleanup(void)
@@ -740,9 +731,9 @@
 	previous_size = A_SIZE_8(agp_bridge.previous_size);
 	pci_read_config_byte(agp_bridge.dev, INTEL_I820_RDCR, &temp);
 	pci_write_config_byte(agp_bridge.dev, INTEL_I820_RDCR, 
-			      temp & ~(1 << 1));
+			temp & ~(1 << 1));
 	pci_write_config_byte(agp_bridge.dev, INTEL_APSIZE,
-			      previous_size->size_value);
+			previous_size->size_value);
 }
 
 
@@ -974,10 +965,10 @@
 
 static struct aper_size_info_8 intel_830mp_sizes[4] = 
 {
-  {256, 65536, 6, 0},
-  {128, 32768, 5, 32},
-  {64, 16384, 4, 48},
-  {32, 8192, 3, 56}
+	{256, 65536, 6, 0},
+	{128, 32768, 5, 32},
+	{64, 16384, 4, 48},
+	{32, 8192, 3, 56}
 };
 
 static int __init intel_generic_setup (struct pci_dev *pdev)
@@ -1263,12 +1254,6 @@
 		.chipset_setup	= intel_830mp_setup
 	},
 	{
-		.device_id	= PCI_DEVICE_ID_INTEL_82845G_HB,
-		.chipset	= INTEL_I845_G,
-		.chipset_name	= "i845G",
-		.chipset_setup	= intel_830mp_setup
-	},
-	{
 		.device_id	= PCI_DEVICE_ID_INTEL_82840_HB,
 		.chipset	= INTEL_I840,
 		.chipset_name	= "i840",
@@ -1281,6 +1266,12 @@
 		.chipset_setup	= intel_845_setup
 	},
 	{
+		.device_id	= PCI_DEVICE_ID_INTEL_82845G_HB,
+		.chipset	= INTEL_I845_G,
+		.chipset_name	= "i845G",
+		.chipset_setup	= intel_845_setup
+	},
+	{
 		.device_id	= PCI_DEVICE_ID_INTEL_82850_HB,
 		.chipset	= INTEL_I850,
 		.chipset_name	= "i850",
@@ -1322,7 +1313,7 @@
 	/* try init anyway, if user requests it */
 	if (agp_try_unsupported) {
 		printk(KERN_WARNING PFX "Trying generic Intel routines"
-		       " for device id: %04x\n", pdev->device);
+			" for device id: %04x\n", pdev->device);
 		agp_bridge.type = INTEL_GENERIC;
 		return intel_generic_setup(pdev);
 	}
@@ -1338,6 +1329,7 @@
 static int __init agp_find_supported_device(struct pci_dev *dev)
 {
 	struct pci_dev *i810_dev;
+	u8 cap_ptr = 0;
 
 	agp_bridge.dev = dev;
 
@@ -1347,7 +1339,7 @@
 		i810_dev = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG1, NULL);
 		if (i810_dev == NULL) {
 			printk(KERN_ERR PFX "Detected an Intel i810,"
-			       " but could not find the secondary device.\n");
+				" but could not find the secondary device.\n");
 			return -ENODEV;
 		}
 		printk(KERN_INFO PFX "Detected an Intel i810 Chipset.\n");
@@ -1358,7 +1350,7 @@
 		i810_dev = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG3, NULL);
 		if (i810_dev == NULL) {
 			printk(KERN_ERR PFX "Detected an Intel i810 DC100, but could not find the "
-			       "secondary device.\n");
+				"secondary device.\n");
 			return -ENODEV;
 		}
 		printk(KERN_INFO PFX "Detected an Intel i810 DC100 Chipset.\n");
@@ -1369,7 +1361,7 @@
 		i810_dev = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810E_IG, NULL);
 		if (i810_dev == NULL) {
 			printk(KERN_ERR PFX "Detected an Intel i810 E"
-			    ", but could not find the secondary device.\n");
+				", but could not find the secondary device.\n");
 			return -ENODEV;
 		}
 		printk(KERN_INFO PFX "Detected an Intel i810 E Chipset.\n");
@@ -1377,11 +1369,11 @@
 		return intel_i810_setup(i810_dev);
 
 	 case PCI_DEVICE_ID_INTEL_82815_MC:
-	   /* The i815 can operate either as an i810 style
-	    * integrated device, or as an AGP4X motherboard.
-	    *
-	    * This only addresses the first mode:
-	    */
+		/* The i815 can operate either as an i810 style
+		 * integrated device, or as an AGP4X motherboard.
+		 *
+		 * This only addresses the first mode:
+		 */
 		i810_dev = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC, NULL);
 		if (i810_dev == NULL) {
 			printk(KERN_ERR PFX "agpgart: Detected an "
@@ -1413,7 +1405,7 @@
 		printk(KERN_INFO PFX "Detected an Intel 845G Chipset.\n");
 		agp_bridge.type = INTEL_I810;
 		return intel_i830_setup(i810_dev);
-		   
+
 	case PCI_DEVICE_ID_INTEL_82830_HB:
 		i810_dev = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82830_CGC, NULL);
 		if(i810_dev && PCI_FUNC(i810_dev->devfn) != 0)
@@ -1433,15 +1425,20 @@
 		break;
 	}
 
-	if (pci_find_capability(dev, PCI_CAP_ID_AGP)==0)
+	cap_ptr = pci_find_capability(dev, PCI_CAP_ID_AGP);
+	if (cap_ptr == 0)
 		return -ENODEV;
+	agp_bridge.capndx = cap_ptr;
+
+	/* Fill in the mode register */
+	pci_read_config_dword(agp_bridge.dev, agp_bridge.capndx+4, &agp_bridge.mode);
 
 	/* probe for known chipsets */
 	return agp_lookup_host_bridge(dev);
 }
 
 
-static int agp_intel_probe (struct pci_dev *dev, const struct pci_device_id *ent)
+static int __init agp_intel_probe (struct pci_dev *dev, const struct pci_device_id *ent)
 {
 	if (agp_find_supported_device(dev) == 0) {
 		agp_register_driver(dev);
@@ -1464,7 +1461,7 @@
 
 MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
 
-static struct pci_driver agp_intel_pci_driver = {
+static struct __initdata pci_driver agp_intel_pci_driver = {
 	.name		= "agpgart-intel",
 	.id_table	= agp_intel_pci_table,
 	.probe		= agp_intel_probe,
@@ -1473,6 +1470,11 @@
 static int __init agp_intel_init(void)
 {
 	int ret_val;
+	static int agp_initialised=0;
+
+	if (agp_initialised==1)
+		return 0;
+	agp_initialised=1;
 
 	ret_val = pci_module_init(&agp_intel_pci_driver);
 	if (ret_val)
@@ -1493,4 +1495,3 @@
 MODULE_PARM(agp_try_unsupported, "1i");
 MODULE_AUTHOR("Dave Jones <davej@codemonkey.org.uk>");
 MODULE_LICENSE("GPL and additional rights");
-
diff -Nru a/drivers/char/agp/sis-agp.c b/drivers/char/agp/sis-agp.c
--- a/drivers/char/agp/sis-agp.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/char/agp/sis-agp.c	Mon Dec 23 21:21:50 2002
@@ -86,7 +86,7 @@
 	{.mask = 0x00000000, .type = 0}
 };
 
-int __init sis_generic_setup (struct pci_dev *pdev)
+static int __init sis_generic_setup (struct pci_dev *pdev)
 {
 	agp_bridge.masks = sis_generic_masks;
 	agp_bridge.num_of_masks = 1;
@@ -223,25 +223,24 @@
 }
 
 
-static int __init agp_find_supported_device(struct pci_dev *dev)
+static int __init agp_sis_probe (struct pci_dev *dev, const struct pci_device_id *ent)
 {
-	agp_bridge.dev = dev;
+	u8 cap_ptr = 0;
 
-	if (pci_find_capability(dev, PCI_CAP_ID_AGP)==0)
+	cap_ptr = pci_find_capability(dev, PCI_CAP_ID_AGP);
+	if (cap_ptr == 0)
 		return -ENODEV;
 
 	/* probe for known chipsets */
-	return agp_lookup_host_bridge (dev);
-}
-
-
-static int agp_sis_probe (struct pci_dev *dev, const struct pci_device_id *ent)
-{
-	if (agp_find_supported_device(dev) == 0) {
+	if (agp_lookup_host_bridge(dev) != -ENODEV) {
+		agp_bridge.dev = dev;
+		agp_bridge.capndx = cap_ptr;
+		/* Fill in the mode register */
+		pci_read_config_dword(agp_bridge.dev, agp_bridge.capndx+4, &agp_bridge.mode);
 		agp_register_driver(dev);
 		return 0;
 	}
-	return -ENODEV;	
+	return -ENODEV;
 }
 
 static struct pci_device_id agp_sis_pci_table[] __initdata = {
@@ -258,13 +257,13 @@
 
 MODULE_DEVICE_TABLE(pci, agp_sis_pci_table);
 
-static struct pci_driver agp_sis_pci_driver = {
+static struct __initdata pci_driver agp_sis_pci_driver = {
 	.name		= "agpgart-sis",
 	.id_table	= agp_sis_pci_table,
 	.probe		= agp_sis_probe,
 };
 
-int __init agp_sis_init(void)
+static int __init agp_sis_init(void)
 {
 	int ret_val;
 
diff -Nru a/drivers/char/agp/sworks-agp.c b/drivers/char/agp/sworks-agp.c
--- a/drivers/char/agp/sworks-agp.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/char/agp/sworks-agp.c	Mon Dec 23 21:21:53 2002
@@ -169,9 +169,7 @@
 	 * used to program the agp master not the cpu
 	 */
 
-	pci_read_config_dword(agp_bridge.dev,
-			      serverworks_private.gart_addr_ofs,
-			      &temp);
+	pci_read_config_dword(agp_bridge.dev,serverworks_private.gart_addr_ofs,&temp);
 	agp_bridge.gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
 
 	/* Calculate the agp offset */	
@@ -206,18 +204,11 @@
 	struct aper_size_info_lvl2 *values;
 
 	values = A_SIZE_LVL2(agp_bridge.aperture_sizes);
-	pci_read_config_dword(agp_bridge.dev,
-			      serverworks_private.gart_addr_ofs,
-			      &temp);
-	pci_write_config_dword(agp_bridge.dev,
-			       serverworks_private.gart_addr_ofs,
-			       SVWRKS_SIZE_MASK);
-	pci_read_config_dword(agp_bridge.dev,
-			      serverworks_private.gart_addr_ofs,
-			      &temp2);
-	pci_write_config_dword(agp_bridge.dev,
-			       serverworks_private.gart_addr_ofs,
-			       temp);
+	pci_read_config_dword(agp_bridge.dev,serverworks_private.gart_addr_ofs,&temp);
+	pci_write_config_dword(agp_bridge.dev,serverworks_private.gart_addr_ofs,
+					SVWRKS_SIZE_MASK);
+	pci_read_config_dword(agp_bridge.dev,serverworks_private.gart_addr_ofs,&temp2);
+	pci_write_config_dword(agp_bridge.dev,serverworks_private.gart_addr_ofs,temp);
 	temp2 &= SVWRKS_SIZE_MASK;
 
 	for (i = 0; i < agp_bridge.num_aperture_sizes; i++) {
@@ -245,9 +236,7 @@
 	current_size = A_SIZE_LVL2(agp_bridge.current_size);
 
 	/* Get the memory mapped registers */
-	pci_read_config_dword(agp_bridge.dev,
-			      serverworks_private.mm_addr_ofs,
-			      &temp);
+	pci_read_config_dword(agp_bridge.dev, serverworks_private.mm_addr_ofs, &temp);
 	temp = (temp & PCI_BASE_ADDRESS_MEM_MASK);
 	serverworks_private.registers = (volatile u8 *) ioremap(temp, 4096);
 
@@ -269,7 +258,7 @@
 	agp_bridge.tlb_flush(NULL);
 
 	pci_read_config_byte(serverworks_private.svrwrks_dev, 0x34, &cap_ptr);
-	if (cap_ptr != 0x00) {
+	if (cap_ptr != 0) {
 		do {
 			pci_read_config_dword(serverworks_private.svrwrks_dev,
 					      cap_ptr, &cap_id);
@@ -277,30 +266,21 @@
 			if ((cap_id & 0xff) != 0x02)
 				cap_ptr = (cap_id >> 8) & 0xff;
 		}
-		while (((cap_id & 0xff) != 0x02) && (cap_ptr != 0x00));
+		while (((cap_id & 0xff) != 0x02) && (cap_ptr != 0));
 	}
 	agp_bridge.capndx = cap_ptr;
 
 	/* Fill in the mode register */
 	pci_read_config_dword(serverworks_private.svrwrks_dev,
-			      agp_bridge.capndx + 4,
-			      &agp_bridge.mode);
+			      agp_bridge.capndx+4, &agp_bridge.mode);
 
-	pci_read_config_byte(agp_bridge.dev,
-			     SVWRKS_CACHING,
-			     &enable_reg);
+	pci_read_config_byte(agp_bridge.dev, SVWRKS_CACHING, &enable_reg);
 	enable_reg &= ~0x3;
-	pci_write_config_byte(agp_bridge.dev,
-			      SVWRKS_CACHING,
-			      enable_reg);
-
-	pci_read_config_byte(agp_bridge.dev,
-			     SVWRKS_FEATURE,
-			     &enable_reg);
+	pci_write_config_byte(agp_bridge.dev, SVWRKS_CACHING, enable_reg);
+
+	pci_read_config_byte(agp_bridge.dev, SVWRKS_FEATURE, &enable_reg);
 	enable_reg |= (1<<6);
-	pci_write_config_byte(agp_bridge.dev,
-			      SVWRKS_FEATURE,
-			      enable_reg);
+	pci_write_config_byte(agp_bridge.dev,SVWRKS_FEATURE, enable_reg);
 
 	return 0;
 }
@@ -532,7 +512,7 @@
 	}
 }
 
-int __init serverworks_setup (struct pci_dev *pdev)
+static int __init serverworks_setup (struct pci_dev *pdev)
 {
 	u32 temp;
 	u32 temp2;
@@ -606,7 +586,6 @@
 static int __init agp_find_supported_device(struct pci_dev *dev)
 {
 	struct pci_dev *bridge_dev;
-	agp_bridge.dev = dev;
 
 	/* Everything is on func 1 here so we are hardcoding function one */
 	bridge_dev = pci_find_slot ((unsigned int)dev->bus->number, PCI_DEVFN(0, 1));
@@ -617,6 +596,8 @@
 		return -ENODEV;
 	}
 
+	agp_bridge.dev = dev;
+
 	switch (dev->device) {
 	case PCI_DEVICE_ID_SERVERWORKS_HE:
 		agp_bridge.type = SVWRKS_HE;
@@ -638,7 +619,7 @@
 }
 
 
-static int agp_serverworks_probe (struct pci_dev *dev, const struct pci_device_id *ent)
+static int __init agp_serverworks_probe (struct pci_dev *dev, const struct pci_device_id *ent)
 {
 	if (agp_find_supported_device(dev) == 0) {
 		agp_register_driver(dev);
@@ -661,7 +642,7 @@
 
 MODULE_DEVICE_TABLE(pci, agp_serverworks_pci_table);
 
-static struct pci_driver agp_serverworks_pci_driver = {
+static struct __initdata pci_driver agp_serverworks_pci_driver = {
 	.name		= "agpgart-serverworks",
 	.id_table	= agp_serverworks_pci_table,
 	.probe		= agp_serverworks_probe,
diff -Nru a/drivers/char/agp/via-agp.c b/drivers/char/agp/via-agp.c
--- a/drivers/char/agp/via-agp.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/char/agp/via-agp.c	Mon Dec 23 21:21:59 2002
@@ -94,7 +94,7 @@
 	{.mask = 0x00000000, .type = 0}
 };
 
-int __init via_generic_setup (struct pci_dev *pdev)
+static int __init via_generic_setup (struct pci_dev *pdev)
 {
 	agp_bridge.masks = via_generic_masks;
 	agp_bridge.num_of_masks = 1;
@@ -124,13 +124,69 @@
 	return 0;
 }
 
-struct agp_device_ids via_agp_device_ids[] __initdata =
+#ifdef CONFIG_AGP3
+/*
+ * The KT400 does magick to put the AGP bridge compliant with the same
+ * standards version as the graphics card. If we haven't fallen into
+ * 2.0 compatability mode, we run the normal 3.0 code, and fall back
+ * if something nasty happens.
+ */
+static void __init via_kt400_enable(u32 mode)
+{
+	if ((agp_generic_agp_3_0_enable(mode))==FALSE)
+		/* Something weird happened, fall back to 2.0 */
+		agp_generic_agp_enable(mode);
+}
+#endif
+
+static int __init via_kt400_setup(struct pci_dev *pdev)
+{
+	u8 reg;
+
+	agp_bridge.masks = via_generic_masks;
+	agp_bridge.num_of_masks = 1;
+	agp_bridge.aperture_sizes = (void *) via_generic_sizes;
+	agp_bridge.size_type = U8_APER_SIZE;
+	agp_bridge.num_aperture_sizes = 7;
+	agp_bridge.dev_private_data = NULL;
+	agp_bridge.needs_scratch_page = FALSE;
+	agp_bridge.configure = via_configure;
+	agp_bridge.fetch_size = via_fetch_size;
+	agp_bridge.cleanup = via_cleanup;
+	agp_bridge.tlb_flush = via_tlbflush;
+	agp_bridge.mask_memory = via_mask_memory;
+	agp_bridge.cache_flush = global_cache_flush;
+	agp_bridge.create_gatt_table = agp_generic_create_gatt_table;
+	agp_bridge.free_gatt_table = agp_generic_free_gatt_table;
+	agp_bridge.insert_memory = agp_generic_insert_memory;
+	agp_bridge.remove_memory = agp_generic_remove_memory;
+	agp_bridge.alloc_by_type = agp_generic_alloc_by_type;
+	agp_bridge.free_by_type = agp_generic_free_by_type;
+	agp_bridge.agp_alloc_page = agp_generic_alloc_page;
+	agp_bridge.agp_destroy_page = agp_generic_destroy_page;
+	agp_bridge.suspend = agp_generic_suspend;
+	agp_bridge.resume = agp_generic_resume;
+	agp_bridge.cant_use_aperture = 0;
+
+	pci_read_config_byte(agp_bridge.dev, VIA_AGPSEL, &reg);
+	if ((reg & (1<<1))==1) {
+		/* AGP 2.0 compatability mode. */
+		agp_bridge.agp_enable = agp_generic_agp_enable;
+
+	} else {
+#ifdef CONFIG_AGP3
+		/* AGP 3.0 mode */
+		agp_bridge.agp_enable = via_kt400_enable;
+#else
+		printk ("AGP: VIA KT400 in AGP3.0 mode support not compiled in.\n");
+		return -ENODEV;
+#endif
+	}
+	return 0;
+}
+
+static struct agp_device_ids via_agp_device_ids[] __initdata =
 {
-	{
-		.device_id	= PCI_DEVICE_ID_VIA_8501_0,
-		.chipset	= VIA_MVP4,
-		.chipset_name	= "MVP4",
-	},
 	{
 		.device_id	= PCI_DEVICE_ID_VIA_82C597_0,
 		.chipset	= VIA_VP3,
@@ -142,6 +198,11 @@
 		.chipset_name	= "MVP3",
 	},
 	{
+		.device_id	= PCI_DEVICE_ID_VIA_8501_0,
+		.chipset	= VIA_MVP4,
+		.chipset_name	= "MVP4",
+	},
+	{
 		.device_id	= PCI_DEVICE_ID_VIA_82C691,
 		.chipset	= VIA_APOLLO_PRO,
 		.chipset_name	= "Apollo Pro",
@@ -167,19 +228,21 @@
 		.chipset_name	= "Apollo Pro KT266",
 	},
 	{
+		.device_id	= PCI_DEVICE_ID_VIA_8653_0,
+		.chipset	= VIA_APOLLO_PRO,
+		.chipset_name	= "Apollo Pro 266T",
+	},
+	{
 		.device_id	= PCI_DEVICE_ID_VIA_8377_0,
 		.chipset	= VIA_APOLLO_KT400,
 		.chipset_name	= "Apollo Pro KT400",
+		.chipset_setup	= via_kt400_setup,
 	},
 	{
-		.device_id	= PCI_DEVICE_ID_VIA_8653_0,
-		.chipset	= VIA_APOLLO_PRO,
-		.chipset_name	= "Apollo Pro266T",
-	},
-	{
+		/* VIA ProSavage PM133 (Apollo Pro133A chipset with S3 Savage4) */
 		.device_id	= PCI_DEVICE_ID_VIA_82C694X_0,
 		.chipset	= VIA_VT8605,
-		.chipset_name	= "PM133"
+		.chipset_name	= "Apollo ProSavage PM133"
 	},
 	{ }, /* dummy final entry, always present */
 };
@@ -220,15 +283,20 @@
 }
 
 
-static int agp_via_probe (struct pci_dev *dev, const struct pci_device_id *ent)
+static int __init agp_via_probe (struct pci_dev *dev, const struct pci_device_id *ent)
 {
-	if (pci_find_capability(dev, PCI_CAP_ID_AGP)==0)
-		return -ENODEV;
+	u8 cap_ptr = 0;
 
-	agp_bridge.dev = dev;
+	cap_ptr = pci_find_capability(dev, PCI_CAP_ID_AGP);
+	if (cap_ptr == 0)
+		return -ENODEV;
 
 	/* probe for known chipsets */
 	if (agp_lookup_host_bridge (dev) != -ENODEV) {
+		agp_bridge.dev = dev;
+		agp_bridge.capndx = cap_ptr;
+		/* Fill in the mode register */
+		pci_read_config_dword(agp_bridge.dev, agp_bridge.capndx+4, &agp_bridge.mode);
 		agp_register_driver(dev);
 		return 0;
 	}
@@ -249,7 +317,7 @@
 
 MODULE_DEVICE_TABLE(pci, agp_via_pci_table);
 
-static struct pci_driver agp_via_pci_driver = {
+static struct __initdata pci_driver agp_via_pci_driver = {
 	.name		= "agpgart-via",
 	.id_table	= agp_via_pci_table,
 	.probe		= agp_via_probe,
diff -Nru a/drivers/char/drm/drm.h b/drivers/char/drm/drm.h
--- a/drivers/char/drm/drm.h	Mon Dec 23 21:21:52 2002
+++ b/drivers/char/drm/drm.h	Mon Dec 23 21:21:52 2002
@@ -346,17 +346,30 @@
 } drm_irq_busid_t;
 
 typedef enum {
-    _DRM_VBLANK_ABSOLUTE = 0x0,	/* Wait for specific vblank sequence number */
-    _DRM_VBLANK_RELATIVE = 0x1	/* Wait for given number of vblanks */
+    _DRM_VBLANK_ABSOLUTE = 0x0,		/* Wait for specific vblank sequence number */
+    _DRM_VBLANK_RELATIVE = 0x1,		/* Wait for given number of vblanks */
+    _DRM_VBLANK_SIGNAL   = 0x40000000	/* Send signal instead of blocking */
 } drm_vblank_seq_type_t;
 
-typedef struct drm_radeon_vbl_wait {
+#define _DRM_VBLANK_FLAGS_MASK _DRM_VBLANK_SIGNAL
+
+struct drm_wait_vblank_request {
+	drm_vblank_seq_type_t type;
+	unsigned int sequence;
+	unsigned long signal;
+};
+
+struct drm_wait_vblank_reply {
 	drm_vblank_seq_type_t type;
 	unsigned int sequence;
 	long tval_sec;
 	long tval_usec;
-} drm_wait_vblank_t;
+};
 
+typedef union drm_wait_vblank {
+	struct drm_wait_vblank_request request;
+	struct drm_wait_vblank_reply reply;
+} drm_wait_vblank_t;
 
 typedef struct drm_agp_mode {
 	unsigned long mode;
diff -Nru a/drivers/char/drm/drmP.h b/drivers/char/drm/drmP.h
--- a/drivers/char/drm/drmP.h	Mon Dec 23 21:21:58 2002
+++ b/drivers/char/drm/drmP.h	Mon Dec 23 21:21:58 2002
@@ -487,7 +487,6 @@
 
 typedef struct drm_agp_head {
 	agp_kern_info      agp_info;
-	const char         *chipset;
 	drm_agp_mem_t      *memory;
 	unsigned long      mode;
 	int                enabled;
@@ -517,6 +516,17 @@
 	drm_map_t		*map;
 } drm_map_list_t;
 
+#if __HAVE_VBL_IRQ
+
+typedef struct drm_vbl_sig {
+	struct list_head	head;
+	unsigned int		sequence;
+	struct siginfo		info;
+	struct task_struct	*task;
+} drm_vbl_sig_t;
+
+#endif
+
 typedef struct drm_device {
 	const char	  *name;	/* Simple driver name		   */
 	char		  *unique;	/* Unique identifier: e.g., busid  */
@@ -579,6 +589,8 @@
 #if __HAVE_VBL_IRQ
    	wait_queue_head_t vbl_queue;
    	atomic_t          vbl_received;
+	spinlock_t        vbl_lock;
+	drm_vbl_sig_t     vbl_sigs;
 #endif
 	cycles_t	  ctx_start;
 	cycles_t	  lck_start;
@@ -819,6 +831,7 @@
 extern int           DRM(wait_vblank)(struct inode *inode, struct file *filp,
 				      unsigned int cmd, unsigned long arg);
 extern int           DRM(vblank_wait)(drm_device_t *dev, unsigned int *vbl_seq);
+extern void          DRM(vbl_send_signals)( drm_device_t *dev );
 #endif
 #if __HAVE_DMA_IRQ_BH
 extern void          DRM(dma_immediate_bh)( void *dev );
diff -Nru a/drivers/char/drm/drm_agpsupport.h b/drivers/char/drm/drm_agpsupport.h
--- a/drivers/char/drm/drm_agpsupport.h	Mon Dec 23 21:21:50 2002
+++ b/drivers/char/drm/drm_agpsupport.h	Mon Dec 23 21:21:50 2002
@@ -260,64 +260,6 @@
 			return NULL;
 		}
 		head->memory = NULL;
-		switch (head->agp_info.chipset) {
-		case INTEL_GENERIC:	head->chipset = "Intel";         break;
-		case INTEL_LX:		head->chipset = "Intel 440LX";   break;
-		case INTEL_BX:		head->chipset = "Intel 440BX";   break;
-		case INTEL_GX:		head->chipset = "Intel 440GX";   break;
-		case INTEL_I810:	head->chipset = "Intel i810";    break;
-
-		case INTEL_I815:	head->chipset = "Intel i815";	 break;
-#if LINUX_VERSION_CODE >= 0x02040f /* KERNEL_VERSION(2,4,15) */
-	 	case INTEL_I820:	head->chipset = "Intel i820";	 break;
-#endif
-		case INTEL_I840:	head->chipset = "Intel i840";    break;
-#if LINUX_VERSION_CODE >= 0x02040f /* KERNEL_VERSION(2,4,15) */
-		case INTEL_I845:	head->chipset = "Intel i845";    break;
-#endif
-		case INTEL_I850:	head->chipset = "Intel i850";	 break;
-		case INTEL_460GX:	head->chipset = "Intel 460GX";	 break;
-
-		case VIA_GENERIC:	head->chipset = "VIA";           break;
-		case VIA_VP3:		head->chipset = "VIA VP3";       break;
-		case VIA_MVP3:		head->chipset = "VIA MVP3";      break;
-		case VIA_MVP4:		head->chipset = "VIA MVP4";      break;
-		case VIA_APOLLO_KX133:	head->chipset = "VIA Apollo KX133";
-			break;
-		case VIA_APOLLO_KT133:	head->chipset = "VIA Apollo KT133";
-			break;
-
-		case VIA_APOLLO_PRO: 	head->chipset = "VIA Apollo Pro";
-			break;
-		case SIS_GENERIC:	head->chipset = "SiS";           break;
-		case AMD_GENERIC:	head->chipset = "AMD";           break;
-		case AMD_IRONGATE:	head->chipset = "AMD Irongate";  break;
-		case ALI_GENERIC:	head->chipset = "ALi";           break;
-		case ALI_M1541: 	head->chipset = "ALi M1541";     break;
-
-#if LINUX_VERSION_CODE >= 0x020402
-		case ALI_M1621: 	head->chipset = "ALi M1621";	 break;
-		case ALI_M1631: 	head->chipset = "ALi M1631";	 break;
-		case ALI_M1632: 	head->chipset = "ALi M1632";	 break;
-		case ALI_M1641: 	head->chipset = "ALi M1641";	 break;
-		case ALI_M1644: 	head->chipset = "ALi M1644";	 break;
-		case ALI_M1647: 	head->chipset = "ALi M1647";	 break;
-		case ALI_M1651: 	head->chipset = "ALi M1651";	 break;
-#endif
-
-#if LINUX_VERSION_CODE >= 0x020406
-		case SVWRKS_HE: 	head->chipset = "Serverworks HE";
-			break;
-		case SVWRKS_LE: 	head->chipset = "Serverworks LE";
-			break;
-		case SVWRKS_GENERIC: 	head->chipset = "Serverworks Generic";
-			break;
-#endif
-
-		case HP_ZX1:		head->chipset = "HP ZX1";	 break;
-
-		default:		head->chipset = "Unknown";       break;
-		}
 #if LINUX_VERSION_CODE <= 0x020408
 		head->cant_use_aperture = 0;
 		head->page_mask = ~(0xfff);
@@ -325,13 +267,12 @@
 		head->cant_use_aperture = head->agp_info.cant_use_aperture;
 		head->page_mask = head->agp_info.page_mask;
 #endif
-
-		DRM_INFO("AGP %d.%d on %s @ 0x%08lx %ZuMB\n",
-			 head->agp_info.version.major,
-			 head->agp_info.version.minor,
-			 head->chipset,
-			 head->agp_info.aper_base,
-			 head->agp_info.aper_size);
+		
+		DRM_DEBUG("AGP %d.%d, aperture @ 0x%08lx %ZuMB\n",
+			  head->agp_info.version.major,
+			  head->agp_info.version.minor,
+			  head->agp_info.aper_base,
+			  head->agp_info.aper_size);
 	}
 	return head;
 }
diff -Nru a/drivers/char/drm/drm_dma.h b/drivers/char/drm/drm_dma.h
--- a/drivers/char/drm/drm_dma.h	Mon Dec 23 21:21:57 2002
+++ b/drivers/char/drm/drm_dma.h	Mon Dec 23 21:21:57 2002
@@ -537,6 +537,10 @@
 
 #if __HAVE_VBL_IRQ
 	init_waitqueue_head(&dev->vbl_queue);
+
+	spin_lock_init( &dev->vbl_lock );
+
+	INIT_LIST_HEAD( &dev->vbl_sigs.head );
 #endif
 
 				/* Before installing handler */
@@ -607,7 +611,8 @@
 	drm_device_t *dev = priv->dev;
 	drm_wait_vblank_t vblwait;
 	struct timeval now;
-	int ret;
+	int ret = 0;
+	unsigned int flags;
 
 	if (!dev->irq)
 		return -EINVAL;
@@ -615,20 +620,77 @@
 	DRM_COPY_FROM_USER_IOCTL( vblwait, (drm_wait_vblank_t *)data,
 				  sizeof(vblwait) );
 
-	if ( vblwait.type == _DRM_VBLANK_RELATIVE ) {
-		vblwait.sequence += atomic_read( &dev->vbl_received );
+	switch ( vblwait.request.type & ~_DRM_VBLANK_FLAGS_MASK ) {
+	case _DRM_VBLANK_RELATIVE:
+		vblwait.request.sequence += atomic_read( &dev->vbl_received );
+	case _DRM_VBLANK_ABSOLUTE:
+		break;
+	default:
+		return -EINVAL;
 	}
 
-	ret = DRM(vblank_wait)( dev, &vblwait.sequence );
+	flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK;
+	
+	if ( flags & _DRM_VBLANK_SIGNAL ) {
+		unsigned long irqflags;
+		drm_vbl_sig_t *vbl_sig = DRM_MALLOC( sizeof( drm_vbl_sig_t ) );
+
+		if ( !vbl_sig )
+			return -ENOMEM;
+
+		memset( (void *)vbl_sig, 0, sizeof(*vbl_sig) );
 
-	do_gettimeofday( &now );
-	vblwait.tval_sec = now.tv_sec;
-	vblwait.tval_usec = now.tv_usec;
+		vbl_sig->sequence = vblwait.request.sequence;
+		vbl_sig->info.si_signo = vblwait.request.signal;
+		vbl_sig->task = current;
+
+		vblwait.reply.sequence = atomic_read( &dev->vbl_received );
+
+		/* Hook signal entry into list */
+		spin_lock_irqsave( &dev->vbl_lock, irqflags );
+
+		list_add_tail( (struct list_head *) vbl_sig, &dev->vbl_sigs.head );
+
+		spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
+	} else {
+		ret = DRM(vblank_wait)( dev, &vblwait.request.sequence );
+
+		do_gettimeofday( &now );
+		vblwait.reply.tval_sec = now.tv_sec;
+		vblwait.reply.tval_usec = now.tv_usec;
+	}
 
 	DRM_COPY_TO_USER_IOCTL( (drm_wait_vblank_t *)data, vblwait,
 				sizeof(vblwait) );
 
 	return ret;
+}
+
+void DRM(vbl_send_signals)( drm_device_t *dev )
+{
+	struct list_head *entry, *tmp;
+	drm_vbl_sig_t *vbl_sig;
+	unsigned int vbl_seq = atomic_read( &dev->vbl_received );
+	unsigned long flags;
+
+	spin_lock_irqsave( &dev->vbl_lock, flags );
+
+	list_for_each_safe( entry, tmp, &dev->vbl_sigs.head ) {
+
+		vbl_sig = (drm_vbl_sig_t *) entry;
+
+		if ( ( vbl_seq - vbl_sig->sequence ) <= (1<<23) ) {
+
+			vbl_sig->info.si_code = atomic_read( &dev->vbl_received );
+			send_sig_info( vbl_sig->info.si_signo, &vbl_sig->info, vbl_sig->task );
+
+			list_del( entry );
+
+			DRM_FREE( entry );
+		}
+	}
+
+	spin_unlock_irqrestore( &dev->vbl_lock, flags );
 }
 
 #endif	/* __HAVE_VBL_IRQ */
diff -Nru a/drivers/char/drm/drm_vm.h b/drivers/char/drm/drm_vm.h
--- a/drivers/char/drm/drm_vm.h	Mon Dec 23 21:22:02 2002
+++ b/drivers/char/drm/drm_vm.h	Mon Dec 23 21:22:02 2002
@@ -408,7 +408,7 @@
 
 	if (!capable(CAP_SYS_ADMIN) && (map->flags & _DRM_READ_ONLY)) {
 		vma->vm_flags &= VM_MAYWRITE;
-#if defined(__i386__)
+#if defined(__i386__) || defined(__x86_64__)
 		pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW;
 #else
 				/* Ye gads this is ugly.  With more thought
@@ -435,7 +435,7 @@
 	case _DRM_FRAME_BUFFER:
 	case _DRM_REGISTERS:
 		if (VM_OFFSET(vma) >= __pa(high_memory)) {
-#if defined(__i386__)
+#if defined(__i386__) || defined(__x86_64__)
 			if (boot_cpu_data.x86 > 3 && map->type != _DRM_AGP) {
 				pgprot_val(vma->vm_page_prot) |= _PAGE_PCD;
 				pgprot_val(vma->vm_page_prot) &= ~_PAGE_PWT;
diff -Nru a/drivers/char/drm/mga_irq.c b/drivers/char/drm/mga_irq.c
--- a/drivers/char/drm/mga_irq.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/char/drm/mga_irq.c	Mon Dec 23 21:21:50 2002
@@ -50,6 +50,7 @@
 		MGA_WRITE( MGA_ICLEAR, MGA_VLINEICLR );
 		atomic_inc(&dev->vbl_received);
 		DRM_WAKEUP(&dev->vbl_queue);
+		DRM(vbl_send_signals)( dev );
 	}
 }
 
@@ -64,7 +65,7 @@
 	 */
 	DRM_WAIT_ON( ret, dev->vbl_queue, 3*DRM_HZ, 
 		     ( ( ( cur_vblank = atomic_read(&dev->vbl_received ) )
-			 + ~*sequence + 1 ) <= (1<<23) ) );
+			 - *sequence ) <= (1<<23) ) );
 
 	*sequence = cur_vblank;
 
diff -Nru a/drivers/char/drm/r128.h b/drivers/char/drm/r128.h
--- a/drivers/char/drm/r128.h	Mon Dec 23 21:21:53 2002
+++ b/drivers/char/drm/r128.h	Mon Dec 23 21:21:53 2002
@@ -71,7 +71,7 @@
    [DRM_IOCTL_NR(DRM_IOCTL_R128_DEPTH)]      = { r128_cce_depth,    1, 0 }, \
    [DRM_IOCTL_NR(DRM_IOCTL_R128_STIPPLE)]    = { r128_cce_stipple,  1, 0 }, \
    [DRM_IOCTL_NR(DRM_IOCTL_R128_INDIRECT)]   = { r128_cce_indirect, 1, 1 }, \
-   [DRM_IOCTL_NR(DRM_IOCTL_R128_GETPARAM)]   = { r128_getparam, 1, 1 },
+   [DRM_IOCTL_NR(DRM_IOCTL_R128_GETPARAM)]   = { r128_getparam, 1, 0 },
 
 /* Driver customization:
  */
diff -Nru a/drivers/char/drm/r128_irq.c b/drivers/char/drm/r128_irq.c
--- a/drivers/char/drm/r128_irq.c	Mon Dec 23 21:22:02 2002
+++ b/drivers/char/drm/r128_irq.c	Mon Dec 23 21:22:02 2002
@@ -50,6 +50,7 @@
 		R128_WRITE( R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK );
 		atomic_inc(&dev->vbl_received);
 		DRM_WAKEUP(&dev->vbl_queue);
+		DRM(vbl_send_signals)( dev );
 	}
 }
 
@@ -64,7 +65,7 @@
 	 */
 	DRM_WAIT_ON( ret, dev->vbl_queue, 3*DRM_HZ, 
 		     ( ( ( cur_vblank = atomic_read(&dev->vbl_received ) )
-			 + ~*sequence + 1 ) <= (1<<23) ) );
+			 - *sequence ) <= (1<<23) ) );
 
 	*sequence = cur_vblank;
 
diff -Nru a/drivers/char/drm/radeon_cp.c b/drivers/char/drm/radeon_cp.c
--- a/drivers/char/drm/radeon_cp.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/char/drm/radeon_cp.c	Mon Dec 23 21:21:51 2002
@@ -1497,7 +1497,7 @@
 		}
 	}
 
-	DRM_ERROR( "returning NULL!\n" );
+	DRM_DEBUG( "returning NULL!\n" );
 	return NULL;
 }
 #if 0
diff -Nru a/drivers/char/drm/radeon_irq.c b/drivers/char/drm/radeon_irq.c
--- a/drivers/char/drm/radeon_irq.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/char/drm/radeon_irq.c	Mon Dec 23 21:22:00 2002
@@ -70,13 +70,12 @@
 		DRM_WAKEUP( &dev_priv->swi_queue );
 	}
 
-#if __HAVE_VBL_IRQ
 	/* VBLANK interrupt */
 	if (stat & RADEON_CRTC_VBLANK_STAT) {
 		atomic_inc(&dev->vbl_received);
 		DRM_WAKEUP(&dev->vbl_queue);
+		DRM(vbl_send_signals)( dev );
 	}
-#endif
 
 	/* Acknowledge all the bits in GEN_INT_STATUS -- seem to get
 	 * more than we asked for...
@@ -138,7 +137,6 @@
 }
 
 
-#if __HAVE_VBL_IRQ
 int DRM(vblank_wait)(drm_device_t *dev, unsigned int *sequence)
 {
   	drm_radeon_private_t *dev_priv = 
@@ -161,13 +159,12 @@
 	 */
 	DRM_WAIT_ON( ret, dev->vbl_queue, 3*DRM_HZ, 
 		     ( ( ( cur_vblank = atomic_read(&dev->vbl_received ) )
-			 + ~*sequence + 1 ) <= (1<<23) ) );
+			 - *sequence ) <= (1<<23) ) );
 
 	*sequence = cur_vblank;
 
 	return ret;
 }
-#endif
 
 
 /* Needs the lock as it touches the ring.
diff -Nru a/drivers/char/drm/radeon_state.c b/drivers/char/drm/radeon_state.c
--- a/drivers/char/drm/radeon_state.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/char/drm/radeon_state.c	Mon Dec 23 21:21:59 2002
@@ -1074,19 +1074,30 @@
 	const u8 *data;
 	int size, dwords, tex_width, blit_width;
 	u32 y, height;
-	int ret = 0, i;
+	int i;
 	RING_LOCALS;
 
 	dev_priv->stats.boxes |= RADEON_BOX_TEXTURE_LOAD;
 
-	/* FIXME: Be smarter about this...
+	/* Flush the pixel cache.  This ensures no pixel data gets mixed
+	 * up with the texture data from the host data blit, otherwise
+	 * part of the texture image may be corrupted.
 	 */
-	buf = radeon_freelist_get( dev );
-	if ( !buf ) return DRM_ERR(EAGAIN);
+	BEGIN_RING( 4 );
+	RADEON_FLUSH_CACHE();
+	RADEON_WAIT_UNTIL_IDLE();
+	ADVANCE_RING();
+
+#ifdef __BIG_ENDIAN
+	/* The Mesa texture functions provide the data in little endian as the
+	 * chip wants it, but we need to compensate for the fact that the CP
+	 * ring gets byte-swapped
+	 */
+	BEGIN_RING( 2 );
+	OUT_RING_REG( RADEON_RBBM_GUICNTL, RADEON_HOST_DATA_SWAP_32BIT );
+	ADVANCE_RING();
+#endif
 
-	DRM_DEBUG( "tex: ofs=0x%x p=%d f=%d x=%hd y=%hd w=%hd h=%hd\n",
-		   tex->offset >> 10, tex->pitch, tex->format,
-		   image->x, image->y, image->width, image->height );
 
 	/* The compiler won't optimize away a division by a variable,
 	 * even if the only legal values are powers of two.  Thus, we'll
@@ -1120,127 +1131,113 @@
 		return DRM_ERR(EINVAL);
 	}
 
-	DRM_DEBUG( "   tex=%dx%d  blit=%d\n",
-		   tex_width, tex->height, blit_width );
+	DRM_DEBUG("tex=%dx%d blit=%d\n", tex_width, tex->height, blit_width );
 
-	/* Flush the pixel cache.  This ensures no pixel data gets mixed
-	 * up with the texture data from the host data blit, otherwise
-	 * part of the texture image may be corrupted.
-	 */
-	BEGIN_RING( 4 );
-
-	RADEON_FLUSH_CACHE();
-	RADEON_WAIT_UNTIL_IDLE();
-
-	ADVANCE_RING();
+	do {
+		DRM_DEBUG( "tex: ofs=0x%x p=%d f=%d x=%hd y=%hd w=%hd h=%hd\n",
+			   tex->offset >> 10, tex->pitch, tex->format,
+			   image->x, image->y, image->width, image->height );
 
-#ifdef __BIG_ENDIAN
-	/* The Mesa texture functions provide the data in little endian as the
-	 * chip wants it, but we need to compensate for the fact that the CP
-	 * ring gets byte-swapped
-	 */
-	BEGIN_RING( 2 );
-	OUT_RING_REG( RADEON_RBBM_GUICNTL, RADEON_HOST_DATA_SWAP_32BIT );
-	ADVANCE_RING();
-#endif
-
-	/* Make a copy of the parameters in case we have to update them
-	 * for a multi-pass texture blit.
-	 */
-	y = image->y;
-	height = image->height;
-	data = (const u8 *)image->data;
-
-	size = height * blit_width;
-
-	if ( size > RADEON_MAX_TEXTURE_SIZE ) {
-		/* Texture image is too large, do a multipass upload */
-		ret = DRM_ERR(EAGAIN);
-
-		/* Adjust the blit size to fit the indirect buffer */
-		height = RADEON_MAX_TEXTURE_SIZE / blit_width;
+		/* Make a copy of the parameters in case we have to
+		 * update them for a multi-pass texture blit.
+		 */
+		y = image->y;
+		height = image->height;
+		data = (const u8 *)image->data;
+		
 		size = height * blit_width;
 
+		if ( size > RADEON_MAX_TEXTURE_SIZE ) {
+			height = RADEON_MAX_TEXTURE_SIZE / blit_width;
+			size = height * blit_width;
+		} else if ( size < 4 && size > 0 ) {
+			size = 4;
+		} else if ( size == 0 ) {
+			return 0;
+		}
+
 		/* Update the input parameters for next time */
 		image->y += height;
 		image->height -= height;
-		image->data = (const char *)image->data + size;
+		image->data += size;
 
-		if ( DRM_COPY_TO_USER( tex->image, image, sizeof(*image) ) ) {
-			DRM_ERROR( "EFAULT on tex->image\n" );
-			return DRM_ERR(EFAULT);
+		buf = radeon_freelist_get( dev );
+		if ( 0 && !buf ) {
+			radeon_do_cp_idle( dev_priv );
+			buf = radeon_freelist_get( dev );
+		}
+		if ( !buf ) {
+			DRM_DEBUG("radeon_cp_dispatch_texture: EAGAIN\n");
+			DRM_COPY_TO_USER( tex->image, image, sizeof(*image) );
+			return DRM_ERR(EAGAIN);
 		}
-	} else if ( size < 4 && size > 0 ) {
-		size = 4;
-	}
-
-	dwords = size / 4;
 
-	/* Dispatch the indirect buffer.
-	 */
-	buffer = (u32 *)((char *)dev_priv->buffers->handle + buf->offset);
 
-	buffer[0] = CP_PACKET3( RADEON_CNTL_HOSTDATA_BLT, dwords + 6 );
-	buffer[1] = (RADEON_GMC_DST_PITCH_OFFSET_CNTL |
-		     RADEON_GMC_BRUSH_NONE |
-		     (format << 8) |
-		     RADEON_GMC_SRC_DATATYPE_COLOR |
-		     RADEON_ROP3_S |
-		     RADEON_DP_SRC_SOURCE_HOST_DATA |
-		     RADEON_GMC_CLR_CMP_CNTL_DIS |
-		     RADEON_GMC_WR_MSK_DIS);
-
-	buffer[2] = (tex->pitch << 22) | (tex->offset >> 10);
-	buffer[3] = 0xffffffff;
-	buffer[4] = 0xffffffff;
-	buffer[5] = (y << 16) | image->x;
-	buffer[6] = (height << 16) | image->width;
-	buffer[7] = dwords;
-
-	buffer += 8;
-
-	if ( tex_width >= 32 ) {
-		/* Texture image width is larger than the minimum, so we
-		 * can upload it directly.
+		/* Dispatch the indirect buffer.
 		 */
-		if ( DRM_COPY_FROM_USER( buffer, data, dwords * sizeof(u32) ) ) {
-			DRM_ERROR( "EFAULT on data, %d dwords\n", dwords );
-			return DRM_ERR(EFAULT);
-		}
-	} else {
-		/* Texture image width is less than the minimum, so we
-		 * need to pad out each image scanline to the minimum
-		 * width.
-		 */
-		for ( i = 0 ; i < tex->height ; i++ ) {
-			if ( DRM_COPY_FROM_USER( buffer, data, tex_width ) ) {
-				DRM_ERROR( "EFAULT on pad, %d bytes\n",
-					   tex_width );
+		buffer = (u32*)((char*)dev_priv->buffers->handle + buf->offset);
+		dwords = size / 4;
+		buffer[0] = CP_PACKET3( RADEON_CNTL_HOSTDATA_BLT, dwords + 6 );
+		buffer[1] = (RADEON_GMC_DST_PITCH_OFFSET_CNTL |
+			     RADEON_GMC_BRUSH_NONE |
+			     (format << 8) |
+			     RADEON_GMC_SRC_DATATYPE_COLOR |
+			     RADEON_ROP3_S |
+			     RADEON_DP_SRC_SOURCE_HOST_DATA |
+			     RADEON_GMC_CLR_CMP_CNTL_DIS |
+			     RADEON_GMC_WR_MSK_DIS);
+		
+		buffer[2] = (tex->pitch << 22) | (tex->offset >> 10);
+		buffer[3] = 0xffffffff;
+		buffer[4] = 0xffffffff;
+		buffer[5] = (y << 16) | image->x;
+		buffer[6] = (height << 16) | image->width;
+		buffer[7] = dwords;
+		buffer += 8;
+
+		if ( tex_width >= 32 ) {
+			/* Texture image width is larger than the minimum, so we
+			 * can upload it directly.
+			 */
+			if ( DRM_COPY_FROM_USER( buffer, data, 
+						 dwords * sizeof(u32) ) ) {
+				DRM_ERROR( "EFAULT on data, %d dwords\n", 
+					   dwords );
 				return DRM_ERR(EFAULT);
 			}
-			buffer += 8;
-			data += tex_width;
+		} else {
+			/* Texture image width is less than the minimum, so we
+			 * need to pad out each image scanline to the minimum
+			 * width.
+			 */
+			for ( i = 0 ; i < tex->height ; i++ ) {
+				if ( DRM_COPY_FROM_USER( buffer, data, 
+							 tex_width ) ) {
+					DRM_ERROR( "EFAULT on pad, %d bytes\n",
+						   tex_width );
+					return DRM_ERR(EFAULT);
+				}
+				buffer += 8;
+				data += tex_width;
+			}
 		}
-	}
 
-	buf->pid = DRM_CURRENTPID;
-	buf->used = (dwords + 8) * sizeof(u32);
+		buf->pid = DRM_CURRENTPID;
+		buf->used = (dwords + 8) * sizeof(u32);
+		radeon_cp_dispatch_indirect( dev, buf, 0, buf->used );
+		radeon_cp_discard_buffer( dev, buf );
 
-	radeon_cp_dispatch_indirect( dev, buf, 0, buf->used );
-	radeon_cp_discard_buffer( dev, buf );
+	} while (image->height > 0);
 
 	/* Flush the pixel cache after the blit completes.  This ensures
 	 * the texture data is written out to memory before rendering
 	 * continues.
 	 */
 	BEGIN_RING( 4 );
-
 	RADEON_FLUSH_CACHE();
 	RADEON_WAIT_UNTIL_2D_IDLE();
-
 	ADVANCE_RING();
-
-	return ret;
+	return 0;
 }
 
 
diff -Nru a/drivers/char/efirtc.c b/drivers/char/efirtc.c
--- a/drivers/char/efirtc.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/char/efirtc.c	Mon Dec 23 21:21:58 2002
@@ -40,7 +40,7 @@
 #include <asm/uaccess.h>
 #include <asm/system.h>
 
-#define EFI_RTC_VERSION		"0.3"
+#define EFI_RTC_VERSION		"0.4"
 
 #define EFI_ISDST (EFI_TIME_ADJUST_DAYLIGHT|EFI_TIME_IN_DAYLIGHT)
 /*
@@ -315,14 +315,14 @@
 	spin_unlock_irqrestore(&efi_rtc_lock,flags);
 
 	p += sprintf(p,
-		     "Time          : %u:%u:%u.%09u\n"
-		     "Date          : %u-%u-%u\n"
-		     "Daylight      : %u\n",
+		     "Time           : %u:%u:%u.%09u\n"
+		     "Date           : %u-%u-%u\n"
+		     "Daylight       : %u\n",
 		     eft.hour, eft.minute, eft.second, eft.nanosecond, 
 		     eft.year, eft.month, eft.day,
 		     eft.daylight);
 
-	if ( eft.timezone == EFI_UNSPECIFIED_TIMEZONE)
+	if (eft.timezone == EFI_UNSPECIFIED_TIMEZONE)
 		p += sprintf(p, "Timezone       : unspecified\n");
 	else
 		/* XXX fixme: convert to string? */
@@ -341,7 +341,7 @@
 		     enabled == 1 ? "yes" : "no",
 		     pending == 1 ? "yes" : "no");
 
-	if ( eft.timezone == EFI_UNSPECIFIED_TIMEZONE)
+	if (eft.timezone == EFI_UNSPECIFIED_TIMEZONE)
 		p += sprintf(p, "Timezone       : unspecified\n");
 	else
 		/* XXX fixme: convert to string? */
@@ -375,17 +375,25 @@
 static int __init 
 efi_rtc_init(void)
 {
-	int ret =0;
+	int ret;
+	struct proc_dir_entry *dir;
+
 	printk(KERN_INFO "EFI Time Services Driver v%s\n", EFI_RTC_VERSION);
 
 	ret = misc_register(&efi_rtc_dev);
 	if (ret) {
-		printk(KERN_ERR "driver/efirtc: can't misc_register on minor=%d\n", EFI_RTC_MINOR);
+		printk(KERN_ERR "efirtc: can't misc_register on minor=%d\n",
+				EFI_RTC_MINOR);
 		return ret;
 	}
 
-	create_proc_read_entry ("driver/efirtc", 0, NULL, efi_rtc_read_proc, NULL);
-
+	dir = create_proc_read_entry ("driver/efirtc", 0, NULL,
+			              efi_rtc_read_proc, NULL);
+	if (dir == NULL) {
+		printk(KERN_ERR "efirtc: can't create /proc/driver/efirtc.\n");
+		misc_deregister(&efi_rtc_dev);
+		return -1;
+	}
 	return 0;
 }
 
diff -Nru a/drivers/char/mem.c b/drivers/char/mem.c
--- a/drivers/char/mem.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/char/mem.c	Mon Dec 23 21:21:55 2002
@@ -619,7 +619,7 @@
 }
 
 static struct file_operations kmsg_fops = {
-	write:		kmsg_write,
+	.write =	kmsg_write,
 };
 
 static int memory_open(struct inode * inode, struct file * filp)
diff -Nru a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
--- a/drivers/i2c/i2c-core.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/i2c/i2c-core.c	Mon Dec 23 21:21:51 2002
@@ -622,7 +622,8 @@
 	struct inode * inode = file->f_dentry->d_inode;
 	char *kbuf;
 	struct i2c_client *client;
-	int i,j,k,order_nr,len=0,len_total;
+	int i,j,k,order_nr,len=0;
+	size_t len_total;
 	int order[I2C_CLIENT_MAX];
 #define OUTPUT_LENGTH_PER_LINE 70
 
diff -Nru a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
--- a/drivers/md/dm-ioctl.c	Mon Dec 23 21:21:52 2002
+++ b/drivers/md/dm-ioctl.c	Mon Dec 23 21:21:52 2002
@@ -986,6 +986,10 @@
 
 static int validate_params(uint cmd, struct dm_ioctl *param)
 {
+	/* Ignores parameters */
+	if (cmd == DM_REMOVE_ALL_CMD)
+		return 0;
+
 	/* Unless creating, either name of uuid but not both */
 	if (cmd != DM_DEV_CREATE_CMD) {
 		if ((!*param->uuid && !*param->name) ||
diff -Nru a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c
--- a/drivers/md/dm-linear.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/md/dm-linear.c	Mon Dec 23 21:21:55 2002
@@ -43,7 +43,7 @@
 		goto bad;
 	}
 
-	if (dm_get_device(ti, argv[0], ti->begin, ti->len,
+	if (dm_get_device(ti, argv[0], lc->start, ti->len,
 			  dm_table_get_mode(ti->table), &lc->dev)) {
 		ti->error = "dm-linear: Device lookup failed";
 		goto bad;
diff -Nru a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
--- a/drivers/md/dm-stripe.c	Mon Dec 23 21:21:54 2002
+++ b/drivers/md/dm-stripe.c	Mon Dec 23 21:21:54 2002
@@ -117,12 +117,29 @@
 		return -EINVAL;
 	}
 
+	/*
+	 * chunk_size is a power of two
+	 */
+	if (!chunk_size || (chunk_size & (chunk_size - 1))) {
+		ti->error = "dm-stripe: Invalid chunk size";
+		return -EINVAL;
+	}
+
 	if (!multiple(ti->len, stripes, &width)) {
 		ti->error = "dm-stripe: Target length not divisable by "
 		    "number of stripes";
 		return -EINVAL;
 	}
 
+	/*
+	 * Do we have enough arguments for that many stripes ?
+	 */
+	if (argc != (2 + 2 * stripes)) {
+		ti->error = "dm-stripe: Not enough destinations "
+			"specified";
+		return -EINVAL;
+	}
+
 	sc = alloc_context(stripes);
 	if (!sc) {
 		ti->error = "dm-stripe: Memory allocation for striped context "
@@ -134,15 +151,6 @@
 	sc->stripe_width = width;
 	ti->split_io = chunk_size;
 
-	/*
-	 * chunk_size is a power of two
-	 */
-	if (!chunk_size || (chunk_size & (chunk_size - 1))) {
-		ti->error = "dm-stripe: Invalid chunk size";
-		kfree(sc);
-		return -EINVAL;
-	}
-
 	sc->chunk_mask = ((sector_t) chunk_size) - 1;
 	for (sc->chunk_shift = 0; chunk_size; sc->chunk_shift++)
 		chunk_size >>= 1;
@@ -152,13 +160,6 @@
 	 * Get the stripe destinations.
 	 */
 	for (i = 0; i < stripes; i++) {
-		if (argc < 2) {
-			ti->error = "dm-stripe: Not enough destinations "
-				"specified";
-			kfree(sc);
-			return -EINVAL;
-		}
-
 		argv += 2;
 
 		r = get_stripe(ti, sc, i, argv);
diff -Nru a/drivers/md/dm-table.c b/drivers/md/dm-table.c
--- a/drivers/md/dm-table.c	Mon Dec 23 21:22:01 2002
+++ b/drivers/md/dm-table.c	Mon Dec 23 21:22:01 2002
@@ -312,7 +312,7 @@
 	}
 
 	if (!S_ISBLK(inode->i_mode)) {
-		r = -EINVAL;
+		r = -ENOTBLK;
 		goto out;
 	}
 
@@ -356,7 +356,7 @@
 		return -ENOMEM;
 
 	r = blkdev_get(d->bdev, d->mode, 0, BDEV_RAW);
-	if (!r)
+	if (r)
 		return r;
 
 	r = bd_claim(d->bdev, _claim_ptr);
@@ -388,7 +388,7 @@
 static int check_device_area(struct dm_dev *dd, sector_t start, sector_t len)
 {
 	sector_t dev_size;
-	dev_size = dd->bdev->bd_inode->i_size;
+	dev_size = dd->bdev->bd_inode->i_size >> SECTOR_SHIFT;
 	return ((start < dev_size) && (len <= (dev_size - start)));
 }
 
diff -Nru a/drivers/md/dm.c b/drivers/md/dm.c
--- a/drivers/md/dm.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/md/dm.c	Mon Dec 23 21:21:59 2002
@@ -16,7 +16,6 @@
 
 static const char *_name = DM_NAME;
 #define MAX_DEVICES (1 << KDEV_MINOR_BITS)
-#define SECTOR_SHIFT 9
 
 static int major = 0;
 static int _major = 0;
@@ -59,11 +58,15 @@
 	 * The current mapping.
 	 */
 	struct dm_table *map;
+
+	/*
+	 * io objects are allocated from here.
+	 */
+	mempool_t *io_pool;
 };
 
 #define MIN_IOS 256
 static kmem_cache_t *_io_cache;
-static mempool_t *_io_pool;
 
 static __init int local_init(void)
 {
@@ -75,18 +78,10 @@
 	if (!_io_cache)
 		return -ENOMEM;
 
-	_io_pool = mempool_create(MIN_IOS, mempool_alloc_slab,
-				  mempool_free_slab, _io_cache);
-	if (!_io_pool) {
-		kmem_cache_destroy(_io_cache);
-		return -ENOMEM;
-	}
-
 	_major = major;
 	r = register_blkdev(_major, _name, &dm_blk_dops);
 	if (r < 0) {
 		DMERR("register_blkdev failed");
-		mempool_destroy(_io_pool);
 		kmem_cache_destroy(_io_cache);
 		return r;
 	}
@@ -99,7 +94,6 @@
 
 static void local_exit(void)
 {
-	mempool_destroy(_io_pool);
 	kmem_cache_destroy(_io_cache);
 
 	if (unregister_blkdev(_major, _name) < 0)
@@ -179,14 +173,14 @@
 	return 0;
 }
 
-static inline struct dm_io *alloc_io(void)
+static inline struct dm_io *alloc_io(struct mapped_device *md)
 {
-	return mempool_alloc(_io_pool, GFP_NOIO);
+	return mempool_alloc(md->io_pool, GFP_NOIO);
 }
 
-static inline void free_io(struct dm_io *io)
+static inline void free_io(struct mapped_device *md, struct dm_io *io)
 {
-	mempool_free(io, _io_pool);
+	mempool_free(io, md->io_pool);
 }
 
 static inline struct deferred_io *alloc_deferred(void)
@@ -212,7 +206,7 @@
 
 	down_write(&md->lock);
 
-	if (!test_bit(DMF_SUSPENDED, &md->flags)) {
+	if (!test_bit(DMF_BLOCK_IO, &md->flags)) {
 		up_write(&md->lock);
 		free_deferred(di);
 		return 1;
@@ -234,6 +228,15 @@
  *   interests of getting something for people to use I give
  *   you this clearly demarcated crap.
  *---------------------------------------------------------------*/
+static inline sector_t to_sector(unsigned int bytes)
+{
+	return bytes >> SECTOR_SHIFT;
+}
+
+static inline unsigned int to_bytes(sector_t sector)
+{
+	return sector << SECTOR_SHIFT;
+}
 
 /*
  * Decrements the number of outstanding ios that a bio has been
@@ -244,18 +247,19 @@
 	static spinlock_t _uptodate_lock = SPIN_LOCK_UNLOCKED;
 	unsigned long flags;
 
-	spin_lock_irqsave(&_uptodate_lock, flags);
-	if (error)
+	if (error) {
+		spin_lock_irqsave(&_uptodate_lock, flags);
 		io->error = error;
-	spin_unlock_irqrestore(&_uptodate_lock, flags);
+		spin_unlock_irqrestore(&_uptodate_lock, flags);
+	}
 
 	if (atomic_dec_and_test(&io->io_count)) {
 		if (atomic_dec_and_test(&io->md->pending))
 			/* nudge anyone waiting on suspend queue */
 			wake_up(&io->md->wait);
 
-		bio_endio(io->bio, io->error ? 0 : io->bio->bi_size, io->error);
-		free_io(io);
+		bio_endio(io->bio, io->bio->bi_size, io->error);
+		free_io(io->md, io);
 	}
 }
 
@@ -263,16 +267,11 @@
 {
 	struct dm_io *io = bio->bi_private;
 
-	/*
-	 * Only call dec_pending if the clone has completely
-	 * finished.  If a partial io errors I'm assuming it won't
-	 * be requeued.  FIXME: check this.
-	 */
-	if (error || !bio->bi_size) {
-		dec_pending(io, error);
-		bio_put(bio);
-	}
+	if (bio->bi_size)
+		return 1;
 
+	dec_pending(io, error);
+	bio_put(bio);
 	return 0;
 }
 
@@ -280,16 +279,17 @@
 static sector_t max_io_len(struct mapped_device *md,
 			   sector_t sector, struct dm_target *ti)
 {
-	sector_t len = ti->len;
+	sector_t offset = sector - ti->begin;
+	sector_t len = ti->len - offset;
 
 	/* FIXME: obey io_restrictions ! */
 
+
 	/*
 	 * Does the target need to split even further ?
 	 */
 	if (ti->split_io) {
 		sector_t boundary;
-		sector_t offset = sector - ti->begin;
 		boundary = dm_round_up(offset + 1, ti->split_io) - offset;
 
 		if (len > boundary)
@@ -299,23 +299,23 @@
 	return len;
 }
 
-static void __map_bio(struct dm_target *ti, struct bio *clone)
+static void __map_bio(struct dm_target *ti, struct bio *clone, struct dm_io *io)
 {
-	struct dm_io *io = clone->bi_private;
 	int r;
 
 	/*
 	 * Sanity checks.
 	 */
-	if (!clone->bi_size)
-		BUG();
+	BUG_ON(!clone->bi_size);
+
+	clone->bi_end_io = clone_endio;
+	clone->bi_private = io;
 
 	/*
 	 * Map the clone.  If r == 0 we don't need to do
 	 * anything, the target has assumed ownership of
 	 * this io.
 	 */
-	atomic_inc(&io->md->pending);
 	atomic_inc(&io->io_count);
 	r = ti->type->map(ti, clone);
 	if (r > 0)
@@ -337,77 +337,125 @@
 };
 
 /*
- * Issues a little bio that just does the back end of a split page.
+ * Creates a little bio that is just does part of a bvec.
  */
-static void __split_page(struct clone_info *ci, unsigned int len)
+static struct bio *split_bvec(struct bio *bio, sector_t sector,
+			      unsigned short idx, unsigned int offset,
+			      unsigned int len)
 {
-	struct dm_target *ti = dm_table_find_target(ci->md->map, ci->sector);
-	struct bio *clone, *bio = ci->bio;
-	struct bio_vec *bv = bio->bi_io_vec + (bio->bi_vcnt - 1);
+	struct bio *clone;
+	struct bio_vec *bv = bio->bi_io_vec + idx;
 
-	DMWARN("splitting page");
+	clone = bio_alloc(GFP_NOIO, 1);
 
-	if (len > ci->sector_count)
-		len = ci->sector_count;
+	if (clone) {
+		memcpy(clone->bi_io_vec, bv, sizeof(*bv));
 
-	clone = bio_alloc(GFP_NOIO, 1);
-	memcpy(clone->bi_io_vec, bv, sizeof(*bv));
+		clone->bi_sector = sector;
+		clone->bi_bdev = bio->bi_bdev;
+		clone->bi_rw = bio->bi_rw;
+		clone->bi_vcnt = 1;
+		clone->bi_size = to_bytes(len);
+		clone->bi_io_vec->bv_offset = offset;
+		clone->bi_io_vec->bv_len = clone->bi_size;
+	}
 
-	clone->bi_sector = ci->sector;
-	clone->bi_bdev = bio->bi_bdev;
-	clone->bi_flags = bio->bi_flags | (1 << BIO_SEG_VALID);
-	clone->bi_rw = bio->bi_rw;
-	clone->bi_size = len << SECTOR_SHIFT;
-	clone->bi_end_io = clone_endio;
-	clone->bi_private = ci->io;
+	return clone;
+}
+
+/*
+ * Creates a bio that consists of range of complete bvecs.
+ */
+static struct bio *clone_bio(struct bio *bio, sector_t sector,
+			     unsigned short idx, unsigned short bv_count,
+			     unsigned int len)
+{
+	struct bio *clone;
 
-	ci->sector += len;
-	ci->sector_count -= len;
+	clone = bio_clone(bio, GFP_NOIO);
+	clone->bi_sector = sector;
+	clone->bi_idx = idx;
+	clone->bi_vcnt = idx + bv_count;
+	clone->bi_size = to_bytes(len);
 
-	__map_bio(ti, clone);
+	return clone;
 }
 
 static void __clone_and_map(struct clone_info *ci)
 {
 	struct bio *clone, *bio = ci->bio;
 	struct dm_target *ti = dm_table_find_target(ci->md->map, ci->sector);
-	sector_t len = max_io_len(ci->md, bio->bi_sector, ti);
+	sector_t len = 0, max = max_io_len(ci->md, ci->sector, ti);
 
-	/* shorter than current target ? */
-	if (ci->sector_count < len)
-		len = ci->sector_count;
-
-	/* create the clone */
-	clone = bio_clone(ci->bio, GFP_NOIO);
-	clone->bi_sector = ci->sector;
-	clone->bi_idx = ci->idx;
-	clone->bi_size = len << SECTOR_SHIFT;
-	clone->bi_end_io = clone_endio;
-	clone->bi_private = ci->io;
+	if (ci->sector_count <= max) {
+		/*
+		 * Optimise for the simple case where we can do all of
+		 * the remaining io with a single clone.
+		 */
+		clone = clone_bio(bio, ci->sector, ci->idx,
+				  bio->bi_vcnt - ci->idx, ci->sector_count);
+		__map_bio(ti, clone, ci->io);
+		ci->sector_count = 0;
 
-	/* adjust the remaining io */
-	ci->sector += len;
-	ci->sector_count -= len;
-	__map_bio(ti, clone);
+	} else if (to_sector(bio->bi_io_vec[ci->idx].bv_len) <= max) {
+		/*
+		 * There are some bvecs that don't span targets.
+		 * Do as many of these as possible.
+		 */
+		int i;
+		sector_t remaining = max;
+		sector_t bv_len;
 
-	/*
-	 * If we are not performing all remaining io in this
-	 * clone then we need to calculate ci->idx for the next
-	 * time round.
-	 */
-	if (ci->sector_count) {
-		while (len) {
-			struct bio_vec *bv = clone->bi_io_vec + ci->idx;
-			sector_t bv_len = bv->bv_len >> SECTOR_SHIFT;
-			if (bv_len <= len)
-				len -= bv_len;
-
-			else {
-				__split_page(ci, bv_len - len);
-				len = 0;
-			}
-			ci->idx++;
+		for (i = ci->idx; remaining && (i < bio->bi_vcnt); i++) {
+			bv_len = to_sector(bio->bi_io_vec[i].bv_len);
+
+			if (bv_len > remaining)
+				break;
+
+			remaining -= bv_len;
+			len += bv_len;
+		}
+
+		clone = clone_bio(bio, ci->sector, ci->idx, i - ci->idx, len);
+		__map_bio(ti, clone, ci->io);
+
+		ci->sector += len;
+		ci->sector_count -= len;
+		ci->idx = i;
+
+	} else {
+		/*
+		 * Create two copy bios to deal with io that has
+		 * been split across a target.
+		 */
+		struct bio_vec *bv = bio->bi_io_vec + ci->idx;
+
+		clone = split_bvec(bio, ci->sector, ci->idx,
+				   bv->bv_offset, max);
+		if (!clone) {
+			dec_pending(ci->io, -ENOMEM);
+			return;
+		}
+
+		__map_bio(ti, clone, ci->io);
+
+		ci->sector += max;
+		ci->sector_count -= max;
+		ti = dm_table_find_target(ci->md->map, ci->sector);
+
+		len = to_sector(bv->bv_len) - max;
+		clone = split_bvec(bio, ci->sector, ci->idx,
+				   bv->bv_offset + to_bytes(max), len);
+		if (!clone) {
+			dec_pending(ci->io, -ENOMEM);
+			return;
 		}
+
+		__map_bio(ti, clone, ci->io);
+
+		ci->sector += len;
+		ci->sector_count -= len;
+		ci->idx++;
 	}
 }
 
@@ -420,7 +468,7 @@
 
 	ci.md = md;
 	ci.bio = bio;
-	ci.io = alloc_io();
+	ci.io = alloc_io(md);
 	ci.io->error = 0;
 	atomic_set(&ci.io->io_count, 1);
 	ci.io->bio = bio;
@@ -429,6 +477,7 @@
 	ci.sector_count = bio_sectors(bio);
 	ci.idx = 0;
 
+	atomic_inc(&md->pending);
 	while (ci.sector_count)
 		__clone_and_map(&ci);
 
@@ -459,13 +508,13 @@
 		up_read(&md->lock);
 
 		if (bio_rw(bio) == READA) {
-			bio_io_error(bio, 0);
+			bio_io_error(bio, bio->bi_size);
 			return 0;
 		}
 
 		r = queue_io(md, bio);
 		if (r < 0) {
-			bio_io_error(bio, 0);
+			bio_io_error(bio, bio->bi_size);
 			return 0;
 
 		} else if (r == 0)
@@ -559,8 +608,17 @@
 	md->queue.queuedata = md;
 	blk_queue_make_request(&md->queue, dm_request);
 
+	md->io_pool = mempool_create(MIN_IOS, mempool_alloc_slab,
+				     mempool_free_slab, _io_cache);
+	if (!md->io_pool) {
+		free_minor(md->disk->first_minor);
+		kfree(md);
+		return NULL;
+	}
+
 	md->disk = alloc_disk(1);
 	if (!md->disk) {
+		mempool_destroy(md->io_pool);
 		free_minor(md->disk->first_minor);
 		kfree(md);
 		return NULL;
@@ -582,6 +640,7 @@
 static void free_dev(struct mapped_device *md)
 {
 	free_minor(md->disk->first_minor);
+	mempool_destroy(md->io_pool);
 	del_gendisk(md->disk);
 	put_disk(md->disk);
 	kfree(md);
@@ -711,15 +770,14 @@
 	}
 
 	set_bit(DMF_BLOCK_IO, &md->flags);
+	add_wait_queue(&md->wait, &wait);
 	up_write(&md->lock);
 
 	/*
 	 * Then we wait for the already mapped ios to
 	 * complete.
 	 */
-	down_read(&md->lock);
-
-	add_wait_queue(&md->wait, &wait);
+	blk_run_queues();
 	while (1) {
 		set_current_state(TASK_INTERRUPTIBLE);
 
@@ -730,11 +788,11 @@
 	}
 
 	current->state = TASK_RUNNING;
-	remove_wait_queue(&md->wait, &wait);
-	up_read(&md->lock);
 
-	/* set_bit is atomic */
+	down_write(&md->lock);
+	remove_wait_queue(&md->wait, &wait);
 	set_bit(DMF_SUSPENDED, &md->flags);
+	up_write(&md->lock);
 
 	return 0;
 }
diff -Nru a/drivers/md/dm.h b/drivers/md/dm.h
--- a/drivers/md/dm.h	Mon Dec 23 21:21:54 2002
+++ b/drivers/md/dm.h	Mon Dec 23 21:21:54 2002
@@ -29,6 +29,8 @@
 #define SECTOR_FORMAT "%lu"
 #endif
 
+#define SECTOR_SHIFT 9
+
 extern struct block_device_operations dm_blk_dops;
 
 /*
diff -Nru a/drivers/net/Kconfig b/drivers/net/Kconfig
--- a/drivers/net/Kconfig	Mon Dec 23 21:21:59 2002
+++ b/drivers/net/Kconfig	Mon Dec 23 21:21:59 2002
@@ -2028,9 +2028,11 @@
 	help
 	  Support for PPP over Ethernet.
 
-	  This driver requires a specially patched pppd daemon.  The patch to
-	  pppd, along with binaries of a patched pppd package can be found at:
-	  <http://www.shoshin.uwaterloo.ca/~mostrows/>.
+	  This driver requires the latest version of pppd from the CVS
+	  repository at cvs.samba.org.  Alternatively, see the 
+	  RoaringPenguin package (http://www.roaringpenguin.com/pppoe)
+	  which contains instruction on how to use this driver (under 
+	  the heading "Kernel mode PPPoE").
 
 config PPPOATM
 	tristate "PPP over ATM"
diff -Nru a/drivers/net/bonding.c b/drivers/net/bonding.c
--- a/drivers/net/bonding.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/net/bonding.c	Mon Dec 23 21:22:00 2002
@@ -177,20 +177,91 @@
  *     - Port Gleb Natapov's multicast support patchs from 2.4.12
  *       to 2.4.18 adding support for multicast.
  *
- * 2002/06/17 - Tony Cureington <tony.cureington * hp_com>
+ * 2002/06/10 - Tony Cureington <tony.cureington * hp_com>
  *     - corrected uninitialized pointer (ifr.ifr_data) in bond_check_dev_link;
- *       actually changed function to use ETHTOOL, then MIIPHY, and finally
- *       MIIREG to determine the link status
+ *       actually changed function to use MIIPHY, then MIIREG, and finally
+ *       ETHTOOL to determine the link status
  *     - fixed bad ifr_data pointer assignments in bond_ioctl
  *     - corrected mode 1 being reported as active-backup in bond_get_info;
  *       also added text to distinguish type of load balancing (rr or xor)
  *     - change arp_ip_target module param from "1-12s" (array of 12 ptrs)
  *       to "s" (a single ptr)
  *
+ * 2002/08/30 - Jay Vosburgh <fubar at us dot ibm dot com>
+ *     - Removed acquisition of xmit_lock in set_multicast_list; caused
+ *       deadlock on SMP (lock is held by caller).
+ *     - Revamped SIOCGMIIPHY, SIOCGMIIREG portion of bond_check_dev_link().
+ *
  * 2002/09/18 - Jay Vosburgh <fubar at us dot ibm dot com>
  *     - Fixed up bond_check_dev_link() (and callers): removed some magic
  *	 numbers, banished local MII_ defines, wrapped ioctl calls to
  *	 prevent EFAULT errors
+ *
+ * 2002/9/30 - Jay Vosburgh <fubar at us dot ibm dot com>
+ *     - make sure the ip target matches the arp_target before saving the
+ *	 hw address.
+ *
+ * 2002/9/30 - Dan Eisner <eisner at 2robots dot com>
+ *     - make sure my_ip is set before taking down the link, since
+ *	 not all switches respond if the source ip is not set.
+ *
+ * 2002/10/8 - Janice Girouard <girouard at us dot ibm dot com>
+ *     - read in the local ip address when enslaving a device
+ *     - add primary support
+ *     - make sure 2*arp_interval has passed when a new device
+ *       is brought on-line before taking it down.
+ *
+ * 2002/09/11 - Philippe De Muyter <phdm at macqel dot be>
+ *     - Added bond_xmit_broadcast logic.
+ *     - Added bond_mode() support function.
+ *
+ * 2002/10/26 - Laurent Deniel <laurent.deniel at free.fr>
+ *     - allow to register multicast addresses only on active slave
+ *       (useful in active-backup mode)
+ *     - add multicast module parameter
+ *     - fix deletion of multicast groups after unloading module
+ *
+ * 2002/11/06 - Kameshwara Rayaprolu <kameshwara.rao * wipro_com>
+ *     - Changes to prevent panic from closing the device twice; if we close 
+ *       the device in bond_release, we must set the original_flags to down 
+ *       so it won't be closed again by the network layer.
+ *
+ * 2002/11/07 - Tony Cureington <tony.cureington * hp_com>
+ *     - Fix arp_target_hw_addr memory leak
+ *     - Created activebackup_arp_monitor function to handle arp monitoring 
+ *       in active backup mode - the bond_arp_monitor had several problems... 
+ *       such as allowing slaves to tx arps sequentially without any delay 
+ *       for a response
+ *     - Renamed bond_arp_monitor to loadbalance_arp_monitor and re-wrote
+ *       this function to just handle arp monitoring in load-balancing mode;
+ *       it is a lot more compact now
+ *     - Changes to ensure one and only one slave transmits in active-backup 
+ *       mode
+ *     - Robustesize parameters; warn users about bad combinations of 
+ *       parameters; also if miimon is specified and a network driver does 
+ *       not support MII or ETHTOOL, inform the user of this
+ *     - Changes to support link_failure_count when in arp monitoring mode
+ *     - Fix up/down delay reported in /proc
+ *     - Added version; log version; make version available from "modinfo -d"
+ *     - Fixed problem in bond_check_dev_link - if the first IOCTL (SIOCGMIIPH)
+ *	 failed, the ETHTOOL ioctl never got a chance
+ *
+ * 2002/11/16 - Laurent Deniel <laurent.deniel at free.fr>
+ *     - fix multicast handling in activebackup_arp_monitor
+ *     - remove one unnecessary and confusing current_slave == slave test 
+ *	 in activebackup_arp_monitor
+ *
+ *  2002/11/17 - Laurent Deniel <laurent.deniel at free.fr>
+ *     - fix bond_slave_info_query when slave_id = num_slaves
+ *
+ *  2002/11/19 - Janice Girouard <girouard at us dot ibm dot com>
+ *     - correct ifr_data reference.  Update ifr_data reference
+ *       to mii_ioctl_data struct values to avoid confusion.
+ *
+ *
+ *  2002/11/22 - Bert Barbe <bert.barbe at oracle dot com>
+ *      - Add support for multiple arp_ip_target
+ *
  */
 
 #include <linux/config.h>
@@ -201,6 +272,7 @@
 #include <linux/interrupt.h>
 #include <linux/ioport.h>
 #include <linux/in.h>
+#include <linux/ip.h>
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/init.h>
@@ -208,6 +280,7 @@
 #include <linux/socket.h>
 #include <linux/errno.h>
 #include <linux/netdevice.h>
+#include <linux/inetdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/skbuff.h>
 #include <net/sock.h>
@@ -225,6 +298,13 @@
 #include <asm/dma.h>
 #include <asm/uaccess.h>
 
+#define DRV_VERSION		"2.4.20-20021210"
+#define DRV_RELDATE		"December 10, 2002"
+#define DRV_NAME		"bonding"
+#define DRV_DESCRIPTION		"Ethernet Channel Bonding Driver"
+
+static const char *version =
+DRV_NAME ".c:v" DRV_VERSION " (" DRV_RELDATE ")\n";
 
 /* monitor all links that often (in milliseconds). <=0 disables monitoring */
 #ifndef BOND_LINK_MON_INTERV
@@ -235,20 +315,31 @@
 #define BOND_LINK_ARP_INTERV	0
 #endif
 
+#ifndef MAX_ARP_IP_TARGETS
+#define MAX_ARP_IP_TARGETS 16
+#endif
+
 static int arp_interval = BOND_LINK_ARP_INTERV;
-static char *arp_ip_target = NULL;
-static unsigned long arp_target = 0;
+static char *arp_ip_target[MAX_ARP_IP_TARGETS] = { NULL, };
+static unsigned long arp_target[MAX_ARP_IP_TARGETS] = { 0, } ;
+static int arp_ip_count = 0;
 static u32 my_ip = 0;
 char *arp_target_hw_addr = NULL;
 
+static char *primary= NULL;
+
 static int max_bonds	= BOND_DEFAULT_MAX_BONDS;
 static int miimon	= BOND_LINK_MON_INTERV;
 static int mode		= BOND_MODE_ROUNDROBIN;
 static int updelay	= 0;
 static int downdelay	= 0;
 
+#define BOND_MULTICAST_DISABLED 0
+#define BOND_MULTICAST_ACTIVE   1
+#define BOND_MULTICAST_ALL      2
+static int multicast    = BOND_MULTICAST_ALL;
+
 static int first_pass	= 1;
-int bond_cnt;
 static struct bonding *these_bonds =  NULL;
 static struct net_device *dev_bonds = NULL;
 
@@ -259,13 +350,17 @@
 MODULE_PARM(mode, "i");
 MODULE_PARM(arp_interval, "i");
 MODULE_PARM_DESC(arp_interval, "arp interval in milliseconds");
-MODULE_PARM(arp_ip_target, "s");
-MODULE_PARM_DESC(arp_ip_target, "arp target in n.n.n.n form");
+MODULE_PARM(arp_ip_target, "1-" __MODULE_STRING(MAX_ARP_IP_TARGETS) "s");
+MODULE_PARM_DESC(arp_ip_target, "arp targets in n.n.n.n form");
 MODULE_PARM_DESC(mode, "Mode of operation : 0 for round robin, 1 for active-backup, 2 for xor");
 MODULE_PARM(updelay, "i");
 MODULE_PARM_DESC(updelay, "Delay before considering link up, in milliseconds");
 MODULE_PARM(downdelay, "i");
 MODULE_PARM_DESC(downdelay, "Delay before considering link down, in milliseconds");
+MODULE_PARM(primary, "s");
+MODULE_PARM_DESC(primary, "Primary network device to use");
+MODULE_PARM(multicast, "i");
+MODULE_PARM_DESC(multicast, "Mode for multicast support : 0 for none, 1 for active slave, 2 for all slaves (default)");
 
 extern void arp_send( int type, int ptype, u32 dest_ip, struct net_device *dev,
 	u32 src_ip, unsigned char *dest_hw, unsigned char *src_hw, 
@@ -276,7 +371,8 @@
 static int bond_xmit_activebackup(struct sk_buff *skb, struct net_device *dev);
 static struct net_device_stats *bond_get_stats(struct net_device *dev);
 static void bond_mii_monitor(struct net_device *dev);
-static void bond_arp_monitor(struct net_device *dev);
+static void loadbalance_arp_monitor(struct net_device *dev);
+static void activebackup_arp_monitor(struct net_device *dev);
 static int bond_event(struct notifier_block *this, unsigned long event, void *ptr);
 static void bond_restore_slave_flags(slave_t *slave);
 static void bond_mc_list_destroy(struct bonding *bond);
@@ -287,6 +383,7 @@
 static void bond_set_promiscuity(bonding_t *bond, int inc);
 static void bond_set_allmulti(bonding_t *bond, int inc);
 static struct dev_mc_list* bond_mc_list_find_dmi(struct dev_mc_list *dmi, struct dev_mc_list *mc_list);
+static void bond_mc_update(bonding_t *bond, slave_t *new, slave_t *old);
 static void bond_set_slave_inactive_flags(slave_t *slave);
 static void bond_set_slave_active_flags(slave_t *slave);
 static int bond_enslave(struct net_device *master, struct net_device *slave);
@@ -308,6 +405,47 @@
 
 #define IS_UP(dev)	((((dev)->flags & (IFF_UP)) == (IFF_UP)) && \
 			(netif_running(dev) && netif_carrier_ok(dev)))
+  
+static void arp_send_all(slave_t *slave)
+{	
+  int i; 
+  for ( i=0; (i<MAX_ARP_IP_TARGETS) && arp_target[i]; i++) { 
+    arp_send(ARPOP_REQUEST, ETH_P_ARP, arp_target[i], slave->dev, 
+	     my_ip, arp_target_hw_addr, slave->dev->dev_addr,
+	     arp_target_hw_addr); 
+  } 
+}
+ 
+
+static const char *bond_mode(void)
+{
+	switch (mode) {
+	case BOND_MODE_ROUNDROBIN :
+		return "load balancing (round-robin)";
+	case BOND_MODE_ACTIVEBACKUP :
+		return "fault-tolerance (active-backup)";
+	case BOND_MODE_XOR :
+		return "load balancing (xor)";
+	case BOND_MODE_BROADCAST :
+		return "fault-tolerance (broadcast)";
+	default :
+		return "unknown";
+	}
+}
+
+static const char *multicast_mode(void)
+{
+	switch(multicast) {
+	case BOND_MULTICAST_DISABLED :
+		return "disabled";
+	case BOND_MULTICAST_ACTIVE :
+		return "active slave only";
+	case BOND_MULTICAST_ALL :
+		return "all slaves";
+	default :
+		return "unknown";
+	}
+}
 
 static void bond_restore_slave_flags(slave_t *slave)
 {
@@ -415,11 +553,24 @@
 		/*       call it and not the others for that team          */
 		/*       member.                                           */
 
-		/* try SOICETHTOOL ioctl, some drivers cache ETHTOOL_GLINK */
-		/* for a period of time; we need to encourage link status  */
-		/* be reported by network drivers in real time; if the     */
-		/* value is cached, the mmimon module parm may have no     */
-		/* effect...                                               */
+		/*
+		 * We cannot assume that SIOCGMIIPHY will also read a
+		 * register; not all network drivers (e.g., e100)
+		 * support that.
+		 */
+
+		/* Yes, the mii is overlaid on the ifreq.ifr_ifru */
+		mii = (struct mii_ioctl_data *)&ifr.ifr_data;
+		if (IOCTL(dev, &ifr, SIOCGMIIPHY) == 0) {
+			mii->reg_num = MII_BMSR;
+			if (IOCTL(dev, &ifr, SIOCGMIIREG) == 0) {
+				return mii->val_out & BMSR_LSTATUS;
+			}
+		}
+
+		/* try SIOCETHTOOL ioctl, some drivers cache ETHTOOL_GLINK */
+		/* for a period of time so we attempt to get link status   */
+		/* from it last if the above MII ioctls fail...            */
 	        etool.cmd = ETHTOOL_GLINK;
 	        ifr.ifr_data = (char*)&etool;
 		if (IOCTL(dev, &ifr, SIOCETHTOOL) == 0) {
@@ -427,26 +578,14 @@
 				return BMSR_LSTATUS;
 			} 
 			else { 
+#ifdef BONDING_DEBUG
+				printk(KERN_INFO 
+					":: SIOCETHTOOL shows failure \n");
+#endif
 				return(0);
 			} 
 		}
 
-		/*
-		 * We cannot assume that SIOCGMIIPHY will also read a
-		 * register; not all network drivers support that.
-		 */
-
-		/* Yes, the mii is overlaid on the ifreq.ifr_ifru */
-		mii = (struct mii_ioctl_data *)&ifr.ifr_data;
-		if (IOCTL(dev, &ifr, SIOCGMIIPHY) != 0) {
-			return BMSR_LSTATUS;	 /* can't tell */
-		}
-
-		mii->reg_num = MII_BMSR;
-		if (IOCTL(dev, &ifr, SIOCGMIIREG) == 0) {
-			return mii->val_out & BMSR_LSTATUS;
-		}
-
 	}
 	return BMSR_LSTATUS;  /* spoof link up ( we can't check it) */
 }
@@ -483,7 +622,11 @@
 		init_timer(arp_timer);
 		arp_timer->expires  = jiffies + (arp_interval * HZ / 1000);
 		arp_timer->data     = (unsigned long)dev;
-		arp_timer->function = (void *)&bond_arp_monitor;
+		if (mode == BOND_MODE_ACTIVEBACKUP) {
+			arp_timer->function = (void *)&activebackup_arp_monitor;
+		} else {
+			arp_timer->function = (void *)&loadbalance_arp_monitor;
+		}
 		add_timer(arp_timer);
 	}
 	return 0;
@@ -501,6 +644,10 @@
 	}
 	if (arp_interval> 0) {  /* arp interval, in milliseconds. */
 		del_timer(&bond->arp_timer);
+                if (arp_target_hw_addr != NULL) {
+			kfree(arp_target_hw_addr); 
+			arp_target_hw_addr = NULL;
+		}
 	}
 
 	/* Release the bonded slaves */
@@ -545,9 +692,18 @@
 static void bond_mc_add(bonding_t *bond, void *addr, int alen)
 { 
 	slave_t *slave;
-
-	for (slave = bond->prev; slave != (slave_t*)bond; slave = slave->prev) {
-		dev_mc_add(slave->dev, addr, alen, 0);
+	switch (multicast) {
+	case BOND_MULTICAST_ACTIVE :
+		/* write lock already acquired */
+		if (bond->current_slave != NULL)
+			dev_mc_add(bond->current_slave->dev, addr, alen, 0);
+		break;
+	case BOND_MULTICAST_ALL :
+		for (slave = bond->prev; slave != (slave_t*)bond; slave = slave->prev)
+			dev_mc_add(slave->dev, addr, alen, 0);
+		break;
+	case BOND_MULTICAST_DISABLED :
+		break;
 	}
 } 
 
@@ -557,9 +713,19 @@
 static void bond_mc_delete(bonding_t *bond, void *addr, int alen)
 { 
 	slave_t *slave; 
-
-	for (slave = bond->prev; slave != (slave_t*)bond; slave = slave->prev)
-		dev_mc_delete(slave->dev, addr, alen, 0);
+	switch (multicast) {
+	case BOND_MULTICAST_ACTIVE :
+		/* write lock already acquired */
+		if (bond->current_slave != NULL)
+			dev_mc_delete(bond->current_slave->dev, addr, alen, 0);
+		break;
+	case BOND_MULTICAST_ALL :
+		for (slave = bond->prev; slave != (slave_t*)bond; slave = slave->prev)
+			dev_mc_delete(slave->dev, addr, alen, 0);
+		break;
+	case BOND_MULTICAST_DISABLED :
+		break;
+	}
 } 
 
 /*
@@ -603,9 +769,19 @@
 static void bond_set_promiscuity(bonding_t *bond, int inc)
 { 
 	slave_t *slave; 
- 
-	for (slave = bond->prev; slave != (slave_t*)bond; slave = slave->prev)
-		dev_set_promiscuity(slave->dev, inc);
+	switch (multicast) {
+	case BOND_MULTICAST_ACTIVE :
+		/* write lock already acquired */
+		if (bond->current_slave != NULL)
+			dev_set_promiscuity(bond->current_slave->dev, inc);
+		break;
+	case BOND_MULTICAST_ALL :
+		for (slave = bond->prev; slave != (slave_t*)bond; slave = slave->prev)
+			dev_set_promiscuity(slave->dev, inc);
+		break;
+	case BOND_MULTICAST_DISABLED :
+		break;
+	}
 } 
 
 /*
@@ -614,9 +790,19 @@
 static void bond_set_allmulti(bonding_t *bond, int inc)
 { 
 	slave_t *slave; 
- 
-	for (slave = bond->prev; slave != (slave_t*)bond; slave = slave->prev)
-		dev_set_allmulti(slave->dev, inc);
+	switch (multicast) {
+	case BOND_MULTICAST_ACTIVE : 
+		/* write lock already acquired */
+		if (bond->current_slave != NULL)
+			dev_set_allmulti(bond->current_slave->dev, inc);
+		break;
+	case BOND_MULTICAST_ALL :
+		for (slave = bond->prev; slave != (slave_t*)bond; slave = slave->prev)
+			dev_set_allmulti(slave->dev, inc);
+		break;
+	case BOND_MULTICAST_DISABLED :
+		break;
+	}
 } 
 
 /* 
@@ -641,6 +827,8 @@
 	struct dev_mc_list *dmi;
 	unsigned long flags = 0;
 
+	if (multicast == BOND_MULTICAST_DISABLED)
+		return;
 	/*
 	 * Lock the private data for the master
 	 */
@@ -683,6 +871,43 @@
 }
 
 /*
+ * Update the mc list and multicast-related flags for the new and 
+ * old active slaves (if any) according to the multicast mode
+ */
+static void bond_mc_update(bonding_t *bond, slave_t *new, slave_t *old)
+{
+	struct dev_mc_list *dmi;
+
+	switch(multicast) {
+	case BOND_MULTICAST_ACTIVE :		
+		if (bond->device->flags & IFF_PROMISC) {
+			if (old != NULL && new != old)
+				dev_set_promiscuity(old->dev, -1);
+			dev_set_promiscuity(new->dev, 1);
+		}
+		if (bond->device->flags & IFF_ALLMULTI) {
+			if (old != NULL && new != old)
+				dev_set_allmulti(old->dev, -1);
+			dev_set_allmulti(new->dev, 1);
+		}
+		/* first remove all mc addresses from old slave if any,
+		   and _then_ add them to new active slave */
+		if (old != NULL && new != old) {
+			for (dmi = bond->device->mc_list; dmi != NULL; dmi = dmi->next)
+				dev_mc_delete(old->dev, dmi->dmi_addr, dmi->dmi_addrlen, 0);
+		}
+		for (dmi = bond->device->mc_list; dmi != NULL; dmi = dmi->next)
+			dev_mc_add(new->dev, dmi->dmi_addr, dmi->dmi_addrlen, 0);
+		break;
+	case BOND_MULTICAST_ALL :
+		/* nothing to do: mc list is already up-to-date on all slaves */
+		break;
+	case BOND_MULTICAST_DISABLED :
+		break;
+	}
+}
+
+/*
  * This function counts the number of attached 
  * slaves for use by bond_xmit_xor.
  */
@@ -703,9 +928,16 @@
 	bonding_t *bond = NULL;
 	slave_t *new_slave = NULL;
 	unsigned long flags = 0;
+	unsigned long rflags = 0;
 	int ndx = 0;
 	int err = 0;
 	struct dev_mc_list *dmi;
+	struct in_ifaddr **ifap;
+	struct in_ifaddr *ifa;
+	static int (* ioctl)(struct net_device *, struct ifreq *, int);
+	struct ifreq ifr;
+	struct ethtool_value etool; 
+	int link_reporting = 0;
 
 	if (master_dev == NULL || slave_dev == NULL) {
 		return -ENODEV;
@@ -758,17 +990,19 @@
 
 	new_slave->dev = slave_dev;
 
-	/* set promiscuity level to new slave */ 
-	if (master_dev->flags & IFF_PROMISC)
-		dev_set_promiscuity(slave_dev, 1); 
+	if (multicast == BOND_MULTICAST_ALL) {
+		/* set promiscuity level to new slave */ 
+		if (master_dev->flags & IFF_PROMISC)
+			dev_set_promiscuity(slave_dev, 1); 
  
-	/* set allmulti level to new slave */
-	if (master_dev->flags & IFF_ALLMULTI) 
-		dev_set_allmulti(slave_dev, 1); 
- 
-	/* upload master's mc_list to new slave */ 
-	for (dmi = master_dev->mc_list; dmi != NULL; dmi = dmi->next) 
-		dev_mc_add (slave_dev, dmi->dmi_addr, dmi->dmi_addrlen, 0);
+		/* set allmulti level to new slave */
+		if (master_dev->flags & IFF_ALLMULTI) 
+			dev_set_allmulti(slave_dev, 1); 
+		
+		/* upload master's mc_list to new slave */ 
+		for (dmi = master_dev->mc_list; dmi != NULL; dmi = dmi->next) 
+			dev_mc_add (slave_dev, dmi->dmi_addr, dmi->dmi_addrlen, 0);
+	}
 
 	/* 
 	 * queue to the end of the slaves list, make the first element its
@@ -799,6 +1033,56 @@
 	new_slave->delay = 0;
 	new_slave->link_failure_count = 0;
 
+	if (miimon > 0) {
+		/* if the network driver for the slave does not support
+		 * ETHTOOL/MII link status reporting, warn the user of this
+		 */
+		if ((ioctl = slave_dev->do_ioctl) != NULL) {
+			etool.cmd = ETHTOOL_GLINK;
+	        	ifr.ifr_data = (char*)&etool;
+			if (IOCTL(slave_dev, &ifr, SIOCETHTOOL) == 0) {
+				link_reporting = 1;
+			}
+			else {
+				if (IOCTL(slave_dev, &ifr, SIOCGMIIPHY) == 0) {
+		                        /* Yes, the mii is overlaid on the
+					 * ifreq.ifr_ifru
+					 */
+					((struct mii_ioctl_data*)
+					 (&ifr.ifr_data))->reg_num = 1;
+					if (IOCTL(slave_dev, &ifr, SIOCGMIIREG)
+						       			== 0) {
+	                                	link_reporting = 1;
+					}
+				}
+			}
+		}
+
+		if ((link_reporting == 0) && (arp_interval == 0)) {
+			/* miimon is set but a bonded network driver does
+			 * not support ETHTOOL/MII and arp_interval is
+			 * not set
+			 */ 
+			printk(KERN_ERR
+				"bond_enslave(): MII and ETHTOOL support not "
+				"available for interface %s, and "
+				"arp_interval/arp_ip_target module parameters "
+		       		"not specified, thus bonding will not detect "
+				"link failures! see bonding.txt for details.\n",
+		       		slave_dev->name);
+		}
+		else if (link_reporting == 0) {
+			/* unable  get link status using mii/ethtool */
+			printk(KERN_WARNING 
+			       "bond_enslave: can't get link status from "
+			       "interface %s; the network driver associated "
+			       "with this interface does not support "
+			       "MII or ETHTOOL link status reporting, thus "
+			       "miimon has no effect on this interface.\n", 
+			       slave_dev->name);
+		}
+	}
+
 	/* check for initial state */
 	if ((miimon <= 0) ||
 	    (bond_check_dev_link(slave_dev) == BMSR_LSTATUS)) {
@@ -806,6 +1090,7 @@
 		printk(KERN_CRIT "Initial state of slave_dev is BOND_LINK_UP\n");
 #endif
 		new_slave->link  = BOND_LINK_UP;
+		new_slave->jiffies = jiffies;
 	}
 	else {
 #ifdef BONDING_DEBUG
@@ -832,6 +1117,7 @@
 			   is OK, so make this interface the active one */
 			bond->current_slave = new_slave;
 			bond_set_slave_active_flags(new_slave);
+			bond_mc_update(bond, new_slave, NULL);
 		}
 		else {
 #ifdef BONDING_DEBUG
@@ -839,15 +1125,24 @@
 #endif
 			bond_set_slave_inactive_flags(new_slave);
 		}
+		read_lock_irqsave(&(((struct in_device *)slave_dev->ip_ptr)->lock), rflags);
+		ifap= &(((struct in_device *)slave_dev->ip_ptr)->ifa_list);
+		ifa = *ifap;
+		my_ip = ifa->ifa_address;
+		read_unlock_irqrestore(&(((struct in_device *)slave_dev->ip_ptr)->lock), rflags);
+
+		/* if there is a primary slave, remember it */
+		if (primary != NULL)
+		  if( strcmp(primary, new_slave->dev->name) == 0) 
+			bond->primary_slave = new_slave;
 	} else {
 #ifdef BONDING_DEBUG
 		printk(KERN_CRIT "This slave is always active in trunk mode\n");
 #endif
 		/* always active in trunk mode */
 		new_slave->state = BOND_STATE_ACTIVE;
-		if (bond->current_slave == NULL) {
+		if (bond->current_slave == NULL) 
 			bond->current_slave = new_slave;
-		}
 	}
 
 	update_slave_cnt(bond);
@@ -938,6 +1233,7 @@
 	    IS_UP(newactive->dev)) {
 		bond_set_slave_inactive_flags(oldactive);
 		bond_set_slave_active_flags(newactive);
+		bond_mc_update(bond, newactive, oldactive);
 		bond->current_slave = newactive;
 		printk("%s : activate %s(old : %s)\n",
 			master_dev->name, newactive->dev->name, 
@@ -978,6 +1274,7 @@
 			newslave = bond->current_slave = bond->next;
 			write_unlock(&bond->ptrlock);
 		} else {
+
 			printk (" but could not find any %s interface.\n",
 				(mode == BOND_MODE_ACTIVEBACKUP) ? "backup":"other");
 			write_lock(&bond->ptrlock);
@@ -985,16 +1282,38 @@
 			write_unlock(&bond->ptrlock);
 			return NULL; /* still no slave, return NULL */
 		}
+	} else if (mode == BOND_MODE_ACTIVEBACKUP) {
+		/* make sure oldslave doesn't send arps - this could
+		 * cause a ping-pong effect between interfaces since they
+		 * would be able to tx arps - in active backup only one
+		 * slave should be able to tx arps, and that should be
+		 * the current_slave; the only exception is when all
+		 * slaves have gone down, then only one non-current slave can
+		 * send arps at a time; clearing oldslaves' mc list is handled
+		 * later in this function.
+		 */
+		bond_set_slave_inactive_flags(oldslave);
 	}
 
 	mintime = updelay;
 
+	/* first try the primary link; if arping, a link must tx/rx traffic 
+	 * before it can be considered the current_slave - also, we would skip 
+	 * slaves between the current_slave and primary_slave that may be up 
+	 * and able to arp
+	 */
+	if ((bond->primary_slave != NULL) && (arp_interval == 0)) {
+		if (IS_UP(bond->primary_slave->dev)) 
+			newslave = bond->primary_slave;
+	}
+
 	do {
 		if (IS_UP(newslave->dev)) {
 			if (newslave->link == BOND_LINK_UP) {
 				/* this one is immediately usable */
 				if (mode == BOND_MODE_ACTIVEBACKUP) {
 					bond_set_slave_active_flags(newslave);
+					bond_mc_update(bond, newslave, oldslave);
 					printk (" and making interface %s the active one.\n",
 						newslave->dev->name);
 				}
@@ -1030,14 +1349,30 @@
 
 		bestslave->delay = 0;
 		bestslave->link = BOND_LINK_UP;
+		bestslave->jiffies = jiffies;
 		bond_set_slave_active_flags(bestslave);
-
+		bond_mc_update(bond, bestslave, oldslave);
 		write_lock(&bond->ptrlock);
 		bond->current_slave = bestslave;
 		write_unlock(&bond->ptrlock);
 		return bestslave;
 	}
 
+	if ((mode == BOND_MODE_ACTIVEBACKUP) &&
+	    (multicast == BOND_MULTICAST_ACTIVE) &&
+	    (oldslave != NULL)) {
+		/* flush bonds (master's) mc_list from oldslave since it wasn't
+		 * updated (and deleted) above
+		 */ 
+		bond_mc_list_flush(oldslave->dev, bond->device); 
+		if (bond->device->flags & IFF_PROMISC) {
+			dev_set_promiscuity(oldslave->dev, -1);
+		}
+		if (bond->device->flags & IFF_ALLMULTI) {
+			dev_set_allmulti(oldslave->dev, -1);
+		}
+	}
+
 	printk (" but could not find any %s interface.\n",
 		(mode == BOND_MODE_ACTIVEBACKUP) ? "backup":"other");
 	
@@ -1081,6 +1416,7 @@
 		return -EINVAL;
 	}
 
+	bond->current_arp_slave = NULL;
 	our_slave = (slave_t *)bond;
 	old_current = bond->current_slave;
 	while ((our_slave = our_slave->prev) != (slave_t *)bond) {
@@ -1101,16 +1437,18 @@
 
 			/* release the slave from its bond */
 
-			/* flush master's mc_list from slave */ 
-			bond_mc_list_flush (slave, master); 
-       
-			/* unset promiscuity level from slave */
-			if (master->flags & IFF_PROMISC) 
-				dev_set_promiscuity(slave, -1); 
+			if (multicast == BOND_MULTICAST_ALL) {
+				/* flush master's mc_list from slave */ 
+				bond_mc_list_flush (slave, master); 
+				
+				/* unset promiscuity level from slave */
+				if (master->flags & IFF_PROMISC) 
+					dev_set_promiscuity(slave, -1); 
        
-			/* unset allmulti level from slave */ 
-			if (master->flags & IFF_ALLMULTI)
-				dev_set_allmulti(slave, -1); 
+				/* unset allmulti level from slave */ 
+				if (master->flags & IFF_ALLMULTI)
+					dev_set_allmulti(slave, -1); 
+			}
 
 			netdev_set_master(slave, NULL);
 
@@ -1122,6 +1460,7 @@
 			if (slave->flags & IFF_NOARP || 
 				bond->current_slave != NULL) {
 					dev_close(slave);
+					our_slave->original_flags &= ~IFF_UP;
 			}
 
 			bond_restore_slave_flags(our_slave);
@@ -1135,6 +1474,10 @@
 
 			update_slave_cnt(bond);
 
+			if (bond->primary_slave == our_slave) {
+				bond->primary_slave = NULL;
+			}
+
 			write_unlock_irqrestore(&bond->lock, flags);
 			return 0;  /* deletion OK */
 		}
@@ -1166,12 +1509,28 @@
 	}
 
 	bond = (struct bonding *) master->priv;
-	bond->current_slave = NULL;
+	bond->current_arp_slave = NULL;
 
 	while ((our_slave = bond->prev) != (slave_t *)bond) {
 		slave_dev = our_slave->dev;
 		bond->prev = our_slave->prev;
 
+		if (multicast == BOND_MULTICAST_ALL 
+		    || (multicast == BOND_MULTICAST_ACTIVE 
+			&& bond->current_slave == our_slave)) {
+
+			/* flush master's mc_list from slave */ 
+			bond_mc_list_flush (slave_dev, master); 
+			
+			/* unset promiscuity level from slave */
+			if (master->flags & IFF_PROMISC) 
+				dev_set_promiscuity(slave_dev, -1); 
+			
+			/* unset allmulti level from slave */ 
+			if (master->flags & IFF_ALLMULTI)
+				dev_set_allmulti(slave_dev, -1); 
+		}
+
 		kfree(our_slave);
 
 		netdev_set_master(slave_dev, NULL);
@@ -1183,9 +1542,12 @@
 		if (slave_dev->flags & IFF_NOARP)
 			dev_close(slave_dev);
 	}
+
+	bond->current_slave = NULL;
 	bond->next = (slave_t *)bond;
 	bond->slave_cnt = 0;
-	printk (KERN_INFO "%s: releases all slaves\n", master->name);
+	bond->primary_slave = NULL;
+	printk (KERN_INFO "%s: released all slaves\n", master->name);
 
 	return 0;
 }
@@ -1291,6 +1653,7 @@
 			} else {
 				/* link up again */
 				slave->link  = BOND_LINK_UP;
+				slave->jiffies = jiffies;
 				printk(KERN_INFO
 					"%s: link status up again after %d ms "
 					"for interface %s.\n",
@@ -1343,8 +1706,10 @@
 				if (slave->delay == 0) {
 					/* now the link has been up for long time enough */
 					slave->link = BOND_LINK_UP;
+					slave->jiffies = jiffies;
 
-					if (mode == BOND_MODE_ACTIVEBACKUP) {
+					if ( (mode == BOND_MODE_ACTIVEBACKUP) 
+					 || (slave != bond->primary_slave) ) {
 						/* prevent it from being the active one */
 						slave->state = BOND_STATE_BACKUP;
 					}
@@ -1358,15 +1723,26 @@
 						"for interface %s.\n",
 						master->name,
 						dev->name);
+	
+					if ( (bond->primary_slave != NULL)	 
+					  && (slave == bond->primary_slave) )
+						change_active_interface(bond); 
 				}
 				else
 					slave->delay--;
 				
 				/* we'll also look for the mostly eligible slave */
-				if (IS_UP(dev) && (slave->delay < mindelay)) {
+				if (bond->primary_slave == NULL)  {
+				    if (IS_UP(dev) && (slave->delay < mindelay)) {
+					mindelay = slave->delay;
+					bestslave = slave;
+				    } 
+				} else if ( (IS_UP(bond->primary_slave->dev))  || 
+				          ( (!IS_UP(bond->primary_slave->dev))  && 
+				          (IS_UP(dev) && (slave->delay < mindelay)) ) ) {
 					mindelay = slave->delay;
 					bestslave = slave;
-				} 
+				}
 			}
 			break;
 		} /* end of switch */
@@ -1380,7 +1756,8 @@
 	oldcurrent = bond->current_slave;
 	read_unlock(&bond->ptrlock);
 
-	if (oldcurrent == NULL) {  /* no active interface at the moment */
+	/* no active interface at the moment or need to bring up the primary */
+	if (oldcurrent == NULL)  { /* no active interface at the moment */
 		if (bestslave != NULL) { /* last chance to find one ? */
 			if (bestslave->link == BOND_LINK_UP) {
 				printk (KERN_INFO
@@ -1395,10 +1772,12 @@
 
 				bestslave->delay = 0;
 				bestslave->link  = BOND_LINK_UP;
+				bestslave->jiffies = jiffies;
 			}
 
 			if (mode == BOND_MODE_ACTIVEBACKUP) {
 				bond_set_slave_active_flags(bestslave);
+				bond_mc_update(bond, bestslave, NULL);
 			} else {
 				bestslave->state = BOND_STATE_ACTIVE;
 			}
@@ -1420,10 +1799,12 @@
 
 /* 
  * this function is called regularly to monitor each slave's link 
- * insuring that traffic is being sent and received.  If the adapter
- * has been dormant, then an arp is transmitted to generate traffic 
+ * ensuring that traffic is being sent and received when arp monitoring
+ * is used in load-balancing mode. if the adapter has been dormant, then an 
+ * arp is transmitted to generate traffic. see activebackup_arp_monitor for 
+ * arp monitoring in active backup mode. 
  */
-static void bond_arp_monitor(struct net_device *master)
+static void loadbalance_arp_monitor(struct net_device *master)
 {
 	bonding_t *bond;
 	unsigned long flags;
@@ -1439,147 +1820,358 @@
 
 	read_lock_irqsave(&bond->lock, flags);
 
-	if (!IS_UP(master)) {
+	/* TODO: investigate why rtnl_shlock_nowait and rtnl_exlock_nowait
+	 * are called below and add comment why they are required... 
+	 */
+	if ((!IS_UP(master)) || rtnl_shlock_nowait()) {
 		mod_timer(&bond->arp_timer, next_timer);
-		goto arp_monitor_out;
-	}
-
-
-	if (rtnl_shlock_nowait()) {
-		goto arp_monitor_out;
+		read_unlock_irqrestore(&bond->lock, flags);
+		return;
 	}
 
 	if (rtnl_exlock_nowait()) {
 		rtnl_shunlock();
-		goto arp_monitor_out;
+		mod_timer(&bond->arp_timer, next_timer);
+		read_unlock_irqrestore(&bond->lock, flags);
+		return;
 	}
 
-	/* see if any of the previous devices are up now (i.e. they have seen a 
-	 * response from an arp request sent by another adapter, since they 
-	 * have the same hardware address).
+	/* see if any of the previous devices are up now (i.e. they have
+	 * xmt and rcv traffic). the current_slave does not come into
+	 * the picture unless it is null. also, slave->jiffies is not needed
+	 * here because we send an arp on each slave and give a slave as
+	 * long as it needs to get the tx/rx within the delta.
+	 * TODO: what about up/down delay in arp mode? it wasn't here before
+	 *       so it can wait 
 	 */
-
 	slave = (slave_t *)bond;
 	while ((slave = slave->prev) != (slave_t *)bond)  {
 
-		read_lock(&bond->ptrlock);
-	  	if ( (!(slave->link == BOND_LINK_UP))  
-				&& (slave != bond->current_slave) ) {
-
-			read_unlock(&bond->ptrlock);
+	  	if (slave->link != BOND_LINK_UP) {
 
-	  		if ( ((jiffies - slave->dev->trans_start) <= 
+	  		if (((jiffies - slave->dev->trans_start) <= 
 						the_delta_in_ticks) &&  
 			     ((jiffies - slave->dev->last_rx) <= 
-						the_delta_in_ticks) ) {
+						the_delta_in_ticks)) {
 
 				slave->link  = BOND_LINK_UP;
-				write_lock(&bond->ptrlock);
+				slave->state = BOND_STATE_ACTIVE;
+
+				/* primary_slave has no meaning in round-robin
+				 * mode. the window of a slave being up and 
+				 * current_slave being null after enslaving
+				 * is closed.
+				 */
+				read_lock(&bond->ptrlock);
 				if (bond->current_slave == NULL) {
-					slave->state = BOND_STATE_ACTIVE;
+					read_unlock(&bond->ptrlock);
+					printk(KERN_INFO
+						"%s: link status definitely up "
+						"for interface %s, ",
+						master->name,
+						slave->dev->name);
+					change_active_interface(bond); 
+				} else {
+					read_unlock(&bond->ptrlock);
+					printk(KERN_INFO
+						"%s: interface %s is now up\n",
+						master->name,
+						slave->dev->name);
+				}
+			} 
+		} else {
+			/* slave->link == BOND_LINK_UP */
+
+			/* not all switches will respond to an arp request
+			 * when the source ip is 0, so don't take the link down
+			 * if we don't know our ip yet
+			 */
+			if (((jiffies - slave->dev->trans_start) >= 
+		              (2*the_delta_in_ticks)) ||
+		             (((jiffies - slave->dev->last_rx) >= 
+		               (2*the_delta_in_ticks)) && my_ip !=0)) {
+				slave->link  = BOND_LINK_DOWN;
+				slave->state = BOND_STATE_BACKUP;
+				if (slave->link_failure_count < UINT_MAX) {
+					slave->link_failure_count++;
+				}
+				printk(KERN_INFO
+				       "%s: interface %s is now down.\n",
+				       master->name,
+				       slave->dev->name);
+
+				read_lock(&bond->ptrlock);
+				if (slave == bond->current_slave) {
+					read_unlock(&bond->ptrlock);
+					change_active_interface(bond);
+				} else {
+					read_unlock(&bond->ptrlock);
+				}
+			}
+		} 
+
+		/* note: if switch is in round-robin mode, all links 
+		 * must tx arp to ensure all links rx an arp - otherwise
+		 * links may oscillate or not come up at all; if switch is 
+		 * in something like xor mode, there is nothing we can 
+		 * do - all replies will be rx'ed on same link causing slaves 
+		 * to be unstable during low/no traffic periods
+		 */
+		if (IS_UP(slave->dev)) {
+			arp_send_all(slave);
+		}
+	}
+
+	rtnl_exunlock();
+	rtnl_shunlock();
+	read_unlock_irqrestore(&bond->lock, flags);
+
+	/* re-arm the timer */
+	mod_timer(&bond->arp_timer, next_timer);
+}
+
+/* 
+ * When using arp monitoring in active-backup mode, this function is
+ * called to determine if any backup slaves have went down or a new
+ * current slave needs to be found.
+ * The backup slaves never generate traffic, they are considered up by merely 
+ * receiving traffic. If the current slave goes down, each backup slave will 
+ * be given the opportunity to tx/rx an arp before being taken down - this 
+ * prevents all slaves from being taken down due to the current slave not 
+ * sending any traffic for the backups to receive. The arps are not necessarily
+ * necessary, any tx and rx traffic will keep the current slave up. While any 
+ * rx traffic will keep the backup slaves up, the current slave is responsible 
+ * for generating traffic to keep them up regardless of any other traffic they 
+ * may have received.
+ * see loadbalance_arp_monitor for arp monitoring in load balancing mode
+ */
+static void activebackup_arp_monitor(struct net_device *master)
+{
+	bonding_t *bond;
+	unsigned long flags;
+	slave_t *slave;
+	int the_delta_in_ticks =  arp_interval * HZ / 1000;
+	int next_timer = jiffies + (arp_interval * HZ / 1000);
+
+	bond = (struct bonding *) master->priv; 
+	if (master->priv == NULL) {
+		mod_timer(&bond->arp_timer, next_timer);
+		return;
+	}
+
+	read_lock_irqsave(&bond->lock, flags);
+
+	if (!IS_UP(master)) {
+		mod_timer(&bond->arp_timer, next_timer);
+	        read_unlock_irqrestore(&bond->lock, flags);
+		return;
+	}
+
+	/* determine if any slave has come up or any backup slave has 
+	 * gone down 
+	 * TODO: what about up/down delay in arp mode? it wasn't here before
+	 *       so it can wait 
+	 */
+	slave = (slave_t *)bond;
+	while ((slave = slave->prev) != (slave_t *)bond)  {
+
+	  	if (slave->link != BOND_LINK_UP) {
+			if ((jiffies - slave->dev->last_rx) <=
+			    the_delta_in_ticks) {
+
+				slave->link = BOND_LINK_UP;
+				write_lock(&bond->ptrlock);
+				if ((bond->current_slave == NULL) &&
+				    ((jiffies - slave->dev->trans_start) <=
+				     the_delta_in_ticks)) {
 					bond->current_slave = slave;
+					bond_set_slave_active_flags(slave);
+			                bond_mc_update(bond, slave, NULL);
+					bond->current_arp_slave = NULL;
+				} else if (bond->current_slave != slave) {
+					/* this slave has just come up but we 
+					 * already have a current slave; this
+					 * can also happen if bond_enslave adds
+					 * a new slave that is up while we are 
+					 * searching for a new slave
+					 */
+					bond_set_slave_inactive_flags(slave);
+					bond->current_arp_slave = NULL;
 				}
-				if (slave != bond->current_slave) {
-					slave->dev->flags |= IFF_NOARP;
+
+				if (slave == bond->current_slave) {
+					printk(KERN_INFO
+						"%s: %s is up and now the "
+						"active interface\n",
+						master->name,
+						slave->dev->name);
+				} else {
+					printk(KERN_INFO
+						"%s: backup interface %s is "
+						"now up\n",
+						master->name,
+						slave->dev->name);
 				}
+
 				write_unlock(&bond->ptrlock);
-			} else {
-				if ((jiffies - slave->dev->last_rx) <= 
-						the_delta_in_ticks)  {
-					arp_send(ARPOP_REQUEST, ETH_P_ARP, 
-						arp_target, slave->dev, 
-						my_ip, arp_target_hw_addr, 
-						slave->dev->dev_addr, 
-		  				arp_target_hw_addr); 
+			}
+		} else {
+			read_lock(&bond->ptrlock);
+			if ((slave != bond->current_slave) &&
+			    (bond->current_arp_slave == NULL) &&
+			    (((jiffies - slave->dev->last_rx) >=
+			     3*the_delta_in_ticks) && (my_ip != 0))) {
+				/* a backup slave has gone down; three times 
+				 * the delta allows the current slave to be 
+				 * taken out before the backup slave.
+				 * note: a non-null current_arp_slave indicates
+				 * the current_slave went down and we are 
+				 * searching for a new one; under this 
+				 * condition we only take the current_slave 
+				 * down - this gives each slave a chance to 
+				 * tx/rx traffic before being taken out
+				 */
+				read_unlock(&bond->ptrlock);
+				slave->link  = BOND_LINK_DOWN;
+				if (slave->link_failure_count < UINT_MAX) {
+					slave->link_failure_count++;
 				}
+				bond_set_slave_inactive_flags(slave);
+				printk(KERN_INFO
+					"%s: backup interface %s is now down\n",
+					master->name,
+					slave->dev->name);
+			} else {
+				read_unlock(&bond->ptrlock);
 			}
-		} else 
-			read_unlock(&bond->ptrlock);
+		}
 	}
 
 	read_lock(&bond->ptrlock);
 	slave = bond->current_slave;
 	read_unlock(&bond->ptrlock);
 
-	if (slave != 0) {
-	
-	  /* see if you need to take down the current_slave, since
-	   * you haven't seen an arp in 2*arp_intervals
-	   */
-
-		if ( ((jiffies - slave->dev->trans_start) >= 
-		      (2*the_delta_in_ticks)) ||
-		     ((jiffies - slave->dev->last_rx) >= 
-		      (2*the_delta_in_ticks)) ) {
+	if (slave != NULL) {
 
-			if (slave->link == BOND_LINK_UP) {
-				slave->link  = BOND_LINK_DOWN;
-				slave->state = BOND_STATE_BACKUP;
-				/* 
-				 * we want to see arps, otherwise we couldn't 
-				 * bring the adapter back online...  
-				 */
-				printk(KERN_INFO "%s: link status definitely "
-						 "down for interface %s, "
-						 "disabling it",
-				       slave->dev->master->name,
-				       slave->dev->name);
-				/* find a new interface and be verbose */
-				change_active_interface(bond);
-				read_lock(&bond->ptrlock);
-				slave = bond->current_slave;
-				read_unlock(&bond->ptrlock);
-			}
-		} 
+		/* if we have sent traffic in the past 2*arp_intervals but
+		 * haven't xmit and rx traffic in that time interval, select 
+		 * a different slave. slave->jiffies is only updated when
+		 * a slave first becomes the current_slave - not necessarily
+		 * after every arp; this ensures the slave has a full 2*delta 
+		 * before being taken out. if a primary is being used, check 
+		 * if it is up and needs to take over as the current_slave
+		 */
+		if ((((jiffies - slave->dev->trans_start) >= 
+		       (2*the_delta_in_ticks)) ||
+		     (((jiffies - slave->dev->last_rx) >= 
+		       (2*the_delta_in_ticks)) && (my_ip != 0))) &&
+		    ((jiffies - slave->jiffies) >= 2*the_delta_in_ticks)) {
+
+			slave->link  = BOND_LINK_DOWN;
+			if (slave->link_failure_count < UINT_MAX) {
+				slave->link_failure_count++;
+			}
+			printk(KERN_INFO "%s: link status down for "
+					 "active interface %s, disabling it",
+			       master->name,
+			       slave->dev->name);
+			slave = change_active_interface(bond);
+			bond->current_arp_slave = slave;
+			if (slave != NULL) {
+				slave->jiffies = jiffies;
+			}
+
+		} else if ((bond->primary_slave != NULL) && 
+			   (bond->primary_slave != slave) && 
+			   (bond->primary_slave->link == BOND_LINK_UP)) {
+			/* at this point, slave is the current_slave */
+			printk(KERN_INFO 
+			       "%s: changing from interface %s to primary "
+			       "interface %s\n",
+			       master->name, 
+			       slave->dev->name, 
+			       bond->primary_slave->dev->name);
+			       
+			/* primary is up so switch to it */
+			bond_set_slave_inactive_flags(slave);
+			bond_mc_update(bond, bond->primary_slave, slave);
+			write_lock(&bond->ptrlock);
+			bond->current_slave = bond->primary_slave;
+			write_unlock(&bond->ptrlock);
+			slave = bond->primary_slave;
+			bond_set_slave_active_flags(slave);
+			slave->jiffies = jiffies;
+		} else {
+			bond->current_arp_slave = NULL;
+		}
 
-		/* 
-		 * ok, we know up/down, so just send a arp out if there has
-		 * been no activity for a while 
+		/* the current slave must tx an arp to ensure backup slaves
+		 * rx traffic
 		 */
+		if ((slave != NULL) &&
+		    (((jiffies - slave->dev->last_rx) >= the_delta_in_ticks) &&
+		     (my_ip != 0))) {
+		  arp_send_all(slave);
+		}
+	}
 
-		if (slave != NULL ) {
-			if ( ((jiffies - slave->dev->trans_start) >= 
-			       the_delta_in_ticks) || 
-			     ((jiffies - slave->dev->last_rx) >= 
-			       the_delta_in_ticks) ) {
-				arp_send(ARPOP_REQUEST, ETH_P_ARP, 
-					 arp_target, slave->dev,
-					 my_ip, arp_target_hw_addr, 
-					 slave->dev->dev_addr, 
-					 arp_target_hw_addr); 
-			}
+	/* if we don't have a current_slave, search for the next available 
+	 * backup slave from the current_arp_slave and make it the candidate 
+	 * for becoming the current_slave
+	 */
+	if (slave == NULL) { 
+
+		if ((bond->current_arp_slave == NULL) ||
+		    (bond->current_arp_slave == (slave_t *)bond)) {
+			bond->current_arp_slave = bond->prev;
 		} 
 
-	}
+		if (bond->current_arp_slave != (slave_t *)bond) {
+			bond_set_slave_inactive_flags(bond->current_arp_slave);
+			slave = bond->current_arp_slave->next;
+
+			/* search for next candidate */
+			do {
+				if (IS_UP(slave->dev)) {
+					slave->link = BOND_LINK_BACK;
+					bond_set_slave_active_flags(slave);
+					arp_send_all(slave);
+					slave->jiffies = jiffies;
+					bond->current_arp_slave = slave;
+					break;
+				}
 
-	/* if we have no current slave.. try sending 
-	 * an arp on all of the interfaces 
-	 */
+				/* if the link state is up at this point, we 
+				 * mark it down - this can happen if we have 
+				 * simultaneous link failures and 
+				 * change_active_interface doesn't make this 
+				 * one the current slave so it is still marked 
+				 * up when it is actually down
+				 */
+				if (slave->link == BOND_LINK_UP) {
+					slave->link  = BOND_LINK_DOWN;
+					if (slave->link_failure_count < 
+							UINT_MAX) {
+						slave->link_failure_count++;
+					}
 
-	read_lock(&bond->ptrlock);
-	if (bond->current_slave == NULL) { 
-		read_unlock(&bond->ptrlock);
-		slave = (slave_t *)bond;
-		while ((slave = slave->prev) != (slave_t *)bond)   {
-			arp_send(ARPOP_REQUEST, ETH_P_ARP, arp_target, 
-				 slave->dev, my_ip, arp_target_hw_addr, 
-				 slave->dev->dev_addr, arp_target_hw_addr); 
+					bond_set_slave_inactive_flags(slave);
+					printk(KERN_INFO
+						"%s: backup interface "
+						"%s is now down.\n",
+						master->name,
+						slave->dev->name);
+				}
+			} while ((slave = slave->next) != 
+					bond->current_arp_slave->next);
 		}
 	}
-	else {
-		read_unlock(&bond->ptrlock);
-	}
-
-	rtnl_exunlock();
-	rtnl_shunlock();
-
-arp_monitor_out:
-	read_unlock_irqrestore(&bond->lock, flags);
 
-	/* re-arm the timer */
 	mod_timer(&bond->arp_timer, next_timer);
+	read_unlock_irqrestore(&bond->lock, flags);
 }
 
+
 #define isdigit(c) (c >= '0' && c <= '9')
 __inline static int atoi( char **s) 
 {
@@ -1720,7 +2312,7 @@
 	}
 	read_unlock_irqrestore(&bond->lock, flags);
 
-	if (cur_ndx == info->slave_id) {
+	if (slave != (slave_t *)bond) {
 		strcpy(info->slave_name, slave->dev->name);
 		info->link = slave->link;
 		info->state = slave->state;
@@ -1737,7 +2329,7 @@
 	struct net_device *slave_dev = NULL;
 	struct ifbond *u_binfo = NULL, k_binfo;
 	struct ifslave *u_sinfo = NULL, k_sinfo;
-	u16 *data = NULL;
+	struct mii_ioctl_data *mii = NULL;
 	int ret = 0;
 
 #ifdef BONDING_DEBUG
@@ -1747,23 +2339,23 @@
 
 	switch (cmd) {
 	case SIOCGMIIPHY:
-		data = (u16 *)ifr->ifr_data;
-		if (data == NULL) {
+		mii = (struct mii_ioctl_data *)&ifr->ifr_data;
+		if (mii == NULL) {
 			return -EINVAL;
 		}
-		data[0] = 0;
+		mii->phy_id = 0;
 		/* Fall Through */
 	case SIOCGMIIREG:
 		/* 
 		 * We do this again just in case we were called by SIOCGMIIREG
 		 * instead of SIOCGMIIPHY.
 		 */
-		data = (u16 *)ifr->ifr_data;
-		if (data == NULL) {
+		mii = (struct mii_ioctl_data *)&ifr->ifr_data;
+		if (mii == NULL) {
 			return -EINVAL;
 		}
-		if (data[1] == 1) {
-			data[3] = bond_check_mii_link(
+		if (mii->reg_num == 1) {
+			mii->val_out = bond_check_mii_link(
 				(struct bonding *)master_dev->priv);
 		}
 		return 0;
@@ -1846,6 +2438,65 @@
 }
 #endif
 
+/* 
+ * in broadcast mode, we send everything to all usable interfaces.
+ */
+static int bond_xmit_broadcast(struct sk_buff *skb, struct net_device *dev)
+{
+	slave_t *slave, *start_at;
+	struct bonding *bond = (struct bonding *) dev->priv;
+	unsigned long flags;
+	struct net_device *device_we_should_send_to = 0;
+
+	if (!IS_UP(dev)) { /* bond down */
+		dev_kfree_skb(skb);
+		return 0;
+	}
+
+	read_lock_irqsave(&bond->lock, flags);
+
+	read_lock(&bond->ptrlock);
+	slave = start_at = bond->current_slave;
+	read_unlock(&bond->ptrlock);
+
+	if (slave == NULL) { /* we're at the root, get the first slave */
+		/* no suitable interface, frame not sent */
+		read_unlock_irqrestore(&bond->lock, flags);
+		dev_kfree_skb(skb);
+		return 0;
+	}
+
+	do {
+		if (IS_UP(slave->dev)
+		    && (slave->link == BOND_LINK_UP)
+		    && (slave->state == BOND_STATE_ACTIVE)) {
+			if (device_we_should_send_to) {
+				struct sk_buff *skb2;
+				if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL) {
+					printk(KERN_ERR "bond_xmit_broadcast: skb_clone() failed\n");
+					continue;
+				}
+
+				skb2->dev = device_we_should_send_to;
+				skb2->priority = 1;
+				dev_queue_xmit(skb2);
+			}
+			device_we_should_send_to = slave->dev;
+		}
+	} while ((slave = slave->next) != start_at);
+
+	if (device_we_should_send_to) {
+		skb->dev = device_we_should_send_to;
+		skb->priority = 1;
+		dev_queue_xmit(skb);
+	} else
+		dev_kfree_skb(skb);
+
+	/* frame sent to all suitable interfaces */
+	read_unlock_irqrestore(&bond->lock, flags);
+	return 0;
+}
+
 static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *dev)
 {
 	slave_t *slave, *start_at;
@@ -1978,14 +2629,25 @@
 	}
 
 	/* if we are sending arp packets and don't know 
-	   the target hw address, save it so we don't need 
-	   to use a broadcast address */
-	if ( (arp_interval > 0) && (arp_target_hw_addr == NULL) &&
+	 * the target hw address, save it so we don't need 
+	 * to use a broadcast address.
+	 * don't do this if in active backup mode because the slaves must 
+	 * receive packets to stay up, and the only ones they receive are 
+	 * broadcasts. 
+	 */
+	if ( (mode != BOND_MODE_ACTIVEBACKUP) && 
+             (arp_ip_count == 1) &&
+	     (arp_interval > 0) && (arp_target_hw_addr == NULL) &&
 	     (skb->protocol == __constant_htons(ETH_P_IP) ) ) {
 		struct ethhdr *eth_hdr = 
 			(struct ethhdr *) (((char *)skb->data));
-		arp_target_hw_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
-		memcpy(arp_target_hw_addr, eth_hdr->h_dest, ETH_ALEN);
+		struct iphdr *ip_hdr = (struct iphdr *)(eth_hdr + 1);
+
+		if (arp_target[0] == ip_hdr->daddr) {
+			arp_target_hw_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
+			if (arp_target_hw_addr != NULL)
+				memcpy(arp_target_hw_addr, eth_hdr->h_dest, ETH_ALEN);
+		}
 	}
 
 	read_lock_irqsave(&bond->lock, flags);
@@ -2074,29 +2736,7 @@
 		 */
 		link = bond_check_mii_link(bond);
 
-		len += sprintf(buf + len, "Bonding Mode: ");
-
-		switch (mode) {
-			case BOND_MODE_ACTIVEBACKUP:
-				len += sprintf(buf + len, "%s\n", 
-						"active-backup");
-			break;
-
-			case BOND_MODE_ROUNDROBIN:
-				len += sprintf(buf + len, "%s\n", 
-						"load balancing (round-robin)");
-			break;
-
-			case BOND_MODE_XOR:
-				len += sprintf(buf + len, "%s\n", 
-						"load balancing (xor)");
-			break;
-
-			default:
-				len += sprintf(buf + len, "%s\n", 
-						"unknown");
-			break;
-		}
+		len += sprintf(buf + len, "Bonding Mode: %s\n", bond_mode());
 
 		if (mode == BOND_MODE_ACTIVEBACKUP) {
 			read_lock_irqsave(&bond->lock, flags);
@@ -2115,8 +2755,11 @@
 				link == BMSR_LSTATUS ? "up\n" : "down\n");
 		len += sprintf(buf + len, "MII Polling Interval (ms): %d\n", 
 				miimon);
-		len += sprintf(buf + len, "Up Delay (ms): %d\n", updelay);
-		len += sprintf(buf + len, "Down Delay (ms): %d\n", downdelay);
+		len += sprintf(buf + len, "Up Delay (ms): %d\n", 
+				updelay * miimon);
+		len += sprintf(buf + len, "Down Delay (ms): %d\n", 
+				downdelay * miimon);
+		len += sprintf(buf + len, "Multicast Mode: %s\n", multicast_mode());
 
 		read_lock_irqsave(&bond->lock, flags);
 		for (slave = bond->prev; slave != (slave_t *)bond; 
@@ -2205,6 +2848,7 @@
 static int __init bond_init(struct net_device *dev)
 {
 	bonding_t *bond, *this_bond, *last_bond;
+	int count;
 
 #ifdef BONDING_DEBUG
 	printk (KERN_INFO "Begin bond_init for %s\n", dev->name);
@@ -2228,6 +2872,7 @@
 
 	bond->next = bond->prev = (slave_t *)bond;
 	bond->current_slave = NULL;
+	bond->current_arp_slave = NULL;
 	bond->device = dev;
 	dev->priv = bond;
 
@@ -2238,6 +2883,8 @@
 		dev->hard_start_xmit = bond_xmit_roundrobin;
 	} else if (mode == BOND_MODE_XOR) {
 		dev->hard_start_xmit = bond_xmit_xor;
+	} else if (mode == BOND_MODE_BROADCAST) {
+		dev->hard_start_xmit = bond_xmit_broadcast;
 	} else {
 		printk(KERN_ERR "Unknown bonding mode %d\n", mode);
 		kfree(bond->stats);
@@ -2272,7 +2919,18 @@
 	} else {
 		printk("out MII link monitoring");
 	}
-	printk(", in %s mode.\n",mode?"active-backup":"bonding");
+	printk(", in %s mode.\n", bond_mode());
+
+	printk(KERN_INFO "%s registered with", dev->name);
+	if (arp_interval > 0) {
+		printk(" ARP monitoring set to %d ms with %d target(s):", 
+			arp_interval, arp_ip_count);
+		for (count=0 ; count<arp_ip_count ; count++)
+                        printk (" %s", arp_ip_target[count]);
+		printk("\n");
+	} else {
+		printk("out ARP monitoring\n");
+	}
 
 #ifdef CONFIG_PROC_FS
 	bond->bond_proc_dir = proc_mkdir(dev->name, proc_net);
@@ -2329,6 +2987,8 @@
 	/* Find a name for this unit */
 	static struct net_device *dev_bond = NULL;
 
+	printk(KERN_INFO "%s", version);
+
 	if (max_bonds < 1 || max_bonds > INT_MAX) {
 		printk(KERN_WARNING 
 		       "bonding_init(): max_bonds (%d) not in range %d-%d, "
@@ -2343,6 +3003,14 @@
 	}
 	memset(dev_bonds, 0, max_bonds*sizeof(struct net_device));
 
+	if (miimon < 0) {
+		printk(KERN_WARNING 
+		       "bonding_init(): miimon module parameter (%d), "
+		       "not in range 0-%d, so it was reset to %d\n",
+		       miimon, INT_MAX, BOND_LINK_MON_INTERV);
+		miimon = BOND_LINK_MON_INTERV;
+	}
+
 	if (updelay < 0) {
 		printk(KERN_WARNING 
 		       "bonding_init(): updelay module parameter (%d), "
@@ -2359,6 +3027,52 @@
 		downdelay = 0;
 	}
 
+	if (miimon == 0) {
+		if ((updelay != 0) || (downdelay != 0)) {
+			/* just warn the user the up/down delay will have
+			 * no effect since miimon is zero...
+			 */
+			printk(KERN_WARNING 
+		               "bonding_init(): miimon module parameter not "
+			       "set and updelay (%d) or downdelay (%d) module "
+			       "parameter is set; updelay and downdelay have "
+			       "no effect unless miimon is set\n",
+		               updelay, downdelay);
+		}
+	} else {
+		/* don't allow arp monitoring */
+		if (arp_interval != 0) {
+			printk(KERN_WARNING 
+		               "bonding_init(): miimon (%d) and arp_interval "
+			       "(%d) can't be used simultaneously, "
+			       "disabling ARP monitoring\n",
+		               miimon, arp_interval);
+			arp_interval = 0;
+		}
+
+		if ((updelay % miimon) != 0) {
+			/* updelay will be rounded in bond_init() when it
+			 * is divided by miimon, we just inform user here
+			 */
+			printk(KERN_WARNING 
+		               "bonding_init(): updelay (%d) is not a multiple "
+			       "of miimon (%d), updelay rounded to %d ms\n",
+		               updelay, miimon, (updelay / miimon) * miimon);
+		}
+
+		if ((downdelay % miimon) != 0) {
+			/* downdelay will be rounded in bond_init() when it
+			 * is divided by miimon, we just inform user here
+			 */
+			printk(KERN_WARNING 
+		               "bonding_init(): downdelay (%d) is not a "
+			       "multiple of miimon (%d), downdelay rounded "
+			       "to %d ms\n",
+		               downdelay, miimon, 
+			       (downdelay / miimon) * miimon);
+		}
+	}
+
 	if (arp_interval < 0) {
 		printk(KERN_WARNING 
 		       "bonding_init(): arp_interval module parameter (%d), "
@@ -2367,11 +3081,63 @@
 		arp_interval = BOND_LINK_ARP_INTERV;
 	}
 
-	if (arp_ip_target) {
-		/* TODO: check and log bad ip address */
-		if (my_inet_aton(arp_ip_target, &arp_target) == 0)  {
-			arp_interval = 0;
+        for (arp_ip_count=0 ;
+             (arp_ip_count < MAX_ARP_IP_TARGETS) && arp_ip_target[arp_ip_count];
+              arp_ip_count++ ) {
+                /* TODO: check and log bad ip address */
+                if (my_inet_aton(arp_ip_target[arp_ip_count],
+                                 &arp_target[arp_ip_count]) == 0) {
+                        printk(KERN_WARNING
+                               "bonding_init(): bad arp_ip_target module "
+                               "parameter (%s), ARP monitoring will not be "
+                               "performed\n",
+                               arp_ip_target[arp_ip_count]);
+                        arp_interval = 0;
 		}
+        }
+
+
+	if ( (arp_interval > 0) && (arp_ip_count==0)) {
+		/* don't allow arping if no arp_ip_target given... */
+		printk(KERN_WARNING 
+		       "bonding_init(): arp_interval module parameter "
+		       "(%d) specified without providing an arp_ip_target "
+		       "parameter, arp_interval was reset to 0\n",
+		       arp_interval);
+		arp_interval = 0;
+	}
+
+	if ((miimon == 0) && (arp_interval == 0)) {
+		/* miimon and arp_interval not set, we need one so things
+		 * work as expected, see bonding.txt for details
+		 */
+		printk(KERN_ERR 
+		       "bonding_init(): either miimon or "
+		       "arp_interval and arp_ip_target module parameters "
+		       "must be specified, otherwise bonding will not detect "
+		       "link failures! see bonding.txt for details.\n");
+	}
+
+	if ((primary != NULL) && (mode != BOND_MODE_ACTIVEBACKUP)){
+		/* currently, using a primary only makes sence 
+		 * in active backup mode 
+		 */
+		printk(KERN_WARNING 
+		       "bonding_init(): %s primary device specified but has "
+		       " no effect in %s mode\n",
+		       primary, bond_mode());
+		primary = NULL;
+	}
+
+
+        if (multicast != BOND_MULTICAST_DISABLED &&
+	    multicast != BOND_MULTICAST_ACTIVE &&
+	    multicast != BOND_MULTICAST_ALL) {
+		printk(KERN_WARNING 
+		       "bonding_init(): unknown multicast module "
+		       "parameter (%d), multicast reset to %d\n", 
+		       multicast, BOND_MULTICAST_ALL);
+		multicast = BOND_MULTICAST_ALL;
 	}
 
 	for (no = 0; no < max_bonds; no++) {
@@ -2420,6 +3186,7 @@
 module_init(bonding_init);
 module_exit(bonding_exit);
 MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION(DRV_DESCRIPTION ", v" DRV_VERSION);
 
 /*
  * Local variables:
diff -Nru a/drivers/net/hp100.c b/drivers/net/hp100.c
--- a/drivers/net/hp100.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/net/hp100.c	Mon Dec 23 21:21:53 2002
@@ -117,7 +117,6 @@
 #include <asm/bitops.h>
 #include <asm/io.h>
 
-#define LINUX_2_1
 typedef struct net_device_stats hp100_stats_t;
 
 #include "hp100.h"
@@ -285,7 +284,6 @@
 
 #define HP100_PCI_IDS_SIZE	(sizeof(hp100_pci_ids)/sizeof(struct hp100_pci_id))
 
-#if LINUX_VERSION_CODE >= 0x20400
 static struct pci_device_id hp100_pci_tbl[] __initdata = {
 	{PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2585A, PCI_ANY_ID, PCI_ANY_ID,},
 	{PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2585B, PCI_ANY_ID, PCI_ANY_ID,},
@@ -294,7 +292,6 @@
 	{}			/* Terminating entry */
 };
 MODULE_DEVICE_TABLE(pci, hp100_pci_tbl);
-#endif				/* LINUX_VERSION_CODE >= 0x20400 */
 
 static int hp100_rx_ratio = HP100_DEFAULT_RX_RATIO;
 static int hp100_priority_tx = HP100_DEFAULT_PRIORITY_TX;
@@ -356,8 +353,8 @@
  * address - Jean II */
 static inline dma_addr_t virt_to_whatever(struct net_device *dev, u32 * ptr)
 {
-  return ((u_long) ptr) +
-    ((struct hp100_private *) (dev->priv))->whatever_offset;
+	return ((u_long) ptr) +
+		((struct hp100_private *) (dev->priv))->whatever_offset;
 }
 
 /* TODO: This function should not really be needed in a good design... */
@@ -376,9 +373,7 @@
 {
 	int base_addr = dev ? dev->base_addr : 0;
 	int ioaddr = 0;
-#ifdef CONFIG_PCI
 	int pci_start_index = 0;
-#endif
 
 #ifdef HP100_DEBUG_B
 	hp100_outw(0x4200, TRACE);
@@ -854,7 +849,10 @@
 		printk("100Mb/s Voice Grade AnyLAN network.\n");
 		break;
 	case HP100_LAN_10:
-		printk("10Mb/s network.\n");
+		printk("10Mb/s network (10baseT).\n");
+		break;
+	case HP100_LAN_COAX:
+		printk("10Mb/s network (coax).\n");
 		break;
 	default:
 		printk("Warning! Link down.\n");
@@ -889,7 +887,7 @@
 		wait();
 	} else {
 		hp100_outw(HP100_INT_EN | HP100_RESET_LB, OPTION_LSW);
-		hp100_cascade_reset(dev, TRUE);
+		hp100_cascade_reset(dev, 1);
 		hp100_page(MAC_CTRL);
 		hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1);
 	}
@@ -900,7 +898,7 @@
 	wait();
 
 	/* Go into reset again. */
-	hp100_cascade_reset(dev, TRUE);
+	hp100_cascade_reset(dev, 1);
 
 	/* Set Option Registers to a safe state  */
 	hp100_outw(HP100_DEBUG_EN |
@@ -943,13 +941,13 @@
 	wait();			/* TODO: Do we really need this? */
 
 	/* Enable Hardware (e.g. unreset) */
-	hp100_cascade_reset(dev, FALSE);
+	hp100_cascade_reset(dev, 0);
 
 	/* ------- initialisation complete ----------- */
 
 	/* Finally try to log in the Hub if there may be a VG connection. */
-	if (lp->lan_type != HP100_LAN_10)
-		hp100_login_to_vg_hub(dev, FALSE);	/* relogin */
+	if ((lp->lan_type == HP100_LAN_100) || (lp->lan_type == HP100_LAN_ERR))
+		hp100_login_to_vg_hub(dev, 0);	/* relogin */
 }
 
 
@@ -1191,7 +1189,7 @@
 	hp100_stop_interface(dev);
 
 	if (lp->lan_type == HP100_LAN_100)
-		lp->hub_status = hp100_login_to_vg_hub(dev, FALSE);
+		lp->hub_status = hp100_login_to_vg_hub(dev, 0);
 
 	netif_stop_queue(dev);
 
@@ -1508,13 +1506,31 @@
 			hp100_andb(~HP100_BM_MASTER, BM);
 		}	/* end of shutdown procedure for non-etr parts */
 
-		hp100_cascade_reset(dev, TRUE);
+		hp100_cascade_reset(dev, 1);
 	}
 	hp100_page(PERFORMANCE);
 	/* hp100_outw( HP100_BM_READ | HP100_BM_WRITE | HP100_RESET_HB, OPTION_LSW ); */
 	/* Busmaster mode should be shut down now. */
 }
 
+static int hp100_check_lan(struct net_device *dev)
+{
+	struct hp100_private *lp = (struct hp100_private *) dev->priv;
+
+	if (lp->lan_type < 0) {	/* no LAN type detected yet? */
+		hp100_stop_interface(dev);
+		if ((lp->lan_type = hp100_sense_lan(dev)) < 0) {
+			printk("hp100: %s: no connection found - check wire\n", dev->name);
+			hp100_start_interface(dev);	/* 10Mb/s RX packets maybe handled */
+			return -EIO;
+		}
+		if (lp->lan_type == HP100_LAN_100)
+			lp->hub_status = hp100_login_to_vg_hub(dev, 0);	/* relogin */
+		hp100_start_interface(dev);
+	}
+	return 0;
+}
+
 /* 
  *  transmit functions
  */
@@ -1550,23 +1566,14 @@
 		if (jiffies - dev->trans_start < HZ)
 			return -EAGAIN;
 
-		if (lp->lan_type < 0) {	/* no LAN type detected yet? */
-			hp100_stop_interface(dev);
-			if ((lp->lan_type = hp100_sense_lan(dev)) < 0) {
-				printk("hp100: %s: no connection found - check wire\n", dev->name);
-				hp100_start_interface(dev);	/* 10Mb/s RX pkts maybe handled */
-				return -EIO;
-			}
-			if (lp->lan_type == HP100_LAN_100)
-				lp->hub_status = hp100_login_to_vg_hub(dev, FALSE);	/* relogin */
-			hp100_start_interface(dev);
-		}
+		if (hp100_check_lan(dev))
+			return -EIO;
 
 		if (lp->lan_type == HP100_LAN_100 && lp->hub_status < 0) {
 			/* we have a 100Mb/s adapter but it isn't connected to hub */
 			printk("hp100: %s: login to 100Mb/s hub retry\n", dev->name);
 			hp100_stop_interface(dev);
-			lp->hub_status = hp100_login_to_vg_hub(dev, FALSE);
+			lp->hub_status = hp100_login_to_vg_hub(dev, 0);
 			hp100_start_interface(dev);
 		} else {
 			spin_lock_irqsave(&lp->lock, flags);
@@ -1577,18 +1584,18 @@
 			if (i == HP100_LAN_ERR)
 				printk("hp100: %s: link down detected\n", dev->name);
 			else if (lp->lan_type != i) {	/* cable change! */
-				/* it's very hard - all network setting must be changed!!! */
+				/* it's very hard - all network settings must be changed!!! */
 				printk("hp100: %s: cable change 10Mb/s <-> 100Mb/s detected\n", dev->name);
 				lp->lan_type = i;
 				hp100_stop_interface(dev);
 				if (lp->lan_type == HP100_LAN_100)
-					lp->hub_status = hp100_login_to_vg_hub(dev, FALSE);
+					lp->hub_status = hp100_login_to_vg_hub(dev, 0);
 				hp100_start_interface(dev);
 			} else {
 				printk("hp100: %s: interface reset\n", dev->name);
 				hp100_stop_interface(dev);
 				if (lp->lan_type == HP100_LAN_100)
-					lp->hub_status = hp100_login_to_vg_hub(dev, FALSE);
+					lp->hub_status = hp100_login_to_vg_hub(dev, 0);
 				hp100_start_interface(dev);
 			}
 		}
@@ -1699,17 +1706,8 @@
 	if (skb->len <= 0)
 		return 0;
 
-	if (lp->lan_type < 0) {	/* no LAN type detected yet? */
-		hp100_stop_interface(dev);
-		if ((lp->lan_type = hp100_sense_lan(dev)) < 0) {
-			printk("hp100: %s: no connection found - check wire\n", dev->name);
-			hp100_start_interface(dev);	/* 10Mb/s RX packets maybe handled */
-			return -EIO;
-		}
-		if (lp->lan_type == HP100_LAN_100)
-			lp->hub_status = hp100_login_to_vg_hub(dev, FALSE);	/* relogin */
-		hp100_start_interface(dev);
-	}
+	if (hp100_check_lan(dev))
+		return -EIO;
 
 	/* If there is not enough free memory on the card... */
 	i = hp100_inl(TX_MEM_FREE) & 0x7fffffff;
@@ -1729,7 +1727,7 @@
 			/* we have a 100Mb/s adapter but it isn't connected to hub */
 			printk("hp100: %s: login to 100Mb/s hub retry\n", dev->name);
 			hp100_stop_interface(dev);
-			lp->hub_status = hp100_login_to_vg_hub(dev, FALSE);
+			lp->hub_status = hp100_login_to_vg_hub(dev, 0);
 			hp100_start_interface(dev);
 		} else {
 			spin_lock_irqsave(&lp->lock, flags);
@@ -1745,13 +1743,13 @@
 				lp->lan_type = i;
 				hp100_stop_interface(dev);
 				if (lp->lan_type == HP100_LAN_100)
-					lp->hub_status = hp100_login_to_vg_hub(dev, FALSE);
+					lp->hub_status = hp100_login_to_vg_hub(dev, 0);
 				hp100_start_interface(dev);
 			} else {
 				printk("hp100: %s: interface reset\n", dev->name);
 				hp100_stop_interface(dev);
 				if (lp->lan_type == HP100_LAN_100)
-					lp->hub_status = hp100_login_to_vg_hub(dev, FALSE);
+					lp->hub_status = hp100_login_to_vg_hub(dev, 0);
 				hp100_start_interface(dev);
 				mdelay(1);
 			}
@@ -2093,6 +2091,9 @@
 
 static void hp100_misc_interrupt(struct net_device *dev)
 {
+#ifdef HP100_DEBUG_B
+	int ioaddr = dev->base_addr;
+#endif
 	struct hp100_private *lp = (struct hp100_private *) dev->priv;
 
 #ifdef HP100_DEBUG_B
@@ -2220,7 +2221,7 @@
 #ifdef HP100_DEBUG
 			printk("hp100: %s: 100VG MAC settings have changed - relogin.\n", dev->name);
 #endif
-			lp->hub_status = hp100_login_to_vg_hub(dev, TRUE);	/* force a relogin to the hub */
+			lp->hub_status = hp100_login_to_vg_hub(dev, 1);	/* force a relogin to the hub */
 		}
 	} else {
 		int i;
@@ -2245,7 +2246,7 @@
 #ifdef HP100_DEBUG
 				printk("hp100: %s: 100VG MAC settings have changed - relogin.\n", dev->name);
 #endif
-				lp->hub_status = hp100_login_to_vg_hub(dev, TRUE);	/* force a relogin to the hub */
+				lp->hub_status = hp100_login_to_vg_hub(dev, 1);	/* force a relogin to the hub */
 			}
 		}
 	}
@@ -2539,7 +2540,7 @@
 		hp100_page(MAC_CTRL);
 		hp100_outb(val_10, 10_LAN_CFG_1);
 		hp100_page(PERFORMANCE);
-		return HP100_LAN_10;
+		return HP100_LAN_COAX;
 	}
 
 	if ((lp->id->id == 0x02019F022) ||
@@ -2685,7 +2686,7 @@
 	 */
 	hp100_page(MAC_CTRL);
 	startst = hp100_inb(VG_LAN_CFG_1);
-	if ((force_relogin == TRUE) || (hp100_inb(MAC_CFG_4) & HP100_MAC_SEL_ST)) {
+	if ((force_relogin == 1) || (hp100_inb(MAC_CFG_4) & HP100_MAC_SEL_ST)) {
 #ifdef HP100_DEBUG_TRAINING
 		printk("hp100: %s: Start training\n", dev->name);
 #endif
@@ -2847,7 +2848,7 @@
 	printk("hp100: %s: cascade_reset\n", dev->name);
 #endif
 
-	if (enable == TRUE) {
+	if (enable) {
 		hp100_outw(HP100_HW_RST | HP100_RESET_LB, OPTION_LSW);
 		if (lp->chip == HP100_CHIPID_LASSEN) {
 			/* Lassen requires a PCI transmit fifo reset */
diff -Nru a/drivers/net/hp100.h b/drivers/net/hp100.h
--- a/drivers/net/hp100.h	Mon Dec 23 21:21:50 2002
+++ b/drivers/net/hp100.h	Mon Dec 23 21:21:50 2002
@@ -518,11 +518,8 @@
  */
 #define HP100_LAN_100		100	/* lan_type value for VG */
 #define HP100_LAN_10		10	/* lan_type value for 10BaseT */
+#define HP100_LAN_COAX		9	/* lan_type value for Coax */
 #define HP100_LAN_ERR		(-1)	/* lan_type value for link down */
-
-#define TRUE 1
-#define FALSE 0
-
 
 /* 
  * Bus Master Data Structures  ----------------------------------------------
diff -Nru a/drivers/net/pppoe.c b/drivers/net/pppoe.c
--- a/drivers/net/pppoe.c	Mon Dec 23 21:21:57 2002
+++ b/drivers/net/pppoe.c	Mon Dec 23 21:21:57 2002
@@ -5,15 +5,15 @@
  * PPPoE --- PPP over Ethernet (RFC 2516)
  *
  *
- * Version:    0.6.11
+ * Version:	0.7.0
  *
  * 220102 :	Fix module use count on failure in pppoe_create, pppox_sk -acme
- * 030700 :     Fixed connect logic to allow for disconnect.
+ * 030700 :	Fixed connect logic to allow for disconnect.
  * 270700 :	Fixed potential SMP problems; we must protect against
  *		simultaneous invocation of ppp_input
  *		and ppp_unregister_channel.
  * 040800 :	Respect reference count mechanisms on net-devices.
- * 200800 :     fix kfree(skb) in pppoe_rcv (acme)
+ * 200800 :	fix kfree(skb) in pppoe_rcv (acme)
  *		Module reference count is decremented in the right spot now,
  *		guards against sock_put not actually freeing the sk
  *		in pppoe_release.
@@ -30,13 +30,14 @@
  *		the original skb that was passed in on success, never on
  *		failure.  Delete the copy of the skb on failure to avoid
  *		a memory leak.
- * 081001 :     Misc. cleanup (licence string, non-blocking, prevent
- *              reference of device on close).
- * 121301 :     New ppp channels interface; cannot unregister a channel
- *              from interrupts.  Thus, we mark the socket as a ZOMBIE
- *              and do the unregistration later.
+ * 081001 :	Misc. cleanup (licence string, non-blocking, prevent
+ *		reference of device on close).
+ * 121301 :	New ppp channels interface; cannot unregister a channel
+ *		from interrupts.  Thus, we mark the socket as a ZOMBIE
+ *		and do the unregistration later.
  * 081002 :	seq_file support for proc stuff -acme
- *
+ * 111602 :	Merge all 2.4 fixes into 2.5/2.6 tree.  Label 2.5/2.6
+ *		as version 0.7.  Spacing cleanup.
  * Author:	Michal Ostrowski <mostrows@speakeasy.net>
  * Contributors:
  * 		Arnaldo Carvalho de Melo <acme@conectiva.com.br>
@@ -381,8 +382,8 @@
  *
  ***********************************************************************/
 static int pppoe_rcv(struct sk_buff *skb,
-		      struct net_device *dev,
-		      struct packet_type *pt)
+		     struct net_device *dev,
+		     struct packet_type *pt)
 
 {
 	struct pppoe_hdr *ph = (struct pppoe_hdr *) skb->nh.raw;
@@ -398,7 +399,7 @@
 	}
 
 	sk = po->sk;
-        bh_lock_sock(sk);
+	bh_lock_sock(sk);
 
 	/* Socket state is unknown, must put skb into backlog. */
 	if (sock_owned_by_user(sk) != 0) {
@@ -443,8 +444,10 @@
 		 * what kind of SKB it is during backlog rcv.
 		 */
 		if (sock_owned_by_user(sk) == 0) {
+			/* We're no longer connect at the PPPOE layer,
+			 * and must wait for ppp channel to disconnect us.
+			 */
 			sk->state = PPPOX_ZOMBIE;
-			pppox_unbind_sock(sk);
 		}
 
 		bh_unlock_sock(sk);
@@ -583,8 +586,7 @@
 	if ((sk->state & PPPOX_CONNECTED) && sp->sa_addr.pppoe.sid)
 		goto end;
 
-	/* Check for already disconnected sockets,
-	   on attempts to disconnect */
+	/* Check for already disconnected sockets, on attempts to disconnect */
 	error = -EALREADY;
 	if((sk->state & PPPOX_DEAD) && !sp->sa_addr.pppoe.sid )
 		goto end;
@@ -596,7 +598,8 @@
 		/* Delete the old binding */
 		delete_item(po->pppoe_pa.sid,po->pppoe_pa.remote);
 
-		dev_put(po->pppoe_dev);
+		if(po->pppoe_dev)
+			dev_put(po->pppoe_dev);
 
 		memset(po, 0, sizeof(struct pppox_opt));
 		po->sk = sk;
@@ -994,7 +997,7 @@
 		   po->pppoe_pa.remote[2], po->pppoe_pa.remote[3],
 		   po->pppoe_pa.remote[4], po->pppoe_pa.remote[5], dev_name);
 out:
-  	return 0;
+	return 0;
 }
 
 static __inline__ struct pppox_opt *pppoe_get_idx(loff_t pos)
@@ -1064,10 +1067,10 @@
 }
 
 static struct file_operations pppoe_seq_fops = {
-	.open           = pppoe_seq_open,
-	.read           = seq_read,
-	.llseek         = seq_lseek,
-	.release        = seq_release,
+	.open		= pppoe_seq_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= seq_release,
 };
 #endif /* CONFIG_PROC_FS */
 
diff -Nru a/drivers/net/pppox.c b/drivers/net/pppox.c
--- a/drivers/net/pppox.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/net/pppox.c	Mon Dec 23 21:22:00 2002
@@ -5,9 +5,9 @@
  * PPPoE --- PPP over Ethernet (RFC 2516)
  *
  *
- * Version:	0.5.1
+ * Version:	0.5.2
  *
- * Author:	Michal Ostrowski <mostrows@styx.uwaterloo.ca>
+ * Author:	Michal Ostrowski <mostrows@speakeasy.net>
  *
  * 051000 :	Initialization cleanup
  *
@@ -56,8 +56,8 @@
 void unregister_pppox_proto(int proto_num)
 {
 	if (proto_num >= 0 && proto_num <= PX_MAX_PROTO) {
-	    proto[proto_num] = NULL;
-	    MOD_DEC_USE_COUNT;
+		proto[proto_num] = NULL;
+		MOD_DEC_USE_COUNT;
 	}
 }
 
@@ -65,9 +65,9 @@
 {
 	/* Clear connection to ppp device, if attached. */
 
-	if (sk->state & PPPOX_BOUND) {
+	if (sk->state & (PPPOX_BOUND|PPPOX_ZOMBIE)) {
 		ppp_unregister_channel(&pppox_sk(sk)->chan);
-		sk->state &= ~PPPOX_BOUND;
+		sk->state = PPPOX_DEAD;
 	}
 }
 
@@ -75,7 +75,7 @@
 EXPORT_SYMBOL(unregister_pppox_proto);
 EXPORT_SYMBOL(pppox_unbind_sock);
 
-static int pppox_ioctl(struct socket* sock, unsigned int cmd,
+static int pppox_ioctl(struct socket* sock, unsigned int cmd, 
 		       unsigned long arg)
 {
 	struct sock *sk = sock->sk;
@@ -117,10 +117,10 @@
 	int err = 0;
 
 	if (protocol < 0 || protocol > PX_MAX_PROTO)
-	    return -EPROTOTYPE;
+		return -EPROTOTYPE;
 
 	if (proto[protocol] == NULL)
-	    return -EPROTONOSUPPORT;
+		return -EPROTONOSUPPORT;
 
 	err = (*proto[protocol]->create)(sock);
 
diff -Nru a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
--- a/drivers/oprofile/buffer_sync.c	Mon Dec 23 21:21:52 2002
+++ b/drivers/oprofile/buffer_sync.c	Mon Dec 23 21:21:52 2002
@@ -19,17 +19,17 @@
  * objects.
  */
 
-#include <linux/fs.h>
 #include <linux/mm.h>
-#include <linux/timer.h>
-#include <linux/dcookies.h>
+#include <linux/workqueue.h>
 #include <linux/notifier.h>
+#include <linux/dcookies.h>
 #include <linux/profile.h>
-#include <linux/workqueue.h>
-
+#include <linux/fs.h>
+ 
+#include "oprofile_stats.h"
 #include "event_buffer.h"
 #include "cpu_buffer.h"
-#include "oprofile_stats.h"
+#include "buffer_sync.h"
  
 #define DEFAULT_EXPIRE (HZ / 4)
  
diff -Nru a/drivers/oprofile/cpu_buffer.c b/drivers/oprofile/cpu_buffer.c
--- a/drivers/oprofile/cpu_buffer.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/oprofile/cpu_buffer.c	Mon Dec 23 21:21:50 2002
@@ -19,13 +19,10 @@
 
 #include <linux/sched.h>
 #include <linux/vmalloc.h>
-#include <linux/smp.h>
 #include <linux/errno.h>
-#include <linux/cache.h>
  
 #include "cpu_buffer.h"
 #include "oprof.h"
-#include "oprofile_stats.h"
 
 struct oprofile_cpu_buffer cpu_buffer[NR_CPUS] __cacheline_aligned;
 
@@ -68,6 +65,7 @@
 		b->sample_received = 0;
 		b->sample_lost_locked = 0;
 		b->sample_lost_overflow = 0;
+		b->sample_lost_task_exit = 0;
 	}
 	return 0;
 fail:
@@ -92,9 +90,6 @@
 	struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[cpu];
 	struct task_struct * task;
 
-	/* temporary ? */
-	BUG_ON(!oprofile_started);
- 
 	cpu_buf->sample_received++;
  
 	if (!spin_trylock(&cpu_buf->int_lock)) {
diff -Nru a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
--- a/drivers/oprofile/event_buffer.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/oprofile/event_buffer.c	Mon Dec 23 21:21:50 2002
@@ -12,19 +12,15 @@
  * escape value ESCAPE_CODE followed by an identifying code.
  */
 
-#include <linux/fs.h>
-#include <linux/slab.h>
-#include <linux/sched.h>
 #include <linux/vmalloc.h>
-#include <linux/smp.h>
-#include <linux/dcookies.h>
 #include <linux/oprofile.h>
+#include <linux/sched.h>
+#include <linux/dcookies.h>
+#include <linux/fs.h>
 #include <asm/uaccess.h>
-#include <asm/atomic.h>
-
-#include "event_buffer.h"
-#include "cpu_buffer.h"
+ 
 #include "oprof.h"
+#include "event_buffer.h"
 #include "oprofile_stats.h"
 
 DECLARE_MUTEX(buffer_sem);
diff -Nru a/drivers/oprofile/event_buffer.h b/drivers/oprofile/event_buffer.h
--- a/drivers/oprofile/event_buffer.h	Mon Dec 23 21:21:51 2002
+++ b/drivers/oprofile/event_buffer.h	Mon Dec 23 21:21:51 2002
@@ -11,7 +11,7 @@
 #define EVENT_BUFFER_H
 
 #include <linux/types.h> 
-#include <linux/sem.h>
+#include <asm/semaphore.h>
  
 int alloc_event_buffer(void);
 
diff -Nru a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
--- a/drivers/oprofile/oprof.c	Mon Dec 23 21:21:52 2002
+++ b/drivers/oprofile/oprof.c	Mon Dec 23 21:21:52 2002
@@ -10,12 +10,8 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/init.h>
-#include <linux/mm.h>
-#include <linux/module.h>
-#include <linux/sched.h>
-#include <linux/notifier.h>
-#include <linux/profile.h>
 #include <linux/oprofile.h>
+#include <asm/semaphore.h>
 
 #include "oprof.h"
 #include "event_buffer.h"
@@ -82,11 +78,12 @@
 	if (oprofile_started)
 		goto out;
  
+	oprofile_reset_stats();
+
 	if ((err = oprofile_ops->start()))
 		goto out;
 
 	oprofile_started = 1;
-	oprofile_reset_stats();
 out:
 	up(&start_sem); 
 	return err;
@@ -148,6 +145,10 @@
 	oprofilefs_unregister();
 }
 
-MODULE_LICENSE("GPL");
+ 
 module_init(oprofile_init);
 module_exit(oprofile_exit);
+ 
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("John Levon <levon@movementarian.org>");
+MODULE_DESCRIPTION("OProfile system profiler");
diff -Nru a/drivers/oprofile/oprof.h b/drivers/oprofile/oprof.h
--- a/drivers/oprofile/oprof.h	Mon Dec 23 21:21:51 2002
+++ b/drivers/oprofile/oprof.h	Mon Dec 23 21:21:51 2002
@@ -10,9 +10,6 @@
 #ifndef OPROF_H
 #define OPROF_H
 
-#include <linux/spinlock.h>
-#include <linux/oprofile.h>
- 
 int oprofile_setup(void);
 void oprofile_shutdown(void); 
 
@@ -22,6 +19,8 @@
 int oprofile_start(void);
 void oprofile_stop(void);
 
+struct oprofile_operations;
+ 
 extern unsigned long fs_buffer_size;
 extern unsigned long fs_cpu_buffer_size;
 extern unsigned long fs_buffer_watershed;
@@ -29,6 +28,9 @@
 extern struct oprofile_operations * oprofile_ops;
 extern unsigned long oprofile_started;
  
+struct super_block;
+struct dentry;
+
 void oprofile_create_files(struct super_block * sb, struct dentry * root);
  
 #endif /* OPROF_H */
diff -Nru a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
--- a/drivers/oprofile/oprofile_files.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/oprofile/oprofile_files.c	Mon Dec 23 21:21:55 2002
@@ -7,26 +7,18 @@
  * @author John Levon <levon@movementarian.org>
  */
 
-#include <linux/oprofile.h>
 #include <linux/fs.h>
-#include <linux/slab.h>
-#include <asm/uaccess.h>
- 
-#include "oprof.h"
+#include <linux/oprofile.h>
+
 #include "event_buffer.h"
 #include "oprofile_stats.h"
+#include "oprof.h"
  
 unsigned long fs_buffer_size = 131072;
 unsigned long fs_cpu_buffer_size = 8192;
 unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */
 
  
-static int simple_open(struct inode * inode, struct file * filp)
-{
-	return 0;
-}
-
-
 static ssize_t cpu_type_read(struct file * file, char * buf, size_t count, loff_t * offset)
 {
 	unsigned long cpu_type = oprofile_cpu_type;
@@ -36,7 +28,6 @@
  
  
 static struct file_operations cpu_type_fops = {
-	.open		= simple_open,
 	.read		= cpu_type_read,
 };
  
@@ -71,15 +62,26 @@
 
  
 static struct file_operations enable_fops = {
-	.open		= simple_open,
 	.read		= enable_read,
 	.write		= enable_write,
 };
 
+
+static ssize_t dump_write(struct file *file, char const * buf, size_t count, loff_t * offset)
+{
+	wake_up_buffer_waiter();
+	return count;
+}
+
+
+static struct file_operations dump_fops = {
+	.write		= dump_write,
+};
  
 void oprofile_create_files(struct super_block * sb, struct dentry * root)
 {
 	oprofilefs_create_file(sb, root, "enable", &enable_fops);
+	oprofilefs_create_file(sb, root, "dump", &dump_fops);
 	oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
 	oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size);
 	oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
diff -Nru a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
--- a/drivers/oprofile/oprofilefs.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/oprofile/oprofilefs.c	Mon Dec 23 21:21:53 2002
@@ -12,12 +12,9 @@
 
 #include <linux/init.h>
 #include <linux/module.h>
-#include <linux/pagemap.h>
-#include <linux/fs.h>
-#include <linux/dcache.h>
-#include <linux/file.h>
-#include <linux/namei.h>
 #include <linux/oprofile.h>
+#include <linux/fs.h>
+#include <linux/pagemap.h>
 #include <asm/uaccess.h>
 
 #include "oprof.h"
diff -Nru a/drivers/pci/probe.c b/drivers/pci/probe.c
--- a/drivers/pci/probe.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/pci/probe.c	Mon Dec 23 21:21:58 2002
@@ -548,7 +548,7 @@
 	return 0;
 }
 
-struct pci_bus * __devinit pci_alloc_primary_bus(int bus)
+struct pci_bus * __devinit pci_alloc_primary_bus_parented(struct device *parent, int bus)
 {
 	struct pci_bus *b;
 
@@ -567,6 +567,7 @@
 	memset(b->dev,0,sizeof(*(b->dev)));
 	sprintf(b->dev->bus_id,"pci%d",bus);
 	strcpy(b->dev->name,"Host/PCI Bridge");
+	b->dev->parent = parent;
 	device_register(b->dev);
 
 	b->number = b->secondary = bus;
@@ -575,9 +576,9 @@
 	return b;
 }
 
-struct pci_bus * __devinit pci_scan_bus(int bus, struct pci_ops *ops, void *sysdata)
+struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent, int bus, struct pci_ops *ops, void *sysdata)
 {
-	struct pci_bus *b = pci_alloc_primary_bus(bus);
+	struct pci_bus *b = pci_alloc_primary_bus_parented(parent, bus);
 	if (b) {
 		b->sysdata = sysdata;
 		b->ops = ops;
diff -Nru a/drivers/pci/quirks.c b/drivers/pci/quirks.c
--- a/drivers/pci/quirks.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/pci/quirks.c	Mon Dec 23 21:21:50 2002
@@ -355,6 +355,26 @@
 		sis_apic_bug = 1;
 }
 
+#define AMD8131_revA0        0x01
+#define AMD8131_revB0        0x11
+#define AMD8131_MISC         0x40
+#define AMD8131_NIOAMODE_BIT 0
+
+static void __init quirk_amd_8131_ioapic(struct pci_dev *dev) 
+{ 
+        unsigned char revid, tmp;
+        
+        if (nr_ioapics == 0) 
+                return;
+
+        pci_read_config_byte(dev, PCI_REVISION_ID, &revid);
+        if (revid == AMD8131_revA0 || revid == AMD8131_revB0) {
+                printk(KERN_INFO "Fixing up AMD8131 IOAPIC mode\n"); 
+                pci_read_config_byte( dev, AMD8131_MISC, &tmp);
+                tmp &= ~(1 << AMD8131_NIOAMODE_BIT);
+                pci_write_config_byte( dev, AMD8131_MISC, tmp);
+        }
+} 
 
 #endif /* CONFIG_X86_IO_APIC */
 
@@ -563,6 +583,8 @@
 	{ PCI_FIXUP_FINAL,	PCI_VENDOR_ID_VIA,	PCI_DEVICE_ID_VIA_82C686,	quirk_via_ioapic },
 	{ PCI_FIXUP_FINAL, 	PCI_VENDOR_ID_AMD,	PCI_DEVICE_ID_AMD_VIPER_7410,	quirk_amd_ioapic },
 	{ PCI_FIXUP_FINAL,	PCI_VENDOR_ID_SI,	PCI_ANY_ID,			quirk_ioapic_rmw },
+        { PCI_FIXUP_FINAL,      PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_APIC,
+          quirk_amd_8131_ioapic }, 
 #endif
 	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_VIA,	PCI_DEVICE_ID_VIA_82C586_3,	quirk_via_acpi },
 	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_VIA,	PCI_DEVICE_ID_VIA_82C686_4,	quirk_via_acpi },
diff -Nru a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
--- a/drivers/pci/setup-bus.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/pci/setup-bus.c	Mon Dec 23 21:22:00 2002
@@ -48,23 +48,10 @@
 	for (ln=bus->devices.next; ln != &bus->devices; ln=ln->next) {
 		struct pci_dev *dev = pci_dev_b(ln);
 		u16 class = dev->class >> 8;
-		u16 cmd;
 
-		/* First, disable the device to avoid side
-		   effects of possibly overlapping I/O and
-		   memory ranges.
-		   Leave VGA enabled - for obvious reason. :-)
-		   Same with all sorts of bridges - they may
-		   have VGA behind them.  */
 		if (class == PCI_CLASS_DISPLAY_VGA
 				|| class == PCI_CLASS_NOT_DEFINED_VGA)
 			found_vga = 1;
-		else if (class >> 8 != PCI_BASE_CLASS_BRIDGE) {
-			pci_read_config_word(dev, PCI_COMMAND, &cmd);
-			cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY
-						| PCI_COMMAND_MASTER);
-			pci_write_config_word(dev, PCI_COMMAND, cmd);
-		}
 
 		pdev_sort_resources(dev, &head);
 	}
@@ -387,7 +374,6 @@
 pci_assign_unassigned_resources(void)
 {
 	struct list_head *ln;
-	struct pci_dev *dev;
 
 	/* Depth first, calculate sizes and alignments of all
 	   subordinate buses. */
@@ -396,8 +382,4 @@
 	/* Depth last, allocate resources and update the hardware. */
 	for(ln=pci_root_buses.next; ln != &pci_root_buses; ln=ln->next)
 		pci_bus_assign_resources(pci_bus_b(ln));
-
-	pci_for_each_dev(dev) {
-		pdev_enable_device(dev);
-	}
 }
diff -Nru a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
--- a/drivers/pci/setup-res.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/pci/setup-res.c	Mon Dec 23 21:22:00 2002
@@ -183,57 +183,3 @@
 		}
 	}
 }
-
-void __init
-pdev_enable_device(struct pci_dev *dev)
-{
-	u32 reg;
-	u16 cmd;
-	int i;
-
-	DBGC((KERN_ERR "PCI enable device: (%s)\n", dev->name));
-
-	pci_read_config_word(dev, PCI_COMMAND, &cmd);
-
-	for (i = 0; i < PCI_NUM_RESOURCES; i++) {
-		struct resource *res = &dev->resource[i];
-
-		if (res->flags & IORESOURCE_IO)
-			cmd |= PCI_COMMAND_IO;
-		else if (res->flags & IORESOURCE_MEM)
-			cmd |= PCI_COMMAND_MEMORY;
-	}
-
-	/* Special case, disable the ROM.  Several devices act funny
-	   (ie. do not respond to memory space writes) when it is left
-	   enabled.  A good example are QlogicISP adapters.  */
-
-	if (dev->rom_base_reg) {
-		pci_read_config_dword(dev, dev->rom_base_reg, &reg);
-		reg &= ~PCI_ROM_ADDRESS_ENABLE;
-		pci_write_config_dword(dev, dev->rom_base_reg, reg);
-		dev->resource[PCI_ROM_RESOURCE].flags &= ~PCI_ROM_ADDRESS_ENABLE;
-	}
-
-	/* All of these (may) have I/O scattered all around and may not
-	   use I/O base address registers at all.  So we just have to
-	   always enable IO to these devices.  */
-	if ((dev->class >> 8) == PCI_CLASS_NOT_DEFINED
-	    || (dev->class >> 8) == PCI_CLASS_NOT_DEFINED_VGA
-	    || (dev->class >> 8) == PCI_CLASS_STORAGE_IDE
-	    || (dev->class >> 16) == PCI_BASE_CLASS_DISPLAY) {
-		cmd |= PCI_COMMAND_IO;
-	}
-
-	/* Do not enable bus mastering.  A device could corrupt
-	 * system memory by DMAing before a driver is ready for it. */
-
-	/* Set the cache line and default latency (32).  */
-	pci_write_config_word(dev, PCI_CACHE_LINE_SIZE,
-			(32 << 8) | (L1_CACHE_BYTES / sizeof(u32)));
-
-	/* Enable the appropriate bits in the PCI command register.  */
-	pci_write_config_word(dev, PCI_COMMAND, cmd);
-
-	DBGC((KERN_ERR "  cmd reg 0x%x\n", cmd));
-}
diff -Nru a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c
--- a/drivers/scsi/53c700.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/scsi/53c700.c	Mon Dec 23 21:21:51 2002
@@ -238,39 +238,30 @@
 NCR_700_detect(Scsi_Host_Template *tpnt,
 	       struct NCR_700_Host_Parameters *hostdata)
 {
-	dma_addr_t pScript, pMemory, pSlots;
+	dma_addr_t pScript, pSlots;
 	__u8 *memory;
 	__u32 *script;
 	struct Scsi_Host *host;
 	static int banner = 0;
 	int j;
 
-#ifdef CONFIG_53C700_USE_CONSISTENT
-	memory = pci_alloc_consistent(hostdata->pci_dev, TOTAL_MEM_SIZE,
-				      &pMemory);
-	hostdata->consistent = 1;
-	if(memory == NULL ) {
-		printk(KERN_WARNING "53c700: consistent memory allocation failed\n");
-#endif
-		memory = kmalloc(TOTAL_MEM_SIZE, GFP_KERNEL);
-		if(memory == NULL) {
-			printk(KERN_ERR "53c700: Failed to allocate memory for driver, detatching\n");
-			return NULL;
-		}
-		pMemory = pci_map_single(hostdata->pci_dev, memory,
-					 TOTAL_MEM_SIZE, PCI_DMA_BIDIRECTIONAL);
-#ifdef CONFIG_53C700_USE_CONSISTENT
-		hostdata->consistent = 0;
+	memory = dma_alloc_noncoherent(hostdata->dev, TOTAL_MEM_SIZE,
+					 &pScript);
+	if(memory == NULL) {
+		printk(KERN_ERR "53c700: Failed to allocate memory for driver, detatching\n");
+		return NULL;
 	}
-#endif
+
 	script = (__u32 *)memory;
-	pScript = pMemory;
 	hostdata->msgin = memory + MSGIN_OFFSET;
 	hostdata->msgout = memory + MSGOUT_OFFSET;
 	hostdata->status = memory + STATUS_OFFSET;
+	/* all of these offsets are L1_CACHE_BYTES separated.  It is fatal
+	 * if this isn't sufficient separation to avoid dma flushing issues */
+	BUG_ON(!dma_is_consistent(pScript) && L1_CACHE_BYTES < dma_get_cache_alignment());
 	hostdata->slots = (struct NCR_700_command_slot *)(memory + SLOTS_OFFSET);
 		
-	pSlots = pMemory + SLOTS_OFFSET;
+	pSlots = pScript + SLOTS_OFFSET;
 
 	/* Fill in the missing routines from the host template */
 	tpnt->queuecommand = NCR_700_queuecommand;
@@ -327,7 +318,7 @@
 
 	hostdata->script = script;
 	hostdata->pScript = pScript;
-	NCR_700_dma_cache_wback((unsigned long)script, sizeof(SCRIPT));
+	dma_sync_single(hostdata->dev, pScript, sizeof(SCRIPT), DMA_TO_DEVICE);
 	hostdata->state = NCR_700_HOST_FREE;
 	hostdata->cmd = NULL;
 	host->max_id = 7;
@@ -363,18 +354,8 @@
 	struct NCR_700_Host_Parameters *hostdata = 
 		(struct NCR_700_Host_Parameters *)host->hostdata[0];
 
-#ifdef CONFIG_53C700_USE_CONSISTENT
-	if(hostdata->consistent) {
-		pci_free_consistent(hostdata->pci_dev, TOTAL_MEM_SIZE,
-				    hostdata->script, hostdata->pScript);
-	} else {
-#endif
-		pci_unmap_single(hostdata->pci_dev, hostdata->pScript,
-				 TOTAL_MEM_SIZE, PCI_DMA_BIDIRECTIONAL);
-		kfree(hostdata->script);
-#ifdef CONFIG_53C700_USE_CONSISTENT
-	}
-#endif
+	dma_free_noncoherent(hostdata->dev, TOTAL_MEM_SIZE,
+			       hostdata->script, hostdata->pScript);
 	return 1;
 }
 
@@ -575,15 +556,16 @@
 {
 	if(SCp->sc_data_direction != SCSI_DATA_NONE &&
 	   SCp->sc_data_direction != SCSI_DATA_UNKNOWN) {
-		int pci_direction = scsi_to_pci_dma_dir(SCp->sc_data_direction);
+		enum dma_data_direction direction = 
+			(enum dma_data_direction)scsi_to_pci_dma_dir(SCp->sc_data_direction);
 		if(SCp->use_sg) {
-			pci_unmap_sg(hostdata->pci_dev, SCp->buffer,
-				     SCp->use_sg, pci_direction);
+			dma_unmap_sg(hostdata->dev, SCp->buffer,
+				     SCp->use_sg, direction);
 		} else {
-			pci_unmap_single(hostdata->pci_dev,
+			dma_unmap_single(hostdata->dev,
 					 slot->dma_handle,
 					 SCp->request_bufflen,
-					 pci_direction);
+					 direction);
 		}
 	}
 }
@@ -600,8 +582,8 @@
 			(struct NCR_700_command_slot *)SCp->host_scribble;
 		
 		NCR_700_unmap(hostdata, SCp, slot);
-		pci_unmap_single(hostdata->pci_dev, slot->pCmd,
-				 sizeof(SCp->cmnd), PCI_DMA_TODEVICE);
+		dma_unmap_single(hostdata->dev, slot->pCmd,
+				 sizeof(SCp->cmnd), DMA_TO_DEVICE);
 		if(SCp->cmnd[0] == REQUEST_SENSE && SCp->cmnd[6] == NCR_700_INTERNAL_SENSE_MAGIC) {
 #ifdef NCR_700_DEBUG
 			printk(" ORIGINAL CMD %p RETURNED %d, new return is %d sense is\n",
@@ -819,7 +801,7 @@
 			printk(KERN_WARNING "scsi%d Unexpected SDTR msg\n",
 			       host->host_no);
 			hostdata->msgout[0] = A_REJECT_MSG;
-			NCR_700_dma_cache_wback((unsigned long)hostdata->msgout, 1);
+			dma_cache_sync(hostdata->msgout, 1, DMA_TO_DEVICE);
 			script_patch_16(hostdata->script, MessageCount, 1);
 			/* SendMsgOut returns, so set up the return
 			 * address */
@@ -831,7 +813,7 @@
 		printk(KERN_INFO "scsi%d: (%d:%d), Unsolicited WDTR after CMD, Rejecting\n",
 		       host->host_no, pun, lun);
 		hostdata->msgout[0] = A_REJECT_MSG;
-		NCR_700_dma_cache_wback((unsigned long)hostdata->msgout, 1);
+		dma_cache_sync(hostdata->msgout, 1, DMA_TO_DEVICE);
 		script_patch_16(hostdata->script, MessageCount, 1);
 		resume_offset = hostdata->pScript + Ent_SendMessageWithATN;
 
@@ -845,7 +827,7 @@
 		printk("\n");
 		/* just reject it */
 		hostdata->msgout[0] = A_REJECT_MSG;
-		NCR_700_dma_cache_wback((unsigned long)hostdata->msgout, 1);
+		dma_cache_sync(hostdata->msgout, 1, DMA_TO_DEVICE);
 		script_patch_16(hostdata->script, MessageCount, 1);
 		/* SendMsgOut returns, so set up the return
 		 * address */
@@ -923,7 +905,7 @@
 		printk("\n");
 		/* just reject it */
 		hostdata->msgout[0] = A_REJECT_MSG;
-		NCR_700_dma_cache_wback((unsigned long)hostdata->msgout, 1);
+		dma_cache_sync(hostdata->msgout, 1, DMA_TO_DEVICE);
 		script_patch_16(hostdata->script, MessageCount, 1);
 		/* SendMsgOut returns, so set up the return
 		 * address */
@@ -933,7 +915,7 @@
 	}
 	NCR_700_writel(temp, host, TEMP_REG);
 	/* set us up to receive another message */
-	NCR_700_dma_cache_inv((unsigned long)hostdata->msgin, MSG_ARRAY_SIZE);
+	dma_cache_sync(hostdata->msgin, MSG_ARRAY_SIZE, DMA_FROM_DEVICE);
 	return resume_offset;
 }
 
@@ -997,19 +979,17 @@
 				SCp->cmnd[7] = hostdata->status[0];
 				SCp->use_sg = 0;
 				SCp->sc_data_direction = SCSI_DATA_READ;
-				pci_dma_sync_single(hostdata->pci_dev,
-						    slot->pCmd,
-						    SCp->cmd_len,
-						    PCI_DMA_TODEVICE);
+				dma_sync_single(hostdata->dev, slot->pCmd,
+						SCp->cmd_len, DMA_TO_DEVICE);
 				SCp->request_bufflen = sizeof(SCp->sense_buffer);
-				slot->dma_handle = pci_map_single(hostdata->pci_dev, SCp->sense_buffer, sizeof(SCp->sense_buffer), PCI_DMA_FROMDEVICE);
+				slot->dma_handle = dma_map_single(hostdata->dev, SCp->sense_buffer, sizeof(SCp->sense_buffer), DMA_FROM_DEVICE);
 				slot->SG[0].ins = bS_to_host(SCRIPT_MOVE_DATA_IN | sizeof(SCp->sense_buffer));
 				slot->SG[0].pAddr = bS_to_host(slot->dma_handle);
 				slot->SG[1].ins = bS_to_host(SCRIPT_RETURN);
 				slot->SG[1].pAddr = 0;
 				slot->resume_offset = hostdata->pScript;
-				NCR_700_dma_cache_wback((unsigned long)slot->SG, sizeof(slot->SG[0])*2);
-				NCR_700_dma_cache_inv((unsigned long)SCp->sense_buffer, sizeof(SCp->sense_buffer));
+				dma_cache_sync(slot->SG, sizeof(slot->SG[0])*2, DMA_TO_DEVICE);
+				dma_cache_sync(SCp->sense_buffer, sizeof(SCp->sense_buffer), DMA_FROM_DEVICE);
 				
 				/* queue the command for reissue */
 				slot->state = NCR_700_SLOT_QUEUED;
@@ -1024,10 +1004,10 @@
 			//   SCp->cmnd[0] == INQUIRY && SCp->use_sg == 0) {
 			//	/* Piggy back the tag queueing support
 			//	 * on this command */
-			//	pci_dma_sync_single(hostdata->pci_dev,
+			//	dma_sync_single(hostdata->dev,
 			//			    slot->dma_handle,
 			//			    SCp->request_bufflen,
-			//			    PCI_DMA_FROMDEVICE);
+			//			    DMA_FROM_DEVICE);
 			//	if(((char *)SCp->request_buffer)[7] & 0x02) {
 			//		printk(KERN_INFO "scsi%d: (%d:%d) Enabling Tag Command Queuing\n", host->host_no, pun, lun);
 			//		hostdata->tag_negotiated |= (1<<SCp->target);
@@ -1137,14 +1117,14 @@
 			 * should therefore always clear ACK */
 			NCR_700_writeb(NCR_700_get_SXFER(hostdata->cmd->device),
 				       host, SXFER_REG);
-			NCR_700_dma_cache_inv((unsigned long)hostdata->msgin,
-				      MSG_ARRAY_SIZE);
-			NCR_700_dma_cache_wback((unsigned long)hostdata->msgout,
-					MSG_ARRAY_SIZE);
+			dma_cache_sync(hostdata->msgin,
+				       MSG_ARRAY_SIZE, DMA_FROM_DEVICE);
+			dma_cache_sync(hostdata->msgout,
+				       MSG_ARRAY_SIZE, DMA_TO_DEVICE);
 			/* I'm just being paranoid here, the command should
 			 * already have been flushed from the cache */
-			NCR_700_dma_cache_wback((unsigned long)slot->cmnd->cmnd,
-					slot->cmnd->cmd_len);
+			dma_cache_sync(slot->cmnd->cmnd,
+				       slot->cmnd->cmd_len, DMA_TO_DEVICE);
 
 
 			
@@ -1207,8 +1187,8 @@
 		hostdata->reselection_id = reselection_id;
 		/* just in case we have a stale simple tag message, clear it */
 		hostdata->msgin[1] = 0;
-		NCR_700_dma_cache_wback_inv((unsigned long)hostdata->msgin,
-					    MSG_ARRAY_SIZE);
+		dma_cache_sync(hostdata->msgin,
+			       MSG_ARRAY_SIZE, DMA_BIDIRECTIONAL);
 		if(hostdata->tag_negotiated & (1<<reselection_id)) {
 			resume_offset = hostdata->pScript + Ent_GetReselectionWithTag;
 		} else {
@@ -1323,7 +1303,8 @@
 	hostdata->cmd = NULL;
 	/* clear any stale simple tag message */
 	hostdata->msgin[1] = 0;
-	NCR_700_dma_cache_wback_inv((unsigned long)hostdata->msgin, MSG_ARRAY_SIZE);
+	dma_cache_sync(hostdata->msgin, MSG_ARRAY_SIZE,
+		       DMA_BIDIRECTIONAL);
 
 	if(id == 0xff) {
 		/* Selected as target, Ignore */
@@ -1434,10 +1415,11 @@
 	if(slot->resume_offset == 0)
 		slot->resume_offset = hostdata->pScript;
 	/* now perform all the writebacks and invalidates */
-	NCR_700_dma_cache_wback((unsigned long)hostdata->msgout, count);
-	NCR_700_dma_cache_inv((unsigned long)hostdata->msgin, MSG_ARRAY_SIZE);
-	NCR_700_dma_cache_wback((unsigned long)SCp->cmnd, SCp->cmd_len);
-	NCR_700_dma_cache_inv((unsigned long)hostdata->status, 1);
+	dma_cache_sync(hostdata->msgout, count, DMA_TO_DEVICE);
+	dma_cache_sync(hostdata->msgin, MSG_ARRAY_SIZE,
+		       DMA_FROM_DEVICE);
+	dma_cache_sync(SCp->cmnd, SCp->cmd_len, DMA_TO_DEVICE);
+	dma_cache_sync(hostdata->status, 1, DMA_FROM_DEVICE);
 
 	/* set the synchronous period/offset */
 	NCR_700_writeb(NCR_700_get_SXFER(SCp->device),
@@ -1606,7 +1588,7 @@
 					slot->SG[i].ins = bS_to_host(SCRIPT_NOP);
 					slot->SG[i].pAddr = 0;
 				}
-				NCR_700_dma_cache_wback((unsigned long)slot->SG, sizeof(slot->SG));
+				dma_cache_sync(slot->SG, sizeof(slot->SG), DMA_TO_DEVICE);
 				/* and pretend we disconnected after
 				 * the command phase */
 				resume_offset = hostdata->pScript + Ent_MsgInDuringData;
@@ -1755,7 +1737,7 @@
 	struct NCR_700_Host_Parameters *hostdata = 
 		(struct NCR_700_Host_Parameters *)SCp->host->hostdata[0];
 	__u32 move_ins;
-	int pci_direction;
+	enum dma_data_direction direction;
 	struct NCR_700_command_slot *slot;
 
 	if(hostdata->command_slot_count >= NCR_700_COMMAND_SLOTS_PER_HOST) {
@@ -1883,7 +1865,7 @@
 	}
 
 	/* now build the scatter gather list */
-	pci_direction = scsi_to_pci_dma_dir(SCp->sc_data_direction);
+	direction = (enum dma_data_direction)scsi_to_pci_dma_dir(SCp->sc_data_direction);
 	if(move_ins != 0) {
 		int i;
 		int sg_count;
@@ -1891,13 +1873,13 @@
 		__u32 count = 0;
 
 		if(SCp->use_sg) {
-			sg_count = pci_map_sg(hostdata->pci_dev, SCp->buffer,
-					      SCp->use_sg, pci_direction);
+			sg_count = dma_map_sg(hostdata->dev, SCp->buffer,
+					      SCp->use_sg, direction);
 		} else {
-			vPtr = pci_map_single(hostdata->pci_dev,
+			vPtr = dma_map_single(hostdata->dev,
 					      SCp->request_buffer, 
 					      SCp->request_bufflen,
-					      pci_direction);
+					      direction);
 			count = SCp->request_bufflen;
 			slot->dma_handle = vPtr;
 			sg_count = 1;
@@ -1920,14 +1902,14 @@
 		}
 		slot->SG[i].ins = bS_to_host(SCRIPT_RETURN);
 		slot->SG[i].pAddr = 0;
-		NCR_700_dma_cache_wback((unsigned long)slot->SG, sizeof(slot->SG));
+		dma_cache_sync(slot->SG, sizeof(slot->SG), DMA_TO_DEVICE);
 		DEBUG((" SETTING %08lx to %x\n",
 		       (&slot->pSG[i].ins), 
 		       slot->SG[i].ins));
 	}
 	slot->resume_offset = 0;
-	slot->pCmd = pci_map_single(hostdata->pci_dev, SCp->cmnd,
-				    sizeof(SCp->cmnd), PCI_DMA_TODEVICE);
+	slot->pCmd = dma_map_single(hostdata->dev, SCp->cmnd,
+				    sizeof(SCp->cmnd), DMA_TO_DEVICE);
 	NCR_700_start_command(SCp);
 	return 0;
 }
@@ -2018,5 +2000,3 @@
 EXPORT_SYMBOL(NCR_700_detect);
 EXPORT_SYMBOL(NCR_700_release);
 EXPORT_SYMBOL(NCR_700_intr);
-
-no_module_init;
diff -Nru a/drivers/scsi/53c700.h b/drivers/scsi/53c700.h
--- a/drivers/scsi/53c700.h	Mon Dec 23 21:21:51 2002
+++ b/drivers/scsi/53c700.h	Mon Dec 23 21:21:51 2002
@@ -45,25 +45,6 @@
 #error "Config.in must define either CONFIG_53C700_IO_MAPPED or CONFIG_53C700_MEM_MAPPED to use this scsi core."
 #endif
 
-/* macros for consistent memory allocation */
-
-#ifdef CONFIG_53C700_USE_CONSISTENT
-#define NCR_700_dma_cache_wback(mem, size) \
-	if(!hostdata->consistent) \
-		dma_cache_wback(mem, size)
-#define NCR_700_dma_cache_inv(mem, size) \
-	if(!hostdata->consistent) \
-		dma_cache_inv(mem, size)
-#define NCR_700_dma_cache_wback_inv(mem, size) \
-	if(!hostdata->consistent) \
-		dma_cache_wback_inv(mem, size)
-#else
-#define NCR_700_dma_cache_wback(mem, size) dma_cache_wback(mem,size)
-#define NCR_700_dma_cache_inv(mem, size) dma_cache_inv(mem,size)
-#define NCR_700_dma_cache_wback_inv(mem, size) dma_cache_wback_inv(mem,size)
-#endif
-
-
 struct NCR_700_Host_Parameters;
 
 /* These are the externally used routines */
@@ -215,7 +196,7 @@
 	/* These must be filled in by the calling driver */
 	int	clock;			/* board clock speed in MHz */
 	unsigned long	base;		/* the base for the port (copied to host) */
-	struct pci_dev	*pci_dev;
+	struct device	*dev;
 	__u32	dmode_extra;	/* adjustable bus settings */
 	__u32	differential:1;	/* if we are differential */
 #ifdef CONFIG_53C700_LE_ON_BE
@@ -229,10 +210,6 @@
 	/* NOTHING BELOW HERE NEEDS ALTERING */
 	__u32	fast:1;		/* if we can alter the SCSI bus clock
                                    speed (so can negiotiate sync) */
-#ifdef CONFIG_53C700_USE_CONSISTENT
-	__u32	consistent:1;
-#endif
-
 	int	sync_clock;	/* The speed of the SYNC core */
 
 	__u32	*script;		/* pointer to script location */
@@ -442,7 +419,7 @@
 	for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
 		__u32 val = bS_to_cpu((script)[A_##symbol##_used[i]]) + value; \
 		(script)[A_##symbol##_used[i]] = bS_to_host(val); \
-		dma_cache_wback((unsigned long)&(script)[A_##symbol##_used[i]], 4); \
+		dma_cache_sync(&(script)[A_##symbol##_used[i]], 4, DMA_TO_DEVICE); \
 		DEBUG((" script, patching %s at %d to 0x%lx\n", \
 		       #symbol, A_##symbol##_used[i], (value))); \
 	} \
@@ -453,7 +430,7 @@
 	int i; \
 	for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
 		(script)[A_##symbol##_used[i]] = bS_to_host(value); \
-		dma_cache_wback((unsigned long)&(script)[A_##symbol##_used[i]], 4); \
+		dma_cache_sync(&(script)[A_##symbol##_used[i]], 4, DMA_TO_DEVICE); \
 		DEBUG((" script, patching %s at %d to 0x%lx\n", \
 		       #symbol, A_##symbol##_used[i], (value))); \
 	} \
@@ -468,7 +445,7 @@
 		val &= 0xff00ffff; \
 		val |= ((value) & 0xff) << 16; \
 		(script)[A_##symbol##_used[i]] = bS_to_host(val); \
-		dma_cache_wback((unsigned long)&(script)[A_##symbol##_used[i]], 4); \
+		dma_cache_sync(&(script)[A_##symbol##_used[i]], 4, DMA_TO_DEVICE); \
 		DEBUG((" script, patching ID field %s at %d to 0x%x\n", \
 		       #symbol, A_##symbol##_used[i], val)); \
 	} \
@@ -482,7 +459,7 @@
 		val &= 0xffff0000; \
 		val |= ((value) & 0xffff); \
 		(script)[A_##symbol##_used[i]] = bS_to_host(val); \
-		dma_cache_wback((unsigned long)&(script)[A_##symbol##_used[i]], 4); \
+		dma_cache_sync(&(script)[A_##symbol##_used[i]], 4, DMA_TO_DEVICE); \
 		DEBUG((" script, patching short field %s at %d to 0x%x\n", \
 		       #symbol, A_##symbol##_used[i], val)); \
 	} \
diff -Nru a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
--- a/drivers/scsi/Kconfig	Mon Dec 23 21:22:00 2002
+++ b/drivers/scsi/Kconfig	Mon Dec 23 21:22:00 2002
@@ -277,15 +277,10 @@
 	tristate "Adaptec AACRAID support (EXPERIMENTAL)"
 	depends on EXPERIMENTAL && SCSI && PCI
 
-choice
-	prompt "Adaptec AIC7xxx support"
-	optional
-	depends on SCSI
-
-source "drivers/scsi/aic7xxx/Kconfig"
+source "drivers/scsi/aic7xxx/Kconfig.aic7xxx"
 
 config SCSI_AIC7XXX_OLD
-	tristate "Old driver"
+	tristate "Adaptec AIC7xxx support (old driver)"
 	help
 	  WARNING This driver is an older aic7xxx driver and is no longer
 	  under active development.  Adaptec, Inc. is writing a new driver to
@@ -325,8 +320,7 @@
 	  say M here and read <file:Documentation/modules.txt>.  The module
 	  will be called aic7xxx_old.o.
 
-endchoice
-
+source "drivers/scsi/aic7xxx/Kconfig.aic79xx"
 
 # All the I2O code and drivers do not seem to be 64bit safe.
 config SCSI_DPT_I2O
@@ -900,11 +894,6 @@
 	depends on SCSI_LASI700
 	default y
 
-config 53C700_USE_CONSISTENT
-	bool
-	depends on SCSI_LASI700
-	default y
-
 config SCSI_NCR53C7xx
 	tristate "NCR53c7,8xx SCSI support"
 	depends on SCSI && PCI
@@ -1550,24 +1539,18 @@
 	  say M here and read <file:Documentation/modules.txt>.  The module
 	  will be called nsp32.o.
 
-#
-# Note - this is a very special 'host' adapter that simulates the presence of some disks.
-# It can come in very handy for troubleshooting.  Anyone else is welcome to use it - all
-# you do is hack it to simulate the condition you want to test for, and then use it.
-#
-# The actual configuration in any kernel release could change at any time as I hack it to
-# simulate various conditions that I am testing.
-#
 config SCSI_DEBUG
-	tristate "SCSI debugging host simulator (EXPERIMENTAL)"
-	depends on EXPERIMENTAL && SCSI
+	tristate "SCSI debugging host simulator"
+	depends on SCSI
 	help
-	  This is a host adapter simulator that can be programmed to simulate
-	  a large number of conditions that could occur on a real bus. The
-	  advantage is that many hard to reproduce problems can be tested in a
-	  controlled environment where there is reduced risk of losing
-	  important data. This is primarily of use to people trying to debug
-	  the middle and upper layers of the SCSI subsystem. If unsure, say N.
+	  This is a host adapter simulator that can simulate multiple hosts
+	  each with multiple dummy SCSI devices (disks). It defaults to one
+	  host adapter with one dummy SCSI disk. Each dummy disk uses kernel
+	  RAM as storage (i.e. it is a ramdisk). To save space when multiple
+	  dummy disks are simulated, they share the same kernel RAM for 
+	  their storage. See http://www.torque.net/sg/sdebug.html for more
+	  information. This driver is primarily of use to those testing the
+	  SCSI and block subsystems. If unsure, say N.
 
 config SCSI_MESH
 	tristate "MESH (Power Mac internal SCSI) support"
diff -Nru a/drivers/scsi/NCR_D700.c b/drivers/scsi/NCR_D700.c
--- a/drivers/scsi/NCR_D700.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/scsi/NCR_D700.c	Mon Dec 23 21:21:51 2002
@@ -307,6 +307,7 @@
 			continue;
 		}
 		scsi_set_device(host, dev);
+		hostdata->dev = dev;
 		found++;
 	}
 	info->found += found;
diff -Nru a/drivers/scsi/aic7xxx/Kconfig b/drivers/scsi/aic7xxx/Kconfig
--- a/drivers/scsi/aic7xxx/Kconfig	Mon Dec 23 21:21:53 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,53 +0,0 @@
-config SCSI_AIC7XXX
-	tristate "New driver"
-	help
-	  This driver supports all of Adaptec's PCI based SCSI controllers
-	  (not the hardware RAID controllers though) as well as the aic7770
-	  based EISA and VLB SCSI controllers (the 274x and 284x series).
-	  This is an Adaptec sponsored driver written by Justin Gibbs.  It is
-	  intended to replace the previous aic7xxx driver maintained by Doug
-	  Ledford since Doug is no longer maintaining that driver.
-
-
-config AIC7XXX_CMDS_PER_DEVICE
-	int "Maximum number of TCQ commands per device"
-	depends on SCSI_AIC7XXX
-	default "253"
-	---help---
-	  Specify the number of commands you would like to allocate per SCSI
-	  device when Tagged Command Queueing (TCQ) is enabled on that device.
-
-	  This is an upper bound value for the number of tagged transactions
-	  to be used for any device.  The aic7xxx driver will automatically
-	  vary this number based on device behavior.  For devices with a
-	  fixed maximum, the driver will eventually lock to this maximum
-	  and display a console message inidicating this value.
-
-	  Note: Unless you experience some type of device failure, the default
-	  	value, no enforced limit, should work for you.
-
-	  Default: 253
-
-config AIC7XXX_RESET_DELAY_MS
-	int "Initial bus reset delay in milli-seconds"
-	depends on SCSI_AIC7XXX
-	default "15000"
-	help
-	  The number of milliseconds to delay after an initial bus reset.
-	  The bus settle delay following all error recovery actions is
-	  dictated by the SCSI layer and is not affected by this value.
-
-	  Default: 15000 (15 seconds)
-
-config AIC7XXX_BUILD_FIRMWARE
-	bool "Build Adapter Firmware with Kernel Build"
-	depends on SCSI_AIC7XXX
-	help
-	  This option should only be enabled if you are modifying the firmware
-	  source to the aic7xxx driver and wish to have the generated firmware
-	  include files updated during a normal kernel build.  The assembler
-	  for the firmware requires lex and yacc or their equivalents, as well
-	  as the db v1 library.  You may have to install additional packages
-	  or modify the assembler make file or the files it includes if your
-	  build environment is different than that of the author.
-
diff -Nru a/drivers/scsi/aic7xxx/Kconfig.aic79xx b/drivers/scsi/aic7xxx/Kconfig.aic79xx
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/Kconfig.aic79xx	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,96 @@
+#
+# AIC79XX 2.5.X Kernel configuration File.
+# $Id: //depot/linux-aic79xx-2.5.0/drivers/scsi/aic7xxx/Kconfig.aic79xx#2 $
+#
+config SCSI_AIC79XX
+	tristate "Adaptec AIC79xx U320 support"
+	depends on PCI
+	help
+	This driver supports all of Adaptec's Ultra 320 PCI-X
+	based SCSI controllers.
+
+config AIC79XX_CMDS_PER_DEVICE
+	int "Maximum number of TCQ commands per device"
+	depends on SCSI_AIC79XX
+	default "32"
+	---help---
+	Specify the number of commands you would like to allocate per SCSI
+	device when Tagged Command Queueing (TCQ) is enabled on that device.
+
+	This is an upper bound value for the number of tagged transactions
+	to be used for any device.  The aic7xxx driver will automatically
+	vary this number based on device behavior.  For devices with a
+	fixed maximum, the driver will eventually lock to this maximum
+	and display a console message inidicating this value.
+
+	Due to resource allocation issues in the Linux SCSI mid-layer, using
+	a high number of commands per device may result in memory allocation
+	failures when many devices are attached to the system.  For this reason,
+	the default is set to 32.  Higher values may result in higer performance
+	on some devices.  The upper bound is 253.  0 disables tagged queueing.
+
+	Per device tag depth can be controlled via the kernel command line
+	"tag_info" option.  See drivers/scsi/aic7xxx/README.aic79xx
+	for details.
+
+config AIC79XX_RESET_DELAY_MS
+	int "Initial bus reset delay in milli-seconds"
+	depends on SCSI_AIC79XX
+	default "15000"
+	---help---
+	The number of milliseconds to delay after an initial bus reset.
+	The bus settle delay following all error recovery actions is
+	dictated by the SCSI layer and is not affected by this value.
+
+	Default: 15000 (15 seconds)
+
+config AIC79XX_BUILD_FIRMWARE
+	bool "Build Adapter Firmware with Kernel Build"
+	depends on SCSI_AIC79XX
+	help
+	This option should only be enabled if you are modifying the firmware
+	source to the aic79xx driver and wish to have the generated firmware
+	include files updated during a normal kernel build.  The assembler
+	for the firmware requires lex and yacc or their equivalents, as well
+	as the db v1 library.  You may have to install additional packages
+	or modify the assembler Makefile or the files it includes if your
+	build environment is different than that of the author.
+
+config AIC79XX_ENABLE_RD_STRM
+	bool "Enable Read Streaming for All Targets"
+	depends on SCSI_AIC79XX
+	help
+	Read Streaming is a U320 protocol option that should enhance
+	performance.  Early U320 drive firmware actually performs slower
+	with read streaming enabled so it is disabled by default.  Read
+	Streaming can be configured in much the same way as tagged queueing
+	using the "rd_strm" command line option.  See
+	drivers/scsi/aic7xxx/README.aic79xx for details.
+
+config AIC79XX_DEBUG_ENABLE
+	bool "Compile in Debugging Code"
+	depends on SCSI_AIC79XX
+	default y
+	help
+	Compile in aic79xx debugging code that can be useful in diagnosing
+	driver errors.
+
+config AIC79XX_DEBUG_MASK
+        int "Debug code enable mask (16383 for all debugging)"
+        depends on SCSI_AIC79XX
+        default "0"
+        help
+	Bit mask of debug options that is only valid if the
+	CONFIG_AIC79XX_DEBUG_ENBLE option is enabled.  The bits in this mask
+	are defined in the drivers/scsi/aic7xxx/aic79xx.h - search for the
+	variable ahd_debug in that file to find them.
+
+config AIC79XX_REG_PRETTY_PRINT
+        bool "Decode registers during diagnostics"
+        depends on SCSI_AIC79XX
+	default y
+        help
+	Compile in register value tables for the output of expanded register
+	contents in diagnostics.  This make it much easier to understand debug
+	output without having to refer to a data book and/or the aic7xxx.reg
+	file.
diff -Nru a/drivers/scsi/aic7xxx/Kconfig.aic7xxx b/drivers/scsi/aic7xxx/Kconfig.aic7xxx
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/Kconfig.aic7xxx	Mon Dec 23 21:21:53 2002
@@ -0,0 +1,100 @@
+#
+# AIC7XXX and AIC79XX 2.5.X Kernel configuration File.
+# $Id: //depot/linux-aic79xx-2.5.0/drivers/scsi/aic7xxx/Kconfig.aic7xxx#4 $
+#
+config SCSI_AIC7XXX
+	tristate "Adaptec AIC7xxx Fast -> U160 support (New Driver)"
+	---help---
+	This driver supports all of Adaptec's Fast through Ultra 160 PCI
+	based SCSI controllers as well as the aic7770 based EISA and VLB
+	SCSI controllers (the 274x and 284x series).  For AAA and ARO based
+	configurations, only SCSI functionality is provided.
+
+	If you want to compile the driver as a module ( = code which can be
+	inserted in and removed from the running kernel whenever you want),
+	say M here and read <file:Documentation/modules.txt>.  The module
+	will be called aic7xxx.o.
+
+config AIC7XXX_CMDS_PER_DEVICE
+	int "Maximum number of TCQ commands per device"
+	depends on SCSI_AIC7XXX
+	default "32"
+	---help---
+	Specify the number of commands you would like to allocate per SCSI
+	device when Tagged Command Queueing (TCQ) is enabled on that device.
+
+	This is an upper bound value for the number of tagged transactions
+	to be used for any device.  The aic7xxx driver will automatically
+	vary this number based on device behavior.  For devices with a
+	fixed maximum, the driver will eventually lock to this maximum
+	and display a console message inidicating this value.
+
+	Due to resource allocation issues in the Linux SCSI mid-layer, using
+	a high number of commands per device may result in memory allocation
+	failures when many devices are attached to the system.  For this reason,
+	the default is set to 32.  Higher values may result in higer performance
+	on some devices.  The upper bound is 253.  0 disables tagged queueing.
+
+	Per device tag depth can be controlled via the kernel command line
+	"tag_info" option.  See drivers/scsi/aic7xxx/README.aic7xxx
+	for details.
+
+config AIC7XXX_RESET_DELAY_MS
+	int "Initial bus reset delay in milli-seconds"
+	depends on SCSI_AIC7XXX
+	default "15000"
+	---help---
+	The number of milliseconds to delay after an initial bus reset.
+	The bus settle delay following all error recovery actions is
+	dictated by the SCSI layer and is not affected by this value.
+
+	Default: 15000 (15 seconds)
+
+config AIC7XXX_PROBE_EISA_VL
+	bool "Probe for EISA and VL AIC7XXX Adapters"
+	help
+	Probe for EISA and VLB Aic7xxx controllers.  In many newer systems,
+	the invasive probes necessary to detect these controllers can cause
+	other devices to fail.  For this reason, the non-PCI probe code is
+	disabled by default.  The current value of this option can be "toggled"
+	via the no_probe kernel command line option.
+
+config AIC7XXX_BUILD_FIRMWARE
+	bool "Build Adapter Firmware with Kernel Build"
+	depends on SCSI_AIC7XXX
+	help
+	This option should only be enabled if you are modifying the firmware
+	source to the aic7xxx driver and wish to have the generated firmware
+	include files updated during a normal kernel build.  The assembler
+	for the firmware requires lex and yacc or their equivalents, as well
+	as the db v1 library.  You may have to install additional packages
+	or modify the assembler Makefile or the files it includes if your
+	build environment is different than that of the author.
+
+config AIC7XXX_DEBUG_ENABLE
+	bool "Compile in Debugging Code"
+	depends on SCSI_AIC7XXX
+	default y
+	help
+	Compile in aic7xxx debugging code that can be useful in diagnosing
+	driver errors.
+
+config AIC7XXX_DEBUG_MASK
+        int "Debug code enable mask (2047 for all debugging)"
+        depends on SCSI_AIC7XXX
+        default "0"
+        help
+	Bit mask of debug options that is only valid if the
+	CONFIG_AIC7XXX_DEBUG_ENBLE option is enabled.  The bits in this mask
+	are defined in the drivers/scsi/aic7xxx/aic7xxx.h - search for the
+	variable ahc_debug in that file to find them.
+
+config AIC7XXX_REG_PRETTY_PRINT
+        bool "Decode registers during diagnostics"
+        depends on SCSI_AIC7XXX
+	default y
+        help
+	Compile in register value tables for the output of expanded register
+	contents in diagnostics.  This make it much easier to understand debug
+	output without having to refer to a data book and/or the aic7xxx.reg
+	file.
diff -Nru a/drivers/scsi/aic7xxx/Makefile b/drivers/scsi/aic7xxx/Makefile
--- a/drivers/scsi/aic7xxx/Makefile	Mon Dec 23 21:22:01 2002
+++ b/drivers/scsi/aic7xxx/Makefile	Mon Dec 23 21:22:01 2002
@@ -1,47 +1,83 @@
 #
 # Makefile for the Linux aic7xxx SCSI driver.
 #
+# $Id: //depot/linux-aic79xx-2.5.0/drivers/scsi/aic7xxx/Makefile#3 $
+#
+
 # Let kbuild descend into aicasm when cleaning
 subdir-				+= aicasm
 
 obj-$(CONFIG_SCSI_AIC7XXX)	+= aic7xxx.o
+obj-$(CONFIG_SCSI_AIC79XX)	+= aic79xx.o
 
-# Core files
-aic7xxx-objs	+= aic7xxx_core.o aic7xxx_93cx6.o aic7770.o
-
-# Platform Specific Files
-aic7xxx-objs	+= aic7xxx_linux.o aic7xxx_proc.o aic7770_linux.o
-
-# PCI Specific Files
-ifeq ($(CONFIG_PCI),y)
-  # Core PCI files
-  aic7xxx-objs	+= aic7xxx_pci.o
-  # Platform Specific PCI Files
-  aic7xxx-objs	+= aic7xxx_linux_pci.o
-endif
+# Core Fast -> U160 files
+aic7xxx-y					+= aic7xxx_core.o	\
+						   aic7xxx_93cx6.o	\
+						   aic7770.o
+aic7xxx-$(CONFIG_PCI)				+= aic7xxx_pci.o
+aic7xxx-$(CONFIG_AIC7XXX_REG_PRETTY_PRINT)	+= aic7xxx_reg_print.o
+
+# Platform Specific Fast -> U160 Files
+aic7xxx-y					+= aic7xxx_osm.o	\
+						   aic7xxx_proc.o	\
+						   aic7770_osm.o
+aic7xxx-$(CONFIG_PCI)				+= aic7xxx_osm_pci.o
+
+# Core U320 files
+aic79xx-y					+= aic79xx_core.o	\
+						   aic79xx_pci.o
+aic79xx-$(CONFIG_AIC79XX_REG_PRETTY_PRINT)	+= aic79xx_reg_print.o
+
+# Platform Specific U320 Files
+aic79xx-y					+= aic79xx_osm.o	\
+						   aic79xx_proc.o	\
+						   aic79xx_osm_pci.o
 
+EXTRA_CFLAGS += -Idrivers/scsi
 #EXTRA_CFLAGS += -g
 
 # Files generated that shall be removed upon make clean
-clean-files := aic7xxx_seq.h aic7xxx_reg.h
+clean-files := aic7xxx_seq.h aic7xxx_reg.h aic7xxx_reg_print.c
+clean-files += aic79xx_seq.h aic79xx_reg.h aic79xx_reg_print.c
 
 # Dependencies for generated files need to be listed explicitly
 
 $(obj)/aic7xxx_core.o: $(obj)/aic7xxx_seq.h
+$(obj)/aic79xx_core.o: $(obj)/aic79xx_seq.h
 
-$(addprefix $(obj)/,$(aic7xxx-objs)): $(obj)/aic7xxx_reg.h
+$(addprefix $(obj)/,$(aic7xxx-y)): $(obj)/aic7xxx_reg.h
+$(addprefix $(obj)/,$(aic79xx-y)): $(obj)/aic79xx_reg.h
 
 ifeq ($(CONFIG_AIC7XXX_BUILD_FIRMWARE),y)
+aic7xxx_gen = $(obj)/aic7xxx_seq.h $(obj)/aic7xxx_reg.h
+ifeq ($(CONFIG_AIC7XXX_REG_PRETTY_PRINT),y)
+aic7xxx_gen += $(obj)/aic7xxx_reg_print.c
+aic7xxx_asm_cmd = $(obj)/aicasm/aicasm -I$(src) -r $(obj)/aic7xxx_reg.h \
+		 -p $(obj)/aic7xxx_reg_print.c -i aic7xxx_osm.h	   \
+		 -o $(obj)/aic7xxx_seq.h $(src)/aic7xxx.seq
+else
+aic7xxx_asm_cmd = $(obj)/aicasm/aicasm -I$(src) -r $(obj)/aic7xxx_reg.h \
+		 -o $(obj)/aic7xxx_seq.h $(src)/aic7xxx.seq
+endif
 
-$(obj)/aic7xxx_seq.h: $(src)/aic7xxx.seq $(src)/aic7xxx.reg \
-		      $(obj)/aicasm/aicasm
-	$(obj)/aicasm/aicasm -I$(obj) -r $(obj)/aic7xxx_reg.h \
-				 -o $(obj)/aic7xxx_seq.h $(src)/aic7xxx.seq
+$(aic7xxx_gen): $(src)/aic7xxx.seq $(src)/aic7xxx.reg $(obj)/aicasm/aicasm
+	$(aic7xxx_asm_cmd)
+endif
 
-$(obj)/aic7xxx_reg.h: $(obj)/aic7xxx_seq.h
+ifeq ($(CONFIG_AIC79XX_BUILD_FIRMWARE),y)
+aic79xx_gen = $(obj)/aic79xx_seq.h $(obj)/aic79xx_reg.h
+ifeq ($(CONFIG_AIC79XX_REG_PRETTY_PRINT),y)
+aic79xx_gen += $(obj)/aic79xx_reg_print.c
+aic79xx_asm_cmd = $(obj)/aicasm/aicasm -I$(src) -r $(obj)/aic79xx_reg.h \
+		 -p $(obj)/aic79xx_reg_print.c -i aic79xx_osm.h	   \
+		 -o $(obj)/aic79xx_seq.h $(src)/aic79xx.seq
+else
+aic79xx_asm_cmd = $(obj)/aicasm/aicasm -I$(src) -r $(obj)/aic79xx_reg.h \
+		 -o $(obj)/aic79xx_seq.h $(src)/aic79xx.seq
+endif
+$(aic79xx_gen): $(src)/aic79xx.seq $(src)/aic79xx.reg $(obj)/aicasm/aicasm
+	$(aic79xx_asm_cmd)
+endif 
 
 $(obj)/aicasm/aicasm: $(src)/aicasm/*.[chyl]
 	$(MAKE) -C $(src)/aicasm
-
-endif
-
diff -Nru a/drivers/scsi/aic7xxx/aic7770.c b/drivers/scsi/aic7xxx/aic7770.c
--- a/drivers/scsi/aic7xxx/aic7770.c	Mon Dec 23 21:22:01 2002
+++ b/drivers/scsi/aic7xxx/aic7770.c	Mon Dec 23 21:22:01 2002
@@ -37,22 +37,29 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $Id: //depot/aic7xxx/aic7xxx/aic7770.c#14 $
+ * $Id: //depot/aic7xxx/aic7xxx/aic7770.c#27 $
  *
- * $FreeBSD: src/sys/dev/aic7xxx/aic7770.c,v 1.1 2000/09/16 20:02:27 gibbs Exp $
+ * $FreeBSD$
  */
 
+#ifdef __linux__
 #include "aic7xxx_osm.h"
 #include "aic7xxx_inline.h"
 #include "aic7xxx_93cx6.h"
+#else
+#include <dev/aic7xxx/aic7xxx_osm.h>
+#include <dev/aic7xxx/aic7xxx_inline.h>
+#include <dev/aic7xxx/aic7xxx_93cx6.h>
+#endif
 
 #define ID_AIC7770	0x04907770
 #define ID_AHA_274x	0x04907771
 #define ID_AHA_284xB	0x04907756 /* BIOS enabled */
 #define ID_AHA_284x	0x04907757 /* BIOS disabled*/
-#define ID_AIC_7782	0x04907782
+#define	ID_OLV_274x	0x04907782 /* Olivetti OEM */
+#define	ID_OLV_274xD	0x04907783 /* Olivetti OEM (Differential) */
 
-static void aha2840_load_seeprom(struct ahc_softc *ahc);
+static int aha2840_load_seeprom(struct ahc_softc *ahc);
 static ahc_device_setup_t ahc_aic7770_VL_setup;
 static ahc_device_setup_t ahc_aic7770_EISA_setup;;
 static ahc_device_setup_t ahc_aic7770_setup;
@@ -72,18 +79,23 @@
 		"Adaptec 284X SCSI adapter",
 		ahc_aic7770_VL_setup
 	},
-	/* Generic chip probes for devices we don't know 'exactly' */
 	{
-		ID_AIC7770,
+		ID_OLV_274x,
 		0xFFFFFFFF,
-		"Adaptec aic7770 SCSI adapter",
+		"Adaptec (Olivetti OEM) 274X SCSI adapter",
+		ahc_aic7770_EISA_setup
+	},
+	{
+		ID_OLV_274xD,
+		0xFFFFFFFF,
+		"Adaptec (Olivetti OEM) 274X Differential SCSI adapter",
 		ahc_aic7770_EISA_setup
 	},
+	/* Generic chip probes for devices we don't know 'exactly' */
 	{
-		/* (Olivetti 2 channel EISA) */
-		ID_AIC_7782,
+		ID_AIC7770,
 		0xFFFFFFFF,
-		"Adaptec aic7782 SCSI adapter",
+		"Adaptec aic7770 SCSI adapter",
 		ahc_aic7770_EISA_setup
 	}
 };
@@ -104,21 +116,32 @@
 }
 
 int
-aic7770_config(struct ahc_softc *ahc, struct aic7770_identity *entry)
+aic7770_config(struct ahc_softc *ahc, struct aic7770_identity *entry, u_int io)
 {
+	u_long	l;
 	int	error;
+	int	have_seeprom;
 	u_int	hostconf;
 	u_int   irq;
 	u_int	intdef;
 
 	error = entry->setup(ahc);
+	have_seeprom = 0;
 	if (error != 0)
 		return (error);
 
-	error = aic7770_map_registers(ahc);
+	error = aic7770_map_registers(ahc, io);
 	if (error != 0)
 		return (error);
 
+	/*
+	 * Before we continue probing the card, ensure that
+	 * its interrupts are *disabled*.  We don't want
+	 * a misstep to hang the machine in an interrupt
+	 * storm.
+	 */
+	ahc_intr_enable(ahc, FALSE);
+
 	ahc->description = entry->name;
 	error = ahc_softc_init(ahc);
 
@@ -176,21 +199,22 @@
 					ahc->flags |= AHC_TERM_ENB_B;
 			}
 		}
-		/*
-		 * We have no way to tell, so assume extended
-		 * translation is enabled.
-		 */
-		ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B;
+		if ((ahc_inb(ahc, HA_274_BIOSGLOBAL) & HA_274_EXTENDED_TRANS))
+			ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B;
 		break;
 	}
 	case AHC_VL:
 	{
-		aha2840_load_seeprom(ahc);
+		have_seeprom = aha2840_load_seeprom(ahc);
 		break;
 	}
 	default:
 		break;
 	}
+	if (have_seeprom == 0) {
+		free(ahc->seep_config, M_DEVBUF);
+		ahc->seep_config = NULL;
+	}
 
 	/*
 	 * Ensure autoflush is enabled
@@ -209,24 +233,22 @@
 	if (error != 0)
 		return (error);
 
+	error = aic7770_map_int(ahc, irq);
+	if (error != 0)
+		return (error);
+
+	ahc_list_lock(&l);
 	/*
 	 * Link this softc in with all other ahc instances.
 	 */
 	ahc_softc_insert(ahc);
 
-	error = aic7770_map_int(ahc, irq);
-	if (error != 0)
-		return (error);
-
 	/*
 	 * Enable the board's BUS drivers
 	 */
 	ahc_outb(ahc, BCTL, ENABLE);
 
-	/*
-	 * Allow interrupts.
-	 */
-	ahc_intr_enable(ahc, TRUE);
+	ahc_list_unlock(&l);
 
 	return (0);
 }
@@ -234,14 +256,13 @@
 /*
  * Read the 284x SEEPROM.
  */
-static void
+static int
 aha2840_load_seeprom(struct ahc_softc *ahc)
 {
-	struct	  seeprom_descriptor sd;
-	struct	  seeprom_config sc;
-	uint16_t  checksum = 0;
-	uint8_t   scsi_conf;
-	int	  have_seeprom;
+	struct	seeprom_descriptor sd;
+	struct	seeprom_config *sc;
+	int	have_seeprom;
+	uint8_t scsi_conf;
 
 	sd.sd_ahc = ahc;
 	sd.sd_control_offset = SEECTL_2840;
@@ -254,23 +275,16 @@
 	sd.sd_CK = CK_2840;
 	sd.sd_DO = DO_2840;
 	sd.sd_DI = DI_2840;
+	sc = ahc->seep_config;
 
 	if (bootverbose)
 		printf("%s: Reading SEEPROM...", ahc_name(ahc));
-	have_seeprom = read_seeprom(&sd,
-				    (uint16_t *)&sc,
-				    /*start_addr*/0,
-				    sizeof(sc)/2);
+	have_seeprom = ahc_read_seeprom(&sd, (uint16_t *)sc,
+					/*start_addr*/0, sizeof(sc)/2);
 
 	if (have_seeprom) {
-		/* Check checksum */
-		int i;
-		int maxaddr = (sizeof(sc)/2) - 1;
-		uint16_t *scarray = (uint16_t *)&sc;
-
-		for (i = 0; i < maxaddr; i++)
-			checksum = checksum + scarray[i];
-		if (checksum != sc.checksum) {
+
+		if (ahc_verify_cksum(sc) == 0) {
 			if(bootverbose)
 				printf ("checksum error\n");
 			have_seeprom = 0;
@@ -288,41 +302,44 @@
 		 * Put the data we've collected down into SRAM
 		 * where ahc_init will find it.
 		 */
-		int i;
-		int max_targ = (ahc->features & AHC_WIDE) != 0 ? 16 : 8;
+		int	 i;
+		int	 max_targ;
 		uint16_t discenable;
 
+		max_targ = (ahc->features & AHC_WIDE) != 0 ? 16 : 8;
 		discenable = 0;
 		for (i = 0; i < max_targ; i++){
-	                uint8_t target_settings;
-			target_settings = (sc.device_flags[i] & CFXFER) << 4;
-			if (sc.device_flags[i] & CFSYNCH)
+			uint8_t target_settings;
+
+			target_settings = (sc->device_flags[i] & CFXFER) << 4;
+			if (sc->device_flags[i] & CFSYNCH)
 				target_settings |= SOFS;
-			if (sc.device_flags[i] & CFWIDEB)
+			if (sc->device_flags[i] & CFWIDEB)
 				target_settings |= WIDEXFER;
-			if (sc.device_flags[i] & CFDISC)
+			if (sc->device_flags[i] & CFDISC)
 				discenable |= (0x01 << i);
 			ahc_outb(ahc, TARG_SCSIRATE + i, target_settings);
 		}
 		ahc_outb(ahc, DISC_DSB, ~(discenable & 0xff));
 		ahc_outb(ahc, DISC_DSB + 1, ~((discenable >> 8) & 0xff));
 
-		ahc->our_id = sc.brtime_id & CFSCSIID;
+		ahc->our_id = sc->brtime_id & CFSCSIID;
 
 		scsi_conf = (ahc->our_id & 0x7);
-		if (sc.adapter_control & CFSPARITY)
+		if (sc->adapter_control & CFSPARITY)
 			scsi_conf |= ENSPCHK;
-		if (sc.adapter_control & CFRESETB)
+		if (sc->adapter_control & CFRESETB)
 			scsi_conf |= RESET_SCSI;
 
-		if (sc.bios_control & CF284XEXTEND)		
+		if (sc->bios_control & CF284XEXTEND)		
 			ahc->flags |= AHC_EXTENDED_TRANS_A;
 		/* Set SCSICONF info */
 		ahc_outb(ahc, SCSICONF, scsi_conf);
 
-		if (sc.adapter_control & CF284XSTERM)
+		if (sc->adapter_control & CF284XSTERM)
 			ahc->flags |= AHC_TERM_ENB_A;
 	}
+	return (have_seeprom);
 }
 
 static int
diff -Nru a/drivers/scsi/aic7xxx/aic7770_linux.c b/drivers/scsi/aic7xxx/aic7770_linux.c
--- a/drivers/scsi/aic7xxx/aic7770_linux.c	Mon Dec 23 21:22:00 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,153 +0,0 @@
-/*
- * Linux driver attachment glue for aic7770 based controllers.
- *
- * Copyright (c) 2000-2001 Adaptec Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7770_linux.c#9 $
- */
-
-#include "aic7xxx_osm.h"
-
-#define MINSLOT			1
-#define NUMSLOTS		16
-#define IDOFFSET		0x80
-
-int
-aic7770_linux_probe(Scsi_Host_Template *template)
-{
-#if defined(__i386__) || defined(__alpha__)
-	struct aic7770_identity *entry;
-	struct ahc_softc *ahc;
-	int i, slot;
-	int eisaBase;
-	int found;
-
-	if (aic7xxx_no_probe)
-		return (0);
-
-	eisaBase = 0x1000 + AHC_EISA_SLOT_OFFSET;
-	found = 0;
-	for (slot = 1; slot < NUMSLOTS; eisaBase+=0x1000, slot++) {
-		uint32_t eisa_id;
-		size_t	 id_size;
-
-		if (check_region(eisaBase, AHC_EISA_IOSIZE) != 0)
-			continue;
-
-		eisa_id = 0;
-		id_size = sizeof(eisa_id);
-		for (i = 0; i < 4; i++) {
-			/* VLcards require priming*/
-			outb(0x80 + i, eisaBase + IDOFFSET);
-			eisa_id |= inb(eisaBase + IDOFFSET + i)
-				   << ((id_size-i-1) * 8);
-		}
-		if (eisa_id & 0x80000000)
-			continue;  /* no EISA card in slot */
-
-		entry = aic7770_find_device(eisa_id);
-		if (entry != NULL) {
-			char	 buf[80];
-			char	*name;
-			int	 error;
-
-			/*
-			 * Allocate a softc for this card and
-			 * set it up for attachment by our
-			 * common detect routine.
-			 */
-			sprintf(buf, "ahc_eisa:%d", slot);
-			name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
-			if (name == NULL)
-				break;
-			strcpy(name, buf);
-			ahc = ahc_alloc(template, name);
-			if (ahc == NULL) {
-				/*
-				 * If we can't allocate this one,
-				 * chances are we won't be able to
-				 * allocate future card structures.
-				 */
-				break;
-			}
-			ahc->tag = BUS_SPACE_PIO;
-			ahc->bsh.ioport = eisaBase;
-			error = aic7770_config(ahc, entry);
-			if (error != 0) {
-				ahc_free(ahc);
-				continue;
-			}
-			found++;
-		}
-	}
-	return (found);
-#else
-	return (0);
-#endif
-}
-
-int
-aic7770_map_registers(struct ahc_softc *ahc)
-{
-	/*
-	 * Lock out other contenders for our i/o space.
-	 */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
-	request_region(ahc->bsh.ioport, AHC_EISA_IOSIZE, "aic7xxx");
-#else
-	if (request_region(ahc->bsh.ioport, AHC_EISA_IOSIZE, "aic7xxx") == 0)
-		return (ENOMEM);
-#endif
-
-	return (0);
-}
-
-int
-aic7770_map_int(struct ahc_softc *ahc, u_int irq)
-{
-	int error;
-	int shared;
-
-	shared = 0;
-	if ((ahc->flags & AHC_EDGE_INTERRUPT) == 0)
-		shared = SA_SHIRQ;
-
-	ahc->platform_data->irq = irq;
-	error = request_irq(ahc->platform_data->irq, ahc_linux_isr,
-			    shared, "aic7xxx", ahc);
-	
-	return (-error);
-}
diff -Nru a/drivers/scsi/aic7xxx/aic7770_osm.c b/drivers/scsi/aic7xxx/aic7770_osm.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aic7770_osm.c	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,150 @@
+/*
+ * Linux driver attachment glue for aic7770 based controllers.
+ *
+ * Copyright (c) 2000-2001 Adaptec Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7770_osm.c#11 $
+ */
+
+#include "aic7xxx_osm.h"
+
+#define MINSLOT			1
+#define NUMSLOTS		16
+#define IDOFFSET		0x80
+
+int
+aic7770_linux_probe(Scsi_Host_Template *template)
+{
+#if defined(__i386__) || defined(__alpha__)
+	struct aic7770_identity *entry;
+	struct ahc_softc *ahc;
+	int i, slot;
+	int eisaBase;
+	int found;
+
+	eisaBase = 0x1000 + AHC_EISA_SLOT_OFFSET;
+	found = 0;
+	for (slot = 1; slot < NUMSLOTS; eisaBase+=0x1000, slot++) {
+		uint32_t eisa_id;
+		size_t	 id_size;
+
+		if (check_region(eisaBase, AHC_EISA_IOSIZE) != 0)
+			continue;
+
+		eisa_id = 0;
+		id_size = sizeof(eisa_id);
+		for (i = 0; i < 4; i++) {
+			/* VLcards require priming*/
+			outb(0x80 + i, eisaBase + IDOFFSET);
+			eisa_id |= inb(eisaBase + IDOFFSET + i)
+				   << ((id_size-i-1) * 8);
+		}
+		if (eisa_id & 0x80000000)
+			continue;  /* no EISA card in slot */
+
+		entry = aic7770_find_device(eisa_id);
+		if (entry != NULL) {
+			char	 buf[80];
+			char	*name;
+			int	 error;
+
+			/*
+			 * Allocate a softc for this card and
+			 * set it up for attachment by our
+			 * common detect routine.
+			 */
+			sprintf(buf, "ahc_eisa:%d", slot);
+			name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
+			if (name == NULL)
+				break;
+			strcpy(name, buf);
+			ahc = ahc_alloc(template, name);
+			if (ahc == NULL) {
+				/*
+				 * If we can't allocate this one,
+				 * chances are we won't be able to
+				 * allocate future card structures.
+				 */
+				break;
+			}
+			error = aic7770_config(ahc, entry, eisaBase);
+			if (error != 0) {
+				ahc->bsh.ioport = 0;
+				ahc_free(ahc);
+				continue;
+			}
+			found++;
+		}
+	}
+	return (found);
+#else
+	return (0);
+#endif
+}
+
+int
+aic7770_map_registers(struct ahc_softc *ahc, u_int port)
+{
+	/*
+	 * Lock out other contenders for our i/o space.
+	 */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
+	request_region(port, AHC_EISA_IOSIZE, "aic7xxx");
+#else
+	if (request_region(port, AHC_EISA_IOSIZE, "aic7xxx") == 0)
+		return (ENOMEM);
+#endif
+	ahc->tag = BUS_SPACE_PIO;
+	ahc->bsh.ioport = port;
+	return (0);
+}
+
+int
+aic7770_map_int(struct ahc_softc *ahc, u_int irq)
+{
+	int error;
+	int shared;
+
+	shared = 0;
+	if ((ahc->flags & AHC_EDGE_INTERRUPT) == 0)
+		shared = SA_SHIRQ;
+
+	error = request_irq(irq, ahc_linux_isr, shared, "aic7xxx", ahc);
+	if (error == 0)
+		ahc->platform_data->irq = irq;
+	
+	return (-error);
+}
diff -Nru a/drivers/scsi/aic7xxx/aic79xx.h b/drivers/scsi/aic7xxx/aic79xx.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aic79xx.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,1480 @@
+/*
+ * Core definitions and data structures shareable across OS platforms.
+ *
+ * Copyright (c) 1994-2002 Justin T. Gibbs.
+ * Copyright (c) 2000-2002 Adaptec Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $Id: //depot/aic7xxx/aic7xxx/aic79xx.h#78 $
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _AIC79XX_H_
+#define _AIC79XX_H_
+
+/* Register Definitions */
+#include "aic79xx_reg.h"
+
+/************************* Forward Declarations *******************************/
+struct ahd_platform_data;
+struct scb_platform_data;
+
+/****************************** Useful Macros *********************************/
+#ifndef MAX
+#define MAX(a,b) (((a) > (b)) ? (a) : (b))
+#endif
+
+#ifndef MIN
+#define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#endif
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array))
+
+#define ALL_CHANNELS '\0'
+#define ALL_TARGETS_MASK 0xFFFF
+#define INITIATOR_WILDCARD	(~0)
+#define	SCB_LIST_NULL		0xFF00
+#define	SCB_LIST_NULL_LE	(ahd_htole16(SCB_LIST_NULL))
+#define QOUTFIFO_ENTRY_VALID 0x8000
+#define QOUTFIFO_ENTRY_VALID_LE (ahd_htole16(0x8000))
+#define SCBID_IS_NULL(scbid) (((scbid) & 0xFF00 ) == SCB_LIST_NULL)
+
+#define SCSIID_TARGET(ahd, scsiid)	\
+	(((scsiid) & TID) >> TID_SHIFT)
+#define SCSIID_OUR_ID(scsiid)		\
+	((scsiid) & OID)
+#define SCSIID_CHANNEL(ahd, scsiid) ('A')
+#define	SCB_IS_SCSIBUS_B(ahd, scb) (0)
+#define	SCB_GET_OUR_ID(scb) \
+	SCSIID_OUR_ID((scb)->hscb->scsiid)
+#define	SCB_GET_TARGET(ahd, scb) \
+	SCSIID_TARGET((ahd), (scb)->hscb->scsiid)
+#define	SCB_GET_CHANNEL(ahd, scb) \
+	SCSIID_CHANNEL(ahd, (scb)->hscb->scsiid)
+#define	SCB_GET_LUN(scb) \
+	((scb)->hscb->lun)
+#define SCB_GET_TARGET_OFFSET(ahd, scb)	\
+	SCB_GET_TARGET(ahd, scb)
+#define SCB_GET_TARGET_MASK(ahd, scb) \
+	(0x01 << (SCB_GET_TARGET_OFFSET(ahd, scb)))
+#ifdef AHD_DEBUG
+#define SCB_IS_SILENT(scb)					\
+	((ahd_debug & AHD_SHOW_MASKED_ERRORS) == 0		\
+      && (((scb)->flags & SCB_SILENT) != 0))
+#else
+#define SCB_IS_SILENT(scb)					\
+	(((scb)->flags & SCB_SILENT) != 0)
+#endif
+/*
+ * TCLs have the following format: TTTTLLLLLLLL
+ */
+#define TCL_TARGET_OFFSET(tcl) \
+	((((tcl) >> 4) & TID) >> 4)
+#define TCL_LUN(tcl) \
+	(tcl & (AHD_NUM_LUNS - 1))
+#define BUILD_TCL(scsiid, lun) \
+	((lun) | (((scsiid) & TID) << 4))
+#define BUILD_TCL_RAW(target, channel, lun) \
+	((lun) | ((target) << 8))
+
+#define SCB_GET_TAG(scb) \
+	ahd_le16toh(scb->hscb->tag)
+
+#ifndef	AHD_TARGET_MODE
+#undef	AHD_TMODE_ENABLE
+#define	AHD_TMODE_ENABLE 0
+#endif
+
+#define AHD_BUILD_COL_IDX(target, lun)				\
+	(((lun) << 4) | target)
+
+#define AHD_GET_SCB_COL_IDX(ahd, scb)				\
+	((SCB_GET_LUN(scb) << 4) | SCB_GET_TARGET(ahd, scb))
+
+#define AHD_SET_SCB_COL_IDX(scb, col_idx)				\
+do {									\
+	(scb)->hscb->scsiid = ((col_idx) << TID_SHIFT) & TID;		\
+	(scb)->hscb->lun = ((col_idx) >> 4) & (AHD_NUM_LUNS_NONPKT-1);	\
+} while (0)
+
+#define AHD_COPY_SCB_COL_IDX(dst, src)				\
+do {								\
+	dst->hscb->scsiid = src->hscb->scsiid;			\
+	dst->hscb->lun = src->hscb->lun;			\
+} while (0)
+
+#define	AHD_NEVER_COL_IDX 0xFFFF
+
+/**************************** Driver Constants ********************************/
+/*
+ * The maximum number of supported targets.
+ */
+#define AHD_NUM_TARGETS 16
+
+/*
+ * The maximum number of supported luns.
+ * The identify message only supports 64 luns in non-packetized transfers.
+ * You can have 2^64 luns when information unit transfers are enabled,
+ * but until we see a need to support that many, we support 256.
+ */
+#define AHD_NUM_LUNS_NONPKT 64
+#define AHD_NUM_LUNS 256
+
+/*
+ * The maximum transfer per S/G segment.
+ */
+#define AHD_MAXTRANSFER_SIZE	 0x00ffffff	/* limited by 24bit counter */
+
+/*
+ * The maximum amount of SCB storage in hardware on a controller.
+ * This value represents an upper bound.  Due to software design,
+ * we may not be able to use this number.
+ */
+#define AHD_SCB_MAX	512
+
+/*
+ * The maximum number of concurrent transactions supported per driver instance.
+ * Sequencer Control Blocks (SCBs) store per-transaction information.
+ */
+#define AHD_MAX_QUEUE	AHD_SCB_MAX
+
+/*
+ * Define the size of our QIN and QOUT FIFOs.  They must be a power of 2
+ * in size and accomodate as many transactions as can be queued concurrently.
+ */
+#define	AHD_QIN_SIZE	AHD_MAX_QUEUE
+#define	AHD_QOUT_SIZE	AHD_MAX_QUEUE
+
+#define AHD_QIN_WRAP(x) ((x) & (AHD_QIN_SIZE-1))
+/*
+ * The maximum amount of SCB storage we allocate in host memory.
+ */
+#define AHD_SCB_MAX_ALLOC AHD_MAX_QUEUE
+
+/*
+ * Ring Buffer of incoming target commands.
+ * We allocate 256 to simplify the logic in the sequencer
+ * by using the natural wrap point of an 8bit counter.
+ */
+#define AHD_TMODE_CMDS	256
+
+/* Reset line assertion time in us */
+#define AHD_BUSRESET_DELAY	25
+
+/******************* Chip Characteristics/Operating Settings  *****************/
+/*
+ * Chip Type
+ * The chip order is from least sophisticated to most sophisticated.
+ */
+typedef enum {
+	AHD_NONE	= 0x0000,
+	AHD_CHIPID_MASK	= 0x00FF,
+	AHD_AIC7901	= 0x0001,
+	AHD_AIC7902	= 0x0002,
+	AHD_AIC7901A	= 0x0003,
+	AHD_PCI		= 0x0100,	/* Bus type PCI */
+	AHD_PCIX	= 0x0200,	/* Bus type PCIX */
+	AHD_BUS_MASK	= 0x0F00
+} ahd_chip;
+
+/*
+ * Features available in each chip type.
+ */
+typedef enum {
+	AHD_FENONE		= 0x00000,
+	AHD_WIDE  		= 0x00001,/* Wide Channel */
+	AHD_MULTI_FUNC		= 0x00100,/* Multi-Function/Channel Device */
+	AHD_TARGETMODE		= 0x01000,/* Has tested target mode support */
+	AHD_MULTIROLE		= 0x02000,/* Space for two roles at a time */
+	AHD_RTI			= 0x04000,/* Retained Training Support */
+	AHD_NEW_IOCELL_OPTS	= 0x08000,/* More Signal knobs in the IOCELL */
+	AHD_NEW_DFCNTRL_OPTS	= 0x10000,/* SCSIENWRDIS bit */
+	AHD_REMOVABLE		= 0x00000,/* Hot-Swap supported - None so far*/
+	AHD_AIC7901_FE		= AHD_FENONE,
+	AHD_AIC7902_FE		= AHD_MULTI_FUNC
+} ahd_feature;
+
+/*
+ * Bugs in the silicon that we work around in software.
+ */
+typedef enum {
+	AHD_BUGNONE		= 0x0000,
+	/*
+	 * Rev A hardware fails to update LAST/CURR/NEXTSCB
+	 * correctly in certain packetized selection cases.
+	 */
+	AHD_SENT_SCB_UPDATE_BUG	= 0x0001,
+	/* The wrong SCB is accessed to check the abort pending bit. */
+	AHD_ABORT_LQI_BUG	= 0x0002,
+	/* Packetized bitbucket crosses packet boundaries. */
+	AHD_PKT_BITBUCKET_BUG	= 0x0004,
+	/* The selection timer runs twice as long as its setting. */
+	AHD_LONG_SETIMO_BUG	= 0x0008,
+	/* The Non-LQ CRC error status is delayed until phase change. */
+	AHD_NLQICRC_DELAYED_BUG	= 0x0010,
+	/* The chip must be reset for all outgoing bus resets.  */
+	AHD_SCSIRST_BUG		= 0x0020,
+	/* Some PCIX fields must be saved and restored across chip reset. */
+	AHD_PCIX_CHIPRST_BUG	= 0x0040,
+	/* MMAPIO is not functional in PCI-X mode.  */
+	AHD_PCIX_MMAPIO_BUG	= 0x0080,
+	/* Bug workarounds that can be disabled on non-PCIX busses. */
+	AHD_PCIX_BUG_MASK	= AHD_PCIX_CHIPRST_BUG
+				| AHD_PCIX_MMAPIO_BUG,
+	/*
+	 * LQOSTOP0 status set even for forced selections with ATN
+	 * to perform non-packetized message delivery.
+	 */
+	AHD_LQO_ATNO_BUG	= 0x0100,
+	/* FIFO auto-flush does not always trigger.  */
+	AHD_AUTOFLUSH_BUG	= 0x0200,
+	/* The CLRLQO registers are not self-clearing. */
+	AHD_CLRLQO_AUTOCLR_BUG	= 0x0400,
+	/* The PACKETIZED status bit refers to the previous connection. */
+	AHD_PKTIZED_STATUS_BUG  = 0x0800,
+	/* "Short Luns" are not placed into outgoing LQ packets correctly. */
+	AHD_PKT_LUN_BUG		= 0x1000,
+	/*
+	 * Only the FIFO allocated to the non-packetized connection may
+	 * be in use during a non-packetzied connection.
+	 */
+	AHD_NONPACKFIFO_BUG	= 0x2000,
+	/*
+	 * Writing to a DFF SCBPTR register may fail if concurent with
+	 * a hardware write to the other DFF SCBPTR register.  This is
+	 * not currently a concern in our sequencer since all chips with
+	 * this bug have the AHD_NONPACKFIFO_BUG and all writes of concern
+	 * occur in non-packetized connections.
+	 */
+	AHD_MDFF_WSCBPTR_BUG	= 0x4000,
+	/* SGHADDR updates are slow. */
+	AHD_REG_SLOW_SETTLE_BUG	= 0x8000,
+	/*
+	 * Changing the MODE_PTR coincident with an interrupt that
+	 * switches to a different mode will cause the interrupt to
+	 * be in the mode written outside of interrupt context.
+	 */
+	AHD_SET_MODE_BUG	= 0x10000,
+	/* Non-packetized busfree revision does not work. */
+	AHD_BUSFREEREV_BUG	= 0x20000,
+	/*
+	 * Paced transfers are indicated with a non-standard PPR
+	 * option bit in the neg table, 160MHz is indicated by
+	 * sync factor 0x7, and the offset if off by a factor of 2.
+	 */
+	AHD_PACED_NEGTABLE_BUG	= 0x40000,
+	/* LQOOVERRUN false positives. */
+	AHD_LQOOVERRUN_BUG	= 0x80000,
+	/*
+	 * Controller write to INTSTAT will lose to a host
+	 * write to CLRINT.
+	 */
+	AHD_INTCOLLISION_BUG	= 0x100000
+} ahd_bug;
+
+/*
+ * Configuration specific settings.
+ * The driver determines these settings by probing the
+ * chip/controller's configuration.
+ */
+typedef enum {
+	AHD_FNONE	      = 0x00000,
+	AHD_PRIMARY_CHANNEL   = 0x00003,/*
+					 * The channel that should
+					 * be probed first.
+					 */
+	AHD_USEDEFAULTS	      = 0x00004,/*
+					 * For cards without an seeprom
+					 * or a BIOS to initialize the chip's
+					 * SRAM, we use the default target
+					 * settings.
+					 */
+	AHD_SEQUENCER_DEBUG   = 0x00008,
+	AHD_RESET_BUS_A	      = 0x00010,
+	AHD_EXTENDED_TRANS_A  = 0x00020,
+	AHD_TERM_ENB_A	      = 0x00040,
+	AHD_SPCHK_ENB_A	      = 0x00080,
+	AHD_STPWLEVEL_A	      = 0x00100,
+	AHD_INITIATORROLE     = 0x00200,/*
+					 * Allow initiator operations on
+					 * this controller.
+					 */
+	AHD_TARGETROLE	      = 0x00400,/*
+					 * Allow target operations on this
+					 * controller.
+					 */
+	AHD_RESOURCE_SHORTAGE = 0x00800,
+	AHD_TQINFIFO_BLOCKED  = 0x01000,/* Blocked waiting for ATIOs */
+	AHD_INT50_SPEEDFLEX   = 0x02000,/*
+					 * Internal 50pin connector
+					 * sits behind an aic3860
+					 */
+	AHD_BIOS_ENABLED      = 0x04000,
+	AHD_ALL_INTERRUPTS    = 0x08000,
+	AHD_39BIT_ADDRESSING  = 0x10000,/* Use 39 bit addressing scheme. */
+	AHD_64BIT_ADDRESSING  = 0x20000,/* Use 64 bit addressing scheme. */
+	AHD_CURRENT_SENSING   = 0x40000,
+	AHD_SCB_CONFIG_USED   = 0x80000,/* No SEEPROM but SCB had info. */
+	AHD_HP_BOARD	      = 0x100000,
+	AHD_RESET_POLL_ACTIVE = 0x200000,
+	AHD_UPDATE_PEND_CMDS  = 0x400000,
+	AHD_RUNNING_QOUTFIFO  = 0x800000
+} ahd_flag;
+
+/************************* Hardware  SCB Definition ***************************/
+
+/*
+ * The driver keeps up to MAX_SCB scb structures per card in memory.  The SCB
+ * consists of a "hardware SCB" mirroring the fields availible on the card
+ * and additional information the kernel stores for each transaction.
+ *
+ * To minimize space utilization, a portion of the hardware scb stores
+ * different data during different portions of a SCSI transaction.
+ * As initialized by the host driver for the initiator role, this area
+ * contains the SCSI cdb (or a pointer to the  cdb) to be executed.  After
+ * the cdb has been presented to the target, this area serves to store
+ * residual transfer information and the SCSI status byte.
+ * For the target role, the contents of this area do not change, but
+ * still serve a different purpose than for the initiator role.  See
+ * struct target_data for details.
+ */
+
+/*
+ * Status information embedded in the shared poriton of
+ * an SCB after passing the cdb to the target.  The kernel
+ * driver will only read this data for transactions that
+ * complete abnormally.
+ */
+struct initiator_status {
+	uint32_t residual_datacnt;	/* Residual in the current S/G seg */
+	uint32_t residual_sgptr;	/* The next S/G for this transfer */
+	uint8_t	 scsi_status;		/* Standard SCSI status byte */
+};
+
+struct target_status {
+	uint32_t residual_datacnt;	/* Residual in the current S/G seg */
+	uint32_t residual_sgptr;	/* The next S/G for this transfer */
+	uint8_t  scsi_status;		/* SCSI status to give to initiator */
+	uint8_t  target_phases;		/* Bitmap of phases to execute */
+	uint8_t  data_phase;		/* Data-In or Data-Out */
+	uint8_t  initiator_tag;		/* Initiator's transaction tag */
+};
+
+/*
+ * Initiator mode SCB shared data area.
+ * If the embedded CDB is 12 bytes or less, we embed
+ * the sense buffer address in the SCB.  This allows
+ * us to retrieve sense information without interupting
+ * the host in packetized mode.
+ */
+typedef uint32_t sense_addr_t;
+#define MAX_CDB_LEN 16
+#define MAX_CDB_LEN_WITH_SENSE_ADDR (MAX_CDB_LEN - sizeof(sense_addr_t))
+union initiator_data {
+	uint64_t cdbptr;
+	uint8_t	 cdb[MAX_CDB_LEN];
+	struct {
+		uint8_t	 cdb[MAX_CDB_LEN_WITH_SENSE_ADDR];
+		sense_addr_t sense_addr;
+	} cdb_plus_saddr;
+};
+
+/*
+ * Target mode version of the shared data SCB segment.
+ */
+struct target_data {
+	uint32_t spare[2];	
+	uint8_t  scsi_status;		/* SCSI status to give to initiator */
+	uint8_t  target_phases;		/* Bitmap of phases to execute */
+	uint8_t  data_phase;		/* Data-In or Data-Out */
+	uint8_t  initiator_tag;		/* Initiator's transaction tag */
+};
+
+struct hardware_scb {
+/*0*/	union {
+		union	initiator_data idata;
+		struct	target_data tdata;
+		struct	initiator_status istatus;
+		struct	target_status tstatus;
+	} shared_data;
+/*
+ * A word about residuals.
+ * The scb is presented to the sequencer with the dataptr and datacnt
+ * fields initialized to the contents of the first S/G element to
+ * transfer.  The sgptr field is initialized to the bus address for
+ * the S/G element that follows the first in the in core S/G array
+ * or'ed with the SG_FULL_RESID flag.  Sgptr may point to an invalid
+ * S/G entry for this transfer (single S/G element transfer with the
+ * first elements address and length preloaded in the dataptr/datacnt
+ * fields).  If no transfer is to occur, sgptr is set to SG_LIST_NULL.
+ * The SG_FULL_RESID flag ensures that the residual will be correctly
+ * noted even if no data transfers occur.  Once the data phase is entered,
+ * the residual sgptr and datacnt are loaded from the sgptr and the
+ * datacnt fields.  After each S/G element's dataptr and length are
+ * loaded into the hardware, the residual sgptr is advanced.  After
+ * each S/G element is expired, its datacnt field is checked to see
+ * if the LAST_SEG flag is set.  If so, SG_LIST_NULL is set in the
+ * residual sg ptr and the transfer is considered complete.  If the
+ * sequencer determines that there is a residual in the tranfer, or
+ * there is non-zero status, it will set the SG_STATUS_VALID flag in
+ * sgptr and dma the scb back into host memory.  To sumarize:
+ *
+ * Sequencer:
+ *	o A residual has occurred if SG_FULL_RESID is set in sgptr,
+ *	  or residual_sgptr does not have SG_LIST_NULL set.
+ *
+ *	o We are transfering the last segment if residual_datacnt has
+ *	  the SG_LAST_SEG flag set.
+ *
+ * Host:
+ *	o A residual can only have occurred if a completed scb has the
+ *	  SG_STATUS_VALID flag set.  Inspection of the SCSI status field,
+ *	  the residual_datacnt, and the residual_sgptr field will tell
+ *	  for sure.
+ *
+ *	o residual_sgptr and sgptr refer to the "next" sg entry
+ *	  and so may point beyond the last valid sg entry for the
+ *	  transfer.
+ */ 
+#define SG_PTR_MASK	0xFFFFFFF8
+/*16*/	uint16_t tag;
+/*18*/	uint8_t  cdb_len;
+/*19*/	uint8_t  task_management;
+/*20*/	uint32_t next_hscb_busaddr;
+/*24*/	uint64_t dataptr;
+/*32*/	uint32_t datacnt;	/* Byte 3 is spare. */
+/*36*/	uint32_t sgptr;
+/*40*/	uint8_t  control;	/* See SCB_CONTROL in aic79xx.reg for details */
+/*41*/	uint8_t	 scsiid;	/*
+				 * Selection out Id
+				 * Our Id (bits 0-3) Their ID (bits 4-7)
+				 */
+/*42*/	uint8_t  lun;
+/*43*/	uint8_t  task_attribute;
+/*44*/	uint32_t hscb_busaddr;
+/******* Long lun field only downloaded for full 8 byte lun support *******/
+/*48*/  uint8_t	 pkt_long_lun[8];
+/******* Fields below are not Downloaded (Sequencer may use for scratch) ******/
+/*56*/  uint8_t	 spare[8];
+};
+
+/************************ Kernel SCB Definitions ******************************/
+/*
+ * Some fields of the SCB are OS dependent.  Here we collect the
+ * definitions for elements that all OS platforms need to include
+ * in there SCB definition.
+ */
+
+/*
+ * Definition of a scatter/gather element as transfered to the controller.
+ * The aic7xxx chips only support a 24bit length.  We use the top byte of
+ * the length to store additional address bits and a flag to indicate
+ * that a given segment terminates the transfer.  This gives us an
+ * addressable range of 512GB on machines with 64bit PCI or with chips
+ * that can support dual address cycles on 32bit PCI busses.
+ */
+struct ahd_dma_seg {
+	uint32_t	addr;
+	uint32_t	len;
+#define	AHD_DMA_LAST_SEG	0x80000000
+#define	AHD_SG_HIGH_ADDR_MASK	0x7F000000
+#define	AHD_SG_LEN_MASK		0x00FFFFFF
+};
+
+struct ahd_dma64_seg {
+	uint64_t	addr;
+	uint32_t	len;
+	uint32_t	pad;
+};
+
+struct map_node {
+	bus_dmamap_t		 dmamap;
+	bus_addr_t		 physaddr;
+	uint8_t			*vaddr;
+	SLIST_ENTRY(map_node)	 links;
+};
+
+/*
+ * The current state of this SCB.
+ */
+typedef enum {
+	SCB_FLAG_NONE		= 0x00000,
+	SCB_TRANSMISSION_ERROR	= 0x00001,/*
+					   * We detected a parity or CRC
+					   * error that has effected the
+					   * payload of the command.  This
+					   * flag is checked when normal
+					   * status is returned to catch
+					   * the case of a target not
+					   * responding to our attempt
+					   * to report the error.
+					   */
+	SCB_OTHERTCL_TIMEOUT	= 0x00002,/*
+					   * Another device was active
+					   * during the first timeout for
+					   * this SCB so we gave ourselves
+					   * an additional timeout period
+					   * in case it was hogging the
+					   * bus.
+				           */
+	SCB_DEVICE_RESET	= 0x00004,
+	SCB_SENSE		= 0x00008,
+	SCB_CDB32_PTR		= 0x00010,
+	SCB_RECOVERY_SCB	= 0x00020,
+	SCB_AUTO_NEGOTIATE	= 0x00040,/* Negotiate to achieve goal. */
+	SCB_NEGOTIATE		= 0x00080,/* Negotiation forced for command. */
+	SCB_ABORT		= 0x00100,
+	SCB_ACTIVE		= 0x00200,
+	SCB_TARGET_IMMEDIATE	= 0x00400,
+	SCB_PACKETIZED		= 0x00800,
+	SCB_EXPECT_PPR_BUSFREE	= 0x01000,
+	SCB_PKT_SENSE		= 0x02000,
+	SCB_CMDPHASE_ABORT	= 0x04000,
+	SCB_ON_COL_LIST		= 0x08000,
+	SCB_SILENT		= 0x10000 /*
+					   * Be quiet about transmission type
+					   * errors.  They are expected and we
+					   * don't want to upset the user.  This
+					   * flag is typically used during DV.
+					   */
+} scb_flag;
+
+struct scb {
+	struct	hardware_scb	 *hscb;
+	union {
+		SLIST_ENTRY(scb)  sle;
+		LIST_ENTRY(scb)	  le;
+		TAILQ_ENTRY(scb)  tqe;
+	} links;
+	union {
+		SLIST_ENTRY(scb)  sle;
+		LIST_ENTRY(scb)	  le;
+		TAILQ_ENTRY(scb)  tqe;
+	} links2;
+#define pending_links links2.le
+#define collision_links links2.le
+	struct scb		 *col_scb;
+	ahd_io_ctx_t		  io_ctx;
+	struct ahd_softc	 *ahd_softc;
+	scb_flag		  flags;
+#ifndef __linux__
+	bus_dmamap_t		  dmamap;
+#endif
+	struct scb_platform_data *platform_data;
+	struct map_node	 	 *hscb_map;
+	struct map_node	 	 *sg_map;
+	struct map_node	 	 *sense_map;
+	void			 *sg_list;
+	uint8_t			 *sense_data;
+	bus_addr_t		  sg_list_busaddr;
+	bus_addr_t		  sense_busaddr;
+	u_int			  sg_count;/* How full ahd_dma_seg is */
+#define	AHD_MAX_LQ_CRC_ERRORS 5
+	u_int			  crc_retry_count;
+};
+
+TAILQ_HEAD(scb_tailq, scb);
+LIST_HEAD(scb_list, scb);
+
+struct scb_data {
+	/*
+	 * TAILQ of lists of free SCBs grouped by device
+	 * collision domains.
+	 */
+	struct scb_tailq free_scbs;
+
+	/*
+	 * Per-device lists of SCBs whose tag ID would collide
+	 * with an already active tag on the device.
+	 */
+	struct scb_list free_scb_lists[AHD_NUM_TARGETS * AHD_NUM_LUNS_NONPKT];
+
+	/*
+	 * SCBs that will not collide with any active device.
+	 */
+	struct scb_list any_dev_free_scb_list;
+
+	/*
+	 * Mapping from tag to SCB.
+	 */
+	struct	scb *scbindex[AHD_SCB_MAX];
+
+	/*
+	 * "Bus" addresses of our data structures.
+	 */
+	bus_dma_tag_t	 hscb_dmat;	/* dmat for our hardware SCB array */
+	bus_dma_tag_t	 sg_dmat;	/* dmat for our sg segments */
+	bus_dma_tag_t	 sense_dmat;	/* dmat for our sense buffers */
+	SLIST_HEAD(, map_node) hscb_maps;
+	SLIST_HEAD(, map_node) sg_maps;
+	SLIST_HEAD(, map_node) sense_maps;
+	int		 scbs_left;	/* unallocated scbs in head map_node */
+	int		 sgs_left;	/* unallocated sgs in head map_node */
+	int		 sense_left;	/* unallocated sense in head map_node */
+	uint16_t	 numscbs;
+	uint16_t	 maxhscbs;	/* Number of SCBs on the card */
+	uint8_t		 init_level;	/*
+					 * How far we've initialized
+					 * this structure.
+					 */
+};
+
+/************************ Target Mode Definitions *****************************/
+
+/*
+ * Connection desciptor for select-in requests in target mode.
+ */
+struct target_cmd {
+	uint8_t scsiid;		/* Our ID and the initiator's ID */
+	uint8_t identify;	/* Identify message */
+	uint8_t bytes[22];	/* 
+				 * Bytes contains any additional message
+				 * bytes terminated by 0xFF.  The remainder
+				 * is the cdb to execute.
+				 */
+	uint8_t cmd_valid;	/*
+				 * When a command is complete, the firmware
+				 * will set cmd_valid to all bits set.
+				 * After the host has seen the command,
+				 * the bits are cleared.  This allows us
+				 * to just peek at host memory to determine
+				 * if more work is complete. cmd_valid is on
+				 * an 8 byte boundary to simplify setting
+				 * it on aic7880 hardware which only has
+				 * limited direct access to the DMA FIFO.
+				 */
+	uint8_t pad[7];
+};
+
+/*
+ * Number of events we can buffer up if we run out
+ * of immediate notify ccbs.
+ */
+#define AHD_TMODE_EVENT_BUFFER_SIZE 8
+struct ahd_tmode_event {
+	uint8_t initiator_id;
+	uint8_t event_type;	/* MSG type or EVENT_TYPE_BUS_RESET */
+#define	EVENT_TYPE_BUS_RESET 0xFF
+	uint8_t event_arg;
+};
+
+/*
+ * Per enabled lun target mode state.
+ * As this state is directly influenced by the host OS'es target mode
+ * environment, we let the OS module define it.  Forward declare the
+ * structure here so we can store arrays of them, etc. in OS neutral
+ * data structures.
+ */
+#ifdef AHD_TARGET_MODE 
+struct ahd_tmode_lstate {
+	struct cam_path *path;
+	struct ccb_hdr_slist accept_tios;
+	struct ccb_hdr_slist immed_notifies;
+	struct ahd_tmode_event event_buffer[AHD_TMODE_EVENT_BUFFER_SIZE];
+	uint8_t event_r_idx;
+	uint8_t event_w_idx;
+};
+#else
+struct ahd_tmode_lstate;
+#endif
+
+/******************** Transfer Negotiation Datastructures *********************/
+#define AHD_TRANS_CUR		0x01	/* Modify current neogtiation status */
+#define AHD_TRANS_ACTIVE	0x03	/* Assume this target is on the bus */
+#define AHD_TRANS_GOAL		0x04	/* Modify negotiation goal */
+#define AHD_TRANS_USER		0x08	/* Modify user negotiation settings */
+#define AHD_PERIOD_10MHz	0x19
+
+#define AHD_WIDTH_UNKNOWN	0xFF
+#define AHD_PERIOD_UNKNOWN	0xFF
+#define AHD_OFFSET_UNKNOWN	0x0
+#define AHD_PPR_OPTS_UNKNOWN	0xFF
+
+/*
+ * Transfer Negotiation Information.
+ */
+struct ahd_transinfo {
+	uint8_t protocol_version;	/* SCSI Revision level */
+	uint8_t transport_version;	/* SPI Revision level */
+	uint8_t width;			/* Bus width */
+	uint8_t period;			/* Sync rate factor */
+	uint8_t offset;			/* Sync offset */
+	uint8_t ppr_options;		/* Parallel Protocol Request options */
+};
+
+/*
+ * Per-initiator current, goal and user transfer negotiation information. */
+struct ahd_initiator_tinfo {
+	struct ahd_transinfo curr;
+	struct ahd_transinfo goal;
+	struct ahd_transinfo user;
+};
+
+/*
+ * Per enabled target ID state.
+ * Pointers to lun target state as well as sync/wide negotiation information
+ * for each initiator<->target mapping.  For the initiator role we pretend
+ * that we are the target and the targets are the initiators since the
+ * negotiation is the same regardless of role.
+ */
+struct ahd_tmode_tstate {
+	struct ahd_tmode_lstate*	enabled_luns[AHD_NUM_LUNS];
+	struct ahd_initiator_tinfo	transinfo[AHD_NUM_TARGETS];
+
+	/*
+	 * Per initiator state bitmasks.
+	 */
+	uint16_t	 auto_negotiate;/* Auto Negotiation Required */
+	uint16_t	 discenable;	/* Disconnection allowed  */
+	uint16_t	 tagenable;	/* Tagged Queuing allowed */
+};
+
+/*
+ * Points of interest along the negotiated transfer scale.
+ */
+#define AHD_SYNCRATE_160	0x8
+#define AHD_SYNCRATE_PACED	0x8
+#define AHD_SYNCRATE_DT		0x9
+#define AHD_SYNCRATE_ULTRA2	0xa
+#define AHD_SYNCRATE_ULTRA	0xc
+#define AHD_SYNCRATE_FAST	0x19
+#define AHD_SYNCRATE_MIN_DT	AHD_SYNCRATE_FAST
+#define AHD_SYNCRATE_SYNC	0x32
+#define AHD_SYNCRATE_MIN	0x60
+#define	AHD_SYNCRATE_ASYNC	0xFF
+#define AHD_SYNCRATE_MAX	AHD_SYNCRATE_160
+
+/* Safe and valid period for async negotiations. */
+#define	AHD_ASYNC_XFER_PERIOD	0x44
+
+/*
+ * In RevA, the synctable uses a 120MHz rate for the period
+ * factor 8 and 160MHz for the period factor 7.  The 120MHz
+ * rate never made it into the official SCSI spec, so we must
+ * compensate when setting the negotiation table for Rev A
+ * parts.
+ */
+#define AHD_SYNCRATE_REVA_120	0x8
+#define AHD_SYNCRATE_REVA_160	0x7
+
+/***************************** Lookup Tables **********************************/
+/*
+ * Phase -> name and message out response
+ * to parity errors in each phase table. 
+ */
+struct ahd_phase_table_entry {
+        uint8_t phase;
+        uint8_t mesg_out; /* Message response to parity errors */
+	char *phasemsg;
+};
+
+/************************** Serial EEPROM Format ******************************/
+
+struct seeprom_config {
+/*
+ * Per SCSI ID Configuration Flags
+ */
+	uint16_t device_flags[16];	/* words 0-15 */
+#define		CFXFER		0x003F	/* synchronous transfer rate */
+#define			CFXFER_ASYNC	0x3F
+#define		CFQAS		0x0040	/* Negotiate QAS */
+#define		CFPACKETIZED	0x0080	/* Negotiate Packetized Transfers */
+#define		CFSTART		0x0100	/* send start unit SCSI command */
+#define		CFINCBIOS	0x0200	/* include in BIOS scan */
+#define		CFDISC		0x0400	/* enable disconnection */
+#define		CFMULTILUNDEV	0x0800	/* Probe multiple luns in BIOS scan */
+#define		CFWIDEB		0x1000	/* wide bus device */
+#define		CFHOSTMANAGED	0x8000	/* Managed by a RAID controller */
+
+/*
+ * BIOS Control Bits
+ */
+	uint16_t bios_control;		/* word 16 */
+#define		CFSUPREM	0x0001	/* support all removeable drives */
+#define		CFSUPREMB	0x0002	/* support removeable boot drives */
+#define		CFBIOSSTATE	0x000C	/* BIOS Action State */
+#define		    CFBS_DISABLED	0x00
+#define		    CFBS_ENABLED	0x04
+#define		    CFBS_DISABLED_SCAN	0x08
+#define		CFENABLEDV	0x0010	/* Perform Domain Validation */
+#define		CFCTRL_A	0x0020	/* BIOS displays Ctrl-A message */	
+#define		CFSPARITY	0x0040	/* SCSI parity */
+#define		CFEXTEND	0x0080	/* extended translation enabled */
+#define		CFBOOTCD	0x0100  /* Support Bootable CD-ROM */
+#define		CFMSG_LEVEL	0x0600	/* BIOS Message Level */
+#define			CFMSG_VERBOSE	0x0000
+#define			CFMSG_SILENT	0x0200
+#define			CFMSG_DIAG	0x0400
+#define		CFRESETB	0x0800	/* reset SCSI bus at boot */
+/*		UNUSED		0xf000	*/
+
+/*
+ * Host Adapter Control Bits
+ */
+	uint16_t adapter_control;	/* word 17 */	
+#define		CFAUTOTERM	0x0001	/* Perform Auto termination */
+#define		CFSTERM		0x0002	/* SCSI low byte termination */
+#define		CFWSTERM	0x0004	/* SCSI high byte termination */
+#define		CFSEAUTOTERM	0x0008	/* Ultra2 Perform secondary Auto Term*/
+#define		CFSELOWTERM	0x0010	/* Ultra2 secondary low term */
+#define		CFSEHIGHTERM	0x0020	/* Ultra2 secondary high term */
+#define		CFSTPWLEVEL	0x0040	/* Termination level control */
+#define		CFBIOSAUTOTERM	0x0080	/* Perform Auto termination */
+#define		CFTERM_MENU	0x0100	/* BIOS displays termination menu */	
+#define		CFCLUSTERENB	0x8000	/* Cluster Enable */
+
+/*
+ * Bus Release Time, Host Adapter ID
+ */
+	uint16_t brtime_id;		/* word 18 */
+#define		CFSCSIID	0x000f	/* host adapter SCSI ID */
+/*		UNUSED		0x00f0	*/
+#define		CFBRTIME	0xff00	/* bus release time/PCI Latency Time */
+
+/*
+ * Maximum targets
+ */
+	uint16_t max_targets;		/* word 19 */	
+#define		CFMAXTARG	0x00ff	/* maximum targets */
+#define		CFBOOTLUN	0x0f00	/* Lun to boot from */
+#define		CFBOOTID	0xf000	/* Target to boot from */
+	uint16_t res_1[10];		/* words 20-29 */
+	uint16_t signature;		/* BIOS Signature */
+#define		CFSIGNATURE	0x400
+	uint16_t checksum;		/* word 31 */
+};
+
+/****************************** Flexport Logic ********************************/
+#define FLXADDR_TERMCTL			0x0
+#define		FLX_TERMCTL_ENSECHIGH	0x8
+#define		FLX_TERMCTL_ENSECLOW	0x4
+#define		FLX_TERMCTL_ENPRIHIGH	0x2
+#define		FLX_TERMCTL_ENPRILOW	0x1
+#define FLXADDR_ROMSTAT_CURSENSECTL	0x1
+#define		FLX_ROMSTAT_SEECFG	0xF0
+#define		FLX_ROMSTAT_EECFG	0x0F
+#define		FLX_ROMSTAT_SEE_93C66	0x00
+#define		FLX_ROMSTAT_SEE_NONE	0xF0
+#define		FLX_ROMSTAT_EE_512x8	0x0
+#define		FLX_ROMSTAT_EE_1MBx8	0x1
+#define		FLX_ROMSTAT_EE_2MBx8	0x2
+#define		FLX_ROMSTAT_EE_4MBx8	0x3
+#define		FLX_ROMSTAT_EE_16MBx8	0x4
+#define 		CURSENSE_ENB	0x1
+#define	FLXADDR_FLEXSTAT		0x2
+#define		FLX_FSTAT_BUSY		0x1
+#define FLXADDR_CURRENT_STAT		0x4
+#define		FLX_CSTAT_SEC_HIGH	0xC0
+#define		FLX_CSTAT_SEC_LOW	0x30
+#define		FLX_CSTAT_PRI_HIGH	0x0C
+#define		FLX_CSTAT_PRI_LOW	0x03
+#define		FLX_CSTAT_MASK		0x03
+#define		FLX_CSTAT_SHIFT		2
+#define		FLX_CSTAT_OKAY		0x0
+#define		FLX_CSTAT_OVER		0x1
+#define		FLX_CSTAT_UNDER		0x2
+#define		FLX_CSTAT_INVALID	0x3
+
+int		ahd_read_seeprom(struct ahd_softc *ahd, uint16_t *buf,
+				 u_int start_addr, u_int count);
+
+int		ahd_write_seeprom(struct ahd_softc *ahd, uint16_t *buf,
+				  u_int start_addr, u_int count);
+int		ahd_wait_seeprom(struct ahd_softc *ahd);
+int		ahd_verify_cksum(struct seeprom_config *sc);
+int		ahd_acquire_seeprom(struct ahd_softc *ahd);
+void		ahd_release_seeprom(struct ahd_softc *ahd);
+
+/****************************  Message Buffer *********************************/
+typedef enum {
+	MSG_FLAG_NONE			= 0x00,
+	MSG_FLAG_EXPECT_PPR_BUSFREE	= 0x01,
+	MSG_FLAG_IU_REQ_CHANGED		= 0x02,
+	MSG_FLAG_EXPECT_IDE_BUSFREE	= 0x04,
+	MSG_FLAG_EXPECT_QASREJ_BUSFREE	= 0x08,
+	MSG_FLAG_PACKETIZED		= 0x10
+} ahd_msg_flags;
+
+typedef enum {
+	MSG_TYPE_NONE			= 0x00,
+	MSG_TYPE_INITIATOR_MSGOUT	= 0x01,
+	MSG_TYPE_INITIATOR_MSGIN	= 0x02,
+	MSG_TYPE_TARGET_MSGOUT		= 0x03,
+	MSG_TYPE_TARGET_MSGIN		= 0x04
+} ahd_msg_type;
+
+typedef enum {
+	MSGLOOP_IN_PROG,
+	MSGLOOP_MSGCOMPLETE,
+	MSGLOOP_TERMINATED
+} msg_loop_stat;
+
+/*********************** Software Configuration Structure *********************/
+struct ahd_suspend_channel_state {
+	uint8_t	scsiseq;
+	uint8_t	sxfrctl0;
+	uint8_t	sxfrctl1;
+	uint8_t	simode0;
+	uint8_t	simode1;
+	uint8_t	seltimer;
+	uint8_t	seqctl;
+};
+
+struct ahd_suspend_state {
+	struct	ahd_suspend_channel_state channel[2];
+	uint8_t	optionmode;
+	uint8_t	dscommand0;
+	uint8_t	dspcistatus;
+	/* hsmailbox */
+	uint8_t	crccontrol1;
+	uint8_t	scbbaddr;
+	/* Host and sequencer SCB counts */
+	uint8_t	dff_thrsh;
+	uint8_t	*scratch_ram;
+	uint8_t	*btt;
+};
+
+typedef void (*ahd_bus_intr_t)(struct ahd_softc *);
+
+typedef enum {
+	AHD_MODE_DFF0,
+	AHD_MODE_DFF1,
+	AHD_MODE_CCHAN,
+	AHD_MODE_SCSI,
+	AHD_MODE_CFG,
+	AHD_MODE_UNKNOWN
+} ahd_mode;
+
+#define AHD_MK_MSK(x) (0x01 << (x))
+#define AHD_MODE_DFF0_MSK	AHD_MK_MSK(AHD_MODE_DFF0)
+#define AHD_MODE_DFF1_MSK	AHD_MK_MSK(AHD_MODE_DFF1)
+#define AHD_MODE_CCHAN_MSK	AHD_MK_MSK(AHD_MODE_CCHAN)
+#define AHD_MODE_SCSI_MSK	AHD_MK_MSK(AHD_MODE_SCSI)
+#define AHD_MODE_CFG_MSK	AHD_MK_MSK(AHD_MODE_CFG)
+#define AHD_MODE_UNKNOWN_MSK	AHD_MK_MSK(AHD_MODE_UNKNOWN)
+#define AHD_MODE_ANY_MSK (~0)
+
+typedef uint8_t ahd_mode_state;
+
+typedef void ahd_callback_t (void *);
+
+struct ahd_softc {
+	bus_space_tag_t           tags[2];
+	bus_space_handle_t        bshs[2];
+#ifndef __linux__
+	bus_dma_tag_t		  buffer_dmat;   /* dmat for buffer I/O */
+#endif
+	struct scb_data		  scb_data;
+
+	struct hardware_scb	 *next_queued_hscb;
+
+	/*
+	 * SCBs that have been sent to the controller
+	 */
+	LIST_HEAD(, scb)	  pending_scbs;
+
+	/*
+	 * Current register window mode information.
+	 */
+	ahd_mode		  dst_mode;
+	ahd_mode		  src_mode;
+
+	/*
+	 * Saved register window mode information
+	 * used for restore on next unpause.
+	 */
+	ahd_mode		  saved_dst_mode;
+	ahd_mode		  saved_src_mode;
+
+	/*
+	 * Platform specific data.
+	 */
+	struct ahd_platform_data *platform_data;
+
+	/*
+	 * Platform specific device information.
+	 */
+	ahd_dev_softc_t		  dev_softc;
+
+	/*
+	 * Bus specific device information.
+	 */
+	ahd_bus_intr_t		  bus_intr;
+
+	/*
+	 * Target mode related state kept on a per enabled lun basis.
+	 * Targets that are not enabled will have null entries.
+	 * As an initiator, we keep one target entry for our initiator
+	 * ID to store our sync/wide transfer settings.
+	 */
+	struct ahd_tmode_tstate  *enabled_targets[AHD_NUM_TARGETS];
+
+	/*
+	 * The black hole device responsible for handling requests for
+	 * disabled luns on enabled targets.
+	 */
+	struct ahd_tmode_lstate  *black_hole;
+
+	/*
+	 * Device instance currently on the bus awaiting a continue TIO
+	 * for a command that was not given the disconnect priveledge.
+	 */
+	struct ahd_tmode_lstate  *pending_device;
+
+	/*
+	 * Timer handles for timer driven callbacks.
+	 */
+	ahd_timer_t		  reset_timer;
+	ahd_timer_t		  stat_timer;
+
+	/*
+	 * Statistics.
+	 */
+#define	AHD_STAT_UPDATE_US	250000 /* 250ms */
+#define	AHD_STAT_BUCKETS	4
+	u_int			  cmdcmplt_bucket;
+	uint32_t		  cmdcmplt_counts[AHD_STAT_BUCKETS];
+	uint32_t		  cmdcmplt_total;
+
+	/*
+	 * Card characteristics
+	 */
+	ahd_chip		  chip;
+	ahd_feature		  features;
+	ahd_bug			  bugs;
+	ahd_flag		  flags;
+	struct seeprom_config	 *seep_config;
+
+	/* Values to store in the SEQCTL register for pause and unpause */
+	uint8_t			  unpause;
+	uint8_t			  pause;
+
+	/* Command Queues */
+	uint16_t		  qoutfifonext;
+	uint16_t		  qoutfifonext_valid_tag;
+	uint16_t		  qinfifonext;
+	uint16_t		  qinfifo[AHD_SCB_MAX];
+	uint16_t		 *qoutfifo;
+
+	/* Critical Section Data */
+	struct cs		 *critical_sections;
+	u_int			  num_critical_sections;
+
+	/* Buffer for handling packetized bitbucket. */
+	uint8_t			 *overrun_buf;
+
+	/* Links for chaining softcs */
+	TAILQ_ENTRY(ahd_softc)	  links;
+
+	/* Channel Names ('A', 'B', etc.) */
+	char			  channel;
+
+	/* Initiator Bus ID */
+	uint8_t			  our_id;
+
+	/*
+	 * Target incoming command FIFO.
+	 */
+	struct target_cmd	 *targetcmds;
+	uint8_t			  tqinfifonext;
+
+	/*
+	 * Cached verson of the hs_mailbox so we can avoid
+	 * pausing the sequencer during mailbox updates.
+	 */
+	uint8_t			  hs_mailbox;
+
+	/*
+	 * Incoming and outgoing message handling.
+	 */
+	uint8_t			  send_msg_perror;
+	ahd_msg_flags		  msg_flags;
+	ahd_msg_type		  msg_type;
+	uint8_t			  msgout_buf[12];/* Message we are sending */
+	uint8_t			  msgin_buf[12];/* Message we are receiving */
+	u_int			  msgout_len;	/* Length of message to send */
+	u_int			  msgout_index;	/* Current index in msgout */
+	u_int			  msgin_index;	/* Current index in msgin */
+
+	/*
+	 * Mapping information for data structures shared
+	 * between the sequencer and kernel.
+	 */
+	bus_dma_tag_t		  parent_dmat;
+	bus_dma_tag_t		  shared_data_dmat;
+	bus_dmamap_t		  shared_data_dmamap;
+	bus_addr_t		  shared_data_busaddr;
+
+	/* Information saved through suspend/resume cycles */
+	struct ahd_suspend_state  suspend_state;
+
+	/* Number of enabled target mode device on this card */
+	u_int			  enabled_luns;
+
+	/* Initialization level of this data structure */
+	u_int			  init_level;
+
+	/* PCI cacheline size. */
+	u_int			  pci_cachesize;
+
+	/* IO Cell Parameters */
+	uint8_t			  iocell_opts[AHD_NUM_PER_DEV_ANNEXCOLS];
+
+	u_int			  stack_size;
+	uint16_t		 *saved_stack;
+
+	/* Per-Unit descriptive information */
+	const char		 *description;
+	const char		 *bus_description;
+	char			 *name;
+	int			  unit;
+
+	/* Selection Timer settings */
+	int			  seltime;
+
+	/*
+	 * Interrupt coalessing settings.
+	 */
+#define	AHD_INT_COALESSING_TIMER_DEFAULT		250 /*us*/
+#define	AHD_INT_COALESSING_MAXCMDS_DEFAULT		10
+#define	AHD_INT_COALESSING_MAXCMDS_MAX			127
+#define	AHD_INT_COALESSING_MINCMDS_DEFAULT		5
+#define	AHD_INT_COALESSING_MINCMDS_MAX			127
+#define	AHD_INT_COALESSING_THRESHOLD_DEFAULT		2000
+#define	AHD_INT_COALESSING_STOP_THRESHOLD_DEFAULT	1000
+	u_int			  int_coalessing_timer;
+	u_int			  int_coalessing_maxcmds;
+	u_int			  int_coalessing_mincmds;
+	u_int			  int_coalessing_threshold;
+	u_int			  int_coalessing_stop_threshold;
+
+	uint16_t	 	  user_discenable;/* Disconnection allowed  */
+	uint16_t		  user_tagenable;/* Tagged Queuing allowed */
+};
+
+TAILQ_HEAD(ahd_softc_tailq, ahd_softc);
+extern struct ahd_softc_tailq ahd_tailq;
+
+/*************************** IO Cell Configuration ****************************/
+#define	AHD_PRECOMP_SLEW_INDEX						\
+    (AHD_ANNEXCOL_PRECOMP_SLEW - AHD_ANNEXCOL_PER_DEV0)
+
+#define	AHD_AMPLITUDE_INDEX						\
+    (AHD_ANNEXCOL_AMPLITUDE - AHD_ANNEXCOL_PER_DEV0)
+
+#define AHD_SET_SLEWRATE(ahd, new_slew)					\
+do {									\
+    (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_SLEWRATE_MASK;	\
+    (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] |=			\
+	(((new_slew) << AHD_SLEWRATE_SHIFT) & AHD_SLEWRATE_MASK);	\
+} while (0)
+
+#define AHD_SET_PRECOMP(ahd, new_pcomp)					\
+do {									\
+    (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_PRECOMP_MASK;	\
+    (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] |=			\
+	(((new_pcomp) << AHD_PRECOMP_SHIFT) & AHD_PRECOMP_MASK);	\
+} while (0)
+
+#define AHD_SET_AMPLITUDE(ahd, new_amp)					\
+do {									\
+    (ahd)->iocell_opts[AHD_AMPLITUDE_INDEX] &= ~AHD_AMPLITUDE_MASK;	\
+    (ahd)->iocell_opts[AHD_AMPLITUDE_INDEX] |=				\
+	(((new_amp) << AHD_AMPLITUDE_SHIFT) & AHD_AMPLITUDE_MASK);	\
+} while (0)
+
+/************************ Active Device Information ***************************/
+typedef enum {
+	ROLE_UNKNOWN,
+	ROLE_INITIATOR,
+	ROLE_TARGET
+} role_t;
+
+struct ahd_devinfo {
+	int	 our_scsiid;
+	int	 target_offset;
+	uint16_t target_mask;
+	u_int	 target;
+	u_int	 lun;
+	char	 channel;
+	role_t	 role;		/*
+				 * Only guaranteed to be correct if not
+				 * in the busfree state.
+				 */
+};
+
+/****************************** PCI Structures ********************************/
+#define AHD_PCI_IOADDR0	PCIR_MAPS	/* I/O BAR*/
+#define AHD_PCI_MEMADDR	(PCIR_MAPS + 4)	/* Memory BAR */
+#define AHD_PCI_IOADDR1	(PCIR_MAPS + 12)/* Second I/O BAR */
+
+typedef int (ahd_device_setup_t)(struct ahd_softc *);
+
+struct ahd_pci_identity {
+	uint64_t		 full_id;
+	uint64_t		 id_mask;
+	char			*name;
+	ahd_device_setup_t	*setup;
+};
+extern struct ahd_pci_identity ahd_pci_ident_table [];
+extern const u_int ahd_num_pci_devs;
+
+/***************************** VL/EISA Declarations ***************************/
+struct aic7770_identity {
+	uint32_t		 full_id;
+	uint32_t		 id_mask;
+	char			*name;
+	ahd_device_setup_t	*setup;
+};
+extern struct aic7770_identity aic7770_ident_table [];
+extern const int ahd_num_aic7770_devs;
+
+#define AHD_EISA_SLOT_OFFSET	0xc00
+#define AHD_EISA_IOSIZE		0x100
+
+/*************************** Function Declarations ****************************/
+/******************************************************************************/
+void			ahd_reset_cmds_pending(struct ahd_softc *ahd);
+u_int			ahd_find_busy_tcl(struct ahd_softc *ahd, u_int tcl);
+void			ahd_busy_tcl(struct ahd_softc *ahd,
+				     u_int tcl, u_int busyid);
+static __inline void	ahd_unbusy_tcl(struct ahd_softc *ahd, u_int tcl);
+static __inline void
+ahd_unbusy_tcl(struct ahd_softc *ahd, u_int tcl)
+{
+	ahd_busy_tcl(ahd, tcl, SCB_LIST_NULL);
+}
+
+/***************************** PCI Front End *********************************/
+struct	ahd_pci_identity *ahd_find_pci_device(ahd_dev_softc_t);
+int			  ahd_pci_config(struct ahd_softc *,
+					 struct ahd_pci_identity *);
+int	ahd_pci_test_register_access(struct ahd_softc *);
+
+/************************** SCB and SCB queue management **********************/
+int		ahd_probe_scbs(struct ahd_softc *);
+void		ahd_qinfifo_requeue_tail(struct ahd_softc *ahd,
+					 struct scb *scb);
+int		ahd_match_scb(struct ahd_softc *ahd, struct scb *scb,
+			      int target, char channel, int lun,
+			      u_int tag, role_t role);
+
+/****************************** Initialization ********************************/
+struct ahd_softc	*ahd_alloc(void *platform_arg, char *name);
+int			 ahd_softc_init(struct ahd_softc *);
+void			 ahd_controller_info(struct ahd_softc *ahd, char *buf);
+int			 ahd_init(struct ahd_softc *ahd);
+int			 ahd_default_config(struct ahd_softc *ahd);
+int			 ahd_parse_cfgdata(struct ahd_softc *ahd,
+					   struct seeprom_config *sc);
+void			 ahd_intr_enable(struct ahd_softc *ahd, int enable);
+void			 ahd_update_coalessing_values(struct ahd_softc *ahd,
+						      u_int timer,
+						      u_int maxcmds,
+						      u_int mincmds);
+void			 ahd_enable_coalessing(struct ahd_softc *ahd,
+					       int enable);
+void			 ahd_pause_and_flushwork(struct ahd_softc *ahd);
+int			 ahd_suspend(struct ahd_softc *ahd); 
+int			 ahd_resume(struct ahd_softc *ahd);
+void			 ahd_softc_insert(struct ahd_softc *);
+struct ahd_softc	*ahd_find_softc(struct ahd_softc *ahd);
+void			 ahd_set_unit(struct ahd_softc *, int);
+void			 ahd_set_name(struct ahd_softc *, char *);
+struct scb		*ahd_get_scb(struct ahd_softc *ahd, u_int col_idx);
+void			 ahd_free_scb(struct ahd_softc *ahd, struct scb *scb);
+void			 ahd_alloc_scbs(struct ahd_softc *ahd);
+void			 ahd_free(struct ahd_softc *ahd);
+int			 ahd_reset(struct ahd_softc *ahd);
+void			 ahd_shutdown(void *arg);
+int			ahd_write_flexport(struct ahd_softc *ahd,
+					   u_int addr, u_int value);
+int			ahd_read_flexport(struct ahd_softc *ahd, u_int addr,
+					  uint8_t *value);
+int			ahd_wait_flexport(struct ahd_softc *ahd);
+
+/*************************** Interrupt Services *******************************/
+void			ahd_pci_intr(struct ahd_softc *ahd);
+void			ahd_clear_intstat(struct ahd_softc *ahd);
+void			ahd_flush_qoutfifo(struct ahd_softc *ahd);
+void			ahd_run_qoutfifo(struct ahd_softc *ahd);
+#ifdef AHD_TARGET_MODE
+void			ahd_run_tqinfifo(struct ahd_softc *ahd, int paused);
+#endif
+void			ahd_handle_hwerrint(struct ahd_softc *ahd);
+void			ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat);
+void			ahd_handle_scsiint(struct ahd_softc *ahd,
+					   u_int intstat);
+void			ahd_clear_critical_section(struct ahd_softc *ahd);
+
+/***************************** Error Recovery *********************************/
+typedef enum {
+	SEARCH_COMPLETE,
+	SEARCH_COUNT,
+	SEARCH_REMOVE,
+	SEARCH_PRINT
+} ahd_search_action;
+int			ahd_search_qinfifo(struct ahd_softc *ahd, int target,
+					   char channel, int lun, u_int tag,
+					   role_t role, uint32_t status,
+					   ahd_search_action action);
+int			ahd_search_disc_list(struct ahd_softc *ahd, int target,
+					     char channel, int lun, u_int tag,
+					     int stop_on_first, int remove,
+					     int save_state);
+void			ahd_freeze_devq(struct ahd_softc *ahd, struct scb *scb);
+int			ahd_reset_channel(struct ahd_softc *ahd, char channel,
+					  int initiate_reset);
+int			ahd_abort_scbs(struct ahd_softc *ahd, int target,
+				       char channel, int lun, u_int tag,
+				       role_t role, uint32_t status);
+void			ahd_restart(struct ahd_softc *ahd);
+void			ahd_clear_fifo(struct ahd_softc *ahd, u_int fifo);
+void			ahd_handle_scb_status(struct ahd_softc *ahd,
+					      struct scb *scb);
+void			ahd_handle_scsi_status(struct ahd_softc *ahd,
+					       struct scb *scb);
+void			ahd_calc_residual(struct ahd_softc *ahd,
+					  struct scb *scb);
+/*************************** Utility Functions ********************************/
+struct ahd_phase_table_entry*
+			ahd_lookup_phase_entry(int phase);
+void			ahd_compile_devinfo(struct ahd_devinfo *devinfo,
+					    u_int our_id, u_int target,
+					    u_int lun, char channel,
+					    role_t role);
+/************************** Transfer Negotiation ******************************/
+void			ahd_find_syncrate(struct ahd_softc *ahd, u_int *period,
+					  u_int *ppr_options, u_int maxsync);
+void			ahd_validate_offset(struct ahd_softc *ahd,
+					    struct ahd_initiator_tinfo *tinfo,
+					    u_int period, u_int *offset,
+					    int wide, role_t role);
+void			ahd_validate_width(struct ahd_softc *ahd,
+					   struct ahd_initiator_tinfo *tinfo,
+					   u_int *bus_width,
+					   role_t role);
+/*
+ * Negotiation types.  These are used to qualify if we should renegotiate
+ * even if our goal and current transport parameters are identical.
+ */
+typedef enum {
+	AHD_NEG_TO_GOAL,	/* Renegotiate only if goal and curr differ. */
+	AHD_NEG_IF_NON_ASYNC,	/* Renegotiate so long as goal is non-async. */
+	AHD_NEG_ALWAYS		/* Renegotiat even if goal is async. */
+} ahd_neg_type;
+int			ahd_update_neg_request(struct ahd_softc*,
+					       struct ahd_devinfo*,
+					       struct ahd_tmode_tstate*,
+					       struct ahd_initiator_tinfo*,
+					       ahd_neg_type);
+void			ahd_set_width(struct ahd_softc *ahd,
+				      struct ahd_devinfo *devinfo,
+				      u_int width, u_int type, int paused);
+void			ahd_set_syncrate(struct ahd_softc *ahd,
+					 struct ahd_devinfo *devinfo,
+					 u_int period, u_int offset,
+					 u_int ppr_options,
+					 u_int type, int paused);
+typedef enum {
+	AHD_QUEUE_NONE,
+	AHD_QUEUE_BASIC,
+	AHD_QUEUE_TAGGED
+} ahd_queue_alg;
+
+void			ahd_set_tags(struct ahd_softc *ahd,
+				     struct ahd_devinfo *devinfo,
+				     ahd_queue_alg alg);
+
+/**************************** Target Mode *************************************/
+#ifdef AHD_TARGET_MODE
+void		ahd_send_lstate_events(struct ahd_softc *,
+				       struct ahd_tmode_lstate *);
+void		ahd_handle_en_lun(struct ahd_softc *ahd,
+				  struct cam_sim *sim, union ccb *ccb);
+cam_status	ahd_find_tmode_devs(struct ahd_softc *ahd,
+				    struct cam_sim *sim, union ccb *ccb,
+				    struct ahd_tmode_tstate **tstate,
+				    struct ahd_tmode_lstate **lstate,
+				    int notfound_failure);
+#ifndef AHD_TMODE_ENABLE
+#define AHD_TMODE_ENABLE 0
+#endif
+#endif
+/******************************* Debug ***************************************/
+#ifdef AHD_DEBUG
+extern uint32_t ahd_debug;
+#define AHD_SHOW_MISC		0x00001
+#define AHD_SHOW_SENSE		0x00002
+#define AHD_SHOW_RECOVERY	0x00004
+#define AHD_DUMP_SEEPROM	0x00008
+#define AHD_SHOW_TERMCTL	0x00010
+#define AHD_SHOW_MEMORY		0x00020
+#define AHD_SHOW_MESSAGES	0x00040
+#define AHD_SHOW_MODEPTR	0x00080
+#define AHD_SHOW_SELTO		0x00100
+#define AHD_SHOW_FIFOS		0x00200
+#define AHD_SHOW_QFULL		0x00400
+#define	AHD_SHOW_DV		0x00800
+#define AHD_SHOW_MASKED_ERRORS	0x01000
+#define AHD_SHOW_QUEUE		0x02000
+#define AHD_SHOW_TQIN		0x04000
+#define AHD_SHOW_SG		0x08000
+#define AHD_SHOW_INT_COALESSING	0x10000
+#define AHD_DEBUG_SEQUENCER	0x20000
+#endif
+void			ahd_print_scb(struct scb *scb);
+void			ahd_print_devinfo(struct ahd_softc *ahd,
+					  struct ahd_devinfo *devinfo);
+void			ahd_dump_sglist(struct scb *scb);
+void			ahd_dump_all_cards_state(void);
+void			ahd_dump_card_state(struct ahd_softc *ahd);
+int			ahd_print_register(ahd_reg_parse_entry_t *table,
+					   u_int num_entries,
+					   const char *name,
+					   u_int address,
+					   u_int value,
+					   u_int *cur_column,
+					   u_int wrap_point);
+void			ahd_dump_scbs(struct ahd_softc *ahd);
+#endif /* _AIC79XX_H_ */
diff -Nru a/drivers/scsi/aic7xxx/aic79xx.reg b/drivers/scsi/aic7xxx/aic79xx.reg
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aic79xx.reg	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,3933 @@
+/*
+ * Aic79xx register and scratch ram definitions.
+ *
+ * Copyright (c) 1994-2001 Justin T. Gibbs.
+ * Copyright (c) 2000-2002 Adaptec Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $FreeBSD$
+ */
+VERSION = "$Id: //depot/aic7xxx/aic7xxx/aic79xx.reg#59 $"
+
+/*
+ * This file is processed by the aic7xxx_asm utility for use in assembling
+ * firmware for the aic79xx family of SCSI host adapters as well as to generate
+ * a C header file for use in the kernel portion of the Aic79xx driver.
+ */
+
+/* Register window Modes */
+#define M_DFF0		0
+#define M_DFF1		1
+#define M_CCHAN		2
+#define M_SCSI		3
+#define M_CFG		4
+#define M_DST_SHIFT	4
+
+#define MK_MODE(src, dst) ((src) | ((dst) << M_DST_SHIFT))
+#define SET_MODE(src, dst)						\
+	SET_SRC_MODE	src;						\
+	SET_DST_MODE	dst;						\
+	if ((ahd->bugs & AHD_SET_MODE_BUG) != 0) {			\
+		mvi	MK_MODE(src, dst) call set_mode_work_around;	\
+	} else {							\
+		mvi	MODE_PTR, MK_MODE(src, dst);			\
+	}
+
+#define TOGGLE_DFF_MODE							\
+	if ((ahd->bugs & AHD_SET_MODE_BUG) != 0) {			\
+		call	toggle_dff_mode_work_around;			\
+	} else {							\
+		xor	MODE_PTR, MK_MODE(M_DFF1, M_DFF1);		\
+	}
+	
+#define RESTORE_MODE(mode)						\
+	if ((ahd->bugs & AHD_SET_MODE_BUG) != 0) {			\
+		mov	mode call set_mode_work_around;			\
+	} else {							\
+		mov	MODE_PTR, mode;					\
+	}
+
+#define SET_SEQINTCODE(code)						\
+	if ((ahd->bugs & AHD_INTCOLLISION_BUG) != 0) {			\
+		mvi	code call set_seqint_work_around;		\
+	} else {							\
+		mvi	SEQINTCODE, code;				\
+	}
+
+/*
+ * Mode Pointer
+ * Controls which of the 5, 512byte, address spaces should be used
+ * as the source and destination of any register accesses in our
+ * register window.
+ */
+register MODE_PTR {
+	address			0x000
+	access_mode	RW
+	field	DST_MODE	0x70
+	field	SRC_MODE	0x07
+	mode_pointer
+}
+
+const SRC_MODE_SHIFT	0
+const DST_MODE_SHIFT	4
+
+/*
+ * Host Interrupt Status
+ */
+register INTSTAT {
+	address			0x001
+	access_mode	RW
+	field	HWERRINT	0x80
+	field	BRKADRINT	0x40
+	field	SWTMINT		0x20
+	field	PCIINT		0x10
+	field	SCSIINT		0x08
+	field	SEQINT		0x04
+	field	CMDCMPLT	0x02
+	field	SPLTINT		0x01
+	mask	INT_PEND 0xFF
+}
+
+/*
+ * Sequencer Interrupt Code
+ */
+register SEQINTCODE {
+	address			0x002
+	access_mode	RW
+	field {
+		NO_SEQINT,			/* No seqint pending. */
+		BAD_PHASE,			/* unknown scsi bus phase */
+		SEND_REJECT,			/* sending a message reject */
+		PROTO_VIOLATION, 		/* Protocol Violation */
+		NO_MATCH,			/* no cmd match for reconnect */
+		IGN_WIDE_RES,			/* Complex IGN Wide Res Msg */
+		PDATA_REINIT,			/*
+						 * Returned to data phase
+						 * that requires data
+						 * transfer pointers to be
+						 * recalculated from the
+						 * transfer residual.
+						 */
+		HOST_MSG_LOOP,			/*
+						 * The bus is ready for the
+						 * host to perform another
+						 * message transaction.  This
+						 * mechanism is used for things
+						 * like sync/wide negotiation
+						 * that require a kernel based
+						 * message state engine.
+						 */
+		BAD_STATUS,			/* Bad status from target */
+		DATA_OVERRUN,			/*
+						 * Target attempted to write
+						 * beyond the bounds of its
+						 * command.
+						 */
+		MKMSG_FAILED,			/*
+						 * Target completed command
+						 * without honoring our ATN
+						 * request to issue a message. 
+						 */
+		MISSED_BUSFREE,			/*
+						 * The sequencer never saw
+						 * the bus go free after
+						 * either a command complete
+						 * or disconnect message.
+						 */
+		DUMP_CARD_STATE,
+		ILLEGAL_PHASE,
+		INVALID_SEQINT,
+		CFG4ISTAT_INTR,
+		STATUS_OVERRUN,
+		CFG4OVERRUN,
+		ENTERING_NONPACK,
+		TRACEPOINT0,
+		TRACEPOINT1,
+		TRACEPOINT2,
+		TRACEPOINT3,
+		SAW_HWERR
+	}
+}
+
+/*
+ * Clear Host Interrupt
+ */
+register CLRINT {
+	address			0x003
+	access_mode	WO
+	field	CLRHWERRINT	0x80 /* Rev B or greater */
+	field	CLRBRKADRINT	0x40
+	field	CLRSWTMINT	0x20
+	field	CLRPCIINT	0x10
+	field	CLRSCSIINT	0x08
+	field	CLRSEQINT	0x04
+	field	CLRCMDINT	0x02
+	field	CLRSPLTINT	0x01
+}
+
+/*
+ * Error Register
+ */
+register ERROR {
+	address			0x004
+	access_mode	RO
+	field	CIOPARERR	0x80
+	field	CIOACCESFAIL	0x40 /* Rev B or greater */
+	field	MPARERR		0x20
+	field	DPARERR		0x10
+	field	SQPARERR	0x08
+	field	ILLOPCODE	0x04
+	field	DSCTMOUT	0x02
+}
+
+/*
+ * Clear Error
+ */
+register CLRERR {
+	address			0x004
+	access_mode 	WO
+	field	CLRCIOPARERR	0x80
+	field	CLRCIOACCESFAIL	0x40 /* Rev B or greater */
+	field	CLRMPARERR	0x20
+	field	CLRDPARERR	0x10
+	field	CLRSQPARERR	0x08
+	field	CLRILLOPCODE	0x04
+	field	CLRDSCTMOUT	0x02
+}
+
+/*
+ * Host Control Register
+ * Overall host control of the device.
+ */
+register HCNTRL {
+	address			0x005
+	access_mode	RW
+	field	SEQ_RESET	0x80 /* Rev B or greater */
+	field	POWRDN		0x40
+	field	SWINT		0x10
+	field	SWTIMER_START_B	0x08 /* Rev B or greater */
+	field	PAUSE		0x04
+	field	INTEN		0x02
+	field	CHIPRST		0x01
+	field	CHIPRSTACK	0x01
+}
+
+/*
+ * Host New SCB Queue Offset
+ */
+register HNSCB_QOFF {
+	address			0x006
+	access_mode	RW
+	size		2
+}
+
+/*
+ * Host Empty SCB Queue Offset
+ */
+register HESCB_QOFF {
+	address			0x008
+	access_mode	RW
+}
+
+/*
+ * Host Mailbox
+ */
+register HS_MAILBOX {
+	address			0x00B
+	access_mode	RW
+	mask	HOST_TQINPOS	0x80	/* Boundary at either 0 or 128 */
+	mask	ENINT_COALESS	0x40	/* Perform interrupt coalessing */
+}
+
+/*
+ * Sequencer Interupt Status
+ */
+register SEQINTSTAT {
+	address			0x00C
+	access_mode	RO
+	field	SEQ_SWTMRTO	0x10
+	field	SEQ_SEQINT	0x08
+	field	SEQ_SCSIINT	0x04
+	field	SEQ_PCIINT	0x02
+	field	SEQ_SPLTINT	0x01
+}
+
+/*
+ * Clear SEQ Interrupt
+ */
+register CLRSEQINTSTAT {
+	address			0x00C
+	access_mode	WO
+	field	CLRSEQ_SWTMRTO	0x10
+	field	CLRSEQ_SEQINT	0x08
+	field	CLRSEQ_SCSIINT	0x04
+	field	CLRSEQ_PCIINT	0x02
+	field	CLRSEQ_SPLTINT	0x01
+}
+
+/*
+ * Software Timer
+ */
+register SWTIMER {
+	address			0x00E
+	access_mode	RW
+	size		2
+}
+
+/*
+ * SEQ New SCB Queue Offset
+ */
+register SNSCB_QOFF {
+	address			0x010
+	access_mode	RW
+	size		2
+	modes		M_CCHAN
+}
+
+/*
+ * SEQ Empty SCB Queue Offset
+ */
+register SESCB_QOFF {
+	address			0x012
+	access_mode	RW
+	modes		M_CCHAN
+}
+
+/*
+ * SEQ Done SCB Queue Offset
+ */
+register SDSCB_QOFF {
+	address			0x014
+	access_mode	RW
+	modes		M_CCHAN
+	size		2
+}
+
+/*
+ * Queue Offset Control & Status
+ */
+register QOFF_CTLSTA {
+	address			0x016
+	access_mode	RW
+	modes		M_CCHAN
+	field	EMPTY_SCB_AVAIL	0x80
+	field	NEW_SCB_AVAIL	0x40
+	field	SDSCB_ROLLOVR	0x20
+	field	HS_MAILBOX_ACT	0x10
+	field	SCB_QSIZE	0x0F {
+		SCB_QSIZE_4,
+		SCB_QSIZE_8,
+		SCB_QSIZE_16,
+		SCB_QSIZE_32,
+		SCB_QSIZE_64,
+		SCB_QSIZE_128,
+		SCB_QSIZE_256,
+		SCB_QSIZE_512,
+		SCB_QSIZE_1024,
+		SCB_QSIZE_2048,
+		SCB_QSIZE_4096,
+		SCB_QSIZE_8192,
+		SCB_QSIZE_16384
+	}
+}
+
+/*
+ * Interrupt Control
+ */
+register INTCTL {
+	address			0x018
+	access_mode	RW
+	field	SWTMINTMASK	0x80
+	field	SWTMINTEN	0x40
+	field	SWTIMER_START	0x20
+	field	AUTOCLRCMDINT	0x10
+	field	PCIINTEN	0x08
+	field	SCSIINTEN	0x04
+	field	SEQINTEN	0x02
+	field	SPLTINTEN	0x01
+}
+
+/*
+ * Data FIFO Control
+ */
+register DFCNTRL {
+	address			0x019
+	access_mode	RW
+	modes		M_DFF0, M_DFF1
+	field	PRELOADEN	0x80
+	field	SCSIENWRDIS	0x40	/* Rev B only. */
+	field	SCSIEN		0x20
+	field	SCSIENACK	0x20
+	field	HDMAEN		0x08
+	field	HDMAENACK	0x08
+	field	DIRECTION	0x04
+	field	DIRECTIONACK	0x04
+	field	FIFOFLUSH	0x02
+	field	FIFOFLUSHACK	0x02
+	field	DIRECTIONEN	0x01
+}
+
+/*
+ * Device Space Command 0
+ */
+register DSCOMMAND0 {
+	address			0x019
+	access_mode	RW
+	modes		M_CFG
+	field	CACHETHEN	0x80	/* Cache Threshold enable */
+	field	DPARCKEN	0x40	/* Data Parity Check Enable */
+	field	MPARCKEN	0x20	/* Memory Parity Check Enable */
+	field	EXTREQLCK	0x10	/* External Request Lock */
+	field	DISABLE_TWATE	0x02	/* Rev B or greater */
+	field	CIOPARCKEN	0x01	/* Internal bus parity error enable */
+}
+
+/*
+ * Data FIFO Status
+ */
+register DFSTATUS {
+	address			0x01A
+	access_mode	RO
+	modes		M_DFF0, M_DFF1
+	field	PRELOAD_AVAIL		0x80
+	field	PKT_PRELOAD_AVAIL	0x40
+	field	MREQPEND		0x10
+	field	HDONE			0x08
+	field	DFTHRESH		0x04
+	field	FIFOFULL		0x02
+	field	FIFOEMP			0x01
+}
+
+/*
+ * S/G Cache Pointer
+ */
+register SG_CACHE_PRE {
+	address			0x01B
+	access_mode	WO
+	modes		M_DFF0, M_DFF1
+	field	SG_ADDR_MASK	0xf8
+	field	ODD_SEG		0x04
+	field	LAST_SEG	0x02
+}
+
+register SG_CACHE_SHADOW {
+	address			0x01B
+	access_mode	RO
+	modes		M_DFF0, M_DFF1
+	field	SG_ADDR_MASK	0xf8
+	field	ODD_SEG		0x04
+	field	LAST_SEG	0x02
+	field	LAST_SEG_DONE	0x01
+}
+
+/*
+ * Arbiter Control
+ */
+register ARBCTL {
+	address			0x01B
+	access_mode	RW
+	modes		M_CFG
+	field	RESET_HARB	0x80
+	field	RETRY_SWEN	0x08
+	field	USE_TIME	0x07
+}
+
+/*
+ * Data Channel Host Address
+ */
+register HADDR {
+	address			0x070
+	access_mode	RW
+	size		8
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * Host Overlay DMA Address
+ */
+register HODMAADR {
+	address			0x070
+	access_mode	RW
+	size		8
+	modes		M_SCSI
+}
+
+/*
+ * PCI PLL Delay.
+ */
+register PLLDELAY {
+	address			0x070
+	access_mode	RW
+	size		1
+	modes		M_CFG
+	field	SPLIT_DROP_REQ	0x80
+}
+
+/*
+ * Data Channel Host Count
+ */
+register HCNT {
+	address			0x078
+	access_mode	RW
+	size		3
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * Host Overlay DMA Count
+ */
+register HODMACNT {
+	address			0x078
+	access_mode	RW
+	size		2
+	modes		M_SCSI
+}
+
+/*
+ * Host Overlay DMA Enable
+ */
+register HODMAEN {
+	address			0x07A
+	access_mode	RW
+	modes		M_SCSI
+}
+
+/*
+ * Scatter/Gather Host Address
+ */
+register SGHADDR {
+	address			0x07C
+	access_mode	RW
+	size		8
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * SCB Host Address
+ */
+register SCBHADDR {
+	address			0x07C
+	access_mode	RW
+	size		8
+	modes		M_CCHAN
+}
+
+/*
+ * Scatter/Gather Host Count
+ */
+register SGHCNT {
+	address			0x084
+	access_mode	RW
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * SCB Host Count
+ */
+register SCBHCNT {
+	address			0x084
+	access_mode	RW
+	modes		M_CCHAN
+}
+
+/*
+ * Data FIFO Threshold
+ */
+register DFF_THRSH {
+	address			0x088
+	access_mode	RW
+	modes		M_CFG
+	field	WR_DFTHRSH	0x70 {
+		WR_DFTHRSH_MIN,
+		WR_DFTHRSH_25,
+		WR_DFTHRSH_50,
+		WR_DFTHRSH_63,
+		WR_DFTHRSH_75,
+		WR_DFTHRSH_85,
+		WR_DFTHRSH_90,
+		WR_DFTHRSH_MAX
+	}
+	field	RD_DFTHRSH	0x07 {
+		RD_DFTHRSH_MIN,
+		RD_DFTHRSH_25,
+		RD_DFTHRSH_50,
+		RD_DFTHRSH_63,
+		RD_DFTHRSH_75,
+		RD_DFTHRSH_85,
+		RD_DFTHRSH_90,
+		RD_DFTHRSH_MAX
+	}
+}
+
+/*
+ * ROM Address
+ */
+register ROMADDR {
+	address			0x08A
+	access_mode	RW
+	size		3
+}
+
+/*
+ * ROM Control
+ */
+register ROMCNTRL {
+	address			0x08D
+	access_mode	RW
+	field	ROMOP		0xE0
+	field	ROMSPD		0x18
+	field	REPEAT		0x02
+	field	RDY		0x01
+}
+
+/*
+ * ROM Data
+ */
+register ROMDATA {
+	address			0x08E
+	access_mode	RW
+}
+
+/*
+ * Data Channel Receive Message 0
+ */
+register DCHRXMSG0 {
+	address			0x090
+	access_mode	RO
+	modes		M_DFF0, M_DFF1
+	field		CDNUM	0xF8
+	field		CFNUM	0x07
+}
+
+/*
+ * CMC Recieve Message 0
+ */
+register CMCRXMSG0 {
+	address			0x090
+	access_mode	RO
+	modes		M_CCHAN
+	field		CDNUM	0xF8
+	field		CFNUM	0x07
+}
+
+/*
+ * Overlay Recieve Message 0
+ */
+register OVLYRXMSG0 {
+	address			0x090
+	access_mode	RO
+	modes		M_SCSI
+	field		CDNUM	0xF8
+	field		CFNUM	0x07
+}
+
+/*
+ * Relaxed Order Enable
+ */
+register ROENABLE {
+	address			0x090
+	access_mode	RW
+	modes		M_CFG
+	field	MSIROEN		0x20
+	field	OVLYROEN	0x10
+	field	CMCROEN		0x08
+	field	SGROEN		0x04
+	field	DCH1ROEN	0x02
+	field	DCH0ROEN	0x01
+}
+
+/*
+ * Data Channel Receive Message 1
+ */
+register DCHRXMSG1 {
+	address			0x091
+	access_mode	RO
+	modes		M_DFF0, M_DFF1
+	field	CBNUM		0xFF
+}
+
+/*
+ * CMC Recieve Message 1
+ */
+register CMCRXMSG1 {
+	address			0x091
+	access_mode	RO
+	modes		M_CCHAN
+	field	CBNUM		0xFF
+}
+
+/*
+ * Overlay Recieve Message 1
+ */
+register OVLYRXMSG1 {
+	address			0x091
+	access_mode	RO
+	modes		M_SCSI
+	field	CBNUM		0xFF
+}
+
+/*
+ * No Snoop Enable
+ */
+register NSENABLE {
+	address			0x091
+	access_mode	RW
+	modes		M_CFG
+	field	MSINSEN		0x20
+	field	OVLYNSEN	0x10
+	field	CMCNSEN		0x08
+	field	SGNSEN		0x04
+	field	DCH1NSEN	0x02
+	field	DCH0NSEN	0x01
+}
+
+/*
+ * Data Channel Receive Message 2
+ */
+register DCHRXMSG2 {
+	address			0x092
+	access_mode	RO
+	modes		M_DFF0, M_DFF1
+	field	MINDEX		0xFF
+}
+
+/*
+ * CMC Recieve Message 2
+ */
+register CMCRXMSG2 {
+	address			0x092
+	access_mode	RO
+	modes		M_CCHAN
+	field	MINDEX		0xFF
+}
+
+/*
+ * Overlay Recieve Message 2
+ */
+register OVLYRXMSG2 {
+	address			0x092
+	access_mode	RO
+	modes		M_SCSI
+	field	MINDEX		0xFF
+}
+
+/*
+ * Outstanding Split Transactions
+ */
+register OST {
+	address			0x092
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Data Channel Receive Message 3
+ */
+register DCHRXMSG3 {
+	address			0x093
+	access_mode	RO
+	modes		M_DFF0, M_DFF1
+	field	MCLASS		0x0F
+}
+
+/*
+ * CMC Recieve Message 3
+ */
+register CMCRXMSG3 {
+	address			0x093
+	access_mode	RO
+	modes		M_CCHAN
+	field	MCLASS		0x0F
+}
+
+/*
+ * Overlay Recieve Message 3
+ */
+register OVLYRXMSG3 {
+	address			0x093
+	access_mode	RO
+	modes		M_SCSI
+	field	MCLASS		0x0F
+}
+
+/*
+ * PCI-X Control
+ */
+register PCIXCTL {
+	address			0x093
+	access_mode	RW
+	modes		M_CFG
+	field	SERRPULSE	0x80
+	field	UNEXPSCIEN	0x20
+	field	SPLTSMADIS	0x10
+	field	SPLTSTADIS	0x08
+	field	SRSPDPEEN	0x04
+	field	TSCSERREN	0x02
+	field	CMPABCDIS	0x01
+}
+
+/*
+ * CMC Sequencer Byte Count
+ */
+register CMCSEQBCNT {
+	address			0x094
+	access_mode	RO
+	modes		M_CCHAN
+}
+
+/*
+ * Overlay Sequencer Byte Count
+ */
+register OVLYSEQBCNT {
+	address			0x094
+	access_mode	RO
+	modes		M_SCSI
+}
+
+/*
+ * Data Channel Sequencer Byte Count
+ */
+register DCHSEQBCNT {
+	address			0x094
+	access_mode	RO
+	size		2
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * Data Channel Split Status 0
+ */
+register DCHSPLTSTAT0 {
+	address			0x096
+	access_mode	RW
+	modes		M_DFF0, M_DFF1
+	field	STAETERM	0x80
+	field	SCBCERR		0x40
+	field	SCADERR		0x20
+	field	SCDATBUCKET	0x10
+	field	CNTNOTCMPLT	0x08
+	field	RXOVRUN		0x04
+	field	RXSCEMSG	0x02
+	field	RXSPLTRSP	0x01
+}
+
+/*
+ * CMC Split Status 0
+ */
+register CMCSPLTSTAT0 {
+	address			0x096
+	access_mode	RW
+	modes		M_CCHAN
+	field	STAETERM	0x80
+	field	SCBCERR		0x40
+	field	SCADERR		0x20
+	field	SCDATBUCKET	0x10
+	field	CNTNOTCMPLT	0x08
+	field	RXOVRUN		0x04
+	field	RXSCEMSG	0x02
+	field	RXSPLTRSP	0x01
+}
+
+/*
+ * Overlay Split Status 0
+ */
+register OVLYSPLTSTAT0 {
+	address			0x096
+	access_mode	RW
+	modes		M_SCSI
+	field	STAETERM	0x80
+	field	SCBCERR		0x40
+	field	SCADERR		0x20
+	field	SCDATBUCKET	0x10
+	field	CNTNOTCMPLT	0x08
+	field	RXOVRUN		0x04
+	field	RXSCEMSG	0x02
+	field	RXSPLTRSP	0x01
+}
+
+/*
+ * Data Channel Split Status 1
+ */
+register DCHSPLTSTAT1 {
+	address			0x097
+	access_mode	RW
+	modes		M_DFF0, M_DFF1
+	field	RXDATABUCKET	0x01
+}
+
+/*
+ * CMC Split Status 1
+ */
+register CMCSPLTSTAT1 {
+	address			0x097
+	access_mode	RW
+	modes		M_CCHAN
+	field	RXDATABUCKET	0x01
+}
+
+/*
+ * Overlay Split Status 1
+ */
+register OVLYSPLTSTAT1 {
+	address			0x097
+	access_mode	RW
+	modes		M_SCSI
+	field	RXDATABUCKET	0x01
+}
+
+/*
+ * S/G Receive Message 0
+ */
+register SGRXMSG0 {
+	address			0x098
+	access_mode	RO
+	modes		M_DFF0, M_DFF1
+	field		CDNUM	0xF8
+	field		CFNUM	0x07
+}
+
+/*
+ * S/G Receive Message 1
+ */
+register SGRXMSG1 {
+	address			0x099
+	access_mode	RO
+	modes		M_DFF0, M_DFF1
+	field	CBNUM		0xFF
+}
+
+/*
+ * S/G Receive Message 2
+ */
+register SGRXMSG2 {
+	address			0x09A
+	access_mode	RO
+	modes		M_DFF0, M_DFF1
+	field	MINDEX		0xFF
+}
+
+/*
+ * S/G Receive Message 3
+ */
+register SGRXMSG3 {
+	address			0x09B
+	access_mode	RO
+	modes		M_DFF0, M_DFF1
+	field	MCLASS		0x0F
+}
+
+/*
+ * Slave Split Out Address 0
+ */
+register SLVSPLTOUTADR0 {
+	address			0x098
+	access_mode	RO
+	modes		M_SCSI
+	field	LOWER_ADDR	0x7F
+}
+
+/*
+ * Slave Split Out Address 1
+ */
+register SLVSPLTOUTADR1 {
+	address			0x099
+	access_mode	RO
+	modes		M_SCSI
+	field	REQ_DNUM	0xF8
+	field	REQ_FNUM	0x07
+}
+
+/*
+ * Slave Split Out Address 2
+ */
+register SLVSPLTOUTADR2 {
+	address			0x09A
+	access_mode	RO
+	modes		M_SCSI
+	field	REQ_BNUM	0xFF
+}
+
+/*
+ * Slave Split Out Address 3
+ */
+register SLVSPLTOUTADR3 {
+	address			0x09B
+	access_mode	RO
+	modes		M_SCSI
+	field	RLXORD		020
+	field	TAG_NUM		0x1F
+}
+
+/*
+ * SG Sequencer Byte Count
+ */
+register SGSEQBCNT {
+	address			0x09C
+	access_mode	RO
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * Slave Split Out Attribute 0
+ */
+register SLVSPLTOUTATTR0 {
+	address			0x09C
+	access_mode	RO
+	modes		M_SCSI
+	field	LOWER_BCNT	0xFF
+}
+
+/*
+ * Slave Split Out Attribute 1
+ */
+register SLVSPLTOUTATTR1 {
+	address			0x09D
+	access_mode	RO
+	modes		M_SCSI
+	field	CMPLT_DNUM	0xF8
+	field	CMPLT_FNUM	0x07
+}
+
+/*
+ * Slave Split Out Attribute 2
+ */
+register SLVSPLTOUTATTR2 {
+	address			0x09E
+	access_mode	RO
+	size		2
+	modes		M_SCSI
+	field	CMPLT_BNUM	0xFF
+}
+/*
+ * S/G Split Status 0
+ */
+register SGSPLTSTAT0 {
+	address			0x09E
+	access_mode	RW
+	modes		M_DFF0, M_DFF1
+	field	STAETERM	0x80
+	field	SCBCERR		0x40
+	field	SCADERR		0x20
+	field	SCDATBUCKET	0x10
+	field	CNTNOTCMPLT	0x08
+	field	RXOVRUN		0x04
+	field	RXSCEMSG	0x02
+	field	RXSPLTRSP	0x01
+}
+
+/*
+ * S/G Split Status 1
+ */
+register SGSPLTSTAT1 {
+	address			0x09F
+	access_mode	RW
+	modes		M_DFF0, M_DFF1
+	field	RXDATABUCKET	0x01
+}
+
+/*
+ * Special Function
+ */
+register SFUNCT {
+	address			0x09f
+	access_mode	RW
+	modes		M_CFG
+	field	TEST_GROUP	0xF0
+	field	TEST_NUM	0x0F
+}
+
+/*
+ * Data FIFO 0 PCI Status 
+ */
+register DF0PCISTAT {
+	address			0x0A0
+	access_mode	RW
+	modes		M_CFG
+	field	DPE		0x80
+	field	SSE		0x40
+	field	RMA		0x20
+	field	RTA		0x10
+	field	SCAAPERR	0x08
+	field	RDPERR		0x04
+	field	TWATERR		0x02
+	field	DPR		0x01
+}
+
+/*
+ * Data FIFO 1 PCI Status 
+ */
+register DF1PCISTAT {
+	address			0x0A1
+	access_mode	RW
+	modes		M_CFG
+	field	DPE		0x80
+	field	SSE		0x40
+	field	RMA		0x20
+	field	RTA		0x10
+	field	SCAAPERR	0x08
+	field	RDPERR		0x04
+	field	TWATERR		0x02
+	field	DPR		0x01
+}
+
+/*
+ * S/G PCI Status 
+ */
+register SGPCISTAT {
+	address			0x0A2
+	access_mode	RW
+	modes		M_CFG
+	field	DPE		0x80
+	field	SSE		0x40
+	field	RMA		0x20
+	field	RTA		0x10
+	field	SCAAPERR	0x08
+	field	RDPERR		0x04
+	field	DPR		0x01
+}
+
+/*
+ * CMC PCI Status 
+ */
+register CMCPCISTAT {
+	address			0x0A3
+	access_mode	RW
+	modes		M_CFG
+	field	DPE		0x80
+	field	SSE		0x40
+	field	RMA		0x20
+	field	RTA		0x10
+	field	SCAAPERR	0x08
+	field	RDPERR		0x04
+	field	TWATERR		0x02
+	field	DPR		0x01
+}
+
+/*
+ * Overlay PCI Status 
+ */
+register OVLYPCISTAT {
+	address			0x0A4
+	access_mode	RW
+	modes		M_CFG
+	field	DPE		0x80
+	field	SSE		0x40
+	field	RMA		0x20
+	field	RTA		0x10
+	field	SCAAPERR	0x08
+	field	RDPERR		0x04
+	field	DPR		0x01
+}
+
+/*
+ * PCI Status for MSI Master DMA Transfer
+ */
+register MSIPCISTAT {
+	address			0x0A6
+	access_mode	RW
+	modes		M_CFG
+	field	SSE		0x40
+	field	RMA		0x20
+	field	RTA		0x10
+	field	CLRPENDMSI	0x08
+	field	TWATERR		0x02
+	field	DPR		0x01
+}
+
+/*
+ * PCI Status for Target
+ */
+register TARGPCISTAT {
+	address			0x0A7
+	access_mode	RW
+	modes		M_CFG
+	field	DPE		0x80
+	field	SSE		0x40
+	field	STA		0x08
+	field	TWATERR		0x02
+}
+
+/*
+ * LQ Packet In
+ * The last LQ Packet recieved
+ */
+register LQIN {
+	address			0x020
+	access_mode	RW
+	size		20
+	modes		M_DFF0, M_DFF1, M_SCSI
+}
+
+/*
+ * SCB Type Pointer
+ * SCB offset for Target Mode SCB type information
+ */
+register TYPEPTR {
+	address			0x020
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Queue Tag Pointer
+ * SCB offset to the Two Byte tag identifier used for target mode.
+ */
+register TAGPTR {
+	address			0x021
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Logical Unit Number Pointer
+ * SCB offset to the LSB (little endian) of the lun field.
+ */
+register LUNPTR {
+	address			0x022
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Data Length Pointer
+ * SCB offset for the 4 byte data length field in target mode.
+ */
+register DATALENPTR {
+	address			0x023
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Status Length Pointer
+ * SCB offset to the two byte status field in target SCBs.
+ */
+register STATLENPTR {
+	address			0x024
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Command Length Pointer
+ * Scb offset for the CDB length field in initiator SCBs.
+ */
+register CMDLENPTR {
+	address			0x025
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Task Attribute Pointer
+ * Scb offset for the byte field specifying the attribute byte
+ * to be used in command packets.
+ */ 
+register ATTRPTR {
+	address			0x026
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Task Management Flags Pointer
+ * Scb offset for the byte field specifying the attribute flags
+ * byte to be used in command packets.
+ */ 
+register FLAGPTR {
+	address			0x027
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Command Pointer
+ * Scb offset for the first byte in the CDB for initiator SCBs.
+ */
+register CMDPTR {
+	address			0x028
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Queue Next Pointer
+ * Scb offset for the 2 byte "next scb link".
+ */
+register QNEXTPTR {
+	address			0x029
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * SCSI ID Pointer
+ * Scb offset to the value to place in the SCSIID register
+ * during target mode connections.
+ */
+register IDPTR {
+	address			0x02A
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Command Aborted Byte Pointer
+ * Offset to the SCB flags field that includes the
+ * "SCB aborted" status bit.
+ */
+register ABRTBYTEPTR {
+	address			0x02B
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Command Aborted Bit Pointer
+ * Bit offset in the SCB flags field for "SCB aborted" status.
+ */
+register ABRTBITPTR {
+	address			0x02C
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Rev B or greater.
+ */
+register MAXCMDBYTES {
+	address			0x02D
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Rev B or greater.
+ */
+register MAXCMD2RCV {
+	address			0x02E
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Rev B or greater.
+ */
+register SHORTTHRESH {
+	address			0x02F
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Logical Unit Number Length
+ * The length, in bytes, of the SCB lun field.
+ */
+register LUNLEN {
+	address			0x030
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * CDB Limit
+ * The size, in bytes, of the embedded CDB field in initator SCBs.
+ */
+register CDBLIMIT {
+	address			0x031
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Maximum Commands
+ * The maximum number of commands to issue during a
+ * single packetized connection.
+ */
+register MAXCMD {
+	address			0x032
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * Maximum Command Counter
+ * The number of commands already sent during this connection
+ */
+register MAXCMDCNT {
+	address			0x033
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * LQ Packet Reserved Bytes
+ * The bytes to be sent in the currently reserved fileds
+ * of all LQ packets.
+ */
+register LQRSVD01 {
+	address			0x034
+	access_mode	RW
+	modes		M_SCSI
+}
+register LQRSVD16 {
+	address			0x035
+	access_mode	RW
+	modes		M_SCSI
+}
+register LQRSVD17 {
+	address			0x036
+	access_mode	RW
+	modes		M_SCSI
+}
+
+/*
+ * Command Reserved 0
+ * The byte to be sent for the reserved byte 0 of
+ * outgoing command packets.
+ */
+register CMDRSVD0 {
+	address			0x037
+	access_mode	RW
+	modes		M_CFG
+}
+
+/*
+ * LQ Manager Control 0
+ */
+register LQCTL0 {
+	address			0x038
+	access_mode	RW
+	modes		M_CFG
+	field	LQITARGCLT	0xC0
+	field	LQIINITGCLT	0x30
+	field	LQ0TARGCLT	0x0C
+	field	LQ0INITGCLT	0x03
+}
+
+/*
+ * LQ Manager Control 1
+ */
+register LQCTL1 {
+	address			0x038
+	access_mode	RW
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	PCI2PCI		0x04
+	field	SINGLECMD	0x02
+	field	ABORTPENDING	0x01
+}
+
+/*
+ * LQ Manager Control 2
+ */
+register LQCTL2 {
+	address			0x039
+	access_mode	RW
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	LQIRETRY	0x80
+	field	LQICONTINUE	0x40
+	field	LQITOIDLE	0x20
+	field	LQIPAUSE	0x10
+	field	LQORETRY	0x08
+	field	LQOCONTINUE	0x04
+	field	LQOTOIDLE	0x02
+	field	LQOPAUSE	0x01
+}
+
+/*
+ * SCSI RAM BIST0
+ */
+register SCSBIST0 {
+	address			0x039
+	access_mode	RW
+	modes		M_CFG
+	field	GSBISTERR	0x40
+	field	GSBISTDONE	0x20
+	field	GSBISTRUN	0x10
+	field	OSBISTERR	0x04
+	field	OSBISTDONE	0x02
+	field	OSBISTRUN	0x01
+}
+
+/*
+ * SCSI Sequence Control0
+ */
+register SCSISEQ0 {
+	address			0x03A
+	access_mode	RW
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	TEMODEO		0x80
+	field	ENSELO		0x40
+	field	ENARBO		0x20
+	field	FORCEBUSFREE	0x10
+	field	SCSIRSTO	0x01
+}
+
+/*
+ * SCSI RAM BIST 1
+ */
+register SCSBIST1 {
+	address			0x03A
+	access_mode	RW
+	modes		M_CFG
+	field	NTBISTERR	0x04
+	field	NTBISTDONE	0x02
+	field	NTBISTRUN	0x01
+}
+
+/*
+ * SCSI Sequence Control 1
+ */
+register SCSISEQ1 {
+	address			0x03B
+	access_mode	RW
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	MANUALCTL	0x40
+	field	ENSELI		0x20
+	field	ENRSELI		0x10
+	field	MANUALP		0x0C
+	field	ENAUTOATNP	0x02
+	field	ALTSTIM		0x01
+}
+
+/*
+ * SCSI Transfer Control 0
+ */
+register SXFRCTL0 {
+	address			0x03C
+	access_mode	RW
+	modes		M_SCSI
+	field	DFON		0x80
+	field	DFPEXP		0x40
+	field	BIOSCANCELEN	0x10
+	field	SPIOEN		0x08
+}
+
+/*
+ * SCSI Transfer Control 1
+ */
+register SXFRCTL1 {
+	address			0x03D
+	access_mode	RW
+	modes		M_SCSI
+	field	BITBUCKET	0x80
+	field	ENSACHK		0x40
+	field	ENSPCHK		0x20
+	field	STIMESEL	0x18
+	field	ENSTIMER	0x04
+	field	ACTNEGEN	0x02
+	field	STPWEN		0x01
+}
+
+/*
+ * SCSI Transfer Control 2
+ */
+register SXFRCTL2 {
+	address			0x03E
+	access_mode	RW
+	modes		M_SCSI
+	field	AUTORSTDIS	0x10
+	field	CMDDMAEN	0x08
+	field	ASU		0x07
+}
+
+/*
+ * SCSI Bus Initiator IDs
+ * Bitmask of observed initiators on the bus.
+ */
+register BUSINITID {
+	address			0x03C
+	access_mode	RW
+	modes		M_CFG
+	size		2
+}
+
+/*
+ * Data Length Counters
+ * Packet byte counter.
+ */
+register DLCOUNT {
+	address			0x03C
+	access_mode	RW
+	modes		M_DFF0, M_DFF1
+	size		3
+}
+
+/*
+ * Data FIFO Status
+ */
+register DFFSTAT {
+	address			0x03F
+	access_mode	RW
+	modes		M_SCSI
+	field	FIFO1FREE	0x20
+	field	FIFO0FREE	0x10
+	/*
+	 * On the B, this enum only works
+	 * in the read direction.  For writes,
+	 * you must use the B version of the
+	 * CURRFIFO_0 definition which is defined
+	 * as a constant outside of this register
+	 * definition to avoid confusing the
+	 * register pretty printing code.
+	 */
+	enum	CURRFIFO	0x03 {
+		CURRFIFO_0,
+		CURRFIFO_1,
+		CURRFIFO_NONE	0x3
+	}
+}
+
+const B_CURRFIFO_0 0x2
+
+/*
+ * SCSI Bus Target IDs
+ * Bitmask of observed targets on the bus.
+ */
+register BUSTARGID {
+	address			0x03E
+	access_mode	RW
+	modes		M_CFG
+	size		2
+}
+
+/*
+ * SCSI Control Signal Out
+ */
+register SCSISIGO {
+	address			0x040
+	access_mode	RW
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	CDO		0x80
+	field	IOO		0x40
+	field	MSGO		0x20
+	field	ATNO		0x10
+	field	SELO		0x08
+	field	BSYO		0x04
+	field	REQO		0x02
+	field	ACKO		0x01
+/*
+ * Possible phases to write into SCSISIG0
+ */
+	enum	PHASE_MASK  CDO|IOO|MSGO {
+		P_DATAOUT	0x0,
+		P_DATAIN	IOO,
+		P_DATAOUT_DT	P_DATAOUT|MSGO,
+		P_DATAIN_DT	P_DATAIN|MSGO,
+		P_COMMAND	CDO,
+		P_MESGOUT	CDO|MSGO,
+		P_STATUS	CDO|IOO,
+		P_MESGIN	CDO|IOO|MSGO
+	}
+}
+
+register SCSISIGI {
+	address			0x041
+	access_mode	RO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	CDI		0x80
+	field	IOI		0x40
+	field	MSGI		0x20
+	field	ATNI		0x10
+	field	SELI		0x08
+	field	BSYI		0x04
+	field	REQI		0x02
+	field	ACKI		0x01
+/*
+ * Possible phases in SCSISIGI
+ */
+	enum	PHASE_MASK  CDO|IOO|MSGO {
+		P_DATAOUT	0x0,
+		P_DATAIN	IOO,
+		P_DATAOUT_DT	P_DATAOUT|MSGO,
+		P_DATAIN_DT	P_DATAIN|MSGO,
+		P_COMMAND	CDO,
+		P_MESGOUT	CDO|MSGO,
+		P_STATUS	CDO|IOO,
+		P_MESGIN	CDO|IOO|MSGO
+	}
+}
+
+/*
+ * Multiple Target IDs
+ * Bitmask of ids to respond as a target.
+ */
+register MULTARGID {
+	address			0x040
+	access_mode	RW
+	modes		M_CFG
+	size		2
+}
+
+/*
+ * SCSI Phase
+ */
+register SCSIPHASE {
+	address			0x042
+	access_mode	RO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	STATUS_PHASE	0x20
+	field	COMMAND_PHASE	0x10
+	field	MSG_IN_PHASE	0x08
+	field	MSG_OUT_PHASE	0x04
+	field	DATA_PHASE_MASK	0x03 {
+		DATA_OUT_PHASE	0x01,
+		DATA_IN_PHASE	0x02
+	}
+}
+
+/*
+ * SCSI Data 0 Image
+ */
+register SCSIDAT0_IMG {
+	address			0x043
+	access_mode	RW
+	modes		M_DFF0, M_DFF1, M_SCSI
+}
+
+/*
+ * SCSI Latched Data
+ */
+register SCSIDAT {
+	address			0x044
+	access_mode	RW
+	modes		M_DFF0, M_DFF1, M_SCSI
+	size		2
+}
+
+/*
+ * SCSI Data Bus
+ */
+register SCSIBUS {
+	address			0x046
+	access_mode	RW
+	modes		M_DFF0, M_DFF1, M_SCSI
+	size		2
+}
+
+/*
+ * Target ID In
+ */
+register TARGIDIN {
+	address			0x048
+	access_mode	RO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	CLKOUT		0x80
+	field	TARGID		0x0F
+}
+
+/*
+ * Selection/Reselection ID
+ * Upper four bits are the device id.  The ONEBIT is set when the re/selecting
+ * device did not set its own ID.
+ */
+register SELID {
+	address			0x049
+	access_mode	RW
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	SELID_MASK	0xf0
+	field	ONEBIT		0x08
+}
+
+/*
+ * SCSI Block Control
+ * Controls Bus type and channel selection.  SELWIDE allows for the
+ * coexistence of 8bit and 16bit devices on a wide bus.
+ */
+register SBLKCTL {
+	address			0x04A
+	access_mode	RW
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	DIAGLEDEN	0x80
+	field	DIAGLEDON	0x40
+	field	ENAB40		0x08	/* LVD transceiver active */
+	field	ENAB20		0x04	/* SE/HVD transceiver active */
+	field	SELWIDE		0x02
+}
+
+/*
+ * Option Mode
+ */
+register OPTIONMODE {
+	address			0x04A
+	access_mode	RW
+	modes		M_CFG
+	field	BIOSCANCTL		0x80
+	field	AUTOACKEN		0x40
+	field	BIASCANCTL		0x20
+	field	BUSFREEREV		0x10
+	field	ENDGFORMCHK		0x04
+	field	AUTO_MSGOUT_DE		0x02
+	mask	OPTIONMODE_DEFAULTS	AUTO_MSGOUT_DE
+}
+
+/*
+ * SCSI Status 0
+ */
+register SSTAT0	{
+	address			0x04B
+	access_mode	RO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	TARGET		0x80	/* Board acting as target */
+	field	SELDO		0x40	/* Selection Done */
+	field	SELDI		0x20	/* Board has been selected */
+	field	SELINGO		0x10	/* Selection In Progress */
+	field	IOERR		0x08	/* LVD Tranceiver mode changed */
+	field	OVERRUN		0x04	/* SCSI Offset overrun detected */
+	field	SPIORDY		0x02	/* SCSI PIO Ready */
+	field	ARBDO		0x01	/* Arbitration Done Out */
+}
+
+/*
+ * Clear SCSI Interrupt 0
+ * Writing a 1 to a bit clears the associated SCSI Interrupt in SSTAT0.
+ */
+register CLRSINT0 {
+	address			0x04B
+	access_mode	WO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	CLRSELDO	0x40
+	field	CLRSELDI	0x20
+	field	CLRSELINGO	0x10
+	field	CLRIOERR	0x08
+	field	CLROVERRUN	0x04
+	field	CLRSPIORDY	0x02
+	field	CLRARBDO	0x01
+}
+
+/*
+ * SCSI Interrupt Mode 0
+ * Setting any bit will enable the corresponding function
+ * in SIMODE0 to interrupt via the IRQ pin.
+ */
+register SIMODE0 {
+	address			0x04B
+	access_mode	RW
+	modes		M_CFG
+	field	ENSELDO		0x40
+	field	ENSELDI		0x20
+	field	ENSELINGO	0x10
+	field	ENIOERR		0x08
+	field	ENOVERRUN	0x04
+	field	ENSPIORDY	0x02
+	field	ENARBDO		0x01
+}
+
+/*
+ * SCSI Status 1
+ */
+register SSTAT1 {
+	address			0x04C
+	access_mode	RO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	SELTO		0x80
+	field	ATNTARG 	0x40
+	field	SCSIRSTI	0x20
+	field	PHASEMIS	0x10
+	field	BUSFREE		0x08
+	field	SCSIPERR	0x04
+	field	STRB2FAST	0x02
+	field	REQINIT		0x01
+}
+
+/*
+ * Clear SCSI Interrupt 1
+ * Writing a 1 to a bit clears the associated SCSI Interrupt in SSTAT1.
+ */
+register CLRSINT1 {
+	address			0x04C
+	access_mode	WO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	CLRSELTIMEO	0x80
+	field	CLRATNO		0x40
+	field	CLRSCSIRSTI	0x20
+	field	CLRBUSFREE	0x08
+	field	CLRSCSIPERR	0x04
+	field	CLRSTRB2FAST	0x02
+	field	CLRREQINIT	0x01
+}
+
+/*
+ * SCSI Status 2
+ */
+register SSTAT2 {
+	address			0x04d
+	access_mode	RO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	BUSFREETIME	0xc0 {
+		BUSFREE_LQO	0x40,
+		BUSFREE_DFF0	0x80,
+		BUSFREE_DFF1	0xC0
+	}
+	field	NONPACKREQ	0x20
+	field	EXP_ACTIVE	0x10	/* SCSI Expander Active */
+	field	BSYX		0x08	/* Busy Expander */
+	field	WIDE_RES	0x04	/* Modes 0 and 1 only */
+	field	SDONE		0x02	/* Modes 0 and 1 only */
+	field	DMADONE		0x01	/* Modes 0 and 1 only */
+}
+
+/*
+ * Clear SCSI Interrupt 2
+ */
+register CLRSINT2 {
+	address			0x04D
+	access_mode	WO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	CLRNONPACKREQ	0x20
+	field	CLRWIDE_RES	0x04	/* Modes 0 and 1 only */
+	field	CLRSDONE	0x02	/* Modes 0 and 1 only */
+	field	CLRDMADONE	0x01	/* Modes 0 and 1 only */
+}
+
+/*
+ * SCSI Interrupt Mode 2
+ */
+register SIMODE2 {
+	address			0x04D
+	access_mode	RW
+	modes		M_CFG
+	field	ENWIDE_RES	0x04
+	field	ENSDONE		0x02
+	field	ENDMADONE	0x01
+}
+
+/*
+ * Physical Error Diagnosis
+ */
+register PERRDIAG {
+	address			0x04E
+	access_mode	RO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	HIZERO		0x80
+	field	HIPERR		0x40
+	field	PREVPHASE	0x20
+	field	PARITYERR	0x10
+	field	AIPERR		0x08
+	field	CRCERR		0x04
+	field	DGFORMERR	0x02
+	field	DTERR		0x01
+}
+
+/*
+ * LQI Manager Current State
+ */
+register LQISTATE {
+	address			0x04E
+	access_mode	RO
+	modes		M_CFG
+}
+
+/*
+ * SCSI Offset Count
+ */
+register SOFFCNT {
+	address			0x04F
+	access_mode	RO
+	modes		M_DFF0, M_DFF1, M_SCSI
+}
+
+/*
+ * LQO Manager Current State
+ */
+register LQOSTATE {
+	address			0x04F
+	access_mode	RO
+	modes		M_CFG
+}
+
+/*
+ * LQI Manager Status
+ */
+register LQISTAT0 {
+	address			0x050
+	access_mode	RO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	LQIATNQAS	0x20
+	field	LQICRCT1	0x10
+	field	LQICRCT2	0x08
+	field	LQIBADLQT	0x04
+	field	LQIATNLQ	0x02
+	field	LQIATNCMD	0x01
+}
+
+/*
+ * Clear LQI Interrupts 0
+ */
+register CLRLQIINT0 {
+	address			0x050
+	access_mode	WO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	CLRLQIATNQAS	0x20
+	field	CLRLQICRCT1	0x10
+	field	CLRLQICRCT2	0x08
+	field	CLRLQIBADLQT	0x04
+	field	CLRLQIATNLQ	0x02
+	field	CLRLQIATNCMD	0x01
+}
+
+/*
+ * LQI Manager Interrupt Mode 0
+ */
+register LQIMODE0 {
+	address			0x050
+	access_mode	RW
+	modes		M_CFG
+	field	ENLQIATNQASK	0x20
+	field	ENLQICRCT1	0x10
+	field	ENLQICRCT2	0x08
+	field	ENLQIBADLQT	0x04
+	field	ENLQIATNLQ	0x02
+	field	ENLQIATNCMD	0x01
+}
+
+/*
+ * LQI Manager Status 1
+ */
+register LQISTAT1 {
+	address			0x051
+	access_mode	RO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	LQIPHASE_LQ	0x80
+	field	LQIPHASE_NLQ	0x40
+	field	LQIABORT	0x20
+	field	LQICRCI_LQ	0x10
+	field	LQICRCI_NLQ	0x08
+	field	LQIBADLQI	0x04
+	field	LQIOVERI_LQ	0x02
+	field	LQIOVERI_NLQ	0x01
+}
+
+/*
+ * Clear LQI Manager Interrupts1
+ */
+register CLRLQIINT1 {
+	address			0x051
+	access_mode	WO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	CLRLQIPHASE_LQ	0x80
+	field	CLRLQIPHASE_NLQ	0x40
+	field	CLRLIQABORT	0x20
+	field	CLRLQICRCI_LQ	0x10
+	field	CLRLQICRCI_NLQ	0x08
+	field	CLRLQIBADLQI	0x04
+	field	CLRLQIOVERI_LQ	0x02
+	field	CLRLQIOVERI_NLQ	0x01
+}
+
+/*
+ * LQI Manager Interrupt Mode 1
+ */
+register LQIMODE1 {
+	address			0x051
+	access_mode	RW
+	modes		M_CFG
+	field	ENLQIPHASE_LQ	0x80
+	field	ENLQIPHASE_NLQ	0x40
+	field	ENLIQABORT	0x20
+	field	ENLQICRCI_LQ	0x10
+	field	ENLQICRCI_NLQ	0x08
+	field	ENLQIBADLQI	0x04
+	field	ENLQIOVERI_LQ	0x02
+	field	ENLQIOVERI_NLQ	0x01
+}
+
+/*
+ * LQI Manager Status 2
+ */
+register LQISTAT2 {
+	address			0x052
+	access_mode	RO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	PACKETIZED	0x80
+	field	LQIPHASE_OUTPKT	0x40
+	field	LQIWORKONLQ	0x20
+	field	LQIWAITFIFO	0x10
+	field	LQISTOPPKT	0x08
+	field	LQISTOPLQ	0x04
+	field	LQISTOPCMD	0x02
+	field	LQIGSAVAIL	0x01
+}
+
+/*
+ * SCSI Status 3
+ */
+register SSTAT3 {
+	address			0x053
+	access_mode	RO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	NTRAMPERR	0x02
+	field	OSRAMPERR	0x01
+}
+
+/*
+ * Clear SCSI Status 3
+ */
+register CLRSINT3 {
+	address			0x053
+	access_mode	WO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	CLRNTRAMPERR	0x02
+	field	CLROSRAMPERR	0x01
+}
+
+/*
+ * SCSI Interrupt Mode 3
+ */
+register SIMODE3 {
+	address			0x053
+	access_mode	RW
+	modes		M_CFG
+	field	ENNTRAMPERR	0x02
+	field	ENOSRAMPERR	0x01
+}
+
+/*
+ * LQO Manager Status 0
+ */
+register LQOSTAT0 {
+	address			0x054
+	access_mode	RO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	LQOTARGSCBPERR	0x10
+	field	LQOSTOPT2	0x08
+	field	LQOATNLQ	0x04
+	field	LQOATNPKT	0x02
+	field	LQOTCRC		0x01
+}
+
+/*
+ * Clear LQO Manager interrupt 0
+ */
+register CLRLQOINT0 {
+	address			0x054
+	access_mode	WO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	CLRLQOTARGSCBPERR	0x10
+	field	CLRLQOSTOPT2		0x08
+	field	CLRLQOATNLQ		0x04
+	field	CLRLQOATNPKT		0x02
+	field	CLRLQOTCRC		0x01
+}
+
+/*
+ * LQO Manager Interrupt Mode 0
+ */
+register LQOMODE0 {
+	address			0x054
+	access_mode	RW
+	modes		M_CFG
+	field	ENLQOTARGSCBPERR	0x10
+	field	ENLQOSTOPT2		0x08
+	field	ENLQOATNLQ		0x04
+	field	ENLQOATNPKT		0x02
+	field	ENLQOTCRC		0x01
+}
+
+/*
+ * LQO Manager Status 1
+ */
+register LQOSTAT1 {
+	address			0x055
+	access_mode	RO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	LQOINITSCBPERR	0x10
+	field	LQOSTOPI2	0x08
+	field	LQOBADQAS	0x04
+	field	LQOBUSFREE	0x02
+	field	LQOPHACHGINPKT	0x01
+}
+
+/*
+ * Clear LOQ Interrupt 1
+ */
+register CLRLQOINT1 {
+	address			0x055
+	access_mode	WO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	CLRLQOINITSCBPERR	0x10
+	field	CLRLQOSTOPI2		0x08
+	field	CLRLQOBADQAS		0x04
+	field	CLRLQOBUSFREE		0x02
+	field	CLRLQOPHACHGINPKT	0x01
+}
+
+/*
+ * LQO Manager Interrupt Mode 1
+ */
+register LQOMODE1 {
+	address			0x055
+	access_mode	RW
+	modes		M_CFG
+	field	ENLQOINITSCBPERR	0x10
+	field	ENLQOSTOPI2		0x08
+	field	ENLQOBADQAS		0x04
+	field	ENLQOBUSFREE		0x02
+	field	ENLQOPHACHGINPKT	0x01
+}
+
+/*
+ * LQO Manager Status 2
+ */
+register LQOSTAT2 {
+	address			0x056
+	access_mode	RO
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	LQOPKT		0xE0
+	field	LQOWAITFIFO	0x10
+	field	LQOPHACHGOUTPKT	0x02	/* outside of packet boundaries. */
+	field	LQOSTOP0	0x01	/* Stopped after sending all packets */
+}
+
+/*
+ * Output Synchronizer Space Count
+ */
+register OS_SPACE_CNT {
+	address			0x056
+	access_mode	RO
+	modes		M_CFG
+}
+
+/*
+ * SCSI Interrupt Mode 1
+ * Setting any bit will enable the corresponding function
+ * in SIMODE1 to interrupt via the IRQ pin.
+ */
+register SIMODE1 {
+	address			0x057
+	access_mode	RW
+	modes		M_DFF0, M_DFF1, M_SCSI
+	field	ENSELTIMO	0x80
+	field	ENATNTARG	0x40
+	field	ENSCSIRST	0x20
+	field	ENPHASEMIS	0x10
+	field	ENBUSFREE	0x08
+	field	ENSCSIPERR	0x04
+	field	ENSTRB2FAST	0x02
+	field	ENREQINIT	0x01
+}
+
+/*
+ * Good Status FIFO
+ */
+register GSFIFO {
+	address			0x058
+	access_mode	RO
+	size		2
+	modes		M_DFF0, M_DFF1, M_SCSI
+}
+
+/*
+ * Data FIFO SCSI Transfer Control
+ */
+register DFFSXFRCTL {
+	address			0x05A
+	access_mode	RW
+	modes		M_DFF0, M_DFF1
+	field	DFFBITBUCKET	0x08
+	field	CLRSHCNT	0x04
+	field	CLRCHN		0x02
+	field	RSTCHN		0x01
+}
+
+/*
+ * Next SCSI Control Block
+ */
+register NEXTSCB {
+	address			0x05A
+	access_mode	RW
+	size		2
+	modes		M_SCSI
+}
+
+/* Rev B only. */
+register LQOSCSCTL {
+	address			0x05A
+	access_mode	RW
+	size		1
+	modes		M_CFG
+	field		LQOH2A_VERSION	0x80
+	field		LQONOCHKOVER	0x01
+}
+
+/*
+ * SEQ Interrupts
+ */
+register SEQINTSRC {
+	address			0x05B
+	access_mode	RO
+	modes		M_DFF0, M_DFF1
+	field	CTXTDONE	0x40
+	field	SAVEPTRS	0x20
+	field	CFG4DATA	0x10
+	field	CFG4ISTAT	0x08
+	field	CFG4TSTAT	0x04
+	field	CFG4ICMD	0x02
+	field	CFG4TCMD	0x01
+}
+
+/*
+ * Clear Arp Interrupts
+ */
+register CLRSEQINTSRC {
+	address			0x05B
+	access_mode	WO
+	modes		M_DFF0, M_DFF1
+	field	CLRCTXTDONE	0x40
+	field	CLRSAVEPTRS	0x20
+	field	CLRCFG4DATA	0x10
+	field	CLRCFG4ISTAT	0x08
+	field	CLRCFG4TSTAT	0x04
+	field	CLRCFG4ICMD	0x02
+	field	CLRCFG4TCMD	0x01
+}
+
+/*
+ * SEQ Interrupt Enabled (Shared)
+ */
+register SEQIMODE {
+	address			0x05C
+	access_mode	RW
+	modes		M_DFF0, M_DFF1
+	field	ENCTXTDONE	0x40
+	field	ENSAVEPTRS	0x20
+	field	ENCFG4DATA	0x10
+	field	ENCFG4ISTAT	0x08
+	field	ENCFG4TSTAT	0x04
+	field	ENCFG4ICMD	0x02
+	field	ENCFG4TCMD	0x01
+}
+
+/*
+ * Current SCSI Control Block
+ */
+register CURRSCB {
+	address			0x05C
+	access_mode	RW
+	size		2
+	modes		M_SCSI
+}
+
+/*
+ * Data FIFO Status
+ */
+register MDFFSTAT {
+	address			0x05D
+	access_mode	RO
+	modes		M_DFF0, M_DFF1
+	field	SHCNTNEGATIVE	0x40 /* Rev B or higher */
+	field	SHCNTMINUS1	0x20 /* Rev B or higher */
+	field	LASTSDONE	0x10
+	field	SHVALID		0x08
+	field	DLZERO		0x04 /* FIFO data ends on packet boundary. */
+	field	DATAINFIFO	0x02
+	field	FIFOFREE	0x01
+}
+
+/*
+ * CRC Control
+ */
+register CRCCONTROL {
+	address			0x05d
+	access_mode	RW
+	modes		M_CFG
+	field	CRCVALCHKEN		0x40
+}
+
+/*
+ * SCSI Test Control
+ */
+register SCSITEST {
+	address			0x05E
+	access_mode	RW
+	modes		M_CFG
+	field	CNTRTEST	0x08
+	field	SEL_TXPLL_DEBUG	0x04
+}
+
+/*
+ * Data FIFO Queue Tag
+ */
+register DFFTAG {
+	address			0x05E
+	access_mode	RW
+	size		2
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * Last SCSI Control Block
+ */
+register LASTSCB {
+	address			0x05E
+	access_mode	RW
+	size		2
+	modes		M_SCSI
+}
+
+/*
+ * SCSI I/O Cell Power-down Control
+ */
+register IOPDNCTL {
+	address			0x05F
+	access_mode	RW
+	modes		M_CFG
+	field	DISABLE_OE	0x80
+	field	PDN_IDIST	0x04
+	field	PDN_DIFFSENSE	0x01
+}
+
+/*
+ * Shaddow Host Address.
+ */
+register SHADDR {
+	address			0x060
+	access_mode	RO
+	size		8
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * Data Group CRC Interval.
+ */
+register DGRPCRCI {
+	address			0x060
+	access_mode	RW
+	size		2
+	modes		M_CFG
+}
+
+/*
+ * Data Transfer Negotiation Address
+ */
+register NEGOADDR {
+	address			0x060
+	access_mode	RW
+	modes		M_SCSI
+}
+
+/*
+ * Data Transfer Negotiation Data - Period Byte
+ */
+register NEGPERIOD {
+	address			0x061
+	access_mode	RW
+	modes		M_SCSI
+}
+
+/*
+ * Packetized CRC Interval
+ */
+register PACKCRCI {
+	address			0x062
+	access_mode	RW
+	size		2
+	modes		M_CFG
+}
+
+/*
+ * Data Transfer Negotiation Data - Offset Byte
+ */
+register NEGOFFSET {
+	address			0x062
+	access_mode	RW
+	modes		M_SCSI
+}
+
+/*
+ * Data Transfer Negotiation Data - PPR Options
+ */
+register NEGPPROPTS {
+	address			0x063
+	access_mode	RW
+	modes		M_SCSI
+	field	PPROPT_PACE	0x08
+	field	PPROPT_QAS	0x04
+	field	PPROPT_DT	0x02
+	field	PPROPT_IUT	0x01
+}
+
+/*
+ * Data Transfer Negotiation Data -  Connection Options
+ */
+register NEGCONOPTS {
+	address			0x064
+	access_mode	RW
+	modes		M_SCSI
+	field	ENSNAPSHOT	0x40
+	field	RTI_WRTDIS	0x20
+	field	RTI_OVRDTRN	0x10
+	field	ENSLOWCRC	0x08
+	field	ENAUTOATNI	0x04
+	field	ENAUTOATNO	0x02
+	field	WIDEXFER	0x01
+}
+
+/*
+ * Negotiation Table Annex Column Index.
+ */
+register ANNEXCOL {
+	address			0x065
+	access_mode	RW
+	modes		M_SCSI
+}
+
+register SCSCHKN {
+	address			0x066
+	access_mode	RW
+	modes		M_CFG
+	field	STSELSKIDDIS	0x40
+	field	CURRFIFODEF	0x20
+	field	WIDERESEN	0x10
+	field	SDONEMSKDIS	0x08
+	field	DFFACTCLR	0x04
+	field	SHVALIDSTDIS	0x02
+	field	LSTSGCLRDIS	0x01
+}
+
+const AHD_ANNEXCOL_PER_DEV0	4
+const AHD_NUM_PER_DEV_ANNEXCOLS	4
+const AHD_ANNEXCOL_PRECOMP_SLEW	4
+const	AHD_PRECOMP_MASK	0x07
+const	AHD_PRECOMP_SHIFT	0
+const	AHD_PRECOMP_CUTBACK_17	0x04
+const	AHD_PRECOMP_CUTBACK_29	0x06
+const	AHD_PRECOMP_CUTBACK_37	0x07
+const	AHD_SLEWRATE_MASK	0x78
+const	AHD_SLEWRATE_SHIFT	3
+/*
+ * Rev A has only a single bit of slew adjustment.
+ * Rev B has 4 bits.
+ */
+const	AHD_SLEWRATE_DEF_REVA	0x01
+const	AHD_SLEWRATE_DEF_REVB	0x08
+
+/* Rev A does not have any amplitude setting. */
+const AHD_ANNEXCOL_AMPLITUDE	6
+const	AHD_AMPLITUDE_MASK	0x7
+const	AHD_AMPLITUDE_SHIFT	0
+const	AHD_AMPLITUDE_DEF	0x7
+
+/*
+ * Negotiation Table Annex Data Port.
+ */
+register ANNEXDAT {
+	address			0x066
+	access_mode	RW
+	modes		M_SCSI
+}
+
+/*
+ * Initiator's Own Id.
+ * The SCSI ID to use for Selection Out and seen during a reselection..
+ */
+register IOWNID {
+	address			0x067
+	access_mode	RW
+	modes		M_SCSI
+}
+
+/*
+ * 960MHz Phase-Locked Loop Control 0
+ */
+register PLL960CTL0 {
+	address			0x068
+	access_mode	RW
+	modes		M_CFG
+	field	PLL_VCOSEL	0x80
+	field	PLL_PWDN	0x40
+	field	PLL_NS		0x30
+	field	PLL_ENLUD	0x08
+	field	PLL_ENLPF	0x04
+	field	PLL_DLPF	0x02
+	field	PLL_ENFBM	0x01
+}
+
+/*
+ * Target Own Id
+ */
+register TOWNID {
+	address			0x069
+	access_mode	RW
+	modes		M_SCSI
+}
+
+/*
+ * 960MHz Phase-Locked Loop Control 1
+ */
+register PLL960CTL1 {
+	address			0x069
+	access_mode	RW
+	modes		M_CFG
+	field	PLL_CNTEN	0x80
+	field	PLL_CNTCLR	0x40
+	field	PLL_RST		0x01
+}
+
+/*
+ * Expander Signature
+ */
+register XSIG {
+	address			0x06A
+	access_mode	RW
+	modes		M_SCSI
+}
+
+/*
+ * Shadow Byte Count
+ */
+register SHCNT {
+	address			0x068
+	access_mode	RW
+	size		3
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * Selection Out ID
+ */
+register SELOID {
+	address			0x06B
+	access_mode	RW
+	modes		M_SCSI
+}
+
+/*
+ * 960-MHz Phase-Locked Loop Test Count
+ */
+register PLL960CNT0 {
+	address			0x06A
+	access_mode	RO
+	size		2
+	modes		M_CFG
+}
+
+/*
+ * 400-MHz Phase-Locked Loop Control 0
+ */
+register PLL400CTL0 {
+	address			0x06C
+	access_mode	RW
+	modes		M_CFG
+	field	PLL_VCOSEL	0x80
+	field	PLL_PWDN	0x40
+	field	PLL_NS		0x30
+	field	PLL_ENLUD	0x08
+	field	PLL_ENLPF	0x04
+	field	PLL_DLPF	0x02
+	field	PLL_ENFBM	0x01
+}
+
+/*
+ * Arbitration Fairness
+ */
+register FAIRNESS {
+	address			0x06C
+	access_mode	RW
+	size		2
+	modes		M_SCSI
+}
+
+/*
+ * 400-MHz Phase-Locked Loop Control 1
+ */
+register PLL400CTL1 {
+	address			0x06D
+	access_mode	RW
+	modes		M_CFG
+	field	PLL_CNTEN	0x80
+	field	PLL_CNTCLR	0x40
+	field	PLL_RST		0x01
+}
+
+/*
+ * Arbitration Unfairness
+ */
+register UNFAIRNESS {
+	address			0x06E
+	access_mode	RW
+	size		2
+	modes		M_SCSI
+}
+
+/*
+ * 400-MHz Phase-Locked Loop Test Count
+ */
+register PLL400CNT0 {
+	address			0x06E
+	access_mode	RO
+	size		2
+	modes		M_CFG
+}
+
+/*
+ * SCB Page Pointer
+ */
+register SCBPTR {
+	address			0x0A8
+	access_mode	RW
+	size		2
+	modes		M_DFF0, M_DFF1, M_CCHAN, M_SCSI
+}
+
+/*
+ * CMC SCB Array Count
+ * Number of bytes to transfer between CMC SCB memory and SCBRAM.
+ * Transfers must be 8byte aligned and sized.
+ */
+register CCSCBACNT {
+	address			0x0AB
+	access_mode	RW
+	modes		M_CCHAN
+}
+
+/*
+ * SCB Autopointer
+ * SCB-Next Address Snooping logic.  When an SCB is transferred to
+ * the card, the next SCB address to be used by the CMC array can
+ * be autoloaded from that transfer.
+ */
+register SCBAUTOPTR {
+	address			0x0AB
+	access_mode	RW
+	modes		M_CFG
+	field	AUSCBPTR_EN	0x80
+	field	SCBPTR_ADDR	0x38
+	field	SCBPTR_OFF	0x07
+}
+
+/*
+ * CMC SG Ram Address Pointer
+ */
+register CCSGADDR {
+	address			0x0AC
+	access_mode	RW
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * CMC SCB RAM Address Pointer
+ */
+register CCSCBADDR {
+	address			0x0AC
+	access_mode	RW
+	modes		M_CCHAN
+}
+
+/*
+ * CMC SCB Ram Back-up Address Pointer
+ * Indicates the true stop location of transfers halted prior
+ * to SCBHCNT going to 0.
+ */
+register CCSCBADR_BK {
+	address			0x0AC
+	access_mode	RO
+	modes		M_CFG
+}
+
+/*
+ * CMC SG Control
+ */
+register CCSGCTL {
+	address			0x0AD
+	access_mode	RW
+	modes		M_DFF0, M_DFF1
+	field	CCSGDONE	0x80
+	field	SG_CACHE_AVAIL	0x10
+	field	CCSGENACK	0x08
+	mask	CCSGEN		0x0C
+	field	SG_FETCH_REQ	0x02
+	field	CCSGRESET	0x01
+}
+
+/*
+ * CMD SCB Control
+ */
+register CCSCBCTL {
+	address			0x0AD
+	access_mode	RW
+	modes		M_CCHAN
+	field	CCSCBDONE	0x80
+	field	ARRDONE		0x40
+	field	CCARREN		0x10
+	field	CCSCBEN		0x08
+	field	CCSCBDIR	0x04
+	field	CCSCBRESET	0x01
+}
+
+/*
+ * CMC Ram BIST
+ */
+register CMC_RAMBIST {
+	address			0x0AD
+	access_mode	RW
+	modes		M_CFG
+	field	SG_ELEMENT_SIZE		0x80
+	field	SCBRAMBIST_FAIL		0x40
+	field	SG_BIST_FAIL		0x20
+	field	SG_BIST_EN		0x10
+	field	CMC_BUFFER_BIST_FAIL	0x02
+	field	CMC_BUFFER_BIST_EN	0x01
+}
+
+/*
+ * CMC SG RAM Data Port
+ */
+register CCSGRAM {
+	address			0x0B0
+	access_mode	RW
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * CMC SCB RAM Data Port
+ */
+register CCSCBRAM {
+	address			0x0B0
+	access_mode	RW
+	modes		M_CCHAN
+}
+
+/*
+ * Flex DMA Address.
+ */
+register FLEXADR {
+	address			0x0B0
+	access_mode	RW
+	size		3
+	modes		M_SCSI
+}
+
+/*
+ * Flex DMA Byte Count
+ */
+register FLEXCNT {
+	address			0x0B3
+	access_mode	RW
+	size		2
+	modes		M_SCSI
+}
+
+/*
+ * Flex DMA Status
+ */
+register FLEXDMASTAT {
+	address			0x0B5
+	access_mode	RW
+	modes		M_SCSI
+	field	FLEXDMAERR	0x02
+	field	FLEXDMADONE	0x01
+}
+
+/*
+ * Flex DMA Data Port
+ */
+register FLEXDATA {
+	address			0x0B6
+	access_mode	RW
+	modes		M_SCSI
+}
+
+/*
+ * Board Data
+ */
+register BRDDAT {
+	address			0x0B8
+	access_mode	RW
+	modes		M_SCSI
+}
+
+/*
+ * Board Control
+ */
+register BRDCTL {
+	address			0x0B9
+	access_mode	RW
+	modes		M_SCSI
+	field	FLXARBACK	0x80
+	field	FLXARBREQ	0x40
+	field	BRDADDR		0x38
+	field	BRDEN		0x04
+	field	BRDRW		0x02
+	field	BRDSTB		0x01
+}
+
+/*
+ * Serial EEPROM Address
+ */
+register SEEADR {
+	address			0x0BA
+	access_mode	RW
+	modes		M_SCSI
+}
+
+/*
+ * Serial EEPROM Data
+ */
+register SEEDAT {
+	address			0x0BC
+	access_mode	RW
+	size		2
+	modes		M_SCSI
+}
+
+/*
+ * Serial EEPROM Status
+ */
+register SEESTAT {
+	address			0x0BE
+	access_mode	RO
+	modes		M_SCSI
+	field	INIT_DONE	0x80
+	field	SEEOPCODE	0x70
+	field	LDALTID_L	0x08
+	field	SEEARBACK	0x04
+	field	SEEBUSY		0x02
+	field	SEESTART	0x01
+}
+
+/*
+ * Serial EEPROM Control
+ */
+register SEECTL {
+	address			0x0BE
+	access_mode	RW
+	modes		M_SCSI
+	field	SEEOPCODE	0x70 {
+		SEEOP_ERASE	0x70,
+		SEEOP_READ	0x60,
+		SEEOP_WRITE	0x50,
+	/*
+	 * The following four commands use special
+	 * addresses for differentiation.
+	 */
+		SEEOP_ERAL	0x40
+	}
+	mask	SEEOP_EWEN	0x40
+	mask	SEEOP_WALL	0x40
+	mask	SEEOP_EWDS	0x40
+	field	SEERST		0x02
+	field	SEESTART	0x01
+}
+
+const SEEOP_ERAL_ADDR	0x80
+const SEEOP_EWEN_ADDR	0xC0
+const SEEOP_WRAL_ADDR	0x40
+const SEEOP_EWDS_ADDR	0x00
+
+/*
+ * SCB Counter
+ */
+register SCBCNT {
+	address			0x0BF
+	access_mode	RW
+	modes		M_SCSI
+}
+
+/*
+ * Data FIFO Write Address
+ * Pointer to the next QWD location to be written to the data FIFO.
+ */
+register DFWADDR {
+	address			0x0C0
+	access_mode	RW
+	size		2
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * DSP Filter Control
+ */
+register DSPFLTRCTL {
+	address			0x0C0
+	access_mode	RW
+	modes		M_CFG
+	field	FLTRDISABLE	0x20
+	field	EDGESENSE	0x10
+	field	DSPFCNTSEL	0x0F
+}
+
+/*
+ * DSP Data Channel Control
+ */
+register DSPDATACTL {
+	address			0x0C1
+	access_mode	RW
+	modes		M_CFG
+	field	BYPASSENAB	0x80
+	field	DESQDIS		0x10
+	field	RCVROFFSTDIS	0x04
+	field	XMITOFFSTDIS	0x02
+}
+
+/*
+ * Data FIFO Read Address
+ * Pointer to the next QWD location to be read from the data FIFO.
+ */
+register DFRADDR {
+	address			0x0C2
+	access_mode	RW
+	size		2
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * DSP REQ Control
+ */
+register DSPREQCTL {
+	address			0x0C2
+	access_mode	RW
+	modes		M_CFG
+	field	MANREQCTL	0xC0
+	field	MANREQDLY	0x3F
+}
+
+/*
+ * DSP ACK Control
+ */
+register DSPACKCTL {
+	address			0x0C3
+	access_mode	RW
+	modes		M_CFG
+	field	MANACKCTL	0xC0
+	field	MANACKDLY	0x3F
+}
+
+/*
+ * Data FIFO Data
+ * Read/Write byte port into the data FIFO.  The read and write
+ * FIFO pointers increment with each read and write respectively
+ * to this port.
+ */
+register DFDAT {
+	address			0x0C4
+	access_mode	RW
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * DSP Channel Select
+ */
+register DSPSELECT {
+	address			0x0C4
+	access_mode	RW
+	modes		M_CFG
+	field	AUTOINCEN	0x80
+	field	DSPSEL		0x1F
+}
+
+const NUMDSPS 0x14
+
+/*
+ * Write Bias Control
+ */
+register WRTBIASCTL {
+	address			0x0C5
+	access_mode	WO
+	modes		M_CFG
+	field	AUTOXBCDIS	0x80
+	field	XMITMANVAL	0x3F
+}
+
+/*
+ * Currently the WRTBIASCTL is the same as the default.
+ */
+const WRTBIASCTL_HP_DEFAULT 0x0
+
+/*
+ * Receiver Bias Control
+ */
+register RCVRBIOSCTL {
+	address			0x0C6
+	access_mode	WO
+	modes		M_CFG
+	field	AUTORBCDIS	0x80
+	field	RCVRMANVAL	0x3F
+}
+
+/*
+ * Write Bias Calculator
+ */
+register WRTBIASCALC {
+	address			0x0C7
+	access_mode	RO
+	modes		M_CFG
+}
+
+/*
+ * Data FIFO Pointers
+ * Contains the byte offset from DFWADDR and DWRADDR to the current
+ * FIFO write/read locations.
+ */
+register DFPTRS {
+	address			0x0C8
+	access_mode	RW
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * Receiver Bias Calculator
+ */
+register RCVRBIASCALC {
+	address			0x0C8
+	access_mode	RO
+	modes		M_CFG
+}
+
+/*
+ * Data FIFO Backup Read Pointer
+ * Contains the data FIFO address to be restored if the last
+ * data accessed from the data FIFO was not transferred successfully.
+ */
+register DFBKPTR {
+	address			0x0C9
+	access_mode	RW
+	size		2
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * Skew Calculator
+ */
+register SKEWCALC {
+	address			0x0C9
+	access_mode	RO
+	modes		M_CFG
+}
+
+/*
+ * Data FIFO Debug Control
+ */
+register DFDBCTL {
+	address				0x0CB
+	access_mode	RW
+	modes		M_DFF0, M_DFF1
+	field	DFF_CIO_WR_RDY		0x20
+	field	DFF_CIO_RD_RDY		0x10
+	field	DFF_DIR_ERR		0x08
+	field	DFF_RAMBIST_FAIL	0x04
+	field	DFF_RAMBIST_DONE	0x02
+	field	DFF_RAMBIST_EN		0x01
+}
+
+/*
+ * Data FIFO Space Count
+ * Number of FIFO locations that are free.
+ */
+register DFSCNT {
+	address			0x0CC
+	access_mode	RO
+	size		2
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * Data FIFO Byte Count
+ * Number of filled FIFO locations.
+ */
+register DFBCNT {
+	address			0x0CE
+	access_mode	RO
+	size		2
+	modes		M_DFF0, M_DFF1
+}
+
+/*
+ * Sequencer Program Overlay Address.
+ * Low address must be written prior to high address.
+ */
+register OVLYADDR {
+	address			0x0D4
+	modes		M_SCSI
+	size		2
+	access_mode	RW
+}
+
+/*
+ * Sequencer Control 0
+ * Error detection mode, speed configuration,
+ * single step, breakpoints and program load.
+ */
+register SEQCTL0 {
+	address			0x0D6
+	access_mode RW
+	field	PERRORDIS	0x80
+	field	PAUSEDIS	0x40
+	field	FAILDIS		0x20
+	field	FASTMODE	0x10
+	field	BRKADRINTEN	0x08
+	field	STEP		0x04
+	field	SEQRESET	0x02
+	field	LOADRAM		0x01
+}
+
+/*
+ * Sequencer Control 1
+ * Instruction RAM Diagnostics
+ */
+register SEQCTL1 {
+	address			0x0D7
+	access_mode RW
+	field	OVRLAY_DATA_CHK	0x08
+	field	RAMBIST_DONE	0x04
+	field	RAMBIST_FAIL	0x02
+	field	RAMBIST_EN	0x01
+}
+
+/*
+ * Sequencer Flags
+ * Zero and Carry state of the ALU.
+ */
+register FLAGS {
+	address			0x0D8
+	access_mode RO
+	field	ZERO		0x02
+	field	CARRY		0x01
+}
+
+/*
+ * Sequencer Interrupt Control
+ */ 
+register SEQINTCTL {
+	address			0x0D9
+	access_mode RW
+	field	INTVEC1DSL	0x80
+	field	INT1_CONTEXT	0x20
+	field	SCS_SEQ_INT1M1	0x10
+	field	SCS_SEQ_INT1M0	0x08
+	field	INTMASK2	0x04
+	field	INTMASK1	0x02
+	field	IRET		0x01
+}
+
+/*
+ * Sequencer RAM Data Port
+ * Single byte window into the Sequencer Instruction Ram area starting
+ * at the address specified by OVLYADDR.  To write a full instruction word,
+ * simply write four bytes in succession.  OVLYADDR will increment after the
+ * most significant instrution byte (the byte with the parity bit) is written.
+ */
+register SEQRAM {
+	address			0x0DA
+	access_mode RW
+}
+
+/*
+ * Sequencer Program Counter
+ * Low byte must be written prior to high byte.
+ */
+register PRGMCNT {
+	address			0x0DE
+	access_mode	RW
+	size		2
+}
+
+/*
+ * Accumulator
+ */
+register ACCUM {
+	address			0x0E0
+	access_mode RW
+	accumulator
+}
+
+/*
+ * Source Index Register
+ * Incrementing index for reads of SINDIR and the destination (low byte only)
+ * for any immediate operands passed in jmp, jc, jnc, call instructions.
+ * Example:
+ *		mvi	0xFF	call some_routine;
+ *
+ *  Will set SINDEX[0] to 0xFF and call the routine "some_routine.
+ */
+register SINDEX	{
+	address			0x0E2
+	access_mode	RW
+	size		2
+	sindex
+}
+
+/*
+ * Destination Index Register
+ * Incrementing index for writes to DINDIR.  Can be used as a scratch register.
+ */
+register DINDEX {
+	address			0x0E4
+	access_mode	RW
+	size		2
+}
+
+/*
+ * Break Address
+ * Sequencer instruction breakpoint address address.
+ */
+register BRKADDR0 {
+	address			0x0E6
+	access_mode	RW
+}
+
+register BRKADDR1 {
+	address			0x0E6
+	access_mode	RW
+	field	BRKDIS		0x80	/* Disable Breakpoint */
+}
+
+/*
+ * All Ones
+ * All reads to this register return the value 0xFF.
+ */
+register ALLONES {
+	address			0x0E8
+	access_mode RO
+	allones
+}
+
+/*
+ * All Zeros
+ * All reads to this register return the value 0.
+ */
+register ALLZEROS {
+	address			0x0EA
+	access_mode RO
+	allzeros
+}
+
+/*
+ * No Destination
+ * Writes to this register have no effect.
+ */
+register NONE {
+	address			0x0EA
+	access_mode WO
+	none
+}
+
+/*
+ * Source Index Indirect
+ * Reading this register is equivalent to reading (register_base + SINDEX) and
+ * incrementing SINDEX by 1.
+ */
+register SINDIR	{
+	address			0x0EC
+	access_mode RO
+}
+
+/*
+ * Destination Index Indirect
+ * Writing this register is equivalent to writing to (register_base + DINDEX)
+ * and incrementing DINDEX by 1.
+ */
+register DINDIR	 {
+	address			0x0ED
+	access_mode WO
+}
+
+/*
+ * Function One
+ * 2's complement to bit value conversion.  Write the 2's complement value
+ * (0-7 only) to the top nibble and retrieve the bit indexed by that value
+ * on the next read of this register. 
+ * Example:
+ *	Write	0x60
+ *	Read	0x40
+ */
+register FUNCTION1 {
+	address			0x0F0
+	access_mode RW
+}
+
+/*
+ * Stack
+ * Window into the stack.  Each stack location is 10 bits wide reported
+ * low byte followed by high byte.  There are 8 stack locations.
+ */
+register STACK {
+	address			0x0F2
+	access_mode RW
+}
+
+/*
+ * Interrupt Vector 1 Address
+ * Interrupt branch address for SCS SEQ_INT1 mode 0 and 1 interrupts.
+ */
+register INTVEC1_ADDR {
+	address			0x0F4
+	access_mode	RW
+	size		2
+	modes		M_CFG
+}
+
+/*
+ * Current Address
+ * Address of the SEQRAM instruction currently executing instruction.
+ */
+register CURADDR {
+	address			0x0F4
+	access_mode	RW
+	size		2
+	modes		M_SCSI
+}
+
+/*
+ * Interrupt Vector 2 Address
+ * Interrupt branch address for HST_SEQ_INT2 interrupts.
+ */
+register INTVEC2_ADDR {
+	address			0x0F6
+	access_mode	RW
+	size		2
+	modes		M_CFG
+}
+
+/*
+ * Last Address
+ * Address of the SEQRAM instruction executed prior to the current instruction.
+ */
+register LASTADDR {
+	address			0x0F6
+	access_mode	RW
+	size		2
+	modes		M_SCSI
+}
+
+register AHD_PCI_CONFIG_BASE {
+	address			0x100
+	access_mode	RW
+	size		256
+	modes		M_CFG
+}
+
+/* ---------------------- Scratch RAM Offsets ------------------------- */
+scratch_ram {
+	/* Mode Specific */
+	address			0x0A0
+	size	8
+	modes	0, 1, 2, 3
+	REG0 {
+		size		2
+	}
+	REG1 {
+		size		2
+	}
+	REG_ISR {
+		size		2
+	}
+	SG_STATE {
+		size		1
+		field	SEGS_AVAIL	0x01
+		field	LOADING_NEEDED	0x02
+		field	FETCH_INPROG	0x04
+	}
+	/*
+	 * Track whether the transfer byte count for
+	 * the current data phase is odd.
+	 */
+	DATA_COUNT_ODD {
+		size		1
+	}
+}
+
+scratch_ram {
+	/* Mode Specific */
+	address			0x0F8
+	size	8
+	modes	0, 1, 2, 3
+	LONGJMP_ADDR {
+		size		2
+	}
+	LONGJMP_SCB {
+		size		2
+	}
+	ACCUM_SAVE {
+		size		1
+	}
+}
+
+
+scratch_ram {
+	address			0x100
+	size	128
+	modes	0, 1, 2, 3
+	/*
+	 * Per "other-id" execution queues.  We use an array of
+	 * tail pointers into lists of SCBs sorted by "other-id".
+	 * The execution head pointer threads the head SCBs for
+	 * each list.
+	 */
+	WAITING_SCB_TAILS {
+		size		32
+	}
+	WAITING_TID_HEAD {
+		size		2
+	}
+	WAITING_TID_TAIL {
+		size		2
+	}
+	/*
+	 * SCBID of the next SCB in the new SCB queue.
+	 */
+	NEXT_QUEUED_SCB_ADDR {
+		size		4
+	}
+	/*
+	 * head of list of SCBs that have
+	 * completed but have not been
+	 * put into the qoutfifo.
+	 */
+	COMPLETE_SCB_HEAD {
+		size		2
+	}
+	/*
+	 * The list of completed SCBs in
+	 * the active DMA.
+	 */
+	COMPLETE_SCB_DMAINPROG_HEAD {
+		size		2
+	}
+	/*
+	 * head of list of SCBs that have
+	 * completed but need to be uploaded
+	 * to the host prior to being completed.
+	 */
+	COMPLETE_DMA_SCB_HEAD {
+		size		2
+	}
+	/* Counting semaphore to prevent new select-outs */
+	QFREEZE_COUNT {
+		size		2
+	}
+	/*
+	 * Mode to restore on legacy idle loop exit.
+	 */
+	SAVED_MODE {
+		size		1
+	}
+	/*
+	 * Single byte buffer used to designate the type or message
+	 * to send to a target.
+	 */
+	MSG_OUT {
+		size		1
+	}
+	/* Parameters for DMA Logic */
+	DMAPARAMS {
+		size		1
+		field	PRELOADEN	0x80
+		field	WIDEODD		0x40
+		field	SCSIEN		0x20
+		field	SDMAEN		0x10
+		field	SDMAENACK	0x10
+		field	HDMAEN		0x08
+		field	HDMAENACK	0x08
+		field	DIRECTION	0x04	/* Set indicates PCI->SCSI */
+		field	FIFOFLUSH	0x02
+		field	FIFORESET	0x01
+	}
+	SEQ_FLAGS {
+		size		1
+		field	NOT_IDENTIFIED		0x80
+		field	NO_CDB_SENT		0x40
+		field	TARGET_CMD_IS_TAGGED	0x40
+		field	DPHASE			0x20
+		/* Target flags */
+		field	TARG_CMD_PENDING	0x10
+		field	CMDPHASE_PENDING	0x08
+		field	DPHASE_PENDING		0x04
+		field	SPHASE_PENDING		0x02
+		field	NO_DISCONNECT		0x01
+	}
+	/*
+	 * Temporary storage for the
+	 * target/channel/lun of a
+	 * reconnecting target
+	 */
+	SAVED_SCSIID {
+		size		1
+	}
+	SAVED_LUN {
+		size		1
+	}
+	/*
+	 * The last bus phase as seen by the sequencer. 
+	 */
+	LASTPHASE {
+		size		1
+		field	CDI		0x80
+		field	IOI		0x40
+		field	MSGI		0x20
+		field	P_BUSFREE	0x01
+		enum	PHASE_MASK  CDO|IOO|MSGO {
+			P_DATAOUT	0x0,
+			P_DATAIN	IOO,
+			P_DATAOUT_DT	P_DATAOUT|MSGO,
+			P_DATAIN_DT	P_DATAIN|MSGO,
+			P_COMMAND	CDO,
+			P_MESGOUT	CDO|MSGO,
+			P_STATUS	CDO|IOO,
+			P_MESGIN	CDO|IOO|MSGO
+		}
+	}
+	/*
+	 * Value to "or" into the SCBPTR[1] value to
+	 * indicate that an entry in the QINFIFO is valid.
+	 */
+	QOUTFIFO_ENTRY_VALID_TAG {
+		size		1
+	}
+	/*
+	 * Base address of our shared data with the kernel driver in host
+	 * memory.  This includes the qoutfifo and target mode
+	 * incoming command queue.
+	 */
+	SHARED_DATA_ADDR {
+		size		4
+	}
+	/*
+	 * Pointer to location in host memory for next
+	 * position in the qoutfifo.
+	 */
+	QOUTFIFO_NEXT_ADDR {
+		size		4
+	}
+	/*
+	 * Kernel and sequencer offsets into the queue of
+	 * incoming target mode command descriptors.  The
+	 * queue is full when the KERNEL_TQINPOS == TQINPOS.
+	 */
+	KERNEL_TQINPOS {
+		size		1
+	}
+	TQINPOS {                
+		size		1
+	}
+	ARG_1 {
+		size		1
+		mask	SEND_MSG		0x80
+		mask	SEND_SENSE		0x40
+		mask	SEND_REJ		0x20
+		mask	MSGOUT_PHASEMIS		0x10
+		mask	EXIT_MSG_LOOP		0x08
+		mask	CONT_MSG_LOOP_WRITE	0x04
+		mask	CONT_MSG_LOOP_READ	0x03
+		mask	CONT_MSG_LOOP_TARG	0x02
+		alias	RETURN_1
+	}
+	ARG_2 {
+		size		1
+		alias	RETURN_2
+	}
+
+	/*
+	 * Snapshot of MSG_OUT taken after each message is sent.
+	 */
+	LAST_MSG {
+		size		1
+	}
+
+	/*
+	 * Sequences the kernel driver has okayed for us.  This allows
+	 * the driver to do things like prevent initiator or target
+	 * operations.
+	 */
+	SCSISEQ_TEMPLATE {
+		size		1
+		field	MANUALCTL	0x40
+		field	ENSELI		0x20
+		field	ENRSELI		0x10
+		field	MANUALP		0x0C
+		field	ENAUTOATNP	0x02
+		field	ALTSTIM		0x01
+	}
+
+	/*
+	 * The initiator specified tag for this target mode transaction.
+	 */
+	INITIATOR_TAG {
+		size		1
+	}
+
+	SEQ_FLAGS2 {
+		size		1
+		field	TARGET_MSG_PENDING	  0x02
+		field	SELECTOUT_QFROZEN	  0x04
+	}
+
+	ALLOCFIFO_SCBPTR {
+		size		2
+	}
+
+	/*
+	 * The maximum amount of time to wait, when interrupt coalessing
+	 * is enabled, before issueing a CMDCMPLT interrupt for a completed
+	 * command.
+	 */
+	INT_COALESSING_TIMER {
+		size		2
+	}
+
+	/*
+	 * The maximum number of commands to coaless into a single interrupt.
+	 * Actually the 2's complement of that value to simplify sequencer
+	 * code.
+	 */
+	INT_COALESSING_MAXCMDS {
+		size		1
+	}
+
+	/*
+	 * The minimum number of commands still outstanding required
+	 * to continue coalessing (2's compliment of value).
+	 */
+	INT_COALESSING_MINCMDS {
+		size		1
+	}
+
+	/*
+	 * Number of commands "in-flight".
+	 */
+	CMDS_PENDING {
+		size		2
+	}
+
+	/*
+	 * The count of commands that have been coalessed.
+	 */
+	INT_COALESSING_CMDCOUNT {
+		size		1
+	}
+
+	/*
+	 * Since the HS_MAIBOX is self clearing, copy its contents to
+	 * this position in scratch ram every time it changes.
+	 */
+	LOCAL_HS_MAILBOX {
+		size		1
+	}
+	/*
+	 * Target-mode CDB type to CDB length table used
+	 * in non-packetized operation.
+	 */
+	CMDSIZE_TABLE {
+		size		8
+	}
+}
+
+/************************* Hardware SCB Definition ****************************/
+scb {
+	address			0x180
+	size	64
+	modes	0, 1, 2, 3
+	SCB_RESIDUAL_DATACNT {
+		size	4
+		alias	SCB_CDB_STORE
+	}
+	SCB_RESIDUAL_SGPTR {
+		size	4
+		alias	SCB_CDB_PTR
+		field	SG_ADDR_MASK		0xf8	/* In the last byte */
+		field	SG_OVERRUN_RESID	0x02	/* In the first byte */
+		field	SG_LIST_NULL		0x01	/* In the first byte */
+	}
+	SCB_SCSI_STATUS {
+		size	1
+	}
+	SCB_TARGET_PHASES {
+		size	1
+	}
+	SCB_TARGET_DATA_DIR {
+		size	1
+	}
+	SCB_TARGET_ITAG {
+		size	1
+	}
+	SCB_SENSE_BUSADDR {
+		/*
+		 * Only valid if CDB length is less than 13 bytes or
+		 * we are using a CDB pointer.  Otherwise contains
+		 * the last 4 bytes of embedded cdb information.
+		 */
+		size	4
+		alias	SCB_NEXT_COMPLETE
+	}
+	SCB_TAG {
+		size	2
+	}
+	SCB_CDB_LEN {
+		size	1
+		field	SCB_CDB_LEN_PTR	0x80	/* CDB in host memory */
+	}
+	SCB_TASK_MANAGEMENT {
+		size	1
+	}
+	SCB_NEXT {
+		alias	SCB_NEXT_SCB_BUSADDR
+		size	2
+	}
+	SCB_NEXT2 {
+		size	2
+	}
+	SCB_DATAPTR {
+		size	8
+	}
+	SCB_DATACNT {
+		/*
+		 * The last byte is really the high address bits for
+		 * the data address.
+		 */
+		size	4
+		field	SG_LAST_SEG		0x80	/* In the fourth byte */
+		field	SG_HIGH_ADDR_BITS	0x7F	/* In the fourth byte */
+	}
+	SCB_SGPTR {
+		size	4
+		field	SG_STATUS_VALID	0x04	/* In the first byte */
+		field	SG_FULL_RESID	0x02	/* In the first byte */
+		field	SG_LIST_NULL	0x01	/* In the first byte */
+	}
+	SCB_CONTROL {
+		size	1
+		field	TARGET_SCB	0x80
+		field	DISCENB		0x40
+		field	TAG_ENB		0x20
+		field	MK_MESSAGE	0x10
+		field	STATUS_RCVD	0x08
+		field	DISCONNECTED	0x04
+		field	SCB_TAG_TYPE	0x03
+	}
+	SCB_SCSIID {
+		size	1
+		field	TID	0xF0
+		field	OID	0x0F
+	}
+	SCB_LUN {
+		size	1
+		field	LID				0xff
+	}
+	SCB_TASK_ATTRIBUTE {
+		size	1
+	}
+	SCB_BUSADDR {
+		size	4
+	}
+	SCB_SPARE {
+		size	8
+		alias	SCB_PKT_LUN
+	}
+	SCB_DISCONNECTED_LISTS {
+		size	8
+	}
+}
+
+/*********************************** Constants ********************************/
+const MK_MESSAGE_BIT_OFFSET	4
+const TID_SHIFT		4
+const TARGET_CMD_CMPLT	0xfe
+const INVALID_ADDR	0x80
+#define SCB_LIST_NULL	0xff
+#define QOUTFIFO_ENTRY_VALID_TOGGLE	0x80
+
+const CCSGADDR_MAX	0x80
+const CCSCBADDR_MAX	0x80
+const CCSGRAM_MAXSEGS	16
+
+/* Selection Timeout Timer Constants */
+const STIMESEL_SHIFT	3
+const STIMESEL_MIN	0x18
+const STIMESEL_BUG_ADJ	0x8
+
+/* WDTR Message values */
+const BUS_8_BIT			0x00
+const BUS_16_BIT		0x01
+const BUS_32_BIT		0x02
+
+/* Offset maximums */
+const MAX_OFFSET		0xfe
+const MAX_OFFSET_PACED		0xfe
+const MAX_OFFSET_PACED_BUG	0x7f
+/*
+ * Some 160 devices incorrectly accept 0xfe as a
+ * sync offset, but will overrun this value.  Limit
+ * to 0x7f for speed lower than U320 which will
+ * avoid the persistent sync offset overruns.
+ */
+const MAX_OFFSET_NON_PACED	0x7f
+const HOST_MSG			0xff
+
+/*
+ * The size of our sense buffers.
+ * Sense buffer mapping can be handled in either of two ways.
+ * The first is to allocate a dmamap for each transaction.
+ * Depending on the architecture, dmamaps can be costly. The
+ * alternative is to statically map the buffers in much the same
+ * way we handle our scatter gather lists.  The driver implements
+ * the later.
+ */
+const AHD_SENSE_BUFSIZE		256
+
+/* Target mode command processing constants */
+const CMD_GROUP_CODE_SHIFT	0x05
+
+const STATUS_BUSY		0x08
+const STATUS_QUEUE_FULL		0x28
+const STATUS_PKT_SENSE		0xFF
+const TARGET_DATA_IN		1
+
+const SCB_TRANSFER_SIZE_FULL_LUN	56
+const SCB_TRANSFER_SIZE_1BYTE_LUN	48
+/* PKT_OVERRUN_BUFSIZE must be a multiple of 256 less than 64K */
+const PKT_OVERRUN_BUFSIZE	512
+
+/*
+ * Timer parameters.
+ */
+const AHD_TIMER_US_PER_TICK	25
+const AHD_TIMER_MAX_TICKS	0xFFFF
+const AHD_TIMER_MAX_US		(AHD_TIMER_MAX_TICKS * AHD_TIMER_US_PER_TICK)
+
+/*
+ * Downloaded (kernel inserted) constants
+ */
+const SG_PREFETCH_CNT download
+const SG_PREFETCH_CNT_LIMIT download
+const SG_PREFETCH_ALIGN_MASK download
+const SG_PREFETCH_ADDR_MASK download
+const SG_SIZEOF download
+const PKT_OVERRUN_BUFOFFSET download
+const SCB_TRANSFER_SIZE	download
+
+/*
+ * BIOS SCB offsets
+ */
+const NVRAM_SCB_OFFSET	0x2C
diff -Nru a/drivers/scsi/aic7xxx/aic79xx.seq b/drivers/scsi/aic7xxx/aic79xx.seq
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aic79xx.seq	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,1868 @@
+/*
+ * Adaptec U320 device driver firmware for Linux and FreeBSD.
+ *
+ * Copyright (c) 1994-2001 Justin T. Gibbs.
+ * Copyright (c) 2000-2002 Adaptec Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $FreeBSD$
+ */
+
+VERSION = "$Id: //depot/aic7xxx/aic7xxx/aic79xx.seq#77 $"
+PATCH_ARG_LIST = "struct ahd_softc *ahd"
+PREFIX = "ahd_"
+
+#include "aic79xx.reg"
+#include "scsi_message.h"
+
+restart:
+if ((ahd->bugs & AHD_INTCOLLISION_BUG) != 0) {
+	test	SEQINTCODE, 0xFF jz idle_loop;
+	SET_SEQINTCODE(NO_SEQINT)
+}
+
+idle_loop:
+
+	if ((ahd->bugs & AHD_INTCOLLISION_BUG) != 0) {
+		/*
+		 * Convert ERROR status into a sequencer
+		 * interrupt to handle the case of an
+		 * interrupt collision on the hardware
+		 * setting of HWERR.
+		 */
+		test	ERROR, 0xFF jz no_error_set;
+		SET_SEQINTCODE(SAW_HWERR)
+no_error_set:
+	}
+	SET_MODE(M_SCSI, M_SCSI)
+	test	SCSISEQ0, ENSELO|ENARBO jnz idle_loop_checkbus;
+	test	SEQ_FLAGS2, SELECTOUT_QFROZEN jnz idle_loop_checkbus;
+	cmp	WAITING_TID_HEAD[1], SCB_LIST_NULL je idle_loop_checkbus;
+	/*
+	 * ENSELO is cleared by a SELDO, so we must test for SELDO
+	 * one last time.
+	 */
+BEGIN_CRITICAL;
+	test	SSTAT0, SELDO jnz select_out;
+END_CRITICAL;
+	call	start_selection;
+idle_loop_checkbus:
+BEGIN_CRITICAL;
+	test	SSTAT0, SELDO jnz select_out;
+END_CRITICAL;
+	test	SSTAT0, SELDI jnz select_in;
+	test	SCSIPHASE, ~DATA_PHASE_MASK jz idle_loop_check_nonpackreq;
+	test	SCSISIGO, ATNO jz idle_loop_check_nonpackreq;
+	call	unexpected_nonpkt_phase_find_ctxt;
+idle_loop_check_nonpackreq:
+	test	SSTAT2, NONPACKREQ jz . + 2;
+	call	unexpected_nonpkt_phase_find_ctxt;
+	call	idle_loop_gsfifo_in_scsi_mode;
+	call	idle_loop_service_fifos;
+	call	idle_loop_cchan;
+	jmp	idle_loop;
+
+BEGIN_CRITICAL;
+idle_loop_gsfifo:
+	SET_MODE(M_SCSI, M_SCSI)
+idle_loop_gsfifo_in_scsi_mode:
+	test	LQISTAT2, LQIGSAVAIL jz return;
+	/*
+	 * We have received good status for this transaction.  There may
+	 * still be data in our FIFOs draining to the host.  Setup
+	 * monitoring of the draining process or complete the SCB.
+	 */
+good_status_IU_done:
+	bmov	SCBPTR, GSFIFO, 2;
+	clr	SCB_SCSI_STATUS;
+	or	SCB_CONTROL, STATUS_RCVD;
+
+	/*
+	 * Since this status did not consume a FIFO, we have to
+	 * be a bit more dilligent in how we check for FIFOs pertaining
+	 * to this transaction.  There are three states that a FIFO still
+	 * transferring data may be in.
+	 *
+	 * 1) Configured and draining to the host, with a pending CLRCHN.
+	 * 2) Configured and draining to the host, no pending CLRCHN.
+	 * 3) Pending cfg4data, fifo not empty.
+	 *
+	 * Cases 1 and 2 can be detected by noticing that a longjmp is
+	 * active for the FIFO and LONGJMP_SCB matches our SCB.  In this
+	 * case, we allow the routine servicing the FIFO to complete the SCB.
+	 * 
+	 * Case 3 implies either a pending or yet to occur save data
+	 * pointers for this same context in the other FIFO.  So, if
+	 * we detect case 2, we will properly defer the post of the SCB
+	 * and achieve the desired result.  The pending cfg4data will
+	 * notice that status has been received and complete the SCB.
+	 */
+	test	SCB_SGPTR, SG_LIST_NULL jz good_status_check_fifos;
+	/*
+	 * All segments have been loaded (or no data transfer), so
+	 * it is safe to complete the command.  Since this was a
+	 * cheap command to check for completion, loop to see if
+	 * more entries can be removed from the GSFIFO.
+	 */
+	call	complete;
+END_CRITICAL;
+	jmp	idle_loop_gsfifo_in_scsi_mode;
+BEGIN_CRITICAL;
+good_status_check_fifos:
+	clc;
+	bmov	ARG_1, SCBPTR, 2;
+	SET_MODE(M_DFF0, M_DFF0)
+	call	check_fifo;
+	jc	return;
+	SET_MODE(M_DFF1, M_DFF1)
+	call	check_fifo;
+	jc	return;
+	SET_MODE(M_SCSI, M_SCSI)
+	jmp	queue_scb_completion;
+END_CRITICAL;
+
+idle_loop_service_fifos:
+	SET_MODE(M_DFF0, M_DFF0)
+	test	LONGJMP_ADDR[1], INVALID_ADDR jnz idle_loop_next_fifo;
+	call	longjmp;
+idle_loop_next_fifo:
+	SET_MODE(M_DFF1, M_DFF1)
+	test	LONGJMP_ADDR[1], INVALID_ADDR jz longjmp;
+	ret;
+
+idle_loop_cchan:
+	SET_MODE(M_CCHAN, M_CCHAN)
+	test	QOFF_CTLSTA, HS_MAILBOX_ACT jz	hs_mailbox_empty;
+	mov	LOCAL_HS_MAILBOX, HS_MAILBOX;
+	or	QOFF_CTLSTA, HS_MAILBOX_ACT;
+hs_mailbox_empty:
+BEGIN_CRITICAL;
+	test	CCSCBCTL, CCARREN|CCSCBEN jz scbdma_idle;
+	test	CCSCBCTL, CCSCBDIR jnz fetch_new_scb_inprog;
+	test	CCSCBCTL, CCSCBDONE jz return;
+END_CRITICAL;
+	/* FALLTHROUGH */
+scbdma_tohost_done:
+	test	CCSCBCTL, CCARREN jz fill_qoutfifo_dmadone;
+	/*
+	 * A complete SCB upload requires no intervention.
+	 * The SCB is already on the COMPLETE_SCB list
+	 * and its completion notification will now be
+	 * handled just like any other SCB.
+	 */
+	and	CCSCBCTL, ~(CCARREN|CCSCBEN) ret;
+fill_qoutfifo_dmadone:
+	and	CCSCBCTL, ~(CCARREN|CCSCBEN);
+	call	qoutfifo_updated;
+	mvi	COMPLETE_SCB_DMAINPROG_HEAD[1], SCB_LIST_NULL;
+	bmov	QOUTFIFO_NEXT_ADDR, SCBHADDR, 4;
+	test	QOFF_CTLSTA, SDSCB_ROLLOVR jz return;
+	bmov	QOUTFIFO_NEXT_ADDR, SHARED_DATA_ADDR, 4;
+	xor	QOUTFIFO_ENTRY_VALID_TAG, QOUTFIFO_ENTRY_VALID_TOGGLE ret;
+
+qoutfifo_updated:
+	/*
+	 * If there are more commands waiting to be dma'ed
+	 * to the host, always coaless.  Otherwise honor the
+	 * host's wishes.
+	 */
+	cmp	COMPLETE_DMA_SCB_HEAD[1], SCB_LIST_NULL jne coaless_by_count;
+	cmp	COMPLETE_SCB_HEAD[1], SCB_LIST_NULL jne coaless_by_count;
+	test	LOCAL_HS_MAILBOX, ENINT_COALESS jz issue_cmdcmplt;
+
+	/*
+	 * If we have relatively few commands outstanding, don't
+	 * bother waiting for another command to complete.
+	 */
+	test	CMDS_PENDING[1], 0xFF jnz coaless_by_count;
+	/* Add -1 so that jnc means <= not just < */
+	add	A, -1, INT_COALESSING_MINCMDS;
+	add	NONE, A, CMDS_PENDING;
+	jnc	issue_cmdcmplt;
+	
+	/*
+	 * If coalessing, only coaless up to the limit
+	 * provided by the host driver.
+	 */
+coaless_by_count:
+	mov	A, INT_COALESSING_MAXCMDS;
+	add	NONE, A, INT_COALESSING_CMDCOUNT;
+	jc	issue_cmdcmplt;
+	/*
+	 * If the timer is not currently active,
+	 * fire it up.
+	 */
+	test	INTCTL, SWTMINTMASK jz return;
+	bmov	SWTIMER, INT_COALESSING_TIMER, 2;
+	mvi	CLRSEQINTSTAT, CLRSEQ_SWTMRTO;
+	or	INTCTL, SWTMINTEN|SWTIMER_START;
+	and	INTCTL, ~SWTMINTMASK ret;
+
+issue_cmdcmplt:
+	mvi	INTSTAT, CMDCMPLT;
+	clr	INT_COALESSING_CMDCOUNT;
+	or	INTCTL, SWTMINTMASK ret;
+
+BEGIN_CRITICAL;
+fetch_new_scb_inprog:
+	test	CCSCBCTL, ARRDONE jz return;
+fetch_new_scb_done:
+	and	CCSCBCTL, ~(CCARREN|CCSCBEN);
+	bmov	REG0, SCBPTR, 2;
+	clr	A;
+	add	CMDS_PENDING, 1;
+	adc	CMDS_PENDING[1], A;
+	/* Update the next SCB address to download. */
+	bmov	NEXT_QUEUED_SCB_ADDR, SCB_NEXT_SCB_BUSADDR, 4;
+	mvi	SCB_NEXT[1], SCB_LIST_NULL;
+	mvi	SCB_NEXT2[1], SCB_LIST_NULL;
+	/* Increment our position in the QINFIFO. */
+	mov	NONE, SNSCB_QOFF;
+	/*
+	 * SCBs that want to send messages are always
+	 * queued independently.  This ensures that they
+	 * are at the head of the SCB list to select out
+	 * to a target and we will see the MK_MESSAGE flag.
+	 */
+	test	SCB_CONTROL, MK_MESSAGE jnz first_new_target_scb;
+	shr	SINDEX, 3, SCB_SCSIID;
+	and	SINDEX, ~0x1;
+	mvi	SINDEX[1], (WAITING_SCB_TAILS >> 8);
+	bmov	DINDEX, SINDEX, 2;
+	bmov	SCBPTR, SINDIR, 2;
+	bmov	DINDIR, REG0, 2;
+	cmp	SCBPTR[1], SCB_LIST_NULL je first_new_target_scb;
+	bmov	SCB_NEXT, REG0, 2 ret;
+first_new_target_scb:
+	cmp	WAITING_TID_HEAD[1], SCB_LIST_NULL je first_new_scb;
+	bmov	SCBPTR, WAITING_TID_TAIL, 2;
+	bmov	SCB_NEXT2, REG0, 2;
+	bmov	WAITING_TID_TAIL, REG0, 2 ret;
+first_new_scb:
+	bmov	WAITING_TID_HEAD, REG0, 2;
+	bmov	WAITING_TID_TAIL, REG0, 2 ret;
+END_CRITICAL;
+
+scbdma_idle:
+	/*
+	 * Give precedence to downloading new SCBs to execute
+	 * unless select-outs are currently frozen.
+	 */
+	test	SEQ_FLAGS2, SELECTOUT_QFROZEN jnz . + 2;
+BEGIN_CRITICAL;
+	test	QOFF_CTLSTA, NEW_SCB_AVAIL jnz fetch_new_scb;
+	cmp	COMPLETE_DMA_SCB_HEAD[1], SCB_LIST_NULL jne dma_complete_scb;
+	cmp	COMPLETE_SCB_HEAD[1], SCB_LIST_NULL je return;
+	/* FALLTHROUGH */
+fill_qoutfifo:
+	/*
+	 * Keep track of the SCBs we are dmaing just
+	 * in case the DMA fails or is aborted.
+	 */
+	mov	A, QOUTFIFO_ENTRY_VALID_TAG;
+	bmov	COMPLETE_SCB_DMAINPROG_HEAD, COMPLETE_SCB_HEAD, 2;
+	mvi	CCSCBCTL, CCSCBRESET;
+	bmov	SCBHADDR, QOUTFIFO_NEXT_ADDR, 4;
+	bmov	SCBPTR, COMPLETE_SCB_HEAD, 2;
+fill_qoutfifo_loop:
+	mov	CCSCBRAM, SCBPTR;
+	or	CCSCBRAM, A, SCBPTR[1];
+	mov	NONE, SDSCB_QOFF;
+	inc	INT_COALESSING_CMDCOUNT;
+	add	CMDS_PENDING, -1;
+	adc	CMDS_PENDING[1], -1;
+	cmp	SCB_NEXT_COMPLETE[1], SCB_LIST_NULL je fill_qoutfifo_done;
+	cmp	CCSCBADDR, CCSCBADDR_MAX je fill_qoutfifo_done;
+	test	QOFF_CTLSTA, SDSCB_ROLLOVR jnz fill_qoutfifo_done;
+	bmov	SCBPTR, SCB_NEXT_COMPLETE, 2;
+	jmp	fill_qoutfifo_loop;
+fill_qoutfifo_done:
+	mov	SCBHCNT, CCSCBADDR;
+	mvi	CCSCBCTL, CCSCBEN|CCSCBRESET;
+	bmov	COMPLETE_SCB_HEAD, SCB_NEXT_COMPLETE, 2;
+	mvi	SCB_NEXT_COMPLETE[1], SCB_LIST_NULL ret;
+
+fetch_new_scb:
+	bmov	SCBHADDR, NEXT_QUEUED_SCB_ADDR, 4;
+	mvi	CCARREN|CCSCBEN|CCSCBDIR|CCSCBRESET jmp dma_scb;
+dma_complete_scb:
+	bmov	SCBPTR, COMPLETE_DMA_SCB_HEAD, 2;
+	bmov	SCBHADDR, SCB_BUSADDR, 4;
+	mvi	CCARREN|CCSCBEN|CCSCBRESET call dma_scb;
+	/*
+	 * Now that we've started the DMA, push us onto
+	 * the normal completion queue to have our SCBID
+	 * posted to the kernel.
+	 */
+	bmov	COMPLETE_DMA_SCB_HEAD, SCB_NEXT_COMPLETE, 2;
+	bmov	SCB_NEXT_COMPLETE, COMPLETE_SCB_HEAD, 2;
+	bmov	COMPLETE_SCB_HEAD, SCBPTR, 2 ret;
+END_CRITICAL;
+
+/*
+ * Either post or fetch an SCB from host memory.  The caller
+ * is responsible for polling for transfer completion.
+ *
+ * Prerequisits: Mode == M_CCHAN
+ *		 SINDEX contains CCSCBCTL flags
+ *		 SCBHADDR set to Host SCB address
+ *		 SCBPTR set to SCB src location on "push" operations
+ */
+SET_SRC_MODE	M_CCHAN;
+SET_DST_MODE	M_CCHAN;
+dma_scb:
+	mvi	SCBHCNT, SCB_TRANSFER_SIZE;
+	mov	CCSCBCTL, SINDEX ret;
+
+BEGIN_CRITICAL;
+setjmp_setscb:
+	bmov	LONGJMP_SCB, SCBPTR, 2;
+setjmp:
+	bmov	LONGJMP_ADDR, STACK, 2 ret;
+setjmp_inline:
+	bmov	LONGJMP_ADDR, STACK, 2;
+longjmp:
+	bmov	STACK, LONGJMP_ADDR, 2 ret;
+END_CRITICAL;
+
+/*************************** Chip Bug Work Arounds ****************************/
+/*
+ * Must disable interrupts when setting the mode pointer
+ * register as an interrupt occurring mid update will
+ * fail to store the new mode value for restoration on
+ * an iret.
+ */
+if ((ahd->bugs & AHD_SET_MODE_BUG) != 0) {
+set_mode_work_around:
+	mvi	SEQINTCTL, INTVEC1DSL;
+	mov	MODE_PTR, SINDEX;
+	clr	SEQINTCTL ret;
+
+toggle_dff_mode_work_around:
+	mvi	SEQINTCTL, INTVEC1DSL;
+	xor	MODE_PTR, MK_MODE(M_DFF1, M_DFF1);
+	clr	SEQINTCTL ret;
+}
+
+
+if ((ahd->bugs & AHD_INTCOLLISION_BUG) != 0) {
+set_seqint_work_around:
+	mov	SEQINTCODE, SINDEX;
+	mvi	SEQINTCODE, NO_SEQINT ret;
+}
+
+/************************ Packetized LongJmp Routines *************************/
+SET_SRC_MODE	M_SCSI;
+SET_DST_MODE	M_SCSI;
+start_selection:
+BEGIN_CRITICAL;
+	if ((ahd->bugs & AHD_SENT_SCB_UPDATE_BUG) != 0) {
+		/*
+		 * Razor #494
+		 * Rev A hardware fails to update LAST/CURR/NEXTSCB
+		 * correctly after a packetized selection in several
+		 * situations:
+		 *
+		 * 1) If only one command existed in the queue, the
+		 *    LAST/CURR/NEXTSCB are unchanged.
+		 *
+		 * 2) In a non QAS, protocol allowed phase change,
+		 *    the queue is shifted 1 too far.  LASTSCB is
+		 *    the last SCB that was correctly processed.
+		 * 
+		 * 3) In the QAS case, if the full list of commands
+		 *    was successfully sent, NEXTSCB is NULL and neither
+		 *    CURRSCB nor LASTSCB can be trusted.  We must
+		 *    manually walk the list counting MAXCMDCNT elements
+		 *    to find the last SCB that was sent correctly.
+		 *
+		 * To simplify the workaround for this bug in SELDO
+		 * handling, we initialize LASTSCB prior to enabling
+		 * selection so we can rely on it even for case #1 above.
+		 */
+		bmov	LASTSCB, WAITING_TID_HEAD, 2;
+	}
+	bmov	CURRSCB, WAITING_TID_HEAD, 2;
+	bmov	SCBPTR, WAITING_TID_HEAD, 2;
+	shr	SELOID, 4, SCB_SCSIID;
+	/*
+	 * If we want to send a message to the device, ensure
+	 * we are selecting with atn irregardless of our packetized
+	 * agreement.  Since SPI4 only allows target reset or PPR
+	 * messages if this is a packetized connection, the change
+	 * to our negotiation table entry for this selection will
+	 * be cleared when the message is acted on.
+	 */
+	test	SCB_CONTROL, MK_MESSAGE jz . + 3;
+	mov	NEGOADDR, SELOID;
+	or	NEGCONOPTS, ENAUTOATNO;
+	or	SCSISEQ0, ENSELO ret;
+END_CRITICAL;
+
+/*
+ * Allocate a FIFO for a non-packetized transaction.
+ * In RevA hardware, both FIFOs must be free before we
+ * can allocate a FIFO for a non-packetized transaction.
+ */
+allocate_fifo_loop:
+	/*
+	 * Do whatever work is required to free a FIFO.
+	 */
+	call	idle_loop_service_fifos;
+	SET_MODE(M_SCSI, M_SCSI)
+allocate_fifo:
+	if ((ahd->bugs & AHD_NONPACKFIFO_BUG) != 0) {
+		and	A, FIFO0FREE|FIFO1FREE, DFFSTAT;
+		cmp	A, FIFO0FREE|FIFO1FREE jne allocate_fifo_loop;
+	} else {
+		test	DFFSTAT, FIFO1FREE jnz allocate_fifo1;
+		test	DFFSTAT, FIFO0FREE jz allocate_fifo_loop;
+		mvi	DFFSTAT, B_CURRFIFO_0;
+		SET_MODE(M_DFF0, M_DFF0)
+		bmov	SCBPTR, ALLOCFIFO_SCBPTR, 2 ret;
+	}
+SET_SRC_MODE	M_SCSI;
+SET_DST_MODE	M_SCSI;
+allocate_fifo1:
+	mvi	DFFSTAT, CURRFIFO_1;
+	SET_MODE(M_DFF1, M_DFF1)
+	bmov	SCBPTR, ALLOCFIFO_SCBPTR, 2 ret;
+
+/*
+ * We have been reselected as an initiator
+ * or selected as a target.
+ */
+SET_SRC_MODE	M_SCSI;
+SET_DST_MODE	M_SCSI;
+select_in:
+	if ((ahd->bugs & AHD_BUSFREEREV_BUG) != 0) {
+		/*
+		 * This exposes a window whereby a
+		 * busfree just after a selection will
+		 * be missed, but there is not other safe
+		 * way to enable busfree detection if
+		 * the busfreerev function is broken.
+		 */
+		mvi	CLRSINT1,CLRBUSFREE;
+		or	SIMODE1, ENBUSFREE;
+	}
+	or	SXFRCTL0, SPIOEN;
+	and	SAVED_SCSIID, SELID_MASK, SELID;
+	and	A, OID, IOWNID;
+	or	SAVED_SCSIID, A;
+	mvi	CLRSINT0, CLRSELDI;
+	jmp	ITloop;
+
+/*
+ * We have successfully selected out.
+ *
+ * Clear SELDO.
+ * Dequeue all SCBs sent from the waiting queue
+ * Requeue all SCBs *not* sent to the tail of the waiting queue
+ * Take Razor #494 into account for above.
+ *
+ * In Packetized Mode:
+ *	Return to the idle loop.  Our interrupt handler will take
+ *	care of any incoming L_Qs.
+ *
+ * In Non-Packetize Mode:
+ *	Continue to our normal state machine.
+ */
+SET_SRC_MODE	M_SCSI;
+SET_DST_MODE	M_SCSI;
+select_out:
+BEGIN_CRITICAL;
+	/* Clear out all SCBs that have been successfully sent. */
+	if ((ahd->bugs & AHD_SENT_SCB_UPDATE_BUG) != 0) {
+		/*
+		 * For packetized, the LQO manager clears ENSELO on
+		 * the assertion of SELDO.  If we are non-packetized,
+		 * LASTSCB and CURRSCB are acuate.
+		 */
+		test	SCSISEQ0, ENSELO jnz use_lastscb;
+
+		/*
+		 * The update is correct for LQOSTAT1 errors.  All
+		 * but LQOBUSFREE are handled by kernel interrupts.
+		 * If we see LQOBUSFREE, return to the idle loop.
+		 * Once we are out of the select_out critical section,
+		 * the kernel will cleanup the LQOBUSFREE and we will
+		 * eventually restart the selection if appropriate.
+		 */
+		test	LQOSTAT1, LQOBUSFREE jnz idle_loop;
+
+		/*
+		 * On a phase change oustside of packet boundaries,
+		 * LASTSCB points to the currently active SCB context
+		 * on the bus.
+		 */
+		test	LQOSTAT2, LQOPHACHGOUTPKT jnz use_lastscb;
+
+		/*
+		 * If the hardware has traversed the whole list, NEXTSCB
+		 * will be NULL, CURRSCB and LASTSCB cannot be trusted,
+		 * but MAXCMDCNT is accurate.  If we stop part way through
+		 * the list or only had one command to issue, NEXTSCB[1] is
+		 * not NULL and LASTSCB is the last command to go out.
+		 */
+		cmp	NEXTSCB[1], SCB_LIST_NULL jne use_lastscb;
+
+		/*
+		 * Brute force walk.
+		 */
+		bmov	SCBPTR, WAITING_TID_HEAD, 2;
+		mvi	SEQINTCTL, INTVEC1DSL;
+		mvi	MODE_PTR, MK_MODE(M_CFG, M_CFG);
+		mov	A, MAXCMDCNT;
+		mvi	MODE_PTR, MK_MODE(M_SCSI, M_SCSI);
+		clr	SEQINTCTL;
+find_lastscb_loop:
+		dec	A;
+		test	A, 0xFF jz found_last_sent_scb;
+		bmov	SCBPTR, SCB_NEXT, 2;
+		jmp	find_lastscb_loop;
+use_lastscb:
+		bmov	SCBPTR, LASTSCB, 2;
+found_last_sent_scb:
+		bmov	CURRSCB, SCBPTR, 2;
+curscb_ww_done:
+	} else {
+		/*
+		 * Untested - Verify with Rev B.
+		 */
+		bmov	SCBPTR, CURRSCB, 2;
+	}
+
+	/*
+	 * Requeue any SCBs not sent, to the tail of the waiting Q.
+	 */
+	cmp	SCB_NEXT[1], SCB_LIST_NULL je select_out_list_done;
+
+	/*
+	 * We know that neither the per-TID list nor the list of
+	 * TIDs is empty.  Use this knowledge to our advantage.
+	 */
+	bmov	REG0, SCB_NEXT, 2;
+	bmov	SCBPTR, WAITING_TID_TAIL, 2;
+	bmov	SCB_NEXT2, REG0, 2;
+	bmov	WAITING_TID_TAIL, REG0, 2;
+	jmp	select_out_inc_tid_q;
+
+select_out_list_done:
+	/*
+	 * The whole list made it.  Just clear our TID's tail pointer
+	 * unless we were queued independently due to our need to
+	 * send a message.
+	 */
+	test	SCB_CONTROL, MK_MESSAGE jnz select_out_inc_tid_q;
+	shr	DINDEX, 3, SCB_SCSIID;
+	or	DINDEX, 1;	/* Want only the second byte */
+	mvi	DINDEX[1], ((WAITING_SCB_TAILS) >> 8);
+	mvi	DINDIR, SCB_LIST_NULL;
+select_out_inc_tid_q:
+	bmov	SCBPTR, WAITING_TID_HEAD, 2;
+	bmov	WAITING_TID_HEAD, SCB_NEXT2, 2;
+	cmp	WAITING_TID_HEAD[1], SCB_LIST_NULL jne . + 2;
+	mvi	WAITING_TID_TAIL[1], SCB_LIST_NULL;
+	bmov	SCBPTR, CURRSCB, 2;
+END_CRITICAL;
+	mvi	CLRSINT0, CLRSELDO;
+	test	LQOSTAT2, LQOPHACHGOUTPKT jnz unexpected_nonpkt_phase;
+	test	LQOSTAT1, LQOPHACHGINPKT jnz unexpected_nonpkt_phase;
+
+	/*
+	 * If this is a packetized connection, return to our
+	 * idle_loop and let our interrupt handler deal with
+	 * any connection setup/teardown issues.  The only
+	 * exception is the case of MK_MESSAGE SCBs.  In the
+	 * A, the LQO manager transitions to LQOSTOP0 even if
+	 * we have selected out with ATN asserted and the target
+	 * REQs in a non-packet phase.
+	 */
+	if ((ahd->bugs & AHD_LQO_ATNO_BUG) != 0) {
+		test 	SCB_CONTROL, MK_MESSAGE jz select_out_no_message;
+		test	SCSISIGO, ATNO jnz select_out_non_packetized;
+select_out_no_message:
+	}
+	test	LQOSTAT2, LQOSTOP0 jnz idle_loop;
+
+select_out_non_packetized:
+	/* Non packetized request. */
+	and     SCSISEQ0, ~ENSELO;
+	if ((ahd->bugs & AHD_BUSFREEREV_BUG) != 0) {
+		/*
+		 * This exposes a window whereby a
+		 * busfree just after a selection will
+		 * be missed, but there is not other safe
+		 * way to enable busfree detection if
+		 * the busfreerev function is broken.
+		 */
+		mvi	CLRSINT1,CLRBUSFREE;
+		or	SIMODE1, ENBUSFREE;
+	}
+	mov	SAVED_SCSIID, SCB_SCSIID;
+	mov	SAVED_LUN, SCB_LUN;
+	or	SXFRCTL0, SPIOEN;
+
+	/*
+	 * As soon as we get a successful selection, the target
+	 * should go into the message out phase since we have ATN
+	 * asserted.
+	 */
+	mvi	MSG_OUT, MSG_IDENTIFYFLAG;
+	mvi	SEQ_FLAGS, NO_CDB_SENT;
+
+	/*
+	 * Main loop for information transfer phases.  Wait for the
+	 * target to assert REQ before checking MSG, C/D and I/O for
+	 * the bus phase.
+	 */
+mesgin_phasemis:
+ITloop:
+	call	phase_lock;
+
+	mov	A, LASTPHASE;
+
+	test	A, ~P_DATAIN_DT	jz p_data;
+	cmp	A,P_COMMAND	je p_command;
+	cmp	A,P_MESGOUT	je p_mesgout;
+	cmp	A,P_STATUS	je p_status;
+	cmp	A,P_MESGIN	je p_mesgin;
+
+	SET_SEQINTCODE(BAD_PHASE)
+	jmp	ITloop;			/* Try reading the bus again. */
+
+/*
+ * Command phase.  Set up the DMA registers and let 'er rip.
+ */
+p_command:
+	test	SEQ_FLAGS, NOT_IDENTIFIED jz p_command_okay;
+	SET_SEQINTCODE(PROTO_VIOLATION)
+p_command_okay:
+	test	MODE_PTR, ~(MK_MODE(M_DFF1, M_DFF1))
+		jnz p_command_allocate_fifo;
+	/*
+	 * Command retry.  Free our current FIFO and
+	 * re-allocate a FIFO so transfer state is
+	 * reset.
+	 */
+SET_SRC_MODE	M_DFF1;
+SET_DST_MODE	M_DFF1;
+	mvi	DFFSXFRCTL, RSTCHN|CLRSHCNT;
+	SET_MODE(M_SCSI, M_SCSI)
+p_command_allocate_fifo:
+	bmov	ALLOCFIFO_SCBPTR, SCBPTR, 2;
+	call	allocate_fifo;
+SET_SRC_MODE	M_DFF1;
+SET_DST_MODE	M_DFF1;
+	add	NONE, -17, SCB_CDB_LEN;
+	jnc	p_command_embedded;
+p_command_from_host:
+	bmov	HADDR[0], SCB_CDB_PTR, 11;
+	mvi	SG_CACHE_PRE, LAST_SEG;
+	mvi	DFCNTRL, (PRELOADEN|SCSIEN|HDMAEN);
+	jmp	p_command_xfer;
+p_command_embedded:
+	bmov	SHCNT[0], SCB_CDB_LEN,  1;
+	bmov	DFDAT, SCB_CDB_STORE, 16; 
+	mvi	DFCNTRL, SCSIEN;
+p_command_xfer:
+	and	SEQ_FLAGS, ~NO_CDB_SENT;
+	test	DFCNTRL, SCSIEN jnz .;
+	/*
+	 * DMA Channel automatically disabled.
+	 * Don't allow a data phase if the command
+	 * was not fully transferred.
+	 */
+	test	SSTAT2, SDONE jnz ITloop;
+	or	SEQ_FLAGS, NO_CDB_SENT;
+	jmp	ITloop;
+
+
+/*
+ * Status phase.  Wait for the data byte to appear, then read it
+ * and store it into the SCB.
+ */
+SET_SRC_MODE	M_SCSI;
+SET_DST_MODE	M_SCSI;
+p_status:
+	test	SEQ_FLAGS,NOT_IDENTIFIED jnz mesgin_proto_violation;
+p_status_okay:
+	mov	SCB_SCSI_STATUS, SCSIDAT;
+	or	SCB_CONTROL, STATUS_RCVD;
+	jmp	ITloop;
+
+/*
+ * Message out phase.  If MSG_OUT is MSG_IDENTIFYFLAG, build a full
+ * indentify message sequence and send it to the target.  The host may
+ * override this behavior by setting the MK_MESSAGE bit in the SCB
+ * control byte.  This will cause us to interrupt the host and allow
+ * it to handle the message phase completely on its own.  If the bit
+ * associated with this target is set, we will also interrupt the host,
+ * thereby allowing it to send a message on the next selection regardless
+ * of the transaction being sent.
+ * 
+ * If MSG_OUT is == HOST_MSG, also interrupt the host and take a message.
+ * This is done to allow the host to send messages outside of an identify
+ * sequence while protecting the seqencer from testing the MK_MESSAGE bit
+ * on an SCB that might not be for the current nexus. (For example, a
+ * BDR message in responce to a bad reselection would leave us pointed to
+ * an SCB that doesn't have anything to do with the current target).
+ *
+ * Otherwise, treat MSG_OUT as a 1 byte message to send (abort, abort tag,
+ * bus device reset).
+ *
+ * When there are no messages to send, MSG_OUT should be set to MSG_NOOP,
+ * in case the target decides to put us in this phase for some strange
+ * reason.
+ */
+p_mesgout_retry:
+	/* Turn on ATN for the retry */
+	mvi	SCSISIGO, ATNO;
+p_mesgout:
+	mov	SINDEX, MSG_OUT;
+	cmp	SINDEX, MSG_IDENTIFYFLAG jne p_mesgout_from_host;
+	test	SCB_CONTROL,MK_MESSAGE	jnz host_message_loop;
+p_mesgout_identify:
+	or	SINDEX, MSG_IDENTIFYFLAG|DISCENB, SCB_LUN;
+	test	SCB_CONTROL, DISCENB jnz . + 2;
+	and	SINDEX, ~DISCENB;
+/*
+ * Send a tag message if TAG_ENB is set in the SCB control block.
+ * Use SCB_NONPACKET_TAG as the tag value.
+ */
+p_mesgout_tag:
+	test	SCB_CONTROL,TAG_ENB jz  p_mesgout_onebyte;
+	mov	SCSIDAT, SINDEX;	/* Send the identify message */
+	call	phase_lock;
+	cmp	LASTPHASE, P_MESGOUT	jne p_mesgout_done;
+	and	SCSIDAT,TAG_ENB|SCB_TAG_TYPE,SCB_CONTROL;
+	call	phase_lock;
+	cmp	LASTPHASE, P_MESGOUT	jne p_mesgout_done;
+	mov	SCBPTR jmp p_mesgout_onebyte;
+/*
+ * Interrupt the driver, and allow it to handle this message
+ * phase and any required retries.
+ */
+p_mesgout_from_host:
+	cmp	SINDEX, HOST_MSG	jne p_mesgout_onebyte;
+	jmp	host_message_loop;
+
+p_mesgout_onebyte:
+	mvi	CLRSINT1, CLRATNO;
+	mov	SCSIDAT, SINDEX;
+
+/*
+ * If the next bus phase after ATN drops is message out, it means
+ * that the target is requesting that the last message(s) be resent.
+ */
+	call	phase_lock;
+	cmp	LASTPHASE, P_MESGOUT	je p_mesgout_retry;
+
+p_mesgout_done:
+	mvi	CLRSINT1,CLRATNO;	/* Be sure to turn ATNO off */
+	mov	LAST_MSG, MSG_OUT;
+	mvi	MSG_OUT, MSG_NOOP;	/* No message left */
+	jmp	ITloop;
+
+/*
+ * Message in phase.  Bytes are read using Automatic PIO mode.
+ */
+p_mesgin:
+	/* read the 1st message byte */
+	mvi	ACCUM		call inb_first;
+
+	test	A,MSG_IDENTIFYFLAG	jnz mesgin_identify;
+	cmp	A,MSG_DISCONNECT	je mesgin_disconnect;
+	cmp	A,MSG_SAVEDATAPOINTER	je mesgin_sdptrs;
+	cmp	ALLZEROS,A		je mesgin_complete;
+	cmp	A,MSG_RESTOREPOINTERS	je mesgin_rdptrs;
+	cmp	A,MSG_IGN_WIDE_RESIDUE	je mesgin_ign_wide_residue;
+	cmp	A,MSG_NOOP		je mesgin_done;
+
+/*
+ * Pushed message loop to allow the kernel to
+ * run it's own message state engine.  To avoid an
+ * extra nop instruction after signaling the kernel,
+ * we perform the phase_lock before checking to see
+ * if we should exit the loop and skip the phase_lock
+ * in the ITloop.  Performing back to back phase_locks
+ * shouldn't hurt, but why do it twice...
+ */
+host_message_loop:
+	call	phase_lock;	/* Benign the first time through. */
+	SET_SEQINTCODE(HOST_MSG_LOOP)
+	cmp	RETURN_1, EXIT_MSG_LOOP	je ITloop;
+	cmp	RETURN_1, CONT_MSG_LOOP_WRITE	jne . + 3;
+	mov	SCSIDAT, RETURN_2;
+	jmp	host_message_loop;
+	/* Must be CONT_MSG_LOOP_READ */
+	mov	NONE, SCSIDAT;	/* ACK Byte */
+	jmp	host_message_loop;
+
+mesgin_ign_wide_residue:
+	mov	SAVED_MODE, MODE_PTR;
+	SET_MODE(M_SCSI, M_SCSI)
+	shr	NEGOADDR, 4, SAVED_SCSIID;
+	mov	A, NEGCONOPTS;
+	RESTORE_MODE(SAVED_MODE)
+	test	A, WIDEXFER jz mesgin_reject;
+	/* Pull the residue byte */
+	mvi	REG0	call inb_next;
+	cmp	REG0, 0x01 jne mesgin_reject;
+	test	SCB_RESIDUAL_SGPTR[0], SG_LIST_NULL jz . + 2;
+	test	DATA_COUNT_ODD, 0x1	jz mesgin_done;
+	jmp	mesgin_done;
+
+mesgin_proto_violation:
+	SET_SEQINTCODE(PROTO_VIOLATION)
+	jmp	mesgin_done;
+mesgin_reject:
+	mvi	MSG_MESSAGE_REJECT	call mk_mesg;
+mesgin_done:
+	mov	NONE,SCSIDAT;		/*dummy read from latch to ACK*/
+	jmp	ITloop;
+
+#define INDEX_DISC_LIST(scsiid, lun)					\
+	and	A, 0xC0, scsiid;					\
+	or	SCBPTR, A, lun;						\
+	clr	SCBPTR[1];						\
+	and	SINDEX, 0x30, scsiid;					\
+	shr	SINDEX, 3;	/* Multiply by 2 */			\
+	add	SINDEX, (SCB_DISCONNECTED_LISTS & 0xFF);		\
+	mvi	SINDEX[1], ((SCB_DISCONNECTED_LISTS >> 8) & 0xFF)
+
+mesgin_identify:
+	/*
+	 * Determine whether a target is using tagged or non-tagged
+	 * transactions by first looking at the transaction stored in
+	 * the per-device, disconnected array.  If there is no untagged
+	 * transaction for this target, this must be a tagged transaction.
+	 */
+	and	SAVED_LUN, MSG_IDENTIFY_LUNMASK, A;
+	INDEX_DISC_LIST(SAVED_SCSIID, SAVED_LUN);
+	bmov	DINDEX, SINDEX, 2;
+	bmov	REG0, SINDIR, 2;
+	cmp	REG0[1], SCB_LIST_NULL je snoop_tag;
+	/* Untagged.  Clear the busy table entry and setup the SCB. */
+	bmov	DINDIR, ALLONES, 2;
+	bmov	SCBPTR, REG0, 2;
+	jmp	setup_SCB;
+
+/*
+ * Here we "snoop" the bus looking for a SIMPLE QUEUE TAG message.
+ * If we get one, we use the tag returned to find the proper
+ * SCB.  After receiving the tag, look for the SCB at SCB locations tag and
+ * tag + 256.
+ */
+snoop_tag:
+	if ((ahd->flags & AHD_SEQUENCER_DEBUG) != 0) {
+		or	SEQ_FLAGS, 0x80;
+	}
+	mov	NONE, SCSIDAT;		/* ACK Identify MSG */
+	call	phase_lock;
+	if ((ahd->flags & AHD_SEQUENCER_DEBUG) != 0) {
+		or	SEQ_FLAGS, 0x1;
+	}
+	cmp	LASTPHASE, P_MESGIN	jne not_found_ITloop;
+	if ((ahd->flags & AHD_SEQUENCER_DEBUG) != 0) {
+		or	SEQ_FLAGS, 0x2;
+	}
+	cmp	SCSIBUS, MSG_SIMPLE_Q_TAG jne not_found;
+get_tag:
+	clr	SCBPTR[1];
+	mvi	SCBPTR	call inb_next;	/* tag value */
+verify_scb:
+	test	SCB_CONTROL,DISCONNECTED jz verify_other_scb;
+	mov	A, SAVED_SCSIID;
+	cmp	SCB_SCSIID, A jne verify_other_scb;
+	mov	A, SAVED_LUN;
+	cmp	SCB_LUN, A je setup_SCB_disconnected;
+verify_other_scb:
+	xor	SCBPTR[1], 1;
+	test	SCBPTR[1], 0xFF jnz verify_scb;
+	jmp	not_found;
+
+/*
+ * Ensure that the SCB the tag points to is for
+ * an SCB transaction to the reconnecting target.
+ */
+setup_SCB:
+	if ((ahd->flags & AHD_SEQUENCER_DEBUG) != 0) {
+		or	SEQ_FLAGS, 0x10;
+	}
+	test	SCB_CONTROL,DISCONNECTED jz not_found;
+setup_SCB_disconnected:
+	and	SCB_CONTROL,~DISCONNECTED;
+	clr	SEQ_FLAGS;	/* make note of IDENTIFY */
+	test	SCB_SGPTR, SG_LIST_NULL jnz . + 3;
+	bmov	ALLOCFIFO_SCBPTR, SCBPTR, 2;
+	call	allocate_fifo;
+	/* See if the host wants to send a message upon reconnection */
+	test	SCB_CONTROL, MK_MESSAGE jz mesgin_done;
+	mvi	HOST_MSG	call mk_mesg;
+	jmp	mesgin_done;
+
+not_found:
+	SET_SEQINTCODE(NO_MATCH)
+	jmp	mesgin_done;
+
+not_found_ITloop:
+	SET_SEQINTCODE(NO_MATCH)
+	jmp	ITloop;
+
+/*
+ * We received a "command complete" message.  Put the SCB on the complete
+ * queue and trigger a completion interrupt via the idle loop.  Before doing
+ * so, check to see if there
+ * is a residual or the status byte is something other than STATUS_GOOD (0).
+ * In either of these conditions, we upload the SCB back to the host so it can
+ * process this information.  In the case of a non zero status byte, we 
+ * additionally interrupt the kernel driver synchronously, allowing it to
+ * decide if sense should be retrieved.  If the kernel driver wishes to request
+ * sense, it will fill the kernel SCB with a request sense command, requeue
+ * it to the QINFIFO and tell us not to post to the QOUTFIFO by setting 
+ * RETURN_1 to SEND_SENSE.
+ */
+mesgin_complete:
+
+	/*
+	 * If ATN is raised, we still want to give the target a message.
+	 * Perhaps there was a parity error on this last message byte.
+	 * Either way, the target should take us to message out phase
+	 * and then attempt to complete the command again.  We should use a
+	 * critical section here to guard against a timeout triggering
+	 * for this command and setting ATN while we are still processing
+	 * the completion.
+	test	SCSISIGI, ATNI jnz mesgin_done;
+	 */
+
+	/*
+	 * If we are identified and have successfully sent the CDB,
+	 * any status will do.  Optimize this fast path.
+	 */
+	test	SCB_CONTROL, STATUS_RCVD jz mesgin_proto_violation;
+	test	SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT jz complete_accepted;
+
+	/*
+	 * If the target never sent an identify message but instead went
+	 * to mesgin to give an invalid message, let the host abort us.
+	 */
+	test	SEQ_FLAGS, NOT_IDENTIFIED jnz mesgin_proto_violation;
+
+	/*
+	 * If we recevied good status but never successfully sent the
+	 * cdb, abort the command.
+	 */
+	test	SCB_SCSI_STATUS,0xff	jnz complete_accepted;
+	test	SEQ_FLAGS, NO_CDB_SENT jnz mesgin_proto_violation;
+complete_accepted:
+
+	/*
+	 * See if we attempted to deliver a message but the target ingnored us.
+	 */
+	test	SCB_CONTROL, MK_MESSAGE jz complete_nomsg;
+	SET_SEQINTCODE(MKMSG_FAILED)
+complete_nomsg:
+	call	queue_scb_completion;
+	jmp	await_busfree;
+
+freeze_queue:
+	/* Cancel any pending select-out. */
+	test	SSTAT0, SELDO|SELINGO jnz . + 2;
+	and	SCSISEQ0, ~ENSELO;
+	mov	ACCUM_SAVE, A;
+	clr	A;
+	add	QFREEZE_COUNT, 1;
+	adc	QFREEZE_COUNT[1], A;
+	or	SEQ_FLAGS2, SELECTOUT_QFROZEN;
+	mov	A, ACCUM_SAVE ret;
+
+queue_arg1_scb_completion:
+	SET_MODE(M_SCSI, M_SCSI)
+	bmov	SCBPTR, ARG_1, 2;
+queue_scb_completion:
+	if ((ahd->bugs & AHD_ABORT_LQI_BUG) == 0) {
+		/*
+		 * Set MK_MESSAGE to trigger an abort should this SCB
+		 * be referenced by a target even though it is not currently
+		 * active.
+		 */
+		or	SCB_CONTROL, MK_MESSAGE;
+	}
+	test	SCB_SCSI_STATUS,0xff	jnz bad_status;
+	/*
+	 * Check for residuals
+	 */
+	test	SCB_SGPTR, SG_LIST_NULL jnz complete;	/* No xfer */
+	test	SCB_SGPTR, SG_FULL_RESID jnz upload_scb;/* Never xfered */
+	test	SCB_RESIDUAL_SGPTR, SG_LIST_NULL jz upload_scb;
+complete:
+	bmov	SCB_NEXT_COMPLETE, COMPLETE_SCB_HEAD, 2;
+	bmov	COMPLETE_SCB_HEAD, SCBPTR, 2 ret;
+bad_status:
+	cmp	SCB_SCSI_STATUS, STATUS_PKT_SENSE je upload_scb;
+	call	freeze_queue;
+upload_scb:
+	bmov	SCB_NEXT_COMPLETE, COMPLETE_DMA_SCB_HEAD, 2;
+	bmov	COMPLETE_DMA_SCB_HEAD, SCBPTR, 2;
+	or	SCB_SGPTR, SG_STATUS_VALID ret;
+
+/*
+ * Is it a disconnect message?  Set a flag in the SCB to remind us
+ * and await the bus going free.  If this is an untagged transaction
+ * store the SCB id for it in our untagged target table for lookup on
+ * a reselction.
+ */
+mesgin_disconnect:
+	/*
+	 * If ATN is raised, we still want to give the target a message.
+	 * Perhaps there was a parity error on this last message byte
+	 * or we want to abort this command.  Either way, the target
+	 * should take us to message out phase and then attempt to
+	 * disconnect again.
+	 * XXX - Wait for more testing.
+	test	SCSISIGI, ATNI jnz mesgin_done;
+	 */
+	test	SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT
+		jnz mesgin_proto_violation;
+	or	SCB_CONTROL,DISCONNECTED;
+	test	SCB_CONTROL, TAG_ENB jnz await_busfree;
+queue_disc_scb:
+	bmov	REG0, SCBPTR, 2;
+	INDEX_DISC_LIST(SAVED_SCSIID, SAVED_LUN);
+	bmov	DINDEX, SINDEX, 2;
+	bmov	DINDIR, REG0, 2;
+	bmov	SCBPTR, REG0, 2;
+	/* FALLTHROUGH */
+await_busfree:
+	and	SIMODE1, ~ENBUSFREE;
+	if ((ahd->bugs & AHD_BUSFREEREV_BUG) == 0) {
+		/*
+		 * In the BUSFREEREV_BUG case, the
+		 * busfree status was cleared at the
+		 * beginning of the connection.
+		 */
+		mvi	CLRSINT1,CLRBUSFREE;
+	}
+	mov	NONE, SCSIDAT;		/* Ack the last byte */
+	test	MODE_PTR, ~(MK_MODE(M_DFF1, M_DFF1))
+		jnz await_busfree_not_m_dff;
+SET_SRC_MODE	M_DFF1;
+SET_DST_MODE	M_DFF1;
+await_busfree_clrchn:
+	mvi	DFFSXFRCTL, CLRCHN;
+await_busfree_not_m_dff:
+	call	clear_target_state;
+	test	SSTAT1,REQINIT|BUSFREE	jz .;
+	test	SSTAT1, BUSFREE jnz idle_loop;
+	SET_SEQINTCODE(MISSED_BUSFREE)
+
+
+/*
+ * Save data pointers message:
+ * Copying RAM values back to SCB, for Save Data Pointers message, but
+ * only if we've actually been into a data phase to change them.  This
+ * protects against bogus data in scratch ram and the residual counts
+ * since they are only initialized when we go into data_in or data_out.
+ * Ack the message as soon as possible.
+ */
+SET_SRC_MODE	M_DFF1;
+SET_DST_MODE	M_DFF1;
+mesgin_sdptrs:
+	mov	NONE,SCSIDAT;		/*dummy read from latch to ACK*/
+	test	SEQ_FLAGS, DPHASE	jz ITloop;
+	call	save_pointers;
+	jmp	ITloop;
+
+save_pointers:
+	/*
+	 * If we are asked to save our position at the end of the
+	 * transfer, just mark us at the end rather than perform a
+	 * full save.
+	 */
+	test	SCB_RESIDUAL_SGPTR[0], SG_LIST_NULL jz save_pointers_full;
+	or	SCB_SGPTR, SG_LIST_NULL ret;
+
+save_pointers_full:
+	/*
+	 * The SCB_DATAPTR becomes the current SHADDR.
+	 * All other information comes directly from our residual
+	 * state.
+	 */
+	bmov	SCB_DATAPTR, SHADDR, 8;
+	bmov	SCB_DATACNT, SCB_RESIDUAL_DATACNT, 8 ret;
+
+/*
+ * Restore pointers message?  Data pointers are recopied from the
+ * SCB anytime we enter a data phase for the first time, so all
+ * we need to do is clear the DPHASE flag and let the data phase
+ * code do the rest.  We also reset/reallocate the FIFO to make
+ * sure we have a clean start for the next data or command phase.
+ */
+mesgin_rdptrs:
+	and	SEQ_FLAGS, ~DPHASE;
+	test	MODE_PTR, ~(MK_MODE(M_DFF1, M_DFF1)) jnz msgin_rdptrs_get_fifo;
+	mvi	DFFSXFRCTL, RSTCHN|CLRSHCNT;
+	SET_MODE(M_SCSI, M_SCSI)
+msgin_rdptrs_get_fifo:
+	call	allocate_fifo;
+	jmp	mesgin_done;
+
+clear_target_state:
+	mvi	LASTPHASE, P_BUSFREE;
+	/* clear target specific flags */
+	mvi	SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT ret;
+
+phase_lock:     
+	test	SCSIPHASE, 0xFF jz .;
+	test	SSTAT1, SCSIPERR jnz phase_lock;
+phase_lock_latch_phase:
+	and	LASTPHASE, PHASE_MASK, SCSISIGI ret;
+
+/*
+ * Functions to read data in Automatic PIO mode.
+ *
+ * An ACK is not sent on input from the target until SCSIDATL is read from.
+ * So we wait until SCSIDATL is latched (the usual way), then read the data
+ * byte directly off the bus using SCSIBUSL.  When we have pulled the ATN
+ * line, or we just want to acknowledge the byte, then we do a dummy read
+ * from SCISDATL.  The SCSI spec guarantees that the target will hold the
+ * data byte on the bus until we send our ACK.
+ *
+ * The assumption here is that these are called in a particular sequence,
+ * and that REQ is already set when inb_first is called.  inb_{first,next}
+ * use the same calling convention as inb.
+ */
+inb_next:
+	mov	NONE,SCSIDAT;		/*dummy read from latch to ACK*/
+inb_next_wait:
+	/*
+	 * If there is a parity error, wait for the kernel to
+	 * see the interrupt and prepare our message response
+	 * before continuing.
+	 */
+	test	SCSIPHASE, 0xFF jz .;
+	test	SSTAT1, SCSIPERR jnz inb_next_wait;
+inb_next_check_phase:
+	and	LASTPHASE, PHASE_MASK, SCSISIGI;
+	cmp	LASTPHASE, P_MESGIN jne mesgin_phasemis;
+inb_first:
+	clr	DINDEX[1];
+	mov	DINDEX,SINDEX;
+	mov	DINDIR,SCSIBUS	ret;		/*read byte directly from bus*/
+inb_last:
+	mov	NONE,SCSIDAT ret;		/*dummy read from latch to ACK*/
+
+mk_mesg:
+	mvi	SCSISIGO, ATNO;
+	mov	MSG_OUT,SINDEX ret;
+
+SET_SRC_MODE	M_DFF1;
+SET_DST_MODE	M_DFF1;
+disable_ccsgen:
+	test	SG_STATE, FETCH_INPROG jz disable_ccsgen_fetch_done;
+	clr	CCSGCTL;
+disable_ccsgen_fetch_done:
+	clr	SG_STATE ret;
+
+service_fifo:
+	/*
+	 * Do we have any prefetch left???
+	 */
+	test	SG_STATE, SEGS_AVAIL jnz idle_sg_avail;
+
+	/*
+	 * Can this FIFO have access to the S/G cache yet?
+	 */
+	test	CCSGCTL, SG_CACHE_AVAIL jz return;
+
+	/* Did we just finish fetching segs? */
+	test	CCSGCTL, CCSGDONE jnz idle_sgfetch_complete;
+
+	/* Are we actively fetching segments? */
+	test	CCSGCTL, CCSGENACK jnz return;
+
+	/*
+	 * We fetch a "cacheline aligned" and sized amount of data
+	 * so we don't end up referencing a non-existant page.
+	 * Cacheline aligned is in quotes because the kernel will
+	 * set the prefetch amount to a reasonable level if the
+	 * cacheline size is unknown.
+	 */
+	bmov	SGHADDR, SCB_RESIDUAL_SGPTR, 4;
+	mvi	SGHCNT, SG_PREFETCH_CNT;
+	if ((ahd->bugs & AHD_REG_SLOW_SETTLE_BUG) != 0) {
+		/*
+		 * Need two instruction between "touches" of SGHADDR.
+		 */
+		nop;
+	}
+	and	SGHADDR[0], SG_PREFETCH_ALIGN_MASK, SCB_RESIDUAL_SGPTR;
+	mvi	CCSGCTL, CCSGEN|SG_CACHE_AVAIL|CCSGRESET;
+	or	SG_STATE, FETCH_INPROG ret;
+idle_sgfetch_complete:
+	/*
+	 * Guard against SG_CACHE_AVAIL activating during sg fetch
+	 * request in the other FIFO.
+	 */
+	test	SG_STATE, FETCH_INPROG jz return;
+	clr	CCSGCTL;
+	and	CCSGADDR, SG_PREFETCH_ADDR_MASK, SCB_RESIDUAL_SGPTR;
+	mvi	SG_STATE, SEGS_AVAIL|LOADING_NEEDED;
+idle_sg_avail:
+	/* Does the hardware have space for another SG entry? */
+	test	DFSTATUS, PRELOAD_AVAIL jz return;
+	if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
+		bmov	HADDR, CCSGRAM, 8;
+	} else {
+		bmov 	HADDR, CCSGRAM, 4;
+	}
+	bmov	HCNT, CCSGRAM, 3;
+	test	HCNT[0], 0x1 jz . + 2;
+	xor	DATA_COUNT_ODD, 0x1;
+	bmov	SCB_RESIDUAL_DATACNT[3], CCSGRAM, 1;
+	if ((ahd->flags & AHD_39BIT_ADDRESSING) != 0) {
+		and	HADDR[4], SG_HIGH_ADDR_BITS, SCB_RESIDUAL_DATACNT[3];
+	}
+	if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
+		/* Skip 4 bytes of pad. */
+		add	CCSGADDR, 4;
+	}
+sg_advance:
+	clr	A;			/* add sizeof(struct scatter) */
+	add	SCB_RESIDUAL_SGPTR[0],SG_SIZEOF;
+	adc	SCB_RESIDUAL_SGPTR[1],A;
+	adc	SCB_RESIDUAL_SGPTR[2],A;
+	adc	SCB_RESIDUAL_SGPTR[3],A;
+	mov	SINDEX, SCB_RESIDUAL_SGPTR[0];
+	test	DATA_COUNT_ODD, 0x1 jz . + 2;
+	or	SINDEX, ODD_SEG;
+	test	SCB_RESIDUAL_DATACNT[3], SG_LAST_SEG jz . + 3;
+	or	SINDEX, LAST_SEG;
+	clr	SG_STATE;
+	mov	SG_CACHE_PRE, SINDEX;
+	/*
+	 * Load the segment.  Or in HDMAEN here too
+	 * just in case HDMAENACK has not come true
+	 * by the time this segment is loaded.  If
+	 * HDMAENACK is not true, this or will disable
+	 * HDMAEN mid-transfer.  We do not want to simply
+	 * mvi our original settings as SCSIEN automatically
+	 * de-asserts and we don't want to accidentally
+	 * re-enable it.
+	 */
+	if ((ahd->features & AHD_NEW_DFCNTRL_OPTS) != 0) {
+		/*
+		 * Use SCSIENWRDIS so that SCSIEN is never
+		 * modified by this operation.
+		 */
+		or	DFCNTRL, PRELOADEN|SCSIENWRDIS|HDMAEN;
+	} else {
+		or	DFCNTRL, PRELOADEN|HDMAEN;
+	}
+	/*
+	 * Do we have another segment in the cache?
+	 */
+	add	NONE, SG_PREFETCH_CNT_LIMIT, CCSGADDR;
+	jnc	return;
+	and	SG_STATE, ~SEGS_AVAIL ret;
+
+/*
+ * Initialize the DMA address and counter from the SCB.
+ */
+load_first_seg:
+	bmov	HADDR, SCB_DATAPTR, 11;
+	and	DATA_COUNT_ODD, 0x1, SCB_DATACNT[0];
+	and	REG_ISR, ~SG_FULL_RESID, SCB_SGPTR[0];
+	test	SCB_DATACNT[3], SG_LAST_SEG jz . + 2;
+	or	REG_ISR, LAST_SEG;
+	test	DATA_COUNT_ODD, 0x1 jz . + 2;
+	or	REG_ISR, ODD_SEG;
+	mov	SG_CACHE_PRE, REG_ISR;
+	mvi	DFCNTRL, (PRELOADEN|SCSIEN|HDMAEN);
+	/*
+	 * Since we've are entering a data phase, we will
+	 * rely on the SCB_RESID* fields.  Initialize the
+	 * residual and clear the full residual flag.
+	 */
+	and	SCB_SGPTR[0], ~SG_FULL_RESID;
+	bmov	SCB_RESIDUAL_DATACNT[3], SCB_DATACNT[3], 5;
+	/* If we need more S/G elements, tell the idle loop */
+	test	SCB_RESIDUAL_DATACNT[3], SG_LAST_SEG jnz . + 2;
+	mvi	SG_STATE, LOADING_NEEDED ret;
+	clr	SG_STATE ret;
+
+p_data_handle_xfer:
+	call	setjmp_setscb;
+	test	SG_STATE, LOADING_NEEDED jnz service_fifo;
+p_data_clear_handler:
+	or	LONGJMP_ADDR[1], INVALID_ADDR ret;
+
+p_data:
+	test	SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT	jz p_data_allowed;
+	SET_SEQINTCODE(PROTO_VIOLATION)
+p_data_allowed:
+ 
+	test	SEQ_FLAGS, DPHASE	jz data_phase_initialize;
+
+	/*
+	 * If we re-enter the data phase after going through another
+	 * phase, our transfer location has almost certainly been
+	 * corrupted by the interveining, non-data, transfers.  Ask
+	 * the host driver to fix us up based on the transfer residual
+	 * unless we already know that we should be bitbucketing.
+	 */
+	test	SCB_RESIDUAL_SGPTR[0], SG_LIST_NULL jnz p_data_bitbucket;
+	SET_SEQINTCODE(PDATA_REINIT)
+	jmp	data_phase_inbounds;
+
+p_data_bitbucket:
+	/*
+	 * Turn on `Bit Bucket' mode, wait until the target takes
+	 * us to another phase, and then notify the host.
+	 */
+	mov	SAVED_MODE, MODE_PTR;
+	test	MODE_PTR, ~(MK_MODE(M_DFF1, M_DFF1))
+		jnz bitbucket_not_m_dff;
+	/*
+	 * Ensure that any FIFO contents are cleared out and the
+	 * FIFO free'd prior to starting the BITBUCKET.  BITBUCKET
+	 * doesn't discard data already in the FIFO.
+	 */
+	mvi	DFFSXFRCTL, RSTCHN|CLRSHCNT;
+	SET_MODE(M_SCSI, M_SCSI)
+bitbucket_not_m_dff:
+	or	SXFRCTL1,BITBUCKET;
+	/* Wait for non-data phase. */
+	test	SCSIPHASE, ~DATA_PHASE_MASK jz .;
+	and	SXFRCTL1, ~BITBUCKET;
+	RESTORE_MODE(SAVED_MODE)
+SET_SRC_MODE	M_DFF1;
+SET_DST_MODE	M_DFF1;
+	SET_SEQINTCODE(DATA_OVERRUN)
+	jmp	ITloop;
+
+data_phase_initialize:
+	test	SCB_SGPTR[0], SG_LIST_NULL jnz p_data_bitbucket;
+	call	load_first_seg;
+data_phase_inbounds:
+	/* We have seen a data phase at least once. */
+	or	SEQ_FLAGS, DPHASE;
+	mov	SAVED_MODE, MODE_PTR;
+	test	SG_STATE, LOADING_NEEDED jz data_group_dma_loop;
+	call	p_data_handle_xfer;
+data_group_dma_loop:
+	/*
+	 * The transfer is complete if either the last segment
+	 * completes or the target changes phase.  Both conditions
+	 * will clear SCSIEN.
+	 */
+	call	idle_loop_service_fifos;
+	call	idle_loop_cchan;
+	call	idle_loop_gsfifo;
+	RESTORE_MODE(SAVED_MODE)
+	test	DFCNTRL, SCSIEN jnz data_group_dma_loop;
+
+data_group_dmafinish:
+	/*
+	 * The transfer has terminated either due to a phase
+	 * change, and/or the completion of the last segment.
+	 * We have two goals here.  Do as much other work
+	 * as possible while the data fifo drains on a read
+	 * and respond as quickly as possible to the standard
+	 * messages (save data pointers/disconnect and command
+	 * complete) that usually follow a data phase.
+	 */
+	call	calc_residual;
+
+	/*
+	 * Go ahead and shut down the DMA engine now.
+	 */
+	test	DFCNTRL, DIRECTION jnz data_phase_finish;
+data_group_fifoflush:
+	if ((ahd->bugs & AHD_AUTOFLUSH_BUG) != 0) {
+		or	DFCNTRL, FIFOFLUSH;
+	}
+	/*
+	 * We have enabled the auto-ack feature.  This means
+	 * that the controller may have already transferred
+	 * some overrun bytes into the data FIFO and acked them
+	 * on the bus.  The only way to detect this situation is
+	 * to wait for LAST_SEG_DONE to come true on a completed
+	 * transfer and then test to see if the data FIFO is
+	 * non-empty.  We know there is more data yet to transfer
+	 * if SG_LIST_NULL is not yet set, thus there cannot be
+	 * an overrun.
+	 */
+	test	SCB_RESIDUAL_SGPTR[0], SG_LIST_NULL jz data_phase_finish;
+	test	SG_CACHE_SHADOW, LAST_SEG_DONE jz .;
+	test	DFSTATUS, FIFOEMP jnz data_phase_finish;
+	/* Overrun */
+	jmp	p_data;
+data_phase_finish:
+	/*
+	 * If the target has left us in data phase, loop through
+	 * the dma code again.  We will only loop if there is a
+	 * data overrun.  
+	 */
+	if ((ahd->flags & AHD_TARGETROLE) != 0) {
+		test	SSTAT0, TARGET jnz data_phase_done;
+	}
+	if ((ahd->flags & AHD_INITIATORROLE) != 0) {
+		test	SSTAT1, REQINIT jz .;
+		test	SCSIPHASE, DATA_PHASE_MASK jnz p_data;
+	}
+
+data_phase_done:
+	/* Kill off any pending prefetch */
+	call	disable_ccsgen;
+	or 	LONGJMP_ADDR[1], INVALID_ADDR;
+
+	if ((ahd->flags & AHD_TARGETROLE) != 0) {
+		test	SEQ_FLAGS, DPHASE_PENDING jz ITloop;
+		/*
+		and	SEQ_FLAGS, ~DPHASE_PENDING;
+		 * For data-in phases, wait for any pending acks from the
+		 * initiator before changing phase.  We only need to
+		 * send Ignore Wide Residue messages for data-in phases.
+		test	DFCNTRL, DIRECTION jz target_ITloop;
+		test	SSTAT1, REQINIT	jnz .;
+		test	DATA_COUNT_ODD, 0x1 jz target_ITloop;
+		SET_MODE(M_SCSI, M_SCSI)
+		test	NEGCONOPTS, WIDEXFER jz target_ITloop;
+		 */
+		/*
+		 * Issue an Ignore Wide Residue Message.
+		mvi	P_MESGIN|BSYO call change_phase;
+		mvi	MSG_IGN_WIDE_RESIDUE call target_outb;
+		mvi	1 call target_outb;
+		jmp	target_ITloop;
+		 */
+	} else {
+		jmp	ITloop;
+	}
+
+/*
+ * We assume that, even though data may still be
+ * transferring to the host, that the SCSI side of
+ * the DMA engine is now in a static state.  This
+ * allows us to update our notion of where we are
+ * in this transfer.
+ *
+ * If, by chance, we stopped before being able
+ * to fetch additional segments for this transfer,
+ * yet the last S/G was completely exhausted,
+ * call our idle loop until it is able to load
+ * another segment.  This will allow us to immediately
+ * pickup on the next segment on the next data phase.
+ *
+ * If we happened to stop on the last segment, then
+ * our residual information is still correct from
+ * the idle loop and there is no need to perform
+ * any fixups.
+ */
+calc_residual:
+	test	SG_CACHE_SHADOW, LAST_SEG jz residual_before_last_seg;
+	/* Record if we've consumed all S/G entries */
+	test	MDFFSTAT, SHVALID	jz . + 2;
+	bmov	SCB_RESIDUAL_DATACNT, SHCNT, 3 ret;
+	or	SCB_RESIDUAL_SGPTR[0], SG_LIST_NULL ret;
+residual_before_last_seg:
+	test    MDFFSTAT, SHVALID	jnz sgptr_fixup;
+	/*
+	 * Can never happen from an interrupt as the packetized
+	 * hardware will only interrupt us once SHVALID or
+	 * LAST_SEG_DONE.
+	 */
+	call	idle_loop_service_fifos;
+	RESTORE_MODE(SAVED_MODE)
+	jmp	calc_residual;
+
+sgptr_fixup:
+	/*
+	 * Fixup the residual next S/G pointer.  The S/G preload
+	 * feature of the chip allows us to load two elements
+	 * in addition to the currently active element.  We
+	 * store the bottom byte of the next S/G pointer in
+	 * the SG_CACHE_PTR register so we can restore the
+	 * correct value when the DMA completes.  If the next
+	 * sg ptr value has advanced to the point where higher
+	 * bytes in the address have been affected, fix them
+	 * too.
+	 */
+	test	SG_CACHE_SHADOW, 0x80 jz sgptr_fixup_done;
+	test	SCB_RESIDUAL_SGPTR[0], 0x80 jnz sgptr_fixup_done;
+	add	SCB_RESIDUAL_SGPTR[1], -1;
+	adc	SCB_RESIDUAL_SGPTR[2], -1; 
+	adc	SCB_RESIDUAL_SGPTR[3], -1;
+sgptr_fixup_done:
+	and	SCB_RESIDUAL_SGPTR[0], SG_ADDR_MASK, SG_CACHE_SHADOW;
+	clr	DATA_COUNT_ODD;
+	test	SG_CACHE_SHADOW, ODD_SEG jz . + 2;
+	or	DATA_COUNT_ODD, 0x1;
+	clr	SCB_RESIDUAL_DATACNT[3]; /* We are not the last seg */
+	bmov	SCB_RESIDUAL_DATACNT, SHCNT, 3 ret;
+
+export timer_isr:
+	call	issue_cmdcmplt;
+	mvi	CLRSEQINTSTAT, CLRSEQ_SWTMRTO;
+	if ((ahd->bugs & AHD_SET_MODE_BUG) != 0) {
+		/*
+		 * In H2A4, the mode pointer is not saved
+		 * for intvec2, but is restored on iret.
+		 * This can lead to the restoration of a
+		 * bogus mode ptr.  Manually clear the
+		 * intmask bits and do a normal return
+		 * to compensate.
+		 */
+		and	SEQINTCTL, ~(INTMASK2|INTMASK1) ret;
+	} else {
+		or	SEQINTCTL, IRET ret;
+	}
+
+export seq_isr:
+	nop;	/* Jumps in the first ISR instruction fail on Rev A. */
+	test	SEQINTSRC, CFG4DATA	jnz cfg4data_intr;
+	test	SEQINTSRC, CFG4ISTAT	jnz cfg4istat_intr;
+	test	SEQINTSRC, SAVEPTRS	jnz saveptr_intr;
+	test	SEQINTSRC, CFG4ICMD	jnz cfg4icmd_intr;
+	SET_SEQINTCODE(INVALID_SEQINT)
+
+/*
+ * There are two types of save pointers interrupts:
+ * The first is a snapshot save pointers where the current FIFO is not
+ * active and contains a snapshot of the current poniter information.
+ * This happens between packets in a stream for a single L_Q.  Since we
+ * are not performing a pointer save, we can safely clear the channel
+ * so it can be used for other transactions.
+ *
+ * The second case is a save pointers on an active FIFO which occurs
+ * if the target changes to a new L_Q or busfrees/QAS' and the transfer
+ * has a residual.  This should occur coincident with a ctxtdone.  We
+ * disable the interrupt and allow our active routine to handle the
+ * save.
+ */
+saveptr_intr:
+	test	DFCNTRL, HDMAENACK jz snapshot_saveptr;
+	and	SEQIMODE, ~ENSAVEPTRS;
+	or	SEQINTCTL, IRET ret;
+snapshot_saveptr:
+	mvi	DFFSXFRCTL, CLRCHN;
+	or	SEQINTCTL, IRET ret;
+
+cfg4data_intr:
+	test	SCB_SGPTR[0], SG_LIST_NULL jnz pkt_handle_overrun;
+	call	load_first_seg;
+	call	pkt_handle_xfer;
+	or	SEQINTCTL, IRET ret;
+
+cfg4istat_intr:
+	call	freeze_queue;
+	add	NONE, -13, SCB_CDB_LEN;
+	jnc	cfg4istat_have_sense_addr;
+	test	SCB_CDB_LEN, SCB_CDB_LEN_PTR jnz cfg4istat_have_sense_addr;
+	/*
+	 * Host sets up address/count and enables transfer.
+	 */
+	SET_SEQINTCODE(CFG4ISTAT_INTR)
+	jmp	cfg4istat_setup_handler;
+cfg4istat_have_sense_addr:
+	bmov	HADDR, SCB_SENSE_BUSADDR, 4;
+	mvi	HCNT[1], (AHD_SENSE_BUFSIZE >> 8);
+	mvi	SG_CACHE_PRE, LAST_SEG;
+	mvi	DFCNTRL, PRELOADEN|SCSIEN|HDMAEN;
+cfg4istat_setup_handler:
+	/*
+	 * Status pkt is transferring to host.
+	 * Wait in idle loop for transfer to complete.
+	 */
+	call	pkt_handle_status;
+	or	SEQINTCTL, IRET ret;
+
+/*
+ * See if the target has gone on in this context creating an
+ * overrun condition.  For the write case, the hardware cannot
+ * ack bytes until data are provided.  So, if the target begins
+ * another  packet without changing contexts, implying we are
+ * not sitting on a packet boundary, we are in an overrun
+ * situation.  For the read case, the hardware will continue to
+ * ack bytes into the FIFO, and may even ack the last overrun packet
+ * into the FIFO.   If the FIFO should become non-empty, we are in
+ * a read overrun case.
+ */
+#define check_overrun							\
+	/* Not on a packet boundary. */					\
+	test 	MDFFSTAT, DLZERO jz pkt_handle_overrun;			\
+	test	DFSTATUS, FIFOEMP jz pkt_handle_overrun
+
+pkt_handle_xfer:
+	bmov	LONGJMP_SCB, SCBPTR, 2;
+	test	SG_STATE, LOADING_NEEDED jz pkt_last_seg;
+	call	setjmp;
+	test	SEQINTSRC, SAVEPTRS jnz pkt_saveptrs;
+	test	SCSIPHASE, ~DATA_PHASE_MASK jz . + 2;
+	test	SCSISIGO, ATNO jnz . + 2;
+	test	SSTAT2, NONPACKREQ jz pkt_service_fifo;
+	/*
+	 * Defer handling of this NONPACKREQ until we
+	 * can be sure it pertains to this FIFO.  SAVEPTRS
+	 * will not be asserted if the NONPACKREQ is for us,
+	 * so we must simulate it if shaddow is valid.  If
+	 * shaddow is not valid, keep running this FIFO until we
+	 * have satisfied the transfer by loading segments and
+	 * waiting for either shaddow valid or last_seg_done.
+	 */
+	test	MDFFSTAT, SHVALID jnz pkt_saveptrs;
+pkt_service_fifo:
+	test	SG_STATE, LOADING_NEEDED jnz service_fifo;
+pkt_last_seg:
+	call	setjmp;
+	test	SEQINTSRC, SAVEPTRS jnz pkt_saveptrs;
+	test	SG_CACHE_SHADOW, LAST_SEG_DONE jnz last_pkt_done;
+	test	SCSIPHASE, ~DATA_PHASE_MASK jz . + 2;
+	test	SCSISIGO, ATNO jnz . + 2;
+	test	SSTAT2, NONPACKREQ jz return;
+	test	MDFFSTAT, SHVALID jz return;
+	/* FALLTHROUGH */
+
+/*
+ * Either a SAVEPTRS interrupt condition is pending for this FIFO
+ * or we have a pending nonpackreq for this FIFO.  We differentiate
+ * between the two by capturing the state of the SAVEPTRS interrupt
+ * prior to clearing this status and executing the common code for
+ * these two cases.
+ */
+pkt_saveptrs:
+BEGIN_CRITICAL;
+	if ((ahd->bugs & AHD_AUTOFLUSH_BUG) != 0) {
+		or	DFCNTRL, FIFOFLUSH;
+	}
+	mov	REG0, SEQINTSRC;
+	call	calc_residual;
+	call	save_pointers;
+	mvi	CLRSEQINTSRC, CLRSAVEPTRS;
+	call	disable_ccsgen;
+	or	SEQIMODE, ENSAVEPTRS;
+	test	DFCNTRL, DIRECTION jnz pkt_saveptrs_check_status;
+	test	DFSTATUS, FIFOEMP jnz pkt_saveptrs_check_status;
+	/*
+	 * Keep a handler around for this FIFO until it drains
+	 * to the host to guarantee that we don't complete the
+	 * command to the host before the data arrives.
+	 */
+pkt_saveptrs_wait_fifoemp:
+	call	setjmp;
+	test	DFSTATUS, FIFOEMP jz return;
+pkt_saveptrs_check_status:
+	or	LONGJMP_ADDR[1], INVALID_ADDR;
+	test	REG0, SAVEPTRS jz unexpected_nonpkt_phase;
+	test	SCB_CONTROL, STATUS_RCVD jz pkt_saveptrs_clrchn;
+	jmp	last_pkt_complete;
+pkt_saveptrs_clrchn:
+	mvi	DFFSXFRCTL, CLRCHN ret;
+END_CRITICAL;
+
+last_pkt_done:
+BEGIN_CRITICAL;
+	if ((ahd->bugs & AHD_AUTOFLUSH_BUG) != 0) {
+		or	DFCNTRL, FIFOFLUSH;
+	}
+	test	SCB_CONTROL, STATUS_RCVD jz wait_pkt_end;
+	check_overrun;
+	or	SCB_SGPTR, SG_LIST_NULL;
+	/*
+	 * It is safe to skip the other FIFO check since
+	 * we defer CLRCHN on SAVEPTRS until all data in
+	 * the FIFO are seen by the host and a CFG4DATA
+	 * in this FIFO for the same context is held off
+	 * by hardware.
+	 */
+last_pkt_queue_scb:
+	or	LONGJMP_ADDR[1], INVALID_ADDR;
+	bmov	ARG_1, SCBPTR, 2;
+	mvi	DFFSXFRCTL, CLRCHN;
+	jmp	queue_arg1_scb_completion;
+
+last_pkt_complete:
+	bmov	ARG_1, SCBPTR, 2;
+	mvi	DFFSXFRCTL, CLRCHN;
+check_other_fifo:
+	clc;
+	TOGGLE_DFF_MODE
+	call	check_fifo;
+	jnc	queue_arg1_scb_completion;
+return:
+	ret;
+
+wait_pkt_end:
+	call	setjmp;
+END_CRITICAL;
+wait_pkt_end_loop:
+	test	SEQINTSRC, CTXTDONE jnz pkt_end;
+	check_overrun;
+	test	SSTAT2, NONPACKREQ jz return;
+	test	SEQINTSRC, CTXTDONE jz unexpected_nonpkt_phase;
+pkt_end:
+BEGIN_CRITICAL;
+	check_overrun;
+	or	LONGJMP_ADDR[1], INVALID_ADDR;
+	or	SCB_SGPTR, SG_LIST_NULL;
+	test	SCB_CONTROL, STATUS_RCVD jnz last_pkt_complete;
+	mvi	DFFSXFRCTL, CLRCHN ret;
+END_CRITICAL;
+
+check_status_overrun:
+	test	SHCNT[2], 0xFF jz status_IU_done;
+	SET_SEQINTCODE(STATUS_OVERRUN)
+	jmp	status_IU_done;
+pkt_handle_status:
+	call	setjmp_setscb;
+	test	MDFFSTAT, LASTSDONE jnz check_status_overrun;
+	test	SEQINTSRC, CTXTDONE jz return;
+status_IU_done:
+BEGIN_CRITICAL;
+	if ((ahd->bugs & AHD_AUTOFLUSH_BUG) != 0) {
+		or	DFCNTRL, FIFOFLUSH;
+	}
+	or	LONGJMP_ADDR[1], INVALID_ADDR;
+	mvi	SCB_SCSI_STATUS, STATUS_PKT_SENSE;
+	or	SCB_CONTROL, STATUS_RCVD;
+	jmp	last_pkt_complete;
+END_CRITICAL;
+
+SET_SRC_MODE	M_DFF0;
+SET_DST_MODE	M_DFF0;
+BEGIN_CRITICAL;
+check_fifo:
+	test	LONGJMP_ADDR[1], INVALID_ADDR jnz return;
+	mov	A, ARG_2;
+	cmp	LONGJMP_SCB[1], A	jne return;
+	mov	A, ARG_1;
+	cmp	LONGJMP_SCB[0], A	jne return;
+	stc	ret;
+END_CRITICAL;
+
+/*
+ * Nonpackreq is a polled status.  It can come true in three situations:
+ * we have received an L_Q, we have sent one or more L_Qs, or there is no
+ * L_Q context associated with this REQ (REQ occurs immediately after a
+ * (re)selection).  Routines that know that the context responsible for this
+ * nonpackreq call directly into unexpected_nonpkt_phase.  In the case of the
+ * top level idle loop, we exhaust all active contexts prior to determining that
+ * we simply do not have the full I_T_L_Q for this phase.
+ */
+unexpected_nonpkt_phase_find_ctxt:
+	/*
+	 * This nonpackreq is most likely associated with one of the tags
+	 * in a FIFO or an outgoing LQ.  Only treat it as an I_T only
+	 * nonpackreq if we've cleared out the FIFOs and handled any
+	 * pending SELDO.
+	 */
+SET_SRC_MODE	M_SCSI;
+SET_DST_MODE	M_SCSI;
+	and	A, FIFO1FREE|FIFO0FREE, DFFSTAT;
+	cmp	A, FIFO1FREE|FIFO0FREE jne return;
+	test	SSTAT0, SELDO jnz return;
+	mvi	SCBPTR[1], SCB_LIST_NULL;
+unexpected_nonpkt_phase:
+	test	MODE_PTR, ~(MK_MODE(M_DFF1, M_DFF1)) jnz . + 3;
+SET_SRC_MODE	M_DFF0;
+SET_DST_MODE	M_DFF0;
+	or	LONGJMP_ADDR[1], INVALID_ADDR;
+	mvi	DFFSXFRCTL, CLRCHN;
+	mvi	CLRSINT2, CLRNONPACKREQ;
+	test	SCSIPHASE, ~(MSG_IN_PHASE|MSG_OUT_PHASE) jnz illegal_phase;
+	SET_SEQINTCODE(ENTERING_NONPACK)
+	jmp	ITloop;
+
+illegal_phase:
+	SET_SEQINTCODE(ILLEGAL_PHASE)
+	jmp	ITloop;
+
+/*
+ * We have entered an overrun situation.  If we have working
+ * BITBUCKET, flip that on and let the hardware eat any overrun
+ * data.  Otherwise use an overrun buffer in the host to simulate
+ * BITBUCKET.
+ */
+pkt_handle_overrun:
+	SET_SEQINTCODE(CFG4OVERRUN)
+	call	freeze_queue;
+	if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) == 0) {
+		or	DFFSXFRCTL, DFFBITBUCKET;
+SET_SRC_MODE	M_DFF1;
+SET_DST_MODE	M_DFF1;
+	} else {
+		call	load_overrun_buf;
+		mvi	DFCNTRL, (HDMAEN|SCSIEN|PRELOADEN);
+	}
+	call	setjmp;
+	if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0) {
+		test	DFSTATUS, PRELOAD_AVAIL jz overrun_load_done;
+		call	load_overrun_buf;
+		or	DFCNTRL, PRELOADEN;
+overrun_load_done:
+		test	SEQINTSRC, CTXTDONE jnz pkt_overrun_end;
+	} else {
+		test	DFFSXFRCTL, DFFBITBUCKET jz pkt_overrun_end;
+	}
+	test	SSTAT2, NONPACKREQ jz return;
+pkt_overrun_end:
+	or	SCB_RESIDUAL_SGPTR, SG_OVERRUN_RESID;
+	test	SEQINTSRC, CTXTDONE jz unexpected_nonpkt_phase;
+	test	SCB_CONTROL, STATUS_RCVD jnz last_pkt_queue_scb;
+	mvi	DFFSXFRCTL, CLRCHN ret;
+
+if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0) {
+load_overrun_buf:
+	/*
+	 * Load a dummy segment if preload space is available.
+	 */
+	mov 	HADDR[0], SHARED_DATA_ADDR;
+	add	HADDR[1], PKT_OVERRUN_BUFOFFSET, SHARED_DATA_ADDR[1];
+	mov	ACCUM_SAVE, A;
+	clr	A;
+	adc	HADDR[2], A, SHARED_DATA_ADDR[2];
+	adc	HADDR[3], A, SHARED_DATA_ADDR[3];
+	mov	A, ACCUM_SAVE;
+	bmov	HADDR[4], ALLZEROS, 4;
+	/* PKT_OVERRUN_BUFSIZE is a multiple of 256 */
+	clr	HCNT[0];
+	mvi	HCNT[1], ((PKT_OVERRUN_BUFSIZE >> 8) & 0xFF);
+	clr	HCNT[2] ret;
+}
+
+cfg4icmd_intr:
diff -Nru a/drivers/scsi/aic7xxx/aic79xx_core.c b/drivers/scsi/aic7xxx/aic79xx_core.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aic79xx_core.c	Mon Dec 23 21:22:03 2002
@@ -0,0 +1,9383 @@
+/*
+ * Core routines and tables shareable across OS platforms.
+ *
+ * Copyright (c) 1994-2002 Justin T. Gibbs.
+ * Copyright (c) 2000-2002 Adaptec Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $Id: //depot/aic7xxx/aic7xxx/aic79xx.c#147 $
+ *
+ * $FreeBSD$
+ */
+
+#ifdef __linux__
+#include "aic79xx_osm.h"
+#include "aic79xx_inline.h"
+#include "aicasm/aicasm_insformat.h"
+#else
+#include <dev/aic7xxx/aic79xx_osm.h>
+#include <dev/aic7xxx/aic79xx_inline.h>
+#include <dev/aic7xxx/aicasm/aicasm_insformat.h>
+#endif
+
+/******************************** Globals *************************************/
+struct ahd_softc_tailq ahd_tailq = TAILQ_HEAD_INITIALIZER(ahd_tailq);
+
+/***************************** Lookup Tables **********************************/
+char *ahd_chip_names[] =
+{
+	"NONE",
+	"aic7901",
+	"aic7902",
+	"aic7901A"
+};
+static const u_int num_chip_names = NUM_ELEMENTS(ahd_chip_names);
+
+/*
+ * Hardware error codes.
+ */
+struct ahd_hard_error_entry {
+        uint8_t errno;
+	char *errmesg;
+};
+
+static struct ahd_hard_error_entry ahd_hard_errors[] = {
+	{ DSCTMOUT,	"Discard Timer has timed out" },
+	{ ILLOPCODE,	"Illegal Opcode in sequencer program" },
+	{ SQPARERR,	"Sequencer Parity Error" },
+	{ DPARERR,	"Data-path Parity Error" },
+	{ MPARERR,	"Scratch or SCB Memory Parity Error" },
+	{ CIOPARERR,	"CIOBUS Parity Error" },
+};
+static const u_int num_errors = NUM_ELEMENTS(ahd_hard_errors);
+
+static struct ahd_phase_table_entry ahd_phase_table[] =
+{
+	{ P_DATAOUT,	MSG_NOOP,		"in Data-out phase"	},
+	{ P_DATAIN,	MSG_INITIATOR_DET_ERR,	"in Data-in phase"	},
+	{ P_DATAOUT_DT,	MSG_NOOP,		"in DT Data-out phase"	},
+	{ P_DATAIN_DT,	MSG_INITIATOR_DET_ERR,	"in DT Data-in phase"	},
+	{ P_COMMAND,	MSG_NOOP,		"in Command phase"	},
+	{ P_MESGOUT,	MSG_NOOP,		"in Message-out phase"	},
+	{ P_STATUS,	MSG_INITIATOR_DET_ERR,	"in Status phase"	},
+	{ P_MESGIN,	MSG_PARITY_ERROR,	"in Message-in phase"	},
+	{ P_BUSFREE,	MSG_NOOP,		"while idle"		},
+	{ 0,		MSG_NOOP,		"in unknown phase"	}
+};
+
+/*
+ * In most cases we only wish to itterate over real phases, so
+ * exclude the last element from the count.
+ */
+static const u_int num_phases = NUM_ELEMENTS(ahd_phase_table) - 1;
+
+/* Our Sequencer Program */
+#include "aic79xx_seq.h"
+
+/**************************** Function Declarations ***************************/
+static void		ahd_handle_transmission_error(struct ahd_softc *ahd);
+static void		ahd_handle_lqiphase_error(struct ahd_softc *ahd,
+						  u_int lqistat1);
+static int		ahd_handle_pkt_busfree(struct ahd_softc *ahd,
+					       u_int busfreetime);
+static int		ahd_handle_nonpkt_busfree(struct ahd_softc *ahd);
+static void		ahd_handle_proto_violation(struct ahd_softc *ahd);
+static void		ahd_force_renegotiation(struct ahd_softc *ahd,
+						struct ahd_devinfo *devinfo);
+
+static struct ahd_tmode_tstate*
+			ahd_alloc_tstate(struct ahd_softc *ahd,
+					 u_int scsi_id, char channel);
+#ifdef AHD_TARGET_MODE
+static void		ahd_free_tstate(struct ahd_softc *ahd,
+					u_int scsi_id, char channel, int force);
+#endif
+static void		ahd_devlimited_syncrate(struct ahd_softc *ahd,
+					        struct ahd_initiator_tinfo *,
+						u_int *period,
+						u_int *ppr_options,
+						role_t role);
+static void		ahd_update_neg_table(struct ahd_softc *ahd,
+					     struct ahd_devinfo *devinfo,
+					     struct ahd_transinfo *tinfo);
+static void		ahd_update_pending_scbs(struct ahd_softc *ahd);
+static void		ahd_fetch_devinfo(struct ahd_softc *ahd,
+					  struct ahd_devinfo *devinfo);
+static void		ahd_scb_devinfo(struct ahd_softc *ahd,
+					struct ahd_devinfo *devinfo,
+					struct scb *scb);
+static void		ahd_setup_initiator_msgout(struct ahd_softc *ahd,
+						   struct ahd_devinfo *devinfo,
+						   struct scb *scb);
+static void		ahd_build_transfer_msg(struct ahd_softc *ahd,
+					       struct ahd_devinfo *devinfo);
+static void		ahd_construct_sdtr(struct ahd_softc *ahd,
+					   struct ahd_devinfo *devinfo,
+					   u_int period, u_int offset);
+static void		ahd_construct_wdtr(struct ahd_softc *ahd,
+					   struct ahd_devinfo *devinfo,
+					   u_int bus_width);
+static void		ahd_construct_ppr(struct ahd_softc *ahd,
+					  struct ahd_devinfo *devinfo,
+					  u_int period, u_int offset,
+					  u_int bus_width, u_int ppr_options);
+static void		ahd_clear_msg_state(struct ahd_softc *ahd);
+static void		ahd_handle_message_phase(struct ahd_softc *ahd);
+typedef enum {
+	AHDMSG_1B,
+	AHDMSG_2B,
+	AHDMSG_EXT
+} ahd_msgtype;
+static int		ahd_sent_msg(struct ahd_softc *ahd, ahd_msgtype type,
+				     u_int msgval, int full);
+static int		ahd_parse_msg(struct ahd_softc *ahd,
+				      struct ahd_devinfo *devinfo);
+static int		ahd_handle_msg_reject(struct ahd_softc *ahd,
+					      struct ahd_devinfo *devinfo);
+static void		ahd_handle_ign_wide_residue(struct ahd_softc *ahd,
+						struct ahd_devinfo *devinfo);
+static void		ahd_reinitialize_dataptrs(struct ahd_softc *ahd);
+static void		ahd_handle_devreset(struct ahd_softc *ahd,
+					    struct ahd_devinfo *devinfo,
+					    cam_status status, char *message,
+					    int verbose_level);
+#if AHD_TARGET_MODE
+static void		ahd_setup_target_msgin(struct ahd_softc *ahd,
+					       struct ahd_devinfo *devinfo,
+					       struct scb *scb);
+#endif
+
+static u_int		ahd_sglist_size(struct ahd_softc *ahd);
+static u_int		ahd_sglist_allocsize(struct ahd_softc *ahd);
+static bus_dmamap_callback_t
+			ahd_dmamap_cb; 
+static void		ahd_initialize_hscbs(struct ahd_softc *ahd);
+static int		ahd_init_scbdata(struct ahd_softc *ahd);
+static void		ahd_fini_scbdata(struct ahd_softc *ahd);
+static void		ahd_setup_iocell_workaround(struct ahd_softc *ahd);
+static void		ahd_iocell_first_selection(struct ahd_softc *ahd);
+static void		ahd_add_col_list(struct ahd_softc *ahd,
+					 struct scb *scb, u_int col_idx);
+static void		ahd_rem_col_list(struct ahd_softc *ahd,
+					 struct scb *scb);
+static void		ahd_chip_init(struct ahd_softc *ahd);
+static void		ahd_qinfifo_requeue(struct ahd_softc *ahd,
+					    struct scb *prev_scb,
+					    struct scb *scb);
+static int		ahd_qinfifo_count(struct ahd_softc *ahd);
+static int		ahd_search_scb_list(struct ahd_softc *ahd, int target,
+					    char channel, int lun, u_int tag,
+					    role_t role, uint32_t status,
+					    ahd_search_action action,
+					    u_int *list_head, u_int tid);
+static void		ahd_stitch_tid_list(struct ahd_softc *ahd,
+					    u_int tid_prev, u_int tid_cur,
+					    u_int tid_next);
+static void		ahd_add_scb_to_free_list(struct ahd_softc *ahd,
+						 u_int scbid);
+static u_int		ahd_rem_wscb(struct ahd_softc *ahd, u_int scbid,
+				     u_int prev, u_int next, u_int tid);
+static void		ahd_reset_current_bus(struct ahd_softc *ahd);
+static ahd_callback_t	ahd_reset_poll;
+static ahd_callback_t	ahd_stat_timer;
+#ifdef AHD_DUMP_SEQ
+static void		ahd_dumpseq(struct ahd_softc *ahd);
+#endif
+static void		ahd_loadseq(struct ahd_softc *ahd);
+static int		ahd_check_patch(struct ahd_softc *ahd,
+					struct patch **start_patch,
+					u_int start_instr, u_int *skip_addr);
+static u_int		ahd_resolve_seqaddr(struct ahd_softc *ahd,
+					    u_int address);
+static void		ahd_download_instr(struct ahd_softc *ahd,
+					   u_int instrptr, uint8_t *dconsts);
+static int		ahd_probe_stack_size(struct ahd_softc *ahd);
+#ifdef AHD_TARGET_MODE
+static void		ahd_queue_lstate_event(struct ahd_softc *ahd,
+					       struct ahd_tmode_lstate *lstate,
+					       u_int initiator_id,
+					       u_int event_type,
+					       u_int event_arg);
+static void		ahd_update_scsiid(struct ahd_softc *ahd,
+					  u_int targid_mask);
+static int		ahd_handle_target_cmd(struct ahd_softc *ahd,
+					      struct target_cmd *cmd);
+#endif
+
+/******************************** Private Inlines *****************************/
+static __inline void	ahd_assert_atn(struct ahd_softc *ahd);
+static __inline int	ahd_currently_packetized(struct ahd_softc *ahd);
+static __inline int	ahd_set_active_fifo(struct ahd_softc *ahd);
+
+static __inline void
+ahd_assert_atn(struct ahd_softc *ahd)
+{
+	ahd_outb(ahd, SCSISIGO, ATNO);
+}
+
+/*
+ * Determine if the current connection has a packetized
+ * agreement.  This does not necessarily mean that we
+ * are currently in a packetized transfer.  We could
+ * just as easily be sending or receiving a message.
+ */
+static __inline int
+ahd_currently_packetized(struct ahd_softc *ahd)
+{
+	ahd_mode_state	 saved_modes;
+	int		 packetized;
+
+	saved_modes = ahd_save_modes(ahd);
+	if ((ahd->bugs & AHD_PKTIZED_STATUS_BUG) != 0) {
+		/*
+		 * The packetized bit refers to the last
+		 * connection, not the current one.  Check
+		 * for non-zero LQISTATE instead.
+		 */
+		ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
+		packetized = ahd_inb(ahd, LQISTATE) != 0;
+	} else {
+		ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+		packetized = ahd_inb(ahd, LQISTAT2) & PACKETIZED;
+	}
+	ahd_restore_modes(ahd, saved_modes);
+	return (packetized);
+}
+
+static __inline int
+ahd_set_active_fifo(struct ahd_softc *ahd)
+{
+	u_int active_fifo;
+
+	AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
+	active_fifo = ahd_inb(ahd, DFFSTAT) & CURRFIFO;
+	switch (active_fifo) {
+	case 0:
+	case 1:
+		ahd_set_modes(ahd, active_fifo, active_fifo);
+		return (1);
+	default:
+		return (0);
+	}
+}
+
+/************************* Sequencer Execution Control ************************/
+/*
+ * Restart the sequencer program from address zero
+ */
+void
+ahd_restart(struct ahd_softc *ahd)
+{
+
+	ahd_pause(ahd);
+
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+
+	/* No more pending messages */
+	ahd_clear_msg_state(ahd);
+	ahd_outb(ahd, SCSISIGO, 0);		/* De-assert BSY */
+	ahd_outb(ahd, MSG_OUT, MSG_NOOP);	/* No message to send */
+	ahd_outb(ahd, SXFRCTL1, ahd_inb(ahd, SXFRCTL1) & ~BITBUCKET);
+	ahd_outb(ahd, SEQINTCTL, 0);
+	ahd_outb(ahd, LASTPHASE, P_BUSFREE);
+	ahd_outb(ahd, SEQ_FLAGS, 0);
+	ahd_outb(ahd, SAVED_SCSIID, 0xFF);
+	ahd_outb(ahd, SAVED_LUN, 0xFF);
+
+	/*
+	 * Ensure that the sequencer's idea of TQINPOS
+	 * matches our own.  The sequencer increments TQINPOS
+	 * only after it sees a DMA complete and a reset could
+	 * occur before the increment leaving the kernel to believe
+	 * the command arrived but the sequencer to not.
+	 */
+	ahd_outb(ahd, TQINPOS, ahd->tqinfifonext);
+
+	/* Always allow reselection */
+	ahd_outb(ahd, SCSISEQ1,
+		 ahd_inb(ahd, SCSISEQ_TEMPLATE) & (ENSELI|ENRSELI|ENAUTOATNP));
+	/* Ensure that no DMA operations are in progress */
+	ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
+	ahd_outb(ahd, SCBHCNT, 0);
+	ahd_outb(ahd, CCSCBCTL, CCSCBRESET);
+	ahd_outb(ahd, SEQCTL0, FASTMODE|SEQRESET);
+	ahd_unpause(ahd);
+}
+
+void
+ahd_clear_fifo(struct ahd_softc *ahd, u_int fifo)
+{
+	ahd_mode_state	 saved_modes;
+
+#ifdef AHD_DEBUG
+	if ((ahd_debug & AHD_SHOW_FIFOS) != 0)
+		printf("%s: Clearing FIFO %d\n", ahd_name(ahd), fifo);
+#endif
+	saved_modes = ahd_save_modes(ahd);
+	ahd_set_modes(ahd, fifo, fifo);
+	ahd_outb(ahd, DFFSXFRCTL, RSTCHN|CLRSHCNT);
+	if ((ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0)
+		ahd_outb(ahd, CCSGCTL, CCSGRESET);
+	ahd_outb(ahd, LONGJMP_ADDR + 1, INVALID_ADDR);
+	ahd_outb(ahd, SG_STATE, 0);
+	ahd_restore_modes(ahd, saved_modes);
+}
+
+/************************* Input/Output Queues ********************************/
+/*
+ * Flush and completed commands that are sitting in the command
+ * complete queues down on the chip but have yet to be dma'ed back up.
+ */
+void
+ahd_flush_qoutfifo(struct ahd_softc *ahd)
+{
+	struct		scb *scb;
+	ahd_mode_state	saved_modes;
+	u_int		saved_scbptr;
+	u_int		ccscbctl;
+	u_int		scbid;
+	u_int		next_scbid;
+
+	saved_modes = ahd_save_modes(ahd);
+	ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
+	saved_scbptr = ahd_get_scbptr(ahd);
+
+	/*
+	 * Wait for any inprogress DMA to complete and clear DMA state
+	 * if this if for an SCB in the qinfifo.
+	 */
+	while ((ccscbctl = ahd_inb(ahd, CCSCBCTL) & (CCARREN|CCSCBEN)) != 0) {
+
+		if ((ccscbctl & (CCSCBDIR|CCARREN)) == (CCSCBDIR|CCARREN)) {
+			if ((ccscbctl & ARRDONE) != 0)
+				break;
+		} else if ((ccscbctl & CCSCBDONE) != 0)
+			break;
+		ahd_delay(200);
+	}
+	if ((ccscbctl & CCSCBDIR) != 0)
+		ahd_outb(ahd, CCSCBCTL, ccscbctl & ~(CCARREN|CCSCBEN));
+
+	/*
+	 * Complete any SCBs that just finished being
+	 * DMA'ed into the qoutfifo.
+	 */
+	ahd_run_qoutfifo(ahd);
+
+	/*
+	 * Manually update/complete any completed SCBs that are waiting to be
+	 * DMA'ed back up to the host.
+	 */
+	scbid = ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
+	while (!SCBID_IS_NULL(scbid)) {
+		uint8_t *hscb_ptr;
+		u_int	 i;
+		
+		ahd_set_scbptr(ahd, scbid);
+		next_scbid = ahd_inw(ahd, SCB_NEXT_COMPLETE);
+		scb = ahd_lookup_scb(ahd, scbid);
+		if (scb == NULL) {
+			printf("%s: Warning - DMA-up and complete "
+			       "SCB %d invalid\n", ahd_name(ahd), scbid);
+			continue;
+		}
+		hscb_ptr = (uint8_t *)scb->hscb;
+		for (i = 0; i < sizeof(struct hardware_scb); i++)
+			*hscb_ptr++ = ahd_inb(ahd, SCB_BASE + i);
+
+		ahd_complete_scb(ahd, scb);
+		scbid = next_scbid;
+	}
+	ahd_outw(ahd, COMPLETE_DMA_SCB_HEAD, SCB_LIST_NULL);
+
+	scbid = ahd_inw(ahd, COMPLETE_SCB_HEAD);
+	while (!SCBID_IS_NULL(scbid)) {
+
+		ahd_set_scbptr(ahd, scbid);
+		next_scbid = ahd_inw(ahd, SCB_NEXT_COMPLETE);
+		scb = ahd_lookup_scb(ahd, scbid);
+		if (scb == NULL) {
+			printf("%s: Warning - Complete SCB %d invalid\n",
+			       ahd_name(ahd), scbid);
+			continue;
+		}
+
+		ahd_complete_scb(ahd, scb);
+		scbid = next_scbid;
+	}
+	ahd_outw(ahd, COMPLETE_SCB_HEAD, SCB_LIST_NULL);
+
+	/*
+	 * Restore state.
+	 */
+	ahd_set_scbptr(ahd, saved_scbptr);
+	ahd_restore_modes(ahd, saved_modes);
+	ahd->flags |= AHD_UPDATE_PEND_CMDS;
+}
+
+void
+ahd_run_qoutfifo(struct ahd_softc *ahd)
+{
+	struct scb *scb;
+	u_int  scb_index;
+
+	if ((ahd->flags & AHD_RUNNING_QOUTFIFO) != 0)
+		panic("ahd_run_qoutfifo recursion");
+	ahd->flags |= AHD_RUNNING_QOUTFIFO;
+	ahd_sync_qoutfifo(ahd, BUS_DMASYNC_POSTREAD);
+	while ((ahd->qoutfifo[ahd->qoutfifonext]
+	     & QOUTFIFO_ENTRY_VALID_LE) == ahd->qoutfifonext_valid_tag) {
+
+		scb_index = ahd_le16toh(ahd->qoutfifo[ahd->qoutfifonext]
+				      & ~QOUTFIFO_ENTRY_VALID_LE);
+		scb = ahd_lookup_scb(ahd, scb_index);
+		if (scb == NULL) {
+			printf("%s: WARNING no command for scb %d "
+			       "(cmdcmplt)\nQOUTPOS = %d\n",
+			       ahd_name(ahd), scb_index,
+			       ahd->qoutfifonext);
+			ahd_dump_card_state(ahd);
+		} else
+			ahd_complete_scb(ahd, scb);
+
+		ahd->qoutfifonext = (ahd->qoutfifonext+1) & (AHD_QOUT_SIZE-1);
+		if (ahd->qoutfifonext == 0)
+			ahd->qoutfifonext_valid_tag ^= QOUTFIFO_ENTRY_VALID_LE;
+	}
+	ahd->flags &= ~AHD_RUNNING_QOUTFIFO;
+}
+
+/************************* Interrupt Handling *********************************/
+void
+ahd_handle_hwerrint(struct ahd_softc *ahd)
+{
+	/*
+	 * Some catastrophic hardware error has occurred.
+	 * Print it for the user and disable the controller.
+	 */
+	int i;
+	int error;
+
+	error = ahd_inb(ahd, ERROR);
+	for (i = 0; i < num_errors; i++) {
+		if ((error & ahd_hard_errors[i].errno) != 0)
+			printf("%s: hwerrint, %s\n",
+			       ahd_name(ahd), ahd_hard_errors[i].errmesg);
+	}
+
+	ahd_dump_card_state(ahd);
+	panic("BRKADRINT");
+
+	/* Tell everyone that this HBA is no longer availible */
+	ahd_abort_scbs(ahd, CAM_TARGET_WILDCARD, ALL_CHANNELS,
+		       CAM_LUN_WILDCARD, SCB_LIST_NULL, ROLE_UNKNOWN,
+		       CAM_NO_HBA);
+
+	/* Tell the system that this controller has gone away. */
+	ahd_free(ahd);
+}
+
+void
+ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat)
+{
+	u_int seqintcode;
+
+	/*
+	 * Save the sequencer interrupt code and clear the SEQINT
+	 * bit. We will unpause the sequencer, if appropriate,
+	 * after servicing the request.
+	 */
+	seqintcode = ahd_inb(ahd, SEQINTCODE);
+	ahd_outb(ahd, CLRINT, CLRSEQINT);
+	if ((ahd->bugs & AHD_INTCOLLISION_BUG) != 0) {
+		/*
+		 * Unpause the sequencer and let it clear
+		 * SEQINT by writing NO_SEQINT to it.  This
+		 * will cause the sequencer to be paused again,
+		 * which is the expected state of this routine.
+		 */
+		ahd_unpause(ahd);
+		while (!ahd_is_paused(ahd))
+			;
+		ahd_outb(ahd, CLRINT, CLRSEQINT);
+	}
+	ahd_update_modes(ahd);
+#ifdef AHD_DEBUG
+	if ((ahd_debug & AHD_SHOW_MISC) != 0)
+		printf("%s: Handle Seqint Called for code %d\n",
+		       ahd_name(ahd), seqintcode);
+#endif
+	switch (seqintcode) {
+	case ENTERING_NONPACK:
+	{
+		struct	scb *scb;
+		u_int	scbid;
+
+		AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
+				 ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK));
+		scbid = ahd_get_scbptr(ahd);
+		scb = ahd_lookup_scb(ahd, scbid);
+		if (scb == NULL) {
+			/*
+			 * Somehow need to know if this
+			 * is from a selection or reselection.
+			 * From that, we can termine target
+			 * ID so we at least have an I_T nexus.
+			 */
+		} else {
+			ahd_outb(ahd, SAVED_SCSIID, scb->hscb->scsiid);
+			ahd_outb(ahd, SAVED_LUN, scb->hscb->lun);
+			ahd_outb(ahd, SEQ_FLAGS, 0x0);
+		}
+		if ((ahd_inb(ahd, LQISTAT2) & LQIPHASE_OUTPKT) != 0
+		 && (ahd_inb(ahd, SCSISIGO) & ATNO) != 0) {
+			/*
+			 * Phase change after read stream with
+			 * CRC error with P0 asserted on last
+			 * packet.
+			 */
+#ifdef AHD_DEBUG
+			if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
+				printf("%s: Assuming LQIPHASE_NLQ with "
+				       "P0 assertion\n", ahd_name(ahd));
+#endif
+		}
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
+			printf("%s: Entering NONPACK\n", ahd_name(ahd));
+#endif
+		break;
+	}
+	case INVALID_SEQINT:
+		printf("%s: Invalid Sequencer interrupt occurred.\n",
+		       ahd_name(ahd));
+		ahd_dump_card_state(ahd);
+		ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
+		break;
+	case STATUS_OVERRUN:
+	{
+		printf("%s: Status Overrun", ahd_name(ahd));
+		ahd_dump_card_state(ahd);
+		ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
+		break;
+	}
+	case CFG4ISTAT_INTR:
+	{
+		struct	scb *scb;
+		u_int	scbid;
+
+		scbid = ahd_get_scbptr(ahd);
+		scb = ahd_lookup_scb(ahd, scbid);
+		if (scb == NULL) {
+			ahd_dump_card_state(ahd);
+			printf("CFG4ISTAT: Free SCB %d referenced", scbid);
+			panic("For safety");
+		}
+		ahd_outq(ahd, HADDR, scb->sense_busaddr);
+		ahd_outw(ahd, HCNT, AHD_SENSE_BUFSIZE);
+		ahd_outb(ahd, HCNT + 2, 0);
+		ahd_outb(ahd, SG_CACHE_PRE, SG_LAST_SEG);
+		ahd_outb(ahd, DFCNTRL, PRELOADEN|SCSIEN|HDMAEN);
+		break;
+	}
+	case ILLEGAL_PHASE:
+	{
+		u_int bus_phase;
+
+		bus_phase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
+		printf("%s: ILLEGAL_PHASE 0x%x\n",
+		       ahd_name(ahd), bus_phase);
+
+		switch (bus_phase) {
+		case P_DATAOUT:
+		case P_DATAIN:
+		case P_DATAOUT_DT:
+		case P_DATAIN_DT:
+		case P_MESGOUT:
+		case P_STATUS:
+		case P_MESGIN:
+			ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
+			printf("%s: Issued Bus Reset.\n", ahd_name(ahd));
+			break;
+		case P_COMMAND:
+		{
+			struct	ahd_devinfo devinfo;
+			struct	scb *scb;
+			struct	ahd_initiator_tinfo *targ_info;
+			struct	ahd_tmode_tstate *tstate;
+			struct	ahd_transinfo *tinfo;
+			u_int	scbid;
+
+			/*
+			 * If a target takes us into the command phase
+			 * assume that it has been externally reset and
+			 * has thus lost our previous packetized negotiation
+			 * agreement.  Since we have not sent an identify
+			 * message and may not have fully qualified the
+			 * connection, we change our command to TUR, assert
+			 * ATN and ABORT the task when we go to message in
+			 * phase.  The OSM will see the REQUEUE_REQUEST
+			 * status and retry the command.
+			 */
+			scbid = ahd_get_scbptr(ahd);
+			scb = ahd_lookup_scb(ahd, scbid);
+			if (scb == NULL) {
+				printf("Invalid phase with no valid SCB.  "
+				       "Resetting bus.\n");
+				ahd_reset_channel(ahd, 'A',
+						  /*Initiate Reset*/TRUE);
+				break;
+			}
+			ahd_compile_devinfo(&devinfo, SCB_GET_OUR_ID(scb),
+					    SCB_GET_TARGET(ahd, scb),
+					    SCB_GET_LUN(scb),
+					    SCB_GET_CHANNEL(ahd, scb),
+					    ROLE_INITIATOR);
+			targ_info = ahd_fetch_transinfo(ahd,
+							devinfo.channel,
+							devinfo.our_scsiid,
+							devinfo.target,
+							&tstate);
+			tinfo = &targ_info->curr;
+			ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
+				      AHD_TRANS_ACTIVE|AHD_TRANS_GOAL,
+				      /*paused*/TRUE);
+			ahd_set_syncrate(ahd, &devinfo, /*period*/0,
+					 /*offset*/0, /*ppr_options*/0,
+					 AHD_TRANS_ACTIVE, /*paused*/TRUE);
+			ahd_outb(ahd, SCB_CDB_STORE, 0);
+			ahd_outb(ahd, SCB_CDB_STORE+1, 0);
+			ahd_outb(ahd, SCB_CDB_STORE+2, 0);
+			ahd_outb(ahd, SCB_CDB_STORE+3, 0);
+			ahd_outb(ahd, SCB_CDB_STORE+4, 0);
+			ahd_outb(ahd, SCB_CDB_STORE+5, 0);
+			ahd_outb(ahd, SCB_CDB_LEN, 6);
+			scb->hscb->control &= ~(TAG_ENB|SCB_TAG_TYPE);
+			scb->hscb->control |= MK_MESSAGE;
+			ahd_outb(ahd, SCB_CONTROL, scb->hscb->control);
+			ahd_outb(ahd, MSG_OUT, HOST_MSG);
+			ahd_outb(ahd, SAVED_SCSIID, scb->hscb->scsiid);
+			/*
+			 * The lun is 0, regardless of the SCB's lun
+			 * as we have not sent an identify message.
+			 */
+			ahd_outb(ahd, SAVED_LUN, 0);
+			ahd_outb(ahd, SEQ_FLAGS, 0);
+			ahd_assert_atn(ahd);
+			scb->flags &= ~(SCB_PACKETIZED);
+			scb->flags |= SCB_ABORT|SCB_CMDPHASE_ABORT;
+			ahd_freeze_devq(ahd, scb);
+			ahd_set_transaction_status(scb, CAM_REQUEUE_REQ);
+			ahd_freeze_scb(scb);
+
+			/*
+			 * Allow the sequencer to continue with
+			 * non-pack processing.
+			 */
+			ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+			ahd_outb(ahd, CLRLQOINT1, CLRLQOPHACHGINPKT);
+			if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0) {
+				ahd_outb(ahd, CLRLQOINT1, 0);
+			}
+#ifdef AHD_DEBUG
+			if ((ahd_debug & AHD_SHOW_RECOVERY) != 0) {
+				ahd_print_path(ahd, scb);
+				printf("Unexpected command phase from "
+				       "packetized target\n");
+			}
+#endif
+			break;
+		}
+		}
+		break;
+	}
+	case CFG4OVERRUN:
+	{
+		struct	scb *scb;
+		u_int	scb_index;
+		
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_RECOVERY) != 0) {
+			printf("%s: CFG4OVERRUN mode = %x\n", ahd_name(ahd),
+			       ahd_inb(ahd, MODE_PTR));
+		}
+#endif
+		scb_index = ahd_get_scbptr(ahd);
+		scb = ahd_lookup_scb(ahd, scb_index);
+		if (scb == NULL) {
+			/*
+			 * Attempt to transfer to an SCB that is
+			 * not outstanding.
+			 */
+			ahd_assert_atn(ahd);
+			ahd_outb(ahd, MSG_OUT, HOST_MSG);
+			ahd->msgout_buf[0] = MSG_ABORT_TASK;
+			ahd->msgout_len = 1;
+			ahd->msgout_index = 0;
+			ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
+			/*
+			 * Clear status received flag to prevent any
+			 * attempt to complete this bogus SCB.
+			 */
+			ahd_outb(ahd, SCB_CONTROL,
+				 ahd_inb(ahd, SCB_CONTROL) & ~STATUS_RCVD);
+		}
+		break;
+	}
+	case DUMP_CARD_STATE:
+	{
+		ahd_dump_card_state(ahd);
+		break;
+	}
+	case PDATA_REINIT:
+	{
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_RECOVERY) != 0) {
+			printf("%s: PDATA_REINIT - DFCNTRL = 0x%x "
+			       "SG_CACHE_SHADOW = 0x%x\n",
+			       ahd_name(ahd), ahd_inb(ahd, DFCNTRL),
+			       ahd_inb(ahd, SG_CACHE_SHADOW));
+		}
+#endif
+		ahd_reinitialize_dataptrs(ahd);
+		break;
+	}
+	case HOST_MSG_LOOP:
+	{
+		struct ahd_devinfo devinfo;
+
+		/*
+		 * The sequencer has encountered a message phase
+		 * that requires host assistance for completion.
+		 * While handling the message phase(s), we will be
+		 * notified by the sequencer after each byte is
+		 * transfered so we can track bus phase changes.
+		 *
+		 * If this is the first time we've seen a HOST_MSG_LOOP
+		 * interrupt, initialize the state of the host message
+		 * loop.
+		 */
+		ahd_fetch_devinfo(ahd, &devinfo);
+		if (ahd->msg_type == MSG_TYPE_NONE) {
+			struct scb *scb;
+			u_int scb_index;
+			u_int bus_phase;
+
+			bus_phase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
+			if (bus_phase != P_MESGIN
+			 && bus_phase != P_MESGOUT) {
+				printf("ahd_intr: HOST_MSG_LOOP bad "
+				       "phase 0x%x\n", bus_phase);
+				/*
+				 * Probably transitioned to bus free before
+				 * we got here.  Just punt the message.
+				 */
+				ahd_dump_card_state(ahd);
+				ahd_clear_intstat(ahd);
+				ahd_restart(ahd);
+				return;
+			}
+
+			scb_index = ahd_get_scbptr(ahd);
+			scb = ahd_lookup_scb(ahd, scb_index);
+			if (devinfo.role == ROLE_INITIATOR) {
+				if (bus_phase == P_MESGOUT)
+					ahd_setup_initiator_msgout(ahd,
+								   &devinfo,
+								   scb);
+				else {
+					ahd->msg_type =
+					    MSG_TYPE_INITIATOR_MSGIN;
+					ahd->msgin_index = 0;
+				}
+			}
+#if AHD_TARGET_MODE
+			else {
+				if (bus_phase == P_MESGOUT) {
+					ahd->msg_type =
+					    MSG_TYPE_TARGET_MSGOUT;
+					ahd->msgin_index = 0;
+				}
+				else 
+					ahd_setup_target_msgin(ahd,
+							       &devinfo,
+							       scb);
+			}
+#endif
+		}
+
+		ahd_handle_message_phase(ahd);
+		break;
+	}
+	case NO_MATCH:
+	{
+		/* Ensure we don't leave the selection hardware on */
+		AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
+		ahd_outb(ahd, SCSISEQ0, ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
+
+		printf("%s:%c:%d: no active SCB for reconnecting "
+		       "target - issuing BUS DEVICE RESET\n",
+		       ahd_name(ahd), 'A', ahd_inb(ahd, SELID) >> 4);
+		printf("SAVED_SCSIID == 0x%x, SAVED_LUN == 0x%x, "
+		       "REG0 == 0x%x ACCUM = 0x%x\n",
+		       ahd_inb(ahd, SAVED_SCSIID), ahd_inb(ahd, SAVED_LUN),
+		       ahd_inw(ahd, REG0), ahd_inb(ahd, ACCUM));
+		printf("SEQ_FLAGS == 0x%x, SCBPTR == 0x%x, BTT == 0x%x, "
+		       "SINDEX == 0x%x\n",
+		       ahd_inb(ahd, SEQ_FLAGS), ahd_get_scbptr(ahd),
+		       ahd_find_busy_tcl(ahd,
+					 BUILD_TCL(ahd_inb(ahd, SAVED_SCSIID),
+						   ahd_inb(ahd, SAVED_LUN))),
+		       ahd_inw(ahd, SINDEX));
+		printf("SELID == 0x%x, SCB_SCSIID == 0x%x, SCB_LUN == 0x%x, "
+		       "SCB_CONTROL == 0x%x\n",
+		       ahd_inb(ahd, SELID), ahd_inb_scbram(ahd, SCB_SCSIID),
+		       ahd_inb_scbram(ahd, SCB_LUN),
+		       ahd_inb_scbram(ahd, SCB_CONTROL));
+		printf("SCSIBUS[0] == 0x%x, SCSISIGI == 0x%x\n",
+		       ahd_inb(ahd, SCSIBUS), ahd_inb(ahd, SCSISIGI));
+		printf("SXFRCTL0 == 0x%x\n", ahd_inb(ahd, SXFRCTL0));
+		printf("SEQCTL0 == 0x%x\n", ahd_inb(ahd, SEQCTL0));
+		ahd_dump_card_state(ahd);
+		ahd->msgout_buf[0] = MSG_BUS_DEV_RESET;
+		ahd->msgout_len = 1;
+		ahd->msgout_index = 0;
+		ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
+		ahd_outb(ahd, MSG_OUT, HOST_MSG);
+		ahd_assert_atn(ahd);
+		break;
+	}
+	case PROTO_VIOLATION:
+	{
+		ahd_handle_proto_violation(ahd);
+		break;
+	}
+	case IGN_WIDE_RES:
+	{
+		struct ahd_devinfo devinfo;
+
+		ahd_fetch_devinfo(ahd, &devinfo);
+		ahd_handle_ign_wide_residue(ahd, &devinfo);
+		break;
+	}
+	case BAD_PHASE:
+	{
+		u_int lastphase;
+
+		lastphase = ahd_inb(ahd, LASTPHASE);
+		printf("%s:%c:%d: unknown scsi bus phase %x, "
+		       "lastphase = 0x%x.  Attempting to continue\n",
+		       ahd_name(ahd), 'A',
+		       SCSIID_TARGET(ahd, ahd_inb(ahd, SAVED_SCSIID)),
+		       lastphase, ahd_inb(ahd, SCSISIGI));
+		break;
+	}
+	case MISSED_BUSFREE:
+	{
+		u_int lastphase;
+
+		lastphase = ahd_inb(ahd, LASTPHASE);
+		printf("%s:%c:%d: Missed busfree. "
+		       "Lastphase = 0x%x, Curphase = 0x%x\n",
+		       ahd_name(ahd), 'A',
+		       SCSIID_TARGET(ahd, ahd_inb(ahd, SAVED_SCSIID)),
+		       lastphase, ahd_inb(ahd, SCSISIGI));
+		ahd_restart(ahd);
+		return;
+	}
+	case DATA_OVERRUN:
+	{
+		/*
+		 * When the sequencer detects an overrun, it
+		 * places the controller in "BITBUCKET" mode
+		 * and allows the target to complete its transfer.
+		 * Unfortunately, none of the counters get updated
+		 * when the controller is in this mode, so we have
+		 * no way of knowing how large the overrun was.
+		 */
+		struct	scb *scb;
+		u_int	scbindex;
+#ifdef AHD_DEBUG
+		u_int	lastphase;
+#endif
+
+		scbindex = ahd_get_scbptr(ahd);
+		scb = ahd_lookup_scb(ahd, scbindex);
+#ifdef AHD_DEBUG
+		lastphase = ahd_inb(ahd, LASTPHASE);
+		if ((ahd_debug & AHD_SHOW_RECOVERY) != 0) {
+			ahd_print_path(ahd, scb);
+			printf("data overrun detected %s.  Tag == 0x%x.\n",
+			       ahd_lookup_phase_entry(lastphase)->phasemsg,
+			       SCB_GET_TAG(scb));
+			ahd_print_path(ahd, scb);
+			printf("%s seen Data Phase.  Length = %ld.  "
+			       "NumSGs = %d.\n",
+			       ahd_inb(ahd, SEQ_FLAGS) & DPHASE
+			       ? "Have" : "Haven't",
+			       ahd_get_transfer_length(scb), scb->sg_count);
+			ahd_dump_sglist(scb);
+		}
+#endif
+
+		/*
+		 * Set this and it will take effect when the
+		 * target does a command complete.
+		 */
+		ahd_freeze_devq(ahd, scb);
+		ahd_set_transaction_status(scb, CAM_DATA_RUN_ERR);
+		ahd_freeze_scb(scb);
+		break;
+	}
+	case MKMSG_FAILED:
+	{
+		struct ahd_devinfo devinfo;
+		struct scb *scb;
+		u_int scbid;
+
+		ahd_fetch_devinfo(ahd, &devinfo);
+		printf("%s:%c:%d:%d: Attempt to issue message failed\n",
+		       ahd_name(ahd), devinfo.channel, devinfo.target,
+		       devinfo.lun);
+		scbid = ahd_get_scbptr(ahd);
+		scb = ahd_lookup_scb(ahd, scbid);
+		if (scb != NULL
+		 && (scb->flags & SCB_RECOVERY_SCB) != 0)
+			/*
+			 * Ensure that we didn't put a second instance of this
+			 * SCB into the QINFIFO.
+			 */
+			ahd_search_qinfifo(ahd, SCB_GET_TARGET(ahd, scb),
+					   SCB_GET_CHANNEL(ahd, scb),
+					   SCB_GET_LUN(scb), SCB_GET_TAG(scb),
+					   ROLE_INITIATOR, /*status*/0,
+					   SEARCH_REMOVE);
+		ahd_outb(ahd, SCB_CONTROL,
+			 ahd_inb(ahd, SCB_CONTROL) & ~MK_MESSAGE);
+		break;
+	}
+	case TRACEPOINT0:
+	case TRACEPOINT1:
+	case TRACEPOINT2:
+	case TRACEPOINT3:
+		printf("%s: Tracepoint %d\n", ahd_name(ahd),
+		       seqintcode - TRACEPOINT0);
+		break;
+	case NO_SEQINT:
+		break;
+	case SAW_HWERR:
+		ahd_handle_hwerrint(ahd);
+		break;
+	default:
+		printf("%s: Unexpected SEQINTCODE %d\n", ahd_name(ahd),
+		       seqintcode);
+		break;
+	}
+	/*
+	 *  The sequencer is paused immediately on
+	 *  a SEQINT, so we should restart it when
+	 *  we're done.
+	 */
+	ahd_unpause(ahd);
+}
+
+void
+ahd_handle_scsiint(struct ahd_softc *ahd, u_int intstat)
+{
+	struct scb	*scb;
+	u_int		 status0;
+	u_int		 status3;
+	u_int		 status;
+	u_int		 lqistat1;
+	u_int		 lqostat0;
+	u_int		 scbid;
+	u_int		 busfreetime;
+
+	ahd_update_modes(ahd);
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+
+	status3 = ahd_inb(ahd, SSTAT3) & (NTRAMPERR|OSRAMPERR);
+	status0 = ahd_inb(ahd, SSTAT0) & (IOERR|OVERRUN|SELDI|SELDO);
+	status = ahd_inb(ahd, SSTAT1) & (SELTO|SCSIRSTI|BUSFREE|SCSIPERR);
+	lqistat1 = ahd_inb(ahd, LQISTAT1);
+	lqostat0 = ahd_inb(ahd, LQOSTAT0);
+	busfreetime = ahd_inb(ahd, SSTAT2) & BUSFREETIME;
+	if ((status0 & (SELDI|SELDO)) != 0) {
+		u_int simode0;
+
+		ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
+		simode0 = ahd_inb(ahd, SIMODE0);
+		status0 &= simode0 & (IOERR|OVERRUN|SELDI|SELDO);
+		ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+	}
+	scbid = ahd_get_scbptr(ahd);
+	scb = ahd_lookup_scb(ahd, scbid);
+	if (scb != NULL
+	 && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) != 0)
+		scb = NULL;
+
+	/* Make sure the sequencer is in a safe location. */
+	ahd_clear_critical_section(ahd);
+
+	if ((status0 & IOERR) != 0) {
+		u_int now_lvd;
+
+		now_lvd = ahd_inb(ahd, SBLKCTL) & ENAB40;
+		printf("%s: Transceiver State Has Changed to %s mode\n",
+		       ahd_name(ahd), now_lvd ? "LVD" : "SE");
+		ahd_outb(ahd, CLRSINT0, CLRIOERR);
+		/*
+		 * A change in I/O mode is equivalent to a bus reset.
+		 */
+		ahd_reset_channel(ahd, 'A', /*Initiate Reset*/FALSE);
+		ahd_pause(ahd);
+		ahd_setup_iocell_workaround(ahd);
+		ahd_unpause(ahd);
+	} else if ((status0 & OVERRUN) != 0) {
+		printf("%s: SCSI offset overrun detected.  Resetting bus.\n",
+		       ahd_name(ahd));
+		ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
+	} else if ((status & SCSIRSTI) != 0) {
+		printf("%s: Someone reset channel A\n", ahd_name(ahd));
+		ahd_reset_channel(ahd, 'A', /*Initiate Reset*/FALSE);
+	} else if ((status & SCSIPERR) != 0) {
+		ahd_handle_transmission_error(ahd);
+	} else if (lqostat0 != 0) {
+		printf("%s: lqostat0 == 0x%x!\n", ahd_name(ahd), lqostat0);
+		ahd_outb(ahd, CLRLQOINT0, lqostat0);
+		if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0) {
+			ahd_outb(ahd, CLRLQOINT1, 0);
+		}
+	} else if ((status & SELTO) != 0) {
+		u_int  scbid;
+
+		/* Stop the selection */
+		ahd_outb(ahd, SCSISEQ0, 0);
+
+		/* No more pending messages */
+		ahd_clear_msg_state(ahd);
+
+		/* Clear interrupt state */
+		ahd_outb(ahd, CLRSINT1, CLRSELTIMEO|CLRBUSFREE|CLRSCSIPERR);
+
+		/*
+		 * Although the driver does not care about the
+		 * 'Selection in Progress' status bit, the busy
+		 * LED does.  SELINGO is only cleared by a sucessfull
+		 * selection, so we must manually clear it to insure
+		 * the LED turns off just incase no future successful
+		 * selections occur (e.g. no devices on the bus).
+		 */
+		ahd_outb(ahd, CLRSINT0, CLRSELINGO);
+
+		scbid = ahd_inw(ahd, WAITING_TID_HEAD);
+		scb = ahd_lookup_scb(ahd, scbid);
+		if (scb == NULL) {
+			printf("%s: ahd_intr - referenced scb not "
+			       "valid during SELTO scb(0x%x)\n",
+			       ahd_name(ahd), scbid);
+			ahd_dump_card_state(ahd);
+		} else {
+			struct ahd_devinfo devinfo;
+#ifdef AHD_DEBUG
+			if ((ahd_debug & AHD_SHOW_SELTO) != 0) {
+				ahd_print_path(ahd, scb);
+				printf("Saw Selection Timeout for SCB 0x%x\n",
+				       scbid);
+			}
+#endif
+			/*
+			 * Force a renegotiation with this target just in
+			 * case the cable was pulled and will later be
+			 * re-attached.  The target may forget its negotiation
+			 * settings with us should it attempt to reselect
+			 * during the interruption.  The target will not issue
+			 * a unit attention in this case, so we must always
+			 * renegotiate.
+			 */
+			ahd_scb_devinfo(ahd, &devinfo, scb);
+			ahd_force_renegotiation(ahd, &devinfo);
+			ahd_set_transaction_status(scb, CAM_SEL_TIMEOUT);
+			ahd_freeze_devq(ahd, scb);
+		}
+		ahd_outb(ahd, CLRINT, CLRSCSIINT);
+		ahd_iocell_first_selection(ahd);
+		ahd_unpause(ahd);
+	} else if ((status0 & (SELDI|SELDO)) != 0) {
+		ahd_iocell_first_selection(ahd);
+		ahd_unpause(ahd);
+	} else if (status3 != 0) {
+		printf("%s: SCSI Cell parity error SSTAT3 == 0x%x\n",
+		       ahd_name(ahd), status3);
+		ahd_outb(ahd, CLRSINT3, status3);
+	} else if ((lqistat1 & (LQIPHASE_LQ|LQIPHASE_NLQ)) != 0) {
+		ahd_handle_lqiphase_error(ahd, lqistat1);
+	} else if ((status & BUSFREE) != 0) {
+		u_int lqostat1;
+		int   restart;
+		int   clear_fifo;
+		int   packetized;
+		u_int mode;
+
+		/*
+		 * Clear our selection hardware as soon as possible.
+		 * We may have an entry in the waiting Q for this target,
+		 * that is affected by this busfree and we don't want to
+		 * go about selecting the target while we handle the event.
+		 */
+		ahd_outb(ahd, SCSISEQ0, 0);
+
+		/*
+		 * Determine what we were up to at the time of
+		 * the busfree.
+		 */
+		mode = AHD_MODE_SCSI;
+		busfreetime = ahd_inb(ahd, SSTAT2) & BUSFREETIME;
+		lqostat1 = ahd_inb(ahd, LQOSTAT1);
+		switch (busfreetime) {
+		case BUSFREE_DFF0:
+		case BUSFREE_DFF1:
+		{
+			u_int	scbid;
+			struct	scb *scb;
+
+			mode = busfreetime == BUSFREE_DFF0
+			     ? AHD_MODE_DFF0 : AHD_MODE_DFF1;
+			ahd_set_modes(ahd, mode, mode);
+			scbid = ahd_get_scbptr(ahd);
+			scb = ahd_lookup_scb(ahd, scbid);
+			if (scb == NULL) {
+				printf("%s: Invalid SCB in DFF%d "
+				       "during unexpected busfree\n",
+				       ahd_name(ahd), mode);
+				packetized = 0;
+			} else
+				packetized = (scb->flags & SCB_PACKETIZED) != 0;
+			clear_fifo = 1;
+			break;
+		}
+		case BUSFREE_LQO:
+			clear_fifo = 0;
+			packetized = 1;
+			break;
+		default:
+			clear_fifo = 0;
+			packetized =  (lqostat1 & LQOBUSFREE) != 0;
+			if (!packetized
+			 && ahd_inb(ahd, LASTPHASE) == P_BUSFREE)
+				packetized = 1;
+			break;
+		}
+
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_MISC) != 0)
+			printf("Saw Busfree.  Busfreetime = 0x%x.\n",
+			       busfreetime);
+#endif
+		/*
+		 * Busfrees that occur in non-packetized phases are
+		 * handled by the nonpkt_busfree handler.
+		 */
+		if (packetized && ahd_inb(ahd, LASTPHASE) == P_BUSFREE) {
+			restart = ahd_handle_pkt_busfree(ahd, busfreetime);
+		} else {
+			packetized = 0;
+			restart = ahd_handle_nonpkt_busfree(ahd);
+		}
+		/*
+		 * Clear the busfree interrupt status.  The setting of
+		 * the interrupt is a pulse, so in a perfect world, we
+		 * would not need to muck with the ENBUSFREE logic.  This
+		 * would ensure that if the bus moves on to another
+		 * connection, busfree protection is still in force.  If
+		 * BUSFREEREV is broken, however, we must manually clear
+		 * the ENBUSFREE if the busfree occurred during a non-pack
+		 * connection so that we don't get false positives during
+		 * future, packetized, connections.
+		 */
+		ahd_outb(ahd, CLRSINT1, CLRBUSFREE);
+		if (packetized == 0
+		 && (ahd->bugs & AHD_BUSFREEREV_BUG) != 0)
+			ahd_outb(ahd, SIMODE1,
+				 ahd_inb(ahd, SIMODE1) & ~ENBUSFREE);
+
+		if (clear_fifo)
+			ahd_clear_fifo(ahd, mode);
+
+		ahd_clear_msg_state(ahd);
+		ahd_outb(ahd, CLRINT, CLRSCSIINT);
+		if (restart) {
+			ahd_restart(ahd);
+		} else {
+			ahd_unpause(ahd);
+		}
+	} else {
+		printf("%s: Missing case in ahd_handle_scsiint. status = %x\n",
+		       ahd_name(ahd), status);
+		ahd_dump_card_state(ahd);
+		ahd_clear_intstat(ahd);
+		ahd_unpause(ahd);
+	}
+}
+
+static void
+ahd_handle_transmission_error(struct ahd_softc *ahd)
+{
+	struct	scb *scb;
+	u_int	scbid;
+	u_int	lqistat1;
+	u_int	lqistat2;
+	u_int	msg_out;
+	u_int	curphase;
+	u_int	lastphase;
+	u_int	perrdiag;
+	u_int	cur_col;
+	int	silent;
+
+	scb = NULL;
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+	lqistat1 = ahd_inb(ahd, LQISTAT1) & ~(LQIPHASE_LQ|LQIPHASE_NLQ);
+	lqistat2 = ahd_inb(ahd, LQISTAT2);
+	if ((lqistat1 & (LQICRCI_NLQ|LQICRCI_LQ)) == 0
+	 && (ahd->bugs & AHD_NLQICRC_DELAYED_BUG) != 0) {
+		u_int lqistate;
+
+		ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
+		lqistate = ahd_inb(ahd, LQISTATE);
+		if ((lqistate >= 0x1E && lqistate <= 0x24)
+		 || (lqistate == 0x29)) {
+#ifdef AHD_DEBUG
+			if ((ahd_debug & AHD_SHOW_RECOVERY) != 0) {
+				printf("%s: NLQCRC found via LQISTATE\n",
+				       ahd_name(ahd));
+			}
+#endif
+			lqistat1 |= LQICRCI_NLQ;
+		}
+		ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+	}
+
+	ahd_outb(ahd, CLRLQIINT1, lqistat1);
+	lastphase = ahd_inb(ahd, LASTPHASE);
+	curphase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
+	perrdiag = ahd_inb(ahd, PERRDIAG);
+	msg_out = MSG_INITIATOR_DET_ERR;
+	ahd_outb(ahd, CLRSINT1, CLRSCSIPERR);
+	
+	/*
+	 * Try to find the SCB associated with this error.
+	 */
+	silent = FALSE;
+	if (lqistat1 == 0
+	 || (lqistat1 & LQICRCI_NLQ) != 0) {
+	 	if ((lqistat1 & (LQICRCI_NLQ|LQIOVERI_NLQ)) != 0)
+			ahd_set_active_fifo(ahd);
+		scbid = ahd_get_scbptr(ahd);
+		scb = ahd_lookup_scb(ahd, scbid);
+		if (scb != NULL && SCB_IS_SILENT(scb))
+			silent = TRUE;
+	}
+
+	cur_col = 0;
+	if (silent == FALSE) {
+		printf("%s: Transmission error detected\n", ahd_name(ahd));
+		ahd_lqistat1_print(lqistat1, &cur_col, 50);
+		ahd_lastphase_print(lastphase, &cur_col, 50);
+		ahd_scsisigi_print(curphase, &cur_col, 50);
+		ahd_perrdiag_print(perrdiag, &cur_col, 50);
+		printf("\n");
+		ahd_dump_card_state(ahd);
+	}
+
+	if ((lqistat1 & (LQIOVERI_LQ|LQIOVERI_NLQ)) != 0) {
+		if (silent == FALSE) {
+			printf("%s: Gross protocol error during incoming "
+			       "packet.  lqistat1 == 0x%x.  Resetting bus.\n",
+			       ahd_name(ahd), lqistat1);
+		}
+		ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
+		return;
+	} else if ((lqistat1 & LQICRCI_LQ) != 0) {
+		/*
+		 * A CRC error has been detected on an incoming LQ.
+		 * The bus is currently hung on the last ACK.
+		 * Hit LQIRETRY to release the last ack, and
+		 * wait for the sequencer to determine that ATNO
+		 * is asserted while in message out to take us
+		 * to our host message loop.  No NONPACKREQ or
+		 * LQIPHASE type errors will occur in this
+		 * scenario.  After this first LQIRETRY, the LQI
+		 * manager will be in ISELO where it will
+		 * happily sit until another packet phase begins.
+		 * Unexpected bus free detection is enabled
+		 * through any phases that occur after we release
+		 * this last ack until the LQI manager sees a
+		 * packet phase.  This implies we may have to
+		 * ignore a perfectly valid "unexected busfree"
+		 * after our "initiator detected error" message is
+		 * sent.  A busfree is the expected response after
+		 * we tell the target that it's L_Q was corrupted.
+		 * (SPI4R09 10.7.3.3.3)
+		 */
+		ahd_outb(ahd, LQCTL2, LQIRETRY);
+		printf("LQIRetry for LQICRCI_LQ to release ACK\n");
+	} else if ((lqistat1 & LQICRCI_NLQ) != 0) {
+		/*
+		 * We detected a CRC error in a NON-LQ packet.
+		 * The hardware has varying behavior in this situation
+		 * depending on whether this packet was part of a
+		 * stream or not.
+		 *
+		 * PKT by PKT mode:
+		 * The hardware has already acked the complete packet.
+		 * If the target honors our outstanding ATN condition,
+		 * we should be (or soon will be) in MSGOUT phase.
+		 * This will trigger the LQIPHASE_LQ status bit as the
+		 * hardware was expecting another LQ.  Unexpected
+		 * busfree detection is enabled.  Once LQIPHASE_LQ is
+		 * true (first entry into host message loop is much
+		 * the same), we must clear LQIPHASE_LQ and hit
+		 * LQIRETRY so the hardware is ready to handle
+		 * a future LQ.  NONPACKREQ will not be asserted again
+		 * once we hit LQIRETRY until another packet is
+		 * processed.  The target may either go busfree
+		 * or start another packet in response to our message.
+		 *
+		 * Read Streaming P0 asserted:
+		 * If we raise ATN and the target completes the entire
+		 * stream (P0 asserted during the last packet), the
+		 * hardware will ack all data and return to the ISTART
+		 * state.  When the target reponds to our ATN condition,
+		 * LQIPHASE_LQ will be asserted.  We should respond to
+		 * this with an LQIRETRY to prepare for any future
+		 * packets.  NONPACKREQ will not be asserted again
+		 * once we hit LQIRETRY until another packet is
+		 * processed.  The target may either go busfree or
+		 * start another packet in response to our message.
+		 * Busfree detection is enabled.
+		 *
+		 * Read Streaming P0 not asserted:
+		 * If we raise ATN and the target transitions to
+		 * MSGOUT in or after a packet where P0 is not
+		 * asserted, the hardware will assert LQIPHASE_NLQ.
+		 * We should respond to the LQIPHASE_NLQ with an
+		 * LQIRETRY.  Should the target stay in a non-pkt
+		 * phase after we send our message, the hardware
+		 * will assert LQIPHASE_LQ.  Recovery is then just as
+		 * listed above for the read streaming with P0 asserted.
+		 * Busfree detection is enabled.
+		 */
+		if (silent == FALSE)
+			printf("LQICRC_NLQ\n");
+		if (scb == NULL) {
+			printf("%s: No SCB valid for LQICRC_NLQ.  "
+			       "Resetting bus\n", ahd_name(ahd));
+			ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
+			return;
+		}
+	} else if ((lqistat1 & LQIBADLQI) != 0) {
+		printf("Need to handle BADLQI!\n");
+		ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
+		return;
+	} else if ((perrdiag & (PARITYERR|PREVPHASE)) == PARITYERR) {
+		if ((curphase & ~P_DATAIN_DT) != 0) {
+			/* Ack the byte.  So we can continue. */
+			if (silent == FALSE)
+				printf("Acking %s to clear perror\n",
+				    ahd_lookup_phase_entry(curphase)->phasemsg);
+			ahd_inb(ahd, SCSIDAT);
+		}
+	
+		if (curphase == P_MESGIN)
+			msg_out = MSG_PARITY_ERROR;
+	}
+
+	/*
+	 * We've set the hardware to assert ATN if we 
+	 * get a parity error on "in" phases, so all we
+	 * need to do is stuff the message buffer with
+	 * the appropriate message.  "In" phases have set
+	 * mesg_out to something other than MSG_NOP.
+	 */
+	ahd->send_msg_perror = msg_out;
+	if (scb != NULL && msg_out == MSG_INITIATOR_DET_ERR)
+		scb->flags |= SCB_TRANSMISSION_ERROR;
+	ahd_outb(ahd, MSG_OUT, HOST_MSG);
+	ahd_outb(ahd, CLRINT, CLRSCSIINT);
+	ahd_unpause(ahd);
+}
+
+static void
+ahd_handle_lqiphase_error(struct ahd_softc *ahd, u_int lqistat1)
+{
+	/*
+	 * Clear the sources of the interrupts.
+	 */
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+	ahd_outb(ahd, CLRLQIINT1, lqistat1);
+
+	/*
+	 * If the "illegal" phase changes were in response
+	 * to our ATN to flag a CRC error, AND we ended up
+	 * on packet boundaries, clear the error, restart the
+	 * LQI manager as appropriate, and go on our merry
+	 * way toward sending the message.  Otherwise, reset
+	 * the bus to clear the error.
+	 */
+	ahd_set_active_fifo(ahd);
+	if ((ahd_inb(ahd, SCSISIGO) & ATNO) != 0
+	 && (ahd_inb(ahd, MDFFSTAT) & DLZERO) != 0) {
+		if ((lqistat1 & LQIPHASE_LQ) != 0) {
+			printf("LQIRETRY for LQIPHASE_LQ\n");
+			ahd_outb(ahd, LQCTL2, LQIRETRY);
+		} else if ((lqistat1 & LQIPHASE_NLQ) != 0) {
+			printf("LQIRETRY for LQIPHASE_NLQ\n");
+			ahd_outb(ahd, LQCTL2, LQIRETRY);
+		} else
+			panic("ahd_handle_lqiphase_error: No phase errors\n");
+		ahd_dump_card_state(ahd);
+		ahd_outb(ahd, CLRINT, CLRSCSIINT);
+		ahd_unpause(ahd);
+	} else {
+		printf("Reseting Channel for LQI Phase error\n");
+		ahd_dump_card_state(ahd);
+		ahd_reset_channel(ahd, 'A', /*Initiate Reset*/TRUE);
+	}
+}
+
+/*
+ * Packetized unexpected or expected busfree.
+ * Entered in mode based on busfreetime.
+ */
+static int
+ahd_handle_pkt_busfree(struct ahd_softc *ahd, u_int busfreetime)
+{
+	u_int lqostat1;
+
+	AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
+			 ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK));
+	lqostat1 = ahd_inb(ahd, LQOSTAT1);
+	if ((lqostat1 & LQOBUSFREE) != 0) {
+		struct scb *scb;
+		u_int scbid;
+		u_int saved_scbptr;
+		u_int waiting_h;
+		u_int waiting_t;
+		u_int next;
+
+		if ((busfreetime & BUSFREE_LQO) == 0)
+			printf("%s: Warning, BUSFREE time is 0x%x.  "
+			       "Expected BUSFREE_LQO.\n",
+			       ahd_name(ahd), busfreetime);
+		/*
+		 * The LQO manager detected an unexpected busfree
+		 * either:
+		 *
+		 * 1) During an outgoing LQ.
+		 * 2) After an outgoing LQ but before the first
+		 *    REQ of the command packet.
+		 * 3) During an outgoing command packet.
+		 *
+		 * In all cases, CURRSCB is pointing to the
+		 * SCB that encountered the failure.  Clean
+		 * up the queue, clear SELDO and LQOBUSFREE,
+		 * and allow the sequencer to restart the select
+		 * out at its lesure.
+		 */
+		ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+		scbid = ahd_inw(ahd, CURRSCB);
+		scb = ahd_lookup_scb(ahd, scbid);
+		if (scb == NULL)
+		       panic("SCB not valid during LQOBUSFREE");
+		/*
+		 * Return the LQO manager to its idle loop.  It will
+		 * not do this automatically if the busfree occurs
+		 * after the first REQ of either the LQ or command
+		 * packet or between the LQ and command packet.
+		 */
+		ahd_outb(ahd, LQCTL2, ahd_inb(ahd, LQCTL2) | LQOTOIDLE);
+
+		/*
+		 * Clear the status.
+		 */
+		ahd_outb(ahd, CLRLQOINT1, CLRLQOBUSFREE);
+		if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0)
+			ahd_outb(ahd, CLRLQOINT1, 0);
+		ahd_outb(ahd, SCSISEQ0, ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
+		ahd_outb(ahd, CLRSINT0, CLRSELDO);
+
+		/*
+		 * Update the waiting for selection queue so
+		 * we restart on the correct SCB.
+		 */
+		waiting_h = ahd_inw(ahd, WAITING_TID_HEAD);
+		saved_scbptr = ahd_get_scbptr(ahd);
+		if (waiting_h != scbid) {
+
+			ahd_outw(ahd, WAITING_TID_HEAD, scbid);
+			waiting_t = ahd_inw(ahd, WAITING_TID_TAIL);
+			next = SCB_LIST_NULL;
+			if (waiting_t == waiting_h) {
+				ahd_outw(ahd, WAITING_TID_TAIL, scbid);
+			} else {
+				ahd_set_scbptr(ahd, waiting_h);
+				next = ahd_inw(ahd, SCB_NEXT2);
+			}
+			ahd_set_scbptr(ahd, scbid);
+			ahd_outw(ahd, SCB_NEXT2, next);
+		}
+		ahd_set_scbptr(ahd, saved_scbptr);
+		if (scb->crc_retry_count < AHD_MAX_LQ_CRC_ERRORS) {
+			if (SCB_IS_SILENT(scb) == FALSE) {
+				ahd_print_path(ahd, scb);
+				printf("Probable outgoing LQ CRC error.  "
+				       "Retrying command\n");
+			}
+			scb->crc_retry_count++;
+		} else {
+			ahd_set_transaction_status(scb, CAM_UNCOR_PARITY);
+			ahd_freeze_scb(scb);
+			ahd_freeze_devq(ahd, scb);
+		}
+		/* Return unpausing the sequencer. */
+		return (0);
+	} else if ((ahd_inb(ahd, PERRDIAG) & PARITYERR) != 0) {
+		/*
+		 * Ignore what are really parity errors that
+		 * occur on the last REQ of a free running
+		 * clock prior to going busfree.  Some drives
+		 * do not properly active negate just before
+		 * going busfree resulting in a parity glitch.
+		 */
+		ahd_outb(ahd, CLRSINT1, CLRSCSIPERR|CLRBUSFREE);
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_MASKED_ERRORS) != 0)
+			printf("%s: Parity on last REQ detected "
+			       "during busfree phase.\n",
+			       ahd_name(ahd));
+#endif
+		/* Return unpausing the sequencer. */
+		return (0);
+	}
+	if (ahd->src_mode != AHD_MODE_SCSI) {
+		u_int	scbid;
+		struct	scb *scb;
+
+		scbid = ahd_get_scbptr(ahd);
+		scb = ahd_lookup_scb(ahd, scbid);
+		ahd_print_path(ahd, scb);
+		printf("Unexpected PKT busfree condition\n");
+		ahd_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb), 'A',
+			       SCB_GET_LUN(scb), SCB_GET_TAG(scb),
+			       ROLE_INITIATOR, CAM_UNEXP_BUSFREE);
+
+		/* Return restarting the sequencer. */
+		return (1);
+	}
+	printf("%s: Unexpected PKT busfree condition\n", ahd_name(ahd));
+	ahd_dump_card_state(ahd);
+	/* Restart the sequencer. */
+	return (1);
+}
+
+/*
+ * Non-packetized unexpected or expected busfree.
+ */
+static int
+ahd_handle_nonpkt_busfree(struct ahd_softc *ahd)
+{
+	struct	ahd_devinfo devinfo;
+	struct	scb *scb;
+	u_int	lastphase;
+	u_int	saved_scsiid;
+	u_int	saved_lun;
+	u_int	target;
+	u_int	initiator_role_id;
+	u_int	scbid;
+	u_int	ppr_busfree;
+	int	printerror;
+
+	/*
+	 * Look at what phase we were last in.  If its message out,
+	 * chances are pretty good that the busfree was in response
+	 * to one of our abort requests.
+	 */
+	lastphase = ahd_inb(ahd, LASTPHASE);
+	saved_scsiid = ahd_inb(ahd, SAVED_SCSIID);
+	saved_lun = ahd_inb(ahd, SAVED_LUN);
+	target = SCSIID_TARGET(ahd, saved_scsiid);
+	initiator_role_id = SCSIID_OUR_ID(saved_scsiid);
+	ahd_compile_devinfo(&devinfo, initiator_role_id,
+			    target, saved_lun, 'A', ROLE_INITIATOR);
+	printerror = 1;
+
+	scbid = ahd_get_scbptr(ahd);
+	scb = ahd_lookup_scb(ahd, scbid);
+	if (scb != NULL
+	 && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) != 0)
+		scb = NULL;
+
+	ppr_busfree = (ahd->msg_flags & MSG_FLAG_EXPECT_PPR_BUSFREE) != 0;
+	if (lastphase == P_MESGOUT) {
+		u_int tag;
+
+		tag = SCB_LIST_NULL;
+		if (ahd_sent_msg(ahd, AHDMSG_1B, MSG_ABORT_TAG, TRUE)
+		 || ahd_sent_msg(ahd, AHDMSG_1B, MSG_ABORT, TRUE)) {
+			int found;
+			int sent_msg;
+
+			if (scb == NULL) {
+				ahd_print_devinfo(ahd, &devinfo);
+				printf("Abort for unidentified "
+				       "connection completed.\n");
+				/* restart the sequencer. */
+				return (1);
+			}
+			sent_msg = ahd->msgout_buf[ahd->msgout_index - 1];
+			ahd_print_path(ahd, scb);
+			printf("SCB %d - Abort%s Completed.\n",
+			       SCB_GET_TAG(scb),
+			       sent_msg == MSG_ABORT_TAG ? "" : " Tag");
+
+			if (sent_msg == MSG_ABORT_TAG)
+				tag = SCB_GET_TAG(scb);
+
+			if ((scb->flags & SCB_CMDPHASE_ABORT) != 0) {
+				/*
+				 * This abort is in response to an
+				 * unexpected switch to command phase
+				 * for a packetized connection.  Since
+				 * the identify message was never sent,
+				 * "saved lun" is 0.  We really want to
+				 * abort only the SCB that encountered
+				 * this error, which could have a different
+				 * lun.  The SCB will be retried so the OS
+				 * will see the UA after renegotiating to
+				 * packetized.
+				 */
+				tag = SCB_GET_TAG(scb);
+				saved_lun = scb->hscb->lun;
+			}
+			found = ahd_abort_scbs(ahd, target, 'A', saved_lun,
+					       tag, ROLE_INITIATOR,
+					       CAM_REQ_ABORTED);
+			printf("found == 0x%x\n", found);
+			printerror = 0;
+		} else if (ahd_sent_msg(ahd, AHDMSG_1B,
+					MSG_BUS_DEV_RESET, TRUE)) {
+#ifdef __FreeBSD__
+			/*
+			 * Don't mark the user's request for this BDR
+			 * as completing with CAM_BDR_SENT.  CAM3
+			 * specifies CAM_REQ_CMP.
+			 */
+			if (scb != NULL
+			 && scb->io_ctx->ccb_h.func_code== XPT_RESET_DEV
+			 && ahd_match_scb(ahd, scb, target, 'A',
+					  CAM_LUN_WILDCARD, SCB_LIST_NULL,
+					  ROLE_INITIATOR))
+				ahd_set_transaction_status(scb, CAM_REQ_CMP);
+#endif
+			ahd_handle_devreset(ahd, &devinfo, CAM_BDR_SENT,
+					    "Bus Device Reset",
+					    /*verbose_level*/0);
+			printerror = 0;
+		} else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, FALSE)
+			&& ppr_busfree == 0) {
+			struct ahd_initiator_tinfo *tinfo;
+			struct ahd_tmode_tstate *tstate;
+
+			/*
+			 * PPR Rejected.  Try non-ppr negotiation
+			 * and retry command.
+			 */
+#ifdef AHD_DEBUG
+			if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
+				printf("PPR negotiation rejected busfree.\n");
+#endif
+			tinfo = ahd_fetch_transinfo(ahd, devinfo.channel,
+						    devinfo.our_scsiid,
+						    devinfo.target, &tstate);
+			tinfo->curr.transport_version = 2;
+			tinfo->goal.transport_version = 2;
+			tinfo->goal.ppr_options = 0;
+			ahd_qinfifo_requeue_tail(ahd, scb);
+			printerror = 0;
+		} else if ((ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_WDTR, FALSE)
+			 || ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_SDTR, FALSE))
+			&& ppr_busfree == 0) {
+			/*
+			 * Negotiation Rejected.  Go-async and
+			 * retry command.
+			 */
+#ifdef AHD_DEBUG
+			if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
+				printf("Negotiation rejected busfree.\n");
+#endif
+			ahd_set_width(ahd, &devinfo,
+				      MSG_EXT_WDTR_BUS_8_BIT,
+				      AHD_TRANS_CUR|AHD_TRANS_GOAL,
+				      /*paused*/TRUE);
+			ahd_set_syncrate(ahd, &devinfo,
+					/*period*/0, /*offset*/0,
+					/*ppr_options*/0,
+					AHD_TRANS_CUR|AHD_TRANS_GOAL,
+					/*paused*/TRUE);
+			ahd_qinfifo_requeue_tail(ahd, scb);
+			printerror = 0;
+		} else if ((ahd->msg_flags & MSG_FLAG_EXPECT_IDE_BUSFREE) != 0
+			&& ahd_sent_msg(ahd, AHDMSG_1B,
+					 MSG_INITIATOR_DET_ERR, TRUE)) {
+
+#ifdef AHD_DEBUG
+			if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
+				printf("Expected IDE Busfree\n");
+#endif
+			printerror = 0;
+		} else if ((ahd->msg_flags & MSG_FLAG_EXPECT_QASREJ_BUSFREE)
+			&& ahd_sent_msg(ahd, AHDMSG_1B,
+					MSG_MESSAGE_REJECT, TRUE)) {
+
+#ifdef AHD_DEBUG
+			if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
+				printf("Expected QAS Reject Busfree\n");
+#endif
+			printerror = 0;
+		}
+	}
+
+	/*
+	 * The busfree required flag is honored at the end of
+	 * the message phases.  We check it last in case we
+	 * had to send some other message that caused a busfree.
+	 */
+	if (printerror != 0
+	 && (lastphase == P_MESGIN || lastphase == P_MESGOUT)
+	 && ((ahd->msg_flags & MSG_FLAG_EXPECT_PPR_BUSFREE) != 0)) {
+
+		ahd_freeze_devq(ahd, scb);
+		ahd_set_transaction_status(scb, CAM_REQUEUE_REQ);
+		ahd_freeze_scb(scb);
+		if ((ahd->msg_flags & MSG_FLAG_IU_REQ_CHANGED) != 0) {
+			ahd_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
+				       SCB_GET_CHANNEL(ahd, scb),
+				       SCB_GET_LUN(scb), SCB_LIST_NULL,
+				       ROLE_INITIATOR, CAM_REQ_ABORTED);
+		} else {
+#ifdef AHD_DEBUG
+			if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
+				printf("PPR Negotiation Busfree.\n");
+#endif
+			ahd_done(ahd, scb);
+		}
+		printerror = 0;
+	}
+	if (printerror != 0) {
+		int aborted;
+
+		aborted = 0;
+		if (scb != NULL) {
+			u_int tag;
+
+			if ((scb->hscb->control & TAG_ENB) != 0)
+				tag = SCB_GET_TAG(scb);
+			else
+				tag = SCB_LIST_NULL;
+			ahd_print_path(ahd, scb);
+			aborted = ahd_abort_scbs(ahd, target, 'A',
+				       SCB_GET_LUN(scb), tag,
+				       ROLE_INITIATOR,
+				       CAM_UNEXP_BUSFREE);
+		} else {
+			/*
+			 * We had not fully identified this connection,
+			 * so we cannot abort anything.
+			 */
+			printf("%s: ", ahd_name(ahd));
+		}
+		if (lastphase != P_BUSFREE)
+			ahd_force_renegotiation(ahd, &devinfo);
+		printf("Unexpected busfree %s, %d SCBs aborted, "
+		       "PRGMCNT == 0x%x\n",
+		       ahd_lookup_phase_entry(lastphase)->phasemsg,
+		       aborted,
+		       ahd_inb(ahd, PRGMCNT)
+			| (ahd_inb(ahd, PRGMCNT+1) << 8));
+		ahd_dump_card_state(ahd);
+	}
+	/* Always restart the sequencer. */
+	return (1);
+}
+
+static void
+ahd_handle_proto_violation(struct ahd_softc *ahd)
+{
+	struct	ahd_devinfo devinfo;
+	struct	scb *scb;
+	u_int	scbid;
+	u_int	seq_flags;
+	u_int	curphase;
+	u_int	lastphase;
+	int	found;
+
+	ahd_fetch_devinfo(ahd, &devinfo);
+	scbid = ahd_get_scbptr(ahd);
+	scb = ahd_lookup_scb(ahd, scbid);
+	seq_flags = ahd_inb(ahd, SEQ_FLAGS);
+	curphase = ahd_inb(ahd, SCSISIGI) & PHASE_MASK;
+	lastphase = ahd_inb(ahd, LASTPHASE);
+	if ((seq_flags & NOT_IDENTIFIED) != 0) {
+
+		/*
+		 * The reconnecting target either did not send an
+		 * identify message, or did, but we didn't find an SCB
+		 * to match.
+		 */
+		ahd_print_devinfo(ahd, &devinfo);
+		printf("Target did not send an IDENTIFY message. "
+		       "LASTPHASE = 0x%x.\n", lastphase);
+		scb = NULL;
+	} else if (scb == NULL) {
+		/*
+		 * We don't seem to have an SCB active for this
+		 * transaction.  Print an error and reset the bus.
+		 */
+		ahd_print_devinfo(ahd, &devinfo);
+		printf("No SCB found during protocol violation\n");
+		goto proto_violation_reset;
+	} else {
+		ahd_set_transaction_status(scb, CAM_SEQUENCE_FAIL);
+		if ((seq_flags & NO_CDB_SENT) != 0) {
+			ahd_print_path(ahd, scb);
+			printf("No or incomplete CDB sent to device.\n");
+		} else if ((ahd_inb(ahd, SCB_CONTROL) & STATUS_RCVD) == 0) {
+			/*
+			 * The target never bothered to provide status to
+			 * us prior to completing the command.  Since we don't
+			 * know the disposition of this command, we must attempt
+			 * to abort it.  Assert ATN and prepare to send an abort
+			 * message.
+			 */
+			ahd_print_path(ahd, scb);
+			printf("Completed command without status.\n");
+		} else {
+			ahd_print_path(ahd, scb);
+			printf("Unknown protocol violation.\n");
+			ahd_dump_card_state(ahd);
+		}
+	}
+	if ((lastphase & ~P_DATAIN_DT) == 0
+	 || lastphase == P_COMMAND) {
+proto_violation_reset:
+		/*
+		 * Target either went directly to data
+		 * phase or didn't respond to our ATN.
+		 * The only safe thing to do is to blow
+		 * it away with a bus reset.
+		 */
+		found = ahd_reset_channel(ahd, 'A', TRUE);
+		printf("%s: Issued Channel %c Bus Reset. "
+		       "%d SCBs aborted\n", ahd_name(ahd), 'A', found);
+	} else {
+		/*
+		 * Leave the selection hardware off in case
+		 * this abort attempt will affect yet to
+		 * be sent commands.
+		 */
+		ahd_outb(ahd, SCSISEQ0,
+			 ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
+		ahd_assert_atn(ahd);
+		ahd_outb(ahd, MSG_OUT, HOST_MSG);
+		if (scb == NULL) {
+			ahd_print_devinfo(ahd, &devinfo);
+			ahd->msgout_buf[0] = MSG_ABORT_TASK;
+			ahd->msgout_len = 1;
+			ahd->msgout_index = 0;
+			ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
+		} else {
+			ahd_print_path(ahd, scb);
+			scb->flags |= SCB_ABORT;
+		}
+		printf("Protocol violation %s.  Attempting to abort.\n",
+		       ahd_lookup_phase_entry(curphase)->phasemsg);
+	}
+}
+
+/*
+ * Force renegotiation to occur the next time we initiate
+ * a command to the current device.
+ */
+static void
+ahd_force_renegotiation(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
+{
+	struct	ahd_initiator_tinfo *targ_info;
+	struct	ahd_tmode_tstate *tstate;
+
+#ifdef AHD_DEBUG
+	if ((ahd_debug & AHD_SHOW_MESSAGES) != 0) {
+		ahd_print_devinfo(ahd, devinfo);
+		printf("Forcing renegotiation\n");
+	}
+#endif
+	targ_info = ahd_fetch_transinfo(ahd,
+					devinfo->channel,
+					devinfo->our_scsiid,
+					devinfo->target,
+					&tstate);
+	ahd_update_neg_request(ahd, devinfo, tstate,
+			       targ_info, AHD_NEG_IF_NON_ASYNC);
+}
+
+#define AHD_MAX_STEPS 2000
+void
+ahd_clear_critical_section(struct ahd_softc *ahd)
+{
+	ahd_mode_state	saved_modes;
+	int		stepping;
+	int		steps;
+	int		first_instr;
+	u_int		simode0;
+	u_int		simode1;
+	u_int		simode3;
+	u_int		lqimode0;
+	u_int		lqimode1;
+	u_int		lqomode0;
+	u_int		lqomode1;
+
+	if (ahd->num_critical_sections == 0)
+		return;
+
+	stepping = FALSE;
+	steps = 0;
+	first_instr = 0;
+	simode0 = 0;
+	simode1 = 0;
+	simode3 = 0;
+	lqimode0 = 0;
+	lqimode1 = 0;
+	lqomode0 = 0;
+	lqomode1 = 0;
+	saved_modes = ahd_save_modes(ahd);
+	for (;;) {
+		struct	cs *cs;
+		u_int	seqaddr;
+		u_int	i;
+
+		ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+		seqaddr = ahd_inb(ahd, CURADDR)
+			| (ahd_inb(ahd, CURADDR+1) << 8);
+
+		cs = ahd->critical_sections;
+		for (i = 0; i < ahd->num_critical_sections; i++, cs++) {
+			
+			if (cs->begin < seqaddr && cs->end >= seqaddr)
+				break;
+		}
+
+		if (i == ahd->num_critical_sections)
+			break;
+
+		if (steps > AHD_MAX_STEPS) {
+			printf("%s: Infinite loop in critical section\n"
+			       "%s: First Instruction 0x%x now 0x%x\n",
+			       ahd_name(ahd), ahd_name(ahd), first_instr,
+			       seqaddr);
+			ahd_dump_card_state(ahd);
+			panic("critical section loop");
+		}
+
+		steps++;
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_MISC) != 0)
+			printf("%s: Single stepping at 0x%x\n", ahd_name(ahd),
+			       seqaddr);
+#endif
+		if (stepping == FALSE) {
+
+			first_instr = seqaddr;
+  			ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
+  			simode0 = ahd_inb(ahd, SIMODE0);
+			simode3 = ahd_inb(ahd, SIMODE3);
+			lqimode0 = ahd_inb(ahd, LQIMODE0);
+			lqimode1 = ahd_inb(ahd, LQIMODE1);
+			lqomode0 = ahd_inb(ahd, LQOMODE0);
+			lqomode1 = ahd_inb(ahd, LQOMODE1);
+			ahd_outb(ahd, SIMODE0, 0);
+			ahd_outb(ahd, SIMODE3, 0);
+			ahd_outb(ahd, LQIMODE0, 0);
+			ahd_outb(ahd, LQIMODE1, 0);
+			ahd_outb(ahd, LQOMODE0, 0);
+			ahd_outb(ahd, LQOMODE1, 0);
+			ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+  			simode1 = ahd_inb(ahd, SIMODE1);
+  			ahd_outb(ahd, SIMODE1, ENBUSFREE);
+			ahd_outb(ahd, SEQCTL0, ahd_inb(ahd, SEQCTL0) | STEP);
+			stepping = TRUE;
+		}
+		ahd_outb(ahd, CLRSINT1, CLRBUSFREE);
+		ahd_outb(ahd, CLRINT, CLRSCSIINT);
+		ahd_set_modes(ahd, ahd->saved_src_mode, ahd->saved_dst_mode);
+		ahd_outb(ahd, HCNTRL, ahd->unpause);
+		do {
+			ahd_delay(200);
+		} while (!ahd_is_paused(ahd));
+		ahd_update_modes(ahd);
+	}
+	if (stepping) {
+		ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
+		ahd_outb(ahd, SIMODE0, simode0);
+		ahd_outb(ahd, SIMODE3, simode3);
+		ahd_outb(ahd, LQIMODE0, lqimode0);
+		ahd_outb(ahd, LQIMODE1, lqimode1);
+		ahd_outb(ahd, LQOMODE0, lqomode0);
+		ahd_outb(ahd, LQOMODE1, lqomode1);
+		ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+		ahd_outb(ahd, SEQCTL0, ahd_inb(ahd, SEQCTL0) & ~STEP);
+  		ahd_outb(ahd, SIMODE1, simode1);
+	}
+	ahd_restore_modes(ahd, saved_modes);
+}
+
+/*
+ * Clear any pending interrupt status.
+ */
+void
+ahd_clear_intstat(struct ahd_softc *ahd)
+{
+	AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
+			 ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK));
+	/* Clear any interrupt conditions this may have caused */
+	ahd_outb(ahd, CLRLQIINT0, CLRLQIATNQAS|CLRLQICRCT1|CLRLQICRCT2
+				 |CLRLQIBADLQT|CLRLQIATNLQ|CLRLQIATNCMD);
+	ahd_outb(ahd, CLRLQIINT1, CLRLQIPHASE_LQ|CLRLQIPHASE_NLQ|CLRLIQABORT
+				 |CLRLQICRCI_LQ|CLRLQICRCI_NLQ|CLRLQIBADLQI
+				 |CLRLQIOVERI_LQ|CLRLQIOVERI_NLQ|CLRNONPACKREQ);
+	ahd_outb(ahd, CLRLQOINT0, CLRLQOTARGSCBPERR|CLRLQOSTOPT2|CLRLQOATNLQ
+				 |CLRLQOATNPKT|CLRLQOTCRC);
+	ahd_outb(ahd, CLRLQOINT1, CLRLQOINITSCBPERR|CLRLQOSTOPI2|CLRLQOBADQAS
+				 |CLRLQOBUSFREE|CLRLQOPHACHGINPKT);
+	if ((ahd->bugs & AHD_CLRLQO_AUTOCLR_BUG) != 0) {
+		ahd_outb(ahd, CLRLQOINT0, 0);
+		ahd_outb(ahd, CLRLQOINT1, 0);
+	}
+	ahd_outb(ahd, CLRSINT3, CLRNTRAMPERR|CLROSRAMPERR);
+	ahd_outb(ahd, CLRSINT1, CLRSELTIMEO|CLRATNO|CLRSCSIRSTI
+				|CLRBUSFREE|CLRSCSIPERR|CLRREQINIT);
+	ahd_outb(ahd, CLRSINT0, CLRSELDO|CLRSELDI|CLRSELINGO
+			        |CLRIOERR|CLROVERRUN);
+	ahd_outb(ahd, CLRINT, CLRSCSIINT);
+}
+
+/**************************** Debugging Routines ******************************/
+#ifdef AHD_DEBUG
+uint32_t ahd_debug = AHD_DEBUG_OPTS;
+#endif
+void
+ahd_print_scb(struct scb *scb)
+{
+	struct hardware_scb *hscb;
+	int i;
+
+	hscb = scb->hscb;
+	printf("scb:%p control:0x%x scsiid:0x%x lun:%d cdb_len:%d\n",
+	       (void *)scb,
+	       hscb->control,
+	       hscb->scsiid,
+	       hscb->lun,
+	       hscb->cdb_len);
+	printf("Shared Data: ");
+	for (i = 0; i < sizeof(hscb->shared_data.idata.cdb); i++)
+		printf("%#02x", hscb->shared_data.idata.cdb[i]);
+	printf("        dataptr:%#x%x datacnt:%#x sgptr:%#x tag:%#x\n",
+	       (uint32_t)((ahd_le64toh(hscb->dataptr) >> 32) & 0xFFFFFFFF),
+	       (uint32_t)(ahd_le64toh(hscb->dataptr) & 0xFFFFFFFF),
+	       ahd_le32toh(hscb->datacnt),
+	       ahd_le32toh(hscb->sgptr),
+	       SCB_GET_TAG(scb));
+	ahd_dump_sglist(scb);
+}
+
+void
+ahd_dump_sglist(struct scb *scb)
+{
+	int i;
+
+	if (scb->sg_count > 0) {
+		if ((scb->ahd_softc->flags & AHD_64BIT_ADDRESSING) != 0) {
+			struct ahd_dma64_seg *sg_list;
+
+			sg_list = (struct ahd_dma64_seg*)scb->sg_list;
+			for (i = 0; i < scb->sg_count; i++) {
+				uint64_t addr;
+				uint32_t len;
+
+				addr = ahd_le64toh(sg_list[i].addr);
+				len = ahd_le32toh(sg_list[i].len);
+				printf("sg[%d] - Addr 0x%x%x : Length %d%s\n",
+				       i,
+				       (uint32_t)((addr >> 32) & 0xFFFFFFFF),
+				       (uint32_t)(addr & 0xFFFFFFFF),
+				       sg_list[i].len & AHD_SG_LEN_MASK,
+				       (sg_list[i].len & AHD_DMA_LAST_SEG)
+				     ? " Last" : "");
+			}
+		} else {
+			struct ahd_dma_seg *sg_list;
+
+			sg_list = (struct ahd_dma_seg*)scb->sg_list;
+			for (i = 0; i < scb->sg_count; i++) {
+				uint32_t len;
+
+				len = ahd_le32toh(sg_list[i].len);
+				printf("sg[%d] - Addr 0x%x%x : Length %d%s\n",
+				       i,
+				       (len >> 24) & SG_HIGH_ADDR_BITS,
+				       ahd_le32toh(sg_list[i].addr),
+				       len & AHD_SG_LEN_MASK,
+				       len & AHD_DMA_LAST_SEG ? " Last" : "");
+			}
+		}
+	}
+}
+
+/************************* Transfer Negotiation *******************************/
+/*
+ * Allocate per target mode instance (ID we respond to as a target)
+ * transfer negotiation data structures.
+ */
+static struct ahd_tmode_tstate *
+ahd_alloc_tstate(struct ahd_softc *ahd, u_int scsi_id, char channel)
+{
+	struct ahd_tmode_tstate *master_tstate;
+	struct ahd_tmode_tstate *tstate;
+	int i;
+
+	master_tstate = ahd->enabled_targets[ahd->our_id];
+	if (ahd->enabled_targets[scsi_id] != NULL
+	 && ahd->enabled_targets[scsi_id] != master_tstate)
+		panic("%s: ahd_alloc_tstate - Target already allocated",
+		      ahd_name(ahd));
+	tstate = malloc(sizeof(*tstate), M_DEVBUF, M_NOWAIT);
+	if (tstate == NULL)
+		return (NULL);
+
+	/*
+	 * If we have allocated a master tstate, copy user settings from
+	 * the master tstate (taken from SRAM or the EEPROM) for this
+	 * channel, but reset our current and goal settings to async/narrow
+	 * until an initiator talks to us.
+	 */
+	if (master_tstate != NULL) {
+		memcpy(tstate, master_tstate, sizeof(*tstate));
+		memset(tstate->enabled_luns, 0, sizeof(tstate->enabled_luns));
+		for (i = 0; i < 16; i++) {
+			memset(&tstate->transinfo[i].curr, 0,
+			      sizeof(tstate->transinfo[i].curr));
+			memset(&tstate->transinfo[i].goal, 0,
+			      sizeof(tstate->transinfo[i].goal));
+		}
+	} else
+		memset(tstate, 0, sizeof(*tstate));
+	ahd->enabled_targets[scsi_id] = tstate;
+	return (tstate);
+}
+
+#ifdef AHD_TARGET_MODE
+/*
+ * Free per target mode instance (ID we respond to as a target)
+ * transfer negotiation data structures.
+ */
+static void
+ahd_free_tstate(struct ahd_softc *ahd, u_int scsi_id, char channel, int force)
+{
+	struct ahd_tmode_tstate *tstate;
+
+	/*
+	 * Don't clean up our "master" tstate.
+	 * It has our default user settings.
+	 */
+	if (scsi_id == ahd->our_id
+	 && force == FALSE)
+		return;
+
+	tstate = ahd->enabled_targets[scsi_id];
+	if (tstate != NULL)
+		free(tstate, M_DEVBUF);
+	ahd->enabled_targets[scsi_id] = NULL;
+}
+#endif
+
+/*
+ * Called when we have an active connection to a target on the bus,
+ * this function finds the nearest period to the input period limited
+ * by the capabilities of the bus connectivity of and sync settings for
+ * the target.
+ */
+void
+ahd_devlimited_syncrate(struct ahd_softc *ahd,
+			struct ahd_initiator_tinfo *tinfo,
+			u_int *period, u_int *ppr_options, role_t role)
+{
+	struct	ahd_transinfo *transinfo;
+	u_int	maxsync;
+
+	if ((ahd_inb(ahd, SBLKCTL) & ENAB40) != 0
+	 && (ahd_inb(ahd, SSTAT2) & EXP_ACTIVE) == 0) {
+		maxsync = AHD_SYNCRATE_PACED;
+	} else {
+		maxsync = AHD_SYNCRATE_ULTRA;
+		/* Can't do DT related options on an SE bus */
+		*ppr_options &= MSG_EXT_PPR_QAS_REQ;
+	}
+	/*
+	 * Never allow a value higher than our current goal
+	 * period otherwise we may allow a target initiated
+	 * negotiation to go above the limit as set by the
+	 * user.  In the case of an initiator initiated
+	 * sync negotiation, we limit based on the user
+	 * setting.  This allows the system to still accept
+	 * incoming negotiations even if target initiated
+	 * negotiation is not performed.
+	 */
+	if (role == ROLE_TARGET)
+		transinfo = &tinfo->user;
+	else 
+		transinfo = &tinfo->goal;
+	*ppr_options &= (transinfo->ppr_options|MSG_EXT_PPR_PCOMP_EN);
+	if (transinfo->width == MSG_EXT_WDTR_BUS_8_BIT) {
+		maxsync = MAX(maxsync, AHD_SYNCRATE_ULTRA2);
+		*ppr_options &= ~MSG_EXT_PPR_DT_REQ;
+	}
+	if (transinfo->period == 0) {
+		*period = 0;
+		*ppr_options = 0;
+	} else {
+		*period = MAX(*period, transinfo->period);
+		ahd_find_syncrate(ahd, period, ppr_options, maxsync);
+	}
+}
+
+/*
+ * Look up the valid period to SCSIRATE conversion in our table.
+ * Return the period and offset that should be sent to the target
+ * if this was the beginning of an SDTR.
+ */
+void
+ahd_find_syncrate(struct ahd_softc *ahd, u_int *period,
+		  u_int *ppr_options, u_int maxsync)
+{
+	if (*period < maxsync)
+		*period = maxsync;
+
+	if ((*ppr_options & MSG_EXT_PPR_DT_REQ) != 0
+	 && *period > AHD_SYNCRATE_MIN_DT)
+		*ppr_options &= ~MSG_EXT_PPR_DT_REQ;
+		
+	if (*period > AHD_SYNCRATE_MIN)
+		*period = 0;
+
+	/* Honor PPR option conformance rules. */
+	if (*period > AHD_SYNCRATE_PACED)
+		*ppr_options &= ~MSG_EXT_PPR_RTI;
+
+	if ((*ppr_options & MSG_EXT_PPR_IU_REQ) == 0)
+		*ppr_options &= (MSG_EXT_PPR_DT_REQ|MSG_EXT_PPR_QAS_REQ);
+
+	if ((*ppr_options & MSG_EXT_PPR_DT_REQ) == 0)
+		*ppr_options &= MSG_EXT_PPR_QAS_REQ;
+
+	/* Skip all PACED only entries if IU is not available */
+	if ((*ppr_options & MSG_EXT_PPR_IU_REQ) == 0
+	 && maxsync < AHD_SYNCRATE_DT)
+		maxsync = AHD_SYNCRATE_DT;
+
+	/* Skip all DT only entries if DT is not available */
+	if ((*ppr_options & MSG_EXT_PPR_DT_REQ) == 0
+	 && maxsync < AHD_SYNCRATE_ULTRA2)
+		maxsync = AHD_SYNCRATE_ULTRA2;
+}
+
+/*
+ * Truncate the given synchronous offset to a value the
+ * current adapter type and syncrate are capable of.
+ */
+void
+ahd_validate_offset(struct ahd_softc *ahd,
+		    struct ahd_initiator_tinfo *tinfo,
+		    u_int period, u_int *offset, int wide,
+		    role_t role)
+{
+	u_int maxoffset;
+
+	/* Limit offset to what we can do */
+	if (period == 0)
+		maxoffset = 0;
+	else if (period <= AHD_SYNCRATE_PACED) {
+		if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0)
+			maxoffset = MAX_OFFSET_PACED_BUG;
+		else
+			maxoffset = MAX_OFFSET_PACED;
+	} else
+		maxoffset = MAX_OFFSET_NON_PACED;
+	*offset = MIN(*offset, maxoffset);
+	if (tinfo != NULL) {
+		if (role == ROLE_TARGET)
+			*offset = MIN(*offset, tinfo->user.offset);
+		else
+			*offset = MIN(*offset, tinfo->goal.offset);
+	}
+}
+
+/*
+ * Truncate the given transfer width parameter to a value the
+ * current adapter type is capable of.
+ */
+void
+ahd_validate_width(struct ahd_softc *ahd, struct ahd_initiator_tinfo *tinfo,
+		   u_int *bus_width, role_t role)
+{
+	switch (*bus_width) {
+	default:
+		if (ahd->features & AHD_WIDE) {
+			/* Respond Wide */
+			*bus_width = MSG_EXT_WDTR_BUS_16_BIT;
+			break;
+		}
+		/* FALLTHROUGH */
+	case MSG_EXT_WDTR_BUS_8_BIT:
+		*bus_width = MSG_EXT_WDTR_BUS_8_BIT;
+		break;
+	}
+	if (tinfo != NULL) {
+		if (role == ROLE_TARGET)
+			*bus_width = MIN(tinfo->user.width, *bus_width);
+		else
+			*bus_width = MIN(tinfo->goal.width, *bus_width);
+	}
+}
+
+/*
+ * Update the bitmask of targets for which the controller should
+ * negotiate with at the next convenient oportunity.  This currently
+ * means the next time we send the initial identify messages for
+ * a new transaction.
+ */
+int
+ahd_update_neg_request(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
+		       struct ahd_tmode_tstate *tstate,
+		       struct ahd_initiator_tinfo *tinfo, ahd_neg_type neg_type)
+{
+	u_int auto_negotiate_orig;
+
+	auto_negotiate_orig = tstate->auto_negotiate;
+	if (neg_type == AHD_NEG_ALWAYS) {
+		/*
+		 * Force our "current" settings to be
+		 * unknown so that unless a bus reset
+		 * occurs the need to renegotiate is
+		 * recorded persistently.
+		 */
+		tinfo->curr.period = AHD_PERIOD_UNKNOWN;
+		tinfo->curr.width = AHD_WIDTH_UNKNOWN;
+		tinfo->curr.offset = AHD_OFFSET_UNKNOWN;
+	}
+	if (tinfo->curr.period != tinfo->goal.period
+	 || tinfo->curr.width != tinfo->goal.width
+	 || tinfo->curr.offset != tinfo->goal.offset
+	 || tinfo->curr.ppr_options != tinfo->goal.ppr_options
+	 || (neg_type == AHD_NEG_IF_NON_ASYNC
+	  && (tinfo->goal.offset != 0
+	   || tinfo->goal.width != MSG_EXT_WDTR_BUS_8_BIT
+	   || tinfo->goal.ppr_options != 0)))
+		tstate->auto_negotiate |= devinfo->target_mask;
+	else
+		tstate->auto_negotiate &= ~devinfo->target_mask;
+
+	return (auto_negotiate_orig != tstate->auto_negotiate);
+}
+
+/*
+ * Update the user/goal/curr tables of synchronous negotiation
+ * parameters as well as, in the case of a current or active update,
+ * any data structures on the host controller.  In the case of an
+ * active update, the specified target is currently talking to us on
+ * the bus, so the transfer parameter update must take effect
+ * immediately.
+ */
+void
+ahd_set_syncrate(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
+		 u_int period, u_int offset, u_int ppr_options,
+		 u_int type, int paused)
+{
+	struct	ahd_initiator_tinfo *tinfo;
+	struct	ahd_tmode_tstate *tstate;
+	u_int	old_period;
+	u_int	old_offset;
+	u_int	old_ppr;
+	int	active;
+	int	update_needed;
+
+	active = (type & AHD_TRANS_ACTIVE) == AHD_TRANS_ACTIVE;
+	update_needed = 0;
+
+	if (period == 0 || offset == 0) {
+		period = 0;
+		offset = 0;
+	}
+
+	tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
+				    devinfo->target, &tstate);
+
+	if ((type & AHD_TRANS_USER) != 0) {
+		tinfo->user.period = period;
+		tinfo->user.offset = offset;
+		tinfo->user.ppr_options = ppr_options;
+	}
+
+	if ((type & AHD_TRANS_GOAL) != 0) {
+		tinfo->goal.period = period;
+		tinfo->goal.offset = offset;
+		tinfo->goal.ppr_options = ppr_options;
+	}
+
+	old_period = tinfo->curr.period;
+	old_offset = tinfo->curr.offset;
+	old_ppr	   = tinfo->curr.ppr_options;
+
+	if ((type & AHD_TRANS_CUR) != 0
+	 && (old_period != period
+	  || old_offset != offset
+	  || old_ppr != ppr_options)) {
+
+		update_needed++;
+
+		tinfo->curr.period = period;
+		tinfo->curr.offset = offset;
+		tinfo->curr.ppr_options = ppr_options;
+
+		ahd_send_async(ahd, devinfo->channel, devinfo->target,
+			       CAM_LUN_WILDCARD, AC_TRANSFER_NEG, NULL);
+		if (bootverbose) {
+			if (offset != 0) {
+				int options;
+
+				printf("%s: target %d synchronous with "
+				       "period = 0x%x, offset = 0x%x",
+				       ahd_name(ahd), devinfo->target,
+				       period, offset);
+				options = 0;
+				if ((ppr_options & MSG_EXT_PPR_DT_REQ) != 0) {
+					printf("(DT");
+					options++;
+				}
+				if ((ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
+					printf("%s", options ? "|IU" : "(IU");
+					options++;
+				}
+				if ((ppr_options & MSG_EXT_PPR_RTI) != 0) {
+					printf("%s", options ? "|RTI" : "(RTI");
+					options++;
+				}
+				if ((ppr_options & MSG_EXT_PPR_QAS_REQ) != 0) {
+					printf("%s", options ? "|QAS" : "(QAS");
+					options++;
+				}
+				if (options != 0)
+					printf(")\n");
+				else
+					printf("\n");
+			} else {
+				printf("%s: target %d using "
+				       "asynchronous transfers%s\n",
+				       ahd_name(ahd), devinfo->target,
+				       (ppr_options & MSG_EXT_PPR_QAS_REQ) != 0
+				     ?  "(QAS)" : "");
+			}
+		}
+	}
+	/*
+	 * Always refresh the neg-table to handle the case of the
+	 * sequencer setting the ENATNO bit for a MK_MESSAGE request.
+	 * We will always renegotiate in that case if this is a
+	 * packetized request.  Also manage the busfree expected flag
+	 * from this common routine so that we catch changes due to
+	 * WDTR or SDTR messages.
+	 */
+	if ((type & AHD_TRANS_CUR) != 0) {
+		if (!paused)
+			ahd_pause(ahd);
+		ahd_update_neg_table(ahd, devinfo, &tinfo->curr);
+		if (!paused)
+			ahd_unpause(ahd);
+		if (ahd->msg_type != MSG_TYPE_NONE) {
+			if ((old_ppr & MSG_EXT_PPR_IU_REQ)
+			 != (ppr_options & MSG_EXT_PPR_IU_REQ)) {
+#ifdef AHD_DEBUG
+				if ((ahd_debug & AHD_SHOW_MESSAGES) != 0) {
+					ahd_print_devinfo(ahd, devinfo);
+					printf("Expecting IU Change busfree\n");
+				}
+#endif
+				ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE
+					       |  MSG_FLAG_IU_REQ_CHANGED;
+			}
+			if ((old_ppr & MSG_EXT_PPR_IU_REQ) != 0) {
+#ifdef AHD_DEBUG
+				if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
+					printf("PPR with IU_REQ outstanding\n");
+#endif
+				ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE;
+			}
+		}
+	}
+
+	update_needed += ahd_update_neg_request(ahd, devinfo, tstate,
+						tinfo, AHD_NEG_TO_GOAL);
+
+	if (update_needed && active)
+		ahd_update_pending_scbs(ahd);
+}
+
+/*
+ * Update the user/goal/curr tables of wide negotiation
+ * parameters as well as, in the case of a current or active update,
+ * any data structures on the host controller.  In the case of an
+ * active update, the specified target is currently talking to us on
+ * the bus, so the transfer parameter update must take effect
+ * immediately.
+ */
+void
+ahd_set_width(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
+	      u_int width, u_int type, int paused)
+{
+	struct	ahd_initiator_tinfo *tinfo;
+	struct	ahd_tmode_tstate *tstate;
+	u_int	oldwidth;
+	int	active;
+	int	update_needed;
+
+	active = (type & AHD_TRANS_ACTIVE) == AHD_TRANS_ACTIVE;
+	update_needed = 0;
+	tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
+				    devinfo->target, &tstate);
+
+	if ((type & AHD_TRANS_USER) != 0)
+		tinfo->user.width = width;
+
+	if ((type & AHD_TRANS_GOAL) != 0)
+		tinfo->goal.width = width;
+
+	oldwidth = tinfo->curr.width;
+	if ((type & AHD_TRANS_CUR) != 0 && oldwidth != width) {
+
+		update_needed++;
+
+		tinfo->curr.width = width;
+		ahd_send_async(ahd, devinfo->channel, devinfo->target,
+			       CAM_LUN_WILDCARD, AC_TRANSFER_NEG, NULL);
+		if (bootverbose) {
+			printf("%s: target %d using %dbit transfers\n",
+			       ahd_name(ahd), devinfo->target,
+			       8 * (0x01 << width));
+		}
+	}
+
+	if ((type & AHD_TRANS_CUR) != 0) {
+		if (!paused)
+			ahd_pause(ahd);
+		ahd_update_neg_table(ahd, devinfo, &tinfo->curr);
+		if (!paused)
+			ahd_unpause(ahd);
+	}
+
+	update_needed += ahd_update_neg_request(ahd, devinfo, tstate,
+						tinfo, AHD_NEG_TO_GOAL);
+	if (update_needed && active)
+		ahd_update_pending_scbs(ahd);
+
+}
+
+/*
+ * Update the current state of tagged queuing for a given target.
+ */
+void
+ahd_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
+	     ahd_queue_alg alg)
+{
+	ahd_platform_set_tags(ahd, devinfo, alg);
+	ahd_send_async(ahd, devinfo->channel, devinfo->target,
+		       devinfo->lun, AC_TRANSFER_NEG, &alg);
+}
+
+static void
+ahd_update_neg_table(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
+		     struct ahd_transinfo *tinfo)
+{
+	ahd_mode_state	saved_modes;
+	u_int		period;
+	u_int		ppr_opts;
+	u_int		con_opts;
+	u_int		offset;
+	u_int		saved_negoaddr;
+	uint8_t		iocell_opts[sizeof(ahd->iocell_opts)];
+
+	saved_modes = ahd_save_modes(ahd);
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+
+	saved_negoaddr = ahd_inb(ahd, NEGOADDR);
+	ahd_outb(ahd, NEGOADDR, devinfo->target);
+	period = tinfo->period;
+	offset = tinfo->offset;
+	memcpy(iocell_opts, ahd->iocell_opts, sizeof(ahd->iocell_opts)); 
+	ppr_opts = tinfo->ppr_options & (MSG_EXT_PPR_QAS_REQ|MSG_EXT_PPR_DT_REQ
+					|MSG_EXT_PPR_IU_REQ|MSG_EXT_PPR_RTI);
+	con_opts = 0;
+	if (period == 0)
+		period = AHD_SYNCRATE_ASYNC;
+	if (period == AHD_SYNCRATE_160) {
+
+		if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0) {
+			/*
+			 * When the SPI4 spec was finalized, PACE transfers
+			 * was not made a configurable option in the PPR
+			 * message.  Instead it is assumed to be enabled for
+			 * any syncrate faster than 80MHz.  Nevertheless,
+			 * Harpoon2A4 allows this to be configurable.
+			 *
+			 * Harpoon2A4 also assumes at most 2 data bytes per
+			 * negotiated REQ/ACK offset.  Paced transfers take
+			 * 4, so we must adjust our offset.
+			 */
+			ppr_opts |= PPROPT_PACE;
+			offset *= 2;
+
+			/*
+			 * Harpoon2A assumed that there would be a
+			 * fallback rate between 160MHz and 80Mhz,
+			 * so 7 is used as the period factor rather
+			 * than 8 for 160MHz.
+			 */
+			period = AHD_SYNCRATE_REVA_160;
+		}
+		if ((tinfo->ppr_options & MSG_EXT_PPR_PCOMP_EN) == 0)
+			iocell_opts[AHD_PRECOMP_SLEW_INDEX] &=
+			    ~AHD_PRECOMP_MASK;
+	} else {
+		/*
+		 * Precomp should be disabled for non-paced transfers.
+		 */
+		iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_PRECOMP_MASK;
+
+		if ((ahd->features & AHD_NEW_IOCELL_OPTS) != 0
+		 && (ppr_opts & MSG_EXT_PPR_DT_REQ) != 0) {
+			/*
+			 * Slow down our CRC interval to be
+			 * compatible with devices that can't
+			 * handle a CRC at full speed.
+			 */
+			con_opts |= ENSLOWCRC;
+		}
+	}
+
+	ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_PRECOMP_SLEW);
+	ahd_outb(ahd, ANNEXDAT, iocell_opts[AHD_PRECOMP_SLEW_INDEX]);
+	ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_AMPLITUDE);
+	ahd_outb(ahd, ANNEXDAT, iocell_opts[AHD_AMPLITUDE_INDEX]);
+
+	ahd_outb(ahd, NEGPERIOD, period);
+	ahd_outb(ahd, NEGPPROPTS, ppr_opts);
+	ahd_outb(ahd, NEGOFFSET, offset);
+
+	if (tinfo->width == MSG_EXT_WDTR_BUS_16_BIT)
+		con_opts |= WIDEXFER;
+
+	/*
+	 * During packetized transfers, the target will
+	 * give us the oportunity to send command packets
+	 * without us asserting attention.
+	 */
+	if ((tinfo->ppr_options & MSG_EXT_PPR_IU_REQ) == 0)
+		con_opts |= ENAUTOATNO;
+	ahd_outb(ahd, NEGCONOPTS, con_opts);
+	ahd_outb(ahd, NEGOADDR, saved_negoaddr);
+	ahd_restore_modes(ahd, saved_modes);
+}
+
+/*
+ * When the transfer settings for a connection change, setup for
+ * negotiation in pending SCBs to effect the change as quickly as
+ * possible.  We also cancel any negotiations that are scheduled
+ * for inflight SCBs that have not been started yet.
+ */
+static void
+ahd_update_pending_scbs(struct ahd_softc *ahd)
+{
+	struct		scb *pending_scb;
+	int		pending_scb_count;
+	int		i;
+	int		paused;
+	u_int		saved_scbptr;
+	ahd_mode_state	saved_modes;
+
+	/*
+	 * Traverse the pending SCB list and ensure that all of the
+	 * SCBs there have the proper settings.  We can only safely
+	 * clear the negotiation required flag (setting requires the
+	 * execution queue to be modified) and this is only possible
+	 * if we are not already attempting to select out for this
+	 * SCB.  For this reason, all callers only call this routine
+	 * if we are changing the negotiation settings for the currently
+	 * active transaction on the bus.
+	 */
+	pending_scb_count = 0;
+	LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
+		struct ahd_devinfo devinfo;
+		struct hardware_scb *pending_hscb;
+		struct ahd_initiator_tinfo *tinfo;
+		struct ahd_tmode_tstate *tstate;
+
+		ahd_scb_devinfo(ahd, &devinfo, pending_scb);
+		tinfo = ahd_fetch_transinfo(ahd, devinfo.channel,
+					    devinfo.our_scsiid,
+					    devinfo.target, &tstate);
+		pending_hscb = pending_scb->hscb;
+		if ((tstate->auto_negotiate & devinfo.target_mask) == 0
+		 && (pending_scb->flags & SCB_AUTO_NEGOTIATE) != 0) {
+			pending_scb->flags &= ~SCB_AUTO_NEGOTIATE;
+			pending_hscb->control &= ~MK_MESSAGE;
+		}
+		ahd_sync_scb(ahd, pending_scb,
+			     BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
+		pending_scb_count++;
+	}
+
+	if (pending_scb_count == 0)
+		return;
+
+	if (ahd_is_paused(ahd)) {
+		paused = 1;
+	} else {
+		paused = 0;
+		ahd_pause(ahd);
+	}
+
+	/*
+	 * Force the sequencer to reinitialize the selection for
+	 * the command at the head of the execution queue if it
+	 * has already been setup.  The negotiation changes may
+	 * effect whether we select-out with ATN.
+	 */
+	saved_modes = ahd_save_modes(ahd);
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+	ahd_outb(ahd, SCSISEQ0, ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
+	saved_scbptr = ahd_get_scbptr(ahd);
+	/* Ensure that the hscbs down on the card match the new information */
+	for (i = 0; i < ahd->scb_data.maxhscbs; i++) {
+		struct	hardware_scb *pending_hscb;
+		u_int	control;
+		u_int	scb_tag;
+
+		ahd_set_scbptr(ahd, i);
+		scb_tag = i;
+		pending_scb = ahd_lookup_scb(ahd, scb_tag);
+		if (pending_scb == NULL)
+			continue;
+
+		pending_hscb = pending_scb->hscb;
+		control = ahd_inb_scbram(ahd, SCB_CONTROL);
+		control &= ~MK_MESSAGE;
+		control |= pending_hscb->control & MK_MESSAGE;
+		ahd_outb(ahd, SCB_CONTROL, control);
+	}
+	ahd_set_scbptr(ahd, saved_scbptr);
+	ahd_restore_modes(ahd, saved_modes);
+
+	if (paused == 0)
+		ahd_unpause(ahd);
+}
+
+/**************************** Pathing Information *****************************/
+static void
+ahd_fetch_devinfo(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
+{
+	ahd_mode_state	saved_modes;
+	u_int		saved_scsiid;
+	role_t		role;
+	int		our_id;
+
+	saved_modes = ahd_save_modes(ahd);
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+
+	if (ahd_inb(ahd, SSTAT0) & TARGET)
+		role = ROLE_TARGET;
+	else
+		role = ROLE_INITIATOR;
+
+	if (role == ROLE_TARGET
+	 && (ahd_inb(ahd, SEQ_FLAGS) & CMDPHASE_PENDING) != 0) {
+		/* We were selected, so pull our id from TARGIDIN */
+		our_id = ahd_inb(ahd, TARGIDIN) & OID;
+	} else if (role == ROLE_TARGET)
+		our_id = ahd_inb(ahd, TOWNID);
+	else
+		our_id = ahd_inb(ahd, IOWNID);
+
+	saved_scsiid = ahd_inb(ahd, SAVED_SCSIID);
+	ahd_compile_devinfo(devinfo,
+			    our_id,
+			    SCSIID_TARGET(ahd, saved_scsiid),
+			    ahd_inb(ahd, SAVED_LUN),
+			    SCSIID_CHANNEL(ahd, saved_scsiid),
+			    role);
+	ahd_restore_modes(ahd, saved_modes);
+}
+
+void
+ahd_print_devinfo(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
+{
+	printf("%s:%c:%d:%d: ", ahd_name(ahd), 'A',
+	       devinfo->target, devinfo->lun);
+}
+
+struct ahd_phase_table_entry*
+ahd_lookup_phase_entry(int phase)
+{
+	struct ahd_phase_table_entry *entry;
+	struct ahd_phase_table_entry *last_entry;
+
+	/*
+	 * num_phases doesn't include the default entry which
+	 * will be returned if the phase doesn't match.
+	 */
+	last_entry = &ahd_phase_table[num_phases];
+	for (entry = ahd_phase_table; entry < last_entry; entry++) {
+		if (phase == entry->phase)
+			break;
+	}
+	return (entry);
+}
+
+void
+ahd_compile_devinfo(struct ahd_devinfo *devinfo, u_int our_id, u_int target,
+		    u_int lun, char channel, role_t role)
+{
+	devinfo->our_scsiid = our_id;
+	devinfo->target = target;
+	devinfo->lun = lun;
+	devinfo->target_offset = target;
+	devinfo->channel = channel;
+	devinfo->role = role;
+	if (channel == 'B')
+		devinfo->target_offset += 8;
+	devinfo->target_mask = (0x01 << devinfo->target_offset);
+}
+
+static void
+ahd_scb_devinfo(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
+		struct scb *scb)
+{
+	role_t	role;
+	int	our_id;
+
+	our_id = SCSIID_OUR_ID(scb->hscb->scsiid);
+	role = ROLE_INITIATOR;
+	if ((scb->hscb->control & TARGET_SCB) != 0)
+		role = ROLE_TARGET;
+	ahd_compile_devinfo(devinfo, our_id, SCB_GET_TARGET(ahd, scb),
+			    SCB_GET_LUN(scb), SCB_GET_CHANNEL(ahd, scb), role);
+}
+
+
+/************************ Message Phase Processing ****************************/
+/*
+ * When an initiator transaction with the MK_MESSAGE flag either reconnects
+ * or enters the initial message out phase, we are interrupted.  Fill our
+ * outgoing message buffer with the appropriate message and beging handing
+ * the message phase(s) manually.
+ */
+static void
+ahd_setup_initiator_msgout(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
+			   struct scb *scb)
+{
+	/*
+	 * To facilitate adding multiple messages together,
+	 * each routine should increment the index and len
+	 * variables instead of setting them explicitly.
+	 */
+	ahd->msgout_index = 0;
+	ahd->msgout_len = 0;
+
+	if (ahd_currently_packetized(ahd))
+		ahd->msg_flags |= MSG_FLAG_PACKETIZED;
+
+	if (ahd->send_msg_perror
+	 && ahd_inb(ahd, MSG_OUT) == HOST_MSG) {
+		ahd->msgout_buf[ahd->msgout_index++] = ahd->send_msg_perror;
+		ahd->msgout_len++;
+		ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
+			printf("Setting up for Parity Error delivery\n");
+#endif
+		return;
+	} else if (scb == NULL) {
+		printf("%s: WARNING. No pending message for "
+		       "I_T msgin.  Issuing NO-OP\n", ahd_name(ahd));
+		ahd->msgout_buf[ahd->msgout_index++] = MSG_NOOP;
+		ahd->msgout_len++;
+		ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
+		return;
+	}
+
+	if ((scb->flags & SCB_DEVICE_RESET) == 0
+	 && (scb->flags & SCB_PACKETIZED) == 0
+	 && ahd_inb(ahd, MSG_OUT) == MSG_IDENTIFYFLAG) {
+		u_int identify_msg;
+
+		identify_msg = MSG_IDENTIFYFLAG | SCB_GET_LUN(scb);
+		if ((scb->hscb->control & DISCENB) != 0)
+			identify_msg |= MSG_IDENTIFY_DISCFLAG;
+		ahd->msgout_buf[ahd->msgout_index++] = identify_msg;
+		ahd->msgout_len++;
+
+		if ((scb->hscb->control & TAG_ENB) != 0) {
+			ahd->msgout_buf[ahd->msgout_index++] =
+			    scb->hscb->control & (TAG_ENB|SCB_TAG_TYPE);
+			ahd->msgout_buf[ahd->msgout_index++] = SCB_GET_TAG(scb);
+			ahd->msgout_len += 2;
+		}
+	}
+
+	if (scb->flags & SCB_DEVICE_RESET) {
+		ahd->msgout_buf[ahd->msgout_index++] = MSG_BUS_DEV_RESET;
+		ahd->msgout_len++;
+		ahd_print_path(ahd, scb);
+		printf("Bus Device Reset Message Sent\n");
+		/*
+		 * Clear our selection hardware in advance of
+		 * the busfree.  We may have an entry in the waiting
+		 * Q for this target, and we don't want to go about
+		 * selecting while we handle the busfree and blow it
+		 * away.
+		 */
+		ahd_outb(ahd, SCSISEQ0, 0);
+	} else if ((scb->flags & SCB_ABORT) != 0) {
+
+		if ((scb->hscb->control & TAG_ENB) != 0) {
+			ahd->msgout_buf[ahd->msgout_index++] = MSG_ABORT_TAG;
+		} else {
+			ahd->msgout_buf[ahd->msgout_index++] = MSG_ABORT;
+		}
+		ahd->msgout_len++;
+		ahd_print_path(ahd, scb);
+		printf("Abort%s Message Sent\n",
+		       (scb->hscb->control & TAG_ENB) != 0 ? " Tag" : "");
+		/*
+		 * Clear our selection hardware in advance of
+		 * the busfree.  We may have an entry in the waiting
+		 * Q for this target, and we don't want to go about
+		 * selecting while we handle the busfree and blow it
+		 * away.
+		 */
+		ahd_outb(ahd, SCSISEQ0, 0);
+	} else if ((scb->flags & (SCB_AUTO_NEGOTIATE|SCB_NEGOTIATE)) != 0) {
+		ahd_build_transfer_msg(ahd, devinfo);
+		/*
+		 * Clear our selection hardware in advance of potential
+		 * PPR IU status change busfree.  We may have an entry in
+		 * the waiting Q for this target, and we don't want to go
+		 * about selecting while we handle the busfree and blow
+		 * it away.
+		 */
+		ahd_outb(ahd, SCSISEQ0, 0);
+	} else {
+		printf("ahd_intr: AWAITING_MSG for an SCB that "
+		       "does not have a waiting message\n");
+		printf("SCSIID = %x, target_mask = %x\n", scb->hscb->scsiid,
+		       devinfo->target_mask);
+		panic("SCB = %d, SCB Control = %x:%x, MSG_OUT = %x "
+		      "SCB flags = %x", SCB_GET_TAG(scb), scb->hscb->control,
+		      ahd_inb(ahd, SCB_CONTROL), ahd_inb(ahd, MSG_OUT),
+		      scb->flags);
+	}
+
+	/*
+	 * Clear the MK_MESSAGE flag from the SCB so we aren't
+	 * asked to send this message again.
+	 */
+	ahd_outb(ahd, SCB_CONTROL,
+		 ahd_inb_scbram(ahd, SCB_CONTROL) & ~MK_MESSAGE);
+	scb->hscb->control &= ~MK_MESSAGE;
+	ahd->msgout_index = 0;
+	ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
+}
+
+/*
+ * Build an appropriate transfer negotiation message for the
+ * currently active target.
+ */
+static void
+ahd_build_transfer_msg(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
+{
+	/*
+	 * We need to initiate transfer negotiations.
+	 * If our current and goal settings are identical,
+	 * we want to renegotiate due to a check condition.
+	 */
+	struct	ahd_initiator_tinfo *tinfo;
+	struct	ahd_tmode_tstate *tstate;
+	int	dowide;
+	int	dosync;
+	int	doppr;
+	u_int	period;
+	u_int	ppr_options;
+	u_int	offset;
+
+	tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
+				    devinfo->target, &tstate);
+	/*
+	 * Filter our period based on the current connection.
+	 * If we can't perform DT transfers on this segment (not in LVD
+	 * mode for instance), then our decision to issue a PPR message
+	 * may change.
+	 */
+	period = tinfo->goal.period;
+	ppr_options = tinfo->goal.ppr_options;
+	/* Target initiated PPR is not allowed in the SCSI spec */
+	if (devinfo->role == ROLE_TARGET)
+		ppr_options = 0;
+	ahd_devlimited_syncrate(ahd, tinfo, &period,
+				&ppr_options, devinfo->role);
+	dowide = tinfo->curr.width != tinfo->goal.width;
+	dosync = tinfo->curr.period != period;
+	/*
+	 * Only use PPR if we have options that need it, even if the device
+	 * claims to support it.  There might be an expander in the way
+	 * that doesn't.
+	 */
+	doppr = ppr_options != 0;
+
+	if (!dowide && !dosync && !doppr) {
+		dowide = tinfo->goal.width != MSG_EXT_WDTR_BUS_8_BIT;
+		dosync = tinfo->goal.period != 0;
+	}
+
+	if (!dowide && !dosync && !doppr) {
+		/*
+		 * Force async with a WDTR message if we have a wide bus,
+		 * or just issue an SDTR with a 0 offset.
+		 */
+		if ((ahd->features & AHD_WIDE) != 0)
+			dowide = 1;
+		else
+			dosync = 1;
+
+		if (bootverbose) {
+			ahd_print_devinfo(ahd, devinfo);
+			printf("Ensuring async\n");
+		}
+	}
+	/* Target initiated PPR is not allowed in the SCSI spec */
+	if (devinfo->role == ROLE_TARGET)
+		doppr = 0;
+
+	/*
+	 * Both the PPR message and SDTR message require the
+	 * goal syncrate to be limited to what the target device
+	 * is capable of handling (based on whether an LVD->SE
+	 * expander is on the bus), so combine these two cases.
+	 * Regardless, guarantee that if we are using WDTR and SDTR
+	 * messages that WDTR comes first.
+	 */
+	if (doppr || (dosync && !dowide)) {
+
+		offset = tinfo->goal.offset;
+		ahd_validate_offset(ahd, tinfo, period, &offset,
+				    doppr ? tinfo->goal.width
+					  : tinfo->curr.width,
+				    devinfo->role);
+		if (doppr) {
+			ahd_construct_ppr(ahd, devinfo, period, offset,
+					  tinfo->goal.width, ppr_options);
+		} else {
+			ahd_construct_sdtr(ahd, devinfo, period, offset);
+		}
+	} else {
+		ahd_construct_wdtr(ahd, devinfo, tinfo->goal.width);
+	}
+}
+
+/*
+ * Build a synchronous negotiation message in our message
+ * buffer based on the input parameters.
+ */
+static void
+ahd_construct_sdtr(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
+		   u_int period, u_int offset)
+{
+	if (offset == 0)
+		period = AHD_ASYNC_XFER_PERIOD;
+	ahd->msgout_buf[ahd->msgout_index++] = MSG_EXTENDED;
+	ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_SDTR_LEN;
+	ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_SDTR;
+	ahd->msgout_buf[ahd->msgout_index++] = period;
+	ahd->msgout_buf[ahd->msgout_index++] = offset;
+	ahd->msgout_len += 5;
+	if (bootverbose) {
+		printf("(%s:%c:%d:%d): Sending SDTR period %x, offset %x\n",
+		       ahd_name(ahd), devinfo->channel, devinfo->target,
+		       devinfo->lun, period, offset);
+	}
+}
+
+/*
+ * Build a wide negotiateion message in our message
+ * buffer based on the input parameters.
+ */
+static void
+ahd_construct_wdtr(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
+		   u_int bus_width)
+{
+	ahd->msgout_buf[ahd->msgout_index++] = MSG_EXTENDED;
+	ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_WDTR_LEN;
+	ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_WDTR;
+	ahd->msgout_buf[ahd->msgout_index++] = bus_width;
+	ahd->msgout_len += 4;
+	if (bootverbose) {
+		printf("(%s:%c:%d:%d): Sending WDTR %x\n",
+		       ahd_name(ahd), devinfo->channel, devinfo->target,
+		       devinfo->lun, bus_width);
+	}
+}
+
+/*
+ * Build a parallel protocol request message in our message
+ * buffer based on the input parameters.
+ */
+static void
+ahd_construct_ppr(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
+		  u_int period, u_int offset, u_int bus_width,
+		  u_int ppr_options)
+{
+	/*
+	 * Always request precompensation from
+	 * the other target if we are running
+	 * at paced syncrates.
+	 */
+	if (period <= AHD_SYNCRATE_PACED)
+		ppr_options |= MSG_EXT_PPR_PCOMP_EN;
+	if (offset == 0)
+		period = AHD_ASYNC_XFER_PERIOD;
+	ahd->msgout_buf[ahd->msgout_index++] = MSG_EXTENDED;
+	ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_PPR_LEN;
+	ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_PPR;
+	ahd->msgout_buf[ahd->msgout_index++] = period;
+	ahd->msgout_buf[ahd->msgout_index++] = 0;
+	ahd->msgout_buf[ahd->msgout_index++] = offset;
+	ahd->msgout_buf[ahd->msgout_index++] = bus_width;
+	ahd->msgout_buf[ahd->msgout_index++] = ppr_options;
+	ahd->msgout_len += 8;
+	if (bootverbose) {
+		printf("(%s:%c:%d:%d): Sending PPR bus_width %x, period %x, "
+		       "offset %x, ppr_options %x\n", ahd_name(ahd),
+		       devinfo->channel, devinfo->target, devinfo->lun,
+		       bus_width, period, offset, ppr_options);
+	}
+}
+
+/*
+ * Clear any active message state.
+ */
+static void
+ahd_clear_msg_state(struct ahd_softc *ahd)
+{
+	ahd_mode_state saved_modes;
+
+	saved_modes = ahd_save_modes(ahd);
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+	ahd->send_msg_perror = 0;
+	ahd->msg_flags = MSG_FLAG_NONE;
+	ahd->msgout_len = 0;
+	ahd->msgin_index = 0;
+	ahd->msg_type = MSG_TYPE_NONE;
+	if ((ahd_inb(ahd, SCSISIGO) & ATNO) != 0) {
+		/*
+		 * The target didn't care to respond to our
+		 * message request, so clear ATN.
+		 */
+		ahd_outb(ahd, CLRSINT1, CLRATNO);
+	}
+	ahd_outb(ahd, MSG_OUT, MSG_NOOP);
+	ahd_outb(ahd, SEQ_FLAGS2,
+		 ahd_inb(ahd, SEQ_FLAGS2) & ~TARGET_MSG_PENDING);
+	ahd_restore_modes(ahd, saved_modes);
+}
+
+/*
+ * Manual message loop handler.
+ */
+static void
+ahd_handle_message_phase(struct ahd_softc *ahd)
+{ 
+	struct	ahd_devinfo devinfo;
+	u_int	bus_phase;
+	int	end_session;
+
+	ahd_fetch_devinfo(ahd, &devinfo);
+	end_session = FALSE;
+	bus_phase = ahd_inb(ahd, LASTPHASE);
+
+	if ((ahd_inb(ahd, LQISTAT2) & LQIPHASE_OUTPKT) != 0) {
+		printf("LQIRETRY for LQIPHASE_OUTPKT\n");
+		ahd_outb(ahd, LQCTL2, LQIRETRY);
+	}
+reswitch:
+	switch (ahd->msg_type) {
+	case MSG_TYPE_INITIATOR_MSGOUT:
+	{
+		int lastbyte;
+		int phasemis;
+		int msgdone;
+
+		if (ahd->msgout_len == 0 && ahd->send_msg_perror == 0)
+			panic("HOST_MSG_LOOP interrupt with no active message");
+
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_MESSAGES) != 0) {
+			ahd_print_devinfo(ahd, &devinfo);
+			printf("INITIATOR_MSG_OUT");
+		}
+#endif
+		phasemis = bus_phase != P_MESGOUT;
+		if (phasemis) {
+#ifdef AHD_DEBUG
+			if ((ahd_debug & AHD_SHOW_MESSAGES) != 0) {
+				printf(" PHASEMIS %s\n",
+				       ahd_lookup_phase_entry(bus_phase)
+							     ->phasemsg);
+			}
+#endif
+			if (bus_phase == P_MESGIN) {
+				/*
+				 * Change gears and see if
+				 * this messages is of interest to
+				 * us or should be passed back to
+				 * the sequencer.
+				 */
+				ahd_outb(ahd, CLRSINT1, CLRATNO);
+				ahd->send_msg_perror = 0;
+				ahd->msg_type = MSG_TYPE_INITIATOR_MSGIN;
+				ahd->msgin_index = 0;
+				goto reswitch;
+			}
+			end_session = TRUE;
+			break;
+		}
+
+		if (ahd->send_msg_perror) {
+			ahd_outb(ahd, CLRSINT1, CLRATNO);
+			ahd_outb(ahd, CLRSINT1, CLRREQINIT);
+#ifdef AHD_DEBUG
+			if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
+				printf(" byte 0x%x\n", ahd->send_msg_perror);
+#endif
+			/*
+			 * If we are notifying the target of a CRC error
+			 * during packetized operations, the target is
+			 * within its rights to acknowledge our message
+			 * with a busfree.
+			 */
+			if ((ahd->msg_flags & MSG_FLAG_PACKETIZED) != 0
+			 && ahd->send_msg_perror == MSG_INITIATOR_DET_ERR)
+				ahd->msg_flags |= MSG_FLAG_EXPECT_IDE_BUSFREE;
+
+			ahd_outb(ahd, RETURN_2, ahd->send_msg_perror);
+			ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_WRITE);
+			break;
+		}
+
+		msgdone	= ahd->msgout_index == ahd->msgout_len;
+		if (msgdone) {
+			/*
+			 * The target has requested a retry.
+			 * Re-assert ATN, reset our message index to
+			 * 0, and try again.
+			 */
+			ahd->msgout_index = 0;
+			ahd_assert_atn(ahd);
+		}
+
+		lastbyte = ahd->msgout_index == (ahd->msgout_len - 1);
+		if (lastbyte) {
+			/* Last byte is signified by dropping ATN */
+			ahd_outb(ahd, CLRSINT1, CLRATNO);
+		}
+
+		/*
+		 * Clear our interrupt status and present
+		 * the next byte on the bus.
+		 */
+		ahd_outb(ahd, CLRSINT1, CLRREQINIT);
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
+			printf(" byte 0x%x\n",
+			       ahd->msgout_buf[ahd->msgout_index]);
+#endif
+		ahd_outb(ahd, RETURN_2, ahd->msgout_buf[ahd->msgout_index++]);
+		ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_WRITE);
+		break;
+	}
+	case MSG_TYPE_INITIATOR_MSGIN:
+	{
+		int phasemis;
+		int message_done;
+
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_MESSAGES) != 0) {
+			ahd_print_devinfo(ahd, &devinfo);
+			printf("INITIATOR_MSG_IN");
+		}
+#endif
+		phasemis = bus_phase != P_MESGIN;
+		if (phasemis) {
+#ifdef AHD_DEBUG
+			if ((ahd_debug & AHD_SHOW_MESSAGES) != 0) {
+				printf(" PHASEMIS %s\n",
+				       ahd_lookup_phase_entry(bus_phase)
+							     ->phasemsg);
+			}
+#endif
+			ahd->msgin_index = 0;
+			if (bus_phase == P_MESGOUT
+			 && (ahd->send_msg_perror != 0
+			  || (ahd->msgout_len != 0
+			   && ahd->msgout_index == 0))) {
+				ahd->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
+				goto reswitch;
+			}
+			end_session = TRUE;
+			break;
+		}
+
+		/* Pull the byte in without acking it */
+		ahd->msgin_buf[ahd->msgin_index] = ahd_inb(ahd, SCSIBUS);
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
+			printf(" byte 0x%x\n",
+			       ahd->msgin_buf[ahd->msgin_index]);
+#endif
+
+		message_done = ahd_parse_msg(ahd, &devinfo);
+
+		if (message_done) {
+			/*
+			 * Clear our incoming message buffer in case there
+			 * is another message following this one.
+			 */
+			ahd->msgin_index = 0;
+
+			/*
+			 * If this message illicited a response,
+			 * assert ATN so the target takes us to the
+			 * message out phase.
+			 */
+			if (ahd->msgout_len != 0) {
+#ifdef AHD_DEBUG
+				if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
+					printf("Asserting ATN for response\n");
+#endif
+				ahd_assert_atn(ahd);
+			}
+		} else 
+			ahd->msgin_index++;
+
+		if (message_done == MSGLOOP_TERMINATED) {
+			end_session = TRUE;
+		} else {
+			/* Ack the byte */
+			ahd_outb(ahd, CLRSINT1, CLRREQINIT);
+			ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_READ);
+		}
+		break;
+	}
+	case MSG_TYPE_TARGET_MSGIN:
+	{
+		int msgdone;
+		int msgout_request;
+
+		/*
+		 * By default, the message loop will continue.
+		 */
+		ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_TARG);
+
+		if (ahd->msgout_len == 0)
+			panic("Target MSGIN with no active message");
+
+		/*
+		 * If we interrupted a mesgout session, the initiator
+		 * will not know this until our first REQ.  So, we
+		 * only honor mesgout requests after we've sent our
+		 * first byte.
+		 */
+		if ((ahd_inb(ahd, SCSISIGI) & ATNI) != 0
+		 && ahd->msgout_index > 0)
+			msgout_request = TRUE;
+		else
+			msgout_request = FALSE;
+
+		if (msgout_request) {
+
+			/*
+			 * Change gears and see if
+			 * this messages is of interest to
+			 * us or should be passed back to
+			 * the sequencer.
+			 */
+			ahd->msg_type = MSG_TYPE_TARGET_MSGOUT;
+			ahd_outb(ahd, SCSISIGO, P_MESGOUT | BSYO);
+			ahd->msgin_index = 0;
+			/* Dummy read to REQ for first byte */
+			ahd_inb(ahd, SCSIDAT);
+			ahd_outb(ahd, SXFRCTL0,
+				 ahd_inb(ahd, SXFRCTL0) | SPIOEN);
+			break;
+		}
+
+		msgdone = ahd->msgout_index == ahd->msgout_len;
+		if (msgdone) {
+			ahd_outb(ahd, SXFRCTL0,
+				 ahd_inb(ahd, SXFRCTL0) & ~SPIOEN);
+			end_session = TRUE;
+			break;
+		}
+
+		/*
+		 * Present the next byte on the bus.
+		 */
+		ahd_outb(ahd, SXFRCTL0, ahd_inb(ahd, SXFRCTL0) | SPIOEN);
+		ahd_outb(ahd, SCSIDAT, ahd->msgout_buf[ahd->msgout_index++]);
+		break;
+	}
+	case MSG_TYPE_TARGET_MSGOUT:
+	{
+		int lastbyte;
+		int msgdone;
+
+		/*
+		 * By default, the message loop will continue.
+		 */
+		ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_TARG);
+
+		/*
+		 * The initiator signals that this is
+		 * the last byte by dropping ATN.
+		 */
+		lastbyte = (ahd_inb(ahd, SCSISIGI) & ATNI) == 0;
+
+		/*
+		 * Read the latched byte, but turn off SPIOEN first
+		 * so that we don't inadvertently cause a REQ for the
+		 * next byte.
+		 */
+		ahd_outb(ahd, SXFRCTL0, ahd_inb(ahd, SXFRCTL0) & ~SPIOEN);
+		ahd->msgin_buf[ahd->msgin_index] = ahd_inb(ahd, SCSIDAT);
+		msgdone = ahd_parse_msg(ahd, &devinfo);
+		if (msgdone == MSGLOOP_TERMINATED) {
+			/*
+			 * The message is *really* done in that it caused
+			 * us to go to bus free.  The sequencer has already
+			 * been reset at this point, so pull the ejection
+			 * handle.
+			 */
+			return;
+		}
+		
+		ahd->msgin_index++;
+
+		/*
+		 * XXX Read spec about initiator dropping ATN too soon
+		 *     and use msgdone to detect it.
+		 */
+		if (msgdone == MSGLOOP_MSGCOMPLETE) {
+			ahd->msgin_index = 0;
+
+			/*
+			 * If this message illicited a response, transition
+			 * to the Message in phase and send it.
+			 */
+			if (ahd->msgout_len != 0) {
+				ahd_outb(ahd, SCSISIGO, P_MESGIN | BSYO);
+				ahd_outb(ahd, SXFRCTL0,
+					 ahd_inb(ahd, SXFRCTL0) | SPIOEN);
+				ahd->msg_type = MSG_TYPE_TARGET_MSGIN;
+				ahd->msgin_index = 0;
+				break;
+			}
+		}
+
+		if (lastbyte)
+			end_session = TRUE;
+		else {
+			/* Ask for the next byte. */
+			ahd_outb(ahd, SXFRCTL0,
+				 ahd_inb(ahd, SXFRCTL0) | SPIOEN);
+		}
+
+		break;
+	}
+	default:
+		panic("Unknown REQINIT message type");
+	}
+
+	if (end_session) {
+		if ((ahd->msg_flags & MSG_FLAG_PACKETIZED) != 0) {
+			printf("%s: Returning to Idle Loop\n",
+			       ahd_name(ahd));
+			ahd_outb(ahd, LASTPHASE, P_BUSFREE);
+			ahd_clear_msg_state(ahd);
+			ahd_outb(ahd, SEQCTL0, FASTMODE|SEQRESET);
+		} else {
+			ahd_clear_msg_state(ahd);
+			ahd_outb(ahd, RETURN_1, EXIT_MSG_LOOP);
+		}
+	}
+}
+
+/*
+ * See if we sent a particular extended message to the target.
+ * If "full" is true, return true only if the target saw the full
+ * message.  If "full" is false, return true if the target saw at
+ * least the first byte of the message.
+ */
+static int
+ahd_sent_msg(struct ahd_softc *ahd, ahd_msgtype type, u_int msgval, int full)
+{
+	int found;
+	u_int index;
+
+	found = FALSE;
+	index = 0;
+
+	while (index < ahd->msgout_len) {
+		if (ahd->msgout_buf[index] == MSG_EXTENDED) {
+			u_int end_index;
+
+			end_index = index + 1 + ahd->msgout_buf[index + 1];
+			if (ahd->msgout_buf[index+2] == msgval
+			 && type == AHDMSG_EXT) {
+
+				if (full) {
+					if (ahd->msgout_index > end_index)
+						found = TRUE;
+				} else if (ahd->msgout_index > index)
+					found = TRUE;
+			}
+			index = end_index;
+		} else if (ahd->msgout_buf[index] >= MSG_SIMPLE_TASK
+			&& ahd->msgout_buf[index] <= MSG_IGN_WIDE_RESIDUE) {
+
+			/* Skip tag type and tag id or residue param*/
+			index += 2;
+		} else {
+			/* Single byte message */
+			if (type == AHDMSG_1B
+			 && ahd->msgout_index > index
+			 && (ahd->msgout_buf[index] == msgval
+			  || ((ahd->msgout_buf[index] & MSG_IDENTIFYFLAG) != 0))
+			   && msgval == MSG_IDENTIFYFLAG)
+				found = TRUE;
+			index++;
+		}
+
+		if (found)
+			break;
+	}
+	return (found);
+}
+
+/*
+ * Wait for a complete incoming message, parse it, and respond accordingly.
+ */
+static int
+ahd_parse_msg(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
+{
+	struct	ahd_initiator_tinfo *tinfo;
+	struct	ahd_tmode_tstate *tstate;
+	int	reject;
+	int	done;
+	int	response;
+
+	done = MSGLOOP_IN_PROG;
+	response = FALSE;
+	reject = FALSE;
+	tinfo = ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
+				    devinfo->target, &tstate);
+
+	/*
+	 * Parse as much of the message as is availible,
+	 * rejecting it if we don't support it.  When
+	 * the entire message is availible and has been
+	 * handled, return MSGLOOP_MSGCOMPLETE, indicating
+	 * that we have parsed an entire message.
+	 *
+	 * In the case of extended messages, we accept the length
+	 * byte outright and perform more checking once we know the
+	 * extended message type.
+	 */
+	switch (ahd->msgin_buf[0]) {
+	case MSG_DISCONNECT:
+	case MSG_SAVEDATAPOINTER:
+	case MSG_CMDCOMPLETE:
+	case MSG_RESTOREPOINTERS:
+	case MSG_IGN_WIDE_RESIDUE:
+		/*
+		 * End our message loop as these are messages
+		 * the sequencer handles on its own.
+		 */
+		done = MSGLOOP_TERMINATED;
+		break;
+	case MSG_MESSAGE_REJECT:
+		response = ahd_handle_msg_reject(ahd, devinfo);
+		/* FALLTHROUGH */
+	case MSG_NOOP:
+		done = MSGLOOP_MSGCOMPLETE;
+		break;
+	case MSG_EXTENDED:
+	{
+		/* Wait for enough of the message to begin validation */
+		if (ahd->msgin_index < 2)
+			break;
+		switch (ahd->msgin_buf[2]) {
+		case MSG_EXT_SDTR:
+		{
+			u_int	 period;
+			u_int	 ppr_options;
+			u_int	 offset;
+			u_int	 saved_offset;
+			
+			if (ahd->msgin_buf[1] != MSG_EXT_SDTR_LEN) {
+				reject = TRUE;
+				break;
+			}
+
+			/*
+			 * Wait until we have both args before validating
+			 * and acting on this message.
+			 *
+			 * Add one to MSG_EXT_SDTR_LEN to account for
+			 * the extended message preamble.
+			 */
+			if (ahd->msgin_index < (MSG_EXT_SDTR_LEN + 1))
+				break;
+
+			period = ahd->msgin_buf[3];
+			ppr_options = 0;
+			saved_offset = offset = ahd->msgin_buf[4];
+			ahd_devlimited_syncrate(ahd, tinfo, &period,
+						&ppr_options, devinfo->role);
+			ahd_validate_offset(ahd, tinfo, period, &offset,
+					    tinfo->curr.width, devinfo->role);
+			if (bootverbose) {
+				printf("(%s:%c:%d:%d): Received "
+				       "SDTR period %x, offset %x\n\t"
+				       "Filtered to period %x, offset %x\n",
+				       ahd_name(ahd), devinfo->channel,
+				       devinfo->target, devinfo->lun,
+				       ahd->msgin_buf[3], saved_offset,
+				       period, offset);
+			}
+			ahd_set_syncrate(ahd, devinfo, period,
+					 offset, ppr_options,
+					 AHD_TRANS_ACTIVE|AHD_TRANS_GOAL,
+					 /*paused*/TRUE);
+
+			/*
+			 * See if we initiated Sync Negotiation
+			 * and didn't have to fall down to async
+			 * transfers.
+			 */
+			if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_SDTR, TRUE)) {
+				/* We started it */
+				if (saved_offset != offset) {
+					/* Went too low - force async */
+					reject = TRUE;
+				}
+			} else {
+				/*
+				 * Send our own SDTR in reply
+				 */
+				if (bootverbose
+				 && devinfo->role == ROLE_INITIATOR) {
+					printf("(%s:%c:%d:%d): Target "
+					       "Initiated SDTR\n",
+					       ahd_name(ahd), devinfo->channel,
+					       devinfo->target, devinfo->lun);
+				}
+				ahd->msgout_index = 0;
+				ahd->msgout_len = 0;
+				ahd_construct_sdtr(ahd, devinfo,
+						   period, offset);
+				ahd->msgout_index = 0;
+				response = TRUE;
+			}
+			done = MSGLOOP_MSGCOMPLETE;
+			break;
+		}
+		case MSG_EXT_WDTR:
+		{
+			u_int bus_width;
+			u_int saved_width;
+			u_int sending_reply;
+
+			sending_reply = FALSE;
+			if (ahd->msgin_buf[1] != MSG_EXT_WDTR_LEN) {
+				reject = TRUE;
+				break;
+			}
+
+			/*
+			 * Wait until we have our arg before validating
+			 * and acting on this message.
+			 *
+			 * Add one to MSG_EXT_WDTR_LEN to account for
+			 * the extended message preamble.
+			 */
+			if (ahd->msgin_index < (MSG_EXT_WDTR_LEN + 1))
+				break;
+
+			bus_width = ahd->msgin_buf[3];
+			saved_width = bus_width;
+			ahd_validate_width(ahd, tinfo, &bus_width,
+					   devinfo->role);
+			if (bootverbose) {
+				printf("(%s:%c:%d:%d): Received WDTR "
+				       "%x filtered to %x\n",
+				       ahd_name(ahd), devinfo->channel,
+				       devinfo->target, devinfo->lun,
+				       saved_width, bus_width);
+			}
+
+			if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_WDTR, TRUE)) {
+				/*
+				 * Don't send a WDTR back to the
+				 * target, since we asked first.
+				 * If the width went higher than our
+				 * request, reject it.
+				 */
+				if (saved_width > bus_width) {
+					reject = TRUE;
+					printf("(%s:%c:%d:%d): requested %dBit "
+					       "transfers.  Rejecting...\n",
+					       ahd_name(ahd), devinfo->channel,
+					       devinfo->target, devinfo->lun,
+					       8 * (0x01 << bus_width));
+					bus_width = 0;
+				}
+			} else {
+				/*
+				 * Send our own WDTR in reply
+				 */
+				if (bootverbose
+				 && devinfo->role == ROLE_INITIATOR) {
+					printf("(%s:%c:%d:%d): Target "
+					       "Initiated WDTR\n",
+					       ahd_name(ahd), devinfo->channel,
+					       devinfo->target, devinfo->lun);
+				}
+				ahd->msgout_index = 0;
+				ahd->msgout_len = 0;
+				ahd_construct_wdtr(ahd, devinfo, bus_width);
+				ahd->msgout_index = 0;
+				response = TRUE;
+				sending_reply = TRUE;
+			}
+			ahd_set_width(ahd, devinfo, bus_width,
+				      AHD_TRANS_ACTIVE|AHD_TRANS_GOAL,
+				      /*paused*/TRUE);
+			/* After a wide message, we are async */
+			ahd_set_syncrate(ahd, devinfo, /*period*/0,
+					 /*offset*/0, /*ppr_options*/0,
+					 AHD_TRANS_ACTIVE, /*paused*/TRUE);
+			if (sending_reply == FALSE && reject == FALSE) {
+
+				if (tinfo->goal.offset) {
+					ahd->msgout_index = 0;
+					ahd->msgout_len = 0;
+					ahd_build_transfer_msg(ahd, devinfo);
+					ahd->msgout_index = 0;
+					response = TRUE;
+				}
+			}
+			done = MSGLOOP_MSGCOMPLETE;
+			break;
+		}
+		case MSG_EXT_PPR:
+		{
+			u_int	period;
+			u_int	offset;
+			u_int	bus_width;
+			u_int	ppr_options;
+			u_int	saved_width;
+			u_int	saved_offset;
+			u_int	saved_ppr_options;
+
+			if (ahd->msgin_buf[1] != MSG_EXT_PPR_LEN) {
+				reject = TRUE;
+				break;
+			}
+
+			/*
+			 * Wait until we have all args before validating
+			 * and acting on this message.
+			 *
+			 * Add one to MSG_EXT_PPR_LEN to account for
+			 * the extended message preamble.
+			 */
+			if (ahd->msgin_index < (MSG_EXT_PPR_LEN + 1))
+				break;
+
+			period = ahd->msgin_buf[3];
+			offset = ahd->msgin_buf[5];
+			bus_width = ahd->msgin_buf[6];
+			saved_width = bus_width;
+			ppr_options = ahd->msgin_buf[7];
+			/*
+			 * According to the spec, a DT only
+			 * period factor with no DT option
+			 * set implies async.
+			 */
+			if ((ppr_options & MSG_EXT_PPR_DT_REQ) == 0
+			 && period <= 9)
+				offset = 0;
+			saved_ppr_options = ppr_options;
+			saved_offset = offset;
+
+			/*
+			 * Transfer options are only available if we
+			 * are negotiating wide.
+			 */
+			if (bus_width == 0)
+				ppr_options &= MSG_EXT_PPR_QAS_REQ;
+
+			ahd_validate_width(ahd, tinfo, &bus_width,
+					   devinfo->role);
+			ahd_devlimited_syncrate(ahd, tinfo, &period,
+						&ppr_options, devinfo->role);
+			ahd_validate_offset(ahd, tinfo, period, &offset,
+					    bus_width, devinfo->role);
+
+			if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, TRUE)) {
+				/*
+				 * If we are unable to do any of the
+				 * requested options (we went too low),
+				 * then we'll have to reject the message.
+				 */
+				if (saved_width > bus_width
+				 || saved_offset != offset
+				 || saved_ppr_options != ppr_options) {
+					reject = TRUE;
+					period = 0;
+					offset = 0;
+					bus_width = 0;
+					ppr_options = 0;
+				}
+			} else {
+				if (devinfo->role != ROLE_TARGET)
+					printf("(%s:%c:%d:%d): Target "
+					       "Initiated PPR\n",
+					       ahd_name(ahd), devinfo->channel,
+					       devinfo->target, devinfo->lun);
+				else
+					printf("(%s:%c:%d:%d): Initiator "
+					       "Initiated PPR\n",
+					       ahd_name(ahd), devinfo->channel,
+					       devinfo->target, devinfo->lun);
+				ahd->msgout_index = 0;
+				ahd->msgout_len = 0;
+				ahd_construct_ppr(ahd, devinfo, period, offset,
+						  bus_width, ppr_options);
+				ahd->msgout_index = 0;
+				response = TRUE;
+			}
+			if (bootverbose) {
+				printf("(%s:%c:%d:%d): Received PPR width %x, "
+				       "period %x, offset %x,options %x\n"
+				       "\tFiltered to width %x, period %x, "
+				       "offset %x, options %x\n",
+				       ahd_name(ahd), devinfo->channel,
+				       devinfo->target, devinfo->lun,
+				       saved_width, ahd->msgin_buf[3],
+				       saved_offset, saved_ppr_options,
+				       bus_width, period, offset, ppr_options);
+			}
+			ahd_set_width(ahd, devinfo, bus_width,
+				      AHD_TRANS_ACTIVE|AHD_TRANS_GOAL,
+				      /*paused*/TRUE);
+			ahd_set_syncrate(ahd, devinfo, period,
+					 offset, ppr_options,
+					 AHD_TRANS_ACTIVE|AHD_TRANS_GOAL,
+					 /*paused*/TRUE);
+
+			done = MSGLOOP_MSGCOMPLETE;
+			break;
+		}
+		default:
+			/* Unknown extended message.  Reject it. */
+			reject = TRUE;
+			break;
+		}
+		break;
+	}
+#ifdef AHD_TARGET_MODE
+	case MSG_BUS_DEV_RESET:
+		ahd_handle_devreset(ahd, devinfo,
+				    CAM_BDR_SENT,
+				    "Bus Device Reset Received",
+				    /*verbose_level*/0);
+		ahd_restart(ahd);
+		done = MSGLOOP_TERMINATED;
+		break;
+	case MSG_ABORT_TAG:
+	case MSG_ABORT:
+	case MSG_CLEAR_QUEUE:
+	{
+		int tag;
+
+		/* Target mode messages */
+		if (devinfo->role != ROLE_TARGET) {
+			reject = TRUE;
+			break;
+		}
+		tag = SCB_LIST_NULL;
+		if (ahd->msgin_buf[0] == MSG_ABORT_TAG)
+			tag = ahd_inb(ahd, INITIATOR_TAG);
+		ahd_abort_scbs(ahd, devinfo->target, devinfo->channel,
+			       devinfo->lun, tag, ROLE_TARGET,
+			       CAM_REQ_ABORTED);
+
+		tstate = ahd->enabled_targets[devinfo->our_scsiid];
+		if (tstate != NULL) {
+			struct ahd_tmode_lstate* lstate;
+
+			lstate = tstate->enabled_luns[devinfo->lun];
+			if (lstate != NULL) {
+				ahd_queue_lstate_event(ahd, lstate,
+						       devinfo->our_scsiid,
+						       ahd->msgin_buf[0],
+						       /*arg*/tag);
+				ahd_send_lstate_events(ahd, lstate);
+			}
+		}
+		ahd_restart(ahd);
+		done = MSGLOOP_TERMINATED;
+		break;
+	}
+#endif
+	case MSG_QAS_REQUEST:
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
+			printf("%s: QAS request.  SCSISIGI == 0x%x\n",
+			       ahd_name(ahd), ahd_inb(ahd, SCSISIGI));
+#endif
+		ahd->msg_flags |= MSG_FLAG_EXPECT_QASREJ_BUSFREE;
+		/* FALLTHROUGH */
+	case MSG_TERM_IO_PROC:
+	default:
+		reject = TRUE;
+		break;
+	}
+
+	if (reject) {
+		/*
+		 * Setup to reject the message.
+		 */
+		ahd->msgout_index = 0;
+		ahd->msgout_len = 1;
+		ahd->msgout_buf[0] = MSG_MESSAGE_REJECT;
+		done = MSGLOOP_MSGCOMPLETE;
+		response = TRUE;
+	}
+
+	if (done != MSGLOOP_IN_PROG && !response)
+		/* Clear the outgoing message buffer */
+		ahd->msgout_len = 0;
+
+	return (done);
+}
+
+/*
+ * Process a message reject message.
+ */
+static int
+ahd_handle_msg_reject(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
+{
+	/*
+	 * What we care about here is if we had an
+	 * outstanding SDTR or WDTR message for this
+	 * target.  If we did, this is a signal that
+	 * the target is refusing negotiation.
+	 */
+	struct scb *scb;
+	struct ahd_initiator_tinfo *tinfo;
+	struct ahd_tmode_tstate *tstate;
+	u_int scb_index;
+	u_int last_msg;
+	int   response = 0;
+
+	scb_index = ahd_get_scbptr(ahd);
+	scb = ahd_lookup_scb(ahd, scb_index);
+	tinfo = ahd_fetch_transinfo(ahd, devinfo->channel,
+				    devinfo->our_scsiid,
+				    devinfo->target, &tstate);
+	/* Might be necessary */
+	last_msg = ahd_inb(ahd, LAST_MSG);
+
+	if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, /*full*/FALSE)) {
+		if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_PPR, /*full*/TRUE)
+		 && tinfo->goal.period <= AHD_SYNCRATE_PACED) {
+			/*
+			 * Target may not like our SPI-4 PPR Options.
+			 * Attempt to negotiate 80MHz which will turn
+			 * off these options.
+			 */
+			if (bootverbose) {
+				printf("(%s:%c:%d:%d): PPR Rejected. "
+				       "Trying simple U160 PPR\n",
+				       ahd_name(ahd), devinfo->channel,
+				       devinfo->target, devinfo->lun);
+			}
+			tinfo->goal.period = AHD_SYNCRATE_DT;
+			tinfo->goal.ppr_options &= MSG_EXT_PPR_IU_REQ
+						|  MSG_EXT_PPR_QAS_REQ
+						|  MSG_EXT_PPR_DT_REQ;
+		} else {
+			/*
+			 * Target does not support the PPR message.
+			 * Attempt to negotiate SPI-2 style.
+			 */
+			if (bootverbose) {
+				printf("(%s:%c:%d:%d): PPR Rejected. "
+				       "Trying WDTR/SDTR\n",
+				       ahd_name(ahd), devinfo->channel,
+				       devinfo->target, devinfo->lun);
+			}
+			tinfo->goal.ppr_options = 0;
+			tinfo->curr.transport_version = 2;
+			tinfo->goal.transport_version = 2;
+		}
+		ahd->msgout_index = 0;
+		ahd->msgout_len = 0;
+		ahd_build_transfer_msg(ahd, devinfo);
+		ahd->msgout_index = 0;
+		response = 1;
+	} else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_WDTR, /*full*/FALSE)) {
+
+		/* note 8bit xfers */
+		printf("(%s:%c:%d:%d): refuses WIDE negotiation.  Using "
+		       "8bit transfers\n", ahd_name(ahd),
+		       devinfo->channel, devinfo->target, devinfo->lun);
+		ahd_set_width(ahd, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
+			      AHD_TRANS_ACTIVE|AHD_TRANS_GOAL,
+			      /*paused*/TRUE);
+		/*
+		 * No need to clear the sync rate.  If the target
+		 * did not accept the command, our syncrate is
+		 * unaffected.  If the target started the negotiation,
+		 * but rejected our response, we already cleared the
+		 * sync rate before sending our WDTR.
+		 */
+		if (tinfo->goal.period) {
+
+			/* Start the sync negotiation */
+			ahd->msgout_index = 0;
+			ahd->msgout_len = 0;
+			ahd_build_transfer_msg(ahd, devinfo);
+			ahd->msgout_index = 0;
+			response = 1;
+		}
+	} else if (ahd_sent_msg(ahd, AHDMSG_EXT, MSG_EXT_SDTR, /*full*/FALSE)) {
+		/* note asynch xfers and clear flag */
+		ahd_set_syncrate(ahd, devinfo, /*period*/0,
+				 /*offset*/0, /*ppr_options*/0,
+				 AHD_TRANS_ACTIVE|AHD_TRANS_GOAL,
+				 /*paused*/TRUE);
+		printf("(%s:%c:%d:%d): refuses synchronous negotiation. "
+		       "Using asynchronous transfers\n",
+		       ahd_name(ahd), devinfo->channel,
+		       devinfo->target, devinfo->lun);
+	} else if ((scb->hscb->control & MSG_SIMPLE_TASK) != 0) {
+		int tag_type;
+		int mask;
+
+		tag_type = (scb->hscb->control & MSG_SIMPLE_TASK);
+
+		if (tag_type == MSG_SIMPLE_TASK) {
+			printf("(%s:%c:%d:%d): refuses tagged commands.  "
+			       "Performing non-tagged I/O\n", ahd_name(ahd),
+			       devinfo->channel, devinfo->target, devinfo->lun);
+			ahd_set_tags(ahd, devinfo, AHD_QUEUE_NONE);
+			mask = ~0x23;
+		} else {
+			printf("(%s:%c:%d:%d): refuses %s tagged commands.  "
+			       "Performing simple queue tagged I/O only\n",
+			       ahd_name(ahd), devinfo->channel, devinfo->target,
+			       devinfo->lun, tag_type == MSG_ORDERED_TASK
+			       ? "ordered" : "head of queue");
+			ahd_set_tags(ahd, devinfo, AHD_QUEUE_BASIC);
+			mask = ~0x03;
+		}
+
+		/*
+		 * Resend the identify for this CCB as the target
+		 * may believe that the selection is invalid otherwise.
+		 */
+		ahd_outb(ahd, SCB_CONTROL,
+			 ahd_inb_scbram(ahd, SCB_CONTROL) & mask);
+	 	scb->hscb->control &= mask;
+		ahd_set_transaction_tag(scb, /*enabled*/FALSE,
+					/*type*/MSG_SIMPLE_TASK);
+		ahd_outb(ahd, MSG_OUT, MSG_IDENTIFYFLAG);
+		ahd_assert_atn(ahd);
+		ahd_busy_tcl(ahd, BUILD_TCL(scb->hscb->scsiid, devinfo->lun),
+			     SCB_GET_TAG(scb));
+
+		/*
+		 * Requeue all tagged commands for this target
+		 * currently in our posession so they can be
+		 * converted to untagged commands.
+		 */
+		ahd_search_qinfifo(ahd, SCB_GET_TARGET(ahd, scb),
+				   SCB_GET_CHANNEL(ahd, scb),
+				   SCB_GET_LUN(scb), /*tag*/SCB_LIST_NULL,
+				   ROLE_INITIATOR, CAM_REQUEUE_REQ,
+				   SEARCH_COMPLETE);
+	} else if (ahd_sent_msg(ahd, AHDMSG_1B, MSG_IDENTIFYFLAG, TRUE)) {
+		/*
+		 * Most likely the device believes that we had
+		 * previously negotiated packetized.
+		 */
+		ahd->msg_flags |= MSG_FLAG_EXPECT_PPR_BUSFREE
+			       |  MSG_FLAG_IU_REQ_CHANGED;
+
+		ahd_force_renegotiation(ahd, devinfo);
+		ahd->msgout_index = 0;
+		ahd->msgout_len = 0;
+		ahd_build_transfer_msg(ahd, devinfo);
+		ahd->msgout_index = 0;
+		response = 1;
+	} else {
+		/*
+		 * Otherwise, we ignore it.
+		 */
+		printf("%s:%c:%d: Message reject for %x -- ignored\n",
+		       ahd_name(ahd), devinfo->channel, devinfo->target,
+		       last_msg);
+	}
+	return (response);
+}
+
+/*
+ * Process an ingnore wide residue message.
+ */
+static void
+ahd_handle_ign_wide_residue(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
+{
+	u_int scb_index;
+	struct scb *scb;
+
+	scb_index = ahd_get_scbptr(ahd);
+	scb = ahd_lookup_scb(ahd, scb_index);
+	/*
+	 * XXX Actually check data direction in the sequencer?
+	 * Perhaps add datadir to some spare bits in the hscb?
+	 */
+	if ((ahd_inb(ahd, SEQ_FLAGS) & DPHASE) == 0
+	 || ahd_get_transfer_dir(scb) != CAM_DIR_IN) {
+		/*
+		 * Ignore the message if we haven't
+		 * seen an appropriate data phase yet.
+		 */
+	} else {
+		/*
+		 * If the residual occurred on the last
+		 * transfer and the transfer request was
+		 * expected to end on an odd count, do
+		 * nothing.  Otherwise, subtract a byte
+		 * and update the residual count accordingly.
+		 */
+		uint32_t sgptr;
+
+		sgptr = ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR);
+		if ((sgptr & SG_LIST_NULL) != 0
+		 && ahd_inb(ahd, DATA_COUNT_ODD) == 1) {
+			/*
+			 * If the residual occurred on the last
+			 * transfer and the transfer request was
+			 * expected to end on an odd count, do
+			 * nothing.
+			 */
+		} else {
+			uint32_t data_cnt;
+			uint64_t data_addr;
+			uint32_t sglen;
+
+			/* Pull in the rest of the sgptr */
+			sgptr |=
+			    (ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR + 3) << 24)
+			  | (ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR + 2) << 16)
+			  | (ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR + 1) << 8);
+			sgptr &= SG_PTR_MASK;
+			data_cnt =
+			    (ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT+3) << 24)
+			  | (ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT+2) << 16)
+			  | (ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT+1) << 8)
+			  | (ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT));
+
+			data_addr = (((uint64_t)ahd_inb(ahd, SHADDR + 7)) << 56)
+				  | (((uint64_t)ahd_inb(ahd, SHADDR + 6)) << 48)
+				  | (((uint64_t)ahd_inb(ahd, SHADDR + 5)) << 40)
+				  | (((uint64_t)ahd_inb(ahd, SHADDR + 4)) << 32)
+				  | (ahd_inb(ahd, SHADDR + 3) << 24)
+				  | (ahd_inb(ahd, SHADDR + 2) << 16)
+				  | (ahd_inb(ahd, SHADDR + 1) << 8)
+				  | (ahd_inb(ahd, SHADDR));
+
+			data_cnt += 1;
+			data_addr -= 1;
+
+			if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
+				struct ahd_dma64_seg *sg;
+
+				sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
+
+				/*
+				 * The residual sg ptr points to the next S/G
+				 * to load so we must go back one.
+				 */
+				sg--;
+				sglen = ahd_le32toh(sg->len) & AHD_SG_LEN_MASK;
+				if (sg != scb->sg_list
+				 && sglen < (data_cnt & AHD_SG_LEN_MASK)) {
+
+					sg--;
+					sglen = ahd_le32toh(sg->len);
+					/*
+					 * Preserve High Address and SG_LIST
+					 * bits while setting the count to 1.
+					 */
+					data_cnt = 1|(sglen&(~AHD_SG_LEN_MASK));
+					data_addr = ahd_le64toh(sg->addr)
+						  + (sglen & AHD_SG_LEN_MASK)
+						  - 1;
+
+					/*
+					 * Increment sg so it points to the
+					 * "next" sg.
+					 */
+					sg++;
+					sgptr = ahd_sg_virt_to_bus(ahd, scb,
+								   sg);
+				}
+			} else {
+				struct ahd_dma_seg *sg;
+
+				sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
+
+				/*
+				 * The residual sg ptr points to the next S/G
+				 * to load so we must go back one.
+				 */
+				sg--;
+				sglen = ahd_le32toh(sg->len) & AHD_SG_LEN_MASK;
+				if (sg != scb->sg_list
+				 && sglen < (data_cnt & AHD_SG_LEN_MASK)) {
+
+					sg--;
+					sglen = ahd_le32toh(sg->len);
+					/*
+					 * Preserve High Address and SG_LIST
+					 * bits while setting the count to 1.
+					 */
+					data_cnt = 1|(sglen&(~AHD_SG_LEN_MASK));
+					data_addr = ahd_le32toh(sg->addr)
+						  + (sglen & AHD_SG_LEN_MASK)
+						  - 1;
+
+					/*
+					 * Increment sg so it points to the
+					 * "next" sg.
+					 */
+					sg++;
+					sgptr = ahd_sg_virt_to_bus(ahd, scb,
+								  sg);
+				}
+			}
+			ahd_outb(ahd, SCB_RESIDUAL_SGPTR + 3, sgptr >> 24);
+			ahd_outb(ahd, SCB_RESIDUAL_SGPTR + 2, sgptr >> 16);
+			ahd_outb(ahd, SCB_RESIDUAL_SGPTR + 1, sgptr >> 8);
+			ahd_outb(ahd, SCB_RESIDUAL_SGPTR, sgptr);
+
+			ahd_outb(ahd, SCB_RESIDUAL_DATACNT + 3, data_cnt >> 24);
+			ahd_outb(ahd, SCB_RESIDUAL_DATACNT + 2, data_cnt >> 16);
+			ahd_outb(ahd, SCB_RESIDUAL_DATACNT + 1, data_cnt >> 8);
+			ahd_outb(ahd, SCB_RESIDUAL_DATACNT, data_cnt);
+
+			/*
+			 * The FIFO's pointers will be updated if/when the
+			 * sequencer re-enters a data phase.
+			 */
+		}
+	}
+}
+
+
+/*
+ * Reinitialize the data pointers for the active transfer
+ * based on its current residual.
+ */
+static void
+ahd_reinitialize_dataptrs(struct ahd_softc *ahd)
+{
+	struct		 scb *scb;
+	ahd_mode_state	 saved_modes;
+	u_int		 scb_index;
+	u_int		 wait;
+	uint32_t	 sgptr;
+	uint32_t	 resid;
+	uint64_t	 dataptr;
+
+	AHD_ASSERT_MODES(ahd, AHD_MODE_DFF0_MSK|AHD_MODE_DFF1_MSK,
+			 AHD_MODE_DFF0_MSK|AHD_MODE_DFF1_MSK);
+			 
+	scb_index = ahd_get_scbptr(ahd);
+	scb = ahd_lookup_scb(ahd, scb_index);
+
+	/*
+	 * Release and reacquire the FIFO so we
+	 * have a clean slate.
+	 */
+	ahd_outb(ahd, DFFSXFRCTL, CLRCHN);
+	wait = 1000;
+	do {
+		ahd_delay(100);
+	} while (--wait && !(ahd_inb(ahd, MDFFSTAT) & FIFOFREE));
+	if (wait == 0) {
+		ahd_print_path(ahd, scb);
+		printf("ahd_reinitialize_dataptrs: Forcing FIFO free.\n");
+		ahd_outb(ahd, DFFSXFRCTL, RSTCHN|CLRSHCNT);
+	}
+	saved_modes = ahd_save_modes(ahd);
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+	ahd_outb(ahd, DFFSTAT,
+		 ahd_inb(ahd, DFFSTAT)
+		| (saved_modes == 0x11 ? CURRFIFO_1 : CURRFIFO_0));
+
+	/*
+	 * Determine initial values for data_addr and data_cnt
+	 * for resuming the data phase.
+	 */
+	sgptr = (ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR + 3) << 24)
+	      | (ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR + 2) << 16)
+	      | (ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR + 1) << 8)
+	      |	ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR);
+	sgptr &= SG_PTR_MASK;
+
+	resid = (ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT + 2) << 16)
+	      | (ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT + 1) << 8)
+	      | ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT);
+
+	if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
+		struct ahd_dma64_seg *sg;
+
+		sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
+
+		/* The residual sg_ptr always points to the next sg */
+		sg--;
+
+		dataptr = ahd_le64toh(sg->addr)
+			+ (ahd_le32toh(sg->len) & AHD_SG_LEN_MASK)
+			- resid;
+		ahd_outb(ahd, HADDR + 7, dataptr >> 56);
+		ahd_outb(ahd, HADDR + 6, dataptr >> 48);
+		ahd_outb(ahd, HADDR + 5, dataptr >> 40);
+		ahd_outb(ahd, HADDR + 4, dataptr >> 32);
+	} else {
+		struct	 ahd_dma_seg *sg;
+
+		sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
+
+		/* The residual sg_ptr always points to the next sg */
+		sg--;
+
+		dataptr = ahd_le32toh(sg->addr)
+			+ (ahd_le32toh(sg->len) & AHD_SG_LEN_MASK)
+			- resid;
+		ahd_outb(ahd, HADDR + 4,
+			 (ahd_le32toh(sg->len) & ~AHD_SG_LEN_MASK) >> 24);
+	}
+	ahd_outb(ahd, HADDR + 3, dataptr >> 24);
+	ahd_outb(ahd, HADDR + 2, dataptr >> 16);
+	ahd_outb(ahd, HADDR + 1, dataptr >> 8);
+	ahd_outb(ahd, HADDR, dataptr);
+	ahd_outb(ahd, HCNT + 2, resid >> 16);
+	ahd_outb(ahd, HCNT + 1, resid >> 8);
+	ahd_outb(ahd, HCNT, resid);
+}
+
+/*
+ * Handle the effects of issuing a bus device reset message.
+ */
+static void
+ahd_handle_devreset(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
+		    cam_status status, char *message, int verbose_level)
+{
+#ifdef AHD_TARGET_MODE
+	struct ahd_tmode_tstate* tstate;
+	u_int lun;
+#endif
+	int found;
+
+	found = ahd_abort_scbs(ahd, devinfo->target, devinfo->channel,
+			       CAM_LUN_WILDCARD, SCB_LIST_NULL, devinfo->role,
+			       status);
+
+#ifdef AHD_TARGET_MODE
+	/*
+	 * Send an immediate notify ccb to all target mord peripheral
+	 * drivers affected by this action.
+	 */
+	tstate = ahd->enabled_targets[devinfo->our_scsiid];
+	if (tstate != NULL) {
+		for (lun = 0; lun < AHD_NUM_LUNS; lun++) {
+			struct ahd_tmode_lstate* lstate;
+
+			lstate = tstate->enabled_luns[lun];
+			if (lstate == NULL)
+				continue;
+
+			ahd_queue_lstate_event(ahd, lstate, devinfo->our_scsiid,
+					       MSG_BUS_DEV_RESET, /*arg*/0);
+			ahd_send_lstate_events(ahd, lstate);
+		}
+	}
+#endif
+
+	/*
+	 * Go back to async/narrow transfers and renegotiate.
+	 */
+	ahd_set_width(ahd, devinfo, MSG_EXT_WDTR_BUS_8_BIT,
+		      AHD_TRANS_CUR, /*paused*/TRUE);
+	ahd_set_syncrate(ahd, devinfo, /*period*/0, /*offset*/0,
+			 /*ppr_options*/0, AHD_TRANS_CUR, /*paused*/TRUE);
+	
+	ahd_send_async(ahd, devinfo->channel, devinfo->target,
+		       CAM_LUN_WILDCARD, AC_SENT_BDR, NULL);
+
+	if (message != NULL
+	 && (verbose_level <= bootverbose))
+		printf("%s: %s on %c:%d. %d SCBs aborted\n", ahd_name(ahd),
+		       message, devinfo->channel, devinfo->target, found);
+}
+
+#ifdef AHD_TARGET_MODE
+static void
+ahd_setup_target_msgin(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
+		       struct scb *scb)
+{
+
+	/*              
+	 * To facilitate adding multiple messages together,
+	 * each routine should increment the index and len
+	 * variables instead of setting them explicitly.
+	 */             
+	ahd->msgout_index = 0;
+	ahd->msgout_len = 0;
+
+	if (scb != NULL && (scb->flags & SCB_AUTO_NEGOTIATE) != 0)
+		ahd_build_transfer_msg(ahd, devinfo);
+	else
+		panic("ahd_intr: AWAITING target message with no message");
+
+	ahd->msgout_index = 0;
+	ahd->msg_type = MSG_TYPE_TARGET_MSGIN;
+}
+#endif
+/**************************** Initialization **********************************/
+static u_int
+ahd_sglist_size(struct ahd_softc *ahd)
+{
+	bus_size_t list_size;
+
+	list_size = sizeof(struct ahd_dma_seg) * AHD_NSEG;
+	if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
+		list_size = sizeof(struct ahd_dma64_seg) * AHD_NSEG;
+	return (list_size);
+}
+
+/*
+ * Calculate the optimum S/G List allocation size.  S/G elements used
+ * for a given transaction must be physically contiguous.  Assume the
+ * OS will allocate full pages to us, so it doesn't make sense to request
+ * less than a page.
+ */
+static u_int
+ahd_sglist_allocsize(struct ahd_softc *ahd)
+{
+	bus_size_t sg_list_increment;
+	bus_size_t sg_list_size;
+	bus_size_t max_list_size;
+	bus_size_t best_list_size;
+
+	/* Start out with the minimum required for AHD_NSEG. */
+	sg_list_increment = ahd_sglist_size(ahd);
+	sg_list_size = sg_list_increment;
+
+	/* Get us as close as possible to a page in size. */
+	while ((sg_list_size + sg_list_increment) <= PAGE_SIZE)
+		sg_list_size += sg_list_increment;
+
+	/*
+	 * Try to reduce the amount of wastage by allocating
+	 * multiple pages.
+	 */
+	best_list_size = sg_list_size;
+	max_list_size = roundup(sg_list_increment, PAGE_SIZE);
+	if (max_list_size < 4 * PAGE_SIZE)
+		max_list_size = 4 * PAGE_SIZE;
+	if (max_list_size > (AHD_SCB_MAX_ALLOC * sg_list_increment))
+		max_list_size = (AHD_SCB_MAX_ALLOC * sg_list_increment);
+	while ((sg_list_size + sg_list_increment) <= max_list_size
+	   &&  (sg_list_size % PAGE_SIZE) != 0) {
+		bus_size_t new_mod;
+		bus_size_t best_mod;
+
+		sg_list_size += sg_list_increment;
+		new_mod = sg_list_size % PAGE_SIZE;
+		best_mod = best_list_size % PAGE_SIZE;
+		if (new_mod > best_mod || new_mod == 0) {
+			best_list_size = sg_list_size;
+		}
+	}
+	return (best_list_size);
+}
+
+/*
+ * Allocate a controller structure for a new device
+ * and perform initial initializion.
+ */
+struct ahd_softc *
+ahd_alloc(void *platform_arg, char *name)
+{
+	struct  ahd_softc *ahd;
+
+#ifndef	__FreeBSD__
+	ahd = malloc(sizeof(*ahd), M_DEVBUF, M_NOWAIT);
+	if (!ahd) {
+		printf("aic7xxx: cannot malloc softc!\n");
+		free(name, M_DEVBUF);
+		return NULL;
+	}
+#else
+	ahd = device_get_softc((device_t)platform_arg);
+#endif
+	memset(ahd, 0, sizeof(*ahd));
+	ahd->seep_config = malloc(sizeof(*ahd->seep_config),
+				  M_DEVBUF, M_NOWAIT);
+	if (ahd->seep_config == NULL) {
+#ifndef	__FreeBSD__
+		free(ahd, M_DEVBUF);
+#endif
+		free(name, M_DEVBUF);
+		return (NULL);
+	}
+	LIST_INIT(&ahd->pending_scbs);
+	/* We don't know our unit number until the OSM sets it */
+	ahd->name = name;
+	ahd->unit = -1;
+	ahd->description = NULL;
+	ahd->bus_description = NULL;
+	ahd->channel = 'A';
+	ahd->chip = AHD_NONE;
+	ahd->features = AHD_FENONE;
+	ahd->bugs = AHD_BUGNONE;
+	ahd->flags = AHD_SPCHK_ENB_A|AHD_RESET_BUS_A|AHD_TERM_ENB_A
+		   | AHD_EXTENDED_TRANS_A|AHD_STPWLEVEL_A;
+	ahd_timer_init(&ahd->reset_timer);
+	ahd_timer_init(&ahd->stat_timer);
+	ahd->int_coalessing_timer = AHD_INT_COALESSING_TIMER_DEFAULT;
+	ahd->int_coalessing_maxcmds = AHD_INT_COALESSING_MAXCMDS_DEFAULT;
+	ahd->int_coalessing_mincmds = AHD_INT_COALESSING_MINCMDS_DEFAULT;
+	ahd->int_coalessing_threshold = AHD_INT_COALESSING_THRESHOLD_DEFAULT;
+	ahd->int_coalessing_stop_threshold =
+	    AHD_INT_COALESSING_STOP_THRESHOLD_DEFAULT;
+
+	if (ahd_platform_alloc(ahd, platform_arg) != 0) {
+		ahd_free(ahd);
+		ahd = NULL;
+	}
+#ifdef AHD_DEBUG
+	if ((ahd_debug & AHD_SHOW_MEMORY) != 0) {
+		printf("%s: scb size = 0x%x, hscb size = 0x%x\n",
+		       ahd_name(ahd), (u_int)sizeof(struct scb),
+		       (u_int)sizeof(struct hardware_scb));
+	}
+#endif
+	return (ahd);
+}
+
+int
+ahd_softc_init(struct ahd_softc *ahd)
+{
+
+	ahd->unpause = 0;
+	ahd->pause = PAUSE; 
+	return (0);
+}
+
+void
+ahd_softc_insert(struct ahd_softc *ahd)
+{
+	struct ahd_softc *list_ahd;
+
+#if AHD_PCI_CONFIG > 0
+	/*
+	 * Second Function PCI devices need to inherit some
+	 * settings from function 0.
+	 */
+	if ((ahd->features & AHD_MULTI_FUNC) != 0) {
+		TAILQ_FOREACH(list_ahd, &ahd_tailq, links) {
+			ahd_dev_softc_t list_pci;
+			ahd_dev_softc_t pci;
+
+			list_pci = list_ahd->dev_softc;
+			pci = ahd->dev_softc;
+			if (ahd_get_pci_slot(list_pci) == ahd_get_pci_slot(pci)
+			 && ahd_get_pci_bus(list_pci) == ahd_get_pci_bus(pci)) {
+				struct ahd_softc *master;
+				struct ahd_softc *slave;
+
+				if (ahd_get_pci_function(list_pci) == 0) {
+					master = list_ahd;
+					slave = ahd;
+				} else {
+					master = ahd;
+					slave = list_ahd;
+				}
+				slave->flags &= ~AHD_BIOS_ENABLED; 
+				slave->flags |=
+				    master->flags & AHD_BIOS_ENABLED;
+				slave->flags &= ~AHD_PRIMARY_CHANNEL; 
+				slave->flags |=
+				    master->flags & AHD_PRIMARY_CHANNEL;
+				break;
+			}
+		}
+	}
+#endif
+
+	/*
+	 * Insertion sort into our list of softcs.
+	 */
+	list_ahd = TAILQ_FIRST(&ahd_tailq);
+	while (list_ahd != NULL
+	    && ahd_softc_comp(list_ahd, ahd) <= 0)
+		list_ahd = TAILQ_NEXT(list_ahd, links);
+	if (list_ahd != NULL)
+		TAILQ_INSERT_BEFORE(list_ahd, ahd, links);
+	else
+		TAILQ_INSERT_TAIL(&ahd_tailq, ahd, links);
+	ahd->init_level++;
+}
+
+/*
+ * Verify that the passed in softc pointer is for a
+ * controller that is still configured.
+ */
+struct ahd_softc *
+ahd_find_softc(struct ahd_softc *ahd)
+{
+	struct ahd_softc *list_ahd;
+
+	TAILQ_FOREACH(list_ahd, &ahd_tailq, links) {
+		if (list_ahd == ahd)
+			return (ahd);
+	}
+	return (NULL);
+}
+
+void
+ahd_set_unit(struct ahd_softc *ahd, int unit)
+{
+	ahd->unit = unit;
+}
+
+void
+ahd_set_name(struct ahd_softc *ahd, char *name)
+{
+	if (ahd->name != NULL)
+		free(ahd->name, M_DEVBUF);
+	ahd->name = name;
+}
+
+void
+ahd_free(struct ahd_softc *ahd)
+{
+	int i;
+
+	ahd_fini_scbdata(ahd);
+	switch (ahd->init_level) {
+	default:
+	case 5:
+		ahd_shutdown(ahd);
+		TAILQ_REMOVE(&ahd_tailq, ahd, links);
+		/* FALLTHROUGH */
+	case 4:
+		ahd_dmamap_unload(ahd, ahd->shared_data_dmat,
+				  ahd->shared_data_dmamap);
+		/* FALLTHROUGH */
+	case 3:
+		ahd_dmamem_free(ahd, ahd->shared_data_dmat, ahd->qoutfifo,
+				ahd->shared_data_dmamap);
+		ahd_dmamap_destroy(ahd, ahd->shared_data_dmat,
+				   ahd->shared_data_dmamap);
+		/* FALLTHROUGH */
+	case 2:
+		ahd_dma_tag_destroy(ahd, ahd->shared_data_dmat);
+	case 1:
+#ifndef __linux__
+		ahd_dma_tag_destroy(ahd, ahd->buffer_dmat);
+#endif
+		break;
+	case 0:
+		break;
+	}
+
+#ifndef __linux__
+	ahd_dma_tag_destroy(ahd, ahd->parent_dmat);
+#endif
+	ahd_platform_free(ahd);
+	for (i = 0; i < AHD_NUM_TARGETS; i++) {
+		struct ahd_tmode_tstate *tstate;
+
+		tstate = ahd->enabled_targets[i];
+		if (tstate != NULL) {
+#if AHD_TARGET_MODE
+			int j;
+
+			for (j = 0; j < AHD_NUM_LUNS; j++) {
+				struct ahd_tmode_lstate *lstate;
+
+				lstate = tstate->enabled_luns[j];
+				if (lstate != NULL) {
+					xpt_free_path(lstate->path);
+					free(lstate, M_DEVBUF);
+				}
+			}
+#endif
+			free(tstate, M_DEVBUF);
+		}
+	}
+#if AHD_TARGET_MODE
+	if (ahd->black_hole != NULL) {
+		xpt_free_path(ahd->black_hole->path);
+		free(ahd->black_hole, M_DEVBUF);
+	}
+#endif
+	if (ahd->name != NULL)
+		free(ahd->name, M_DEVBUF);
+	if (ahd->seep_config != NULL)
+		free(ahd->seep_config, M_DEVBUF);
+	if (ahd->saved_stack != NULL)
+		free(ahd->saved_stack, M_DEVBUF);
+#ifndef __FreeBSD__
+	free(ahd, M_DEVBUF);
+#endif
+	return;
+}
+
+void
+ahd_shutdown(void *arg)
+{
+	struct	ahd_softc *ahd;
+
+	ahd = (struct ahd_softc *)arg;
+
+	/*
+	 * Stop periodic timer callbacks.
+	 */
+	ahd_timer_stop(&ahd->reset_timer);
+	ahd_timer_stop(&ahd->stat_timer);
+
+	/* This will reset most registers to 0, but not all */
+	ahd_reset(ahd);
+}
+
+/*
+ * Reset the controller and record some information about it
+ * that is only available just after a reset.
+ */
+int
+ahd_reset(struct ahd_softc *ahd)
+{
+	u_int	 sxfrctl1;
+	int	 wait;
+	uint32_t cmd;
+	
+	/*
+	 * Preserve the value of the SXFRCTL1 register for all channels.
+	 * It contains settings that affect termination and we don't want
+	 * to disturb the integrity of the bus.
+	 */
+	ahd_pause(ahd);
+	sxfrctl1 = ahd_inb(ahd, SXFRCTL1);
+
+	cmd = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2);
+	if ((ahd->bugs & AHD_PCIX_CHIPRST_BUG) != 0) {
+		uint32_t mod_cmd;
+
+		/*
+		 * A4 Razor #632
+		 * During the assertion of CHIPRST, the chip
+		 * does not disable its parity logic prior to
+		 * the start of the reset.  This may cause a
+		 * parity error to be detected and thus a
+		 * spurious SERR or PERR assertion.  Disble
+		 * PERR and SERR responses during the CHIPRST.
+		 */
+		mod_cmd = cmd & ~(PCIM_CMD_PERRESPEN|PCIM_CMD_SERRESPEN);
+		ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
+				     mod_cmd, /*bytes*/2);
+	}
+	ahd_outb(ahd, HCNTRL, CHIPRST | ahd->pause);
+
+	/*
+	 * Ensure that the reset has finished.  We delay 1000us
+	 * prior to reading the register to make sure the chip
+	 * has sufficiently completed its reset to handle register
+	 * accesses.
+	 */
+	wait = 1000;
+	do {
+		ahd_delay(1000);
+	} while (--wait && !(ahd_inb(ahd, HCNTRL) & CHIPRSTACK));
+
+	if (wait == 0) {
+		printf("%s: WARNING - Failed chip reset!  "
+		       "Trying to initialize anyway.\n", ahd_name(ahd));
+	}
+	ahd_outb(ahd, HCNTRL, ahd->pause);
+
+	if ((ahd->bugs & AHD_PCIX_CHIPRST_BUG) != 0) {
+		/*
+		 * Clear any latched PCI error status and restore
+		 * previous SERR and PERR response enables.
+		 */
+		ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
+				     0xFF, /*bytes*/1);
+		ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
+				     cmd, /*bytes*/2);
+	}
+	/* After a reset, we know the state of the mode register. */
+	ahd_known_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+
+	/* Determine chip configuration */
+	ahd->features &= ~AHD_WIDE;
+	if ((ahd_inb(ahd, SBLKCTL) & SELWIDE) != 0)
+		ahd->features |= AHD_WIDE;
+
+	/*
+	 * Restore SXFRCTL1.
+	 *
+	 * We must always initialize STPWEN to 1 before we
+	 * restore the saved values.  STPWEN is initialized
+	 * to a tri-state condition which can only be cleared
+	 * by turning it on.
+	 */
+	ahd_outb(ahd, SXFRCTL1, sxfrctl1|STPWEN);
+	ahd_outb(ahd, SXFRCTL1, sxfrctl1);
+
+	/*
+	 * If a recovery action has forced a chip reset,
+	 * re-initialize the chip to our likeing.
+	 */
+	if (ahd->init_level > 0)
+		ahd_chip_init(ahd);
+
+	return (0);
+}
+
+/*
+ * Determine the number of SCBs available on the controller
+ */
+int
+ahd_probe_scbs(struct ahd_softc *ahd) {
+	int i;
+
+	AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
+			 ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK));
+	for (i = 0; i < AHD_SCB_MAX; i++) {
+		int j;
+
+		ahd_set_scbptr(ahd, i);
+		ahd_outw(ahd, SCB_BASE, i);
+		for (j = 2; j < 64; j++)
+			ahd_outb(ahd, SCB_BASE+j, 0);
+		/* Start out life as unallocated (needing an abort) */
+		ahd_outb(ahd, SCB_CONTROL, MK_MESSAGE);
+		if (ahd_inw_scbram(ahd, SCB_BASE) != i)
+			break;
+		ahd_set_scbptr(ahd, 0);
+		if (ahd_inw_scbram(ahd, SCB_BASE) != 0)
+			break;
+	}
+	return (i);
+}
+
+static void
+ahd_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error) 
+{
+	bus_addr_t *baddr;
+
+	baddr = (bus_addr_t *)arg;
+	*baddr = segs->ds_addr;
+}
+
+static void
+ahd_initialize_hscbs(struct ahd_softc *ahd)
+{
+	int i;
+
+	for (i = 0; i < ahd->scb_data.maxhscbs; i++) {
+		ahd_set_scbptr(ahd, i);
+
+		/* Clear the control byte. */
+		ahd_outb(ahd, SCB_CONTROL, 0);
+
+		/* Set the next pointer */
+		ahd_outw(ahd, SCB_NEXT, SCB_LIST_NULL);
+	}
+}
+
+static int
+ahd_init_scbdata(struct ahd_softc *ahd)
+{
+	struct	scb_data *scb_data;
+	int	i;
+
+	scb_data = &ahd->scb_data;
+	TAILQ_INIT(&scb_data->free_scbs);
+	for (i = 0; i < AHD_NUM_TARGETS * AHD_NUM_LUNS_NONPKT; i++)
+		LIST_INIT(&scb_data->free_scb_lists[i]);
+	LIST_INIT(&scb_data->any_dev_free_scb_list);
+	SLIST_INIT(&scb_data->hscb_maps);
+	SLIST_INIT(&scb_data->sg_maps);
+	SLIST_INIT(&scb_data->sense_maps);
+
+	/* Determine the number of hardware SCBs and initialize them */
+	scb_data->maxhscbs = ahd_probe_scbs(ahd);
+	if (scb_data->maxhscbs == 0) {
+		printf("%s: No SCB space found\n", ahd_name(ahd));
+		return (ENXIO);
+	}
+
+	ahd_initialize_hscbs(ahd);
+
+	/*
+	 * Create our DMA tags.  These tags define the kinds of device
+	 * accessible memory allocations and memory mappings we will
+	 * need to perform during normal operation.
+	 *
+	 * Unless we need to further restrict the allocation, we rely
+	 * on the restrictions of the parent dmat, hence the common
+	 * use of MAXADDR and MAXSIZE.
+	 */
+
+	/* DMA tag for our hardware scb structures */
+	if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
+			       /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
+			       /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
+			       /*highaddr*/BUS_SPACE_MAXADDR,
+			       /*filter*/NULL, /*filterarg*/NULL,
+			       PAGE_SIZE, /*nsegments*/1,
+			       /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
+			       /*flags*/0, &scb_data->hscb_dmat) != 0) {
+		goto error_exit;
+	}
+
+	scb_data->init_level++;
+
+	/* DMA tag for our S/G structures. */
+	if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
+			       /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
+			       /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
+			       /*highaddr*/BUS_SPACE_MAXADDR,
+			       /*filter*/NULL, /*filterarg*/NULL,
+			       ahd_sglist_allocsize(ahd), /*nsegments*/1,
+			       /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
+			       /*flags*/0, &scb_data->sg_dmat) != 0) {
+		goto error_exit;
+	}
+#ifdef AHD_DEBUG
+	if ((ahd_debug & AHD_SHOW_MEMORY) != 0)
+		printf("%s: ahd_sglist_allocsize = 0x%x\n", ahd_name(ahd),
+		       ahd_sglist_allocsize(ahd));
+#endif
+
+	scb_data->init_level++;
+
+	/* DMA tag for our sense buffers.  We allocate in page sized chunks */
+	if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
+			       /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
+			       /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
+			       /*highaddr*/BUS_SPACE_MAXADDR,
+			       /*filter*/NULL, /*filterarg*/NULL,
+			       PAGE_SIZE, /*nsegments*/1,
+			       /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
+			       /*flags*/0, &scb_data->sense_dmat) != 0) {
+		goto error_exit;
+	}
+
+	scb_data->init_level++;
+
+	/* Perform initial CCB allocation */
+	ahd_alloc_scbs(ahd);
+
+	if (scb_data->numscbs == 0) {
+		printf("%s: ahd_init_scbdata - "
+		       "Unable to allocate initial scbs\n",
+		       ahd_name(ahd));
+		goto error_exit;
+	}
+
+	/*
+	 * Note that we were successfull
+	 */
+	return (0); 
+
+error_exit:
+
+	return (ENOMEM);
+}
+
+static struct scb *
+ahd_find_scb_by_tag(struct ahd_softc *ahd, u_int tag)
+{
+	struct scb *scb;
+
+	/*
+	 * Look on the pending list.
+	 */
+	LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
+		if (SCB_GET_TAG(scb) == tag)
+			return (scb);
+	}
+
+	/*
+	 * Then on all of the collision free lists.
+	 */
+	TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) {
+		struct scb *list_scb;
+
+		list_scb = scb;
+		do {
+			if (SCB_GET_TAG(list_scb) == tag)
+				return (list_scb);
+			list_scb = LIST_NEXT(list_scb, collision_links);
+		} while (list_scb);
+	}
+
+	/*
+	 * And finally on the generic free list.
+	 */
+	LIST_FOREACH(scb, &ahd->scb_data.any_dev_free_scb_list, links.le) {
+		if (SCB_GET_TAG(scb) == tag)
+			return (scb);
+	}
+
+	return (NULL);
+}
+
+static void
+ahd_fini_scbdata(struct ahd_softc *ahd)
+{
+	struct scb_data *scb_data;
+
+	scb_data = &ahd->scb_data;
+	if (scb_data == NULL)
+		return;
+
+	switch (scb_data->init_level) {
+	default:
+	case 7:
+	{
+		struct map_node *sns_map;
+
+		while ((sns_map = SLIST_FIRST(&scb_data->sense_maps)) != NULL) {
+			SLIST_REMOVE_HEAD(&scb_data->sense_maps, links);
+			ahd_dmamap_unload(ahd, scb_data->sense_dmat,
+					  sns_map->dmamap);
+			ahd_dmamem_free(ahd, scb_data->sense_dmat,
+					sns_map->vaddr, sns_map->dmamap);
+			free(sns_map, M_DEVBUF);
+		}
+		ahd_dma_tag_destroy(ahd, scb_data->sense_dmat);
+		/* FALLTHROUGH */
+	}
+	case 6:
+	{
+		struct map_node *sg_map;
+
+		while ((sg_map = SLIST_FIRST(&scb_data->sg_maps)) != NULL) {
+			SLIST_REMOVE_HEAD(&scb_data->sg_maps, links);
+			ahd_dmamap_unload(ahd, scb_data->sg_dmat,
+					  sg_map->dmamap);
+			ahd_dmamem_free(ahd, scb_data->sg_dmat,
+					sg_map->vaddr, sg_map->dmamap);
+			free(sg_map, M_DEVBUF);
+		}
+		ahd_dma_tag_destroy(ahd, scb_data->sg_dmat);
+		/* FALLTHROUGH */
+	}
+	case 5:
+	{
+		struct map_node *hscb_map;
+
+		while ((hscb_map = SLIST_FIRST(&scb_data->hscb_maps)) != NULL) {
+			SLIST_REMOVE_HEAD(&scb_data->hscb_maps, links);
+			ahd_dmamap_unload(ahd, scb_data->hscb_dmat,
+					  hscb_map->dmamap);
+			ahd_dmamem_free(ahd, scb_data->hscb_dmat,
+					hscb_map->vaddr, hscb_map->dmamap);
+			free(hscb_map, M_DEVBUF);
+		}
+		ahd_dma_tag_destroy(ahd, scb_data->hscb_dmat);
+		/* FALLTHROUGH */
+	}
+	case 4:
+	case 3:
+	case 2:
+	case 1:
+	case 0:
+		break;
+	}
+}
+
+/*
+ * DSP filter Bypass must be enabled until the first selection
+ * after a change in bus mode (Razor #491 and #493).
+ */
+static void
+ahd_setup_iocell_workaround(struct ahd_softc *ahd)
+{
+	ahd_mode_state saved_modes;
+
+	saved_modes = ahd_save_modes(ahd);
+	ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
+	ahd_outb(ahd, DSPDATACTL, ahd_inb(ahd, DSPDATACTL)
+	       | BYPASSENAB | RCVROFFSTDIS | XMITOFFSTDIS);
+	ahd_outb(ahd, SIMODE0, ahd_inb(ahd, SIMODE0) | (ENSELDO|ENSELDI));
+#ifdef AHD_DEBUG
+	if ((ahd_debug & AHD_SHOW_MISC) != 0)
+		printf("%s: Setting up iocell workaround\n", ahd_name(ahd));
+#endif
+	ahd_restore_modes(ahd, saved_modes);
+}
+
+static void
+ahd_iocell_first_selection(struct ahd_softc *ahd)
+{
+	ahd_mode_state	saved_modes;
+	u_int		sblkctl;
+
+	saved_modes = ahd_save_modes(ahd);
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+	sblkctl = ahd_inb(ahd, SBLKCTL);
+	ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
+#ifdef AHD_DEBUG
+	if ((ahd_debug & AHD_SHOW_MISC) != 0)
+		printf("%s: iocell first selection\n", ahd_name(ahd));
+#endif
+	if ((sblkctl & ENAB40) != 0) {
+		ahd_outb(ahd, DSPDATACTL,
+			 ahd_inb(ahd, DSPDATACTL) & ~BYPASSENAB);
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_MISC) != 0)
+			printf("%s: BYPASS now disabled\n", ahd_name(ahd));
+#endif
+	}
+	ahd_outb(ahd, SIMODE0, ahd_inb(ahd, SIMODE0) & ~(ENSELDO|ENSELDI));
+	ahd_outb(ahd, CLRINT, CLRSCSIINT);
+	ahd_restore_modes(ahd, saved_modes);
+}
+
+/*************************** SCB Management ***********************************/
+static void
+ahd_add_col_list(struct ahd_softc *ahd, struct scb *scb, u_int col_idx)
+{
+	struct	scb_list *free_list;
+	struct	scb_tailq *free_tailq;
+	struct	scb *first_scb;
+
+	scb->flags |= SCB_ON_COL_LIST;
+	AHD_SET_SCB_COL_IDX(scb, col_idx);
+	free_list = &ahd->scb_data.free_scb_lists[col_idx];
+	free_tailq = &ahd->scb_data.free_scbs;
+	first_scb = LIST_FIRST(free_list);
+	if (first_scb != NULL) {
+		LIST_INSERT_AFTER(first_scb, scb, collision_links);
+	} else {
+		LIST_INSERT_HEAD(free_list, scb, collision_links);
+		TAILQ_INSERT_TAIL(free_tailq, scb, links.tqe);
+	}
+}
+
+static void
+ahd_rem_col_list(struct ahd_softc *ahd, struct scb *scb)
+{
+	struct	scb_list *free_list;
+	struct	scb_tailq *free_tailq;
+	struct	scb *first_scb;
+	u_int	col_idx;
+
+	scb->flags &= ~SCB_ON_COL_LIST;
+	col_idx = AHD_GET_SCB_COL_IDX(ahd, scb);
+	free_list = &ahd->scb_data.free_scb_lists[col_idx];
+	free_tailq = &ahd->scb_data.free_scbs;
+	first_scb = LIST_FIRST(free_list);
+	if (first_scb == scb) {
+		struct scb *next_scb;
+
+		/*
+		 * Maintain order in the collision free
+		 * lists for fairness if this device has
+		 * other colliding tags active.
+		 */
+		next_scb = LIST_NEXT(scb, collision_links);
+		if (next_scb != NULL) {
+			TAILQ_INSERT_AFTER(free_tailq, scb,
+					   next_scb, links.tqe);
+		}
+		TAILQ_REMOVE(free_tailq, scb, links.tqe);
+	}
+	LIST_REMOVE(scb, collision_links);
+}
+
+/*
+ * Get a free scb. If there are none, see if we can allocate a new SCB.
+ */
+struct scb *
+ahd_get_scb(struct ahd_softc *ahd, u_int col_idx)
+{
+	struct scb *scb;
+	int tries;
+
+	tries = 0;
+look_again:
+	TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) {
+		if (AHD_GET_SCB_COL_IDX(ahd, scb) != col_idx) {
+			ahd_rem_col_list(ahd, scb);
+			goto found;
+		}
+	}
+	if ((scb = LIST_FIRST(&ahd->scb_data.any_dev_free_scb_list)) == NULL) {
+
+		if (tries++ != 0)
+			return (NULL);
+		ahd_alloc_scbs(ahd);
+		goto look_again;
+	}
+	LIST_REMOVE(scb, links.le);
+	if (col_idx != AHD_NEVER_COL_IDX
+	 && (scb->col_scb != NULL)
+	 && (scb->col_scb->flags & SCB_ACTIVE) == 0) {
+		LIST_REMOVE(scb->col_scb, links.le);
+		ahd_add_col_list(ahd, scb->col_scb, col_idx);
+	}
+found:
+	scb->flags |= SCB_ACTIVE;
+	return (scb);
+}
+
+/*
+ * Return an SCB resource to the free list.
+ */
+void
+ahd_free_scb(struct ahd_softc *ahd, struct scb *scb)
+{       
+
+	/* Clean up for the next user */
+	scb->flags = SCB_FLAG_NONE;
+	scb->hscb->control = 0;
+	ahd->scb_data.scbindex[scb->hscb->tag] = NULL;
+
+	if (scb->col_scb == NULL) {
+
+		/*
+		 * No collision possible.  Just free normally.
+		 */
+		LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
+				 scb, links.le);
+	} else if ((scb->col_scb->flags & SCB_ON_COL_LIST) != 0) {
+
+		/*
+		 * The SCB we might have collided with is on
+		 * a free collision list.  Put both SCBs on
+		 * the generic list.
+		 */
+		ahd_rem_col_list(ahd, scb->col_scb);
+		LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
+				 scb, links.le);
+		LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
+				 scb->col_scb, links.le);
+	} else if ((scb->col_scb->flags
+		  & (SCB_PACKETIZED|SCB_ACTIVE)) == SCB_ACTIVE
+		&& (scb->col_scb->hscb->control & TAG_ENB) != 0) {
+
+		/*
+		 * The SCB we might collide with on the next allocation
+		 * is still active in a non-packetized, tagged, context.
+		 * Put us on the SCB collision list.
+		 */
+		ahd_add_col_list(ahd, scb,
+				 AHD_GET_SCB_COL_IDX(ahd, scb->col_scb));
+	} else {
+		/*
+		 * The SCB we might collide with on the next allocation
+		 * is either active in a packetized context, or free.
+		 * Since we can't collide, put this SCB on the generic
+		 * free list.
+		 */
+		LIST_INSERT_HEAD(&ahd->scb_data.any_dev_free_scb_list,
+				 scb, links.le);
+	}
+
+	ahd_platform_scb_free(ahd, scb);
+}
+
+void
+ahd_alloc_scbs(struct ahd_softc *ahd)
+{
+	struct scb_data *scb_data;
+	struct scb	*next_scb;
+	struct hardware_scb *hscb;
+	struct map_node *hscb_map;
+	struct map_node *sg_map;
+	struct map_node *sense_map;
+	uint8_t		*segs;
+	uint8_t		*sense_data;
+	bus_addr_t	 hscb_busaddr;
+	bus_addr_t	 sg_busaddr;
+	bus_addr_t	 sense_busaddr;
+	int		 newcount;
+	int		 i;
+
+	scb_data = &ahd->scb_data;
+	if (scb_data->numscbs >= AHD_SCB_MAX_ALLOC)
+		/* Can't allocate any more */
+		return;
+
+	if (scb_data->scbs_left != 0) {
+		int offset;
+
+		offset = (PAGE_SIZE / sizeof(*hscb)) - scb_data->scbs_left;
+		hscb_map = SLIST_FIRST(&scb_data->hscb_maps);
+		hscb = &((struct hardware_scb *)hscb_map->vaddr)[offset];
+		hscb_busaddr = hscb_map->physaddr + (offset * sizeof(*hscb));
+	} else {
+		hscb_map = malloc(sizeof(*hscb_map), M_DEVBUF, M_NOWAIT);
+
+		if (hscb_map == NULL)
+			return;
+
+		/* Allocate the next batch of hardware SCBs */
+		if (ahd_dmamem_alloc(ahd, scb_data->hscb_dmat,
+				     (void **)&hscb_map->vaddr,
+				     BUS_DMA_NOWAIT, &hscb_map->dmamap) != 0) {
+			free(hscb_map, M_DEVBUF);
+			return;
+		}
+
+		SLIST_INSERT_HEAD(&scb_data->hscb_maps, hscb_map, links);
+
+		ahd_dmamap_load(ahd, scb_data->hscb_dmat, hscb_map->dmamap,
+				hscb_map->vaddr, PAGE_SIZE, ahd_dmamap_cb,
+				&hscb_map->physaddr, /*flags*/0);
+
+		hscb = (struct hardware_scb *)hscb_map->vaddr;
+		hscb_busaddr = hscb_map->physaddr;
+		scb_data->scbs_left = PAGE_SIZE / sizeof(*hscb);
+	}
+
+	if (scb_data->sgs_left != 0) {
+		int offset;
+
+		offset = ahd_sglist_allocsize(ahd)
+		       - (scb_data->sgs_left * ahd_sglist_size(ahd));
+		sg_map = SLIST_FIRST(&scb_data->sg_maps);
+		segs = sg_map->vaddr + offset;
+		sg_busaddr = sg_map->physaddr + offset;
+	} else {
+		sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_NOWAIT);
+
+		if (sg_map == NULL)
+			return;
+
+		/* Allocate the next batch of S/G lists */
+		if (ahd_dmamem_alloc(ahd, scb_data->sg_dmat,
+				     (void **)&sg_map->vaddr,
+				     BUS_DMA_NOWAIT, &sg_map->dmamap) != 0) {
+			free(sg_map, M_DEVBUF);
+			return;
+		}
+
+		SLIST_INSERT_HEAD(&scb_data->sg_maps, sg_map, links);
+
+		ahd_dmamap_load(ahd, scb_data->sg_dmat, sg_map->dmamap,
+				sg_map->vaddr, ahd_sglist_allocsize(ahd),
+				ahd_dmamap_cb, &sg_map->physaddr, /*flags*/0);
+
+		segs = sg_map->vaddr;
+		sg_busaddr = sg_map->physaddr;
+		scb_data->sgs_left =
+		    ahd_sglist_allocsize(ahd) / ahd_sglist_size(ahd);
+#ifdef AHD_DEBUG
+		if (ahd_debug & AHD_SHOW_MEMORY)
+			printf("Mapped SG data\n");
+#endif
+	}
+
+	if (scb_data->sense_left != 0) {
+		int offset;
+
+		offset = PAGE_SIZE - (AHD_SENSE_BUFSIZE * scb_data->sense_left);
+		sense_map = SLIST_FIRST(&scb_data->sense_maps);
+		sense_data = sense_map->vaddr + offset;
+		sense_busaddr = sense_map->physaddr + offset;
+	} else {
+		sense_map = malloc(sizeof(*sense_map), M_DEVBUF, M_NOWAIT);
+
+		if (sense_map == NULL)
+			return;
+
+		/* Allocate the next batch of sense buffers */
+		if (ahd_dmamem_alloc(ahd, scb_data->sense_dmat,
+				     (void **)&sense_map->vaddr,
+				     BUS_DMA_NOWAIT, &sense_map->dmamap) != 0) {
+			free(sense_map, M_DEVBUF);
+			return;
+		}
+
+		SLIST_INSERT_HEAD(&scb_data->sense_maps, sense_map, links);
+
+		ahd_dmamap_load(ahd, scb_data->sense_dmat, sense_map->dmamap,
+				sense_map->vaddr, PAGE_SIZE, ahd_dmamap_cb,
+				&sense_map->physaddr, /*flags*/0);
+
+		sense_data = sense_map->vaddr;
+		sense_busaddr = sense_map->physaddr;
+		scb_data->sense_left = PAGE_SIZE / AHD_SENSE_BUFSIZE;
+#ifdef AHD_DEBUG
+		if (ahd_debug & AHD_SHOW_MEMORY)
+			printf("Mapped sense data\n");
+#endif
+	}
+
+	newcount = MIN(scb_data->sense_left, scb_data->scbs_left);
+	newcount = MIN(newcount, scb_data->sgs_left);
+	newcount = MIN(newcount, (AHD_SCB_MAX_ALLOC - scb_data->numscbs));
+	scb_data->sense_left -= newcount;
+	scb_data->scbs_left -= newcount;
+	scb_data->sgs_left -= newcount;
+	for (i = 0; i < newcount; i++) {
+		u_int col_tag;
+
+		struct scb_platform_data *pdata;
+#ifndef __linux__
+		int error;
+#endif
+		next_scb = (struct scb *)malloc(sizeof(*next_scb),
+						M_DEVBUF, M_NOWAIT);
+		if (next_scb == NULL)
+			break;
+
+		pdata = (struct scb_platform_data *)malloc(sizeof(*pdata),
+							   M_DEVBUF, M_NOWAIT);
+		if (pdata == NULL) {
+			free(next_scb, M_DEVBUF);
+			break;
+		}
+		next_scb->platform_data = pdata;
+		next_scb->hscb_map = hscb_map;
+		next_scb->sg_map = sg_map;
+		next_scb->sense_map = sense_map;
+		next_scb->sg_list = segs;
+		next_scb->sense_data = sense_data;
+		next_scb->sense_busaddr = sense_busaddr;
+		next_scb->hscb = hscb;
+		hscb->hscb_busaddr = ahd_htole32(hscb_busaddr);
+
+		/*
+		 * The sequencer always starts with the second entry.
+		 * The first entry is embedded in the scb.
+		 */
+		next_scb->sg_list_busaddr = sg_busaddr;
+		if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
+			next_scb->sg_list_busaddr
+			    += sizeof(struct ahd_dma64_seg);
+		else
+			next_scb->sg_list_busaddr += sizeof(struct ahd_dma_seg);
+		next_scb->ahd_softc = ahd;
+		next_scb->flags = SCB_FLAG_NONE;
+#ifndef __linux__
+		error = ahd_dmamap_create(ahd, ahd->buffer_dmat, /*flags*/0,
+					  &next_scb->dmamap);
+		if (error != 0) {
+			free(next_scb, M_DEVBUF);
+			free(pdata, M_DEVBUF);
+			break;
+		}
+#endif
+		next_scb->hscb->tag = ahd_htole16(scb_data->numscbs);
+		col_tag = scb_data->numscbs ^ 0x100;
+		next_scb->col_scb = ahd_find_scb_by_tag(ahd, col_tag);
+		if (next_scb->col_scb != NULL)
+			next_scb->col_scb->col_scb = next_scb;
+		ahd_free_scb(ahd, next_scb);
+		hscb++;
+		hscb_busaddr += sizeof(*hscb);
+		segs += ahd_sglist_size(ahd);
+		sg_busaddr += ahd_sglist_size(ahd);
+		sense_data += AHD_SENSE_BUFSIZE;
+		sense_busaddr += AHD_SENSE_BUFSIZE;
+		scb_data->numscbs++;
+	}
+}
+
+void
+ahd_controller_info(struct ahd_softc *ahd, char *buf)
+{
+	const char *speed;
+	const char *type;
+	int len;
+
+	len = sprintf(buf, "%s: ", ahd_chip_names[ahd->chip & AHD_CHIPID_MASK]);
+	buf += len;
+
+	speed = "Ultra320 ";
+	if ((ahd->features & AHD_WIDE) != 0) {
+		type = "Wide ";
+	} else {
+		type = "Single ";
+	}
+	len = sprintf(buf, "%s%sChannel %c, SCSI Id=%d, ",
+		      speed, type, ahd->channel, ahd->our_id);
+	buf += len;
+
+	sprintf(buf, "%s, %d SCBs", ahd->bus_description,
+		ahd->scb_data.maxhscbs);
+}
+
+static const char *channel_strings[] = {
+	"Primary Low",
+	"Primary High",
+	"Secondary Low", 
+	"Secondary High"
+};
+
+static const char *termstat_strings[] = {
+	"Terminated Correctly",
+	"Over Terminated",
+	"Under Terminated",
+	"Not Configured"
+};
+
+/*
+ * Start the board, ready for normal operation
+ */
+int
+ahd_init(struct ahd_softc *ahd)
+{
+	uint8_t		*base_vaddr;
+	uint8_t		*next_vaddr;
+	bus_addr_t	 next_baddr;
+	size_t		 driver_data_size;
+	int		 i;
+	int		 error;
+	u_int		 warn_user;
+	uint8_t		 current_sensing;
+	uint8_t		 fstat;
+
+	AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
+
+	ahd->stack_size = ahd_probe_stack_size(ahd);
+	ahd->saved_stack = malloc(ahd->stack_size * sizeof(uint16_t),
+				  M_DEVBUF, M_NOWAIT);
+	if (ahd->saved_stack == NULL)
+		return (ENOMEM);
+
+	/*
+	 * Verify that the compiler hasn't over-agressively
+	 * padded important structures.
+	 */
+	if (sizeof(struct hardware_scb) != 64)
+		panic("Hardware SCB size is incorrect");
+
+#ifdef AHD_DEBUG
+	if ((ahd_debug & AHD_DEBUG_SEQUENCER) != 0)
+		ahd->flags |= AHD_SEQUENCER_DEBUG;
+#endif
+
+	/*
+	 * Default to allowing initiator operations.
+	 */
+	ahd->flags |= AHD_INITIATORROLE;
+
+	/*
+	 * Only allow target mode features if this unit has them enabled.
+	 */
+	if ((AHD_TMODE_ENABLE & (0x1 << ahd->unit)) == 0)
+		ahd->features &= ~AHD_TARGETMODE;
+
+#ifndef __linux__
+	/* DMA tag for mapping buffers into device visible space. */
+	if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
+			       /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
+			       /*lowaddr*/BUS_SPACE_MAXADDR,
+			       /*highaddr*/BUS_SPACE_MAXADDR,
+			       /*filter*/NULL, /*filterarg*/NULL,
+			       /*maxsize*/MAXBSIZE, /*nsegments*/AHD_NSEG,
+			       /*maxsegsz*/AHD_MAXTRANSFER_SIZE,
+			       /*flags*/BUS_DMA_ALLOCNOW,
+			       &ahd->buffer_dmat) != 0) {
+		return (ENOMEM);
+	}
+#endif
+
+	ahd->init_level++;
+
+	/*
+	 * DMA tag for our command fifos and other data in system memory
+	 * the card's sequencer must be able to access.  For initiator
+	 * roles, we need to allocate space for the qoutfifo.  When providing
+	 * for the target mode role, we must additionally provide space for
+	 * the incoming target command fifo.
+	 */
+	driver_data_size = AHD_SCB_MAX * sizeof(uint16_t)
+			 + sizeof(struct hardware_scb);
+	if ((ahd->features & AHD_TARGETMODE) != 0)
+		driver_data_size += AHD_TMODE_CMDS * sizeof(struct target_cmd);
+	if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0)
+		driver_data_size += PKT_OVERRUN_BUFSIZE;
+	if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
+			       /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
+			       /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
+			       /*highaddr*/BUS_SPACE_MAXADDR,
+			       /*filter*/NULL, /*filterarg*/NULL,
+			       driver_data_size,
+			       /*nsegments*/1,
+			       /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
+			       /*flags*/0, &ahd->shared_data_dmat) != 0) {
+		return (ENOMEM);
+	}
+
+	ahd->init_level++;
+
+	/* Allocation of driver data */
+	if (ahd_dmamem_alloc(ahd, ahd->shared_data_dmat,
+			     (void **)&base_vaddr,
+			     BUS_DMA_NOWAIT, &ahd->shared_data_dmamap) != 0) {
+		return (ENOMEM);
+	}
+
+	ahd->init_level++;
+
+	/* And permanently map it in */
+	ahd_dmamap_load(ahd, ahd->shared_data_dmat, ahd->shared_data_dmamap,
+			base_vaddr, driver_data_size, ahd_dmamap_cb,
+			&ahd->shared_data_busaddr, /*flags*/0);
+	ahd->qoutfifo = (uint16_t *)base_vaddr;
+	next_vaddr = (uint8_t *)&ahd->qoutfifo[AHD_QOUT_SIZE];
+	next_baddr = ahd->shared_data_busaddr + AHD_QOUT_SIZE*sizeof(uint16_t);
+	if ((ahd->features & AHD_TARGETMODE) != 0) {
+		ahd->targetcmds = (struct target_cmd *)next_vaddr;
+		next_vaddr += AHD_TMODE_CMDS * sizeof(struct target_cmd);
+		next_baddr += AHD_TMODE_CMDS * sizeof(struct target_cmd);
+	}
+
+	if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0) {
+		ahd->overrun_buf = next_vaddr;
+		next_vaddr += PKT_OVERRUN_BUFSIZE;
+		next_baddr += PKT_OVERRUN_BUFSIZE;
+	}
+
+	/*
+	 * We need one SCB to serve as the "next SCB".  Since the
+	 * tag identifier in this SCB will never be used, there is
+	 * no point in using a valid HSCB tag from an SCB pulled from
+	 * the standard free pool.  So, we allocate this "sentinel"
+	 * specially from the DMA safe memory chunk used for the QOUTFIFO.
+	 */
+	ahd->next_queued_hscb = (struct hardware_scb *)next_vaddr;
+	ahd->next_queued_hscb->hscb_busaddr = next_baddr;
+
+	ahd->init_level++;
+
+	/* Allocate SCB data now that buffer_dmat is initialized */
+	if (ahd_init_scbdata(ahd) != 0)
+		return (ENOMEM);
+
+	if ((ahd->flags & AHD_INITIATORROLE) == 0)
+		ahd->flags &= ~AHD_RESET_BUS_A;
+
+	/*
+	 * Before committing these settings to the chip, give
+	 * the OSM one last chance to modify our configuration.
+	 */
+	ahd_platform_init(ahd);
+
+	/* Bring up the chip. */
+	ahd_chip_init(ahd);
+
+	AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
+
+	if ((ahd->flags & AHD_CURRENT_SENSING) == 0)
+		goto init_done;
+
+	/*
+	 * Verify termination based on current draw and
+	 * warn user if the bus is over/under terminated.
+	 */
+	error = ahd_write_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL,
+				   CURSENSE_ENB);
+	if (error != 0) {
+		printf("%s: current sensing timeout 1\n", ahd_name(ahd));
+		goto init_done;
+	}
+	for (i = 20, fstat = FLX_FSTAT_BUSY;
+	     (fstat & FLX_FSTAT_BUSY) != 0 && i; i--) {
+		error = ahd_read_flexport(ahd, FLXADDR_FLEXSTAT, &fstat);
+		if (error != 0) {
+			printf("%s: current sensing timeout 2\n",
+			       ahd_name(ahd));
+			goto init_done;
+		}
+	}
+	if (i == 0) {
+		printf("%s: Timedout during current-sensing test\n",
+		       ahd_name(ahd));
+		goto init_done;
+	}
+
+	/* Latch Current Sensing status. */
+	error = ahd_read_flexport(ahd, FLXADDR_CURRENT_STAT, &current_sensing);
+	if (error != 0) {
+		printf("%s: current sensing timeout 3\n", ahd_name(ahd));
+		goto init_done;
+	}
+
+	/* Diable current sensing. */
+	ahd_write_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL, 0);
+
+#ifdef AHD_DEBUG
+	if ((ahd_debug & AHD_SHOW_TERMCTL) != 0) {
+		printf("%s: current_sensing == 0x%x\n",
+		       ahd_name(ahd), current_sensing);
+	}
+#endif
+	warn_user = 0;
+	for (i = 0; i < 4; i++, current_sensing >>= FLX_CSTAT_SHIFT) {
+		u_int term_stat;
+
+		term_stat = (current_sensing & FLX_CSTAT_MASK);
+		switch (term_stat) {
+		case FLX_CSTAT_OVER:
+		case FLX_CSTAT_UNDER:
+			warn_user++;
+		case FLX_CSTAT_INVALID:
+		case FLX_CSTAT_OKAY:
+			if (warn_user == 0 && bootverbose == 0)
+				break;
+			printf("%s: %s Channel %s\n", ahd_name(ahd),
+			       channel_strings[i], termstat_strings[term_stat]);
+			break;
+		}
+	}
+	if (warn_user) {
+		printf("%s: WARNING. Termination is not configured correctly.\n"
+		       "%s: WARNING. SCSI bus operations may FAIL.\n",
+		       ahd_name(ahd), ahd_name(ahd));
+	}
+init_done:
+	ahd_restart(ahd);
+	ahd_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_US,
+			ahd_stat_timer, ahd);
+	return (0);
+}
+
+/*
+ * (Re)initialize chip state after a chip reset.
+ */
+static void
+ahd_chip_init(struct ahd_softc *ahd)
+{
+	uint32_t busaddr;
+	u_int	 sxfrctl1;
+	u_int	 scsiseq_template;
+	u_int	 wait;
+	u_int	 i;
+	u_int	 target;
+
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+	/*
+	 * Take the LED out of diagnostic mode
+	 */
+	ahd_outb(ahd, SBLKCTL, ahd_inb(ahd, SBLKCTL) & ~(DIAGLEDEN|DIAGLEDON));
+
+	/*
+	 * Return HS_MAILBOX to its default value.
+	 */
+	ahd->hs_mailbox = 0;
+	ahd_outb(ahd, HS_MAILBOX, 0);
+
+	/* Set the SCSI Id, SXFRCTL0, SXFRCTL1, and SIMODE1. */
+	ahd_outb(ahd, IOWNID, ahd->our_id);
+	ahd_outb(ahd, TOWNID, ahd->our_id);
+	sxfrctl1 = (ahd->flags & AHD_TERM_ENB_A) != 0 ? STPWEN : 0;
+	sxfrctl1 |= (ahd->flags & AHD_SPCHK_ENB_A) != 0 ? ENSPCHK : 0;
+	if ((ahd->bugs & AHD_LONG_SETIMO_BUG)
+	 && (ahd->seltime != STIMESEL_MIN)) {
+		/*
+		 * The selection timer duration is twice as long
+		 * as it should be.  Halve it by adding "1" to
+		 * the user specified setting.
+		 */
+		sxfrctl1 |= ahd->seltime + STIMESEL_BUG_ADJ;
+	} else {
+		sxfrctl1 |= ahd->seltime;
+	}
+		
+	ahd_outb(ahd, SXFRCTL0, DFON);
+	ahd_outb(ahd, SXFRCTL1, sxfrctl1|ahd->seltime|ENSTIMER|ACTNEGEN);
+	ahd_outb(ahd, SIMODE1, ENSELTIMO|ENSCSIRST|ENSCSIPERR);
+
+	/*
+	 * Now that termination is set, wait for up
+	 * to 500ms for our transceivers to settle.  If
+	 * the adapter does not have a cable attached,
+	 * the tranceivers may never settle, so don't
+	 * complain if we fail here.
+	 */
+	for (wait = 10000;
+	     (ahd_inb(ahd, SBLKCTL) & (ENAB40|ENAB20)) == 0 && wait;
+	     wait--)
+		ahd_delay(100);
+
+	/* Clear any false bus resets due to the transceivers settling */
+	ahd_outb(ahd, CLRSINT1, CLRSCSIRSTI);
+	ahd_outb(ahd, CLRINT, CLRSCSIINT);
+
+	/* Initialize mode specific S/G state. */
+	for (i = 0; i < 2; i++) {
+		ahd_set_modes(ahd, AHD_MODE_DFF0 + i, AHD_MODE_DFF0 + i);
+		ahd_outb(ahd, LONGJMP_ADDR + 1, INVALID_ADDR);
+		ahd_outw(ahd, LONGJMP_SCB, SCB_LIST_NULL);
+		ahd_outb(ahd, SG_STATE, 0);
+		ahd_outb(ahd, CLRSEQINTSRC, 0xFF);
+		ahd_outb(ahd, SEQIMODE,
+			 ENSAVEPTRS|ENCFG4DATA|ENCFG4ISTAT
+			|ENCFG4TSTAT|ENCFG4ICMD|ENCFG4TCMD);
+	}
+
+	ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
+	ahd_outb(ahd, DSCOMMAND0, ahd_inb(ahd, DSCOMMAND0)|MPARCKEN|CACHETHEN);
+	ahd_outb(ahd, DFF_THRSH, RD_DFTHRSH_75|WR_DFTHRSH_75);
+	ahd_outb(ahd, SIMODE0, ENIOERR|ENOVERRUN);
+	ahd_outb(ahd, SIMODE3, ENNTRAMPERR|ENOSRAMPERR);
+	if ((ahd->bugs & AHD_BUSFREEREV_BUG) != 0) {
+		ahd_outb(ahd, OPTIONMODE, AUTOACKEN|AUTO_MSGOUT_DE);
+	} else {
+		ahd_outb(ahd, OPTIONMODE, AUTOACKEN|BUSFREEREV|AUTO_MSGOUT_DE);
+	}
+	ahd_outb(ahd, SCSCHKN, CURRFIFODEF|WIDERESEN);
+	if ((ahd->chip & AHD_BUS_MASK) == AHD_PCIX)
+		/*
+		 * Do not issue a target abort when a split completion
+		 * error occurs.  Let our PCIX interrupt handler deal
+		 * with it instead. H2A4 Razor #625
+		 */
+		ahd_outb(ahd, PCIXCTL, ahd_inb(ahd, PCIXCTL) | SPLTSTADIS);
+
+	if ((ahd->bugs & AHD_LQOOVERRUN_BUG) != 0)
+		ahd_outb(ahd, LQOSCSCTL, LQONOCHKOVER);
+
+	/*
+	 * Tweak IOCELL settings.
+	 */
+	if ((ahd->flags & AHD_HP_BOARD) != 0) {
+		for (i = 0; i < NUMDSPS; i++) {
+			ahd_outb(ahd, DSPSELECT, i);
+			ahd_outb(ahd, WRTBIASCTL, WRTBIASCTL_HP_DEFAULT);
+		}
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_MISC) != 0)
+			printf("%s: WRTBIASCTL now 0x%x\n", ahd_name(ahd),
+			       WRTBIASCTL_HP_DEFAULT);
+#endif
+	}
+	ahd_setup_iocell_workaround(ahd);
+
+	/*
+	 * Enable LQI Manager interrupts.
+	 */
+	ahd_outb(ahd, LQIMODE1, ENLQIPHASE_LQ|ENLQIPHASE_NLQ|ENLIQABORT
+			      | ENLQICRCI_LQ|ENLQICRCI_NLQ|ENLQIBADLQI
+			      | ENLQIOVERI_LQ|ENLQIOVERI_NLQ);
+	ahd_outb(ahd, LQOMODE0, ENLQOATNLQ|ENLQOATNPKT|ENLQOTCRC);
+	/*
+	 * An interrupt from LQOBUSFREE is made redundant by the
+	 * BUSFREE interrupt.  We choose to have the sequencer catch
+	 * LQOPHCHGINPKT errors manually for the command phase at the
+	 * start of a packetized selection case.
+	ahd_outb(ahd, LQOMODE1, ENLQOBUSFREE|ENLQOPHACHGINPKT);
+	 */
+	ahd_outb(ahd, LQOMODE1, 0);
+
+	/*
+	 * Setup sequencer interrupt handlers.
+	 */
+	ahd_outw(ahd, INTVEC1_ADDR, ahd_resolve_seqaddr(ahd, LABEL_seq_isr));
+	ahd_outw(ahd, INTVEC2_ADDR, ahd_resolve_seqaddr(ahd, LABEL_timer_isr));
+
+	/*
+	 * Setup SCB Offset registers.
+	 */
+	if ((ahd->bugs & AHD_PKT_LUN_BUG) != 0) {
+		ahd_outb(ahd, LUNPTR, offsetof(struct hardware_scb,
+			 pkt_long_lun));
+	} else {
+		ahd_outb(ahd, LUNPTR, offsetof(struct hardware_scb, lun));
+	}
+	ahd_outb(ahd, CMDLENPTR, offsetof(struct hardware_scb, cdb_len));
+	ahd_outb(ahd, ATTRPTR, offsetof(struct hardware_scb, task_attribute));
+	ahd_outb(ahd, FLAGPTR, offsetof(struct hardware_scb, task_management));
+	ahd_outb(ahd, CMDPTR, offsetof(struct hardware_scb,
+				       shared_data.idata.cdb));
+	ahd_outb(ahd, QNEXTPTR,
+		 offsetof(struct hardware_scb, next_hscb_busaddr));
+	ahd_outb(ahd, ABRTBITPTR, MK_MESSAGE_BIT_OFFSET);
+	ahd_outb(ahd, ABRTBYTEPTR, offsetof(struct hardware_scb, control));
+	if ((ahd->bugs & AHD_PKT_LUN_BUG) != 0) {
+		ahd_outb(ahd, LUNLEN,
+			 sizeof(ahd->next_queued_hscb->pkt_long_lun) - 1);
+	} else {
+		ahd_outb(ahd, LUNLEN, sizeof(ahd->next_queued_hscb->lun) - 1);
+	}
+	ahd_outb(ahd, CDBLIMIT, SCB_CDB_LEN_PTR - 1);
+	ahd_outb(ahd, MAXCMD, 0xFF);
+	ahd_outb(ahd, SCBAUTOPTR,
+		 AUSCBPTR_EN | offsetof(struct hardware_scb, tag));
+
+	/* We haven't been enabled for target mode yet. */
+	ahd_outb(ahd, MULTARGID, 0);
+	ahd_outb(ahd, MULTARGID + 1, 0);
+
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+	/* Initialize the negotiation table. */
+	if ((ahd->features & AHD_NEW_IOCELL_OPTS) == 0) {
+		/*
+		 * Clear the spare bytes in the neg table to avoid
+		 * spurious parity errors.
+		 */
+		for (target = 0; target < AHD_NUM_TARGETS; target++) {
+			ahd_outb(ahd, NEGOADDR, target);
+			ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_PER_DEV0);
+			for (i = 0; i < AHD_NUM_PER_DEV_ANNEXCOLS; i++)
+				ahd_outb(ahd, ANNEXDAT, 0);
+		}
+	}
+	for (target = 0; target < AHD_NUM_TARGETS; target++) {
+		struct	 ahd_devinfo devinfo;
+		struct	 ahd_initiator_tinfo *tinfo;
+		struct	 ahd_tmode_tstate *tstate;
+
+		tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
+					    target, &tstate);
+		ahd_compile_devinfo(&devinfo, ahd->our_id,
+				    target, CAM_LUN_WILDCARD,
+				    'A', ROLE_INITIATOR);
+		ahd_update_neg_table(ahd, &devinfo, &tinfo->curr);
+	}
+
+	ahd_outb(ahd, CLRSINT3, NTRAMPERR|OSRAMPERR);
+	ahd_outb(ahd, CLRINT, CLRSCSIINT);
+
+	/*
+	 * Always enable abort on incoming L_Qs if this feature is
+	 * supported.  We use this to catch invalid SCB references.
+	 */
+	if ((ahd->bugs & AHD_ABORT_LQI_BUG) == 0)
+		ahd_outb(ahd, LQCTL1, ABORTPENDING);
+	else
+		ahd_outb(ahd, LQCTL1, 0);
+
+	/* All of our queues are empty */
+	ahd->qoutfifonext = 0;
+	ahd->qoutfifonext_valid_tag = QOUTFIFO_ENTRY_VALID_LE;
+	ahd_outb(ahd, QOUTFIFO_ENTRY_VALID_TAG, QOUTFIFO_ENTRY_VALID >> 8);
+	for (i = 0; i < AHD_QOUT_SIZE; i++)
+		ahd->qoutfifo[i] = 0;
+	ahd_sync_qoutfifo(ahd, BUS_DMASYNC_PREREAD);
+
+	ahd->qinfifonext = 0;
+	for (i = 0; i < AHD_QIN_SIZE; i++)
+		ahd->qinfifo[i] = SCB_LIST_NULL;
+
+	if ((ahd->features & AHD_TARGETMODE) != 0) {
+		/* All target command blocks start out invalid. */
+		for (i = 0; i < AHD_TMODE_CMDS; i++)
+			ahd->targetcmds[i].cmd_valid = 0;
+		ahd_sync_tqinfifo(ahd, BUS_DMASYNC_PREREAD);
+		ahd->tqinfifonext = 1;
+		ahd_outb(ahd, KERNEL_TQINPOS, ahd->tqinfifonext - 1);
+		ahd_outb(ahd, TQINPOS, ahd->tqinfifonext);
+	}
+
+	/* Initialize Scratch Ram. */
+	ahd_outb(ahd, SEQ_FLAGS, 0);
+	ahd_outb(ahd, SEQ_FLAGS2, 0);
+
+	/* We don't have any waiting selections */
+	ahd_outw(ahd, WAITING_TID_HEAD, SCB_LIST_NULL);
+	ahd_outw(ahd, WAITING_TID_TAIL, SCB_LIST_NULL);
+	for (i = 0; i < AHD_NUM_TARGETS; i++)
+		ahd_outw(ahd, WAITING_SCB_TAILS + (2 * i), SCB_LIST_NULL);
+
+	/*
+	 * Nobody is waiting to be DMAed into the QOUTFIFO.
+	 */
+	ahd_outw(ahd, COMPLETE_SCB_HEAD, SCB_LIST_NULL);
+	ahd_outw(ahd, COMPLETE_SCB_DMAINPROG_HEAD, SCB_LIST_NULL);
+	ahd_outw(ahd, COMPLETE_DMA_SCB_HEAD, SCB_LIST_NULL);
+
+	/*
+	 * The Freeze Count is 0.
+	 */
+	ahd_outw(ahd, QFREEZE_COUNT, 0);
+
+	/*
+	 * Tell the sequencer where it can find our arrays in memory.
+	 */
+	busaddr = ahd->shared_data_busaddr;
+	ahd_outb(ahd, SHARED_DATA_ADDR, busaddr & 0xFF);
+	ahd_outb(ahd, SHARED_DATA_ADDR + 1, (busaddr >> 8) & 0xFF);
+	ahd_outb(ahd, SHARED_DATA_ADDR + 2, (busaddr >> 16) & 0xFF);
+	ahd_outb(ahd, SHARED_DATA_ADDR + 3, (busaddr >> 24) & 0xFF);
+	ahd_outb(ahd, QOUTFIFO_NEXT_ADDR, busaddr & 0xFF);
+	ahd_outb(ahd, QOUTFIFO_NEXT_ADDR + 1, (busaddr >> 8) & 0xFF);
+	ahd_outb(ahd, QOUTFIFO_NEXT_ADDR + 2, (busaddr >> 16) & 0xFF);
+	ahd_outb(ahd, QOUTFIFO_NEXT_ADDR + 3, (busaddr >> 24) & 0xFF);
+
+	/*
+	 * Setup the allowed SCSI Sequences based on operational mode.
+	 * If we are a target, we'll enable select in operations once
+	 * we've had a lun enabled.
+	 */
+	scsiseq_template = ENAUTOATNP;
+	if ((ahd->flags & AHD_INITIATORROLE) != 0)
+		scsiseq_template |= ENRSELI;
+	ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq_template);
+
+	/* There are no busy SCBs yet. */
+	for (target = 0; target < AHD_NUM_TARGETS; target++) {
+		int lun;
+
+		for (lun = 0; lun < AHD_NUM_LUNS_NONPKT; lun++)
+			ahd_unbusy_tcl(ahd, BUILD_TCL_RAW(target, 'A', lun));
+	}
+
+	/*
+	 * Initialize the group code to command length table.
+	 * Vendor Unique codes are set to 0 so we only capture
+	 * the first byte of the cdb.  These can be overridden
+	 * when target mode is enabled.
+	 */
+	ahd_outb(ahd, CMDSIZE_TABLE, 5);
+	ahd_outb(ahd, CMDSIZE_TABLE + 1, 9);
+	ahd_outb(ahd, CMDSIZE_TABLE + 2, 9);
+	ahd_outb(ahd, CMDSIZE_TABLE + 3, 0);
+	ahd_outb(ahd, CMDSIZE_TABLE + 4, 15);
+	ahd_outb(ahd, CMDSIZE_TABLE + 5, 11);
+	ahd_outb(ahd, CMDSIZE_TABLE + 6, 0);
+	ahd_outb(ahd, CMDSIZE_TABLE + 7, 0);
+		
+	/* Tell the sequencer of our initial queue positions */
+	ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
+	ahd_outb(ahd, QOFF_CTLSTA, SCB_QSIZE_512);
+	ahd->qinfifonext = 0;
+	ahd_set_hnscb_qoff(ahd, ahd->qinfifonext);
+	ahd_set_hescb_qoff(ahd, 0);
+	ahd_set_snscb_qoff(ahd, 0);
+	ahd_set_sescb_qoff(ahd, 0);
+	ahd_set_sdscb_qoff(ahd, 0);
+
+	/*
+	 * Tell the sequencer which SCB will be the next one it receives.
+	 */
+	busaddr = ahd_le32toh(ahd->next_queued_hscb->hscb_busaddr);
+	ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 0, busaddr & 0xFF);
+	ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 1, (busaddr >> 8) & 0xFF);
+	ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 2, (busaddr >> 16) & 0xFF);
+	ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 3, (busaddr >> 24) & 0xFF);
+
+	/*
+	 * Default to coalessing disabled.
+	 */
+	ahd_outw(ahd, INT_COALESSING_CMDCOUNT, 0);
+	ahd_outw(ahd, CMDS_PENDING, 0);
+	ahd_update_coalessing_values(ahd, ahd->int_coalessing_timer,
+				     ahd->int_coalessing_maxcmds,
+				     ahd->int_coalessing_mincmds);
+	ahd_enable_coalessing(ahd, FALSE);
+
+	ahd_loadseq(ahd);
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+}
+
+/*
+ * Setup default device and controller settings.
+ * This should only be called if our probe has
+ * determined that no configuration data is available.
+ */
+int
+ahd_default_config(struct ahd_softc *ahd)
+{
+	int	targ;
+
+	ahd->our_id = 7;
+
+	/*
+	 * Allocate a tstate to house information for our
+	 * initiator presence on the bus as well as the user
+	 * data for any target mode initiator.
+	 */
+	if (ahd_alloc_tstate(ahd, ahd->our_id, 'A') == NULL) {
+		printf("%s: unable to allocate ahd_tmode_tstate.  "
+		       "Failing attach\n", ahd_name(ahd));
+		return (ENOMEM);
+	}
+
+	for (targ = 0; targ < AHD_NUM_TARGETS; targ++) {
+		struct	 ahd_devinfo devinfo;
+		struct	 ahd_initiator_tinfo *tinfo;
+		struct	 ahd_tmode_tstate *tstate;
+		uint16_t target_mask;
+
+		tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
+					    targ, &tstate);
+		/*
+		 * We support SPC2 and SPI4.
+		 */
+		tinfo->user.protocol_version = 4;
+		tinfo->user.transport_version = 4;
+
+		target_mask = 0x01 << targ;
+		ahd->user_discenable |= target_mask;
+		tstate->discenable |= target_mask;
+		ahd->user_tagenable |= target_mask;
+#ifdef AHD_FORCE_160
+		tinfo->user.period = AHD_SYNCRATE_DT;
+#else
+		tinfo->user.period = AHD_SYNCRATE_160;
+#endif
+		tinfo->user.offset= ~0;
+		tinfo->user.ppr_options = MSG_EXT_PPR_RD_STRM
+					| MSG_EXT_PPR_WR_FLOW
+					| MSG_EXT_PPR_HOLD_MCS
+					| MSG_EXT_PPR_IU_REQ
+					| MSG_EXT_PPR_QAS_REQ
+					| MSG_EXT_PPR_DT_REQ;
+		if ((ahd->features & AHD_RTI) != 0)
+			tinfo->user.ppr_options |= MSG_EXT_PPR_RTI;
+
+		tinfo->user.width = MSG_EXT_WDTR_BUS_16_BIT;
+
+		/*
+		 * Start out Async/Narrow/Untagged and with
+		 * conservative protocol support.
+		 */
+		tinfo->goal.protocol_version = 2;
+		tinfo->goal.transport_version = 2;
+		tinfo->curr.protocol_version = 2;
+		tinfo->curr.transport_version = 2;
+		ahd_compile_devinfo(&devinfo, ahd->our_id,
+				    targ, CAM_LUN_WILDCARD,
+				    'A', ROLE_INITIATOR);
+		tstate->tagenable &= ~target_mask;
+		ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
+			      AHD_TRANS_CUR|AHD_TRANS_GOAL, /*paused*/TRUE);
+		ahd_set_syncrate(ahd, &devinfo, /*period*/0, /*offset*/0,
+				 /*ppr_options*/0, AHD_TRANS_CUR|AHD_TRANS_GOAL,
+				 /*paused*/TRUE);
+	}
+	return (0);
+}
+
+/*
+ * Parse device configuration information.
+ */
+int
+ahd_parse_cfgdata(struct ahd_softc *ahd, struct seeprom_config *sc)
+{
+	int targ;
+	int max_targ;
+
+	max_targ = sc->max_targets & CFMAXTARG;
+	ahd->our_id = sc->brtime_id & CFSCSIID;
+
+	/*
+	 * Allocate a tstate to house information for our
+	 * initiator presence on the bus as well as the user
+	 * data for any target mode initiator.
+	 */
+	if (ahd_alloc_tstate(ahd, ahd->our_id, 'A') == NULL) {
+		printf("%s: unable to allocate ahd_tmode_tstate.  "
+		       "Failing attach\n", ahd_name(ahd));
+		return (ENOMEM);
+	}
+
+	for (targ = 0; targ < max_targ; targ++) {
+		struct	 ahd_devinfo devinfo;
+		struct	 ahd_initiator_tinfo *tinfo;
+		struct	 ahd_transinfo *user_tinfo;
+		struct	 ahd_tmode_tstate *tstate;
+		uint16_t target_mask;
+
+		tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
+					    targ, &tstate);
+		user_tinfo = &tinfo->user;
+
+		/*
+		 * We support SPC2 and SPI4.
+		 */
+		tinfo->user.protocol_version = 4;
+		tinfo->user.transport_version = 4;
+
+		target_mask = 0x01 << targ;
+		ahd->user_discenable &= ~target_mask;
+		tstate->discenable &= ~target_mask;
+		ahd->user_tagenable &= ~target_mask;
+		if (sc->device_flags[targ] & CFDISC) {
+			tstate->discenable |= target_mask;
+			ahd->user_discenable |= target_mask;
+			ahd->user_tagenable |= target_mask;
+		} else {
+			/*
+			 * Cannot be packetized without disconnection.
+			 */
+			sc->device_flags[targ] &= ~CFPACKETIZED;
+		}
+
+		user_tinfo->ppr_options = 0;
+		user_tinfo->period = (sc->device_flags[targ] & CFXFER);
+		if (user_tinfo->period < CFXFER_ASYNC) {
+			if (user_tinfo->period <= AHD_PERIOD_10MHz)
+				user_tinfo->ppr_options |= MSG_EXT_PPR_DT_REQ;
+			user_tinfo->offset = MAX_OFFSET;
+		} else  {
+			user_tinfo->offset = 0;
+			user_tinfo->period = AHD_ASYNC_XFER_PERIOD;
+		}
+#ifdef AHD_FORCE_160
+		if (user_tinfo->period <= AHD_SYNCRATE_160)
+			user_tinfo->period = AHD_SYNCRATE_DT;
+#endif
+
+		if ((sc->device_flags[targ] & CFPACKETIZED) != 0) {
+			user_tinfo->ppr_options |= MSG_EXT_PPR_RD_STRM
+						|  MSG_EXT_PPR_WR_FLOW
+						|  MSG_EXT_PPR_HOLD_MCS
+						|  MSG_EXT_PPR_IU_REQ;
+			if ((ahd->features & AHD_RTI) != 0)
+				user_tinfo->ppr_options |= MSG_EXT_PPR_RTI;
+		}
+
+		if ((sc->device_flags[targ] & CFQAS) != 0)
+			user_tinfo->ppr_options |= MSG_EXT_PPR_QAS_REQ;
+
+		if ((sc->device_flags[targ] & CFWIDEB) != 0)
+			user_tinfo->width = MSG_EXT_WDTR_BUS_16_BIT;
+		else
+			user_tinfo->width = MSG_EXT_WDTR_BUS_8_BIT;
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_MISC) != 0)
+			printf("(%d): %x:%x:%x:%x\n", targ, user_tinfo->width,
+			       user_tinfo->period, user_tinfo->offset,
+			       user_tinfo->ppr_options);
+#endif
+		/*
+		 * Start out Async/Narrow/Untagged and with
+		 * conservative protocol support.
+		 */
+		tstate->tagenable &= ~target_mask;
+		tinfo->goal.protocol_version = 2;
+		tinfo->goal.transport_version = 2;
+		tinfo->curr.protocol_version = 2;
+		tinfo->curr.transport_version = 2;
+		ahd_compile_devinfo(&devinfo, ahd->our_id,
+				    targ, CAM_LUN_WILDCARD,
+				    'A', ROLE_INITIATOR);
+		ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
+			      AHD_TRANS_CUR|AHD_TRANS_GOAL, /*paused*/TRUE);
+		ahd_set_syncrate(ahd, &devinfo, /*period*/0, /*offset*/0,
+				 /*ppr_options*/0, AHD_TRANS_CUR|AHD_TRANS_GOAL,
+				 /*paused*/TRUE);
+	}
+
+	ahd->flags &= ~AHD_SPCHK_ENB_A;
+	if (sc->bios_control & CFSPARITY)
+		ahd->flags |= AHD_SPCHK_ENB_A;
+
+	ahd->flags &= ~AHD_RESET_BUS_A;
+	if (sc->bios_control & CFRESETB)
+		ahd->flags |= AHD_RESET_BUS_A;
+
+	ahd->flags &= ~AHD_EXTENDED_TRANS_A;
+	if (sc->bios_control & CFEXTEND)
+		ahd->flags |= AHD_EXTENDED_TRANS_A;
+
+	ahd->flags &= ~AHD_BIOS_ENABLED;
+	if ((sc->bios_control & CFBIOSSTATE) == CFBS_ENABLED)
+		ahd->flags |= AHD_BIOS_ENABLED;
+
+	ahd->flags &= ~AHD_STPWLEVEL_A;
+	if ((sc->adapter_control & CFSTPWLEVEL) != 0)
+		ahd->flags |= AHD_STPWLEVEL_A;
+
+	return (0);
+}
+
+void
+ahd_intr_enable(struct ahd_softc *ahd, int enable)
+{
+	u_int hcntrl;
+
+	hcntrl = ahd_inb(ahd, HCNTRL);
+	hcntrl &= ~INTEN;
+	ahd->pause &= ~INTEN;
+	ahd->unpause &= ~INTEN;
+	if (enable) {
+		hcntrl |= INTEN;
+		ahd->pause |= INTEN;
+		ahd->unpause |= INTEN;
+	}
+	ahd_outb(ahd, HCNTRL, hcntrl);
+}
+
+void
+ahd_update_coalessing_values(struct ahd_softc *ahd, u_int timer, u_int maxcmds,
+			     u_int mincmds)
+{
+	if (timer > AHD_TIMER_MAX_US)
+		timer = AHD_TIMER_MAX_US;
+	ahd->int_coalessing_timer = timer;
+
+	if (maxcmds > AHD_INT_COALESSING_MAXCMDS_MAX)
+		maxcmds = AHD_INT_COALESSING_MAXCMDS_MAX;
+	if (mincmds > AHD_INT_COALESSING_MINCMDS_MAX)
+		mincmds = AHD_INT_COALESSING_MINCMDS_MAX;
+	ahd->int_coalessing_maxcmds = maxcmds;
+	ahd_outw(ahd, INT_COALESSING_TIMER, timer / AHD_TIMER_US_PER_TICK);
+	ahd_outb(ahd, INT_COALESSING_MAXCMDS, -maxcmds);
+	ahd_outb(ahd, INT_COALESSING_MINCMDS, -mincmds);
+}
+
+void
+ahd_enable_coalessing(struct ahd_softc *ahd, int enable)
+{
+
+	ahd->hs_mailbox &= ~ENINT_COALESS;
+	if (enable)
+		ahd->hs_mailbox |= ENINT_COALESS;
+	ahd_outb(ahd, HS_MAILBOX, ahd->hs_mailbox);
+	ahd_flush_device_writes(ahd);
+	ahd_run_qoutfifo(ahd);
+}
+
+/*
+ * Ensure that the card is paused in a location
+ * outside of all critical sections and that all
+ * pending work is completed prior to returning.
+ * This routine should only be called from outside
+ * an interrupt context.
+ */
+void
+ahd_pause_and_flushwork(struct ahd_softc *ahd)
+{
+	u_int intstat;
+	u_int maxloops;
+	int   paused;
+
+	maxloops = 1000;
+	ahd->flags |= AHD_ALL_INTERRUPTS;
+	intstat = 0;
+	paused = FALSE;
+	do {
+		struct scb *waiting_scb;
+
+		if (paused)
+			ahd_unpause(ahd);
+		ahd_intr(ahd);
+		ahd_pause(ahd);
+		paused = TRUE;
+		ahd_clear_critical_section(ahd);
+		if ((ahd_inb(ahd, SSTAT0) & (SELDO|SELINGO)) == 0)
+			ahd_outb(ahd, SCSISEQ0,
+				 ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
+		/*
+		 * In the non-packetized case, the sequencer (for Rev A),
+		 * relies on ENSELO remaining set after SELDO.  The hardware
+		 * auto-clears ENSELO in the packetized case.
+		 */
+		waiting_scb = ahd_lookup_scb(ahd,
+					     ahd_inw(ahd, WAITING_TID_HEAD));
+		if (waiting_scb != NULL
+		 && (waiting_scb->flags & SCB_PACKETIZED) == 0
+		 && (ahd_inb(ahd, SSTAT0) & (SELDO|SELINGO)) != 0)
+			ahd_outb(ahd, SCSISEQ0,
+				 ahd_inb(ahd, SCSISEQ0) | ENSELO);
+
+		if (intstat == 0xFF && (ahd->features & AHD_REMOVABLE) != 0)
+			break;
+	} while (--maxloops
+	      && (((intstat = ahd_inb(ahd, INTSTAT)) & INT_PEND) != 0
+	       || (ahd_inb(ahd, SSTAT0) & (SELDO|SELINGO))));
+	if (maxloops == 0) {
+		printf("Infinite interrupt loop, INTSTAT = %x",
+		      ahd_inb(ahd, INTSTAT));
+	}
+
+	ahd_flush_qoutfifo(ahd);
+
+	ahd_platform_flushwork(ahd);
+	ahd->flags &= ~AHD_ALL_INTERRUPTS;
+}
+
+int
+ahd_suspend(struct ahd_softc *ahd)
+{
+#if 0
+	uint8_t *ptr;
+	int	 i;
+
+	ahd_pause_and_flushwork(ahd);
+
+	if (LIST_FIRST(&ahd->pending_scbs) != NULL)
+		return (EBUSY);
+
+#if AHD_TARGET_MODE
+	/*
+	 * XXX What about ATIOs that have not yet been serviced?
+	 * Perhaps we should just refuse to be suspended if we
+	 * are acting in a target role.
+	 */
+	if (ahd->pending_device != NULL)
+		return (EBUSY);
+#endif
+
+	/* Save volatile registers */
+	ahd->suspend_state.channel[0].scsiseq = ahd_inb(ahd, SCSISEQ0);
+	ahd->suspend_state.channel[0].sxfrctl0 = ahd_inb(ahd, SXFRCTL0);
+	ahd->suspend_state.channel[0].sxfrctl1 = ahd_inb(ahd, SXFRCTL1);
+	ahd->suspend_state.channel[0].simode0 = ahd_inb(ahd, SIMODE0);
+	ahd->suspend_state.channel[0].simode1 = ahd_inb(ahd, SIMODE1);
+	ahd->suspend_state.channel[0].seltimer = ahd_inb(ahd, SELTIMER);
+	ahd->suspend_state.channel[0].seqctl = ahd_inb(ahd, SEQCTL0);
+	ahd->suspend_state.dscommand0 = ahd_inb(ahd, DSCOMMAND0);
+	ahd->suspend_state.dspcistatus = ahd_inb(ahd, DSPCISTATUS);
+
+	if ((ahd->features & AHD_DT) != 0) {
+		u_int sfunct;
+
+		sfunct = ahd_inb(ahd, SFUNCT) & ~ALT_MODE;
+		ahd_outb(ahd, SFUNCT, sfunct | ALT_MODE);
+		ahd->suspend_state.optionmode = ahd_inb(ahd, OPTIONMODE);
+		ahd_outb(ahd, SFUNCT, sfunct);
+		ahd->suspend_state.crccontrol1 = ahd_inb(ahd, CRCCONTROL1);
+	}
+
+	if ((ahd->features & AHD_MULTI_FUNC) != 0)
+		ahd->suspend_state.scbbaddr = ahd_inb(ahd, SCBBADDR);
+
+	if ((ahd->features & AHD_ULTRA2) != 0)
+		ahd->suspend_state.dff_thrsh = ahd_inb(ahd, DFF_THRSH);
+
+	ptr = ahd->suspend_state.scratch_ram;
+	for (i = 0; i < 64; i++)
+		*ptr++ = ahd_inb(ahd, SRAM_BASE + i);
+
+	if ((ahd->features & AHD_MORE_SRAM) != 0) {
+		for (i = 0; i < 16; i++)
+			*ptr++ = ahd_inb(ahd, TARG_OFFSET + i);
+	}
+
+	ptr = ahd->suspend_state.btt;
+	for (i = 0;i < AHD_NUM_TARGETS; i++) {
+		int j;
+
+		for (j = 0;j < AHD_NUM_LUNS_NONPKT; j++) {
+			u_int tcl;
+
+			tcl = BUILD_TCL_RAW(i, 'A', j);
+			*ptr = ahd_find_busy_tcl(ahd, tcl);
+		}
+	}
+	ahd_shutdown(ahd);
+#endif
+	return (0);
+}
+
+int
+ahd_resume(struct ahd_softc *ahd)
+{
+#if 0
+	uint8_t *ptr;
+	int	 i;
+
+	ahd_reset(ahd);
+
+	ahd_build_free_scb_list(ahd);
+
+	/* Restore volatile registers */
+	ahd_outb(ahd, SCSISEQ0, ahd->suspend_state.channel[0].scsiseq);
+	ahd_outb(ahd, SXFRCTL0, ahd->suspend_state.channel[0].sxfrctl0);
+	ahd_outb(ahd, SXFRCTL1, ahd->suspend_state.channel[0].sxfrctl1);
+	ahd_outb(ahd, SIMODE0, ahd->suspend_state.channel[0].simode0);
+	ahd_outb(ahd, SIMODE1, ahd->suspend_state.channel[0].simode1);
+	ahd_outb(ahd, SELTIMER, ahd->suspend_state.channel[0].seltimer);
+	ahd_outb(ahd, SEQCTL0, ahd->suspend_state.channel[0].seqctl);
+	if ((ahd->features & AHD_ULTRA2) != 0)
+		ahd_outb(ahd, SCSIID_ULTRA2, ahd->our_id);
+	else
+		ahd_outb(ahd, SCSIID, ahd->our_id);
+
+	ahd_outb(ahd, DSCOMMAND0, ahd->suspend_state.dscommand0);
+	ahd_outb(ahd, DSPCISTATUS, ahd->suspend_state.dspcistatus);
+
+	if ((ahd->features & AHD_DT) != 0) {
+		u_int sfunct;
+
+		sfunct = ahd_inb(ahd, SFUNCT) & ~ALT_MODE;
+		ahd_outb(ahd, SFUNCT, sfunct | ALT_MODE);
+		ahd_outb(ahd, OPTIONMODE, ahd->suspend_state.optionmode);
+		ahd_outb(ahd, SFUNCT, sfunct);
+		ahd_outb(ahd, CRCCONTROL1, ahd->suspend_state.crccontrol1);
+	}
+
+	if ((ahd->features & AHD_MULTI_FUNC) != 0)
+		ahd_outb(ahd, SCBBADDR, ahd->suspend_state.scbbaddr);
+
+	if ((ahd->features & AHD_ULTRA2) != 0)
+		ahd_outb(ahd, DFF_THRSH, ahd->suspend_state.dff_thrsh);
+
+	ptr = ahd->suspend_state.scratch_ram;
+	for (i = 0; i < 64; i++)
+		ahd_outb(ahd, SRAM_BASE + i, *ptr++);
+
+	if ((ahd->features & AHD_MORE_SRAM) != 0) {
+		for (i = 0; i < 16; i++)
+			ahd_outb(ahd, TARG_OFFSET + i, *ptr++);
+	}
+
+	ptr = ahd->suspend_state.btt;
+	for (i = 0;i < AHD_NUM_TARGETS; i++) {
+		int j;
+
+		for (j = 0;j < AHD_NUM_LUNS; j++) {
+			u_int tcl;
+
+			tcl = BUILD_TCL(i << 4, j);
+			ahd_busy_tcl(ahd, tcl, *ptr);
+		}
+	}
+#endif
+	return (0);
+}
+
+/************************** Busy Target Table *********************************/
+/*
+ * Set SCBPTR to the SCB that contains the busy
+ * table entry for TCL.  Return the offset into
+ * the SCB that contains the entry for TCL.
+ * saved_scbid is dereferenced and set to the
+ * scbid that should be restored once manipualtion
+ * of the TCL entry is complete.
+ */
+static __inline u_int
+ahd_index_busy_tcl(struct ahd_softc *ahd, u_int *saved_scbid, u_int tcl)
+{
+	/*
+	 * Index to the SCB that contains the busy entry.
+	 */
+	AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
+	*saved_scbid = ahd_get_scbptr(ahd);
+	ahd_set_scbptr(ahd, TCL_LUN(tcl)
+		     | ((TCL_TARGET_OFFSET(tcl) & 0xC) << 4));
+
+	/*
+	 * And now calculate the SCB offset to the entry.
+	 * Each entry is 2 bytes wide, hence the
+	 * multiplication by 2.
+	 */
+	return (((TCL_TARGET_OFFSET(tcl) & 0x3) << 1) + SCB_DISCONNECTED_LISTS);
+}
+
+/*
+ * Return the untagged transaction id for a given target/channel lun.
+ * Optionally, clear the entry.
+ */
+u_int
+ahd_find_busy_tcl(struct ahd_softc *ahd, u_int tcl)
+{
+	u_int scbid;
+	u_int scb_offset;
+	u_int saved_scbptr;
+		
+	scb_offset = ahd_index_busy_tcl(ahd, &saved_scbptr, tcl);
+	scbid = ahd_inw_scbram(ahd, scb_offset);
+	ahd_set_scbptr(ahd, saved_scbptr);
+	return (scbid);
+}
+
+void
+ahd_busy_tcl(struct ahd_softc *ahd, u_int tcl, u_int scbid)
+{
+	u_int scb_offset;
+	u_int saved_scbptr;
+		
+	scb_offset = ahd_index_busy_tcl(ahd, &saved_scbptr, tcl);
+	ahd_outw(ahd, scb_offset, scbid);
+	ahd_set_scbptr(ahd, saved_scbptr);
+}
+
+/************************** SCB and SCB queue management **********************/
+int
+ahd_match_scb(struct ahd_softc *ahd, struct scb *scb, int target,
+	      char channel, int lun, u_int tag, role_t role)
+{
+	int targ = SCB_GET_TARGET(ahd, scb);
+	char chan = SCB_GET_CHANNEL(ahd, scb);
+	int slun = SCB_GET_LUN(scb);
+	int match;
+
+	match = ((chan == channel) || (channel == ALL_CHANNELS));
+	if (match != 0)
+		match = ((targ == target) || (target == CAM_TARGET_WILDCARD));
+	if (match != 0)
+		match = ((lun == slun) || (lun == CAM_LUN_WILDCARD));
+	if (match != 0) {
+#if AHD_TARGET_MODE
+		int group;
+
+		group = XPT_FC_GROUP(scb->io_ctx->ccb_h.func_code);
+		if (role == ROLE_INITIATOR) {
+			match = (group != XPT_FC_GROUP_TMODE)
+			      && ((tag == SCB_GET_TAG(scb))
+			       || (tag == SCB_LIST_NULL));
+		} else if (role == ROLE_TARGET) {
+			match = (group == XPT_FC_GROUP_TMODE)
+			      && ((tag == scb->io_ctx->csio.tag_id)
+			       || (tag == SCB_LIST_NULL));
+		}
+#else /* !AHD_TARGET_MODE */
+		match = ((tag == SCB_GET_TAG(scb)) || (tag == SCB_LIST_NULL));
+#endif /* AHD_TARGET_MODE */
+	}
+
+	return match;
+}
+
+void
+ahd_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
+{
+	int	target;
+	char	channel;
+	int	lun;
+
+	target = SCB_GET_TARGET(ahd, scb);
+	lun = SCB_GET_LUN(scb);
+	channel = SCB_GET_CHANNEL(ahd, scb);
+	
+	ahd_search_qinfifo(ahd, target, channel, lun,
+			   /*tag*/SCB_LIST_NULL, ROLE_UNKNOWN,
+			   CAM_REQUEUE_REQ, SEARCH_COMPLETE);
+
+	ahd_platform_freeze_devq(ahd, scb);
+}
+
+void
+ahd_qinfifo_requeue_tail(struct ahd_softc *ahd, struct scb *scb)
+{
+	struct scb	*prev_scb;
+	ahd_mode_state	 saved_modes;
+
+	saved_modes = ahd_save_modes(ahd);
+	ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
+	prev_scb = NULL;
+	if (ahd_qinfifo_count(ahd) != 0) {
+		u_int prev_tag;
+		u_int prev_pos;
+
+		prev_pos = AHD_QIN_WRAP(ahd->qinfifonext - 1);
+		prev_tag = ahd->qinfifo[prev_pos];
+		prev_scb = ahd_lookup_scb(ahd, prev_tag);
+	}
+	ahd_qinfifo_requeue(ahd, prev_scb, scb);
+	ahd_set_hnscb_qoff(ahd, ahd->qinfifonext);
+	ahd_restore_modes(ahd, saved_modes);
+}
+
+static void
+ahd_qinfifo_requeue(struct ahd_softc *ahd, struct scb *prev_scb,
+		    struct scb *scb)
+{
+	if (prev_scb == NULL) {
+		uint32_t busaddr;
+
+		busaddr = ahd_le32toh(scb->hscb->hscb_busaddr);
+		ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 0, busaddr & 0xFF);
+		ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 1, (busaddr >> 8) & 0xFF);
+		ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 2, (busaddr >> 16) & 0xFF);
+		ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 3, (busaddr >> 24) & 0xFF);
+	} else {
+		prev_scb->hscb->next_hscb_busaddr = scb->hscb->hscb_busaddr;
+		ahd_sync_scb(ahd, prev_scb, 
+			     BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
+	}
+	ahd->qinfifo[AHD_QIN_WRAP(ahd->qinfifonext)] = SCB_GET_TAG(scb);
+	ahd->qinfifonext++;
+	scb->hscb->next_hscb_busaddr = ahd->next_queued_hscb->hscb_busaddr;
+	ahd_sync_scb(ahd, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
+}
+
+static int
+ahd_qinfifo_count(struct ahd_softc *ahd)
+{
+	u_int qinpos;
+	u_int wrap_qinpos;
+	u_int wrap_qinfifonext;
+
+	AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
+	qinpos = ahd_get_snscb_qoff(ahd);
+	wrap_qinpos = AHD_QIN_WRAP(qinpos);
+	wrap_qinfifonext = AHD_QIN_WRAP(ahd->qinfifonext);
+	if (wrap_qinfifonext >= wrap_qinpos)
+		return (wrap_qinfifonext - wrap_qinpos);
+	else
+		return (wrap_qinfifonext
+		      + NUM_ELEMENTS(ahd->qinfifo) - wrap_qinpos);
+}
+
+void
+ahd_reset_cmds_pending(struct ahd_softc *ahd)
+{
+	struct		scb *scb;
+	ahd_mode_state	saved_modes;
+	u_int		pending_cmds;
+
+	saved_modes = ahd_save_modes(ahd);
+	ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
+
+	/*
+	 * Don't count any commands as outstanding that the
+	 * sequencer has already marked for completion.
+	 */
+	ahd_flush_qoutfifo(ahd);
+
+	pending_cmds = 0;
+	LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
+		pending_cmds++;
+	}
+	ahd_outw(ahd, CMDS_PENDING, pending_cmds - ahd_qinfifo_count(ahd));
+	ahd_restore_modes(ahd, saved_modes);
+	ahd->flags &= ~AHD_UPDATE_PEND_CMDS;
+}
+
+int
+ahd_search_qinfifo(struct ahd_softc *ahd, int target, char channel,
+		   int lun, u_int tag, role_t role, uint32_t status,
+		   ahd_search_action action)
+{
+	struct scb	*scb;
+	struct scb	*prev_scb;
+	ahd_mode_state	 saved_modes;
+	u_int		 qinstart;
+	u_int		 qinpos;
+	u_int		 qintail;
+	u_int		 tid_next;
+	u_int		 tid_prev;
+	u_int		 scbid;
+	u_int		 savedscbptr;
+	uint32_t	 busaddr;
+	int		 found;
+	int		 targets;
+
+	/* Must be in CCHAN mode */
+	saved_modes = ahd_save_modes(ahd);
+	ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
+
+	/*
+	 * Halt any pending SCB DMA.  The sequencer will reinitiate
+	 * this dma if the qinfifo is not empty once we unpause.
+	 */
+	if ((ahd_inb(ahd, CCSCBCTL) & (CCARREN|CCSCBEN|CCSCBDIR))
+	 == (CCARREN|CCSCBEN|CCSCBDIR)) {
+		ahd_outb(ahd, CCSCBCTL,
+			 ahd_inb(ahd, CCSCBCTL) & ~(CCARREN|CCSCBEN));
+		while ((ahd_inb(ahd, CCSCBCTL) & (CCARREN|CCSCBEN)) != 0)
+			;
+	}
+	/* Determine sequencer's position in the qinfifo. */
+	qintail = AHD_QIN_WRAP(ahd->qinfifonext);
+	qinstart = ahd_get_snscb_qoff(ahd);
+	qinpos = AHD_QIN_WRAP(qinstart);
+	found = 0;
+	prev_scb = NULL;
+
+	if (action == SEARCH_PRINT) {
+		printf("qinstart = %d qinfifonext = %d\nQINFIFO:",
+		       qinstart, ahd->qinfifonext);
+	}
+
+	/*
+	 * Start with an empty queue.  Entries that are not chosen
+	 * for removal will be re-added to the queue as we go.
+	 */
+	ahd->qinfifonext = qinstart;
+	busaddr = ahd_le32toh(ahd->next_queued_hscb->hscb_busaddr);
+	ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 0, busaddr & 0xFF);
+	ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 1, (busaddr >> 8) & 0xFF);
+	ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 2, (busaddr >> 16) & 0xFF);
+	ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 3, (busaddr >> 24) & 0xFF);
+
+	while (qinpos != qintail) {
+		scb = ahd_lookup_scb(ahd, ahd->qinfifo[qinpos]);
+		if (scb == NULL) {
+			printf("qinpos = %d, SCB index = %d\n",
+				qinpos, ahd->qinfifo[qinpos]);
+			panic("Loop 1\n");
+		}
+
+		if (ahd_match_scb(ahd, scb, target, channel, lun, tag, role)) {
+			/*
+			 * We found an scb that needs to be acted on.
+			 */
+			found++;
+			switch (action) {
+			case SEARCH_COMPLETE:
+			{
+				cam_status ostat;
+				cam_status cstat;
+
+				ostat = ahd_get_transaction_status(scb);
+				if (ostat == CAM_REQ_INPROG)
+					ahd_set_transaction_status(scb,
+								   status);
+				cstat = ahd_get_transaction_status(scb);
+				if (cstat != CAM_REQ_CMP)
+					ahd_freeze_scb(scb);
+				if ((scb->flags & SCB_ACTIVE) == 0)
+					printf("Inactive SCB in qinfifo\n");
+				ahd_done(ahd, scb);
+
+				/* FALLTHROUGH */
+			}
+			case SEARCH_REMOVE:
+				break;
+			case SEARCH_PRINT:
+				printf(" 0x%x", ahd->qinfifo[qinpos]);
+				/* FALLTHROUGH */
+			case SEARCH_COUNT:
+				ahd_qinfifo_requeue(ahd, prev_scb, scb);
+				prev_scb = scb;
+				break;
+			}
+		} else {
+			ahd_qinfifo_requeue(ahd, prev_scb, scb);
+			prev_scb = scb;
+		}
+		qinpos = AHD_QIN_WRAP(qinpos+1);
+	}
+
+	ahd_set_hnscb_qoff(ahd, ahd->qinfifonext);
+
+	if (action == SEARCH_PRINT)
+		printf("\nWAITING_TID_QUEUES:\n");
+
+	/*
+	 * Search waiting for selection lists.  We traverse the
+	 * list of "their ids" waiting for selection and, if
+	 * appropriate, traverse the SCBs of each "their id"
+	 * looking for matches.
+	 */
+	savedscbptr = ahd_get_scbptr(ahd);
+	tid_next = ahd_inw(ahd, WAITING_TID_HEAD);
+	tid_prev = SCB_LIST_NULL;
+	targets = 0;
+	for (scbid = tid_next; !SCBID_IS_NULL(scbid); scbid = tid_next) {
+		u_int tid_head;
+
+		/*
+		 * We limit based on the number of SCBs since
+		 * MK_MESSAGE SCBs are not in the per-tid lists.
+		 */
+		targets++;
+		if (targets > AHD_SCB_MAX) {
+			panic("TID LIST LOOP");
+		}
+		if (scbid >= ahd->scb_data.numscbs) {
+			printf("%s: Waiting TID List inconsistency. "
+			       "SCB index == 0x%x, yet numscbs == 0x%x.",
+			       ahd_name(ahd), scbid, ahd->scb_data.numscbs);
+			ahd_dump_card_state(ahd);
+			panic("for safety");
+		}
+		scb = ahd_lookup_scb(ahd, scbid);
+		if (scb == NULL) {
+			printf("%s: SCB = 0x%x Not Active!\n",
+			       ahd_name(ahd), scbid);
+			panic("Waiting TID List traversal\n");
+		}
+		ahd_set_scbptr(ahd, scbid);
+		tid_next = ahd_inw_scbram(ahd, SCB_NEXT2);
+		if (ahd_match_scb(ahd, scb, target, channel, CAM_LUN_WILDCARD,
+				  SCB_LIST_NULL, ROLE_UNKNOWN) == 0) {
+			tid_prev = scbid;
+			continue;
+		}
+
+		/*
+		 * We found a list of scbs that needs to be searched.
+		 */
+		if (action == SEARCH_PRINT)
+			printf("       %d ( ", SCB_GET_TARGET(ahd, scb));
+		tid_head = scbid;
+		found += ahd_search_scb_list(ahd, target, channel,
+					     lun, tag, role, status,
+					     action, &tid_head,
+					     SCB_GET_TARGET(ahd, scb));
+		if (tid_head != scbid)
+			ahd_stitch_tid_list(ahd, tid_prev, tid_head, tid_next);
+		if (!SCBID_IS_NULL(tid_head))
+			tid_prev = tid_head;
+		if (action == SEARCH_PRINT)
+			printf(")\n");
+	}
+	ahd_set_scbptr(ahd, savedscbptr);
+	ahd_restore_modes(ahd, saved_modes);
+	return (found);
+}
+
+static int
+ahd_search_scb_list(struct ahd_softc *ahd, int target, char channel,
+		    int lun, u_int tag, role_t role, uint32_t status,
+		    ahd_search_action action, u_int *list_head, u_int tid)
+{
+	struct	scb *scb;
+	u_int	scbid;
+	u_int	next;
+	u_int	prev;
+	int	found;
+
+	AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
+	found = 0;
+	prev = SCB_LIST_NULL;
+	next = *list_head;
+	for (scbid = next; !SCBID_IS_NULL(scbid); scbid = next) {
+		if (scbid >= ahd->scb_data.numscbs) {
+			printf("%s:SCB List inconsistency. "
+			       "SCB == 0x%x, yet numscbs == 0x%x.",
+			       ahd_name(ahd), scbid, ahd->scb_data.numscbs);
+			ahd_dump_card_state(ahd);
+			panic("for safety");
+		}
+		scb = ahd_lookup_scb(ahd, scbid);
+		if (scb == NULL) {
+			printf("%s: SCB = %d Not Active!\n",
+			       ahd_name(ahd), scbid);
+			panic("Waiting List traversal\n");
+		}
+		ahd_set_scbptr(ahd, scbid);
+		next = ahd_inw_scbram(ahd, SCB_NEXT);
+		if (ahd_match_scb(ahd, scb, target, channel,
+				  lun, SCB_LIST_NULL, role) == 0) {
+			prev = scbid;
+			continue;
+		}
+		found++;
+		switch (action) {
+		case SEARCH_COMPLETE:
+		{
+			cam_status ostat;
+			cam_status cstat;
+
+			ostat = ahd_get_transaction_status(scb);
+			if (ostat == CAM_REQ_INPROG)
+				ahd_set_transaction_status(scb, status);
+			cstat = ahd_get_transaction_status(scb);
+			if (cstat != CAM_REQ_CMP)
+				ahd_freeze_scb(scb);
+			if ((scb->flags & SCB_ACTIVE) == 0)
+				printf("Inactive SCB in Waiting List\n");
+			ahd_done(ahd, scb);
+			/* FALLTHROUGH */
+		}
+		case SEARCH_REMOVE:
+			ahd_rem_wscb(ahd, scbid, prev, next, tid);
+			if (prev == SCB_LIST_NULL)
+				*list_head = next;
+			break;
+		case SEARCH_PRINT:
+			printf("0x%x ", scbid);
+		case SEARCH_COUNT:
+			prev = scbid;
+			break;
+		}
+		if (found > AHD_SCB_MAX)
+			panic("SCB LIST LOOP");
+	}
+	if (action == SEARCH_COMPLETE
+	 || action == SEARCH_REMOVE)
+		ahd_outw(ahd, CMDS_PENDING, ahd_inw(ahd, CMDS_PENDING) - found);
+	return (found);
+}
+
+static void
+ahd_stitch_tid_list(struct ahd_softc *ahd, u_int tid_prev,
+		    u_int tid_cur, u_int tid_next)
+{
+	AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
+
+	if (SCBID_IS_NULL(tid_cur)) {
+
+		/* Bypass current TID list */
+		if (SCBID_IS_NULL(tid_prev)) {
+			ahd_outw(ahd, WAITING_TID_HEAD, tid_next);
+		} else {
+			ahd_set_scbptr(ahd, tid_prev);
+			ahd_outw(ahd, SCB_NEXT2, tid_next);
+		}
+		if (SCBID_IS_NULL(tid_next))
+			ahd_outw(ahd, WAITING_TID_TAIL, tid_prev);
+	} else {
+
+		/* Stitch through tid_cur */
+		if (SCBID_IS_NULL(tid_prev)) {
+			ahd_outw(ahd, WAITING_TID_HEAD, tid_cur);
+		} else {
+			ahd_set_scbptr(ahd, tid_prev);
+			ahd_outw(ahd, SCB_NEXT2, tid_cur);
+		}
+		ahd_set_scbptr(ahd, tid_cur);
+		ahd_outw(ahd, SCB_NEXT2, tid_next);
+
+		if (SCBID_IS_NULL(tid_next))
+			ahd_outw(ahd, WAITING_TID_TAIL, tid_cur);
+	}
+}
+
+/*
+ * Manipulate the waiting for selection list and return the
+ * scb that follows the one that we remove.
+ */
+static u_int
+ahd_rem_wscb(struct ahd_softc *ahd, u_int scbid,
+	     u_int prev, u_int next, u_int tid)
+{
+	u_int tail_offset;
+
+	AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
+	if (!SCBID_IS_NULL(prev)) {
+		ahd_set_scbptr(ahd, prev);
+		ahd_outw(ahd, SCB_NEXT, next);
+	}
+
+	/*
+	 * SCBs that had MK_MESSAGE set in them will not
+	 * be queued to the per-target lists, so don't
+	 * blindly clear the tail pointer.
+	 */
+	tail_offset = WAITING_SCB_TAILS + (2 * tid);
+	if (SCBID_IS_NULL(next)
+	 && ahd_inw(ahd, tail_offset) == scbid)
+		ahd_outw(ahd, tail_offset, prev);
+	ahd_add_scb_to_free_list(ahd, scbid);
+	return (next);
+}
+
+/*
+ * Add the SCB as selected by SCBPTR onto the on chip list of
+ * free hardware SCBs.  This list is empty/unused if we are not
+ * performing SCB paging.
+ */
+static void
+ahd_add_scb_to_free_list(struct ahd_softc *ahd, u_int scbid)
+{
+/* XXX Need some other mechanism to designate "free". */
+	/*
+	 * Invalidate the tag so that our abort
+	 * routines don't think it's active.
+	ahd_outb(ahd, SCB_TAG, SCB_LIST_NULL);
+	 */
+}
+
+/******************************** Error Handling ******************************/
+/*
+ * Abort all SCBs that match the given description (target/channel/lun/tag),
+ * setting their status to the passed in status if the status has not already
+ * been modified from CAM_REQ_INPROG.  This routine assumes that the sequencer
+ * is paused before it is called.
+ */
+int
+ahd_abort_scbs(struct ahd_softc *ahd, int target, char channel,
+	       int lun, u_int tag, role_t role, uint32_t status)
+{
+	struct		scb *scbp;
+	struct		scb *scbp_next;
+	u_int		active_scb;
+	u_int		i, j;
+	u_int		maxtarget;
+	u_int		minlun;
+	u_int		maxlun;
+	int		found;
+	ahd_mode_state	saved_modes;
+
+	/* restore these when we're done */
+	active_scb = ahd_get_scbptr(ahd);
+	saved_modes = ahd_save_modes(ahd);
+
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+	found = ahd_search_qinfifo(ahd, target, channel, lun, SCB_LIST_NULL,
+				   role, CAM_REQUEUE_REQ, SEARCH_COMPLETE);
+
+	/*
+	 * Clean out the busy target table for any untagged commands.
+	 */
+	i = 0;
+	maxtarget = 16;
+	if (target != CAM_TARGET_WILDCARD) {
+		i = target;
+		if (channel == 'B')
+			i += 8;
+		maxtarget = i + 1;
+	}
+
+	if (lun == CAM_LUN_WILDCARD) {
+		minlun = 0;
+		maxlun = AHD_NUM_LUNS_NONPKT;
+	} else if (lun >= AHD_NUM_LUNS_NONPKT) {
+		minlun = maxlun = 0;
+	} else {
+		minlun = lun;
+		maxlun = lun + 1;
+	}
+
+	if (role != ROLE_TARGET) {
+		for (;i < maxtarget; i++) {
+			for (j = minlun;j < maxlun; j++) {
+				u_int scbid;
+				u_int tcl;
+
+				tcl = BUILD_TCL_RAW(i, 'A', j);
+				scbid = ahd_find_busy_tcl(ahd, tcl);
+				scbp = ahd_lookup_scb(ahd, scbid);
+				if (scbp == NULL
+				 || ahd_match_scb(ahd, scbp, target, channel,
+						  lun, tag, role) == 0)
+					continue;
+				ahd_unbusy_tcl(ahd, BUILD_TCL_RAW(i, 'A', j));
+			}
+		}
+	}
+
+	/*
+	 * Don't abort commands that have already completed,
+	 * but haven't quite made it up to the host yet.
+	 */
+	ahd_flush_qoutfifo(ahd);
+
+	/*
+	 * Go through the pending CCB list and look for
+	 * commands for this target that are still active.
+	 * These are other tagged commands that were
+	 * disconnected when the reset occurred.
+	 */
+	scbp_next = LIST_FIRST(&ahd->pending_scbs);
+	while (scbp_next != NULL) {
+		scbp = scbp_next;
+		scbp_next = LIST_NEXT(scbp, pending_links);
+		if (ahd_match_scb(ahd, scbp, target, channel, lun, tag, role)) {
+			cam_status ostat;
+
+			ostat = ahd_get_transaction_status(scbp);
+			if (ostat == CAM_REQ_INPROG)
+				ahd_set_transaction_status(scbp, status);
+			if (ahd_get_transaction_status(scbp) != CAM_REQ_CMP)
+				ahd_freeze_scb(scbp);
+			if ((scbp->flags & SCB_ACTIVE) == 0)
+				printf("Inactive SCB on pending list\n");
+			ahd_done(ahd, scbp);
+			found++;
+		}
+	}
+	ahd_set_scbptr(ahd, active_scb);
+	ahd_restore_modes(ahd, saved_modes);
+	ahd_platform_abort_scbs(ahd, target, channel, lun, tag, role, status);
+	ahd->flags |= AHD_UPDATE_PEND_CMDS;
+	return found;
+}
+
+static void
+ahd_reset_current_bus(struct ahd_softc *ahd)
+{
+	uint8_t scsiseq;
+
+	AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
+	ahd_outb(ahd, SIMODE1, ahd_inb(ahd, SIMODE1) & ~ENSCSIRST);
+	scsiseq = ahd_inb(ahd, SCSISEQ0) & ~(ENSELO|ENARBO|SCSIRSTO);
+	ahd_outb(ahd, SCSISEQ0, scsiseq | SCSIRSTO);
+	ahd_delay(AHD_BUSRESET_DELAY);
+	/* Turn off the bus reset */
+	ahd_outb(ahd, SCSISEQ0, scsiseq);
+	if ((ahd->bugs & AHD_SCSIRST_BUG) != 0) {
+		/*
+		 * 2A Razor #474
+		 * Certain chip state is not cleared for
+		 * SCSI bus resets that we initiate, so
+		 * we must reset the chip.
+		 */
+		ahd_delay(AHD_BUSRESET_DELAY);
+		ahd_reset(ahd);
+		ahd_intr_enable(ahd, /*enable*/TRUE);
+		AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
+	}
+
+	ahd_clear_intstat(ahd);
+}
+
+int
+ahd_reset_channel(struct ahd_softc *ahd, char channel, int initiate_reset)
+{
+	struct	ahd_devinfo devinfo;
+	u_int	initiator;
+	u_int	target;
+	u_int	max_scsiid;
+	int	found;
+	u_int	fifo;
+	u_int	next_fifo;
+
+	ahd->pending_device = NULL;
+
+	ahd_compile_devinfo(&devinfo,
+			    CAM_TARGET_WILDCARD,
+			    CAM_TARGET_WILDCARD,
+			    CAM_LUN_WILDCARD,
+			    channel, ROLE_UNKNOWN);
+	ahd_pause(ahd);
+
+	/* Make sure the sequencer is in a safe location. */
+	ahd_clear_critical_section(ahd);
+
+#if AHD_TARGET_MODE
+	if ((ahd->flags & AHD_TARGETROLE) != 0) {
+		ahd_run_tqinfifo(ahd, /*paused*/TRUE);
+	}
+#endif
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+
+	/*
+	 * Disable selections so no automatic hardware
+	 * functions will modify chip state.
+	 */
+	ahd_outb(ahd, SCSISEQ0, 0);
+	ahd_outb(ahd, SCSISEQ1, 0);
+
+	/*
+	 * Safely shut down our DMA engines.  Always start with
+	 * the FIFO that is not currently active (if any are
+	 * actively connected).
+	 */
+	next_fifo = fifo = ahd_inb(ahd, DFFSTAT) & CURRFIFO;
+	if (next_fifo > CURRFIFO_1)
+		/* If disconneced, arbitrarily start with FIFO1. */
+		next_fifo = fifo = 0;
+	do {
+		next_fifo ^= CURRFIFO_1;
+		ahd_set_modes(ahd, next_fifo, next_fifo);
+		ahd_outb(ahd, DFCNTRL,
+			 ahd_inb(ahd, DFCNTRL) & ~(SCSIEN|HDMAEN));
+		while ((ahd_inb(ahd, DFCNTRL) & HDMAENACK) != 0)
+			ahd_delay(10);
+		/*
+		 * Set CURRFIFO to the now inactive channel.
+		 */
+		ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+		ahd_outb(ahd, DFFSTAT, next_fifo);
+	} while (next_fifo != fifo);
+	/*
+	 * Reset the bus if we are initiating this reset
+	 */
+	ahd_clear_msg_state(ahd);
+	ahd_outb(ahd, SIMODE1,
+		 ahd_inb(ahd, SIMODE1) & ~(ENBUSFREE|ENSCSIRST|ENBUSFREE));
+	if (initiate_reset)
+		ahd_reset_current_bus(ahd);
+	ahd_clear_intstat(ahd);
+
+	/*
+	 * Clean up all the state information for the
+	 * pending transactions on this bus.
+	 */
+	found = ahd_abort_scbs(ahd, CAM_TARGET_WILDCARD, channel,
+			       CAM_LUN_WILDCARD, SCB_LIST_NULL,
+			       ROLE_UNKNOWN, CAM_SCSI_BUS_RESET);
+
+	/*
+	 * Cleanup anything left in the FIFOs.
+	 */
+	ahd_clear_fifo(ahd, 0);
+	ahd_clear_fifo(ahd, 1);
+
+	/*
+	 * Revert to async/narrow transfers until we renegotiate.
+	 */
+	max_scsiid = (ahd->features & AHD_WIDE) ? 15 : 7;
+	for (target = 0; target <= max_scsiid; target++) {
+
+		if (ahd->enabled_targets[target] == NULL)
+			continue;
+		for (initiator = 0; initiator <= max_scsiid; initiator++) {
+			struct ahd_devinfo devinfo;
+
+			ahd_compile_devinfo(&devinfo, target, initiator,
+					    CAM_LUN_WILDCARD,
+					    'A', ROLE_UNKNOWN);
+			ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
+				      AHD_TRANS_CUR, /*paused*/TRUE);
+			ahd_set_syncrate(ahd, &devinfo, /*period*/0,
+					 /*offset*/0, /*ppr_options*/0,
+					 AHD_TRANS_CUR, /*paused*/TRUE);
+		}
+	}
+
+#ifdef AHD_TARGET_MODE
+	max_scsiid = (ahd->features & AHD_WIDE) ? 15 : 7;
+
+	/*
+	 * Send an immediate notify ccb to all target more peripheral
+	 * drivers affected by this action.
+	 */
+	for (target = 0; target <= max_scsiid; target++) {
+		struct ahd_tmode_tstate* tstate;
+		u_int lun;
+
+		tstate = ahd->enabled_targets[target];
+		if (tstate == NULL)
+			continue;
+		for (lun = 0; lun < AHD_NUM_LUNS; lun++) {
+			struct ahd_tmode_lstate* lstate;
+
+			lstate = tstate->enabled_luns[lun];
+			if (lstate == NULL)
+				continue;
+
+			ahd_queue_lstate_event(ahd, lstate, CAM_TARGET_WILDCARD,
+					       EVENT_TYPE_BUS_RESET, /*arg*/0);
+			ahd_send_lstate_events(ahd, lstate);
+		}
+	}
+#endif
+	/* Notify the XPT that a bus reset occurred */
+	ahd_send_async(ahd, devinfo.channel, CAM_TARGET_WILDCARD,
+		       CAM_LUN_WILDCARD, AC_BUS_RESET, NULL);
+	ahd_restart(ahd);
+	/*
+	 * Freeze the SIMQ until our poller can determine that
+	 * the bus reset has really gone away.  We set the initial
+	 * timer to 0 to have the check performed as soon as possible
+	 * from the timer context.
+	 */
+	if ((ahd->flags & AHD_RESET_POLL_ACTIVE) == 0) {
+		ahd->flags |= AHD_RESET_POLL_ACTIVE;
+		ahd_freeze_simq(ahd);
+		ahd_timer_reset(&ahd->reset_timer, 0, ahd_reset_poll, ahd);
+	}
+	return (found);
+}
+
+
+#define AHD_RESET_POLL_US 1000
+static void
+ahd_reset_poll(void *arg)
+{
+	struct	ahd_softc *ahd;
+	u_int	scsiseq1;
+	u_long	l;
+	u_long	s;
+	
+	ahd_list_lock(&l);
+	ahd = ahd_find_softc((struct ahd_softc *)arg);
+	if (ahd == NULL) {
+		printf("ahd_reset_poll: Instance %p no longer exists\n", arg);
+		ahd_list_unlock(&l);
+		return;
+	}
+	ahd_lock(ahd, &s);
+	ahd_pause(ahd);
+	ahd_update_modes(ahd);
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+	ahd_outb(ahd, CLRSINT1, CLRSCSIRSTI);
+	if ((ahd_inb(ahd, SSTAT1) & SCSIRSTI) != 0) {
+		ahd_timer_reset(&ahd->reset_timer, AHD_RESET_POLL_US,
+				ahd_reset_poll, ahd);
+		ahd_unpause(ahd);
+		ahd_unlock(ahd, &s);
+		ahd_list_unlock(&l);
+		return;
+	}
+
+	/* Reset is now low.  Complete chip reinitialization. */
+	ahd_outb(ahd, SIMODE1, ahd_inb(ahd, SIMODE1) | ENSCSIRST);
+	scsiseq1 = ahd_inb(ahd, SCSISEQ_TEMPLATE);
+	ahd_outb(ahd, SCSISEQ1, scsiseq1 & (ENSELI|ENRSELI|ENAUTOATNP));
+	ahd_unpause(ahd);
+	ahd->flags &= ~AHD_RESET_POLL_ACTIVE;
+	ahd_unlock(ahd, &s);
+	ahd_release_simq(ahd);
+	ahd_list_unlock(&l);
+}
+
+/**************************** Statistics Processing ***************************/
+static void
+ahd_stat_timer(void *arg)
+{
+	struct	ahd_softc *ahd;
+	u_long	l;
+	u_long	s;
+	int	enint_coal;
+	
+	ahd_list_lock(&l);
+	ahd = ahd_find_softc((struct ahd_softc *)arg);
+	if (ahd == NULL) {
+		printf("ahd_stat_timer: Instance %p no longer exists\n", arg);
+		ahd_list_unlock(&l);
+		return;
+	}
+	ahd_lock(ahd, &s);
+
+	enint_coal = ahd->hs_mailbox & ENINT_COALESS;
+	if (ahd->cmdcmplt_total > ahd->int_coalessing_threshold)
+		enint_coal |= ENINT_COALESS;
+	else if (ahd->cmdcmplt_total < ahd->int_coalessing_stop_threshold)
+		enint_coal &= ~ENINT_COALESS;
+
+	if (enint_coal != (ahd->hs_mailbox & ENINT_COALESS)) {
+		ahd_enable_coalessing(ahd, enint_coal);
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_INT_COALESSING) != 0)
+			printf("%s: Interrupt coalessing "
+			       "now %sabled. Cmds %d\n",
+			       ahd_name(ahd),
+			       (enint_coal & ENINT_COALESS) ? "en" : "dis",
+			       ahd->cmdcmplt_total,
+			       ahd->cmdcmplt_counts[ahd->cmdcmplt_bucket]);
+#endif
+	}
+
+	ahd->cmdcmplt_bucket = (ahd->cmdcmplt_bucket+1) & (AHD_STAT_BUCKETS-1);
+	ahd->cmdcmplt_total -= ahd->cmdcmplt_counts[ahd->cmdcmplt_bucket];
+	ahd->cmdcmplt_counts[ahd->cmdcmplt_bucket] = 0;
+	ahd_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_US,
+			ahd_stat_timer, ahd);
+	ahd_unlock(ahd, &s);
+	ahd_list_unlock(&l);
+}
+
+/****************************** Status Processing *****************************/
+void
+ahd_handle_scb_status(struct ahd_softc *ahd, struct scb *scb)
+{
+	if (scb->hscb->shared_data.istatus.scsi_status != 0) {
+		ahd_handle_scsi_status(ahd, scb);
+	} else {
+		ahd_calc_residual(ahd, scb);
+		ahd_done(ahd, scb);
+	}
+}
+
+void
+ahd_handle_scsi_status(struct ahd_softc *ahd, struct scb *scb)
+{
+	struct hardware_scb *hscb;
+	u_int  qfreeze_cnt;
+	ahd_mode_state saved_modes;
+
+	/*
+	 * The sequencer freezes its select-out queue
+	 * anytime a SCSI status error occurs.  We must
+	 * handle the error and decrement the QFREEZE count
+	 * to allow the sequencer to continue.
+	 */
+	hscb = scb->hscb; 
+
+	/* Freeze the queue until the client sees the error. */
+	ahd_pause(ahd);
+	saved_modes = ahd_save_modes(ahd);
+	ahd_clear_critical_section(ahd);
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+	ahd_freeze_devq(ahd, scb);
+	ahd_freeze_scb(scb);
+	qfreeze_cnt = ahd_inw(ahd, QFREEZE_COUNT);
+	if (qfreeze_cnt == 0) {
+		printf("%s: Bad status with 0 qfreeze count!\n", ahd_name(ahd));
+	} else {
+		qfreeze_cnt--;
+		ahd_outw(ahd, QFREEZE_COUNT, qfreeze_cnt);
+	}
+	if (qfreeze_cnt == 0)
+		ahd_outb(ahd, SEQ_FLAGS2,
+			 ahd_inb(ahd, SEQ_FLAGS2) & ~SELECTOUT_QFROZEN);
+	ahd_unpause(ahd);
+	/* Don't want to clobber the original sense code */
+	if ((scb->flags & SCB_SENSE) != 0) {
+		/*
+		 * Clear the SCB_SENSE Flag and perform
+		 * a normal command completion.
+		 */
+		scb->flags &= ~SCB_SENSE;
+		ahd_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
+		ahd_done(ahd, scb);
+		return;
+	}
+	ahd_set_transaction_status(scb, CAM_SCSI_STATUS_ERROR);
+	ahd_set_scsi_status(scb, hscb->shared_data.istatus.scsi_status);
+	switch (hscb->shared_data.istatus.scsi_status) {
+	case STATUS_PKT_SENSE:
+	{
+		struct scsi_status_iu_header *siu;
+
+		ahd_sync_sense(ahd, scb, BUS_DMASYNC_POSTREAD);
+		siu = (struct scsi_status_iu_header *)scb->sense_data;
+		ahd_set_scsi_status(scb, siu->status);
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_SENSE) != 0) {
+			ahd_print_path(ahd, scb);
+			printf("SCB 0x%x Received PKT Status of 0x%x\n",
+			       SCB_GET_TAG(scb), siu->status);
+			printf("\tflags = 0x%x, sense len = 0x%x, "
+			       "pktfail = 0x%x\n",
+			       siu->flags, scsi_4btoul(siu->sense_length),
+			       scsi_4btoul(siu->pkt_failures_length));
+		}
+#endif
+		if ((siu->flags & SIU_RSPVALID) != 0) {
+			ahd_print_path(ahd, scb);
+			if (scsi_4btoul(siu->pkt_failures_length) < 4) {
+				printf("Unable to parse pkt_failures\n");
+			} else {
+
+				switch (SIU_PKTFAIL_CODE(siu)) {
+				case SIU_PFC_NONE:
+					printf("No packet failure found\n");
+					break;
+				case SIU_PFC_CIU_FIELDS_INVALID:
+					printf("Invalid Command IU Field\n");
+					break;
+				case SIU_PFC_TMF_NOT_SUPPORTED:
+					printf("TMF not supportd\n");
+					break;
+				case SIU_PFC_TMF_FAILED:
+					printf("TMF failed\n");
+					break;
+				case SIU_PFC_INVALID_TYPE_CODE:
+					printf("Invalid L_Q Type code\n");
+					break;
+				case SIU_PFC_ILLEGAL_REQUEST:
+					printf("Illegal request\n");
+				default:
+					break;
+				}
+			}
+			if (siu->status == SCSI_STATUS_OK)
+				ahd_set_transaction_status(scb,
+							   CAM_REQ_CMP_ERR);
+		}
+		if ((siu->flags & SIU_SNSVALID) != 0) {
+			scb->flags |= SCB_PKT_SENSE;
+#ifdef AHD_DEBUG
+			if ((ahd_debug & AHD_SHOW_SENSE) != 0)
+				printf("Sense data available\n");
+#endif
+		}
+		ahd_done(ahd, scb);
+		break;
+	}
+	case SCSI_STATUS_CMD_TERMINATED:
+	case SCSI_STATUS_CHECK_COND:
+	{
+		struct ahd_devinfo devinfo;
+		struct ahd_dma_seg *sg;
+		struct scsi_sense *sc;
+		struct ahd_initiator_tinfo *targ_info;
+		struct ahd_tmode_tstate *tstate;
+		struct ahd_transinfo *tinfo;
+#ifdef AHD_DEBUG
+		if (ahd_debug & AHD_SHOW_SENSE) {
+			ahd_print_path(ahd, scb);
+			printf("SCB %d: requests Check Status\n",
+			       SCB_GET_TAG(scb));
+		}
+#endif
+
+		if (ahd_perform_autosense(scb) == 0)
+			break;
+
+		ahd_compile_devinfo(&devinfo, SCB_GET_OUR_ID(scb),
+				    SCB_GET_TARGET(ahd, scb),
+				    SCB_GET_LUN(scb),
+				    SCB_GET_CHANNEL(ahd, scb),
+				    ROLE_INITIATOR);
+		targ_info = ahd_fetch_transinfo(ahd,
+						devinfo.channel,
+						devinfo.our_scsiid,
+						devinfo.target,
+						&tstate);
+		tinfo = &targ_info->curr;
+		sg = scb->sg_list;
+		sc = (struct scsi_sense *)hscb->shared_data.idata.cdb;
+		/*
+		 * Save off the residual if there is one.
+		 */
+		ahd_update_residual(ahd, scb);
+#ifdef AHD_DEBUG
+		if (ahd_debug & AHD_SHOW_SENSE) {
+			ahd_print_path(ahd, scb);
+			printf("Sending Sense\n");
+		}
+#endif
+		scb->sg_count = 0;
+		sg = ahd_sg_setup(ahd, scb, sg, ahd_get_sense_bufaddr(ahd, scb),
+				  ahd_get_sense_bufsize(ahd, scb),
+				  /*last*/TRUE);
+		sc->opcode = REQUEST_SENSE;
+		sc->byte2 = 0;
+		if (tinfo->protocol_version <= SCSI_REV_2
+		 && SCB_GET_LUN(scb) < 8)
+			sc->byte2 = SCB_GET_LUN(scb) << 5;
+		sc->unused[0] = 0;
+		sc->unused[1] = 0;
+		sc->length = ahd_get_sense_bufsize(ahd, scb);
+		sc->control = 0;
+
+		/*
+		 * We can't allow the target to disconnect.
+		 * This will be an untagged transaction and
+		 * having the target disconnect will make this
+		 * transaction indestinguishable from outstanding
+		 * tagged transactions.
+		 */
+		hscb->control = 0;
+
+		/*
+		 * This request sense could be because the
+		 * the device lost power or in some other
+		 * way has lost our transfer negotiations.
+		 * Renegotiate if appropriate.  Unit attention
+		 * errors will be reported before any data
+		 * phases occur.
+		 */
+		if (ahd_get_residual(scb) == ahd_get_transfer_length(scb)) {
+			ahd_update_neg_request(ahd, &devinfo,
+					       tstate, targ_info,
+					       AHD_NEG_IF_NON_ASYNC);
+		}
+		if (tstate->auto_negotiate & devinfo.target_mask) {
+			hscb->control |= MK_MESSAGE;
+			scb->flags &=
+			    ~(SCB_NEGOTIATE|SCB_ABORT|SCB_DEVICE_RESET);
+			scb->flags |= SCB_AUTO_NEGOTIATE;
+		}
+		hscb->cdb_len = sizeof(*sc);
+		ahd_setup_data_scb(ahd, scb);
+		scb->flags |= SCB_SENSE;
+		ahd_queue_scb(ahd, scb);
+		/*
+		 * Ensure we have enough time to actually
+		 * retrieve the sense.
+		 */
+		ahd_scb_timer_reset(scb, 5 * 1000000);
+		break;
+	}
+	case SCSI_STATUS_OK:
+		printf("%s: Interrupted for staus of 0???\n",
+		       ahd_name(ahd));
+		/* FALLTHROUGH */
+	default:
+		ahd_done(ahd, scb);
+		break;
+	}
+}
+
+/*
+ * Calculate the residual for a just completed SCB.
+ */
+void
+ahd_calc_residual(struct ahd_softc *ahd, struct scb *scb)
+{
+	struct hardware_scb *hscb;
+	struct initiator_status *spkt;
+	uint32_t sgptr;
+	uint32_t resid_sgptr;
+	uint32_t resid;
+
+	/*
+	 * 5 cases.
+	 * 1) No residual.
+	 *    SG_STATUS_VALID clear in sgptr.
+	 * 2) Transferless command
+	 * 3) Never performed any transfers.
+	 *    sgptr has SG_FULL_RESID set.
+	 * 4) No residual but target did not
+	 *    save data pointers after the
+	 *    last transfer, so sgptr was
+	 *    never updated.
+	 * 5) We have a partial residual.
+	 *    Use residual_sgptr to determine
+	 *    where we are.
+	 */
+
+	hscb = scb->hscb;
+	sgptr = ahd_le32toh(hscb->sgptr);
+	if ((sgptr & SG_STATUS_VALID) == 0)
+		/* Case 1 */
+		return;
+	sgptr &= ~SG_STATUS_VALID;
+
+	if ((sgptr & SG_LIST_NULL) != 0)
+		/* Case 2 */
+		return;
+
+	/*
+	 * Residual fields are the same in both
+	 * target and initiator status packets,
+	 * so we can always use the initiator fields
+	 * regardless of the role for this SCB.
+	 */
+	spkt = &hscb->shared_data.istatus;
+	resid_sgptr = ahd_le32toh(spkt->residual_sgptr);
+	if ((sgptr & SG_FULL_RESID) != 0) {
+		/* Case 3 */
+		resid = ahd_get_transfer_length(scb);
+	} else if ((resid_sgptr & SG_LIST_NULL) != 0) {
+		/* Case 4 */
+		return;
+	} else if ((resid_sgptr & SG_OVERRUN_RESID) != 0) {
+		ahd_print_path(ahd, scb);
+		printf("data overrun detected Tag == 0x%x.\n",
+		       SCB_GET_TAG(scb));
+		ahd_freeze_devq(ahd, scb);
+		ahd_set_transaction_status(scb, CAM_DATA_RUN_ERR);
+		ahd_freeze_scb(scb);
+		return;
+	} else if ((resid_sgptr & ~SG_PTR_MASK) != 0) {
+		panic("Bogus resid sgptr value 0x%x\n", resid_sgptr);
+		/* NOTREACHED */
+	} else {
+		struct ahd_dma_seg *sg;
+
+		/*
+		 * Remainder of the SG where the transfer
+		 * stopped.  
+		 */
+		resid = ahd_le32toh(spkt->residual_datacnt) & AHD_SG_LEN_MASK;
+		sg = ahd_sg_bus_to_virt(ahd, scb, resid_sgptr & SG_PTR_MASK);
+
+		/* The residual sg_ptr always points to the next sg */
+		sg--;
+
+		/*
+		 * Add up the contents of all residual
+		 * SG segments that are after the SG where
+		 * the transfer stopped.
+		 */
+		while ((ahd_le32toh(sg->len) & AHD_DMA_LAST_SEG) == 0) {
+			sg++;
+			resid += ahd_le32toh(sg->len) & AHD_SG_LEN_MASK;
+		}
+	}
+	if ((scb->flags & SCB_SENSE) == 0)
+		ahd_set_residual(scb, resid);
+	else
+		ahd_set_sense_residual(scb, resid);
+
+#ifdef AHD_DEBUG
+	if ((ahd_debug & AHD_SHOW_MISC) != 0) {
+		ahd_print_path(ahd, scb);
+		printf("Handled Residual of %d bytes\n", resid);
+	}
+#endif
+}
+
+/******************************* Target Mode **********************************/
+#ifdef AHD_TARGET_MODE
+/*
+ * Add a target mode event to this lun's queue
+ */
+static void
+ahd_queue_lstate_event(struct ahd_softc *ahd, struct ahd_tmode_lstate *lstate,
+		       u_int initiator_id, u_int event_type, u_int event_arg)
+{
+	struct ahd_tmode_event *event;
+	int pending;
+
+	xpt_freeze_devq(lstate->path, /*count*/1);
+	if (lstate->event_w_idx >= lstate->event_r_idx)
+		pending = lstate->event_w_idx - lstate->event_r_idx;
+	else
+		pending = AHD_TMODE_EVENT_BUFFER_SIZE + 1
+			- (lstate->event_r_idx - lstate->event_w_idx);
+
+	if (event_type == EVENT_TYPE_BUS_RESET
+	 || event_type == MSG_BUS_DEV_RESET) {
+		/*
+		 * Any earlier events are irrelevant, so reset our buffer.
+		 * This has the effect of allowing us to deal with reset
+		 * floods (an external device holding down the reset line)
+		 * without losing the event that is really interesting.
+		 */
+		lstate->event_r_idx = 0;
+		lstate->event_w_idx = 0;
+		xpt_release_devq(lstate->path, pending, /*runqueue*/FALSE);
+	}
+
+	if (pending == AHD_TMODE_EVENT_BUFFER_SIZE) {
+		xpt_print_path(lstate->path);
+		printf("immediate event %x:%x lost\n",
+		       lstate->event_buffer[lstate->event_r_idx].event_type,
+		       lstate->event_buffer[lstate->event_r_idx].event_arg);
+		lstate->event_r_idx++;
+		if (lstate->event_r_idx == AHD_TMODE_EVENT_BUFFER_SIZE)
+			lstate->event_r_idx = 0;
+		xpt_release_devq(lstate->path, /*count*/1, /*runqueue*/FALSE);
+	}
+
+	event = &lstate->event_buffer[lstate->event_w_idx];
+	event->initiator_id = initiator_id;
+	event->event_type = event_type;
+	event->event_arg = event_arg;
+	lstate->event_w_idx++;
+	if (lstate->event_w_idx == AHD_TMODE_EVENT_BUFFER_SIZE)
+		lstate->event_w_idx = 0;
+}
+
+/*
+ * Send any target mode events queued up waiting
+ * for immediate notify resources.
+ */
+void
+ahd_send_lstate_events(struct ahd_softc *ahd, struct ahd_tmode_lstate *lstate)
+{
+	struct ccb_hdr *ccbh;
+	struct ccb_immed_notify *inot;
+
+	while (lstate->event_r_idx != lstate->event_w_idx
+	    && (ccbh = SLIST_FIRST(&lstate->immed_notifies)) != NULL) {
+		struct ahd_tmode_event *event;
+
+		event = &lstate->event_buffer[lstate->event_r_idx];
+		SLIST_REMOVE_HEAD(&lstate->immed_notifies, sim_links.sle);
+		inot = (struct ccb_immed_notify *)ccbh;
+		switch (event->event_type) {
+		case EVENT_TYPE_BUS_RESET:
+			ccbh->status = CAM_SCSI_BUS_RESET|CAM_DEV_QFRZN;
+			break;
+		default:
+			ccbh->status = CAM_MESSAGE_RECV|CAM_DEV_QFRZN;
+			inot->message_args[0] = event->event_type;
+			inot->message_args[1] = event->event_arg;
+			break;
+		}
+		inot->initiator_id = event->initiator_id;
+		inot->sense_len = 0;
+		xpt_done((union ccb *)inot);
+		lstate->event_r_idx++;
+		if (lstate->event_r_idx == AHD_TMODE_EVENT_BUFFER_SIZE)
+			lstate->event_r_idx = 0;
+	}
+}
+#endif
+
+/******************** Sequencer Program Patching/Download *********************/
+
+#ifdef AHD_DUMP_SEQ
+void
+ahd_dumpseq(struct ahd_softc* ahd)
+{
+	int i;
+	int max_prog;
+
+	max_prog = 2048;
+
+	ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
+	ahd_outb(ahd, PRGMCNT, 0);
+	ahd_outb(ahd, PRGMCNT+1, 0);
+	for (i = 0; i < max_prog; i++) {
+		uint8_t ins_bytes[4];
+
+		ahd_insb(ahd, SEQRAM, ins_bytes, 4);
+		printf("0x%08x\n", ins_bytes[0] << 24
+				 | ins_bytes[1] << 16
+				 | ins_bytes[2] << 8
+				 | ins_bytes[3]);
+	}
+}
+#endif
+
+static void
+ahd_loadseq(struct ahd_softc *ahd)
+{
+	struct	cs cs_table[num_critical_sections];
+	u_int	begin_set[num_critical_sections];
+	u_int	end_set[num_critical_sections];
+	struct	patch *cur_patch;
+	u_int	cs_count;
+	u_int	cur_cs;
+	u_int	i;
+	int	downloaded;
+	u_int	skip_addr;
+	u_int	sg_prefetch_cnt;
+	u_int	sg_prefetch_cnt_limit;
+	u_int	sg_prefetch_align;
+	u_int	sg_size;
+	uint8_t	download_consts[DOWNLOAD_CONST_COUNT];
+
+	if (bootverbose)
+		printf("%s: Downloading Sequencer Program...",
+		       ahd_name(ahd));
+
+#if DOWNLOAD_CONST_COUNT != 7
+#error "Download Const Mismatch"
+#endif
+	/*
+	 * Start out with 0 critical sections
+	 * that apply to this firmware load.
+	 */
+	cs_count = 0;
+	cur_cs = 0;
+	memset(begin_set, 0, sizeof(begin_set));
+	memset(end_set, 0, sizeof(end_set));
+
+	/*
+	 * Setup downloadable constant table.
+	 * 
+	 * The computation for the S/G prefetch variables is
+	 * a bit complicated.  We would like to always fetch
+	 * in terms of cachelined sized increments.  However,
+	 * if the cacheline is not an even multiple of the
+	 * SG element size or is larger than our SG RAM, using
+	 * just the cache size might leave us with only a portion
+	 * of an SG element at the tail of a prefetch.  If the
+	 * cacheline is larger than our S/G prefetch buffer less
+	 * the size of an SG element, we may round down to a cacheline
+	 * that doesn't contain any or all of the S/G of interest
+	 * within the bounds of our S/G ram.  Provide variables to
+	 * the sequencer that will allow it to handle these edge
+	 * cases.
+	 */
+	/* Start by aligning to the nearest cacheline. */
+	sg_prefetch_align = ahd->pci_cachesize;
+	if (sg_prefetch_align == 0)
+		sg_prefetch_cnt = 8;
+	/* Round down to the nearest power of 2. */
+	while (powerof2(sg_prefetch_align) == 0)
+		sg_prefetch_align--;
+	/*
+	 * If the cacheline boundary is greater than half our prefetch RAM
+	 * we risk not being able to fetch even a single complete S/G
+	 * segment if we align to that boundary.
+	 */
+	if (sg_prefetch_align > CCSGADDR_MAX/2)
+		sg_prefetch_align = CCSGADDR_MAX/2;
+	/* Start by fetching a single cacheline. */
+	sg_prefetch_cnt = sg_prefetch_align;
+	/*
+	 * Increment the prefetch count by cachelines until
+	 * at least one S/G element will fit.
+	 */
+	sg_size = sizeof(struct ahd_dma_seg);
+	if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
+		sg_size = sizeof(struct ahd_dma64_seg);
+	while (sg_prefetch_cnt < sg_size)
+		sg_prefetch_cnt += sg_prefetch_align;
+	/*
+	 * If the cacheline is not an even multiple of
+	 * the S/G size, we may only get a partial S/G when
+	 * we align. Add a cacheline if this is the case.
+	 */
+	if ((sg_prefetch_align % sg_size) != 0
+	 && (sg_prefetch_cnt < CCSGADDR_MAX))
+		sg_prefetch_cnt += sg_prefetch_align;
+	/*
+	 * Lastly, compute a value that the sequencer can use
+	 * to determine if the remainder of the CCSGRAM buffer
+	 * has a full S/G element in it.
+	 */
+	sg_prefetch_cnt_limit = -(sg_prefetch_cnt - sg_size + 1);
+	download_consts[SG_PREFETCH_CNT] = sg_prefetch_cnt;
+	download_consts[SG_PREFETCH_CNT_LIMIT] = sg_prefetch_cnt_limit;
+	download_consts[SG_PREFETCH_ALIGN_MASK] = ~(sg_prefetch_align - 1);
+	download_consts[SG_PREFETCH_ADDR_MASK] = (sg_prefetch_align - 1);
+	download_consts[SG_SIZEOF] = sg_size;
+	download_consts[PKT_OVERRUN_BUFOFFSET] =
+		(ahd->overrun_buf - (uint8_t *)ahd->qoutfifo) / 256;
+	download_consts[SCB_TRANSFER_SIZE] = SCB_TRANSFER_SIZE_1BYTE_LUN;
+	if ((ahd->bugs & AHD_PKT_LUN_BUG) != 0)
+		download_consts[SCB_TRANSFER_SIZE] = SCB_TRANSFER_SIZE_FULL_LUN;
+	cur_patch = patches;
+	downloaded = 0;
+	skip_addr = 0;
+	ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
+	ahd_outb(ahd, PRGMCNT, 0);
+	ahd_outb(ahd, PRGMCNT+1, 0);
+
+	for (i = 0; i < sizeof(seqprog)/4; i++) {
+		if (ahd_check_patch(ahd, &cur_patch, i, &skip_addr) == 0) {
+			/*
+			 * Don't download this instruction as it
+			 * is in a patch that was removed.
+			 */
+			continue;
+		}
+		/*
+		 * Move through the CS table until we find a CS
+		 * that might apply to this instruction.
+		 */
+		for (; cur_cs < num_critical_sections; cur_cs++) {
+			if (critical_sections[cur_cs].end <= i) {
+				if (begin_set[cs_count] == TRUE
+				 && end_set[cs_count] == FALSE) {
+					cs_table[cs_count].end = downloaded;
+				 	end_set[cs_count] = TRUE;
+					cs_count++;
+				}
+				continue;
+			}
+			if (critical_sections[cur_cs].begin <= i
+			 && begin_set[cs_count] == FALSE) {
+				cs_table[cs_count].begin = downloaded;
+				begin_set[cs_count] = TRUE;
+			}
+			break;
+		}
+		ahd_download_instr(ahd, i, download_consts);
+		downloaded++;
+	}
+
+	ahd->num_critical_sections = cs_count;
+	if (cs_count != 0) {
+
+		cs_count *= sizeof(struct cs);
+		ahd->critical_sections = malloc(cs_count, M_DEVBUF, M_NOWAIT);
+		if (ahd->critical_sections == NULL)
+			panic("ahd_loadseq: Could not malloc");
+		memcpy(ahd->critical_sections, cs_table, cs_count);
+	}
+	ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE);
+
+	if (bootverbose)
+		printf(" %d instructions downloaded\n", downloaded);
+}
+
+static int
+ahd_check_patch(struct ahd_softc *ahd, struct patch **start_patch,
+		u_int start_instr, u_int *skip_addr)
+{
+	struct	patch *cur_patch;
+	struct	patch *last_patch;
+	u_int	num_patches;
+
+	num_patches = sizeof(patches)/sizeof(struct patch);
+	last_patch = &patches[num_patches];
+	cur_patch = *start_patch;
+
+	while (cur_patch < last_patch && start_instr == cur_patch->begin) {
+
+		if (cur_patch->patch_func(ahd) == 0) {
+
+			/* Start rejecting code */
+			*skip_addr = start_instr + cur_patch->skip_instr;
+			cur_patch += cur_patch->skip_patch;
+		} else {
+			/* Accepted this patch.  Advance to the next
+			 * one and wait for our intruction pointer to
+			 * hit this point.
+			 */
+			cur_patch++;
+		}
+	}
+
+	*start_patch = cur_patch;
+	if (start_instr < *skip_addr)
+		/* Still skipping */
+		return (0);
+
+	return (1);
+}
+
+static u_int
+ahd_resolve_seqaddr(struct ahd_softc *ahd, u_int address)
+{
+	struct patch *cur_patch;
+	int address_offset;
+	u_int skip_addr;
+	u_int i;
+
+	address_offset = 0;
+	cur_patch = patches;
+	skip_addr = 0;
+
+	for (i = 0; i < address;) {
+
+		ahd_check_patch(ahd, &cur_patch, i, &skip_addr);
+
+		if (skip_addr > i) {
+			int end_addr;
+
+			end_addr = MIN(address, skip_addr);
+			address_offset += end_addr - i;
+			i = skip_addr;
+		} else {
+			i++;
+		}
+	}
+	return (address - address_offset);
+}
+
+static void
+ahd_download_instr(struct ahd_softc *ahd, u_int instrptr, uint8_t *dconsts)
+{
+	union	ins_formats instr;
+	struct	ins_format1 *fmt1_ins;
+	struct	ins_format3 *fmt3_ins;
+	u_int	opcode;
+
+	/*
+	 * The firmware is always compiled into a little endian format.
+	 */
+	instr.integer = ahd_le32toh(*(uint32_t*)&seqprog[instrptr * 4]);
+
+	fmt1_ins = &instr.format1;
+	fmt3_ins = NULL;
+
+	/* Pull the opcode */
+	opcode = instr.format1.opcode;
+	switch (opcode) {
+	case AIC_OP_JMP:
+	case AIC_OP_JC:
+	case AIC_OP_JNC:
+	case AIC_OP_CALL:
+	case AIC_OP_JNE:
+	case AIC_OP_JNZ:
+	case AIC_OP_JE:
+	case AIC_OP_JZ:
+	{
+		fmt3_ins = &instr.format3;
+		fmt3_ins->address = ahd_resolve_seqaddr(ahd, fmt3_ins->address);
+		/* FALLTHROUGH */
+	}
+	case AIC_OP_OR:
+	case AIC_OP_AND:
+	case AIC_OP_XOR:
+	case AIC_OP_ADD:
+	case AIC_OP_ADC:
+	case AIC_OP_BMOV:
+		if (fmt1_ins->parity != 0) {
+			fmt1_ins->immediate = dconsts[fmt1_ins->immediate];
+		}
+		fmt1_ins->parity = 0;
+		/* FALLTHROUGH */
+	case AIC_OP_ROL:
+	{
+		int i, count;
+
+		/* Calculate odd parity for the instruction */
+		for (i = 0, count = 0; i < 31; i++) {
+			uint32_t mask;
+
+			mask = 0x01 << i;
+			if ((instr.integer & mask) != 0)
+				count++;
+		}
+		if ((count & 0x01) == 0)
+			instr.format1.parity = 1;
+
+		/* The sequencer is a little endian cpu */
+		instr.integer = ahd_htole32(instr.integer);
+		ahd_outsb(ahd, SEQRAM, instr.bytes, 4);
+		break;
+	}
+	default:
+		panic("Unknown opcode encountered in seq program");
+		break;
+	}
+}
+
+static int
+ahd_probe_stack_size(struct ahd_softc *ahd)
+{
+	int last_probe;
+
+	last_probe = 0;
+	while (1) {
+		int i;
+
+		/*
+		 * We avoid using 0 as a pattern to avoid
+		 * confusion if the stack implementation
+		 * "back-fills" with zeros when "poping'
+		 * entries.
+		 */
+		for (i = 1; i <= last_probe+1; i++) {
+		       ahd_outb(ahd, STACK, i & 0xFF);
+		       ahd_outb(ahd, STACK, (i >> 8) & 0xFF);
+		}
+
+		/* Verify */
+		for (i = last_probe+1; i > 0; i--) {
+			u_int stack_entry;
+
+			stack_entry = ahd_inb(ahd, STACK)
+				    |(ahd_inb(ahd, STACK) << 8);
+			if (stack_entry != i)
+				goto sized;
+		}
+		last_probe++;
+	}
+sized:
+	return (last_probe);
+}
+
+void
+ahd_dump_all_cards_state()
+{
+	struct ahd_softc *list_ahd;
+
+	TAILQ_FOREACH(list_ahd, &ahd_tailq, links) {
+		ahd_dump_card_state(list_ahd);
+	}
+}
+
+int
+ahd_print_register(ahd_reg_parse_entry_t *table, u_int num_entries,
+		   const char *name, u_int address, u_int value,
+		   u_int *cur_column, u_int wrap_point)
+{
+	int	printed;
+	u_int	printed_mask;
+
+	if (cur_column != NULL && *cur_column >= wrap_point) {
+		printf("\n");
+		*cur_column = 0;
+	}
+	printed = printf("%s[0x%x]", name, value);
+	if (table == NULL) {
+		printed += printf(" ");
+		*cur_column += printed;
+		return (printed);
+	}
+	printed_mask = 0;
+	while (printed_mask != 0xFF) {
+		int entry;
+
+		for (entry = 0; entry < num_entries; entry++) {
+			if (((value & table[entry].mask)
+			  != table[entry].value)
+			 || ((printed_mask & table[entry].mask)
+			  == table[entry].mask))
+				continue;
+
+			printed += printf("%s%s",
+					  printed_mask == 0 ? ":(" : "|",
+					  table[entry].name);
+			printed_mask |= table[entry].mask;
+			
+			break;
+		}
+		if (entry >= num_entries)
+			break;
+	}
+	if (printed_mask != 0)
+		printed += printf(") ");
+	else
+		printed += printf(" ");
+	if (cur_column != NULL)
+		*cur_column += printed;
+	return (printed);
+}
+
+void
+ahd_dump_card_state(struct ahd_softc *ahd)
+{
+	struct scb	*scb;
+	ahd_mode_state	 saved_modes;
+	u_int		 dffstat;
+	int		 paused;
+	u_int		 scb_index;
+	u_int		 saved_scb_index;
+	u_int		 cur_col;
+	int		 i;
+
+	if (ahd_is_paused(ahd)) {
+		paused = 1;
+	} else {
+		paused = 0;
+		ahd_pause(ahd);
+	}
+	saved_modes = ahd_save_modes(ahd);
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+	printf(">>>>>>>>>>>>>>>>>> Dump Card State Begins <<<<<<<<<<<<<<<<<\n"
+	       "%s: Dumping Card State at program address 0x%x Mode 0x%x\n",
+	       ahd_name(ahd), 
+	       ahd_inb(ahd, CURADDR) | (ahd_inb(ahd, CURADDR+1) << 8),
+	       ahd_build_mode_state(ahd, ahd->saved_src_mode,
+				    ahd->saved_dst_mode));
+	if (paused)
+		printf("Card was paused\n");
+	/*
+	 * Mode independent registers.
+	 */
+	cur_col = 0;
+	ahd_hs_mailbox_print(ahd_inb(ahd, LOCAL_HS_MAILBOX), &cur_col, 50);
+	ahd_intctl_print(ahd_inb(ahd, INTCTL), &cur_col, 50);
+	ahd_seqintstat_print(ahd_inb(ahd, SEQINTSTAT), &cur_col, 50);
+	ahd_saved_mode_print(ahd_inb(ahd, SAVED_MODE), &cur_col, 50);
+	ahd_dffstat_print(ahd_inb(ahd, DFFSTAT), &cur_col, 50);
+	ahd_scsisigi_print(ahd_inb(ahd, SCSISIGI), &cur_col, 50);
+	ahd_scsiphase_print(ahd_inb(ahd, SCSIPHASE), &cur_col, 50);
+	ahd_scsibus_print(ahd_inb(ahd, SCSIBUS), &cur_col, 50);
+	ahd_lastphase_print(ahd_inb(ahd, LASTPHASE), &cur_col, 50);
+	ahd_scsiseq0_print(ahd_inb(ahd, SCSISEQ0), &cur_col, 50);
+	ahd_scsiseq1_print(ahd_inb(ahd, SCSISEQ1), &cur_col, 50);
+	ahd_seqctl0_print(ahd_inb(ahd, SEQCTL0), &cur_col, 50);
+	ahd_seqintctl_print(ahd_inb(ahd, SEQINTCTL), &cur_col, 50);
+	ahd_seq_flags_print(ahd_inb(ahd, SEQ_FLAGS), &cur_col, 50);
+	ahd_seq_flags2_print(ahd_inb(ahd, SEQ_FLAGS2), &cur_col, 50);
+	ahd_sstat0_print(ahd_inb(ahd, SSTAT0), &cur_col, 50);
+	ahd_sstat1_print(ahd_inb(ahd, SSTAT1), &cur_col, 50);
+	ahd_sstat2_print(ahd_inb(ahd, SSTAT2), &cur_col, 50);
+	ahd_sstat3_print(ahd_inb(ahd, SSTAT3), &cur_col, 50);
+	ahd_perrdiag_print(ahd_inb(ahd, PERRDIAG), &cur_col, 50);
+	ahd_simode1_print(ahd_inb(ahd, SIMODE1), &cur_col, 50);
+	ahd_lqistat0_print(ahd_inb(ahd, LQISTAT0), &cur_col, 50);
+	ahd_lqistat1_print(ahd_inb(ahd, LQISTAT1), &cur_col, 50);
+	ahd_lqistat2_print(ahd_inb(ahd, LQISTAT2), &cur_col, 50);
+	ahd_lqostat0_print(ahd_inb(ahd, LQOSTAT0), &cur_col, 50);
+	ahd_lqostat1_print(ahd_inb(ahd, LQOSTAT1), &cur_col, 50);
+	ahd_lqostat2_print(ahd_inb(ahd, LQOSTAT2), &cur_col, 50);
+	printf("\n");
+	printf("\nSCB Count = %d CMDS_PENDING = %d LASTSCB 0x%x "
+	       "CURRSCB 0x%x NEXTSCB 0x%x\n",
+	       ahd->scb_data.numscbs, ahd_inw(ahd, CMDS_PENDING),
+	       ahd_inw(ahd, LASTSCB), ahd_inw(ahd, CURRSCB),
+	       ahd_inw(ahd, NEXTSCB));
+	cur_col = 0;
+	/* QINFIFO */
+	ahd_search_qinfifo(ahd, CAM_TARGET_WILDCARD, ALL_CHANNELS,
+			   CAM_LUN_WILDCARD, SCB_LIST_NULL,
+			   ROLE_UNKNOWN, /*status*/0, SEARCH_PRINT);
+	saved_scb_index = ahd_get_scbptr(ahd);
+	printf("Pending list:");
+	i = 0;
+	LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
+		if (i++ > AHD_SCB_MAX)
+			break;
+		cur_col = printf("\n%3d ", SCB_GET_TAG(scb));
+		ahd_set_scbptr(ahd, SCB_GET_TAG(scb));
+		ahd_scb_control_print(ahd_inb(ahd, SCB_CONTROL), &cur_col, 60);
+		ahd_scb_scsiid_print(ahd_inb(ahd, SCB_SCSIID), &cur_col, 60);
+		ahd_scb_tag_print(ahd_inb(ahd, SCB_TAG), &cur_col, 60);
+	}
+	printf("\nTotal %d\n", i);
+
+	printf("Kernel Free SCB list: ");
+	i = 0;
+	TAILQ_FOREACH(scb, &ahd->scb_data.free_scbs, links.tqe) {
+		struct scb *list_scb;
+
+		list_scb = scb;
+		do {
+			printf("%d ", SCB_GET_TAG(list_scb));
+			list_scb = LIST_NEXT(list_scb, collision_links);
+		} while (list_scb && i++ < AHD_SCB_MAX);
+	}
+
+	LIST_FOREACH(scb, &ahd->scb_data.any_dev_free_scb_list, links.le) {
+		if (i++ > AHD_SCB_MAX)
+			break;
+		printf("%d ", SCB_GET_TAG(scb));
+	}
+	printf("\n");
+
+	printf("Sequencer Complete DMA-inprog list: ");
+	scb_index = ahd_inw(ahd, COMPLETE_SCB_DMAINPROG_HEAD);
+	i = 0;
+	while (!SCBID_IS_NULL(scb_index) && i++ < AHD_SCB_MAX) {
+		ahd_set_scbptr(ahd, scb_index);
+		printf("%d ", scb_index);
+		scb_index = ahd_inw(ahd, SCB_NEXT_COMPLETE);
+	}
+	printf("\n");
+
+	printf("Sequencer Complete list: ");
+	scb_index = ahd_inw(ahd, COMPLETE_SCB_HEAD);
+	i = 0;
+	while (!SCBID_IS_NULL(scb_index) && i++ < AHD_SCB_MAX) {
+		ahd_set_scbptr(ahd, scb_index);
+		printf("%d ", scb_index);
+		scb_index = ahd_inw(ahd, SCB_NEXT_COMPLETE);
+	}
+	printf("\n");
+
+	
+	printf("Sequencer DMA-Up and Complete list: ");
+	scb_index = ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
+	i = 0;
+	while (!SCBID_IS_NULL(scb_index) && i++ < AHD_SCB_MAX) {
+		ahd_set_scbptr(ahd, scb_index);
+		printf("%d ", scb_index);
+		scb_index = ahd_inw(ahd, SCB_NEXT_COMPLETE);
+	}
+	printf("\n");
+	ahd_set_scbptr(ahd, saved_scb_index);
+	dffstat = ahd_inb(ahd, DFFSTAT);
+	for (i = 0; i < 2; i++) {
+#ifdef AHD_DEBUG
+		struct scb *fifo_scb;
+#endif
+		u_int	    fifo_scbptr;
+
+		ahd_set_modes(ahd, AHD_MODE_DFF0 + i, AHD_MODE_DFF0 + i);
+		fifo_scbptr = ahd_get_scbptr(ahd);
+		printf("\n%s: FIFO%d %s, LONGJMP == 0x%x, "
+		       "SCB 0x%x, LJSCB 0x%x\n",
+		       ahd_name(ahd), i,
+		       (dffstat & (FIFO0FREE << i)) ? "Free" : "Active",
+		       ahd_inw(ahd, LONGJMP_ADDR), fifo_scbptr,
+		       ahd_inw(ahd, LONGJMP_SCB));
+		cur_col = 0;
+		ahd_seqimode_print(ahd_inb(ahd, SEQIMODE), &cur_col, 50);
+		ahd_seqintsrc_print(ahd_inb(ahd, SEQINTSRC), &cur_col, 50);
+		ahd_dfcntrl_print(ahd_inb(ahd, DFCNTRL), &cur_col, 50);
+		ahd_dfstatus_print(ahd_inb(ahd, DFSTATUS), &cur_col, 50);
+		ahd_sg_cache_shadow_print(ahd_inb(ahd, SG_CACHE_SHADOW),
+					  &cur_col, 50);
+		ahd_sg_state_print(ahd_inb(ahd, SG_STATE), &cur_col, 50);
+		ahd_dffsxfrctl_print(ahd_inb(ahd, DFFSXFRCTL), &cur_col, 50);
+		ahd_soffcnt_print(ahd_inb(ahd, SOFFCNT), &cur_col, 50);
+		ahd_mdffstat_print(ahd_inb(ahd, MDFFSTAT), &cur_col, 50);
+		if (cur_col > 50) {
+			printf("\n");
+			cur_col = 0;
+		}
+		cur_col += printf("SHADDR = 0x%x%x, SHCNT = 0x%x ",
+				  ahd_inl(ahd, SHADDR+4),
+				  ahd_inl(ahd, SHADDR),
+				  (ahd_inb(ahd, SHCNT)
+				| (ahd_inb(ahd, SHCNT + 1) << 8)
+				| (ahd_inb(ahd, SHCNT + 2) << 16)));
+		if (cur_col > 50) {
+			printf("\n");
+			cur_col = 0;
+		}
+		cur_col += printf("HADDR = 0x%x%x, HCNT = 0x%x ",
+				  ahd_inl(ahd, HADDR+4),
+				  ahd_inl(ahd, HADDR),
+				  (ahd_inb(ahd, HCNT)
+				| (ahd_inb(ahd, HCNT + 1) << 8)
+				| (ahd_inb(ahd, HCNT + 2) << 16)));
+		ahd_ccsgctl_print(ahd_inb(ahd, CCSGCTL), &cur_col, 50);
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_SG) != 0) {
+			fifo_scb = ahd_lookup_scb(ahd, fifo_scbptr);
+			if (fifo_scb != NULL)
+				ahd_dump_sglist(fifo_scb);
+		}
+#endif
+	}
+	printf("\nLQIN: ");
+	for (i = 0; i < 20; i++)
+		printf("0x%x ", ahd_inb(ahd, LQIN + i));
+	printf("\n");
+	ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
+	printf("%s: LQISTATE = 0x%x, LQOSTATE = 0x%x, OPTIONMODE = 0x%x\n",
+	       ahd_name(ahd), ahd_inb(ahd, LQISTATE), ahd_inb(ahd, LQOSTATE),
+	       ahd_inb(ahd, OPTIONMODE));
+	printf("%s: OS_SPACE_CNT = 0x%x MAXCMDCNT = 0x%x\n",
+	       ahd_name(ahd), ahd_inb(ahd, OS_SPACE_CNT),
+	       ahd_inb(ahd, MAXCMDCNT));
+	ahd_simode0_print(ahd_inb(ahd, SIMODE0), &cur_col, 50);
+	printf("\n");
+	ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
+	cur_col = 0;
+	ahd_ccscbctl_print(ahd_inb(ahd, CCSCBCTL), &cur_col, 50);
+	printf("\n");
+	ahd_set_modes(ahd, ahd->saved_src_mode, ahd->saved_dst_mode);
+	printf("%s: REG0 == 0x%x, SINDEX = 0x%x, DINDEX = 0x%x\n",
+	       ahd_name(ahd), ahd_inw(ahd, REG0), ahd_inw(ahd, SINDEX),
+	       ahd_inw(ahd, DINDEX));
+	printf("%s: SCBPTR == 0x%x, SCB_NEXT == 0x%x, SCB_NEXT2 == 0x%x\n",
+	       ahd_name(ahd), ahd_get_scbptr(ahd), ahd_inw(ahd, SCB_NEXT),
+	       ahd_inw(ahd, SCB_NEXT2));
+	printf("CDB %x %x %x %x %x %x\n",
+	       ahd_inb(ahd, SCB_CDB_STORE),
+	       ahd_inb(ahd, SCB_CDB_STORE+1),
+	       ahd_inb(ahd, SCB_CDB_STORE+2),
+	       ahd_inb(ahd, SCB_CDB_STORE+3),
+	       ahd_inb(ahd, SCB_CDB_STORE+4),
+	       ahd_inb(ahd, SCB_CDB_STORE+5));
+	printf("STACK:");
+	for (i = 0; i < ahd->stack_size; i++) {
+		ahd->saved_stack[i] =
+		    ahd_inb(ahd, STACK)|(ahd_inb(ahd, STACK) << 8);
+		printf(" 0x%x", ahd->saved_stack[i]);
+	}
+	for (i = ahd->stack_size-1; i >= 0; i--) {
+		ahd_outb(ahd, STACK, ahd->saved_stack[i] & 0xFF);
+		ahd_outb(ahd, STACK, (ahd->saved_stack[i] >> 8) & 0xFF);
+	}
+	printf("\n<<<<<<<<<<<<<<<<< Dump Card State Ends >>>>>>>>>>>>>>>>>>\n");
+	ahd_platform_dump_card_state(ahd);
+	ahd_restore_modes(ahd, saved_modes);
+	if (paused == 0)
+		ahd_unpause(ahd);
+}
+
+void
+ahd_dump_scbs(struct ahd_softc *ahd)
+{
+	ahd_mode_state saved_modes;
+	u_int	       saved_scb_index;
+	int	       i;
+
+	saved_modes = ahd_save_modes(ahd);
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+	saved_scb_index = ahd_get_scbptr(ahd);
+	for (i = 0; i < AHD_SCB_MAX; i++) {
+		ahd_set_scbptr(ahd, i);
+		printf("%3d", i);
+		printf("(CTRL 0x%x ID 0x%x N 0x%x N2 0x%x SG 0x%x, RSG 0x%x)\n",
+		       ahd_inb(ahd, SCB_CONTROL),
+		       ahd_inb(ahd, SCB_SCSIID), ahd_inw(ahd, SCB_NEXT),
+		       ahd_inw(ahd, SCB_NEXT2), ahd_inl(ahd, SCB_SGPTR),
+		       ahd_inl(ahd, SCB_RESIDUAL_SGPTR));
+	}
+	printf("\n");
+	ahd_set_scbptr(ahd, saved_scb_index);
+	ahd_restore_modes(ahd, saved_modes);
+}
+
+/**************************** Flexport Logic **********************************/
+/*
+ * Read count 16bit words from 16bit word address start_addr from the
+ * SEEPROM attached to the controller, into buf, using the controller's
+ * SEEPROM reading state machine.
+ */
+int
+ahd_read_seeprom(struct ahd_softc *ahd, uint16_t *buf,
+		 u_int start_addr, u_int count)
+{
+	u_int cur_addr;
+	u_int end_addr;
+	int   error;
+
+	/*
+	 * If we never make it through the loop even once,
+	 * we were passed invalid arguments.
+	 */
+	error = EINVAL;
+	AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
+	end_addr = start_addr + count;
+	for (cur_addr = start_addr; cur_addr < end_addr; cur_addr++) {
+		ahd_outb(ahd, SEEADR, cur_addr);
+		ahd_outb(ahd, SEECTL, SEEOP_READ | SEESTART);
+		
+		error = ahd_wait_seeprom(ahd);
+		if (error)
+			break;
+		*buf++ = ahd_inw(ahd, SEEDAT);
+	}
+	return (error);
+}
+
+/*
+ * Write count 16bit words from buf, into SEEPROM attache to the
+ * controller starting at 16bit word address start_addr, using the
+ * controller's SEEPROM writing state machine.
+ */
+int
+ahd_write_seeprom(struct ahd_softc *ahd, uint16_t *buf,
+		  u_int start_addr, u_int count)
+{
+	u_int cur_addr;
+	u_int end_addr;
+	int   error;
+	int   retval;
+
+	AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
+	error = ENOENT;
+
+	/* Place the chip into write-enable mode */
+	ahd_outb(ahd, SEEADR, SEEOP_EWEN_ADDR);
+	ahd_outb(ahd, SEECTL, SEEOP_EWEN | SEESTART);
+	error = ahd_wait_seeprom(ahd);
+	if (error)
+		return (error);
+
+	/*
+	 * Write the data.  If we don't get throught the loop at
+	 * least once, the arguments were invalid.
+	 */
+	retval = EINVAL;
+	end_addr = start_addr + count;
+	for (cur_addr = start_addr; cur_addr < end_addr; cur_addr++) {
+		ahd_outw(ahd, SEEDAT, *buf++);
+		ahd_outb(ahd, SEEADR, cur_addr);
+		ahd_outb(ahd, SEECTL, SEEOP_WRITE | SEESTART);
+		
+		retval = ahd_wait_seeprom(ahd);
+		if (retval)
+			break;
+	}
+
+	/*
+	 * Disable writes.
+	 */
+	ahd_outb(ahd, SEEADR, SEEOP_EWDS_ADDR);
+	ahd_outb(ahd, SEECTL, SEEOP_EWDS | SEESTART);
+	error = ahd_wait_seeprom(ahd);
+	if (error)
+		return (error);
+	return (retval);
+}
+
+/*
+ * Wait ~100us for the serial eeprom to satisfy our request.
+ */
+int
+ahd_wait_seeprom(struct ahd_softc *ahd)
+{
+	int cnt;
+
+	cnt = 20;
+	while ((ahd_inb(ahd, SEESTAT) & (SEEARBACK|SEEBUSY)) != 0 && --cnt)
+		ahd_delay(5);
+
+	if (cnt == 0)
+		return (ETIMEDOUT);
+	return (0);
+}
+
+int
+ahd_verify_cksum(struct seeprom_config *sc)
+{
+	int i;
+	int maxaddr;
+	uint32_t checksum;
+	uint16_t *scarray;
+
+	maxaddr = (sizeof(*sc)/2) - 1;
+	checksum = 0;
+	scarray = (uint16_t *)sc;
+
+	for (i = 0; i < maxaddr; i++)
+		checksum = checksum + scarray[i];
+	if (checksum == 0
+	 || (checksum & 0xFFFF) != sc->checksum) {
+		return (0);
+	} else {
+		return (1);
+	}
+}
+
+int
+ahd_acquire_seeprom(struct ahd_softc *ahd)
+{
+	/*
+	 * We should be able to determine the SEEPROM type
+	 * from the flexport logic, but unfortunately not
+	 * all implementations have this logic and there is
+	 * no programatic method for determining if the logic
+	 * is present.
+	 */
+	return (1);
+#if 0
+	uint8_t	seetype;
+	int	error;
+
+	error = ahd_read_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL, &seetype);
+	if (error != 0
+         || ((seetype & FLX_ROMSTAT_SEECFG) == FLX_ROMSTAT_SEE_NONE))
+		return (0);
+	return (1);
+#endif
+}
+
+void
+ahd_release_seeprom(struct ahd_softc *ahd)
+{
+	/* Currently a no-op */
+}
+
+int
+ahd_write_flexport(struct ahd_softc *ahd, u_int addr, u_int value)
+{
+	int error;
+
+	AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
+	if (addr > 7)
+		panic("ahd_write_flexport: address out of range");
+	ahd_outb(ahd, BRDCTL, BRDEN|(addr << 3));
+	error = ahd_wait_flexport(ahd);
+	if (error != 0)
+		return (error);
+	ahd_outb(ahd, BRDDAT, value);
+	ahd_flush_device_writes(ahd);
+	ahd_outb(ahd, BRDCTL, BRDSTB|BRDEN|(addr << 3));
+	ahd_flush_device_writes(ahd);
+	ahd_outb(ahd, BRDCTL, BRDEN|(addr << 3));
+	ahd_flush_device_writes(ahd);
+	ahd_outb(ahd, BRDCTL, 0);
+	ahd_flush_device_writes(ahd);
+	return (0);
+}
+
+int
+ahd_read_flexport(struct ahd_softc *ahd, u_int addr, uint8_t *value)
+{
+	int	error;
+
+	AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
+	if (addr > 7)
+		panic("ahd_read_flexport: address out of range");
+	ahd_outb(ahd, BRDCTL, BRDRW|BRDEN|(addr << 3));
+	error = ahd_wait_flexport(ahd);
+	if (error != 0)
+		return (error);
+	*value = ahd_inb(ahd, BRDDAT);
+	ahd_outb(ahd, BRDCTL, 0);
+	ahd_flush_device_writes(ahd);
+	return (0);
+}
+
+/*
+ * Wait at most 2 seconds for flexport arbitration to succeed.
+ */
+int
+ahd_wait_flexport(struct ahd_softc *ahd)
+{
+	int cnt;
+
+	AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
+	cnt = 1000000 * 2 / 5;
+	while ((ahd_inb(ahd, BRDCTL) & FLXARBACK) == 0 && --cnt)
+		ahd_delay(5);
+
+	if (cnt == 0)
+		return (ETIMEDOUT);
+	return (0);
+}
+
+/************************* Target Mode ****************************************/
+#ifdef AHD_TARGET_MODE
+cam_status
+ahd_find_tmode_devs(struct ahd_softc *ahd, struct cam_sim *sim, union ccb *ccb,
+		    struct ahd_tmode_tstate **tstate,
+		    struct ahd_tmode_lstate **lstate,
+		    int notfound_failure)
+{
+
+	if ((ahd->features & AHD_TARGETMODE) == 0)
+		return (CAM_REQ_INVALID);
+
+	/*
+	 * Handle the 'black hole' device that sucks up
+	 * requests to unattached luns on enabled targets.
+	 */
+	if (ccb->ccb_h.target_id == CAM_TARGET_WILDCARD
+	 && ccb->ccb_h.target_lun == CAM_LUN_WILDCARD) {
+		*tstate = NULL;
+		*lstate = ahd->black_hole;
+	} else {
+		u_int max_id;
+
+		max_id = (ahd->features & AHD_WIDE) ? 15 : 7;
+		if (ccb->ccb_h.target_id > max_id)
+			return (CAM_TID_INVALID);
+
+		if (ccb->ccb_h.target_lun >= AHD_NUM_LUNS)
+			return (CAM_LUN_INVALID);
+
+		*tstate = ahd->enabled_targets[ccb->ccb_h.target_id];
+		*lstate = NULL;
+		if (*tstate != NULL)
+			*lstate =
+			    (*tstate)->enabled_luns[ccb->ccb_h.target_lun];
+	}
+
+	if (notfound_failure != 0 && *lstate == NULL)
+		return (CAM_PATH_INVALID);
+
+	return (CAM_REQ_CMP);
+}
+
+void
+ahd_handle_en_lun(struct ahd_softc *ahd, struct cam_sim *sim, union ccb *ccb)
+{
+#if NOT_YET
+	struct	   ahd_tmode_tstate *tstate;
+	struct	   ahd_tmode_lstate *lstate;
+	struct	   ccb_en_lun *cel;
+	cam_status status;
+	u_int	   target;
+	u_int	   lun;
+	u_int	   target_mask;
+	u_long	   s;
+	char	   channel;
+
+	status = ahd_find_tmode_devs(ahd, sim, ccb, &tstate, &lstate,
+				     /*notfound_failure*/FALSE);
+
+	if (status != CAM_REQ_CMP) {
+		ccb->ccb_h.status = status;
+		return;
+	}
+
+	if ((ahd->features & AHD_MULTIROLE) != 0) {
+		u_int	   our_id;
+
+		our_id = ahd->our_id;
+		if (ccb->ccb_h.target_id != our_id) {
+			if ((ahd->features & AHD_MULTI_TID) != 0
+		   	 && (ahd->flags & AHD_INITIATORROLE) != 0) {
+				/*
+				 * Only allow additional targets if
+				 * the initiator role is disabled.
+				 * The hardware cannot handle a re-select-in
+				 * on the initiator id during a re-select-out
+				 * on a different target id.
+				 */
+				status = CAM_TID_INVALID;
+			} else if ((ahd->flags & AHD_INITIATORROLE) != 0
+				|| ahd->enabled_luns > 0) {
+				/*
+				 * Only allow our target id to change
+				 * if the initiator role is not configured
+				 * and there are no enabled luns which
+				 * are attached to the currently registered
+				 * scsi id.
+				 */
+				status = CAM_TID_INVALID;
+			}
+		}
+	}
+
+	if (status != CAM_REQ_CMP) {
+		ccb->ccb_h.status = status;
+		return;
+	}
+
+	/*
+	 * We now have an id that is valid.
+	 * If we aren't in target mode, switch modes.
+	 */
+	if ((ahd->flags & AHD_TARGETROLE) == 0
+	 && ccb->ccb_h.target_id != CAM_TARGET_WILDCARD) {
+		u_long	s;
+
+		printf("Configuring Target Mode\n");
+		ahd_lock(ahd, &s);
+		if (LIST_FIRST(&ahd->pending_scbs) != NULL) {
+			ccb->ccb_h.status = CAM_BUSY;
+			ahd_unlock(ahd, &s);
+			return;
+		}
+		ahd->flags |= AHD_TARGETROLE;
+		if ((ahd->features & AHD_MULTIROLE) == 0)
+			ahd->flags &= ~AHD_INITIATORROLE;
+		ahd_pause(ahd);
+		ahd_loadseq(ahd);
+		ahd_unlock(ahd, &s);
+	}
+	cel = &ccb->cel;
+	target = ccb->ccb_h.target_id;
+	lun = ccb->ccb_h.target_lun;
+	channel = SIM_CHANNEL(ahd, sim);
+	target_mask = 0x01 << target;
+	if (channel == 'B')
+		target_mask <<= 8;
+
+	if (cel->enable != 0) {
+		u_int scsiseq1;
+
+		/* Are we already enabled?? */
+		if (lstate != NULL) {
+			xpt_print_path(ccb->ccb_h.path);
+			printf("Lun already enabled\n");
+			ccb->ccb_h.status = CAM_LUN_ALRDY_ENA;
+			return;
+		}
+
+		if (cel->grp6_len != 0
+		 || cel->grp7_len != 0) {
+			/*
+			 * Don't (yet?) support vendor
+			 * specific commands.
+			 */
+			ccb->ccb_h.status = CAM_REQ_INVALID;
+			printf("Non-zero Group Codes\n");
+			return;
+		}
+
+		/*
+		 * Seems to be okay.
+		 * Setup our data structures.
+		 */
+		if (target != CAM_TARGET_WILDCARD && tstate == NULL) {
+			tstate = ahd_alloc_tstate(ahd, target, channel);
+			if (tstate == NULL) {
+				xpt_print_path(ccb->ccb_h.path);
+				printf("Couldn't allocate tstate\n");
+				ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
+				return;
+			}
+		}
+		lstate = malloc(sizeof(*lstate), M_DEVBUF, M_NOWAIT);
+		if (lstate == NULL) {
+			xpt_print_path(ccb->ccb_h.path);
+			printf("Couldn't allocate lstate\n");
+			ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
+			return;
+		}
+		memset(lstate, 0, sizeof(*lstate));
+		status = xpt_create_path(&lstate->path, /*periph*/NULL,
+					 xpt_path_path_id(ccb->ccb_h.path),
+					 xpt_path_target_id(ccb->ccb_h.path),
+					 xpt_path_lun_id(ccb->ccb_h.path));
+		if (status != CAM_REQ_CMP) {
+			free(lstate, M_DEVBUF);
+			xpt_print_path(ccb->ccb_h.path);
+			printf("Couldn't allocate path\n");
+			ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
+			return;
+		}
+		SLIST_INIT(&lstate->accept_tios);
+		SLIST_INIT(&lstate->immed_notifies);
+		ahd_lock(ahd, &s);
+		ahd_pause(ahd);
+		if (target != CAM_TARGET_WILDCARD) {
+			tstate->enabled_luns[lun] = lstate;
+			ahd->enabled_luns++;
+
+			if ((ahd->features & AHD_MULTI_TID) != 0) {
+				u_int targid_mask;
+
+				targid_mask = ahd_inb(ahd, TARGID)
+					    | (ahd_inb(ahd, TARGID + 1) << 8);
+
+				targid_mask |= target_mask;
+				ahd_outb(ahd, TARGID, targid_mask);
+				ahd_outb(ahd, TARGID+1, (targid_mask >> 8));
+				
+				ahd_update_scsiid(ahd, targid_mask);
+			} else {
+				u_int our_id;
+				char  channel;
+
+				channel = SIM_CHANNEL(ahd, sim);
+				our_id = SIM_SCSI_ID(ahd, sim);
+
+				/*
+				 * This can only happen if selections
+				 * are not enabled
+				 */
+				if (target != our_id) {
+					u_int sblkctl;
+					char  cur_channel;
+					int   swap;
+
+					sblkctl = ahd_inb(ahd, SBLKCTL);
+					cur_channel = (sblkctl & SELBUSB)
+						    ? 'B' : 'A';
+					if ((ahd->features & AHD_TWIN) == 0)
+						cur_channel = 'A';
+					swap = cur_channel != channel;
+					ahd->our_id = target;
+
+					if (swap)
+						ahd_outb(ahd, SBLKCTL,
+							 sblkctl ^ SELBUSB);
+
+					ahd_outb(ahd, SCSIID, target);
+
+					if (swap)
+						ahd_outb(ahd, SBLKCTL, sblkctl);
+				}
+			}
+		} else
+			ahd->black_hole = lstate;
+		/* Allow select-in operations */
+		if (ahd->black_hole != NULL && ahd->enabled_luns > 0) {
+			scsiseq1 = ahd_inb(ahd, SCSISEQ_TEMPLATE);
+			scsiseq1 |= ENSELI;
+			ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq1);
+			scsiseq1 = ahd_inb(ahd, SCSISEQ1);
+			scsiseq1 |= ENSELI;
+			ahd_outb(ahd, SCSISEQ1, scsiseq1);
+		}
+		ahd_unpause(ahd);
+		ahd_unlock(ahd, &s);
+		ccb->ccb_h.status = CAM_REQ_CMP;
+		xpt_print_path(ccb->ccb_h.path);
+		printf("Lun now enabled for target mode\n");
+	} else {
+		struct scb *scb;
+		int i, empty;
+
+		if (lstate == NULL) {
+			ccb->ccb_h.status = CAM_LUN_INVALID;
+			return;
+		}
+
+		ahd_lock(ahd, &s);
+		
+		ccb->ccb_h.status = CAM_REQ_CMP;
+		LIST_FOREACH(scb, &ahd->pending_scbs, pending_links) {
+			struct ccb_hdr *ccbh;
+
+			ccbh = &scb->io_ctx->ccb_h;
+			if (ccbh->func_code == XPT_CONT_TARGET_IO
+			 && !xpt_path_comp(ccbh->path, ccb->ccb_h.path)){
+				printf("CTIO pending\n");
+				ccb->ccb_h.status = CAM_REQ_INVALID;
+				ahd_unlock(ahd, &s);
+				return;
+			}
+		}
+
+		if (SLIST_FIRST(&lstate->accept_tios) != NULL) {
+			printf("ATIOs pending\n");
+			ccb->ccb_h.status = CAM_REQ_INVALID;
+		}
+
+		if (SLIST_FIRST(&lstate->immed_notifies) != NULL) {
+			printf("INOTs pending\n");
+			ccb->ccb_h.status = CAM_REQ_INVALID;
+		}
+
+		if (ccb->ccb_h.status != CAM_REQ_CMP) {
+			ahd_unlock(ahd, &s);
+			return;
+		}
+
+		xpt_print_path(ccb->ccb_h.path);
+		printf("Target mode disabled\n");
+		xpt_free_path(lstate->path);
+		free(lstate, M_DEVBUF);
+
+		ahd_pause(ahd);
+		/* Can we clean up the target too? */
+		if (target != CAM_TARGET_WILDCARD) {
+			tstate->enabled_luns[lun] = NULL;
+			ahd->enabled_luns--;
+			for (empty = 1, i = 0; i < 8; i++)
+				if (tstate->enabled_luns[i] != NULL) {
+					empty = 0;
+					break;
+				}
+
+			if (empty) {
+				ahd_free_tstate(ahd, target, channel,
+						/*force*/FALSE);
+				if (ahd->features & AHD_MULTI_TID) {
+					u_int targid_mask;
+
+					targid_mask = ahd_inb(ahd, TARGID)
+						    | (ahd_inb(ahd, TARGID + 1)
+						       << 8);
+
+					targid_mask &= ~target_mask;
+					ahd_outb(ahd, TARGID, targid_mask);
+					ahd_outb(ahd, TARGID+1,
+					 	 (targid_mask >> 8));
+					ahd_update_scsiid(ahd, targid_mask);
+				}
+			}
+		} else {
+
+			ahd->black_hole = NULL;
+
+			/*
+			 * We can't allow selections without
+			 * our black hole device.
+			 */
+			empty = TRUE;
+		}
+		if (ahd->enabled_luns == 0) {
+			/* Disallow select-in */
+			u_int scsiseq1;
+
+			scsiseq1 = ahd_inb(ahd, SCSISEQ_TEMPLATE);
+			scsiseq1 &= ~ENSELI;
+			ahd_outb(ahd, SCSISEQ_TEMPLATE, scsiseq1);
+			scsiseq1 = ahd_inb(ahd, SCSISEQ1);
+			scsiseq1 &= ~ENSELI;
+			ahd_outb(ahd, SCSISEQ1, scsiseq1);
+
+			if ((ahd->features & AHD_MULTIROLE) == 0) {
+				printf("Configuring Initiator Mode\n");
+				ahd->flags &= ~AHD_TARGETROLE;
+				ahd->flags |= AHD_INITIATORROLE;
+				ahd_pause(ahd);
+				ahd_loadseq(ahd);
+			}
+		}
+		ahd_unpause(ahd);
+		ahd_unlock(ahd, &s);
+	}
+#endif
+}
+
+static void
+ahd_update_scsiid(struct ahd_softc *ahd, u_int targid_mask)
+{
+#if NOT_YET
+	u_int scsiid_mask;
+	u_int scsiid;
+
+	if ((ahd->features & AHD_MULTI_TID) == 0)
+		panic("ahd_update_scsiid called on non-multitid unit\n");
+
+	/*
+	 * Since we will rely on the TARGID mask
+	 * for selection enables, ensure that OID
+	 * in SCSIID is not set to some other ID
+	 * that we don't want to allow selections on.
+	 */
+	if ((ahd->features & AHD_ULTRA2) != 0)
+		scsiid = ahd_inb(ahd, SCSIID_ULTRA2);
+	else
+		scsiid = ahd_inb(ahd, SCSIID);
+	scsiid_mask = 0x1 << (scsiid & OID);
+	if ((targid_mask & scsiid_mask) == 0) {
+		u_int our_id;
+
+		/* ffs counts from 1 */
+		our_id = ffs(targid_mask);
+		if (our_id == 0)
+			our_id = ahd->our_id;
+		else
+			our_id--;
+		scsiid &= TID;
+		scsiid |= our_id;
+	}
+	if ((ahd->features & AHD_ULTRA2) != 0)
+		ahd_outb(ahd, SCSIID_ULTRA2, scsiid);
+	else
+		ahd_outb(ahd, SCSIID, scsiid);
+#endif
+}
+
+void
+ahd_run_tqinfifo(struct ahd_softc *ahd, int paused)
+{
+	struct target_cmd *cmd;
+
+	ahd_sync_tqinfifo(ahd, BUS_DMASYNC_POSTREAD);
+	while ((cmd = &ahd->targetcmds[ahd->tqinfifonext])->cmd_valid != 0) {
+
+		/*
+		 * Only advance through the queue if we
+		 * have the resources to process the command.
+		 */
+		if (ahd_handle_target_cmd(ahd, cmd) != 0)
+			break;
+
+		cmd->cmd_valid = 0;
+		ahd_dmamap_sync(ahd, ahd->shared_data_dmat,
+				ahd->shared_data_dmamap,
+				ahd_targetcmd_offset(ahd, ahd->tqinfifonext),
+				sizeof(struct target_cmd),
+				BUS_DMASYNC_PREREAD);
+		ahd->tqinfifonext++;
+
+		/*
+		 * Lazily update our position in the target mode incoming
+		 * command queue as seen by the sequencer.
+		 */
+		if ((ahd->tqinfifonext & (HOST_TQINPOS - 1)) == 1) {
+			u_int hs_mailbox;
+
+			hs_mailbox = ahd_inb(ahd, HS_MAILBOX);
+			hs_mailbox &= ~HOST_TQINPOS;
+			hs_mailbox |= ahd->tqinfifonext & HOST_TQINPOS;
+			ahd_outb(ahd, HS_MAILBOX, hs_mailbox);
+		}
+	}
+}
+
+static int
+ahd_handle_target_cmd(struct ahd_softc *ahd, struct target_cmd *cmd)
+{
+	struct	  ahd_tmode_tstate *tstate;
+	struct	  ahd_tmode_lstate *lstate;
+	struct	  ccb_accept_tio *atio;
+	uint8_t *byte;
+	int	  initiator;
+	int	  target;
+	int	  lun;
+
+	initiator = SCSIID_TARGET(ahd, cmd->scsiid);
+	target = SCSIID_OUR_ID(cmd->scsiid);
+	lun    = (cmd->identify & MSG_IDENTIFY_LUNMASK);
+
+	byte = cmd->bytes;
+	tstate = ahd->enabled_targets[target];
+	lstate = NULL;
+	if (tstate != NULL)
+		lstate = tstate->enabled_luns[lun];
+
+	/*
+	 * Commands for disabled luns go to the black hole driver.
+	 */
+	if (lstate == NULL)
+		lstate = ahd->black_hole;
+
+	atio = (struct ccb_accept_tio*)SLIST_FIRST(&lstate->accept_tios);
+	if (atio == NULL) {
+		ahd->flags |= AHD_TQINFIFO_BLOCKED;
+		/*
+		 * Wait for more ATIOs from the peripheral driver for this lun.
+		 */
+		return (1);
+	} else
+		ahd->flags &= ~AHD_TQINFIFO_BLOCKED;
+#ifdef AHD_DEBUG
+	if ((ahd_debug & AHD_SHOW_TQIN) != 0)
+		printf("Incoming command from %d for %d:%d%s\n",
+		       initiator, target, lun,
+		       lstate == ahd->black_hole ? "(Black Holed)" : "");
+#endif
+	SLIST_REMOVE_HEAD(&lstate->accept_tios, sim_links.sle);
+
+	if (lstate == ahd->black_hole) {
+		/* Fill in the wildcards */
+		atio->ccb_h.target_id = target;
+		atio->ccb_h.target_lun = lun;
+	}
+
+	/*
+	 * Package it up and send it off to
+	 * whomever has this lun enabled.
+	 */
+	atio->sense_len = 0;
+	atio->init_id = initiator;
+	if (byte[0] != 0xFF) {
+		/* Tag was included */
+		atio->tag_action = *byte++;
+		atio->tag_id = *byte++;
+		atio->ccb_h.flags = CAM_TAG_ACTION_VALID;
+	} else {
+		atio->ccb_h.flags = 0;
+	}
+	byte++;
+
+	/* Okay.  Now determine the cdb size based on the command code */
+	switch (*byte >> CMD_GROUP_CODE_SHIFT) {
+	case 0:
+		atio->cdb_len = 6;
+		break;
+	case 1:
+	case 2:
+		atio->cdb_len = 10;
+		break;
+	case 4:
+		atio->cdb_len = 16;
+		break;
+	case 5:
+		atio->cdb_len = 12;
+		break;
+	case 3:
+	default:
+		/* Only copy the opcode. */
+		atio->cdb_len = 1;
+		printf("Reserved or VU command code type encountered\n");
+		break;
+	}
+	
+	memcpy(atio->cdb_io.cdb_bytes, byte, atio->cdb_len);
+
+	atio->ccb_h.status |= CAM_CDB_RECVD;
+
+	if ((cmd->identify & MSG_IDENTIFY_DISCFLAG) == 0) {
+		/*
+		 * We weren't allowed to disconnect.
+		 * We're hanging on the bus until a
+		 * continue target I/O comes in response
+		 * to this accept tio.
+		 */
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_TQIN) != 0)
+			printf("Received Immediate Command %d:%d:%d - %p\n",
+			       initiator, target, lun, ahd->pending_device);
+#endif
+		ahd->pending_device = lstate;
+		ahd_freeze_ccb((union ccb *)atio);
+		atio->ccb_h.flags |= CAM_DIS_DISCONNECT;
+	}
+	xpt_done((union ccb*)atio);
+	return (0);
+}
+
+#endif
diff -Nru a/drivers/scsi/aic7xxx/aic79xx_inline.h b/drivers/scsi/aic7xxx/aic79xx_inline.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aic79xx_inline.h	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,951 @@
+/*
+ * Inline routines shareable across OS platforms.
+ *
+ * Copyright (c) 1994-2001 Justin T. Gibbs.
+ * Copyright (c) 2000-2002 Adaptec Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $Id: //depot/aic7xxx/aic7xxx/aic79xx_inline.h#40 $
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _AIC79XX_INLINE_H_
+#define _AIC79XX_INLINE_H_
+
+/******************************** Debugging ***********************************/
+static __inline char *ahd_name(struct ahd_softc *ahd);
+
+static __inline char *
+ahd_name(struct ahd_softc *ahd)
+{
+	return (ahd->name);
+}
+
+/************************ Sequencer Execution Control *************************/
+static __inline void ahd_known_modes(struct ahd_softc *ahd,
+				     ahd_mode src, ahd_mode dst);
+static __inline ahd_mode_state ahd_build_mode_state(struct ahd_softc *ahd,
+						    ahd_mode src,
+						    ahd_mode dst);
+static __inline void ahd_extract_mode_state(struct ahd_softc *ahd,
+					    ahd_mode_state state,
+					    ahd_mode *src, ahd_mode *dst);
+static __inline void ahd_set_modes(struct ahd_softc *ahd, ahd_mode src,
+				   ahd_mode dst);
+static __inline void ahd_update_modes(struct ahd_softc *ahd);
+static __inline void ahd_assert_modes(struct ahd_softc *ahd, ahd_mode srcmode,
+				      ahd_mode dstmode, const char *file,
+				      int line);
+static __inline ahd_mode_state ahd_save_modes(struct ahd_softc *ahd);
+static __inline void ahd_restore_modes(struct ahd_softc *ahd,
+				       ahd_mode_state state);
+static __inline int  ahd_is_paused(struct ahd_softc *ahd);
+static __inline void ahd_pause(struct ahd_softc *ahd);
+static __inline void ahd_unpause(struct ahd_softc *ahd);
+
+static __inline void
+ahd_known_modes(struct ahd_softc *ahd, ahd_mode src, ahd_mode dst)
+{
+	ahd->src_mode = src;
+	ahd->dst_mode = dst;
+	ahd->saved_src_mode = src;
+	ahd->saved_dst_mode = dst;
+}
+
+static __inline ahd_mode_state
+ahd_build_mode_state(struct ahd_softc *ahd, ahd_mode src, ahd_mode dst)
+{
+	return ((src << SRC_MODE_SHIFT) | (dst << DST_MODE_SHIFT));
+}
+
+static __inline void
+ahd_extract_mode_state(struct ahd_softc *ahd, ahd_mode_state state,
+		       ahd_mode *src, ahd_mode *dst)
+{
+	*src = (state & SRC_MODE) >> SRC_MODE_SHIFT;
+	*dst = (state & DST_MODE) >> DST_MODE_SHIFT;
+}
+
+static __inline void
+ahd_set_modes(struct ahd_softc *ahd, ahd_mode src, ahd_mode dst)
+{
+	if (ahd->src_mode == src && ahd->dst_mode == dst)
+		return;
+#ifdef AHD_DEBUG
+	if (ahd->src_mode == AHD_MODE_UNKNOWN
+	 || ahd->dst_mode == AHD_MODE_UNKNOWN)
+		panic("Setting mode prior to saving it.\n");
+	if ((ahd_debug & AHD_SHOW_MODEPTR) != 0)
+		printf("%s: Setting mode 0x%x\n", ahd_name(ahd),
+		       ahd_build_mode_state(ahd, src, dst));
+#endif
+	ahd_outb(ahd, MODE_PTR, ahd_build_mode_state(ahd, src, dst));
+	ahd->src_mode = src;
+	ahd->dst_mode = dst;
+}
+
+static __inline void
+ahd_update_modes(struct ahd_softc *ahd)
+{
+	ahd_mode_state mode_ptr;
+	ahd_mode src;
+	ahd_mode dst;
+
+	mode_ptr = ahd_inb(ahd, MODE_PTR);
+#ifdef AHD_DEBUG
+	if ((ahd_debug & AHD_SHOW_MODEPTR) != 0)
+		printf("Reading mode 0x%x\n", mode_ptr);
+#endif
+	ahd_extract_mode_state(ahd, mode_ptr, &src, &dst);
+	ahd_known_modes(ahd, src, dst);
+}
+
+static __inline void
+ahd_assert_modes(struct ahd_softc *ahd, ahd_mode srcmode,
+		 ahd_mode dstmode, const char *file, int line)
+{
+#ifdef AHD_DEBUG
+	if ((srcmode & AHD_MK_MSK(ahd->src_mode)) == 0
+	 || (dstmode & AHD_MK_MSK(ahd->dst_mode)) == 0) {
+		panic("%s:%s:%d: Mode assertion failed.\n",
+		       ahd_name(ahd), file, line);
+	}
+#endif
+}
+
+static __inline ahd_mode_state
+ahd_save_modes(struct ahd_softc *ahd)
+{
+	if (ahd->src_mode == AHD_MODE_UNKNOWN
+	 || ahd->dst_mode == AHD_MODE_UNKNOWN)
+		ahd_update_modes(ahd);
+
+	return (ahd_build_mode_state(ahd, ahd->src_mode, ahd->dst_mode));
+}
+
+static __inline void
+ahd_restore_modes(struct ahd_softc *ahd, ahd_mode_state state)
+{
+	ahd_mode src;
+	ahd_mode dst;
+
+	ahd_extract_mode_state(ahd, state, &src, &dst);
+	ahd_set_modes(ahd, src, dst);
+}
+
+#define AHD_ASSERT_MODES(ahd, source, dest) \
+	ahd_assert_modes(ahd, source, dest, __FILE__, __LINE__);
+
+/*
+ * Determine whether the sequencer has halted code execution.
+ * Returns non-zero status if the sequencer is stopped.
+ */
+static __inline int
+ahd_is_paused(struct ahd_softc *ahd)
+{
+	return ((ahd_inb(ahd, HCNTRL) & PAUSE) != 0);
+}
+
+/*
+ * Request that the sequencer stop and wait, indefinitely, for it
+ * to stop.  The sequencer will only acknowledge that it is paused
+ * once it has reached an instruction boundary and PAUSEDIS is
+ * cleared in the SEQCTL register.  The sequencer may use PAUSEDIS
+ * for critical sections.
+ */
+static __inline void
+ahd_pause(struct ahd_softc *ahd)
+{
+	ahd_outb(ahd, HCNTRL, ahd->pause);
+
+	/*
+	 * Since the sequencer can disable pausing in a critical section, we
+	 * must loop until it actually stops.
+	 */
+	while (ahd_is_paused(ahd) == 0)
+		;
+}
+
+/*
+ * Allow the sequencer to continue program execution.
+ * We check here to ensure that no additional interrupt
+ * sources that would cause the sequencer to halt have been
+ * asserted.  If, for example, a SCSI bus reset is detected
+ * while we are fielding a different, pausing, interrupt type,
+ * we don't want to release the sequencer before going back
+ * into our interrupt handler and dealing with this new
+ * condition.
+ */
+static __inline void
+ahd_unpause(struct ahd_softc *ahd)
+{
+	/*
+	 * Automatically restore our modes to those saved
+	 * prior to the first change of the mode.
+	 */
+	if (ahd->saved_src_mode != AHD_MODE_UNKNOWN
+	 && ahd->saved_dst_mode != AHD_MODE_UNKNOWN) {
+		if ((ahd->flags & AHD_UPDATE_PEND_CMDS) != 0)
+			ahd_reset_cmds_pending(ahd);
+		ahd_set_modes(ahd, ahd->saved_src_mode, ahd->saved_dst_mode);
+	}
+
+	if ((ahd_inb(ahd, INTSTAT) & ~(SWTMINT | CMDCMPLT)) == 0)
+		ahd_outb(ahd, HCNTRL, ahd->unpause);
+
+	ahd_known_modes(ahd, AHD_MODE_UNKNOWN, AHD_MODE_UNKNOWN);
+}
+
+/*********************** Scatter Gather List Handling *************************/
+static __inline void	*ahd_sg_setup(struct ahd_softc *ahd, struct scb *scb,
+				      void *sgptr, bus_addr_t addr,
+				      bus_size_t len, int last);
+static __inline void	 ahd_setup_scb_common(struct ahd_softc *ahd,
+					      struct scb *scb);
+static __inline void	 ahd_setup_data_scb(struct ahd_softc *ahd,
+					    struct scb *scb);
+static __inline void	 ahd_setup_noxfer_scb(struct ahd_softc *ahd,
+					      struct scb *scb);
+
+static __inline void *
+ahd_sg_setup(struct ahd_softc *ahd, struct scb *scb,
+	     void *sgptr, bus_addr_t addr, bus_size_t len, int last)
+{
+	scb->sg_count++;
+	if (sizeof(bus_addr_t) > 4
+	 && (ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
+		struct ahd_dma64_seg *sg;
+
+		sg = (struct ahd_dma64_seg *)sgptr;
+		sg->addr = ahd_htole64(addr);
+		sg->len = ahd_htole32(len | (last ? AHD_DMA_LAST_SEG : 0));
+		return (sg + 1);
+	} else {
+		struct ahd_dma_seg *sg;
+
+		sg = (struct ahd_dma_seg *)sgptr;
+		sg->addr = ahd_htole32(addr & 0xFFFFFFFF);
+		sg->len = ahd_htole32(len | ((addr >> 8) & 0x7F000000)
+				    | (last ? AHD_DMA_LAST_SEG : 0));
+		return (sg + 1);
+	}
+}
+
+static __inline void
+ahd_setup_scb_common(struct ahd_softc *ahd, struct scb *scb)
+{
+	/* XXX Handle target mode SCBs. */
+	scb->crc_retry_count = 0;
+	if ((scb->flags & SCB_PACKETIZED) != 0) {
+		/* XXX what about ACA??  It is type 4, but TAG_TYPE == 0x3. */
+		scb->hscb->task_attribute= scb->hscb->control & SCB_TAG_TYPE;
+		scb->hscb->task_management = 0;
+		/*
+		 * For Rev A short lun workaround.
+		 */
+		scb->hscb->pkt_long_lun[6] = scb->hscb->lun;
+	}
+
+	if (scb->hscb->cdb_len <= MAX_CDB_LEN_WITH_SENSE_ADDR
+	 || (scb->hscb->cdb_len & SCB_CDB_LEN_PTR) != 0)
+		scb->hscb->shared_data.idata.cdb_plus_saddr.sense_addr =
+		    ahd_htole32(scb->sense_busaddr);
+}
+
+static __inline void
+ahd_setup_data_scb(struct ahd_softc *ahd, struct scb *scb)
+{
+	/*
+	 * Copy the first SG into the "current" data ponter area.
+	 */
+	if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
+		struct ahd_dma64_seg *sg;
+
+		sg = (struct ahd_dma64_seg *)scb->sg_list;
+		scb->hscb->dataptr = sg->addr;
+		scb->hscb->datacnt = sg->len;
+	} else {
+		struct ahd_dma_seg *sg;
+
+		sg = (struct ahd_dma_seg *)scb->sg_list;
+		scb->hscb->dataptr = sg->addr;
+		if ((ahd->flags & AHD_39BIT_ADDRESSING) != 0) {
+			uint64_t high_addr;
+
+			high_addr = ahd_le32toh(sg->len) & 0x7F000000;
+			scb->hscb->dataptr |= ahd_htole64(high_addr << 8);
+		}
+		scb->hscb->datacnt = sg->len;
+	}
+	/*
+	 * Note where to find the SG entries in bus space.
+	 * We also set the full residual flag which the 
+	 * sequencer will clear as soon as a data transfer
+	 * occurs.
+	 */
+	scb->hscb->sgptr = ahd_htole32(scb->sg_list_busaddr|SG_FULL_RESID);
+}
+
+static __inline void
+ahd_setup_noxfer_scb(struct ahd_softc *ahd, struct scb *scb)
+{
+	scb->hscb->sgptr = ahd_htole32(SG_LIST_NULL);
+	scb->hscb->dataptr = 0;
+	scb->hscb->datacnt = 0;
+}
+
+/************************** Memory mapping routines ***************************/
+static __inline size_t	ahd_sg_size(struct ahd_softc *ahd);
+static __inline void *
+			ahd_sg_bus_to_virt(struct ahd_softc *ahd,
+					   struct scb *scb,
+					   uint32_t sg_busaddr);
+static __inline uint32_t
+			ahd_sg_virt_to_bus(struct ahd_softc *ahd,
+					   struct scb *scb,
+					   void *sg);
+static __inline void	ahd_sync_scb(struct ahd_softc *ahd,
+				     struct scb *scb, int op);
+static __inline void	ahd_sync_sglist(struct ahd_softc *ahd,
+					struct scb *scb, int op);
+static __inline void	ahd_sync_sense(struct ahd_softc *ahd,
+				       struct scb *scb, int op);
+static __inline uint32_t
+			ahd_targetcmd_offset(struct ahd_softc *ahd,
+					     u_int index);
+
+static __inline size_t
+ahd_sg_size(struct ahd_softc *ahd)
+{
+	if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
+		return (sizeof(struct ahd_dma64_seg));
+	return (sizeof(struct ahd_dma_seg));
+}
+
+static __inline void *
+ahd_sg_bus_to_virt(struct ahd_softc *ahd, struct scb *scb, uint32_t sg_busaddr)
+{
+	bus_addr_t sg_offset;
+
+	/* sg_list_phys points to entry 1, not 0 */
+	sg_offset = sg_busaddr - (scb->sg_list_busaddr - ahd_sg_size(ahd));
+	return ((uint8_t *)scb->sg_list + sg_offset);
+}
+
+static __inline uint32_t
+ahd_sg_virt_to_bus(struct ahd_softc *ahd, struct scb *scb, void *sg)
+{
+	bus_addr_t sg_offset;
+
+	/* sg_list_phys points to entry 1, not 0 */
+	sg_offset = ((uint8_t *)sg - (uint8_t *)scb->sg_list)
+		  - ahd_sg_size(ahd);
+
+	return (scb->sg_list_busaddr + sg_offset);
+}
+
+static __inline void
+ahd_sync_scb(struct ahd_softc *ahd, struct scb *scb, int op)
+{
+	ahd_dmamap_sync(ahd, ahd->scb_data.hscb_dmat,
+			scb->hscb_map->dmamap,
+			/*offset*/(uint8_t*)scb->hscb - scb->hscb_map->vaddr,
+			/*len*/sizeof(*scb->hscb), op);
+}
+
+static __inline void
+ahd_sync_sglist(struct ahd_softc *ahd, struct scb *scb, int op)
+{
+	if (scb->sg_count == 0)
+		return;
+
+	ahd_dmamap_sync(ahd, ahd->scb_data.sg_dmat,
+			scb->sg_map->dmamap,
+			/*offset*/scb->sg_list_busaddr - ahd_sg_size(ahd),
+			/*len*/ahd_sg_size(ahd) * scb->sg_count, op);
+}
+
+static __inline void
+ahd_sync_sense(struct ahd_softc *ahd, struct scb *scb, int op)
+{
+	ahd_dmamap_sync(ahd, ahd->scb_data.sense_dmat,
+			scb->sense_map->dmamap,
+			/*offset*/scb->sense_busaddr,
+			/*len*/AHD_SENSE_BUFSIZE, op);
+}
+
+static __inline uint32_t
+ahd_targetcmd_offset(struct ahd_softc *ahd, u_int index)
+{
+	return (((uint8_t *)&ahd->targetcmds[index])
+	       - (uint8_t *)ahd->qoutfifo);
+}
+
+/*********************** Miscelaneous Support Functions ***********************/
+static __inline void	ahd_complete_scb(struct ahd_softc *ahd,
+					 struct scb *scb);
+static __inline void	ahd_update_residual(struct ahd_softc *ahd,
+					    struct scb *scb);
+static __inline struct ahd_initiator_tinfo *
+			ahd_fetch_transinfo(struct ahd_softc *ahd,
+					    char channel, u_int our_id,
+					    u_int remote_id,
+					    struct ahd_tmode_tstate **tstate);
+static __inline uint16_t
+			ahd_inw(struct ahd_softc *ahd, u_int port);
+static __inline void	ahd_outw(struct ahd_softc *ahd, u_int port,
+				 u_int value);
+static __inline uint32_t
+			ahd_inl(struct ahd_softc *ahd, u_int port);
+static __inline void	ahd_outl(struct ahd_softc *ahd, u_int port,
+				 uint32_t value);
+static __inline uint64_t
+			ahd_inq(struct ahd_softc *ahd, u_int port);
+static __inline void	ahd_outq(struct ahd_softc *ahd, u_int port,
+				 uint64_t value);
+static __inline u_int	ahd_get_scbptr(struct ahd_softc *ahd);
+static __inline void	ahd_set_scbptr(struct ahd_softc *ahd, u_int scbptr);
+static __inline u_int	ahd_get_hnscb_qoff(struct ahd_softc *ahd);
+static __inline void	ahd_set_hnscb_qoff(struct ahd_softc *ahd, u_int value);
+static __inline u_int	ahd_get_hescb_qoff(struct ahd_softc *ahd);
+static __inline void	ahd_set_hescb_qoff(struct ahd_softc *ahd, u_int value);
+static __inline u_int	ahd_get_snscb_qoff(struct ahd_softc *ahd);
+static __inline void	ahd_set_snscb_qoff(struct ahd_softc *ahd, u_int value);
+static __inline u_int	ahd_get_sescb_qoff(struct ahd_softc *ahd);
+static __inline void	ahd_set_sescb_qoff(struct ahd_softc *ahd, u_int value);
+static __inline u_int	ahd_get_sdscb_qoff(struct ahd_softc *ahd);
+static __inline void	ahd_set_sdscb_qoff(struct ahd_softc *ahd, u_int value);
+static __inline u_int	ahd_inb_scbram(struct ahd_softc *ahd, u_int offset);
+static __inline u_int	ahd_inw_scbram(struct ahd_softc *ahd, u_int offset);
+static __inline uint32_t
+			ahd_inl_scbram(struct ahd_softc *ahd, u_int offset);
+static __inline void	ahd_swap_with_next_hscb(struct ahd_softc *ahd,
+						struct scb *scb);
+static __inline void	ahd_queue_scb(struct ahd_softc *ahd, struct scb *scb);
+static __inline uint8_t *
+			ahd_get_sense_buf(struct ahd_softc *ahd,
+					  struct scb *scb);
+static __inline uint32_t
+			ahd_get_sense_bufaddr(struct ahd_softc *ahd,
+					      struct scb *scb);
+
+static __inline void
+ahd_complete_scb(struct ahd_softc *ahd, struct scb *scb)
+{
+	uint32_t sgptr;
+
+	sgptr = ahd_le32toh(scb->hscb->sgptr);
+	if ((sgptr & SG_STATUS_VALID) != 0)
+		ahd_handle_scb_status(ahd, scb);
+	else
+		ahd_done(ahd, scb);
+}
+
+/*
+ * Determine whether the sequencer reported a residual
+ * for this SCB/transaction.
+ */
+static __inline void
+ahd_update_residual(struct ahd_softc *ahd, struct scb *scb)
+{
+	uint32_t sgptr;
+
+	sgptr = ahd_le32toh(scb->hscb->sgptr);
+	if ((sgptr & SG_STATUS_VALID) != 0)
+		ahd_calc_residual(ahd, scb);
+}
+
+/*
+ * Return pointers to the transfer negotiation information
+ * for the specified our_id/remote_id pair.
+ */
+static __inline struct ahd_initiator_tinfo *
+ahd_fetch_transinfo(struct ahd_softc *ahd, char channel, u_int our_id,
+		    u_int remote_id, struct ahd_tmode_tstate **tstate)
+{
+	/*
+	 * Transfer data structures are stored from the perspective
+	 * of the target role.  Since the parameters for a connection
+	 * in the initiator role to a given target are the same as
+	 * when the roles are reversed, we pretend we are the target.
+	 */
+	if (channel == 'B')
+		our_id += 8;
+	*tstate = ahd->enabled_targets[our_id];
+	return (&(*tstate)->transinfo[remote_id]);
+}
+
+#define AHD_COPY_COL_IDX(dst, src)				\
+do {								\
+	dst->hscb->scsiid = src->hscb->scsiid;			\
+	dst->hscb->lun = src->hscb->lun;			\
+} while (0)
+
+static __inline uint16_t
+ahd_inw(struct ahd_softc *ahd, u_int port)
+{
+	return ((ahd_inb(ahd, port+1) << 8) | ahd_inb(ahd, port));
+}
+
+static __inline void
+ahd_outw(struct ahd_softc *ahd, u_int port, u_int value)
+{
+	ahd_outb(ahd, port, value & 0xFF);
+	ahd_outb(ahd, port+1, (value >> 8) & 0xFF);
+}
+
+static __inline uint32_t
+ahd_inl(struct ahd_softc *ahd, u_int port)
+{
+	return ((ahd_inb(ahd, port))
+	      | (ahd_inb(ahd, port+1) << 8)
+	      | (ahd_inb(ahd, port+2) << 16)
+	      | (ahd_inb(ahd, port+3) << 24));
+}
+
+static __inline void
+ahd_outl(struct ahd_softc *ahd, u_int port, uint32_t value)
+{
+	ahd_outb(ahd, port, (value) & 0xFF);
+	ahd_outb(ahd, port+1, ((value) >> 8) & 0xFF);
+	ahd_outb(ahd, port+2, ((value) >> 16) & 0xFF);
+	ahd_outb(ahd, port+3, ((value) >> 24) & 0xFF);
+}
+
+static __inline uint64_t
+ahd_inq(struct ahd_softc *ahd, u_int port)
+{
+	return ((ahd_inb(ahd, port))
+	      | (ahd_inb(ahd, port+1) << 8)
+	      | (ahd_inb(ahd, port+2) << 16)
+	      | (ahd_inb(ahd, port+3) << 24)
+	      | (((uint64_t)ahd_inb(ahd, port+4)) << 32)
+	      | (((uint64_t)ahd_inb(ahd, port+5)) << 40)
+	      | (((uint64_t)ahd_inb(ahd, port+6)) << 48)
+	      | (((uint64_t)ahd_inb(ahd, port+7)) << 56));
+}
+
+static __inline void
+ahd_outq(struct ahd_softc *ahd, u_int port, uint64_t value)
+{
+	ahd_outb(ahd, port, value & 0xFF);
+	ahd_outb(ahd, port+1, (value >> 8) & 0xFF);
+	ahd_outb(ahd, port+2, (value >> 16) & 0xFF);
+	ahd_outb(ahd, port+3, (value >> 24) & 0xFF);
+	ahd_outb(ahd, port+4, (value >> 32) & 0xFF);
+	ahd_outb(ahd, port+5, (value >> 40) & 0xFF);
+	ahd_outb(ahd, port+6, (value >> 48) & 0xFF);
+	ahd_outb(ahd, port+7, (value >> 56) & 0xFF);
+}
+
+static __inline u_int
+ahd_get_scbptr(struct ahd_softc *ahd)
+{
+	AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
+			 ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK));
+	return (ahd_inb(ahd, SCBPTR) | (ahd_inb(ahd, SCBPTR + 1) << 8));
+}
+
+static __inline void
+ahd_set_scbptr(struct ahd_softc *ahd, u_int scbptr)
+{
+	AHD_ASSERT_MODES(ahd, ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK),
+			 ~(AHD_MODE_UNKNOWN_MSK|AHD_MODE_CFG_MSK));
+	ahd_outb(ahd, SCBPTR, scbptr & 0xFF);
+	ahd_outb(ahd, SCBPTR+1, (scbptr >> 8) & 0xFF);
+}
+
+static __inline u_int
+ahd_get_hnscb_qoff(struct ahd_softc *ahd)
+{
+	return (ahd_inw_atomic(ahd, HNSCB_QOFF));
+}
+
+static __inline void
+ahd_set_hnscb_qoff(struct ahd_softc *ahd, u_int value)
+{
+	ahd_outw_atomic(ahd, HNSCB_QOFF, value);
+}
+
+static __inline u_int
+ahd_get_hescb_qoff(struct ahd_softc *ahd)
+{
+	return (ahd_inb(ahd, HESCB_QOFF));
+}
+
+static __inline void
+ahd_set_hescb_qoff(struct ahd_softc *ahd, u_int value)
+{
+	ahd_outb(ahd, HESCB_QOFF, value);
+}
+
+static __inline u_int
+ahd_get_snscb_qoff(struct ahd_softc *ahd)
+{
+	u_int oldvalue;
+
+	AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
+	oldvalue = ahd_inw(ahd, SNSCB_QOFF);
+	ahd_outw(ahd, SNSCB_QOFF, oldvalue);
+	return (oldvalue);
+}
+
+static __inline void
+ahd_set_snscb_qoff(struct ahd_softc *ahd, u_int value)
+{
+	AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
+	ahd_outw(ahd, SNSCB_QOFF, value);
+}
+
+static __inline u_int
+ahd_get_sescb_qoff(struct ahd_softc *ahd)
+{
+	AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
+	return (ahd_inb(ahd, SESCB_QOFF));
+}
+
+static __inline void
+ahd_set_sescb_qoff(struct ahd_softc *ahd, u_int value)
+{
+	AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
+	ahd_outb(ahd, SESCB_QOFF, value);
+}
+
+static __inline u_int
+ahd_get_sdscb_qoff(struct ahd_softc *ahd)
+{
+	AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
+	return (ahd_inb(ahd, SDSCB_QOFF) | (ahd_inb(ahd, SDSCB_QOFF + 1) << 8));
+}
+
+static __inline void
+ahd_set_sdscb_qoff(struct ahd_softc *ahd, u_int value)
+{
+	AHD_ASSERT_MODES(ahd, AHD_MODE_CCHAN_MSK, AHD_MODE_CCHAN_MSK);
+	ahd_outb(ahd, SDSCB_QOFF, value & 0xFF);
+	ahd_outb(ahd, SDSCB_QOFF+1, (value >> 8) & 0xFF);
+}
+
+static __inline u_int
+ahd_inb_scbram(struct ahd_softc *ahd, u_int offset)
+{
+	u_int value;
+
+	/*
+	 * Workaround PCI-X Rev A. hardware bug.
+	 * After a host read of SCB memory, the chip
+	 * may become confused into thinking prefetch
+	 * was required.  This starts the discard timer
+	 * running and can cause an unexpected discard
+	 * timer interrupt.  The work around is to read
+	 * a normal register prior to the exhaustion of
+	 * the discard timer.  The mode pointer register
+	 * has no side effects and so serves well for
+	 * this purpose.
+	 *
+	 * Razor #528
+	 */
+	value = ahd_inb(ahd, offset);
+	ahd_inb(ahd, MODE_PTR);
+	return (value);
+}
+
+static __inline u_int
+ahd_inw_scbram(struct ahd_softc *ahd, u_int offset)
+{
+	return (ahd_inb_scbram(ahd, offset)
+	      | (ahd_inb_scbram(ahd, offset+1) << 8));
+}
+
+static __inline uint32_t
+ahd_inl_scbram(struct ahd_softc *ahd, u_int offset)
+{
+	return (ahd_inb_scbram(ahd, offset)
+	      | (ahd_inb_scbram(ahd, offset+1) << 8)
+	      | (ahd_inb_scbram(ahd, offset+2) << 16)
+	      | (ahd_inb_scbram(ahd, offset+3) << 24));
+}
+
+static __inline struct scb *
+ahd_lookup_scb(struct ahd_softc *ahd, u_int tag)
+{
+	struct scb* scb;
+
+	if (tag >= AHD_SCB_MAX)
+		return (NULL);
+	scb = ahd->scb_data.scbindex[tag];
+	if (scb != NULL)
+		ahd_sync_scb(ahd, scb,
+			     BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
+	return (scb);
+}
+
+static __inline void
+ahd_swap_with_next_hscb(struct ahd_softc *ahd, struct scb *scb)
+{
+	struct hardware_scb *q_hscb;
+	uint32_t saved_hscb_busaddr;
+
+	/*
+	 * Our queuing method is a bit tricky.  The card
+	 * knows in advance which HSCB (by address) to download,
+	 * and we can't disappoint it.  To achieve this, the next
+	 * HSCB to download is saved off in ahd->next_queued_hscb.
+	 * When we are called to queue "an arbitrary scb",
+	 * we copy the contents of the incoming HSCB to the one
+	 * the sequencer knows about, swap HSCB pointers and
+	 * finally assign the SCB to the tag indexed location
+	 * in the scb_array.  This makes sure that we can still
+	 * locate the correct SCB by SCB_TAG.
+	 */
+	q_hscb = ahd->next_queued_hscb;
+	saved_hscb_busaddr = q_hscb->hscb_busaddr;
+	memcpy(q_hscb, scb->hscb, sizeof(*scb->hscb));
+	q_hscb->hscb_busaddr = saved_hscb_busaddr;
+	q_hscb->next_hscb_busaddr = scb->hscb->hscb_busaddr;
+
+	/* Now swap HSCB pointers. */
+	ahd->next_queued_hscb = scb->hscb;
+	scb->hscb = q_hscb;
+
+	/* Now define the mapping from tag to SCB in the scbindex */
+	ahd->scb_data.scbindex[SCB_GET_TAG(scb)] = scb;
+}
+
+/*
+ * Tell the sequencer about a new transaction to execute.
+ */
+static __inline void
+ahd_queue_scb(struct ahd_softc *ahd, struct scb *scb)
+{
+	ahd_swap_with_next_hscb(ahd, scb);
+
+	if (SCBID_IS_NULL(SCB_GET_TAG(scb)))
+		panic("Attempt to queue invalid SCB tag %x\n",
+		      SCB_GET_TAG(scb));
+
+	/*
+	 * Keep a history of SCBs we've downloaded in the qinfifo.
+	 */
+	ahd->qinfifo[AHD_QIN_WRAP(ahd->qinfifonext)] = SCB_GET_TAG(scb);
+	ahd->qinfifonext++;
+
+	if (scb->sg_count != 0)
+		ahd_setup_data_scb(ahd, scb);
+	else
+		ahd_setup_noxfer_scb(ahd, scb);
+	ahd_setup_scb_common(ahd, scb);
+
+	/*
+	 * Make sure our data is consistant from the
+	 * perspective of the adapter.
+	 */
+	ahd_sync_scb(ahd, scb, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
+
+#ifdef AHD_DEBUG
+	if ((ahd_debug & AHD_SHOW_QUEUE) != 0) {
+		printf("%s: Queueing SCB 0x%x bus addr 0x%x - 0x%x%x/0x%x\n",
+		       ahd_name(ahd),
+		       SCB_GET_TAG(scb), scb->hscb->hscb_busaddr,
+		       (u_int)((scb->hscb->dataptr >> 32) & 0xFFFFFFFF),
+		       (u_int)(scb->hscb->dataptr & 0xFFFFFFFF),
+		       scb->hscb->datacnt);
+	}
+#endif
+	/* Tell the adapter about the newly queued SCB */
+	ahd_set_hnscb_qoff(ahd, ahd->qinfifonext);
+}
+
+static __inline uint8_t *
+ahd_get_sense_buf(struct ahd_softc *ahd, struct scb *scb)
+{
+	return (scb->sense_data);
+}
+
+static __inline uint32_t
+ahd_get_sense_bufaddr(struct ahd_softc *ahd, struct scb *scb)
+{
+	return (scb->sense_busaddr);
+}
+
+/************************** Interrupt Processing ******************************/
+static __inline void	ahd_sync_qoutfifo(struct ahd_softc *ahd, int op);
+static __inline void	ahd_sync_tqinfifo(struct ahd_softc *ahd, int op);
+static __inline u_int	ahd_check_cmdcmpltqueues(struct ahd_softc *ahd);
+static __inline void	ahd_intr(struct ahd_softc *ahd);
+
+static __inline void
+ahd_sync_qoutfifo(struct ahd_softc *ahd, int op)
+{
+	ahd_dmamap_sync(ahd, ahd->shared_data_dmat, ahd->shared_data_dmamap,
+			/*offset*/0, /*len*/AHC_SCB_MAX * sizeof(uint16_t), op);
+}
+
+static __inline void
+ahd_sync_tqinfifo(struct ahd_softc *ahd, int op)
+{
+#ifdef AHD_TARGET_MODE
+	if ((ahd->flags & AHD_TARGETROLE) != 0) {
+		ahd_dmamap_sync(ahd, ahd->shared_data_dmat,
+				ahd->shared_data_dmamap,
+				ahd_targetcmd_offset(ahd, 0),
+				sizeof(struct target_cmd) * AHD_TMODE_CMDS,
+				op);
+	}
+#endif
+}
+
+/*
+ * See if the firmware has posted any completed commands
+ * into our in-core command complete fifos.
+ */
+#define AHD_RUN_QOUTFIFO 0x1
+#define AHD_RUN_TQINFIFO 0x2
+static __inline u_int
+ahd_check_cmdcmpltqueues(struct ahd_softc *ahd)
+{
+	u_int retval;
+
+	retval = 0;
+	ahd_dmamap_sync(ahd, ahd->shared_data_dmat, ahd->shared_data_dmamap,
+			/*offset*/ahd->qoutfifonext, /*len*/2,
+			BUS_DMASYNC_POSTREAD);
+	if ((ahd->qoutfifo[ahd->qoutfifonext]
+	     & QOUTFIFO_ENTRY_VALID_LE) == ahd->qoutfifonext_valid_tag)
+		retval |= AHD_RUN_QOUTFIFO;
+#ifdef AHD_TARGET_MODE
+	if ((ahd->flags & AHD_TARGETROLE) != 0
+	 && (ahd->flags & AHD_TQINFIFO_BLOCKED) == 0) {
+		ahd_dmamap_sync(ahd, ahd->shared_data_dmat,
+				ahd->shared_data_dmamap,
+				ahd_targetcmd_offset(ahd, ahd->tqinfifofnext),
+				/*len*/sizeof(struct target_cmd),
+				BUS_DMASYNC_POSTREAD);
+		if (ahd->targetcmds[ahd->tqinfifonext].cmd_valid != 0)
+			retval |= AHD_RUN_TQINFIFO;
+	}
+#endif
+	return (retval);
+}
+
+/*
+ * Catch an interrupt from the adapter
+ */
+static __inline void
+ahd_intr(struct ahd_softc *ahd)
+{
+	u_int	intstat;
+
+	if ((ahd->pause & INTEN) == 0) {
+		/*
+		 * Our interrupt is not enabled on the chip
+		 * and may be disabled for re-entrancy reasons,
+		 * so just return.  This is likely just a shared
+		 * interrupt.
+		 */
+		return;
+	}
+
+	/*
+	 * Instead of directly reading the interrupt status register,
+	 * infer the cause of the interrupt by checking our in-core
+	 * completion queues.  This avoids a costly PCI bus read in
+	 * most cases.
+	 */
+	if ((ahd->flags & AHD_ALL_INTERRUPTS) == 0
+	 && (ahd_check_cmdcmpltqueues(ahd) != 0))
+		intstat = CMDCMPLT;
+	else
+		intstat = ahd_inb(ahd, INTSTAT);
+
+	if (intstat & CMDCMPLT) {
+		ahd_outb(ahd, CLRINT, CLRCMDINT);
+
+		/*
+		 * Ensure that the chip sees that we've cleared
+		 * this interrupt before we walk the output fifo.
+		 * Otherwise, we may, due to posted bus writes,
+		 * clear the interrupt after we finish the scan,
+		 * and after the sequencer has added new entries
+		 * and asserted the interrupt again.
+		 */
+		if ((ahd->bugs & AHD_INTCOLLISION_BUG) != 0) {
+			if (ahd_is_paused(ahd)) {
+				/*
+				 * Potentially lost SEQINT.
+				 * If SEQINTCODE is non-zero,
+				 * simulate the SEQINT.
+				 */
+				if (ahd_inb(ahd, SEQINTCODE) != NO_SEQINT)
+					intstat |= SEQINT;
+			}
+		} else {
+			ahd_flush_device_writes(ahd);
+		}
+		ahd_run_qoutfifo(ahd);
+		ahd->cmdcmplt_counts[ahd->cmdcmplt_bucket]++;
+		ahd->cmdcmplt_total++;
+#ifdef AHD_TARGET_MODE
+		if ((ahd->flags & AHD_TARGETROLE) != 0)
+			ahd_run_tqinfifo(ahd, /*paused*/FALSE);
+#endif
+	}
+
+	if (intstat == 0xFF && (ahd->features & AHD_REMOVABLE) != 0)
+		/* Hot eject */
+		return;
+
+	if ((intstat & INT_PEND) == 0)
+		return;
+
+	if (intstat & HWERRINT) {
+		ahd_handle_hwerrint(ahd);
+		return;
+	}
+
+	if ((intstat & (PCIINT|SPLTINT)) != 0) {
+		ahd->bus_intr(ahd);
+		return;
+	}
+
+	if ((intstat & SEQINT) != 0)
+		ahd_handle_seqint(ahd, intstat);
+
+	if ((intstat & SCSIINT) != 0)
+		ahd_handle_scsiint(ahd, intstat);
+}
+
+#endif  /* _AIC79XX_INLINE_H_ */
diff -Nru a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c	Mon Dec 23 21:22:03 2002
@@ -0,0 +1,5242 @@
+/*
+ * Adaptec AIC79xx device driver for Linux.
+ *
+ * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_osm.c#100 $
+ *
+ * --------------------------------------------------------------------------
+ * Copyright (c) 1994-2000 Justin T. Gibbs.
+ * Copyright (c) 1997-1999 Doug Ledford
+ * Copyright (c) 2000-2002 Adaptec Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ */
+
+/*
+ * This is the only file where module.h should
+ * embed module global version info.
+ */
+#define AHD_MODVERSION_FILE
+
+#include "aic79xx_osm.h"
+#include "aic79xx_inline.h"
+#include <scsi/scsicam.h>
+
+/*
+ * Include aiclib.c as part of our
+ * "module dependencies are hard" work around.
+ */
+#include "aiclib.c"
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+#include <linux/init.h>		/* __setup */
+#endif
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+#include "sd.h"			/* For geometry detection */
+#endif
+
+#include <linux/mm.h>		/* For fetching system memory size */
+
+#define __KERNEL_SYSCALLS__
+
+#include <linux/unistd.h>
+static int errno;
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
+/*
+ * Lock protecting manipulation of the ahd softc list.
+ */
+spinlock_t ahd_list_spinlock;
+#endif
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
+struct proc_dir_entry proc_scsi_aic79xx = {
+	PROC_SCSI_AIC79XX, 7, "aic79xx",
+	S_IFDIR | S_IRUGO | S_IXUGO, 2,
+	0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+};
+#endif
+
+/*
+ * Bucket size for counting good commands in between bad ones.
+ */
+#define AHD_LINUX_ERR_THRESH	1000
+
+/*
+ * Set this to the delay in seconds after SCSI bus reset.
+ * Note, we honor this only for the initial bus reset.
+ * The scsi error recovery code performs its own bus settle
+ * delay handling for error recovery actions.
+ */
+#ifdef CONFIG_AIC79XX_RESET_DELAY_MS
+#define AIC79XX_RESET_DELAY CONFIG_AIC79XX_RESET_DELAY_MS
+#else
+#define AIC79XX_RESET_DELAY 5000
+#endif
+
+/*
+ * To change the default number of tagged transactions allowed per-device,
+ * add a line to the lilo.conf file like:
+ * append="aic79xx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}"
+ * which will result in the first four devices on the first two
+ * controllers being set to a tagged queue depth of 32.
+ *
+ * The tag_commands is an array of 16 to allow for wide and twin adapters.
+ * Twin adapters will use indexes 0-7 for channel 0, and indexes 8-15
+ * for channel 1.
+ */
+typedef struct {
+	uint16_t tag_commands[16];	/* Allow for wide/twin adapters. */
+} adapter_tag_info_t;
+
+/*
+ * Modify this as you see fit for your system.
+ *
+ * 0			tagged queuing disabled
+ * 1 <= n <= 253	n == max tags ever dispatched.
+ *
+ * The driver will throttle the number of commands dispatched to a
+ * device if it returns queue full.  For devices with a fixed maximum
+ * queue depth, the driver will eventually determine this depth and
+ * lock it in (a console message is printed to indicate that a lock
+ * has occurred).  On some devices, queue full is returned for a temporary
+ * resource shortage.  These devices will return queue full at varying
+ * depths.  The driver will throttle back when the queue fulls occur and
+ * attempt to slowly increase the depth over time as the device recovers
+ * from the resource shortage.
+ *
+ * In this example, the first line will disable tagged queueing for all
+ * the devices on the first probed aic79xx adapter.
+ *
+ * The second line enables tagged queueing with 4 commands/LUN for IDs
+ * (0, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
+ * driver to attempt to use up to 64 tags for ID 1.
+ *
+ * The third line is the same as the first line.
+ *
+ * The fourth line disables tagged queueing for devices 0 and 3.  It
+ * enables tagged queueing for the other IDs, with 16 commands/LUN
+ * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
+ * IDs 2, 5-7, and 9-15.
+ */
+
+/*
+ * NOTE: The below structure is for reference only, the actual structure
+ *       to modify in order to change things is just below this comment block.
+adapter_tag_info_t aic79xx_tag_info[] =
+{
+	{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+	{{4, 64, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4}},
+	{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+	{{0, 16, 4, 0, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
+};
+*/
+
+#ifdef CONFIG_AIC79XX_CMDS_PER_DEVICE
+#define AIC79XX_CMDS_PER_DEVICE CONFIG_AIC79XX_CMDS_PER_DEVICE
+#else
+#define AIC79XX_CMDS_PER_DEVICE AHD_MAX_QUEUE
+#endif
+
+#define AIC79XX_CONFIGED_TAG_COMMANDS {					\
+	AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE,		\
+	AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE,		\
+	AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE,		\
+	AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE,		\
+	AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE,		\
+	AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE,		\
+	AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE,		\
+	AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE		\
+}
+
+/*
+ * By default, use the number of commands specified by
+ * the users kernel configuration.
+ */
+static adapter_tag_info_t aic79xx_tag_info[] =
+{
+	{AIC79XX_CONFIGED_TAG_COMMANDS},
+	{AIC79XX_CONFIGED_TAG_COMMANDS},
+	{AIC79XX_CONFIGED_TAG_COMMANDS},
+	{AIC79XX_CONFIGED_TAG_COMMANDS},
+	{AIC79XX_CONFIGED_TAG_COMMANDS},
+	{AIC79XX_CONFIGED_TAG_COMMANDS},
+	{AIC79XX_CONFIGED_TAG_COMMANDS},
+	{AIC79XX_CONFIGED_TAG_COMMANDS},
+	{AIC79XX_CONFIGED_TAG_COMMANDS},
+	{AIC79XX_CONFIGED_TAG_COMMANDS},
+	{AIC79XX_CONFIGED_TAG_COMMANDS},
+	{AIC79XX_CONFIGED_TAG_COMMANDS},
+	{AIC79XX_CONFIGED_TAG_COMMANDS},
+	{AIC79XX_CONFIGED_TAG_COMMANDS},
+	{AIC79XX_CONFIGED_TAG_COMMANDS},
+	{AIC79XX_CONFIGED_TAG_COMMANDS}
+};
+
+/*
+ * By default, read streaming is disabled.  In theory,
+ * read streaming should enhance performance, but early
+ * U320 drive firmware actually performs slower with
+ * read streaming enabled.
+ */
+#ifdef CONFIG_AIC79XX_ENABLE_RD_STRM
+#define AIC79XX_CONFIGED_RD_STRM 0xFFFF
+#else
+#define AIC79XX_CONFIGED_RD_STRM 0
+#endif
+
+static uint16_t aic79xx_rd_strm_info[] =
+{
+	AIC79XX_CONFIGED_RD_STRM,
+	AIC79XX_CONFIGED_RD_STRM,
+	AIC79XX_CONFIGED_RD_STRM,
+	AIC79XX_CONFIGED_RD_STRM,
+	AIC79XX_CONFIGED_RD_STRM,
+	AIC79XX_CONFIGED_RD_STRM,
+	AIC79XX_CONFIGED_RD_STRM,
+	AIC79XX_CONFIGED_RD_STRM,
+	AIC79XX_CONFIGED_RD_STRM,
+	AIC79XX_CONFIGED_RD_STRM,
+	AIC79XX_CONFIGED_RD_STRM,
+	AIC79XX_CONFIGED_RD_STRM,
+	AIC79XX_CONFIGED_RD_STRM,
+	AIC79XX_CONFIGED_RD_STRM,
+	AIC79XX_CONFIGED_RD_STRM,
+	AIC79XX_CONFIGED_RD_STRM
+};
+
+/*
+ * DV option:
+ *
+ * positive value = DV Enabled
+ * zero		  = DV Disabled
+ * negative value = DV Default for adapter type/seeprom
+ */
+#ifdef CONFIG_AIC79XX_DV_SETTING
+#define AIC79XX_CONFIGED_DV CONFIG_AIC79XX_DV_SETTING
+#else
+#define AIC79XX_CONFIGED_DV -1
+#endif
+
+static int8_t aic79xx_dv_settings[] =
+{
+	AIC79XX_CONFIGED_DV,
+	AIC79XX_CONFIGED_DV,
+	AIC79XX_CONFIGED_DV,
+	AIC79XX_CONFIGED_DV,
+	AIC79XX_CONFIGED_DV,
+	AIC79XX_CONFIGED_DV,
+	AIC79XX_CONFIGED_DV,
+	AIC79XX_CONFIGED_DV,
+	AIC79XX_CONFIGED_DV,
+	AIC79XX_CONFIGED_DV,
+	AIC79XX_CONFIGED_DV,
+	AIC79XX_CONFIGED_DV,
+	AIC79XX_CONFIGED_DV,
+	AIC79XX_CONFIGED_DV,
+	AIC79XX_CONFIGED_DV,
+	AIC79XX_CONFIGED_DV
+};
+
+/*
+ * The I/O cell on the chip is very configurable in respect to its analog
+ * characteristics.  Set the defaults here; they can be overriden with
+ * the proper insmod parameters.
+ */
+struct ahd_linux_iocell_opts
+{
+	uint8_t	precomp;
+	uint8_t	slewrate;
+	uint8_t amplitude;
+};
+#define AIC79XX_DEFAULT_PRECOMP		0xFF
+#define AIC79XX_DEFAULT_SLEWRATE	0xFF
+#define AIC79XX_DEFAULT_AMPLITUDE	0xFF
+#define AIC79XX_DEFAULT_IOOPTS			\
+{						\
+	AIC79XX_DEFAULT_PRECOMP,		\
+	AIC79XX_DEFAULT_SLEWRATE,		\
+	AIC79XX_DEFAULT_AMPLITUDE		\
+}
+#define AIC79XX_PRECOMP_INDEX	0
+#define AIC79XX_SLEWRATE_INDEX	1
+#define AIC79XX_AMPLITUDE_INDEX	2
+static struct ahd_linux_iocell_opts aic79xx_iocell_info[] =
+{
+	AIC79XX_DEFAULT_IOOPTS,
+	AIC79XX_DEFAULT_IOOPTS,
+	AIC79XX_DEFAULT_IOOPTS,
+	AIC79XX_DEFAULT_IOOPTS,
+	AIC79XX_DEFAULT_IOOPTS,
+	AIC79XX_DEFAULT_IOOPTS,
+	AIC79XX_DEFAULT_IOOPTS,
+	AIC79XX_DEFAULT_IOOPTS,
+	AIC79XX_DEFAULT_IOOPTS,
+	AIC79XX_DEFAULT_IOOPTS,
+	AIC79XX_DEFAULT_IOOPTS,
+	AIC79XX_DEFAULT_IOOPTS,
+	AIC79XX_DEFAULT_IOOPTS,
+	AIC79XX_DEFAULT_IOOPTS,
+	AIC79XX_DEFAULT_IOOPTS,
+	AIC79XX_DEFAULT_IOOPTS
+};
+
+/*
+ * There should be a specific return value for this in scsi.h, but
+ * it seems that most drivers ignore it.
+ */
+#define DID_UNDERFLOW   DID_ERROR
+
+void
+ahd_print_path(struct ahd_softc *ahd, struct scb *scb)
+{
+	printk("(scsi%d:%c:%d:%d): ",
+	       ahd->platform_data->host->host_no,
+	       scb != NULL ? SCB_GET_CHANNEL(ahd, scb) : 'X',
+	       scb != NULL ? SCB_GET_TARGET(ahd, scb) : -1,
+	       scb != NULL ? SCB_GET_LUN(scb) : -1);
+}
+
+/*
+ * XXX - these options apply unilaterally to _all_ adapters
+ *       cards in the system.  This should be fixed.  Exceptions to this
+ *       rule are noted in the comments.
+ */
+
+/*
+ * Skip the scsi bus reset.  Non 0 make us skip the reset at startup.  This
+ * has no effect on any later resets that might occur due to things like
+ * SCSI bus timeouts.
+ */
+static uint32_t aic79xx_no_reset;
+
+/*
+ * Certain PCI motherboards will scan PCI devices from highest to lowest,
+ * others scan from lowest to highest, and they tend to do all kinds of
+ * strange things when they come into contact with PCI bridge chips.  The
+ * net result of all this is that the PCI card that is actually used to boot
+ * the machine is very hard to detect.  Most motherboards go from lowest
+ * PCI slot number to highest, and the first SCSI controller found is the
+ * one you boot from.  The only exceptions to this are when a controller
+ * has its BIOS disabled.  So, we by default sort all of our SCSI controllers
+ * from lowest PCI slot number to highest PCI slot number.  We also force
+ * all controllers with their BIOS disabled to the end of the list.  This
+ * works on *almost* all computers.  Where it doesn't work, we have this
+ * option.  Setting this option to non-0 will reverse the order of the sort
+ * to highest first, then lowest, but will still leave cards with their BIOS
+ * disabled at the very end.  That should fix everyone up unless there are
+ * really strange cirumstances.
+ */
+static int aic79xx_reverse_scan = 0;
+
+/*
+ * Should we force EXTENDED translation on a controller.
+ *     0 == Use whatever is in the SEEPROM or default to off
+ *     1 == Use whatever is in the SEEPROM or default to on
+ */
+static uint32_t aic79xx_extended = 0;
+
+/*
+ * PCI bus parity checking of the Adaptec controllers.  This is somewhat
+ * dubious at best.  To my knowledge, this option has never actually
+ * solved a PCI parity problem, but on certain machines with broken PCI
+ * chipset configurations, it can generate tons of false error messages.
+ * It's included in the driver for completeness.
+ *   0 = Shut off PCI parity check
+ *  -1 = Normal polarity pci parity checking
+ *   1 = reverse polarity pci parity checking
+ *
+ * NOTE: you can't actually pass -1 on the lilo prompt.  So, to set this
+ * variable to -1 you would actually want to simply pass the variable
+ * name without a number.  That will invert the 0 which will result in
+ * -1.
+ */
+static int aic79xx_pci_parity = 0;
+
+/*
+ * There are lots of broken chipsets in the world.  Some of them will
+ * violate the PCI spec when we issue byte sized memory writes to our
+ * controller.  I/O mapped register access, if allowed by the given
+ * platform, will work in almost all cases.
+ */
+int aic79xx_allow_memio = 1;
+
+/*
+ * aic79xx_detect() has been run, so register all device arrivals
+ * immediately with the system rather than deferring to the sorted
+ * attachment performed by aic79xx_detect().
+ */
+int aic79xx_detect_complete;
+
+/*
+ * So that we can set how long each device is given as a selection timeout.
+ * The table of values goes like this:
+ *   0 - 256ms
+ *   1 - 128ms
+ *   2 - 64ms
+ *   3 - 32ms
+ * We default to 256ms because some older devices need a longer time
+ * to respond to initial selection.
+ */
+static int aic79xx_seltime = 0x00;
+
+/*
+ * Certain devices do not perform any aging on commands.  Should the
+ * device be saturated by commands in one portion of the disk, it is
+ * possible for transactions on far away sectors to never be serviced.
+ * To handle these devices, we can periodically send an ordered tag to
+ * force all outstanding transactions to be serviced prior to a new
+ * transaction.
+ */
+int aic79xx_periodic_otag;
+
+/*
+ * Module information and settable options.
+ */
+#ifdef MODULE
+static char *aic79xx = NULL;
+/*
+ * Just in case someone uses commas to separate items on the insmod
+ * command line, we define a dummy buffer here to avoid having insmod
+ * write wild stuff into our code segment
+ */
+static char dummy_buffer[60] = "Please don't trounce on me insmod!!\n";
+
+MODULE_AUTHOR("Maintainer: Justin T. Gibbs <gibbs@scsiguy.com>");
+MODULE_DESCRIPTION("Adaptec Aic77XX/78XX SCSI Host Bus Adapter driver");
+#ifdef MODULE_LICENSE
+MODULE_LICENSE("Dual BSD/GPL");
+#endif
+MODULE_PARM(aic79xx, "s");
+MODULE_PARM_DESC(aic79xx,
+"period delimited, options string.\n"
+"	verbose			Enable verbose/diagnostic logging\n"
+"	allow_memio		Allow device registers to be memory mapped\n"
+"	debug			Bitmask of debug values to enable\n"
+"	no_reset		Supress initial bus resets\n"
+"	extended		Enable extended geometry on all controllers\n"
+"	periodic_otag		Send an ordered tagged transaction\n"
+"				periodically to prevent tag starvation.\n"
+"				This may be required by some older disk\n"
+"				or drives/RAID arrays.\n"
+"	reverse_scan		Sort PCI devices highest Bus/Slot to lowest\n"
+"	tag_info:<tag_str>	Set per-target tag depth\n"
+"	global_tag_depth:<int>	Global tag depth for all targets on all buses\n"
+"	rd_strm:<rd_strm_masks> Set per-target read streaming setting.\n"
+"	dv:<dv_settings>	Set per-controller Domain Validation Setting.\n"
+"	slewrate:<slewrate_list>Set the signal slew rate (0-15).\n"
+"	precomp:<pcomp_list>	Set the signal precompensation (0-7).\n"
+"	amplitude:<int>		Set the signal amplitude (0-7).\n"
+"	seltime:<int>		Selection Timeout:\n"
+"				(0/256ms,1/128ms,2/64ms,3/32ms)\n"
+"\n"
+"	Sample /etc/modules.conf line:\n"
+"		Enable verbose logging\n"
+"		Set tag depth on Controller 2/Target 2 to 10 tags\n"
+"		Shorten the selection timeout to 128ms\n"
+"\n"
+"	options aic79xx='\"verbose.tag_info:{{}.{}.{..10}}.seltime:1\"'\n"
+"\n"
+"	Sample /etc/modules.conf line:\n"
+"		Change Read Streaming for Controller's 2 and 3\n"
+"\n"
+"	options aic79xx='\"rd_strm:{..0xFFF0.0xC0F0}\"'");
+#endif
+
+static void ahd_linux_handle_scsi_status(struct ahd_softc *,
+					 struct ahd_linux_device *,
+					 struct scb *);
+static void ahd_linux_queue_cmd_complete(struct ahd_softc *ahd,
+					 Scsi_Cmnd *cmd);
+static void ahd_linux_filter_inquiry(struct ahd_softc *ahd,
+				     struct ahd_devinfo *devinfo);
+static void ahd_linux_dev_timed_unfreeze(u_long arg);
+#if NO_YET
+static void ahd_linux_sem_timeout(u_long arg);
+static int  ahd_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag);
+#endif 
+static void ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd);
+static void ahd_linux_thread_run_complete_queue(struct ahd_softc *ahd);
+static void ahd_linux_start_dv(struct ahd_softc *ahd);
+static void ahd_linux_dv_timeout(struct scsi_cmnd *cmd);
+static int  ahd_linux_dv_thread(void *data);
+static void ahd_linux_dv_target(struct ahd_softc *ahd, u_int target);
+static void ahd_linux_dv_transition(struct ahd_softc *ahd,
+				    struct scsi_cmnd *cmd,
+				    struct ahd_devinfo *devinfo,
+				    struct ahd_linux_target *targ);
+static uint32_t aic_error_action(struct scsi_cmnd *cmd,
+				 struct scsi_inquiry_data *inq_data);
+static void ahd_linux_dv_fill_cmd(struct ahd_softc *ahd,
+				  struct scsi_cmnd *cmd,
+				  struct ahd_devinfo *devinfo);
+static void ahd_linux_dv_inq(struct ahd_softc *ahd,
+			     struct scsi_cmnd *cmd,
+			     struct ahd_devinfo *devinfo,
+			     struct ahd_linux_target *targ,
+			     u_int request_length);
+static void ahd_linux_dv_tur(struct ahd_softc *ahd,
+			     struct scsi_cmnd *cmd,
+			     struct ahd_devinfo *devinfo);
+static void ahd_linux_dv_rebd(struct ahd_softc *ahd,
+			      struct scsi_cmnd *cmd,
+			      struct ahd_devinfo *devinfo,
+			      struct ahd_linux_target *targ);
+static void ahd_linux_dv_web(struct ahd_softc *ahd,
+			     struct scsi_cmnd *cmd,
+			     struct ahd_devinfo *devinfo,
+			     struct ahd_linux_target *targ);
+static void ahd_linux_dv_reb(struct ahd_softc *ahd,
+			     struct scsi_cmnd *cmd,
+			     struct ahd_devinfo *devinfo,
+			     struct ahd_linux_target *targ);
+static void ahd_linux_dv_su(struct ahd_softc *ahd,
+			    struct scsi_cmnd *cmd,
+			    struct ahd_devinfo *devinfo,
+			    struct ahd_linux_target *targ);
+static __inline int
+	   ahd_linux_dv_fallback(struct ahd_softc *ahd,
+				 struct ahd_devinfo *devinfo);
+static int ahd_linux_fallback(struct ahd_softc *ahd,
+			      struct ahd_devinfo *devinfo);
+static __inline int ahd_linux_dv_fallback(struct ahd_softc *ahd,
+					  struct ahd_devinfo *devinfo);
+static void ahd_linux_dv_complete(Scsi_Cmnd *cmd);
+static void ahd_linux_generate_dv_pattern(struct ahd_linux_target *targ);
+static u_int ahd_linux_user_tagdepth(struct ahd_softc *ahd,
+				     struct ahd_devinfo *devinfo);
+static u_int ahd_linux_user_dv_setting(struct ahd_softc *ahd);
+static void ahd_linux_device_queue_depth(struct ahd_softc *ahd,
+					 struct ahd_linux_device *dev);
+static struct ahd_linux_target*	ahd_linux_alloc_target(struct ahd_softc*,
+						       u_int, u_int);
+static void			ahd_linux_free_target(struct ahd_softc*,
+						      struct ahd_linux_target*);
+static struct ahd_linux_device*	ahd_linux_alloc_device(struct ahd_softc*,
+						       struct ahd_linux_target*,
+						       u_int);
+static void			ahd_linux_free_device(struct ahd_softc*,
+						      struct ahd_linux_device*);
+static void ahd_linux_run_device_queue(struct ahd_softc*,
+				       struct ahd_linux_device*);
+static void ahd_linux_setup_tag_info(char *p, char *end, char *s);
+static void ahd_linux_setup_tag_info_global(char *p);
+static void ahd_linux_setup_rd_strm_info(char *p, char *end, char *s);
+static void ahd_linux_setup_dv(char *p, char *end, char *s);
+static void ahd_linux_setup_iocell_info(char *p, char *end, char *s, int index);
+static int ahd_linux_next_unit(void);
+static void ahd_runq_tasklet(unsigned long data);
+static int ahd_linux_halt(struct notifier_block *nb, u_long event, void *buf);
+static int aic79xx_setup(char *c);
+
+/****************************** Inlines ***************************************/
+static __inline void ahd_schedule_completeq(struct ahd_softc *ahd,
+					    struct ahd_cmd *acmd);
+static __inline void ahd_schedule_runq(struct ahd_softc *ahd);
+static __inline void ahd_setup_runq_tasklet(struct ahd_softc *ahd);
+static __inline void ahd_teardown_runq_tasklet(struct ahd_softc *ahd);
+static __inline struct ahd_linux_device*
+		     ahd_linux_get_device(struct ahd_softc *ahd, u_int channel,
+					  u_int target, u_int lun, int alloc);
+static struct ahd_cmd *ahd_linux_run_complete_queue(struct ahd_softc *ahd,
+						    struct ahd_cmd *acmd);
+static __inline void ahd_linux_check_device_queue(struct ahd_softc *ahd,
+						  struct ahd_linux_device *dev);
+static __inline struct ahd_linux_device *
+		     ahd_linux_next_device_to_run(struct ahd_softc *ahd);
+static __inline void ahd_linux_run_device_queues(struct ahd_softc *ahd);
+static __inline void ahd_linux_unmap_scb(struct ahd_softc*, struct scb*);
+
+static __inline int ahd_linux_map_seg(struct ahd_softc *ahd, struct scb *scb,
+		 		      struct ahd_dma_seg *sg,
+				      bus_addr_t addr, bus_size_t len);
+
+static __inline void
+ahd_schedule_completeq(struct ahd_softc *ahd, struct ahd_cmd *acmd)
+{
+	while (acmd != NULL) {
+		struct ahd_completeq *completeq;
+		struct ahd_cmd *list_cmd;
+		struct ahd_cmd *next_cmd;
+
+		next_cmd = TAILQ_NEXT(acmd, acmd_links.tqe);
+		completeq = &ahd->platform_data->completeq;
+		list_cmd = TAILQ_FIRST(completeq);
+		while (list_cmd != NULL
+		    && acmd_scsi_cmd(list_cmd).serial_number
+		     < acmd_scsi_cmd(acmd).serial_number)
+			list_cmd = TAILQ_NEXT(list_cmd, acmd_links.tqe);
+		if (list_cmd != NULL)
+			TAILQ_INSERT_BEFORE(list_cmd, acmd, acmd_links.tqe);
+		else
+			TAILQ_INSERT_TAIL(completeq, acmd, acmd_links.tqe);
+		acmd = next_cmd;
+	}
+	if ((ahd->platform_data->flags & AHD_RUN_CMPLT_Q_TIMER) == 0) {
+		ahd->platform_data->flags |= AHD_RUN_CMPLT_Q_TIMER;
+		ahd->platform_data->completeq_timer.expires = jiffies;
+		add_timer(&ahd->platform_data->completeq_timer);
+	}
+}
+
+static __inline void
+ahd_schedule_runq(struct ahd_softc *ahd)
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+	tasklet_schedule(&ahd->platform_data->runq_tasklet);
+#else
+	/*
+	 * Tasklets are not available, so run inline.
+	 */
+	ahd_runq_tasklet((unsigned long)ahd);
+#endif
+}
+
+static __inline
+void ahd_setup_runq_tasklet(struct ahd_softc *ahd)
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+	tasklet_init(&ahd->platform_data->runq_tasklet, ahd_runq_tasklet,
+		     (unsigned long)ahd);
+#endif
+}
+
+static __inline void
+ahd_teardown_runq_tasklet(struct ahd_softc *ahd)
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+	tasklet_kill(&ahd->platform_data->runq_tasklet);
+#endif
+}
+
+static __inline struct ahd_linux_device*
+ahd_linux_get_device(struct ahd_softc *ahd, u_int channel, u_int target,
+		     u_int lun, int alloc)
+{
+	struct ahd_linux_target *targ;
+	struct ahd_linux_device *dev;
+	u_int target_offset;
+
+	target_offset = target;
+	if (channel != 0)
+		target_offset += 8;
+	targ = ahd->platform_data->targets[target_offset];
+	if (targ == NULL) {
+		if (alloc != 0) {
+			targ = ahd_linux_alloc_target(ahd, channel, target);
+			if (targ == NULL)
+				return (NULL);
+		} else
+			return (NULL);
+	}
+	dev = targ->devices[lun];
+	if (dev == NULL && alloc != 0)
+		dev = ahd_linux_alloc_device(ahd, targ, lun);
+	return (dev);
+}
+
+#define AHD_LINUX_MAX_RETURNED_ERRORS 4
+static struct ahd_cmd *
+ahd_linux_run_complete_queue(struct ahd_softc *ahd, struct ahd_cmd *acmd)
+{	
+	u_long	done_flags;
+	int	with_errors;
+
+	ahd_done_lock(ahd, &done_flags);
+	with_errors = 0;
+	while (acmd != NULL) {
+		Scsi_Cmnd *cmd;
+
+		cmd = &acmd_scsi_cmd(acmd);
+		acmd = TAILQ_NEXT(acmd, acmd_links.tqe);
+		cmd->host_scribble = NULL;
+		if (ahd_cmd_get_transaction_status(cmd) != DID_OK
+		 || (cmd->result & 0xFF) != SCSI_STATUS_OK)
+			with_errors++;
+
+		cmd->scsi_done(cmd);
+
+		if (with_errors > AHD_LINUX_MAX_RETURNED_ERRORS) {
+			/*
+			 * Linux uses stack recursion to requeue
+			 * commands that need to be retried.  Avoid
+			 * blowing out the stack by "spoon feeding"
+			 * commands that completed with error back
+			 * the operating system in case they are going
+			 * to be retried. "ick"
+			 */
+			break;
+		}
+	}
+	ahd_done_unlock(ahd, &done_flags);
+	return (acmd);
+}
+
+static __inline void
+ahd_linux_check_device_queue(struct ahd_softc *ahd,
+			     struct ahd_linux_device *dev)
+{
+	if ((dev->flags & AHD_DEV_FREEZE_TIL_EMPTY) != 0
+	 && dev->active == 0) {
+		dev->flags &= ~AHD_DEV_FREEZE_TIL_EMPTY;
+		dev->qfrozen--;
+	}
+
+	if (TAILQ_FIRST(&dev->busyq) == NULL
+	 || dev->openings == 0 || dev->qfrozen != 0)
+		return;
+
+	ahd_linux_run_device_queue(ahd, dev);
+}
+
+static __inline struct ahd_linux_device *
+ahd_linux_next_device_to_run(struct ahd_softc *ahd)
+{
+	
+	if ((ahd->flags & AHD_RESOURCE_SHORTAGE) != 0
+	 || (ahd->platform_data->qfrozen != 0
+	  && AHD_DV_SIMQ_FROZEN(ahd) == 0))
+		return (NULL);
+	return (TAILQ_FIRST(&ahd->platform_data->device_runq));
+}
+
+static __inline void
+ahd_linux_run_device_queues(struct ahd_softc *ahd)
+{
+	struct ahd_linux_device *dev;
+
+	while ((dev = ahd_linux_next_device_to_run(ahd)) != NULL) {
+		TAILQ_REMOVE(&ahd->platform_data->device_runq, dev, links);
+		dev->flags &= ~AHD_DEV_ON_RUN_LIST;
+		ahd_linux_check_device_queue(ahd, dev);
+	}
+}
+
+static __inline void
+ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb)
+{
+	Scsi_Cmnd *cmd;
+	int direction;
+
+	cmd = scb->io_ctx;
+	direction = scsi_to_pci_dma_dir(cmd->sc_data_direction);
+	ahd_sync_sglist(ahd, scb, BUS_DMASYNC_POSTWRITE);
+	if (cmd->use_sg != 0) {
+		struct scatterlist *sg;
+
+		sg = (struct scatterlist *)cmd->request_buffer;
+		pci_unmap_sg(ahd->dev_softc, sg, cmd->use_sg, direction);
+	} else if (cmd->request_bufflen != 0) {
+		pci_unmap_single(ahd->dev_softc,
+				 scb->platform_data->buf_busaddr,
+				 cmd->request_bufflen, direction);
+	}
+}
+
+static __inline int
+ahd_linux_map_seg(struct ahd_softc *ahd, struct scb *scb,
+		  struct ahd_dma_seg *sg, bus_addr_t addr, bus_size_t len)
+{
+	int	 consumed;
+
+	if ((scb->sg_count + 1) > AHD_NSEG)
+		panic("Too few segs for dma mapping.  "
+		      "Increase AHD_NSEG\n");
+
+	consumed = 1;
+	sg->addr = ahd_htole32(addr & 0xFFFFFFFF);
+	scb->platform_data->xfer_len += len;
+	if (sizeof(bus_addr_t) > 4
+	 && (ahd->flags & AHD_39BIT_ADDRESSING) != 0) {
+		/*
+		 * Due to DAC restrictions, we can't
+		 * cross a 4GB boundary.
+		 */
+		if ((addr ^ (addr + len - 1)) & ~0xFFFFFFFF) {
+			struct	 ahd_dma_seg *next_sg;
+			uint32_t next_len;
+
+			printf("Crossed Seg\n");
+			if ((scb->sg_count + 2) > AHD_NSEG)
+				panic("Too few segs for dma mapping.  "
+				      "Increase AHD_NSEG\n");
+
+			consumed++;
+			next_sg = sg + 1;
+			next_sg->addr = 0;
+			next_len = 0x100000000 - (addr & 0xFFFFFFFF);
+			len -= next_len;
+			next_len |= ((addr >> 8) + 0x1000000) & 0x7F000000;
+			next_sg->len = ahd_htole32(next_len);
+		}
+		len |= (addr >> 8) & 0x7F000000;
+	}
+	sg->len = ahd_htole32(len);
+	return (consumed);
+}
+
+/************************  Host template entry points *************************/
+static int	   ahd_linux_detect(Scsi_Host_Template *);
+static int	   ahd_linux_release(struct Scsi_Host *);
+static const char *ahd_linux_info(struct Scsi_Host *);
+static int	   ahd_linux_queue(Scsi_Cmnd *, void (*)(Scsi_Cmnd *));
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+static int	   ahd_linux_slave_alloc(Scsi_Device *);
+static int	   ahd_linux_slave_configure(Scsi_Device *);
+static void	   ahd_linux_slave_destroy(Scsi_Device *);
+static int	   ahd_linux_biosparam(struct scsi_device*,
+				       struct block_device*, sector_t, int[]);
+#else
+static void	   ahd_linux_select_queue_depth(struct Scsi_Host *host,
+						Scsi_Device *scsi_devs);
+static int	   ahd_linux_biosparam(Disk *, kdev_t, int[]);
+#endif
+static int	   ahd_linux_bus_reset(Scsi_Cmnd *);
+static int	   ahd_linux_dev_reset(Scsi_Cmnd *);
+static int	   ahd_linux_abort(Scsi_Cmnd *);
+
+/*
+ * Try to detect an Adaptec 79XX controller.
+ */
+static int
+ahd_linux_detect(Scsi_Host_Template *template)
+{
+	struct	ahd_softc *ahd;
+	int     found;
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	/*
+	 * It is a bug that the upper layer takes
+	 * this lock just prior to calling us.
+	 */
+	spin_unlock_irq(&io_request_lock);
+#endif
+
+	/*
+	 * Sanity checking of Linux SCSI data structures so
+	 * that some of our hacks^H^H^H^H^Hassumptions aren't
+	 * violated.
+	 */
+	if (offsetof(struct ahd_cmd_internal, end)
+	  > offsetof(struct scsi_cmnd, host_scribble)) {
+		printf("ahd_linux_detect: SCSI data structures changed.\n");
+		printf("ahd_linux_detect: Unable to attach\n");
+		return (0);
+	}
+#ifdef MODULE
+	/*
+	 * If we've been passed any parameters, process them now.
+	 */
+	if (aic79xx)
+		aic79xx_setup(aic79xx);
+	if (dummy_buffer[0] != 'P')
+		printk(KERN_WARNING
+"aic79xx: Please read the file /usr/src/linux/drivers/scsi/README.aic79xx\n"
+"aic79xx: to see the proper way to specify options to the aic79xx module\n"
+"aic79xx: Specifically, don't use any commas when passing arguments to\n"
+"aic79xx: insmod or else it might trash certain memory areas.\n");
+#endif
+
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0)
+	template->proc_name = "aic79xx";
+#else
+	template->proc_dir = &proc_scsi_aic79xx;
+#endif
+
+	/*
+	 * Initialize our softc list lock prior to
+	 * probing for any adapters.
+	 */
+	ahd_list_lockinit();
+
+#ifdef CONFIG_PCI
+	ahd_linux_pci_probe(template);
+#endif
+
+	/*
+	 * Register with the SCSI layer all
+	 * controllers we've found.
+	 */
+	found = 0;
+	TAILQ_FOREACH(ahd, &ahd_tailq, links) {
+
+		if (ahd_linux_register_host(ahd, template) == 0)
+			found++;
+	}
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	spin_lock_irq(&io_request_lock);
+#endif
+	aic79xx_detect_complete++;
+	return (found);
+}
+
+/*
+ * Free the passed in Scsi_Host memory structures prior to unloading the
+ * module.
+ */
+static int
+ahd_linux_release(struct Scsi_Host * host)
+{
+	struct ahd_softc *ahd;
+	u_long l;
+
+	ahd_list_lock(&l);
+	if (host != NULL) {
+
+		/*
+		 * We should be able to just perform
+		 * the free directly, but check our
+		 * list for extra sanity.
+		 */
+		ahd = ahd_find_softc(*(struct ahd_softc **)host->hostdata);
+		if (ahd != NULL) {
+			u_long s;
+
+			ahd_lock(ahd, &s);
+			ahd_intr_enable(ahd, FALSE);
+			ahd_unlock(ahd, &s);
+			ahd_free(ahd);
+		}
+	}
+	ahd_list_unlock(&l);
+	return (0);
+}
+
+/*
+ * Return a string describing the driver.
+ */
+static const char *
+ahd_linux_info(struct Scsi_Host *host)
+{
+	static char buffer[512];
+	char	ahd_info[256];
+	char   *bp;
+	struct ahd_softc *ahd;
+
+	bp = &buffer[0];
+	ahd = *(struct ahd_softc **)host->hostdata;
+	memset(bp, 0, sizeof(buffer));
+	strcpy(bp, "Adaptec AIC79XX PCI-X SCSI HBA DRIVER, Rev ");
+	strcat(bp, AIC79XX_DRIVER_VERSION);
+	strcat(bp, "\n");
+	strcat(bp, "        <");
+	strcat(bp, ahd->description);
+	strcat(bp, ">\n");
+	strcat(bp, "        ");
+	ahd_controller_info(ahd, ahd_info);
+	strcat(bp, ahd_info);
+	strcat(bp, "\n");
+
+	return (bp);
+}
+
+/*
+ * Queue an SCB to the controller.
+ */
+static int
+ahd_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
+{
+	struct	 ahd_softc *ahd;
+	struct	 ahd_linux_device *dev;
+	u_long	 flags;
+
+	ahd = *(struct ahd_softc **)cmd->host->hostdata;
+
+	/*
+	 * Save the callback on completion function.
+	 */
+	cmd->scsi_done = scsi_done;
+
+	ahd_midlayer_entrypoint_lock(ahd, &flags);
+
+	/*
+	 * Close the race of a command that was in the process of
+	 * being queued to us just as our simq was frozen.  Let
+	 * DV commands through so long as we are only frozen to
+	 * perform DV.
+	 */
+	if (ahd->platform_data->qfrozen != 0
+	 && AHD_DV_CMD(cmd) == 0) {
+
+		ahd_cmd_set_transaction_status(cmd, CAM_REQUEUE_REQ);
+		ahd_linux_queue_cmd_complete(ahd, cmd);
+		ahd_schedule_completeq(ahd, NULL);
+		ahd_midlayer_entrypoint_unlock(ahd, &flags);
+		return (0);
+	}
+	dev = ahd_linux_get_device(ahd, cmd->channel, cmd->target,
+				   cmd->lun, /*alloc*/TRUE);
+	if (dev == NULL) {
+		ahd_midlayer_entrypoint_unlock(ahd, &flags);
+		printf("aic79xx_linux_queue: Unable to allocate device!\n");
+		return (-ENOMEM);
+	}
+	if (cmd->cmd_len > MAX_CDB_LEN)
+		return (-EINVAL);
+	cmd->result = CAM_REQ_INPROG << 16;
+	TAILQ_INSERT_TAIL(&dev->busyq, (struct ahd_cmd *)cmd, acmd_links.tqe);
+	if ((dev->flags & AHD_DEV_ON_RUN_LIST) == 0) {
+		TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq, dev, links);
+		dev->flags |= AHD_DEV_ON_RUN_LIST;
+		ahd_linux_run_device_queues(ahd);
+	}
+	ahd_midlayer_entrypoint_unlock(ahd, &flags);
+	return (0);
+}
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+static int
+ahd_linux_slave_alloc(Scsi_Device *device)
+{
+	struct	ahd_softc *ahd;
+
+	ahd = *((struct ahd_softc **)device->host->hostdata);
+	if (bootverbose)
+		printf("%s: Slave Alloc %d\n", ahd_name(ahd), device->id);
+	return (0);
+}
+
+static int
+ahd_linux_slave_configure(Scsi_Device *device)
+{
+	struct	ahd_softc *ahd;
+	struct	ahd_linux_device *dev;
+	u_long	flags;
+
+	ahd = *((struct ahd_softc **)device->host->hostdata);
+	if (bootverbose)
+		printf("%s: Slave Configure %d\n", ahd_name(ahd), device->id);
+	ahd_midlayer_entrypoint_lock(ahd, &flags);
+	/*
+	 * Since Linux has attached to the device, configure
+	 * it so we don't free and allocate the device
+	 * structure on every command.
+	 */
+	dev = ahd_linux_get_device(ahd, device->channel,
+				   device->id, device->lun,
+				   /*alloc*/TRUE);
+	if (dev != NULL) {
+		dev->flags &= ~AHD_DEV_UNCONFIGURED;
+		dev->flags |= AHD_DEV_SLAVE_CONFIGURED;
+		dev->scsi_device = device;
+		ahd_linux_device_queue_depth(ahd, dev);
+	}
+	ahd_midlayer_entrypoint_unlock(ahd, &flags);
+	return (0);
+}
+
+static void
+ahd_linux_slave_destroy(Scsi_Device *device)
+{
+	struct	ahd_softc *ahd;
+	struct	ahd_linux_device *dev;
+	u_long	flags;
+
+	ahd = *((struct ahd_softc **)device->host->hostdata);
+	if (bootverbose)
+		printf("%s: Slave Destroy %d\n", ahd_name(ahd), device->id);
+	ahd_midlayer_entrypoint_lock(ahd, &flags);
+	dev = ahd_linux_get_device(ahd, device->channel,
+				   device->id, device->lun,
+					   /*alloc*/FALSE);
+
+	/*
+	 * Filter out "silly" deletions of real devices by only
+	 * deleting devices that have had slave_configure()
+	 * called on them.  All other devices that have not
+	 * been configured will automatically be deleted by
+	 * the refcounting process.
+	 */
+	if (dev != NULL
+	 && (dev->flags & AHD_DEV_SLAVE_CONFIGURED) != 0) {
+		dev->flags |= AHD_DEV_UNCONFIGURED;
+		if (TAILQ_EMPTY(&dev->busyq)
+		 && dev->active == 0)
+			ahd_linux_free_device(ahd, dev);
+	}
+	ahd_midlayer_entrypoint_unlock(ahd, &flags);
+}
+#else
+/*
+ * Sets the queue depth for each SCSI device hanging
+ * off the input host adapter.
+ */
+static void
+ahd_linux_select_queue_depth(struct Scsi_Host * host,
+			     Scsi_Device * scsi_devs)
+{
+	Scsi_Device *device;
+	struct	ahd_softc *ahd;
+	u_long	flags;
+	int	scbnum;
+
+	ahd = *((struct ahd_softc **)host->hostdata);
+	ahd_midlayer_entrypoint_lock(ahd, &flags);
+	scbnum = 0;
+	for (device = scsi_devs; device != NULL; device = device->next) {
+
+		if (device->host == host) {
+			struct	 ahd_linux_device *dev;
+
+			/*
+			 * Since Linux has attached to the device, configure
+			 * it so we don't free and allocate the device
+			 * structure on every command.
+			 */
+			dev = ahd_linux_get_device(ahd, device->channel,
+						   device->id, device->lun,
+						   /*alloc*/TRUE);
+			if (dev != NULL) {
+				dev->flags &= ~AHD_DEV_UNCONFIGURED;
+				dev->scsi_device = device;
+				ahd_linux_device_queue_depth(ahd, dev);
+				device->queue_depth = dev->openings
+						    + dev->active;
+				if ((dev->flags & (AHD_DEV_Q_BASIC
+						| AHD_DEV_Q_TAGGED)) == 0) {
+					/*
+					 * We allow the OS to queue 2 untagged
+					 * transactions to us at any time even
+					 * though we can only execute them
+					 * serially on the controller/device.
+					 * This should remove some latency.
+					 */
+					device->queue_depth = 2;
+				}
+			}
+		}
+	}
+	ahd_midlayer_entrypoint_unlock(ahd, &flags);
+}
+#endif
+
+/*
+ * Return the disk geometry for the given SCSI device.
+ */
+static int
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
+		    sector_t capacity, int geom[])
+{
+	uint8_t *bh;
+#else
+ahd_linux_biosparam(Disk *disk, kdev_t dev, int geom[])
+{
+	struct	scsi_device *sdev = disk->device;
+	u_long	capacity = disk->capacity;
+	struct	buffer_head *bh;
+#endif
+	int	 heads;
+	int	 sectors;
+	int	 cylinders;
+	int	 ret;
+	int	 extended;
+	struct	 ahd_softc *ahd;
+
+	ahd = *((struct ahd_softc **)sdev->host->hostdata);
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+	bh = scsi_bios_ptable(bdev);
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,17)
+	bh = bread(MKDEV(MAJOR(dev), MINOR(dev) & ~0xf), 0, block_size(dev));
+#else
+	bh = bread(MKDEV(MAJOR(dev), MINOR(dev) & ~0xf), 0, 1024);
+#endif
+
+	if (bh) {
+		ret = scsi_partsize(bh, capacity,
+				    &geom[2], &geom[0], &geom[1]);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+		kfree(bh);
+#else
+		brelse(bh);
+#endif
+		if (ret != -1)
+			return (ret);
+	}
+	heads = 64;
+	sectors = 32;
+	cylinders = aic_sector_div(capacity, heads, sectors);
+
+	if (aic79xx_extended != 0)
+		extended = 1;
+	else
+		extended = (ahd->flags & AHD_EXTENDED_TRANS_A) != 0;
+	if (extended && cylinders >= 1024) {
+		heads = 255;
+		sectors = 63;
+		cylinders = aic_sector_div(capacity, heads, sectors);
+	}
+	geom[0] = heads;
+	geom[1] = sectors;
+	geom[2] = cylinders;
+	return (0);
+}
+
+/*
+ * Abort the current SCSI command(s).
+ */
+static int
+ahd_linux_abort(Scsi_Cmnd *cmd)
+{
+	struct ahd_softc *ahd;
+	u_long s;
+#if NOTYET
+	struct ahd_cmd *acmd;
+	int    found;
+#endif
+
+	ahd = *(struct ahd_softc **)cmd->host->hostdata;
+#if NOTYET
+	int error;
+
+	error = ahd_linux_queue_recovery_cmd(cmd, SCB_ABORT);
+	if (error != 0)
+		printf("aic79xx_abort returns 0x%x\n", error);
+	return (error);
+#else
+	ahd_midlayer_entrypoint_lock(ahd, &s);
+#ifdef AHD_DEBUG
+	if ((ahd_debug & AHD_SHOW_RECOVERY) != 0) {
+		printf("%s: Abort called for cmd %p\n", ahd_name(ahd), cmd);
+		ahd_dump_card_state(ahd);
+	}
+#endif
+	ahd_midlayer_entrypoint_unlock(ahd, &s);
+	return (FAILED);
+#endif
+}
+
+/*
+ * Attempt to send a target reset message to the device that timed out.
+ */
+static int
+ahd_linux_dev_reset(Scsi_Cmnd *cmd)
+{
+	struct ahd_softc *ahd;
+#if NOTYET
+	struct ahd_cmd *acmd;
+	u_long s;
+	int    found;
+#endif
+
+	ahd = *(struct ahd_softc **)cmd->host->hostdata;
+#ifdef AHD_DEBUG
+	if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
+		printf("%s: Dev reset called for cmd %p\n",
+		       ahd_name(ahd), cmd);
+#endif
+#if NOTYET
+	int error;
+
+	error = ahd_linux_queue_recovery_cmd(cmd, SCB_DEVICE_RESET);
+	if (error != 0)
+		printf("aic79xx_dev_reset returns 0x%x\n", error);
+	return (error);
+#else
+	return (FAILED);
+#endif
+}
+
+/*
+ * Reset the SCSI bus.
+ */
+static int
+ahd_linux_bus_reset(Scsi_Cmnd *cmd)
+{
+	struct ahd_softc *ahd;
+	struct ahd_cmd *acmd;
+	u_long s;
+	int    found;
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	spin_unlock_irq(&io_request_lock);
+#endif
+	ahd = *(struct ahd_softc **)cmd->host->hostdata;
+#ifdef AHD_DEBUG
+	if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
+		printf("%s: Bus reset called for cmd %p\n",
+		       ahd_name(ahd), cmd);
+#endif
+	ahd_midlayer_entrypoint_lock(ahd, &s);
+	found = ahd_reset_channel(ahd, cmd->channel + 'A',
+				  /*initiate reset*/TRUE);
+	acmd = TAILQ_FIRST(&ahd->platform_data->completeq);
+	TAILQ_INIT(&ahd->platform_data->completeq);
+	ahd_midlayer_entrypoint_unlock(ahd, &s);
+	if (bootverbose)
+		printf("%s: SCSI bus reset delivered. "
+		       "%d SCBs aborted.\n", ahd_name(ahd), found);
+
+	if (acmd != NULL) {
+		acmd = ahd_linux_run_complete_queue(ahd, acmd);
+		if (acmd != NULL) {
+			ahd_midlayer_entrypoint_lock(ahd, &s);
+			ahd_schedule_completeq(ahd, acmd);
+			ahd_midlayer_entrypoint_unlock(ahd, &s);
+		}
+	}
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	spin_lock_irq(&io_request_lock);
+#endif
+	return (SUCCESS);
+}
+
+Scsi_Host_Template aic79xx_driver_template = {
+	.proc_info		= ahd_linux_proc_info,
+	.detect			= ahd_linux_detect,
+	.release		= ahd_linux_release,
+	.info			= ahd_linux_info,
+	.queuecommand		= ahd_linux_queue,
+	.eh_abort_handler	= ahd_linux_abort,
+	.eh_device_reset_handler = ahd_linux_dev_reset,
+	.eh_bus_reset_handler	= ahd_linux_bus_reset,
+#if defined(__i386__)
+	.bios_param		= ahd_linux_biosparam,
+#endif
+	.can_queue		= AHD_MAX_QUEUE,
+	.this_id		= -1,
+	.sg_tablesize		= AHD_NSEG,
+	.cmd_per_lun		= 2,
+	.use_clustering		= ENABLE_CLUSTERING,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,7)
+	/*
+	 * We can only map 16MB per-SG
+	 * so create a sector limit of
+	 * "16MB" in 2K sectors.
+	 */
+	.max_sectors		= 8192,
+#endif
+#if defined CONFIG_HIGHIO
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
+/* Assume RedHat Distribution with its different HIGHIO conventions. */
+	.can_dma_32		= 1,
+	.single_sg_okay		= 1,
+#else
+	.highmem_io		= 1,
+#endif
+#endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+	.name			= "aic79xx",
+	.slave_alloc		= ahd_linux_slave_alloc,
+	.slave_configure	= ahd_linux_slave_configure,
+	.slave_destroy		= ahd_linux_slave_destroy,
+#else
+	.select_queue_depths	= ahd_linux_select_queue_depth,
+	.use_new_eh_code	= 1,
+#endif
+};
+
+#define driver_template aic79xx_driver_template
+#include "scsi_module.c"
+/**************************** Tasklet Handler *********************************/
+
+static void
+ahd_runq_tasklet(unsigned long data)
+{
+	struct ahd_softc* ahd;
+	struct ahd_linux_device *dev;
+	u_long flags;
+
+	ahd = (struct ahd_softc *)data;
+	ahd_lock(ahd, &flags);
+	while ((dev = ahd_linux_next_device_to_run(ahd)) != NULL) {
+	
+		TAILQ_REMOVE(&ahd->platform_data->device_runq, dev, links);
+		dev->flags &= ~AHD_DEV_ON_RUN_LIST;
+		ahd_linux_check_device_queue(ahd, dev);
+		/* Yeild to our interrupt handler */
+		ahd_unlock(ahd, &flags);
+		ahd_lock(ahd, &flags);
+	}
+	ahd_unlock(ahd, &flags);
+}
+
+/************************ Shutdown/halt/reboot hook ***************************/
+#include <linux/notifier.h>
+#include <linux/reboot.h>
+
+static struct notifier_block ahd_linux_notifier = {
+	ahd_linux_halt, NULL, 0
+};
+
+static int ahd_linux_halt(struct notifier_block *nb, u_long event, void *buf)
+{
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	struct ahd_softc *ahd;
+
+	/*
+	 * In 2.5.X, this is called prior to the filesystems
+	 * being synced and the SCSI layer being properly
+	 * shutdown.  A different API is required there,
+	 * but the device hooks for this don't quite look
+	 * right.
+	 */
+	if (event == SYS_DOWN || event == SYS_HALT) {
+		TAILQ_FOREACH(ahd, &ahd_tailq, links) {
+			ahd_shutdown(ahd);
+		}
+	}
+#endif
+	return (NOTIFY_OK);
+}
+
+/******************************** Macros **************************************/
+#define BUILD_SCSIID(ahd, cmd)						\
+	((((cmd)->target << TID_SHIFT) & TID) | (ahd)->our_id)
+
+/******************************** Bus DMA *************************************/
+int
+ahd_dma_tag_create(struct ahd_softc *ahd, bus_dma_tag_t parent,
+		   bus_size_t alignment, bus_size_t boundary,
+		   bus_addr_t lowaddr, bus_addr_t highaddr,
+		   bus_dma_filter_t *filter, void *filterarg,
+		   bus_size_t maxsize, int nsegments,
+		   bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
+{
+	bus_dma_tag_t dmat;
+
+	dmat = malloc(sizeof(*dmat), M_DEVBUF, M_NOWAIT);
+	if (dmat == NULL)
+		return (ENOMEM);
+
+	/*
+	 * Linux is very simplistic about DMA memory.  For now don't
+	 * maintain all specification information.  Once Linux supplies
+	 * better facilities for doing these operations, or the
+	 * needs of this particular driver change, we might need to do
+	 * more here.
+	 */
+	dmat->alignment = alignment;
+	dmat->boundary = boundary;
+	dmat->maxsize = maxsize;
+	*ret_tag = dmat;
+	return (0);
+}
+
+void
+ahd_dma_tag_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat)
+{
+	free(dmat, M_DEVBUF);
+}
+
+int
+ahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr,
+		 int flags, bus_dmamap_t *mapp)
+{
+	bus_dmamap_t map;
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+	map = malloc(sizeof(*map), M_DEVBUF, M_NOWAIT);
+	if (map == NULL)
+		return (ENOMEM);
+	/*
+	 * Although we can dma data above 4GB, our
+	 * "consistent" memory is below 4GB for
+	 * space efficiency reasons (only need a 4byte
+	 * address).  For this reason, we have to reset
+	 * our dma mask when doing allocations.
+	 */
+	if (ahd->dev_softc != NULL)
+		ahd_pci_set_dma_mask(ahd->dev_softc, 0xFFFFFFFF);
+	*vaddr = pci_alloc_consistent(ahd->dev_softc,
+				      dmat->maxsize, &map->bus_addr);
+	if (ahd->dev_softc != NULL)
+		ahd_pci_set_dma_mask(ahd->dev_softc,
+				     ahd->platform_data->hw_dma_mask);
+#else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) */
+	/*
+	 * At least in 2.2.14, malloc is a slab allocator so all
+	 * allocations are aligned.  We assume for these kernel versions
+	 * that all allocations will be bellow 4Gig, physically contiguous,
+	 * and accessable via DMA by the controller.
+	 */
+	map = NULL; /* No additional information to store */
+	*vaddr = malloc(dmat->maxsize, M_DEVBUF, M_NOWAIT);
+#endif
+	if (*vaddr == NULL)
+		return (ENOMEM);
+	*mapp = map;
+	return(0);
+}
+
+void
+ahd_dmamem_free(struct ahd_softc *ahd, bus_dma_tag_t dmat,
+		void* vaddr, bus_dmamap_t map)
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+	pci_free_consistent(ahd->dev_softc, dmat->maxsize,
+			    vaddr, map->bus_addr);
+#else
+	free(vaddr, M_DEVBUF);
+#endif
+}
+
+int
+ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map,
+		void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
+		void *cb_arg, int flags)
+{
+	/*
+	 * Assume for now that this will only be used during
+	 * initialization and not for per-transaction buffer mapping.
+	 */
+	bus_dma_segment_t stack_sg;
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+	stack_sg.ds_addr = map->bus_addr;
+#else
+#define VIRT_TO_BUS(a) (uint32_t)virt_to_bus((void *)(a))
+	stack_sg.ds_addr = VIRT_TO_BUS(buf);
+#endif
+	stack_sg.ds_len = dmat->maxsize;
+	cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
+	return (0);
+}
+
+void
+ahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
+{
+	/*
+	 * The map may is NULL in our < 2.3.X implementation.
+	 */
+	if (map != NULL)
+		free(map, M_DEVBUF);
+}
+
+int
+ahd_dmamap_unload(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
+{
+	/* Nothing to do */
+	return (0);
+}
+
+/********************* Platform Dependent Functions ***************************/
+int
+ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd)
+{
+	int	value;
+	char	primary_channel;
+
+	/*
+	 * Under Linux, cards are ordered as follows:
+	 *	1) PCI devices with BIOS enabled sorted by bus/slot/func.
+	 *	2) All remaining PCI devices sorted by bus/slot/func.
+	 */
+	value = (lahd->flags & AHD_BIOS_ENABLED)
+	      - (rahd->flags & AHD_BIOS_ENABLED);
+	if (value != 0)
+		/* Controllers with BIOS enabled have a *higher* priority */
+		return (-value);
+
+	/* Still equal.  Sort by bus/slot/func. */
+	if (aic79xx_reverse_scan != 0)
+		value = ahd_get_pci_bus(rahd->dev_softc)
+		      - ahd_get_pci_bus(lahd->dev_softc);
+	else
+		value = ahd_get_pci_bus(lahd->dev_softc)
+		      - ahd_get_pci_bus(rahd->dev_softc);
+	if (value != 0)
+		return (value);
+	if (aic79xx_reverse_scan != 0)
+		value = ahd_get_pci_slot(rahd->dev_softc)
+		      - ahd_get_pci_slot(lahd->dev_softc);
+	else
+		value = ahd_get_pci_slot(lahd->dev_softc)
+		      - ahd_get_pci_slot(rahd->dev_softc);
+	if (value != 0)
+		return (value);
+
+	/*
+	 * On multi-function devices, the user can choose
+	 * to have function 1 probed before function 0.
+	 * Give whichever channel is the primary channel
+	 * the lowest priority.
+	 */
+	primary_channel = (lahd->flags & AHD_PRIMARY_CHANNEL) + 'A';
+	value = 1;
+	if (lahd->channel == primary_channel)
+		value = -1;
+	return (value);
+}
+
+static void
+ahd_linux_setup_tag_info(char *p, char *end, char *s)
+{
+	char	*base;
+	char	*tok;
+	char	*tok_end;
+	char	*tok_end2;
+	int      i;
+	int      instance;
+	int	 targ;
+	int	 done;
+	char	 tok_list[] = {'.', ',', '{', '}', '\0'};
+
+	if (*p != ':')
+		return;
+
+	instance = -1;
+	targ = -1;
+	done = FALSE;
+	base = p;
+	/* Forward us just past the ':' */
+	tok = base + 1;
+	tok_end = strchr(tok, '\0');
+	if (tok_end < end)
+		*tok_end = ',';
+	while (!done) {
+		switch (*tok) {
+		case '{':
+			if (instance == -1)
+				instance = 0;
+			else if (targ == -1)
+				targ = 0;
+			tok++;
+			break;
+		case '}':
+			if (targ != -1)
+				targ = -1;
+			else if (instance != -1)
+				instance = -1;
+			tok++;
+			break;
+		case ',':
+		case '.':
+			if (instance == -1)
+				done = TRUE;
+			else if (targ >= 0)
+				targ++;
+			else if (instance >= 0)
+				instance++;
+			if ((targ >= AHD_NUM_TARGETS) ||
+			    (instance >= NUM_ELEMENTS(aic79xx_tag_info)))
+				done = TRUE;
+			tok++;
+			if (!done) {
+				base = tok;
+			}
+			break;
+		case '\0':
+			done = TRUE;
+			break;
+		default:
+			done = TRUE;
+			tok_end = strchr(tok, '\0');
+			for (i = 0; tok_list[i]; i++) {
+				tok_end2 = strchr(tok, tok_list[i]);
+				if ((tok_end2) && (tok_end2 < tok_end)) {
+					tok_end = tok_end2;
+					done = FALSE;
+				}
+			}
+			if ((instance >= 0) && (targ >= 0)
+			 && (instance < NUM_ELEMENTS(aic79xx_tag_info))
+			 && (targ < AHD_NUM_TARGETS)) {
+				aic79xx_tag_info[instance].tag_commands[targ] =
+				    simple_strtoul(tok, NULL, 0) & 0xff;
+			}
+			tok = tok_end;
+			break;
+		}
+	}
+	while ((p != base) && (p != NULL))
+		p = strsep(&s, ",.");
+}
+
+static void
+ahd_linux_setup_rd_strm_info(char *p, char *end, char *s)
+{
+	char	*base;
+	char	*tok;
+	char	*tok_end;
+	char	*tok_end2;
+	int      i;
+	int      instance;
+	int	 done;
+	char	 tok_list[] = {'.', ',', '{', '}', '\0'};
+
+	if (*p != ':')
+		return;
+
+	instance = -1;
+	done = FALSE;
+	base = p;
+	/* Forward us just past the ':' */
+	tok = base + 1;
+	tok_end = strchr(tok, '\0');
+	if (tok_end < end)
+		*tok_end = ',';
+	while (!done) {
+		switch (*tok) {
+		case '{':
+			if (instance == -1)
+				instance = 0;
+			tok++;
+			break;
+		case '}':
+			if (instance != -1)
+				instance = -1;
+			tok++;
+			break;
+		case ',':
+		case '.':
+			if (instance == -1)
+				done = TRUE;
+			else if (instance >= 0)
+				instance++;
+			if (instance >= NUM_ELEMENTS(aic79xx_rd_strm_info))
+				done = TRUE;
+			tok++;
+			if (!done) {
+				base = tok;
+			}
+			break;
+		case '\0':
+			done = TRUE;
+			break;
+		default:
+			done = TRUE;
+			tok_end = strchr(tok, '\0');
+			for (i = 0; tok_list[i]; i++) {
+				tok_end2 = strchr(tok, tok_list[i]);
+				if ((tok_end2) && (tok_end2 < tok_end)) {
+					tok_end = tok_end2;
+					done = FALSE;
+				}
+			}
+			if ((instance >= 0)
+			 && (instance < NUM_ELEMENTS(aic79xx_rd_strm_info))) {
+				aic79xx_rd_strm_info[instance] =
+				    simple_strtoul(tok, NULL, 0) & 0xffff;
+			}
+			tok = tok_end;
+			break;
+		}
+	}
+	while ((p != base) && (p != NULL))
+		p = strsep(&s, ",.");
+}
+
+static void
+ahd_linux_setup_dv(char *p, char *end, char *s)
+{
+	char	*base;
+	char	*tok;
+	char	*tok_end;
+	char	*tok_end2;
+	int      i;
+	int      instance;
+	int	 done;
+	char	 tok_list[] = {'.', ',', '{', '}', '\0'};
+
+	if (*p != ':')
+		return;
+
+	instance = -1;
+	done = FALSE;
+	base = p;
+	/* Forward us just past the ':' */
+	tok = base + 1;
+	tok_end = strchr(tok, '\0');
+	if (tok_end < end)
+		*tok_end = ',';
+	while (!done) {
+		switch (*tok) {
+		case '{':
+			if (instance == -1)
+				instance = 0;
+			tok++;
+			break;
+		case '}':
+			if (instance != -1)
+				instance = -1;
+			tok++;
+			break;
+		case ',':
+		case '.':
+			if (instance == -1)
+				done = TRUE;
+			else if (instance >= 0)
+				instance++;
+			if (instance >= NUM_ELEMENTS(aic79xx_dv_settings))
+				done = TRUE;
+			tok++;
+			if (!done) {
+				base = tok;
+			}
+			break;
+		case '\0':
+			done = TRUE;
+			break;
+		default:
+			done = TRUE;
+			tok_end = strchr(tok, '\0');
+			for (i = 0; tok_list[i]; i++) {
+				tok_end2 = strchr(tok, tok_list[i]);
+				if ((tok_end2) && (tok_end2 < tok_end)) {
+					tok_end = tok_end2;
+					done = FALSE;
+				}
+			}
+			if ((instance >= 0)
+			 && (instance < NUM_ELEMENTS(aic79xx_dv_settings))) {
+				aic79xx_dv_settings[instance] =
+				    simple_strtol(tok, NULL, 0);
+			}
+			tok = tok_end;
+			break;
+		}
+	}
+	while ((p != base) && (p != NULL))
+		p = strsep(&s, ",.");
+}
+
+static void
+ahd_linux_setup_iocell_info(char *p, char *end, char *s, int index)
+{
+	char	*base;
+	char	*tok;
+	char	*tok_end;
+	char	*tok_end2;
+	uint8_t	*iocell_info;
+	int      i;
+	int      instance;
+	int	 done;
+	char	 tok_list[] = {'.', ',', '{', '}', '\0'};
+
+	if (*p != ':')
+		return;
+
+	instance = -1;
+	done = FALSE;
+	base = p;
+	/* Forward us just past the ':' */
+	tok = base + 1;
+	tok_end = strchr(tok, '\0');
+	if (tok_end < end)
+		*tok_end = ',';
+	while (!done) {
+		switch (*tok) {
+		case '{':
+			if (instance == -1)
+				instance = 0;
+			tok++;
+			break;
+		case '}':
+			if (instance != -1)
+				instance = -1;
+			tok++;
+			break;
+		case ',':
+		case '.':
+			if (instance == -1)
+				done = TRUE;
+			else if (instance >= 0)
+				instance++;
+			if (instance >= NUM_ELEMENTS(aic79xx_iocell_info))
+				done = TRUE;
+			tok++;
+			if (!done) {
+				base = tok;
+			}
+			break;
+		case '\0':
+			done = TRUE;
+			break;
+		default:
+			done = TRUE;
+			tok_end = strchr(tok, '\0');
+			for (i = 0; tok_list[i]; i++) {
+				tok_end2 = strchr(tok, tok_list[i]);
+				if ((tok_end2) && (tok_end2 < tok_end)) {
+					tok_end = tok_end2;
+					done = FALSE;
+				}
+			}
+			if ((instance >= 0)
+			 && (instance < NUM_ELEMENTS(aic79xx_iocell_info))) {
+				iocell_info =
+				    (uint8_t*)&aic79xx_iocell_info[instance];
+				iocell_info[index] = 
+				    simple_strtoul(tok, NULL, 0) & 0xffff;
+			}
+			tok = tok_end;
+			break;
+		}
+	}
+	while ((p != base) && (p != NULL))
+		p = strsep(&s, ",.");
+}
+
+static void
+ahd_linux_setup_tag_info_global(char *p)
+{
+	int tags, i, j;
+
+	tags = simple_strtoul(p + 1, NULL, 0) & 0xff;
+	printf("Setting Global Tags= %d\n", tags);
+
+	for (i = 0; i < NUM_ELEMENTS(aic79xx_tag_info); i++) {
+		for (j = 0; j < AHD_NUM_TARGETS; j++) {
+			aic79xx_tag_info[i].tag_commands[j] = tags;
+		}
+	}
+}
+
+/*
+ * Handle Linux boot parameters. This routine allows for assigning a value
+ * to a parameter with a ':' between the parameter and the value.
+ * ie. aic79xx=stpwlev:1,extended
+ */
+static int
+aic79xx_setup(char *s)
+{
+	int	i, n;
+	char   *p;
+	char   *end;
+
+	static struct {
+		const char *name;
+		uint32_t *flag;
+	} options[] = {
+		{ "extended", &aic79xx_extended },
+		{ "no_reset", &aic79xx_no_reset },
+		{ "verbose", &aic79xx_verbose },
+		{ "allow_memio", &aic79xx_allow_memio},
+#ifdef AHD_DEBUG
+		{ "debug", &ahd_debug },
+#endif
+		{ "reverse_scan", &aic79xx_reverse_scan },
+		{ "periodic_otag", &aic79xx_periodic_otag },
+		{ "pci_parity", &aic79xx_pci_parity },
+		{ "seltime", &aic79xx_seltime },
+		{ "tag_info", NULL },
+		{ "global_tag_depth", NULL},
+		{ "rd_strm", NULL },
+		{ "dv", NULL },
+		{ "slewrate", NULL },
+		{ "precomp", NULL },
+		{ "amplitude", NULL },
+	};
+
+	end = strchr(s, '\0');
+
+	while ((p = strsep(&s, ",.")) != NULL) {
+		if (*p == '\0')
+			continue;
+		for (i = 0; i < NUM_ELEMENTS(options); i++) {
+			n = strlen(options[i].name);
+
+			if (strncmp(options[i].name, p, n) != 0)
+				continue;
+
+			if (!strncmp(p, "global_tag_depth", n)) {
+				ahd_linux_setup_tag_info_global(p + n);
+			} else if (!strncmp(p, "tag_info", n)) {
+				ahd_linux_setup_tag_info(p + n, end, s);
+			} else if (strncmp(p, "rd_strm", n) == 0) {
+				ahd_linux_setup_rd_strm_info(p + n, end, s);
+			} else if (strncmp(p, "dv", n) == 0) {
+				ahd_linux_setup_dv(p + n, end, s);
+			} else if (strncmp(p, "slewrate", n) == 0) {
+				ahd_linux_setup_iocell_info(p + n, end, s,
+				    AIC79XX_SLEWRATE_INDEX);
+			} else if (strncmp(p, "precomp", n) == 0) {
+				ahd_linux_setup_iocell_info(p + n, end, s,
+				    AIC79XX_PRECOMP_INDEX);
+			} else if (strncmp(p, "amplitude", n) == 0) {
+				ahd_linux_setup_iocell_info(p + n, end, s,
+				    AIC79XX_AMPLITUDE_INDEX);
+			} else if (p[n] == ':') {
+				*(options[i].flag) =
+				    simple_strtoul(p + n + 1, NULL, 0);
+			} else if (!strncmp(p, "verbose", n)) {
+				*(options[i].flag) = 1;
+			} else {
+				*(options[i].flag) = ~(*(options[i].flag));
+			}
+			break;
+		}
+	}
+	return 1;
+}
+
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0)
+__setup("aic79xx=", aic79xx_setup);
+#endif
+
+int aic79xx_verbose;
+
+int
+ahd_linux_register_host(struct ahd_softc *ahd, Scsi_Host_Template *template)
+{
+	char	buf[80];
+	struct	Scsi_Host *host;
+	char	*new_name;
+	u_long	s;
+	u_long	target;
+
+	template->name = ahd->description;
+	host = scsi_register(template, sizeof(struct ahd_softc *));
+	if (host == NULL)
+		return (ENOMEM);
+
+	*((struct ahd_softc **)host->hostdata) = ahd;
+	ahd_lock(ahd, &s);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+	scsi_assign_lock(host, &ahd->platform_data->spin_lock);
+#endif
+	ahd->platform_data->host = host;
+	host->can_queue = AHD_MAX_QUEUE;
+	host->cmd_per_lun = 2;
+	host->sg_tablesize = AHD_NSEG;
+	host->this_id = ahd->our_id;
+	host->irq = ahd->platform_data->irq;
+	host->max_id = (ahd->features & AHD_WIDE) ? 16 : 8;
+	host->max_lun = AHD_NUM_LUNS;
+	host->max_channel = 0;
+	ahd_set_unit(ahd, ahd_linux_next_unit());
+	sprintf(buf, "scsi%d", host->host_no);
+	new_name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
+	if (new_name != NULL) {
+		strcpy(new_name, buf);
+		ahd_set_name(ahd, new_name);
+	}
+	host->unique_id = ahd->unit;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,4)
+	scsi_set_pci_device(host, ahd->dev_softc);
+#endif
+	ahd_linux_initialize_scsi_bus(ahd);
+	ahd_unlock(ahd, &s);
+	ahd->platform_data->dv_pid = kernel_thread(ahd_linux_dv_thread, ahd, 0);
+	ahd_lock(ahd, &s);
+	if (ahd->platform_data->dv_pid < 0) {
+		printf("%s: Failed to create DV thread, error= %d\n",
+		       ahd_name(ahd), ahd->platform_data->dv_pid);
+		return (-ahd->platform_data->dv_pid);
+	}
+	/*
+	 * Initially allocate *all* of our linux target objects
+	 * so that the DV thread will scan them all in parallel
+	 * just after driver initialization.  Any device that
+	 * does not exist will have its target object destroyed
+	 * by the selection timeout handler.  In the case of a
+	 * device that appears after the initial DV scan, async
+	 * negotiation will occur for the first command, and DV
+	 * will comence should that first command be successful.
+	 */
+	for (target = 0; target < AHD_NUM_TARGETS; target++)
+		ahd_linux_alloc_target(ahd, 0, target);
+	ahd_intr_enable(ahd, TRUE);
+	ahd_linux_start_dv(ahd);
+	ahd_unlock(ahd, &s);
+	return (0);
+}
+
+uint64_t
+ahd_linux_get_memsize()
+{
+	struct sysinfo si;
+
+	si_meminfo(&si);
+	return ((uint64_t)si.totalram << PAGE_SHIFT);
+}
+
+/*
+ * Find the smallest available unit number to use
+ * for a new device.  We don't just use a static
+ * count to handle the "repeated hot-(un)plug"
+ * scenario.
+ */
+static int
+ahd_linux_next_unit()
+{
+	struct ahd_softc *ahd;
+	int unit;
+
+	unit = 0;
+retry:
+	TAILQ_FOREACH(ahd, &ahd_tailq, links) {
+		if (ahd->unit == unit) {
+			unit++;
+			goto retry;
+		}
+	}
+	return (unit);
+}
+
+/*
+ * Place the SCSI bus into a known state by either resetting it,
+ * or forcing transfer negotiations on the next command to any
+ * target.
+ */
+static void
+ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd)
+{
+	int i;
+	int numtarg;
+
+	i = 0;
+	numtarg = 0;
+
+	if (aic79xx_no_reset != 0)
+		ahd->flags &= ~AHD_RESET_BUS_A;
+
+	if ((ahd->flags & AHD_RESET_BUS_A) != 0)
+		ahd_reset_channel(ahd, 'A', /*initiate_reset*/TRUE);
+	else
+		numtarg = (ahd->features & AHD_WIDE) ? 16 : 8;
+
+	/*
+	 * Force negotiation to async for all targets that
+	 * will not see an initial bus reset.
+	 */
+	for (; i < numtarg; i++) {
+		struct ahd_devinfo devinfo;
+		struct ahd_initiator_tinfo *tinfo;
+		struct ahd_tmode_tstate *tstate;
+		u_int our_id;
+		u_int target_id;
+		char channel;
+
+		channel = 'A';
+		our_id = ahd->our_id;
+		target_id = i;
+		tinfo = ahd_fetch_transinfo(ahd, channel, our_id,
+					    target_id, &tstate);
+		ahd_compile_devinfo(&devinfo, our_id, target_id,
+				    CAM_LUN_WILDCARD, channel, ROLE_INITIATOR);
+		ahd_update_neg_request(ahd, &devinfo, tstate,
+				       tinfo, AHD_NEG_ALWAYS);
+	}
+	/* Give the bus some time to recover */
+	if ((ahd->flags & AHD_RESET_BUS_A) != 0) {
+		ahd_freeze_simq(ahd);
+		init_timer(&ahd->platform_data->reset_timer);
+		ahd->platform_data->reset_timer.data = (u_long)ahd;
+		ahd->platform_data->reset_timer.expires =
+		    jiffies + (AIC79XX_RESET_DELAY * HZ)/1000;
+		ahd->platform_data->reset_timer.function =
+		    (ahd_linux_callback_t *)ahd_release_simq;
+		add_timer(&ahd->platform_data->reset_timer);
+	}
+}
+
+int
+ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg)
+{
+	ahd->platform_data =
+	    malloc(sizeof(struct ahd_platform_data), M_DEVBUF, M_NOWAIT);
+	if (ahd->platform_data == NULL)
+		return (ENOMEM);
+	memset(ahd->platform_data, 0, sizeof(struct ahd_platform_data));
+	TAILQ_INIT(&ahd->platform_data->completeq);
+	TAILQ_INIT(&ahd->platform_data->device_runq);
+	ahd->platform_data->irq = AHD_LINUX_NOIRQ;
+	ahd->platform_data->hw_dma_mask = 0xFFFFFFFF;
+	ahd_lockinit(ahd);
+	ahd_done_lockinit(ahd);
+	init_timer(&ahd->platform_data->completeq_timer);
+	ahd->platform_data->completeq_timer.data = (u_long)ahd;
+	ahd->platform_data->completeq_timer.function =
+	    (ahd_linux_callback_t *)ahd_linux_thread_run_complete_queue;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+	init_MUTEX_LOCKED(&ahd->platform_data->eh_sem);
+	init_MUTEX_LOCKED(&ahd->platform_data->dv_sem);
+	init_MUTEX_LOCKED(&ahd->platform_data->dv_cmd_sem);
+#else
+	ahd->platform_data->eh_sem = MUTEX_LOCKED;
+	ahd->platform_data->dv_sem = MUTEX_LOCKED;
+	ahd->platform_data->dv_cmd_sem = MUTEX_LOCKED;
+#endif
+	ahd_setup_runq_tasklet(ahd);
+	ahd->seltime = (aic79xx_seltime & 0x3) << 4;
+	if (TAILQ_EMPTY(&ahd_tailq))
+		register_reboot_notifier(&ahd_linux_notifier);
+	return (0);
+}
+
+void
+ahd_platform_free(struct ahd_softc *ahd)
+{
+	u_long s;
+
+	if (ahd->platform_data != NULL) {
+		/* Kill the DV kthread */
+		if (ahd->platform_data->dv_pid != 0) {
+			ahd_lock(ahd, &s);
+			ahd->platform_data->flags |= AHD_DV_SHUTDOWN;
+			ahd_unlock(ahd, &s);
+			up(&ahd->platform_data->dv_sem);
+			do {
+#ifdef AHD_DEBUG
+				if (ahd_debug & AHD_SHOW_DV) {
+					printf("%s: Waiting for DV thread to "
+					       "exit\n", ahd_name(ahd));
+				}
+#endif
+			} while (waitpid(ahd->platform_data->dv_pid, NULL,
+					 __WCLONE) == -ERESTARTSYS);
+		}
+		ahd_teardown_runq_tasklet(ahd);
+		if (ahd->platform_data->host != NULL)
+			scsi_unregister(ahd->platform_data->host);
+		if (ahd->platform_data->irq != AHD_LINUX_NOIRQ)
+			free_irq(ahd->platform_data->irq, ahd);
+		if (ahd->tags[0] == BUS_SPACE_PIO
+		 && ahd->bshs[0].ioport != 0)
+			release_region(ahd->bshs[0].ioport, 256);
+		if (ahd->tags[1] == BUS_SPACE_PIO
+		 && ahd->bshs[1].ioport != 0)
+			release_region(ahd->bshs[1].ioport, 256);
+		if (ahd->tags[0] == BUS_SPACE_MEMIO
+		 && ahd->bshs[0].maddr != NULL) {
+			u_long base_addr;
+
+			base_addr = (u_long)ahd->bshs[0].maddr;
+			base_addr &= PAGE_MASK;
+			iounmap((void *)base_addr);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+			release_mem_region(ahd->platform_data->mem_busaddr,
+					   0x1000);
+#endif
+		}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+		/* XXX Need an instance detach in the PCI code */
+		if (ahd->dev_softc != NULL)
+			ahd->dev_softc->driver = NULL;
+#endif
+		free(ahd->platform_data, M_DEVBUF);
+	}
+	if (TAILQ_EMPTY(&ahd_tailq)) {
+		unregister_reboot_notifier(&ahd_linux_notifier);
+#ifdef CONFIG_PCI
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+		pci_unregister_driver(&aic79xx_pci_driver);
+#endif
+#endif
+	}
+}
+
+void
+ahd_platform_init(struct ahd_softc *ahd)
+{
+	/*
+	 * Lookup and commit any modified IO Cell options.
+	 */
+	if (ahd->unit < NUM_ELEMENTS(aic79xx_iocell_info)) {
+		struct ahd_linux_iocell_opts *iocell_opts;
+
+		iocell_opts = &aic79xx_iocell_info[ahd->unit];
+		if (iocell_opts->precomp != AIC79XX_DEFAULT_PRECOMP)
+			AHD_SET_PRECOMP(ahd, iocell_opts->precomp);
+		if (iocell_opts->slewrate != AIC79XX_DEFAULT_SLEWRATE)
+			AHD_SET_SLEWRATE(ahd, iocell_opts->slewrate);
+		if (iocell_opts->amplitude != AIC79XX_DEFAULT_AMPLITUDE)
+			AHD_SET_AMPLITUDE(ahd, iocell_opts->amplitude);
+	}
+
+}
+
+void
+ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
+{
+	ahd_platform_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
+				SCB_GET_CHANNEL(ahd, scb),
+				SCB_GET_LUN(scb), SCB_LIST_NULL,
+				ROLE_UNKNOWN, CAM_REQUEUE_REQ);
+}
+
+void
+ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
+		      ahd_queue_alg alg)
+{
+	struct ahd_linux_device *dev;
+	int was_queuing;
+	int now_queuing;
+
+	dev = ahd_linux_get_device(ahd, devinfo->channel - 'A',
+				   devinfo->target,
+				   devinfo->lun, /*alloc*/FALSE);
+	if (dev == NULL)
+		return;
+	was_queuing = dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED);
+	now_queuing = alg != AHD_QUEUE_NONE;
+	if ((dev->flags & AHD_DEV_FREEZE_TIL_EMPTY) == 0
+	 && (was_queuing != now_queuing)
+	 && (dev->active != 0)) {
+		dev->flags |= AHD_DEV_FREEZE_TIL_EMPTY;
+		dev->qfrozen++;
+	}
+
+	dev->flags &= ~(AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED|AHD_DEV_PERIODIC_OTAG);
+	if (now_queuing) {
+		u_int usertags;
+
+		usertags = ahd_linux_user_tagdepth(ahd, devinfo);
+		if (!was_queuing) {
+			/*
+			 * Start out agressively and allow our
+			 * dynamic queue depth algorithm to take
+			 * care of the rest.
+			 */
+			dev->maxtags = usertags;
+			dev->openings = dev->maxtags - dev->active;
+		}
+		if (dev->maxtags == 0) {
+			/*
+			 * Queueing is disabled by the user.
+			 */
+			dev->openings = 1;
+		} else if (alg == AHD_QUEUE_TAGGED) {
+			dev->flags |= AHD_DEV_Q_TAGGED;
+			if (aic79xx_periodic_otag != 0)
+				dev->flags |= AHD_DEV_PERIODIC_OTAG;
+		} else
+			dev->flags |= AHD_DEV_Q_BASIC;
+	} else {
+		/* We can only have one opening. */
+		dev->maxtags = 0;
+		dev->openings =  1 - dev->active;
+	}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+	if (dev->scsi_device != NULL) {
+		switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) {
+		case AHD_DEV_Q_BASIC:
+			scsi_adjust_queue_depth(dev->scsi_device,
+						MSG_SIMPLE_TASK,
+						dev->openings + dev->active);
+			break;
+		case AHD_DEV_Q_TAGGED:
+			scsi_adjust_queue_depth(dev->scsi_device,
+						MSG_ORDERED_TASK,
+						dev->openings + dev->active);
+			break;
+		default:
+			/*
+			 * We allow the OS to queue 2 untagged transactions to
+			 * us at any time even though we can only execute them
+			 * serially on the controller/device.  This should
+			 * remove some latency.
+			 */
+			scsi_adjust_queue_depth(dev->scsi_device,
+						/*NON-TAGGED*/0,
+						/*queue depth*/2);
+			break;
+		}
+	}
+#endif
+}
+
+int
+ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, char channel,
+			int lun, u_int tag, role_t role, uint32_t status)
+{
+	int targ;
+	int maxtarg;
+	int maxlun;
+	int clun;
+	int count;
+
+	if (tag != SCB_LIST_NULL)
+		return (0);
+
+	targ = 0;
+	if (target != CAM_TARGET_WILDCARD) {
+		targ = target;
+		maxtarg = targ + 1;
+	} else {
+		maxtarg = (ahd->features & AHD_WIDE) ? 16 : 8;
+	}
+	clun = 0;
+	if (lun != CAM_LUN_WILDCARD) {
+		clun = lun;
+		maxlun = clun + 1;
+	} else {
+		maxlun = AHD_NUM_LUNS;
+	}
+
+	count = 0;
+	for (; targ < maxtarg; targ++) {
+
+		for (; clun < maxlun; clun++) {
+			struct ahd_linux_device *dev;
+			struct ahd_busyq *busyq;
+			struct ahd_cmd *acmd;
+
+			dev = ahd_linux_get_device(ahd, /*chan*/0, targ,
+						   clun, /*alloc*/FALSE);
+			if (dev == NULL)
+				continue;
+
+			busyq = &dev->busyq;
+			while ((acmd = TAILQ_FIRST(busyq)) != NULL) {
+				Scsi_Cmnd *cmd;
+
+				cmd = &acmd_scsi_cmd(acmd);
+				TAILQ_REMOVE(busyq, acmd,
+					     acmd_links.tqe);
+				count++;
+				cmd->result = status << 16;
+				ahd_linux_queue_cmd_complete(ahd, cmd);
+			}
+		}
+	}
+
+	return (count);
+}
+
+static void
+ahd_linux_thread_run_complete_queue(struct ahd_softc *ahd)
+{
+	struct ahd_cmd *acmd;
+	u_long flags;
+
+	ahd_lock(ahd, &flags);
+	del_timer(&ahd->platform_data->completeq_timer);
+	ahd->platform_data->flags &= ~AHD_RUN_CMPLT_Q_TIMER;
+	acmd = TAILQ_FIRST(&ahd->platform_data->completeq);
+	TAILQ_INIT(&ahd->platform_data->completeq);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	ahd_unlock(ahd, &flags);
+#endif
+	if (acmd != NULL) {
+		acmd = ahd_linux_run_complete_queue(ahd, acmd);
+		if (acmd != NULL) {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+			ahd_lock(ahd, &flags);
+#endif
+			ahd_schedule_completeq(ahd, acmd);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+			ahd_unlock(ahd, &flags);
+#endif
+		}
+	}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+	ahd_unlock(ahd, &flags);
+#endif
+}
+
+static void
+ahd_linux_start_dv(struct ahd_softc *ahd)
+{
+
+	/*
+	 * Freeze the simq and signal ahd_linux_queue to not let any
+	 * more commands through
+	 */
+	if ((ahd->platform_data->flags & AHD_DV_ACTIVE) == 0) {
+#ifdef AHD_DEBUG
+		if (ahd_debug & AHD_SHOW_DV)
+			printf("%s: Starting DV\n", ahd_name(ahd));
+#endif
+
+		ahd->platform_data->flags |= AHD_DV_ACTIVE;
+		ahd_freeze_simq(ahd);
+
+		/* Wake up the DV kthread */
+		up(&ahd->platform_data->dv_sem);
+	}
+}
+
+static int
+ahd_linux_dv_thread(void *data)
+{
+	struct	ahd_softc *ahd;
+	int	target;
+	u_long	s;
+
+	ahd = (struct ahd_softc *)data;
+
+#ifdef AHD_DEBUG
+	if (ahd_debug & AHD_SHOW_DV)
+		printf("In DV Thread\n");
+#endif
+
+	while (1) {
+		down(&ahd->platform_data->dv_sem);
+
+		/* Check to see if we've been signaled to exit */
+		ahd_lock(ahd, &s);
+		if ((ahd->platform_data->flags & AHD_DV_SHUTDOWN) != 0) {
+			ahd_unlock(ahd, &s);
+			return (0);
+		}
+		ahd_unlock(ahd, &s);
+
+#ifdef AHD_DEBUG
+		if (ahd_debug & AHD_SHOW_DV)
+			printf("%s: Beginning Domain Validation\n",
+			       ahd_name(ahd));
+#endif
+
+		/*
+		 * Wait for any pending commands to drain before proceeding.
+		 */
+		ahd_lock(ahd, &s);
+		while (LIST_FIRST(&ahd->pending_scbs) != NULL) {
+			ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_EMPTY;
+			ahd_unlock(ahd, &s);
+			down(&ahd->platform_data->dv_sem);
+			ahd_lock(ahd, &s);
+		}
+
+		/*
+		 * Wait for the SIMQ to be released so that DV is the
+		 * only reason the queue is frozen.
+		 */
+		while (AHD_DV_SIMQ_FROZEN(ahd) == 0) {
+			ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_RELEASE;
+			ahd_unlock(ahd, &s);
+			down(&ahd->platform_data->dv_sem);
+			ahd_lock(ahd, &s);
+		}
+		ahd_unlock(ahd, &s);
+
+		for (target = 0; target < AHD_NUM_TARGETS; target++)
+			ahd_linux_dv_target(ahd, target);
+
+		ahd_lock(ahd, &s);
+		ahd->platform_data->flags &= ~AHD_DV_ACTIVE;
+		ahd_unlock(ahd, &s);
+
+		/*
+		 * Release the SIMQ so that normal commands are
+		 * allowed to continue on the bus.
+		 */
+		ahd_release_simq(ahd);
+	}
+
+	return (0);
+}
+
+#define AHD_LINUX_DV_INQ_SHORT_LEN	36
+#define AHD_LINUX_DV_INQ_LEN		256
+#define AHD_LINUX_DV_TIMEOUT		(HZ / 4)
+
+#define AHD_SET_DV_STATE(ahd, targ, newstate) \
+	ahd_set_dv_state(ahd, targ, newstate, __LINE__)
+
+static __inline void
+ahd_set_dv_state(struct ahd_softc *ahd, struct ahd_linux_target *targ,
+		 ahd_dv_state newstate, u_int line)
+{
+	ahd_dv_state oldstate;
+
+	oldstate = targ->dv_state;
+#ifdef AHD_DEBUG
+	if (ahd_debug & AHD_SHOW_DV)
+		printf("%s:%d: Going from state %d to state %d\n",
+		       ahd_name(ahd), line, oldstate, newstate);
+#endif
+
+	if (oldstate == newstate)
+		targ->dv_state_retry++;
+	else
+		targ->dv_state_retry = 0;
+	targ->dv_state = newstate;
+}
+
+static void
+ahd_linux_dv_target(struct ahd_softc *ahd, u_int target_offset)
+{
+	struct	 ahd_devinfo devinfo;
+	struct	 ahd_linux_target *targ;
+	struct	 scsi_cmnd *cmd;
+	struct	 scsi_sense_data *sense;
+	uint8_t *buffer;
+	u_long	 s;
+	u_int	 timeout;
+	int	 echo_size;
+
+	sense = NULL;
+	buffer = NULL;
+	echo_size = 0;
+	ahd_lock(ahd, &s);
+	targ = ahd->platform_data->targets[target_offset];
+	if (targ == NULL || (targ->flags & AHD_DV_REQUIRED) == 0) {
+		ahd_unlock(ahd, &s);
+		return;
+	}
+	ahd_compile_devinfo(&devinfo, ahd->our_id, targ->target, /*lun*/0,
+			    targ->channel + 'A', ROLE_INITIATOR);
+#ifdef AHD_DEBUG
+	if (ahd_debug & AHD_SHOW_DV) {
+		ahd_print_devinfo(ahd, &devinfo);
+		printf("Performing DV\n");
+	}
+#endif
+
+	ahd_unlock(ahd, &s);
+
+	cmd = malloc(sizeof(struct scsi_cmnd), M_DEVBUF, M_WAITOK);
+
+	AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_INQ_SHORT_ASYNC);
+
+	while (targ->dv_state != AHD_DV_STATE_EXIT) {
+		timeout = AHD_LINUX_DV_TIMEOUT;
+		switch (targ->dv_state) {
+		case AHD_DV_STATE_INQ_SHORT_ASYNC:
+		case AHD_DV_STATE_INQ_ASYNC:
+		case AHD_DV_STATE_INQ_ASYNC_VERIFY:
+			/*
+			 * Set things to async narrow to reduce the
+			 * chance that the INQ will fail.
+			 */
+			ahd_lock(ahd, &s);
+			ahd_set_syncrate(ahd, &devinfo, 0, 0, 0,
+					 AHD_TRANS_GOAL, /*paused*/FALSE);
+			ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
+				      AHD_TRANS_GOAL, /*paused*/FALSE);
+			ahd_unlock(ahd, &s);
+			timeout = 10 * HZ;
+			/* FALLTHROUGH */
+		case AHD_DV_STATE_INQ_VERIFY:
+		{
+			u_int inq_len;
+
+			if (targ->dv_state == AHD_DV_STATE_INQ_SHORT_ASYNC)
+				inq_len = AHD_LINUX_DV_INQ_SHORT_LEN;
+			else
+				inq_len = targ->inq_data->additional_length + 5;
+			ahd_linux_dv_inq(ahd, cmd, &devinfo, targ, inq_len);
+			break;
+		}
+		case AHD_DV_STATE_TUR:
+		case AHD_DV_STATE_BUSY:
+			ahd_linux_dv_tur(ahd, cmd, &devinfo);
+			break;
+		case AHD_DV_STATE_REBD:
+			ahd_linux_dv_rebd(ahd, cmd, &devinfo, targ);
+			break;
+		case AHD_DV_STATE_WEB:
+			ahd_linux_dv_web(ahd, cmd, &devinfo, targ);
+			break;
+
+		case AHD_DV_STATE_REB:
+			ahd_linux_dv_reb(ahd, cmd, &devinfo, targ);
+			break;
+
+		case AHD_DV_STATE_SU:
+			ahd_linux_dv_su(ahd, cmd, &devinfo, targ);
+			timeout = 50 * HZ;
+			break;
+
+		default:
+			ahd_print_devinfo(ahd, &devinfo);
+			printf("Unknown DV state %d\n", targ->dv_state);
+			goto out;
+		}
+
+		/* Queue the command and wait for it to complete */
+		/* Abuse eh_timeout in the scsi_cmnd struct for our purposes */
+		init_timer(&cmd->eh_timeout);
+#ifdef AHD_DEBUG
+		if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
+			/*
+			 * All of the printfs during negotiation
+			 * really slow down the negotiation.
+			 * Add a bit of time just to be safe.
+			 */
+			timeout += HZ;
+#endif
+		scsi_add_timer(cmd, timeout, ahd_linux_dv_timeout);
+		/*
+		 * In 2.5.X, it is assumed that all calls from the
+		 * "midlayer" (which we are emulating) will have the
+		 * ahd host lock held.
+		 */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+		ahd_lock(ahd, &s);
+#endif
+		ahd_linux_queue(cmd, ahd_linux_dv_complete);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+		ahd_unlock(ahd, &s);
+#endif
+		down(&ahd->platform_data->dv_cmd_sem);
+		/*
+		 * Wait for the SIMQ to be released so that DV is the
+		 * only reason the queue is frozen.
+		 */
+		ahd_lock(ahd, &s);
+		while (AHD_DV_SIMQ_FROZEN(ahd) == 0) {
+			ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_RELEASE;
+			ahd_unlock(ahd, &s);
+			down(&ahd->platform_data->dv_sem);
+			ahd_lock(ahd, &s);
+		}
+		ahd_unlock(ahd, &s);
+
+		ahd_linux_dv_transition(ahd, cmd, &devinfo, targ);
+	}
+
+out:
+	if (cmd != NULL)
+		free(cmd, M_DEVBUF);
+
+	ahd_lock(ahd, &s);
+	if (targ->dv_buffer != NULL)
+		free(targ->dv_buffer, M_DEVBUF);
+	if (targ->dv_buffer1 != NULL)
+		free(targ->dv_buffer1, M_DEVBUF);
+	targ->flags &= ~AHD_DV_REQUIRED;
+	if (targ->refcount == 0)
+		ahd_linux_free_target(ahd, targ);
+	ahd_unlock(ahd, &s);
+}
+
+static void
+ahd_linux_dv_transition(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
+			struct ahd_devinfo *devinfo,
+			struct ahd_linux_target *targ)
+{
+	u_int32_t status;
+
+	status = aic_error_action(cmd, targ->inq_data);
+
+	
+#ifdef AHD_DEBUG
+	if (ahd_debug & AHD_SHOW_DV) {
+		ahd_print_devinfo(ahd, devinfo);
+		printf("Entering ahd_linux_dv_transition, state= %d, "
+		       "status= 0x%x, cmd->result= 0x%x\n", targ->dv_state,
+		       status, cmd->result);
+	}
+#endif
+
+	switch (targ->dv_state) {
+	case AHD_DV_STATE_INQ_SHORT_ASYNC:
+	case AHD_DV_STATE_INQ_ASYNC:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+		{
+			AHD_SET_DV_STATE(ahd, targ, targ->dv_state+1);
+			break;
+		}
+		case SS_INQ_REFRESH:
+			AHD_SET_DV_STATE(ahd, targ,
+					 AHD_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		case SS_TUR:
+		case SS_RETRY:
+			AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
+			if (ahd_cmd_get_transaction_status(cmd)
+			 == CAM_REQUEUE_REQ)
+				targ->dv_state_retry--;
+			if ((status & SS_ERRMASK) == EBUSY)
+				AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
+			if (targ->dv_state_retry < 10)
+				break;
+			/* FALLTHROUGH */
+		default:
+			AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
+#ifdef AHD_DEBUG
+			if (ahd_debug & AHD_SHOW_DV) {
+				ahd_print_devinfo(ahd, devinfo);
+				printf("Failed DV inquiry, skipping\n");
+			}
+#endif
+			break;
+		}
+		break;
+	case AHD_DV_STATE_INQ_ASYNC_VERIFY:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+		{
+			u_int spi3data;
+
+			if (memcmp(targ->inq_data, targ->dv_buffer,
+				   AHD_LINUX_DV_INQ_LEN) != 0) {
+				/*
+				 * Inquiry data must have changed.
+				 * Try from the top again.
+				 */
+				AHD_SET_DV_STATE(ahd, targ,
+						 AHD_DV_STATE_INQ_SHORT_ASYNC);
+				break;
+			}
+
+			if (ahd_linux_user_dv_setting(ahd) == 0) {
+				ahd_linux_filter_inquiry(ahd, devinfo);
+				AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
+				break;
+			}
+
+			spi3data = targ->inq_data->spi3data;
+			switch (spi3data & SID_SPI_CLOCK_DT_ST) {
+			default:
+			case SID_SPI_CLOCK_ST:
+				/* Assume only basic DV is supported. */
+				ahd_linux_filter_inquiry(ahd, devinfo);
+				AHD_SET_DV_STATE(ahd, targ,
+						 AHD_DV_STATE_INQ_VERIFY);
+				break;
+			case SID_SPI_CLOCK_DT:
+			case SID_SPI_CLOCK_DT_ST:
+				AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_REBD);
+				break;
+			}
+			break;
+		}
+		case SS_INQ_REFRESH:
+			AHD_SET_DV_STATE(ahd, targ,
+					 AHD_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		case SS_TUR:
+		case SS_RETRY:
+			AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
+			if (ahd_cmd_get_transaction_status(cmd)
+			 == CAM_REQUEUE_REQ)
+				targ->dv_state_retry--;
+
+			if ((status & SS_ERRMASK) == EBUSY)
+				AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
+			if (targ->dv_state_retry < 10)
+				break;
+			/* FALLTHROUGH */
+		default:
+			AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
+#ifdef AHD_DEBUG
+			if (ahd_debug & AHD_SHOW_DV) {
+				ahd_print_devinfo(ahd, devinfo);
+				printf("Failed DV inquiry, skipping\n");
+			}
+#endif
+			break;
+		}
+		break;
+	case AHD_DV_STATE_INQ_VERIFY:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+		{
+
+			if (memcmp(targ->inq_data, targ->dv_buffer,
+				   AHD_LINUX_DV_INQ_LEN) == 0) {
+				AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
+				break;
+			}
+
+			if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
+				AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
+				break;
+			}
+			/*
+			 * Do not count "falling back"
+			 * against our retries.
+			 */
+			targ->dv_state_retry = 0;
+			AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
+			break;
+		}
+		case SS_INQ_REFRESH:
+			AHD_SET_DV_STATE(ahd, targ,
+					 AHD_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		case SS_TUR:
+		case SS_RETRY:
+			AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
+			if (ahd_cmd_get_transaction_status(cmd)
+			 == CAM_REQUEUE_REQ) {
+				targ->dv_state_retry--;
+			} else if ((status & SSQ_FALLBACK) != 0) {
+				if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
+					AHD_SET_DV_STATE(ahd, targ,
+							 AHD_DV_STATE_EXIT);
+					break;
+				}
+				/*
+				 * Do not count "falling back"
+				 * against our retries.
+				 */
+				targ->dv_state_retry = 0;
+			} else if ((status & SS_ERRMASK) == EBUSY)
+				AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
+			if (targ->dv_state_retry < 10)
+				break;
+			/* FALLTHROUGH */
+		default:
+			AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
+#ifdef AHD_DEBUG
+			if (ahd_debug & AHD_SHOW_DV) {
+				ahd_print_devinfo(ahd, devinfo);
+				printf("Failed DV inquiry, skipping\n");
+			}
+#endif
+			break;
+		}
+		break;
+
+	case AHD_DV_STATE_TUR:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+			AHD_SET_DV_STATE(ahd, targ,
+					 AHD_DV_STATE_INQ_ASYNC);
+			break;
+		case SS_RETRY:
+		case SS_TUR:
+			if ((status & SS_ERRMASK) == EBUSY) {
+				AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
+				break;
+			}
+			AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
+			if (ahd_cmd_get_transaction_status(cmd)
+			 == CAM_REQUEUE_REQ) {
+				targ->dv_state_retry--;
+			} else if ((status & SSQ_FALLBACK) != 0) {
+				if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
+					AHD_SET_DV_STATE(ahd, targ,
+							 AHD_DV_STATE_EXIT);
+					break;
+				}
+				/*
+				 * Do not count "falling back"
+				 * against our retries.
+				 */
+				targ->dv_state_retry = 0;
+			}
+			if (targ->dv_state_retry >= 10) {
+#ifdef AHD_DEBUG
+				if (ahd_debug & AHD_SHOW_DV) {
+					ahd_print_devinfo(ahd, devinfo);
+					printf("DV TUR reties exhausted\n");
+				}
+#endif
+				AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
+				break;
+			}
+			if (status & SSQ_DELAY)
+				scsi_sleep(1 * HZ);
+
+			break;
+		case SS_START:
+			AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_SU);
+			break;
+		case SS_INQ_REFRESH:
+			AHD_SET_DV_STATE(ahd, targ,
+					 AHD_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		default:
+			AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
+			break;
+		}
+		break;
+
+	case AHD_DV_STATE_REBD:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+		{
+			uint32_t echo_size;
+
+			AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_WEB);
+			echo_size = scsi_3btoul(&targ->dv_buffer[1]);
+			echo_size &= 0x1FFF;
+#ifdef AHD_DEBUG
+			if (ahd_debug & AHD_SHOW_DV) {
+				ahd_print_devinfo(ahd, devinfo);
+				printf("Echo buffer size= %d\n", echo_size);
+			}
+#endif
+			if (echo_size == 0) {
+				AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
+				break;
+			}
+
+			/* Generate the buffer pattern */
+			targ->dv_echo_size = echo_size;
+			ahd_linux_generate_dv_pattern(targ);
+			/*
+			 * Setup initial negotiation values.
+			 */
+			ahd_linux_filter_inquiry(ahd, devinfo);
+			break;
+		}
+		case SS_INQ_REFRESH:
+			AHD_SET_DV_STATE(ahd, targ,
+					 AHD_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		case SS_RETRY:
+			AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
+			if (ahd_cmd_get_transaction_status(cmd)
+			 == CAM_REQUEUE_REQ)
+				targ->dv_state_retry--;
+			if (targ->dv_state_retry <= 10)
+				break;
+#ifdef AHD_DEBUG
+			if (ahd_debug & AHD_SHOW_DV) {
+				ahd_print_devinfo(ahd, devinfo);
+				printf("DV REBD reties exhausted\n");
+			}
+#endif
+			/* FALLTHROUGH */
+		case SS_FATAL:
+		default:
+			/*
+			 * Setup initial negotiation values
+			 * and try level 1 DV.
+			 */
+			ahd_linux_filter_inquiry(ahd, devinfo);
+			AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_INQ_VERIFY);
+			targ->dv_echo_size = 0;
+			break;
+		}
+		break;
+
+	case AHD_DV_STATE_WEB:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+			AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_REB);
+			break;
+		case SS_INQ_REFRESH:
+			AHD_SET_DV_STATE(ahd, targ,
+					 AHD_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		case SS_RETRY:
+			AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
+			if (ahd_cmd_get_transaction_status(cmd)
+			 == CAM_REQUEUE_REQ) {
+				targ->dv_state_retry--;
+			} else if ((status & SSQ_FALLBACK) != 0) {
+				if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
+					AHD_SET_DV_STATE(ahd, targ,
+							 AHD_DV_STATE_EXIT);
+					break;
+				}
+				/*
+				 * Do not count "falling back"
+				 * against our retries.
+				 */
+				targ->dv_state_retry = 0;
+			}
+			if (targ->dv_state_retry <= 10)
+				break;
+			/* FALLTHROUGH */
+#ifdef AHD_DEBUG
+			if (ahd_debug & AHD_SHOW_DV) {
+				ahd_print_devinfo(ahd, devinfo);
+				printf("DV WEB reties exhausted\n");
+			}
+#endif
+		default:
+			AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
+			break;
+		}
+		break;
+
+	case AHD_DV_STATE_REB:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+			if (memcmp(targ->dv_buffer, targ->dv_buffer1,
+				   targ->dv_echo_size) != 0) {
+				if (ahd_linux_dv_fallback(ahd, devinfo) != 0)
+					AHD_SET_DV_STATE(ahd, targ,
+							 AHD_DV_STATE_EXIT);
+				else
+					AHD_SET_DV_STATE(ahd, targ,
+							 AHD_DV_STATE_WEB);
+				break;
+			}
+			
+			if (targ->dv_buffer != NULL) {
+				free(targ->dv_buffer, M_DEVBUF);
+				targ->dv_buffer = NULL;
+			}
+			if (targ->dv_buffer1 != NULL) {
+				free(targ->dv_buffer1, M_DEVBUF);
+				targ->dv_buffer1 = NULL;
+			}
+			AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
+			break;
+		case SS_INQ_REFRESH:
+			AHD_SET_DV_STATE(ahd, targ,
+					 AHD_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		case SS_RETRY:
+			AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
+			if (ahd_cmd_get_transaction_status(cmd)
+			 == CAM_REQUEUE_REQ) {
+				targ->dv_state_retry--;
+			} else if ((status & SSQ_FALLBACK) != 0) {
+				if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
+					AHD_SET_DV_STATE(ahd, targ,
+							 AHD_DV_STATE_EXIT);
+					break;
+				}
+				AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_WEB);
+			}
+			if (targ->dv_state_retry <= 10) {
+				if ((status & (SSQ_DELAY_RANDOM|SSQ_DELAY))!= 0)
+					scsi_sleep(ahd->our_id*HZ/10);
+				break;
+			}
+#ifdef AHD_DEBUG
+			if (ahd_debug & AHD_SHOW_DV) {
+				ahd_print_devinfo(ahd, devinfo);
+				printf("DV REB reties exhausted\n");
+			}
+#endif
+			/* FALLTHROUGH */
+		default:
+			AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
+			break;
+		}
+		break;
+
+	case AHD_DV_STATE_SU:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+		case SS_INQ_REFRESH:
+			AHD_SET_DV_STATE(ahd, targ,
+					 AHD_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		default:
+			AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
+			break;
+		}
+		break;
+
+	case AHD_DV_STATE_BUSY:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+		case SS_INQ_REFRESH:
+			AHD_SET_DV_STATE(ahd, targ,
+					 AHD_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		case SS_TUR:
+		case SS_RETRY:
+			AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
+			if (ahd_cmd_get_transaction_status(cmd)
+			 == CAM_REQUEUE_REQ) {
+				targ->dv_state_retry--;
+			} else if (targ->dv_state_retry < 60) {
+				if ((status & SSQ_DELAY) != 0)
+					scsi_sleep(1 * HZ);
+			} else {
+#ifdef AHD_DEBUG
+				if (ahd_debug & AHD_SHOW_DV) {
+					ahd_print_devinfo(ahd, devinfo);
+					printf("DV BUSY reties exhausted\n");
+				}
+#endif
+				AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
+			}
+			break;
+		default:
+			AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
+			break;
+		}
+		break;
+
+	default:
+		printf("%s: Invalid DV completion state %d\n", ahd_name(ahd),
+		       targ->dv_state);
+		AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
+		break;
+	}
+}
+
+static uint32_t
+aic_error_action(struct scsi_cmnd *cmd, struct scsi_inquiry_data *inq_data)
+{
+	aic_sense_action  err_action;
+	cam_status	  status;
+	u_int		  scsi_status;
+	int		  sense;
+
+	status = ahd_cmd_get_transaction_status(cmd);
+	scsi_status = ahd_cmd_get_scsi_status(cmd);
+	sense  = (cmd->result >> 24) == DRIVER_SENSE;
+
+	switch (status) {
+	case CAM_REQ_CMP:
+		err_action = SS_NOP;
+		break;
+	case CAM_AUTOSENSE_FAIL:
+	case CAM_SCSI_STATUS_ERROR:
+
+		switch (scsi_status) {
+		case SCSI_STATUS_OK:
+		case SCSI_STATUS_COND_MET:
+		case SCSI_STATUS_INTERMED:
+		case SCSI_STATUS_INTERMED_COND_MET:
+			err_action = SS_NOP;
+			break;
+		case SCSI_STATUS_CMD_TERMINATED:
+		case SCSI_STATUS_CHECK_COND:
+			if (sense != 0) {
+				struct scsi_sense_data *sense;
+
+				sense = (struct scsi_sense_data *)
+				    &cmd->sense_buffer;
+				err_action =
+				    aic_sense_error_action(sense, inq_data, 0);
+
+			} else {
+				err_action = SS_RETRY|SSQ_FALLBACK
+					   | SSQ_DECREMENT_COUNT|EIO;
+			}
+			break;
+		case SCSI_STATUS_QUEUE_FULL:
+		case SCSI_STATUS_BUSY:
+			err_action = SS_RETRY|SSQ_DELAY|SSQ_MANY
+				   | SSQ_DECREMENT_COUNT|EBUSY;
+			break;
+		case SCSI_STATUS_RESERV_CONFLICT:
+		default:
+			err_action = SS_FAIL|EBUSY;
+			break;
+		}
+		break;
+	case CAM_CMD_TIMEOUT:
+	case CAM_REQ_CMP_ERR:
+	case CAM_UNEXP_BUSFREE:
+	case CAM_UNCOR_PARITY:
+	case CAM_DATA_RUN_ERR:
+		err_action = SS_RETRY|SSQ_FALLBACK|EIO;
+		break;
+	case CAM_UA_ABORT:
+	case CAM_UA_TERMIO:
+	case CAM_MSG_REJECT_REC:
+	case CAM_SEL_TIMEOUT:
+		err_action = SS_FAIL|EIO;
+		break;
+	case CAM_REQ_INVALID:
+	case CAM_PATH_INVALID:
+	case CAM_DEV_NOT_THERE:
+	case CAM_NO_HBA:
+	case CAM_PROVIDE_FAIL:
+	case CAM_REQ_TOO_BIG:		
+	case CAM_RESRC_UNAVAIL:
+	case CAM_BUSY:
+	default:
+		/* panic??  These should never occur in our application. */
+		err_action = SS_FAIL|EIO;
+		break;
+	case CAM_SCSI_BUS_RESET:
+	case CAM_BDR_SENT:		
+	case CAM_REQUEUE_REQ:
+		/* Unconditional requeue */
+		err_action = SS_RETRY;
+		break;
+	}
+
+	return (err_action);
+}
+
+static void
+ahd_linux_dv_fill_cmd(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
+		      struct ahd_devinfo *devinfo)
+{
+	memset(cmd, 0, sizeof(struct scsi_cmnd));
+	cmd->host = ahd->platform_data->host;
+	cmd->scsi_done = ahd_linux_dv_complete;
+	cmd->target = devinfo->target;
+	cmd->lun = devinfo->lun;
+	cmd->channel = devinfo->channel - 'A';
+}
+
+/*
+ * Synthesize an inquiry command.  On the return trip, it'll be
+ * sniffed and the device transfer settings set for us.
+ */
+static void
+ahd_linux_dv_inq(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
+		 struct ahd_devinfo *devinfo, struct ahd_linux_target *targ,
+		 u_int request_length)
+{
+
+#ifdef AHD_DEBUG
+	if (ahd_debug & AHD_SHOW_DV) {
+		ahd_print_devinfo(ahd, devinfo);
+		printf("Sending INQ\n");
+	}
+#endif
+	if (targ->inq_data == NULL)
+		targ->inq_data = malloc(AHD_LINUX_DV_INQ_LEN,
+					M_DEVBUF, M_WAITOK);
+	if (targ->dv_state > AHD_DV_STATE_INQ_ASYNC) {
+		if (targ->dv_buffer != NULL)
+			free(targ->dv_buffer, M_DEVBUF);
+		targ->dv_buffer = malloc(AHD_LINUX_DV_INQ_LEN,
+					 M_DEVBUF, M_WAITOK);
+	}
+
+	ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
+	cmd->sc_data_direction = SCSI_DATA_READ;
+	cmd->cmd_len = 6;
+	cmd->cmnd[0] = INQUIRY;
+	cmd->cmnd[4] = request_length;
+	cmd->request_bufflen = request_length;
+	if (targ->dv_state > AHD_DV_STATE_INQ_ASYNC)
+		cmd->request_buffer = targ->dv_buffer;
+	else
+		cmd->request_buffer = targ->inq_data;
+	memset(cmd->request_buffer, 0, AHD_LINUX_DV_INQ_LEN);
+}
+
+static void
+ahd_linux_dv_tur(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
+		 struct ahd_devinfo *devinfo)
+{
+
+#ifdef AHD_DEBUG
+	if (ahd_debug & AHD_SHOW_DV) {
+		ahd_print_devinfo(ahd, devinfo);
+		printf("Sending TUR\n");
+	}
+#endif
+	/* Do a TUR to clear out any non-fatal transitional state */
+	ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
+	cmd->sc_data_direction = SCSI_DATA_NONE;
+	cmd->cmd_len = 6;
+	cmd->cmnd[0] = TEST_UNIT_READY;
+}
+
+#define AHD_REBD_LEN 4
+
+static void
+ahd_linux_dv_rebd(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
+		 struct ahd_devinfo *devinfo, struct ahd_linux_target *targ)
+{
+
+#ifdef AHD_DEBUG
+	if (ahd_debug & AHD_SHOW_DV) {
+		ahd_print_devinfo(ahd, devinfo);
+		printf("Sending REBD\n");
+	}
+#endif
+	if (targ->dv_buffer != NULL)
+		free(targ->dv_buffer, M_DEVBUF);
+	targ->dv_buffer = malloc(AHD_REBD_LEN, M_DEVBUF, M_WAITOK);
+	ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
+	cmd->sc_data_direction = SCSI_DATA_READ;
+	cmd->cmd_len = 10;
+	cmd->cmnd[0] = READ_BUFFER;
+	cmd->cmnd[1] = 0x0b;
+	scsi_ulto3b(AHD_REBD_LEN, &cmd->cmnd[6]);
+	cmd->request_bufflen = AHD_REBD_LEN;
+	cmd->underflow = cmd->request_bufflen;
+	cmd->request_buffer = targ->dv_buffer;
+}
+
+static void
+ahd_linux_dv_web(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
+		 struct ahd_devinfo *devinfo, struct ahd_linux_target *targ)
+{
+
+#ifdef AHD_DEBUG
+	if (ahd_debug & AHD_SHOW_DV) {
+		ahd_print_devinfo(ahd, devinfo);
+		printf("Sending WEB\n");
+	}
+#endif
+	ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
+	cmd->sc_data_direction = SCSI_DATA_WRITE;
+	cmd->cmd_len = 10;
+	cmd->cmnd[0] = WRITE_BUFFER;
+	cmd->cmnd[1] = 0x0a;
+	scsi_ulto3b(targ->dv_echo_size, &cmd->cmnd[6]);
+	cmd->request_bufflen = targ->dv_echo_size;
+	cmd->underflow = cmd->request_bufflen;
+	cmd->request_buffer = targ->dv_buffer;
+}
+
+static void
+ahd_linux_dv_reb(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
+		 struct ahd_devinfo *devinfo, struct ahd_linux_target *targ)
+{
+
+#ifdef AHD_DEBUG
+	if (ahd_debug & AHD_SHOW_DV) {
+		ahd_print_devinfo(ahd, devinfo);
+		printf("Sending REB\n");
+	}
+#endif
+	ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
+	cmd->sc_data_direction = SCSI_DATA_READ;
+	cmd->cmd_len = 10;
+	cmd->cmnd[0] = READ_BUFFER;
+	cmd->cmnd[1] = 0x0a;
+	scsi_ulto3b(targ->dv_echo_size, &cmd->cmnd[6]);
+	cmd->request_bufflen = targ->dv_echo_size;
+	cmd->underflow = cmd->request_bufflen;
+	cmd->request_buffer = targ->dv_buffer1;
+}
+
+static void
+ahd_linux_dv_su(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
+		struct ahd_devinfo *devinfo,
+		struct ahd_linux_target *targ)
+{
+	u_int le;
+
+	le = SID_IS_REMOVABLE(targ->inq_data) ? SSS_LOEJ : 0;
+
+#ifdef AHD_DEBUG
+	if (ahd_debug & AHD_SHOW_DV) {
+		ahd_print_devinfo(ahd, devinfo);
+		printf("Sending SU\n");
+	}
+#endif
+	ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
+	cmd->sc_data_direction = SCSI_DATA_NONE;
+	cmd->cmd_len = 6;
+	cmd->cmnd[0] = START_STOP_UNIT;
+	cmd->cmnd[4] = le | SSS_START;
+}
+
+/*
+ * Return speed in KB/s.
+ */
+static u_int
+ahd_linux_calc_speed(u_int width, u_int period, u_int offset)
+{
+	u_int freq;
+
+	if (offset != 0 && period < AHD_SYNCRATE_MIN)
+		freq  = aic_calc_syncsrate(period);
+	else
+		/* Roughly 3.3MB/s for async */
+		freq  = 3300;
+	freq <<= width;
+	return (freq);
+}
+
+static __inline int
+ahd_linux_dv_fallback(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
+{
+	u_long s;
+	int retval;
+
+	ahd_lock(ahd, &s);
+	retval = ahd_linux_fallback(ahd, devinfo);
+	ahd_unlock(ahd, &s);
+
+	return (retval);
+}
+
+static int
+ahd_linux_fallback(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
+{
+	struct	ahd_linux_target *targ;
+	struct	ahd_initiator_tinfo *tinfo;
+	struct	ahd_transinfo *goal;
+	struct	ahd_tmode_tstate *tstate;
+	u_int	width;
+	u_int	period;
+	u_int	offset;
+	u_int	ppr_options;
+	u_int	cur_speed;
+	u_int	wide_speed;
+	u_int	narrow_speed;
+	u_int	fallback_speed;
+
+#ifdef AHD_DEBUG
+	if (ahd_debug & AHD_SHOW_DV) {
+		ahd_print_devinfo(ahd, devinfo);
+		printf("Trying to fallback\n");
+	}
+#endif
+	targ = ahd->platform_data->targets[devinfo->target_offset];
+	tinfo = ahd_fetch_transinfo(ahd, devinfo->channel,
+				    devinfo->our_scsiid,
+				    devinfo->target, &tstate);
+	goal = &tinfo->goal;
+	width = goal->width;
+	period = goal->period;
+	offset = goal->offset;
+	ppr_options = goal->ppr_options;
+	if (offset == 0)
+		period = AHD_ASYNC_XFER_PERIOD;
+	if (targ->dv_next_narrow_period == 0)
+		targ->dv_next_narrow_period = MAX(period, AHD_SYNCRATE_ULTRA2);
+	if (targ->dv_next_wide_period == 0)
+		targ->dv_next_wide_period = period;
+	if (targ->dv_max_ppr_options == 0)
+		targ->dv_max_ppr_options = ppr_options;
+	if (targ->dv_last_ppr_options == 0)
+		targ->dv_last_ppr_options = ppr_options;
+
+	cur_speed = ahd_linux_calc_speed(width, period, offset);
+	wide_speed = ahd_linux_calc_speed(MSG_EXT_WDTR_BUS_16_BIT,
+					  targ->dv_next_wide_period,
+					  MAX_OFFSET);
+	narrow_speed = ahd_linux_calc_speed(MSG_EXT_WDTR_BUS_8_BIT,
+					    targ->dv_next_narrow_period,
+					    MAX_OFFSET);
+	fallback_speed = ahd_linux_calc_speed(width, period+1, offset);
+#ifdef AHD_DEBUG
+	if (ahd_debug & AHD_SHOW_DV) {
+		printf("cur_speed= %d, wide_speed= %d, narrow_speed= %d, "
+		       "fallback_speed= %d\n", cur_speed, wide_speed,
+		       narrow_speed, fallback_speed);
+	}
+#endif
+
+	if (cur_speed > 160000) {
+		/*
+		 * Paced/DT/IU_REQ only transfer speeds.  All we
+		 * can do is fallback in terms of syncrate.
+		 */
+		period++;
+	} else if (cur_speed > 80000) {
+		if ((ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
+			/*
+			 * Try without IU_REQ as it may be confusing
+			 * an expander.
+			 */
+			ppr_options &= ~MSG_EXT_PPR_IU_REQ;
+		} else {
+			/*
+			 * Paced/DT only transfer speeds.  All we
+			 * can do is fallback in terms of syncrate.
+			 */
+			period++;
+			ppr_options = targ->dv_max_ppr_options;
+		}
+	} else if (cur_speed > 3300) {
+
+		/*
+		 * In this range we the following
+		 * options ordered from highest to
+		 * lowest desireability:
+		 *
+		 * o Wide/DT
+		 * o Wide/non-DT
+		 * o Narrow at a potentally higher sync rate.
+		 *
+		 * All modes are tested with and without IU_REQ
+		 * set since using IUs may confuse an expander.
+		 */
+		if ((ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
+
+			ppr_options &= ~MSG_EXT_PPR_IU_REQ;
+		} else if ((ppr_options & MSG_EXT_PPR_DT_REQ) != 0) {
+			/*
+			 * Try going non-DT.
+			 */
+			ppr_options = targ->dv_max_ppr_options;
+			ppr_options &= ~MSG_EXT_PPR_DT_REQ;
+		} else if (targ->dv_last_ppr_options != 0) {
+			/*
+			 * Try without QAS or any other PPR options.
+			 * We may need a non-PPR message to work with
+			 * an expander.  We look at the "last PPR options"
+			 * so we will perform this fallback even if the
+			 * target responded to our PPR negotiation with
+			 * no option bits set.
+			 */
+			ppr_options = 0;
+		} else if (width == MSG_EXT_WDTR_BUS_16_BIT) {
+			/*
+			 * If the next narrow speed is greater than
+			 * the next wide speed, fallback to narrow.
+			 * Otherwise fallback to the next DT/Wide setting.
+			 * The narrow async speed will always be smaller
+			 * than the wide async speed, so handle this case
+			 * specifically.
+			 */
+			ppr_options = targ->dv_max_ppr_options;
+			if (narrow_speed > fallback_speed
+			 || period >= AHD_ASYNC_XFER_PERIOD) {
+				targ->dv_next_wide_period = period+1;
+				width = MSG_EXT_WDTR_BUS_8_BIT;
+				period = targ->dv_next_narrow_period;
+			} else {
+				period++;
+			}
+		} else if ((ahd->features & AHD_WIDE) != 0
+			&& tinfo->user.width != 0
+			&& wide_speed >= fallback_speed
+			&& (targ->dv_next_wide_period <= AHD_ASYNC_XFER_PERIOD
+			 || period >= AHD_ASYNC_XFER_PERIOD)) {
+
+			/*
+			 * We are narrow.  Try falling back
+			 * to the next wide speed with 
+			 * all supported ppr options set.
+			 */
+			targ->dv_next_narrow_period = period+1;
+			width = MSG_EXT_WDTR_BUS_16_BIT;
+			period = targ->dv_next_wide_period;
+			ppr_options = targ->dv_max_ppr_options;
+		} else {
+			/* Only narrow fallback is allowed. */
+			period++;
+			ppr_options = targ->dv_max_ppr_options;
+		}
+	} else {
+		return (-1);
+	}
+	offset = MAX_OFFSET;
+	ahd_find_syncrate(ahd, &period, &ppr_options, AHD_SYNCRATE_PACED);
+	ahd_set_width(ahd, devinfo, width, AHD_TRANS_GOAL, FALSE);
+	if (period == 0) {
+		period = 0;
+		offset = 0;
+		ppr_options = 0;
+		if (width == MSG_EXT_WDTR_BUS_8_BIT)
+			targ->dv_next_narrow_period = AHD_ASYNC_XFER_PERIOD;
+		else
+			targ->dv_next_wide_period = AHD_ASYNC_XFER_PERIOD;
+	}
+	ahd_set_syncrate(ahd, devinfo, period, offset,
+			 ppr_options, AHD_TRANS_GOAL, FALSE);
+	targ->dv_last_ppr_options = ppr_options;
+	return (0);
+}
+
+static void
+ahd_linux_dv_timeout(struct scsi_cmnd *cmd)
+{
+	struct	ahd_softc *ahd;
+	struct	ahd_cmd *acmd;
+	struct	ahd_linux_device *next_dev;
+	struct	scb *scb;
+	u_long	flags;
+
+	ahd = *((struct ahd_softc **)cmd->host->hostdata);
+	ahd_lock(ahd, &flags);
+
+#ifdef AHD_DEBUG
+	if (ahd_debug & AHD_SHOW_DV)
+		printf("%s: Timeout while doing DV command %x.\n",
+		       ahd_name(ahd), cmd->cmnd[0]);
+#endif
+	
+	/*
+	 * Guard against "done race".  No action is
+	 * required if we just completed.
+	 */
+	if ((scb = (struct scb *)cmd->host_scribble) == NULL) {
+		ahd_unlock(ahd, &flags);
+		return;
+	}
+
+	/*
+	 * Command has not completed.  Mark this
+	 * SCB as having failing status prior to
+	 * resetting the bus, so we get the correct
+	 * error code.
+	 */
+	if ((scb->flags & SCB_SENSE) != 0)
+		ahd_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
+	else
+		ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT);
+	ahd_reset_channel(ahd, cmd->channel + 'A', /*initiate*/TRUE);
+
+	/*
+	 * Add a minimal bus settle delay for devices that are slow to
+	 * respond after bus resets.
+	 */
+	ahd_freeze_simq(ahd);
+	init_timer(&ahd->platform_data->reset_timer);
+	ahd->platform_data->reset_timer.data = (u_long)ahd;
+	ahd->platform_data->reset_timer.expires = jiffies + HZ / 2;
+	ahd->platform_data->reset_timer.function =
+	    (ahd_linux_callback_t *)ahd_release_simq;
+	add_timer(&ahd->platform_data->reset_timer);
+	/*
+	 * In 2.5.X, the "done lock" is the ahd_lock.
+	 * Instead of dropping and re-acquiring the same
+	 * lock in the 2.5.X case, just hold our ahd_lock
+	 * the whole time.  ahd_done_lock() has been
+	 * made a no-op for 2.5.X too.
+	 */
+	acmd = TAILQ_FIRST(&ahd->platform_data->completeq);
+	TAILQ_INIT(&ahd->platform_data->completeq);
+	next_dev = ahd_linux_next_device_to_run(ahd);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	ahd_unlock(ahd, &flags);
+#endif
+	if (next_dev)
+		ahd_schedule_runq(ahd);
+	if (acmd != NULL) {
+		acmd = ahd_linux_run_complete_queue(ahd, acmd);
+		if (acmd != NULL) {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+			ahd_lock(ahd, &flags);
+#endif
+			ahd_schedule_completeq(ahd, acmd);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+			ahd_unlock(ahd, &flags);
+#endif
+		}
+	}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+	ahd_unlock(ahd, &flags);
+#endif
+}
+
+static void
+ahd_linux_dv_complete(struct scsi_cmnd *cmd)
+{
+	struct ahd_softc *ahd;
+
+	ahd = *((struct ahd_softc **)cmd->host->hostdata);
+
+	/* Delete the DV timer before it goes off! */
+	scsi_delete_timer(cmd);
+
+#ifdef AHD_DEBUG
+	if (ahd_debug & AHD_SHOW_DV)
+		printf("%s:%c:%d: Command completed, status= 0x%x\n",
+		       ahd_name(ahd), cmd->channel, cmd->target, cmd->result);
+#endif
+
+	/* Wake up the state machine */
+	up(&ahd->platform_data->dv_cmd_sem);
+}
+
+static void
+ahd_linux_generate_dv_pattern(struct ahd_linux_target *targ)
+{
+	uint16_t b;
+	u_int	 i;
+	u_int	 j;
+
+	if (targ->dv_buffer != NULL)
+		free(targ->dv_buffer, M_DEVBUF);
+	targ->dv_buffer = malloc(targ->dv_echo_size, M_DEVBUF, M_WAITOK);
+	if (targ->dv_buffer1 != NULL)
+		free(targ->dv_buffer1, M_DEVBUF);
+	targ->dv_buffer1 = malloc(targ->dv_echo_size, M_DEVBUF, M_WAITOK);
+
+	i = 0;
+
+	b = 0x0001;
+	for (j = 0 ; i < targ->dv_echo_size; j++) {
+		if (j < 32) {
+			/*
+			 * 32bytes of sequential numbers.
+			 */
+			targ->dv_buffer[i++] = j & 0xff;
+		} else if (j < 48) {
+			/*
+			 * 32bytes of repeating 0x0000, 0xffff.
+			 */
+			targ->dv_buffer[i++] = (j & 0x02) ? 0xff : 0x00;
+		} else if (j < 64) {
+			/*
+			 * 32bytes of repeating 0x5555, 0xaaaa.
+			 */
+			targ->dv_buffer[i++] = (j & 0x02) ? 0xaa : 0x55;
+		} else {
+			/*
+			 * Remaining buffer is filled with a repeating
+			 * patter of:
+			 *
+			 *	 0xffff
+			 *	~0x0001 << shifted once in each loop.
+			 */
+			if (j & 0x02) {
+				if (j & 0x01) {
+					targ->dv_buffer[i++] = ~(b >> 8) & 0xff;
+					b <<= 1;
+					if (b == 0x0000)
+						b = 0x0001;
+				} else {
+					targ->dv_buffer[i++] = (~b & 0xff);
+				}
+			} else {
+				targ->dv_buffer[i++] = 0xff;
+			}
+		}
+	}
+}
+
+static u_int
+ahd_linux_user_tagdepth(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
+{
+	static int warned_user;
+	u_int tags;
+
+	tags = 0;
+	if ((ahd->user_discenable & devinfo->target_mask) != 0) {
+		if (warned_user == 0
+		 && ahd->unit >= NUM_ELEMENTS(aic79xx_tag_info)) {
+
+			printf("aic79xx: WARNING, insufficient "
+			       "tag_info instances for installed "
+			       "controllers. Using defaults\n");
+			printf("aic79xx: Please update the "
+			       "aic79xx_tag_info array in the "
+			       "aic79xx.c source file.\n");
+			tags = AHD_MAX_QUEUE;
+			warned_user++;
+		} else {
+			adapter_tag_info_t *tag_info;
+
+			tag_info = &aic79xx_tag_info[ahd->unit];
+			tags = tag_info->tag_commands[devinfo->target_offset];
+			if (tags > AHD_MAX_QUEUE)
+				tags = AHD_MAX_QUEUE;
+		}
+	}
+	return (tags);
+}
+
+static u_int
+ahd_linux_user_dv_setting(struct ahd_softc *ahd)
+{
+	static int warned_user;
+	int dv;
+
+	if (warned_user == 0
+	 && ahd->unit >= NUM_ELEMENTS(aic79xx_dv_settings)) {
+
+		printf("aic79xx: WARNING, insufficient "
+		       "dv settings instances for installed "
+		       "controllers. Using defaults\n");
+		printf("aic79xx: Please update the "
+		       "aic79xx_dv_settings array in the "
+		       "aic79xx.c source file.\n");
+		dv = -1;
+		warned_user++;
+	} else {
+
+		dv = aic79xx_dv_settings[ahd->unit];
+	}
+
+	if (dv < 0) {
+		/*
+		 * Apply the default.
+		 */
+		dv = 1;
+		if (ahd->seep_config != 0)
+			dv = (ahd->seep_config->bios_control & CFENABLEDV);
+	}
+	return (dv);
+}
+
+/*
+ * Determines the queue depth for a given device.
+ */
+static void
+ahd_linux_device_queue_depth(struct ahd_softc *ahd,
+			     struct ahd_linux_device *dev)
+{
+	struct	ahd_devinfo devinfo;
+	u_int	tags;
+
+	ahd_compile_devinfo(&devinfo,
+			    ahd->our_id,
+			    dev->target->target, dev->lun,
+			    dev->target->channel == 0 ? 'A' : 'B',
+			    ROLE_INITIATOR);
+	tags = ahd_linux_user_tagdepth(ahd, &devinfo);
+	if (tags != 0
+	 && dev->scsi_device != NULL
+	 && dev->scsi_device->tagged_supported != 0) {
+
+		ahd_set_tags(ahd, &devinfo, AHD_QUEUE_TAGGED);
+		printf("scsi%d:%c:%d:%d: Tagged Queuing enabled.  Depth %d\n",
+	       	       ahd->platform_data->host->host_no, devinfo.channel,
+		       devinfo.target, devinfo.lun, tags);
+	} else {
+		ahd_set_tags(ahd, &devinfo, AHD_QUEUE_NONE);
+	}
+}
+
+static void
+ahd_linux_run_device_queue(struct ahd_softc *ahd, struct ahd_linux_device *dev)
+{
+	struct	 ahd_cmd *acmd;
+	struct	 scsi_cmnd *cmd;
+	struct	 scb *scb;
+	struct	 hardware_scb *hscb;
+	struct	 ahd_initiator_tinfo *tinfo;
+	struct	 ahd_tmode_tstate *tstate;
+	u_int	 col_idx;
+	uint16_t mask;
+
+	if ((dev->flags & AHD_DEV_ON_RUN_LIST) != 0)
+		panic("running device on run list");
+
+	while ((acmd = TAILQ_FIRST(&dev->busyq)) != NULL
+	    && dev->openings > 0 && dev->qfrozen == 0) {
+
+		/*
+		 * Schedule us to run later.  The only reason we are not
+		 * running is because the whole controller Q is frozen.
+		 */
+		if (ahd->platform_data->qfrozen != 0
+		 && AHD_DV_SIMQ_FROZEN(ahd) == 0) {
+
+			TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq,
+					  dev, links);
+			dev->flags |= AHD_DEV_ON_RUN_LIST;
+			return;
+		}
+
+		cmd = &acmd_scsi_cmd(acmd);
+
+		/*
+		 * Get an scb to use.
+		 */
+		tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
+					    cmd->target, &tstate);
+		if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) == 0
+		 || (tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
+			col_idx = AHD_NEVER_COL_IDX;
+		} else {
+			col_idx = AHD_BUILD_COL_IDX(cmd->target, cmd->lun);
+		}
+		if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) {
+			TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq,
+					 dev, links);
+			dev->flags |= AHD_DEV_ON_RUN_LIST;
+			ahd->flags |= AHD_RESOURCE_SHORTAGE;
+			return;
+		}
+		TAILQ_REMOVE(&dev->busyq, acmd, acmd_links.tqe);
+		scb->io_ctx = cmd;
+		scb->platform_data->dev = dev;
+		hscb = scb->hscb;
+		cmd->host_scribble = (char *)scb;
+
+		/*
+		 * Fill out basics of the HSCB.
+		 */
+		hscb->control = 0;
+		hscb->scsiid = BUILD_SCSIID(ahd, cmd);
+		hscb->lun = cmd->lun;
+		mask = SCB_GET_TARGET_MASK(ahd, scb);
+
+		if ((ahd->user_discenable & mask) != 0)
+			hscb->control |= DISCENB;
+
+	 	if (AHD_DV_CMD(cmd) != 0)
+			scb->flags |= SCB_SILENT;
+
+		if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0)
+			scb->flags |= SCB_PACKETIZED;
+
+		if ((tstate->auto_negotiate & mask) != 0) {
+			scb->flags |= SCB_AUTO_NEGOTIATE;
+			scb->hscb->control |= MK_MESSAGE;
+		}
+
+		if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+			int	msg_bytes;
+			uint8_t tag_msgs[2];
+
+			msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
+			if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
+				hscb->control |= tag_msgs[0];
+				if (tag_msgs[0] == MSG_ORDERED_TASK)
+					dev->commands_since_idle_or_otag = 0;
+			} else
+#endif
+			if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH
+			 && (dev->flags & AHD_DEV_Q_TAGGED) != 0) {
+				hscb->control |= MSG_ORDERED_TASK;
+				dev->commands_since_idle_or_otag = 0;
+			} else {
+				hscb->control |= MSG_SIMPLE_TASK;
+			}
+		}
+
+		hscb->cdb_len = cmd->cmd_len;
+		memcpy(hscb->shared_data.idata.cdb, cmd->cmnd, hscb->cdb_len);
+
+		scb->sg_count = 0;
+		ahd_set_residual(scb, 0);
+		ahd_set_sense_residual(scb, 0);
+		if (cmd->use_sg != 0) {
+			void	*sg;
+			struct	 scatterlist *cur_seg;
+			u_int	 nseg;
+			int	 dir;
+
+			cur_seg = (struct scatterlist *)cmd->request_buffer;
+			dir = scsi_to_pci_dma_dir(cmd->sc_data_direction);
+			nseg = pci_map_sg(ahd->dev_softc, cur_seg,
+					  cmd->use_sg, dir);
+			scb->platform_data->xfer_len = 0;
+			for (sg = scb->sg_list; nseg > 0; nseg--, cur_seg++) {
+				bus_addr_t addr;
+				bus_size_t len;
+
+				addr = sg_dma_address(cur_seg);
+				len = sg_dma_len(cur_seg);
+				scb->platform_data->xfer_len += len;
+				sg = ahd_sg_setup(ahd, scb, sg, addr, len,
+						  /*last*/nseg == 1);
+			}
+		} else if (cmd->request_bufflen != 0) {
+			void *sg;
+			bus_addr_t addr;
+			int dir;
+
+			sg = scb->sg_list;
+			dir = scsi_to_pci_dma_dir(cmd->sc_data_direction);
+			addr = pci_map_single(ahd->dev_softc,
+					      cmd->request_buffer,
+					      cmd->request_bufflen, dir);
+			scb->platform_data->xfer_len = cmd->request_bufflen;
+			scb->platform_data->buf_busaddr = addr;
+			sg = ahd_sg_setup(ahd, scb, sg, addr,
+					  cmd->request_bufflen, /*last*/TRUE);
+		}
+
+		LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
+		dev->openings--;
+		dev->active++;
+		dev->commands_issued++;
+
+		/* Update the error counting bucket and dump if needed */
+		if (dev->target->cmds_since_error) {
+			dev->target->cmds_since_error++;
+			if (dev->target->cmds_since_error >
+			    AHD_LINUX_ERR_THRESH)
+				dev->target->cmds_since_error = 0;
+		}
+
+		if ((dev->flags & AHD_DEV_PERIODIC_OTAG) != 0)
+			dev->commands_since_idle_or_otag++;
+		scb->flags |= SCB_ACTIVE;
+		ahd_queue_scb(ahd, scb);
+	}
+}
+
+/*
+ * SCSI controller interrupt handler.
+ */
+void
+ahd_linux_isr(int irq, void *dev_id, struct pt_regs * regs)
+{
+	struct	ahd_softc *ahd;
+	struct	ahd_cmd *acmd;
+	u_long	flags;
+	struct	ahd_linux_device *next_dev;
+
+	ahd = (struct ahd_softc *) dev_id;
+	ahd_lock(ahd, &flags); 
+	ahd_intr(ahd);
+	acmd = TAILQ_FIRST(&ahd->platform_data->completeq);
+	TAILQ_INIT(&ahd->platform_data->completeq);
+	next_dev = ahd_linux_next_device_to_run(ahd);
+	/*
+	 * In 2.5.X, the "done lock" is the ahd_lock.
+	 * Instead of dropping and re-acquiring the same
+	 * lock in the 2.5.X case, just hold our ahd_lock
+	 * the whole time.  ahd_done_lock() has been
+	 * made a no-op for 2.5.X too.
+	 */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	ahd_unlock(ahd, &flags);
+#endif
+	if (next_dev)
+		ahd_schedule_runq(ahd);
+	if (acmd != NULL) {
+		acmd = ahd_linux_run_complete_queue(ahd, acmd);
+		if (acmd != NULL) {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+			ahd_lock(ahd, &flags);
+#endif
+			ahd_schedule_completeq(ahd, acmd);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+			ahd_unlock(ahd, &flags);
+#endif
+		}
+	}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+	ahd_unlock(ahd, &flags);
+#endif
+}
+
+void
+ahd_platform_flushwork(struct ahd_softc *ahd)
+{
+	struct ahd_cmd *acmd;
+
+	acmd = TAILQ_FIRST(&ahd->platform_data->completeq);
+	TAILQ_INIT(&ahd->platform_data->completeq);
+	while (acmd != NULL)
+		acmd = ahd_linux_run_complete_queue(ahd, acmd);
+}
+
+static struct ahd_linux_target*
+ahd_linux_alloc_target(struct ahd_softc *ahd, u_int channel, u_int target)
+{
+	struct ahd_linux_target *targ;
+	u_int target_offset;
+
+	target_offset = target;
+	/*
+	 * Never allow allocation of a target object for
+	 * our own SCSIID.
+	 */
+	if (target == ahd->our_id) {
+		ahd->platform_data->targets[target_offset] = NULL;
+		return (NULL);
+	}
+
+	targ = malloc(sizeof(*targ), M_DEVBUF, M_NOWAIT);
+	if (targ == NULL)
+		return (NULL);
+	memset(targ, 0, sizeof(*targ));
+	targ->channel = channel;
+	targ->target = target;
+	targ->ahd = ahd;
+	targ->flags = AHD_DV_REQUIRED;
+	ahd->platform_data->targets[target_offset] = targ;
+	return (targ);
+}
+
+static void
+ahd_linux_free_target(struct ahd_softc *ahd, struct ahd_linux_target *targ)
+{
+	struct ahd_devinfo devinfo;
+	struct ahd_initiator_tinfo *tinfo;
+	struct ahd_tmode_tstate *tstate;
+	u_int our_id;
+	u_int target_offset;
+	char channel;
+
+	/*
+	 * Force a negotiation to async/narrow on any
+	 * future command to this device unless a bus
+	 * reset occurs between now and that command.
+	 */
+	channel = 'A' + targ->channel;
+	our_id = ahd->our_id;
+	target_offset = targ->target;
+	tinfo = ahd_fetch_transinfo(ahd, channel, our_id,
+				    targ->target, &tstate);
+	ahd_compile_devinfo(&devinfo, our_id, targ->target, CAM_LUN_WILDCARD,
+			    channel, ROLE_INITIATOR);
+	ahd_set_syncrate(ahd, &devinfo, 0, 0, 0,
+			 AHD_TRANS_GOAL, /*paused*/FALSE);
+	ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
+		      AHD_TRANS_GOAL, /*paused*/FALSE);
+	ahd_update_neg_request(ahd, &devinfo, tstate, tinfo, AHD_NEG_ALWAYS);
+ 	ahd->platform_data->targets[target_offset] = NULL;
+	if (targ->inq_data != NULL)
+		free(targ->inq_data, M_DEVBUF);
+	if (targ->dv_buffer != NULL)
+		free(targ->dv_buffer, M_DEVBUF);
+	if (targ->dv_buffer1 != NULL)
+		free(targ->dv_buffer1, M_DEVBUF);
+	free(targ, M_DEVBUF);
+}
+
+static struct ahd_linux_device*
+ahd_linux_alloc_device(struct ahd_softc *ahd,
+		 struct ahd_linux_target *targ, u_int lun)
+{
+	struct ahd_linux_device *dev;
+
+	dev = malloc(sizeof(*dev), M_DEVBUG, M_NOWAIT);
+	if (dev == NULL)
+		return (NULL);
+	memset(dev, 0, sizeof(*dev));
+	init_timer(&dev->timer);
+	TAILQ_INIT(&dev->busyq);
+	dev->flags = AHD_DEV_UNCONFIGURED;
+	dev->lun = lun;
+	dev->target = targ;
+
+	/*
+	 * We start out life using untagged
+	 * transactions of which we allow one.
+	 */
+	dev->openings = 1;
+
+	/*
+	 * Set maxtags to 0.  This will be changed if we
+	 * later determine that we are dealing with
+	 * a tagged queuing capable device.
+	 */
+	dev->maxtags = 0;
+	
+	targ->refcount++;
+	targ->devices[lun] = dev;
+	return (dev);
+}
+
+static void
+ahd_linux_free_device(struct ahd_softc *ahd, struct ahd_linux_device *dev)
+{
+	struct ahd_linux_target *targ;
+
+	del_timer(&dev->timer);
+	targ = dev->target;
+	targ->devices[dev->lun] = NULL;
+	free(dev, M_DEVBUF);
+	targ->refcount--;
+	if (targ->refcount == 0
+	 && (targ->flags & AHD_DV_REQUIRED) == 0)
+		ahd_linux_free_target(ahd, targ);
+}
+
+void
+ahd_send_async(struct ahd_softc *ahd, char channel,
+	       u_int target, u_int lun, ac_code code, void *arg)
+{
+	switch (code) {
+	case AC_TRANSFER_NEG:
+	{
+		char	buf[80];
+		struct	ahd_linux_target *targ;
+		struct	info_str info;
+		struct	ahd_initiator_tinfo *tinfo;
+		struct	ahd_tmode_tstate *tstate;
+
+		info.buffer = buf;
+		info.length = sizeof(buf);
+		info.offset = 0;
+		info.pos = 0;
+		tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id,
+					    target, &tstate);
+
+		/*
+		 * Don't bother reporting results while
+		 * negotiations are still pending.
+		 */
+		if (tinfo->curr.period != tinfo->goal.period
+		 || tinfo->curr.width != tinfo->goal.width
+		 || tinfo->curr.offset != tinfo->goal.offset
+		 || tinfo->curr.ppr_options != tinfo->goal.ppr_options)
+			if (bootverbose == 0)
+				break;
+
+		/*
+		 * Don't bother reporting results that
+		 * are identical to those last reported.
+		 */
+		targ = ahd->platform_data->targets[target];
+		if (targ == NULL)
+			break;
+		if (tinfo->curr.period == targ->last_tinfo.period
+		 && tinfo->curr.width == targ->last_tinfo.width
+		 && tinfo->curr.offset == targ->last_tinfo.offset
+		 && tinfo->curr.ppr_options == targ->last_tinfo.ppr_options)
+			if (bootverbose == 0)
+				break;
+
+		targ->last_tinfo.period = tinfo->curr.period;
+		targ->last_tinfo.width = tinfo->curr.width;
+		targ->last_tinfo.offset = tinfo->curr.offset;
+		targ->last_tinfo.ppr_options = tinfo->curr.ppr_options;
+
+		printf("(%s:%c:", ahd_name(ahd), channel);
+		if (target == CAM_TARGET_WILDCARD)
+			printf("*): ");
+		else
+			printf("%d): ", target);
+		ahd_format_transinfo(&info, &tinfo->curr);
+		if (info.pos < info.length)
+			*info.buffer = '\0';
+		else
+			buf[info.length - 1] = '\0';
+		printf("%s", buf);
+		break;
+	}
+        case AC_SENT_BDR:
+		break;
+        case AC_BUS_RESET:
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+		if (ahd->platform_data->host != NULL) {
+			scsi_report_bus_reset(ahd->platform_data->host,
+					      channel - 'A');
+		}
+#endif
+                break;
+        default:
+                panic("ahd_send_async: Unexpected async event");
+        }
+}
+
+/*
+ * Calls the higher level scsi done function and frees the scb.
+ */
+void
+ahd_done(struct ahd_softc *ahd, struct scb * scb)
+{
+	Scsi_Cmnd *cmd;
+	struct	  ahd_linux_device *dev;
+
+	LIST_REMOVE(scb, pending_links);
+
+	if ((scb->flags & SCB_ACTIVE) == 0) {
+		printf("SCB %d done'd twice\n", scb->hscb->tag);
+		ahd_dump_card_state(ahd);
+		panic("Stopping for safety");
+	}
+	cmd = scb->io_ctx;
+	dev = scb->platform_data->dev;
+	dev->active--;
+	dev->openings++;
+	if ((cmd->result & (CAM_DEV_QFRZN << 16)) != 0) {
+		cmd->result &= ~(CAM_DEV_QFRZN << 16);
+		dev->qfrozen--;
+	}
+	ahd_linux_unmap_scb(ahd, scb);
+
+	/*
+	 * Guard against stale sense data.
+	 * The Linux mid-layer assumes that sense
+	 * was retrieved anytime the first byte of
+	 * the sense buffer looks "sane".
+	 */
+	cmd->sense_buffer[0] = 0;
+	if (ahd_get_transaction_status(scb) == CAM_REQ_INPROG) {
+		uint32_t amount_xferred;
+
+		amount_xferred =
+		    ahd_get_transfer_length(scb) - ahd_get_residual(scb);
+		if ((scb->flags & SCB_TRANSMISSION_ERROR) != 0) {
+#ifdef AHD_DEBUG
+			if ((ahd_debug & AHD_SHOW_MISC) != 0) {
+				ahd_print_path(ahd, scb);
+				printf("Set CAM_UNCOR_PARITY\n");
+			}
+#endif
+			ahd_set_transaction_status(scb, CAM_UNCOR_PARITY);
+		} else if (amount_xferred < scb->io_ctx->underflow) {
+			printf("Saw underflow (%ld of %ld bytes). "
+			       "Treated as error\n",
+				ahd_get_residual(scb),
+				ahd_get_transfer_length(scb));
+			ahd_set_transaction_status(scb, CAM_DATA_RUN_ERR);
+		} else {
+			ahd_set_transaction_status(scb, CAM_REQ_CMP);
+		}
+	} else if (ahd_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
+		ahd_linux_handle_scsi_status(ahd, dev, scb);
+	} else if (ahd_get_transaction_status(scb) == CAM_SEL_TIMEOUT) {
+		dev->flags |= AHD_DEV_UNCONFIGURED;
+		if (AHD_DV_CMD(cmd) == FALSE)
+			dev->target->flags &= ~AHD_DV_REQUIRED;
+	}
+	/*
+	 * Start DV for devices that require it assuming the first command
+	 * sent does not result in a selection timeout.
+	 */
+	if (ahd_get_transaction_status(scb) != CAM_SEL_TIMEOUT
+	 && (dev->target->flags & AHD_DV_REQUIRED) != 0)
+		ahd_linux_start_dv(ahd);
+
+	if (dev->openings == 1
+	 && ahd_get_transaction_status(scb) == CAM_REQ_CMP
+	 && ahd_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL)
+		dev->tag_success_count++;
+	/*
+	 * Some devices deal with temporary internal resource
+	 * shortages by returning queue full.  When the queue
+	 * full occurrs, we throttle back.  Slowly try to get
+	 * back to our previous queue depth.
+	 */
+	if ((dev->openings + dev->active) < dev->maxtags
+	 && dev->tag_success_count > AHD_TAG_SUCCESS_INTERVAL) {
+		dev->tag_success_count = 0;
+		dev->openings++;
+	}
+
+	if (dev->active == 0)
+		dev->commands_since_idle_or_otag = 0;
+
+	if (TAILQ_EMPTY(&dev->busyq)) {
+		if ((dev->flags & AHD_DEV_UNCONFIGURED) != 0
+		 && dev->active == 0)
+			ahd_linux_free_device(ahd, dev);
+	} else if ((dev->flags & AHD_DEV_ON_RUN_LIST) == 0) {
+		TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq, dev, links);
+		dev->flags |= AHD_DEV_ON_RUN_LIST;
+	}
+
+	if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
+		printf("Recovery SCB completes\n");
+		if (ahd_get_transaction_status(scb) == CAM_BDR_SENT
+		 || ahd_get_transaction_status(scb) == CAM_REQ_ABORTED)
+			ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT);
+		if ((scb->platform_data->flags & AHD_UP_EH_SEMAPHORE) != 0) {
+			scb->platform_data->flags &= ~AHD_UP_EH_SEMAPHORE;
+			up(&ahd->platform_data->eh_sem);
+		}
+	}
+
+	ahd_free_scb(ahd, scb);
+	ahd_linux_queue_cmd_complete(ahd, cmd);
+
+	if ((ahd->platform_data->flags & AHD_DV_WAIT_SIMQ_EMPTY) != 0
+	 && LIST_FIRST(&ahd->pending_scbs) == NULL) {
+		ahd->platform_data->flags &= ~AHD_DV_WAIT_SIMQ_EMPTY;
+		up(&ahd->platform_data->dv_sem);
+	}
+		
+}
+
+static void
+ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
+			     struct ahd_linux_device *dev, struct scb *scb)
+{
+	struct	ahd_devinfo devinfo;
+
+	ahd_compile_devinfo(&devinfo,
+			    ahd->our_id,
+			    dev->target->target, dev->lun,
+			    dev->target->channel == 0 ? 'A' : 'B',
+			    ROLE_INITIATOR);
+	
+	/*
+	 * We don't currently trust the mid-layer to
+	 * properly deal with queue full or busy.  So,
+	 * when one occurs, we tell the mid-layer to
+	 * unconditionally requeue the command to us
+	 * so that we can retry it ourselves.  We also
+	 * implement our own throttling mechanism so
+	 * we don't clobber the device with too many
+	 * commands.
+	 */
+	switch (ahd_get_scsi_status(scb)) {
+	default:
+		break;
+	case SCSI_STATUS_CHECK_COND:
+	case SCSI_STATUS_CMD_TERMINATED:
+	{
+		Scsi_Cmnd *cmd;
+
+		/*
+		 * Copy sense information to the OS's cmd
+		 * structure if it is available.
+		 */
+		cmd = scb->io_ctx;
+		if ((scb->flags & (SCB_SENSE|SCB_PKT_SENSE)) != 0) {
+			struct scsi_status_iu_header *siu;
+			u_int sense_size;
+			u_int sense_offset;
+
+			if (scb->flags & SCB_SENSE) {
+				sense_size = MIN(sizeof(struct scsi_sense_data)
+					       - ahd_get_sense_residual(scb),
+						 sizeof(cmd->sense_buffer));
+				sense_offset = 0;
+			} else {
+				/*
+				 * Copy only the sense data into the provided
+				 * buffer.
+				 */
+				siu = (struct scsi_status_iu_header *)
+				    scb->sense_data;
+				sense_size = MIN(scsi_4btoul(siu->sense_length),
+						sizeof(cmd->sense_buffer));
+				sense_offset = SIU_SENSE_OFFSET(siu);
+			}
+
+			memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
+			memcpy(cmd->sense_buffer,
+			       ahd_get_sense_buf(ahd, scb)
+			       + sense_offset, sense_size);
+			cmd->result |= (DRIVER_SENSE << 24);
+
+#ifdef AHD_DEBUG
+			if (ahd_debug & AHD_SHOW_SENSE) {
+				int i;
+
+				printf("Copied %d bytes of sense data at %d:",
+				       sense_size, sense_offset);
+				for (i = 0; i < sense_size; i++)
+					printf(" 0x%x", cmd->sense_buffer[i]);
+				printf("\n");
+			}
+#endif
+		}
+		break;
+	}
+	case SCSI_STATUS_QUEUE_FULL:
+	{
+		/*
+		 * By the time the core driver has returned this
+		 * command, all other commands that were queued
+		 * to us but not the device have been returned.
+		 * This ensures that dev->active is equal to
+		 * the number of commands actually queued to
+		 * the device.
+		 */
+		dev->tag_success_count = 0;
+		if (dev->active != 0) {
+			/*
+			 * Drop our opening count to the number
+			 * of commands currently outstanding.
+			 */
+			dev->openings = 0;
+#ifdef AHD_DEBUG
+			if (ahd_debug & AHD_SHOW_QFULL) {
+				ahd_print_path(ahd, scb);
+				printf("Dropping tag count to %d\n",
+				       dev->active);
+			}
+#endif
+			if (dev->active == dev->tags_on_last_queuefull) {
+
+				dev->last_queuefull_same_count++;
+				/*
+				 * If we repeatedly see a queue full
+				 * at the same queue depth, this
+				 * device has a fixed number of tag
+				 * slots.  Lock in this tag depth
+				 * so we stop seeing queue fulls from
+				 * this device.
+				 */
+				if (dev->last_queuefull_same_count
+				 == AHD_LOCK_TAGS_COUNT) {
+					dev->maxtags = dev->active;
+					ahd_print_path(ahd, scb);
+					printf("Locking max tag count at %d\n",
+					       dev->active);
+				}
+			} else {
+				dev->tags_on_last_queuefull = dev->active;
+				dev->last_queuefull_same_count = 0;
+			}
+			ahd_set_transaction_status(scb, CAM_REQUEUE_REQ);
+			ahd_set_scsi_status(scb, SCSI_STATUS_OK);
+			ahd_set_tags(ahd, &devinfo,
+				     (dev->flags & AHD_DEV_Q_BASIC)
+				   ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
+			break;
+		}
+		/*
+		 * Drop down to a single opening, and treat this
+		 * as if the target returned BUSY SCSI status.
+		 */
+		dev->openings = 1;
+		ahd_set_tags(ahd, &devinfo,
+			     (dev->flags & AHD_DEV_Q_BASIC)
+			   ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
+		ahd_set_scsi_status(scb, SCSI_STATUS_BUSY);
+		/* FALLTHROUGH */
+	}
+	case SCSI_STATUS_BUSY:
+		/*
+		 * Set a short timer to defer sending commands for
+		 * a bit since Linux will not delay in this case.
+		 */
+		if ((dev->flags & AHD_DEV_TIMER_ACTIVE) != 0) {
+			printf("%s:%c:%d: Device Timer still active during "
+			       "busy processing\n", ahd_name(ahd),
+				dev->target->channel, dev->target->target);
+			break;
+		}
+		dev->flags |= AHD_DEV_TIMER_ACTIVE;
+		dev->qfrozen++;
+		init_timer(&dev->timer);
+		dev->timer.data = (u_long)dev;
+		dev->timer.expires = jiffies + (HZ/2);
+		dev->timer.function = ahd_linux_dev_timed_unfreeze;
+		add_timer(&dev->timer);
+		break;
+	}
+}
+
+static void
+ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, Scsi_Cmnd *cmd)
+{
+	/*
+	 * Typically, the complete queue has very few entries
+	 * queued to it before the queue is emptied by
+	 * ahd_linux_run_complete_queue, so sorting the entries
+	 * by generation number should be inexpensive.
+	 * We perform the sort so that commands that complete
+	 * with an error are retuned in the order origionally
+	 * queued to the controller so that any subsequent retries
+	 * are performed in order.  The underlying ahd routines do
+	 * not guarantee the order that aborted commands will be
+	 * returned to us.
+	 */
+	struct ahd_completeq *completeq;
+	struct ahd_cmd *list_cmd;
+	struct ahd_cmd *acmd;
+
+	/*
+	 * Map CAM error codes into Linux Error codes.  We
+	 * avoid the conversion so that the DV code has the
+	 * full error information available when making
+	 * state change decisions.
+	 */
+	if (AHD_DV_CMD(cmd) == FALSE) {
+		uint32_t status;
+		u_int new_status;
+
+		status = ahd_cmd_get_transaction_status(cmd);
+		if (status != CAM_REQ_CMP) {
+			struct ahd_linux_device *dev;
+			struct ahd_devinfo devinfo;
+			uint32_t action;
+
+			dev = ahd_linux_get_device(ahd, cmd->channel,
+						   cmd->target, cmd->lun,
+						   /*alloc*/FALSE);
+
+			if (dev == NULL)
+				goto no_fallback;
+
+			ahd_compile_devinfo(&devinfo,
+					    ahd->our_id,
+					    dev->target->target, dev->lun,
+					    dev->target->channel == 0 ? 'A':'B',
+					    ROLE_INITIATOR);
+	
+			action = aic_error_action(cmd, dev->target->inq_data);
+			if ((action & SSQ_FALLBACK) != 0) {
+
+				/* Update stats */
+				dev->target->errors_detected++;
+				if (dev->target->cmds_since_error == 0)
+					dev->target->cmds_since_error++;
+				else {
+					dev->target->cmds_since_error = 0;
+					ahd_linux_fallback(ahd, &devinfo);
+				}
+			}
+		}
+no_fallback:
+		switch (status) {
+		case CAM_REQ_INPROG:
+		case CAM_REQ_CMP:
+		case CAM_SCSI_STATUS_ERROR:
+			new_status = DID_OK;
+			break;
+		case CAM_REQ_ABORTED:
+			new_status = DID_ABORT;
+			break;
+		case CAM_BUSY:
+			new_status = DID_BUS_BUSY;
+			break;
+		case CAM_REQ_INVALID:
+		case CAM_PATH_INVALID:
+			new_status = DID_BAD_TARGET;
+			break;
+		case CAM_SEL_TIMEOUT:
+			new_status = DID_NO_CONNECT;
+			break;
+		case CAM_SCSI_BUS_RESET:
+		case CAM_BDR_SENT:
+			new_status = DID_RESET;
+			break;
+		case CAM_UNCOR_PARITY:
+			new_status = DID_PARITY;
+			break;
+		case CAM_CMD_TIMEOUT:
+			new_status = DID_TIME_OUT;
+			break;
+		case CAM_UA_ABORT:
+		case CAM_REQ_CMP_ERR:
+		case CAM_AUTOSENSE_FAIL:
+		case CAM_NO_HBA:
+		case CAM_DATA_RUN_ERR:
+		case CAM_UNEXP_BUSFREE:
+		case CAM_SEQUENCE_FAIL:
+		case CAM_CCB_LEN_ERR:
+		case CAM_PROVIDE_FAIL:
+		case CAM_REQ_TERMIO:
+		case CAM_UNREC_HBA_ERROR:
+		case CAM_REQ_TOO_BIG:
+			new_status = DID_ERROR;
+			break;
+		case CAM_REQUEUE_REQ:
+			/*
+			 * If we want the request requeued, make sure there
+			 * are sufficent retries.  In the old scsi error code,
+			 * we used to be able to specify a result code that
+			 * bypassed the retry count.  Now we must use this
+			 * hack.  We also "fake" a check condition with
+			 * a sense code of ABORTED COMMAND.  This seems to
+			 * evoke a retry even if this command is being sent
+			 * via the eh thread.  Ick!  Ick!  Ick!
+			 */
+			cmd->retries--;
+			new_status = DID_OK;
+			ahd_cmd_set_scsi_status(cmd, SCSI_STATUS_CHECK_COND);
+			cmd->result |= (DRIVER_SENSE << 24);
+			memset(cmd->sense_buffer, 0,
+			       sizeof(cmd->sense_buffer));
+			cmd->sense_buffer[0] = SSD_ERRCODE_VALID
+					     | SSD_CURRENT_ERROR;
+			cmd->sense_buffer[2] = SSD_KEY_ABORTED_COMMAND;
+			break;
+		default:
+			/* We should never get here */
+			new_status = DID_ERROR;
+			break;
+		}
+
+		ahd_cmd_set_transaction_status(cmd, new_status);
+	}
+
+	completeq = &ahd->platform_data->completeq;
+	list_cmd = TAILQ_FIRST(completeq);
+	acmd = (struct ahd_cmd *)cmd;
+	while (list_cmd != NULL
+	    && acmd_scsi_cmd(list_cmd).serial_number
+	     < acmd_scsi_cmd(acmd).serial_number)
+		list_cmd = TAILQ_NEXT(list_cmd, acmd_links.tqe);
+	if (list_cmd != NULL)
+		TAILQ_INSERT_BEFORE(list_cmd, acmd, acmd_links.tqe);
+	else
+		TAILQ_INSERT_TAIL(completeq, acmd, acmd_links.tqe);
+}
+
+static void
+ahd_linux_filter_inquiry(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
+{
+	struct	scsi_inquiry_data *sid;
+	struct	ahd_initiator_tinfo *tinfo;
+	struct	ahd_transinfo *user;
+	struct	ahd_transinfo *goal;
+	struct	ahd_transinfo *curr;
+	struct	ahd_tmode_tstate *tstate;
+	struct	ahd_linux_device *dev;
+	u_int	width;
+	u_int	period;
+	u_int	offset;
+	u_int	ppr_options;
+	u_int	trans_version;
+	u_int	prot_version;
+	static	int warned_user;
+
+	/*
+	 * Determine if this lun actually exists.  If so,
+	 * hold on to its corresponding device structure.
+	 * If not, make sure we release the device and
+	 * don't bother processing the rest of this inquiry
+	 * command.
+	 */
+	dev = ahd_linux_get_device(ahd, devinfo->channel - 'A',
+				   devinfo->target, devinfo->lun,
+				   /*alloc*/TRUE);
+
+	sid = (struct scsi_inquiry_data *)dev->target->inq_data;
+	if (SID_QUAL(sid) == SID_QUAL_LU_CONNECTED) {
+
+		dev->flags &= ~AHD_DEV_UNCONFIGURED;
+	} else {
+		dev->flags |= AHD_DEV_UNCONFIGURED;
+		return;
+	}
+
+	/*
+	 * Update our notion of this device's transfer
+	 * negotiation capabilities.
+	 */
+	tinfo = ahd_fetch_transinfo(ahd, devinfo->channel,
+				    devinfo->our_scsiid,
+				    devinfo->target, &tstate);
+	user = &tinfo->user;
+	goal = &tinfo->goal;
+	curr = &tinfo->curr;
+	width = user->width;
+	period = user->period;
+	offset = user->offset;
+	ppr_options = user->ppr_options;
+	trans_version = user->transport_version;
+	prot_version = MIN(user->protocol_version, SID_ANSI_REV(sid));
+
+	/*
+	 * If we have read streaming info for this controller,
+	 * apply it to this target.
+	 */
+	if (warned_user == 0
+	 && ahd->unit >= NUM_ELEMENTS(aic79xx_rd_strm_info)) {
+
+		printf("aic79xx: WARNING, insufficient rd_strm instances "
+		       "for installed controllers. Using defaults\n");
+		printf("aic79xx: Please update the aic79xx_rd_strm_info "
+		       "array in the aic79xx_osm.c source file.\n");
+		warned_user++;
+	} else {
+		uint16_t rd_strm_mask;
+
+		rd_strm_mask = aic79xx_rd_strm_info[ahd->unit];
+		if ((rd_strm_mask & devinfo->target_mask) == 0)
+			ppr_options &= ~MSG_EXT_PPR_RD_STRM;
+	}
+	
+	/*
+	 * Only attempt SPI3/4 once we've verified that
+	 * the device claims to support SPI3/4 features.
+	 */
+	if (prot_version < SCSI_REV_2)
+		trans_version = SID_ANSI_REV(sid);
+	else
+		trans_version = SCSI_REV_2;
+
+	if ((sid->flags & SID_WBus16) == 0)
+		width = MSG_EXT_WDTR_BUS_8_BIT;
+	if ((sid->flags & SID_Sync) == 0) {
+		period = 0;
+		offset = 0;
+		ppr_options = 0;
+	}
+	if ((sid->spi3data & SID_SPI_QAS) == 0)
+		ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
+	if ((sid->spi3data & SID_SPI_CLOCK_DT) == 0)
+		ppr_options &= MSG_EXT_PPR_QAS_REQ;
+	if ((sid->spi3data & SID_SPI_IUS) == 0)
+		ppr_options &= (MSG_EXT_PPR_DT_REQ
+			      | MSG_EXT_PPR_QAS_REQ);
+
+	if (prot_version > SCSI_REV_2
+	 && ppr_options != 0)
+		trans_version = user->transport_version;
+
+	ahd_validate_width(ahd, /*tinfo limit*/NULL, &width, ROLE_UNKNOWN);
+	ahd_find_syncrate(ahd, &period, &ppr_options, AHD_SYNCRATE_MAX);
+	ahd_validate_offset(ahd, /*tinfo limit*/NULL, period,
+			    &offset, width, ROLE_UNKNOWN);
+	if (offset == 0 || period == 0) {
+		period = 0;
+		offset = 0;
+		ppr_options = 0;
+	}
+	/* Apply our filtered user settings. */
+	curr->transport_version = trans_version;
+	curr->protocol_version = prot_version;
+	ahd_set_width(ahd, devinfo, width, AHD_TRANS_GOAL, /*paused*/FALSE);
+	ahd_set_syncrate(ahd, devinfo, period, offset, ppr_options,
+			 AHD_TRANS_GOAL, /*paused*/FALSE);
+}
+
+void
+ahd_freeze_simq(struct ahd_softc *ahd)
+{
+	ahd->platform_data->qfrozen++;
+	if (ahd->platform_data->qfrozen == 1) {
+		scsi_block_requests(ahd->platform_data->host);
+		ahd_platform_abort_scbs(ahd, CAM_TARGET_WILDCARD, ALL_CHANNELS,
+					CAM_LUN_WILDCARD, SCB_LIST_NULL,
+					ROLE_INITIATOR, CAM_REQUEUE_REQ);
+	}
+}
+
+void
+ahd_release_simq(struct ahd_softc *ahd)
+{
+	u_long s;
+	int    unblock_reqs;
+
+	unblock_reqs = 0;
+	ahd_lock(ahd, &s);
+	if (ahd->platform_data->qfrozen > 0)
+		ahd->platform_data->qfrozen--;
+	if (ahd->platform_data->qfrozen == 0) {
+		unblock_reqs = 1;
+	}
+	if (AHD_DV_SIMQ_FROZEN(ahd)
+	 && ((ahd->platform_data->flags & AHD_DV_WAIT_SIMQ_RELEASE) != 0)) {
+		ahd->platform_data->flags &= ~AHD_DV_WAIT_SIMQ_RELEASE;
+		up(&ahd->platform_data->dv_sem);
+	}
+	ahd_unlock(ahd, &s);
+	/*
+	 * There is still a race here.  The mid-layer
+	 * should keep its own freeze count and use
+	 * a bottom half handler to run the queues
+	 * so we can unblock with our own lock held.
+	 */
+	if (unblock_reqs)
+		scsi_unblock_requests(ahd->platform_data->host);
+
+	ahd_schedule_runq(ahd);
+}
+
+#if NOT_YET
+static void
+ahd_linux_sem_timeout(u_long arg)
+{
+	struct	ahd_softc *ahd;
+	u_long	s;
+
+	ahd = (struct ahd_softc *)arg;
+	ahd_lock(ahd, &s);
+	if ((ahd->platform_data->flags & AHD_UP_EH_SEMAPHORE) != 0) {
+		ahd->platform_data->flags &= ~AHD_UP_EH_SEMAPHORE;
+		up(&ahd->platform_data->eh_sem);
+	}
+	ahd_unlock(ahd, &s);
+}
+
+static int
+ahd_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag)
+{
+	struct ahd_softc *ahd;
+	struct ahd_cmd *acmd;
+	struct ahd_cmd *list_acmd;
+	struct ahd_linux_device *dev;
+	struct scb *pending_scb;
+	u_long s;
+	u_int  saved_scbptr;
+	u_int  active_scb_index;
+	u_int  last_phase;
+	int    retval;
+	int    paused;
+	int    wait;
+	int    disconnected;
+
+	pending_scb = NULL;
+	paused = FALSE;
+	wait = FALSE;
+	ahd = *(struct ahd_softc **)cmd->host->hostdata;
+	acmd = (struct ahd_cmd *)cmd;
+
+	printf("%s:%d:%d:%d: Attempting to queue a%s message\n",
+	       ahd_name(ahd), cmd->channel, cmd->target, cmd->lun,
+	       flag == SCB_ABORT ? "n ABORT" : " TARGET RESET");
+
+	/*
+	 * In all versions of Linux, we have to work around
+	 * a major flaw in how the mid-layer is locked down
+	 * if we are to sleep successfully in our error handler
+	 * while allowing our interrupt handler to run.  Since
+	 * the midlayer acquires either the io_request_lock or
+	 * our lock prior to calling us, we must use the
+	 * spin_unlock_irq() method for unlocking our lock.
+	 * This will force interrupts to be enabled on the
+	 * current CPU.  Since the EH thread should not have
+	 * been running with CPU interrupts disabled other than
+	 * by acquiring either the io_request_lock or our own
+	 * lock, this *should* be safe.
+	 */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	spin_unlock_irq(&io_request_lock);
+#endif
+	ahd_midlayer_entrypoint_lock(ahd, &s);
+
+	/*
+	 * First determine if we currently own this command.
+	 * Start by searching the device queue.  If not found
+	 * there, check the pending_scb list.  If not found
+	 * at all, and the system wanted us to just abort the
+	 * command return success.
+	 */
+	dev = ahd_linux_get_device(ahd, cmd->channel, cmd->target,
+				   cmd->lun, /*alloc*/FALSE);
+
+	if (dev == NULL) {
+		/*
+		 * No target device for this command exists,
+		 * so we must not still own the command.
+		 */
+		printf("%s:%d:%d:%d: Is not an active device\n",
+		       ahd_name(ahd), cmd->channel, cmd->target, cmd->lun);
+		retval = SUCCESS;
+		goto no_cmd;
+	}
+
+	TAILQ_FOREACH(list_acmd, &dev->busyq, acmd_links.tqe) {
+		if (list_acmd == acmd)
+			break;
+	}
+
+	if (list_acmd != NULL) {
+		printf("%s:%d:%d:%d: Command found on device queue\n",
+		       ahd_name(ahd), cmd->channel, cmd->target, cmd->lun);
+		if (flag == SCB_ABORT) {
+			TAILQ_REMOVE(&dev->busyq, list_acmd, acmd_links.tqe);
+			cmd->result = DID_ABORT << 16;
+			ahd_linux_queue_cmd_complete(ahd, cmd);
+			retval = SUCCESS;
+			goto done;
+		}
+	}
+
+	/*
+	 * See if we can find a matching cmd in the pending list.
+	 */
+	LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
+		if (pending_scb->io_ctx == cmd)
+			break;
+	}
+
+	if (pending_scb == NULL && flag == SCB_DEVICE_RESET) {
+
+		/* Any SCB for this device will do for a target reset */
+		LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
+		  	if (ahd_match_scb(ahd, pending_scb, cmd->target,
+					  cmd->channel, CAM_LUN_WILDCARD,
+					  SCB_LIST_NULL, ROLE_INITIATOR) == 0)
+				break;
+		}
+	}
+
+	if (pending_scb == NULL) {
+		printf("%s:%d:%d:%d: Command not found\n",
+		       ahd_name(ahd), cmd->channel, cmd->target, cmd->lun);
+		goto no_cmd;
+	}
+
+	if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) {
+		/*
+		 * We can't queue two recovery actions using the same SCB
+		 */
+		retval = FAILED;
+		goto  done;
+	}
+
+	/*
+	 * Ensure that the card doesn't do anything
+	 * behind our back.  Also make sure that we
+	 * didn't "just" miss an interrupt that would
+	 * affect this cmd.
+	 */
+	ahd->flags |= AHD_ALL_INTERRUPTS;
+	do {
+		ahd_intr(ahd);
+		ahd_pause(ahd);
+		ahd_clear_critical_section(ahd);
+	} while (ahd_inb(ahd, INTSTAT) & INT_PEND);
+	ahd->flags &= ~AHD_ALL_INTERRUPTS;
+	paused = TRUE;
+
+	ahd_dump_card_state(ahd);
+
+	if ((pending_scb->flags & SCB_ACTIVE) == 0) {
+		printf("%s:%d:%d:%d: Command already completed\n",
+		       ahd_name(ahd), cmd->channel, cmd->target, cmd->lun);
+		goto no_cmd;
+	}
+
+	disconnected = TRUE;
+	if (flag == SCB_ABORT) {
+		if (ahd_search_qinfifo(ahd, cmd->target, cmd->channel + 'A',
+				       cmd->lun, pending_scb->hscb->tag,
+				       ROLE_INITIATOR, CAM_REQ_ABORTED,
+				       SEARCH_COMPLETE) > 0) {
+			printf("%s:%d:%d:%d: Cmd aborted from QINFIFO\n",
+			       ahd_name(ahd), cmd->channel, cmd->target,
+					cmd->lun);
+			retval = SUCCESS;
+			goto done;
+		}
+	} else if (ahd_search_qinfifo(ahd, cmd->target, cmd->channel + 'A',
+				      cmd->lun, pending_scb->hscb->tag,
+				      ROLE_INITIATOR, /*status*/0,
+				      SEARCH_COUNT) > 0) {
+		disconnected = FALSE;
+	}
+
+	/*
+	 * At this point, pending_scb is the scb associated with the
+	 * passed in command.  That command is currently active on the
+	 * bus, is in the disconnected state, or we're hoping to find
+	 * a command for the same target active on the bus to abuse to
+	 * send a BDR.  Queue the appropriate message based on which of
+	 * these states we are in.
+	 */
+	last_phase = ahd_inb(ahd, LASTPHASE);
+	saved_scbptr = ahd_inb(ahd, SCBPTR);
+	active_scb_index = ahd_inb(ahd, SCB_TAG);
+	if (last_phase != P_BUSFREE
+	 && (pending_scb->hscb->tag == active_scb_index
+	  || (flag == SCB_DEVICE_RESET
+	   && SCSIID_TARGET(ahd, ahd_inb(ahd, SAVED_SCSIID)) == cmd->target))) {
+
+		/*
+		 * We're active on the bus, so assert ATN
+		 * and hope that the target responds.
+		 */
+		pending_scb = ahd_lookup_scb(ahd, active_scb_index);
+		pending_scb->flags |= SCB_RECOVERY_SCB|flag;
+		ahd_outb(ahd, MSG_OUT, HOST_MSG);
+		ahd_outb(ahd, SCSISIGO, last_phase|ATNO);
+		printf("%s:%d:%d:%d: Device is active, asserting ATN\n",
+		       ahd_name(ahd), cmd->channel, cmd->target, cmd->lun);
+		wait = TRUE;
+	} else if (disconnected) {
+
+		/*
+		 * Actually re-queue this SCB in an attempt
+		 * to select the device before it reconnects.
+		 * In either case (selection or reselection),
+		 * we will now issue the approprate message
+		 * to the timed-out device.
+		 *
+		 * Set the MK_MESSAGE control bit indicating
+		 * that we desire to send a message.  We
+		 * also set the disconnected flag since
+		 * in the paging case there is no guarantee
+		 * that our SCB control byte matches the
+		 * version on the card.  We don't want the
+		 * sequencer to abort the command thinking
+		 * an unsolicited reselection occurred.
+		 */
+		pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
+		pending_scb->flags |= SCB_RECOVERY_SCB|flag;
+
+		/*
+		 * In the non-paging case, the sequencer will
+		 * never re-reference the in-core SCB.
+		 * To make sure we are notified during
+		 * reslection, set the MK_MESSAGE flag in
+		 * the card's copy of the SCB.
+		 */
+		ahd_outb(ahd, SCBPTR, pending_scb->hscb->tag);
+		ahd_outb(ahd, SCB_CONTROL,
+			 ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE);
+
+		/*
+		 * Clear out any entries in the QINFIFO first
+		 * so we are the next SCB for this target
+		 * to run.
+		 */
+		ahd_search_qinfifo(ahd, cmd->target, cmd->channel + 'A',
+				   cmd->lun, SCB_LIST_NULL, ROLE_INITIATOR,
+				   CAM_REQUEUE_REQ, SEARCH_COMPLETE);
+		ahd_print_path(ahd, pending_scb);
+		printf("Queuing a recovery SCB\n");
+		ahd_qinfifo_requeue_tail(ahd, pending_scb);
+		ahd_outb(ahd, SCBPTR, saved_scbptr);
+		printf("%s:%d:%d:%d: Device is disconnected, re-queuing SCB\n",
+		       ahd_name(ahd), cmd->channel, cmd->target, cmd->lun);
+		wait = TRUE;
+	} else {
+		printf("%s:%d:%d:%d: Unable to deliver message\n",
+		       ahd_name(ahd), cmd->channel, cmd->target, cmd->lun);
+		retval = FAILED;
+		goto done;
+	}
+
+no_cmd:
+	/*
+	 * Our assumption is that if we don't have the command, no
+	 * recovery action was required, so we return success.  Again,
+	 * the semantics of the mid-layer recovery engine are not
+	 * well defined, so this may change in time.
+	 */
+	retval = SUCCESS;
+done:
+	if (paused)
+		ahd_unpause(ahd);
+	if (wait) {
+		struct timer_list timer;
+		int ret;
+
+		pending_scb->platform_data->flags |= AHD_UP_EH_SEMAPHORE;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+		ahd_unlock(ahd, &s);
+#else
+		spin_unlock_irq(ahd->platform_data->host->host_lock);
+#endif
+		init_timer(&timer);
+		timer.data = (u_long)ahd;
+		timer.expires = jiffies + (5 * HZ);
+		timer.function = ahd_linux_sem_timeout;
+		add_timer(&timer);
+		printf("Recovery code sleeping\n");
+		down(&ahd->platform_data->eh_sem);
+		printf("Recovery code awake\n");
+        	ret = del_timer(&timer);
+		if (ret == 0) {
+			printf("Timer Expired\n");
+			retval = FAILED;
+		}
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+		ahd_lock(ahd, &s);
+#else
+		spin_lock_irq(ahd->platform_data->host->host_lock);
+#endif
+	}
+	acmd = TAILQ_FIRST(&ahd->platform_data->completeq);
+	TAILQ_INIT(&ahd->platform_data->completeq);
+	ahd_midlayer_entry_unlock(ahd, &s);
+	if (acmd != NULL) {
+		acmd = ahd_linux_run_complete_queue(ahd, acmd);
+		if (acmd != NULL) {
+			ahd_midlayer_entrypoint_lock(ahd, &s);
+			ahd_schedule_completeq(ahd, acmd);
+			ahd_midlayer_entrypoint_unlock(ahd, &s);
+		}
+	}
+	ahd_schedule_runq(ahd);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	spin_lock_irq(&io_request_lock);
+#endif
+	return (retval);
+}
+#endif
+
+static void
+ahd_linux_dev_timed_unfreeze(u_long arg)
+{
+	struct ahd_linux_device *dev;
+	struct ahd_softc *ahd;
+	u_long s;
+
+	dev = (struct ahd_linux_device *)arg;
+	ahd = dev->target->ahd;
+	ahd_lock(ahd, &s);
+	dev->flags &= ~AHD_DEV_TIMER_ACTIVE;
+	if (dev->qfrozen > 0)
+		dev->qfrozen--;
+	if (dev->qfrozen == 0
+	 && (dev->flags & AHD_DEV_ON_RUN_LIST) == 0)
+		ahd_linux_run_device_queue(ahd, dev);
+	ahd_unlock(ahd, &s);
+}
+
+void
+ahd_platform_dump_card_state(struct ahd_softc *ahd)
+{
+	struct ahd_linux_device *dev;
+	int target;
+	int maxtarget;
+	int lun;
+	int i;
+
+	maxtarget = (ahd->features & AHD_WIDE) ? 15 : 7;
+	for (target = 0; target <=maxtarget; target++) {
+
+		for (lun = 0; lun < AHD_NUM_LUNS; lun++) {
+			struct ahd_cmd *acmd;
+
+			dev = ahd_linux_get_device(ahd, 0, target,
+						   lun, /*alloc*/FALSE);
+			if (dev == NULL)
+				continue;
+
+			printf("DevQ(%d:%d:%d): ", 0, target, lun);
+			i = 0;
+			TAILQ_FOREACH(acmd, &dev->busyq, acmd_links.tqe) {
+				if (i++ > AHD_SCB_MAX)
+					break;
+			}
+			printf("%d waiting\n", i);
+		}
+	}
+}
diff -Nru a/drivers/scsi/aic7xxx/aic79xx_osm.h b/drivers/scsi/aic7xxx/aic79xx_osm.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.h	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,1281 @@
+/*
+ * Adaptec AIC79xx device driver for Linux.
+ *
+ * Copyright (c) 2000-2001 Adaptec Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_osm.h#96 $
+ *
+ */
+#ifndef _AIC79XX_LINUX_H_
+#define _AIC79XX_LINUX_H_
+
+#include <linux/types.h>
+#include <linux/blk.h>
+#include <linux/blkdev.h>
+#include <linux/delay.h>
+#include <linux/ioport.h>
+#include <linux/pci.h>
+#include <linux/version.h>
+#ifndef AHD_MODVERSION_FILE
+#define __NO_VERSION__
+#endif
+#include <linux/module.h>
+#include <asm/byteorder.h>
+
+#ifndef KERNEL_VERSION
+#define KERNEL_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
+#endif
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+#include <linux/interrupt.h> /* For tasklet support. */
+#include <linux/config.h>
+#include <linux/slab.h>
+#else
+#include <linux/malloc.h>
+#endif
+
+/* Core SCSI definitions */
+#define AIC_LIB_PREFIX ahd
+#include "scsi.h"
+#include "hosts.h"
+#include "aiclib.h"
+
+/* Name space conflict with BSD queue macros */
+#ifdef LIST_HEAD
+#undef LIST_HEAD
+#endif
+
+#include "cam.h"
+#include "queue.h"
+#include "scsi_message.h"
+#include "scsi_iu.h"
+
+/*********************************** Debugging ********************************/
+#ifdef CONFIG_AIC79XX_DEBUG_ENABLE
+#ifdef CONFIG_AIC79XX_DEBUG_MASK
+#define AHD_DEBUG 1
+#define AHD_DEBUG_OPTS CONFIG_AIC79XX_DEBUG_MASK
+#else
+/*
+ * Compile in debugging code, but do not enable any printfs.
+ */
+#define AHD_DEBUG 1
+#endif
+/* No debugging code. */
+#endif
+
+/********************************** Misc Macros *******************************/
+#define	roundup(x, y)   ((((x)+((y)-1))/(y))*(y))
+#define	powerof2(x)	((((x)-1)&(x))==0)
+
+/************************* Forward Declarations *******************************/
+struct ahd_softc;
+typedef struct pci_dev *ahd_dev_softc_t;
+typedef Scsi_Cmnd      *ahd_io_ctx_t;
+
+/******************************* Byte Order ***********************************/
+#define ahd_htobe16(x)	cpu_to_be16(x)
+#define ahd_htobe32(x)	cpu_to_be32(x)
+#define ahd_htobe64(x)	cpu_to_be64(x)
+#define ahd_htole16(x)	cpu_to_le16(x)
+#define ahd_htole32(x)	cpu_to_le32(x)
+#define ahd_htole64(x)	cpu_to_le64(x)
+
+#define ahd_be16toh(x)	be16_to_cpu(x)
+#define ahd_be32toh(x)	be32_to_cpu(x)
+#define ahd_be64toh(x)	be64_to_cpu(x)
+#define ahd_le16toh(x)	le16_to_cpu(x)
+#define ahd_le32toh(x)	le32_to_cpu(x)
+#define ahd_le64toh(x)	le64_to_cpu(x)
+
+#ifndef LITTLE_ENDIAN
+#define LITTLE_ENDIAN 1234
+#endif
+
+#ifndef BIG_ENDIAN
+#define BIG_ENDIAN 4321
+#endif
+
+#ifndef BYTE_ORDER
+#if defined(__BIG_ENDIAN)
+#define BYTE_ORDER BIG_ENDIAN
+#endif
+#if defined(__LITTLE_ENDIAN)
+#define BYTE_ORDER LITTLE_ENDIAN
+#endif
+#endif /* BYTE_ORDER */
+
+/************************* Configuration Data *********************************/
+extern int aic79xx_allow_memio;
+extern int aic79xx_detect_complete;
+extern Scsi_Host_Template aic79xx_driver_template;
+
+/***************************** Bus Space/DMA **********************************/
+
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,2,17)
+typedef dma_addr_t bus_addr_t;
+#else
+typedef uint32_t bus_addr_t;
+#endif
+typedef uint32_t bus_size_t;
+
+typedef enum {
+	BUS_SPACE_MEMIO,
+	BUS_SPACE_PIO
+} bus_space_tag_t;
+
+typedef union {
+	u_long		  ioport;
+	volatile uint8_t *maddr;
+} bus_space_handle_t;
+
+typedef struct bus_dma_segment
+{
+	bus_addr_t	ds_addr;
+	bus_size_t	ds_len;
+} bus_dma_segment_t;
+
+struct ahd_linux_dma_tag
+{
+	bus_size_t	alignment;
+	bus_size_t	boundary;
+	bus_size_t	maxsize;
+};
+typedef struct ahd_linux_dma_tag* bus_dma_tag_t;
+
+struct ahd_linux_dmamap
+{
+	bus_addr_t	bus_addr;
+};
+typedef struct ahd_linux_dmamap* bus_dmamap_t;
+
+typedef int bus_dma_filter_t(void*, bus_addr_t);
+typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
+
+#define BUS_DMA_WAITOK		0x0
+#define BUS_DMA_NOWAIT		0x1
+#define BUS_DMA_ALLOCNOW	0x2
+#define BUS_DMA_LOAD_SEGS	0x4	/*
+					 * Argument is an S/G list not
+					 * a single buffer.
+					 */
+
+#define BUS_SPACE_MAXADDR	0xFFFFFFFF
+#define BUS_SPACE_MAXADDR_32BIT	0xFFFFFFFF
+#define BUS_SPACE_MAXSIZE_32BIT	0xFFFFFFFF
+
+int	ahd_dma_tag_create(struct ahd_softc *, bus_dma_tag_t /*parent*/,
+			   bus_size_t /*alignment*/, bus_size_t /*boundary*/,
+			   bus_addr_t /*lowaddr*/, bus_addr_t /*highaddr*/,
+			   bus_dma_filter_t*/*filter*/, void */*filterarg*/,
+			   bus_size_t /*maxsize*/, int /*nsegments*/,
+			   bus_size_t /*maxsegsz*/, int /*flags*/,
+			   bus_dma_tag_t */*dma_tagp*/);
+
+void	ahd_dma_tag_destroy(struct ahd_softc *, bus_dma_tag_t /*tag*/);
+
+int	ahd_dmamem_alloc(struct ahd_softc *, bus_dma_tag_t /*dmat*/,
+			 void** /*vaddr*/, int /*flags*/,
+			 bus_dmamap_t* /*mapp*/);
+
+void	ahd_dmamem_free(struct ahd_softc *, bus_dma_tag_t /*dmat*/,
+			void* /*vaddr*/, bus_dmamap_t /*map*/);
+
+void	ahd_dmamap_destroy(struct ahd_softc *, bus_dma_tag_t /*tag*/,
+			   bus_dmamap_t /*map*/);
+
+int	ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t /*dmat*/,
+			bus_dmamap_t /*map*/, void * /*buf*/,
+			bus_size_t /*buflen*/, bus_dmamap_callback_t *,
+			void */*callback_arg*/, int /*flags*/);
+
+int	ahd_dmamap_unload(struct ahd_softc *, bus_dma_tag_t, bus_dmamap_t);
+
+/*
+ * Operations performed by ahd_dmamap_sync().
+ */
+#define BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
+#define BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
+#define BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
+#define BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
+
+/*
+ * XXX
+ * ahd_dmamap_sync is only used on buffers allocated with
+ * the pci_alloc_consistent() API.  Although I'm not sure how
+ * this works on architectures with a write buffer, Linux does
+ * not have an API to sync "coherent" memory.  Perhaps we need
+ * to do an mb()?
+ */
+#define ahd_dmamap_sync(ahd, dma_tag, dmamap, offset, len, op)
+
+/************************** Timer DataStructures ******************************/
+typedef struct timer_list ahd_timer_t;
+
+/********************************** Includes **********************************/
+#if CONFIG_AIC79XX_REG_PRETTY_PRINT
+#define AIC_DEBUG_REGISTERS 1
+#else
+#define AIC_DEBUG_REGISTERS 0
+#endif
+#include "aic79xx.h"
+
+/***************************** Timer Facilities *******************************/
+#define ahd_timer_init init_timer
+#define ahd_timer_stop del_timer
+typedef void ahd_linux_callback_t (u_long);  
+static __inline void ahd_timer_reset(ahd_timer_t *timer, u_int usec,
+				     ahd_callback_t *func, void *arg);
+static __inline void ahd_scb_timer_reset(struct scb *scb, u_int usec);
+
+static __inline void
+ahd_timer_reset(ahd_timer_t *timer, u_int usec, ahd_callback_t *func, void *arg)
+{
+	struct ahd_softc *ahd;
+
+	ahd = (struct ahd_softc *)arg;
+	del_timer(timer);
+	timer->data = (u_long)arg;
+	timer->expires = jiffies + (usec * HZ)/1000000;
+	timer->function = (ahd_linux_callback_t*)func;
+	add_timer(timer);
+}
+
+static __inline void
+ahd_scb_timer_reset(struct scb *scb, u_int usec)
+{
+	mod_timer(&scb->io_ctx->eh_timeout, jiffies + (usec * HZ)/1000000);
+}
+
+/***************************** SMP support ************************************/
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,17)
+#include <linux/spinlock.h>
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,93)
+#include <linux/smp.h>
+#endif
+
+#define AIC79XX_DRIVER_VERSION "1.3.0.ALPHA5"
+
+/**************************** Front End Queues ********************************/
+/*
+ * Data structure used to cast the Linux struct scsi_cmnd to something
+ * that allows us to use the queue macros.  The linux structure has
+ * plenty of space to hold the links fields as required by the queue
+ * macros, but the queue macors require them to have the correct type.
+ */
+struct ahd_cmd_internal {
+	/* Area owned by the Linux scsi layer. */
+	uint8_t	private[offsetof(struct scsi_cmnd, SCp.Status)];
+	union {
+		STAILQ_ENTRY(ahd_cmd)	ste;
+		LIST_ENTRY(ahd_cmd)	le;
+		TAILQ_ENTRY(ahd_cmd)	tqe;
+	} links;
+	uint32_t			end;
+};
+
+struct ahd_cmd {
+	union {
+		struct ahd_cmd_internal	icmd;
+		struct scsi_cmnd	scsi_cmd;
+	} un;
+};
+
+#define acmd_icmd(cmd) ((cmd)->un.icmd)
+#define acmd_scsi_cmd(cmd) ((cmd)->un.scsi_cmd)
+#define acmd_links un.icmd.links
+
+/*************************** Device Data Structures ***************************/
+/*
+ * A per probed device structure used to deal with some error recovery
+ * scenarios that the Linux mid-layer code just doesn't know how to
+ * handle.  The structure allocated for a device only becomes persistant
+ * after a successfully completed inquiry command to the target when
+ * that inquiry data indicates a lun is present.
+ */
+TAILQ_HEAD(ahd_busyq, ahd_cmd);
+typedef enum {
+	AHD_DEV_UNCONFIGURED	 = 0x01,
+	AHD_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */
+	AHD_DEV_TIMER_ACTIVE	 = 0x04, /* Our timer is active */
+	AHD_DEV_ON_RUN_LIST	 = 0x08, /* Queued to be run later */
+	AHD_DEV_Q_BASIC		 = 0x10, /* Allow basic device queuing */
+	AHD_DEV_Q_TAGGED	 = 0x20, /* Allow full SCSI2 command queueing */
+	AHD_DEV_PERIODIC_OTAG	 = 0x40, /* Send OTAG to prevent starvation */
+	AHD_DEV_SLAVE_CONFIGURED = 0x80	 /* slave_configure() has been called */
+} ahd_linux_dev_flags;
+
+struct ahd_linux_target;
+struct ahd_linux_device {
+	TAILQ_ENTRY(ahd_linux_device) links;
+	struct			ahd_busyq busyq;
+
+	/*
+	 * The number of transactions currently
+	 * queued to the device.
+	 */
+	int			active;
+
+	/*
+	 * The currently allowed number of 
+	 * transactions that can be queued to
+	 * the device.  Must be signed for
+	 * conversion from tagged to untagged
+	 * mode where the device may have more
+	 * than one outstanding active transaction.
+	 */
+	int			openings;
+
+	/*
+	 * A positive count indicates that this
+	 * device's queue is halted.
+	 */
+	u_int			qfrozen;
+	
+	/*
+	 * Cumulative command counter.
+	 */
+	u_long			commands_issued;
+
+	/*
+	 * The number of tagged transactions when
+	 * running at our current opening level
+	 * that have been successfully received by
+	 * this device since the last QUEUE FULL.
+	 */
+	u_int			tag_success_count;
+#define AHD_TAG_SUCCESS_INTERVAL 50
+
+	ahd_linux_dev_flags	flags;
+
+	/*
+	 * Per device timer.
+	 */
+	struct timer_list	timer;
+
+	/*
+	 * The high limit for the tags variable.
+	 */
+	u_int			maxtags;
+
+	/*
+	 * The computed number of tags outstanding
+	 * at the time of the last QUEUE FULL event.
+	 */
+	u_int			tags_on_last_queuefull;
+
+	/*
+	 * How many times we have seen a queue full
+	 * with the same number of tags.  This is used
+	 * to stop our adaptive queue depth algorithm
+	 * on devices with a fixed number of tags.
+	 */
+	u_int			last_queuefull_same_count;
+#define AHD_LOCK_TAGS_COUNT 50
+
+	/*
+	 * How many transactions have been queued
+	 * without the device going idle.  We use
+	 * this statistic to determine when to issue
+	 * an ordered tag to prevent transaction
+	 * starvation.  This statistic is only updated
+	 * if the AHD_DEV_PERIODIC_OTAG flag is set
+	 * on this device.
+	 */
+	u_int			commands_since_idle_or_otag;
+#define AHD_OTAG_THRESH	500
+
+	int			lun;
+	Scsi_Device	       *scsi_device;
+	struct			ahd_linux_target *target;
+};
+
+typedef enum {
+	AHD_DV_REQUIRED		 = 0x01
+} ahd_linux_targ_flags;
+
+/* DV States */
+typedef enum {
+	AHD_DV_STATE_EXIT = 0,
+	AHD_DV_STATE_INQ_SHORT_ASYNC,
+	AHD_DV_STATE_TUR,
+	AHD_DV_STATE_INQ_ASYNC,
+	AHD_DV_STATE_INQ_ASYNC_VERIFY,
+	AHD_DV_STATE_REBD,
+	AHD_DV_STATE_INQ_VERIFY,
+	AHD_DV_STATE_WEB,
+	AHD_DV_STATE_REB,
+	AHD_DV_STATE_SU,
+	AHD_DV_STATE_BUSY
+} ahd_dv_state;
+
+struct ahd_linux_target {
+	struct ahd_linux_device	 *devices[AHD_NUM_LUNS];
+	int			  channel;
+	int			  target;
+	int			  refcount;
+	struct ahd_transinfo	  last_tinfo;
+	struct ahd_softc	 *ahd;
+	ahd_linux_targ_flags	  flags;
+	struct scsi_inquiry_data *inq_data;
+	/*
+	 * The next "fallback" period to use for narrow/wide transfers.
+	 */
+	u_int			  dv_next_narrow_period;
+	u_int			  dv_next_wide_period;
+	u_int			  dv_max_ppr_options;
+	u_int			  dv_last_ppr_options;
+	u_int			  dv_echo_size;
+	ahd_dv_state		  dv_state;
+	u_int			  dv_state_retry;
+	uint8_t			 *dv_buffer;
+	uint8_t			 *dv_buffer1;
+
+	/*
+	 * Cumulative counter of errors.
+	 */
+	u_long			errors_detected;
+	u_long			cmds_since_error;
+};
+
+/********************* Definitions Required by the Core ***********************/
+/*
+ * Number of SG segments we require.  So long as the S/G segments for
+ * a particular transaction are allocated in a physically contiguous
+ * manner and are allocated below 4GB, the number of S/G segments is
+ * unrestricted.
+ */
+#define        AHD_NSEG 128
+
+/*
+ * Per-SCB OSM storage.
+ */
+typedef enum {
+	AHD_UP_EH_SEMAPHORE
+} ahd_linux_scb_flags;
+
+struct scb_platform_data {
+	struct ahd_linux_device	*dev;
+	bus_addr_t		 buf_busaddr;
+	uint32_t		 xfer_len;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
+	uint32_t		 resid;		/* Transfer residual */
+#endif
+	uint32_t		 sense_resid;	/* Auto-Sense residual */
+	ahd_linux_scb_flags	 flags;
+};
+
+/*
+ * Define a structure used for each host adapter.  All members are
+ * aligned on a boundary >= the size of the member to honor the
+ * alignment restrictions of the various platforms supported by
+ * this driver.
+ */
+typedef enum {
+	AHD_DV_WAIT_SIMQ_EMPTY	 = 0x01,
+	AHD_DV_WAIT_SIMQ_RELEASE = 0x02,
+	AHD_DV_ACTIVE		 = 0x04,
+	AHD_DV_SHUTDOWN		 = 0x08,
+	AHD_RUN_CMPLT_Q_TIMER	 = 0x10
+} ahd_linux_softc_flags;
+
+TAILQ_HEAD(ahd_completeq, ahd_cmd);
+
+struct ahd_platform_data {
+	/*
+	 * Fields accessed from interrupt context.
+	 */
+	struct ahd_linux_target *targets[AHD_NUM_TARGETS]; 
+	TAILQ_HEAD(, ahd_linux_device) device_runq;
+	struct ahd_completeq	 completeq;
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,93)
+	spinlock_t		 spin_lock;
+#endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+	struct tasklet_struct	 runq_tasklet;
+#endif
+	u_int			 qfrozen;
+	pid_t			 dv_pid;
+	struct timer_list	 completeq_timer;
+	struct timer_list	 reset_timer;
+	struct timer_list	 stats_timer;
+	struct semaphore	 eh_sem;
+	struct semaphore	 dv_sem;
+	struct semaphore	 dv_cmd_sem;	/* XXX This needs to be in
+						 * the target struct
+						 */
+	struct Scsi_Host        *host;		/* pointer to scsi host */
+#define AHD_LINUX_NOIRQ	((uint32_t)~0)
+	uint32_t		 irq;		/* IRQ for this adapter */
+	uint32_t		 bios_address;
+	uint32_t		 mem_busaddr;	/* Mem Base Addr */
+	bus_addr_t		 hw_dma_mask;
+	ahd_linux_softc_flags	 flags;
+};
+
+/************************** OS Utility Wrappers *******************************/
+#define printf printk
+#define M_NOWAIT GFP_ATOMIC
+#define M_WAITOK 0
+#define malloc(size, type, flags) kmalloc(size, flags)
+#define free(ptr, type) kfree(ptr)
+
+static __inline void ahd_delay(long);
+static __inline void
+ahd_delay(long usec)
+{
+	/*
+	 * udelay on Linux can have problems for
+	 * multi-millisecond waits.  Wait at most
+	 * 1024us per call.
+	 */
+	while (usec > 0) {
+		udelay(usec % 1024);
+		usec -= 1024;
+	}
+}
+
+
+/***************************** Low Level I/O **********************************/
+#if defined(__powerpc__) || defined(__i386__) || defined(__ia64__)
+#define MMAPIO
+#endif
+
+static __inline uint8_t ahd_inb(struct ahd_softc * ahd, long port);
+static __inline uint16_t ahd_inw_atomic(struct ahd_softc * ahd, long port);
+static __inline void ahd_outb(struct ahd_softc * ahd, long port, uint8_t val);
+static __inline void ahd_outw_atomic(struct ahd_softc * ahd,
+				     long port, uint16_t val);
+static __inline void ahd_outsb(struct ahd_softc * ahd, long port,
+			       uint8_t *, int count);
+static __inline void ahd_insb(struct ahd_softc * ahd, long port,
+			       uint8_t *, int count);
+
+static __inline uint8_t
+ahd_inb(struct ahd_softc * ahd, long port)
+{
+	uint8_t x;
+#ifdef MMAPIO
+
+	if (ahd->tags[0] == BUS_SPACE_MEMIO) {
+		x = readb(ahd->bshs[0].maddr + port);
+	} else {
+		x = inb(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
+	}
+#else
+	x = inb(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
+#endif
+	mb();
+	return (x);
+}
+
+static __inline uint16_t
+ahd_inw_atomic(struct ahd_softc * ahd, long port)
+{
+	uint8_t x;
+#ifdef MMAPIO
+
+	if (ahd->tags[0] == BUS_SPACE_MEMIO) {
+		x = readw(ahd->bshs[0].maddr + port);
+	} else {
+		x = inw(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
+	}
+#else
+	x = inw(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
+#endif
+	mb();
+	return (x);
+}
+
+static __inline void
+ahd_outb(struct ahd_softc * ahd, long port, uint8_t val)
+{
+#ifdef MMAPIO
+	if (ahd->tags[0] == BUS_SPACE_MEMIO) {
+		writeb(val, ahd->bshs[0].maddr + port);
+	} else {
+		outb(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
+	}
+#else
+	outb(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
+#endif
+	mb();
+}
+
+static __inline void
+ahd_outw_atomic(struct ahd_softc * ahd, long port, uint16_t val)
+{
+#ifdef MMAPIO
+	if (ahd->tags[0] == BUS_SPACE_MEMIO) {
+		writew(val, ahd->bshs[0].maddr + port);
+	} else {
+		outw(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
+	}
+#else
+	outw(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
+#endif
+	mb();
+}
+
+static __inline void
+ahd_outsb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
+{
+	int i;
+
+	/*
+	 * There is probably a more efficient way to do this on Linux
+	 * but we don't use this for anything speed critical and this
+	 * should work.
+	 */
+	for (i = 0; i < count; i++)
+		ahd_outb(ahd, port, *array++);
+}
+
+static __inline void
+ahd_insb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
+{
+	int i;
+
+	/*
+	 * There is probably a more efficient way to do this on Linux
+	 * but we don't use this for anything speed critical and this
+	 * should work.
+	 */
+	for (i = 0; i < count; i++)
+		*array++ = ahd_inb(ahd, port);
+}
+
+/**************************** Initialization **********************************/
+int		ahd_linux_register_host(struct ahd_softc *,
+					Scsi_Host_Template *);
+
+uint64_t	ahd_linux_get_memsize(void);
+
+/*************************** Pretty Printing **********************************/
+struct info_str {
+	char *buffer;
+	int length;
+	off_t offset;
+	int pos;
+};
+
+void	ahd_format_transinfo(struct info_str *info,
+			     struct ahd_transinfo *tinfo);
+
+/******************************** Locking *************************************/
+/* Lock protecting internal data structures */
+static __inline void ahd_lockinit(struct ahd_softc *);
+static __inline void ahd_lock(struct ahd_softc *, unsigned long *flags);
+static __inline void ahd_unlock(struct ahd_softc *, unsigned long *flags);
+
+/* Lock acquisition and release of the above lock in midlayer entry points. */
+static __inline void ahd_midlayer_entrypoint_lock(struct ahd_softc *,
+						  unsigned long *flags);
+static __inline void ahd_midlayer_entrypoint_unlock(struct ahd_softc *,
+						    unsigned long *flags);
+
+/* Lock held during command compeletion to the upper layer */
+static __inline void ahd_done_lockinit(struct ahd_softc *);
+static __inline void ahd_done_lock(struct ahd_softc *, unsigned long *flags);
+static __inline void ahd_done_unlock(struct ahd_softc *, unsigned long *flags);
+
+/* Lock held during ahd_list manipulation and ahd softc frees */
+extern spinlock_t ahd_list_spinlock;
+static __inline void ahd_list_lockinit(void);
+static __inline void ahd_list_lock(unsigned long *flags);
+static __inline void ahd_list_unlock(unsigned long *flags);
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,93)
+static __inline void
+ahd_lockinit(struct ahd_softc *ahd)
+{
+	spin_lock_init(&ahd->platform_data->spin_lock);
+}
+
+static __inline void
+ahd_lock(struct ahd_softc *ahd, unsigned long *flags)
+{
+	*flags = 0;
+	spin_lock_irqsave(&ahd->platform_data->spin_lock, *flags);
+}
+
+static __inline void
+ahd_unlock(struct ahd_softc *ahd, unsigned long *flags)
+{
+	spin_unlock_irqrestore(&ahd->platform_data->spin_lock, *flags);
+}
+
+static __inline void
+ahd_midlayer_entrypoint_lock(struct ahd_softc *ahd, unsigned long *flags)
+{
+	/*
+	 * In 2.5.X, the midlayer takes our lock just before
+	 * calling us, so avoid locking again.
+	 */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	ahd_lock(ahd, flags);
+#endif
+}
+
+static __inline void
+ahd_midlayer_entrypoint_unlock(struct ahd_softc *ahd, unsigned long *flags)
+{
+	/*
+	 * In 2.5.X, the midlayer takes our lock just before
+	 * calling us and unlocks when we return, so let it do the unlock.
+	 */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	ahd_unlock(ahd, flags);
+#endif
+}
+
+static __inline void
+ahd_done_lockinit(struct ahd_softc *ahd)
+{
+	/*
+	 * In 2.5.X, our own lock is held during completions.
+	 * In previous versions, the io_request_lock is used.
+	 * In either case, we can't initialize this lock again.
+	 */
+}
+
+static __inline void
+ahd_done_lock(struct ahd_softc *ahd, unsigned long *flags)
+{
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	*flags = 0;
+	spin_lock_irqsave(&io_request_lock, *flags);
+#endif
+}
+
+static __inline void
+ahd_done_unlock(struct ahd_softc *ahd, unsigned long *flags)
+{
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	spin_unlock_irqrestore(&io_request_lock, *flags);
+#endif
+}
+
+static __inline void
+ahd_list_lockinit()
+{
+	spin_lock_init(&ahd_list_spinlock);
+}
+
+static __inline void
+ahd_list_lock(unsigned long *flags)
+{
+	*flags = 0;
+	spin_lock_irqsave(&ahd_list_spinlock, *flags);
+}
+
+static __inline void
+ahd_list_unlock(unsigned long *flags)
+{
+	spin_unlock_irqrestore(&ahd_list_spinlock, *flags);
+}
+
+#else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0) */
+
+ahd_lockinit(struct ahd_softc *ahd)
+{
+}
+
+static __inline void
+ahd_lock(struct ahd_softc *ahd, unsigned long *flags)
+{
+	*flags = 0;
+	save_flags(*flags);
+	cli();
+}
+
+static __inline void
+ahd_unlock(struct ahd_softc *ahd, unsigned long *flags)
+{
+	restore_flags(*flags);
+}
+
+ahd_done_lockinit(struct ahd_softc *ahd)
+{
+}
+
+static __inline void
+ahd_done_lock(struct ahd_softc *ahd, unsigned long *flags)
+{
+	/*
+	 * The done lock is always held while
+	 * the ahd lock is held so blocking
+	 * interrupts again would have no effect.
+	 */
+}
+
+static __inline void
+ahd_done_unlock(struct ahd_softc *ahd, unsigned long *flags)
+{
+}
+
+static __inline void
+ahd_list_lockinit()
+{
+}
+
+static __inline void
+ahd_list_lock(unsigned long *flags)
+{
+	*flags = 0;
+	save_flags(*flags);
+	cli();
+}
+
+static __inline void
+ahd_list_unlock(unsigned long *flags)
+{
+	restore_flags(*flags);
+}
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0) */
+
+/******************************* PCI Definitions ******************************/
+/*
+ * PCIM_xxx: mask to locate subfield in register
+ * PCIR_xxx: config register offset
+ * PCIC_xxx: device class
+ * PCIS_xxx: device subclass
+ * PCIP_xxx: device programming interface
+ * PCIV_xxx: PCI vendor ID (only required to fixup ancient devices)
+ * PCID_xxx: device ID
+ */
+#define PCIR_DEVVENDOR		0x00
+#define PCIR_VENDOR		0x00
+#define PCIR_DEVICE		0x02
+#define PCIR_COMMAND		0x04
+#define PCIM_CMD_PORTEN		0x0001
+#define PCIM_CMD_MEMEN		0x0002
+#define PCIM_CMD_BUSMASTEREN	0x0004
+#define PCIM_CMD_MWRICEN	0x0010
+#define PCIM_CMD_PERRESPEN	0x0040
+#define	PCIM_CMD_SERRESPEN	0x0100
+#define PCIR_STATUS		0x06
+#define PCIR_REVID		0x08
+#define PCIR_PROGIF		0x09
+#define PCIR_SUBCLASS		0x0a
+#define PCIR_CLASS		0x0b
+#define PCIR_CACHELNSZ		0x0c
+#define PCIR_LATTIMER		0x0d
+#define PCIR_HEADERTYPE		0x0e
+#define PCIM_MFDEV		0x80
+#define PCIR_BIST		0x0f
+#define PCIR_CAP_PTR		0x34
+
+/* config registers for header type 0 devices */
+#define PCIR_MAPS	0x10
+#define PCIR_SUBVEND_0	0x2c
+#define PCIR_SUBDEV_0	0x2e
+
+/****************************** PCI-X definitions *****************************/
+#define PCIXR_COMMAND	0x96
+#define PCIXR_DEVADDR	0x98
+#define PCIXM_DEVADDR_FNUM	0x0003	/* Function Number */
+#define PCIXM_DEVADDR_DNUM	0x00F8	/* Device Number */
+#define PCIXM_DEVADDR_BNUM	0xFF00	/* Bus Number */
+#define PCIXR_STATUS	0x9A
+#define PCIXM_STATUS_64BIT	0x0001	/* Active 64bit connection to device. */
+#define PCIXM_STATUS_133CAP	0x0002	/* Device is 133MHz capable */
+#define PCIXM_STATUS_SCDISC	0x0004	/* Split Completion Discarded */
+#define PCIXM_STATUS_UNEXPSC	0x0008	/* Unexpected Split Completion */
+#define PCIXM_STATUS_CMPLEXDEV	0x0010	/* Device Complexity (set == bridge) */
+#define PCIXM_STATUS_MAXMRDBC	0x0060	/* Maximum Burst Read Count */
+#define PCIXM_STATUS_MAXSPLITS	0x0380	/* Maximum Split Transactions */
+#define PCIXM_STATUS_MAXCRDS	0x1C00	/* Maximum Cumulative Read Size */
+#define PCIXM_STATUS_RCVDSCEM	0x2000	/* Received a Split Comp w/Error msg */
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+extern struct pci_driver aic79xx_pci_driver;
+#endif
+
+typedef enum
+{
+	AHD_POWER_STATE_D0,
+	AHD_POWER_STATE_D1,
+	AHD_POWER_STATE_D2,
+	AHD_POWER_STATE_D3
+} ahd_power_state;
+
+void ahd_power_state_change(struct ahd_softc *ahd,
+			    ahd_power_state new_state);
+
+/******************************* PCI Routines *********************************/
+/*
+ * We need to use the bios32.h routines if we are kernel version 2.1.92 or less.
+ */
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,1,92)
+#if defined(__sparc_v9__) || defined(__powerpc__)
+#error "PPC and Sparc platforms are only support under 2.1.92 and above"
+#endif
+#include <linux/bios32.h>
+#endif
+
+int			 ahd_linux_pci_probe(Scsi_Host_Template *);
+int			 ahd_pci_map_registers(struct ahd_softc *ahd);
+int			 ahd_pci_map_int(struct ahd_softc *ahd);
+
+static __inline uint32_t ahd_pci_read_config(ahd_dev_softc_t pci,
+					     int reg, int width);
+
+static __inline uint32_t
+ahd_pci_read_config(ahd_dev_softc_t pci, int reg, int width)
+{
+	switch (width) {
+	case 1:
+	{
+		uint8_t retval;
+
+		pci_read_config_byte(pci, reg, &retval);
+		return (retval);
+	}
+	case 2:
+	{
+		uint16_t retval;
+		pci_read_config_word(pci, reg, &retval);
+		return (retval);
+	}
+	case 4:
+	{
+		uint32_t retval;
+		pci_read_config_dword(pci, reg, &retval);
+		return (retval);
+	}
+	default:
+		panic("ahd_pci_read_config: Read size too big");
+		/* NOTREACHED */
+		return (0);
+	}
+}
+
+static __inline void ahd_pci_write_config(ahd_dev_softc_t pci,
+					  int reg, uint32_t value,
+					  int width);
+
+static __inline void
+ahd_pci_write_config(ahd_dev_softc_t pci, int reg, uint32_t value, int width)
+{
+	switch (width) {
+	case 1:
+		pci_write_config_byte(pci, reg, value);
+		break;
+	case 2:
+		pci_write_config_word(pci, reg, value);
+		break;
+	case 4:
+		pci_write_config_dword(pci, reg, value);
+		break;
+	default:
+		panic("ahd_pci_write_config: Write size too big");
+		/* NOTREACHED */
+	}
+}
+
+static __inline int ahd_get_pci_function(ahd_dev_softc_t);
+static __inline int
+ahd_get_pci_function(ahd_dev_softc_t pci)
+{
+	return (PCI_FUNC(pci->devfn));
+}
+
+static __inline int ahd_get_pci_slot(ahd_dev_softc_t);
+static __inline int
+ahd_get_pci_slot(ahd_dev_softc_t pci)
+{
+	return (PCI_SLOT(pci->devfn));
+}
+
+static __inline int ahd_get_pci_bus(ahd_dev_softc_t);
+static __inline int
+ahd_get_pci_bus(ahd_dev_softc_t pci)
+{
+	return (pci->bus->number);
+}
+
+static __inline void ahd_flush_device_writes(struct ahd_softc *);
+static __inline void
+ahd_flush_device_writes(struct ahd_softc *ahd)
+{
+	/* XXX Is this sufficient for all architectures??? */
+	ahd_inb(ahd, INTSTAT);
+}
+
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,0)
+#define pci_map_sg(pdev, sg_list, nseg, direction) (nseg)
+#define pci_unmap_sg(pdev, sg_list, nseg, direction)
+#define sg_dma_address(sg) (VIRT_TO_BUS((sg)->address))
+#define sg_dma_len(sg) ((sg)->length)
+#define pci_map_single(pdev, buffer, bufflen, direction) \
+	(VIRT_TO_BUS(buffer))
+#define pci_unmap_single(pdev, buffer, buflen, direction)
+#endif
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,3)
+#define ahd_pci_set_dma_mask pci_set_dma_mask
+#else
+/*
+ * Always "return" 0 for success.
+ */
+#define ahd_pci_set_dma_mask(dev_softc, mask)	\
+	(((dev_softc)->dma_mask = mask) && 0)
+#endif
+/**************************** Proc FS Support *********************************/
+int	ahd_linux_proc_info(char *, char **, off_t, int, int, int);
+
+/*************************** Domain Validation ********************************/
+#define AHD_DV_CMD(cmd) ((cmd)->scsi_done == ahd_linux_dv_complete)
+#define AHD_DV_SIMQ_FROZEN(ahd)					\
+	((((ahd)->platform_data->flags & AHD_DV_ACTIVE) != 0)	\
+	 && (ahd)->platform_data->qfrozen == 1)
+
+/*********************** Transaction Access Wrappers **************************/
+static __inline void ahd_cmd_set_transaction_status(Scsi_Cmnd *, uint32_t);
+static __inline void ahd_set_transaction_status(struct scb *, uint32_t);
+static __inline void ahd_cmd_set_scsi_status(Scsi_Cmnd *, uint32_t);
+static __inline void ahd_set_scsi_status(struct scb *, uint32_t);
+static __inline uint32_t ahd_cmd_get_transaction_status(Scsi_Cmnd *cmd);
+static __inline uint32_t ahd_get_transaction_status(struct scb *);
+static __inline uint32_t ahd_cmd_get_scsi_status(Scsi_Cmnd *cmd);
+static __inline uint32_t ahd_get_scsi_status(struct scb *);
+static __inline void ahd_set_transaction_tag(struct scb *, int, u_int);
+static __inline u_long ahd_get_transfer_length(struct scb *);
+static __inline int ahd_get_transfer_dir(struct scb *);
+static __inline void ahd_set_residual(struct scb *, u_long);
+static __inline void ahd_set_sense_residual(struct scb *scb, u_long resid);
+static __inline u_long ahd_get_residual(struct scb *);
+static __inline u_long ahd_get_sense_residual(struct scb *);
+static __inline int ahd_perform_autosense(struct scb *);
+static __inline uint32_t ahd_get_sense_bufsize(struct ahd_softc *,
+					       struct scb *);
+static __inline void ahd_notify_xfer_settings_change(struct ahd_softc *,
+						     struct ahd_devinfo *);
+static __inline void ahd_platform_scb_free(struct ahd_softc *ahd,
+					   struct scb *scb);
+static __inline void ahd_freeze_scb(struct scb *scb);
+
+static __inline
+void ahd_cmd_set_transaction_status(Scsi_Cmnd *cmd, uint32_t status)
+{
+	cmd->result &= ~(CAM_STATUS_MASK << 16);
+	cmd->result |= status << 16;
+}
+
+static __inline
+void ahd_set_transaction_status(struct scb *scb, uint32_t status)
+{
+	ahd_cmd_set_transaction_status(scb->io_ctx,status);
+}
+
+static __inline
+void ahd_cmd_set_scsi_status(Scsi_Cmnd *cmd, uint32_t status)
+{
+	cmd->result &= ~0xFFFF;
+	cmd->result |= status;
+}
+
+static __inline
+void ahd_set_scsi_status(struct scb *scb, uint32_t status)
+{
+	ahd_cmd_set_scsi_status(scb->io_ctx, status);
+}
+
+static __inline
+uint32_t ahd_cmd_get_transaction_status(Scsi_Cmnd *cmd)
+{
+	return ((cmd->result >> 16) & CAM_STATUS_MASK);
+}
+
+static __inline
+uint32_t ahd_get_transaction_status(struct scb *scb)
+{
+	return (ahd_cmd_get_transaction_status(scb->io_ctx));
+}
+
+static __inline
+uint32_t ahd_cmd_get_scsi_status(Scsi_Cmnd *cmd)
+{
+	return (cmd->result & 0xFFFF);
+}
+
+static __inline
+uint32_t ahd_get_scsi_status(struct scb *scb)
+{
+	return (ahd_cmd_get_scsi_status(scb->io_ctx));
+}
+
+static __inline
+void ahd_set_transaction_tag(struct scb *scb, int enabled, u_int type)
+{
+	/*
+	 * Nothing to do for linux as the incoming transaction
+	 * has no concept of tag/non tagged, etc.
+	 */
+}
+
+static __inline
+u_long ahd_get_transfer_length(struct scb *scb)
+{
+	return (scb->platform_data->xfer_len);
+}
+
+static __inline
+int ahd_get_transfer_dir(struct scb *scb)
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,40)
+	return (scb->io_ctx->sc_data_direction);
+#else
+	if (scb->io_ctx->bufflen == 0)
+		return (CAM_DIR_NONE);
+
+	switch(scb->io_ctx->cmnd[0]) {
+	case 0x08:  /* READ(6)  */
+	case 0x28:  /* READ(10) */
+	case 0xA8:  /* READ(12) */
+		return (CAM_DIR_IN);
+        case 0x0A:  /* WRITE(6)  */
+        case 0x2A:  /* WRITE(10) */
+        case 0xAA:  /* WRITE(12) */
+		return (CAM_DIR_OUT);
+        default:
+		return (CAM_DIR_NONE);
+        }
+#endif
+}
+
+static __inline
+void ahd_set_residual(struct scb *scb, u_long resid)
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+	scb->io_ctx->resid = resid;
+#else
+	scb->platform_data->resid = resid;
+#endif
+}
+
+static __inline
+void ahd_set_sense_residual(struct scb *scb, u_long resid)
+{
+	scb->platform_data->sense_resid = resid;
+}
+
+static __inline
+u_long ahd_get_residual(struct scb *scb)
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+	return (scb->io_ctx->resid);
+#else
+	return (scb->platform_data->resid);
+#endif
+}
+
+static __inline
+u_long ahd_get_sense_residual(struct scb *scb)
+{
+	return (scb->platform_data->sense_resid);
+}
+
+static __inline
+int ahd_perform_autosense(struct scb *scb)
+{
+	/*
+	 * We always perform autosense in Linux.
+	 * On other platforms this is set on a
+	 * per-transaction basis.
+	 */
+	return (1);
+}
+
+static __inline uint32_t
+ahd_get_sense_bufsize(struct ahd_softc *ahd, struct scb *scb)
+{
+	return (sizeof(struct scsi_sense_data));
+}
+
+static __inline void
+ahd_notify_xfer_settings_change(struct ahd_softc *ahd,
+				struct ahd_devinfo *devinfo)
+{
+	/* Nothing to do here for linux */
+}
+
+static __inline void
+ahd_platform_scb_free(struct ahd_softc *ahd, struct scb *scb)
+{
+	ahd->flags &= ~AHD_RESOURCE_SHORTAGE;
+}
+
+int	ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg);
+void	ahd_platform_free(struct ahd_softc *ahd);
+void	ahd_platform_init(struct ahd_softc *ahd);
+void	ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb);
+void	ahd_freeze_simq(struct ahd_softc *ahd);
+void	ahd_release_simq(struct ahd_softc *ahd);
+
+static __inline void
+ahd_freeze_scb(struct scb *scb)
+{
+	if ((scb->io_ctx->result & (CAM_DEV_QFRZN << 16)) == 0) {
+                scb->io_ctx->result |= CAM_DEV_QFRZN << 16;
+                scb->platform_data->dev->qfrozen++;
+        }
+}
+
+void	ahd_platform_set_tags(struct ahd_softc *ahd,
+			      struct ahd_devinfo *devinfo, ahd_queue_alg);
+int	ahd_platform_abort_scbs(struct ahd_softc *ahd, int target,
+				char channel, int lun, u_int tag,
+				role_t role, uint32_t status);
+void	ahd_linux_isr(int irq, void *dev_id, struct pt_regs * regs);
+void	ahd_platform_flushwork(struct ahd_softc *ahd);
+int	ahd_softc_comp(struct ahd_softc *, struct ahd_softc *);
+void	ahd_done(struct ahd_softc*, struct scb*);
+void	ahd_send_async(struct ahd_softc *, char channel,
+		       u_int target, u_int lun, ac_code, void *);
+void	ahd_print_path(struct ahd_softc *, struct scb *);
+void	ahd_platform_dump_card_state(struct ahd_softc *ahd);
+
+#ifdef CONFIG_PCI
+#define AHD_PCI_CONFIG 1
+#else
+#define AHD_PCI_CONFIG 0
+#endif
+#define bootverbose aic79xx_verbose
+extern int aic79xx_verbose;
+#endif /* _AIC79XX_LINUX_H_ */
diff -Nru a/drivers/scsi/aic7xxx/aic79xx_osm_pci.c b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,431 @@
+/*
+ * Linux driver attachment glue for PCI based U320 controllers.
+ *
+ * Copyright (c) 2000-2001 Adaptec Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_osm_pci.c#18 $
+ */
+
+#include "aic79xx_osm.h"
+#include "aic79xx_inline.h"
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
+struct pci_device_id
+{
+};
+#endif
+
+static int	ahd_linux_pci_dev_probe(struct pci_dev *pdev,
+					const struct pci_device_id *ent);
+static int	ahd_linux_pci_reserve_io_regions(struct ahd_softc *ahd,
+						 u_long *base, u_long *base2);
+static int	ahd_linux_pci_reserve_mem_region(struct ahd_softc *ahd,
+						 u_long *bus_addr,
+						 uint8_t **maddr);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+static void	ahd_linux_pci_dev_remove(struct pci_dev *pdev);
+
+/* We do our own ID filtering.  So, grab all SCSI storage class devices. */
+static struct pci_device_id ahd_linux_pci_id_table[] = {
+	{
+		0x9005, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
+		PCI_CLASS_STORAGE_SCSI << 8, 0xFFFF00, 0
+	},
+	{ 0 }
+};
+
+MODULE_DEVICE_TABLE(pci, ahd_linux_pci_id_table);
+
+struct pci_driver aic79xx_pci_driver = {
+	name:		"aic79xx",
+	probe:		ahd_linux_pci_dev_probe,
+	remove:		ahd_linux_pci_dev_remove,
+	id_table:	ahd_linux_pci_id_table
+};
+
+static void
+ahd_linux_pci_dev_remove(struct pci_dev *pdev)
+{
+	struct ahd_softc *ahd;
+	u_long l;
+
+	/*
+	 * We should be able to just perform
+	 * the free directly, but check our
+	 * list for extra sanity.
+	 */
+	ahd_list_lock(&l);
+	ahd = ahd_find_softc((struct ahd_softc *)pci_get_drvdata(pdev));
+	if (ahd != NULL) {
+		u_long s;
+
+		ahd_lock(ahd, &s);
+		ahd_intr_enable(ahd, FALSE);
+		ahd_unlock(ahd, &s);
+		ahd_free(ahd);
+	}
+	ahd_list_unlock(&l);
+}
+#endif /* !LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) */
+
+static int
+ahd_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
+{
+	char		 buf[80];
+	struct		 ahd_softc *ahd;
+	ahd_dev_softc_t	 pci;
+	struct		 ahd_pci_identity *entry;
+	char		*name;
+	int		 error;
+
+	/*
+	 * Some BIOSen report the same device multiple times.
+	 */
+	TAILQ_FOREACH(ahd, &ahd_tailq, links) {
+		struct pci_dev *probed_pdev;
+
+		probed_pdev = ahd->dev_softc;
+		if (probed_pdev->bus->number == pdev->bus->number
+		 && probed_pdev->devfn == pdev->devfn)
+			break;
+	}
+	if (ahd != NULL) {
+		/* Skip duplicate. */
+		return (-ENODEV);
+	}
+
+	pci = pdev;
+	entry = ahd_find_pci_device(pci);
+	if (entry == NULL)
+		return (-ENODEV);
+
+	/*
+	 * Allocate a softc for this card and
+	 * set it up for attachment by our
+	 * common detect routine.
+	 */
+	sprintf(buf, "ahd_pci:%d:%d:%d",
+		ahd_get_pci_bus(pci),
+		ahd_get_pci_slot(pci),
+		ahd_get_pci_function(pci));
+	name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
+	if (name == NULL)
+		return (-ENOMEM);
+	strcpy(name, buf);
+	ahd = ahd_alloc(NULL, name);
+	if (ahd == NULL)
+		return (-ENOMEM);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+	if (pci_enable_device(pdev)) {
+		ahd_free(ahd);
+		return (-ENODEV);
+	}
+	pci_set_master(pdev);
+
+	if (sizeof(bus_addr_t) > 4) {
+		uint64_t memsize;
+
+		memsize = ahd_linux_get_memsize();
+		if (memsize >= 0x8000000000
+	 	 && ahd_pci_set_dma_mask(pdev, 0xFFFFFFFFFFFFFFFFULL) == 0) {
+			ahd->flags |= AHD_64BIT_ADDRESSING;
+			ahd->platform_data->hw_dma_mask =
+			    (bus_addr_t)(0xFFFFFFFFFFFFFFFFULL&(bus_addr_t)~0);
+		} else if (memsize > 0x80000000
+			&& ahd_pci_set_dma_mask(pdev, 0x7FFFFFFFFFULL) == 0) {
+			ahd->flags |= AHD_39BIT_ADDRESSING;
+			ahd->platform_data->hw_dma_mask =
+			    (bus_addr_t)(0x7FFFFFFFFFULL & (bus_addr_t)~0);
+		}
+	}
+#endif
+	ahd->dev_softc = pci;
+	error = ahd_pci_config(ahd, entry);
+	if (error != 0) {
+		ahd_free(ahd);
+		return (-error);
+	}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+	pci_set_drvdata(pdev, ahd);
+	if (aic79xx_detect_complete)
+		ahd_linux_register_host(ahd, &aic79xx_driver_template);
+#endif
+	return (0);
+}
+
+int
+ahd_linux_pci_probe(Scsi_Host_Template *template)
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+	return (pci_module_init(&aic79xx_pci_driver));
+#else
+	struct pci_dev *pdev;
+	u_int class;
+	int found;
+
+	/* If we don't have a PCI bus, we can't find any adapters. */
+	if (pci_present() == 0)
+		return (0);
+
+	found = 0;
+	pdev = NULL;
+	class = PCI_CLASS_STORAGE_SCSI << 8;
+	while ((pdev = pci_find_class(class, pdev)) != NULL) {
+		ahd_dev_softc_t pci;
+		int error;
+
+		pci = pdev;
+		error = ahd_linux_pci_dev_probe(pdev, /*pci_devid*/NULL);
+		if (error == 0)
+			found++;
+	}
+	return (found);
+#endif
+}
+
+static int
+ahd_linux_pci_reserve_io_regions(struct ahd_softc *ahd, u_long *base,
+				 u_long *base2)
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+	*base = pci_resource_start(ahd->dev_softc, 0);
+	/*
+	 * This is really the 3rd bar and should be at index 2,
+	 * but the Linux PCI code doesn't know how to "count" 64bit
+	 * bars.
+	 */
+	*base2 = pci_resource_start(ahd->dev_softc, 3);
+#else
+	*base = ahd_pci_read_config(ahd->dev_softc, AHD_PCI_IOADDR0, 4);
+	*base2 = ahd_pci_read_config(ahd->dev_softc, AHD_PCI_IOADDR1, 4);
+	*base &= PCI_BASE_ADDRESS_IO_MASK;
+	*base2 &= PCI_BASE_ADDRESS_IO_MASK;
+#endif
+	if (*base == 0 || *base2 == 0)
+		return (ENOMEM);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
+	if (check_region(*base, 256) != 0
+	 || check_region(*base2, 256) != 0)
+		return (ENOMEM);
+	else {
+		request_region(*base, 256, "aic79xx");
+		request_region(*base2, 256, "aic79xx");
+	}
+#else
+	if (request_region(*base, 256, "aic79xx") == 0)
+		return (ENOMEM);
+	if (request_region(*base2, 256, "aic79xx") == 0) {
+		release_region(*base2, 256);
+		return (ENOMEM);
+	}
+#endif
+	return (0);
+}
+
+static int
+ahd_linux_pci_reserve_mem_region(struct ahd_softc *ahd,
+				 u_long *bus_addr,
+				 uint8_t **maddr)
+{
+	u_long	start;
+	u_long	base_page;
+	u_long	base_offset;
+	int	error;
+
+	if (aic79xx_allow_memio == 0)
+		return (ENOMEM);
+
+	if ((ahd->bugs & AHD_PCIX_MMAPIO_BUG) != 0)
+		return (ENOMEM);
+
+	error = 0;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+	start = pci_resource_start(ahd->dev_softc, 1);
+	base_page = start & PAGE_MASK;
+	base_offset = start - base_page;
+#else
+	start = ahd_pci_read_config(ahd->dev_softc, PCIR_MAPS+4, 4);
+	base_offset = start & PCI_BASE_ADDRESS_MEM_MASK;
+	base_page = base_offset & PAGE_MASK;
+	base_offset -= base_page;
+#endif
+	if (start != 0) {
+		*bus_addr = start;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+		if (request_mem_region(start, 0x1000, "aic79xx") == 0)
+			error = ENOMEM;
+#endif
+		if (error == 0) {
+			*maddr = ioremap_nocache(base_page, base_offset + 256);
+			if (*maddr == NULL) {
+				error = ENOMEM;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+				release_mem_region(start, 0x1000);
+#endif
+			} else
+				*maddr += base_offset;
+		}
+	} else
+		error = ENOMEM;
+	return (error);
+}
+
+int
+ahd_pci_map_registers(struct ahd_softc *ahd)
+{
+	uint32_t command;
+	u_long	 base;
+	uint8_t	*maddr;
+	int	 error;
+
+	/*
+	 * If its allowed, we prefer memory mapped access.
+	 */
+	command = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, 4);
+	command &= ~(PCIM_CMD_PORTEN|PCIM_CMD_MEMEN);
+	base = 0;
+	maddr = NULL;
+#ifdef MMAPIO
+	error = ahd_linux_pci_reserve_mem_region(ahd, &base, &maddr);
+	if (error == 0) {
+		ahd->platform_data->mem_busaddr = base;
+		ahd->tags[0] = BUS_SPACE_MEMIO;
+		ahd->bshs[0].maddr = maddr;
+		ahd->tags[1] = BUS_SPACE_MEMIO;
+		ahd->bshs[1].maddr = maddr + 0x100;
+		ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
+				     command | PCIM_CMD_MEMEN, 4);
+
+		if (ahd_pci_test_register_access(ahd) != 0) {
+
+			printf("aic79xx: PCI Device %d:%d:%d "
+			       "failed memory mapped test.  Using PIO.\n",
+			       ahd_get_pci_bus(ahd->dev_softc),
+			       ahd_get_pci_slot(ahd->dev_softc),
+			       ahd_get_pci_function(ahd->dev_softc));
+			iounmap((void *)((u_long)maddr & PAGE_MASK));
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+			release_mem_region(ahd->platform_data->mem_busaddr,
+					   0x1000);
+#endif
+			ahd->bshs[0].maddr = NULL;
+			maddr = NULL;
+		} else
+			command |= PCIM_CMD_MEMEN;
+	} else if (bootverbose) {
+		printf("aic79xx: PCI%d:%d:%d MEM region 0x%lx "
+		       "unavailable. Cannot memory map device.\n",
+		       ahd_get_pci_bus(ahd->dev_softc),
+		       ahd_get_pci_slot(ahd->dev_softc),
+		       ahd_get_pci_function(ahd->dev_softc),
+		       base);
+	}
+#endif
+
+	if (maddr == NULL) {
+		u_long	 base2;
+
+		error = ahd_linux_pci_reserve_io_regions(ahd, &base, &base2);
+		if (error == 0) {
+			ahd->tags[0] = BUS_SPACE_PIO;
+			ahd->tags[1] = BUS_SPACE_PIO;
+			ahd->bshs[0].ioport = base;
+			ahd->bshs[1].ioport = base2;
+			command |= PCIM_CMD_PORTEN;
+		} else {
+			printf("aic79xx: PCI%d:%d:%d IO regions 0x%lx and 0x%lx"
+			       "unavailable. Cannot map device.\n",
+			       ahd_get_pci_bus(ahd->dev_softc),
+			       ahd_get_pci_slot(ahd->dev_softc),
+			       ahd_get_pci_function(ahd->dev_softc),
+			       base, base2);
+		}
+	}
+	ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND, command, 4);
+	return (error);
+}
+
+int
+ahd_pci_map_int(struct ahd_softc *ahd)
+{
+	int error;
+
+	error = request_irq(ahd->dev_softc->irq, ahd_linux_isr,
+			    SA_SHIRQ, "aic79xx", ahd);
+	if (error == 0)
+		ahd->platform_data->irq = ahd->dev_softc->irq;
+	
+	return (-error);
+}
+
+void
+ahd_power_state_change(struct ahd_softc *ahd, ahd_power_state new_state)
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+	pci_set_power_state(ahd->dev_softc, new_state);
+#else
+	uint32_t cap;
+	u_int cap_offset;
+
+	/*
+	 * Traverse the capability list looking for
+	 * the power management capability.
+	 */
+	cap = 0;
+	cap_offset = ahd_pci_read_config(ahd->dev_softc,
+					 PCIR_CAP_PTR, /*bytes*/1);
+	while (cap_offset != 0) {
+
+		cap = ahd_pci_read_config(ahd->dev_softc,
+					  cap_offset, /*bytes*/4);
+		if ((cap & 0xFF) == 1
+		 && ((cap >> 16) & 0x3) > 0) {
+			uint32_t pm_control;
+
+			pm_control = ahd_pci_read_config(ahd->dev_softc,
+							 cap_offset + 4,
+							 /*bytes*/4);
+			pm_control &= ~0x3;
+			pm_control |= new_state;
+			ahd_pci_write_config(ahd->dev_softc,
+					     cap_offset + 4,
+					     pm_control, /*bytes*/2);
+			break;
+		}
+		cap_offset = (cap >> 8) & 0xFF;
+	}
+#endif 
+}
diff -Nru a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,912 @@
+/*
+ * Product specific probe and attach routines for:
+ *	aic7901 and aic7902 SCSI controllers
+ *
+ * Copyright (c) 1994-2001 Justin T. Gibbs.
+ * Copyright (c) 2000-2002 Adaptec Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $Id: //depot/aic7xxx/aic7xxx/aic79xx_pci.c#60 $
+ *
+ * $FreeBSD$
+ */
+
+#ifdef __linux__
+#include "aic79xx_osm.h"
+#include "aic79xx_inline.h"
+#else
+#include <dev/aic7xxx/aic79xx_osm.h>
+#include <dev/aic7xxx/aic79xx_inline.h>
+#endif
+
+static __inline uint64_t
+ahd_compose_id(u_int device, u_int vendor, u_int subdevice, u_int subvendor)
+{
+	uint64_t id;
+
+	id = subvendor
+	   | (subdevice << 16)
+	   | ((uint64_t)vendor << 32)
+	   | ((uint64_t)device << 48);
+
+	return (id);
+}
+
+#define ID_ALL_MASK			0xFFFFFFFFFFFFFFFFull
+#define ID_DEV_VENDOR_MASK		0xFFFFFFFF00000000ull
+#define ID_9005_GENERIC_MASK		0xFFF0FFFF00000000ull
+
+#define ID_AIC7901			0x800F9005FFFF9005ull
+#define ID_AIC7901A			0x801E9005FFFF9005ull
+#define ID_AIC7901A_IROC		0x809E9005FFFF9005ull
+#define ID_AHA_29320A			0x8000900500609005ull
+#define ID_AHA_29320LP			0x8014900500449005ull
+#define ID_AHA_29320LP_IROC		0x8094900500449005ull
+
+#define ID_AIC7902			0x801F9005FFFF9005ull
+#define ID_AIC7902_IROC			0x809F9005FFFF9005ull
+#define ID_AIC7902_B			0x801D9005FFFF9005ull
+#define ID_AIC7902_B_IROC		0x809D9005FFFF9005ull
+#define ID_AHA_39320			0x8010900500409005ull
+#define ID_AHA_39320D			0x8011900500419005ull
+#define ID_AHA_39320D_B			0x801C900500419005ull
+#define ID_AHA_39320D_HP		0x8011900500AC0E11ull
+#define ID_AHA_39320D_B_HP		0x801C900500AC0E11ull
+#define ID_AHA_29320			0x8012900500429005ull
+#define ID_AHA_29320B			0x8013900500439005ull
+#define ID_AIC7902_PCI_REV_A4		0x3
+#define ID_AIC7902_PCI_REV_B0		0x10
+#define SUBID_HP			0x0E11
+
+#define DEVID_9005_TYPE(id) ((id) & 0xF)
+#define		DEVID_9005_TYPE_HBA		0x0	/* Standard Card */
+#define		DEVID_9005_TYPE_HBA_2EXT	0x1	/* 2 External Ports */
+#define		DEVID_9005_TYPE_IROC		0x8	/* Raid(0,1,10) Card */
+#define		DEVID_9005_TYPE_MB		0xF	/* On Motherboard */
+
+#define DEVID_9005_MFUNC(id) ((id) & 0x10)
+
+#define DEVID_9005_PACKETIZED(id) ((id) & 0x8000)
+
+#define SUBID_9005_TYPE(id) ((id) & 0xF)
+#define		SUBID_9005_TYPE_HBA		0x0	/* Standard Card */
+#define		SUBID_9005_TYPE_MB		0xF	/* On Motherboard */
+
+#define SUBID_9005_AUTOTERM(id)	(((id) & 0x10) == 0)
+
+#define SUBID_9005_LEGACYCONN_FUNC(id) ((id) & 0x20)
+
+#define SUBID_9005_SEEPTYPE(id) ((id) & 0x0C0) >> 6)
+#define		SUBID_9005_SEEPTYPE_NONE	0x0
+#define		SUBID_9005_SEEPTYPE_4K		0x1
+
+static ahd_device_setup_t ahd_aic7901A_setup;
+static ahd_device_setup_t ahd_aic7902_setup;
+
+struct ahd_pci_identity ahd_pci_ident_table [] =
+{
+	/* aic7901A based controllers */
+	{
+		ID_AHA_29320LP,
+		ID_ALL_MASK,
+		"Adaptec 29320LP Ultra320 SCSI adapter",
+		ahd_aic7901A_setup
+	},
+	{
+		ID_AHA_29320A,
+		ID_ALL_MASK,
+		"Adaptec 29320A Ultra320 SCSI adapter",
+		ahd_aic7901A_setup
+	},
+	/* aic7902 based controllers */	
+	{
+		ID_AHA_39320,
+		ID_ALL_MASK,
+		"Adaptec 39320 Ultra320 SCSI adapter",
+		ahd_aic7902_setup
+	},
+	{
+		ID_AHA_39320D,
+		ID_ALL_MASK,
+		"Adaptec 39320D Ultra320 SCSI adapter",
+		ahd_aic7902_setup
+	},
+	{
+		ID_AHA_39320D_HP,
+		ID_ALL_MASK,
+		"Adaptec (HP OEM) 39320D Ultra320 SCSI adapter",
+		ahd_aic7902_setup
+	},
+	{
+		ID_AHA_39320D_B,
+		ID_ALL_MASK,
+		"Adaptec 39320D Ultra320 SCSI adapter",
+		ahd_aic7902_setup
+	},
+	{
+		ID_AHA_39320D_B_HP,
+		ID_ALL_MASK,
+		"Adaptec (HP OEM) 39320D Ultra320 SCSI adapter",
+		ahd_aic7902_setup
+	},
+	{
+		ID_AHA_29320,
+		ID_ALL_MASK,
+		"Adaptec 29320 Ultra320 SCSI adapter",
+		ahd_aic7902_setup
+	},
+	{
+		ID_AHA_29320B,
+		ID_ALL_MASK,
+		"Adaptec 29320B Ultra320 SCSI adapter",
+		ahd_aic7902_setup
+	},
+	/* Generic chip probes for devices we don't know 'exactly' */
+	{
+		ID_AIC7901A & ID_DEV_VENDOR_MASK,
+		ID_DEV_VENDOR_MASK,
+		"Adaptec AIC7901A Ultra320 SCSI adapter",
+		ahd_aic7901A_setup
+	},
+	{
+		ID_AIC7902 & ID_9005_GENERIC_MASK,
+		ID_9005_GENERIC_MASK,
+		"Adaptec AIC7902 Ultra320 SCSI adapter",
+		ahd_aic7902_setup
+	}
+};
+
+const u_int ahd_num_pci_devs = NUM_ELEMENTS(ahd_pci_ident_table);
+		
+#define	DEVCONFIG		0x40
+#define		PCIXINITPAT	0x0000E000ul
+#define			PCIXINIT_PCI33_66	0x0000E000ul
+#define			PCIXINIT_PCIX50_66	0x0000C000ul
+#define			PCIXINIT_PCIX66_100	0x0000A000ul
+#define			PCIXINIT_PCIX100_133	0x00008000ul
+#define	PCI_BUS_MODES_INDEX(devconfig)	\
+	(((devconfig) & PCIXINITPAT) >> 13)
+static const char *pci_bus_modes[] =
+{
+	"PCI bus mode unknown",
+	"PCI bus mode unknown",
+	"PCI bus mode unknown",
+	"PCI bus mode unknown",
+	"PCI-X 101-133Mhz",
+	"PCI-X 67-100Mhz",
+	"PCI-X 50-66Mhz",
+	"PCI 33 or 66Mhz"
+};
+
+#define		TESTMODE	0x00000800ul
+#define		IRDY_RST	0x00000200ul
+#define		FRAME_RST	0x00000100ul
+#define		PCI64BIT	0x00000080ul
+#define		MRDCEN		0x00000040ul
+#define		ENDIANSEL	0x00000020ul
+#define		MIXQWENDIANEN	0x00000008ul
+#define		DACEN		0x00000004ul
+#define		STPWLEVEL	0x00000002ul
+#define		QWENDIANSEL	0x00000001ul
+
+#define	DEVCONFIG1		0x44
+#define		PREQDIS		0x01
+
+#define	CSIZE_LATTIME		0x0c
+#define		CACHESIZE	0x000000fful
+#define		LATTIME		0x0000ff00ul
+
+static int	ahd_check_extport(struct ahd_softc *ahd);
+static void	ahd_configure_termination(struct ahd_softc *ahd,
+					  u_int adapter_control);
+static void	ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat);
+
+struct ahd_pci_identity *
+ahd_find_pci_device(ahd_dev_softc_t pci)
+{
+	uint64_t  full_id;
+	uint16_t  device;
+	uint16_t  vendor;
+	uint16_t  subdevice;
+	uint16_t  subvendor;
+	struct	  ahd_pci_identity *entry;
+	u_int	  i;
+
+	vendor = ahd_pci_read_config(pci, PCIR_DEVVENDOR, /*bytes*/2);
+	device = ahd_pci_read_config(pci, PCIR_DEVICE, /*bytes*/2);
+	subvendor = ahd_pci_read_config(pci, PCIR_SUBVEND_0, /*bytes*/2);
+	subdevice = ahd_pci_read_config(pci, PCIR_SUBDEV_0, /*bytes*/2);
+	full_id = ahd_compose_id(device,
+				 vendor,
+				 subdevice,
+				 subvendor);
+
+	for (i = 0; i < ahd_num_pci_devs; i++) {
+		entry = &ahd_pci_ident_table[i];
+		if (entry->full_id == (full_id & entry->id_mask)) {
+			/* Honor exclusion entries. */
+			if (entry->name == NULL)
+				return (NULL);
+			return (entry);
+		}
+	}
+	return (NULL);
+}
+
+int
+ahd_pci_config(struct ahd_softc *ahd, struct ahd_pci_identity *entry)
+{
+	struct scb_data *shared_scb_data;
+	u_long		 l;
+	u_int		 command;
+	uint32_t	 devconfig;
+	uint16_t	 subvendor; 
+	int		 error;
+
+	shared_scb_data = NULL;
+	ahd->description = entry->name;
+	/*
+	 * Record if this is an HP board.
+	 */
+	subvendor = ahd_pci_read_config(ahd->dev_softc,
+					PCIR_SUBVEND_0, /*bytes*/2);
+	if (subvendor == SUBID_HP)
+		ahd->flags |= AHD_HP_BOARD;
+
+	error = entry->setup(ahd);
+	if (error != 0)
+		return (error);
+	
+	devconfig = ahd_pci_read_config(ahd->dev_softc, DEVCONFIG, /*bytes*/4);
+	if ((devconfig & PCIXINITPAT) == PCIXINIT_PCI33_66) {
+		ahd->chip |= AHD_PCI;
+		/* Disable PCIX workarounds when running in PCI mode. */
+		ahd->bugs &= ~AHD_PCIX_BUG_MASK;
+	} else {
+		ahd->chip |= AHD_PCIX;
+	}
+	ahd->bus_description = pci_bus_modes[PCI_BUS_MODES_INDEX(devconfig)];
+
+	ahd_power_state_change(ahd, AHD_POWER_STATE_D0);
+
+	error = ahd_pci_map_registers(ahd);
+	if (error != 0)
+		return (error);
+
+	/*
+	 * If we need to support high memory, enable dual
+	 * address cycles.  This bit must be set to enable
+	 * high address bit generation even if we are on a
+	 * 64bit bus (PCI64BIT set in devconfig).
+	 */
+	if ((ahd->flags & (AHD_39BIT_ADDRESSING|AHD_64BIT_ADDRESSING)) != 0) {
+		uint32_t devconfig;
+
+		if (bootverbose)
+			printf("%s: Enabling 39Bit Addressing\n",
+			       ahd_name(ahd));
+		devconfig = ahd_pci_read_config(ahd->dev_softc,
+						DEVCONFIG, /*bytes*/4);
+		devconfig |= DACEN;
+		ahd_pci_write_config(ahd->dev_softc, DEVCONFIG,
+				     devconfig, /*bytes*/4);
+	}
+	
+	/* Ensure busmastering is enabled */
+	command = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/1);
+	command |= PCIM_CMD_BUSMASTEREN;
+	ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND, command, /*bytes*/1);
+
+	error = ahd_softc_init(ahd);
+	if (error != 0)
+		return (error);
+
+	ahd->bus_intr = ahd_pci_intr;
+
+	error = ahd_reset(ahd);
+	if (error != 0)
+		return (ENXIO);
+
+	ahd->pci_cachesize =
+	    ahd_pci_read_config(ahd->dev_softc, CSIZE_LATTIME,
+				/*bytes*/1) & CACHESIZE;
+	ahd->pci_cachesize *= 4;
+
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+	/* See if we have a SEEPROM and perform auto-term */
+	error = ahd_check_extport(ahd);
+	if (error != 0)
+		return (error);
+
+	/* Core initialization */
+	error = ahd_init(ahd);
+	if (error != 0)
+		return (error);
+
+	/*
+	 * Allow interrupts now that we are completely setup.
+	 */
+	error = ahd_pci_map_int(ahd);
+	if (error != 0)
+		return (error);
+
+	ahd_list_lock(&l);
+	/*
+	 * Link this softc in with all other ahd instances.
+	 */
+	ahd_softc_insert(ahd);
+	ahd_list_unlock(&l);
+	return (0);
+}
+
+/*
+ * Perform some simple tests that should catch situations where
+ * our registers are invalidly mapped.
+ */
+int
+ahd_pci_test_register_access(struct ahd_softc *ahd)
+{
+	ahd_mode_state	saved_modes;
+	int		error;
+	uint8_t		seqctl;
+
+	saved_modes = ahd_save_modes(ahd);
+	error = EIO;
+
+	/* Enable PCI error interrupt status */
+	seqctl = ahd_inb(ahd, SEQCTL0);
+	ahd_outb(ahd, SEQCTL0, seqctl & ~FAILDIS);
+
+	/*
+	 * First a simple test to see if any
+	 * registers can be read.  Reading
+	 * HCNTRL has no side effects and has
+	 * at least one bit that is guaranteed to
+	 * be zero so it is a good register to
+	 * use for this test.
+	 */
+	if (ahd_inb(ahd, HCNTRL) == 0xFF)
+		goto fail;
+
+	/*
+	 * Next create a situation where write combining
+	 * or read prefetching could be initiated by the
+	 * CPU or host bridge.  Our device does not support
+	 * either, so look for data corruption and/or flaged
+	 * PCI errors.
+	 */
+	ahd_outl(ahd, SRAM_BASE, 0x5aa555aa);
+	if (ahd_inl(ahd, SRAM_BASE) != 0x5aa555aa)
+		goto fail;
+
+	if ((ahd_inb(ahd, INTSTAT) & PCIINT) != 0) {
+		u_int targpcistat;
+
+		ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
+		targpcistat = ahd_inb(ahd, TARGPCISTAT);
+		if ((targpcistat & STA) != 0)
+			goto fail;
+	}
+
+	error = 0;
+
+fail:
+	if ((ahd_inb(ahd, INTSTAT) & PCIINT) != 0) {
+		u_int targpcistat;
+		u_int pci_status1;
+
+		ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
+		targpcistat = ahd_inb(ahd, TARGPCISTAT);
+
+		/* Silently clear any latched errors. */
+		ahd_outb(ahd, TARGPCISTAT, targpcistat);
+		pci_status1 = ahd_pci_read_config(ahd->dev_softc,
+						  PCIR_STATUS + 1, /*bytes*/1);
+		ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
+				     pci_status1, /*bytes*/1);
+		ahd_outb(ahd, CLRINT, CLRPCIINT);
+	}
+
+	ahd_restore_modes(ahd, saved_modes);
+	ahd_outb(ahd, SEQCTL0, seqctl);
+	return (error);
+}
+
+/*
+ * Check the external port logic for a serial eeprom
+ * and termination/cable detection contrls.
+ */
+static int
+ahd_check_extport(struct ahd_softc *ahd)
+{
+	struct	seeprom_config *sc;
+	u_int	adapter_control;
+	int	have_seeprom;
+	int	error;
+
+	sc = ahd->seep_config;
+	have_seeprom = ahd_acquire_seeprom(ahd);
+	if (have_seeprom) {
+		u_int start_addr;
+
+		if (bootverbose) 
+			printf("%s: Reading SEEPROM...", ahd_name(ahd));
+
+		/* Address is always in units of 16bit words */
+		start_addr = (sizeof(*sc) / 2) * (ahd->channel - 'A');
+
+		error = ahd_read_seeprom(ahd, (uint16_t *)sc,
+					 start_addr, sizeof(*sc)/2);
+
+		if (error != 0) {
+			printf("Unable to read SEEPROM\n");
+			have_seeprom = 0;
+		} else {
+			have_seeprom = ahd_verify_cksum(sc);
+
+			if (bootverbose) {
+				if (have_seeprom == 0)
+					printf ("checksum error\n");
+				else
+					printf ("done.\n");
+			}
+		}
+		ahd_release_seeprom(ahd);
+	}
+
+	if (!have_seeprom) {
+		u_int	  nvram_scb;
+
+		/*
+		 * Pull scratch ram settings and treat them as
+		 * if they are the contents of an seeprom if
+		 * the 'ADPT', 'BIOS', or 'ASPI' signature is found
+		 * in SCB 0xFF.  We manually compose the data as 16bit
+		 * values to avoid endian issues.
+		 */
+		ahd_set_scbptr(ahd, 0xFF);
+		nvram_scb = ahd_inb_scbram(ahd, SCB_BASE + NVRAM_SCB_OFFSET);
+		if (nvram_scb != 0xFF
+		 && ((ahd_inb_scbram(ahd, SCB_BASE + 0) == 'A'
+		   && ahd_inb_scbram(ahd, SCB_BASE + 1) == 'D'
+		   && ahd_inb_scbram(ahd, SCB_BASE + 2) == 'P'
+		   && ahd_inb_scbram(ahd, SCB_BASE + 3) == 'T')
+		  || (ahd_inb_scbram(ahd, SCB_BASE + 0) == 'B'
+		   && ahd_inb_scbram(ahd, SCB_BASE + 1) == 'I'
+		   && ahd_inb_scbram(ahd, SCB_BASE + 2) == 'O'
+		   && ahd_inb_scbram(ahd, SCB_BASE + 3) == 'S')
+		  || (ahd_inb_scbram(ahd, SCB_BASE + 0) == 'A'
+		   && ahd_inb_scbram(ahd, SCB_BASE + 1) == 'S'
+		   && ahd_inb_scbram(ahd, SCB_BASE + 2) == 'P'
+		   && ahd_inb_scbram(ahd, SCB_BASE + 3) == 'I'))) {
+			uint16_t *sc_data;
+			int	  i;
+
+			ahd_set_scbptr(ahd, nvram_scb);
+			sc_data = (uint16_t *)sc;
+			for (i = 0; i < 64; i += 2)
+				*sc_data++ = ahd_inw_scbram(ahd, SCB_BASE+i);
+			have_seeprom = ahd_verify_cksum(sc);
+			if (have_seeprom)
+				ahd->flags |= AHD_SCB_CONFIG_USED;
+		}
+	}
+
+#if AHD_DEBUG
+	if (have_seeprom != 0
+	 && (ahd_debug & AHD_DUMP_SEEPROM) != 0) {
+		uint8_t *sc_data;
+		int	 i;
+
+		printf("%s: Seeprom Contents:", ahd_name(ahd));
+		sc_data = (uint8_t *)sc;
+		for (i = 0; i < (sizeof(*sc)); i += 2)
+			printf("\n\t0x%.4x", 
+			       sc_data[i] | (sc_data[i+1] << 8));
+		printf("\n");
+	}
+#endif
+
+	if (!have_seeprom) {
+		if (bootverbose)
+			printf("%s: No SEEPROM available.\n", ahd_name(ahd));
+		ahd->flags |= AHD_USEDEFAULTS;
+		error = ahd_default_config(ahd);
+		adapter_control = CFAUTOTERM|CFSEAUTOTERM;
+		free(ahd->seep_config, M_DEVBUF);
+		ahd->seep_config = NULL;
+	} else {
+		error = ahd_parse_cfgdata(ahd, sc);
+		adapter_control = sc->adapter_control;
+	}
+	if (error != 0)
+		return (error);
+
+	ahd_configure_termination(ahd, adapter_control);
+
+	return (0);
+}
+
+static void
+ahd_configure_termination(struct ahd_softc *ahd, u_int adapter_control)
+{
+	int	 error;
+	u_int	 sxfrctl1;
+	uint8_t	 termctl;
+	uint32_t devconfig;
+
+	devconfig = ahd_pci_read_config(ahd->dev_softc, DEVCONFIG, /*bytes*/4);
+	devconfig &= ~STPWLEVEL;
+	if ((ahd->flags & AHD_STPWLEVEL_A) != 0)
+		devconfig |= STPWLEVEL;
+	if (bootverbose)
+		printf("%s: STPWLEVEL is %s\n",
+		       ahd_name(ahd), (devconfig & STPWLEVEL) ? "on" : "off");
+	ahd_pci_write_config(ahd->dev_softc, DEVCONFIG, devconfig, /*bytes*/4);
+ 
+	/* Make sure current sensing is off. */
+	if ((ahd->flags & AHD_CURRENT_SENSING) != 0) {
+		(void)ahd_write_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL, 0);
+	}
+
+	/*
+	 * Read to sense.  Write to set.
+	 */
+	error = ahd_read_flexport(ahd, FLXADDR_TERMCTL, &termctl);
+	if ((adapter_control & CFAUTOTERM) == 0) {
+		if (bootverbose)
+			printf("%s: Manual Primary Termination\n",
+			       ahd_name(ahd));
+		termctl &= ~(FLX_TERMCTL_ENPRILOW|FLX_TERMCTL_ENPRIHIGH);
+		if ((adapter_control & CFSTERM) != 0)
+			termctl |= FLX_TERMCTL_ENPRILOW;
+		if ((adapter_control & CFWSTERM) != 0)
+			termctl |= FLX_TERMCTL_ENPRIHIGH;
+	} else if (error != 0) {
+		printf("%s: Primary Auto-Term Sensing failed! "
+		       "Using Defaults.\n", ahd_name(ahd));
+		termctl = FLX_TERMCTL_ENPRILOW|FLX_TERMCTL_ENPRIHIGH;
+	}
+
+	if ((adapter_control & CFSEAUTOTERM) == 0) {
+		if (bootverbose)
+			printf("%s: Manual Secondary Termination\n",
+			       ahd_name(ahd));
+		termctl &= ~(FLX_TERMCTL_ENSECLOW|FLX_TERMCTL_ENSECHIGH);
+		if ((adapter_control & CFSELOWTERM) != 0)
+			termctl |= FLX_TERMCTL_ENSECLOW;
+		if ((adapter_control & CFSEHIGHTERM) != 0)
+			termctl |= FLX_TERMCTL_ENSECHIGH;
+	} else if (error != 0) {
+		printf("%s: Secondary Auto-Term Sensing failed! "
+		       "Using Defaults.\n", ahd_name(ahd));
+		termctl |= FLX_TERMCTL_ENSECLOW|FLX_TERMCTL_ENSECHIGH;
+	}
+
+	/*
+	 * Now set the termination based on what we found.
+	 */
+	sxfrctl1 = ahd_inb(ahd, SXFRCTL1) & ~STPWEN;
+	if ((termctl & FLX_TERMCTL_ENPRILOW) != 0) {
+		ahd->flags |= AHD_TERM_ENB_A;
+		sxfrctl1 |= STPWEN;
+	}
+	/* Must set the latch once in order to be effective. */
+	ahd_outb(ahd, SXFRCTL1, sxfrctl1|STPWEN);
+	ahd_outb(ahd, SXFRCTL1, sxfrctl1);
+
+	error = ahd_write_flexport(ahd, FLXADDR_TERMCTL, termctl);
+	if (error != 0) {
+		printf("%s: Unable to set termination settings!\n",
+		       ahd_name(ahd));
+	} else if (bootverbose) {
+		printf("%s: Primary High byte termination %sabled\n",
+		       ahd_name(ahd),
+		       (termctl & FLX_TERMCTL_ENPRIHIGH) ? "En" : "Dis");
+
+		printf("%s: Primary Low byte termination %sabled\n",
+		       ahd_name(ahd),
+		       (termctl & FLX_TERMCTL_ENPRILOW) ? "En" : "Dis");
+
+		printf("%s: Secondary High byte termination %sabled\n",
+		       ahd_name(ahd),
+		       (termctl & FLX_TERMCTL_ENSECHIGH) ? "En" : "Dis");
+
+		printf("%s: Secondary Low byte termination %sabled\n",
+		       ahd_name(ahd),
+		       (termctl & FLX_TERMCTL_ENSECLOW) ? "En" : "Dis");
+	}
+	return;
+}
+
+#define	DPE	0x80
+#define SSE	0x40
+#define	RMA	0x20
+#define	RTA	0x10
+#define STA	0x08
+#define DPR	0x01
+
+static const char *split_status_source[] =
+{
+	"DFF0",
+	"DFF1",
+	"OVLY",
+	"CMC",
+};
+
+static const char *pci_status_source[] =
+{
+	"DFF0",
+	"DFF1",
+	"SG",
+	"CMC",
+	"OVLY",
+	"NONE",
+	"MSI",
+	"TARG"
+};
+
+static const char *split_status_strings[] =
+{
+	"%s: Received split response in %s.\n"
+	"%s: Received split completion error message in %s\n",
+	"%s: Receive overrun in %s\n",
+	"%s: Count not complete in %s\n",
+	"%s: Split completion data bucket in %s\n",
+	"%s: Split completion address error in %s\n",
+	"%s: Split completion byte count error in %s\n",
+	"%s: Signaled Target-abort to early terminate a split in %s\n",
+};
+
+static const char *pci_status_strings[] =
+{
+	"%s: Data Parity Error has been reported via PERR# in %s\n",
+	"%s: Target initial wait state error in %s\n",
+	"%s: Split completion read data parity error in %s\n",
+	"%s: Split completion address attribute parity error in %s\n",
+	"%s: Received a Target Abort in %s\n",
+	"%s: Received a Master Abort in %s\n",
+	"%s: Signal System Error Detected in %s\n",
+	"%s: Address or Write Phase Parity Error Detected in %s.\n"
+};
+
+void
+ahd_pci_intr(struct ahd_softc *ahd)
+{
+	uint8_t		pci_status[8];
+	ahd_mode_state	saved_modes;
+	u_int		pci_status1;
+	u_int		intstat;
+	u_int		i;
+	u_int		reg;
+	
+	intstat = ahd_inb(ahd, INTSTAT);
+
+	if ((intstat & SPLTINT) != 0)
+		ahd_pci_split_intr(ahd, intstat);
+
+	if ((intstat & PCIINT) == 0)
+		return;
+
+	printf("%s: PCI error Interrupt\n", ahd_name(ahd));
+	saved_modes = ahd_save_modes(ahd);
+	ahd_dump_card_state(ahd);
+	ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
+	for (i = 0, reg = DF0PCISTAT; i < 8; i++, reg++) {
+
+		if (i == 5)
+			continue;
+		pci_status[i] = ahd_inb(ahd, reg);
+		/* Clear latched errors.  So our interupt deasserts. */
+		ahd_outb(ahd, reg, pci_status[i]);
+	}
+
+	for (i = 0; i < 8; i++) {
+		u_int bit;
+	
+		if (i == 5)
+			continue;
+
+		for (bit = 0; bit < 8; bit++) {
+
+			if ((pci_status[i] & (0x1 << bit)) != 0) {
+				static const char *s;
+
+				s = pci_status_strings[bit];
+				if (i == 7/*TARG*/ && bit == 3)
+					s = "%s: Signaled Target Abort\n";
+				printf(s, ahd_name(ahd), pci_status_source[i]);
+			}
+		}	
+	}
+	pci_status1 = ahd_pci_read_config(ahd->dev_softc,
+					  PCIR_STATUS + 1, /*bytes*/1);
+	ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
+			     pci_status1, /*bytes*/1);
+	ahd_restore_modes(ahd, saved_modes);
+	ahd_outb(ahd, CLRINT, CLRPCIINT);
+	ahd_unpause(ahd);
+}
+
+static void
+ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
+{
+	uint8_t		split_status[4];
+	uint8_t		split_status1[4];
+	uint8_t		sg_split_status[2];
+	uint8_t		sg_split_status1[2];
+	ahd_mode_state	saved_modes;
+	u_int		i;
+	uint16_t	pcix_status;
+
+	/*
+	 * Check for splits in all modes.  Modes 0 and 1
+	 * additionally have SG engine splits to look at.
+	 */
+	pcix_status = ahd_pci_read_config(ahd->dev_softc, PCIXR_STATUS,
+					  /*bytes*/2);
+	printf("%s: PCI Split Interrupt - PCI-X status = 0x%x\n",
+	       ahd_name(ahd), pcix_status);
+	saved_modes = ahd_save_modes(ahd);
+	for (i = 0; i < 4; i++) {
+		ahd_set_modes(ahd, i, i);
+
+		split_status[i] = ahd_inb(ahd, DCHSPLTSTAT0);
+		split_status1[i] = ahd_inb(ahd, DCHSPLTSTAT1);
+		/* Clear latched errors.  So our interupt deasserts. */
+		ahd_outb(ahd, DCHSPLTSTAT0, split_status[i]);
+		ahd_outb(ahd, DCHSPLTSTAT1, split_status1[i]);
+		if (i != 0)
+			continue;
+		sg_split_status[i] = ahd_inb(ahd, SGSPLTSTAT0);
+		sg_split_status1[i] = ahd_inb(ahd, SGSPLTSTAT1);
+		/* Clear latched errors.  So our interupt deasserts. */
+		ahd_outb(ahd, SGSPLTSTAT0, sg_split_status[i]);
+		ahd_outb(ahd, SGSPLTSTAT1, sg_split_status1[i]);
+	}
+
+	for (i = 0; i < 4; i++) {
+		u_int bit;
+
+		for (bit = 0; bit < 8; bit++) {
+
+			if ((split_status[i] & (0x1 << bit)) != 0) {
+				static const char *s;
+
+				s = split_status_strings[bit];
+				printf(s, ahd_name(ahd),
+				       split_status_source[i]);
+			}
+
+			if (i != 0)
+				continue;
+
+			if ((sg_split_status[i] & (0x1 << bit)) != 0) {
+				static const char *s;
+
+				s = split_status_strings[bit];
+				printf(s, ahd_name(ahd), "SG");
+			}
+		}
+	}
+	/*
+	 * Clear PCI-X status bits.
+	 */
+	ahd_pci_write_config(ahd->dev_softc, PCIXR_STATUS,
+			     pcix_status, /*bytes*/2);
+	ahd_outb(ahd, CLRINT, CLRSPLTINT);
+	ahd_restore_modes(ahd, saved_modes);
+}
+
+static int
+ahd_aic7901A_setup(struct ahd_softc *ahd)
+{
+	int error;
+
+	error = ahd_aic7902_setup(ahd);
+	if (error != 0)
+		return (error);
+	ahd->chip = AHD_AIC7901A;
+	return (0);
+}
+
+static int
+ahd_aic7902_setup(struct ahd_softc *ahd)
+{
+	ahd_dev_softc_t pci;
+	u_int rev;
+
+	pci = ahd->dev_softc;
+	rev = ahd_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
+	if (rev < ID_AIC7902_PCI_REV_A4) {
+		printf("%s: Unable to attach to unsupported chip revision %d\n",
+		       ahd_name(ahd), rev);
+		ahd_pci_write_config(pci, PCIR_COMMAND, 0, /*bytes*/1);
+		return (ENXIO);
+	}
+	ahd->channel = ahd_get_pci_function(pci) + 'A';
+	ahd->chip = AHD_AIC7902;
+	ahd->features = AHD_AIC7902_FE;
+	if (rev < ID_AIC7902_PCI_REV_B0) {
+		/*
+		 * Enable A series workarounds.
+		 */
+		ahd->bugs |= AHD_SENT_SCB_UPDATE_BUG|AHD_ABORT_LQI_BUG
+			  |  AHD_PKT_BITBUCKET_BUG|AHD_LONG_SETIMO_BUG
+			  |  AHD_NLQICRC_DELAYED_BUG|AHD_SCSIRST_BUG
+			  |  AHD_LQO_ATNO_BUG|AHD_AUTOFLUSH_BUG
+			  |  AHD_CLRLQO_AUTOCLR_BUG|AHD_PCIX_MMAPIO_BUG
+			  |  AHD_PCIX_CHIPRST_BUG|AHD_PKTIZED_STATUS_BUG
+			  |  AHD_PKT_LUN_BUG|AHD_MDFF_WSCBPTR_BUG
+			  |  AHD_REG_SLOW_SETTLE_BUG|AHD_SET_MODE_BUG
+			  |  AHD_BUSFREEREV_BUG|AHD_NONPACKFIFO_BUG
+			  |  AHD_PACED_NEGTABLE_BUG;
+
+		/*
+		 * IO Cell paramter setup.
+		 */
+		AHD_SET_PRECOMP(ahd, AHD_PRECOMP_CUTBACK_29);
+
+		if ((ahd->flags & AHD_HP_BOARD) == 0)
+			AHD_SET_SLEWRATE(ahd, AHD_SLEWRATE_DEF_REVA);
+	} else {
+		u_int devconfig1;
+
+		ahd->features |= AHD_RTI|AHD_NEW_IOCELL_OPTS
+			      |  AHD_NEW_DFCNTRL_OPTS;
+		ahd->bugs |= AHD_LQOOVERRUN_BUG|AHD_ABORT_LQI_BUG
+			  |  AHD_INTCOLLISION_BUG;
+
+		/*
+		 * IO Cell paramter setup.
+		 */
+		AHD_SET_PRECOMP(ahd, AHD_PRECOMP_CUTBACK_29);
+		AHD_SET_SLEWRATE(ahd, AHD_SLEWRATE_DEF_REVB);
+		AHD_SET_AMPLITUDE(ahd, AHD_AMPLITUDE_DEF);
+
+		/*
+		 * Set the PREQDIS bit for H2B which disables some workaround
+		 * that doesn't work on regular PCI busses.
+		 * XXX - Find out exactly what this does from the hardware
+		 * 	 folks!
+		 */
+		devconfig1 = ahd_pci_read_config(pci, DEVCONFIG1, /*bytes*/1);
+		ahd_pci_write_config(pci, DEVCONFIG1,
+				     devconfig1|PREQDIS, /*bytes*/1);
+		devconfig1 = ahd_pci_read_config(pci, DEVCONFIG1, /*bytes*/1);
+	}
+
+	return (0);
+}
diff -Nru a/drivers/scsi/aic7xxx/aic79xx_proc.c b/drivers/scsi/aic7xxx/aic79xx_proc.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aic79xx_proc.c	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,345 @@
+/*
+ * Copyright (c) 2000-2001 Adaptec Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * String handling code courtesy of Gerard Roudier's <groudier@club-internet.fr>
+ * sym driver.
+ *
+ * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_proc.c#11 $
+ */
+#include "aic79xx_osm.h"
+#include "aic79xx_inline.h"
+
+static void	copy_mem_info(struct info_str *info, char *data, int len);
+static int	copy_info(struct info_str *info, char *fmt, ...);
+static void	ahd_dump_target_state(struct ahd_softc *ahd,
+				      struct info_str *info,
+				      u_int our_id, char channel,
+				      u_int target_id, u_int target_offset);
+static void	ahd_dump_device_state(struct info_str *info,
+				      struct ahd_linux_device *dev);
+static int	ahd_proc_write_seeprom(struct ahd_softc *ahd,
+				       char *buffer, int length);
+
+static void
+copy_mem_info(struct info_str *info, char *data, int len)
+{
+	if (info->pos + len > info->offset + info->length)
+		len = info->offset + info->length - info->pos;
+
+	if (info->pos + len < info->offset) {
+		info->pos += len;
+		return;
+	}
+
+	if (info->pos < info->offset) {
+		off_t partial;
+
+		partial = info->offset - info->pos;
+		data += partial;
+		info->pos += partial;
+		len  -= partial;
+	}
+
+	if (len > 0) {
+		memcpy(info->buffer, data, len);
+		info->pos += len;
+		info->buffer += len;
+	}
+}
+
+static int
+copy_info(struct info_str *info, char *fmt, ...)
+{
+	va_list args;
+	char buf[256];
+	int len;
+
+	va_start(args, fmt);
+	len = vsprintf(buf, fmt, args);
+	va_end(args);
+
+	copy_mem_info(info, buf, len);
+	return (len);
+}
+
+void
+ahd_format_transinfo(struct info_str *info, struct ahd_transinfo *tinfo)
+{
+	u_int speed;
+	u_int freq;
+	u_int mb;
+
+	if (tinfo->period == AHD_PERIOD_UNKNOWN) {
+		copy_info(info, "Renegotiation Pending\n");
+		return;
+	}
+        speed = 3300;
+        freq = 0;
+	if (tinfo->offset != 0) {
+		freq = aic_calc_syncsrate(tinfo->period);
+		speed = freq;
+	}
+	speed *= (0x01 << tinfo->width);
+        mb = speed / 1000;
+        if (mb > 0)
+		copy_info(info, "%d.%03dMB/s transfers", mb, speed % 1000);
+        else
+		copy_info(info, "%dKB/s transfers", speed);
+
+	if (freq != 0) {
+		int	printed_options;
+
+		printed_options = 0;
+		copy_info(info, " (%d.%03dMHz", freq / 1000, freq % 1000);
+		if ((tinfo->ppr_options & MSG_EXT_PPR_DT_REQ) != 0) {
+			copy_info(info, " DT");
+			printed_options++;
+		}
+		if ((tinfo->ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
+			copy_info(info, "%s", printed_options ? "|IU" : " IU");
+			printed_options++;
+		}
+		if ((tinfo->ppr_options & MSG_EXT_PPR_RTI) != 0) {
+			copy_info(info, "%s",
+				  printed_options ? "|RTI" : " RTI");
+			printed_options++;
+		}
+		if ((tinfo->ppr_options & MSG_EXT_PPR_QAS_REQ) != 0) {
+			copy_info(info, "%s",
+				  printed_options ? "|QAS" : " QAS");
+			printed_options++;
+		}
+	}
+
+	if (tinfo->width > 0) {
+		if (freq != 0) {
+			copy_info(info, ", ");
+		} else {
+			copy_info(info, " (");
+		}
+		copy_info(info, "%dbit)", 8 * (0x01 << tinfo->width));
+	} else if (freq != 0) {
+		copy_info(info, ")");
+	}
+	copy_info(info, "\n");
+}
+
+static void
+ahd_dump_target_state(struct ahd_softc *ahd, struct info_str *info,
+		      u_int our_id, char channel, u_int target_id,
+		      u_int target_offset)
+{
+	struct	ahd_linux_target *targ;
+	struct	ahd_initiator_tinfo *tinfo;
+	struct	ahd_tmode_tstate *tstate;
+	int	lun;
+
+	tinfo = ahd_fetch_transinfo(ahd, channel, our_id,
+				    target_id, &tstate);
+	copy_info(info, "Channel %c Target %d Negotiation Settings\n",
+		  channel, target_id);
+	copy_info(info, "\tUser: ");
+	ahd_format_transinfo(info, &tinfo->user);
+	targ = ahd->platform_data->targets[target_offset];
+	if (targ == NULL)
+		return;
+
+	copy_info(info, "\tGoal: ");
+	ahd_format_transinfo(info, &tinfo->goal);
+	copy_info(info, "\tCurr: ");
+	ahd_format_transinfo(info, &tinfo->curr);
+	copy_info(info, "\tTransmission Errors %ld\n", targ->errors_detected);
+
+	for (lun = 0; lun < AHD_NUM_LUNS; lun++) {
+		struct ahd_linux_device *dev;
+
+		dev = targ->devices[lun];
+
+		if (dev == NULL)
+			continue;
+
+		ahd_dump_device_state(info, dev);
+	}
+}
+
+static void
+ahd_dump_device_state(struct info_str *info, struct ahd_linux_device *dev)
+{
+	copy_info(info, "\tChannel %c Target %d Lun %d Settings\n",
+		  dev->target->channel + 'A', dev->target->target, dev->lun);
+
+	copy_info(info, "\t\tCommands Queued %ld\n", dev->commands_issued);
+	copy_info(info, "\t\tCommands Active %d\n", dev->active);
+	copy_info(info, "\t\tCommand Openings %d\n", dev->openings);
+	copy_info(info, "\t\tMax Tagged Openings %d\n", dev->maxtags);
+	copy_info(info, "\t\tDevice Queue Frozen Count %d\n", dev->qfrozen);
+}
+
+static int
+ahd_proc_write_seeprom(struct ahd_softc *ahd, char *buffer, int length)
+{
+	ahd_mode_state saved_modes;
+	int have_seeprom;
+	u_long s;
+	int paused;
+	int written;
+
+	/* Default to failure. */
+	written = -EINVAL;
+	ahd_lock(ahd, &s);
+	paused = ahd_is_paused(ahd);
+	if (!paused)
+		ahd_pause(ahd);
+
+	saved_modes = ahd_save_modes(ahd);
+	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
+	if (length != sizeof(struct seeprom_config)) {
+		printf("ahd_proc_write_seeprom: incorrect buffer size\n");
+		goto done;
+	}
+
+	have_seeprom = ahd_verify_cksum((struct seeprom_config*)buffer);
+	if (have_seeprom == 0) {
+		printf("ahd_proc_write_seeprom: cksum verification failed\n");
+		goto done;
+	}
+
+	have_seeprom = ahd_acquire_seeprom(ahd);
+	if (!have_seeprom) {
+		printf("ahd_proc_write_seeprom: No Serial EEPROM\n");
+		goto done;
+	} else {
+		u_int start_addr;
+
+		if (ahd->seep_config == NULL) {
+			ahd->seep_config = malloc(sizeof(*ahd->seep_config),
+						  M_DEVBUF, M_NOWAIT);
+			if (ahd->seep_config == NULL) {
+				printf("aic79xx: Unable to allocate serial "
+				       "eeprom buffer.  Write failing\n");
+				goto done;
+			}
+		}
+		printf("aic79xx: Writing Serial EEPROM\n");
+		start_addr = 32 * (ahd->channel - 'A');
+		ahd_write_seeprom(ahd, (u_int16_t *)buffer, start_addr,
+				  sizeof(struct seeprom_config)/2);
+		ahd_read_seeprom(ahd, (uint16_t *)ahd->seep_config,
+				 start_addr, sizeof(struct seeprom_config)/2);
+		ahd_release_seeprom(ahd);
+		written = length;
+	}
+
+done:
+	ahd_restore_modes(ahd, saved_modes);
+	if (!paused)
+		ahd_unpause(ahd);
+	ahd_unlock(ahd, &s);
+	return (written);
+}
+/*
+ * Return information to handle /proc support for the driver.
+ */
+int
+ahd_linux_proc_info(char *buffer, char **start, off_t offset,
+		  int length, int hostno, int inout)
+{
+	struct	ahd_softc *ahd;
+	struct	info_str info;
+	char	ahd_info[256];
+	u_long	l;
+	u_int	max_targ;
+	u_int	i;
+	int	retval;
+
+	retval = -EINVAL;
+	ahd_list_lock(&l);
+	TAILQ_FOREACH(ahd, &ahd_tailq, links) {
+		if (ahd->platform_data->host->host_no == hostno)
+			break;
+	}
+
+	if (ahd == NULL)
+		goto done;
+
+	 /* Has data been written to the file? */ 
+	if (inout == TRUE) {
+		retval = ahd_proc_write_seeprom(ahd, buffer, length);
+		goto done;
+	}
+
+	if (start)
+		*start = buffer;
+
+	info.buffer	= buffer;
+	info.length	= length;
+	info.offset	= offset;
+	info.pos	= 0;
+
+	copy_info(&info, "Adaptec AIC79xx driver version: %s\n",
+		  AIC79XX_DRIVER_VERSION);
+	ahd_controller_info(ahd, ahd_info);
+	copy_info(&info, "%s\n\n", ahd_info);
+
+	if (ahd->seep_config == NULL)
+		copy_info(&info, "No Serial EEPROM\n");
+	else {
+		copy_info(&info, "Serial EEPROM:\n");
+		for (i = 0; i < sizeof(*ahd->seep_config)/2; i++) {
+			if (((i % 8) == 0) && (i != 0)) {
+				copy_info(&info, "\n");
+			}
+			copy_info(&info, "0x%.4x ",
+				  ((uint16_t*)ahd->seep_config)[i]);
+		}
+		copy_info(&info, "\n");
+	}
+	copy_info(&info, "\n");
+
+	max_targ = 15;
+	if ((ahd->features & AHD_WIDE) == 0)
+		max_targ = 7;
+
+	for (i = 0; i <= max_targ; i++) {
+
+		ahd_dump_target_state(ahd, &info, ahd->our_id, 'A',
+				      /*target_id*/i, /*target_offset*/i);
+	}
+	retval = info.pos > info.offset ? info.pos - info.offset : 0;
+done:
+	ahd_list_unlock(&l);
+	return (retval);
+}
diff -Nru a/drivers/scsi/aic7xxx/aic79xx_reg.h_shipped b/drivers/scsi/aic7xxx/aic79xx_reg.h_shipped
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aic79xx_reg.h_shipped	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,3776 @@
+/*
+ * DO NOT EDIT - This file is automatically generated
+ *		 from the following source files:
+ *
+ * $Id: //depot/aic7xxx/aic7xxx/aic79xx.seq#77 $
+ * $Id: //depot/aic7xxx/aic7xxx/aic79xx.reg#59 $
+ */
+typedef int (ahd_reg_print_t)(u_int, u_int *, u_int);
+typedef struct ahd_reg_parse_entry {
+	char	*name;
+	uint8_t	 value;
+	uint8_t	 mask;
+} ahd_reg_parse_entry_t;
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_mode_ptr_print;
+#else
+#define ahd_mode_ptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "MODE_PTR", 0x00, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_intstat_print;
+#else
+#define ahd_intstat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "INTSTAT", 0x01, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_seqintcode_print;
+#else
+#define ahd_seqintcode_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SEQINTCODE", 0x02, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_clrint_print;
+#else
+#define ahd_clrint_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CLRINT", 0x03, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_error_print;
+#else
+#define ahd_error_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ERROR", 0x04, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_clrerr_print;
+#else
+#define ahd_clrerr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CLRERR", 0x04, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_hcntrl_print;
+#else
+#define ahd_hcntrl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "HCNTRL", 0x05, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_hnscb_qoff_print;
+#else
+#define ahd_hnscb_qoff_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "HNSCB_QOFF", 0x06, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_hescb_qoff_print;
+#else
+#define ahd_hescb_qoff_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "HESCB_QOFF", 0x08, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_hs_mailbox_print;
+#else
+#define ahd_hs_mailbox_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "HS_MAILBOX", 0x0b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_clrseqintstat_print;
+#else
+#define ahd_clrseqintstat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CLRSEQINTSTAT", 0x0c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_seqintstat_print;
+#else
+#define ahd_seqintstat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SEQINTSTAT", 0x0c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_swtimer_print;
+#else
+#define ahd_swtimer_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SWTIMER", 0x0e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_snscb_qoff_print;
+#else
+#define ahd_snscb_qoff_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SNSCB_QOFF", 0x10, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sescb_qoff_print;
+#else
+#define ahd_sescb_qoff_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SESCB_QOFF", 0x12, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sdscb_qoff_print;
+#else
+#define ahd_sdscb_qoff_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SDSCB_QOFF", 0x14, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_qoff_ctlsta_print;
+#else
+#define ahd_qoff_ctlsta_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "QOFF_CTLSTA", 0x16, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_intctl_print;
+#else
+#define ahd_intctl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "INTCTL", 0x18, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dfcntrl_print;
+#else
+#define ahd_dfcntrl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DFCNTRL", 0x19, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dscommand0_print;
+#else
+#define ahd_dscommand0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DSCOMMAND0", 0x19, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dfstatus_print;
+#else
+#define ahd_dfstatus_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DFSTATUS", 0x1a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sg_cache_shadow_print;
+#else
+#define ahd_sg_cache_shadow_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SG_CACHE_SHADOW", 0x1b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_arbctl_print;
+#else
+#define ahd_arbctl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ARBCTL", 0x1b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sg_cache_pre_print;
+#else
+#define ahd_sg_cache_pre_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SG_CACHE_PRE", 0x1b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqin_print;
+#else
+#define ahd_lqin_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQIN", 0x20, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_typeptr_print;
+#else
+#define ahd_typeptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "TYPEPTR", 0x20, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_tagptr_print;
+#else
+#define ahd_tagptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "TAGPTR", 0x21, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lunptr_print;
+#else
+#define ahd_lunptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LUNPTR", 0x22, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_datalenptr_print;
+#else
+#define ahd_datalenptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DATALENPTR", 0x23, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_statlenptr_print;
+#else
+#define ahd_statlenptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "STATLENPTR", 0x24, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_cmdlenptr_print;
+#else
+#define ahd_cmdlenptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CMDLENPTR", 0x25, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_attrptr_print;
+#else
+#define ahd_attrptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ATTRPTR", 0x26, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_flagptr_print;
+#else
+#define ahd_flagptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "FLAGPTR", 0x27, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_cmdptr_print;
+#else
+#define ahd_cmdptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CMDPTR", 0x28, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_qnextptr_print;
+#else
+#define ahd_qnextptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "QNEXTPTR", 0x29, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_idptr_print;
+#else
+#define ahd_idptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "IDPTR", 0x2a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_abrtbyteptr_print;
+#else
+#define ahd_abrtbyteptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ABRTBYTEPTR", 0x2b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_abrtbitptr_print;
+#else
+#define ahd_abrtbitptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ABRTBITPTR", 0x2c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_maxcmdbytes_print;
+#else
+#define ahd_maxcmdbytes_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "MAXCMDBYTES", 0x2d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_maxcmd2rcv_print;
+#else
+#define ahd_maxcmd2rcv_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "MAXCMD2RCV", 0x2e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_shortthresh_print;
+#else
+#define ahd_shortthresh_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SHORTTHRESH", 0x2f, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lunlen_print;
+#else
+#define ahd_lunlen_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LUNLEN", 0x30, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_cdblimit_print;
+#else
+#define ahd_cdblimit_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CDBLIMIT", 0x31, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_maxcmd_print;
+#else
+#define ahd_maxcmd_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "MAXCMD", 0x32, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_maxcmdcnt_print;
+#else
+#define ahd_maxcmdcnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "MAXCMDCNT", 0x33, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqrsvd01_print;
+#else
+#define ahd_lqrsvd01_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQRSVD01", 0x34, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqrsvd16_print;
+#else
+#define ahd_lqrsvd16_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQRSVD16", 0x35, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqrsvd17_print;
+#else
+#define ahd_lqrsvd17_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQRSVD17", 0x36, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_cmdrsvd0_print;
+#else
+#define ahd_cmdrsvd0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CMDRSVD0", 0x37, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqctl0_print;
+#else
+#define ahd_lqctl0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQCTL0", 0x38, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqctl1_print;
+#else
+#define ahd_lqctl1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQCTL1", 0x38, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scsbist0_print;
+#else
+#define ahd_scsbist0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCSBIST0", 0x39, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqctl2_print;
+#else
+#define ahd_lqctl2_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQCTL2", 0x39, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scsbist1_print;
+#else
+#define ahd_scsbist1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCSBIST1", 0x3a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scsiseq0_print;
+#else
+#define ahd_scsiseq0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCSISEQ0", 0x3a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scsiseq1_print;
+#else
+#define ahd_scsiseq1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCSISEQ1", 0x3b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sxfrctl0_print;
+#else
+#define ahd_sxfrctl0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SXFRCTL0", 0x3c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_businitid_print;
+#else
+#define ahd_businitid_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "BUSINITID", 0x3c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dlcount_print;
+#else
+#define ahd_dlcount_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DLCOUNT", 0x3c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sxfrctl1_print;
+#else
+#define ahd_sxfrctl1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SXFRCTL1", 0x3d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_bustargid_print;
+#else
+#define ahd_bustargid_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "BUSTARGID", 0x3e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sxfrctl2_print;
+#else
+#define ahd_sxfrctl2_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SXFRCTL2", 0x3e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dffstat_print;
+#else
+#define ahd_dffstat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DFFSTAT", 0x3f, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scsisigo_print;
+#else
+#define ahd_scsisigo_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCSISIGO", 0x40, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_multargid_print;
+#else
+#define ahd_multargid_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "MULTARGID", 0x40, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scsisigi_print;
+#else
+#define ahd_scsisigi_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCSISIGI", 0x41, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scsiphase_print;
+#else
+#define ahd_scsiphase_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCSIPHASE", 0x42, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scsidat0_img_print;
+#else
+#define ahd_scsidat0_img_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCSIDAT0_IMG", 0x43, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scsidat_print;
+#else
+#define ahd_scsidat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCSIDAT", 0x44, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scsibus_print;
+#else
+#define ahd_scsibus_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCSIBUS", 0x46, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_targidin_print;
+#else
+#define ahd_targidin_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "TARGIDIN", 0x48, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_selid_print;
+#else
+#define ahd_selid_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SELID", 0x49, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sblkctl_print;
+#else
+#define ahd_sblkctl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SBLKCTL", 0x4a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_optionmode_print;
+#else
+#define ahd_optionmode_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "OPTIONMODE", 0x4a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sstat0_print;
+#else
+#define ahd_sstat0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SSTAT0", 0x4b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_clrsint0_print;
+#else
+#define ahd_clrsint0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CLRSINT0", 0x4b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_simode0_print;
+#else
+#define ahd_simode0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SIMODE0", 0x4b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_clrsint1_print;
+#else
+#define ahd_clrsint1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CLRSINT1", 0x4c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sstat1_print;
+#else
+#define ahd_sstat1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SSTAT1", 0x4c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sstat2_print;
+#else
+#define ahd_sstat2_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SSTAT2", 0x4d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_clrsint2_print;
+#else
+#define ahd_clrsint2_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CLRSINT2", 0x4d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_simode2_print;
+#else
+#define ahd_simode2_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SIMODE2", 0x4d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_perrdiag_print;
+#else
+#define ahd_perrdiag_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "PERRDIAG", 0x4e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqistate_print;
+#else
+#define ahd_lqistate_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQISTATE", 0x4e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_soffcnt_print;
+#else
+#define ahd_soffcnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SOFFCNT", 0x4f, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqostate_print;
+#else
+#define ahd_lqostate_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQOSTATE", 0x4f, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqistat0_print;
+#else
+#define ahd_lqistat0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQISTAT0", 0x50, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_clrlqiint0_print;
+#else
+#define ahd_clrlqiint0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CLRLQIINT0", 0x50, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqimode0_print;
+#else
+#define ahd_lqimode0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQIMODE0", 0x50, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqimode1_print;
+#else
+#define ahd_lqimode1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQIMODE1", 0x51, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqistat1_print;
+#else
+#define ahd_lqistat1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQISTAT1", 0x51, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_clrlqiint1_print;
+#else
+#define ahd_clrlqiint1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CLRLQIINT1", 0x51, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqistat2_print;
+#else
+#define ahd_lqistat2_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQISTAT2", 0x52, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sstat3_print;
+#else
+#define ahd_sstat3_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SSTAT3", 0x53, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_simode3_print;
+#else
+#define ahd_simode3_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SIMODE3", 0x53, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_clrsint3_print;
+#else
+#define ahd_clrsint3_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CLRSINT3", 0x53, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqomode0_print;
+#else
+#define ahd_lqomode0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQOMODE0", 0x54, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqostat0_print;
+#else
+#define ahd_lqostat0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQOSTAT0", 0x54, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_clrlqoint0_print;
+#else
+#define ahd_clrlqoint0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CLRLQOINT0", 0x54, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqostat1_print;
+#else
+#define ahd_lqostat1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQOSTAT1", 0x55, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_clrlqoint1_print;
+#else
+#define ahd_clrlqoint1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CLRLQOINT1", 0x55, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqomode1_print;
+#else
+#define ahd_lqomode1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQOMODE1", 0x55, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqostat2_print;
+#else
+#define ahd_lqostat2_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQOSTAT2", 0x56, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_os_space_cnt_print;
+#else
+#define ahd_os_space_cnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "OS_SPACE_CNT", 0x56, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_simode1_print;
+#else
+#define ahd_simode1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SIMODE1", 0x57, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_gsfifo_print;
+#else
+#define ahd_gsfifo_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "GSFIFO", 0x58, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dffsxfrctl_print;
+#else
+#define ahd_dffsxfrctl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DFFSXFRCTL", 0x5a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lqoscsctl_print;
+#else
+#define ahd_lqoscsctl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LQOSCSCTL", 0x5a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_nextscb_print;
+#else
+#define ahd_nextscb_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "NEXTSCB", 0x5a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_clrseqintsrc_print;
+#else
+#define ahd_clrseqintsrc_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CLRSEQINTSRC", 0x5b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_seqintsrc_print;
+#else
+#define ahd_seqintsrc_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SEQINTSRC", 0x5b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_currscb_print;
+#else
+#define ahd_currscb_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CURRSCB", 0x5c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_seqimode_print;
+#else
+#define ahd_seqimode_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SEQIMODE", 0x5c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_mdffstat_print;
+#else
+#define ahd_mdffstat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "MDFFSTAT", 0x5d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_crccontrol_print;
+#else
+#define ahd_crccontrol_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CRCCONTROL", 0x5d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dfftag_print;
+#else
+#define ahd_dfftag_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DFFTAG", 0x5e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lastscb_print;
+#else
+#define ahd_lastscb_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LASTSCB", 0x5e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scsitest_print;
+#else
+#define ahd_scsitest_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCSITEST", 0x5e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_iopdnctl_print;
+#else
+#define ahd_iopdnctl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "IOPDNCTL", 0x5f, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_shaddr_print;
+#else
+#define ahd_shaddr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SHADDR", 0x60, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_negoaddr_print;
+#else
+#define ahd_negoaddr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "NEGOADDR", 0x60, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dgrpcrci_print;
+#else
+#define ahd_dgrpcrci_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DGRPCRCI", 0x60, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_negperiod_print;
+#else
+#define ahd_negperiod_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "NEGPERIOD", 0x61, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_packcrci_print;
+#else
+#define ahd_packcrci_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "PACKCRCI", 0x62, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_negoffset_print;
+#else
+#define ahd_negoffset_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "NEGOFFSET", 0x62, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_negppropts_print;
+#else
+#define ahd_negppropts_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "NEGPPROPTS", 0x63, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_negconopts_print;
+#else
+#define ahd_negconopts_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "NEGCONOPTS", 0x64, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_annexcol_print;
+#else
+#define ahd_annexcol_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ANNEXCOL", 0x65, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scschkn_print;
+#else
+#define ahd_scschkn_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCSCHKN", 0x66, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_annexdat_print;
+#else
+#define ahd_annexdat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ANNEXDAT", 0x66, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_iownid_print;
+#else
+#define ahd_iownid_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "IOWNID", 0x67, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_pll960ctl0_print;
+#else
+#define ahd_pll960ctl0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "PLL960CTL0", 0x68, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_shcnt_print;
+#else
+#define ahd_shcnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SHCNT", 0x68, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_townid_print;
+#else
+#define ahd_townid_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "TOWNID", 0x69, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_pll960ctl1_print;
+#else
+#define ahd_pll960ctl1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "PLL960CTL1", 0x69, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_pll960cnt0_print;
+#else
+#define ahd_pll960cnt0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "PLL960CNT0", 0x6a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_xsig_print;
+#else
+#define ahd_xsig_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "XSIG", 0x6a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_seloid_print;
+#else
+#define ahd_seloid_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SELOID", 0x6b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_pll400ctl0_print;
+#else
+#define ahd_pll400ctl0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "PLL400CTL0", 0x6c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_fairness_print;
+#else
+#define ahd_fairness_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "FAIRNESS", 0x6c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_pll400ctl1_print;
+#else
+#define ahd_pll400ctl1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "PLL400CTL1", 0x6d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_pll400cnt0_print;
+#else
+#define ahd_pll400cnt0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "PLL400CNT0", 0x6e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_unfairness_print;
+#else
+#define ahd_unfairness_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "UNFAIRNESS", 0x6e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_haddr_print;
+#else
+#define ahd_haddr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "HADDR", 0x70, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_plldelay_print;
+#else
+#define ahd_plldelay_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "PLLDELAY", 0x70, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_hodmaadr_print;
+#else
+#define ahd_hodmaadr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "HODMAADR", 0x70, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_hodmacnt_print;
+#else
+#define ahd_hodmacnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "HODMACNT", 0x78, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_hcnt_print;
+#else
+#define ahd_hcnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "HCNT", 0x78, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_hodmaen_print;
+#else
+#define ahd_hodmaen_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "HODMAEN", 0x7a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sghaddr_print;
+#else
+#define ahd_sghaddr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SGHADDR", 0x7c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scbhaddr_print;
+#else
+#define ahd_scbhaddr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCBHADDR", 0x7c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sghcnt_print;
+#else
+#define ahd_sghcnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SGHCNT", 0x84, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scbhcnt_print;
+#else
+#define ahd_scbhcnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCBHCNT", 0x84, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dff_thrsh_print;
+#else
+#define ahd_dff_thrsh_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DFF_THRSH", 0x88, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_romaddr_print;
+#else
+#define ahd_romaddr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ROMADDR", 0x8a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_romcntrl_print;
+#else
+#define ahd_romcntrl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ROMCNTRL", 0x8d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_romdata_print;
+#else
+#define ahd_romdata_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ROMDATA", 0x8e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_cmcrxmsg0_print;
+#else
+#define ahd_cmcrxmsg0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CMCRXMSG0", 0x90, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_roenable_print;
+#else
+#define ahd_roenable_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ROENABLE", 0x90, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ovlyrxmsg0_print;
+#else
+#define ahd_ovlyrxmsg0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "OVLYRXMSG0", 0x90, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dchrxmsg0_print;
+#else
+#define ahd_dchrxmsg0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DCHRXMSG0", 0x90, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ovlyrxmsg1_print;
+#else
+#define ahd_ovlyrxmsg1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "OVLYRXMSG1", 0x91, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_nsenable_print;
+#else
+#define ahd_nsenable_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "NSENABLE", 0x91, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dchrxmsg1_print;
+#else
+#define ahd_dchrxmsg1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DCHRXMSG1", 0x91, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_cmcrxmsg1_print;
+#else
+#define ahd_cmcrxmsg1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CMCRXMSG1", 0x91, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dchrxmsg2_print;
+#else
+#define ahd_dchrxmsg2_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DCHRXMSG2", 0x92, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ovlyrxmsg2_print;
+#else
+#define ahd_ovlyrxmsg2_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "OVLYRXMSG2", 0x92, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_cmcrxmsg2_print;
+#else
+#define ahd_cmcrxmsg2_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CMCRXMSG2", 0x92, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ost_print;
+#else
+#define ahd_ost_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "OST", 0x92, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dchrxmsg3_print;
+#else
+#define ahd_dchrxmsg3_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DCHRXMSG3", 0x93, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_cmcrxmsg3_print;
+#else
+#define ahd_cmcrxmsg3_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CMCRXMSG3", 0x93, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_pcixctl_print;
+#else
+#define ahd_pcixctl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "PCIXCTL", 0x93, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ovlyrxmsg3_print;
+#else
+#define ahd_ovlyrxmsg3_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "OVLYRXMSG3", 0x93, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ovlyseqbcnt_print;
+#else
+#define ahd_ovlyseqbcnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "OVLYSEQBCNT", 0x94, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_cmcseqbcnt_print;
+#else
+#define ahd_cmcseqbcnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CMCSEQBCNT", 0x94, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dchseqbcnt_print;
+#else
+#define ahd_dchseqbcnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DCHSEQBCNT", 0x94, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_cmcspltstat0_print;
+#else
+#define ahd_cmcspltstat0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CMCSPLTSTAT0", 0x96, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ovlyspltstat0_print;
+#else
+#define ahd_ovlyspltstat0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "OVLYSPLTSTAT0", 0x96, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dchspltstat0_print;
+#else
+#define ahd_dchspltstat0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DCHSPLTSTAT0", 0x96, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dchspltstat1_print;
+#else
+#define ahd_dchspltstat1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DCHSPLTSTAT1", 0x97, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_cmcspltstat1_print;
+#else
+#define ahd_cmcspltstat1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CMCSPLTSTAT1", 0x97, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ovlyspltstat1_print;
+#else
+#define ahd_ovlyspltstat1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "OVLYSPLTSTAT1", 0x97, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sgrxmsg0_print;
+#else
+#define ahd_sgrxmsg0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SGRXMSG0", 0x98, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_slvspltoutadr0_print;
+#else
+#define ahd_slvspltoutadr0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SLVSPLTOUTADR0", 0x98, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sgrxmsg1_print;
+#else
+#define ahd_sgrxmsg1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SGRXMSG1", 0x99, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_slvspltoutadr1_print;
+#else
+#define ahd_slvspltoutadr1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SLVSPLTOUTADR1", 0x99, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sgrxmsg2_print;
+#else
+#define ahd_sgrxmsg2_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SGRXMSG2", 0x9a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_slvspltoutadr2_print;
+#else
+#define ahd_slvspltoutadr2_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SLVSPLTOUTADR2", 0x9a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sgrxmsg3_print;
+#else
+#define ahd_sgrxmsg3_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SGRXMSG3", 0x9b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_slvspltoutadr3_print;
+#else
+#define ahd_slvspltoutadr3_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SLVSPLTOUTADR3", 0x9b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sgseqbcnt_print;
+#else
+#define ahd_sgseqbcnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SGSEQBCNT", 0x9c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_slvspltoutattr0_print;
+#else
+#define ahd_slvspltoutattr0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SLVSPLTOUTATTR0", 0x9c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_slvspltoutattr1_print;
+#else
+#define ahd_slvspltoutattr1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SLVSPLTOUTATTR1", 0x9d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_slvspltoutattr2_print;
+#else
+#define ahd_slvspltoutattr2_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SLVSPLTOUTATTR2", 0x9e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sgspltstat0_print;
+#else
+#define ahd_sgspltstat0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SGSPLTSTAT0", 0x9e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sfunct_print;
+#else
+#define ahd_sfunct_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SFUNCT", 0x9f, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sgspltstat1_print;
+#else
+#define ahd_sgspltstat1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SGSPLTSTAT1", 0x9f, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_df0pcistat_print;
+#else
+#define ahd_df0pcistat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DF0PCISTAT", 0xa0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_reg0_print;
+#else
+#define ahd_reg0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "REG0", 0xa0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_df1pcistat_print;
+#else
+#define ahd_df1pcistat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DF1PCISTAT", 0xa1, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sgpcistat_print;
+#else
+#define ahd_sgpcistat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SGPCISTAT", 0xa2, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_reg1_print;
+#else
+#define ahd_reg1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "REG1", 0xa2, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_cmcpcistat_print;
+#else
+#define ahd_cmcpcistat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CMCPCISTAT", 0xa3, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ovlypcistat_print;
+#else
+#define ahd_ovlypcistat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "OVLYPCISTAT", 0xa4, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_reg_isr_print;
+#else
+#define ahd_reg_isr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "REG_ISR", 0xa4, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sg_state_print;
+#else
+#define ahd_sg_state_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SG_STATE", 0xa6, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_msipcistat_print;
+#else
+#define ahd_msipcistat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "MSIPCISTAT", 0xa6, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_targpcistat_print;
+#else
+#define ahd_targpcistat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "TARGPCISTAT", 0xa7, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_data_count_odd_print;
+#else
+#define ahd_data_count_odd_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DATA_COUNT_ODD", 0xa7, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scbptr_print;
+#else
+#define ahd_scbptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCBPTR", 0xa8, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ccscbacnt_print;
+#else
+#define ahd_ccscbacnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CCSCBACNT", 0xab, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scbautoptr_print;
+#else
+#define ahd_scbautoptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCBAUTOPTR", 0xab, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ccsgaddr_print;
+#else
+#define ahd_ccsgaddr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CCSGADDR", 0xac, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ccscbaddr_print;
+#else
+#define ahd_ccscbaddr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CCSCBADDR", 0xac, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ccscbadr_bk_print;
+#else
+#define ahd_ccscbadr_bk_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CCSCBADR_BK", 0xac, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_cmc_rambist_print;
+#else
+#define ahd_cmc_rambist_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CMC_RAMBIST", 0xad, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ccsgctl_print;
+#else
+#define ahd_ccsgctl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CCSGCTL", 0xad, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ccscbctl_print;
+#else
+#define ahd_ccscbctl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CCSCBCTL", 0xad, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ccsgram_print;
+#else
+#define ahd_ccsgram_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CCSGRAM", 0xb0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_flexadr_print;
+#else
+#define ahd_flexadr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "FLEXADR", 0xb0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ccscbram_print;
+#else
+#define ahd_ccscbram_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CCSCBRAM", 0xb0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_flexcnt_print;
+#else
+#define ahd_flexcnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "FLEXCNT", 0xb3, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_flexdmastat_print;
+#else
+#define ahd_flexdmastat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "FLEXDMASTAT", 0xb5, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_flexdata_print;
+#else
+#define ahd_flexdata_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "FLEXDATA", 0xb6, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_brddat_print;
+#else
+#define ahd_brddat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "BRDDAT", 0xb8, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_brdctl_print;
+#else
+#define ahd_brdctl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "BRDCTL", 0xb9, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_seeadr_print;
+#else
+#define ahd_seeadr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SEEADR", 0xba, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_seedat_print;
+#else
+#define ahd_seedat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SEEDAT", 0xbc, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_seectl_print;
+#else
+#define ahd_seectl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SEECTL", 0xbe, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_seestat_print;
+#else
+#define ahd_seestat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SEESTAT", 0xbe, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scbcnt_print;
+#else
+#define ahd_scbcnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCBCNT", 0xbf, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dfwaddr_print;
+#else
+#define ahd_dfwaddr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DFWADDR", 0xc0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dspfltrctl_print;
+#else
+#define ahd_dspfltrctl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DSPFLTRCTL", 0xc0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dspdatactl_print;
+#else
+#define ahd_dspdatactl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DSPDATACTL", 0xc1, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dfraddr_print;
+#else
+#define ahd_dfraddr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DFRADDR", 0xc2, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dspreqctl_print;
+#else
+#define ahd_dspreqctl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DSPREQCTL", 0xc2, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dspackctl_print;
+#else
+#define ahd_dspackctl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DSPACKCTL", 0xc3, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dfdat_print;
+#else
+#define ahd_dfdat_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DFDAT", 0xc4, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dspselect_print;
+#else
+#define ahd_dspselect_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DSPSELECT", 0xc4, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_wrtbiasctl_print;
+#else
+#define ahd_wrtbiasctl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "WRTBIASCTL", 0xc5, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_rcvrbiosctl_print;
+#else
+#define ahd_rcvrbiosctl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "RCVRBIOSCTL", 0xc6, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_wrtbiascalc_print;
+#else
+#define ahd_wrtbiascalc_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "WRTBIASCALC", 0xc7, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dfptrs_print;
+#else
+#define ahd_dfptrs_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DFPTRS", 0xc8, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_rcvrbiascalc_print;
+#else
+#define ahd_rcvrbiascalc_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "RCVRBIASCALC", 0xc8, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dfbkptr_print;
+#else
+#define ahd_dfbkptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DFBKPTR", 0xc9, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_skewcalc_print;
+#else
+#define ahd_skewcalc_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SKEWCALC", 0xc9, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dfdbctl_print;
+#else
+#define ahd_dfdbctl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DFDBCTL", 0xcb, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dfscnt_print;
+#else
+#define ahd_dfscnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DFSCNT", 0xcc, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dfbcnt_print;
+#else
+#define ahd_dfbcnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DFBCNT", 0xce, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ovlyaddr_print;
+#else
+#define ahd_ovlyaddr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "OVLYADDR", 0xd4, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_seqctl0_print;
+#else
+#define ahd_seqctl0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SEQCTL0", 0xd6, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_seqctl1_print;
+#else
+#define ahd_seqctl1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SEQCTL1", 0xd7, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_flags_print;
+#else
+#define ahd_flags_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "FLAGS", 0xd8, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_seqintctl_print;
+#else
+#define ahd_seqintctl_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SEQINTCTL", 0xd9, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_seqram_print;
+#else
+#define ahd_seqram_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SEQRAM", 0xda, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_prgmcnt_print;
+#else
+#define ahd_prgmcnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "PRGMCNT", 0xde, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_accum_print;
+#else
+#define ahd_accum_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ACCUM", 0xe0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sindex_print;
+#else
+#define ahd_sindex_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SINDEX", 0xe2, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dindex_print;
+#else
+#define ahd_dindex_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DINDEX", 0xe4, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_brkaddr1_print;
+#else
+#define ahd_brkaddr1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "BRKADDR1", 0xe6, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_brkaddr0_print;
+#else
+#define ahd_brkaddr0_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "BRKADDR0", 0xe6, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_allones_print;
+#else
+#define ahd_allones_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ALLONES", 0xe8, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_allzeros_print;
+#else
+#define ahd_allzeros_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ALLZEROS", 0xea, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_none_print;
+#else
+#define ahd_none_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "NONE", 0xea, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sindir_print;
+#else
+#define ahd_sindir_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SINDIR", 0xec, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dindir_print;
+#else
+#define ahd_dindir_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DINDIR", 0xed, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_function1_print;
+#else
+#define ahd_function1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "FUNCTION1", 0xf0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_stack_print;
+#else
+#define ahd_stack_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "STACK", 0xf2, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_curaddr_print;
+#else
+#define ahd_curaddr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CURADDR", 0xf4, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_intvec1_addr_print;
+#else
+#define ahd_intvec1_addr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "INTVEC1_ADDR", 0xf4, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_intvec2_addr_print;
+#else
+#define ahd_intvec2_addr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "INTVEC2_ADDR", 0xf6, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lastaddr_print;
+#else
+#define ahd_lastaddr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LASTADDR", 0xf6, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_longjmp_addr_print;
+#else
+#define ahd_longjmp_addr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LONGJMP_ADDR", 0xf8, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_longjmp_scb_print;
+#else
+#define ahd_longjmp_scb_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LONGJMP_SCB", 0xfa, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_accum_save_print;
+#else
+#define ahd_accum_save_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ACCUM_SAVE", 0xfc, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_waiting_scb_tails_print;
+#else
+#define ahd_waiting_scb_tails_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "WAITING_SCB_TAILS", 0x100, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_ahd_pci_config_base_print;
+#else
+#define ahd_ahd_pci_config_base_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "AHD_PCI_CONFIG_BASE", 0x100, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_sram_base_print;
+#else
+#define ahd_sram_base_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SRAM_BASE", 0x100, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_waiting_tid_head_print;
+#else
+#define ahd_waiting_tid_head_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "WAITING_TID_HEAD", 0x120, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_waiting_tid_tail_print;
+#else
+#define ahd_waiting_tid_tail_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "WAITING_TID_TAIL", 0x122, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_next_queued_scb_addr_print;
+#else
+#define ahd_next_queued_scb_addr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "NEXT_QUEUED_SCB_ADDR", 0x124, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_complete_scb_head_print;
+#else
+#define ahd_complete_scb_head_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "COMPLETE_SCB_HEAD", 0x128, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_complete_scb_dmainprog_head_print;
+#else
+#define ahd_complete_scb_dmainprog_head_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "COMPLETE_SCB_DMAINPROG_HEAD", 0x12a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_complete_dma_scb_head_print;
+#else
+#define ahd_complete_dma_scb_head_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "COMPLETE_DMA_SCB_HEAD", 0x12c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_qfreeze_count_print;
+#else
+#define ahd_qfreeze_count_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "QFREEZE_COUNT", 0x12e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_saved_mode_print;
+#else
+#define ahd_saved_mode_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SAVED_MODE", 0x130, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_msg_out_print;
+#else
+#define ahd_msg_out_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "MSG_OUT", 0x131, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_dmaparams_print;
+#else
+#define ahd_dmaparams_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "DMAPARAMS", 0x132, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_seq_flags_print;
+#else
+#define ahd_seq_flags_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SEQ_FLAGS", 0x133, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_saved_scsiid_print;
+#else
+#define ahd_saved_scsiid_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SAVED_SCSIID", 0x134, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_saved_lun_print;
+#else
+#define ahd_saved_lun_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SAVED_LUN", 0x135, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_lastphase_print;
+#else
+#define ahd_lastphase_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LASTPHASE", 0x136, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_qoutfifo_entry_valid_tag_print;
+#else
+#define ahd_qoutfifo_entry_valid_tag_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "QOUTFIFO_ENTRY_VALID_TAG", 0x137, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_shared_data_addr_print;
+#else
+#define ahd_shared_data_addr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SHARED_DATA_ADDR", 0x138, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_qoutfifo_next_addr_print;
+#else
+#define ahd_qoutfifo_next_addr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "QOUTFIFO_NEXT_ADDR", 0x13c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_kernel_tqinpos_print;
+#else
+#define ahd_kernel_tqinpos_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "KERNEL_TQINPOS", 0x140, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_tqinpos_print;
+#else
+#define ahd_tqinpos_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "TQINPOS", 0x141, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_arg_1_print;
+#else
+#define ahd_arg_1_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ARG_1", 0x142, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_arg_2_print;
+#else
+#define ahd_arg_2_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ARG_2", 0x143, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_last_msg_print;
+#else
+#define ahd_last_msg_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LAST_MSG", 0x144, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scsiseq_template_print;
+#else
+#define ahd_scsiseq_template_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCSISEQ_TEMPLATE", 0x145, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_initiator_tag_print;
+#else
+#define ahd_initiator_tag_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "INITIATOR_TAG", 0x146, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_seq_flags2_print;
+#else
+#define ahd_seq_flags2_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SEQ_FLAGS2", 0x147, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_allocfifo_scbptr_print;
+#else
+#define ahd_allocfifo_scbptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "ALLOCFIFO_SCBPTR", 0x148, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_int_coalessing_timer_print;
+#else
+#define ahd_int_coalessing_timer_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "INT_COALESSING_TIMER", 0x14a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_int_coalessing_maxcmds_print;
+#else
+#define ahd_int_coalessing_maxcmds_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "INT_COALESSING_MAXCMDS", 0x14c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_int_coalessing_mincmds_print;
+#else
+#define ahd_int_coalessing_mincmds_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "INT_COALESSING_MINCMDS", 0x14d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_cmds_pending_print;
+#else
+#define ahd_cmds_pending_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CMDS_PENDING", 0x14e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_int_coalessing_cmdcount_print;
+#else
+#define ahd_int_coalessing_cmdcount_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "INT_COALESSING_CMDCOUNT", 0x150, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_local_hs_mailbox_print;
+#else
+#define ahd_local_hs_mailbox_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "LOCAL_HS_MAILBOX", 0x151, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_cmdsize_table_print;
+#else
+#define ahd_cmdsize_table_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "CMDSIZE_TABLE", 0x152, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_base_print;
+#else
+#define ahd_scb_base_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_BASE", 0x180, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_residual_datacnt_print;
+#else
+#define ahd_scb_residual_datacnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_RESIDUAL_DATACNT", 0x180, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_residual_sgptr_print;
+#else
+#define ahd_scb_residual_sgptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_RESIDUAL_SGPTR", 0x184, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_scsi_status_print;
+#else
+#define ahd_scb_scsi_status_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_SCSI_STATUS", 0x188, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_target_phases_print;
+#else
+#define ahd_scb_target_phases_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_TARGET_PHASES", 0x189, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_target_data_dir_print;
+#else
+#define ahd_scb_target_data_dir_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_TARGET_DATA_DIR", 0x18a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_target_itag_print;
+#else
+#define ahd_scb_target_itag_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_TARGET_ITAG", 0x18b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_sense_busaddr_print;
+#else
+#define ahd_scb_sense_busaddr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_SENSE_BUSADDR", 0x18c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_tag_print;
+#else
+#define ahd_scb_tag_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_TAG", 0x190, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_cdb_len_print;
+#else
+#define ahd_scb_cdb_len_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_CDB_LEN", 0x192, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_task_management_print;
+#else
+#define ahd_scb_task_management_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_TASK_MANAGEMENT", 0x193, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_next_print;
+#else
+#define ahd_scb_next_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_NEXT", 0x194, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_next2_print;
+#else
+#define ahd_scb_next2_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_NEXT2", 0x196, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_dataptr_print;
+#else
+#define ahd_scb_dataptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_DATAPTR", 0x198, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_datacnt_print;
+#else
+#define ahd_scb_datacnt_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_DATACNT", 0x1a0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_sgptr_print;
+#else
+#define ahd_scb_sgptr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_SGPTR", 0x1a4, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_control_print;
+#else
+#define ahd_scb_control_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_CONTROL", 0x1a8, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_scsiid_print;
+#else
+#define ahd_scb_scsiid_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_SCSIID", 0x1a9, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_lun_print;
+#else
+#define ahd_scb_lun_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_LUN", 0x1aa, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_task_attribute_print;
+#else
+#define ahd_scb_task_attribute_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_TASK_ATTRIBUTE", 0x1ab, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_busaddr_print;
+#else
+#define ahd_scb_busaddr_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_BUSADDR", 0x1ac, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_spare_print;
+#else
+#define ahd_scb_spare_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_SPARE", 0x1b0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahd_reg_print_t ahd_scb_disconnected_lists_print;
+#else
+#define ahd_scb_disconnected_lists_print(regvalue, cur_col, wrap) \
+    ahd_print_register(NULL, 0, "SCB_DISCONNECTED_LISTS", 0x1b8, regvalue, cur_col, wrap)
+#endif
+
+
+#define	MODE_PTR        		0x00
+#define		DST_MODE        	0x70
+#define		SRC_MODE        	0x07
+
+#define	INTSTAT         		0x01
+#define		INT_PEND        	0xff
+#define		HWERRINT        	0x80
+#define		BRKADRINT       	0x40
+#define		SWTMINT         	0x20
+#define		PCIINT          	0x10
+#define		SCSIINT         	0x08
+#define		SEQINT          	0x04
+#define		CMDCMPLT        	0x02
+#define		SPLTINT         	0x01
+
+#define	SEQINTCODE      		0x02
+#define		SAW_HWERR       	0x17
+#define		TRACEPOINT3     	0x16
+#define		TRACEPOINT2     	0x15
+#define		TRACEPOINT1     	0x14
+#define		TRACEPOINT0     	0x13
+#define		ENTERING_NONPACK	0x12
+#define		CFG4OVERRUN     	0x11
+#define		STATUS_OVERRUN  	0x10
+#define		CFG4ISTAT_INTR  	0x0f
+#define		INVALID_SEQINT  	0x0e
+#define		ILLEGAL_PHASE   	0x0d
+#define		DUMP_CARD_STATE 	0x0c
+#define		MISSED_BUSFREE  	0x0b
+#define		MKMSG_FAILED    	0x0a
+#define		DATA_OVERRUN    	0x09
+#define		BAD_STATUS      	0x08
+#define		HOST_MSG_LOOP   	0x07
+#define		PDATA_REINIT    	0x06
+#define		IGN_WIDE_RES    	0x05
+#define		NO_MATCH        	0x04
+#define		PROTO_VIOLATION 	0x03
+#define		SEND_REJECT     	0x02
+#define		BAD_PHASE       	0x01
+#define		NO_SEQINT       	0x00
+
+#define	CLRINT          		0x03
+#define		CLRHWERRINT     	0x80
+#define		CLRBRKADRINT    	0x40
+#define		CLRSWTMINT      	0x20
+#define		CLRPCIINT       	0x10
+#define		CLRSCSIINT      	0x08
+#define		CLRSEQINT       	0x04
+#define		CLRCMDINT       	0x02
+#define		CLRSPLTINT      	0x01
+
+#define	ERROR           		0x04
+#define		CIOPARERR       	0x80
+#define		CIOACCESFAIL    	0x40
+#define		MPARERR         	0x20
+#define		DPARERR         	0x10
+#define		SQPARERR        	0x08
+#define		ILLOPCODE       	0x04
+#define		DSCTMOUT        	0x02
+
+#define	CLRERR          		0x04
+#define		CLRCIOPARERR    	0x80
+#define		CLRCIOACCESFAIL 	0x40
+#define		CLRMPARERR      	0x20
+#define		CLRDPARERR      	0x10
+#define		CLRSQPARERR     	0x08
+#define		CLRILLOPCODE    	0x04
+#define		CLRDSCTMOUT     	0x02
+
+#define	HCNTRL          		0x05
+#define		SEQ_RESET       	0x80
+#define		POWRDN          	0x40
+#define		SWINT           	0x10
+#define		SWTIMER_START_B 	0x08
+#define		PAUSE           	0x04
+#define		INTEN           	0x02
+#define		CHIPRST         	0x01
+#define		CHIPRSTACK      	0x01
+
+#define	HNSCB_QOFF      		0x06
+
+#define	HESCB_QOFF      		0x08
+
+#define	HS_MAILBOX      		0x0b
+#define		HOST_TQINPOS    	0x80
+#define		ENINT_COALESS   	0x40
+
+#define	CLRSEQINTSTAT   		0x0c
+#define		CLRSEQ_SWTMRTO  	0x10
+#define		CLRSEQ_SEQINT   	0x08
+#define		CLRSEQ_SCSIINT  	0x04
+#define		CLRSEQ_PCIINT   	0x02
+#define		CLRSEQ_SPLTINT  	0x01
+
+#define	SEQINTSTAT      		0x0c
+#define		SEQ_SWTMRTO     	0x10
+#define		SEQ_SEQINT      	0x08
+#define		SEQ_SCSIINT     	0x04
+#define		SEQ_PCIINT      	0x02
+#define		SEQ_SPLTINT     	0x01
+
+#define	SWTIMER         		0x0e
+
+#define	SNSCB_QOFF      		0x10
+
+#define	SESCB_QOFF      		0x12
+
+#define	SDSCB_QOFF      		0x14
+
+#define	QOFF_CTLSTA     		0x16
+#define		EMPTY_SCB_AVAIL 	0x80
+#define		NEW_SCB_AVAIL   	0x40
+#define		SDSCB_ROLLOVR   	0x20
+#define		HS_MAILBOX_ACT  	0x10
+#define		SCB_QSIZE       	0x0f
+#define		SCB_QSIZE_16384 	0x0c
+#define		SCB_QSIZE_8192  	0x0b
+#define		SCB_QSIZE_4096  	0x0a
+#define		SCB_QSIZE_2048  	0x09
+#define		SCB_QSIZE_1024  	0x08
+#define		SCB_QSIZE_512   	0x07
+#define		SCB_QSIZE_256   	0x06
+#define		SCB_QSIZE_128   	0x05
+#define		SCB_QSIZE_64    	0x04
+#define		SCB_QSIZE_32    	0x03
+#define		SCB_QSIZE_16    	0x02
+#define		SCB_QSIZE_8     	0x01
+#define		SCB_QSIZE_4     	0x00
+
+#define	INTCTL          		0x18
+#define		SWTMINTMASK     	0x80
+#define		SWTMINTEN       	0x40
+#define		SWTIMER_START   	0x20
+#define		AUTOCLRCMDINT   	0x10
+#define		PCIINTEN        	0x08
+#define		SCSIINTEN       	0x04
+#define		SEQINTEN        	0x02
+#define		SPLTINTEN       	0x01
+
+#define	DFCNTRL         		0x19
+#define		SCSIENWRDIS     	0x40
+#define		SCSIENACK       	0x20
+#define		DIRECTIONACK    	0x04
+#define		FIFOFLUSHACK    	0x02
+#define		DIRECTIONEN     	0x01
+
+#define	DSCOMMAND0      		0x19
+#define		CACHETHEN       	0x80
+#define		DPARCKEN        	0x40
+#define		MPARCKEN        	0x20
+#define		EXTREQLCK       	0x10
+#define		DISABLE_TWATE   	0x02
+#define		CIOPARCKEN      	0x01
+
+#define	DFSTATUS        		0x1a
+#define		PRELOAD_AVAIL   	0x80
+#define		PKT_PRELOAD_AVAIL	0x40
+#define		MREQPEND        	0x10
+#define		HDONE           	0x08
+#define		DFTHRESH        	0x04
+#define		FIFOFULL        	0x02
+#define		FIFOEMP         	0x01
+
+#define	SG_CACHE_SHADOW 		0x1b
+#define		ODD_SEG         	0x04
+#define		LAST_SEG        	0x02
+#define		LAST_SEG_DONE   	0x01
+
+#define	ARBCTL          		0x1b
+#define		RESET_HARB      	0x80
+#define		RETRY_SWEN      	0x08
+#define		USE_TIME        	0x07
+
+#define	SG_CACHE_PRE    		0x1b
+
+#define	LQIN            		0x20
+
+#define	TYPEPTR         		0x20
+
+#define	TAGPTR          		0x21
+
+#define	LUNPTR          		0x22
+
+#define	DATALENPTR      		0x23
+
+#define	STATLENPTR      		0x24
+
+#define	CMDLENPTR       		0x25
+
+#define	ATTRPTR         		0x26
+
+#define	FLAGPTR         		0x27
+
+#define	CMDPTR          		0x28
+
+#define	QNEXTPTR        		0x29
+
+#define	IDPTR           		0x2a
+
+#define	ABRTBYTEPTR     		0x2b
+
+#define	ABRTBITPTR      		0x2c
+
+#define	MAXCMDBYTES     		0x2d
+
+#define	MAXCMD2RCV      		0x2e
+
+#define	SHORTTHRESH     		0x2f
+
+#define	LUNLEN          		0x30
+
+#define	CDBLIMIT        		0x31
+
+#define	MAXCMD          		0x32
+
+#define	MAXCMDCNT       		0x33
+
+#define	LQRSVD01        		0x34
+
+#define	LQRSVD16        		0x35
+
+#define	LQRSVD17        		0x36
+
+#define	CMDRSVD0        		0x37
+
+#define	LQCTL0          		0x38
+#define		LQITARGCLT      	0xc0
+#define		LQIINITGCLT     	0x30
+#define		LQ0TARGCLT      	0x0c
+#define		LQ0INITGCLT     	0x03
+
+#define	LQCTL1          		0x38
+#define		PCI2PCI         	0x04
+#define		SINGLECMD       	0x02
+#define		ABORTPENDING    	0x01
+
+#define	SCSBIST0        		0x39
+#define		GSBISTERR       	0x40
+#define		GSBISTDONE      	0x20
+#define		GSBISTRUN       	0x10
+#define		OSBISTERR       	0x04
+#define		OSBISTDONE      	0x02
+#define		OSBISTRUN       	0x01
+
+#define	LQCTL2          		0x39
+#define		LQIRETRY        	0x80
+#define		LQICONTINUE     	0x40
+#define		LQITOIDLE       	0x20
+#define		LQIPAUSE        	0x10
+#define		LQORETRY        	0x08
+#define		LQOCONTINUE     	0x04
+#define		LQOTOIDLE       	0x02
+#define		LQOPAUSE        	0x01
+
+#define	SCSBIST1        		0x3a
+#define		NTBISTERR       	0x04
+#define		NTBISTDONE      	0x02
+#define		NTBISTRUN       	0x01
+
+#define	SCSISEQ0        		0x3a
+#define		TEMODEO         	0x80
+#define		ENSELO          	0x40
+#define		ENARBO          	0x20
+#define		FORCEBUSFREE    	0x10
+#define		SCSIRSTO        	0x01
+
+#define	SCSISEQ1        		0x3b
+
+#define	SXFRCTL0        		0x3c
+#define		DFON            	0x80
+#define		DFPEXP          	0x40
+#define		BIOSCANCELEN    	0x10
+#define		SPIOEN          	0x08
+
+#define	BUSINITID       		0x3c
+
+#define	DLCOUNT         		0x3c
+
+#define	SXFRCTL1        		0x3d
+#define		BITBUCKET       	0x80
+#define		ENSACHK         	0x40
+#define		ENSPCHK         	0x20
+#define		STIMESEL        	0x18
+#define		ENSTIMER        	0x04
+#define		ACTNEGEN        	0x02
+#define		STPWEN          	0x01
+
+#define	BUSTARGID       		0x3e
+
+#define	SXFRCTL2        		0x3e
+#define		AUTORSTDIS      	0x10
+#define		CMDDMAEN        	0x08
+#define		ASU             	0x07
+
+#define	DFFSTAT         		0x3f
+#define		CURRFIFO        	0x03
+#define		FIFO1FREE       	0x20
+#define		FIFO0FREE       	0x10
+#define		CURRFIFO_NONE   	0x03
+#define		CURRFIFO_1      	0x01
+#define		CURRFIFO_0      	0x00
+
+#define	SCSISIGO        		0x40
+#define		CDO             	0x80
+#define		IOO             	0x40
+#define		MSGO            	0x20
+#define		ATNO            	0x10
+#define		SELO            	0x08
+#define		BSYO            	0x04
+#define		REQO            	0x02
+#define		ACKO            	0x01
+
+#define	MULTARGID       		0x40
+
+#define	SCSISIGI        		0x41
+#define		ATNI            	0x10
+#define		SELI            	0x08
+#define		BSYI            	0x04
+#define		REQI            	0x02
+#define		ACKI            	0x01
+
+#define	SCSIPHASE       		0x42
+#define		STATUS_PHASE    	0x20
+#define		COMMAND_PHASE   	0x10
+#define		MSG_IN_PHASE    	0x08
+#define		MSG_OUT_PHASE   	0x04
+#define		DATA_PHASE_MASK 	0x03
+#define		DATA_IN_PHASE   	0x02
+#define		DATA_OUT_PHASE  	0x01
+
+#define	SCSIDAT0_IMG    		0x43
+
+#define	SCSIDAT         		0x44
+
+#define	SCSIBUS         		0x46
+
+#define	TARGIDIN        		0x48
+#define		CLKOUT          	0x80
+#define		TARGID          	0x0f
+
+#define	SELID           		0x49
+#define		SELID_MASK      	0xf0
+#define		ONEBIT          	0x08
+
+#define	SBLKCTL         		0x4a
+#define		DIAGLEDEN       	0x80
+#define		DIAGLEDON       	0x40
+#define		ENAB40          	0x08
+#define		ENAB20          	0x04
+#define		SELWIDE         	0x02
+
+#define	OPTIONMODE      		0x4a
+#define		OPTIONMODE_DEFAULTS	0x02
+#define		BIOSCANCTL      	0x80
+#define		AUTOACKEN       	0x40
+#define		BIASCANCTL      	0x20
+#define		BUSFREEREV      	0x10
+#define		ENDGFORMCHK     	0x04
+#define		AUTO_MSGOUT_DE  	0x02
+
+#define	SSTAT0          		0x4b
+#define		TARGET          	0x80
+#define		SELDO           	0x40
+#define		SELDI           	0x20
+#define		SELINGO         	0x10
+#define		IOERR           	0x08
+#define		OVERRUN         	0x04
+#define		SPIORDY         	0x02
+#define		ARBDO           	0x01
+
+#define	CLRSINT0        		0x4b
+#define		CLRSELDO        	0x40
+#define		CLRSELDI        	0x20
+#define		CLRSELINGO      	0x10
+#define		CLRIOERR        	0x08
+#define		CLROVERRUN      	0x04
+#define		CLRSPIORDY      	0x02
+#define		CLRARBDO        	0x01
+
+#define	SIMODE0         		0x4b
+#define		ENSELDO         	0x40
+#define		ENSELDI         	0x20
+#define		ENSELINGO       	0x10
+#define		ENIOERR         	0x08
+#define		ENOVERRUN       	0x04
+#define		ENSPIORDY       	0x02
+#define		ENARBDO         	0x01
+
+#define	CLRSINT1        		0x4c
+#define		CLRSELTIMEO     	0x80
+#define		CLRATNO         	0x40
+#define		CLRSCSIRSTI     	0x20
+#define		CLRBUSFREE      	0x08
+#define		CLRSCSIPERR     	0x04
+#define		CLRSTRB2FAST    	0x02
+#define		CLRREQINIT      	0x01
+
+#define	SSTAT1          		0x4c
+#define		SELTO           	0x80
+#define		ATNTARG         	0x40
+#define		SCSIRSTI        	0x20
+#define		PHASEMIS        	0x10
+#define		BUSFREE         	0x08
+#define		SCSIPERR        	0x04
+#define		STRB2FAST       	0x02
+#define		REQINIT         	0x01
+
+#define	SSTAT2          		0x4d
+#define		BUSFREETIME     	0xc0
+#define		NONPACKREQ      	0x20
+#define		EXP_ACTIVE      	0x10
+#define		BSYX            	0x08
+#define		WIDE_RES        	0x04
+#define		SDONE           	0x02
+#define		DMADONE         	0x01
+#define		BUSFREE_DFF1    	0xc0
+#define		BUSFREE_DFF0    	0x80
+#define		BUSFREE_LQO     	0x40
+
+#define	CLRSINT2        		0x4d
+#define		CLRNONPACKREQ   	0x20
+#define		CLRWIDE_RES     	0x04
+#define		CLRSDONE        	0x02
+#define		CLRDMADONE      	0x01
+
+#define	SIMODE2         		0x4d
+#define		ENWIDE_RES      	0x04
+#define		ENSDONE         	0x02
+#define		ENDMADONE       	0x01
+
+#define	PERRDIAG        		0x4e
+#define		HIZERO          	0x80
+#define		HIPERR          	0x40
+#define		PREVPHASE       	0x20
+#define		PARITYERR       	0x10
+#define		AIPERR          	0x08
+#define		CRCERR          	0x04
+#define		DGFORMERR       	0x02
+#define		DTERR           	0x01
+
+#define	LQISTATE        		0x4e
+
+#define	SOFFCNT         		0x4f
+
+#define	LQOSTATE        		0x4f
+
+#define	LQISTAT0        		0x50
+#define		LQIATNQAS       	0x20
+#define		LQICRCT1        	0x10
+#define		LQICRCT2        	0x08
+#define		LQIBADLQT       	0x04
+#define		LQIATNLQ        	0x02
+#define		LQIATNCMD       	0x01
+
+#define	CLRLQIINT0      		0x50
+#define		CLRLQIATNQAS    	0x20
+#define		CLRLQICRCT1     	0x10
+#define		CLRLQICRCT2     	0x08
+#define		CLRLQIBADLQT    	0x04
+#define		CLRLQIATNLQ     	0x02
+#define		CLRLQIATNCMD    	0x01
+
+#define	LQIMODE0        		0x50
+#define		ENLQIATNQASK    	0x20
+#define		ENLQICRCT1      	0x10
+#define		ENLQICRCT2      	0x08
+#define		ENLQIBADLQT     	0x04
+#define		ENLQIATNLQ      	0x02
+#define		ENLQIATNCMD     	0x01
+
+#define	LQIMODE1        		0x51
+#define		ENLQIPHASE_LQ   	0x80
+#define		ENLQIPHASE_NLQ  	0x40
+#define		ENLIQABORT      	0x20
+#define		ENLQICRCI_LQ    	0x10
+#define		ENLQICRCI_NLQ   	0x08
+#define		ENLQIBADLQI     	0x04
+#define		ENLQIOVERI_LQ   	0x02
+#define		ENLQIOVERI_NLQ  	0x01
+
+#define	LQISTAT1        		0x51
+#define		LQIPHASE_LQ     	0x80
+#define		LQIPHASE_NLQ    	0x40
+#define		LQIABORT        	0x20
+#define		LQICRCI_LQ      	0x10
+#define		LQICRCI_NLQ     	0x08
+#define		LQIBADLQI       	0x04
+#define		LQIOVERI_LQ     	0x02
+#define		LQIOVERI_NLQ    	0x01
+
+#define	CLRLQIINT1      		0x51
+#define		CLRLQIPHASE_LQ  	0x80
+#define		CLRLQIPHASE_NLQ 	0x40
+#define		CLRLIQABORT     	0x20
+#define		CLRLQICRCI_LQ   	0x10
+#define		CLRLQICRCI_NLQ  	0x08
+#define		CLRLQIBADLQI    	0x04
+#define		CLRLQIOVERI_LQ  	0x02
+#define		CLRLQIOVERI_NLQ 	0x01
+
+#define	LQISTAT2        		0x52
+#define		PACKETIZED      	0x80
+#define		LQIPHASE_OUTPKT 	0x40
+#define		LQIWORKONLQ     	0x20
+#define		LQIWAITFIFO     	0x10
+#define		LQISTOPPKT      	0x08
+#define		LQISTOPLQ       	0x04
+#define		LQISTOPCMD      	0x02
+#define		LQIGSAVAIL      	0x01
+
+#define	SSTAT3          		0x53
+#define		NTRAMPERR       	0x02
+#define		OSRAMPERR       	0x01
+
+#define	SIMODE3         		0x53
+#define		ENNTRAMPERR     	0x02
+#define		ENOSRAMPERR     	0x01
+
+#define	CLRSINT3        		0x53
+#define		CLRNTRAMPERR    	0x02
+#define		CLROSRAMPERR    	0x01
+
+#define	LQOMODE0        		0x54
+#define		ENLQOTARGSCBPERR	0x10
+#define		ENLQOSTOPT2     	0x08
+#define		ENLQOATNLQ      	0x04
+#define		ENLQOATNPKT     	0x02
+#define		ENLQOTCRC       	0x01
+
+#define	LQOSTAT0        		0x54
+#define		LQOTARGSCBPERR  	0x10
+#define		LQOSTOPT2       	0x08
+#define		LQOATNLQ        	0x04
+#define		LQOATNPKT       	0x02
+#define		LQOTCRC         	0x01
+
+#define	CLRLQOINT0      		0x54
+#define		CLRLQOTARGSCBPERR	0x10
+#define		CLRLQOSTOPT2    	0x08
+#define		CLRLQOATNLQ     	0x04
+#define		CLRLQOATNPKT    	0x02
+#define		CLRLQOTCRC      	0x01
+
+#define	LQOSTAT1        		0x55
+#define		LQOINITSCBPERR  	0x10
+#define		LQOSTOPI2       	0x08
+#define		LQOBADQAS       	0x04
+#define		LQOBUSFREE      	0x02
+#define		LQOPHACHGINPKT  	0x01
+
+#define	CLRLQOINT1      		0x55
+#define		CLRLQOINITSCBPERR	0x10
+#define		CLRLQOSTOPI2    	0x08
+#define		CLRLQOBADQAS    	0x04
+#define		CLRLQOBUSFREE   	0x02
+#define		CLRLQOPHACHGINPKT	0x01
+
+#define	LQOMODE1        		0x55
+#define		ENLQOINITSCBPERR	0x10
+#define		ENLQOSTOPI2     	0x08
+#define		ENLQOBADQAS     	0x04
+#define		ENLQOBUSFREE    	0x02
+#define		ENLQOPHACHGINPKT	0x01
+
+#define	LQOSTAT2        		0x56
+#define		LQOPKT          	0xe0
+#define		LQOWAITFIFO     	0x10
+#define		LQOPHACHGOUTPKT 	0x02
+#define		LQOSTOP0        	0x01
+
+#define	OS_SPACE_CNT    		0x56
+
+#define	SIMODE1         		0x57
+#define		ENSELTIMO       	0x80
+#define		ENATNTARG       	0x40
+#define		ENSCSIRST       	0x20
+#define		ENPHASEMIS      	0x10
+#define		ENBUSFREE       	0x08
+#define		ENSCSIPERR      	0x04
+#define		ENSTRB2FAST     	0x02
+#define		ENREQINIT       	0x01
+
+#define	GSFIFO          		0x58
+
+#define	DFFSXFRCTL      		0x5a
+#define		DFFBITBUCKET    	0x08
+#define		CLRSHCNT        	0x04
+#define		CLRCHN          	0x02
+#define		RSTCHN          	0x01
+
+#define	LQOSCSCTL       		0x5a
+#define		LQOH2A_VERSION  	0x80
+#define		LQONOCHKOVER    	0x01
+
+#define	NEXTSCB         		0x5a
+
+#define	CLRSEQINTSRC    		0x5b
+#define		CLRCTXTDONE     	0x40
+#define		CLRSAVEPTRS     	0x20
+#define		CLRCFG4DATA     	0x10
+#define		CLRCFG4ISTAT    	0x08
+#define		CLRCFG4TSTAT    	0x04
+#define		CLRCFG4ICMD     	0x02
+#define		CLRCFG4TCMD     	0x01
+
+#define	SEQINTSRC       		0x5b
+#define		CTXTDONE        	0x40
+#define		SAVEPTRS        	0x20
+#define		CFG4DATA        	0x10
+#define		CFG4ISTAT       	0x08
+#define		CFG4TSTAT       	0x04
+#define		CFG4ICMD        	0x02
+#define		CFG4TCMD        	0x01
+
+#define	CURRSCB         		0x5c
+
+#define	SEQIMODE        		0x5c
+#define		ENCTXTDONE      	0x40
+#define		ENSAVEPTRS      	0x20
+#define		ENCFG4DATA      	0x10
+#define		ENCFG4ISTAT     	0x08
+#define		ENCFG4TSTAT     	0x04
+#define		ENCFG4ICMD      	0x02
+#define		ENCFG4TCMD      	0x01
+
+#define	MDFFSTAT        		0x5d
+#define		SHCNTNEGATIVE   	0x40
+#define		SHCNTMINUS1     	0x20
+#define		LASTSDONE       	0x10
+#define		SHVALID         	0x08
+#define		DLZERO          	0x04
+#define		DATAINFIFO      	0x02
+#define		FIFOFREE        	0x01
+
+#define	CRCCONTROL      		0x5d
+#define		CRCVALCHKEN     	0x40
+
+#define	DFFTAG          		0x5e
+
+#define	LASTSCB         		0x5e
+
+#define	SCSITEST        		0x5e
+#define		CNTRTEST        	0x08
+#define		SEL_TXPLL_DEBUG 	0x04
+
+#define	IOPDNCTL        		0x5f
+#define		DISABLE_OE      	0x80
+#define		PDN_IDIST       	0x04
+#define		PDN_DIFFSENSE   	0x01
+
+#define	SHADDR          		0x60
+
+#define	NEGOADDR        		0x60
+
+#define	DGRPCRCI        		0x60
+
+#define	NEGPERIOD       		0x61
+
+#define	PACKCRCI        		0x62
+
+#define	NEGOFFSET       		0x62
+
+#define	NEGPPROPTS      		0x63
+#define		PPROPT_PACE     	0x08
+#define		PPROPT_QAS      	0x04
+#define		PPROPT_DT       	0x02
+#define		PPROPT_IUT      	0x01
+
+#define	NEGCONOPTS      		0x64
+#define		ENSNAPSHOT      	0x40
+#define		RTI_WRTDIS      	0x20
+#define		RTI_OVRDTRN     	0x10
+#define		ENSLOWCRC       	0x08
+#define		ENAUTOATNI      	0x04
+#define		ENAUTOATNO      	0x02
+#define		WIDEXFER        	0x01
+
+#define	ANNEXCOL        		0x65
+
+#define	SCSCHKN         		0x66
+#define		STSELSKIDDIS    	0x40
+#define		CURRFIFODEF     	0x20
+#define		WIDERESEN       	0x10
+#define		SDONEMSKDIS     	0x08
+#define		DFFACTCLR       	0x04
+#define		SHVALIDSTDIS    	0x02
+#define		LSTSGCLRDIS     	0x01
+
+#define	ANNEXDAT        		0x66
+
+#define	IOWNID          		0x67
+
+#define	PLL960CTL0      		0x68
+
+#define	SHCNT           		0x68
+
+#define	TOWNID          		0x69
+
+#define	PLL960CTL1      		0x69
+
+#define	PLL960CNT0      		0x6a
+
+#define	XSIG            		0x6a
+
+#define	SELOID          		0x6b
+
+#define	PLL400CTL0      		0x6c
+#define		PLL_VCOSEL      	0x80
+#define		PLL_PWDN        	0x40
+#define		PLL_NS          	0x30
+#define		PLL_ENLUD       	0x08
+#define		PLL_ENLPF       	0x04
+#define		PLL_DLPF        	0x02
+#define		PLL_ENFBM       	0x01
+
+#define	FAIRNESS        		0x6c
+
+#define	PLL400CTL1      		0x6d
+#define		PLL_CNTEN       	0x80
+#define		PLL_CNTCLR      	0x40
+#define		PLL_RST         	0x01
+
+#define	PLL400CNT0      		0x6e
+
+#define	UNFAIRNESS      		0x6e
+
+#define	HADDR           		0x70
+
+#define	PLLDELAY        		0x70
+#define		SPLIT_DROP_REQ  	0x80
+
+#define	HODMAADR        		0x70
+
+#define	HODMACNT        		0x78
+
+#define	HCNT            		0x78
+
+#define	HODMAEN         		0x7a
+
+#define	SGHADDR         		0x7c
+
+#define	SCBHADDR        		0x7c
+
+#define	SGHCNT          		0x84
+
+#define	SCBHCNT         		0x84
+
+#define	DFF_THRSH       		0x88
+#define		WR_DFTHRSH      	0x70
+#define		RD_DFTHRSH      	0x07
+#define		WR_DFTHRSH_MAX  	0x70
+#define		WR_DFTHRSH_90   	0x60
+#define		WR_DFTHRSH_85   	0x50
+#define		WR_DFTHRSH_75   	0x40
+#define		WR_DFTHRSH_63   	0x30
+#define		WR_DFTHRSH_50   	0x20
+#define		WR_DFTHRSH_25   	0x10
+#define		RD_DFTHRSH_MAX  	0x07
+#define		RD_DFTHRSH_90   	0x06
+#define		RD_DFTHRSH_85   	0x05
+#define		RD_DFTHRSH_75   	0x04
+#define		RD_DFTHRSH_63   	0x03
+#define		RD_DFTHRSH_50   	0x02
+#define		RD_DFTHRSH_25   	0x01
+#define		WR_DFTHRSH_MIN  	0x00
+#define		RD_DFTHRSH_MIN  	0x00
+
+#define	ROMADDR         		0x8a
+
+#define	ROMCNTRL        		0x8d
+#define		ROMOP           	0xe0
+#define		ROMSPD          	0x18
+#define		REPEAT          	0x02
+#define		RDY             	0x01
+
+#define	ROMDATA         		0x8e
+
+#define	CMCRXMSG0       		0x90
+
+#define	ROENABLE        		0x90
+#define		MSIROEN         	0x20
+#define		OVLYROEN        	0x10
+#define		CMCROEN         	0x08
+#define		SGROEN          	0x04
+#define		DCH1ROEN        	0x02
+#define		DCH0ROEN        	0x01
+
+#define	OVLYRXMSG0      		0x90
+
+#define	DCHRXMSG0       		0x90
+
+#define	OVLYRXMSG1      		0x91
+
+#define	NSENABLE        		0x91
+#define		MSINSEN         	0x20
+#define		OVLYNSEN        	0x10
+#define		CMCNSEN         	0x08
+#define		SGNSEN          	0x04
+#define		DCH1NSEN        	0x02
+#define		DCH0NSEN        	0x01
+
+#define	DCHRXMSG1       		0x91
+
+#define	CMCRXMSG1       		0x91
+
+#define	DCHRXMSG2       		0x92
+
+#define	OVLYRXMSG2      		0x92
+
+#define	CMCRXMSG2       		0x92
+
+#define	OST             		0x92
+
+#define	DCHRXMSG3       		0x93
+
+#define	CMCRXMSG3       		0x93
+
+#define	PCIXCTL         		0x93
+#define		SERRPULSE       	0x80
+#define		UNEXPSCIEN      	0x20
+#define		SPLTSMADIS      	0x10
+#define		SPLTSTADIS      	0x08
+#define		SRSPDPEEN       	0x04
+#define		TSCSERREN       	0x02
+#define		CMPABCDIS       	0x01
+
+#define	OVLYRXMSG3      		0x93
+
+#define	OVLYSEQBCNT     		0x94
+
+#define	CMCSEQBCNT      		0x94
+
+#define	DCHSEQBCNT      		0x94
+
+#define	CMCSPLTSTAT0    		0x96
+
+#define	OVLYSPLTSTAT0   		0x96
+
+#define	DCHSPLTSTAT0    		0x96
+
+#define	DCHSPLTSTAT1    		0x97
+
+#define	CMCSPLTSTAT1    		0x97
+
+#define	OVLYSPLTSTAT1   		0x97
+
+#define	SGRXMSG0        		0x98
+#define		CDNUM           	0xf8
+#define		CFNUM           	0x07
+
+#define	SLVSPLTOUTADR0  		0x98
+#define		LOWER_ADDR      	0x7f
+
+#define	SGRXMSG1        		0x99
+#define		CBNUM           	0xff
+
+#define	SLVSPLTOUTADR1  		0x99
+#define		REQ_DNUM        	0xf8
+#define		REQ_FNUM        	0x07
+
+#define	SGRXMSG2        		0x9a
+#define		MINDEX          	0xff
+
+#define	SLVSPLTOUTADR2  		0x9a
+#define		REQ_BNUM        	0xff
+
+#define	SGRXMSG3        		0x9b
+#define		MCLASS          	0x0f
+
+#define	SLVSPLTOUTADR3  		0x9b
+#define		TAG_NUM         	0x1f
+#define		RLXORD          	0x10
+
+#define	SGSEQBCNT       		0x9c
+
+#define	SLVSPLTOUTATTR0 		0x9c
+#define		LOWER_BCNT      	0xff
+
+#define	SLVSPLTOUTATTR1 		0x9d
+#define		CMPLT_DNUM      	0xf8
+#define		CMPLT_FNUM      	0x07
+
+#define	SLVSPLTOUTATTR2 		0x9e
+#define		CMPLT_BNUM      	0xff
+
+#define	SGSPLTSTAT0     		0x9e
+#define		STAETERM        	0x80
+#define		SCBCERR         	0x40
+#define		SCADERR         	0x20
+#define		SCDATBUCKET     	0x10
+#define		CNTNOTCMPLT     	0x08
+#define		RXOVRUN         	0x04
+#define		RXSCEMSG        	0x02
+#define		RXSPLTRSP       	0x01
+
+#define	SFUNCT          		0x9f
+#define		TEST_GROUP      	0xf0
+#define		TEST_NUM        	0x0f
+
+#define	SGSPLTSTAT1     		0x9f
+#define		RXDATABUCKET    	0x01
+
+#define	DF0PCISTAT      		0xa0
+
+#define	REG0            		0xa0
+
+#define	DF1PCISTAT      		0xa1
+
+#define	SGPCISTAT       		0xa2
+
+#define	REG1            		0xa2
+
+#define	CMCPCISTAT      		0xa3
+
+#define	OVLYPCISTAT     		0xa4
+#define		SCAAPERR        	0x08
+#define		RDPERR          	0x04
+
+#define	REG_ISR         		0xa4
+
+#define	SG_STATE        		0xa6
+#define		FETCH_INPROG    	0x04
+#define		LOADING_NEEDED  	0x02
+#define		SEGS_AVAIL      	0x01
+
+#define	MSIPCISTAT      		0xa6
+#define		RMA             	0x20
+#define		RTA             	0x10
+#define		CLRPENDMSI      	0x08
+#define		DPR             	0x01
+
+#define	TARGPCISTAT     		0xa7
+#define		DPE             	0x80
+#define		SSE             	0x40
+#define		STA             	0x08
+#define		TWATERR         	0x02
+
+#define	DATA_COUNT_ODD  		0xa7
+
+#define	SCBPTR          		0xa8
+
+#define	CCSCBACNT       		0xab
+
+#define	SCBAUTOPTR      		0xab
+#define		AUSCBPTR_EN     	0x80
+#define		SCBPTR_ADDR     	0x38
+#define		SCBPTR_OFF      	0x07
+
+#define	CCSGADDR        		0xac
+
+#define	CCSCBADDR       		0xac
+
+#define	CCSCBADR_BK     		0xac
+
+#define	CMC_RAMBIST     		0xad
+#define		SG_ELEMENT_SIZE 	0x80
+#define		SCBRAMBIST_FAIL 	0x40
+#define		SG_BIST_FAIL    	0x20
+#define		SG_BIST_EN      	0x10
+#define		CMC_BUFFER_BIST_FAIL	0x02
+#define		CMC_BUFFER_BIST_EN	0x01
+
+#define	CCSGCTL         		0xad
+#define		CCSGEN          	0x0c
+#define		CCSGDONE        	0x80
+#define		SG_CACHE_AVAIL  	0x10
+#define		CCSGENACK       	0x08
+#define		SG_FETCH_REQ    	0x02
+#define		CCSGRESET       	0x01
+
+#define	CCSCBCTL        		0xad
+#define		CCSCBDONE       	0x80
+#define		ARRDONE         	0x40
+#define		CCARREN         	0x10
+#define		CCSCBEN         	0x08
+#define		CCSCBDIR        	0x04
+#define		CCSCBRESET      	0x01
+
+#define	CCSGRAM         		0xb0
+
+#define	FLEXADR         		0xb0
+
+#define	CCSCBRAM        		0xb0
+
+#define	FLEXCNT         		0xb3
+
+#define	FLEXDMASTAT     		0xb5
+#define		FLEXDMAERR      	0x02
+#define		FLEXDMADONE     	0x01
+
+#define	FLEXDATA        		0xb6
+
+#define	BRDDAT          		0xb8
+
+#define	BRDCTL          		0xb9
+#define		FLXARBACK       	0x80
+#define		FLXARBREQ       	0x40
+#define		BRDADDR         	0x38
+#define		BRDEN           	0x04
+#define		BRDRW           	0x02
+#define		BRDSTB          	0x01
+
+#define	SEEADR          		0xba
+
+#define	SEEDAT          		0xbc
+
+#define	SEECTL          		0xbe
+#define		SEEOP_EWEN      	0x40
+#define		SEEOP_WALL      	0x40
+#define		SEEOP_EWDS      	0x40
+#define		SEEOPCODE       	0x70
+#define		SEERST          	0x02
+#define		SEESTART        	0x01
+#define		SEEOP_ERASE     	0x70
+#define		SEEOP_READ      	0x60
+#define		SEEOP_WRITE     	0x50
+#define		SEEOP_ERAL      	0x40
+
+#define	SEESTAT         		0xbe
+#define		INIT_DONE       	0x80
+#define		LDALTID_L       	0x08
+#define		SEEARBACK       	0x04
+#define		SEEBUSY         	0x02
+
+#define	SCBCNT          		0xbf
+
+#define	DFWADDR         		0xc0
+
+#define	DSPFLTRCTL      		0xc0
+#define		FLTRDISABLE     	0x20
+#define		EDGESENSE       	0x10
+#define		DSPFCNTSEL      	0x0f
+
+#define	DSPDATACTL      		0xc1
+#define		BYPASSENAB      	0x80
+#define		DESQDIS         	0x10
+#define		RCVROFFSTDIS    	0x04
+#define		XMITOFFSTDIS    	0x02
+
+#define	DFRADDR         		0xc2
+
+#define	DSPREQCTL       		0xc2
+#define		MANREQCTL       	0xc0
+#define		MANREQDLY       	0x3f
+
+#define	DSPACKCTL       		0xc3
+#define		MANACKCTL       	0xc0
+#define		MANACKDLY       	0x3f
+
+#define	DFDAT           		0xc4
+
+#define	DSPSELECT       		0xc4
+#define		AUTOINCEN       	0x80
+#define		DSPSEL          	0x1f
+
+#define	WRTBIASCTL      		0xc5
+#define		AUTOXBCDIS      	0x80
+#define		XMITMANVAL      	0x3f
+
+#define	RCVRBIOSCTL     		0xc6
+#define		AUTORBCDIS      	0x80
+#define		RCVRMANVAL      	0x3f
+
+#define	WRTBIASCALC     		0xc7
+
+#define	DFPTRS          		0xc8
+
+#define	RCVRBIASCALC    		0xc8
+
+#define	DFBKPTR         		0xc9
+
+#define	SKEWCALC        		0xc9
+
+#define	DFDBCTL         		0xcb
+#define		DFF_CIO_WR_RDY  	0x20
+#define		DFF_CIO_RD_RDY  	0x10
+#define		DFF_DIR_ERR     	0x08
+#define		DFF_RAMBIST_FAIL	0x04
+#define		DFF_RAMBIST_DONE	0x02
+#define		DFF_RAMBIST_EN  	0x01
+
+#define	DFSCNT          		0xcc
+
+#define	DFBCNT          		0xce
+
+#define	OVLYADDR        		0xd4
+
+#define	SEQCTL0         		0xd6
+#define		PERRORDIS       	0x80
+#define		PAUSEDIS        	0x40
+#define		FAILDIS         	0x20
+#define		FASTMODE        	0x10
+#define		BRKADRINTEN     	0x08
+#define		STEP            	0x04
+#define		SEQRESET        	0x02
+#define		LOADRAM         	0x01
+
+#define	SEQCTL1         		0xd7
+#define		OVRLAY_DATA_CHK 	0x08
+#define		RAMBIST_DONE    	0x04
+#define		RAMBIST_FAIL    	0x02
+#define		RAMBIST_EN      	0x01
+
+#define	FLAGS           		0xd8
+#define		ZERO            	0x02
+#define		CARRY           	0x01
+
+#define	SEQINTCTL       		0xd9
+#define		INTVEC1DSL      	0x80
+#define		INT1_CONTEXT    	0x20
+#define		SCS_SEQ_INT1M1  	0x10
+#define		SCS_SEQ_INT1M0  	0x08
+#define		INTMASK2        	0x04
+#define		INTMASK1        	0x02
+#define		IRET            	0x01
+
+#define	SEQRAM          		0xda
+
+#define	PRGMCNT         		0xde
+
+#define	ACCUM           		0xe0
+
+#define	SINDEX          		0xe2
+
+#define	DINDEX          		0xe4
+
+#define	BRKADDR1        		0xe6
+#define		BRKDIS          	0x80
+
+#define	BRKADDR0        		0xe6
+
+#define	ALLONES         		0xe8
+
+#define	ALLZEROS        		0xea
+
+#define	NONE            		0xea
+
+#define	SINDIR          		0xec
+
+#define	DINDIR          		0xed
+
+#define	FUNCTION1       		0xf0
+
+#define	STACK           		0xf2
+
+#define	CURADDR         		0xf4
+
+#define	INTVEC1_ADDR    		0xf4
+
+#define	INTVEC2_ADDR    		0xf6
+
+#define	LASTADDR        		0xf6
+
+#define	LONGJMP_ADDR    		0xf8
+
+#define	LONGJMP_SCB     		0xfa
+
+#define	ACCUM_SAVE      		0xfc
+
+#define	WAITING_SCB_TAILS		0x100
+
+#define	AHD_PCI_CONFIG_BASE		0x100
+
+#define	SRAM_BASE       		0x100
+
+#define	WAITING_TID_HEAD		0x120
+
+#define	WAITING_TID_TAIL		0x122
+
+#define	NEXT_QUEUED_SCB_ADDR		0x124
+
+#define	COMPLETE_SCB_HEAD		0x128
+
+#define	COMPLETE_SCB_DMAINPROG_HEAD		0x12a
+
+#define	COMPLETE_DMA_SCB_HEAD		0x12c
+
+#define	QFREEZE_COUNT   		0x12e
+
+#define	SAVED_MODE      		0x130
+
+#define	MSG_OUT         		0x131
+
+#define	DMAPARAMS       		0x132
+#define		PRELOADEN       	0x80
+#define		WIDEODD         	0x40
+#define		SCSIEN          	0x20
+#define		SDMAEN          	0x10
+#define		SDMAENACK       	0x10
+#define		HDMAENACK       	0x08
+#define		HDMAEN          	0x08
+#define		DIRECTION       	0x04
+#define		FIFOFLUSH       	0x02
+#define		FIFORESET       	0x01
+
+#define	SEQ_FLAGS       		0x133
+#define		NOT_IDENTIFIED  	0x80
+#define		NO_CDB_SENT     	0x40
+#define		TARGET_CMD_IS_TAGGED	0x40
+#define		DPHASE          	0x20
+#define		TARG_CMD_PENDING	0x10
+#define		CMDPHASE_PENDING	0x08
+#define		DPHASE_PENDING  	0x04
+#define		SPHASE_PENDING  	0x02
+#define		NO_DISCONNECT   	0x01
+
+#define	SAVED_SCSIID    		0x134
+
+#define	SAVED_LUN       		0x135
+
+#define	LASTPHASE       		0x136
+#define		PHASE_MASK      	0xe0
+#define		CDI             	0x80
+#define		IOI             	0x40
+#define		MSGI            	0x20
+#define		P_BUSFREE       	0x01
+#define		P_MESGIN        	0xe0
+#define		P_STATUS        	0xc0
+#define		P_MESGOUT       	0xa0
+#define		P_COMMAND       	0x80
+#define		P_DATAIN_DT     	0x60
+#define		P_DATAIN        	0x40
+#define		P_DATAOUT_DT    	0x20
+#define		P_DATAOUT       	0x00
+
+#define	QOUTFIFO_ENTRY_VALID_TAG		0x137
+
+#define	SHARED_DATA_ADDR		0x138
+
+#define	QOUTFIFO_NEXT_ADDR		0x13c
+
+#define	KERNEL_TQINPOS  		0x140
+
+#define	TQINPOS         		0x141
+
+#define	ARG_1           		0x142
+#define	RETURN_1        		0x142
+#define		SEND_MSG        	0x80
+#define		SEND_SENSE      	0x40
+#define		SEND_REJ        	0x20
+#define		MSGOUT_PHASEMIS 	0x10
+#define		EXIT_MSG_LOOP   	0x08
+#define		CONT_MSG_LOOP_WRITE	0x04
+#define		CONT_MSG_LOOP_READ	0x03
+#define		CONT_MSG_LOOP_TARG	0x02
+
+#define	ARG_2           		0x143
+#define	RETURN_2        		0x143
+
+#define	LAST_MSG        		0x144
+
+#define	SCSISEQ_TEMPLATE		0x145
+#define		MANUALCTL       	0x40
+#define		ENSELI          	0x20
+#define		ENRSELI         	0x10
+#define		MANUALP         	0x0c
+#define		ENAUTOATNP      	0x02
+#define		ALTSTIM         	0x01
+
+#define	INITIATOR_TAG   		0x146
+
+#define	SEQ_FLAGS2      		0x147
+#define		SELECTOUT_QFROZEN	0x04
+#define		TARGET_MSG_PENDING	0x02
+
+#define	ALLOCFIFO_SCBPTR		0x148
+
+#define	INT_COALESSING_TIMER		0x14a
+
+#define	INT_COALESSING_MAXCMDS		0x14c
+
+#define	INT_COALESSING_MINCMDS		0x14d
+
+#define	CMDS_PENDING    		0x14e
+
+#define	INT_COALESSING_CMDCOUNT		0x150
+
+#define	LOCAL_HS_MAILBOX		0x151
+
+#define	CMDSIZE_TABLE   		0x152
+
+#define	SCB_BASE        		0x180
+
+#define	SCB_RESIDUAL_DATACNT		0x180
+#define	SCB_CDB_STORE   		0x180
+
+#define	SCB_RESIDUAL_SGPTR		0x184
+#define	SCB_CDB_PTR     		0x184
+#define		SG_ADDR_MASK    	0xf8
+#define		SG_OVERRUN_RESID	0x02
+
+#define	SCB_SCSI_STATUS 		0x188
+
+#define	SCB_TARGET_PHASES		0x189
+
+#define	SCB_TARGET_DATA_DIR		0x18a
+
+#define	SCB_TARGET_ITAG 		0x18b
+
+#define	SCB_SENSE_BUSADDR		0x18c
+#define	SCB_NEXT_COMPLETE		0x18c
+
+#define	SCB_TAG         		0x190
+
+#define	SCB_CDB_LEN     		0x192
+#define		SCB_CDB_LEN_PTR 	0x80
+
+#define	SCB_TASK_MANAGEMENT		0x193
+
+#define	SCB_NEXT        		0x194
+#define	SCB_NEXT_SCB_BUSADDR		0x194
+
+#define	SCB_NEXT2       		0x196
+
+#define	SCB_DATAPTR     		0x198
+
+#define	SCB_DATACNT     		0x1a0
+#define		SG_LAST_SEG     	0x80
+#define		SG_HIGH_ADDR_BITS	0x7f
+
+#define	SCB_SGPTR       		0x1a4
+#define		SG_STATUS_VALID 	0x04
+#define		SG_FULL_RESID   	0x02
+#define		SG_LIST_NULL    	0x01
+
+#define	SCB_CONTROL     		0x1a8
+#define		TARGET_SCB      	0x80
+#define		DISCENB         	0x40
+#define		TAG_ENB         	0x20
+#define		MK_MESSAGE      	0x10
+#define		STATUS_RCVD     	0x08
+#define		DISCONNECTED    	0x04
+#define		SCB_TAG_TYPE    	0x03
+
+#define	SCB_SCSIID      		0x1a9
+#define		TID             	0xf0
+#define		OID             	0x0f
+
+#define	SCB_LUN         		0x1aa
+#define		LID             	0xff
+
+#define	SCB_TASK_ATTRIBUTE		0x1ab
+
+#define	SCB_BUSADDR     		0x1ac
+
+#define	SCB_SPARE       		0x1b0
+#define	SCB_PKT_LUN     		0x1b0
+
+#define	SCB_DISCONNECTED_LISTS		0x1b8
+
+
+#define	AHD_TIMER_US_PER_TICK	0x19
+#define	SCB_TRANSFER_SIZE_FULL_LUN	0x38
+#define	STATUS_QUEUE_FULL	0x28
+#define	STATUS_BUSY	0x08
+#define	MAX_OFFSET_NON_PACED	0x7f
+#define	MAX_OFFSET_PACED	0xfe
+#define	BUS_32_BIT	0x02
+#define	CCSGADDR_MAX	0x80
+#define	TID_SHIFT	0x04
+#define	MK_MESSAGE_BIT_OFFSET	0x04
+#define	WRTBIASCTL_HP_DEFAULT	0x00
+#define	SEEOP_EWDS_ADDR	0x00
+#define	AHD_AMPLITUDE_SHIFT	0x00
+#define	AHD_AMPLITUDE_MASK	0x07
+#define	AHD_ANNEXCOL_AMPLITUDE	0x06
+#define	AHD_SLEWRATE_DEF_REVA	0x01
+#define	AHD_SLEWRATE_SHIFT	0x03
+#define	AHD_SLEWRATE_MASK	0x78
+#define	AHD_PRECOMP_CUTBACK_29	0x06
+#define	AHD_NUM_PER_DEV_ANNEXCOLS	0x04
+#define	B_CURRFIFO_0	0x02
+#define	NVRAM_SCB_OFFSET	0x2c
+#define	AHD_TIMER_MAX_US	0x18ffe7
+#define	AHD_TIMER_MAX_TICKS	0xffff
+#define	STATUS_PKT_SENSE	0xff
+#define	CMD_GROUP_CODE_SHIFT	0x05
+#define	AHD_SENSE_BUFSIZE	0x100
+#define	MAX_OFFSET_PACED_BUG	0x7f
+#define	BUS_8_BIT	0x00
+#define	STIMESEL_BUG_ADJ	0x08
+#define	STIMESEL_MIN	0x18
+#define	STIMESEL_SHIFT	0x03
+#define	CCSGRAM_MAXSEGS	0x10
+#define	INVALID_ADDR	0x80
+#define	TARGET_CMD_CMPLT	0xfe
+#define	SEEOP_WRAL_ADDR	0x40
+#define	SEEOP_ERAL_ADDR	0x80
+#define	AHD_AMPLITUDE_DEF	0x07
+#define	AHD_SLEWRATE_DEF_REVB	0x08
+#define	AHD_PRECOMP_CUTBACK_37	0x07
+#define	AHD_PRECOMP_CUTBACK_17	0x04
+#define	AHD_PRECOMP_SHIFT	0x00
+#define	AHD_PRECOMP_MASK	0x07
+#define	AHD_ANNEXCOL_PRECOMP_SLEW	0x04
+#define	SRC_MODE_SHIFT	0x00
+#define	PKT_OVERRUN_BUFSIZE	0x200
+#define	SCB_TRANSFER_SIZE_1BYTE_LUN	0x30
+#define	TARGET_DATA_IN	0x01
+#define	HOST_MSG	0xff
+#define	MAX_OFFSET	0xfe
+#define	BUS_16_BIT	0x01
+#define	CCSCBADDR_MAX	0x80
+#define	NUMDSPS 	0x14
+#define	SEEOP_EWEN_ADDR	0xc0
+#define	AHD_ANNEXCOL_PER_DEV0	0x04
+#define	DST_MODE_SHIFT	0x04
+
+
+/* Downloaded Constant Definitions */
+#define	SCB_TRANSFER_SIZE	0x06
+#define	PKT_OVERRUN_BUFOFFSET	0x05
+#define	SG_SIZEOF	0x04
+#define	SG_PREFETCH_ADDR_MASK	0x03
+#define	SG_PREFETCH_ALIGN_MASK	0x02
+#define	SG_PREFETCH_CNT_LIMIT	0x01
+#define	SG_PREFETCH_CNT	0x00
+#define	DOWNLOAD_CONST_COUNT	0x07
+
+
+/* Exported Labels */
+#define	LABEL_seq_isr 	0x25a
+#define	LABEL_timer_isr	0x256
diff -Nru a/drivers/scsi/aic7xxx/aic79xx_reg_print.c_shipped b/drivers/scsi/aic7xxx/aic79xx_reg_print.c_shipped
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aic79xx_reg_print.c_shipped	Mon Dec 23 21:22:03 2002
@@ -0,0 +1,3630 @@
+/*
+ * DO NOT EDIT - This file is automatically generated
+ *		 from the following source files:
+ *
+ * $Id: //depot/aic7xxx/aic7xxx/aic79xx.seq#77 $
+ * $Id: //depot/aic7xxx/aic7xxx/aic79xx.reg#59 $
+ */
+
+#include "aic79xx_osm.h"
+
+static ahd_reg_parse_entry_t MODE_PTR_parse_table[] = {
+	{ "SRC_MODE",		0x07, 0x07 },
+	{ "DST_MODE",		0x70, 0x70 }
+};
+
+int
+ahd_mode_ptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(MODE_PTR_parse_table, 2, "MODE_PTR",
+	    0x00, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t INTSTAT_parse_table[] = {
+	{ "SPLTINT",		0x01, 0x01 },
+	{ "CMDCMPLT",		0x02, 0x02 },
+	{ "SEQINT",		0x04, 0x04 },
+	{ "SCSIINT",		0x08, 0x08 },
+	{ "PCIINT",		0x10, 0x10 },
+	{ "SWTMINT",		0x20, 0x20 },
+	{ "BRKADRINT",		0x40, 0x40 },
+	{ "HWERRINT",		0x80, 0x80 },
+	{ "INT_PEND",		0xff, 0xff }
+};
+
+int
+ahd_intstat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(INTSTAT_parse_table, 9, "INTSTAT",
+	    0x01, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SEQINTCODE_parse_table[] = {
+	{ "NO_SEQINT",		0x00, 0xff },
+	{ "BAD_PHASE",		0x01, 0xff },
+	{ "SEND_REJECT",	0x02, 0xff },
+	{ "PROTO_VIOLATION",	0x03, 0xff },
+	{ "NO_MATCH",		0x04, 0xff },
+	{ "IGN_WIDE_RES",	0x05, 0xff },
+	{ "PDATA_REINIT",	0x06, 0xff },
+	{ "HOST_MSG_LOOP",	0x07, 0xff },
+	{ "BAD_STATUS",		0x08, 0xff },
+	{ "DATA_OVERRUN",	0x09, 0xff },
+	{ "MKMSG_FAILED",	0x0a, 0xff },
+	{ "MISSED_BUSFREE",	0x0b, 0xff },
+	{ "DUMP_CARD_STATE",	0x0c, 0xff },
+	{ "ILLEGAL_PHASE",	0x0d, 0xff },
+	{ "INVALID_SEQINT",	0x0e, 0xff },
+	{ "CFG4ISTAT_INTR",	0x0f, 0xff },
+	{ "STATUS_OVERRUN",	0x10, 0xff },
+	{ "CFG4OVERRUN",	0x11, 0xff },
+	{ "ENTERING_NONPACK",	0x12, 0xff },
+	{ "TRACEPOINT0",	0x13, 0xff },
+	{ "TRACEPOINT1",	0x14, 0xff },
+	{ "TRACEPOINT2",	0x15, 0xff },
+	{ "TRACEPOINT3",	0x16, 0xff },
+	{ "SAW_HWERR",		0x17, 0xff }
+};
+
+int
+ahd_seqintcode_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SEQINTCODE_parse_table, 24, "SEQINTCODE",
+	    0x02, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CLRINT_parse_table[] = {
+	{ "CLRSPLTINT",		0x01, 0x01 },
+	{ "CLRCMDINT",		0x02, 0x02 },
+	{ "CLRSEQINT",		0x04, 0x04 },
+	{ "CLRSCSIINT",		0x08, 0x08 },
+	{ "CLRPCIINT",		0x10, 0x10 },
+	{ "CLRSWTMINT",		0x20, 0x20 },
+	{ "CLRBRKADRINT",	0x40, 0x40 },
+	{ "CLRHWERRINT",	0x80, 0x80 }
+};
+
+int
+ahd_clrint_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CLRINT_parse_table, 8, "CLRINT",
+	    0x03, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t ERROR_parse_table[] = {
+	{ "DSCTMOUT",		0x02, 0x02 },
+	{ "ILLOPCODE",		0x04, 0x04 },
+	{ "SQPARERR",		0x08, 0x08 },
+	{ "DPARERR",		0x10, 0x10 },
+	{ "MPARERR",		0x20, 0x20 },
+	{ "CIOACCESFAIL",	0x40, 0x40 },
+	{ "CIOPARERR",		0x80, 0x80 }
+};
+
+int
+ahd_error_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(ERROR_parse_table, 7, "ERROR",
+	    0x04, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CLRERR_parse_table[] = {
+	{ "CLRDSCTMOUT",	0x02, 0x02 },
+	{ "CLRILLOPCODE",	0x04, 0x04 },
+	{ "CLRSQPARERR",	0x08, 0x08 },
+	{ "CLRDPARERR",		0x10, 0x10 },
+	{ "CLRMPARERR",		0x20, 0x20 },
+	{ "CLRCIOACCESFAIL",	0x40, 0x40 },
+	{ "CLRCIOPARERR",	0x80, 0x80 }
+};
+
+int
+ahd_clrerr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CLRERR_parse_table, 7, "CLRERR",
+	    0x04, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t HCNTRL_parse_table[] = {
+	{ "CHIPRST",		0x01, 0x01 },
+	{ "CHIPRSTACK",		0x01, 0x01 },
+	{ "INTEN",		0x02, 0x02 },
+	{ "PAUSE",		0x04, 0x04 },
+	{ "SWTIMER_START_B",	0x08, 0x08 },
+	{ "SWINT",		0x10, 0x10 },
+	{ "POWRDN",		0x40, 0x40 },
+	{ "SEQ_RESET",		0x80, 0x80 }
+};
+
+int
+ahd_hcntrl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(HCNTRL_parse_table, 8, "HCNTRL",
+	    0x05, regvalue, cur_col, wrap));
+}
+
+int
+ahd_hnscb_qoff_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "HNSCB_QOFF",
+	    0x06, regvalue, cur_col, wrap));
+}
+
+int
+ahd_hescb_qoff_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "HESCB_QOFF",
+	    0x08, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t HS_MAILBOX_parse_table[] = {
+	{ "ENINT_COALESS",	0x40, 0x40 },
+	{ "HOST_TQINPOS",	0x80, 0x80 }
+};
+
+int
+ahd_hs_mailbox_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(HS_MAILBOX_parse_table, 2, "HS_MAILBOX",
+	    0x0b, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CLRSEQINTSTAT_parse_table[] = {
+	{ "CLRSEQ_SPLTINT",	0x01, 0x01 },
+	{ "CLRSEQ_PCIINT",	0x02, 0x02 },
+	{ "CLRSEQ_SCSIINT",	0x04, 0x04 },
+	{ "CLRSEQ_SEQINT",	0x08, 0x08 },
+	{ "CLRSEQ_SWTMRTO",	0x10, 0x10 }
+};
+
+int
+ahd_clrseqintstat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CLRSEQINTSTAT_parse_table, 5, "CLRSEQINTSTAT",
+	    0x0c, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SEQINTSTAT_parse_table[] = {
+	{ "SEQ_SPLTINT",	0x01, 0x01 },
+	{ "SEQ_PCIINT",		0x02, 0x02 },
+	{ "SEQ_SCSIINT",	0x04, 0x04 },
+	{ "SEQ_SEQINT",		0x08, 0x08 },
+	{ "SEQ_SWTMRTO",	0x10, 0x10 }
+};
+
+int
+ahd_seqintstat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SEQINTSTAT_parse_table, 5, "SEQINTSTAT",
+	    0x0c, regvalue, cur_col, wrap));
+}
+
+int
+ahd_swtimer_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SWTIMER",
+	    0x0e, regvalue, cur_col, wrap));
+}
+
+int
+ahd_snscb_qoff_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SNSCB_QOFF",
+	    0x10, regvalue, cur_col, wrap));
+}
+
+int
+ahd_sescb_qoff_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SESCB_QOFF",
+	    0x12, regvalue, cur_col, wrap));
+}
+
+int
+ahd_sdscb_qoff_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SDSCB_QOFF",
+	    0x14, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t QOFF_CTLSTA_parse_table[] = {
+	{ "SCB_QSIZE_4",	0x00, 0x0f },
+	{ "SCB_QSIZE_8",	0x01, 0x0f },
+	{ "SCB_QSIZE_16",	0x02, 0x0f },
+	{ "SCB_QSIZE_32",	0x03, 0x0f },
+	{ "SCB_QSIZE_64",	0x04, 0x0f },
+	{ "SCB_QSIZE_128",	0x05, 0x0f },
+	{ "SCB_QSIZE_256",	0x06, 0x0f },
+	{ "SCB_QSIZE_512",	0x07, 0x0f },
+	{ "SCB_QSIZE_1024",	0x08, 0x0f },
+	{ "SCB_QSIZE_2048",	0x09, 0x0f },
+	{ "SCB_QSIZE_4096",	0x0a, 0x0f },
+	{ "SCB_QSIZE_8192",	0x0b, 0x0f },
+	{ "SCB_QSIZE_16384",	0x0c, 0x0f },
+	{ "SCB_QSIZE",		0x0f, 0x0f },
+	{ "HS_MAILBOX_ACT",	0x10, 0x10 },
+	{ "SDSCB_ROLLOVR",	0x20, 0x20 },
+	{ "NEW_SCB_AVAIL",	0x40, 0x40 },
+	{ "EMPTY_SCB_AVAIL",	0x80, 0x80 }
+};
+
+int
+ahd_qoff_ctlsta_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(QOFF_CTLSTA_parse_table, 18, "QOFF_CTLSTA",
+	    0x16, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t INTCTL_parse_table[] = {
+	{ "SPLTINTEN",		0x01, 0x01 },
+	{ "SEQINTEN",		0x02, 0x02 },
+	{ "SCSIINTEN",		0x04, 0x04 },
+	{ "PCIINTEN",		0x08, 0x08 },
+	{ "AUTOCLRCMDINT",	0x10, 0x10 },
+	{ "SWTIMER_START",	0x20, 0x20 },
+	{ "SWTMINTEN",		0x40, 0x40 },
+	{ "SWTMINTMASK",	0x80, 0x80 }
+};
+
+int
+ahd_intctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(INTCTL_parse_table, 8, "INTCTL",
+	    0x18, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DFCNTRL_parse_table[] = {
+	{ "DIRECTIONEN",	0x01, 0x01 },
+	{ "FIFOFLUSH",		0x02, 0x02 },
+	{ "FIFOFLUSHACK",	0x02, 0x02 },
+	{ "DIRECTION",		0x04, 0x04 },
+	{ "DIRECTIONACK",	0x04, 0x04 },
+	{ "HDMAEN",		0x08, 0x08 },
+	{ "HDMAENACK",		0x08, 0x08 },
+	{ "SCSIEN",		0x20, 0x20 },
+	{ "SCSIENACK",		0x20, 0x20 },
+	{ "SCSIENWRDIS",	0x40, 0x40 },
+	{ "PRELOADEN",		0x80, 0x80 }
+};
+
+int
+ahd_dfcntrl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DFCNTRL_parse_table, 11, "DFCNTRL",
+	    0x19, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DSCOMMAND0_parse_table[] = {
+	{ "CIOPARCKEN",		0x01, 0x01 },
+	{ "DISABLE_TWATE",	0x02, 0x02 },
+	{ "EXTREQLCK",		0x10, 0x10 },
+	{ "MPARCKEN",		0x20, 0x20 },
+	{ "DPARCKEN",		0x40, 0x40 },
+	{ "CACHETHEN",		0x80, 0x80 }
+};
+
+int
+ahd_dscommand0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DSCOMMAND0_parse_table, 6, "DSCOMMAND0",
+	    0x19, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DFSTATUS_parse_table[] = {
+	{ "FIFOEMP",		0x01, 0x01 },
+	{ "FIFOFULL",		0x02, 0x02 },
+	{ "DFTHRESH",		0x04, 0x04 },
+	{ "HDONE",		0x08, 0x08 },
+	{ "MREQPEND",		0x10, 0x10 },
+	{ "PKT_PRELOAD_AVAIL",	0x40, 0x40 },
+	{ "PRELOAD_AVAIL",	0x80, 0x80 }
+};
+
+int
+ahd_dfstatus_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DFSTATUS_parse_table, 7, "DFSTATUS",
+	    0x1a, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SG_CACHE_SHADOW_parse_table[] = {
+	{ "LAST_SEG_DONE",	0x01, 0x01 },
+	{ "LAST_SEG",		0x02, 0x02 },
+	{ "ODD_SEG",		0x04, 0x04 },
+	{ "SG_ADDR_MASK",	0xf8, 0xf8 }
+};
+
+int
+ahd_sg_cache_shadow_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SG_CACHE_SHADOW_parse_table, 4, "SG_CACHE_SHADOW",
+	    0x1b, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t ARBCTL_parse_table[] = {
+	{ "USE_TIME",		0x07, 0x07 },
+	{ "RETRY_SWEN",		0x08, 0x08 },
+	{ "RESET_HARB",		0x80, 0x80 }
+};
+
+int
+ahd_arbctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(ARBCTL_parse_table, 3, "ARBCTL",
+	    0x1b, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SG_CACHE_PRE_parse_table[] = {
+	{ "LAST_SEG",		0x02, 0x02 },
+	{ "ODD_SEG",		0x04, 0x04 },
+	{ "SG_ADDR_MASK",	0xf8, 0xf8 }
+};
+
+int
+ahd_sg_cache_pre_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SG_CACHE_PRE_parse_table, 3, "SG_CACHE_PRE",
+	    0x1b, regvalue, cur_col, wrap));
+}
+
+int
+ahd_lqin_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "LQIN",
+	    0x20, regvalue, cur_col, wrap));
+}
+
+int
+ahd_typeptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "TYPEPTR",
+	    0x20, regvalue, cur_col, wrap));
+}
+
+int
+ahd_tagptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "TAGPTR",
+	    0x21, regvalue, cur_col, wrap));
+}
+
+int
+ahd_lunptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "LUNPTR",
+	    0x22, regvalue, cur_col, wrap));
+}
+
+int
+ahd_datalenptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "DATALENPTR",
+	    0x23, regvalue, cur_col, wrap));
+}
+
+int
+ahd_statlenptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "STATLENPTR",
+	    0x24, regvalue, cur_col, wrap));
+}
+
+int
+ahd_cmdlenptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "CMDLENPTR",
+	    0x25, regvalue, cur_col, wrap));
+}
+
+int
+ahd_attrptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "ATTRPTR",
+	    0x26, regvalue, cur_col, wrap));
+}
+
+int
+ahd_flagptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "FLAGPTR",
+	    0x27, regvalue, cur_col, wrap));
+}
+
+int
+ahd_cmdptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "CMDPTR",
+	    0x28, regvalue, cur_col, wrap));
+}
+
+int
+ahd_qnextptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "QNEXTPTR",
+	    0x29, regvalue, cur_col, wrap));
+}
+
+int
+ahd_idptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "IDPTR",
+	    0x2a, regvalue, cur_col, wrap));
+}
+
+int
+ahd_abrtbyteptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "ABRTBYTEPTR",
+	    0x2b, regvalue, cur_col, wrap));
+}
+
+int
+ahd_abrtbitptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "ABRTBITPTR",
+	    0x2c, regvalue, cur_col, wrap));
+}
+
+int
+ahd_maxcmdbytes_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "MAXCMDBYTES",
+	    0x2d, regvalue, cur_col, wrap));
+}
+
+int
+ahd_maxcmd2rcv_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "MAXCMD2RCV",
+	    0x2e, regvalue, cur_col, wrap));
+}
+
+int
+ahd_shortthresh_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SHORTTHRESH",
+	    0x2f, regvalue, cur_col, wrap));
+}
+
+int
+ahd_lunlen_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "LUNLEN",
+	    0x30, regvalue, cur_col, wrap));
+}
+
+int
+ahd_cdblimit_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "CDBLIMIT",
+	    0x31, regvalue, cur_col, wrap));
+}
+
+int
+ahd_maxcmd_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "MAXCMD",
+	    0x32, regvalue, cur_col, wrap));
+}
+
+int
+ahd_maxcmdcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "MAXCMDCNT",
+	    0x33, regvalue, cur_col, wrap));
+}
+
+int
+ahd_lqrsvd01_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "LQRSVD01",
+	    0x34, regvalue, cur_col, wrap));
+}
+
+int
+ahd_lqrsvd16_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "LQRSVD16",
+	    0x35, regvalue, cur_col, wrap));
+}
+
+int
+ahd_lqrsvd17_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "LQRSVD17",
+	    0x36, regvalue, cur_col, wrap));
+}
+
+int
+ahd_cmdrsvd0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "CMDRSVD0",
+	    0x37, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t LQCTL0_parse_table[] = {
+	{ "LQ0INITGCLT",	0x03, 0x03 },
+	{ "LQ0TARGCLT",		0x0c, 0x0c },
+	{ "LQIINITGCLT",	0x30, 0x30 },
+	{ "LQITARGCLT",		0xc0, 0xc0 }
+};
+
+int
+ahd_lqctl0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(LQCTL0_parse_table, 4, "LQCTL0",
+	    0x38, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t LQCTL1_parse_table[] = {
+	{ "ABORTPENDING",	0x01, 0x01 },
+	{ "SINGLECMD",		0x02, 0x02 },
+	{ "PCI2PCI",		0x04, 0x04 }
+};
+
+int
+ahd_lqctl1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(LQCTL1_parse_table, 3, "LQCTL1",
+	    0x38, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCSBIST0_parse_table[] = {
+	{ "OSBISTRUN",		0x01, 0x01 },
+	{ "OSBISTDONE",		0x02, 0x02 },
+	{ "OSBISTERR",		0x04, 0x04 },
+	{ "GSBISTRUN",		0x10, 0x10 },
+	{ "GSBISTDONE",		0x20, 0x20 },
+	{ "GSBISTERR",		0x40, 0x40 }
+};
+
+int
+ahd_scsbist0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCSBIST0_parse_table, 6, "SCSBIST0",
+	    0x39, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t LQCTL2_parse_table[] = {
+	{ "LQOPAUSE",		0x01, 0x01 },
+	{ "LQOTOIDLE",		0x02, 0x02 },
+	{ "LQOCONTINUE",	0x04, 0x04 },
+	{ "LQORETRY",		0x08, 0x08 },
+	{ "LQIPAUSE",		0x10, 0x10 },
+	{ "LQITOIDLE",		0x20, 0x20 },
+	{ "LQICONTINUE",	0x40, 0x40 },
+	{ "LQIRETRY",		0x80, 0x80 }
+};
+
+int
+ahd_lqctl2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(LQCTL2_parse_table, 8, "LQCTL2",
+	    0x39, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCSBIST1_parse_table[] = {
+	{ "NTBISTRUN",		0x01, 0x01 },
+	{ "NTBISTDONE",		0x02, 0x02 },
+	{ "NTBISTERR",		0x04, 0x04 }
+};
+
+int
+ahd_scsbist1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCSBIST1_parse_table, 3, "SCSBIST1",
+	    0x3a, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCSISEQ0_parse_table[] = {
+	{ "SCSIRSTO",		0x01, 0x01 },
+	{ "FORCEBUSFREE",	0x10, 0x10 },
+	{ "ENARBO",		0x20, 0x20 },
+	{ "ENSELO",		0x40, 0x40 },
+	{ "TEMODEO",		0x80, 0x80 }
+};
+
+int
+ahd_scsiseq0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCSISEQ0_parse_table, 5, "SCSISEQ0",
+	    0x3a, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCSISEQ1_parse_table[] = {
+	{ "ALTSTIM",		0x01, 0x01 },
+	{ "ENAUTOATNP",		0x02, 0x02 },
+	{ "MANUALP",		0x0c, 0x0c },
+	{ "ENRSELI",		0x10, 0x10 },
+	{ "ENSELI",		0x20, 0x20 },
+	{ "MANUALCTL",		0x40, 0x40 }
+};
+
+int
+ahd_scsiseq1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCSISEQ1_parse_table, 6, "SCSISEQ1",
+	    0x3b, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SXFRCTL0_parse_table[] = {
+	{ "SPIOEN",		0x08, 0x08 },
+	{ "BIOSCANCELEN",	0x10, 0x10 },
+	{ "DFPEXP",		0x40, 0x40 },
+	{ "DFON",		0x80, 0x80 }
+};
+
+int
+ahd_sxfrctl0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SXFRCTL0_parse_table, 4, "SXFRCTL0",
+	    0x3c, regvalue, cur_col, wrap));
+}
+
+int
+ahd_businitid_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "BUSINITID",
+	    0x3c, regvalue, cur_col, wrap));
+}
+
+int
+ahd_dlcount_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "DLCOUNT",
+	    0x3c, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SXFRCTL1_parse_table[] = {
+	{ "STPWEN",		0x01, 0x01 },
+	{ "ACTNEGEN",		0x02, 0x02 },
+	{ "ENSTIMER",		0x04, 0x04 },
+	{ "STIMESEL",		0x18, 0x18 },
+	{ "ENSPCHK",		0x20, 0x20 },
+	{ "ENSACHK",		0x40, 0x40 },
+	{ "BITBUCKET",		0x80, 0x80 }
+};
+
+int
+ahd_sxfrctl1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SXFRCTL1_parse_table, 7, "SXFRCTL1",
+	    0x3d, regvalue, cur_col, wrap));
+}
+
+int
+ahd_bustargid_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "BUSTARGID",
+	    0x3e, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SXFRCTL2_parse_table[] = {
+	{ "ASU",		0x07, 0x07 },
+	{ "CMDDMAEN",		0x08, 0x08 },
+	{ "AUTORSTDIS",		0x10, 0x10 }
+};
+
+int
+ahd_sxfrctl2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SXFRCTL2_parse_table, 3, "SXFRCTL2",
+	    0x3e, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DFFSTAT_parse_table[] = {
+	{ "CURRFIFO_0",		0x00, 0x03 },
+	{ "CURRFIFO_1",		0x01, 0x03 },
+	{ "CURRFIFO_NONE",	0x03, 0x03 },
+	{ "FIFO0FREE",		0x10, 0x10 },
+	{ "FIFO1FREE",		0x20, 0x20 },
+	{ "CURRFIFO",		0x03, 0x03 }
+};
+
+int
+ahd_dffstat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DFFSTAT_parse_table, 6, "DFFSTAT",
+	    0x3f, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCSISIGO_parse_table[] = {
+	{ "P_DATAOUT",		0x00, 0xe0 },
+	{ "P_DATAOUT_DT",	0x20, 0xe0 },
+	{ "P_DATAIN",		0x40, 0xe0 },
+	{ "P_DATAIN_DT",	0x60, 0xe0 },
+	{ "P_COMMAND",		0x80, 0xe0 },
+	{ "P_MESGOUT",		0xa0, 0xe0 },
+	{ "P_STATUS",		0xc0, 0xe0 },
+	{ "P_MESGIN",		0xe0, 0xe0 },
+	{ "ACKO",		0x01, 0x01 },
+	{ "REQO",		0x02, 0x02 },
+	{ "BSYO",		0x04, 0x04 },
+	{ "SELO",		0x08, 0x08 },
+	{ "ATNO",		0x10, 0x10 },
+	{ "MSGO",		0x20, 0x20 },
+	{ "IOO",		0x40, 0x40 },
+	{ "CDO",		0x80, 0x80 },
+	{ "PHASE_MASK",		0xe0, 0xe0 }
+};
+
+int
+ahd_scsisigo_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCSISIGO_parse_table, 17, "SCSISIGO",
+	    0x40, regvalue, cur_col, wrap));
+}
+
+int
+ahd_multargid_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "MULTARGID",
+	    0x40, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCSISIGI_parse_table[] = {
+	{ "P_DATAOUT",		0x00, 0xe0 },
+	{ "P_DATAOUT_DT",	0x20, 0xe0 },
+	{ "P_DATAIN",		0x40, 0xe0 },
+	{ "P_DATAIN_DT",	0x60, 0xe0 },
+	{ "P_COMMAND",		0x80, 0xe0 },
+	{ "P_MESGOUT",		0xa0, 0xe0 },
+	{ "P_STATUS",		0xc0, 0xe0 },
+	{ "P_MESGIN",		0xe0, 0xe0 },
+	{ "ACKI",		0x01, 0x01 },
+	{ "REQI",		0x02, 0x02 },
+	{ "BSYI",		0x04, 0x04 },
+	{ "SELI",		0x08, 0x08 },
+	{ "ATNI",		0x10, 0x10 },
+	{ "MSGI",		0x20, 0x20 },
+	{ "IOI",		0x40, 0x40 },
+	{ "CDI",		0x80, 0x80 },
+	{ "PHASE_MASK",		0xe0, 0xe0 }
+};
+
+int
+ahd_scsisigi_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCSISIGI_parse_table, 17, "SCSISIGI",
+	    0x41, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCSIPHASE_parse_table[] = {
+	{ "DATA_OUT_PHASE",	0x01, 0x03 },
+	{ "DATA_IN_PHASE",	0x02, 0x03 },
+	{ "DATA_PHASE_MASK",	0x03, 0x03 },
+	{ "MSG_OUT_PHASE",	0x04, 0x04 },
+	{ "MSG_IN_PHASE",	0x08, 0x08 },
+	{ "COMMAND_PHASE",	0x10, 0x10 },
+	{ "STATUS_PHASE",	0x20, 0x20 }
+};
+
+int
+ahd_scsiphase_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCSIPHASE_parse_table, 7, "SCSIPHASE",
+	    0x42, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scsidat0_img_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCSIDAT0_IMG",
+	    0x43, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scsidat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCSIDAT",
+	    0x44, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scsibus_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCSIBUS",
+	    0x46, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t TARGIDIN_parse_table[] = {
+	{ "TARGID",		0x0f, 0x0f },
+	{ "CLKOUT",		0x80, 0x80 }
+};
+
+int
+ahd_targidin_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(TARGIDIN_parse_table, 2, "TARGIDIN",
+	    0x48, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SELID_parse_table[] = {
+	{ "ONEBIT",		0x08, 0x08 },
+	{ "SELID_MASK",		0xf0, 0xf0 }
+};
+
+int
+ahd_selid_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SELID_parse_table, 2, "SELID",
+	    0x49, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SBLKCTL_parse_table[] = {
+	{ "SELWIDE",		0x02, 0x02 },
+	{ "ENAB20",		0x04, 0x04 },
+	{ "ENAB40",		0x08, 0x08 },
+	{ "DIAGLEDON",		0x40, 0x40 },
+	{ "DIAGLEDEN",		0x80, 0x80 }
+};
+
+int
+ahd_sblkctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SBLKCTL_parse_table, 5, "SBLKCTL",
+	    0x4a, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t OPTIONMODE_parse_table[] = {
+	{ "AUTO_MSGOUT_DE",	0x02, 0x02 },
+	{ "ENDGFORMCHK",	0x04, 0x04 },
+	{ "BUSFREEREV",		0x10, 0x10 },
+	{ "BIASCANCTL",		0x20, 0x20 },
+	{ "AUTOACKEN",		0x40, 0x40 },
+	{ "BIOSCANCTL",		0x80, 0x80 },
+	{ "OPTIONMODE_DEFAULTS",0x02, 0x02 }
+};
+
+int
+ahd_optionmode_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(OPTIONMODE_parse_table, 7, "OPTIONMODE",
+	    0x4a, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SSTAT0_parse_table[] = {
+	{ "ARBDO",		0x01, 0x01 },
+	{ "SPIORDY",		0x02, 0x02 },
+	{ "OVERRUN",		0x04, 0x04 },
+	{ "IOERR",		0x08, 0x08 },
+	{ "SELINGO",		0x10, 0x10 },
+	{ "SELDI",		0x20, 0x20 },
+	{ "SELDO",		0x40, 0x40 },
+	{ "TARGET",		0x80, 0x80 }
+};
+
+int
+ahd_sstat0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SSTAT0_parse_table, 8, "SSTAT0",
+	    0x4b, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CLRSINT0_parse_table[] = {
+	{ "CLRARBDO",		0x01, 0x01 },
+	{ "CLRSPIORDY",		0x02, 0x02 },
+	{ "CLROVERRUN",		0x04, 0x04 },
+	{ "CLRIOERR",		0x08, 0x08 },
+	{ "CLRSELINGO",		0x10, 0x10 },
+	{ "CLRSELDI",		0x20, 0x20 },
+	{ "CLRSELDO",		0x40, 0x40 }
+};
+
+int
+ahd_clrsint0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CLRSINT0_parse_table, 7, "CLRSINT0",
+	    0x4b, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SIMODE0_parse_table[] = {
+	{ "ENARBDO",		0x01, 0x01 },
+	{ "ENSPIORDY",		0x02, 0x02 },
+	{ "ENOVERRUN",		0x04, 0x04 },
+	{ "ENIOERR",		0x08, 0x08 },
+	{ "ENSELINGO",		0x10, 0x10 },
+	{ "ENSELDI",		0x20, 0x20 },
+	{ "ENSELDO",		0x40, 0x40 }
+};
+
+int
+ahd_simode0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SIMODE0_parse_table, 7, "SIMODE0",
+	    0x4b, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CLRSINT1_parse_table[] = {
+	{ "CLRREQINIT",		0x01, 0x01 },
+	{ "CLRSTRB2FAST",	0x02, 0x02 },
+	{ "CLRSCSIPERR",	0x04, 0x04 },
+	{ "CLRBUSFREE",		0x08, 0x08 },
+	{ "CLRSCSIRSTI",	0x20, 0x20 },
+	{ "CLRATNO",		0x40, 0x40 },
+	{ "CLRSELTIMEO",	0x80, 0x80 }
+};
+
+int
+ahd_clrsint1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CLRSINT1_parse_table, 7, "CLRSINT1",
+	    0x4c, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SSTAT1_parse_table[] = {
+	{ "REQINIT",		0x01, 0x01 },
+	{ "STRB2FAST",		0x02, 0x02 },
+	{ "SCSIPERR",		0x04, 0x04 },
+	{ "BUSFREE",		0x08, 0x08 },
+	{ "PHASEMIS",		0x10, 0x10 },
+	{ "SCSIRSTI",		0x20, 0x20 },
+	{ "ATNTARG",		0x40, 0x40 },
+	{ "SELTO",		0x80, 0x80 }
+};
+
+int
+ahd_sstat1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SSTAT1_parse_table, 8, "SSTAT1",
+	    0x4c, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SSTAT2_parse_table[] = {
+	{ "BUSFREE_LQO",	0x40, 0xc0 },
+	{ "BUSFREE_DFF0",	0x80, 0xc0 },
+	{ "BUSFREE_DFF1",	0xc0, 0xc0 },
+	{ "DMADONE",		0x01, 0x01 },
+	{ "SDONE",		0x02, 0x02 },
+	{ "WIDE_RES",		0x04, 0x04 },
+	{ "BSYX",		0x08, 0x08 },
+	{ "EXP_ACTIVE",		0x10, 0x10 },
+	{ "NONPACKREQ",		0x20, 0x20 },
+	{ "BUSFREETIME",	0xc0, 0xc0 }
+};
+
+int
+ahd_sstat2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SSTAT2_parse_table, 10, "SSTAT2",
+	    0x4d, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CLRSINT2_parse_table[] = {
+	{ "CLRDMADONE",		0x01, 0x01 },
+	{ "CLRSDONE",		0x02, 0x02 },
+	{ "CLRWIDE_RES",	0x04, 0x04 },
+	{ "CLRNONPACKREQ",	0x20, 0x20 }
+};
+
+int
+ahd_clrsint2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CLRSINT2_parse_table, 4, "CLRSINT2",
+	    0x4d, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SIMODE2_parse_table[] = {
+	{ "ENDMADONE",		0x01, 0x01 },
+	{ "ENSDONE",		0x02, 0x02 },
+	{ "ENWIDE_RES",		0x04, 0x04 }
+};
+
+int
+ahd_simode2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SIMODE2_parse_table, 3, "SIMODE2",
+	    0x4d, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t PERRDIAG_parse_table[] = {
+	{ "DTERR",		0x01, 0x01 },
+	{ "DGFORMERR",		0x02, 0x02 },
+	{ "CRCERR",		0x04, 0x04 },
+	{ "AIPERR",		0x08, 0x08 },
+	{ "PARITYERR",		0x10, 0x10 },
+	{ "PREVPHASE",		0x20, 0x20 },
+	{ "HIPERR",		0x40, 0x40 },
+	{ "HIZERO",		0x80, 0x80 }
+};
+
+int
+ahd_perrdiag_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(PERRDIAG_parse_table, 8, "PERRDIAG",
+	    0x4e, regvalue, cur_col, wrap));
+}
+
+int
+ahd_lqistate_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "LQISTATE",
+	    0x4e, regvalue, cur_col, wrap));
+}
+
+int
+ahd_soffcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SOFFCNT",
+	    0x4f, regvalue, cur_col, wrap));
+}
+
+int
+ahd_lqostate_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "LQOSTATE",
+	    0x4f, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t LQISTAT0_parse_table[] = {
+	{ "LQIATNCMD",		0x01, 0x01 },
+	{ "LQIATNLQ",		0x02, 0x02 },
+	{ "LQIBADLQT",		0x04, 0x04 },
+	{ "LQICRCT2",		0x08, 0x08 },
+	{ "LQICRCT1",		0x10, 0x10 },
+	{ "LQIATNQAS",		0x20, 0x20 }
+};
+
+int
+ahd_lqistat0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(LQISTAT0_parse_table, 6, "LQISTAT0",
+	    0x50, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CLRLQIINT0_parse_table[] = {
+	{ "CLRLQIATNCMD",	0x01, 0x01 },
+	{ "CLRLQIATNLQ",	0x02, 0x02 },
+	{ "CLRLQIBADLQT",	0x04, 0x04 },
+	{ "CLRLQICRCT2",	0x08, 0x08 },
+	{ "CLRLQICRCT1",	0x10, 0x10 },
+	{ "CLRLQIATNQAS",	0x20, 0x20 }
+};
+
+int
+ahd_clrlqiint0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CLRLQIINT0_parse_table, 6, "CLRLQIINT0",
+	    0x50, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t LQIMODE0_parse_table[] = {
+	{ "ENLQIATNCMD",	0x01, 0x01 },
+	{ "ENLQIATNLQ",		0x02, 0x02 },
+	{ "ENLQIBADLQT",	0x04, 0x04 },
+	{ "ENLQICRCT2",		0x08, 0x08 },
+	{ "ENLQICRCT1",		0x10, 0x10 },
+	{ "ENLQIATNQASK",	0x20, 0x20 }
+};
+
+int
+ahd_lqimode0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(LQIMODE0_parse_table, 6, "LQIMODE0",
+	    0x50, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t LQIMODE1_parse_table[] = {
+	{ "ENLQIOVERI_NLQ",	0x01, 0x01 },
+	{ "ENLQIOVERI_LQ",	0x02, 0x02 },
+	{ "ENLQIBADLQI",	0x04, 0x04 },
+	{ "ENLQICRCI_NLQ",	0x08, 0x08 },
+	{ "ENLQICRCI_LQ",	0x10, 0x10 },
+	{ "ENLIQABORT",		0x20, 0x20 },
+	{ "ENLQIPHASE_NLQ",	0x40, 0x40 },
+	{ "ENLQIPHASE_LQ",	0x80, 0x80 }
+};
+
+int
+ahd_lqimode1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(LQIMODE1_parse_table, 8, "LQIMODE1",
+	    0x51, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t LQISTAT1_parse_table[] = {
+	{ "LQIOVERI_NLQ",	0x01, 0x01 },
+	{ "LQIOVERI_LQ",	0x02, 0x02 },
+	{ "LQIBADLQI",		0x04, 0x04 },
+	{ "LQICRCI_NLQ",	0x08, 0x08 },
+	{ "LQICRCI_LQ",		0x10, 0x10 },
+	{ "LQIABORT",		0x20, 0x20 },
+	{ "LQIPHASE_NLQ",	0x40, 0x40 },
+	{ "LQIPHASE_LQ",	0x80, 0x80 }
+};
+
+int
+ahd_lqistat1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(LQISTAT1_parse_table, 8, "LQISTAT1",
+	    0x51, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CLRLQIINT1_parse_table[] = {
+	{ "CLRLQIOVERI_NLQ",	0x01, 0x01 },
+	{ "CLRLQIOVERI_LQ",	0x02, 0x02 },
+	{ "CLRLQIBADLQI",	0x04, 0x04 },
+	{ "CLRLQICRCI_NLQ",	0x08, 0x08 },
+	{ "CLRLQICRCI_LQ",	0x10, 0x10 },
+	{ "CLRLIQABORT",	0x20, 0x20 },
+	{ "CLRLQIPHASE_NLQ",	0x40, 0x40 },
+	{ "CLRLQIPHASE_LQ",	0x80, 0x80 }
+};
+
+int
+ahd_clrlqiint1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CLRLQIINT1_parse_table, 8, "CLRLQIINT1",
+	    0x51, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t LQISTAT2_parse_table[] = {
+	{ "LQIGSAVAIL",		0x01, 0x01 },
+	{ "LQISTOPCMD",		0x02, 0x02 },
+	{ "LQISTOPLQ",		0x04, 0x04 },
+	{ "LQISTOPPKT",		0x08, 0x08 },
+	{ "LQIWAITFIFO",	0x10, 0x10 },
+	{ "LQIWORKONLQ",	0x20, 0x20 },
+	{ "LQIPHASE_OUTPKT",	0x40, 0x40 },
+	{ "PACKETIZED",		0x80, 0x80 }
+};
+
+int
+ahd_lqistat2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(LQISTAT2_parse_table, 8, "LQISTAT2",
+	    0x52, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SSTAT3_parse_table[] = {
+	{ "OSRAMPERR",		0x01, 0x01 },
+	{ "NTRAMPERR",		0x02, 0x02 }
+};
+
+int
+ahd_sstat3_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SSTAT3_parse_table, 2, "SSTAT3",
+	    0x53, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SIMODE3_parse_table[] = {
+	{ "ENOSRAMPERR",	0x01, 0x01 },
+	{ "ENNTRAMPERR",	0x02, 0x02 }
+};
+
+int
+ahd_simode3_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SIMODE3_parse_table, 2, "SIMODE3",
+	    0x53, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CLRSINT3_parse_table[] = {
+	{ "CLROSRAMPERR",	0x01, 0x01 },
+	{ "CLRNTRAMPERR",	0x02, 0x02 }
+};
+
+int
+ahd_clrsint3_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CLRSINT3_parse_table, 2, "CLRSINT3",
+	    0x53, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t LQOMODE0_parse_table[] = {
+	{ "ENLQOTCRC",		0x01, 0x01 },
+	{ "ENLQOATNPKT",	0x02, 0x02 },
+	{ "ENLQOATNLQ",		0x04, 0x04 },
+	{ "ENLQOSTOPT2",	0x08, 0x08 },
+	{ "ENLQOTARGSCBPERR",	0x10, 0x10 }
+};
+
+int
+ahd_lqomode0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(LQOMODE0_parse_table, 5, "LQOMODE0",
+	    0x54, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t LQOSTAT0_parse_table[] = {
+	{ "LQOTCRC",		0x01, 0x01 },
+	{ "LQOATNPKT",		0x02, 0x02 },
+	{ "LQOATNLQ",		0x04, 0x04 },
+	{ "LQOSTOPT2",		0x08, 0x08 },
+	{ "LQOTARGSCBPERR",	0x10, 0x10 }
+};
+
+int
+ahd_lqostat0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(LQOSTAT0_parse_table, 5, "LQOSTAT0",
+	    0x54, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CLRLQOINT0_parse_table[] = {
+	{ "CLRLQOTCRC",		0x01, 0x01 },
+	{ "CLRLQOATNPKT",	0x02, 0x02 },
+	{ "CLRLQOATNLQ",	0x04, 0x04 },
+	{ "CLRLQOSTOPT2",	0x08, 0x08 },
+	{ "CLRLQOTARGSCBPERR",	0x10, 0x10 }
+};
+
+int
+ahd_clrlqoint0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CLRLQOINT0_parse_table, 5, "CLRLQOINT0",
+	    0x54, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t LQOSTAT1_parse_table[] = {
+	{ "LQOPHACHGINPKT",	0x01, 0x01 },
+	{ "LQOBUSFREE",		0x02, 0x02 },
+	{ "LQOBADQAS",		0x04, 0x04 },
+	{ "LQOSTOPI2",		0x08, 0x08 },
+	{ "LQOINITSCBPERR",	0x10, 0x10 }
+};
+
+int
+ahd_lqostat1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(LQOSTAT1_parse_table, 5, "LQOSTAT1",
+	    0x55, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CLRLQOINT1_parse_table[] = {
+	{ "CLRLQOPHACHGINPKT",	0x01, 0x01 },
+	{ "CLRLQOBUSFREE",	0x02, 0x02 },
+	{ "CLRLQOBADQAS",	0x04, 0x04 },
+	{ "CLRLQOSTOPI2",	0x08, 0x08 },
+	{ "CLRLQOINITSCBPERR",	0x10, 0x10 }
+};
+
+int
+ahd_clrlqoint1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CLRLQOINT1_parse_table, 5, "CLRLQOINT1",
+	    0x55, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t LQOMODE1_parse_table[] = {
+	{ "ENLQOPHACHGINPKT",	0x01, 0x01 },
+	{ "ENLQOBUSFREE",	0x02, 0x02 },
+	{ "ENLQOBADQAS",	0x04, 0x04 },
+	{ "ENLQOSTOPI2",	0x08, 0x08 },
+	{ "ENLQOINITSCBPERR",	0x10, 0x10 }
+};
+
+int
+ahd_lqomode1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(LQOMODE1_parse_table, 5, "LQOMODE1",
+	    0x55, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t LQOSTAT2_parse_table[] = {
+	{ "LQOSTOP0",		0x01, 0x01 },
+	{ "LQOPHACHGOUTPKT",	0x02, 0x02 },
+	{ "LQOWAITFIFO",	0x10, 0x10 },
+	{ "LQOPKT",		0xe0, 0xe0 }
+};
+
+int
+ahd_lqostat2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(LQOSTAT2_parse_table, 4, "LQOSTAT2",
+	    0x56, regvalue, cur_col, wrap));
+}
+
+int
+ahd_os_space_cnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "OS_SPACE_CNT",
+	    0x56, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SIMODE1_parse_table[] = {
+	{ "ENREQINIT",		0x01, 0x01 },
+	{ "ENSTRB2FAST",	0x02, 0x02 },
+	{ "ENSCSIPERR",		0x04, 0x04 },
+	{ "ENBUSFREE",		0x08, 0x08 },
+	{ "ENPHASEMIS",		0x10, 0x10 },
+	{ "ENSCSIRST",		0x20, 0x20 },
+	{ "ENATNTARG",		0x40, 0x40 },
+	{ "ENSELTIMO",		0x80, 0x80 }
+};
+
+int
+ahd_simode1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SIMODE1_parse_table, 8, "SIMODE1",
+	    0x57, regvalue, cur_col, wrap));
+}
+
+int
+ahd_gsfifo_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "GSFIFO",
+	    0x58, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DFFSXFRCTL_parse_table[] = {
+	{ "RSTCHN",		0x01, 0x01 },
+	{ "CLRCHN",		0x02, 0x02 },
+	{ "CLRSHCNT",		0x04, 0x04 },
+	{ "DFFBITBUCKET",	0x08, 0x08 }
+};
+
+int
+ahd_dffsxfrctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DFFSXFRCTL_parse_table, 4, "DFFSXFRCTL",
+	    0x5a, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t LQOSCSCTL_parse_table[] = {
+	{ "LQONOCHKOVER",	0x01, 0x01 },
+	{ "LQOH2A_VERSION",	0x80, 0x80 }
+};
+
+int
+ahd_lqoscsctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(LQOSCSCTL_parse_table, 2, "LQOSCSCTL",
+	    0x5a, regvalue, cur_col, wrap));
+}
+
+int
+ahd_nextscb_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "NEXTSCB",
+	    0x5a, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CLRSEQINTSRC_parse_table[] = {
+	{ "CLRCFG4TCMD",	0x01, 0x01 },
+	{ "CLRCFG4ICMD",	0x02, 0x02 },
+	{ "CLRCFG4TSTAT",	0x04, 0x04 },
+	{ "CLRCFG4ISTAT",	0x08, 0x08 },
+	{ "CLRCFG4DATA",	0x10, 0x10 },
+	{ "CLRSAVEPTRS",	0x20, 0x20 },
+	{ "CLRCTXTDONE",	0x40, 0x40 }
+};
+
+int
+ahd_clrseqintsrc_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CLRSEQINTSRC_parse_table, 7, "CLRSEQINTSRC",
+	    0x5b, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SEQINTSRC_parse_table[] = {
+	{ "CFG4TCMD",		0x01, 0x01 },
+	{ "CFG4ICMD",		0x02, 0x02 },
+	{ "CFG4TSTAT",		0x04, 0x04 },
+	{ "CFG4ISTAT",		0x08, 0x08 },
+	{ "CFG4DATA",		0x10, 0x10 },
+	{ "SAVEPTRS",		0x20, 0x20 },
+	{ "CTXTDONE",		0x40, 0x40 }
+};
+
+int
+ahd_seqintsrc_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SEQINTSRC_parse_table, 7, "SEQINTSRC",
+	    0x5b, regvalue, cur_col, wrap));
+}
+
+int
+ahd_currscb_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "CURRSCB",
+	    0x5c, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SEQIMODE_parse_table[] = {
+	{ "ENCFG4TCMD",		0x01, 0x01 },
+	{ "ENCFG4ICMD",		0x02, 0x02 },
+	{ "ENCFG4TSTAT",	0x04, 0x04 },
+	{ "ENCFG4ISTAT",	0x08, 0x08 },
+	{ "ENCFG4DATA",		0x10, 0x10 },
+	{ "ENSAVEPTRS",		0x20, 0x20 },
+	{ "ENCTXTDONE",		0x40, 0x40 }
+};
+
+int
+ahd_seqimode_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SEQIMODE_parse_table, 7, "SEQIMODE",
+	    0x5c, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t MDFFSTAT_parse_table[] = {
+	{ "FIFOFREE",		0x01, 0x01 },
+	{ "DATAINFIFO",		0x02, 0x02 },
+	{ "DLZERO",		0x04, 0x04 },
+	{ "SHVALID",		0x08, 0x08 },
+	{ "LASTSDONE",		0x10, 0x10 },
+	{ "SHCNTMINUS1",	0x20, 0x20 },
+	{ "SHCNTNEGATIVE",	0x40, 0x40 }
+};
+
+int
+ahd_mdffstat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(MDFFSTAT_parse_table, 7, "MDFFSTAT",
+	    0x5d, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CRCCONTROL_parse_table[] = {
+	{ "CRCVALCHKEN",	0x40, 0x40 }
+};
+
+int
+ahd_crccontrol_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CRCCONTROL_parse_table, 1, "CRCCONTROL",
+	    0x5d, regvalue, cur_col, wrap));
+}
+
+int
+ahd_dfftag_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "DFFTAG",
+	    0x5e, regvalue, cur_col, wrap));
+}
+
+int
+ahd_lastscb_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "LASTSCB",
+	    0x5e, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCSITEST_parse_table[] = {
+	{ "SEL_TXPLL_DEBUG",	0x04, 0x04 },
+	{ "CNTRTEST",		0x08, 0x08 }
+};
+
+int
+ahd_scsitest_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCSITEST_parse_table, 2, "SCSITEST",
+	    0x5e, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t IOPDNCTL_parse_table[] = {
+	{ "PDN_DIFFSENSE",	0x01, 0x01 },
+	{ "PDN_IDIST",		0x04, 0x04 },
+	{ "DISABLE_OE",		0x80, 0x80 }
+};
+
+int
+ahd_iopdnctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(IOPDNCTL_parse_table, 3, "IOPDNCTL",
+	    0x5f, regvalue, cur_col, wrap));
+}
+
+int
+ahd_shaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SHADDR",
+	    0x60, regvalue, cur_col, wrap));
+}
+
+int
+ahd_negoaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "NEGOADDR",
+	    0x60, regvalue, cur_col, wrap));
+}
+
+int
+ahd_dgrpcrci_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "DGRPCRCI",
+	    0x60, regvalue, cur_col, wrap));
+}
+
+int
+ahd_negperiod_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "NEGPERIOD",
+	    0x61, regvalue, cur_col, wrap));
+}
+
+int
+ahd_packcrci_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "PACKCRCI",
+	    0x62, regvalue, cur_col, wrap));
+}
+
+int
+ahd_negoffset_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "NEGOFFSET",
+	    0x62, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t NEGPPROPTS_parse_table[] = {
+	{ "PPROPT_IUT",		0x01, 0x01 },
+	{ "PPROPT_DT",		0x02, 0x02 },
+	{ "PPROPT_QAS",		0x04, 0x04 },
+	{ "PPROPT_PACE",	0x08, 0x08 }
+};
+
+int
+ahd_negppropts_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NEGPPROPTS_parse_table, 4, "NEGPPROPTS",
+	    0x63, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t NEGCONOPTS_parse_table[] = {
+	{ "WIDEXFER",		0x01, 0x01 },
+	{ "ENAUTOATNO",		0x02, 0x02 },
+	{ "ENAUTOATNI",		0x04, 0x04 },
+	{ "ENSLOWCRC",		0x08, 0x08 },
+	{ "RTI_OVRDTRN",	0x10, 0x10 },
+	{ "RTI_WRTDIS",		0x20, 0x20 },
+	{ "ENSNAPSHOT",		0x40, 0x40 }
+};
+
+int
+ahd_negconopts_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NEGCONOPTS_parse_table, 7, "NEGCONOPTS",
+	    0x64, regvalue, cur_col, wrap));
+}
+
+int
+ahd_annexcol_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "ANNEXCOL",
+	    0x65, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCSCHKN_parse_table[] = {
+	{ "LSTSGCLRDIS",	0x01, 0x01 },
+	{ "SHVALIDSTDIS",	0x02, 0x02 },
+	{ "DFFACTCLR",		0x04, 0x04 },
+	{ "SDONEMSKDIS",	0x08, 0x08 },
+	{ "WIDERESEN",		0x10, 0x10 },
+	{ "CURRFIFODEF",	0x20, 0x20 },
+	{ "STSELSKIDDIS",	0x40, 0x40 }
+};
+
+int
+ahd_scschkn_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCSCHKN_parse_table, 7, "SCSCHKN",
+	    0x66, regvalue, cur_col, wrap));
+}
+
+int
+ahd_annexdat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "ANNEXDAT",
+	    0x66, regvalue, cur_col, wrap));
+}
+
+int
+ahd_iownid_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "IOWNID",
+	    0x67, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t PLL960CTL0_parse_table[] = {
+	{ "PLL_ENFBM",		0x01, 0x01 },
+	{ "PLL_DLPF",		0x02, 0x02 },
+	{ "PLL_ENLPF",		0x04, 0x04 },
+	{ "PLL_ENLUD",		0x08, 0x08 },
+	{ "PLL_NS",		0x30, 0x30 },
+	{ "PLL_PWDN",		0x40, 0x40 },
+	{ "PLL_VCOSEL",		0x80, 0x80 }
+};
+
+int
+ahd_pll960ctl0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(PLL960CTL0_parse_table, 7, "PLL960CTL0",
+	    0x68, regvalue, cur_col, wrap));
+}
+
+int
+ahd_shcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SHCNT",
+	    0x68, regvalue, cur_col, wrap));
+}
+
+int
+ahd_townid_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "TOWNID",
+	    0x69, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t PLL960CTL1_parse_table[] = {
+	{ "PLL_RST",		0x01, 0x01 },
+	{ "PLL_CNTCLR",		0x40, 0x40 },
+	{ "PLL_CNTEN",		0x80, 0x80 }
+};
+
+int
+ahd_pll960ctl1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(PLL960CTL1_parse_table, 3, "PLL960CTL1",
+	    0x69, regvalue, cur_col, wrap));
+}
+
+int
+ahd_pll960cnt0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "PLL960CNT0",
+	    0x6a, regvalue, cur_col, wrap));
+}
+
+int
+ahd_xsig_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "XSIG",
+	    0x6a, regvalue, cur_col, wrap));
+}
+
+int
+ahd_seloid_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SELOID",
+	    0x6b, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t PLL400CTL0_parse_table[] = {
+	{ "PLL_ENFBM",		0x01, 0x01 },
+	{ "PLL_DLPF",		0x02, 0x02 },
+	{ "PLL_ENLPF",		0x04, 0x04 },
+	{ "PLL_ENLUD",		0x08, 0x08 },
+	{ "PLL_NS",		0x30, 0x30 },
+	{ "PLL_PWDN",		0x40, 0x40 },
+	{ "PLL_VCOSEL",		0x80, 0x80 }
+};
+
+int
+ahd_pll400ctl0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(PLL400CTL0_parse_table, 7, "PLL400CTL0",
+	    0x6c, regvalue, cur_col, wrap));
+}
+
+int
+ahd_fairness_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "FAIRNESS",
+	    0x6c, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t PLL400CTL1_parse_table[] = {
+	{ "PLL_RST",		0x01, 0x01 },
+	{ "PLL_CNTCLR",		0x40, 0x40 },
+	{ "PLL_CNTEN",		0x80, 0x80 }
+};
+
+int
+ahd_pll400ctl1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(PLL400CTL1_parse_table, 3, "PLL400CTL1",
+	    0x6d, regvalue, cur_col, wrap));
+}
+
+int
+ahd_pll400cnt0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "PLL400CNT0",
+	    0x6e, regvalue, cur_col, wrap));
+}
+
+int
+ahd_unfairness_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "UNFAIRNESS",
+	    0x6e, regvalue, cur_col, wrap));
+}
+
+int
+ahd_haddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "HADDR",
+	    0x70, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t PLLDELAY_parse_table[] = {
+	{ "SPLIT_DROP_REQ",	0x80, 0x80 }
+};
+
+int
+ahd_plldelay_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(PLLDELAY_parse_table, 1, "PLLDELAY",
+	    0x70, regvalue, cur_col, wrap));
+}
+
+int
+ahd_hodmaadr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "HODMAADR",
+	    0x70, regvalue, cur_col, wrap));
+}
+
+int
+ahd_hodmacnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "HODMACNT",
+	    0x78, regvalue, cur_col, wrap));
+}
+
+int
+ahd_hcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "HCNT",
+	    0x78, regvalue, cur_col, wrap));
+}
+
+int
+ahd_hodmaen_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "HODMAEN",
+	    0x7a, regvalue, cur_col, wrap));
+}
+
+int
+ahd_sghaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SGHADDR",
+	    0x7c, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scbhaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCBHADDR",
+	    0x7c, regvalue, cur_col, wrap));
+}
+
+int
+ahd_sghcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SGHCNT",
+	    0x84, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scbhcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCBHCNT",
+	    0x84, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DFF_THRSH_parse_table[] = {
+	{ "WR_DFTHRSH_MIN",	0x00, 0x70 },
+	{ "RD_DFTHRSH_MIN",	0x00, 0x07 },
+	{ "RD_DFTHRSH_25",	0x01, 0x07 },
+	{ "RD_DFTHRSH_50",	0x02, 0x07 },
+	{ "RD_DFTHRSH_63",	0x03, 0x07 },
+	{ "RD_DFTHRSH_75",	0x04, 0x07 },
+	{ "RD_DFTHRSH_85",	0x05, 0x07 },
+	{ "RD_DFTHRSH_90",	0x06, 0x07 },
+	{ "RD_DFTHRSH_MAX",	0x07, 0x07 },
+	{ "WR_DFTHRSH_25",	0x10, 0x70 },
+	{ "WR_DFTHRSH_50",	0x20, 0x70 },
+	{ "WR_DFTHRSH_63",	0x30, 0x70 },
+	{ "WR_DFTHRSH_75",	0x40, 0x70 },
+	{ "WR_DFTHRSH_85",	0x50, 0x70 },
+	{ "WR_DFTHRSH_90",	0x60, 0x70 },
+	{ "WR_DFTHRSH_MAX",	0x70, 0x70 },
+	{ "RD_DFTHRSH",		0x07, 0x07 },
+	{ "WR_DFTHRSH",		0x70, 0x70 }
+};
+
+int
+ahd_dff_thrsh_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DFF_THRSH_parse_table, 18, "DFF_THRSH",
+	    0x88, regvalue, cur_col, wrap));
+}
+
+int
+ahd_romaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "ROMADDR",
+	    0x8a, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t ROMCNTRL_parse_table[] = {
+	{ "RDY",		0x01, 0x01 },
+	{ "REPEAT",		0x02, 0x02 },
+	{ "ROMSPD",		0x18, 0x18 },
+	{ "ROMOP",		0xe0, 0xe0 }
+};
+
+int
+ahd_romcntrl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(ROMCNTRL_parse_table, 4, "ROMCNTRL",
+	    0x8d, regvalue, cur_col, wrap));
+}
+
+int
+ahd_romdata_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "ROMDATA",
+	    0x8e, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CMCRXMSG0_parse_table[] = {
+	{ "CFNUM",		0x07, 0x07 },
+	{ "CDNUM",		0xf8, 0xf8 }
+};
+
+int
+ahd_cmcrxmsg0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CMCRXMSG0_parse_table, 2, "CMCRXMSG0",
+	    0x90, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t ROENABLE_parse_table[] = {
+	{ "DCH0ROEN",		0x01, 0x01 },
+	{ "DCH1ROEN",		0x02, 0x02 },
+	{ "SGROEN",		0x04, 0x04 },
+	{ "CMCROEN",		0x08, 0x08 },
+	{ "OVLYROEN",		0x10, 0x10 },
+	{ "MSIROEN",		0x20, 0x20 }
+};
+
+int
+ahd_roenable_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(ROENABLE_parse_table, 6, "ROENABLE",
+	    0x90, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t OVLYRXMSG0_parse_table[] = {
+	{ "CFNUM",		0x07, 0x07 },
+	{ "CDNUM",		0xf8, 0xf8 }
+};
+
+int
+ahd_ovlyrxmsg0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(OVLYRXMSG0_parse_table, 2, "OVLYRXMSG0",
+	    0x90, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DCHRXMSG0_parse_table[] = {
+	{ "CFNUM",		0x07, 0x07 },
+	{ "CDNUM",		0xf8, 0xf8 }
+};
+
+int
+ahd_dchrxmsg0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DCHRXMSG0_parse_table, 2, "DCHRXMSG0",
+	    0x90, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t OVLYRXMSG1_parse_table[] = {
+	{ "CBNUM",		0xff, 0xff }
+};
+
+int
+ahd_ovlyrxmsg1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(OVLYRXMSG1_parse_table, 1, "OVLYRXMSG1",
+	    0x91, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t NSENABLE_parse_table[] = {
+	{ "DCH0NSEN",		0x01, 0x01 },
+	{ "DCH1NSEN",		0x02, 0x02 },
+	{ "SGNSEN",		0x04, 0x04 },
+	{ "CMCNSEN",		0x08, 0x08 },
+	{ "OVLYNSEN",		0x10, 0x10 },
+	{ "MSINSEN",		0x20, 0x20 }
+};
+
+int
+ahd_nsenable_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NSENABLE_parse_table, 6, "NSENABLE",
+	    0x91, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DCHRXMSG1_parse_table[] = {
+	{ "CBNUM",		0xff, 0xff }
+};
+
+int
+ahd_dchrxmsg1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DCHRXMSG1_parse_table, 1, "DCHRXMSG1",
+	    0x91, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CMCRXMSG1_parse_table[] = {
+	{ "CBNUM",		0xff, 0xff }
+};
+
+int
+ahd_cmcrxmsg1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CMCRXMSG1_parse_table, 1, "CMCRXMSG1",
+	    0x91, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DCHRXMSG2_parse_table[] = {
+	{ "MINDEX",		0xff, 0xff }
+};
+
+int
+ahd_dchrxmsg2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DCHRXMSG2_parse_table, 1, "DCHRXMSG2",
+	    0x92, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t OVLYRXMSG2_parse_table[] = {
+	{ "MINDEX",		0xff, 0xff }
+};
+
+int
+ahd_ovlyrxmsg2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(OVLYRXMSG2_parse_table, 1, "OVLYRXMSG2",
+	    0x92, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CMCRXMSG2_parse_table[] = {
+	{ "MINDEX",		0xff, 0xff }
+};
+
+int
+ahd_cmcrxmsg2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CMCRXMSG2_parse_table, 1, "CMCRXMSG2",
+	    0x92, regvalue, cur_col, wrap));
+}
+
+int
+ahd_ost_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "OST",
+	    0x92, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DCHRXMSG3_parse_table[] = {
+	{ "MCLASS",		0x0f, 0x0f }
+};
+
+int
+ahd_dchrxmsg3_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DCHRXMSG3_parse_table, 1, "DCHRXMSG3",
+	    0x93, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CMCRXMSG3_parse_table[] = {
+	{ "MCLASS",		0x0f, 0x0f }
+};
+
+int
+ahd_cmcrxmsg3_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CMCRXMSG3_parse_table, 1, "CMCRXMSG3",
+	    0x93, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t PCIXCTL_parse_table[] = {
+	{ "CMPABCDIS",		0x01, 0x01 },
+	{ "TSCSERREN",		0x02, 0x02 },
+	{ "SRSPDPEEN",		0x04, 0x04 },
+	{ "SPLTSTADIS",		0x08, 0x08 },
+	{ "SPLTSMADIS",		0x10, 0x10 },
+	{ "UNEXPSCIEN",		0x20, 0x20 },
+	{ "SERRPULSE",		0x80, 0x80 }
+};
+
+int
+ahd_pcixctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(PCIXCTL_parse_table, 7, "PCIXCTL",
+	    0x93, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t OVLYRXMSG3_parse_table[] = {
+	{ "MCLASS",		0x0f, 0x0f }
+};
+
+int
+ahd_ovlyrxmsg3_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(OVLYRXMSG3_parse_table, 1, "OVLYRXMSG3",
+	    0x93, regvalue, cur_col, wrap));
+}
+
+int
+ahd_ovlyseqbcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "OVLYSEQBCNT",
+	    0x94, regvalue, cur_col, wrap));
+}
+
+int
+ahd_cmcseqbcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "CMCSEQBCNT",
+	    0x94, regvalue, cur_col, wrap));
+}
+
+int
+ahd_dchseqbcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "DCHSEQBCNT",
+	    0x94, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CMCSPLTSTAT0_parse_table[] = {
+	{ "RXSPLTRSP",		0x01, 0x01 },
+	{ "RXSCEMSG",		0x02, 0x02 },
+	{ "RXOVRUN",		0x04, 0x04 },
+	{ "CNTNOTCMPLT",	0x08, 0x08 },
+	{ "SCDATBUCKET",	0x10, 0x10 },
+	{ "SCADERR",		0x20, 0x20 },
+	{ "SCBCERR",		0x40, 0x40 },
+	{ "STAETERM",		0x80, 0x80 }
+};
+
+int
+ahd_cmcspltstat0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CMCSPLTSTAT0_parse_table, 8, "CMCSPLTSTAT0",
+	    0x96, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t OVLYSPLTSTAT0_parse_table[] = {
+	{ "RXSPLTRSP",		0x01, 0x01 },
+	{ "RXSCEMSG",		0x02, 0x02 },
+	{ "RXOVRUN",		0x04, 0x04 },
+	{ "CNTNOTCMPLT",	0x08, 0x08 },
+	{ "SCDATBUCKET",	0x10, 0x10 },
+	{ "SCADERR",		0x20, 0x20 },
+	{ "SCBCERR",		0x40, 0x40 },
+	{ "STAETERM",		0x80, 0x80 }
+};
+
+int
+ahd_ovlyspltstat0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(OVLYSPLTSTAT0_parse_table, 8, "OVLYSPLTSTAT0",
+	    0x96, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DCHSPLTSTAT0_parse_table[] = {
+	{ "RXSPLTRSP",		0x01, 0x01 },
+	{ "RXSCEMSG",		0x02, 0x02 },
+	{ "RXOVRUN",		0x04, 0x04 },
+	{ "CNTNOTCMPLT",	0x08, 0x08 },
+	{ "SCDATBUCKET",	0x10, 0x10 },
+	{ "SCADERR",		0x20, 0x20 },
+	{ "SCBCERR",		0x40, 0x40 },
+	{ "STAETERM",		0x80, 0x80 }
+};
+
+int
+ahd_dchspltstat0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DCHSPLTSTAT0_parse_table, 8, "DCHSPLTSTAT0",
+	    0x96, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DCHSPLTSTAT1_parse_table[] = {
+	{ "RXDATABUCKET",	0x01, 0x01 }
+};
+
+int
+ahd_dchspltstat1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DCHSPLTSTAT1_parse_table, 1, "DCHSPLTSTAT1",
+	    0x97, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CMCSPLTSTAT1_parse_table[] = {
+	{ "RXDATABUCKET",	0x01, 0x01 }
+};
+
+int
+ahd_cmcspltstat1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CMCSPLTSTAT1_parse_table, 1, "CMCSPLTSTAT1",
+	    0x97, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t OVLYSPLTSTAT1_parse_table[] = {
+	{ "RXDATABUCKET",	0x01, 0x01 }
+};
+
+int
+ahd_ovlyspltstat1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(OVLYSPLTSTAT1_parse_table, 1, "OVLYSPLTSTAT1",
+	    0x97, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SGRXMSG0_parse_table[] = {
+	{ "CFNUM",		0x07, 0x07 },
+	{ "CDNUM",		0xf8, 0xf8 }
+};
+
+int
+ahd_sgrxmsg0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SGRXMSG0_parse_table, 2, "SGRXMSG0",
+	    0x98, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SLVSPLTOUTADR0_parse_table[] = {
+	{ "LOWER_ADDR",		0x7f, 0x7f }
+};
+
+int
+ahd_slvspltoutadr0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SLVSPLTOUTADR0_parse_table, 1, "SLVSPLTOUTADR0",
+	    0x98, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SGRXMSG1_parse_table[] = {
+	{ "CBNUM",		0xff, 0xff }
+};
+
+int
+ahd_sgrxmsg1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SGRXMSG1_parse_table, 1, "SGRXMSG1",
+	    0x99, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SLVSPLTOUTADR1_parse_table[] = {
+	{ "REQ_FNUM",		0x07, 0x07 },
+	{ "REQ_DNUM",		0xf8, 0xf8 }
+};
+
+int
+ahd_slvspltoutadr1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SLVSPLTOUTADR1_parse_table, 2, "SLVSPLTOUTADR1",
+	    0x99, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SGRXMSG2_parse_table[] = {
+	{ "MINDEX",		0xff, 0xff }
+};
+
+int
+ahd_sgrxmsg2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SGRXMSG2_parse_table, 1, "SGRXMSG2",
+	    0x9a, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SLVSPLTOUTADR2_parse_table[] = {
+	{ "REQ_BNUM",		0xff, 0xff }
+};
+
+int
+ahd_slvspltoutadr2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SLVSPLTOUTADR2_parse_table, 1, "SLVSPLTOUTADR2",
+	    0x9a, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SGRXMSG3_parse_table[] = {
+	{ "MCLASS",		0x0f, 0x0f }
+};
+
+int
+ahd_sgrxmsg3_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SGRXMSG3_parse_table, 1, "SGRXMSG3",
+	    0x9b, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SLVSPLTOUTADR3_parse_table[] = {
+	{ "RLXORD",		0x10, 0x10 },
+	{ "TAG_NUM",		0x1f, 0x1f }
+};
+
+int
+ahd_slvspltoutadr3_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SLVSPLTOUTADR3_parse_table, 2, "SLVSPLTOUTADR3",
+	    0x9b, regvalue, cur_col, wrap));
+}
+
+int
+ahd_sgseqbcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SGSEQBCNT",
+	    0x9c, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SLVSPLTOUTATTR0_parse_table[] = {
+	{ "LOWER_BCNT",		0xff, 0xff }
+};
+
+int
+ahd_slvspltoutattr0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SLVSPLTOUTATTR0_parse_table, 1, "SLVSPLTOUTATTR0",
+	    0x9c, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SLVSPLTOUTATTR1_parse_table[] = {
+	{ "CMPLT_FNUM",		0x07, 0x07 },
+	{ "CMPLT_DNUM",		0xf8, 0xf8 }
+};
+
+int
+ahd_slvspltoutattr1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SLVSPLTOUTATTR1_parse_table, 2, "SLVSPLTOUTATTR1",
+	    0x9d, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SLVSPLTOUTATTR2_parse_table[] = {
+	{ "CMPLT_BNUM",		0xff, 0xff }
+};
+
+int
+ahd_slvspltoutattr2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SLVSPLTOUTATTR2_parse_table, 1, "SLVSPLTOUTATTR2",
+	    0x9e, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SGSPLTSTAT0_parse_table[] = {
+	{ "RXSPLTRSP",		0x01, 0x01 },
+	{ "RXSCEMSG",		0x02, 0x02 },
+	{ "RXOVRUN",		0x04, 0x04 },
+	{ "CNTNOTCMPLT",	0x08, 0x08 },
+	{ "SCDATBUCKET",	0x10, 0x10 },
+	{ "SCADERR",		0x20, 0x20 },
+	{ "SCBCERR",		0x40, 0x40 },
+	{ "STAETERM",		0x80, 0x80 }
+};
+
+int
+ahd_sgspltstat0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SGSPLTSTAT0_parse_table, 8, "SGSPLTSTAT0",
+	    0x9e, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SFUNCT_parse_table[] = {
+	{ "TEST_NUM",		0x0f, 0x0f },
+	{ "TEST_GROUP",		0xf0, 0xf0 }
+};
+
+int
+ahd_sfunct_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SFUNCT_parse_table, 2, "SFUNCT",
+	    0x9f, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SGSPLTSTAT1_parse_table[] = {
+	{ "RXDATABUCKET",	0x01, 0x01 }
+};
+
+int
+ahd_sgspltstat1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SGSPLTSTAT1_parse_table, 1, "SGSPLTSTAT1",
+	    0x9f, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DF0PCISTAT_parse_table[] = {
+	{ "DPR",		0x01, 0x01 },
+	{ "TWATERR",		0x02, 0x02 },
+	{ "RDPERR",		0x04, 0x04 },
+	{ "SCAAPERR",		0x08, 0x08 },
+	{ "RTA",		0x10, 0x10 },
+	{ "RMA",		0x20, 0x20 },
+	{ "SSE",		0x40, 0x40 },
+	{ "DPE",		0x80, 0x80 }
+};
+
+int
+ahd_df0pcistat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DF0PCISTAT_parse_table, 8, "DF0PCISTAT",
+	    0xa0, regvalue, cur_col, wrap));
+}
+
+int
+ahd_reg0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "REG0",
+	    0xa0, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DF1PCISTAT_parse_table[] = {
+	{ "DPR",		0x01, 0x01 },
+	{ "TWATERR",		0x02, 0x02 },
+	{ "RDPERR",		0x04, 0x04 },
+	{ "SCAAPERR",		0x08, 0x08 },
+	{ "RTA",		0x10, 0x10 },
+	{ "RMA",		0x20, 0x20 },
+	{ "SSE",		0x40, 0x40 },
+	{ "DPE",		0x80, 0x80 }
+};
+
+int
+ahd_df1pcistat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DF1PCISTAT_parse_table, 8, "DF1PCISTAT",
+	    0xa1, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SGPCISTAT_parse_table[] = {
+	{ "DPR",		0x01, 0x01 },
+	{ "RDPERR",		0x04, 0x04 },
+	{ "SCAAPERR",		0x08, 0x08 },
+	{ "RTA",		0x10, 0x10 },
+	{ "RMA",		0x20, 0x20 },
+	{ "SSE",		0x40, 0x40 },
+	{ "DPE",		0x80, 0x80 }
+};
+
+int
+ahd_sgpcistat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SGPCISTAT_parse_table, 7, "SGPCISTAT",
+	    0xa2, regvalue, cur_col, wrap));
+}
+
+int
+ahd_reg1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "REG1",
+	    0xa2, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CMCPCISTAT_parse_table[] = {
+	{ "DPR",		0x01, 0x01 },
+	{ "TWATERR",		0x02, 0x02 },
+	{ "RDPERR",		0x04, 0x04 },
+	{ "SCAAPERR",		0x08, 0x08 },
+	{ "RTA",		0x10, 0x10 },
+	{ "RMA",		0x20, 0x20 },
+	{ "SSE",		0x40, 0x40 },
+	{ "DPE",		0x80, 0x80 }
+};
+
+int
+ahd_cmcpcistat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CMCPCISTAT_parse_table, 8, "CMCPCISTAT",
+	    0xa3, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t OVLYPCISTAT_parse_table[] = {
+	{ "DPR",		0x01, 0x01 },
+	{ "RDPERR",		0x04, 0x04 },
+	{ "SCAAPERR",		0x08, 0x08 },
+	{ "RTA",		0x10, 0x10 },
+	{ "RMA",		0x20, 0x20 },
+	{ "SSE",		0x40, 0x40 },
+	{ "DPE",		0x80, 0x80 }
+};
+
+int
+ahd_ovlypcistat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(OVLYPCISTAT_parse_table, 7, "OVLYPCISTAT",
+	    0xa4, regvalue, cur_col, wrap));
+}
+
+int
+ahd_reg_isr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "REG_ISR",
+	    0xa4, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SG_STATE_parse_table[] = {
+	{ "SEGS_AVAIL",		0x01, 0x01 },
+	{ "LOADING_NEEDED",	0x02, 0x02 },
+	{ "FETCH_INPROG",	0x04, 0x04 }
+};
+
+int
+ahd_sg_state_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SG_STATE_parse_table, 3, "SG_STATE",
+	    0xa6, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t MSIPCISTAT_parse_table[] = {
+	{ "DPR",		0x01, 0x01 },
+	{ "TWATERR",		0x02, 0x02 },
+	{ "CLRPENDMSI",		0x08, 0x08 },
+	{ "RTA",		0x10, 0x10 },
+	{ "RMA",		0x20, 0x20 },
+	{ "SSE",		0x40, 0x40 }
+};
+
+int
+ahd_msipcistat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(MSIPCISTAT_parse_table, 6, "MSIPCISTAT",
+	    0xa6, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t TARGPCISTAT_parse_table[] = {
+	{ "TWATERR",		0x02, 0x02 },
+	{ "STA",		0x08, 0x08 },
+	{ "SSE",		0x40, 0x40 },
+	{ "DPE",		0x80, 0x80 }
+};
+
+int
+ahd_targpcistat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(TARGPCISTAT_parse_table, 4, "TARGPCISTAT",
+	    0xa7, regvalue, cur_col, wrap));
+}
+
+int
+ahd_data_count_odd_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "DATA_COUNT_ODD",
+	    0xa7, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scbptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCBPTR",
+	    0xa8, regvalue, cur_col, wrap));
+}
+
+int
+ahd_ccscbacnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "CCSCBACNT",
+	    0xab, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCBAUTOPTR_parse_table[] = {
+	{ "SCBPTR_OFF",		0x07, 0x07 },
+	{ "SCBPTR_ADDR",	0x38, 0x38 },
+	{ "AUSCBPTR_EN",	0x80, 0x80 }
+};
+
+int
+ahd_scbautoptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCBAUTOPTR_parse_table, 3, "SCBAUTOPTR",
+	    0xab, regvalue, cur_col, wrap));
+}
+
+int
+ahd_ccsgaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "CCSGADDR",
+	    0xac, regvalue, cur_col, wrap));
+}
+
+int
+ahd_ccscbaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "CCSCBADDR",
+	    0xac, regvalue, cur_col, wrap));
+}
+
+int
+ahd_ccscbadr_bk_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "CCSCBADR_BK",
+	    0xac, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CMC_RAMBIST_parse_table[] = {
+	{ "CMC_BUFFER_BIST_EN",	0x01, 0x01 },
+	{ "CMC_BUFFER_BIST_FAIL",0x02, 0x02 },
+	{ "SG_BIST_EN",		0x10, 0x10 },
+	{ "SG_BIST_FAIL",	0x20, 0x20 },
+	{ "SCBRAMBIST_FAIL",	0x40, 0x40 },
+	{ "SG_ELEMENT_SIZE",	0x80, 0x80 }
+};
+
+int
+ahd_cmc_rambist_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CMC_RAMBIST_parse_table, 6, "CMC_RAMBIST",
+	    0xad, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CCSGCTL_parse_table[] = {
+	{ "CCSGRESET",		0x01, 0x01 },
+	{ "SG_FETCH_REQ",	0x02, 0x02 },
+	{ "CCSGENACK",		0x08, 0x08 },
+	{ "SG_CACHE_AVAIL",	0x10, 0x10 },
+	{ "CCSGDONE",		0x80, 0x80 },
+	{ "CCSGEN",		0x0c, 0x0c }
+};
+
+int
+ahd_ccsgctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CCSGCTL_parse_table, 6, "CCSGCTL",
+	    0xad, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t CCSCBCTL_parse_table[] = {
+	{ "CCSCBRESET",		0x01, 0x01 },
+	{ "CCSCBDIR",		0x04, 0x04 },
+	{ "CCSCBEN",		0x08, 0x08 },
+	{ "CCARREN",		0x10, 0x10 },
+	{ "ARRDONE",		0x40, 0x40 },
+	{ "CCSCBDONE",		0x80, 0x80 }
+};
+
+int
+ahd_ccscbctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(CCSCBCTL_parse_table, 6, "CCSCBCTL",
+	    0xad, regvalue, cur_col, wrap));
+}
+
+int
+ahd_ccsgram_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "CCSGRAM",
+	    0xb0, regvalue, cur_col, wrap));
+}
+
+int
+ahd_flexadr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "FLEXADR",
+	    0xb0, regvalue, cur_col, wrap));
+}
+
+int
+ahd_ccscbram_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "CCSCBRAM",
+	    0xb0, regvalue, cur_col, wrap));
+}
+
+int
+ahd_flexcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "FLEXCNT",
+	    0xb3, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t FLEXDMASTAT_parse_table[] = {
+	{ "FLEXDMADONE",	0x01, 0x01 },
+	{ "FLEXDMAERR",		0x02, 0x02 }
+};
+
+int
+ahd_flexdmastat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(FLEXDMASTAT_parse_table, 2, "FLEXDMASTAT",
+	    0xb5, regvalue, cur_col, wrap));
+}
+
+int
+ahd_flexdata_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "FLEXDATA",
+	    0xb6, regvalue, cur_col, wrap));
+}
+
+int
+ahd_brddat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "BRDDAT",
+	    0xb8, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t BRDCTL_parse_table[] = {
+	{ "BRDSTB",		0x01, 0x01 },
+	{ "BRDRW",		0x02, 0x02 },
+	{ "BRDEN",		0x04, 0x04 },
+	{ "BRDADDR",		0x38, 0x38 },
+	{ "FLXARBREQ",		0x40, 0x40 },
+	{ "FLXARBACK",		0x80, 0x80 }
+};
+
+int
+ahd_brdctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(BRDCTL_parse_table, 6, "BRDCTL",
+	    0xb9, regvalue, cur_col, wrap));
+}
+
+int
+ahd_seeadr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SEEADR",
+	    0xba, regvalue, cur_col, wrap));
+}
+
+int
+ahd_seedat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SEEDAT",
+	    0xbc, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SEECTL_parse_table[] = {
+	{ "SEEOP_ERAL",		0x40, 0x70 },
+	{ "SEEOP_WRITE",	0x50, 0x70 },
+	{ "SEEOP_READ",		0x60, 0x70 },
+	{ "SEEOP_ERASE",	0x70, 0x70 },
+	{ "SEESTART",		0x01, 0x01 },
+	{ "SEERST",		0x02, 0x02 },
+	{ "SEEOPCODE",		0x70, 0x70 },
+	{ "SEEOP_EWEN",		0x40, 0x40 },
+	{ "SEEOP_WALL",		0x40, 0x40 },
+	{ "SEEOP_EWDS",		0x40, 0x40 }
+};
+
+int
+ahd_seectl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SEECTL_parse_table, 10, "SEECTL",
+	    0xbe, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SEESTAT_parse_table[] = {
+	{ "SEESTART",		0x01, 0x01 },
+	{ "SEEBUSY",		0x02, 0x02 },
+	{ "SEEARBACK",		0x04, 0x04 },
+	{ "LDALTID_L",		0x08, 0x08 },
+	{ "SEEOPCODE",		0x70, 0x70 },
+	{ "INIT_DONE",		0x80, 0x80 }
+};
+
+int
+ahd_seestat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SEESTAT_parse_table, 6, "SEESTAT",
+	    0xbe, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scbcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCBCNT",
+	    0xbf, regvalue, cur_col, wrap));
+}
+
+int
+ahd_dfwaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "DFWADDR",
+	    0xc0, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DSPFLTRCTL_parse_table[] = {
+	{ "DSPFCNTSEL",		0x0f, 0x0f },
+	{ "EDGESENSE",		0x10, 0x10 },
+	{ "FLTRDISABLE",	0x20, 0x20 }
+};
+
+int
+ahd_dspfltrctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DSPFLTRCTL_parse_table, 3, "DSPFLTRCTL",
+	    0xc0, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DSPDATACTL_parse_table[] = {
+	{ "XMITOFFSTDIS",	0x02, 0x02 },
+	{ "RCVROFFSTDIS",	0x04, 0x04 },
+	{ "DESQDIS",		0x10, 0x10 },
+	{ "BYPASSENAB",		0x80, 0x80 }
+};
+
+int
+ahd_dspdatactl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DSPDATACTL_parse_table, 4, "DSPDATACTL",
+	    0xc1, regvalue, cur_col, wrap));
+}
+
+int
+ahd_dfraddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "DFRADDR",
+	    0xc2, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DSPREQCTL_parse_table[] = {
+	{ "MANREQDLY",		0x3f, 0x3f },
+	{ "MANREQCTL",		0xc0, 0xc0 }
+};
+
+int
+ahd_dspreqctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DSPREQCTL_parse_table, 2, "DSPREQCTL",
+	    0xc2, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DSPACKCTL_parse_table[] = {
+	{ "MANACKDLY",		0x3f, 0x3f },
+	{ "MANACKCTL",		0xc0, 0xc0 }
+};
+
+int
+ahd_dspackctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DSPACKCTL_parse_table, 2, "DSPACKCTL",
+	    0xc3, regvalue, cur_col, wrap));
+}
+
+int
+ahd_dfdat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "DFDAT",
+	    0xc4, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DSPSELECT_parse_table[] = {
+	{ "DSPSEL",		0x1f, 0x1f },
+	{ "AUTOINCEN",		0x80, 0x80 }
+};
+
+int
+ahd_dspselect_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DSPSELECT_parse_table, 2, "DSPSELECT",
+	    0xc4, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t WRTBIASCTL_parse_table[] = {
+	{ "XMITMANVAL",		0x3f, 0x3f },
+	{ "AUTOXBCDIS",		0x80, 0x80 }
+};
+
+int
+ahd_wrtbiasctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(WRTBIASCTL_parse_table, 2, "WRTBIASCTL",
+	    0xc5, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t RCVRBIOSCTL_parse_table[] = {
+	{ "RCVRMANVAL",		0x3f, 0x3f },
+	{ "AUTORBCDIS",		0x80, 0x80 }
+};
+
+int
+ahd_rcvrbiosctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(RCVRBIOSCTL_parse_table, 2, "RCVRBIOSCTL",
+	    0xc6, regvalue, cur_col, wrap));
+}
+
+int
+ahd_wrtbiascalc_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "WRTBIASCALC",
+	    0xc7, regvalue, cur_col, wrap));
+}
+
+int
+ahd_dfptrs_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "DFPTRS",
+	    0xc8, regvalue, cur_col, wrap));
+}
+
+int
+ahd_rcvrbiascalc_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "RCVRBIASCALC",
+	    0xc8, regvalue, cur_col, wrap));
+}
+
+int
+ahd_dfbkptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "DFBKPTR",
+	    0xc9, regvalue, cur_col, wrap));
+}
+
+int
+ahd_skewcalc_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SKEWCALC",
+	    0xc9, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DFDBCTL_parse_table[] = {
+	{ "DFF_RAMBIST_EN",	0x01, 0x01 },
+	{ "DFF_RAMBIST_DONE",	0x02, 0x02 },
+	{ "DFF_RAMBIST_FAIL",	0x04, 0x04 },
+	{ "DFF_DIR_ERR",	0x08, 0x08 },
+	{ "DFF_CIO_RD_RDY",	0x10, 0x10 },
+	{ "DFF_CIO_WR_RDY",	0x20, 0x20 }
+};
+
+int
+ahd_dfdbctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DFDBCTL_parse_table, 6, "DFDBCTL",
+	    0xcb, regvalue, cur_col, wrap));
+}
+
+int
+ahd_dfscnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "DFSCNT",
+	    0xcc, regvalue, cur_col, wrap));
+}
+
+int
+ahd_dfbcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "DFBCNT",
+	    0xce, regvalue, cur_col, wrap));
+}
+
+int
+ahd_ovlyaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "OVLYADDR",
+	    0xd4, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SEQCTL0_parse_table[] = {
+	{ "LOADRAM",		0x01, 0x01 },
+	{ "SEQRESET",		0x02, 0x02 },
+	{ "STEP",		0x04, 0x04 },
+	{ "BRKADRINTEN",	0x08, 0x08 },
+	{ "FASTMODE",		0x10, 0x10 },
+	{ "FAILDIS",		0x20, 0x20 },
+	{ "PAUSEDIS",		0x40, 0x40 },
+	{ "PERRORDIS",		0x80, 0x80 }
+};
+
+int
+ahd_seqctl0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SEQCTL0_parse_table, 8, "SEQCTL0",
+	    0xd6, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SEQCTL1_parse_table[] = {
+	{ "RAMBIST_EN",		0x01, 0x01 },
+	{ "RAMBIST_FAIL",	0x02, 0x02 },
+	{ "RAMBIST_DONE",	0x04, 0x04 },
+	{ "OVRLAY_DATA_CHK",	0x08, 0x08 }
+};
+
+int
+ahd_seqctl1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SEQCTL1_parse_table, 4, "SEQCTL1",
+	    0xd7, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t FLAGS_parse_table[] = {
+	{ "CARRY",		0x01, 0x01 },
+	{ "ZERO",		0x02, 0x02 }
+};
+
+int
+ahd_flags_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(FLAGS_parse_table, 2, "FLAGS",
+	    0xd8, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SEQINTCTL_parse_table[] = {
+	{ "IRET",		0x01, 0x01 },
+	{ "INTMASK1",		0x02, 0x02 },
+	{ "INTMASK2",		0x04, 0x04 },
+	{ "SCS_SEQ_INT1M0",	0x08, 0x08 },
+	{ "SCS_SEQ_INT1M1",	0x10, 0x10 },
+	{ "INT1_CONTEXT",	0x20, 0x20 },
+	{ "INTVEC1DSL",		0x80, 0x80 }
+};
+
+int
+ahd_seqintctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SEQINTCTL_parse_table, 7, "SEQINTCTL",
+	    0xd9, regvalue, cur_col, wrap));
+}
+
+int
+ahd_seqram_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SEQRAM",
+	    0xda, regvalue, cur_col, wrap));
+}
+
+int
+ahd_prgmcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "PRGMCNT",
+	    0xde, regvalue, cur_col, wrap));
+}
+
+int
+ahd_accum_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "ACCUM",
+	    0xe0, regvalue, cur_col, wrap));
+}
+
+int
+ahd_sindex_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SINDEX",
+	    0xe2, regvalue, cur_col, wrap));
+}
+
+int
+ahd_dindex_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "DINDEX",
+	    0xe4, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t BRKADDR1_parse_table[] = {
+	{ "BRKDIS",		0x80, 0x80 }
+};
+
+int
+ahd_brkaddr1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(BRKADDR1_parse_table, 1, "BRKADDR1",
+	    0xe6, regvalue, cur_col, wrap));
+}
+
+int
+ahd_brkaddr0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "BRKADDR0",
+	    0xe6, regvalue, cur_col, wrap));
+}
+
+int
+ahd_allones_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "ALLONES",
+	    0xe8, regvalue, cur_col, wrap));
+}
+
+int
+ahd_allzeros_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "ALLZEROS",
+	    0xea, regvalue, cur_col, wrap));
+}
+
+int
+ahd_none_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "NONE",
+	    0xea, regvalue, cur_col, wrap));
+}
+
+int
+ahd_sindir_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SINDIR",
+	    0xec, regvalue, cur_col, wrap));
+}
+
+int
+ahd_dindir_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "DINDIR",
+	    0xed, regvalue, cur_col, wrap));
+}
+
+int
+ahd_function1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "FUNCTION1",
+	    0xf0, regvalue, cur_col, wrap));
+}
+
+int
+ahd_stack_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "STACK",
+	    0xf2, regvalue, cur_col, wrap));
+}
+
+int
+ahd_curaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "CURADDR",
+	    0xf4, regvalue, cur_col, wrap));
+}
+
+int
+ahd_intvec1_addr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "INTVEC1_ADDR",
+	    0xf4, regvalue, cur_col, wrap));
+}
+
+int
+ahd_intvec2_addr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "INTVEC2_ADDR",
+	    0xf6, regvalue, cur_col, wrap));
+}
+
+int
+ahd_lastaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "LASTADDR",
+	    0xf6, regvalue, cur_col, wrap));
+}
+
+int
+ahd_longjmp_addr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "LONGJMP_ADDR",
+	    0xf8, regvalue, cur_col, wrap));
+}
+
+int
+ahd_longjmp_scb_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "LONGJMP_SCB",
+	    0xfa, regvalue, cur_col, wrap));
+}
+
+int
+ahd_accum_save_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "ACCUM_SAVE",
+	    0xfc, regvalue, cur_col, wrap));
+}
+
+int
+ahd_waiting_scb_tails_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "WAITING_SCB_TAILS",
+	    0x100, regvalue, cur_col, wrap));
+}
+
+int
+ahd_ahd_pci_config_base_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "AHD_PCI_CONFIG_BASE",
+	    0x100, regvalue, cur_col, wrap));
+}
+
+int
+ahd_sram_base_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SRAM_BASE",
+	    0x100, regvalue, cur_col, wrap));
+}
+
+int
+ahd_waiting_tid_head_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "WAITING_TID_HEAD",
+	    0x120, regvalue, cur_col, wrap));
+}
+
+int
+ahd_waiting_tid_tail_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "WAITING_TID_TAIL",
+	    0x122, regvalue, cur_col, wrap));
+}
+
+int
+ahd_next_queued_scb_addr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "NEXT_QUEUED_SCB_ADDR",
+	    0x124, regvalue, cur_col, wrap));
+}
+
+int
+ahd_complete_scb_head_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "COMPLETE_SCB_HEAD",
+	    0x128, regvalue, cur_col, wrap));
+}
+
+int
+ahd_complete_scb_dmainprog_head_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "COMPLETE_SCB_DMAINPROG_HEAD",
+	    0x12a, regvalue, cur_col, wrap));
+}
+
+int
+ahd_complete_dma_scb_head_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "COMPLETE_DMA_SCB_HEAD",
+	    0x12c, regvalue, cur_col, wrap));
+}
+
+int
+ahd_qfreeze_count_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "QFREEZE_COUNT",
+	    0x12e, regvalue, cur_col, wrap));
+}
+
+int
+ahd_saved_mode_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SAVED_MODE",
+	    0x130, regvalue, cur_col, wrap));
+}
+
+int
+ahd_msg_out_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "MSG_OUT",
+	    0x131, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t DMAPARAMS_parse_table[] = {
+	{ "FIFORESET",		0x01, 0x01 },
+	{ "FIFOFLUSH",		0x02, 0x02 },
+	{ "DIRECTION",		0x04, 0x04 },
+	{ "HDMAEN",		0x08, 0x08 },
+	{ "HDMAENACK",		0x08, 0x08 },
+	{ "SDMAEN",		0x10, 0x10 },
+	{ "SDMAENACK",		0x10, 0x10 },
+	{ "SCSIEN",		0x20, 0x20 },
+	{ "WIDEODD",		0x40, 0x40 },
+	{ "PRELOADEN",		0x80, 0x80 }
+};
+
+int
+ahd_dmaparams_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(DMAPARAMS_parse_table, 10, "DMAPARAMS",
+	    0x132, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SEQ_FLAGS_parse_table[] = {
+	{ "NO_DISCONNECT",	0x01, 0x01 },
+	{ "SPHASE_PENDING",	0x02, 0x02 },
+	{ "DPHASE_PENDING",	0x04, 0x04 },
+	{ "CMDPHASE_PENDING",	0x08, 0x08 },
+	{ "TARG_CMD_PENDING",	0x10, 0x10 },
+	{ "DPHASE",		0x20, 0x20 },
+	{ "NO_CDB_SENT",	0x40, 0x40 },
+	{ "TARGET_CMD_IS_TAGGED",0x40, 0x40 },
+	{ "NOT_IDENTIFIED",	0x80, 0x80 }
+};
+
+int
+ahd_seq_flags_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SEQ_FLAGS_parse_table, 9, "SEQ_FLAGS",
+	    0x133, regvalue, cur_col, wrap));
+}
+
+int
+ahd_saved_scsiid_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SAVED_SCSIID",
+	    0x134, regvalue, cur_col, wrap));
+}
+
+int
+ahd_saved_lun_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SAVED_LUN",
+	    0x135, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t LASTPHASE_parse_table[] = {
+	{ "P_DATAOUT",		0x00, 0xe0 },
+	{ "P_DATAOUT_DT",	0x20, 0xe0 },
+	{ "P_DATAIN",		0x40, 0xe0 },
+	{ "P_DATAIN_DT",	0x60, 0xe0 },
+	{ "P_COMMAND",		0x80, 0xe0 },
+	{ "P_MESGOUT",		0xa0, 0xe0 },
+	{ "P_STATUS",		0xc0, 0xe0 },
+	{ "P_MESGIN",		0xe0, 0xe0 },
+	{ "P_BUSFREE",		0x01, 0x01 },
+	{ "MSGI",		0x20, 0x20 },
+	{ "IOI",		0x40, 0x40 },
+	{ "CDI",		0x80, 0x80 },
+	{ "PHASE_MASK",		0xe0, 0xe0 }
+};
+
+int
+ahd_lastphase_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(LASTPHASE_parse_table, 13, "LASTPHASE",
+	    0x136, regvalue, cur_col, wrap));
+}
+
+int
+ahd_qoutfifo_entry_valid_tag_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "QOUTFIFO_ENTRY_VALID_TAG",
+	    0x137, regvalue, cur_col, wrap));
+}
+
+int
+ahd_shared_data_addr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SHARED_DATA_ADDR",
+	    0x138, regvalue, cur_col, wrap));
+}
+
+int
+ahd_qoutfifo_next_addr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "QOUTFIFO_NEXT_ADDR",
+	    0x13c, regvalue, cur_col, wrap));
+}
+
+int
+ahd_kernel_tqinpos_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "KERNEL_TQINPOS",
+	    0x140, regvalue, cur_col, wrap));
+}
+
+int
+ahd_tqinpos_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "TQINPOS",
+	    0x141, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t ARG_1_parse_table[] = {
+	{ "CONT_MSG_LOOP_TARG",	0x02, 0x02 },
+	{ "CONT_MSG_LOOP_READ",	0x03, 0x03 },
+	{ "CONT_MSG_LOOP_WRITE",0x04, 0x04 },
+	{ "EXIT_MSG_LOOP",	0x08, 0x08 },
+	{ "MSGOUT_PHASEMIS",	0x10, 0x10 },
+	{ "SEND_REJ",		0x20, 0x20 },
+	{ "SEND_SENSE",		0x40, 0x40 },
+	{ "SEND_MSG",		0x80, 0x80 }
+};
+
+int
+ahd_arg_1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(ARG_1_parse_table, 8, "ARG_1",
+	    0x142, regvalue, cur_col, wrap));
+}
+
+int
+ahd_arg_2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "ARG_2",
+	    0x143, regvalue, cur_col, wrap));
+}
+
+int
+ahd_last_msg_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "LAST_MSG",
+	    0x144, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCSISEQ_TEMPLATE_parse_table[] = {
+	{ "ALTSTIM",		0x01, 0x01 },
+	{ "ENAUTOATNP",		0x02, 0x02 },
+	{ "MANUALP",		0x0c, 0x0c },
+	{ "ENRSELI",		0x10, 0x10 },
+	{ "ENSELI",		0x20, 0x20 },
+	{ "MANUALCTL",		0x40, 0x40 }
+};
+
+int
+ahd_scsiseq_template_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCSISEQ_TEMPLATE_parse_table, 6, "SCSISEQ_TEMPLATE",
+	    0x145, regvalue, cur_col, wrap));
+}
+
+int
+ahd_initiator_tag_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "INITIATOR_TAG",
+	    0x146, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SEQ_FLAGS2_parse_table[] = {
+	{ "TARGET_MSG_PENDING",	0x02, 0x02 },
+	{ "SELECTOUT_QFROZEN",	0x04, 0x04 }
+};
+
+int
+ahd_seq_flags2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SEQ_FLAGS2_parse_table, 2, "SEQ_FLAGS2",
+	    0x147, regvalue, cur_col, wrap));
+}
+
+int
+ahd_allocfifo_scbptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "ALLOCFIFO_SCBPTR",
+	    0x148, regvalue, cur_col, wrap));
+}
+
+int
+ahd_int_coalessing_timer_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "INT_COALESSING_TIMER",
+	    0x14a, regvalue, cur_col, wrap));
+}
+
+int
+ahd_int_coalessing_maxcmds_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "INT_COALESSING_MAXCMDS",
+	    0x14c, regvalue, cur_col, wrap));
+}
+
+int
+ahd_int_coalessing_mincmds_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "INT_COALESSING_MINCMDS",
+	    0x14d, regvalue, cur_col, wrap));
+}
+
+int
+ahd_cmds_pending_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "CMDS_PENDING",
+	    0x14e, regvalue, cur_col, wrap));
+}
+
+int
+ahd_int_coalessing_cmdcount_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "INT_COALESSING_CMDCOUNT",
+	    0x150, regvalue, cur_col, wrap));
+}
+
+int
+ahd_local_hs_mailbox_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "LOCAL_HS_MAILBOX",
+	    0x151, regvalue, cur_col, wrap));
+}
+
+int
+ahd_cmdsize_table_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "CMDSIZE_TABLE",
+	    0x152, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scb_base_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCB_BASE",
+	    0x180, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scb_residual_datacnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCB_RESIDUAL_DATACNT",
+	    0x180, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCB_RESIDUAL_SGPTR_parse_table[] = {
+	{ "SG_LIST_NULL",	0x01, 0x01 },
+	{ "SG_OVERRUN_RESID",	0x02, 0x02 },
+	{ "SG_ADDR_MASK",	0xf8, 0xf8 }
+};
+
+int
+ahd_scb_residual_sgptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCB_RESIDUAL_SGPTR_parse_table, 3, "SCB_RESIDUAL_SGPTR",
+	    0x184, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scb_scsi_status_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCB_SCSI_STATUS",
+	    0x188, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scb_target_phases_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCB_TARGET_PHASES",
+	    0x189, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scb_target_data_dir_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCB_TARGET_DATA_DIR",
+	    0x18a, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scb_target_itag_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCB_TARGET_ITAG",
+	    0x18b, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scb_sense_busaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCB_SENSE_BUSADDR",
+	    0x18c, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scb_tag_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCB_TAG",
+	    0x190, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCB_CDB_LEN_parse_table[] = {
+	{ "SCB_CDB_LEN_PTR",	0x80, 0x80 }
+};
+
+int
+ahd_scb_cdb_len_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCB_CDB_LEN_parse_table, 1, "SCB_CDB_LEN",
+	    0x192, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scb_task_management_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCB_TASK_MANAGEMENT",
+	    0x193, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scb_next_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCB_NEXT",
+	    0x194, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scb_next2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCB_NEXT2",
+	    0x196, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scb_dataptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCB_DATAPTR",
+	    0x198, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCB_DATACNT_parse_table[] = {
+	{ "SG_HIGH_ADDR_BITS",	0x7f, 0x7f },
+	{ "SG_LAST_SEG",	0x80, 0x80 }
+};
+
+int
+ahd_scb_datacnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCB_DATACNT_parse_table, 2, "SCB_DATACNT",
+	    0x1a0, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCB_SGPTR_parse_table[] = {
+	{ "SG_LIST_NULL",	0x01, 0x01 },
+	{ "SG_FULL_RESID",	0x02, 0x02 },
+	{ "SG_STATUS_VALID",	0x04, 0x04 }
+};
+
+int
+ahd_scb_sgptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCB_SGPTR_parse_table, 3, "SCB_SGPTR",
+	    0x1a4, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCB_CONTROL_parse_table[] = {
+	{ "SCB_TAG_TYPE",	0x03, 0x03 },
+	{ "DISCONNECTED",	0x04, 0x04 },
+	{ "STATUS_RCVD",	0x08, 0x08 },
+	{ "MK_MESSAGE",		0x10, 0x10 },
+	{ "TAG_ENB",		0x20, 0x20 },
+	{ "DISCENB",		0x40, 0x40 },
+	{ "TARGET_SCB",		0x80, 0x80 }
+};
+
+int
+ahd_scb_control_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCB_CONTROL_parse_table, 7, "SCB_CONTROL",
+	    0x1a8, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCB_SCSIID_parse_table[] = {
+	{ "OID",		0x0f, 0x0f },
+	{ "TID",		0xf0, 0xf0 }
+};
+
+int
+ahd_scb_scsiid_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCB_SCSIID_parse_table, 2, "SCB_SCSIID",
+	    0x1a9, regvalue, cur_col, wrap));
+}
+
+static ahd_reg_parse_entry_t SCB_LUN_parse_table[] = {
+	{ "LID",		0xff, 0xff }
+};
+
+int
+ahd_scb_lun_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(SCB_LUN_parse_table, 1, "SCB_LUN",
+	    0x1aa, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scb_task_attribute_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCB_TASK_ATTRIBUTE",
+	    0x1ab, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scb_busaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCB_BUSADDR",
+	    0x1ac, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scb_spare_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCB_SPARE",
+	    0x1b0, regvalue, cur_col, wrap));
+}
+
+int
+ahd_scb_disconnected_lists_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahd_print_register(NULL, 0, "SCB_DISCONNECTED_LISTS",
+	    0x1b8, regvalue, cur_col, wrap));
+}
+
diff -Nru a/drivers/scsi/aic7xxx/aic79xx_seq.h_shipped b/drivers/scsi/aic7xxx/aic79xx_seq.h_shipped
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aic79xx_seq.h_shipped	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,1067 @@
+/*
+ * DO NOT EDIT - This file is automatically generated
+ *		 from the following source files:
+ *
+ * $Id: //depot/aic7xxx/aic7xxx/aic79xx.seq#77 $
+ * $Id: //depot/aic7xxx/aic7xxx/aic79xx.reg#59 $
+ */
+static uint8_t seqprog[] = {
+	0xff, 0x02, 0x06, 0x78,
+	0x00, 0xea, 0x3c, 0x59,
+	0x01, 0xea, 0x04, 0x30,
+	0xff, 0x04, 0x0c, 0x78,
+	0x17, 0xea, 0x3c, 0x59,
+	0x17, 0xea, 0x04, 0x00,
+	0x33, 0xea, 0x30, 0x59,
+	0x33, 0xea, 0x00, 0x00,
+	0x60, 0x3a, 0x1a, 0x68,
+	0x04, 0x47, 0x1b, 0x68,
+	0xff, 0x21, 0x1b, 0x70,
+	0x40, 0x4b, 0x7e, 0x69,
+	0x00, 0xe2, 0x40, 0x59,
+	0x40, 0x4b, 0x7e, 0x69,
+	0x20, 0x4b, 0x6e, 0x69,
+	0xfc, 0x42, 0x24, 0x78,
+	0x10, 0x40, 0x24, 0x78,
+	0x00, 0xe2, 0x8c, 0x5d,
+	0x20, 0x4d, 0x28, 0x78,
+	0x00, 0xe2, 0x8c, 0x5d,
+	0x00, 0xe2, 0x34, 0x58,
+	0x00, 0xe2, 0x5c, 0x58,
+	0x00, 0xe2, 0x6c, 0x58,
+	0x00, 0xe2, 0x06, 0x40,
+	0x33, 0xea, 0x30, 0x59,
+	0x33, 0xea, 0x00, 0x00,
+	0x01, 0x52, 0x4e, 0x7d,
+	0x02, 0x58, 0x50, 0x31,
+	0xff, 0xea, 0x10, 0x0b,
+	0x08, 0xa8, 0x51, 0x03,
+	0x01, 0xa4, 0x43, 0x78,
+	0x00, 0xe2, 0x32, 0x5b,
+	0x00, 0xe2, 0x34, 0x40,
+	0xff, 0xea, 0xd4, 0x19,
+	0x02, 0xa8, 0x84, 0x32,
+	0x00, 0xea, 0x30, 0x59,
+	0x01, 0xea, 0x00, 0x30,
+	0x00, 0xe2, 0x80, 0x5d,
+	0x00, 0xe2, 0x4e, 0x4d,
+	0x11, 0xea, 0x30, 0x59,
+	0x11, 0xea, 0x00, 0x00,
+	0x00, 0xe2, 0x80, 0x5d,
+	0x00, 0xe2, 0x4e, 0x4d,
+	0x33, 0xea, 0x30, 0x59,
+	0x33, 0xea, 0x00, 0x00,
+	0x00, 0xe2, 0x28, 0x43,
+	0x00, 0xea, 0x30, 0x59,
+	0x01, 0xea, 0x00, 0x30,
+	0x80, 0xf9, 0x64, 0x68,
+	0x00, 0xe2, 0x2e, 0x59,
+	0x11, 0xea, 0x30, 0x59,
+	0x11, 0xea, 0x00, 0x00,
+	0x80, 0xf9, 0x2e, 0x79,
+	0xff, 0xea, 0xd4, 0x0d,
+	0x22, 0xea, 0x30, 0x59,
+	0x22, 0xea, 0x00, 0x00,
+	0x10, 0x16, 0x76, 0x78,
+	0x01, 0x0b, 0xa2, 0x32,
+	0x10, 0x16, 0x2c, 0x00,
+	0x18, 0xad, 0xe4, 0x78,
+	0x04, 0xad, 0xb2, 0x68,
+	0x80, 0xad, 0x4e, 0x7d,
+	0x10, 0xad, 0x80, 0x78,
+	0xe7, 0xad, 0x5a, 0x0d,
+	0xe7, 0xad, 0x5a, 0x09,
+	0x00, 0xe2, 0x8e, 0x58,
+	0xff, 0xea, 0x56, 0x02,
+	0x04, 0x7c, 0x78, 0x32,
+	0x20, 0x16, 0x4e, 0x7d,
+	0x04, 0x38, 0x79, 0x32,
+	0x80, 0x37, 0x6f, 0x16,
+	0xff, 0x2d, 0x9d, 0x60,
+	0xff, 0x29, 0x9d, 0x60,
+	0x40, 0x51, 0xad, 0x78,
+	0xff, 0x4f, 0x9d, 0x68,
+	0xff, 0x4d, 0xc1, 0x19,
+	0x00, 0x4e, 0xd5, 0x19,
+	0x00, 0xe2, 0xac, 0x50,
+	0x01, 0x4c, 0xc1, 0x31,
+	0x00, 0x50, 0xd5, 0x19,
+	0x00, 0xe2, 0xac, 0x48,
+	0x80, 0x18, 0x4e, 0x7d,
+	0x02, 0x4a, 0x1d, 0x30,
+	0x10, 0xea, 0x18, 0x00,
+	0x60, 0x18, 0x30, 0x00,
+	0x7f, 0x18, 0x30, 0x0c,
+	0x02, 0xea, 0x02, 0x00,
+	0xff, 0xea, 0xa0, 0x0a,
+	0x80, 0x18, 0x30, 0x04,
+	0x40, 0xad, 0x4e, 0x7d,
+	0xe7, 0xad, 0x5a, 0x09,
+	0x02, 0xa8, 0x40, 0x31,
+	0xff, 0xea, 0xc0, 0x09,
+	0x01, 0x4e, 0x9d, 0x1a,
+	0x00, 0x4f, 0x9f, 0x22,
+	0x04, 0x94, 0x49, 0x32,
+	0xff, 0xea, 0x2a, 0x03,
+	0xff, 0xea, 0x2e, 0x03,
+	0x01, 0x10, 0xd4, 0x31,
+	0x10, 0xa8, 0xd9, 0x68,
+	0x3d, 0xa9, 0xc5, 0x29,
+	0xfe, 0xe2, 0xc4, 0x09,
+	0x01, 0xea, 0xc6, 0x01,
+	0x02, 0xe2, 0xc8, 0x31,
+	0x02, 0xec, 0x50, 0x31,
+	0x02, 0xa0, 0xda, 0x31,
+	0xff, 0xa9, 0xd8, 0x70,
+	0x02, 0xa0, 0x28, 0x37,
+	0xff, 0x21, 0xe1, 0x70,
+	0x02, 0x22, 0x51, 0x31,
+	0x02, 0xa0, 0x2c, 0x33,
+	0x02, 0xa0, 0x44, 0x36,
+	0x02, 0xa0, 0x40, 0x32,
+	0x02, 0xa0, 0x44, 0x36,
+	0x04, 0x47, 0xe9, 0x68,
+	0x40, 0x16, 0x14, 0x69,
+	0xff, 0x2d, 0x19, 0x61,
+	0xff, 0x29, 0x4f, 0x75,
+	0x01, 0x37, 0xc1, 0x31,
+	0x02, 0x28, 0x55, 0x32,
+	0x01, 0xea, 0x5a, 0x01,
+	0x04, 0x3c, 0xf9, 0x30,
+	0x02, 0x28, 0x51, 0x31,
+	0x01, 0xa8, 0x60, 0x31,
+	0x00, 0xa9, 0x60, 0x01,
+	0x01, 0x14, 0xd4, 0x31,
+	0x01, 0x50, 0xa1, 0x1a,
+	0xff, 0x4e, 0x9d, 0x1a,
+	0xff, 0x4f, 0x9f, 0x22,
+	0xff, 0x8d, 0x0d, 0x71,
+	0x80, 0xac, 0x0c, 0x71,
+	0x20, 0x16, 0x0c, 0x69,
+	0x02, 0x8c, 0x51, 0x31,
+	0x00, 0xe2, 0xf6, 0x40,
+	0x01, 0xac, 0x08, 0x31,
+	0x09, 0xea, 0x5a, 0x01,
+	0x02, 0x8c, 0x51, 0x32,
+	0xff, 0xea, 0x1a, 0x07,
+	0x04, 0x24, 0xf9, 0x30,
+	0x1d, 0xea, 0x24, 0x41,
+	0x02, 0x2c, 0x51, 0x31,
+	0x04, 0xac, 0xf9, 0x30,
+	0x19, 0xea, 0x24, 0x59,
+	0x02, 0x8c, 0x59, 0x32,
+	0x02, 0x28, 0x19, 0x33,
+	0x02, 0xa8, 0x50, 0x36,
+	0x06, 0xea, 0x08, 0x81,
+	0x01, 0xe2, 0x5a, 0x35,
+	0x02, 0xa8, 0xf4, 0x31,
+	0x02, 0xf2, 0xf0, 0x35,
+	0x02, 0xf2, 0xf0, 0x31,
+	0x02, 0xf8, 0xe4, 0x35,
+	0x80, 0xea, 0xb2, 0x01,
+	0x01, 0xe2, 0x00, 0x30,
+	0xff, 0xea, 0xb2, 0x0d,
+	0x80, 0xea, 0xb2, 0x01,
+	0x11, 0x00, 0x00, 0x10,
+	0xff, 0xea, 0xb2, 0x0d,
+	0x01, 0xe2, 0x04, 0x30,
+	0x01, 0xea, 0x04, 0x34,
+	0x02, 0x20, 0xbd, 0x30,
+	0x02, 0x20, 0xb9, 0x30,
+	0x02, 0x20, 0x51, 0x31,
+	0x4c, 0xa9, 0xd7, 0x28,
+	0x10, 0xa8, 0x4f, 0x79,
+	0x01, 0x6b, 0xc0, 0x30,
+	0x02, 0x64, 0xc8, 0x00,
+	0x40, 0x3a, 0x74, 0x04,
+	0x00, 0xe2, 0x5c, 0x58,
+	0x33, 0xea, 0x30, 0x59,
+	0x33, 0xea, 0x00, 0x00,
+	0x30, 0x3f, 0xc0, 0x09,
+	0x30, 0xe0, 0x50, 0x61,
+	0x20, 0x3f, 0x66, 0x69,
+	0x10, 0x3f, 0x50, 0x79,
+	0x02, 0xea, 0x7e, 0x00,
+	0x00, 0xea, 0x30, 0x59,
+	0x01, 0xea, 0x00, 0x30,
+	0x02, 0x48, 0x51, 0x35,
+	0x01, 0xea, 0x7e, 0x00,
+	0x11, 0xea, 0x30, 0x59,
+	0x11, 0xea, 0x00, 0x00,
+	0x02, 0x48, 0x51, 0x35,
+	0x08, 0xea, 0x98, 0x00,
+	0x08, 0x57, 0xae, 0x00,
+	0x08, 0x3c, 0x78, 0x00,
+	0xf0, 0x49, 0x68, 0x0a,
+	0x0f, 0x67, 0xc0, 0x09,
+	0x00, 0x34, 0x69, 0x02,
+	0x20, 0xea, 0x96, 0x00,
+	0x00, 0xe2, 0xdc, 0x41,
+	0x40, 0x3a, 0x9a, 0x69,
+	0x02, 0x55, 0x06, 0x68,
+	0x02, 0x56, 0x9a, 0x69,
+	0xff, 0x5b, 0x9a, 0x61,
+	0x02, 0x20, 0x51, 0x31,
+	0x80, 0xea, 0xb2, 0x01,
+	0x44, 0xea, 0x00, 0x00,
+	0x01, 0x33, 0xc0, 0x31,
+	0x33, 0xea, 0x00, 0x00,
+	0xff, 0xea, 0xb2, 0x09,
+	0xff, 0xe0, 0xc0, 0x19,
+	0xff, 0xe0, 0x9c, 0x79,
+	0x02, 0x94, 0x51, 0x31,
+	0x00, 0xe2, 0x92, 0x41,
+	0x02, 0x5e, 0x50, 0x31,
+	0x02, 0xa8, 0xb8, 0x30,
+	0x02, 0x5c, 0x50, 0x31,
+	0xff, 0x95, 0xad, 0x71,
+	0x02, 0x94, 0x41, 0x31,
+	0x02, 0x22, 0x51, 0x31,
+	0x02, 0xa0, 0x2c, 0x33,
+	0x02, 0xa0, 0x44, 0x32,
+	0x00, 0xe2, 0xb6, 0x41,
+	0x10, 0xa8, 0xb7, 0x69,
+	0x3d, 0xa9, 0xc9, 0x29,
+	0x01, 0xe4, 0xc8, 0x01,
+	0x01, 0xea, 0xca, 0x01,
+	0xff, 0xea, 0xda, 0x01,
+	0x02, 0x20, 0x51, 0x31,
+	0x02, 0x96, 0x41, 0x32,
+	0xff, 0x21, 0xbf, 0x61,
+	0xff, 0xea, 0x46, 0x02,
+	0x02, 0x5c, 0x50, 0x31,
+	0x40, 0xea, 0x96, 0x00,
+	0x02, 0x56, 0x94, 0x6d,
+	0x01, 0x55, 0x94, 0x6d,
+	0x10, 0xa8, 0xcb, 0x79,
+	0x10, 0x40, 0xcc, 0x69,
+	0x01, 0x56, 0x06, 0x68,
+	0xbf, 0x3a, 0x74, 0x08,
+	0x08, 0xea, 0x98, 0x00,
+	0x08, 0x57, 0xae, 0x00,
+	0x01, 0xa9, 0x69, 0x32,
+	0x01, 0xaa, 0x6b, 0x32,
+	0x08, 0x3c, 0x78, 0x00,
+	0x80, 0xea, 0x62, 0x02,
+	0x40, 0xea, 0x66, 0x02,
+	0x00, 0xe2, 0x92, 0x5b,
+	0x01, 0x36, 0xc1, 0x31,
+	0x9f, 0xe0, 0x26, 0x7c,
+	0x80, 0xe0, 0xf0, 0x71,
+	0xa0, 0xe0, 0x28, 0x72,
+	0xc0, 0xe0, 0x1e, 0x72,
+	0xe0, 0xe0, 0x58, 0x72,
+	0x01, 0xea, 0x3c, 0x59,
+	0x01, 0xea, 0x04, 0x00,
+	0x00, 0xe2, 0xdc, 0x41,
+	0x80, 0x33, 0xf7, 0x79,
+	0x03, 0xea, 0x3c, 0x59,
+	0x03, 0xea, 0x04, 0x00,
+	0xee, 0x00, 0xfe, 0x69,
+	0x05, 0xea, 0xb4, 0x00,
+	0x33, 0xea, 0x30, 0x59,
+	0x33, 0xea, 0x00, 0x00,
+	0x02, 0xa8, 0x90, 0x32,
+	0x00, 0xe2, 0x56, 0x59,
+	0xef, 0x92, 0xd5, 0x19,
+	0x00, 0xe2, 0x0e, 0x52,
+	0x0b, 0x84, 0xe1, 0x30,
+	0x02, 0xea, 0x36, 0x00,
+	0xa8, 0xea, 0x32, 0x00,
+	0x00, 0xe2, 0x14, 0x42,
+	0x01, 0x92, 0xd1, 0x30,
+	0x10, 0x80, 0x89, 0x31,
+	0x20, 0xea, 0x32, 0x00,
+	0xbf, 0x33, 0x67, 0x0a,
+	0x20, 0x19, 0x16, 0x6a,
+	0x02, 0x4d, 0xdc, 0x69,
+	0x40, 0x33, 0x67, 0x02,
+	0x00, 0xe2, 0xdc, 0x41,
+	0x80, 0x33, 0x95, 0x6a,
+	0x01, 0x44, 0x10, 0x33,
+	0x08, 0xa8, 0x51, 0x03,
+	0x00, 0xe2, 0xdc, 0x41,
+	0x10, 0xea, 0x80, 0x00,
+	0x01, 0x31, 0xc5, 0x31,
+	0x80, 0xe2, 0x44, 0x62,
+	0x10, 0xa8, 0x69, 0x6a,
+	0xc0, 0xaa, 0xc5, 0x01,
+	0x40, 0xa8, 0x35, 0x6a,
+	0xbf, 0xe2, 0xc4, 0x09,
+	0x20, 0xa8, 0x49, 0x7a,
+	0x01, 0xe2, 0x88, 0x30,
+	0x00, 0xe2, 0x92, 0x5b,
+	0xa0, 0x36, 0x51, 0x62,
+	0x23, 0xa8, 0x89, 0x08,
+	0x00, 0xe2, 0x92, 0x5b,
+	0xa0, 0x36, 0x51, 0x62,
+	0x00, 0xa8, 0x48, 0x42,
+	0xff, 0xe2, 0x48, 0x62,
+	0x00, 0xe2, 0x68, 0x42,
+	0x40, 0xea, 0x98, 0x00,
+	0x01, 0xe2, 0x88, 0x30,
+	0x00, 0xe2, 0x92, 0x5b,
+	0xa0, 0x36, 0x27, 0x72,
+	0x40, 0xea, 0x98, 0x00,
+	0x01, 0x31, 0x89, 0x32,
+	0x08, 0xea, 0x62, 0x02,
+	0x00, 0xe2, 0xdc, 0x41,
+	0xe0, 0xea, 0xa2, 0x5b,
+	0x80, 0xe0, 0xa0, 0x6a,
+	0x04, 0xe0, 0x40, 0x73,
+	0x02, 0xe0, 0x70, 0x73,
+	0x00, 0xea, 0xfe, 0x72,
+	0x03, 0xe0, 0x80, 0x73,
+	0x23, 0xe0, 0x7a, 0x72,
+	0x08, 0xe0, 0x9c, 0x72,
+	0x00, 0xe2, 0x92, 0x5b,
+	0x07, 0xea, 0x3c, 0x59,
+	0x07, 0xea, 0x04, 0x00,
+	0x08, 0x42, 0xdd, 0x71,
+	0x04, 0x42, 0x77, 0x62,
+	0x01, 0x43, 0x89, 0x30,
+	0x00, 0xe2, 0x68, 0x42,
+	0x01, 0x44, 0xd4, 0x31,
+	0x00, 0xe2, 0x68, 0x42,
+	0x01, 0x00, 0x60, 0x32,
+	0x33, 0xea, 0x30, 0x59,
+	0x33, 0xea, 0x00, 0x00,
+	0x4c, 0x34, 0xc1, 0x28,
+	0x01, 0x64, 0xc0, 0x31,
+	0x00, 0x30, 0x31, 0x59,
+	0x01, 0x30, 0x01, 0x30,
+	0x01, 0xe0, 0x9a, 0x7a,
+	0xa0, 0xea, 0x98, 0x5b,
+	0x01, 0xa0, 0x9a, 0x62,
+	0x01, 0x84, 0x93, 0x7a,
+	0x01, 0xa7, 0x9c, 0x7a,
+	0x00, 0xe2, 0x9c, 0x42,
+	0x03, 0xea, 0x3c, 0x59,
+	0x03, 0xea, 0x04, 0x00,
+	0x00, 0xe2, 0x9c, 0x42,
+	0x07, 0xea, 0xaa, 0x5b,
+	0x01, 0x44, 0xd4, 0x31,
+	0x00, 0xe2, 0xdc, 0x41,
+	0x3f, 0xe0, 0x6a, 0x0a,
+	0xc0, 0x34, 0xc1, 0x09,
+	0x00, 0x35, 0x51, 0x01,
+	0xff, 0xea, 0x52, 0x09,
+	0x30, 0x34, 0xc5, 0x09,
+	0x3d, 0xe2, 0xc4, 0x29,
+	0xb8, 0xe2, 0xc4, 0x19,
+	0x01, 0xea, 0xc6, 0x01,
+	0x02, 0xe2, 0xc8, 0x31,
+	0x02, 0xec, 0x40, 0x31,
+	0xff, 0xa1, 0xbc, 0x72,
+	0x02, 0xe8, 0xda, 0x31,
+	0x02, 0xa0, 0x50, 0x31,
+	0x00, 0xe2, 0xde, 0x42,
+	0x80, 0x33, 0x67, 0x02,
+	0x01, 0x44, 0xd4, 0x31,
+	0x00, 0xe2, 0x92, 0x5b,
+	0x01, 0x33, 0x67, 0x02,
+	0xe0, 0x36, 0xf9, 0x62,
+	0x02, 0x33, 0x67, 0x02,
+	0x20, 0x46, 0xf2, 0x62,
+	0xff, 0xea, 0x52, 0x09,
+	0xa8, 0xea, 0x98, 0x5b,
+	0x04, 0xa8, 0xd9, 0x7a,
+	0x01, 0x34, 0xc1, 0x31,
+	0x00, 0xa9, 0xd9, 0x62,
+	0x01, 0x35, 0xc1, 0x31,
+	0x00, 0xaa, 0xe3, 0x72,
+	0x01, 0xa9, 0x52, 0x11,
+	0xff, 0xa9, 0xce, 0x6a,
+	0x00, 0xe2, 0xf2, 0x42,
+	0x10, 0x33, 0x67, 0x02,
+	0x04, 0xa8, 0xf3, 0x7a,
+	0xfb, 0xa8, 0x51, 0x0b,
+	0xff, 0xea, 0x66, 0x0a,
+	0x01, 0xa4, 0xed, 0x6a,
+	0x02, 0xa8, 0x90, 0x32,
+	0x00, 0xe2, 0x56, 0x59,
+	0x10, 0xa8, 0x9d, 0x7a,
+	0xff, 0xea, 0xaa, 0x5b,
+	0x00, 0xe2, 0x9c, 0x42,
+	0x04, 0xea, 0x3c, 0x59,
+	0x04, 0xea, 0x04, 0x00,
+	0x00, 0xe2, 0x9c, 0x42,
+	0x04, 0xea, 0x3c, 0x59,
+	0x04, 0xea, 0x04, 0x00,
+	0x00, 0xe2, 0xdc, 0x41,
+	0x08, 0xa8, 0x95, 0x7a,
+	0xc0, 0x33, 0x09, 0x7b,
+	0x80, 0x33, 0x95, 0x6a,
+	0xff, 0x88, 0x09, 0x6b,
+	0x40, 0x33, 0x95, 0x6a,
+	0x10, 0xa8, 0x0f, 0x7b,
+	0x0a, 0xea, 0x3c, 0x59,
+	0x0a, 0xea, 0x04, 0x00,
+	0x00, 0xe2, 0x28, 0x5b,
+	0x00, 0xe2, 0x5c, 0x43,
+	0x50, 0x4b, 0x16, 0x6b,
+	0xbf, 0x3a, 0x74, 0x08,
+	0x01, 0xe0, 0xf8, 0x31,
+	0xff, 0xea, 0xc0, 0x09,
+	0x01, 0x2e, 0x5d, 0x1a,
+	0x00, 0x2f, 0x5f, 0x22,
+	0x04, 0x47, 0x8f, 0x02,
+	0x01, 0xfc, 0xc0, 0x35,
+	0x33, 0xea, 0x30, 0x59,
+	0x33, 0xea, 0x00, 0x00,
+	0x02, 0x42, 0x51, 0x31,
+	0x10, 0xa8, 0x51, 0x03,
+	0xff, 0x88, 0x37, 0x6b,
+	0x01, 0xa4, 0x33, 0x6b,
+	0x02, 0xa4, 0x3b, 0x6b,
+	0x01, 0x84, 0x3b, 0x7b,
+	0x02, 0x28, 0x19, 0x33,
+	0x02, 0xa8, 0x50, 0x36,
+	0xff, 0x88, 0x3b, 0x73,
+	0x00, 0xe2, 0x12, 0x5b,
+	0x02, 0x2c, 0x19, 0x33,
+	0x02, 0xa8, 0x58, 0x32,
+	0x04, 0xa4, 0x49, 0x07,
+	0xc0, 0x33, 0x95, 0x6a,
+	0x04, 0xa8, 0x51, 0x03,
+	0x20, 0xa8, 0x5d, 0x6b,
+	0x02, 0xa8, 0x40, 0x31,
+	0xc0, 0x34, 0xc1, 0x09,
+	0x00, 0x35, 0x51, 0x01,
+	0xff, 0xea, 0x52, 0x09,
+	0x30, 0x34, 0xc5, 0x09,
+	0x3d, 0xe2, 0xc4, 0x29,
+	0xb8, 0xe2, 0xc4, 0x19,
+	0x01, 0xea, 0xc6, 0x01,
+	0x02, 0xe2, 0xc8, 0x31,
+	0x02, 0xa0, 0xda, 0x31,
+	0x02, 0xa0, 0x50, 0x31,
+	0xf7, 0x57, 0xae, 0x08,
+	0x08, 0xea, 0x98, 0x00,
+	0x01, 0x44, 0xd4, 0x31,
+	0xee, 0x00, 0x66, 0x6b,
+	0x02, 0xea, 0xb4, 0x00,
+	0x00, 0xe2, 0x8e, 0x5b,
+	0x09, 0x4c, 0x68, 0x7b,
+	0x08, 0x4c, 0x06, 0x68,
+	0x0b, 0xea, 0x3c, 0x59,
+	0x0b, 0xea, 0x04, 0x00,
+	0x01, 0x44, 0xd4, 0x31,
+	0x20, 0x33, 0xdd, 0x79,
+	0x00, 0xe2, 0x78, 0x5b,
+	0x00, 0xe2, 0xdc, 0x41,
+	0x01, 0x84, 0x7d, 0x7b,
+	0x01, 0xa4, 0x49, 0x07,
+	0x08, 0x60, 0x30, 0x33,
+	0x08, 0x80, 0x41, 0x37,
+	0xdf, 0x33, 0x67, 0x0a,
+	0xee, 0x00, 0x8a, 0x6b,
+	0x05, 0xea, 0xb4, 0x00,
+	0x33, 0xea, 0x30, 0x59,
+	0x33, 0xea, 0x00, 0x00,
+	0x00, 0xe2, 0x56, 0x59,
+	0x00, 0xe2, 0x9c, 0x42,
+	0x01, 0xea, 0x6c, 0x02,
+	0xc0, 0xea, 0x66, 0x06,
+	0xff, 0x42, 0x92, 0x7b,
+	0x04, 0x4c, 0x92, 0x6b,
+	0xe0, 0x41, 0x6c, 0x0e,
+	0x01, 0x44, 0xd4, 0x31,
+	0xff, 0x42, 0x9a, 0x7b,
+	0x04, 0x4c, 0x9a, 0x6b,
+	0xe0, 0x41, 0x6c, 0x0a,
+	0xe0, 0x36, 0xdd, 0x61,
+	0xff, 0xea, 0xca, 0x09,
+	0x01, 0xe2, 0xc8, 0x31,
+	0x01, 0x46, 0xda, 0x35,
+	0x01, 0x44, 0xd4, 0x35,
+	0x10, 0xea, 0x80, 0x00,
+	0x01, 0xe2, 0x62, 0x36,
+	0x04, 0xa6, 0xb2, 0x7b,
+	0xff, 0xea, 0x5a, 0x09,
+	0xff, 0xea, 0x4c, 0x0d,
+	0x01, 0xa6, 0xd0, 0x6b,
+	0x10, 0xad, 0x4e, 0x7d,
+	0x80, 0xad, 0xc8, 0x6b,
+	0x08, 0xad, 0x4e, 0x6d,
+	0x04, 0x84, 0xf9, 0x30,
+	0x00, 0xea, 0x08, 0x81,
+	0xff, 0xea, 0xd4, 0x09,
+	0x02, 0x84, 0xf9, 0x88,
+	0x1d, 0xea, 0x5a, 0x01,
+	0x04, 0xa6, 0x4c, 0x05,
+	0x04, 0xa6, 0x4e, 0x7d,
+	0xff, 0xea, 0x5a, 0x09,
+	0x03, 0x84, 0x59, 0x89,
+	0x03, 0xea, 0x4c, 0x01,
+	0x80, 0x1a, 0x4e, 0x7d,
+	0x08, 0xb0, 0xe0, 0x30,
+	0x04, 0xb0, 0xe0, 0x30,
+	0x03, 0xb0, 0xf0, 0x30,
+	0x01, 0x78, 0xdc, 0x7b,
+	0x01, 0xa7, 0x4e, 0x11,
+	0x01, 0xb0, 0x06, 0x33,
+	0x7f, 0x83, 0xe9, 0x08,
+	0x04, 0xac, 0x58, 0x19,
+	0xff, 0xea, 0xc0, 0x09,
+	0x04, 0x84, 0x09, 0x9b,
+	0x00, 0x85, 0x0b, 0x23,
+	0x00, 0x86, 0x0d, 0x23,
+	0x00, 0x87, 0x0f, 0x23,
+	0x01, 0x84, 0xc5, 0x31,
+	0x01, 0xa7, 0xf2, 0x7b,
+	0x04, 0xe2, 0xc4, 0x01,
+	0x80, 0x83, 0xf9, 0x7b,
+	0x02, 0xe2, 0xc4, 0x01,
+	0xff, 0xea, 0x4c, 0x09,
+	0x01, 0xe2, 0x36, 0x30,
+	0xc8, 0x19, 0x32, 0x00,
+	0x88, 0x19, 0x32, 0x00,
+	0x01, 0xac, 0xd4, 0x99,
+	0x00, 0xe2, 0x4e, 0x55,
+	0xfe, 0xa6, 0x4c, 0x0d,
+	0x0b, 0x98, 0xe1, 0x30,
+	0x01, 0xa0, 0x4f, 0x09,
+	0xfd, 0xa4, 0x49, 0x09,
+	0x80, 0xa3, 0x0f, 0x7c,
+	0x02, 0xa4, 0x48, 0x01,
+	0x01, 0xa7, 0x12, 0x7c,
+	0x04, 0xa4, 0x48, 0x01,
+	0x01, 0xa4, 0x36, 0x30,
+	0xa8, 0xea, 0x32, 0x00,
+	0xfd, 0xa4, 0x49, 0x0b,
+	0x05, 0xa3, 0x07, 0x33,
+	0x80, 0x83, 0x1f, 0x6c,
+	0x02, 0xea, 0x4c, 0x05,
+	0xff, 0xea, 0x4c, 0x0d,
+	0x00, 0xe2, 0x28, 0x59,
+	0x02, 0xa6, 0xb4, 0x6b,
+	0x80, 0xf9, 0xf2, 0x05,
+	0xc0, 0x33, 0x2d, 0x7c,
+	0x03, 0xea, 0x3c, 0x59,
+	0x03, 0xea, 0x04, 0x00,
+	0x20, 0x33, 0x51, 0x7c,
+	0x01, 0x84, 0x37, 0x6c,
+	0x06, 0xea, 0x3c, 0x59,
+	0x06, 0xea, 0x04, 0x00,
+	0x00, 0xe2, 0x54, 0x44,
+	0x01, 0x00, 0x60, 0x32,
+	0xee, 0x00, 0x40, 0x6c,
+	0x05, 0xea, 0xb4, 0x00,
+	0x33, 0xea, 0x30, 0x59,
+	0x33, 0xea, 0x00, 0x00,
+	0x80, 0x3d, 0x7a, 0x00,
+	0xfc, 0x42, 0x42, 0x7c,
+	0x7f, 0x3d, 0x7a, 0x08,
+	0x00, 0x30, 0x31, 0x59,
+	0x01, 0x30, 0x01, 0x30,
+	0x09, 0xea, 0x3c, 0x59,
+	0x09, 0xea, 0x04, 0x00,
+	0x00, 0xe2, 0xdc, 0x41,
+	0x01, 0xa4, 0x37, 0x6c,
+	0x00, 0xe2, 0x04, 0x5c,
+	0x20, 0x33, 0x67, 0x02,
+	0x01, 0x00, 0x60, 0x32,
+	0x02, 0xa6, 0x5c, 0x7c,
+	0x00, 0xe2, 0x20, 0x5c,
+	0x00, 0xe2, 0x5c, 0x58,
+	0x00, 0xe2, 0x6c, 0x58,
+	0x00, 0xe2, 0x30, 0x58,
+	0x00, 0x30, 0x31, 0x59,
+	0x01, 0x30, 0x01, 0x30,
+	0x20, 0x19, 0x5c, 0x6c,
+	0x00, 0xe2, 0x84, 0x5c,
+	0x04, 0x19, 0x76, 0x6c,
+	0x02, 0x19, 0x32, 0x00,
+	0x01, 0x84, 0x77, 0x7c,
+	0x01, 0x1b, 0x70, 0x7c,
+	0x01, 0x1a, 0x76, 0x6c,
+	0x00, 0xe2, 0x26, 0x44,
+	0x80, 0x4b, 0x7c, 0x6c,
+	0x01, 0x4c, 0x78, 0x7c,
+	0x03, 0x42, 0x26, 0x6c,
+	0x00, 0xe2, 0xae, 0x5b,
+	0x80, 0xf9, 0xf2, 0x01,
+	0x04, 0x33, 0xdd, 0x79,
+	0x00, 0xe2, 0xdc, 0x41,
+	0x02, 0x1b, 0x8c, 0x7c,
+	0x08, 0x5d, 0x8a, 0x7c,
+	0x03, 0x68, 0x00, 0x37,
+	0x01, 0x84, 0x09, 0x07,
+	0x08, 0x5d, 0x96, 0x6c,
+	0x00, 0xe2, 0x5c, 0x58,
+	0x00, 0x30, 0x31, 0x59,
+	0x01, 0x30, 0x01, 0x30,
+	0x00, 0xe2, 0x84, 0x44,
+	0x80, 0x1b, 0xa0, 0x7c,
+	0x80, 0x84, 0xa1, 0x6c,
+	0xff, 0x85, 0x0b, 0x1b,
+	0xff, 0x86, 0x0d, 0x23,
+	0xff, 0x87, 0x0f, 0x23,
+	0xf8, 0x1b, 0x08, 0x0b,
+	0xff, 0xea, 0x4e, 0x09,
+	0x04, 0x1b, 0xa8, 0x7c,
+	0x01, 0xa7, 0x4e, 0x01,
+	0xff, 0xea, 0x06, 0x0b,
+	0x03, 0x68, 0x00, 0x37,
+	0x00, 0xe2, 0xac, 0x58,
+	0x10, 0xea, 0x18, 0x00,
+	0xf9, 0xd9, 0xb2, 0x0d,
+	0x01, 0xd9, 0xb2, 0x05,
+	0xff, 0xea, 0xd4, 0x09,
+	0x10, 0x5b, 0xcc, 0x6c,
+	0x08, 0x5b, 0xd4, 0x6c,
+	0x20, 0x5b, 0xc2, 0x6c,
+	0x02, 0x5b, 0xe2, 0x6d,
+	0x0e, 0xea, 0x3c, 0x59,
+	0x0e, 0xea, 0x04, 0x00,
+	0x08, 0x19, 0xc8, 0x7c,
+	0xdf, 0x5c, 0xb8, 0x08,
+	0x01, 0xd9, 0xb2, 0x05,
+	0x02, 0xea, 0xb4, 0x00,
+	0x01, 0xd9, 0xb2, 0x05,
+	0x01, 0xa4, 0xab, 0x6d,
+	0x00, 0xe2, 0x04, 0x5c,
+	0x00, 0xe2, 0xee, 0x5c,
+	0x01, 0xd9, 0xb2, 0x05,
+	0x00, 0xe2, 0x12, 0x5b,
+	0xf3, 0x92, 0xd5, 0x19,
+	0x00, 0xe2, 0xe2, 0x54,
+	0x80, 0x92, 0xe3, 0x6c,
+	0x0f, 0xea, 0x3c, 0x59,
+	0x0f, 0xea, 0x04, 0x00,
+	0x00, 0xe2, 0xea, 0x44,
+	0x04, 0x8c, 0xe1, 0x30,
+	0x01, 0xea, 0xf2, 0x00,
+	0x02, 0xea, 0x36, 0x00,
+	0xa8, 0xea, 0x32, 0x00,
+	0x00, 0xe2, 0x70, 0x5d,
+	0x01, 0xd9, 0xb2, 0x05,
+	0x02, 0xa8, 0xf4, 0x31,
+	0x02, 0xa6, 0x00, 0x7d,
+	0x00, 0xe2, 0x2a, 0x59,
+	0x20, 0x5b, 0x0e, 0x6d,
+	0xfc, 0x42, 0xfa, 0x7c,
+	0x10, 0x40, 0xfc, 0x6c,
+	0x20, 0x4d, 0xfe, 0x7c,
+	0x08, 0x5d, 0x0e, 0x6d,
+	0x02, 0xa6, 0xb4, 0x6b,
+	0x00, 0xe2, 0x2a, 0x59,
+	0x20, 0x5b, 0x0e, 0x6d,
+	0x01, 0x1b, 0x2e, 0x6d,
+	0xfc, 0x42, 0x0a, 0x7d,
+	0x10, 0x40, 0x0c, 0x6d,
+	0x20, 0x4d, 0x4e, 0x7d,
+	0x08, 0x5d, 0x4e, 0x7d,
+	0x02, 0x19, 0x32, 0x00,
+	0x01, 0x5b, 0x40, 0x31,
+	0x00, 0xe2, 0x84, 0x5c,
+	0x00, 0xe2, 0x78, 0x5b,
+	0x20, 0xea, 0xb6, 0x00,
+	0x00, 0xe2, 0xae, 0x5b,
+	0x20, 0x5c, 0xb8, 0x00,
+	0x04, 0x19, 0x24, 0x6d,
+	0x01, 0x1a, 0x24, 0x6d,
+	0x00, 0xe2, 0x2a, 0x59,
+	0x01, 0x1a, 0x4e, 0x7d,
+	0x80, 0xf9, 0xf2, 0x01,
+	0x20, 0xa0, 0x94, 0x7d,
+	0x08, 0xa8, 0x2d, 0x7d,
+	0x00, 0xe2, 0x40, 0x45,
+	0x02, 0xea, 0xb4, 0x04,
+	0x02, 0x19, 0x32, 0x00,
+	0x08, 0xa8, 0x51, 0x7d,
+	0x04, 0x5d, 0xaa, 0x7d,
+	0x01, 0x1a, 0xaa, 0x7d,
+	0x01, 0xa4, 0x49, 0x03,
+	0x80, 0xf9, 0xf2, 0x01,
+	0x02, 0xa8, 0x84, 0x32,
+	0x02, 0xea, 0xb4, 0x00,
+	0x00, 0xe2, 0x22, 0x43,
+	0x02, 0xa8, 0x84, 0x32,
+	0x02, 0xea, 0xb4, 0x00,
+	0xff, 0xea, 0xd4, 0x19,
+	0x00, 0xe2, 0x36, 0x59,
+	0x11, 0x00, 0x00, 0x10,
+	0x00, 0xe2, 0x80, 0x5d,
+	0x00, 0xe2, 0x22, 0x53,
+	0xff, 0xea, 0xd4, 0x0d,
+	0x00, 0xe2, 0x2a, 0x59,
+	0x40, 0x5b, 0x5c, 0x6d,
+	0x04, 0x5d, 0xaa, 0x7d,
+	0x01, 0x1a, 0xaa, 0x7d,
+	0x20, 0x4d, 0x4e, 0x7d,
+	0x40, 0x5b, 0x94, 0x7d,
+	0x04, 0x5d, 0xaa, 0x7d,
+	0x01, 0x1a, 0xaa, 0x7d,
+	0x80, 0xf9, 0xf2, 0x01,
+	0x01, 0xa4, 0x49, 0x03,
+	0x08, 0xa8, 0x41, 0x6d,
+	0x02, 0xea, 0xb4, 0x04,
+	0xff, 0x6a, 0x76, 0x7d,
+	0x10, 0xea, 0x3c, 0x59,
+	0x10, 0xea, 0x04, 0x00,
+	0x00, 0xe2, 0x76, 0x45,
+	0x00, 0xe2, 0x28, 0x59,
+	0x10, 0x5d, 0x68, 0x6d,
+	0x40, 0x5b, 0x4e, 0x7d,
+	0x02, 0x19, 0x32, 0x00,
+	0x80, 0xf9, 0xf2, 0x01,
+	0xff, 0xea, 0x10, 0x03,
+	0x08, 0xa8, 0x51, 0x03,
+	0x00, 0xe2, 0x40, 0x45,
+	0x80, 0xf9, 0x4e, 0x6d,
+	0x01, 0x43, 0xc1, 0x31,
+	0x00, 0xfb, 0x4e, 0x65,
+	0x01, 0x42, 0xc1, 0x31,
+	0x00, 0xfa, 0x4e, 0x65,
+	0x01, 0xe8, 0xd4, 0x1d,
+	0x30, 0x3f, 0xc0, 0x09,
+	0x30, 0xe0, 0x4e, 0x65,
+	0x40, 0x4b, 0x4e, 0x6d,
+	0xff, 0xea, 0x52, 0x01,
+	0xee, 0x00, 0x9a, 0x6d,
+	0x80, 0xf9, 0xf2, 0x01,
+	0x02, 0xea, 0xb4, 0x00,
+	0x20, 0xea, 0x9a, 0x00,
+	0xf3, 0x42, 0xa4, 0x6d,
+	0x12, 0xea, 0x3c, 0x59,
+	0x12, 0xea, 0x04, 0x00,
+	0x00, 0xe2, 0xdc, 0x41,
+	0x0d, 0xea, 0x3c, 0x59,
+	0x0d, 0xea, 0x04, 0x00,
+	0x00, 0xe2, 0xdc, 0x41,
+	0x11, 0xea, 0x3c, 0x59,
+	0x11, 0xea, 0x04, 0x00,
+	0x00, 0xe2, 0x12, 0x5b,
+	0x08, 0x5a, 0xb4, 0x00,
+	0x00, 0xe2, 0xcc, 0x5d,
+	0xa8, 0xea, 0x32, 0x00,
+	0x00, 0xe2, 0x2a, 0x59,
+	0x80, 0x1a, 0xbe, 0x7d,
+	0x00, 0xe2, 0xcc, 0x5d,
+	0x80, 0x19, 0x32, 0x00,
+	0x40, 0x5b, 0xc4, 0x6d,
+	0x08, 0x5a, 0xc4, 0x7d,
+	0x20, 0x4d, 0x4e, 0x7d,
+	0x02, 0x84, 0x09, 0x03,
+	0x40, 0x5b, 0x94, 0x7d,
+	0x08, 0xa8, 0x39, 0x6d,
+	0x02, 0xea, 0xb4, 0x04,
+	0x01, 0x38, 0xe1, 0x30,
+	0x05, 0x39, 0xe3, 0x98,
+	0x01, 0xe0, 0xf8, 0x31,
+	0xff, 0xea, 0xc0, 0x09,
+	0x00, 0x3a, 0xe5, 0x20,
+	0x00, 0x3b, 0xe7, 0x20,
+	0x01, 0xfc, 0xc0, 0x31,
+	0x04, 0xea, 0xe8, 0x30,
+	0xff, 0xea, 0xf0, 0x08,
+	0x02, 0xea, 0xf2, 0x00,
+	0xff, 0xea, 0xf4, 0x0c
+};
+
+typedef int ahd_patch_func_t (struct ahd_softc *ahd);
+static ahd_patch_func_t ahd_patch18_func;
+
+static int
+ahd_patch18_func(struct ahd_softc *ahd)
+{
+	return ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0);
+}
+
+static ahd_patch_func_t ahd_patch17_func;
+
+static int
+ahd_patch17_func(struct ahd_softc *ahd)
+{
+	return ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) == 0);
+}
+
+static ahd_patch_func_t ahd_patch16_func;
+
+static int
+ahd_patch16_func(struct ahd_softc *ahd)
+{
+	return ((ahd->flags & AHD_INITIATORROLE) != 0);
+}
+
+static ahd_patch_func_t ahd_patch15_func;
+
+static int
+ahd_patch15_func(struct ahd_softc *ahd)
+{
+	return ((ahd->flags & AHD_TARGETROLE) != 0);
+}
+
+static ahd_patch_func_t ahd_patch14_func;
+
+static int
+ahd_patch14_func(struct ahd_softc *ahd)
+{
+	return ((ahd->bugs & AHD_AUTOFLUSH_BUG) != 0);
+}
+
+static ahd_patch_func_t ahd_patch13_func;
+
+static int
+ahd_patch13_func(struct ahd_softc *ahd)
+{
+	return ((ahd->features & AHD_NEW_DFCNTRL_OPTS) != 0);
+}
+
+static ahd_patch_func_t ahd_patch12_func;
+
+static int
+ahd_patch12_func(struct ahd_softc *ahd)
+{
+	return ((ahd->flags & AHD_39BIT_ADDRESSING) != 0);
+}
+
+static ahd_patch_func_t ahd_patch11_func;
+
+static int
+ahd_patch11_func(struct ahd_softc *ahd)
+{
+	return ((ahd->flags & AHD_64BIT_ADDRESSING) != 0);
+}
+
+static ahd_patch_func_t ahd_patch10_func;
+
+static int
+ahd_patch10_func(struct ahd_softc *ahd)
+{
+	return ((ahd->bugs & AHD_REG_SLOW_SETTLE_BUG) != 0);
+}
+
+static ahd_patch_func_t ahd_patch9_func;
+
+static int
+ahd_patch9_func(struct ahd_softc *ahd)
+{
+	return ((ahd->bugs & AHD_BUSFREEREV_BUG) == 0);
+}
+
+static ahd_patch_func_t ahd_patch8_func;
+
+static int
+ahd_patch8_func(struct ahd_softc *ahd)
+{
+	return ((ahd->bugs & AHD_ABORT_LQI_BUG) == 0);
+}
+
+static ahd_patch_func_t ahd_patch7_func;
+
+static int
+ahd_patch7_func(struct ahd_softc *ahd)
+{
+	return ((ahd->flags & AHD_SEQUENCER_DEBUG) != 0);
+}
+
+static ahd_patch_func_t ahd_patch6_func;
+
+static int
+ahd_patch6_func(struct ahd_softc *ahd)
+{
+	return ((ahd->bugs & AHD_LQO_ATNO_BUG) != 0);
+}
+
+static ahd_patch_func_t ahd_patch5_func;
+
+static int
+ahd_patch5_func(struct ahd_softc *ahd)
+{
+	return ((ahd->bugs & AHD_BUSFREEREV_BUG) != 0);
+}
+
+static ahd_patch_func_t ahd_patch4_func;
+
+static int
+ahd_patch4_func(struct ahd_softc *ahd)
+{
+	return ((ahd->bugs & AHD_NONPACKFIFO_BUG) != 0);
+}
+
+static ahd_patch_func_t ahd_patch3_func;
+
+static int
+ahd_patch3_func(struct ahd_softc *ahd)
+{
+	return ((ahd->bugs & AHD_SENT_SCB_UPDATE_BUG) != 0);
+}
+
+static ahd_patch_func_t ahd_patch2_func;
+
+static int
+ahd_patch2_func(struct ahd_softc *ahd)
+{
+	return ((ahd->bugs & AHD_SET_MODE_BUG) != 0);
+}
+
+static ahd_patch_func_t ahd_patch1_func;
+
+static int
+ahd_patch1_func(struct ahd_softc *ahd)
+{
+	return ((ahd->bugs & AHD_INTCOLLISION_BUG) != 0);
+}
+
+static ahd_patch_func_t ahd_patch0_func;
+
+static int
+ahd_patch0_func(struct ahd_softc *ahd)
+{
+	return (0);
+}
+
+static struct patch {
+	ahd_patch_func_t		*patch_func;
+	uint32_t		 begin		:10,
+				 skip_instr	:10,
+				 skip_patch	:12;
+} patches[] = {
+	{ ahd_patch1_func, 0, 3, 3 },
+	{ ahd_patch1_func, 1, 1, 2 },
+	{ ahd_patch0_func, 2, 1, 1 },
+	{ ahd_patch1_func, 3, 3, 3 },
+	{ ahd_patch1_func, 4, 1, 2 },
+	{ ahd_patch0_func, 5, 1, 1 },
+	{ ahd_patch2_func, 6, 1, 2 },
+	{ ahd_patch0_func, 7, 1, 1 },
+	{ ahd_patch2_func, 24, 1, 2 },
+	{ ahd_patch0_func, 25, 1, 1 },
+	{ ahd_patch2_func, 35, 1, 2 },
+	{ ahd_patch0_func, 36, 1, 1 },
+	{ ahd_patch2_func, 39, 1, 2 },
+	{ ahd_patch0_func, 40, 1, 1 },
+	{ ahd_patch2_func, 43, 1, 2 },
+	{ ahd_patch0_func, 44, 1, 1 },
+	{ ahd_patch2_func, 46, 1, 2 },
+	{ ahd_patch0_func, 47, 1, 1 },
+	{ ahd_patch2_func, 50, 1, 2 },
+	{ ahd_patch0_func, 51, 1, 1 },
+	{ ahd_patch2_func, 54, 1, 2 },
+	{ ahd_patch0_func, 55, 1, 1 },
+	{ ahd_patch2_func, 152, 6, 1 },
+	{ ahd_patch1_func, 158, 2, 1 },
+	{ ahd_patch3_func, 160, 1, 1 },
+	{ ahd_patch2_func, 169, 1, 2 },
+	{ ahd_patch0_func, 170, 1, 1 },
+	{ ahd_patch4_func, 171, 2, 2 },
+	{ ahd_patch0_func, 173, 6, 3 },
+	{ ahd_patch2_func, 176, 1, 2 },
+	{ ahd_patch0_func, 177, 1, 1 },
+	{ ahd_patch2_func, 180, 1, 2 },
+	{ ahd_patch0_func, 181, 1, 1 },
+	{ ahd_patch5_func, 183, 2, 1 },
+	{ ahd_patch3_func, 191, 16, 2 },
+	{ ahd_patch0_func, 207, 1, 1 },
+	{ ahd_patch6_func, 227, 2, 1 },
+	{ ahd_patch5_func, 231, 2, 1 },
+	{ ahd_patch1_func, 245, 1, 2 },
+	{ ahd_patch0_func, 246, 1, 1 },
+	{ ahd_patch1_func, 249, 1, 2 },
+	{ ahd_patch0_func, 250, 1, 1 },
+	{ ahd_patch2_func, 253, 1, 2 },
+	{ ahd_patch0_func, 254, 1, 1 },
+	{ ahd_patch1_func, 309, 1, 2 },
+	{ ahd_patch0_func, 310, 1, 1 },
+	{ ahd_patch2_func, 318, 1, 2 },
+	{ ahd_patch0_func, 319, 1, 1 },
+	{ ahd_patch2_func, 322, 1, 2 },
+	{ ahd_patch0_func, 323, 1, 1 },
+	{ ahd_patch1_func, 330, 1, 2 },
+	{ ahd_patch0_func, 331, 1, 1 },
+	{ ahd_patch7_func, 350, 1, 1 },
+	{ ahd_patch7_func, 353, 1, 1 },
+	{ ahd_patch7_func, 355, 1, 1 },
+	{ ahd_patch7_func, 367, 1, 1 },
+	{ ahd_patch1_func, 377, 1, 2 },
+	{ ahd_patch0_func, 378, 1, 1 },
+	{ ahd_patch1_func, 380, 1, 2 },
+	{ ahd_patch0_func, 381, 1, 1 },
+	{ ahd_patch1_func, 389, 1, 2 },
+	{ ahd_patch0_func, 390, 1, 1 },
+	{ ahd_patch2_func, 401, 1, 2 },
+	{ ahd_patch0_func, 402, 1, 1 },
+	{ ahd_patch8_func, 404, 1, 1 },
+	{ ahd_patch9_func, 431, 1, 1 },
+	{ ahd_patch1_func, 438, 1, 2 },
+	{ ahd_patch0_func, 439, 1, 1 },
+	{ ahd_patch2_func, 451, 1, 2 },
+	{ ahd_patch0_func, 452, 1, 1 },
+	{ ahd_patch10_func, 480, 1, 1 },
+	{ ahd_patch11_func, 489, 1, 2 },
+	{ ahd_patch0_func, 490, 1, 1 },
+	{ ahd_patch12_func, 495, 1, 1 },
+	{ ahd_patch11_func, 496, 1, 1 },
+	{ ahd_patch13_func, 509, 1, 2 },
+	{ ahd_patch0_func, 510, 1, 1 },
+	{ ahd_patch1_func, 532, 1, 2 },
+	{ ahd_patch0_func, 533, 1, 1 },
+	{ ahd_patch1_func, 536, 1, 2 },
+	{ ahd_patch0_func, 537, 1, 1 },
+	{ ahd_patch2_func, 542, 1, 2 },
+	{ ahd_patch0_func, 543, 1, 1 },
+	{ ahd_patch2_func, 547, 1, 2 },
+	{ ahd_patch0_func, 548, 1, 1 },
+	{ ahd_patch1_func, 549, 1, 2 },
+	{ ahd_patch0_func, 550, 1, 1 },
+	{ ahd_patch2_func, 561, 1, 2 },
+	{ ahd_patch0_func, 562, 1, 1 },
+	{ ahd_patch14_func, 566, 1, 1 },
+	{ ahd_patch15_func, 571, 1, 1 },
+	{ ahd_patch16_func, 572, 2, 1 },
+	{ ahd_patch15_func, 576, 1, 2 },
+	{ ahd_patch0_func, 577, 1, 1 },
+	{ ahd_patch2_func, 584, 1, 2 },
+	{ ahd_patch0_func, 585, 1, 1 },
+	{ ahd_patch2_func, 600, 1, 2 },
+	{ ahd_patch0_func, 601, 1, 1 },
+	{ ahd_patch1_func, 607, 1, 2 },
+	{ ahd_patch0_func, 608, 1, 1 },
+	{ ahd_patch1_func, 622, 1, 2 },
+	{ ahd_patch0_func, 623, 1, 1 },
+	{ ahd_patch14_func, 647, 1, 1 },
+	{ ahd_patch14_func, 663, 1, 1 },
+	{ ahd_patch2_func, 675, 1, 2 },
+	{ ahd_patch0_func, 676, 1, 1 },
+	{ ahd_patch1_func, 693, 1, 2 },
+	{ ahd_patch0_func, 694, 1, 1 },
+	{ ahd_patch14_func, 699, 1, 1 },
+	{ ahd_patch1_func, 719, 1, 2 },
+	{ ahd_patch0_func, 720, 1, 1 },
+	{ ahd_patch1_func, 722, 1, 2 },
+	{ ahd_patch0_func, 723, 1, 1 },
+	{ ahd_patch1_func, 725, 1, 2 },
+	{ ahd_patch0_func, 726, 1, 1 },
+	{ ahd_patch17_func, 728, 1, 2 },
+	{ ahd_patch0_func, 729, 2, 1 },
+	{ ahd_patch18_func, 732, 4, 2 },
+	{ ahd_patch0_func, 736, 1, 1 },
+	{ ahd_patch18_func, 742, 11, 1 }
+};
+
+static struct cs {
+	uint16_t	begin;
+	uint16_t	end;
+} critical_sections[] = {
+	{ 11, 12 },
+	{ 13, 14 },
+	{ 24, 32 },
+	{ 33, 46 },
+	{ 59, 62 },
+	{ 89, 114 },
+	{ 115, 146 },
+	{ 148, 152 },
+	{ 160, 168 },
+	{ 191, 224 },
+	{ 647, 663 },
+	{ 663, 681 },
+	{ 686, 692 },
+	{ 699, 704 },
+	{ 704, 710 }
+};
+
+static const int num_critical_sections = sizeof(critical_sections)
+				       / sizeof(*critical_sections);
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx.h b/drivers/scsi/aic7xxx/aic7xxx.h
--- a/drivers/scsi/aic7xxx/aic7xxx.h	Mon Dec 23 21:21:55 2002
+++ b/drivers/scsi/aic7xxx/aic7xxx.h	Mon Dec 23 21:21:55 2002
@@ -37,9 +37,9 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.h#34 $
+ * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.h#66 $
  *
- * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx.h,v 1.30 2000/11/10 20:13:40 gibbs Exp $
+ * $FreeBSD$
  */
 
 #ifndef _AIC7XXX_H_
@@ -51,6 +51,7 @@
 /************************* Forward Declarations *******************************/
 struct ahc_platform_data;
 struct scb_platform_data;
+struct seeprom_descriptor;
 
 /****************************** Useful Macros *********************************/
 #ifndef MAX
@@ -97,6 +98,14 @@
 	(SCB_GET_TARGET(ahc, scb) + (SCB_IS_SCSIBUS_B(ahc, scb) ? 8 : 0))
 #define SCB_GET_TARGET_MASK(ahc, scb) \
 	(0x01 << (SCB_GET_TARGET_OFFSET(ahc, scb)))
+#ifdef AHC_DEBUG
+#define SCB_IS_SILENT(scb)					\
+	((ahc_debug & AHC_SHOW_MASKED_ERRORS) == 0		\
+      && (((scb)->flags & SCB_SILENT) != 0))
+#else
+#define SCB_IS_SILENT(scb)					\
+	(((scb)->flags & SCB_SILENT) != 0)
+#endif
 #define TCL_TARGET_OFFSET(tcl) \
 	((((tcl) >> 4) & TID) >> 4)
 #define TCL_LUN(tcl) \
@@ -170,7 +179,7 @@
 #define AHC_TMODE_CMDS	256
 
 /* Reset line assertion time in us */
-#define AHC_BUSRESET_DELAY	250
+#define AHC_BUSRESET_DELAY	25
 
 /******************* Chip Characteristics/Operating Settings  *****************/
 /*
@@ -350,9 +359,11 @@
 					   */
 	AHC_BIOS_ENABLED      = 0x80000,
 	AHC_ALL_INTERRUPTS    = 0x100000,
-	AHC_PAGESCBS	      = 0x400000, /* Enable SCB paging */
-	AHC_EDGE_INTERRUPT    = 0x800000, /* Device uses edge triggered ints */
-	AHC_39BIT_ADDRESSING  = 0x1000000 /* Use 39 bit addressing scheme. */
+	AHC_PAGESCBS	      = 0x400000,  /* Enable SCB paging */
+	AHC_EDGE_INTERRUPT    = 0x800000,  /* Device uses edge triggered ints */
+	AHC_39BIT_ADDRESSING  = 0x1000000, /* Use 39 bit addressing scheme. */
+	AHC_LSCBS_ENABLED     = 0x2000000, /* 64Byte SCBs enabled */
+	AHC_SCB_CONFIG_USED   = 0x4000000  /* No SEEPROM but SCB2 had info. */
 } ahc_flag;
 
 /************************* Hardware  SCB Definition ***************************/
@@ -531,10 +542,27 @@
 	SCB_RECOVERY_SCB	= 0x0020,
 	SCB_AUTO_NEGOTIATE	= 0x0040,/* Negotiate to achieve goal. */
 	SCB_NEGOTIATE		= 0x0080,/* Negotiation forced for command. */
-	SCB_ABORT		= 0x1000,
-	SCB_UNTAGGEDQ		= 0x2000,
-	SCB_ACTIVE		= 0x4000,
-	SCB_TARGET_IMMEDIATE	= 0x8000
+	SCB_ABORT		= 0x0100,
+	SCB_UNTAGGEDQ		= 0x0200,
+	SCB_ACTIVE		= 0x0400,
+	SCB_TARGET_IMMEDIATE	= 0x0800,
+	SCB_TRANSMISSION_ERROR	= 0x1000,/*
+					  * We detected a parity or CRC
+					  * error that has effected the
+					  * payload of the command.  This
+					  * flag is checked when normal
+					  * status is returned to catch
+					  * the case of a target not
+					  * responding to our attempt
+					  * to report the error.
+					  */
+	SCB_TARGET_SCB		= 0x2000,
+	SCB_SILENT		= 0x4000 /*
+					  * Be quiet about transmission type
+					  * errors.  They are expected and we
+					  * don't want to upset the user.  This
+					  * flag is typically used during DV.
+					  */
 } scb_flag;
 
 struct scb {
@@ -659,6 +687,11 @@
 #define AHC_TRANS_GOAL		0x04	/* Modify negotiation goal */
 #define AHC_TRANS_USER		0x08	/* Modify user negotiation settings */
 
+#define AHC_WIDTH_UNKNOWN	0xFF
+#define AHC_PERIOD_UNKNOWN	0xFF
+#define AHC_OFFSET_UNKNOWN	0x0
+#define AHC_PPR_OPTS_UNKNOWN	0xFF
+
 /*
  * Transfer Negotiation Information.
  */
@@ -713,10 +746,9 @@
 	char *rate;
 };
 
-/*
- * The synchronouse transfer rate table.
- */
-extern struct ahc_syncrate ahc_syncrates[];
+/* Safe and valid period for async negotiations. */
+#define	AHC_ASYNC_XFER_PERIOD 0x45
+#define	AHC_ULTRA2_XFER_PERIOD 0x0a
 
 /*
  * Indexes into our table of syncronous transfer rates.
@@ -725,6 +757,7 @@
 #define AHC_SYNCRATE_ULTRA2	1
 #define AHC_SYNCRATE_ULTRA	3
 #define AHC_SYNCRATE_FAST	6
+#define AHC_SYNCRATE_MAX	AHC_SYNCRATE_DT
 
 /***************************** Lookup Tables **********************************/
 /*
@@ -799,7 +832,7 @@
 #define		CFSEAUTOTERM	0x0400	/* Ultra2 Perform secondary Auto Term*/
 #define		CFSELOWTERM	0x0800	/* Ultra2 secondary low term */
 #define		CFSEHIGHTERM	0x1000	/* Ultra2 secondary high term */
-#define		CFDOMAINVAL	0x4000	/* Perform Domain Validation*/
+#define		CFENABLEDV	0x4000	/* Perform Domain Validation*/
 
 /*
  * Bus Release Time, Host Adapter ID
@@ -866,6 +899,7 @@
 };
 
 typedef void (*ahc_bus_intr_t)(struct ahc_softc *);
+typedef void ahc_callback_t (void *);
 
 struct ahc_softc {
 	bus_space_tag_t           tag;
@@ -941,6 +975,7 @@
 	ahc_feature		  features;
 	ahc_bug			  bugs;
 	ahc_flag		  flags;
+	struct seeprom_config	 *seep_config;
 
 	/* Values to store in the SEQCTL register for pause and unpause */
 	uint8_t			  unpause;
@@ -1017,6 +1052,9 @@
 	/* PCI cacheline size. */
 	u_int			  pci_cachesize;
 
+	u_int			  stack_size;
+	uint16_t		 *saved_stack;
+
 	/* Per-Unit descriptive information */
 	const char		 *description;
 	char			 *name;
@@ -1089,11 +1127,13 @@
 struct ahc_pci_identity	*ahc_find_pci_device(ahc_dev_softc_t);
 int			 ahc_pci_config(struct ahc_softc *,
 					struct ahc_pci_identity *);
+int			 ahc_pci_test_register_access(struct ahc_softc *);
 
 /*************************** EISA/VL Front End ********************************/
 struct aic7770_identity *aic7770_find_device(uint32_t);
 int			 aic7770_config(struct ahc_softc *ahc,
-					struct aic7770_identity *);
+					struct aic7770_identity *,
+					u_int port);
 
 /************************** SCB and SCB queue management **********************/
 int		ahc_probe_scbs(struct ahc_softc *);
@@ -1116,6 +1156,7 @@
 int			 ahc_suspend(struct ahc_softc *ahc); 
 int			 ahc_resume(struct ahc_softc *ahc);
 void			 ahc_softc_insert(struct ahc_softc *);
+struct ahc_softc	*ahc_find_softc(struct ahc_softc *ahc);
 void			 ahc_set_unit(struct ahc_softc *, int);
 void			 ahc_set_name(struct ahc_softc *, char *);
 void			 ahc_alloc_scbs(struct ahc_softc *ahc);
@@ -1146,6 +1187,11 @@
 					   char channel, int lun, u_int tag,
 					   role_t role, uint32_t status,
 					   ahc_search_action action);
+int			ahc_search_untagged_queues(struct ahc_softc *ahc,
+						   ahc_io_ctx_t ctx,
+						   int target, char channel,
+						   int lun, uint32_t status,
+						   ahc_search_action action);
 int			ahc_search_disc_list(struct ahc_softc *ahc, int target,
 					     char channel, int lun, u_int tag,
 					     int stop_on_first, int remove,
@@ -1157,7 +1203,8 @@
 				       char channel, int lun, u_int tag,
 				       role_t role, uint32_t status);
 void			ahc_restart(struct ahc_softc *ahc);
-void			ahc_calc_residual(struct scb *scb);
+void			ahc_calc_residual(struct ahc_softc *ahc,
+					  struct scb *scb);
 /*************************** Utility Functions ********************************/
 struct ahc_phase_table_entry*
 			ahc_lookup_phase_entry(int phase);
@@ -1179,11 +1226,20 @@
 					   struct ahc_initiator_tinfo *tinfo,
 					   u_int *bus_width,
 					   role_t role);
+/*
+ * Negotiation types.  These are used to qualify if we should renegotiate
+ * even if our goal and current transport parameters are identical.
+ */
+typedef enum {
+	AHC_NEG_TO_GOAL,	/* Renegotiate only if goal and curr differ. */
+	AHC_NEG_IF_NON_ASYNC,	/* Renegotiate so long as goal is non-async. */
+	AHC_NEG_ALWAYS		/* Renegotiat even if goal is async. */
+} ahc_neg_type;
 int			ahc_update_neg_request(struct ahc_softc*,
 					       struct ahc_devinfo*,
 					       struct ahc_tmode_tstate*,
 					       struct ahc_initiator_tinfo*,
-					       int /*force*/);
+					       ahc_neg_type);
 void			ahc_set_width(struct ahc_softc *ahc,
 				      struct ahc_devinfo *devinfo,
 				      u_int width, u_int type, int paused);
@@ -1219,6 +1275,35 @@
 #endif
 #endif
 /******************************* Debug ***************************************/
+#ifdef AHC_DEBUG
+extern uint32_t ahc_debug;
+#define	AHC_SHOW_MISC		0x0001
+#define	AHC_SHOW_SENSE		0x0002
+#define AHC_DUMP_SEEPROM	0x0004
+#define AHC_SHOW_TERMCTL	0x0008
+#define AHC_SHOW_MEMORY		0x0010
+#define AHC_SHOW_MESSAGES	0x0020
+#define	AHC_SHOW_DV		0x0040
+#define AHC_SHOW_SELTO		0x0080
+#define AHC_SHOW_QFULL		0x0200
+#define AHC_SHOW_QUEUE		0x0400
+#define AHC_SHOW_TQIN		0x0800
+#define AHC_SHOW_MASKED_ERRORS	0x1000
+#define AHC_DEBUG_SEQUENCER	0x2000
+#endif
 void			ahc_print_scb(struct scb *scb);
+void			ahc_print_devinfo(struct ahc_softc *ahc,
+					  struct ahc_devinfo *dev);
 void			ahc_dump_card_state(struct ahc_softc *ahc);
+int			ahc_print_register(ahc_reg_parse_entry_t *table,
+					   u_int num_entries,
+					   const char *name,
+					   u_int address,
+					   u_int value,
+					   u_int *cur_column,
+					   u_int wrap_point);
+/******************************* SEEPROM *************************************/
+int		ahc_acquire_seeprom(struct ahc_softc *ahc,
+				    struct seeprom_descriptor *sd);
+void		ahc_release_seeprom(struct seeprom_descriptor *sd);
 #endif /* _AIC7XXX_H_ */
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx.reg b/drivers/scsi/aic7xxx/aic7xxx.reg
--- a/drivers/scsi/aic7xxx/aic7xxx.reg	Mon Dec 23 21:22:02 2002
+++ b/drivers/scsi/aic7xxx/aic7xxx.reg	Mon Dec 23 21:22:02 2002
@@ -37,9 +37,9 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx.reg,v 1.31 2000/11/10 20:13:40 gibbs Exp $
+ * $FreeBSD$
  */
-VERSION = "$Id: //depot/aic7xxx/aic7xxx/aic7xxx.reg#24 $"
+VERSION = "$Id: //depot/aic7xxx/aic7xxx/aic7xxx.reg#36 $"
 
 /*
  * This file is processed by the aic7xxx_asm utility for use in assembling
@@ -57,14 +57,14 @@
 register SCSISEQ {
 	address			0x000
 	access_mode RW
-	bit	TEMODE		0x80
-	bit	ENSELO		0x40
-	bit	ENSELI		0x20
-	bit	ENRSELI		0x10
-	bit	ENAUTOATNO	0x08
-	bit	ENAUTOATNI	0x04
-	bit	ENAUTOATNP	0x02
-	bit	SCSIRSTO	0x01
+	field	TEMODE		0x80
+	field	ENSELO		0x40
+	field	ENSELI		0x20
+	field	ENRSELI		0x10
+	field	ENAUTOATNO	0x08
+	field	ENAUTOATNI	0x04
+	field	ENAUTOATNP	0x02
+	field	SCSIRSTO	0x01
 }
 
 /*
@@ -74,13 +74,13 @@
 register SXFRCTL0 {
 	address			0x001
 	access_mode RW
-	bit	DFON		0x80
-	bit	DFPEXP		0x40
-	bit	FAST20		0x20
-	bit	CLRSTCNT	0x10
-	bit	SPIOEN		0x08
-	bit	SCAMEN		0x04
-	bit	CLRCHN		0x02
+	field	DFON		0x80
+	field	DFPEXP		0x40
+	field	FAST20		0x20
+	field	CLRSTCNT	0x10
+	field	SPIOEN		0x08
+	field	SCAMEN		0x04
+	field	CLRCHN		0x02
 }
 
 /*
@@ -90,13 +90,13 @@
 register SXFRCTL1 {
 	address			0x002
 	access_mode RW
-	bit	BITBUCKET	0x80
-	bit	SWRAPEN		0x40
-	bit	ENSPCHK		0x20
+	field	BITBUCKET	0x80
+	field	SWRAPEN		0x40
+	field	ENSPCHK		0x20
 	mask	STIMESEL	0x18
-	bit	ENSTIMER	0x04
-	bit	ACTNEGEN	0x02
-	bit	STPWEN		0x01	/* Powered Termination */
+	field	ENSTIMER	0x04
+	field	ACTNEGEN	0x02
+	field	STPWEN		0x01	/* Powered Termination */
 }
 
 /*
@@ -106,14 +106,14 @@
 register SCSISIGI {
 	address			0x003
 	access_mode RO
-	bit	CDI		0x80
-	bit	IOI		0x40
-	bit	MSGI		0x20
-	bit	ATNI		0x10
-	bit	SELI		0x08
-	bit	BSYI		0x04
-	bit	REQI		0x02
-	bit	ACKI		0x01
+	field	CDI		0x80
+	field	IOI		0x40
+	field	MSGI		0x20
+	field	ATNI		0x10
+	field	SELI		0x08
+	field	BSYI		0x04
+	field	REQI		0x02
+	field	ACKI		0x01
 /*
  * Possible phases in SCSISIGI
  */
@@ -137,14 +137,14 @@
 register SCSISIGO {
 	address			0x003
 	access_mode WO
-	bit	CDO		0x80
-	bit	IOO		0x40
-	bit	MSGO		0x20
-	bit	ATNO		0x10
-	bit	SELO		0x08
-	bit	BSYO		0x04
-	bit	REQO		0x02
-	bit	ACKO		0x01
+	field	CDO		0x80
+	field	IOO		0x40
+	field	MSGO		0x20
+	field	ATNO		0x10
+	field	SELO		0x08
+	field	BSYO		0x04
+	field	REQO		0x02
+	field	ACKO		0x01
 /*
  * Possible phases to write into SCSISIG0
  */
@@ -167,9 +167,9 @@
 register SCSIRATE {
 	address			0x004
 	access_mode RW
-	bit	WIDEXFER	0x80		/* Wide transfer control */
-	bit	ENABLE_CRC	0x40		/* CRC for D-Phases */
-	bit	SINGLE_EDGE	0x10		/* Disable DT Transfers */
+	field	WIDEXFER	0x80		/* Wide transfer control */
+	field	ENABLE_CRC	0x40		/* CRC for D-Phases */
+	field	SINGLE_EDGE	0x10		/* Disable DT Transfers */
 	mask	SXFR		0x70		/* Sync transfer rate */
 	mask	SXFR_ULTRA2	0x0f		/* Sync transfer rate */
 	mask	SOFS		0x0f		/* Sync offset */
@@ -185,7 +185,7 @@
 	access_mode RW
 	mask	TID		0xf0		/* Target ID mask */
 	mask	TWIN_TID	0x70
-	bit	TWIN_CHNLB	0x80
+	field	TWIN_CHNLB	0x80
 	mask	OID		0x0f		/* Our ID mask */
 	/*
 	 * SCSI Maximum Offset (p. 4-61 aic7890/91 Data Book)
@@ -225,18 +225,27 @@
 	access_mode RW
 }
 
+/* ALT_MODE registers (Ultra2 and Ultra160 chips) */
+register SXFRCTL2 {
+	address			0x013
+	access_mode RW
+	field	AUTORSTDIS	0x10
+	field	CMDDMAEN	0x08
+	mask	ASYNC_SETUP	0x07
+}
+
 /* ALT_MODE register on Ultra160 chips */
 register OPTIONMODE {
 	address			0x008
 	access_mode RW
-	bit	AUTORATEEN		0x80
-	bit	AUTOACKEN		0x40
-	bit	ATNMGMNTEN		0x20
-	bit	BUSFREEREV		0x10
-	bit	EXPPHASEDIS		0x08
-	bit	SCSIDATL_IMGEN		0x04
-	bit	AUTO_MSGOUT_DE		0x02
-	bit	DIS_MSGIN_DUALEDGE	0x01
+	field	AUTORATEEN		0x80
+	field	AUTOACKEN		0x40
+	field	ATNMGMNTEN		0x20
+	field	BUSFREEREV		0x10
+	field	EXPPHASEDIS		0x08
+	field	SCSIDATL_IMGEN		0x04
+	field	AUTO_MSGOUT_DE		0x02
+	field	DIS_MSGIN_DUALEDGE	0x01
 	mask	OPTIONMODE_DEFAULTS	AUTO_MSGOUT_DE|DIS_MSGIN_DUALEDGE
 }
 
@@ -254,12 +263,12 @@
 register CLRSINT0 {
 	address			0x00b
 	access_mode WO
-	bit	CLRSELDO	0x40
-	bit	CLRSELDI	0x20
-	bit	CLRSELINGO	0x10
-	bit	CLRSWRAP	0x08
-	bit	CLRIOERR	0x08	/* Ultra2 Only */
-	bit	CLRSPIORDY	0x02
+	field	CLRSELDO	0x40
+	field	CLRSELDI	0x20
+	field	CLRSELINGO	0x10
+	field	CLRSWRAP	0x08
+	field	CLRIOERR	0x08	/* Ultra2 Only */
+	field	CLRSPIORDY	0x02
 }
 
 /*
@@ -270,15 +279,15 @@
 register SSTAT0	{
 	address			0x00b
 	access_mode RO
-	bit	TARGET		0x80	/* Board acting as target */
-	bit	SELDO		0x40	/* Selection Done */
-	bit	SELDI		0x20	/* Board has been selected */
-	bit	SELINGO		0x10	/* Selection In Progress */
-	bit	SWRAP		0x08	/* 24bit counter wrap */
-	bit	IOERR		0x08	/* LVD Tranceiver mode changed */
-	bit	SDONE		0x04	/* STCNT = 0x000000 */
-	bit	SPIORDY		0x02	/* SCSI PIO Ready */
-	bit	DMADONE		0x01	/* DMA transfer completed */
+	field	TARGET		0x80	/* Board acting as target */
+	field	SELDO		0x40	/* Selection Done */
+	field	SELDI		0x20	/* Board has been selected */
+	field	SELINGO		0x10	/* Selection In Progress */
+	field	SWRAP		0x08	/* 24bit counter wrap */
+	field	IOERR		0x08	/* LVD Tranceiver mode changed */
+	field	SDONE		0x04	/* STCNT = 0x000000 */
+	field	SPIORDY		0x02	/* SCSI PIO Ready */
+	field	DMADONE		0x01	/* DMA transfer completed */
 }
 
 /*
@@ -288,13 +297,13 @@
 register CLRSINT1 {
 	address			0x00c
 	access_mode WO
-	bit	CLRSELTIMEO	0x80
-	bit	CLRATNO		0x40
-	bit	CLRSCSIRSTI	0x20
-	bit	CLRBUSFREE	0x08
-	bit	CLRSCSIPERR	0x04
-	bit	CLRPHASECHG	0x02
-	bit	CLRREQINIT	0x01
+	field	CLRSELTIMEO	0x80
+	field	CLRATNO		0x40
+	field	CLRSCSIRSTI	0x20
+	field	CLRBUSFREE	0x08
+	field	CLRSCSIPERR	0x04
+	field	CLRPHASECHG	0x02
+	field	CLRREQINIT	0x01
 }
 
 /*
@@ -303,14 +312,14 @@
 register SSTAT1	{
 	address			0x00c
 	access_mode RO
-	bit	SELTO		0x80
-	bit	ATNTARG 	0x40
-	bit	SCSIRSTI	0x20
-	bit	PHASEMIS	0x10
-	bit	BUSFREE		0x08
-	bit	SCSIPERR	0x04
-	bit	PHASECHG	0x02
-	bit	REQINIT		0x01
+	field	SELTO		0x80
+	field	ATNTARG 	0x40
+	field	SCSIRSTI	0x20
+	field	PHASEMIS	0x10
+	field	BUSFREE		0x08
+	field	SCSIPERR	0x04
+	field	PHASECHG	0x02
+	field	REQINIT		0x01
 }
 
 /*
@@ -319,13 +328,13 @@
 register SSTAT2 {
 	address			0x00d
 	access_mode RO
-	bit	OVERRUN		0x80
-	bit	SHVALID		0x40	/* Shaddow Layer non-zero */
-	bit	EXP_ACTIVE	0x10	/* SCSI Expander Active */
-	bit	CRCVALERR	0x08	/* CRC doesn't match (U3 only) */
-	bit	CRCENDERR	0x04	/* No terminal CRC packet (U3 only) */
-	bit	CRCREQERR	0x02	/* Illegal CRC packet req (U3 only) */
-	bit	DUAL_EDGE_ERR	0x01	/* Incorrect data phase (U3 only) */
+	field	OVERRUN		0x80
+	field	SHVALID		0x40	/* Shaddow Layer non-zero */
+	field	EXP_ACTIVE	0x10	/* SCSI Expander Active */
+	field	CRCVALERR	0x08	/* CRC doesn't match (U3 only) */
+	field	CRCENDERR	0x04	/* No terminal CRC packet (U3 only) */
+	field	CRCREQERR	0x02	/* Illegal CRC packet req (U3 only) */
+	field	DUAL_EDGE_ERR	0x01	/* Incorrect data phase (U3 only) */
 	mask	SFCNT		0x1f
 }
 
@@ -358,14 +367,14 @@
 register SIMODE0 {
 	address			0x010
 	access_mode RW
-	bit	ENSELDO		0x40
-	bit	ENSELDI		0x20
-	bit	ENSELINGO	0x10
-	bit	ENSWRAP		0x08
-	bit	ENIOERR		0x08	/* LVD Tranceiver mode changes */
-	bit	ENSDONE		0x04
-	bit	ENSPIORDY	0x02
-	bit	ENDMADONE	0x01
+	field	ENSELDO		0x40
+	field	ENSELDI		0x20
+	field	ENSELINGO	0x10
+	field	ENSWRAP		0x08
+	field	ENIOERR		0x08	/* LVD Tranceiver mode changes */
+	field	ENSDONE		0x04
+	field	ENSPIORDY	0x02
+	field	ENDMADONE	0x01
 }
 
 /*
@@ -376,14 +385,14 @@
 register SIMODE1 {
 	address			0x011
 	access_mode RW
-	bit	ENSELTIMO	0x80
-	bit	ENATNTARG	0x40
-	bit	ENSCSIRST	0x20
-	bit	ENPHASEMIS	0x10
-	bit	ENBUSFREE	0x08
-	bit	ENSCSIPERR	0x04
-	bit	ENPHASECHG	0x02
-	bit	ENREQINIT	0x01
+	field	ENSELTIMO	0x80
+	field	ENATNTARG	0x40
+	field	ENSCSIRST	0x20
+	field	ENPHASEMIS	0x10
+	field	ENBUSFREE	0x08
+	field	ENSCSIPERR	0x04
+	field	ENPHASECHG	0x02
+	field	ENREQINIT	0x01
 }
 
 /*
@@ -420,12 +429,12 @@
 register SELTIMER {
 	address			0x018
 	access_mode RW
-	bit	STAGE6		0x20
-	bit	STAGE5		0x10
-	bit	STAGE4		0x08
-	bit	STAGE3		0x04
-	bit	STAGE2		0x02
-	bit	STAGE1		0x01
+	field	STAGE6		0x20
+	field	STAGE5		0x10
+	field	STAGE4		0x08
+	field	STAGE3		0x04
+	field	STAGE2		0x02
+	field	STAGE1		0x01
 	alias	TARGIDIN
 }
 
@@ -438,16 +447,16 @@
 	address			0x019
 	access_mode RW
 	mask	SELID_MASK	0xf0
-	bit	ONEBIT		0x08
+	field	ONEBIT		0x08
 }
 
 register SCAMCTL {
 	address			0x01a
 	access_mode RW
-	bit	ENSCAMSELO	0x80
-	bit	CLRSCAMSELID	0x40
-	bit	ALTSTIM		0x20
-	bit	DFLTTID		0x10
+	field	ENSCAMSELO	0x80
+	field	CLRSCAMSELID	0x40
+	field	ALTSTIM		0x20
+	field	DFLTTID		0x10
 	mask	SCAMLVL		0x03
 }
 
@@ -471,32 +480,32 @@
 register SPIOCAP {
 	address			0x01b
 	access_mode RW
-	bit	SOFT1		0x80
-	bit	SOFT0		0x40
-	bit	SOFTCMDEN	0x20	
-	bit	HAS_BRDCTL	0x10	/* External Board control */
-	bit	SEEPROM		0x08	/* External serial eeprom logic */
-	bit	EEPROM		0x04	/* Writable external BIOS ROM */
-	bit	ROM		0x02	/* Logic for accessing external ROM */
-	bit	SSPIOCPS	0x01	/* Termination and cable detection */
+	field	SOFT1		0x80
+	field	SOFT0		0x40
+	field	SOFTCMDEN	0x20	
+	field	EXT_BRDCTL	0x10	/* External Board control */
+	field	SEEPROM		0x08	/* External serial eeprom logic */
+	field	EEPROM		0x04	/* Writable external BIOS ROM */
+	field	ROM		0x02	/* Logic for accessing external ROM */
+	field	SSPIOCPS	0x01	/* Termination and cable detection */
 }
 
 register BRDCTL	{
 	address			0x01d
-	bit	BRDDAT7		0x80
-	bit	BRDDAT6		0x40
-	bit	BRDDAT5		0x20
-	bit	BRDSTB		0x10
-	bit	BRDCS		0x08
-	bit	BRDRW		0x04
-	bit	BRDCTL1		0x02
-	bit	BRDCTL0		0x01
+	field	BRDDAT7		0x80
+	field	BRDDAT6		0x40
+	field	BRDDAT5		0x20
+	field	BRDSTB		0x10
+	field	BRDCS		0x08
+	field	BRDRW		0x04
+	field	BRDCTL1		0x02
+	field	BRDCTL0		0x01
 	/* 7890 Definitions */
-	bit	BRDDAT4		0x10
-	bit	BRDDAT3		0x08
-	bit	BRDDAT2		0x04
-	bit	BRDRW_ULTRA2	0x02
-	bit	BRDSTB_ULTRA2	0x01
+	field	BRDDAT4		0x10
+	field	BRDDAT3		0x08
+	field	BRDDAT2		0x04
+	field	BRDRW_ULTRA2	0x02
+	field	BRDSTB_ULTRA2	0x01
 }
 
 /*
@@ -525,14 +534,14 @@
  */
 register SEECTL {
 	address			0x01e
-	bit	EXTARBACK	0x80
-	bit	EXTARBREQ	0x40
-	bit	SEEMS		0x20
-	bit	SEERDY		0x10
-	bit	SEECS		0x08
-	bit	SEECK		0x04
-	bit	SEEDO		0x02
-	bit	SEEDI		0x01
+	field	EXTARBACK	0x80
+	field	EXTARBREQ	0x40
+	field	SEEMS		0x20
+	field	SEERDY		0x10
+	field	SEECS		0x08
+	field	SEECK		0x04
+	field	SEEDO		0x02
+	field	SEEDI		0x01
 }
 /*
  * SCSI Block Control (p. 3-32)
@@ -544,14 +553,14 @@
 register SBLKCTL {
 	address			0x01f
 	access_mode RW
-	bit	DIAGLEDEN	0x80	/* Aic78X0 only */
-	bit	DIAGLEDON	0x40	/* Aic78X0 only */
-	bit	AUTOFLUSHDIS	0x20
-	bit	SELBUSB		0x08
-	bit	ENAB40		0x08	/* LVD transceiver active */
-	bit	ENAB20		0x04	/* SE/HVD transceiver active */
-	bit	SELWIDE		0x02
-	bit	XCVR		0x01	/* External transceiver active */
+	field	DIAGLEDEN	0x80	/* Aic78X0 only */
+	field	DIAGLEDON	0x40	/* Aic78X0 only */
+	field	AUTOFLUSHDIS	0x20
+	field	SELBUSB		0x08
+	field	ENAB40		0x08	/* LVD transceiver active */
+	field	ENAB20		0x04	/* SE/HVD transceiver active */
+	field	SELWIDE		0x02
+	field	XCVR		0x01	/* External transceiver active */
 }
 
 /*
@@ -561,14 +570,14 @@
 register SEQCTL {
 	address			0x060
 	access_mode RW
-	bit	PERRORDIS	0x80
-	bit	PAUSEDIS	0x40
-	bit	FAILDIS		0x20
-	bit	FASTMODE	0x10
-	bit	BRKADRINTEN	0x08
-	bit	STEP		0x04
-	bit	SEQRESET	0x02
-	bit	LOADRAM		0x01
+	field	PERRORDIS	0x80
+	field	PAUSEDIS	0x40
+	field	FAILDIS		0x20
+	field	FASTMODE	0x10
+	field	BRKADRINTEN	0x08
+	field	STEP		0x04
+	field	SEQRESET	0x02
+	field	LOADRAM		0x01
 }
 
 /*
@@ -640,8 +649,8 @@
 register FLAGS {
 	address			0x06b
 	access_mode RO
-	bit	ZERO		0x02
-	bit	CARRY		0x01
+	field	ZERO		0x02
+	field	CARRY		0x01
 }
 
 register SINDIR	{
@@ -670,8 +679,8 @@
 register BCTL {
 	address			0x084
 	access_mode RW
-	bit	ACE		0x08
-	bit	ENABLE		0x01
+	field	ACE		0x08
+	field	ENABLE		0x01
 }
 
 /*
@@ -681,23 +690,23 @@
 register DSCOMMAND0 {
 	address			0x084
 	access_mode RW
-	bit	CACHETHEN	0x80	/* Cache Threshold enable */
-	bit	DPARCKEN	0x40	/* Data Parity Check Enable */
-	bit	MPARCKEN	0x20	/* Memory Parity Check Enable */
-	bit	EXTREQLCK	0x10	/* External Request Lock */
+	field	CACHETHEN	0x80	/* Cache Threshold enable */
+	field	DPARCKEN	0x40	/* Data Parity Check Enable */
+	field	MPARCKEN	0x20	/* Memory Parity Check Enable */
+	field	EXTREQLCK	0x10	/* External Request Lock */
 	/* aic7890/91/96/97 only */
-	bit	INTSCBRAMSEL	0x08	/* Internal SCB RAM Select */
-	bit	RAMPS		0x04	/* External SCB RAM Present */
-	bit	USCBSIZE32	0x02	/* Use 32byte SCB Page Size */
-	bit	CIOPARCKEN	0x01	/* Internal bus parity error enable */
+	field	INTSCBRAMSEL	0x08	/* Internal SCB RAM Select */
+	field	RAMPS		0x04	/* External SCB RAM Present */
+	field	USCBSIZE32	0x02	/* Use 32byte SCB Page Size */
+	field	CIOPARCKEN	0x01	/* Internal bus parity error enable */
 }
 
 register DSCOMMAND1 {
 	address			0x085
 	access_mode RW
 	mask	DSLATT		0xfc	/* PCI latency timer (non-ultra2) */
-	bit	HADDLDSEL1	0x02	/* Host Address Load Select Bits */
-	bit	HADDLDSEL0	0x01
+	field	HADDLDSEL1	0x02	/* Host Address Load Select Bits */
+	field	HADDLDSEL0	0x01
 }
 
 /*
@@ -747,13 +756,13 @@
 register HCNTRL {
 	address			0x087
 	access_mode RW
-	bit	POWRDN		0x40
-	bit	SWINT		0x10
-	bit	IRQMS		0x08
-	bit	PAUSE		0x04
-	bit	INTEN		0x02
-	bit	CHIPRST		0x01
-	bit	CHIPRSTACK	0x01
+	field	POWRDN		0x40
+	field	SWINT		0x10
+	field	IRQMS		0x08
+	field	PAUSE		0x04
+	field	INTEN		0x02
+	field	CHIPRST		0x01
+	field	CHIPRSTACK	0x01
 }
 
 /*
@@ -789,13 +798,13 @@
 register INTSTAT {
 	address			0x091
 	access_mode RW
-	bit	BRKADRINT 0x08
-	bit	SCSIINT	  0x04
-	bit	CMDCMPLT  0x02
-	bit	SEQINT    0x01
+	field	BRKADRINT 0x08
+	field	SCSIINT	  0x04
+	field	CMDCMPLT  0x02
+	field	SEQINT    0x01
 	mask	BAD_PHASE	SEQINT		/* unknown scsi bus phase */
 	mask	SEND_REJECT	0x10|SEQINT	/* sending a message reject */
-	mask	NO_IDENT	0x20|SEQINT	/* no IDENTIFY after reconnect*/
+	mask	PROTO_VIOLATION	0x20|SEQINT	/* SCSI protocol violation */ 
 	mask	NO_MATCH	0x30|SEQINT	/* no cmd match for reconnect */
 	mask	IGN_WIDE_RES	0x40|SEQINT	/* Complex IGN Wide Res Msg */
 	mask	PDATA_REINIT	0x50|SEQINT	/*
@@ -858,14 +867,14 @@
 register ERROR {
 	address			0x092
 	access_mode RO
-	bit	CIOPARERR	0x80	/* Ultra2 only */
-	bit	PCIERRSTAT	0x40	/* PCI only */
-	bit	MPARERR		0x20	/* PCI only */
-	bit	DPARERR		0x10	/* PCI only */
-	bit	SQPARERR	0x08
-	bit	ILLOPCODE	0x04
-	bit	ILLSADDR	0x02
-	bit	ILLHADDR	0x01
+	field	CIOPARERR	0x80	/* Ultra2 only */
+	field	PCIERRSTAT	0x40	/* PCI only */
+	field	MPARERR		0x20	/* PCI only */
+	field	DPARERR		0x10	/* PCI only */
+	field	SQPARERR	0x08
+	field	ILLOPCODE	0x04
+	field	ILLSADDR	0x02
+	field	ILLHADDR	0x01
 }
 
 /*
@@ -874,39 +883,39 @@
 register CLRINT {
 	address			0x092
 	access_mode WO
-	bit	CLRPARERR	0x10	/* PCI only */
-	bit	CLRBRKADRINT	0x08
-	bit	CLRSCSIINT      0x04
-	bit	CLRCMDINT 	0x02
-	bit	CLRSEQINT 	0x01
+	field	CLRPARERR	0x10	/* PCI only */
+	field	CLRBRKADRINT	0x08
+	field	CLRSCSIINT      0x04
+	field	CLRCMDINT 	0x02
+	field	CLRSEQINT 	0x01
 }
 
 register DFCNTRL {
 	address			0x093
 	access_mode RW
-	bit	PRELOADEN	0x80	/* aic7890 only */
-	bit	WIDEODD		0x40
-	bit	SCSIEN		0x20
-	bit	SDMAEN		0x10
-	bit	SDMAENACK	0x10
-	bit	HDMAEN		0x08
-	bit	HDMAENACK	0x08
-	bit	DIRECTION	0x04
-	bit	FIFOFLUSH	0x02
-	bit	FIFORESET	0x01
+	field	PRELOADEN	0x80	/* aic7890 only */
+	field	WIDEODD		0x40
+	field	SCSIEN		0x20
+	field	SDMAEN		0x10
+	field	SDMAENACK	0x10
+	field	HDMAEN		0x08
+	field	HDMAENACK	0x08
+	field	DIRECTION	0x04
+	field	FIFOFLUSH	0x02
+	field	FIFORESET	0x01
 }
 
 register DFSTATUS {
 	address			0x094
 	access_mode RO
-	bit	PRELOAD_AVAIL	0x80
-	bit	DFCACHETH	0x40
-	bit	FIFOQWDEMP	0x20
-	bit	MREQPEND	0x10
-	bit	HDONE		0x08
-	bit	DFTHRESH	0x04
-	bit	FIFOFULL	0x02
-	bit	FIFOEMP		0x01
+	field	PRELOAD_AVAIL	0x80
+	field	DFCACHETH	0x40
+	field	FIFOQWDEMP	0x20
+	field	MREQPEND	0x10
+	field	HDONE		0x08
+	field	DFTHRESH	0x04
+	field	FIFOFULL	0x02
+	field	FIFOEMP		0x01
 }
 
 register DFWADDR {
@@ -932,7 +941,7 @@
 register SCBCNT {
 	address			0x09a
 	access_mode RW
-	bit	SCBAUTO		0x80
+	field	SCBAUTO		0x80
 	mask	SCBCNT_MASK	0x1f
 }
 
@@ -966,12 +975,12 @@
 register CRCCONTROL1 {
 	address			0x09d
 	access_mode RW
-	bit	CRCONSEEN		0x80
-	bit	CRCVALCHKEN		0x40
-	bit	CRCENDCHKEN		0x20
-	bit	CRCREQCHKEN		0x10
-	bit	TARGCRCENDEN		0x08
-	bit	TARGCRCCNTEN		0x04
+	field	CRCONSEEN		0x80
+	field	CRCVALCHKEN		0x40
+	field	CRCENDCHKEN		0x20
+	field	CRCREQCHKEN		0x10
+	field	TARGCRCENDEN		0x08
+	field	TARGCRCCNTEN		0x04
 }
 
 
@@ -987,12 +996,12 @@
 register SCSIPHASE {
 	address			0x09e
 	access_mode RO
-	bit	STATUS_PHASE	0x20
-	bit	COMMAND_PHASE	0x10
-	bit	MSG_IN_PHASE	0x08
-	bit	MSG_OUT_PHASE	0x04
-	bit	DATA_IN_PHASE	0x02
-	bit	DATA_OUT_PHASE	0x01
+	field	STATUS_PHASE	0x20
+	field	COMMAND_PHASE	0x10
+	field	MSG_IN_PHASE	0x08
+	field	MSG_OUT_PHASE	0x04
+	field	DATA_IN_PHASE	0x02
+	field	DATA_OUT_PHASE	0x01
 	mask	DATA_PHASE_MASK	0x03
 }
 
@@ -1002,14 +1011,16 @@
 register SFUNCT {
 	address			0x09f
 	access_mode RW
-	bit	ALT_MODE	0x80
+	field	ALT_MODE	0x80
 }
 
 /*
  * SCB Definition (p. 5-4)
  */
 scb {
-	address			0x0a0
+	address		0x0a0
+	size		64
+
 	SCB_CDB_PTR {
 		size	4
 		alias	SCB_RESIDUAL_DATACNT
@@ -1039,28 +1050,29 @@
 		 * the data address.
 		 */
 		size	4
-		bit	SG_LAST_SEG		0x80	/* In the fourth byte */
+		field	SG_LAST_SEG		0x80	/* In the fourth byte */
 		mask	SG_HIGH_ADDR_BITS	0x7F	/* In the fourth byte */
 	}
 	SCB_SGPTR {
 		size	4
-		bit	SG_RESID_VALID	0x04	/* In the first byte */
-		bit	SG_FULL_RESID	0x02	/* In the first byte */
-		bit	SG_LIST_NULL	0x01	/* In the first byte */
+		field	SG_RESID_VALID	0x04	/* In the first byte */
+		field	SG_FULL_RESID	0x02	/* In the first byte */
+		field	SG_LIST_NULL	0x01	/* In the first byte */
 	}
 	SCB_CONTROL {
 		size	1
-		bit	TARGET_SCB			0x80
-		bit	DISCENB				0x40
-		bit	TAG_ENB				0x20
-		bit	MK_MESSAGE			0x10
-		bit	ULTRAENB			0x08
-		bit	DISCONNECTED			0x04
+		field	TARGET_SCB			0x80
+		field	STATUS_RCVD			0x80
+		field	DISCENB				0x40
+		field	TAG_ENB				0x20
+		field	MK_MESSAGE			0x10
+		field	ULTRAENB			0x08
+		field	DISCONNECTED			0x04
 		mask	SCB_TAG_TYPE			0x03
 	}
 	SCB_SCSIID {
 		size	1
-		bit	TWIN_CHNLB			0x80
+		field	TWIN_CHNLB			0x80
 		mask	TWIN_TID			0x70
 		mask	TID				0xf0
 		mask	OID				0x0f
@@ -1103,18 +1115,18 @@
 register SEECTL_2840 {
 	address			0x0c0
 	access_mode RW
-	bit	CS_2840		0x04
-	bit	CK_2840		0x02
-	bit	DO_2840		0x01
+	field	CS_2840		0x04
+	field	CK_2840		0x02
+	field	DO_2840		0x01
 }
 
 register STATUS_2840 {
 	address			0x0c1
 	access_mode RW
-	bit	EEPROM_TF	0x80
+	field	EEPROM_TF	0x80
 	mask	BIOS_SEL	0x60
 	mask	ADSEL		0x1e
-	bit	DI_2840		0x01
+	field	DI_2840		0x01
 }
 
 /* --------------------- AIC-7870-only definitions -------------------- */
@@ -1138,10 +1150,10 @@
 
 register CCSGCTL {
 	address			0x0EB
-	bit	CCSGDONE	0x80
-	bit	CCSGEN		0x08
-	bit	SG_FETCH_NEEDED 0x02	/* Bit used for software state */
-	bit	CCSGRESET	0x01
+	field	CCSGDONE	0x80
+	field	CCSGEN		0x08
+	field	SG_FETCH_NEEDED 0x02	/* Bit used for software state */
+	field	CCSGRESET	0x01
 }
 
 register CCSCBCNT {
@@ -1150,12 +1162,12 @@
 
 register CCSCBCTL {
 	address			0x0EE
-	bit	CCSCBDONE	0x80
-	bit	ARRDONE		0x40	/* SCB Array prefetch done */
-	bit	CCARREN		0x10
-	bit	CCSCBEN		0x08
-	bit	CCSCBDIR	0x04
-	bit	CCSCBRESET	0x01
+	field	CCSCBDONE	0x80
+	field	ARRDONE		0x40	/* SCB Array prefetch done */
+	field	CCARREN		0x10
+	field	CCSCBEN		0x08
+	field	CCSCBDIR	0x04
+	field	CCSCBRESET	0x01
 }
 
 register CCSCBADDR {
@@ -1192,9 +1204,9 @@
 
 register QOFF_CTLSTA {
 	address			0x0FA
-	bit	SCB_AVAIL	0x40
-	bit	SNSCB_ROLLOVER	0x20
-	bit	SDSCB_ROLLOVER	0x10
+	field	SCB_AVAIL	0x40
+	field	SNSCB_ROLLOVER	0x20
+	field	SDSCB_ROLLOVER	0x10
 	mask	SCB_QSIZE	0x07
 	mask	SCB_QSIZE_256	0x06
 }
@@ -1225,18 +1237,18 @@
 	access_mode WO
 	address			0x0fc
 	mask	SG_ADDR_MASK	0xf8
-	bit	ODD_SEG		0x04
-	bit	LAST_SEG	0x02
-	bit	LAST_SEG_DONE	0x01
+	field	ODD_SEG		0x04
+	field	LAST_SEG	0x02
+	field	LAST_SEG_DONE	0x01
 }
 
 register SG_CACHE_SHADOW {
 	access_mode RO
 	address			0x0fc
 	mask	SG_ADDR_MASK	0xf8
-	bit	ODD_SEG		0x04
-	bit	LAST_SEG	0x02
-	bit	LAST_SEG_DONE	0x01
+	field	ODD_SEG		0x04
+	field	LAST_SEG	0x02
+	field	LAST_SEG_DONE	0x01
 }
 /* ---------------------- Scratch RAM Offsets ------------------------- */
 /* These offsets are either to values that are initialized by the board's
@@ -1254,7 +1266,8 @@
  */
 
 scratch_ram {
-	address			0x020
+	address		0x020
+	size		58
 
 	/*
 	 * 1 byte per target starting at this address for configuration values
@@ -1292,6 +1305,7 @@
 	 */
 	MWI_RESIDUAL {
 		size		1
+		alias	TARG_IMMEDIATE_SCB
 	}
 	/*
 	 * SCBID of the next SCB to be started by the controller.
@@ -1309,28 +1323,29 @@
 	/* Parameters for DMA Logic */
 	DMAPARAMS {
 		size		1
-		bit	PRELOADEN	0x80
-		bit	WIDEODD		0x40
-		bit	SCSIEN		0x20
-		bit	SDMAEN		0x10
-		bit	SDMAENACK	0x10
-		bit	HDMAEN		0x08
-		bit	HDMAENACK	0x08
-		bit	DIRECTION	0x04
-		bit	FIFOFLUSH	0x02
-		bit	FIFORESET	0x01
+		field	PRELOADEN	0x80
+		field	WIDEODD		0x40
+		field	SCSIEN		0x20
+		field	SDMAEN		0x10
+		field	SDMAENACK	0x10
+		field	HDMAEN		0x08
+		field	HDMAENACK	0x08
+		field	DIRECTION	0x04	/* Set indicates PCI->SCSI */
+		field	FIFOFLUSH	0x02
+		field	FIFORESET	0x01
 	}
 	SEQ_FLAGS {
 		size		1
-		bit	IDENTIFY_SEEN		0x80
-		bit	TARGET_CMD_IS_TAGGED	0x40
-		bit	DPHASE			0x20
+		field	NOT_IDENTIFIED		0x80
+		field	NO_CDB_SENT		0x40
+		field	TARGET_CMD_IS_TAGGED	0x40
+		field	DPHASE			0x20
 		/* Target flags */
-		bit	TARG_CMD_PENDING	0x10
-		bit	CMDPHASE_PENDING	0x08
-		bit	DPHASE_PENDING		0x04
-		bit	SPHASE_PENDING		0x02
-		bit	NO_DISCONNECT		0x01
+		field	TARG_CMD_PENDING	0x10
+		field	CMDPHASE_PENDING	0x08
+		field	DPHASE_PENDING		0x04
+		field	SPHASE_PENDING		0x02
+		field	NO_DISCONNECT		0x01
 	}
 	/*
 	 * Temporary storage for the
@@ -1348,9 +1363,9 @@
 	 */
 	LASTPHASE {
 		size		1
-		bit	CDI		0x80
-		bit	IOI		0x40
-		bit	MSGI		0x20
+		field	CDI		0x80
+		field	IOI		0x40
+		field	MSGI		0x20
 		mask	PHASE_MASK	CDI|IOI|MSGI
 		mask	P_DATAOUT	0x00
 		mask	P_DATAIN	IOI
@@ -1454,12 +1469,12 @@
 	 */
 	SCSISEQ_TEMPLATE {
 		size		1
-		bit	ENSELO		0x40
-		bit	ENSELI		0x20
-		bit	ENRSELI		0x10
-		bit	ENAUTOATNO	0x08
-		bit	ENAUTOATNI	0x04
-		bit	ENAUTOATNP	0x02
+		field	ENSELO		0x40
+		field	ENSELI		0x20
+		field	ENRSELI		0x10
+		field	ENAUTOATNO	0x08
+		field	ENAUTOATNI	0x04
+		field	ENAUTOATNP	0x02
 	}
 
 	/*
@@ -1469,37 +1484,57 @@
 	DATA_COUNT_ODD {
 		size		1
 	}
+}
+
+scratch_ram {
+	address		0x056
+	size		4
+	/*
+	 * These scratch ram locations are initialized by the 274X BIOS.
+	 * We reuse them after capturing the BIOS settings during
+	 * initialization.
+	 */
 
 	/*
 	 * The initiator specified tag for this target mode transaction.
 	 */
-	INITIATOR_TAG {
-		size		1
+	HA_274_BIOSGLOBAL {
+		size	1
+		field	HA_274_EXTENDED_TRANS	0x01
+		alias	INITIATOR_TAG
 	}
 
 	SEQ_FLAGS2 {
-		size		1
-		bit	SCB_DMA			  0x01
-		bit	TARGET_MSG_PENDING	  0x02
+		size	1
+		field	SCB_DMA			0x01
+		field	TARGET_MSG_PENDING	0x02
 	}
+}
+
+scratch_ram {
+	address		0x05a
+	size		6
 	/*
-	 * These are reserved registers in the card's scratch ram.  Some of
-	 * the values are specified in the AHA2742 technical reference manual
-	 * and are initialized by the BIOS at boot time.
+	 * These are reserved registers in the card's scratch ram on the 2742.
+	 * The EISA configuraiton chip is mapped here.  On Rev E. of the
+	 * aic7770, the sequencer can use this area for scratch, but the
+	 * host cannot directly access these registers.  On later chips, this
+	 * area can be read and written by both the host and the sequencer.
+	 * Even on later chips, many of these locations are initialized by
+	 * the BIOS.
 	 */
 	SCSICONF {
-		address		0x05a
 		size		1
-		bit	TERM_ENB	0x80
-		bit	RESET_SCSI	0x40
-		bit	ENSPCHK		0x20
+		field	TERM_ENB	0x80
+		field	RESET_SCSI	0x40
+		field	ENSPCHK		0x20
 		mask	HSCSIID		0x07	/* our SCSI ID */
 		mask	HWSCSIID	0x0f	/* our SCSI ID if Wide Bus */
 	}
 	INTDEF {
 		address		0x05c
 		size		1
-		bit	EDGE_TRIG	0x80
+		field	EDGE_TRIG	0x80
 		mask	VECTOR		0x0f
 	}
 	HOSTCONF {
@@ -1511,13 +1546,18 @@
 		size		1
 		mask	BIOSMODE		0x30
 		mask	BIOSDISABLED		0x30	
-		bit	CHANNEL_B_PRIMARY	0x08
+		field	CHANNEL_B_PRIMARY	0x08
 	}
+}
+
+scratch_ram {
+	address		0x070
+	size		16
+
 	/*
 	 * Per target SCSI offset values for Ultra2 controllers.
 	 */
 	TARG_OFFSET {
-		address		0x070
 		size		16
 	}
 }
@@ -1538,6 +1578,7 @@
 const MAX_OFFSET_8BIT		0x0f
 const MAX_OFFSET_16BIT		0x08
 const MAX_OFFSET_ULTRA2		0x7f
+const MAX_OFFSET		0xff
 const HOST_MSG			0xff
 
 /* Target mode command processing constants */
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx.seq b/drivers/scsi/aic7xxx/aic7xxx.seq
--- a/drivers/scsi/aic7xxx/aic7xxx.seq	Mon Dec 23 21:21:59 2002
+++ b/drivers/scsi/aic7xxx/aic7xxx.seq	Mon Dec 23 21:21:59 2002
@@ -37,10 +37,12 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx.seq,v 1.106 2000/11/12 05:19:46 gibbs Exp $
+ * $FreeBSD$
  */
 
-VERSION = "$Id: //depot/aic7xxx/aic7xxx/aic7xxx.seq#37 $"
+VERSION = "$Id: //depot/aic7xxx/aic7xxx/aic7xxx.seq#52 $"
+PATCH_ARG_LIST = "struct ahc_softc *ahc"
+PREFIX = "ahc_"
 
 #include "aic7xxx.reg"
 #include "scsi_message.h"
@@ -89,7 +91,7 @@
 	test	SSTAT0, SELDO|SELDI	jnz selection;
 test_queue:
 	/* Has the driver posted any work for us? */
-BEGIN_CRITICAL
+BEGIN_CRITICAL;
 	if ((ahc->features & AHC_QUEUE_REGS) != 0) {
 		test	QOFF_CTLSTA, SCB_AVAIL jz poll_for_work_loop;
 	} else {
@@ -110,7 +112,7 @@
 		mov	SCBPTR, ARG_1;
 	}
 	or	SEQ_FLAGS2, SCB_DMA;
-END_CRITICAL
+END_CRITICAL;
 dma_queued_scb:
 	/*
 	 * DMA the SCB from host ram into the current SCB location.
@@ -124,7 +126,7 @@
 	 * value.
 	 */
 	mov	A, ARG_1;
-BEGIN_CRITICAL
+BEGIN_CRITICAL;
 	cmp	NEXT_QUEUED_SCB, A jne abort_qinscb;
 	if ((ahc->flags & AHC_SEQUENCER_DEBUG) != 0) {
 		cmp	SCB_TAG, A je . + 2;
@@ -139,7 +141,7 @@
 		inc	QINPOS;
 	}
 	and	SEQ_FLAGS2, ~SCB_DMA;
-END_CRITICAL
+END_CRITICAL;
 start_waiting:
 	/*
 	 * Start the first entry on the waiting SCB list.
@@ -304,7 +306,7 @@
 		} else {
 			mvi	DFDAT, SCB_LIST_NULL;
 		}
-		or	SEQ_FLAGS, TARG_CMD_PENDING|IDENTIFY_SEEN;
+		mvi	SEQ_FLAGS, TARG_CMD_PENDING;
 		test	SEQ_FLAGS2, TARGET_MSG_PENDING
 			jnz target_mesgout_pending;
 		test	SCSISIGI, ATNI jnz target_mesgout_continue;
@@ -388,13 +390,8 @@
 	}
 
 /*
- * Initialize transfer settings and clear the SCSI channel.
- * SINDEX should contain any additional bit's the client wants
- * set in SXFRCTL0.  We also assume that the current SCB is
- * a valid SCB for the target we wish to talk to.
+ * Initialize transfer settings with SCB provided settings.
  */
-initialize_channel:
-	or	SXFRCTL0, SPIOEN|CLRSTCNT|CLRCHN;
 set_transfer_settings:
 	if ((ahc->features & AHC_ULTRA) != 0) {
 		test	SCB_CONTROL, ULTRAENB jz . + 2;
@@ -437,21 +434,29 @@
 select_out:
 	/* Turn off the selection hardware */
 	and	SCSISEQ, TEMODE|ENSELI|ENRSELI|ENAUTOATNP, SCSISEQ;
-	mvi	CLRSINT0, CLRSELDO;
 	mov	SCBPTR, WAITING_SCBH;
 	mov	WAITING_SCBH,SCB_NEXT;
 	mov	SAVED_SCSIID, SCB_SCSIID;
 	mov	SAVED_LUN, SCB_LUN;
-	call	initialize_channel;
+	call	set_transfer_settings;
 	if ((ahc->flags & AHC_TARGETROLE) != 0) {
 		test	SSTAT0, TARGET	jz initiator_select;
 
+		or	SXFRCTL0, CLRSTCNT|CLRCHN;
+
+		/*
+		 * Put tag in connonical location since not
+		 * all connections have an SCB.
+		 */
+		mov	INITIATOR_TAG, SCB_TARGET_ITAG;
+
 		/*
 		 * We've just re-selected an initiator.
 		 * Assert BSY and setup the phase for
 		 * sending our identify messages.
 		 */
 		mvi	P_MESGIN|BSYO call change_phase;
+		mvi	CLRSINT0, CLRSELDO;
 
 		/*
 		 * Start out with a simple identify message.
@@ -490,14 +495,16 @@
 		 * on the state of NO_DISCONNECT.
 		 */
 		test	SEQ_FLAGS, NO_DISCONNECT jz target_disconnect; 
-		mov	RETURN_1, ALLZEROS;
+		mvi	TARG_IMMEDIATE_SCB, SCB_LIST_NULL;
 		call	complete_target_cmd;
-		cmp	RETURN_1, CONT_MSG_LOOP jne .;
 		if ((ahc->flags & AHC_PAGESCBS) != 0) {
 			mov	ALLZEROS	call	get_free_or_disc_scb;
 		}
+		cmp	TARG_IMMEDIATE_SCB, SCB_LIST_NULL je .;
 		mvi	DMAPARAMS, HDMAEN|DIRECTION|FIFORESET;
-		mov	SCB_TAG	 call dma_scb;
+		mov	TARG_IMMEDIATE_SCB call dma_scb;
+		call	set_transfer_settings;
+		or	SXFRCTL0, CLRSTCNT|CLRCHN;
 		jmp	target_synccmd;
 
 target_mesgout:
@@ -634,13 +641,15 @@
 
 if ((ahc->flags & AHC_INITIATORROLE) != 0) {
 initiator_select:
+	or	SXFRCTL0, SPIOEN|CLRSTCNT|CLRCHN;
 	/*
 	 * As soon as we get a successful selection, the target
 	 * should go into the message out phase since we have ATN
 	 * asserted.
 	 */
 	mvi	MSG_OUT, MSG_IDENTIFYFLAG;
-	or	SEQ_FLAGS, IDENTIFY_SEEN;
+	mvi	SEQ_FLAGS, NO_CDB_SENT;
+	mvi	CLRSINT0, CLRSELDO;
 
 	/*
 	 * Main loop for information transfer phases.  Wait for the
@@ -698,7 +707,7 @@
 	}
 	mvi	LASTPHASE, P_BUSFREE;
 	/* clear target specific flags */
-	clr	SEQ_FLAGS ret;
+	mvi	SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT ret;
 
 sg_advance:
 	clr	A;			/* add sizeof(struct scatter) */
@@ -812,9 +821,9 @@
 }
 
 p_data:
-	test	SEQ_FLAGS,IDENTIFY_SEEN	jnz p_data_okay;
-	mvi	NO_IDENT jmp set_seqint;
-p_data_okay:
+	test	SEQ_FLAGS,NOT_IDENTIFIED|NO_CDB_SENT jz p_data_allowed;
+	mvi	PROTO_VIOLATION call set_seqint;
+p_data_allowed:
 	if ((ahc->features & AHC_ULTRA2) != 0) {
 		mvi	DMAPARAMS, PRELOADEN|SCSIEN|HDMAEN;
 	} else {
@@ -968,12 +977,12 @@
 ultra2_ensure_sg:
 		test	SG_CACHE_SHADOW, LAST_SEG jz ultra2_shvalid;
 		/* Record if we've consumed all S/G entries */
-		test    SSTAT2, SHVALID	jnz residuals_correct;
+		test	SSTAT2, SHVALID	jnz residuals_correct;
 		or	SCB_RESIDUAL_SGPTR[0], SG_LIST_NULL;
 		jmp	residuals_correct;
 
 ultra2_shvalid:
-                test    SSTAT2, SHVALID	jnz sgptr_fixup;
+		test	SSTAT2, SHVALID	jnz sgptr_fixup;
 		call	idle_loop;
 		jmp	ultra2_ensure_sg;
 
@@ -1358,8 +1367,8 @@
  * Command phase.  Set up the DMA registers and let 'er rip.
  */
 p_command:
-	test	SEQ_FLAGS,IDENTIFY_SEEN	jnz p_command_okay;
-	mvi	NO_IDENT jmp set_seqint;
+	test	SEQ_FLAGS, NOT_IDENTIFIED jz p_command_okay;
+	mvi	PROTO_VIOLATION call set_seqint;
 p_command_okay:
 
 	if ((ahc->features & AHC_ULTRA2) != 0) {
@@ -1391,13 +1400,13 @@
 		}
 		mvi	DFCNTRL, (SCSIEN|SDMAEN|HDMAEN|DIRECTION|FIFORESET);
 	}
-	jmp	p_command_loop;
+	jmp	p_command_xfer;
 p_command_embedded:
 	/*
 	 * The data fifo seems to require 4 byte aligned
 	 * transfers from the sequencer.  Force this to
 	 * be the case by clearing HADDR[0] even though
-	 * we aren't going to touch host memeory.
+	 * we aren't going to touch host memory.
 	 */
 	clr	HADDR[0];
 	if ((ahc->features & AHC_ULTRA2) != 0) {
@@ -1429,24 +1438,28 @@
 		call	copy_to_fifo_6;
 		or	DFCNTRL, FIFOFLUSH;
 	}
-p_command_loop:
+p_command_xfer:
+	and	SEQ_FLAGS, ~NO_CDB_SENT;
 	if ((ahc->features & AHC_DT) == 0) {
 		test	SSTAT0, SDONE jnz . + 2;
-		test    SSTAT1, PHASEMIS jz p_command_loop;
+		test    SSTAT1, PHASEMIS jz . - 1;
 		/*
 		 * Wait for our ACK to go-away on it's own
 		 * instead of being killed by SCSIEN getting cleared.
 		 */
 		test	SCSISIGI, ACKI jnz .;
 	} else {
-		test	DFCNTRL, SCSIEN jnz p_command_loop;
+		test	DFCNTRL, SCSIEN jnz .;
 	}
+	test	SSTAT0, SDONE jnz p_command_successful;
+	/*
+	 * Don't allow a data phase if the command
+	 * was not fully transferred.
+	 */
+	or	SEQ_FLAGS, NO_CDB_SENT;
+p_command_successful:
 	and	DFCNTRL, ~(SCSIEN|SDMAEN|HDMAEN);
 	test	DFCNTRL, (SCSIEN|SDMAEN|HDMAEN) jnz .;
-	if ((ahc->features & AHC_ULTRA2) != 0) {
-		/* Drop any residual from the S/G Preload queue */
-		or	SXFRCTL0, CLRSTCNT;
-	}
 	jmp	ITloop;
 
 /*
@@ -1454,10 +1467,10 @@
  * and store it into the SCB.
  */
 p_status:
-	test	SEQ_FLAGS,IDENTIFY_SEEN	jnz p_status_okay;
-	mvi	NO_IDENT jmp set_seqint;
+	test	SEQ_FLAGS, NOT_IDENTIFIED jnz mesgin_proto_violation;
 p_status_okay:
 	mov	SCB_SCSI_STATUS, SCSIDATL;
+	or	SCB_CONTROL, STATUS_RCVD;
 	jmp	ITloop;
 
 /*
@@ -1578,13 +1591,15 @@
 	jmp	mesgin_done;
 }
 
+mesgin_proto_violation:
+	mvi	PROTO_VIOLATION call set_seqint;
+	jmp	mesgin_done;
 mesgin_reject:
 	mvi	MSG_MESSAGE_REJECT	call mk_mesg;
 mesgin_done:
 	mov	NONE,SCSIDATL;		/*dummy read from latch to ACK*/
 	jmp	ITloop;
 
-mesgin_complete:
 /*
  * We received a "command complete" message.  Put the SCB_TAG into the QOUTFIFO,
  * and trigger a completion interrupt.  Before doing so, check to see if there
@@ -1597,27 +1612,49 @@
  * it to the QINFIFO and tell us not to post to the QOUTFIFO by setting 
  * RETURN_1 to SEND_SENSE.
  */
+mesgin_complete:
 
-/*
- * If ATN is raised, we still want to give the target a message.
- * Perhaps there was a parity error on this last message byte.
- * Either way, the target should take us to message out phase
- * and then attempt to complete the command again.  We should use a
- * critical section here to guard against a timeout triggering
- * for this command and setting ATN while we are still processing
- * the completion.
+	/*
+	 * If ATN is raised, we still want to give the target a message.
+	 * Perhaps there was a parity error on this last message byte.
+	 * Either way, the target should take us to message out phase
+	 * and then attempt to complete the command again.  We should use a
+	 * critical section here to guard against a timeout triggering
+	 * for this command and setting ATN while we are still processing
+	 * the completion.
 	test	SCSISIGI, ATNI jnz mesgin_done;
- */
+	 */
 
-/*
- * See if we attempted to deliver a message but the target ingnored us.
- */
+	/*
+	 * If we are identified and have successfully sent the CDB,
+	 * any status will do.  Optimize this fast path.
+	 */
+	test	SCB_CONTROL, STATUS_RCVD jz mesgin_proto_violation;
+	test	SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT jz complete_accepted; 
+
+	/*
+	 * If the target never sent an identify message but instead went
+	 * to mesgin to give an invalid message, let the host abort us.
+	 */
+	test	SEQ_FLAGS, NOT_IDENTIFIED jnz mesgin_proto_violation;
+
+	/*
+	 * If we recevied good status but never successfully sent the
+	 * cdb, abort the command.
+	 */
+	test	SCB_SCSI_STATUS,0xff	jnz complete_accepted;
+	test	SEQ_FLAGS, NO_CDB_SENT jnz mesgin_proto_violation;
+
+complete_accepted:
+	/*
+	 * See if we attempted to deliver a message but the target ingnored us.
+	 */
 	test	SCB_CONTROL, MK_MESSAGE jz . + 2;
 	mvi	MKMSG_FAILED call set_seqint;
 
-/*
- * Check for residuals
- */
+	/*
+	 * Check for residuals
+	 */
 	test	SCB_SGPTR, SG_LIST_NULL jnz check_status;/* No xfer */
 	test	SCB_SGPTR, SG_FULL_RESID jnz upload_scb;/* Never xfered */
 	test	SCB_RESIDUAL_SGPTR, SG_LIST_NULL jz upload_scb;
@@ -1670,7 +1707,8 @@
 	 * XXX - Wait for more testing.
 	test	SCSISIGI, ATNI jnz mesgin_done;
 	 */
-
+	test	SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT
+		jnz mesgin_proto_violation;
 	or	SCB_CONTROL,DISCONNECTED;
 	if ((ahc->flags & AHC_PAGESCBS) != 0) {
 		call	add_scb_to_disc_list;
@@ -1738,7 +1776,8 @@
  * Restore pointers message?  Data pointers are recopied from the
  * SCB anytime we enter a data phase for the first time, so all
  * we need to do is clear the DPHASE flag and let the data phase
- * code do the rest.
+ * code do the rest.  We also reset/reallocate the FIFO to make
+ * sure we have a clean start for the next data or command phase.
  */
 mesgin_rdptrs:
 	and	SEQ_FLAGS, ~DPHASE;		/*
@@ -1746,6 +1785,7 @@
 						 * the next time through
 						 * the dataphase.
 						 */
+	or	SXFRCTL0, CLRSTCNT|CLRCHN;
 	jmp	mesgin_done;
 
 /*
@@ -1773,7 +1813,7 @@
 	 * transactions by first looking at the transaction stored in
 	 * the busy target array.  If there is no untagged transaction
 	 * for this target or the transaction is for a different lun, then
-	 * this must be an untagged transaction.
+	 * this must be a tagged transaction.
 	 */
 	shr	SINDEX, 4, SAVED_SCSIID;
 	and	SAVED_LUN, MSG_IDENTIFY_LUNMASK, A;
@@ -1894,7 +1934,7 @@
 		mov	SCBPTR, A;
 	}
 setup_SCB_tagged:
-	mvi	SEQ_FLAGS,IDENTIFY_SEEN;	/* make note of IDENTIFY */
+	clr	SEQ_FLAGS;	/* make note of IDENTIFY */
 	call	set_transfer_settings;
 	/* See if the host wants to send a message upon reconnection */
 	test	SCB_CONTROL, MK_MESSAGE jz mesgin_done;
@@ -2003,7 +2043,7 @@
  * removal of the found SCB from the disconnected list.
  */
 if ((ahc->flags & AHC_PAGESCBS) != 0) {
-BEGIN_CRITICAL
+BEGIN_CRITICAL;
 findSCB:
 	mov	A, SINDEX;			/* Tag passed in SINDEX */
 	cmp	DISCONNECTED_SCBH, SCB_LIST_NULL je findSCB_notFound;
@@ -2025,7 +2065,7 @@
 	mov	SCBPTR, SINDEX ret;
 rHead:
 	mov	DISCONNECTED_SCBH,SCB_NEXT ret;
-END_CRITICAL
+END_CRITICAL;
 findSCB_notFound:
 	/*
 	 * We didn't find it.  Page in the SCB.
@@ -2150,7 +2190,7 @@
 	adc	DINDIR, A, SINDIR ret;
 
 /*
- * Either post or fetch and SCB from host memory based on the
+ * Either post or fetch an SCB from host memory based on the
  * DIRECTION bit in DMAPARAMS. The host SCB index is in SINDEX.
  */
 dma_scb:
@@ -2215,9 +2255,9 @@
 			 * available data to force the chip to
 			 * continue the transfer.  This does not
 			 * happen for SCSI transfers as the SCSI module
-			 * will drain the FIFO as data is made available.
+			 * will drain the FIFO as data are made available.
 			 * When the hang occurs, we know that a multiple
-			 * of 8 bytes are in the FIFO because the PCI
+			 * of 8 bytes is in the FIFO because the PCI
 			 * module has an 8 byte input latch that only
 			 * dumps to the FIFO when HCNT == 0 or the
 			 * latch is full.
@@ -2254,7 +2294,6 @@
 		} else {
 			call	dma_finish;
 		}
-		/* If we were putting the SCB, we are done */
 		call	dfdat_in_8;
 		call	dfdat_in_8;
 		call	dfdat_in_8;
@@ -2308,11 +2347,11 @@
 	}
 add_scb_to_free_list:
 	if ((ahc->flags & AHC_PAGESCBS) != 0) {
-BEGIN_CRITICAL
+BEGIN_CRITICAL;
 		mov	SCB_NEXT, FREE_SCBH;
 		mvi	SCB_TAG, SCB_LIST_NULL;
 		mov	FREE_SCBH, SCBPTR ret;
-END_CRITICAL
+END_CRITICAL;
 	} else {
 		mvi	SCB_TAG, SCB_LIST_NULL ret;
 	}
@@ -2326,7 +2365,7 @@
 
 if ((ahc->flags & AHC_PAGESCBS) != 0) {
 get_free_or_disc_scb:
-BEGIN_CRITICAL
+BEGIN_CRITICAL;
 	cmp	FREE_SCBH, SCB_LIST_NULL jne dequeue_free_scb;
 	cmp	DISCONNECTED_SCBH, SCB_LIST_NULL jne dequeue_disc_scb;
 return_error:
@@ -2335,14 +2374,14 @@
 dequeue_disc_scb:
 	mov	SCBPTR, DISCONNECTED_SCBH;
 	mov	DISCONNECTED_SCBH, SCB_NEXT;
-END_CRITICAL
+END_CRITICAL;
 	mvi	DMAPARAMS, FIFORESET;
 	mov	SCB_TAG	jmp dma_scb;
-BEGIN_CRITICAL
+BEGIN_CRITICAL;
 dequeue_free_scb:
 	mov	SCBPTR, FREE_SCBH;
 	mov	FREE_SCBH, SCB_NEXT ret;
-END_CRITICAL
+END_CRITICAL;
 
 add_scb_to_disc_list:
 /*
@@ -2350,10 +2389,10 @@
  * candidates for paging out an SCB if one is needed for a new command.
  * Modifying the disconnected list is a critical(pause dissabled) section.
  */
-BEGIN_CRITICAL
+BEGIN_CRITICAL;
 	mov	SCB_NEXT, DISCONNECTED_SCBH;
 	mov	DISCONNECTED_SCBH, SCBPTR ret;
-END_CRITICAL
+END_CRITICAL;
 }
 set_seqint:
 	mov	INTSTAT, SINDEX;
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx_93cx6.c b/drivers/scsi/aic7xxx/aic7xxx_93cx6.c
--- a/drivers/scsi/aic7xxx/aic7xxx_93cx6.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/scsi/aic7xxx/aic7xxx_93cx6.c	Mon Dec 23 21:22:00 2002
@@ -28,9 +28,9 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: //depot/aic7xxx/aic7xxx/aic7xxx_93cx6.c#10 $
+ * $Id: //depot/aic7xxx/aic7xxx/aic7xxx_93cx6.c#17 $
  *
- * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx_93cx6.c,v 1.9 2000/11/10 20:13:41 gibbs Exp $
+ * $FreeBSD$
  */
 
 /*
@@ -67,9 +67,15 @@
  *
  */
 
+#ifdef __linux__
 #include "aic7xxx_osm.h"
 #include "aic7xxx_inline.h"
 #include "aic7xxx_93cx6.h"
+#else
+#include <dev/aic7xxx/aic7xxx_osm.h>
+#include <dev/aic7xxx/aic7xxx_inline.h>
+#include <dev/aic7xxx/aic7xxx_93cx6.h>
+#endif
 
 /*
  * Right now, we only have to read the SEEPROM.  But we make it easier to
@@ -77,9 +83,13 @@
  */
 static struct seeprom_cmd {
   	uint8_t len;
- 	uint8_t bits[3];
+ 	uint8_t bits[9];
 } seeprom_read = {3, {1, 1, 0}};
 
+static struct seeprom_cmd seeprom_ewen = {9, {1, 0, 0, 1, 1, 0, 0, 0, 0}};
+static struct seeprom_cmd seeprom_ewds = {9, {1, 0, 0, 0, 0, 0, 0, 0, 0}};
+static struct seeprom_cmd seeprom_write = {3, {1, 0, 1}};
+
 /*
  * Wait for the SEERDY to go high; about 800 ns.
  */
@@ -90,15 +100,55 @@
 	(void)SEEPROM_INB(sd);	/* Clear clock */
 
 /*
+ * Send a START condition and the given command
+ */
+static void
+send_seeprom_cmd(struct seeprom_descriptor *sd, struct seeprom_cmd *cmd)
+{
+	uint8_t temp;
+	int i = 0;
+
+	/* Send chip select for one clock cycle. */
+	temp = sd->sd_MS ^ sd->sd_CS;
+	SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
+	CLOCK_PULSE(sd, sd->sd_RDY);
+
+	for (i = 0; i < cmd->len; i++) {
+		if (cmd->bits[i] != 0)
+			temp ^= sd->sd_DO;
+		SEEPROM_OUTB(sd, temp);
+		CLOCK_PULSE(sd, sd->sd_RDY);
+		SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
+		CLOCK_PULSE(sd, sd->sd_RDY);
+		if (cmd->bits[i] != 0)
+			temp ^= sd->sd_DO;
+	}
+}
+
+/*
+ * Clear CS put the chip in the reset state, where it can wait for new commands.
+ */
+static void
+reset_seeprom(struct seeprom_descriptor *sd)
+{
+	uint8_t temp;
+
+	temp = sd->sd_MS;
+	SEEPROM_OUTB(sd, temp);
+	CLOCK_PULSE(sd, sd->sd_RDY);
+	SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
+	CLOCK_PULSE(sd, sd->sd_RDY);
+	SEEPROM_OUTB(sd, temp);
+	CLOCK_PULSE(sd, sd->sd_RDY);
+}
+
+/*
  * Read the serial EEPROM and returns 1 if successful and 0 if
  * not successful.
  */
 int
-read_seeprom(sd, buf, start_addr, count)
-	struct seeprom_descriptor *sd;
-	uint16_t *buf;
-	u_int start_addr;
-	u_int count;
+ahc_read_seeprom(struct seeprom_descriptor *sd, uint16_t *buf,
+		 u_int start_addr, u_int count)
 {
 	int i = 0;
 	u_int k = 0;
@@ -110,26 +160,14 @@
 	 * will range from 0 to count-1.
 	 */
 	for (k = start_addr; k < count + start_addr; k++) {
-		/* Send chip select for one clock cycle. */
-		temp = sd->sd_MS ^ sd->sd_CS;
-		SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
-		CLOCK_PULSE(sd, sd->sd_RDY);
-
 		/*
 		 * Now we're ready to send the read command followed by the
 		 * address of the 16-bit register we want to read.
 		 */
-		for (i = 0; i < seeprom_read.len; i++) {
-			if (seeprom_read.bits[i] != 0)
-				temp ^= sd->sd_DO;
-			SEEPROM_OUTB(sd, temp);
-			CLOCK_PULSE(sd, sd->sd_RDY);
-			SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
-			CLOCK_PULSE(sd, sd->sd_RDY);
-			if (seeprom_read.bits[i] != 0)
-				temp ^= sd->sd_DO;
-		}
+		send_seeprom_cmd(sd, &seeprom_read);
+
 		/* Send the 6 or 8 bit address (MSB first, LSB last). */
+		temp = sd->sd_MS ^ sd->sd_CS;
 		for (i = (sd->sd_chip - 1); i >= 0; i--) {
 			if ((k & (1 << i)) != 0)
 				temp ^= sd->sd_DO;
@@ -161,13 +199,7 @@
 		buf[k - start_addr] = v;
 
 		/* Reset the chip select for the next command cycle. */
-		temp = sd->sd_MS;
-		SEEPROM_OUTB(sd, temp);
-		CLOCK_PULSE(sd, sd->sd_RDY);
-		SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
-		CLOCK_PULSE(sd, sd->sd_RDY);
-		SEEPROM_OUTB(sd, temp);
-		CLOCK_PULSE(sd, sd->sd_RDY);
+		reset_seeprom(sd);
 	}
 #ifdef AHC_DUMP_EEPROM
 	printf("\nSerial EEPROM:\n\t");
@@ -182,8 +214,77 @@
 	return (1);
 }
 
+/*
+ * Write the serial EEPROM and return 1 if successful and 0 if
+ * not successful.
+ */
+int
+ahc_write_seeprom(struct seeprom_descriptor *sd, uint16_t *buf,
+		  u_int start_addr, u_int count)
+{
+	uint16_t v;
+	uint8_t temp;
+	int i, k;
+
+	/* Place the chip into write-enable mode */
+	send_seeprom_cmd(sd, &seeprom_ewen);
+	reset_seeprom(sd);
+
+	/* Write all requested data out to the seeprom. */
+	temp = sd->sd_MS ^ sd->sd_CS;
+	for (k = start_addr; k < count + start_addr; k++) {
+		/* Send the write command */
+		send_seeprom_cmd(sd, &seeprom_write);
+
+		/* Send the 6 or 8 bit address (MSB first). */
+		for (i = (sd->sd_chip - 1); i >= 0; i--) {
+			if ((k & (1 << i)) != 0)
+				temp ^= sd->sd_DO;
+			SEEPROM_OUTB(sd, temp);
+			CLOCK_PULSE(sd, sd->sd_RDY);
+			SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
+			CLOCK_PULSE(sd, sd->sd_RDY);
+			if ((k & (1 << i)) != 0)
+				temp ^= sd->sd_DO;
+		}
+
+		/* Write the 16 bit value, MSB first */
+		v = buf[k - start_addr];
+		for (i = 15; i >= 0; i--) {
+			if ((v & (1 << i)) != 0)
+				temp ^= sd->sd_DO;
+			SEEPROM_OUTB(sd, temp);
+			CLOCK_PULSE(sd, sd->sd_RDY);
+			SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
+			CLOCK_PULSE(sd, sd->sd_RDY);
+			if ((v & (1 << i)) != 0)
+				temp ^= sd->sd_DO;
+		}
+
+		/* Wait for the chip to complete the write */
+		temp = sd->sd_MS;
+		SEEPROM_OUTB(sd, temp);
+		CLOCK_PULSE(sd, sd->sd_RDY);
+		temp = sd->sd_MS ^ sd->sd_CS;
+		do {
+			SEEPROM_OUTB(sd, temp);
+			CLOCK_PULSE(sd, sd->sd_RDY);
+			SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
+			CLOCK_PULSE(sd, sd->sd_RDY);
+		} while ((SEEPROM_DATA_INB(sd) & sd->sd_DI) == 0);
+
+		reset_seeprom(sd);
+	}
+
+	/* Put the chip back into write-protect mode */
+	send_seeprom_cmd(sd, &seeprom_ewds);
+	reset_seeprom(sd);
+
+	return (1);
+}
+
 int
-verify_cksum(struct seeprom_config *sc)
+ahc_verify_cksum(struct seeprom_config *sc)
 {
 	int i;
 	int maxaddr;
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx_93cx6.h b/drivers/scsi/aic7xxx/aic7xxx_93cx6.h
--- a/drivers/scsi/aic7xxx/aic7xxx_93cx6.h	Mon Dec 23 21:21:52 2002
+++ b/drivers/scsi/aic7xxx/aic7xxx_93cx6.h	Mon Dec 23 21:21:52 2002
@@ -38,9 +38,9 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $Id: //depot/aic7xxx/aic7xxx/aic7xxx_93cx6.h#7 $
+ * $Id: //depot/aic7xxx/aic7xxx/aic7xxx_93cx6.h#12 $
  *
- * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx_93cx6.h,v 1.8 2000/11/10 20:13:41 gibbs Exp $
+ * $FreeBSD$
  */
 #ifndef _AIC7XXX_93CX6_H_
 #define _AIC7XXX_93CX6_H_
@@ -93,8 +93,10 @@
 #define	SEEPROM_DATA_INB(sd) \
 	ahc_inb(sd->sd_ahc, sd->sd_dataout_offset)
 
-int read_seeprom(struct seeprom_descriptor *sd, uint16_t *buf,
-		 u_int start_addr, u_int count);
-int verify_cksum(struct seeprom_config *sc);
+int ahc_read_seeprom(struct seeprom_descriptor *sd, uint16_t *buf,
+		     u_int start_addr, u_int count);
+int ahc_write_seeprom(struct seeprom_descriptor *sd, uint16_t *buf,
+		      u_int start_addr, u_int count);
+int ahc_verify_cksum(struct seeprom_config *sc);
 
 #endif /* _AIC7XXX_93CX6_H_ */
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx_core.c b/drivers/scsi/aic7xxx/aic7xxx_core.c
--- a/drivers/scsi/aic7xxx/aic7xxx_core.c	Mon Dec 23 21:21:54 2002
+++ b/drivers/scsi/aic7xxx/aic7xxx_core.c	Mon Dec 23 21:21:54 2002
@@ -1,8 +1,8 @@
 /*
  * Core routines and tables shareable across OS platforms.
  *
- * Copyright (c) 1994-2001 Justin T. Gibbs.
- * Copyright (c) 2000-2001 Adaptec Inc.
+ * Copyright (c) 1994-2002 Justin T. Gibbs.
+ * Copyright (c) 2000-2002 Adaptec Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -37,14 +37,20 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.c#50 $
+ * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.c#104 $
  *
- * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx.c,v 1.61 2000/11/13 03:35:43 gibbs Exp $
+ * $FreeBSD$
  */
 
+#ifdef __linux__
 #include "aic7xxx_osm.h"
 #include "aic7xxx_inline.h"
 #include "aicasm/aicasm_insformat.h"
+#else
+#include <dev/aic7xxx/aic7xxx_osm.h>
+#include <dev/aic7xxx/aic7xxx_inline.h>
+#include <dev/aic7xxx/aicasm/aicasm_insformat.h>
+#endif
 
 /****************************** Softc Data ************************************/
 struct ahc_softc_tailq ahc_tailq = TAILQ_HEAD_INITIALIZER(ahc_tailq);
@@ -175,6 +181,7 @@
 					  u_int period, u_int offset,
 					  u_int bus_width, u_int ppr_options);
 static void		ahc_clear_msg_state(struct ahc_softc *ahc);
+static void		ahc_handle_proto_violation(struct ahc_softc *ahc);
 static void		ahc_handle_message_phase(struct ahc_softc *ahc);
 typedef enum {
 	AHCMSG_1B,
@@ -223,6 +230,7 @@
 					u_int start_instr, u_int *skip_addr);
 static void		ahc_download_instr(struct ahc_softc *ahc,
 					   u_int instrptr, uint8_t *dconsts);
+static int		ahc_probe_stack_size(struct ahc_softc *ahc);
 #ifdef AHC_TARGET_MODE
 static void		ahc_queue_lstate_event(struct ahc_softc *ahc,
 					       struct ahc_tmode_lstate *lstate,
@@ -244,10 +252,15 @@
 
 	ahc_pause(ahc);
 
+	/* No more pending messages. */
+	ahc_clear_msg_state(ahc);
+
 	ahc_outb(ahc, SCSISIGO, 0);		/* De-assert BSY */
 	ahc_outb(ahc, MSG_OUT, MSG_NOOP);	/* No message to send */
 	ahc_outb(ahc, SXFRCTL1, ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET);
 	ahc_outb(ahc, LASTPHASE, P_BUSFREE);
+	ahc_outb(ahc, SAVED_SCSIID, 0xFF);
+	ahc_outb(ahc, SAVED_LUN, 0xFF);
 
 	/*
 	 * Ensure that the sequencer's idea of TQINPOS
@@ -319,7 +332,7 @@
 			printf("%s: WARNING no command for scb %d "
 			       "(cmdcmplt)\nQOUTPOS = %d\n",
 			       ahc_name(ahc), scb_index,
-			       ahc->qoutfifonext - 1);
+			       (ahc->qoutfifonext - 1) & 0xFF);
 			continue;
 		}
 
@@ -327,7 +340,7 @@
 		 * Save off the residual
 		 * if there is one.
 		 */
-		ahc_update_residual(scb);
+		ahc_update_residual(ahc, scb);
 		ahc_done(ahc, scb);
 	}
 }
@@ -426,10 +439,10 @@
 		scb_index = ahc_inb(ahc, SCB_TAG);
 		scb = ahc_lookup_scb(ahc, scb_index);
 		if (scb == NULL) {
-			printf("%s:%c:%d: ahc_intr - referenced scb "
+			ahc_print_devinfo(ahc, &devinfo);
+			printf("ahc_intr - referenced scb "
 			       "not valid during seqint 0x%x scb(%d)\n",
-			       ahc_name(ahc), devinfo.channel,
-			       devinfo.target, intstat, scb_index);
+			       intstat, scb_index);
 			ahc_dump_card_state(ahc);
 			panic("for safety");
 			goto unpause;
@@ -467,7 +480,7 @@
 			struct ahc_tmode_tstate *tstate;
 			struct ahc_transinfo *tinfo;
 #ifdef AHC_DEBUG
-			if (ahc_debug & AHC_SHOWSENSE) {
+			if (ahc_debug & AHC_SHOW_SENSE) {
 				ahc_print_path(ahc, scb);
 				printf("SCB %d: requests Check Status\n",
 				       scb->hscb->tag);
@@ -488,9 +501,9 @@
 			/*
 			 * Save off the residual if there is one.
 			 */
-			ahc_update_residual(scb);
+			ahc_update_residual(ahc, scb);
 #ifdef AHC_DEBUG
-			if (ahc_debug & AHC_SHOWSENSE) {
+			if (ahc_debug & AHC_SHOW_SENSE) {
 				ahc_print_path(ahc, scb);
 				printf("Sending Sense\n");
 			}
@@ -534,7 +547,7 @@
 			 == ahc_get_transfer_length(scb)) {
 				ahc_update_neg_request(ahc, &devinfo,
 						       tstate, targ_info,
-						       /*force*/TRUE);
+						       AHC_NEG_IF_NON_ASYNC);
 			}
 			if (tstate->auto_negotiate & devinfo.target_mask) {
 				hscb->control |= MK_MESSAGE;
@@ -550,16 +563,11 @@
 			scb->flags |= SCB_SENSE;
 			ahc_qinfifo_requeue_tail(ahc, scb);
 			ahc_outb(ahc, RETURN_1, SEND_SENSE);
-#ifdef __FreeBSD__
 			/*
 			 * Ensure we have enough time to actually
 			 * retrieve the sense.
 			 */
-			untimeout(ahc_timeout, (caddr_t)scb,
-				  scb->io_ctx->ccb_h.timeout_ch);
-			scb->io_ctx->ccb_h.timeout_ch =
-			    timeout(ahc_timeout, (caddr_t)scb, 5 * hz);
-#endif
+			ahc_scb_timer_reset(scb, 5 * 1000000);
 			break;
 		}
 		default:
@@ -613,27 +621,10 @@
 		       ahc_name(ahc), devinfo.channel, devinfo.target, rejbyte);
 		break; 
 	}
-	case NO_IDENT: 
+	case PROTO_VIOLATION:
 	{
-		/*
-		 * The reconnecting target either did not send an identify
-		 * message, or did, but we didn't find an SCB to match and
-		 * before it could respond to our ATN/abort, it hit a dataphase.
-		 * The only safe thing to do is to blow it away with a bus
-		 * reset.
-		 */
-		int found;
-
-		printf("%s:%c:%d: Target did not send an IDENTIFY message. "
-		       "LASTPHASE = 0x%x, SAVED_SCSIID == 0x%x\n",
-		       ahc_name(ahc), devinfo.channel, devinfo.target,
-		       ahc_inb(ahc, LASTPHASE), ahc_inb(ahc, SAVED_SCSIID));
-		found = ahc_reset_channel(ahc, devinfo.channel, 
-					  /*initiate reset*/TRUE);
-		printf("%s: Issued Channel %c Bus Reset. "
-		       "%d SCBs aborted\n", ahc_name(ahc), devinfo.channel,
-		       found);
-		return;
+		ahc_handle_proto_violation(ahc);
+		break;
 	}
 	case IGN_WIDE_RES:
 		ahc_handle_ign_wide_residue(ahc, &devinfo);
@@ -761,7 +752,44 @@
 				ahc_outb(ahc, LASTPHASE, curphase);
 				ahc_outb(ahc, SCSISIGO, curphase);
 			}
-			ahc_inb(ahc, SCSIDATL);
+			if ((ahc_inb(ahc, SCSISIGI) & (CDI|MSGI)) == 0) {
+				int wait;
+
+				/*
+				 * In a data phase.  Faster to bitbucket
+				 * the data than to individually ack each
+				 * byte.  This is also the only strategy
+				 * that will work with AUTOACK enabled.
+				 */
+				ahc_outb(ahc, SXFRCTL1,
+					 ahc_inb(ahc, SXFRCTL1) | BITBUCKET);
+				wait = 5000;
+				while (--wait != 0) {
+					if ((ahc_inb(ahc, SCSISIGI)
+					  & (CDI|MSGI)) != 0)
+						break;
+					ahc_delay(100);
+				}
+				ahc_outb(ahc, SXFRCTL1,
+					 ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET);
+				if (wait == 0) {
+					struct	scb *scb;
+					u_int	scb_index;
+
+					ahc_print_devinfo(ahc, &devinfo);
+					printf("Unable to clear parity error.  "
+					       "Resetting bus.\n");
+					scb_index = ahc_inb(ahc, SCB_TAG);
+					scb = ahc_lookup_scb(ahc, scb_index);
+					if (scb != NULL)
+						ahc_set_transaction_status(scb,
+						    CAM_UNCOR_PARITY);
+					ahc_reset_channel(ahc, devinfo.channel, 
+							  /*init reset*/TRUE);
+				}
+			} else {
+				ahc_inb(ahc, SCSIDATL);
+			}
 		}
 		break;
 	}
@@ -810,7 +838,12 @@
 		 * target does a command complete.
 		 */
 		ahc_freeze_devq(ahc, scb);
-		ahc_set_transaction_status(scb, CAM_DATA_RUN_ERR);
+		if ((scb->flags & SCB_SENSE) == 0) {
+			ahc_set_transaction_status(scb, CAM_DATA_RUN_ERR);
+		} else {
+			scb->flags &= ~SCB_SENSE;
+			ahc_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
+		}
 		ahc_freeze_scb(scb);
 
 		if ((ahc->features & AHC_ULTRA2) != 0) {
@@ -926,9 +959,6 @@
 	char	cur_channel;
 	char	intr_channel;
 
-	/* Make sure the sequencer is in a safe location. */
-	ahc_clear_critical_section(ahc);
-
 	if ((ahc->features & AHC_TWIN) != 0
 	 && ((ahc_inb(ahc, SBLKCTL) & SELBUSB) != 0))
 		cur_channel = 'B';
@@ -957,10 +987,13 @@
 		}
 	}
 
+	/* Make sure the sequencer is in a safe location. */
+	ahc_clear_critical_section(ahc);
+
 	scb_index = ahc_inb(ahc, SCB_TAG);
 	scb = ahc_lookup_scb(ahc, scb_index);
 	if (scb != NULL
-	 && (ahc_inb(ahc, SEQ_FLAGS) & IDENTIFY_SEEN) == 0)
+	 && (ahc_inb(ahc, SEQ_FLAGS) & NOT_IDENTIFIED) != 0)
 		scb = NULL;
 
 	if ((ahc->features & AHC_ULTRA2) != 0
@@ -1007,6 +1040,7 @@
 		u_int scsirate;
 		u_int i;
 		u_int sstat2;
+		int   silent;
 
 		lastphase = ahc_inb(ahc, LASTPHASE);
 		curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
@@ -1034,29 +1068,47 @@
 				break;
 		}
 		mesg_out = ahc_phase_table[i].mesg_out;
-		if (scb != NULL)
-			ahc_print_path(ahc, scb);
-		else
+		silent = FALSE;
+		if (scb != NULL) {
+			if (SCB_IS_SILENT(scb))
+				silent = TRUE;
+			else
+				ahc_print_path(ahc, scb);
+			scb->flags |= SCB_TRANSMISSION_ERROR;
+		} else
 			printf("%s:%c:%d: ", ahc_name(ahc), intr_channel,
 			       SCSIID_TARGET(ahc, ahc_inb(ahc, SAVED_SCSIID)));
 		scsirate = ahc_inb(ahc, SCSIRATE);
-		printf("parity error detected %s. "
-		       "SEQADDR(0x%x) SCSIRATE(0x%x)\n",
-		       ahc_phase_table[i].phasemsg,
-		       ahc_inb(ahc, SEQADDR0) | (ahc_inb(ahc, SEQADDR1) << 8),
-		       scsirate);
-
-		if ((ahc->features & AHC_DT) != 0) {
+		if (silent == FALSE) {
+			printf("parity error detected %s. "
+			       "SEQADDR(0x%x) SCSIRATE(0x%x)\n",
+			       ahc_phase_table[i].phasemsg,
+			       ahc_inw(ahc, SEQADDR0),
+			       scsirate);
+			if ((ahc->features & AHC_DT) != 0) {
+				if ((sstat2 & CRCVALERR) != 0)
+					printf("\tCRC Value Mismatch\n");
+				if ((sstat2 & CRCENDERR) != 0)
+					printf("\tNo terminal CRC packet "
+					       "recevied\n");
+				if ((sstat2 & CRCREQERR) != 0)
+					printf("\tIllegal CRC packet "
+					       "request\n");
+				if ((sstat2 & DUAL_EDGE_ERR) != 0)
+					printf("\tUnexpected %sDT Data Phase\n",
+					       (scsirate & SINGLE_EDGE)
+					     ? "" : "non-");
+			}
+		}
 
-			if ((sstat2 & CRCVALERR) != 0)
-				printf("\tCRC Value Mismatch\n");
-			if ((sstat2 & CRCENDERR) != 0)
-				printf("\tNo terminal CRC packet recevied\n");
-			if ((sstat2 & CRCREQERR) != 0)
-				printf("\tIllegal CRC packet request\n");
-			if ((sstat2 & DUAL_EDGE_ERR) != 0)
-				printf("\tUnexpected %sDT Data Phase\n",
-				       (scsirate & SINGLE_EDGE) ? "" : "non-");
+		if ((ahc->features & AHC_DT) != 0
+		 && (sstat2 & DUAL_EDGE_ERR) != 0) {
+			/*
+			 * This error applies regardless of
+			 * data direction, so ignore the value
+			 * in the phase table.
+			 */
+			mesg_out = MSG_INITIATOR_DET_ERR;
 		}
 
 		/*
@@ -1112,21 +1164,29 @@
 			printf("%s: ahc_intr - referenced scb not "
 			       "valid during SELTO scb(%d, %d)\n",
 			       ahc_name(ahc), scbptr, scb_index);
+			ahc_dump_card_state(ahc);
 		} else {
+			/*
+			 * Force a renegotiation with this target just in
+			 * case the cable was pulled and will later be
+			 * re-attached.  The target may forget its negotiation
+			 * settings with us should it attempt to reselect
+			 * during the interruption.  The target will not issue
+			 * a unit attention in this case, so we must always
+			 * renegotiate.
+			 */
+			ahc_force_renegotiation(ahc);
 			ahc_set_transaction_status(scb, CAM_SEL_TIMEOUT);
 			ahc_freeze_devq(ahc, scb);
+#ifdef AHC_DEBUG
+			if ((ahc_debug & AHC_SHOW_SELTO) != 0) {
+				ahc_print_path(ahc, scb);
+				printf("Saw Selection Timeout for SCB 0x%x\n",
+				       scb_index);
+			}
+#endif
 		}
 		ahc_outb(ahc, CLRINT, CLRSCSIINT);
-		/*
-		 * Force a renegotiation with this target just in
-		 * case the cable was pulled and will later be
-		 * re-attached.  The target may forget its negotiation
-		 * settings with us should it attempt to reselect
-		 * during the interruption.  The target will not issue
-		 * a unit attention in this case, so we must always
-		 * renegotiate.
-		 */
-		ahc_force_renegotiation(ahc);
 		ahc_restart(ahc);
 	} else if ((status & BUSFREE) != 0
 		&& (ahc_inb(ahc, SIMODE1) & ENBUSFREE) != 0) {
@@ -1285,13 +1345,19 @@
 				if (lastphase == ahc_phase_table[i].phase)
 					break;
 			}
+			/*
+			 * Renegotiate with this device at the
+			 * next oportunity just in case this busfree
+			 * is due to a negotiation mismatch with the
+			 * device.
+			 */
+			ahc_force_renegotiation(ahc);
 			printf("Unexpected busfree %s\n"
 			       "SEQADDR == 0x%x\n",
 			       ahc_phase_table[i].phasemsg,
 			       ahc_inb(ahc, SEQADDR0)
 				| (ahc_inb(ahc, SEQADDR1) << 8));
 		}
-		ahc_clear_msg_state(ahc);
 		ahc_outb(ahc, CLRINT, CLRSCSIINT);
 		ahc_restart(ahc);
 	} else {
@@ -1319,7 +1385,7 @@
 					devinfo.target,
 					&tstate);
 	ahc_update_neg_request(ahc, &devinfo, tstate,
-			       targ_info, /*force*/TRUE);
+			       targ_info, AHC_NEG_IF_NON_ASYNC);
 }
 
 #define AHC_MAX_STEPS 2000
@@ -1382,15 +1448,29 @@
 			simode0 = ahc_inb(ahc, SIMODE0);
 			ahc_outb(ahc, SIMODE0, 0);
 			simode1 = ahc_inb(ahc, SIMODE1);
-			ahc_outb(ahc, SIMODE1, 0);
+			if ((ahc->features & AHC_DT) != 0)
+				/*
+				 * On DT class controllers, we
+				 * use the enhanced busfree logic.
+				 * Unfortunately we cannot re-enable
+				 * busfree detection within the
+				 * current connection, so we must
+				 * leave it on while single stepping.
+				 */
+				ahc_outb(ahc, SIMODE1, ENBUSFREE);
+			else
+				ahc_outb(ahc, SIMODE1, 0);
 			ahc_outb(ahc, CLRINT, CLRSCSIINT);
 			ahc_outb(ahc, SEQCTL, ahc_inb(ahc, SEQCTL) | STEP);
 			stepping = TRUE;
 		}
+		if ((ahc->features & AHC_DT) != 0) {
+			ahc_outb(ahc, CLRSINT1, CLRBUSFREE);
+			ahc_outb(ahc, CLRINT, CLRSCSIINT);
+		}
 		ahc_outb(ahc, HCNTRL, ahc->unpause);
-		do {
+		while (!ahc_is_paused(ahc))
 			ahc_delay(200);
-		} while (!ahc_is_paused(ahc));
 	}
 	if (stepping) {
 		ahc_outb(ahc, SIMODE0, simode0);
@@ -1409,11 +1489,18 @@
 	ahc_outb(ahc, CLRSINT1, CLRSELTIMEO|CLRATNO|CLRSCSIRSTI
 				|CLRBUSFREE|CLRSCSIPERR|CLRPHASECHG|
 				CLRREQINIT);
+	ahc_flush_device_writes(ahc);
 	ahc_outb(ahc, CLRSINT0, CLRSELDO|CLRSELDI|CLRSELINGO);
+ 	ahc_flush_device_writes(ahc);
 	ahc_outb(ahc, CLRINT, CLRSCSIINT);
+	ahc_flush_device_writes(ahc);
 }
 
 /**************************** Debugging Routines ******************************/
+#ifdef AHC_DEBUG
+uint32_t ahc_debug = AHC_DEBUG_OPTS;
+#endif
+
 void
 ahc_print_scb(struct scb *scb)
 {
@@ -1468,7 +1555,8 @@
 	 && ahc->enabled_targets[scsi_id] != master_tstate)
 		panic("%s: ahc_alloc_tstate - Target already allocated",
 		      ahc_name(ahc));
-	tstate = malloc(sizeof(*tstate), M_DEVBUF, M_NOWAIT);
+	tstate = (struct ahc_tmode_tstate*)malloc(sizeof(*tstate),
+						   M_DEVBUF, M_NOWAIT);
 	if (tstate == NULL)
 		return (NULL);
 
@@ -1482,7 +1570,7 @@
 		memcpy(tstate, master_tstate, sizeof(*tstate));
 		memset(tstate->enabled_luns, 0, sizeof(tstate->enabled_luns));
 		tstate->ultraenb = 0;
-		for (i = 0; i < 16; i++) {
+		for (i = 0; i < AHC_NUM_TARGETS; i++) {
 			memset(&tstate->transinfo[i].curr, 0,
 			      sizeof(tstate->transinfo[i].curr));
 			memset(&tstate->transinfo[i].goal, 0,
@@ -1531,7 +1619,8 @@
 struct ahc_syncrate *
 ahc_devlimited_syncrate(struct ahc_softc *ahc,
 			struct ahc_initiator_tinfo *tinfo,
-			u_int *period, u_int *ppr_options, role_t role) {
+			u_int *period, u_int *ppr_options, role_t role)
+{
 	struct	ahc_transinfo *transinfo;
 	u_int	maxsync;
 
@@ -1564,6 +1653,10 @@
 	else 
 		transinfo = &tinfo->goal;
 	*ppr_options &= transinfo->ppr_options;
+	if (transinfo->width == MSG_EXT_WDTR_BUS_8_BIT) {
+		maxsync = MAX(maxsync, AHC_SYNCRATE_ULTRA2);
+		*ppr_options &= ~MSG_EXT_PPR_DT_REQ;
+	}
 	if (transinfo->period == 0) {
 		*period = 0;
 		*ppr_options = 0;
@@ -1740,17 +1833,28 @@
 int
 ahc_update_neg_request(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
 		       struct ahc_tmode_tstate *tstate,
-		       struct ahc_initiator_tinfo *tinfo, int force)
+		       struct ahc_initiator_tinfo *tinfo, ahc_neg_type neg_type)
 {
 	u_int auto_negotiate_orig;
 
 	auto_negotiate_orig = tstate->auto_negotiate;
+	if (neg_type == AHC_NEG_ALWAYS) {
+		/*
+		 * Force our "current" settings to be
+		 * unknown so that unless a bus reset
+		 * occurs the need to renegotiate is
+		 * recorded persistently.
+		 */
+		tinfo->curr.period = AHC_PERIOD_UNKNOWN;
+		tinfo->curr.width = AHC_WIDTH_UNKNOWN;
+		tinfo->curr.offset = AHC_OFFSET_UNKNOWN;
+	}
 	if (tinfo->curr.period != tinfo->goal.period
 	 || tinfo->curr.width != tinfo->goal.width
 	 || tinfo->curr.offset != tinfo->goal.offset
 	 || tinfo->curr.ppr_options != tinfo->goal.ppr_options
-	 || (force
-	  && (tinfo->goal.period != 0
+	 || (neg_type == AHC_NEG_IF_NON_ASYNC
+	  && (tinfo->goal.offset != 0
 	   || tinfo->goal.width != MSG_EXT_WDTR_BUS_8_BIT
 	   || tinfo->goal.ppr_options != 0)))
 		tstate->auto_negotiate |= devinfo->target_mask;
@@ -1881,7 +1985,7 @@
 	}
 
 	update_needed += ahc_update_neg_request(ahc, devinfo, tstate,
-						tinfo, /*force*/FALSE);
+						tinfo, AHC_NEG_TO_GOAL);
 
 	if (update_needed)
 		ahc_update_pending_scbs(ahc);
@@ -1943,7 +2047,7 @@
 	}
 
 	update_needed += ahc_update_neg_request(ahc, devinfo, tstate,
-						tinfo, /*force*/FALSE);
+						tinfo, AHC_NEG_TO_GOAL);
 	if (update_needed)
 		ahc_update_pending_scbs(ahc);
 }
@@ -2057,7 +2161,8 @@
 
 	if (role == ROLE_TARGET
 	 && (ahc->features & AHC_MULTI_TID) != 0
-	 && (ahc_inb(ahc, SEQ_FLAGS) & CMDPHASE_PENDING) != 0) {
+	 && (ahc_inb(ahc, SEQ_FLAGS)
+ 	   & (CMDPHASE_PENDING|TARG_CMD_PENDING|NO_DISCONNECT)) != 0) {
 		/* We were selected, so pull our id from TARGIDIN */
 		our_id = ahc_inb(ahc, TARGIDIN) & OID;
 	} else if ((ahc->features & AHC_ULTRA2) != 0)
@@ -2107,6 +2212,13 @@
 	devinfo->target_mask = (0x01 << devinfo->target_offset);
 }
 
+void
+ahc_print_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
+{
+	printf("%s:%c:%d:%d: ", ahc_name(ahc), devinfo->channel,
+	       devinfo->target, devinfo->lun);
+}
+
 static void
 ahc_scb_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
 		struct scb *scb)
@@ -2116,7 +2228,7 @@
 
 	our_id = SCSIID_OUR_ID(scb->hscb->scsiid);
 	role = ROLE_INITIATOR;
-	if ((scb->hscb->control & TARGET_SCB) != 0)
+	if ((scb->flags & SCB_TARGET_SCB) != 0)
 		role = ROLE_TARGET;
 	ahc_compile_devinfo(devinfo, our_id, SCB_GET_TARGET(ahc, scb),
 			    SCB_GET_LUN(scb), SCB_GET_CHANNEL(ahc, scb), role);
@@ -2241,7 +2353,6 @@
 	int	dowide;
 	int	dosync;
 	int	doppr;
-	int	use_ppr;
 	u_int	period;
 	u_int	ppr_options;
 	u_int	offset;
@@ -2263,23 +2374,37 @@
 				       &ppr_options, devinfo->role);
 	dowide = tinfo->curr.width != tinfo->goal.width;
 	dosync = tinfo->curr.period != period;
-	doppr = tinfo->curr.ppr_options != ppr_options;
+	/*
+	 * Only use PPR if we have options that need it, even if the device
+	 * claims to support it.  There might be an expander in the way
+	 * that doesn't.
+	 */
+	doppr = ppr_options != 0;
 
 	if (!dowide && !dosync && !doppr) {
 		dowide = tinfo->goal.width != MSG_EXT_WDTR_BUS_8_BIT;
-		dosync = tinfo->goal.period != 0;
-		doppr = tinfo->goal.ppr_options != 0;
+		dosync = tinfo->goal.offset != 0;
 	}
 
 	if (!dowide && !dosync && !doppr) {
-		panic("ahc_intr: AWAITING_MSG for negotiation, "
-		      "but no negotiation needed\n");	
+		/*
+		 * Force async with a WDTR message if we have a wide bus,
+		 * or just issue an SDTR with a 0 offset.
+		 */
+		if ((ahc->features & AHC_WIDE) != 0)
+			dowide = 1;
+		else
+			dosync = 1;
+
+		if (bootverbose) {
+			ahc_print_devinfo(ahc, devinfo);
+			printf("Ensuring async\n");
+		}
 	}
 
-	use_ppr = (tinfo->curr.transport_version >= 3) || doppr;
 	/* Target initiated PPR is not allowed in the SCSI spec */
 	if (devinfo->role == ROLE_TARGET)
-		use_ppr = 0;
+		doppr = 0;
 
 	/*
 	 * Both the PPR message and SDTR message require the
@@ -2289,14 +2414,14 @@
 	 * Regardless, guarantee that if we are using WDTR and SDTR
 	 * messages that WDTR comes first.
 	 */
-	if (use_ppr || (dosync && !dowide)) {
+	if (doppr || (dosync && !dowide)) {
 
 		offset = tinfo->goal.offset;
 		ahc_validate_offset(ahc, tinfo, rate, &offset,
-				    use_ppr ? tinfo->goal.width
-					    : tinfo->curr.width,
+				    doppr ? tinfo->goal.width
+					  : tinfo->curr.width,
 				    devinfo->role);
-		if (use_ppr) {
+		if (doppr) {
 			ahc_construct_ppr(ahc, devinfo, period, offset,
 					  tinfo->goal.width, ppr_options);
 		} else {
@@ -2315,6 +2440,8 @@
 ahc_construct_sdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
 		   u_int period, u_int offset)
 {
+	if (offset == 0)
+		period = AHC_ASYNC_XFER_PERIOD;
 	ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
 	ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_SDTR_LEN;
 	ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_SDTR;
@@ -2357,6 +2484,8 @@
 		  u_int period, u_int offset, u_int bus_width,
 		  u_int ppr_options)
 {
+	if (offset == 0)
+		period = AHC_ASYNC_XFER_PERIOD;
 	ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
 	ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_PPR_LEN;
 	ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_PPR;
@@ -2395,6 +2524,100 @@
 		 ahc_inb(ahc, SEQ_FLAGS2) & ~TARGET_MSG_PENDING);
 }
 
+static void
+ahc_handle_proto_violation(struct ahc_softc *ahc)
+{
+	struct	ahc_devinfo devinfo;
+	struct	scb *scb;
+	u_int	scbid;
+	u_int	seq_flags;
+	u_int	curphase;
+	u_int	lastphase;
+	int	found;
+
+	ahc_fetch_devinfo(ahc, &devinfo);
+	scbid = ahc_inb(ahc, SCB_TAG);
+	scb = ahc_lookup_scb(ahc, scbid);
+	seq_flags = ahc_inb(ahc, SEQ_FLAGS);
+	curphase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
+	lastphase = ahc_inb(ahc, LASTPHASE);
+	if ((seq_flags & NOT_IDENTIFIED) != 0) {
+
+		/*
+		 * The reconnecting target either did not send an
+		 * identify message, or did, but we didn't find an SCB
+		 * to match.
+		 */
+		ahc_print_devinfo(ahc, &devinfo);
+		printf("Target did not send an IDENTIFY message. "
+		       "LASTPHASE = 0x%x.\n", lastphase);
+		scb = NULL;
+	} else if (scb == NULL) {
+		/*
+		 * We don't seem to have an SCB active for this
+		 * transaction.  Print an error and reset the bus.
+		 */
+		ahc_print_devinfo(ahc, &devinfo);
+		printf("No SCB found during protocol violation\n");
+		goto proto_violation_reset;
+	} else {
+		ahc_set_transaction_status(scb, CAM_SEQUENCE_FAIL);
+		if ((seq_flags & NO_CDB_SENT) != 0) {
+			ahc_print_path(ahc, scb);
+			printf("No or incomplete CDB sent to device.\n");
+		} else if ((ahc_inb(ahc, SCB_CONTROL) & STATUS_RCVD) == 0) {
+			/*
+			 * The target never bothered to provide status to
+			 * us prior to completing the command.  Since we don't
+			 * know the disposition of this command, we must attempt
+			 * to abort it.  Assert ATN and prepare to send an abort
+			 * message.
+			 */
+			ahc_print_path(ahc, scb);
+			printf("Completed command without status.\n");
+		} else {
+			ahc_print_path(ahc, scb);
+			printf("Unknown protocol violation.\n");
+			ahc_dump_card_state(ahc);
+		}
+	}
+	if ((lastphase & ~P_DATAIN_DT) == 0
+	 || lastphase == P_COMMAND) {
+proto_violation_reset:
+		/*
+		 * Target either went directly to data/command
+		 * phase or didn't respond to our ATN.
+		 * The only safe thing to do is to blow
+		 * it away with a bus reset.
+		 */
+		found = ahc_reset_channel(ahc, 'A', TRUE);
+		printf("%s: Issued Channel %c Bus Reset. "
+		       "%d SCBs aborted\n", ahc_name(ahc), 'A', found);
+	} else {
+		/*
+		 * Leave the selection hardware off in case
+		 * this abort attempt will affect yet to
+		 * be sent commands.
+		 */
+		ahc_outb(ahc, SCSISEQ,
+			 ahc_inb(ahc, SCSISEQ) & ~ENSELO);
+		ahc_assert_atn(ahc);
+		ahc_outb(ahc, MSG_OUT, HOST_MSG);
+		if (scb == NULL) {
+			ahc_print_devinfo(ahc, &devinfo);
+			ahc->msgout_buf[0] = MSG_ABORT_TASK;
+			ahc->msgout_len = 1;
+			ahc->msgout_index = 0;
+			ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
+		} else {
+			ahc_print_path(ahc, scb);
+			scb->flags |= SCB_ABORT;
+		}
+		printf("Protocol violation %s.  Attempting to abort.\n",
+		       ahc_lookup_phase_entry(curphase)->phasemsg);
+	}
+}
+
 /*
  * Manual message loop handler.
  */
@@ -2420,8 +2643,21 @@
 		if (ahc->msgout_len == 0)
 			panic("HOST_MSG_LOOP interrupt with no active message");
 
+#ifdef AHC_DEBUG
+		if ((ahc_debug & AHC_SHOW_MESSAGES) != 0) {
+			ahc_print_devinfo(ahc, &devinfo);
+			printf("INITIATOR_MSG_OUT");
+		}
+#endif
 		phasemis = bus_phase != P_MESGOUT;
 		if (phasemis) {
+#ifdef AHC_DEBUG
+			if ((ahc_debug & AHC_SHOW_MESSAGES) != 0) {
+				printf(" PHASEMIS %s\n",
+				       ahc_lookup_phase_entry(bus_phase)
+							     ->phasemsg);
+			}
+#endif
 			if (bus_phase == P_MESGIN) {
 				/*
 				 * Change gears and see if
@@ -2442,6 +2678,10 @@
 		if (ahc->send_msg_perror) {
 			ahc_outb(ahc, CLRSINT1, CLRATNO);
 			ahc_outb(ahc, CLRSINT1, CLRREQINIT);
+#ifdef AHC_DEBUG
+			if ((ahc_debug & AHC_SHOW_MESSAGES) != 0)
+				printf(" byte 0x%x\n", ahc->send_msg_perror);
+#endif
 			ahc_outb(ahc, SCSIDATL, MSG_PARITY_ERROR);
 			break;
 		}
@@ -2468,6 +2708,11 @@
 		 * the next byte on the bus.
 		 */
 		ahc_outb(ahc, CLRSINT1, CLRREQINIT);
+#ifdef AHC_DEBUG
+		if ((ahc_debug & AHC_SHOW_MESSAGES) != 0)
+			printf(" byte 0x%x\n",
+			       ahc->msgout_buf[ahc->msgout_index]);
+#endif
 		ahc_outb(ahc, SCSIDATL, ahc->msgout_buf[ahc->msgout_index++]);
 		break;
 	}
@@ -2476,9 +2721,21 @@
 		int phasemis;
 		int message_done;
 
+#ifdef AHC_DEBUG
+		if ((ahc_debug & AHC_SHOW_MESSAGES) != 0) {
+			ahc_print_devinfo(ahc, &devinfo);
+			printf("INITIATOR_MSG_IN");
+		}
+#endif
 		phasemis = bus_phase != P_MESGIN;
-
 		if (phasemis) {
+#ifdef AHC_DEBUG
+			if ((ahc_debug & AHC_SHOW_MESSAGES) != 0) {
+				printf(" PHASEMIS %s\n",
+				       ahc_lookup_phase_entry(bus_phase)
+							     ->phasemsg);
+			}
+#endif
 			ahc->msgin_index = 0;
 			if (bus_phase == P_MESGOUT
 			 && (ahc->send_msg_perror == TRUE
@@ -2493,6 +2750,11 @@
 
 		/* Pull the byte in without acking it */
 		ahc->msgin_buf[ahc->msgin_index] = ahc_inb(ahc, SCSIBUSL);
+#ifdef AHC_DEBUG
+		if ((ahc_debug & AHC_SHOW_MESSAGES) != 0)
+			printf(" byte 0x%x\n",
+			       ahc->msgin_buf[ahc->msgin_index]);
+#endif
 
 		message_done = ahc_parse_msg(ahc, &devinfo);
 
@@ -2508,14 +2770,22 @@
 			 * assert ATN so the target takes us to the
 			 * message out phase.
 			 */
-			if (ahc->msgout_len != 0)
-				ahc_assert_atn(ahc);
+			if (ahc->msgout_len != 0) {
+#ifdef AHC_DEBUG
+				if ((ahc_debug & AHC_SHOW_MESSAGES) != 0)
+					printf("Asserting ATN for response\n");
+#endif
+			}
 		} else 
 			ahc->msgin_index++;
 
-		/* Ack the byte */
-		ahc_outb(ahc, CLRSINT1, CLRREQINIT);
-		ahc_inb(ahc, SCSIDATL);
+		if (message_done == MSGLOOP_TERMINATED) {
+			end_session = TRUE;
+		} else {
+			/* Ack the byte */
+			ahc_outb(ahc, CLRSINT1, CLRREQINIT);
+			ahc_inb(ahc, SCSIDATL);
+		}
 		break;
 	}
 	case MSG_TYPE_TARGET_MSGIN:
@@ -2726,6 +2996,17 @@
 	 * extended message type.
 	 */
 	switch (ahc->msgin_buf[0]) {
+	case MSG_DISCONNECT:
+	case MSG_SAVEDATAPOINTER:
+	case MSG_CMDCOMPLETE:
+	case MSG_RESTOREPOINTERS:
+	case MSG_IGN_WIDE_RESIDUE:
+		/*
+		 * End our message loop as these are messages
+		 * the sequencer handles on its own.
+		 */
+		done = MSGLOOP_TERMINATED;
+		break;
 	case MSG_MESSAGE_REJECT:
 		response = ahc_handle_msg_reject(ahc, devinfo);
 		/* FALLTHROUGH */
@@ -2895,7 +3176,7 @@
 					 AHC_TRANS_ACTIVE, /*paused*/TRUE);
 			if (sending_reply == FALSE && reject == FALSE) {
 
-				if (tinfo->goal.period) {
+				if (tinfo->goal.offset) {
 					ahc->msgout_index = 0;
 					ahc->msgout_len = 0;
 					ahc_build_transfer_msg(ahc, devinfo);
@@ -3160,7 +3441,7 @@
 		 * but rejected our response, we already cleared the
 		 * sync rate before sending our WDTR.
 		 */
-		if (tinfo->goal.period) {
+		if (tinfo->goal.offset) {
 
 			/* Start the sync negotiation */
 			ahc->msgout_index = 0;
@@ -3515,6 +3796,15 @@
 	ahc = device_get_softc((device_t)platform_arg);
 #endif
 	memset(ahc, 0, sizeof(*ahc));
+	ahc->seep_config = malloc(sizeof(*ahc->seep_config),
+				  M_DEVBUF, M_NOWAIT);
+	if (ahc->seep_config == NULL) {
+#ifndef	__FreeBSD__
+		free(ahc, M_DEVBUF);
+#endif
+		free(name, M_DEVBUF);
+		return (NULL);
+	}
 	LIST_INIT(&ahc->pending_scbs);
 	/* We don't know our unit number until the OSM sets it */
 	ahc->name = name;
@@ -3527,7 +3817,7 @@
 	ahc->bugs = AHC_BUGNONE;
 	ahc->flags = AHC_FNONE;
 
-	for (i = 0; i < 16; i++)
+	for (i = 0; i < AHC_NUM_TARGETS; i++)
 		TAILQ_INIT(&ahc->untagged_queues[i]);
 	if (ahc_platform_alloc(ahc, platform_arg) != 0) {
 		ahc_free(ahc);
@@ -3614,6 +3904,22 @@
 	ahc->init_level++;
 }
 
+/*
+ * Verify that the passed in softc pointer is for a
+ * controller that is still configured.
+ */
+struct ahc_softc *
+ahc_find_softc(struct ahc_softc *ahc)
+{
+	struct ahc_softc *list_ahc;
+
+	TAILQ_FOREACH(list_ahc, &ahc_tailq, links) {
+		if (list_ahc == ahc)
+			return (ahc);
+	}
+	return (NULL);
+}
+
 void
 ahc_set_unit(struct ahc_softc *ahc, int unit)
 {
@@ -3694,6 +4000,10 @@
 #endif
 	if (ahc->name != NULL)
 		free(ahc->name, M_DEVBUF);
+	if (ahc->seep_config != NULL)
+		free(ahc->seep_config, M_DEVBUF);
+	if (ahc->saved_stack != NULL)
+		free(ahc->saved_stack, M_DEVBUF);
 #ifndef __FreeBSD__
 	free(ahc, M_DEVBUF);
 #endif
@@ -3714,7 +4024,7 @@
 	ahc_outb(ahc, SXFRCTL0, 0);
 	ahc_outb(ahc, DSPCISTATUS, 0);
 
-	for (i = TARG_SCSIRATE; i < HA_274_BIOSCTRL; i++)
+	for (i = TARG_SCSIRATE; i < SCSICONF; i++)
 		ahc_outb(ahc, i, 0);
 }
 
@@ -3753,7 +4063,10 @@
 	ahc_outb(ahc, HCNTRL, CHIPRST | ahc->pause);
 
 	/*
-	 * Ensure that the reset has finished
+	 * Ensure that the reset has finished.  We delay 1000us
+	 * prior to reading the register to make sure the chip
+	 * has sufficiently completed its reset to handle register
+	 * accesses.
 	 */
 	wait = 1000;
 	do {
@@ -3846,11 +4159,26 @@
 static void
 ahc_build_free_scb_list(struct ahc_softc *ahc)
 {
+	int scbsize;
 	int i;
 
+	scbsize = 32;
+	if ((ahc->flags & AHC_LSCBS_ENABLED) != 0)
+		scbsize = 64;
+
 	for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
+		int j;
+
 		ahc_outb(ahc, SCBPTR, i);
 
+		/*
+		 * Touch all SCB bytes to avoid parity errors
+		 * should one of our debugging routines read
+		 * an otherwise uninitiatlized byte.
+		 */
+		for (j = 0; j < scbsize; j++)
+			ahc_outb(ahc, SCB_BASE+j, 0xFF);
+
 		/* Clear the control byte. */
 		ahc_outb(ahc, SCB_CONTROL, 0);
 
@@ -3860,17 +4188,15 @@
 		else 
 			ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL);
 
-		/* Make the tag number invalid */
+		/* Make the tag number, SCSIID, and lun invalid */
 		ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL);
+		ahc_outb(ahc, SCB_SCSIID, 0xFF);
+		ahc_outb(ahc, SCB_LUN, 0xFF);
 	}
 
 	/* Make sure that the last SCB terminates the free list */
 	ahc_outb(ahc, SCBPTR, i-1);
 	ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL);
-
-	/* Ensure we clear the 0 SCB's control byte. */
-	ahc_outb(ahc, SCBPTR, 0);
-	ahc_outb(ahc, SCB_CONTROL, 0);
 }
 
 static int
@@ -3982,7 +4308,7 @@
 	scb_data->init_level++;
 
 	/* DMA tag for our S/G structures.  We allocate in page sized chunks */
-	if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
+	if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/8,
 			       /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
 			       /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
 			       /*highaddr*/BUS_SPACE_MAXADDR,
@@ -4213,6 +4539,12 @@
 	size_t	 driver_data_size;
 	uint32_t physaddr;
 
+	ahc->stack_size = ahc_probe_stack_size(ahc);
+	ahc->saved_stack = malloc(ahc->stack_size * sizeof(uint16_t),
+				  M_DEVBUF, M_NOWAIT);
+	if (ahc->saved_stack == NULL)
+		return (ENOMEM);
+
 #ifdef AHC_DEBUG_SEQUENCER
 	ahc->flags |= AHC_SEQUENCER_DEBUG;
 #endif
@@ -4234,6 +4566,12 @@
 		}
 	}
 	printf ("\n");
+	/*
+	 * Reading uninitialized scratch ram may
+	 * generate parity errors.
+	 */
+	ahc_outb(ahc, CLRINT, CLRPARERR);
+	ahc_outb(ahc, CLRINT, CLRBRKADRINT);
 #endif
 	max_targ = 15;
 
@@ -4364,7 +4702,7 @@
 	}
 
 #ifdef AHC_DEBUG
-	if (ahc_debug & AHC_SHOWMISC) {
+	if (ahc_debug & AHC_SHOW_MISC) {
 		printf("%s: hardware scb %d bytes; kernel scb %d bytes; "
 		       "ahc_dma %d bytes\n",
 			ahc_name(ahc),
@@ -4425,7 +4763,7 @@
 	tagenable = ALL_TARGETS_MASK;
 
 	/* Grab the disconnection disable table and invert it for our needs */
-	if (ahc->flags & AHC_USEDEFAULTS) {
+	if ((ahc->flags & AHC_USEDEFAULTS) != 0) {
 		printf("%s: Host Adapter Bios disabled.  Using default SCSI "
 			"device parameters\n", ahc_name(ahc));
 		ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B|
@@ -4699,21 +5037,28 @@
 {
 	int intstat;
 	int maxloops;
+	int paused;
 
 	maxloops = 1000;
 	ahc->flags |= AHC_ALL_INTERRUPTS;
 	intstat = 0;
+	paused = FALSE;
 	do {
+		if (paused)
+			ahc_unpause(ahc);
 		ahc_intr(ahc);
 		ahc_pause(ahc);
+		paused = TRUE;
+		ahc_outb(ahc, SCSISEQ, ahc_inb(ahc, SCSISEQ) & ~ENSELO);
 		ahc_clear_critical_section(ahc);
 		if (intstat == 0xFF && (ahc->features & AHC_REMOVABLE) != 0)
 			break;
-		maxloops--;
-	} while (((intstat = ahc_inb(ahc, INTSTAT)) & INT_PEND) && --maxloops);
+	} while (--maxloops
+	      && (((intstat = ahc_inb(ahc, INTSTAT)) & INT_PEND) != 0
+	       || (ahc_inb(ahc, SSTAT0) & (SELDO|SELINGO))));
 	if (maxloops == 0) {
 		printf("Infinite interrupt loop, INTSTAT = %x",
-		      ahc_inb(ahc, INTSTAT));
+		       ahc_inb(ahc, INTSTAT));
 	}
 	ahc_platform_flushwork(ahc);
 	ahc->flags &= ~AHC_ALL_INTERRUPTS;
@@ -5046,8 +5391,8 @@
 static int
 ahc_qinfifo_count(struct ahc_softc *ahc)
 {
-	u_int8_t qinpos;
-	u_int8_t diff;
+	uint8_t qinpos;
+	uint8_t diff;
 
 	if ((ahc->features & AHC_QUEUE_REGS) != 0) {
 		qinpos = ahc_inb(ahc, SNSCB_QOFF);
@@ -5068,11 +5413,10 @@
 	uint8_t qinstart;
 	uint8_t qinpos;
 	uint8_t qintail;
-	uint8_t next, prev;
+	uint8_t next;
+	uint8_t prev;
 	uint8_t curscbptr;
 	int	found;
-	int	maxtarget;
-	int	i;
 	int	have_qregs;
 
 	qintail = ahc->qinfifonext;
@@ -5083,7 +5427,6 @@
 	} else
 		qinstart = ahc_inb(ahc, QINPOS);
 	qinpos = qinstart;
-	next = ahc_inb(ahc, NEXT_QUEUED_SCB);
 	found = 0;
 	prev_scb = NULL;
 
@@ -5123,8 +5466,7 @@
 
 				ostat = ahc_get_transaction_status(scb);
 				if (ostat == CAM_REQ_INPROG)
-					ahc_set_transaction_status(scb,
-								   status);
+					ahc_set_transaction_status(scb, status);
 				cstat = ahc_get_transaction_status(scb);
 				if (cstat != CAM_REQ_CMP)
 					ahc_freeze_scb(scb);
@@ -5133,9 +5475,9 @@
 				ahc_done(ahc, scb);
 
 				/* FALLTHROUGH */
+			}
 			case SEARCH_REMOVE:
 				break;
-			}
 			case SEARCH_COUNT:
 				ahc_qinfifo_requeue(ahc, prev_scb, scb);
 				prev_scb = scb;
@@ -5262,9 +5604,33 @@
 	}
 	ahc_outb(ahc, SCBPTR, curscbptr);
 
-	/*
-	 * And lastly, the untagged holding queues.
-	 */
+	found += ahc_search_untagged_queues(ahc, /*ahc_io_ctx_t*/NULL, target,
+					    channel, lun, status, action);
+
+	if (action == SEARCH_COMPLETE)
+		ahc_release_untagged_queues(ahc);
+	return (found);
+}
+
+int
+ahc_search_untagged_queues(struct ahc_softc *ahc, ahc_io_ctx_t ctx,
+			   int target, char channel, int lun, uint32_t status,
+			   ahc_search_action action)
+{
+	struct	scb *scb;
+	int	maxtarget;
+	int	found;
+	int	i;
+
+	if (action == SEARCH_COMPLETE) {
+		/*
+		 * Don't attempt to run any queued untagged transactions
+		 * until we are done with the abort process.
+		 */
+		ahc_freeze_untagged_queues(ahc);
+	}
+
+	found = 0;
 	i = 0;
 	if ((ahc->flags & AHC_SCB_BTT) == 0) {
 
@@ -5303,37 +5669,38 @@
 			if ((scb->flags & SCB_ACTIVE) != 0)
 				continue;
 
-			if (ahc_match_scb(ahc, scb, target, channel,
-					  lun, SCB_LIST_NULL, role)) {
-				/*
-				 * We found an scb that needs to be acted on.
-				 */
-				found++;
-				switch (action) {
-				case SEARCH_COMPLETE:
-				{
-					cam_status ostat;
-					cam_status cstat;
+			if (ahc_match_scb(ahc, scb, target, channel, lun,
+					  SCB_LIST_NULL, ROLE_INITIATOR) == 0
+			 || (ctx != NULL && ctx != scb->io_ctx))
+				continue;
 
-					ostat = ahc_get_transaction_status(scb);
-					if (ostat == CAM_REQ_INPROG)
-						ahc_set_transaction_status(scb,
-								   status);
-					cstat = ahc_get_transaction_status(scb);
-					if (cstat != CAM_REQ_CMP)
-						ahc_freeze_scb(scb);
-					if ((scb->flags & SCB_ACTIVE) == 0)
-						printf("Inactive SCB in untaggedQ\n");
-					ahc_done(ahc, scb);
-					break;
-				}
-				case SEARCH_REMOVE:
-					TAILQ_REMOVE(untagged_q, scb,
-						     links.tqe);
-					break;
-				case SEARCH_COUNT:
-					break;
-				}
+			/*
+			 * We found an scb that needs to be acted on.
+			 */
+			found++;
+			switch (action) {
+			case SEARCH_COMPLETE:
+			{
+				cam_status ostat;
+				cam_status cstat;
+
+				ostat = ahc_get_transaction_status(scb);
+				if (ostat == CAM_REQ_INPROG)
+					ahc_set_transaction_status(scb, status);
+				cstat = ahc_get_transaction_status(scb);
+				if (cstat != CAM_REQ_CMP)
+					ahc_freeze_scb(scb);
+				if ((scb->flags & SCB_ACTIVE) == 0)
+					printf("Inactive SCB in untaggedQ\n");
+				ahc_done(ahc, scb);
+				break;
+			}
+			case SEARCH_REMOVE:
+				scb->flags &= ~SCB_UNTAGGEDQ;
+				TAILQ_REMOVE(untagged_q, scb, links.tqe);
+				break;
+			case SEARCH_COUNT:
+				break;
 			}
 		}
 	}
@@ -5646,6 +6013,7 @@
 	ahc_outb(ahc, SIMODE1, ahc_inb(ahc, SIMODE1) & ~ENSCSIRST);
 	scsiseq = ahc_inb(ahc, SCSISEQ);
 	ahc_outb(ahc, SCSISEQ, scsiseq | SCSIRSTO);
+	ahc_flush_device_writes(ahc);
 	ahc_delay(AHC_BUSRESET_DELAY);
 	/* Turn off the bus reset */
 	ahc_outb(ahc, SCSISEQ, scsiseq & ~SCSIRSTO);
@@ -5687,6 +6055,16 @@
 	 */
 	ahc_run_qoutfifo(ahc);
 #if AHC_TARGET_MODE
+	/*
+	 * XXX - In Twin mode, the tqinfifo may have commands
+	 *	 for an unaffected channel in it.  However, if
+	 *	 we have run out of ATIO resources to drain that
+	 *	 queue, we may not get them all out here.  Further,
+	 *	 the blocked transactions for the reset channel
+	 *	 should just be killed off, irrespecitve of whether
+	 *	 we are blocked on ATIO resources.  Write a routine
+	 *	 to compact the tqinfifo appropriately.
+	 */
 	if ((ahc->flags & AHC_TARGETROLE) != 0) {
 		ahc_run_tqinfifo(ahc, /*paused*/TRUE);
 	}
@@ -5708,10 +6086,6 @@
 		 */
 		ahc_outb(ahc, SBLKCTL, sblkctl ^ SELBUSB);
 		simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST);
-		ahc_outb(ahc, SIMODE1, simode1);
-		if (initiate_reset)
-			ahc_reset_current_bus(ahc);
-		ahc_clear_intstat(ahc);
 #if AHC_TARGET_MODE
 		/*
 		 * Bus resets clear ENSELI, so we cannot
@@ -5719,19 +6093,18 @@
 		 * if we are in target mode.
 		 */
 		if ((ahc->flags & AHC_TARGETROLE) != 0)
-			ahc_outb(ahc, SIMODE1, simode1 | ENSCSIRST);
+			simode1 |= ENSCSIRST;
 #endif
+		ahc_outb(ahc, SIMODE1, simode1);
+		if (initiate_reset)
+			ahc_reset_current_bus(ahc);
+		ahc_clear_intstat(ahc);
 		ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP));
 		ahc_outb(ahc, SBLKCTL, sblkctl);
 		restart_needed = FALSE;
 	} else {
 		/* Case 2: A command from this bus is active or we're idle */
-		ahc_clear_msg_state(ahc);
 		simode1 = ahc_inb(ahc, SIMODE1) & ~(ENBUSFREE|ENSCSIRST);
-		ahc_outb(ahc, SIMODE1, simode1);
-		if (initiate_reset)
-			ahc_reset_current_bus(ahc);
-		ahc_clear_intstat(ahc);
 #if AHC_TARGET_MODE
 		/*
 		 * Bus resets clear ENSELI, so we cannot
@@ -5739,8 +6112,12 @@
 		 * if we are in target mode.
 		 */
 		if ((ahc->flags & AHC_TARGETROLE) != 0)
-			ahc_outb(ahc, SIMODE1, simode1 | ENSCSIRST);
+			simode1 |= ENSCSIRST;
 #endif
+		ahc_outb(ahc, SIMODE1, simode1);
+		if (initiate_reset)
+			ahc_reset_current_bus(ahc);
+		ahc_clear_intstat(ahc);
 		ahc_outb(ahc, SCSISEQ, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP));
 		restart_needed = TRUE;
 	}
@@ -5819,7 +6196,7 @@
  * Calculate the residual for a just completed SCB.
  */
 void
-ahc_calc_residual(struct scb *scb)
+ahc_calc_residual(struct ahc_softc *ahc, struct scb *scb)
 {
 	struct hardware_scb *hscb;
 	struct status_pkt *spkt;
@@ -5893,7 +6270,7 @@
 		ahc_set_sense_residual(scb, resid);
 
 #ifdef AHC_DEBUG
-	if ((ahc_debug & AHC_SHOWMISC) != 0) {
+	if ((ahc_debug & AHC_SHOW_MISC) != 0) {
 		ahc_print_path(ahc, scb);
 		printf("Handled Residual of %d bytes\n", resid);
 	}
@@ -6275,14 +6652,98 @@
 	}
 }
 
+static int
+ahc_probe_stack_size(struct ahc_softc *ahc)
+{
+	int last_probe;
+
+	last_probe = 0;
+	while (1) {
+		int i;
+
+		/*
+		 * We avoid using 0 as a pattern to avoid
+		 * confusion if the stack implementation
+		 * "back-fills" with zeros when "poping'
+		 * entries.
+		 */
+		for (i = 1; i <= last_probe+1; i++) {
+		       ahc_outb(ahc, STACK, i & 0xFF);
+		       ahc_outb(ahc, STACK, (i >> 8) & 0xFF);
+		}
+
+		/* Verify */
+		for (i = last_probe+1; i > 0; i--) {
+			u_int stack_entry;
+
+			stack_entry = ahc_inb(ahc, STACK)
+				    |(ahc_inb(ahc, STACK) << 8);
+			if (stack_entry != i)
+				goto sized;
+		}
+		last_probe++;
+	}
+sized:
+	return (last_probe);
+}
+
+int
+ahc_print_register(ahc_reg_parse_entry_t *table, u_int num_entries,
+		   const char *name, u_int address, u_int value,
+		   u_int *cur_column, u_int wrap_point)
+{
+	int	printed;
+	u_int	printed_mask;
+
+	if (cur_column != NULL && *cur_column >= wrap_point) {
+		printf("\n");
+		*cur_column = 0;
+	}
+	printed = printf("%s[0x%x]", name, value);
+	if (table == NULL) {
+		printed += printf(" ");
+		*cur_column += printed;
+		return (printed);
+	}
+	printed_mask = 0;
+	while (printed_mask != 0xFF) {
+		int entry;
+
+		for (entry = 0; entry < num_entries; entry++) {
+			if (((value & table[entry].mask)
+			  != table[entry].value)
+			 || ((printed_mask & table[entry].mask)
+			  == table[entry].mask))
+				continue;
+
+			printed += printf("%s%s",
+					  printed_mask == 0 ? ":(" : "|",
+					  table[entry].name);
+			printed_mask |= table[entry].mask;
+			
+			break;
+		}
+		if (entry >= num_entries)
+			break;
+	}
+	if (printed_mask != 0)
+		printed += printf(") ");
+	else
+		printed += printf(" ");
+	if (cur_column != NULL)
+		*cur_column += printed;
+	return (printed);
+}
+
 void
 ahc_dump_card_state(struct ahc_softc *ahc)
 {
-	struct scb *scb;
-	struct scb_tailq *untagged_q;
-	int target;
-	int maxtarget;
-	int i;
+	struct	scb *scb;
+	struct	scb_tailq *untagged_q;
+	u_int	cur_col;
+	int	target;
+	int	maxtarget;
+	int	i;
 	uint8_t last_phase;
 	uint8_t qinpos;
 	uint8_t qintail;
@@ -6299,23 +6760,36 @@
 	printf("ACCUM = 0x%x, SINDEX = 0x%x, DINDEX = 0x%x, ARG_2 = 0x%x\n",
 	       ahc_inb(ahc, ACCUM), ahc_inb(ahc, SINDEX), ahc_inb(ahc, DINDEX),
 	       ahc_inb(ahc, ARG_2));
-	printf("HCNT = 0x%x\n", ahc_inb(ahc, HCNT));
-	printf("SCSISEQ = 0x%x, SBLKCTL = 0x%x\n",
-	       ahc_inb(ahc, SCSISEQ), ahc_inb(ahc, SBLKCTL));
-	printf(" DFCNTRL = 0x%x, DFSTATUS = 0x%x\n",
-	       ahc_inb(ahc, DFCNTRL), ahc_inb(ahc, DFSTATUS));
-	printf("LASTPHASE = 0x%x, SCSISIGI = 0x%x, SXFRCTL0 = 0x%x\n",
-	       last_phase, ahc_inb(ahc, SCSISIGI), ahc_inb(ahc, SXFRCTL0));
-	printf("SSTAT0 = 0x%x, SSTAT1 = 0x%x\n",
-	       ahc_inb(ahc, SSTAT0), ahc_inb(ahc, SSTAT1));
+	printf("HCNT = 0x%x SCBPTR = 0x%x\n", ahc_inb(ahc, HCNT),
+	       ahc_inb(ahc, SCBPTR));
+	cur_col = 0;
 	if ((ahc->features & AHC_DT) != 0)
-		printf("SCSIPHASE = 0x%x\n", ahc_inb(ahc, SCSIPHASE));
-	printf("STACK == 0x%x, 0x%x, 0x%x, 0x%x\n",
-		ahc_inb(ahc, STACK) | (ahc_inb(ahc, STACK) << 8),
-		ahc_inb(ahc, STACK) | (ahc_inb(ahc, STACK) << 8),
-		ahc_inb(ahc, STACK) | (ahc_inb(ahc, STACK) << 8),
-		ahc_inb(ahc, STACK) | (ahc_inb(ahc, STACK) << 8));
-	printf("SCB count = %d\n", ahc->scb_data->numscbs);
+		ahc_scsisigi_print(ahc_inb(ahc, SCSISIGI), &cur_col, 50);
+	ahc_scsiphase_print(ahc_inb(ahc, SCSIPHASE), &cur_col, 50);
+	ahc_scsibusl_print(ahc_inb(ahc, SCSIBUSL), &cur_col, 50);
+	ahc_lastphase_print(ahc_inb(ahc, LASTPHASE), &cur_col, 50);
+	ahc_scsiseq_print(ahc_inb(ahc, SCSISEQ), &cur_col, 50);
+	ahc_sblkctl_print(ahc_inb(ahc, SBLKCTL), &cur_col, 50);
+	ahc_seqctl_print(ahc_inb(ahc, SEQCTL), &cur_col, 50);
+	ahc_seq_flags_print(ahc_inb(ahc, SEQ_FLAGS), &cur_col, 50);
+	ahc_sstat0_print(ahc_inb(ahc, SSTAT0), &cur_col, 50);
+	ahc_sstat1_print(ahc_inb(ahc, SSTAT1), &cur_col, 50);
+	ahc_sstat2_print(ahc_inb(ahc, SSTAT2), &cur_col, 50);
+	ahc_sstat3_print(ahc_inb(ahc, SSTAT3), &cur_col, 50);
+	ahc_simode0_print(ahc_inb(ahc, SIMODE0), &cur_col, 50);
+	ahc_simode1_print(ahc_inb(ahc, SIMODE1), &cur_col, 50);
+	ahc_sxfrctl0_print(ahc_inb(ahc, SXFRCTL0), &cur_col, 50);
+	ahc_dfcntrl_print(ahc_inb(ahc, DFCNTRL), &cur_col, 50);
+	ahc_dfstatus_print(ahc_inb(ahc, DFSTATUS), &cur_col, 50);
+	if (cur_col != 0)
+		printf("\n");
+	printf("STACK:");
+	for (i = 0; i < ahc->stack_size; i++) {
+		ahc->saved_stack[i] =
+		    ahc_inb(ahc, STACK)|(ahc_inb(ahc, STACK) << 8);
+	       printf(" 0x%x", ahc->saved_stack[i]);
+	}
+	printf("\nSCB count = %d\n", ahc->scb_data->numscbs);
 	printf("Kernel NEXTQSCB = %d\n", ahc->next_queued_scb->hscb->tag);
 	printf("Card NEXTQSCB = %d\n", ahc_inb(ahc, NEXT_QUEUED_SCB));
 	/* QINFIFO */
@@ -6372,18 +6846,34 @@
 	}
 	printf("\n");
 
+	printf("Sequencer SCB Info: ");
+	for (i = 0; i < ahc->scb_data->maxhscbs; i++) {
+		ahc_outb(ahc, SCBPTR, i);
+		cur_col = printf("\n%3d ", i);
+
+		ahc_scb_control_print(ahc_inb(ahc, SCB_CONTROL), &cur_col, 60);
+		ahc_scb_scsiid_print(ahc_inb(ahc, SCB_SCSIID), &cur_col, 60);
+		ahc_scb_lun_print(ahc_inb(ahc, SCB_LUN), &cur_col, 60);
+		ahc_scb_tag_print(ahc_inb(ahc, SCB_TAG), &cur_col, 60);
+	}
+	printf("\n");
+
 	printf("Pending list: ");
 	i = 0;
 	LIST_FOREACH(scb, &ahc->pending_scbs, pending_links) {
 		if (i++ > 256)
 			break;
-		if (scb != LIST_FIRST(&ahc->pending_scbs))
-			printf(", ");
-		printf("%d", scb->hscb->tag);
+		cur_col = printf("\n%3d ", scb->hscb->tag);
+		ahc_scb_control_print(scb->hscb->control, &cur_col, 60);
+		ahc_scb_scsiid_print(scb->hscb->scsiid, &cur_col, 60);
+		ahc_scb_lun_print(scb->hscb->lun, &cur_col, 60);
 		if ((ahc->flags & AHC_PAGESCBS) == 0) {
 			ahc_outb(ahc, SCBPTR, scb->hscb->tag);
-			printf("(0x%x, 0x%x)", ahc_inb(ahc, SCB_CONTROL),
-			       ahc_inb(ahc, SCB_TAG));
+			printf("(");
+			ahc_scb_control_print(ahc_inb(ahc, SCB_CONTROL),
+					      &cur_col, 60);
+			ahc_scb_tag_print(ahc_inb(ahc, SCB_TAG), &cur_col, 60);
+			printf(")");
 		}
 	}
 	printf("\n");
@@ -6469,6 +6959,7 @@
 	u_int	   target;
 	u_int	   lun;
 	u_int	   target_mask;
+	u_int	   our_id;
 	u_long	   s;
 	char	   channel;
 
@@ -6480,15 +6971,33 @@
 		return;
 	}
 
-	if ((ahc->features & AHC_MULTIROLE) != 0) {
-		u_int	   our_id;
+	if (cam_sim_bus(sim) == 0)
+		our_id = ahc->our_id;
+	else
+		our_id = ahc->our_id_b;
 
-		if (cam_sim_bus(sim) == 0)
-			our_id = ahc->our_id;
-		else
-			our_id = ahc->our_id_b;
+	if (ccb->ccb_h.target_id != our_id) {
+		/*
+		 * our_id represents our initiator ID, or
+		 * the ID of the first target to have an
+		 * enabled lun in target mode.  There are
+		 * two cases that may preclude enabling a
+		 * target id other than our_id.
+		 *
+		 *   o our_id is for an active initiator role.
+		 *     Since the hardware does not support
+		 *     reselections to the initiator role at
+		 *     anything other than our_id, and our_id
+		 *     is used by the hardware to indicate the
+		 *     ID to use for both select-out and
+		 *     reselect-out operations, the only target
+		 *     ID we can support in this mode is our_id.
+		 *
+		 *   o The MULTARGID feature is not available and
+		 *     a previous target mode ID has been enabled.
+		 */
+		if ((ahc->features & AHC_MULTIROLE) != 0) {
 
-		if (ccb->ccb_h.target_id != our_id) {
 			if ((ahc->features & AHC_MULTI_TID) != 0
 		   	 && (ahc->flags & AHC_INITIATORROLE) != 0) {
 				/*
@@ -6510,6 +7019,10 @@
 				 */
 				status = CAM_TID_INVALID;
 			}
+		} else if ((ahc->features & AHC_MULTI_TID) == 0
+			&& ahc->enabled_luns > 0) {
+
+			status = CAM_TID_INVALID;
 		}
 	}
 
@@ -6907,6 +7420,8 @@
 		/*
 		 * Wait for more ATIOs from the peripheral driver for this lun.
 		 */
+		if (bootverbose)
+			printf("%s: ATIOs exhausted\n", ahc_name(ahc));
 		return (1);
 	} else
 		ahc->flags &= ~AHC_TQINFIFO_BLOCKED;
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx_inline.h b/drivers/scsi/aic7xxx/aic7xxx_inline.h
--- a/drivers/scsi/aic7xxx/aic7xxx_inline.h	Mon Dec 23 21:22:02 2002
+++ b/drivers/scsi/aic7xxx/aic7xxx_inline.h	Mon Dec 23 21:22:02 2002
@@ -37,9 +37,9 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $Id: //depot/aic7xxx/aic7xxx/aic7xxx_inline.h#31 $
+ * $Id: //depot/aic7xxx/aic7xxx/aic7xxx_inline.h#39 $
  *
- * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx_inline.h,v 1.8 2000/11/12 05:19:46 gibbs Exp $
+ * $FreeBSD$
  */
 
 #ifndef _AIC7XXX_INLINE_H_
@@ -231,12 +231,25 @@
 
 /*********************** Miscelaneous Support Functions ***********************/
 
-static __inline void	ahc_update_residual(struct scb *scb);
+static __inline void	ahc_update_residual(struct ahc_softc *ahc,
+					    struct scb *scb);
 static __inline struct ahc_initiator_tinfo *
 			ahc_fetch_transinfo(struct ahc_softc *ahc,
 					    char channel, u_int our_id,
 					    u_int remote_id,
 					    struct ahc_tmode_tstate **tstate);
+static __inline uint16_t
+			ahc_inw(struct ahc_softc *ahc, u_int port);
+static __inline void	ahc_outw(struct ahc_softc *ahc, u_int port,
+				 u_int value);
+static __inline uint32_t
+			ahc_inl(struct ahc_softc *ahc, u_int port);
+static __inline void	ahc_outl(struct ahc_softc *ahc, u_int port,
+				 uint32_t value);
+static __inline uint64_t
+			ahc_inq(struct ahc_softc *ahc, u_int port);
+static __inline void	ahc_outq(struct ahc_softc *ahc, u_int port,
+				 uint64_t value);
 static __inline struct scb*
 			ahc_get_scb(struct ahc_softc *ahc);
 static __inline void	ahc_free_scb(struct ahc_softc *ahc, struct scb *scb);
@@ -255,13 +268,13 @@
  * for this SCB/transaction.
  */
 static __inline void
-ahc_update_residual(struct scb *scb)
+ahc_update_residual(struct ahc_softc *ahc, struct scb *scb)
 {
 	uint32_t sgptr;
 
 	sgptr = ahc_le32toh(scb->hscb->sgptr);
 	if ((sgptr & SG_RESID_VALID) != 0)
-		ahc_calc_residual(scb);
+		ahc_calc_residual(ahc, scb);
 }
 
 /*
@@ -284,6 +297,63 @@
 	return (&(*tstate)->transinfo[remote_id]);
 }
 
+static __inline uint16_t
+ahc_inw(struct ahc_softc *ahc, u_int port)
+{
+	return ((ahc_inb(ahc, port+1) << 8) | ahc_inb(ahc, port));
+}
+
+static __inline void
+ahc_outw(struct ahc_softc *ahc, u_int port, u_int value)
+{
+	ahc_outb(ahc, port, value & 0xFF);
+	ahc_outb(ahc, port+1, (value >> 8) & 0xFF);
+}
+
+static __inline uint32_t
+ahc_inl(struct ahc_softc *ahc, u_int port)
+{
+	return ((ahc_inb(ahc, port))
+	      | (ahc_inb(ahc, port+1) << 8)
+	      | (ahc_inb(ahc, port+2) << 16)
+	      | (ahc_inb(ahc, port+3) << 24));
+}
+
+static __inline void
+ahc_outl(struct ahc_softc *ahc, u_int port, uint32_t value)
+{
+	ahc_outb(ahc, port, (value) & 0xFF);
+	ahc_outb(ahc, port+1, ((value) >> 8) & 0xFF);
+	ahc_outb(ahc, port+2, ((value) >> 16) & 0xFF);
+	ahc_outb(ahc, port+3, ((value) >> 24) & 0xFF);
+}
+
+static __inline uint64_t
+ahc_inq(struct ahc_softc *ahc, u_int port)
+{
+	return ((ahc_inb(ahc, port))
+	      | (ahc_inb(ahc, port+1) << 8)
+	      | (ahc_inb(ahc, port+2) << 16)
+	      | (ahc_inb(ahc, port+3) << 24)
+	      | (((uint64_t)ahc_inb(ahc, port+4)) << 32)
+	      | (((uint64_t)ahc_inb(ahc, port+5)) << 40)
+	      | (((uint64_t)ahc_inb(ahc, port+6)) << 48)
+	      | (((uint64_t)ahc_inb(ahc, port+7)) << 56));
+}
+
+static __inline void
+ahc_outq(struct ahc_softc *ahc, u_int port, uint64_t value)
+{
+	ahc_outb(ahc, port, value & 0xFF);
+	ahc_outb(ahc, port+1, (value >> 8) & 0xFF);
+	ahc_outb(ahc, port+2, (value >> 16) & 0xFF);
+	ahc_outb(ahc, port+3, (value >> 24) & 0xFF);
+	ahc_outb(ahc, port+4, (value >> 32) & 0xFF);
+	ahc_outb(ahc, port+5, (value >> 40) & 0xFF);
+	ahc_outb(ahc, port+6, (value >> 48) & 0xFF);
+	ahc_outb(ahc, port+7, (value >> 56) & 0xFF);
+}
+
 /*
  * Get a free scb. If there are none, see if we can allocate a new SCB.
  */
@@ -357,8 +427,8 @@
 	memcpy(q_hscb, scb->hscb, sizeof(*scb->hscb));
 	if ((scb->flags & SCB_CDB32_PTR) != 0) {
 		q_hscb->shared_data.cdb_ptr =
-		    ahc_hscb_busaddr(ahc, q_hscb->tag)
-		  + offsetof(struct hardware_scb, cdb32);	
+		    ahc_htole32(ahc_hscb_busaddr(ahc, q_hscb->tag)
+			      + offsetof(struct hardware_scb, cdb32));
 	}
 	q_hscb->tag = saved_tag;
 	q_hscb->next = scb->hscb->tag;
@@ -471,7 +541,8 @@
 	if (ahc->qoutfifo[ahc->qoutfifonext] != SCB_LIST_NULL)
 		retval |= AHC_RUN_QOUTFIFO;
 #ifdef AHC_TARGET_MODE
-	if ((ahc->flags & AHC_TARGETROLE) != 0) {
+	if ((ahc->flags & AHC_TARGETROLE) != 0
+	 && (ahc->flags & AHC_TQINFIFO_BLOCKED) == 0) {
 		ahc_dmamap_sync(ahc, ahc->shared_data_dmat,
 				ahc->shared_data_dmamap,
 				ahc_targetcmd_offset(ahc, ahc->tqinfifofnext),
@@ -492,6 +563,15 @@
 {
 	u_int	intstat;
 
+	if ((ahc->pause & INTEN) == 0) {
+		/*
+		 * Our interrupt is not enabled on the chip
+		 * and may be disabled for re-entrancy reasons,
+		 * so just return.  This is likely just a shared
+		 * interrupt.
+		 */
+		return;
+	}
 	/*
 	 * Instead of directly reading the interrupt status register,
 	 * infer the cause of the interrupt by checking our in-core
@@ -517,10 +597,7 @@
 		 * and asserted the interrupt again.
 		 */
 		ahc_flush_device_writes(ahc);
-#ifdef AHC_TARGET_MODE
-		if ((ahc->flags & AHC_INITIATORROLE) != 0)
-#endif
-			ahc_run_qoutfifo(ahc);
+		ahc_run_qoutfifo(ahc);
 #ifdef AHC_TARGET_MODE
 		if ((ahc->flags & AHC_TARGETROLE) != 0)
 			ahc_run_tqinfifo(ahc, /*paused*/FALSE);
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx_linux.c b/drivers/scsi/aic7xxx/aic7xxx_linux.c
--- a/drivers/scsi/aic7xxx/aic7xxx_linux.c	Mon Dec 23 21:21:53 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,2827 +0,0 @@
-/*
- * Adaptec AIC7xxx device driver for Linux.
- *
- * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_linux.c#79 $
- *
- * Copyright (c) 1994 John Aycock
- *   The University of Calgary Department of Computer Science.
- *
- * 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, 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; see the file COPYING.  If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * Sources include the Adaptec 1740 driver (aha1740.c), the Ultrastor 24F
- * driver (ultrastor.c), various Linux kernel source, the Adaptec EISA
- * config file (!adp7771.cfg), the Adaptec AHA-2740A Series User's Guide,
- * the Linux Kernel Hacker's Guide, Writing a SCSI Device Driver for Linux,
- * the Adaptec 1542 driver (aha1542.c), the Adaptec EISA overlay file
- * (adp7770.ovl), the Adaptec AHA-2740 Series Technical Reference Manual,
- * the Adaptec AIC-7770 Data Book, the ANSI SCSI specification, the
- * ANSI SCSI-2 specification (draft 10c), ...
- *
- * --------------------------------------------------------------------------
- *
- *  Modifications by Daniel M. Eischen (deischen@iworks.InterWorks.org):
- *
- *  Substantially modified to include support for wide and twin bus
- *  adapters, DMAing of SCBs, tagged queueing, IRQ sharing, bug fixes,
- *  SCB paging, and other rework of the code.
- *
- * --------------------------------------------------------------------------
- * Copyright (c) 1994-2000 Justin T. Gibbs.
- * Copyright (c) 2000-2001 Adaptec Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- *---------------------------------------------------------------------------
- *
- *  Thanks also go to (in alphabetical order) the following:
- *
- *    Rory Bolt     - Sequencer bug fixes
- *    Jay Estabrook - Initial DEC Alpha support
- *    Doug Ledford  - Much needed abort/reset bug fixes
- *    Kai Makisara  - DMAing of SCBs
- *
- *  A Boot time option was also added for not resetting the scsi bus.
- *
- *    Form:  aic7xxx=extended
- *           aic7xxx=no_reset
- *           aic7xxx=verbose
- *
- *  Daniel M. Eischen, deischen@iworks.InterWorks.org, 1/23/97
- *
- *  Id: aic7xxx.c,v 4.1 1997/06/12 08:23:42 deang Exp
- */
-
-/*
- * Further driver modifications made by Doug Ledford <dledford@redhat.com>
- *
- * Copyright (c) 1997-1999 Doug Ledford
- *
- * These changes are released under the same licensing terms as the FreeBSD
- * driver written by Justin Gibbs.  Please see his Copyright notice above
- * for the exact terms and conditions covering my changes as well as the
- * warranty statement.
- *
- * Modifications made to the aic7xxx.c,v 4.1 driver from Dan Eischen include
- * but are not limited to:
- *
- *  1: Import of the latest FreeBSD sequencer code for this driver
- *  2: Modification of kernel code to accomodate different sequencer semantics
- *  3: Extensive changes throughout kernel portion of driver to improve
- *     abort/reset processing and error hanndling
- *  4: Other work contributed by various people on the Internet
- *  5: Changes to printk information and verbosity selection code
- *  6: General reliability related changes, especially in IRQ management
- *  7: Modifications to the default probe/attach order for supported cards
- *  8: SMP friendliness has been improved
- *
- */
-
-#include "aic7xxx_osm.h"
-#include "aic7xxx_inline.h"
-
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
-#include <linux/init.h>		/* __setup */
-#endif
-
-#include <linux/mm.h>		/* For fetching system memory size */
-#include <linux/blk.h>
-#include <scsi/scsicam.h>
-
-/*
- * To generate the correct addresses for the controller to issue
- * on the bus.  Originally added for DEC Alpha support.
- */
-#define VIRT_TO_BUS(a) (uint32_t)virt_to_bus((void *)(a))
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
-struct proc_dir_entry proc_scsi_aic7xxx = {
-	PROC_SCSI_AIC7XXX, 7, "aic7xxx",
-	S_IFDIR | S_IRUGO | S_IXUGO, 2,
-	0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL
-};
-#endif
-
-/*
- * Set this to the delay in seconds after SCSI bus reset.
- * Note, we honor this only for the initial bus reset.
- * The scsi error recovery code performs its own bus settle
- * delay handling for error recovery actions.
- */
-#ifdef CONFIG_AIC7XXX_RESET_DELAY_MS
-#define AIC7XXX_RESET_DELAY CONFIG_AIC7XXX_RESET_DELAY_MS
-#else
-#define AIC7XXX_RESET_DELAY 5000
-#endif
-
-/*
- * Control collection of SCSI transfer statistics for the /proc filesystem.
- *
- * NOTE: Do NOT enable this when running on kernels version 1.2.x and below.
- * NOTE: This does affect performance since it has to maintain statistics.
- */
-#ifdef CONFIG_AIC7XXX_PROC_STATS
-#define AIC7XXX_PROC_STATS
-#endif
-
-/*
- * To change the default number of tagged transactions allowed per-device,
- * add a line to the lilo.conf file like:
- * append="aic7xxx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}"
- * which will result in the first four devices on the first two
- * controllers being set to a tagged queue depth of 32.
- *
- * The tag_commands is an array of 16 to allow for wide and twin adapters.
- * Twin adapters will use indexes 0-7 for channel 0, and indexes 8-15
- * for channel 1.
- */
-typedef struct {
-	uint8_t tag_commands[16];	/* Allow for wide/twin adapters. */
-} adapter_tag_info_t;
-
-/*
- * Modify this as you see fit for your system.
- *
- * 0			tagged queuing disabled
- * 1 <= n <= 253	n == max tags ever dispatched.
- *
- * The driver will throttle the number of commands dispatched to a
- * device if it returns queue full.  For devices with a fixed maximum
- * queue depth, the driver will eventually determine this depth and
- * lock it in (a console message is printed to indicate that a lock
- * has occurred).  On some devices, queue full is returned for a temporary
- * resource shortage.  These devices will return queue full at varying
- * depths.  The driver will throttle back when the queue fulls occur and
- * attempt to slowly increase the depth over time as the device recovers
- * from the resource shortage.
- *
- * In this example, the first line will disable tagged queueing for all
- * the devices on the first probed aic7xxx adapter.
- *
- * The second line enables tagged queueing with 4 commands/LUN for IDs
- * (0, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
- * driver to attempt to use up to 64 tags for ID 1.
- *
- * The third line is the same as the first line.
- *
- * The fourth line disables tagged queueing for devices 0 and 3.  It
- * enables tagged queueing for the other IDs, with 16 commands/LUN
- * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
- * IDs 2, 5-7, and 9-15.
- */
-
-/*
- * NOTE: The below structure is for reference only, the actual structure
- *       to modify in order to change things is just below this comment block.
-adapter_tag_info_t aic7xxx_tag_info[] =
-{
-	{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
-	{{4, 64, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4}},
-	{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
-	{{0, 16, 4, 0, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
-};
-*/
-
-#ifdef CONFIG_AIC7XXX_CMDS_PER_DEVICE
-#define AIC7XXX_CMDS_PER_DEVICE CONFIG_AIC7XXX_CMDS_PER_DEVICE
-#else
-#define AIC7XXX_CMDS_PER_DEVICE AHC_MAX_QUEUE
-#endif
-
-#define AIC7XXX_CONFIGED_TAG_COMMANDS {					\
-	AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE,		\
-	AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE,		\
-	AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE,		\
-	AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE,		\
-	AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE,		\
-	AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE,		\
-	AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE,		\
-	AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE		\
-}
-
-/*
- * By default, use the number of commands specified by
- * the users kernel configuration.
- */
-static adapter_tag_info_t aic7xxx_tag_info[] =
-{
-	{AIC7XXX_CONFIGED_TAG_COMMANDS},
-	{AIC7XXX_CONFIGED_TAG_COMMANDS},
-	{AIC7XXX_CONFIGED_TAG_COMMANDS},
-	{AIC7XXX_CONFIGED_TAG_COMMANDS},
-	{AIC7XXX_CONFIGED_TAG_COMMANDS},
-	{AIC7XXX_CONFIGED_TAG_COMMANDS},
-	{AIC7XXX_CONFIGED_TAG_COMMANDS},
-	{AIC7XXX_CONFIGED_TAG_COMMANDS},
-	{AIC7XXX_CONFIGED_TAG_COMMANDS},
-	{AIC7XXX_CONFIGED_TAG_COMMANDS},
-	{AIC7XXX_CONFIGED_TAG_COMMANDS},
-	{AIC7XXX_CONFIGED_TAG_COMMANDS},
-	{AIC7XXX_CONFIGED_TAG_COMMANDS},
-	{AIC7XXX_CONFIGED_TAG_COMMANDS},
-	{AIC7XXX_CONFIGED_TAG_COMMANDS},
-	{AIC7XXX_CONFIGED_TAG_COMMANDS}
-};
-
-/*
- * There should be a specific return value for this in scsi.h, but
- * it seems that most drivers ignore it.
- */
-#define DID_UNDERFLOW   DID_ERROR
-
-void
-ahc_print_path(struct ahc_softc *ahc, struct scb *scb)
-{
-	printk("(scsi%d:%c:%d:%d): ",
-	       ahc->platform_data->host->host_no,
-	       scb != NULL ? SCB_GET_CHANNEL(ahc, scb) : 'X',
-	       scb != NULL ? SCB_GET_TARGET(ahc, scb) : -1,
-	       scb != NULL ? SCB_GET_LUN(scb) : -1);
-}
-
-/*
- * XXX - these options apply unilaterally to _all_ 274x/284x/294x
- *       cards in the system.  This should be fixed.  Exceptions to this
- *       rule are noted in the comments.
- */
-
-/*
- * Skip the scsi bus reset.  Non 0 make us skip the reset at startup.  This
- * has no effect on any later resets that might occur due to things like
- * SCSI bus timeouts.
- */
-static uint32_t aic7xxx_no_reset;
-
-/*
- * Certain PCI motherboards will scan PCI devices from highest to lowest,
- * others scan from lowest to highest, and they tend to do all kinds of
- * strange things when they come into contact with PCI bridge chips.  The
- * net result of all this is that the PCI card that is actually used to boot
- * the machine is very hard to detect.  Most motherboards go from lowest
- * PCI slot number to highest, and the first SCSI controller found is the
- * one you boot from.  The only exceptions to this are when a controller
- * has its BIOS disabled.  So, we by default sort all of our SCSI controllers
- * from lowest PCI slot number to highest PCI slot number.  We also force
- * all controllers with their BIOS disabled to the end of the list.  This
- * works on *almost* all computers.  Where it doesn't work, we have this
- * option.  Setting this option to non-0 will reverse the order of the sort
- * to highest first, then lowest, but will still leave cards with their BIOS
- * disabled at the very end.  That should fix everyone up unless there are
- * really strange cirumstances.
- */
-static int aic7xxx_reverse_scan = 0;
-
-/*
- * Should we force EXTENDED translation on a controller.
- *     0 == Use whatever is in the SEEPROM or default to off
- *     1 == Use whatever is in the SEEPROM or default to on
- */
-static uint32_t aic7xxx_extended = 0;
-
-/*
- * PCI bus parity checking of the Adaptec controllers.  This is somewhat
- * dubious at best.  To my knowledge, this option has never actually
- * solved a PCI parity problem, but on certain machines with broken PCI
- * chipset configurations, it can generate tons of false error messages.
- * It's included in the driver for completeness.
- *   0 = Shut off PCI parity check
- *  -1 = Normal polarity pci parity checking
- *   1 = reverse polarity pci parity checking
- *
- * NOTE: you can't actually pass -1 on the lilo prompt.  So, to set this
- * variable to -1 you would actually want to simply pass the variable
- * name without a number.  That will invert the 0 which will result in
- * -1.
- */
-static int aic7xxx_pci_parity = 0;
-
-/*
- * Certain newer motherboards have put new PCI based devices into the
- * IO spaces that used to typically be occupied by VLB or EISA cards.
- * This overlap can cause these newer motherboards to lock up when scanned
- * for older EISA and VLB devices.  Setting this option to non-0 will
- * cause the driver to skip scanning for any VLB or EISA controllers and
- * only support the PCI controllers.  NOTE: this means that if the kernel
- * os compiled with PCI support disabled, then setting this to non-0
- * would result in never finding any devices :)
- */
-int aic7xxx_no_probe;
-
-/*
- * aic7xxx_detect() has been run, so register all device arrivals
- * immediately with the system rather than deferring to the sorted
- * attachment performed by aic7xxx_detect().
- */
-int aic7xxx_detect_complete;
-
-/*
- * So that we can set how long each device is given as a selection timeout.
- * The table of values goes like this:
- *   0 - 256ms
- *   1 - 128ms
- *   2 - 64ms
- *   3 - 32ms
- * We default to 256ms because some older devices need a longer time
- * to respond to initial selection.
- */
-static int aic7xxx_seltime = 0x00;
-
-/*
- * Certain devices do not perform any aging on commands.  Should the
- * device be saturated by commands in one portion of the disk, it is
- * possible for transactions on far away sectors to never be serviced.
- * To handle these devices, we can periodically send an ordered tag to
- * force all outstanding transactions to be serviced prior to a new
- * transaction.
- */
-int aic7xxx_periodic_otag;
-
-/*
- * Module information and settable options.
- */
-#ifdef MODULE
-static char *aic7xxx = NULL;
-/*
- * Just in case someone uses commas to separate items on the insmod
- * command line, we define a dummy buffer here to avoid having insmod
- * write wild stuff into our code segment
- */
-static char dummy_buffer[60] = "Please don't trounce on me insmod!!\n";
-
-MODULE_AUTHOR("Maintainer: Justin T. Gibbs <gibbs@scsiguy.com>");
-MODULE_DESCRIPTION("Adaptec Aic77XX/78XX SCSI Host Bus Adapter driver");
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,10)
-MODULE_LICENSE("Dual BSD/GPL");
-#endif
-MODULE_PARM(aic7xxx, "s");
-MODULE_PARM_DESC(aic7xxx, "period delimited, options string.\n" \
-"	verbose			Enable verbose/diagnostic logging\n" \
-"	no_probe		Disable EISA/VLB controller probing\n" \
-"	no_reset		Supress initial bus resets\n" \
-"	extended		Enable extended geometry on all controllers\n" \
-"	periodic_otag		Send an ordered tagged transaction periodically\n" \
-"				to prevent tag starvation.  This may be\n" \
-"				required by some older disk drives/RAID arrays. \n" \
-"	reverse_scan		Sort PCI devices highest Bus/Slot to lowest\n" \
-"	tag_info:<tag_str>	Set per-target tag depth\n" \
-"	seltime:<int>		Selection Timeout(0/256ms,1/128ms,2/64ms,3/32ms)\n" \
-"\n" \
-"	Sample /etc/modules.conf line:\n" \
-"		Enable verbose logging\n" \
-"		Disable EISA/VLB probing\n" \
-"		Set tag depth on Controller 2/Target 2 to 10 tags\n" \
-"		Shorten the selection timeout to 128ms from its default of 256\n" \
-" \n" \
-"	options aic7xxx='\"verbose.no_probe.tag_info:{{}.{}.{..10}}.seltime:1\"'\n"
-);
-#endif
-
-static void ahc_linux_handle_scsi_status(struct ahc_softc *,
-					 struct ahc_linux_device *,
-					 struct scb *);
-static void ahc_linux_filter_command(struct ahc_softc*, Scsi_Cmnd*,
-				     struct scb*);
-static void ahc_linux_sem_timeout(u_long arg);
-static void ahc_linux_freeze_sim_queue(struct ahc_softc *ahc);
-static void ahc_linux_release_sim_queue(u_long arg);
-static int  ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag);
-static void ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc);
-static int  ahc_linux_slave_configure(Scsi_Device *device);
-static void ahc_linux_device_queue_depth(struct ahc_softc *ahc,
-					 Scsi_Device *device);
-static struct ahc_linux_target*	ahc_linux_alloc_target(struct ahc_softc*,
-						       u_int, u_int);
-static void			ahc_linux_free_target(struct ahc_softc*,
-						      struct ahc_linux_target*);
-static struct ahc_linux_device*	ahc_linux_alloc_device(struct ahc_softc*,
-						       struct ahc_linux_target*,
-						       u_int);
-static void			ahc_linux_free_device(struct ahc_softc*,
-						      struct ahc_linux_device*);
-static void ahc_linux_run_device_queue(struct ahc_softc*,
-				       struct ahc_linux_device*);
-static void ahc_linux_setup_tag_info(char *p, char *end, char *s);
-static int ahc_linux_next_unit(void);
-static int ahc_linux_halt(struct notifier_block *nb, u_long event, void *buf);
-
-static __inline struct ahc_linux_device*
-		     ahc_linux_get_device(struct ahc_softc *ahc, u_int channel,
-					  u_int target, u_int lun, int alloc);
-static __inline void ahc_linux_queue_cmd_complete(struct ahc_softc *ahc,
-						  Scsi_Cmnd *cmd);
-static __inline void ahc_linux_run_complete_queue(struct ahc_softc *ahc,
-						  struct ahc_cmd *acmd);
-static __inline void ahc_linux_check_device_queue(struct ahc_softc *ahc,
-						  struct ahc_linux_device *dev);
-static __inline void ahc_linux_sniff_command(struct ahc_softc*, Scsi_Cmnd*,
-					     struct scb*);
-static __inline void ahc_linux_unmap_scb(struct ahc_softc*, struct scb*);
-
-static __inline int ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb,
-		 		      struct ahc_dma_seg *sg,
-				      bus_addr_t addr, bus_size_t len);
-
-static __inline struct ahc_linux_device*
-ahc_linux_get_device(struct ahc_softc *ahc, u_int channel, u_int target,
-	       u_int lun, int alloc)
-{
-	struct ahc_linux_target *targ;
-	struct ahc_linux_device *dev;
-	u_int target_offset;
-
-	target_offset = target;
-	if (channel != 0)
-		target_offset += 8;
-	targ = ahc->platform_data->targets[target_offset];
-	if (targ == NULL) {
-		if (alloc != 0) {
-			targ = ahc_linux_alloc_target(ahc, channel, target);
-			if (targ == NULL)
-				return (NULL);
-		} else
-			return (NULL);
-	}
-	dev = targ->devices[lun];
-	if (dev == NULL && alloc != 0)
-		dev = ahc_linux_alloc_device(ahc, targ, lun);
-	return (dev);
-}
-
-static __inline void
-ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, Scsi_Cmnd *cmd)
-{
-	/*
-	 * Typically, the complete queue has very few entries
-	 * queued to it before the queue is emptied by
-	 * ahc_linux_run_complete_queue, so sorting the entries
-	 * by generation number should be inexpensive.
-	 * We perform the sort so that commands that complete
-	 * with an error are retuned in the order origionally
-	 * queued to the controller so that any subsequent retries
-	 * are performed in order.  The underlying ahc routines do
-	 * not guarantee the order that aborted commands will be
-	 * returned to us.
-	 */
-	struct ahc_completeq *completeq;
-	struct ahc_cmd *list_cmd;
-	struct ahc_cmd *acmd;
-
-	/*
-	 * If we want the request requeued, make sure there
-	 * are sufficent retries.  In the old scsi error code,
-	 * we used to be able to specify a result code that
-	 * bypassed the retry count.  Now we must use this
-	 * hack.
-	 */
-	if (cmd->result == (CAM_REQUEUE_REQ << 16))
-		cmd->retries--;
-	completeq = &ahc->platform_data->completeq;
-	list_cmd = TAILQ_FIRST(completeq);
-	acmd = (struct ahc_cmd *)cmd;
-	while (list_cmd != NULL
-	    && acmd_scsi_cmd(list_cmd).serial_number
-	     < acmd_scsi_cmd(acmd).serial_number)
-		list_cmd = TAILQ_NEXT(list_cmd, acmd_links.tqe);
-	if (list_cmd != NULL)
-		TAILQ_INSERT_BEFORE(list_cmd, acmd, acmd_links.tqe);
-	else
-		TAILQ_INSERT_TAIL(completeq, acmd, acmd_links.tqe);
-}
-
-static __inline void
-ahc_linux_run_complete_queue(struct ahc_softc *ahc, struct ahc_cmd *acmd)
-{	
-	u_long done_flags;
-
-	ahc_done_lock(ahc, &done_flags);
-	while (acmd != NULL) {
-		Scsi_Cmnd *cmd;
-
-		cmd = &acmd_scsi_cmd(acmd);
-		acmd = TAILQ_NEXT(acmd, acmd_links.tqe);
-		cmd->host_scribble = NULL;
-		cmd->scsi_done(cmd);
-	}
-	ahc_done_unlock(ahc, &done_flags);
-}
-
-static __inline void
-ahc_linux_check_device_queue(struct ahc_softc *ahc,
-			     struct ahc_linux_device *dev)
-{
-	if ((dev->flags & AHC_DEV_FREEZE_TIL_EMPTY) != 0
-	 && dev->active == 0) {
-		dev->flags &= ~AHC_DEV_FREEZE_TIL_EMPTY;
-		dev->qfrozen--;
-	}
-
-	if (TAILQ_FIRST(&dev->busyq) == NULL
-	 || dev->openings == 0 || dev->qfrozen != 0)
-		return;
-
-	ahc_linux_run_device_queue(ahc, dev);
-}
-
-static __inline void
-ahc_linux_run_device_queues(struct ahc_softc *ahc)
-{
-	struct ahc_linux_device *dev;
-
-	while ((ahc->flags & AHC_RESOURCE_SHORTAGE) == 0
-	    && ahc->platform_data->qfrozen == 0
-	    && (dev = TAILQ_FIRST(&ahc->platform_data->device_runq)) != NULL) {
-		TAILQ_REMOVE(&ahc->platform_data->device_runq, dev, links);
-		dev->flags &= ~AHC_DEV_ON_RUN_LIST;
-		ahc_linux_check_device_queue(ahc, dev);
-	}
-}
-
-static __inline void
-ahc_linux_sniff_command(struct ahc_softc *ahc, Scsi_Cmnd *cmd, struct scb *scb)
-{
-	/*
-	 * Determine whether we care to filter
-	 * information out of this command.  If so,
-	 * pass it on to ahc_linux_filter_command() for more
-	 * heavy weight processing.
-	 */
-	if (cmd->cmnd[0] == INQUIRY)
-		ahc_linux_filter_command(ahc, cmd, scb);
-}
-
-static __inline void
-ahc_linux_unmap_scb(struct ahc_softc *ahc, struct scb *scb)
-{
-	Scsi_Cmnd *cmd;
-
-	cmd = scb->io_ctx;
-	ahc_sync_sglist(ahc, scb, BUS_DMASYNC_POSTWRITE);
-	if (cmd->use_sg != 0) {
-		struct scatterlist *sg;
-
-		sg = (struct scatterlist *)cmd->request_buffer;
-		pci_unmap_sg(ahc->dev_softc, sg, cmd->use_sg,
-			     scsi_to_pci_dma_dir(cmd->sc_data_direction));
-	} else if (cmd->request_bufflen != 0) {
-		u_int32_t high_addr;
-
-		high_addr = ahc_le32toh(scb->sg_list[0].len)
-			  & AHC_SG_HIGH_ADDR_MASK;
-		pci_unmap_single(ahc->dev_softc,
-				 ahc_le32toh(scb->sg_list[0].addr)
-			        | (((dma_addr_t)high_addr) << 8),
-				 cmd->request_bufflen,
-				 scsi_to_pci_dma_dir(cmd->sc_data_direction));
-	}
-}
-
-static __inline int
-ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb,
-		  struct ahc_dma_seg *sg, bus_addr_t addr, bus_size_t len)
-{
-	int	 consumed;
-
-	if ((scb->sg_count + 1) > AHC_NSEG)
-		panic("Too few segs for dma mapping.  "
-		      "Increase AHC_NSEG\n");
-
-	consumed = 1;
-	sg->addr = ahc_htole32(addr & 0xFFFFFFFF);
-	scb->platform_data->xfer_len += len;
-	if (sizeof(bus_addr_t) > 4
-	 && (ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
-		/*
-		 * Due to DAC restrictions, we can't
-		 * cross a 4GB boundary.
-		 */
-		if ((addr ^ (addr + len - 1)) & ~0xFFFFFFFF) {
-			struct	 ahc_dma_seg *next_sg;
-			uint32_t next_len;
-
-			printf("Crossed Seg\n");
-			if ((scb->sg_count + 2) > AHC_NSEG)
-				panic("Too few segs for dma mapping.  "
-				      "Increase AHC_NSEG\n");
-
-			consumed++;
-			next_sg = sg + 1;
-			next_sg->addr = 0;
-			next_len = 0x100000000 - (addr & 0xFFFFFFFF);
-			len -= next_len;
-			next_len |= ((addr >> 8) + 0x1000000) & 0x7F000000;
-			next_sg->len = ahc_htole32(next_len);
-		}
-		len |= (addr >> 8) & 0x7F000000;
-	}
-	sg->len = ahc_htole32(len);
-	return (consumed);
-}
-
-/************************ Shutdown/halt/reboot hook ***************************/
-#include <linux/notifier.h>
-#include <linux/reboot.h>
-
-static struct notifier_block ahc_linux_notifier = {
-	ahc_linux_halt, NULL, 0
-};
-
-static int ahc_linux_halt(struct notifier_block *nb, u_long event, void *buf)
-{
-	struct ahc_softc *ahc;
-
-	if (event == SYS_DOWN || event == SYS_HALT) {
-		TAILQ_FOREACH(ahc, &ahc_tailq, links) {
-			ahc_shutdown(ahc);
-		}
-	}
-	return (NOTIFY_OK);
-}
-
-/******************************** Macros **************************************/
-#define BUILD_SCSIID(ahc, cmd)						\
-	((((cmd)->target << TID_SHIFT) & TID)				\
-	| (((cmd)->channel == 0) ? (ahc)->our_id : (ahc)->our_id_b)	\
-	| (((cmd)->channel == 0) ? 0 : TWIN_CHNLB))
-
-/******************************** Bus DMA *************************************/
-int
-ahc_dma_tag_create(struct ahc_softc *ahc, bus_dma_tag_t parent,
-		   bus_size_t alignment, bus_size_t boundary,
-		   bus_addr_t lowaddr, bus_addr_t highaddr,
-		   bus_dma_filter_t *filter, void *filterarg,
-		   bus_size_t maxsize, int nsegments,
-		   bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
-{
-	bus_dma_tag_t dmat;
-
-	dmat = malloc(sizeof(*dmat), M_DEVBUF, M_NOWAIT);
-	if (dmat == NULL)
-		return (ENOMEM);
-
-	/*
-	 * Linux is very simplistic about DMA memory.  For now don't
-	 * maintain all specification information.  Once Linux supplies
-	 * better facilities for doing these operations, or the
-	 * needs of this particular driver change, we might need to do
-	 * more here.
-	 */
-	dmat->alignment = alignment;
-	dmat->boundary = boundary;
-	dmat->maxsize = maxsize;
-	*ret_tag = dmat;
-	return (0);
-}
-
-void
-ahc_dma_tag_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat)
-{
-	free(dmat, M_DEVBUF);
-}
-
-int
-ahc_dmamem_alloc(struct ahc_softc *ahc, bus_dma_tag_t dmat, void** vaddr,
-		 int flags, bus_dmamap_t *mapp)
-{
-	bus_dmamap_t map;
-
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
-	map = malloc(sizeof(*map), M_DEVBUF, M_NOWAIT);
-	if (map == NULL)
-		return (ENOMEM);
-	/*
-	 * Although we can dma data above 4GB, our
-	 * "consistent" memory is below 4GB for
-	 * space efficiency reasons (only need a 4byte
-	 * address).  For this reason, we have to reset
-	 * our dma mask when doing allocations.
-	 */
-	if(ahc->dev_softc)
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,3)
-		pci_set_dma_mask(ahc->dev_softc, 0xFFFFFFFF);
-#else
-		ahc->dev_softc->dma_mask = 0xFFFFFFFF;
-#endif
-	*vaddr = pci_alloc_consistent(ahc->dev_softc,
-				      dmat->maxsize, &map->bus_addr);
-	if (ahc->dev_softc)
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,3)
-		pci_set_dma_mask(ahc->dev_softc, ahc->platform_data->hw_dma_mask);
-#else
-		ahc->dev_softc->dma_mask = ahc->platform_data->hw_dma_mask;
-#endif
-#else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) */
-	/*
-	 * At least in 2.2.14, malloc is a slab allocator so all
-	 * allocations are aligned.  We assume for these kernel versions
-	 * that all allocations will be bellow 4Gig, physically contiguous,
-	 * and accessable via DMA by the controller.
-	 */
-	map = NULL; /* No additional information to store */
-	*vaddr = malloc(dmat->maxsize, M_DEVBUF, M_NOWAIT);
-#endif
-	if (*vaddr == NULL)
-		return (ENOMEM);
-	*mapp = map;
-	return(0);
-}
-
-void
-ahc_dmamem_free(struct ahc_softc *ahc, bus_dma_tag_t dmat,
-		void* vaddr, bus_dmamap_t map)
-{
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
-	pci_free_consistent(ahc->dev_softc, dmat->maxsize,
-			    vaddr, map->bus_addr);
-#else
-	free(vaddr, M_DEVBUF);
-#endif
-}
-
-int
-ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map,
-		void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
-		void *cb_arg, int flags)
-{
-	/*
-	 * Assume for now that this will only be used during
-	 * initialization and not for per-transaction buffer mapping.
-	 */
-	bus_dma_segment_t stack_sg;
-
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
-	stack_sg.ds_addr = map->bus_addr;
-#else
-	stack_sg.ds_addr = VIRT_TO_BUS(buf);
-#endif
-	stack_sg.ds_len = dmat->maxsize;
-	cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
-	return (0);
-}
-
-void
-ahc_dmamap_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map)
-{
-	/*
-	 * The map may is NULL in our < 2.3.X implementation.
-	 */
-	if (map != NULL)
-		free(map, M_DEVBUF);
-}
-
-int
-ahc_dmamap_unload(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map)
-{
-	/* Nothing to do */
-	return (0);
-}
-
-/********************* Platform Dependent Functions ***************************/
-int
-ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc)
-{
-	int	value;
-	int	rvalue;
-	int	lvalue;
-
-	/*
-	 * Under Linux, cards are ordered as follows:
-	 *	1) VLB/EISA BIOS enabled devices sorted by BIOS address.
-	 *	2) PCI devices with BIOS enabled sorted by bus/slot/func.
-	 *	3) All remaining VLB/EISA devices sorted by ioport.
-	 *	4) All remaining PCI devices sorted by bus/slot/func.
-	 */
-	value = (lahc->flags & AHC_BIOS_ENABLED)
-	      - (rahc->flags & AHC_BIOS_ENABLED);
-	if (value != 0)
-		/* Controllers with BIOS enabled have a *higher* priority */
-		return (-value);
-
-	/*
-	 * Same BIOS setting, now sort based on bus type.
-	 * EISA and VL controllers sort together.  EISA/VL
-	 * have higher priority than PCI.
-	 */
-	rvalue = (rahc->chip & AHC_BUS_MASK);
- 	if (rvalue == AHC_VL)
-		rvalue = AHC_EISA;
-	lvalue = (lahc->chip & AHC_BUS_MASK);
- 	if (lvalue == AHC_VL)
-		lvalue = AHC_EISA;
-	value = lvalue - rvalue;
-	if (value != 0)
-		return (value);
-
-	/* Still equal.  Sort by BIOS address, ioport, or bus/slot/func. */
-	switch (rvalue) {
-	case AHC_PCI:
-	{
-		char primary_channel;
-
-		if (aic7xxx_reverse_scan != 0)
-			value = ahc_get_pci_bus(rahc->dev_softc)
-			      - ahc_get_pci_bus(lahc->dev_softc);
-		else
-			value = ahc_get_pci_bus(lahc->dev_softc)
-			      - ahc_get_pci_bus(rahc->dev_softc);
-		if (value != 0)
-			break;
-		if (aic7xxx_reverse_scan != 0)
-			value = ahc_get_pci_slot(rahc->dev_softc)
-			      - ahc_get_pci_slot(lahc->dev_softc);
-		else
-			value = ahc_get_pci_slot(lahc->dev_softc)
-			      - ahc_get_pci_slot(rahc->dev_softc);
-		if (value != 0)
-			break;
-		/*
-		 * On multi-function devices, the user can choose
-		 * to have function 1 probed before function 0.
-		 * Give whichever channel is the primary channel
-		 * the lowest priority.
-		 */
-		primary_channel = (lahc->flags & AHC_PRIMARY_CHANNEL) + 'A';
-		value = 1;
-		if (lahc->channel == primary_channel)
-			value = -1;
-		break;
-	}
-	case AHC_EISA:
-		if ((rahc->flags & AHC_BIOS_ENABLED) != 0) {
-			value = lahc->platform_data->bios_address
-			      - rahc->platform_data->bios_address; 
-		} else {
-			value = lahc->bsh.ioport
-			      - rahc->bsh.ioport; 
-		}
-		break;
-	default:
-		panic("ahc_softc_sort: invalid bus type");
-	}
-	return (value);
-}
-
-static void
-ahc_linux_setup_tag_info(char *p, char *end, char *s)
-{
-	char	*base;
-	char	*tok;
-	char	*tok_end;
-	char	*tok_end2;
-	int      i;
-	int      instance;
-	int	 targ;
-	int	 done;
-	char	 tok_list[] = {'.', ',', '{', '}', '\0'};
-
-	if (*p != ':')
-		return;
-
-	instance = -1;
-	targ = -1;
-	done = FALSE;
-	base = p;
-	/* Forward us just past the ':' */
-	tok = base + 1;
-	tok_end = strchr(tok, '\0');
-	if (tok_end < end)
-		*tok_end = ',';
-	while (!done) {
-		switch (*tok) {
-		case '{':
-			if (instance == -1)
-				instance = 0;
-			else if (targ == -1)
-				targ = 0;
-			tok++;
-			break;
-		case '}':
-			if (targ != -1)
-				targ = -1;
-			else if (instance != -1)
-				instance = -1;
-			tok++;
-			break;
-		case ',':
-		case '.':
-			if (instance == -1)
-				done = TRUE;
-			else if (targ >= 0)
-				targ++;
-			else if (instance >= 0)
-				instance++;
-			if ((targ >= AHC_NUM_TARGETS) ||
-			    (instance >= NUM_ELEMENTS(aic7xxx_tag_info)))
-				done = TRUE;
-			tok++;
-			if (!done) {
-				base = tok;
-			}
-			break;
-		case '\0':
-			done = TRUE;
-			break;
-		default:
-			done = TRUE;
-			tok_end = strchr(tok, '\0');
-			for (i = 0; tok_list[i]; i++) {
-				tok_end2 = strchr(tok, tok_list[i]);
-				if ((tok_end2) && (tok_end2 < tok_end)) {
-					tok_end = tok_end2;
-					done = FALSE;
-				}
-			}
-			if ((instance >= 0) && (targ >= 0)
-			 && (instance < NUM_ELEMENTS(aic7xxx_tag_info))
-			 && (targ < AHC_NUM_TARGETS)) {
-				aic7xxx_tag_info[instance].tag_commands[targ] =
-				    simple_strtoul(tok, NULL, 0) & 0xff;
-			}
-			tok = tok_end;
-			break;
-		}
-	}
-	while ((p != base) && (p != NULL))
-		p = strsep(&s, ",.");
-}
-
-/*
- * Handle Linux boot parameters. This routine allows for assigning a value
- * to a parameter with a ':' between the parameter and the value.
- * ie. aic7xxx=stpwlev:1,extended
- */
-int
-aic7xxx_setup(char *s)
-{
-	int	i, n;
-	char   *p;
-	char   *end;
-
-	static struct {
-		const char *name;
-		uint32_t *flag;
-	} options[] = {
-		{ "extended", &aic7xxx_extended },
-		{ "no_reset", &aic7xxx_no_reset },
-		{ "verbose", &aic7xxx_verbose },
-		{ "reverse_scan", &aic7xxx_reverse_scan },
-		{ "no_probe", &aic7xxx_no_probe },
-		{ "periodic_otag", &aic7xxx_periodic_otag },
-		{ "pci_parity", &aic7xxx_pci_parity },
-		{ "seltime", &aic7xxx_seltime },
-		{ "tag_info", NULL }
-	};
-
-	end = strchr(s, '\0');
-
-	while ((p = strsep(&s, ",.")) != NULL) {
-		if (!*p) continue;
-		for (i = 0; i < NUM_ELEMENTS(options); i++) {
-			n = strlen(options[i].name);
-
-			if (strncmp(options[i].name, p, n) != 0)
-				continue;
-
-			if (strncmp(p, "tag_info", n) == 0) {
-				ahc_linux_setup_tag_info(p + n, end, s);
-			} else if (p[n] == ':') {
-				*(options[i].flag) =
-				    simple_strtoul(p + n + 1, NULL, 0);
-			} else if (!strncmp(p, "verbose", n)) {
-				*(options[i].flag) = 1;
-			} else {
-				*(options[i].flag) = ~(*(options[i].flag));
-			}
-			break;
-		}
-	}
-	register_reboot_notifier(&ahc_linux_notifier);
-	return 1;
-}
-
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0)
-__setup("aic7xxx=", aic7xxx_setup);
-#endif
-
-int aic7xxx_verbose;
-
-/*
- * Try to detect an Adaptec 7XXX controller.
- */
-int
-ahc_linux_detect(Scsi_Host_Template *template)
-{
-	struct	ahc_softc *ahc;
-	int     found;
-
-	/*
-	 * Sanity checking of Linux SCSI data structures so
-	 * that some of our hacks^H^H^H^H^Hassumptions aren't
-	 * violated.
-	 */
-	if (offsetof(struct ahc_cmd_internal, end)
-	  > offsetof(struct scsi_cmnd, host_scribble)) {
-		printf("ahc_linux_detect: SCSI data structures changed.\n");
-		printf("ahc_linux_detect: Unable to attach\n");
-		return (0);
-	}
-#ifdef MODULE
-	/*
-	 * If we've been passed any parameters, process them now.
-	 */
-	if (aic7xxx)
-		aic7xxx_setup(aic7xxx);
-	if (dummy_buffer[0] != 'P')
-		printk(KERN_WARNING
-"aic7xxx: Please read the file /usr/src/linux/Documentation/scsi/aic7xxx.txt\n"
-"aic7xxx: to see the proper way to specify options to the aic7xxx module\n"
-"aic7xxx: Specifically, don't use any commas when passing arguments to\n"
-"aic7xxx: insmod or else it might trash certain memory areas.\n");
-#endif
-
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0)
-	template->proc_name = "aic7xxx";
-#else
-	template->proc_dir = &proc_scsi_aic7xxx;
-#endif
-	template->sg_tablesize = AHC_NSEG;
-
-#ifdef CONFIG_PCI
-	ahc_linux_pci_probe(template);
-#endif
-
-	if (aic7xxx_no_probe == 0)
-		aic7770_linux_probe(template);
-
-	/*
-	 * Register with the SCSI layer all
-	 * controllers we've found.
-	 */
-	found = 0;
-	TAILQ_FOREACH(ahc, &ahc_tailq, links) {
-
-		if (ahc_linux_register_host(ahc, template) == 0)
-			found++;
-	}
-	aic7xxx_detect_complete++;
-	return (found);
-}
-
-int
-ahc_linux_register_host(struct ahc_softc *ahc, Scsi_Host_Template *template)
-{
-	char  buf[80];
-	struct Scsi_Host *host;
-	char *new_name;
-	u_long s;
-
-
-	template->name = ahc->description;
-	host = scsi_register(template, sizeof(struct ahc_softc *));
-	if (host == NULL)
-		return (ENOMEM);
-
-	*((struct ahc_softc **)host->hostdata) = ahc;
-	ahc->platform_data->host = host;
-	ahc_lock(ahc, &s);
-	host->can_queue = AHC_MAX_QUEUE;
-	host->cmd_per_lun = 2;
-	host->sg_tablesize = AHC_NSEG;
-	/* XXX No way to communicate the ID for multiple channels */
-	host->this_id = ahc->our_id;
-	host->irq = ahc->platform_data->irq;
-	host->max_id = (ahc->features & AHC_WIDE) ? 16 : 8;
-	host->max_lun = AHC_NUM_LUNS;
-	host->max_channel = (ahc->features & AHC_TWIN) ? 1 : 0;
-	ahc_set_unit(ahc, ahc_linux_next_unit());
-	sprintf(buf, "scsi%d", host->host_no);
-	new_name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
-	if (new_name != NULL) {
-		strcpy(new_name, buf);
-		ahc_set_name(ahc, new_name);
-	}
-	host->unique_id = ahc->unit;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,4)
-	scsi_set_pci_device(host, ahc->dev_softc);
-#endif
-	ahc_linux_initialize_scsi_bus(ahc);
-	ahc_unlock(ahc, &s);
-	return (0);
-}
-
-uint64_t
-ahc_linux_get_memsize()
-{
-	struct sysinfo si;
-
-	si_meminfo(&si);
-	return (si.totalram << PAGE_SHIFT);
-}
-
-/*
- * Find the smallest available unit number to use
- * for a new device.  We don't just use a static
- * count to handle the "repeated hot-(un)plug"
- * scenario.
- */
-static int
-ahc_linux_next_unit()
-{
-	struct ahc_softc *ahc;
-	int unit;
-
-	unit = 0;
-retry:
-	TAILQ_FOREACH(ahc, &ahc_tailq, links) {
-		if (ahc->unit == unit) {
-			unit++;
-			goto retry;
-		}
-	}
-	return (unit);
-}
-
-/*
- * Place the SCSI bus into a known state by either resetting it,
- * or forcing transfer negotiations on the next command to any
- * target.
- */
-void
-ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc)
-{
-	int i;
-	int numtarg;
-
-	i = 0;
-	numtarg = 0;
-
-	if (aic7xxx_no_reset != 0)
-		ahc->flags &= ~(AHC_RESET_BUS_A|AHC_RESET_BUS_B);
-
-	if ((ahc->flags & AHC_RESET_BUS_A) != 0)
-		ahc_reset_channel(ahc, 'A', /*initiate_reset*/TRUE);
-	else
-		numtarg = (ahc->features & AHC_WIDE) ? 16 : 8;
-
-	if ((ahc->features & AHC_TWIN) != 0) {
-
-		if ((ahc->flags & AHC_RESET_BUS_B) != 0) {
-			ahc_reset_channel(ahc, 'B', /*initiate_reset*/TRUE);
-		} else {
-			if (numtarg == 0)
-				i = 8;
-			numtarg += 8;
-		}
-	}
-
-	for (; i < numtarg; i++) {
-		struct ahc_devinfo devinfo;
-		struct ahc_initiator_tinfo *tinfo;
-		struct ahc_tmode_tstate *tstate;
-		u_int our_id;
-		u_int target_id;
-		char channel;
-
-		channel = 'A';
-		our_id = ahc->our_id;
-		target_id = i;
-		if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
-			channel = 'B';
-			our_id = ahc->our_id_b;
-			target_id = i % 8;
-		}
-		tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
-					    target_id, &tstate);
-		tinfo->goal = tinfo->user;
-		/*
-		 * Don't try negotiations that require PPR messages
-		 * until we successfully retrieve Inquiry data.
-		 */
-		tinfo->goal.ppr_options = 0;
-		if (tinfo->goal.transport_version > SCSI_REV_2)
-			tinfo->goal.transport_version = SCSI_REV_2;
-		ahc_compile_devinfo(&devinfo, our_id, target_id,
-				   CAM_LUN_WILDCARD, channel, ROLE_INITIATOR);
-		ahc_update_neg_request(ahc, &devinfo, tstate,
-				       tinfo, /*force*/FALSE);
-	}
-	/* Give the bus some time to recover */
-	if ((ahc->flags & (AHC_RESET_BUS_A|AHC_RESET_BUS_B)) != 0) {
-		ahc_linux_freeze_sim_queue(ahc);
-		init_timer(&ahc->platform_data->reset_timer);
-		ahc->platform_data->reset_timer.data = (u_long)ahc;
-		ahc->platform_data->reset_timer.expires =
-		    jiffies + (AIC7XXX_RESET_DELAY * HZ)/1000;
-		ahc->platform_data->reset_timer.function =
-		    ahc_linux_release_sim_queue;
-		add_timer(&ahc->platform_data->reset_timer);
-	}
-}
-
-int
-ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg)
-{
-	ahc->platform_data =
-	    malloc(sizeof(struct ahc_platform_data), M_DEVBUF, M_NOWAIT);
-	if (ahc->platform_data == NULL)
-		return (ENOMEM);
-	memset(ahc->platform_data, 0, sizeof(struct ahc_platform_data));
-	TAILQ_INIT(&ahc->platform_data->completeq);
-	TAILQ_INIT(&ahc->platform_data->device_runq);
-	ahc->platform_data->hw_dma_mask = 0xFFFFFFFF;
-	/*
-	 * ahc_lockinit done by scsi_register, as we don't own that lock
-	 */
-	ahc_done_lockinit(ahc);
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
-	init_MUTEX_LOCKED(&ahc->platform_data->eh_sem);
-#else
-	ahc->platform_data->eh_sem = MUTEX_LOCKED;
-#endif
-	ahc->seltime = (aic7xxx_seltime & 0x3) << 4;
-	ahc->seltime_b = (aic7xxx_seltime & 0x3) << 4;
-	return (0);
-}
-
-void
-ahc_platform_free(struct ahc_softc *ahc)
-{
-	if (ahc->platform_data != NULL) {
-		if (ahc->platform_data->host != NULL)
-			scsi_unregister(ahc->platform_data->host);
-		if (ahc->platform_data->irq)
-			free_irq(ahc->platform_data->irq, ahc);
-		if (ahc->tag == BUS_SPACE_PIO
-		 && ahc->bsh.ioport != 0)
-			release_region(ahc->bsh.ioport, 256);
-		if (ahc->tag == BUS_SPACE_MEMIO
-		 && ahc->bsh.maddr != NULL) {
-			u_long base_addr;
-
-			base_addr = (u_long)ahc->bsh.maddr;
-			base_addr &= PAGE_MASK;
-			iounmap((void *)base_addr);
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
-			release_mem_region(ahc->platform_data->mem_busaddr,
-					   0x1000);
-#endif
-		}
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
-		/* XXX Need an instance detach in the PCI code */
-		if (ahc->dev_softc != NULL)
-			ahc->dev_softc->driver = NULL;
-#endif
-		free(ahc->platform_data, M_DEVBUF);
-	}
-}
-
-void
-ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
-{
-	ahc_platform_abort_scbs(ahc, SCB_GET_TARGET(ahc, scb),
-				SCB_GET_CHANNEL(ahc, scb),
-				SCB_GET_LUN(scb), SCB_LIST_NULL,
-				ROLE_UNKNOWN, CAM_REQUEUE_REQ);
-}
-
-void
-ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
-		      ahc_queue_alg alg)
-{
-	struct ahc_linux_device *dev;
-	int was_queuing;
-	int now_queuing;
-
-	dev = ahc_linux_get_device(ahc, devinfo->channel - 'A',
-				   devinfo->target,
-				   devinfo->lun, /*alloc*/FALSE);
-	if (dev == NULL)
-		return;
-	was_queuing = dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED);
-	now_queuing = alg != AHC_QUEUE_NONE;
-	if ((dev->flags & AHC_DEV_FREEZE_TIL_EMPTY) == 0
-	 && (was_queuing != now_queuing)
-	 && (dev->active != 0)) {
-		dev->flags |= AHC_DEV_FREEZE_TIL_EMPTY;
-		dev->qfrozen++;
-	}
-
-	dev->flags &= ~(AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED|AHC_DEV_PERIODIC_OTAG);
-	if (now_queuing) {
-
-		if (!was_queuing) {
-			/*
-			 * Start out agressively and allow our
-			 * dynamic queue depth algorithm to take
-			 * care of the rest.
-			 */
-			dev->maxtags = AHC_MAX_QUEUE;
-			dev->openings = dev->maxtags - dev->active;
-		}
-		if (alg == AHC_QUEUE_TAGGED) {
-			dev->flags |= AHC_DEV_Q_TAGGED;
-			if (aic7xxx_periodic_otag != 0)
-				dev->flags |= AHC_DEV_PERIODIC_OTAG;
-		} else
-			dev->flags |= AHC_DEV_Q_BASIC;
-	} else {
-		/* We can only have one opening */
-		dev->maxtags = 0;
-		dev->openings =  1 - dev->active;
-	}
-}
-
-int
-ahc_platform_abort_scbs(struct ahc_softc *ahc, int target, char channel,
-			int lun, u_int tag, role_t role, uint32_t status)
-{
-	int chan;
-	int maxchan;
-	int targ;
-	int maxtarg;
-	int clun;
-	int maxlun;
-	int count;
-
-	if (tag != SCB_LIST_NULL)
-		return (0);
-
-	chan = 0;
-	if (channel != ALL_CHANNELS) {
-		chan = channel - 'A';
-		maxchan = chan + 1;
-	} else {
-		maxchan = (ahc->features & AHC_TWIN) ? 2 : 1;
-	}
-	targ = 0;
-	if (target != CAM_TARGET_WILDCARD) {
-		targ = target;
-		maxtarg = targ + 1;
-	} else {
-		maxtarg = (ahc->features & AHC_WIDE) ? 16 : 8;
-	}
-	clun = 0;
-	if (lun != CAM_LUN_WILDCARD) {
-		clun = lun;
-		maxlun = clun + 1;
-	} else {
-		maxlun = 16;
-	}
-
-	count = 0;
-	for (; chan < maxchan; chan++) {
-		for (; targ < maxtarg; targ++) {
-			for (; clun < maxlun; clun++) {
-				struct ahc_linux_device *dev;
-				struct ahc_busyq *busyq;
-				struct ahc_cmd *acmd;
-
-				dev = ahc_linux_get_device(ahc, chan,
-							   targ, clun,
-							   /*alloc*/FALSE);
-				if (dev == NULL)
-					continue;
-
-				busyq = &dev->busyq;
-				while ((acmd = TAILQ_FIRST(busyq)) != NULL) {
-					Scsi_Cmnd *cmd;
-
-					cmd = &acmd_scsi_cmd(acmd);
-					TAILQ_REMOVE(busyq, acmd,
-						     acmd_links.tqe);
-					count++;
-					cmd->result = status << 16;
-					ahc_linux_queue_cmd_complete(ahc, cmd);
-				}
-			}
-		}
-	}
-
-	return (count);
-}
-
-/*
- * Sets the queue depth for each SCSI device hanging
- * off the input host adapter.
- */
-static int
-ahc_linux_slave_configure(Scsi_Device * device)
-{
-	struct	ahc_softc *ahc;
-	u_long	flags;
-
-	ahc = *((struct ahc_softc **)device->host->hostdata);
-	ahc_lock(ahc, &flags);
-	ahc_linux_device_queue_depth(ahc, device);
-	ahc_unlock(ahc, &flags);
-	return 0;
-}
-
-/*
- * Determines the queue depth for a given device.
- */
-static void
-ahc_linux_device_queue_depth(struct ahc_softc *ahc, Scsi_Device * device)
-{
-	struct	ahc_devinfo devinfo;
-	struct	ahc_initiator_tinfo *targ_info;
-	struct	ahc_tmode_tstate *tstate;
-	uint8_t tags;
-
-	ahc_compile_devinfo(&devinfo,
-			    device->channel == 0 ? ahc->our_id : ahc->our_id_b,
-			    device->id, device->lun,
-			    device->channel == 0 ? 'A' : 'B',
-			    ROLE_INITIATOR);
-	targ_info = ahc_fetch_transinfo(ahc, devinfo.channel,
-					devinfo.our_scsiid,
-					devinfo.target, &tstate);
-
-	tags = 0;
-	if (device->tagged_supported != 0
-	 && (ahc->user_discenable & devinfo.target_mask) != 0) {
-		if (ahc->unit >= NUM_ELEMENTS(aic7xxx_tag_info)) {
-
-			printf("aic7xxx: WARNING, insufficient "
-			       "tag_info instances for installed "
-			       "controllers. Using defaults\n");
-			printf("aic7xxx: Please update the "
-			       "aic7xxx_tag_info array in the "
-			       "aic7xxx.c source file.\n");
-			tags = AHC_MAX_QUEUE;
-		} else {
-			adapter_tag_info_t *tag_info;
-
-			tag_info = &aic7xxx_tag_info[ahc->unit];
-			tags = tag_info->tag_commands[devinfo.target_offset];
-			if (tags > AHC_MAX_QUEUE)
-				tags = AHC_MAX_QUEUE;
-		}
-	}
-	if (tags != 0) {
-		scsi_adjust_queue_depth(device, MSG_ORDERED_TAG, tags);
-		/* device->queue_depth = tags; */
-		ahc_set_tags(ahc, &devinfo, AHC_QUEUE_TAGGED);
-		printf("scsi%d:%c:%d:%d: Tagged Queuing enabled.  Depth %d\n",
-	       	       ahc->platform_data->host->host_no, device->channel + 'A',
-		       device->id, device->lun, tags);
-	} else {
-		/*
-		 * We allow the OS to queue 2 untagged transactions to
-		 * us at any time even though we can only execute them
-		 * serially on the controller/device.  This should remove
-		 * some latency.
-		device->queue_depth = 2;
-		 */
-		scsi_adjust_queue_depth(device, 0, device->host->cmd_per_lun);
-	}
-}
-
-/*
- * Queue an SCB to the controller.
- */
-int
-ahc_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
-{
-	struct	 ahc_softc *ahc = *(struct ahc_softc **)cmd->host->hostdata;
-	struct	 ahc_linux_device *dev;
-
-	/*
-	 * Save the callback on completion function.
-	 */
-	cmd->scsi_done = scsi_done;
-
-	dev = ahc_linux_get_device(ahc, cmd->channel, cmd->target,
-				   cmd->lun, /*alloc*/TRUE);
-	if (dev == NULL) {
-		printf("aic7xxx_linux_queue: Unable to allocate device!\n");
-		return (-ENOMEM);
-	}
-	cmd->result = CAM_REQ_INPROG << 16;
-	TAILQ_INSERT_TAIL(&dev->busyq, (struct ahc_cmd *)cmd, acmd_links.tqe);
-	if ((dev->flags & AHC_DEV_ON_RUN_LIST) == 0) {
-		TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq, dev, links);
-		dev->flags |= AHC_DEV_ON_RUN_LIST;
-		ahc_linux_run_device_queues(ahc);
-	}
-	return (0);
-}
-
-static void
-ahc_linux_run_device_queue(struct ahc_softc *ahc, struct ahc_linux_device *dev)
-{
-	struct	 ahc_cmd *acmd;
-	struct	 scsi_cmnd *cmd;
-	struct	 scb *scb;
-	struct	 hardware_scb *hscb;
-	struct	 ahc_initiator_tinfo *tinfo;
-	struct	 ahc_tmode_tstate *tstate;
-	uint16_t mask;
-
-	if ((dev->flags & AHC_DEV_ON_RUN_LIST) != 0)
-		panic("running device on run list");
-
-	while ((acmd = TAILQ_FIRST(&dev->busyq)) != NULL
-	    && dev->openings > 0 && dev->qfrozen == 0) {
-
-		/*
-		 * Schedule us to run later.  The only reason we are not
-		 * running is because the whole controller Q is frozen.
-		 */
-		if (ahc->platform_data->qfrozen != 0) {
-
-			TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq,
-					  dev, links);
-			dev->flags |= AHC_DEV_ON_RUN_LIST;
-			return;
-		}
-		/*
-		 * Get an scb to use.
-		 */
-		if ((scb = ahc_get_scb(ahc)) == NULL) {
-			TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq,
-					 dev, links);
-			dev->flags |= AHC_DEV_ON_RUN_LIST;
-			ahc->flags |= AHC_RESOURCE_SHORTAGE;
-			return;
-		}
-		TAILQ_REMOVE(&dev->busyq, acmd, acmd_links.tqe);
-		cmd = &acmd_scsi_cmd(acmd);
-		scb->io_ctx = cmd;
-		scb->platform_data->dev = dev;
-		hscb = scb->hscb;
-		cmd->host_scribble = (char *)scb;
-
-		/*
-		 * Fill out basics of the HSCB.
-		 */
-		hscb->control = 0;
-		hscb->scsiid = BUILD_SCSIID(ahc, cmd);
-		hscb->lun = cmd->lun;
-		mask = SCB_GET_TARGET_MASK(ahc, scb);
-		tinfo = ahc_fetch_transinfo(ahc, SCB_GET_CHANNEL(ahc, scb),
-					    SCB_GET_OUR_ID(scb),
-					    SCB_GET_TARGET(ahc, scb), &tstate);
-		hscb->scsirate = tinfo->scsirate;
-		hscb->scsioffset = tinfo->curr.offset;
-		if ((tstate->ultraenb & mask) != 0)
-			hscb->control |= ULTRAENB;
-
-		if ((ahc->user_discenable & mask) != 0)
-			hscb->control |= DISCENB;
-
-		if ((tstate->auto_negotiate & mask) != 0) {
-			scb->flags |= SCB_AUTO_NEGOTIATE;
-			scb->hscb->control |= MK_MESSAGE;
-		}
-
-		if ((dev->flags & (AHC_DEV_Q_TAGGED|AHC_DEV_Q_BASIC)) != 0) {
-			if (dev->commands_since_idle_or_otag == AHC_OTAG_THRESH
-			 && (dev->flags & AHC_DEV_Q_TAGGED) != 0) {
-				hscb->control |= MSG_ORDERED_TASK;
-				dev->commands_since_idle_or_otag = 0;
-			} else {
-				hscb->control |= MSG_SIMPLE_TASK;
-			}
-		}
-
-		hscb->cdb_len = cmd->cmd_len;
-		if (hscb->cdb_len <= 12) {
-			memcpy(hscb->shared_data.cdb, cmd->cmnd, hscb->cdb_len);
-		} else {
-			memcpy(hscb->cdb32, cmd->cmnd, hscb->cdb_len);
-			scb->flags |= SCB_CDB32_PTR;
-		}
-
-		scb->platform_data->xfer_len = 0;
-		ahc_set_residual(scb, 0);
-		ahc_set_sense_residual(scb, 0);
-		if (cmd->use_sg != 0) {
-			struct	ahc_dma_seg *sg;
-			struct	scatterlist *cur_seg;
-			struct	scatterlist *end_seg;
-			int	nseg;
-
-			cur_seg = (struct scatterlist *)cmd->request_buffer;
-			nseg = pci_map_sg(ahc->dev_softc, cur_seg, cmd->use_sg,
-				 scsi_to_pci_dma_dir(cmd ->sc_data_direction));
-			end_seg = cur_seg + nseg;
-			/* Copy the segments into the SG list. */
-			sg = scb->sg_list;
-			/*
-			 * The sg_count may be larger than nseg if
-			 * a transfer crosses a 32bit page.
-			 */ 
-			scb->sg_count = 0;
-			while(cur_seg < end_seg) {
-				bus_addr_t addr;
-				bus_size_t len;
-				int consumed;
-
-				addr = sg_dma_address(cur_seg);
-				len = sg_dma_len(cur_seg);
-				consumed = ahc_linux_map_seg(ahc, scb,
-							     sg, addr, len);
-				sg += consumed;
-				scb->sg_count += consumed;
-				cur_seg++;
-			}
-			sg--;
-			sg->len |= ahc_htole32(AHC_DMA_LAST_SEG);
-
-			/*
-			 * Reset the sg list pointer.
-			 */
-			scb->hscb->sgptr =
-			    ahc_htole32(scb->sg_list_phys | SG_FULL_RESID);
-
-			/*
-			 * Copy the first SG into the "current"
-			 * data pointer area.
-			 */
-			scb->hscb->dataptr = scb->sg_list->addr;
-			scb->hscb->datacnt = scb->sg_list->len;
-		} else if (cmd->request_bufflen != 0) {
-			struct	 ahc_dma_seg *sg;
-			bus_addr_t addr;
-
-			sg = scb->sg_list;
-			addr = pci_map_single(ahc->dev_softc,
-			       cmd->request_buffer,
-			       cmd->request_bufflen,
-			       scsi_to_pci_dma_dir(cmd->sc_data_direction));
-			scb->sg_count = 0;
-			scb->sg_count = ahc_linux_map_seg(ahc, scb,
-							  sg, addr,
-							  cmd->request_bufflen);
-			sg->len |= ahc_htole32(AHC_DMA_LAST_SEG);
-
-			/*
-			 * Reset the sg list pointer.
-			 */
-			scb->hscb->sgptr =
-			    ahc_htole32(scb->sg_list_phys | SG_FULL_RESID);
-
-			/*
-			 * Copy the first SG into the "current"
-			 * data pointer area.
-			 */
-			scb->hscb->dataptr = sg->addr;
-			scb->hscb->datacnt = sg->len;
-		} else {
-			scb->hscb->sgptr = ahc_htole32(SG_LIST_NULL);
-			scb->hscb->dataptr = 0;
-			scb->hscb->datacnt = 0;
-			scb->sg_count = 0;
-		}
-
-		ahc_sync_sglist(ahc, scb, BUS_DMASYNC_PREWRITE);
-		LIST_INSERT_HEAD(&ahc->pending_scbs, scb, pending_links);
-		dev->openings--;
-		dev->active++;
-		dev->commands_issued++;
-		if ((dev->flags & AHC_DEV_PERIODIC_OTAG) != 0)
-			dev->commands_since_idle_or_otag++;
-
-		/*
-		 * We only allow one untagged transaction
-		 * per target in the initiator role unless
-		 * we are storing a full busy target *lun*
-		 * table in SCB space.
-		 */
-		if ((scb->hscb->control & (TARGET_SCB|TAG_ENB)) == 0
-		 && (ahc->features & AHC_SCB_BTT) == 0) {
-			struct scb_tailq *untagged_q;
-			int target_offset;
-
-			target_offset = SCB_GET_TARGET_OFFSET(ahc, scb);
-			untagged_q = &(ahc->untagged_queues[target_offset]);
-			TAILQ_INSERT_TAIL(untagged_q, scb, links.tqe);
-			scb->flags |= SCB_UNTAGGEDQ;
-			if (TAILQ_FIRST(untagged_q) != scb)
-				continue;
-		}
-		scb->flags |= SCB_ACTIVE;
-		ahc_queue_scb(ahc, scb);
-	}
-}
-
-/*
- * SCSI controller interrupt handler.
- */
-void
-ahc_linux_isr(int irq, void *dev_id, struct pt_regs * regs)
-{
-	struct ahc_softc *ahc;
-	struct ahc_cmd *acmd;
-	u_long flags;
-
-	ahc = (struct ahc_softc *) dev_id;
-	if (!ahc->platform_data->host) {
-		printk("aic7xxx: interrupt while setup incomplete\n");
-		return;
-	}
-	ahc_lock(ahc, &flags); 
-	ahc_intr(ahc);
-	/*
-	 * It would be nice to run the device queues from a
-	 * bottom half handler, but as there is no way to
-	 * dynamically register one, we'll have to postpone
-	 * that until we get integrated into the kernel.
-	 */
-	ahc_linux_run_device_queues(ahc);
-	acmd = TAILQ_FIRST(&ahc->platform_data->completeq);
-	TAILQ_INIT(&ahc->platform_data->completeq);
-	ahc_unlock(ahc, &flags);
-	if (acmd != NULL)
-		ahc_linux_run_complete_queue(ahc, acmd);
-}
-
-void
-ahc_platform_flushwork(struct ahc_softc *ahc)
-{
-	struct ahc_cmd *acmd;
-
-	acmd = TAILQ_FIRST(&ahc->platform_data->completeq);
-	TAILQ_INIT(&ahc->platform_data->completeq);
-	if (acmd != NULL)
-		ahc_linux_run_complete_queue(ahc, acmd);
-}
-
-static struct ahc_linux_target*
-ahc_linux_alloc_target(struct ahc_softc *ahc, u_int channel, u_int target)
-{
-	struct ahc_linux_target *targ;
-	u_int target_offset;
-
-	targ = malloc(sizeof(*targ), M_DEVBUG, M_NOWAIT);
-	if (targ == NULL)
-		return (NULL);
-	memset(targ, 0, sizeof(*targ));
-	targ->channel = channel;
-	targ->target = target;
-	target_offset = target;
-	if (channel != 0)
-		target_offset += 8;
-	ahc->platform_data->targets[target_offset] = targ;
-	return (targ);
-}
-
-static void
-ahc_linux_free_target(struct ahc_softc *ahc, struct ahc_linux_target *targ)
-{
-	u_int target_offset;
-
-	target_offset = targ->target;
-	if (targ->channel != 0)
-		target_offset += 8;
-	ahc->platform_data->targets[target_offset] = NULL;
-	free(targ, M_DEVBUF);
-}
-
-static struct ahc_linux_device*
-ahc_linux_alloc_device(struct ahc_softc *ahc,
-		 struct ahc_linux_target *targ, u_int lun)
-{
-	struct ahc_linux_device *dev;
-
-	dev = malloc(sizeof(*dev), M_DEVBUG, M_NOWAIT);
-	if (dev == NULL)
-		return (NULL);
-	memset(dev, 0, sizeof(*dev));
-	TAILQ_INIT(&dev->busyq);
-	dev->flags = AHC_DEV_UNCONFIGURED;
-	dev->lun = lun;
-	dev->target = targ;
-
-	/*
-	 * We start out life using untagged
-	 * transactions of which we allow one.
-	 */
-	dev->openings = 1;
-
-	/*
-	 * Set maxtags to 0.  This will be changed if we
-	 * later determine that we are dealing with
-	 * a tagged queuing capable device.
-	 */
-	dev->maxtags = 0;
-	
-	targ->refcount++;
-	targ->devices[lun] = dev;
-	return (dev);
-}
-
-static void
-ahc_linux_free_device(struct ahc_softc *ahc, struct ahc_linux_device *dev)
-{
-	struct ahc_linux_target *targ;
-
-	targ = dev->target;
-	targ->devices[dev->lun] = NULL;
-	free(dev, M_DEVBUF);
-	targ->refcount--;
-	if (targ->refcount == 0)
-		ahc_linux_free_target(ahc, targ);
-}
-
-/*
- * Return a string describing the driver.
- */
-const char *
-ahc_linux_info(struct Scsi_Host *host)
-{
-	static char buffer[512];
-	char	ahc_info[256];
-	char   *bp;
-	struct ahc_softc *ahc;
-
-	bp = &buffer[0];
-	ahc = *(struct ahc_softc **)host->hostdata;
-	memset(bp, 0, sizeof(buffer));
-	strcpy(bp, "Adaptec AIC7XXX EISA/VLB/PCI SCSI HBA DRIVER, Rev ");
-	strcat(bp, AIC7XXX_DRIVER_VERSION);
-	strcat(bp, "\n");
-	strcat(bp, "        <");
-	strcat(bp, ahc->description);
-	strcat(bp, ">\n");
-	strcat(bp, "        ");
-	ahc_controller_info(ahc, ahc_info);
-	strcat(bp, ahc_info);
-	strcat(bp, "\n");
-
-	return (bp);
-}
-
-void
-ahc_send_async(struct ahc_softc *ahc, char channel,
-	       u_int target, u_int lun, ac_code code, void *arg)
-{
-	switch (code) {
-	case AC_TRANSFER_NEG:
-	{
-		char	buf[80];
-		struct	ahc_linux_target *targ;
-		struct	info_str info;
-		struct	ahc_initiator_tinfo *tinfo;
-		struct	ahc_tmode_tstate *tstate;
-		int	target_offset;
-
-		info.buffer = buf;
-		info.length = sizeof(buf);
-		info.offset = 0;
-		info.pos = 0;
-		tinfo = ahc_fetch_transinfo(ahc, channel,
-						channel == 'A' ? ahc->our_id
-							       : ahc->our_id_b,
-						target, &tstate);
-
-		/*
-		 * Don't bother reporting results while
-		 * negotiations are still pending.
-		 */
-		if (tinfo->curr.period != tinfo->goal.period
-		 || tinfo->curr.width != tinfo->goal.width
-		 || tinfo->curr.offset != tinfo->goal.offset
-		 || tinfo->curr.ppr_options != tinfo->goal.ppr_options)
-			if (bootverbose == 0)
-				break;
-
-		/*
-		 * Don't bother reporting results that
-		 * are identical to those last reported.
-		 */
-		target_offset = target;
-		if (channel == 'B')
-			target_offset += 8;
-		targ = ahc->platform_data->targets[target_offset];
-		if (targ != NULL
-		 && tinfo->curr.period == targ->last_tinfo.period
-		 && tinfo->curr.width == targ->last_tinfo.width
-		 && tinfo->curr.offset == targ->last_tinfo.offset
-		 && tinfo->curr.ppr_options == targ->last_tinfo.ppr_options)
-			if (bootverbose == 0)
-				break;
-
-		targ->last_tinfo.period = tinfo->curr.period;
-		targ->last_tinfo.width = tinfo->curr.width;
-		targ->last_tinfo.offset = tinfo->curr.offset;
-		targ->last_tinfo.ppr_options = tinfo->curr.ppr_options;
-
-		printf("(%s:%c:", ahc_name(ahc), channel);
-		if (target == CAM_TARGET_WILDCARD)
-			printf("*): ");
-		else
-			printf("%d): ", target);
-		ahc_format_transinfo(&info, &tinfo->curr);
-		if (info.pos < info.length)
-			*info.buffer = '\0';
-		else
-			buf[info.length - 1] = '\0';
-		printf("%s", buf);
-		break;
-	}
-        case AC_SENT_BDR:
-		break;
-        case AC_BUS_RESET:
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
-		if (ahc->platform_data->host != NULL) {
-			scsi_report_bus_reset(ahc->platform_data->host,
-					      channel - 'A');
-		}
-#endif
-                break;
-        default:
-                panic("ahc_send_async: Unexpected async event");
-        }
-}
-
-/*
- * Calls the higher level scsi done function and frees the scb.
- */
-void
-ahc_done(struct ahc_softc *ahc, struct scb * scb)
-{
-	Scsi_Cmnd *cmd;
-	struct ahc_linux_device *dev;
-
-	LIST_REMOVE(scb, pending_links);
-	if ((scb->flags & SCB_UNTAGGEDQ) != 0) {
-		struct scb_tailq *untagged_q;
-		int target_offset;
-
-		target_offset = SCB_GET_TARGET_OFFSET(ahc, scb);
-		untagged_q = &(ahc->untagged_queues[target_offset]);
-		TAILQ_REMOVE(untagged_q, scb, links.tqe);
-		ahc_run_untagged_queue(ahc, untagged_q);
-	}
-
-	if ((scb->flags & SCB_ACTIVE) == 0) {
-		printf("SCB %d done'd twice\n", scb->hscb->tag);
-		ahc_dump_card_state(ahc);
-		panic("Stopping for safety");
-	}
-	cmd = scb->io_ctx;
-	dev = scb->platform_data->dev;
-	dev->active--;
-	dev->openings++;
-	ahc_linux_unmap_scb(ahc, scb);
-	if (scb->flags & SCB_SENSE) {
-		memcpy(cmd->sense_buffer, ahc_get_sense_buf(ahc, scb),
-		       MIN(sizeof(struct scsi_sense_data),
-			   sizeof(cmd->sense_buffer)));
-		cmd->result |= (DRIVER_SENSE << 24);
-	} else {
-		/*
-		 * Guard against stale sense data.
-		 * The Linux mid-layer assumes that sense
-		 * was retrieved anytime the first byte of
-		 * the sense buffer looks "sane".
-		 */
-		cmd->sense_buffer[0] = 0;
-	}
-	if (ahc_get_transaction_status(scb) == CAM_REQ_INPROG) {
-		uint32_t amount_xferred;
-
-		amount_xferred =
-		    ahc_get_transfer_length(scb) - ahc_get_residual(scb);
-		if (amount_xferred < scb->io_ctx->underflow) {
-			printf("Saw underflow (%ld of %ld bytes). "
-			       "Treated as error\n",
-				ahc_get_residual(scb),
-				ahc_get_transfer_length(scb));
-			ahc_set_transaction_status(scb, CAM_DATA_RUN_ERR);
-		} else {
-			ahc_set_transaction_status(scb, CAM_REQ_CMP);
-			ahc_linux_sniff_command(ahc, cmd, scb);
-		}
-	} else if (ahc_get_transaction_status(scb) == DID_OK) {
-		ahc_linux_handle_scsi_status(ahc, dev, scb);
-	} else if (ahc_get_transaction_status(scb) == DID_NO_CONNECT) {
-		/*
-		 * Should a selection timeout kill the device?
-		 * That depends on whether the selection timeout
-		 * is persistent.  Since we have no guarantee that
-		 * the mid-layer will issue an inquiry for this device
-		 * again, we can't just kill it off.
-		dev->flags |= AHC_DEV_UNCONFIGURED;
-		 */
-	}
-
-	if (dev->openings == 1
-	 && ahc_get_transaction_status(scb) == CAM_REQ_CMP
-	 && ahc_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL)
-		dev->tag_success_count++;
-	/*
-	 * Some devices deal with temporary internal resource
-	 * shortages by returning queue full.  When the queue
-	 * full occurrs, we throttle back.  Slowly try to get
-	 * back to our previous queue depth.
-	 */
-	if ((dev->openings + dev->active) < dev->maxtags
-	 && dev->tag_success_count > AHC_TAG_SUCCESS_INTERVAL) {
-		dev->tag_success_count = 0;
-		dev->openings++;
-	}
-
-	if (dev->active == 0)
-		dev->commands_since_idle_or_otag = 0;
-
-	if (TAILQ_EMPTY(&dev->busyq)) {
-		if ((dev->flags & AHC_DEV_UNCONFIGURED) != 0
-		 && dev->active == 0)
-			ahc_linux_free_device(ahc, dev);
-	} else if ((dev->flags & AHC_DEV_ON_RUN_LIST) == 0) {
-		TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq, dev, links);
-		dev->flags |= AHC_DEV_ON_RUN_LIST;
-	}
-
-	if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
-		printf("Recovery SCB completes\n");
-		up(&ahc->platform_data->eh_sem);
-	}
-
-	ahc_free_scb(ahc, scb);
-	ahc_linux_queue_cmd_complete(ahc, cmd);
-}
-
-static void
-ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
-			     struct ahc_linux_device *dev, struct scb *scb)
-{
-	/*
-	 * We don't currently trust the mid-layer to
-	 * properly deal with queue full or busy.  So,
-	 * when one occurs, we tell the mid-layer to
-	 * unconditionally requeue the command to us
-	 * so that we can retry it ourselves.  We also
-	 * implement our own throttling mechanism so
-	 * we don't clobber the device with too many
-	 * commands.
-	 */
-	switch (ahc_get_scsi_status(scb)) {
-	default:
-		break;
-	case SCSI_STATUS_QUEUE_FULL:
-	{
-		/*
-		 * By the time the core driver has returned this
-		 * command, all other commands that were queued
-		 * to us but not the device have been returned.
-		 * This ensures that dev->active is equal to
-		 * the number of commands actually queued to
-		 * the device.
-		 */
-		dev->tag_success_count = 0;
-		if (dev->active != 0) {
-			/*
-			 * Drop our opening count to the number
-			 * of commands currently outstanding.
-			 */
-			dev->openings = 0;
-/*
-			ahc_print_path(ahc, scb);
-			printf("Dropping tag count to %d\n", dev->active);
- */
-			if (dev->active == dev->tags_on_last_queuefull) {
-
-				dev->last_queuefull_same_count++;
-				/*
-				 * If we repeatedly see a queue full
-				 * at the same queue depth, this
-				 * device has a fixed number of tag
-				 * slots.  Lock in this tag depth
-				 * so we stop seeing queue fulls from
-				 * this device.
-				 */
-				if (dev->last_queuefull_same_count
-				 == AHC_LOCK_TAGS_COUNT) {
-					dev->maxtags = dev->active;
-					ahc_print_path(ahc, scb);
-					printf("Locking max tag count at %d\n",
-					       dev->active);
-				}
-			} else {
-				dev->tags_on_last_queuefull = dev->active;
-				dev->last_queuefull_same_count = 0;
-			}
-			ahc_set_transaction_status(scb, CAM_REQUEUE_REQ);
-			ahc_set_scsi_status(scb, SCSI_STATUS_OK);
-			break;
-		}
-		/*
-		 * Drop down to a single opening, and treat this
-		 * as if the target return BUSY SCSI status.
-		 */
-		dev->openings = 1;
-		/* FALLTHROUGH */
-	}
-	case SCSI_STATUS_BUSY:
-		/*
-		 * XXX Set a timer and handle ourselves????
-		 * For now we pray that the mid-layer does something
-		 * sane for devices that are busy.
-		 */
-		ahc_set_scsi_status(scb, SCSI_STATUS_BUSY);
-		break;
-	}
-}
-
-static void
-ahc_linux_filter_command(struct ahc_softc *ahc, Scsi_Cmnd *cmd, struct scb *scb)
-{
-	switch (cmd->cmnd[0]) {
-	case INQUIRY:
-	{
-		struct	ahc_devinfo devinfo;
-		struct	scsi_inquiry *inq;
-		struct	scsi_inquiry_data *sid;
-		struct	ahc_initiator_tinfo *targ_info;
-		struct	ahc_tmode_tstate *tstate;
-		struct	ahc_syncrate *syncrate;
-		struct	ahc_linux_device *dev;
-		u_int	scsiid;
-		u_int	maxsync;
-		int	transferred_len;
-		int	minlen;
-		u_int	width;
-		u_int	period;
-		u_int	offset;
-		u_int	ppr_options;
-
-		 /*
-		  * Validate the command.  We only want to filter
-		  * standard inquiry commands, not those querying
-		  * Vital Product Data.
-		  */
-		inq = (struct scsi_inquiry *)cmd->cmnd;
-		if ((inq->byte2 & SI_EVPD) != 0
-		 || inq->page_code != 0)
-			break;
-
-		if (cmd->use_sg != 0) {
-			printf("%s: SG Inquiry response ignored\n",
-			       ahc_name(ahc));
-			break;
-		}
-		transferred_len = ahc_get_transfer_length(scb)
-				- ahc_get_residual(scb);
-		sid = (struct scsi_inquiry_data *)cmd->request_buffer;
-
-		/*
-		 * Determine if this lun actually exists.  If so,
-		 * hold on to its corresponding device structure.
-		 * If not, make sure we release the device and
-		 * don't bother processing the rest of this inquiry
-		 * command.
-		 */
-		dev = ahc_linux_get_device(ahc, cmd->channel,
-					   cmd->target, cmd->lun,
-					   /*alloc*/FALSE);
-		if (transferred_len >= 1
-		 && SID_QUAL(sid) == SID_QUAL_LU_CONNECTED) {
-
-			dev->flags &= ~AHC_DEV_UNCONFIGURED;
-		} else {
-			dev->flags |= AHC_DEV_UNCONFIGURED;
-			break;
-		}
-
-		/*
-		 * Update our notion of this device's transfer
-		 * negotiation capabilities.
-		 */
-		scsiid = BUILD_SCSIID(ahc, cmd);
-		ahc_compile_devinfo(&devinfo, SCSIID_OUR_ID(scsiid),
-				    cmd->target, cmd->lun,
-				    SCSIID_CHANNEL(ahc, scsiid),
-				    ROLE_INITIATOR);
-		targ_info = ahc_fetch_transinfo(ahc, devinfo.channel,
-						devinfo.our_scsiid,
-						devinfo.target, &tstate);
-		width = targ_info->user.width;
-		period = targ_info->user.period;
-		offset = targ_info->user.offset;
-		ppr_options = targ_info->user.ppr_options;
-		minlen = offsetof(struct scsi_inquiry_data, version) + 1;
-		if (transferred_len >= minlen) {
-			targ_info->curr.protocol_version = SID_ANSI_REV(sid);
-
-			/*
-			 * Only attempt SPI3 once we've verified that
-			 * the device claims to support SPI3 features.
-			 */
-			if (targ_info->curr.protocol_version < SCSI_REV_2)
-				targ_info->curr.transport_version =
-				    SID_ANSI_REV(sid);
-			else
-				targ_info->curr.transport_version =
-				     SCSI_REV_2;
-		}
-
-		minlen = offsetof(struct scsi_inquiry_data, flags) + 1;
-		if (transferred_len >= minlen
-		 && (sid->additional_length + 4) >= minlen) {
-			if ((sid->flags & SID_WBus16) == 0)
-				width = MSG_EXT_WDTR_BUS_8_BIT;
-			if ((sid->flags & SID_Sync) == 0) {
-				period = 0;
-				offset = 0;
-				ppr_options = 0;
-			}
-		} else {
-			/* Keep current settings */
-			break;
-		}
-		minlen = offsetof(struct scsi_inquiry_data, spi3data) + 1;
-		/*
-		 * This is a kludge to deal with inquiry requests that
-		 * are not large enough for us to pull the spi3 bits.
-		 * In this case, we assume that a device that tells us
-		 * they can provide inquiry data that spans the SPI3
-		 * bits and says its SCSI3 can handle a PPR request.
-		 * If the inquiry request has sufficient buffer space to
-		 * cover these bits, we check them to see if any ppr options
-		 * are available.
-		 */
-		if ((sid->additional_length + 4) >= minlen) {
-			if (transferred_len >= minlen
-			 && (sid->spi3data & SID_SPI_CLOCK_DT) == 0)
-				ppr_options = 0;
-
-			if (targ_info->curr.protocol_version > SCSI_REV_2)
-				targ_info->curr.transport_version = 3;
-			else
-				ppr_options = 0;
-		} else {
-			ppr_options = 0;
-		}
-		ahc_validate_width(ahc, /*tinfo limit*/NULL, &width,
-				   ROLE_UNKNOWN);
-		if ((ahc->features & AHC_ULTRA2) != 0)
-			maxsync = AHC_SYNCRATE_DT;
-		else if ((ahc->features & AHC_ULTRA) != 0)
-			maxsync = AHC_SYNCRATE_ULTRA;
-		else
-			maxsync = AHC_SYNCRATE_FAST;
-
-		syncrate = ahc_find_syncrate(ahc, &period,
-					     &ppr_options, maxsync);
-		ahc_validate_offset(ahc, /*tinfo limit*/NULL, syncrate,
-				    &offset, width, ROLE_UNKNOWN);
-		if (offset == 0 || period == 0) {
-			period = 0;
-			offset = 0;
-			ppr_options = 0;
-		}
-		/* Apply our filtered user settings. */
-		ahc_set_width(ahc, &devinfo, width,
-			      AHC_TRANS_GOAL, /*paused*/FALSE);
-		ahc_set_syncrate(ahc, &devinfo, syncrate, period,
-				 offset, ppr_options, AHC_TRANS_GOAL,
-				 /*paused*/FALSE);
-		break;
-	}
-	default:
-		panic("ahc_linux_filter_command: Unexpected Command type  %x\n",
-		      cmd->cmnd[0]);
-		break;
-	}
-}
-
-static void
-ahc_linux_sem_timeout(u_long arg)
-{
-	struct semaphore *sem;
-
-	sem = (struct semaphore *)arg;
-	up(sem);
-}
-
-static void
-ahc_linux_freeze_sim_queue(struct ahc_softc *ahc)
-{
-	ahc->platform_data->qfrozen++;
-	if (ahc->platform_data->qfrozen == 1)
-		scsi_block_requests(ahc->platform_data->host);
-}
-
-static void
-ahc_linux_release_sim_queue(u_long arg)
-{
-	struct ahc_softc *ahc;
-	u_long s;
-	int    unblock_reqs;
-
-	ahc = (struct ahc_softc *)arg;
-	unblock_reqs = 0;
-	ahc_lock(ahc, &s);
-	if (ahc->platform_data->qfrozen > 0)
-		ahc->platform_data->qfrozen--;
-	if (ahc->platform_data->qfrozen == 0) {
-		unblock_reqs = 1;
-		ahc_linux_run_device_queues(ahc);
-	}
-	ahc_unlock(ahc, &s);
-	/*
-	 * There is still a race here.  The mid-layer
-	 * should keep its own freeze count and use
-	 * a bottom half handler to run the queues
-	 * so we can unblock with our own lock held.
-	 */
-	if (unblock_reqs)
-		scsi_unblock_requests(ahc->platform_data->host);
-}
-
-static int
-ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag)
-{
-	struct ahc_softc *ahc;
-	struct ahc_cmd *acmd;
-	struct ahc_cmd *list_acmd;
-	struct ahc_linux_device *dev;
-	struct scb *pending_scb;
-	u_long s;
-	u_int  saved_scbptr;
-	u_int  active_scb_index;
-	u_int  last_phase;
-	int    retval;
-	int    paused;
-	int    wait;
-	int    disconnected;
-
-	paused = FALSE;
-	wait = FALSE;
-	ahc = *(struct ahc_softc **)cmd->host->hostdata;
-	acmd = (struct ahc_cmd *)cmd;
-
-	printf("%s:%d:%d:%d: Attempting to queue a%s message\n",
-	       ahc_name(ahc), cmd->channel, cmd->target, cmd->lun,
-	       flag == SCB_ABORT ? "n ABORT" : " TARGET RESET");
-
-	/*
-	 * we used to drop io_request_lock and lock ahc from here, but
-	 * now that the global lock is gone the upper layer have already
-	 * done what ahc_lock would do /jens
-	 */
-
-	/*
-	 * First determine if we currently own this command.
-	 * Start by searching the device queue.  If not found
-	 * there, check the pending_scb list.  If not found
-	 * at all, and the system wanted us to just abort the
-	 * command return success.
-	 */
-	dev = ahc_linux_get_device(ahc, cmd->channel, cmd->target,
-				   cmd->lun, /*alloc*/FALSE);
-
-	if (dev == NULL) {
-		/*
-		 * No target device for this command exists,
-		 * so we must not still own the command.
-		 */
-		printf("%s:%d:%d:%d: Is not an active device\n",
-		       ahc_name(ahc), cmd->channel, cmd->target, cmd->lun);
-		retval = SUCCESS;
-		goto no_cmd;
-	}
-
-	TAILQ_FOREACH(list_acmd, &dev->busyq, acmd_links.tqe) {
-		if (list_acmd == acmd)
-			break;
-	}
-
-	if (list_acmd != NULL) {
-		printf("%s:%d:%d:%d: Command found on device queue\n",
-		       ahc_name(ahc), cmd->channel, cmd->target, cmd->lun);
-		if (flag == SCB_ABORT) {
-			TAILQ_REMOVE(&dev->busyq, list_acmd, acmd_links.tqe);
-			cmd->result = DID_ABORT << 16;
-			ahc_linux_queue_cmd_complete(ahc, cmd);
-			retval = SUCCESS;
-			goto done;
-		}
-	}
-
-	/*
-	 * See if we can find a matching cmd in the pending list.
-	 */
-	LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) {
-		if (pending_scb->io_ctx == cmd)
-			break;
-	}
-
-	if (pending_scb == NULL && flag == SCB_DEVICE_RESET) {
-
-		/* Any SCB for this device will do for a target reset */
-		LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) {
-		  	if (ahc_match_scb(ahc, pending_scb, cmd->target,
-					  cmd->channel, CAM_LUN_WILDCARD,
-					  SCB_LIST_NULL, ROLE_INITIATOR) == 0)
-				break;
-		}
-	}
-
-	if (pending_scb == NULL) {
-		printf("%s:%d:%d:%d: Command not found\n",
-		       ahc_name(ahc), cmd->channel, cmd->target, cmd->lun);
-		goto no_cmd;
-	}
-
-	if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) {
-		/*
-		 * We can't queue two recovery actions using the same SCB
-		 */
-		retval = FAILED;
-		goto  done;
-	}
-
-	/*
-	 * Ensure that the card doesn't do anything
-	 * behind our back.  Also make sure that we
-	 * didn't "just" miss an interrupt that would
-	 * affect this cmd.
-	 */
-	ahc->flags |= AHC_ALL_INTERRUPTS;
-	do {
-		ahc_intr(ahc);
-		ahc_pause(ahc);
-		ahc_clear_critical_section(ahc);
-	} while (ahc_inb(ahc, INTSTAT) & INT_PEND);
-	ahc->flags &= ~AHC_ALL_INTERRUPTS;
-	paused = TRUE;
-
-	ahc_dump_card_state(ahc);
-
-	if ((pending_scb->flags & SCB_ACTIVE) == 0) {
-		printf("%s:%d:%d:%d: Command already completed\n",
-		       ahc_name(ahc), cmd->channel, cmd->target, cmd->lun);
-		goto no_cmd;
-	}
-
-	disconnected = TRUE;
-	if (flag == SCB_ABORT) {
-		if (ahc_search_qinfifo(ahc, cmd->target, cmd->channel + 'A',
-				       cmd->lun, pending_scb->hscb->tag,
-				       ROLE_INITIATOR, CAM_REQ_ABORTED,
-				       SEARCH_COMPLETE) > 0) {
-			printf("%s:%d:%d:%d: Cmd aborted from QINFIFO\n",
-			       ahc_name(ahc), cmd->channel, cmd->target,
-					cmd->lun);
-			retval = SUCCESS;
-			goto done;
-		}
-	} else if (ahc_search_qinfifo(ahc, cmd->target, cmd->channel + 'A',
-				      cmd->lun, pending_scb->hscb->tag,
-				      ROLE_INITIATOR, /*status*/0,
-				      SEARCH_COUNT) > 0) {
-		disconnected = FALSE;
-	}
-
-	/*
-	 * At this point, pending_scb is the scb associated with the
-	 * passed in command.  That command is currently active on the
-	 * bus, is in the disconnected state, or we're hoping to find
-	 * a command for the same target active on the bus to abuse to
-	 * send a BDR.  Queue the appropriate message based on which of
-	 * these states we are in.
-	 */
-	last_phase = ahc_inb(ahc, LASTPHASE);
-	saved_scbptr = ahc_inb(ahc, SCBPTR);
-	active_scb_index = ahc_inb(ahc, SCB_TAG);
-	if (last_phase != P_BUSFREE
-	 && (pending_scb->hscb->tag == active_scb_index
-	  || (flag == SCB_DEVICE_RESET
-	   && SCSIID_TARGET(ahc, ahc_inb(ahc, SAVED_SCSIID)) == cmd->target))) {
-
-		/*
-		 * We're active on the bus, so assert ATN
-		 * and hope that the target responds.
-		 */
-		pending_scb = ahc_lookup_scb(ahc, active_scb_index);
-		pending_scb->flags |= SCB_RECOVERY_SCB|flag;
-		ahc_outb(ahc, MSG_OUT, HOST_MSG);
-		ahc_outb(ahc, SCSISIGO, last_phase|ATNO);
-		printf("%s:%d:%d:%d: Device is active, asserting ATN\n",
-		       ahc_name(ahc), cmd->channel, cmd->target, cmd->lun);
-		wait = TRUE;
-	} else if (disconnected) {
-
-		/*
-		 * Actually re-queue this SCB in an attempt
-		 * to select the device before it reconnects.
-		 * In either case (selection or reselection),
-		 * we will now issue the approprate message
-		 * to the timed-out device.
-		 *
-		 * Set the MK_MESSAGE control bit indicating
-		 * that we desire to send a message.  We
-		 * also set the disconnected flag since
-		 * in the paging case there is no guarantee
-		 * that our SCB control byte matches the
-		 * version on the card.  We don't want the
-		 * sequencer to abort the command thinking
-		 * an unsolicited reselection occurred.
-		 */
-		pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
-		pending_scb->flags |= SCB_RECOVERY_SCB|flag;
-
-		/*
-		 * Remove any cached copy of this SCB in the
-		 * disconnected list in preparation for the
-		 * queuing of our abort SCB.  We use the
-		 * same element in the SCB, SCB_NEXT, for
-		 * both the qinfifo and the disconnected list.
-		 */
-		ahc_search_disc_list(ahc, cmd->target, cmd->channel + 'A',
-				     cmd->lun, pending_scb->hscb->tag,
-				     /*stop_on_first*/TRUE,
-				     /*remove*/TRUE,
-				     /*save_state*/FALSE);
-
-		/*
-		 * In the non-paging case, the sequencer will
-		 * never re-reference the in-core SCB.
-		 * To make sure we are notified during
-		 * reslection, set the MK_MESSAGE flag in
-		 * the card's copy of the SCB.
-		 */
-		if ((ahc->flags & AHC_PAGESCBS) == 0) {
-			ahc_outb(ahc, SCBPTR, pending_scb->hscb->tag);
-			ahc_outb(ahc, SCB_CONTROL,
-				 ahc_inb(ahc, SCB_CONTROL)|MK_MESSAGE);
-		}
-
-		/*
-		 * Clear out any entries in the QINFIFO first
-		 * so we are the next SCB for this target
-		 * to run.
-		 */
-		ahc_search_qinfifo(ahc, cmd->target, cmd->channel + 'A',
-				   cmd->lun, SCB_LIST_NULL, ROLE_INITIATOR,
-				   CAM_REQUEUE_REQ, SEARCH_COMPLETE);
-		ahc_print_path(ahc, pending_scb);
-		printf("Queuing a recovery SCB\n");
-		ahc_qinfifo_requeue_tail(ahc, pending_scb);
-		ahc_outb(ahc, SCBPTR, saved_scbptr);
-		printf("%s:%d:%d:%d: Device is disconnected, re-queuing SCB\n",
-		       ahc_name(ahc), cmd->channel, cmd->target, cmd->lun);
-		wait = TRUE;
-	} else {
-		printf("%s:%d:%d:%d: Unable to deliver message\n",
-		       ahc_name(ahc), cmd->channel, cmd->target, cmd->lun);
-		retval = FAILED;
-		goto done;
-	}
-
-no_cmd:
-	/*
-	 * Our assumption is that if we don't have the command, no
-	 * recovery action was required, so we return success.  Again,
-	 * the semantics of the mid-layer recovery engine are not
-	 * well defined, so this may change in time.
-	 */
-	retval = SUCCESS;
-done:
-	if (paused)
-		ahc_unpause(ahc);
-	if (wait) {
-		struct timer_list timer;
-		int ret;
-
-		ahc_unlock(ahc, &s);
-		init_timer(&timer);
-		timer.data = (u_long)&ahc->platform_data->eh_sem;
-		timer.expires = jiffies + (5 * HZ);
-		timer.function = ahc_linux_sem_timeout;
-		add_timer(&timer);
-		printf("Recovery code sleeping\n");
-		down(&ahc->platform_data->eh_sem);
-		printf("Recovery code awake\n");
-        	ret = del_timer(&timer);
-		if (ret == 0) {
-			printf("Timer Expired\n");
-			retval = FAILED;
-		}
-		ahc_lock(ahc, &s);
-	}
-	ahc_linux_run_device_queues(ahc);
-	acmd = TAILQ_FIRST(&ahc->platform_data->completeq);
-	TAILQ_INIT(&ahc->platform_data->completeq);
-	ahc_unlock(ahc, &s);
-	if (acmd != NULL)
-		ahc_linux_run_complete_queue(ahc, acmd);
-	ahc_lock(ahc, &s);
-	return (retval);
-}
-
-/*
- * Abort the current SCSI command(s).
- */
-int
-ahc_linux_abort(Scsi_Cmnd *cmd)
-{
-	int error;
-
-	error = ahc_linux_queue_recovery_cmd(cmd, SCB_ABORT);
-	if (error != 0)
-		printf("aic7xxx_abort returns 0x%x\n", error);
-	return (error);
-}
-
-/*
- * Attempt to send a target reset message to the device that timed out.
- */
-int
-ahc_linux_dev_reset(Scsi_Cmnd *cmd)
-{
-	int error;
-
-	error = ahc_linux_queue_recovery_cmd(cmd, SCB_DEVICE_RESET);
-	if (error != 0)
-		printf("aic7xxx_dev_reset returns 0x%x\n", error);
-	return (error);
-}
-
-/*
- * Reset the SCSI bus.
- */
-int
-ahc_linux_bus_reset(Scsi_Cmnd *cmd)
-{
-	struct ahc_softc *ahc;
-	struct ahc_cmd *acmd;
-	u_long s;
-	int    found;
-
-	ahc = *(struct ahc_softc **)cmd->host->hostdata;
-	found = ahc_reset_channel(ahc, cmd->channel + 'A',
-				  /*initiate reset*/TRUE);
-	acmd = TAILQ_FIRST(&ahc->platform_data->completeq);
-	TAILQ_INIT(&ahc->platform_data->completeq);
-	ahc_unlock(ahc, &s);
-	if (bootverbose)
-		printf("%s: SCSI bus reset delivered. "
-		       "%d SCBs aborted.\n", ahc_name(ahc), found);
-
-	if (acmd != NULL)
-		ahc_linux_run_complete_queue(ahc, acmd);
-
-	ahc_lock(ahc, &s);
-	return SUCCESS;
-}
-
-/*
- * Return the disk geometry for the given SCSI device.
- */
-int
-ahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
-		sector_t capacity, int geom[])
-{
-	int	heads;
-	int	sectors;
-	int	cylinders;
-	int	ret;
-	int	extended;
-	struct	ahc_softc *ahc;
-	unsigned char *buf;
-
-	ahc = *((struct ahc_softc **)sdev->host->hostdata);
-	buf = scsi_bios_ptable(bdev);
-
-	if (buf) {
-		ret = scsi_partsize(buf, capacity,
-				    &geom[2], &geom[0], &geom[1]);
-		kfree(buf);
-		if (ret != -1)
-			return (ret);
-	}
-	heads = 64;
-	sectors = 32;
-	cylinders = (unsigned long)capacity / (heads * sectors);
-
-	if (aic7xxx_extended != 0)
-		extended = 1;
-	else if (sdev->channel == 0)
-		extended = (ahc->flags & AHC_EXTENDED_TRANS_A) != 0;
-	else
-		extended = (ahc->flags & AHC_EXTENDED_TRANS_B) != 0;
-	if (extended && cylinders >= 1024) {
-		heads = 255;
-		sectors = 63;
-		cylinders = (unsigned long)capacity / (heads * sectors);
-	}
-	geom[0] = heads;
-	geom[1] = sectors;
-	geom[2] = cylinders;
-	return (0);
-}
-
-/*
- * Free the passed in Scsi_Host memory structures prior to unloading the
- * module.
- */
-int
-ahc_linux_release(struct Scsi_Host * host)
-{
-	struct ahc_softc *ahc;
-
-	if (host != NULL) {
-
-		ahc = *(struct ahc_softc **)host->hostdata;
-		ahc_free(ahc);
-	}
-	if (TAILQ_EMPTY(&ahc_tailq)) {
-		unregister_reboot_notifier(&ahc_linux_notifier);
-#ifdef CONFIG_PCI
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
-		pci_unregister_driver(&aic7xxx_pci_driver);
-#endif
-#endif
-	}
-	return (0);
-}
-
-void
-ahc_platform_dump_card_state(struct ahc_softc *ahc)
-{
-	struct ahc_linux_device *dev;
-	int channel;
-	int maxchannel;
-	int target;
-	int maxtarget;
-	int lun;
-	int i;
-
-	maxchannel = (ahc->features & AHC_TWIN) ? 1 : 0;
-	maxtarget = (ahc->features & AHC_WIDE) ? 15 : 7;
-	for (channel = 0; channel <= maxchannel; channel++) {
-		for (target = 0; target <=maxtarget; target++) {
-			for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
-				struct ahc_cmd *acmd;
-
-				dev = ahc_linux_get_device(ahc, channel, target,
-							   lun, /*alloc*/FALSE);
-				if (dev == NULL)
-					continue;
-
-				printf("DevQ(%d:%d:%d): ",
-				       channel, target, lun);
-				i = 0;
-				TAILQ_FOREACH(acmd, &dev->busyq,
-					      acmd_links.tqe) {
-					if (i++ > 256)
-						break;
-				}
-				printf("%d waiting\n", i);
-			}
-		}
-	}
-}
-
-#if defined(MODULE) || LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
-static Scsi_Host_Template driver_template = AIC7XXX;
-Scsi_Host_Template *aic7xxx_driver_template = &driver_template;
-#include "../scsi_module.c"
-#endif
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx_linux_host.h b/drivers/scsi/aic7xxx/aic7xxx_linux_host.h
--- a/drivers/scsi/aic7xxx/aic7xxx_linux_host.h	Mon Dec 23 21:21:53 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,87 +0,0 @@
-/*
- * Adaptec AIC7xxx device driver host template for Linux.
- *
- * Copyright (c) 2000-2001 Adaptec Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_linux_host.h#5 $
- */
-
-#ifndef _AIC7XXX_LINUX_HOST_H_
-#define _AIC7XXX_LINUX_HOST_H_
-
-int		 ahc_linux_proc_info(char *, char **, off_t, int, int, int);
-int		 ahc_linux_queue(Scsi_Cmnd *, void (*)(Scsi_Cmnd *));
-int		 ahc_linux_detect(Scsi_Host_Template *);
-int		 ahc_linux_release(struct Scsi_Host *);
-const char	*ahc_linux_info(struct Scsi_Host *);
-int		 ahc_linux_biosparam(struct scsi_device *,
-			struct block_device *, sector_t, int[]);
-int		 ahc_linux_bus_reset(Scsi_Cmnd *);
-int		 ahc_linux_dev_reset(Scsi_Cmnd *);
-int		 ahc_linux_abort(Scsi_Cmnd *);
-
-#if defined(__i386__)
-#  define AIC7XXX_BIOSPARAM ahc_linux_biosparam
-#else
-#  define AIC7XXX_BIOSPARAM NULL
-#endif
-
-/*
- * Scsi_Host_Template (see hosts.h) for AIC-7xxx - some fields
- * to do with card config are filled in after the card is detected.
- */
-#define AIC7XXX	{						\
-	proc_info: ahc_linux_proc_info,				\
-	detect: ahc_linux_detect,				\
-	release: ahc_linux_release,				\
-	info: ahc_linux_info,					\
-	queuecommand: ahc_linux_queue,				\
-	eh_abort_handler: ahc_linux_abort,			\
-	eh_device_reset_handler: ahc_linux_dev_reset,		\
-	eh_bus_reset_handler: ahc_linux_bus_reset,		\
-	slave_configure: ahc_linux_slave_configure,		\
-	bios_param: AIC7XXX_BIOSPARAM,				\
-	can_queue: 253,		/* max simultaneous cmds      */\
-	this_id: -1,		/* scsi id of host adapter    */\
-	sg_tablesize: 0,	/* max scatter-gather cmds    */\
-	cmd_per_lun: 2,		/* cmds per lun		      */\
-	present: 0,		/* number of 7xxx's present   */\
-	unchecked_isa_dma: 0,	/* no memory DMA restrictions */\
-	use_clustering: ENABLE_CLUSTERING,			\
-	highmem_io: 1						\
-}
-
-#endif /* _AIC7XXX_LINUX_HOST_H_ */
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx_linux_pci.c b/drivers/scsi/aic7xxx/aic7xxx_linux_pci.c
--- a/drivers/scsi/aic7xxx/aic7xxx_linux_pci.c	Mon Dec 23 21:21:58 2002
+++ /dev/null	Wed Dec 31 16:00:00 1969
@@ -1,407 +0,0 @@
-/*
- * Linux driver attachment glue for PCI based controllers.
- *
- * Copyright (c) 2000-2001 Adaptec Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
- *    substantially similar to the "NO WARRANTY" disclaimer below
- *    ("Disclaimer") and any redistribution must be conditioned upon
- *    including a substantially similar Disclaimer requirement for further
- *    binary redistribution.
- * 3. Neither the names of the above-listed copyright holders nor the names
- *    of any contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_linux_pci.c#27 $
- */
-
-#include "aic7xxx_osm.h"
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
-struct pci_device_id
-{
-};
-#endif
-
-static int	ahc_linux_pci_dev_probe(struct pci_dev *pdev,
-					const struct pci_device_id *ent);
-static int	ahc_linux_pci_reserve_io_region(struct ahc_softc *ahc,
-						u_long *base);
-#ifdef MMAPIO
-static int	ahc_linux_pci_reserve_mem_region(struct ahc_softc *ahc,
-						 u_long *bus_addr,
-						 uint8_t **maddr);
-#endif /* MMAPIO */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
-static void	ahc_linux_pci_dev_remove(struct pci_dev *pdev);
-
-/* We do our own ID filtering.  So, grab all SCSI storage class devices. */
-static struct pci_device_id ahc_linux_pci_id_table[] = {
-	{
-		0x9004, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
-		PCI_CLASS_STORAGE_SCSI << 8, 0xFFFF00, 0
-	},
-	{
-		0x9005, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
-		PCI_CLASS_STORAGE_SCSI << 8, 0xFFFF00, 0
-	},
-	{ 0 }
-};
-MODULE_DEVICE_TABLE(pci, ahc_linux_pci_id_table);
-
-struct pci_driver aic7xxx_pci_driver = {
-	name:		"aic7xxx",
-	probe:		ahc_linux_pci_dev_probe,
-	remove:		ahc_linux_pci_dev_remove,
-	id_table:	ahc_linux_pci_id_table
-};
-
-static void
-ahc_linux_pci_dev_remove(struct pci_dev *pdev)
-{
-	struct ahc_softc *ahc;
-	struct ahc_softc *list_ahc;
-
-	/*
-	 * We should be able to just perform
-	 * the free directly, but check our
-	 * list for extra sanity.
-	 */
-	ahc = pci_get_drvdata(pdev);
-	TAILQ_FOREACH(list_ahc, &ahc_tailq, links) {
-		if (list_ahc == ahc) {
-			ahc_free(ahc);
-			break;
-		}
-	}
-}
-#endif /* !LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) */
-
-static int
-ahc_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
-{
-	char		 buf[80];
-	struct		 ahc_softc *ahc;
-	ahc_dev_softc_t	 pci;
-	struct		 ahc_pci_identity *entry;
-	char		*name;
-	int		 error;
-
-	/*
-	 * Some BIOSen report the same device multiple times.
-	 */
-	TAILQ_FOREACH(ahc, &ahc_tailq, links) {
-		struct pci_dev *probed_pdev;
-
-		probed_pdev = ahc->dev_softc;
-		if (probed_pdev->bus->number == pdev->bus->number
-		 && probed_pdev->devfn == pdev->devfn)
-			break;
-	}
-	if (ahc != NULL) {
-		/* Skip duplicate. */
-		return (-ENODEV);
-	}
-
-	pci = pdev;
-	entry = ahc_find_pci_device(pci);
-	if (entry == NULL)
-		return (-ENODEV);
-
-	/*
-	 * Allocate a softc for this card and
-	 * set it up for attachment by our
-	 * common detect routine.
-	 */
-	sprintf(buf, "ahc_pci:%d:%d:%d",
-		ahc_get_pci_bus(pci),
-		ahc_get_pci_slot(pci),
-		ahc_get_pci_function(pci));
-	name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
-	if (name == NULL)
-		return (-ENOMEM);
-	strcpy(name, buf);
-	ahc = ahc_alloc(NULL, name);
-	if (ahc == NULL)
-		return (-ENOMEM);
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
-	if (pci_enable_device(pdev)) {
-		ahc_free(ahc);
-		return (-ENODEV);
-	}
-	pci_set_master(pdev);
-
-	if (sizeof(bus_addr_t) > 4
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,3)
-	 && ahc_linux_get_memsize() > 0x80000000
-	 && pci_set_dma_mask(pdev, 0x7FFFFFFFFFULL) == 0) {
-#else
-	 && ahc_linux_get_memsize() > 0x80000000) {
-
-		ahc->dev_softc->dma_mask = 
-		    (bus_addr_t)(0x7FFFFFFFFFULL & (bus_addr_t)~0);
-#endif
-		ahc->flags |= AHC_39BIT_ADDRESSING;
-		ahc->platform_data->hw_dma_mask =
-		    (bus_addr_t)(0x7FFFFFFFFFULL & (bus_addr_t)~0);
-	}
-#endif
-	ahc->dev_softc = pci;
-	ahc->platform_data->irq = pdev->irq;
-	error = ahc_pci_config(ahc, entry);
-	if (error != 0) {
-		ahc_free(ahc);
-		return (-error);
-	}
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
-	pci_set_drvdata(pdev, ahc);
-	if (aic7xxx_detect_complete)
-		ahc_linux_register_host(ahc, aic7xxx_driver_template);
-#endif
-	return (0);
-}
-
-int
-ahc_linux_pci_probe(Scsi_Host_Template *template)
-{
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
-	return (pci_module_init(&aic7xxx_pci_driver));
-#else
-	struct pci_dev *pdev;
-	u_int class;
-	int found;
-
-	/* If we don't have a PCI bus, we can't find any adapters. */
-	if (pci_present() == 0)
-		return (0);
-
-	found = 0;
-	pdev = NULL;
-	class = PCI_CLASS_STORAGE_SCSI << 8;
-	while ((pdev = pci_find_class(class, pdev)) != NULL) {
-		ahc_dev_softc_t pci;
-		int error;
-
-		pci = pdev;
-		error = ahc_linux_pci_dev_probe(pdev, /*pci_devid*/NULL);
-		if (error == 0)
-			found++;
-	}
-	return (found);
-#endif
-}
-
-static int
-ahc_linux_pci_reserve_io_region(struct ahc_softc *ahc, u_long *base)
-{
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
-	*base = pci_resource_start(ahc->dev_softc, 0);
-#else
-	*base = ahc_pci_read_config(ahc->dev_softc, PCIR_MAPS, 4);
-	*base &= PCI_BASE_ADDRESS_IO_MASK;
-#endif
-	if (base == 0)
-		return (ENOMEM);
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
-	if (check_region(*base, 256) != 0)
-		return (ENOMEM);
-	else
-		request_region(*base, 256, "aic7xxx");
-#else
-	if (request_region(*base, 256, "aic7xxx") == 0)
-		return (ENOMEM);
-#endif
-	return (0);
-}
-
-#ifdef MMAPIO
-static int
-ahc_linux_pci_reserve_mem_region(struct ahc_softc *ahc,
-				 u_long *bus_addr,
-				 uint8_t **maddr)
-{
-	u_long	start;
-	u_long	base_page;
-	u_long	base_offset;
-	int	error;
-
-	error = 0;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
-	start = pci_resource_start(ahc->dev_softc, 1);
-	base_page = start & PAGE_MASK;
-	base_offset = start - base_page;
-#else
-	start = ahc_pci_read_config(ahc->dev_softc, PCIR_MAPS+4, 4);
-	base_offset = start & PCI_BASE_ADDRESS_MEM_MASK;
-	base_page = base_offset & PAGE_MASK;
-	base_offset -= base_page;
-#endif
-	if (start != 0) {
-		*bus_addr = start;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
-		if (request_mem_region(start, 0x1000, "aic7xxx") == 0)
-			error = ENOMEM;
-#endif
-		if (error == 0) {
-			*maddr = ioremap_nocache(base_page, base_offset + 256);
-			if (*maddr == NULL)
-				error = ENOMEM;
-			else
-				*maddr += base_offset;
-		}
-	} else
-		error = ENOMEM;
-	return (error);
-}
-#endif /* MMAPIO */
-
-int
-ahc_pci_map_registers(struct ahc_softc *ahc)
-{
-	uint32_t command;
-	u_long	 base;
-	uint8_t	*maddr;
-	int	 error;
-	int	 io_error;
-
-	/*
-	 * We always reserve both our register spaces to avoid
-	 * other devices claiming them.
-	 */
-	command = ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, 4);
-	command &= ~(PCIM_CMD_PORTEN|PCIM_CMD_MEMEN);
-	base = 0;
-	maddr = NULL;
-#ifdef MMAPIO
-	error = ahc_linux_pci_reserve_mem_region(ahc, &base, &maddr);
-	if (error == 0) {
-		ahc->platform_data->mem_busaddr = base;
-		ahc->tag = BUS_SPACE_MEMIO;
-		ahc->bsh.maddr = maddr;
-		ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND,
-				     command | PCIM_CMD_MEMEN, 4);
-
-		/*
-		 * Do a quick test to see if memory mapped
-		 * I/O is functioning correctly.
-		 */
-		if (ahc_inb(ahc, HCNTRL) == 0xFF) {
-
-			printf("aic7xxx: PCI Device %d:%d:%d "
-			       "failed memory mapped test\n",
-			       ahc_get_pci_bus(ahc->dev_softc),
-			       ahc_get_pci_slot(ahc->dev_softc),
-			       ahc_get_pci_function(ahc->dev_softc));
-			maddr = NULL;
-		} else
-			command |= PCIM_CMD_MEMEN;
-	} else {
-		printf("aic7xxx: PCI%d:%d:%d MEM region 0x%lx "
-		       "unavailable. Cannot map device.\n",
-		       ahc_get_pci_bus(ahc->dev_softc),
-		       ahc_get_pci_slot(ahc->dev_softc),
-		       ahc_get_pci_function(ahc->dev_softc),
-		       base);
-	}
-#endif
-
-	/*
-	 * We always prefer memory mapped access.  Only
-	 * complain about our ioport conflicting with
-	 * another device if we are going to use it.
-	 */
-	io_error = ahc_linux_pci_reserve_io_region(ahc, &base);
-	if (maddr == NULL) {
-		error = io_error;
-		if (error != 0) {
-			printf("aic7xxx: PCI%d:%d:%d IO region 0x%lx[0..255] "
-			       "unavailable. Cannot map device.\n",
-			       ahc_get_pci_bus(ahc->dev_softc),
-			       ahc_get_pci_slot(ahc->dev_softc),
-			       ahc_get_pci_function(ahc->dev_softc),
-			       base);
-			base = 0;
-		} else {
-			ahc->tag = BUS_SPACE_PIO;
-			ahc->bsh.ioport = base;
-			command |= PCIM_CMD_PORTEN;
-		}
-	}
-	ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, command, 4);
-	return (error);
-}
-
-int
-ahc_pci_map_int(struct ahc_softc *ahc)
-{
-	int error;
-
-	ahc->platform_data->irq = ahc->dev_softc->irq;
-	error = request_irq(ahc->platform_data->irq, ahc_linux_isr,
-			    SA_SHIRQ, "aic7xxx", ahc);
-	
-	return (-error);
-}
-
-void
-ahc_power_state_change(struct ahc_softc *ahc, ahc_power_state new_state)
-{
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
-	pci_set_power_state(ahc->dev_softc, new_state);
-#else
-	uint32_t cap;
-	u_int cap_offset;
-
-	/*
-	 * Traverse the capability list looking for
-	 * the power management capability.
-	 */
-	cap = 0;
-	cap_offset = ahc_pci_read_config(ahc->dev_softc,
-					 PCIR_CAP_PTR, /*bytes*/1);
-	while (cap_offset != 0) {
-
-		cap = ahc_pci_read_config(ahc->dev_softc,
-					  cap_offset, /*bytes*/4);
-		if ((cap & 0xFF) == 1
-		 && ((cap >> 16) & 0x3) > 0) {
-			uint32_t pm_control;
-
-			pm_control = ahc_pci_read_config(ahc->dev_softc,
-							 cap_offset + 4,
-							 /*bytes*/4);
-			pm_control &= ~0x3;
-			pm_control |= new_state;
-			ahc_pci_write_config(ahc->dev_softc,
-					     cap_offset + 4,
-					     pm_control, /*bytes*/2);
-			break;
-		}
-		cap_offset = (cap >> 8) & 0xFF;
-	}
-#endif 
-}
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c	Mon Dec 23 21:22:03 2002
@@ -0,0 +1,5136 @@
+/*
+ * Adaptec AIC7xxx device driver for Linux.
+ *
+ * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_osm.c#163 $
+ *
+ * Copyright (c) 1994 John Aycock
+ *   The University of Calgary Department of Computer Science.
+ *
+ * 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, 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; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Sources include the Adaptec 1740 driver (aha1740.c), the Ultrastor 24F
+ * driver (ultrastor.c), various Linux kernel source, the Adaptec EISA
+ * config file (!adp7771.cfg), the Adaptec AHA-2740A Series User's Guide,
+ * the Linux Kernel Hacker's Guide, Writing a SCSI Device Driver for Linux,
+ * the Adaptec 1542 driver (aha1542.c), the Adaptec EISA overlay file
+ * (adp7770.ovl), the Adaptec AHA-2740 Series Technical Reference Manual,
+ * the Adaptec AIC-7770 Data Book, the ANSI SCSI specification, the
+ * ANSI SCSI-2 specification (draft 10c), ...
+ *
+ * --------------------------------------------------------------------------
+ *
+ *  Modifications by Daniel M. Eischen (deischen@iworks.InterWorks.org):
+ *
+ *  Substantially modified to include support for wide and twin bus
+ *  adapters, DMAing of SCBs, tagged queueing, IRQ sharing, bug fixes,
+ *  SCB paging, and other rework of the code.
+ *
+ * --------------------------------------------------------------------------
+ * Copyright (c) 1994-2000 Justin T. Gibbs.
+ * Copyright (c) 2000-2001 Adaptec Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ *---------------------------------------------------------------------------
+ *
+ *  Thanks also go to (in alphabetical order) the following:
+ *
+ *    Rory Bolt     - Sequencer bug fixes
+ *    Jay Estabrook - Initial DEC Alpha support
+ *    Doug Ledford  - Much needed abort/reset bug fixes
+ *    Kai Makisara  - DMAing of SCBs
+ *
+ *  A Boot time option was also added for not resetting the scsi bus.
+ *
+ *    Form:  aic7xxx=extended
+ *           aic7xxx=no_reset
+ *           aic7xxx=verbose
+ *
+ *  Daniel M. Eischen, deischen@iworks.InterWorks.org, 1/23/97
+ *
+ *  Id: aic7xxx.c,v 4.1 1997/06/12 08:23:42 deang Exp
+ */
+
+/*
+ * Further driver modifications made by Doug Ledford <dledford@redhat.com>
+ *
+ * Copyright (c) 1997-1999 Doug Ledford
+ *
+ * These changes are released under the same licensing terms as the FreeBSD
+ * driver written by Justin Gibbs.  Please see his Copyright notice above
+ * for the exact terms and conditions covering my changes as well as the
+ * warranty statement.
+ *
+ * Modifications made to the aic7xxx.c,v 4.1 driver from Dan Eischen include
+ * but are not limited to:
+ *
+ *  1: Import of the latest FreeBSD sequencer code for this driver
+ *  2: Modification of kernel code to accomodate different sequencer semantics
+ *  3: Extensive changes throughout kernel portion of driver to improve
+ *     abort/reset processing and error hanndling
+ *  4: Other work contributed by various people on the Internet
+ *  5: Changes to printk information and verbosity selection code
+ *  6: General reliability related changes, especially in IRQ management
+ *  7: Modifications to the default probe/attach order for supported cards
+ *  8: SMP friendliness has been improved
+ *
+ */
+
+/*
+ * This is the only file where module.h should
+ * embed module global version info.
+ */
+#define AHC_MODVERSION_FILE
+
+#include "aic7xxx_osm.h"
+#include "aic7xxx_inline.h"
+#include <scsi/scsicam.h>
+
+/*
+ * Include aiclib.c as part of our
+ * "module dependencies are hard" work around.
+ */
+#include "aiclib.c"
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+#include <linux/init.h>		/* __setup */
+#endif
+
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+#include "sd.h"			/* For geometry detection */
+#endif
+
+#include <linux/mm.h>		/* For fetching system memory size */
+#include <linux/blk.h>		/* For block_size() */
+
+#define __KERNEL_SYSCALLS__
+ 
+#include <linux/unistd.h>
+static int errno;
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
+/*
+ * Lock protecting manipulation of the ahc softc list.
+ */
+spinlock_t ahc_list_spinlock;
+#endif
+
+/*
+ * To generate the correct addresses for the controller to issue
+ * on the bus.  Originally added for DEC Alpha support.
+ */
+#define VIRT_TO_BUS(a) (uint32_t)virt_to_bus((void *)(a))
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
+struct proc_dir_entry proc_scsi_aic7xxx = {
+	PROC_SCSI_AIC7XXX, 7, "aic7xxx",
+	S_IFDIR | S_IRUGO | S_IXUGO, 2,
+	0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+};
+#endif
+
+/*
+ * Set this to the delay in seconds after SCSI bus reset.
+ * Note, we honor this only for the initial bus reset.
+ * The scsi error recovery code performs its own bus settle
+ * delay handling for error recovery actions.
+ */
+#ifdef CONFIG_AIC7XXX_RESET_DELAY_MS
+#define AIC7XXX_RESET_DELAY CONFIG_AIC7XXX_RESET_DELAY_MS
+#else
+#define AIC7XXX_RESET_DELAY 5000
+#endif
+
+/*
+ * Control collection of SCSI transfer statistics for the /proc filesystem.
+ *
+ * NOTE: Do NOT enable this when running on kernels version 1.2.x and below.
+ * NOTE: This does affect performance since it has to maintain statistics.
+ */
+#ifdef CONFIG_AIC7XXX_PROC_STATS
+#define AIC7XXX_PROC_STATS
+#endif
+
+/*
+ * To change the default number of tagged transactions allowed per-device,
+ * add a line to the lilo.conf file like:
+ * append="aic7xxx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}"
+ * which will result in the first four devices on the first two
+ * controllers being set to a tagged queue depth of 32.
+ *
+ * The tag_commands is an array of 16 to allow for wide and twin adapters.
+ * Twin adapters will use indexes 0-7 for channel 0, and indexes 8-15
+ * for channel 1.
+ */
+typedef struct {
+	uint8_t tag_commands[16];	/* Allow for wide/twin adapters. */
+} adapter_tag_info_t;
+
+/*
+ * Modify this as you see fit for your system.
+ *
+ * 0			tagged queuing disabled
+ * 1 <= n <= 253	n == max tags ever dispatched.
+ *
+ * The driver will throttle the number of commands dispatched to a
+ * device if it returns queue full.  For devices with a fixed maximum
+ * queue depth, the driver will eventually determine this depth and
+ * lock it in (a console message is printed to indicate that a lock
+ * has occurred).  On some devices, queue full is returned for a temporary
+ * resource shortage.  These devices will return queue full at varying
+ * depths.  The driver will throttle back when the queue fulls occur and
+ * attempt to slowly increase the depth over time as the device recovers
+ * from the resource shortage.
+ *
+ * In this example, the first line will disable tagged queueing for all
+ * the devices on the first probed aic7xxx adapter.
+ *
+ * The second line enables tagged queueing with 4 commands/LUN for IDs
+ * (0, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
+ * driver to attempt to use up to 64 tags for ID 1.
+ *
+ * The third line is the same as the first line.
+ *
+ * The fourth line disables tagged queueing for devices 0 and 3.  It
+ * enables tagged queueing for the other IDs, with 16 commands/LUN
+ * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
+ * IDs 2, 5-7, and 9-15.
+ */
+
+/*
+ * NOTE: The below structure is for reference only, the actual structure
+ *       to modify in order to change things is just below this comment block.
+adapter_tag_info_t aic7xxx_tag_info[] =
+{
+	{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+	{{4, 64, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4}},
+	{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+	{{0, 16, 4, 0, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
+};
+*/
+
+#ifdef CONFIG_AIC7XXX_CMDS_PER_DEVICE
+#define AIC7XXX_CMDS_PER_DEVICE CONFIG_AIC7XXX_CMDS_PER_DEVICE
+#else
+#define AIC7XXX_CMDS_PER_DEVICE AHC_MAX_QUEUE
+#endif
+
+#define AIC7XXX_CONFIGED_TAG_COMMANDS {					\
+	AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE,		\
+	AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE,		\
+	AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE,		\
+	AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE,		\
+	AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE,		\
+	AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE,		\
+	AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE,		\
+	AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE		\
+}
+
+/*
+ * By default, use the number of commands specified by
+ * the users kernel configuration.
+ */
+static adapter_tag_info_t aic7xxx_tag_info[] =
+{
+	{AIC7XXX_CONFIGED_TAG_COMMANDS},
+	{AIC7XXX_CONFIGED_TAG_COMMANDS},
+	{AIC7XXX_CONFIGED_TAG_COMMANDS},
+	{AIC7XXX_CONFIGED_TAG_COMMANDS},
+	{AIC7XXX_CONFIGED_TAG_COMMANDS},
+	{AIC7XXX_CONFIGED_TAG_COMMANDS},
+	{AIC7XXX_CONFIGED_TAG_COMMANDS},
+	{AIC7XXX_CONFIGED_TAG_COMMANDS},
+	{AIC7XXX_CONFIGED_TAG_COMMANDS},
+	{AIC7XXX_CONFIGED_TAG_COMMANDS},
+	{AIC7XXX_CONFIGED_TAG_COMMANDS},
+	{AIC7XXX_CONFIGED_TAG_COMMANDS},
+	{AIC7XXX_CONFIGED_TAG_COMMANDS},
+	{AIC7XXX_CONFIGED_TAG_COMMANDS},
+	{AIC7XXX_CONFIGED_TAG_COMMANDS},
+	{AIC7XXX_CONFIGED_TAG_COMMANDS}
+};
+
+/*
+ * DV option:
+ *
+ * positive value = DV Enabled
+ * zero		  = DV Disabled
+ * negative value = DV Default for adapter type/seeprom
+ */
+#ifdef CONFIG_AIC7XXX_DV_SETTING
+#define AIC7XXX_CONFIGED_DV CONFIG_AIC7XXX_DV_SETTING
+#else
+#define AIC7XXX_CONFIGED_DV -1
+#endif
+
+static uint8_t aic7xxx_dv_settings[] =
+{
+	AIC7XXX_CONFIGED_DV,
+	AIC7XXX_CONFIGED_DV,
+	AIC7XXX_CONFIGED_DV,
+	AIC7XXX_CONFIGED_DV,
+	AIC7XXX_CONFIGED_DV,
+	AIC7XXX_CONFIGED_DV,
+	AIC7XXX_CONFIGED_DV,
+	AIC7XXX_CONFIGED_DV,
+	AIC7XXX_CONFIGED_DV,
+	AIC7XXX_CONFIGED_DV,
+	AIC7XXX_CONFIGED_DV,
+	AIC7XXX_CONFIGED_DV,
+	AIC7XXX_CONFIGED_DV,
+	AIC7XXX_CONFIGED_DV,
+	AIC7XXX_CONFIGED_DV,
+	AIC7XXX_CONFIGED_DV
+};
+
+/*
+ * There should be a specific return value for this in scsi.h, but
+ * it seems that most drivers ignore it.
+ */
+#define DID_UNDERFLOW   DID_ERROR
+
+void
+ahc_print_path(struct ahc_softc *ahc, struct scb *scb)
+{
+	printk("(scsi%d:%c:%d:%d): ",
+	       ahc->platform_data->host->host_no,
+	       scb != NULL ? SCB_GET_CHANNEL(ahc, scb) : 'X',
+	       scb != NULL ? SCB_GET_TARGET(ahc, scb) : -1,
+	       scb != NULL ? SCB_GET_LUN(scb) : -1);
+}
+
+/*
+ * XXX - these options apply unilaterally to _all_ 274x/284x/294x
+ *       cards in the system.  This should be fixed.  Exceptions to this
+ *       rule are noted in the comments.
+ */
+
+/*
+ * Skip the scsi bus reset.  Non 0 make us skip the reset at startup.  This
+ * has no effect on any later resets that might occur due to things like
+ * SCSI bus timeouts.
+ */
+static uint32_t aic7xxx_no_reset;
+
+/*
+ * Certain PCI motherboards will scan PCI devices from highest to lowest,
+ * others scan from lowest to highest, and they tend to do all kinds of
+ * strange things when they come into contact with PCI bridge chips.  The
+ * net result of all this is that the PCI card that is actually used to boot
+ * the machine is very hard to detect.  Most motherboards go from lowest
+ * PCI slot number to highest, and the first SCSI controller found is the
+ * one you boot from.  The only exceptions to this are when a controller
+ * has its BIOS disabled.  So, we by default sort all of our SCSI controllers
+ * from lowest PCI slot number to highest PCI slot number.  We also force
+ * all controllers with their BIOS disabled to the end of the list.  This
+ * works on *almost* all computers.  Where it doesn't work, we have this
+ * option.  Setting this option to non-0 will reverse the order of the sort
+ * to highest first, then lowest, but will still leave cards with their BIOS
+ * disabled at the very end.  That should fix everyone up unless there are
+ * really strange cirumstances.
+ */
+static int aic7xxx_reverse_scan = 0;
+
+/*
+ * Should we force EXTENDED translation on a controller.
+ *     0 == Use whatever is in the SEEPROM or default to off
+ *     1 == Use whatever is in the SEEPROM or default to on
+ */
+static uint32_t aic7xxx_extended = 0;
+
+/*
+ * PCI bus parity checking of the Adaptec controllers.  This is somewhat
+ * dubious at best.  To my knowledge, this option has never actually
+ * solved a PCI parity problem, but on certain machines with broken PCI
+ * chipset configurations, it can generate tons of false error messages.
+ * It's included in the driver for completeness.
+ *   0 = Shut off PCI parity check
+ *  -1 = Normal polarity pci parity checking
+ *   1 = reverse polarity pci parity checking
+ *
+ * NOTE: you can't actually pass -1 on the lilo prompt.  So, to set this
+ * variable to -1 you would actually want to simply pass the variable
+ * name without a number.  That will invert the 0 which will result in
+ * -1.
+ */
+static int aic7xxx_pci_parity = 0;
+
+/*
+ * Certain newer motherboards have put new PCI based devices into the
+ * IO spaces that used to typically be occupied by VLB or EISA cards.
+ * This overlap can cause these newer motherboards to lock up when scanned
+ * for older EISA and VLB devices.  Setting this option to non-0 will
+ * cause the driver to skip scanning for any VLB or EISA controllers and
+ * only support the PCI controllers.  NOTE: this means that if the kernel
+ * os compiled with PCI support disabled, then setting this to non-0
+ * would result in never finding any devices :)
+ */
+#ifndef CONFIG_AIC7XXX_PROBE_EISA_VL
+#define CONFIG_AIC7XXX_PROBE_EISA_VL n
+#endif
+#if CONFIG_AIC7XXX_PROBE_EISA_VL == n
+static int aic7xxx_no_probe = 1;
+#else
+static int aic7xxx_no_probe;
+#endif
+
+/*
+ * There are lots of broken chipsets in the world.  Some of them will
+ * violate the PCI spec when we issue byte sized memory writes to our
+ * controller.  I/O mapped register access, if allowed by the given
+ * platform, will work in almost all cases.
+ */
+int aic7xxx_allow_memio = 1;
+
+/*
+ * aic7xxx_detect() has been run, so register all device arrivals
+ * immediately with the system rather than deferring to the sorted
+ * attachment performed by aic7xxx_detect().
+ */
+int aic7xxx_detect_complete;
+
+/*
+ * So that we can set how long each device is given as a selection timeout.
+ * The table of values goes like this:
+ *   0 - 256ms
+ *   1 - 128ms
+ *   2 - 64ms
+ *   3 - 32ms
+ * We default to 256ms because some older devices need a longer time
+ * to respond to initial selection.
+ */
+static int aic7xxx_seltime = 0x00;
+
+/*
+ * Certain devices do not perform any aging on commands.  Should the
+ * device be saturated by commands in one portion of the disk, it is
+ * possible for transactions on far away sectors to never be serviced.
+ * To handle these devices, we can periodically send an ordered tag to
+ * force all outstanding transactions to be serviced prior to a new
+ * transaction.
+ */
+int aic7xxx_periodic_otag;
+
+/*
+ * Module information and settable options.
+ */
+#ifdef MODULE
+static char *aic7xxx = NULL;
+/*
+ * Just in case someone uses commas to separate items on the insmod
+ * command line, we define a dummy buffer here to avoid having insmod
+ * write wild stuff into our code segment
+ */
+static char dummy_buffer[60] = "Please don't trounce on me insmod!!\n";
+
+MODULE_AUTHOR("Maintainer: Justin T. Gibbs <gibbs@scsiguy.com>");
+MODULE_DESCRIPTION("Adaptec Aic77XX/78XX SCSI Host Bus Adapter driver");
+#ifdef MODULE_LICENSE
+MODULE_LICENSE("Dual BSD/GPL");
+#endif
+MODULE_PARM(aic7xxx, "s");
+MODULE_PARM_DESC(aic7xxx,
+"period delimited, options string.\n"
+"	verbose			Enable verbose/diagnostic logging\n"
+"	allow_memio		Allow device registers to be memory mapped\n"
+"	debug			Bitmask of debug values to enable\n"
+"	no_probe		Disable EISA/VLB controller probing\n"
+"	no_reset		Supress initial bus resets\n"
+"	extended		Enable extended geometry on all controllers\n"
+"	periodic_otag		Send an ordered tagged transaction\n"
+"				periodically to prevent tag starvation.\n"
+"				This may be required by some older disk\n"
+"				drives or RAID arrays.\n"
+"	reverse_scan		Sort PCI devices highest Bus/Slot to lowest\n"
+"	tag_info:<tag_str>	Set per-target tag depth\n"
+"	global_tag_depth:<int>	Global tag depth for every target\n"
+"				on every bus\n"
+"	dv:<dv_settings>	Set per-controller Domain Validation Setting.\n"
+"	seltime:<int>		Selection Timeout\n"
+"				(0/256ms,1/128ms,2/64ms,3/32ms)\n"
+"\n"
+"	Sample /etc/modules.conf line:\n"
+"		Enable verbose logging\n"
+"		Disable EISA/VLB probing\n"
+"		Set tag depth on Controller 1/Target 2 to 10 tags\n"
+"		Shorten the selection timeout to 128ms\n"
+"\n"
+"	options aic7xxx='\"verbose.no_probe.tag_info:{{}.{..10}}.seltime:1\"'\n"
+);
+#endif
+
+static void ahc_linux_handle_scsi_status(struct ahc_softc *,
+					 struct ahc_linux_device *,
+					 struct scb *);
+static void ahc_linux_queue_cmd_complete(struct ahc_softc *ahc,
+					 Scsi_Cmnd *cmd);
+static void ahc_linux_filter_inquiry(struct ahc_softc*, struct ahc_devinfo*);
+static void ahc_linux_sem_timeout(u_long arg);
+static void ahc_linux_freeze_simq(struct ahc_softc *ahc);
+static void ahc_linux_release_simq(u_long arg);
+static void ahc_linux_dev_timed_unfreeze(u_long arg);
+static int  ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag);
+static void ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc);
+static void ahc_linux_thread_run_complete_queue(struct ahc_softc *ahc);
+static void ahc_linux_start_dv(struct ahc_softc *ahc);
+static void ahc_linux_dv_timeout(struct scsi_cmnd *cmd);
+static int  ahc_linux_dv_thread(void *data);
+static void ahc_linux_dv_target(struct ahc_softc *ahc, u_int target);
+static void ahc_linux_dv_transition(struct ahc_softc *ahc,
+				    struct scsi_cmnd *cmd,
+				    struct ahc_devinfo *devinfo,
+				    struct ahc_linux_target *targ);
+static uint32_t aic_dv_error_action(struct scsi_cmnd *cmd,
+				    struct scsi_inquiry_data *inq_data);
+static void ahc_linux_dv_fill_cmd(struct ahc_softc *ahc,
+				  struct scsi_cmnd *cmd,
+				  struct ahc_devinfo *devinfo);
+static void ahc_linux_dv_inq(struct ahc_softc *ahc,
+			     struct scsi_cmnd *cmd,
+			     struct ahc_devinfo *devinfo,
+			     struct ahc_linux_target *targ,
+			     u_int request_length);
+static void ahc_linux_dv_tur(struct ahc_softc *ahc,
+			     struct scsi_cmnd *cmd,
+			     struct ahc_devinfo *devinfo);
+static void ahc_linux_dv_rebd(struct ahc_softc *ahc,
+			      struct scsi_cmnd *cmd,
+			      struct ahc_devinfo *devinfo,
+			      struct ahc_linux_target *targ);
+static void ahc_linux_dv_web(struct ahc_softc *ahc,
+			     struct scsi_cmnd *cmd,
+			     struct ahc_devinfo *devinfo,
+			     struct ahc_linux_target *targ);
+static void ahc_linux_dv_reb(struct ahc_softc *ahc,
+			     struct scsi_cmnd *cmd,
+			     struct ahc_devinfo *devinfo,
+			     struct ahc_linux_target *targ);
+static void ahc_linux_dv_su(struct ahc_softc *ahc,
+			    struct scsi_cmnd *cmd,
+			    struct ahc_devinfo *devinfo,
+			    struct ahc_linux_target *targ);
+static int ahc_linux_fallback(struct ahc_softc *ahc,
+			      struct ahc_devinfo *devinfo);
+static void ahc_linux_dv_complete(Scsi_Cmnd *cmd);
+static void ahc_linux_generate_dv_pattern(struct ahc_linux_target *targ);
+static u_int ahc_linux_user_tagdepth(struct ahc_softc *ahc,
+				     struct ahc_devinfo *devinfo);
+static u_int ahc_linux_user_dv_setting(struct ahc_softc *ahc);
+static void ahc_linux_device_queue_depth(struct ahc_softc *ahc,
+					 struct ahc_linux_device *dev);
+static struct ahc_linux_target*	ahc_linux_alloc_target(struct ahc_softc*,
+						       u_int, u_int);
+static void			ahc_linux_free_target(struct ahc_softc*,
+						      struct ahc_linux_target*);
+static struct ahc_linux_device*	ahc_linux_alloc_device(struct ahc_softc*,
+						       struct ahc_linux_target*,
+						       u_int);
+static void			ahc_linux_free_device(struct ahc_softc*,
+						      struct ahc_linux_device*);
+static void ahc_linux_run_device_queue(struct ahc_softc*,
+				       struct ahc_linux_device*);
+static void ahc_linux_setup_tag_info(char *p, char *end, char *s);
+static void ahc_linux_setup_tag_info_global(char *p);
+static void ahc_linux_setup_dv(char *p, char *end, char *s);
+static int  ahc_linux_next_unit(void);
+static void ahc_runq_tasklet(unsigned long data);
+static int  ahc_linux_halt(struct notifier_block *nb, u_long event, void *buf);
+static void ahc_schedule_completeq(struct ahc_softc *ahc, struct ahc_cmd *acmd);
+
+/********************************* Inlines ************************************/
+static __inline void ahc_schedule_runq(struct ahc_softc *ahc);
+static __inline struct ahc_linux_device*
+		     ahc_linux_get_device(struct ahc_softc *ahc, u_int channel,
+					  u_int target, u_int lun, int alloc);
+static struct ahc_cmd *ahc_linux_run_complete_queue(struct ahc_softc *ahc,
+						    struct ahc_cmd *acmd);
+static __inline void ahc_linux_check_device_queue(struct ahc_softc *ahc,
+						  struct ahc_linux_device *dev);
+static __inline struct ahc_linux_device *
+		     ahc_linux_next_device_to_run(struct ahc_softc *ahc);
+static __inline void ahc_linux_run_device_queues(struct ahc_softc *ahc);
+static __inline void ahc_linux_unmap_scb(struct ahc_softc*, struct scb*);
+
+static __inline int ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb,
+		 		      struct ahc_dma_seg *sg,
+				      bus_addr_t addr, bus_size_t len);
+
+static void
+ahc_schedule_completeq(struct ahc_softc *ahc, struct ahc_cmd *acmd)
+{
+	while (acmd != NULL) {
+		struct ahc_completeq *completeq;
+		struct ahc_cmd *list_cmd;
+		struct ahc_cmd *next_cmd;
+
+		next_cmd = TAILQ_NEXT(acmd, acmd_links.tqe);
+		completeq = &ahc->platform_data->completeq;
+		list_cmd = TAILQ_FIRST(completeq);
+		while (list_cmd != NULL
+		    && acmd_scsi_cmd(list_cmd).serial_number
+		     < acmd_scsi_cmd(acmd).serial_number)
+			list_cmd = TAILQ_NEXT(list_cmd, acmd_links.tqe);
+		if (list_cmd != NULL)
+			TAILQ_INSERT_BEFORE(list_cmd, acmd, acmd_links.tqe);
+		else
+			TAILQ_INSERT_TAIL(completeq, acmd, acmd_links.tqe);
+		acmd = next_cmd;
+	}
+	if ((ahc->platform_data->flags & AHC_RUN_CMPLT_Q_TIMER) == 0) {
+		ahc->platform_data->flags |= AHC_RUN_CMPLT_Q_TIMER;
+		ahc->platform_data->completeq_timer.expires = jiffies;
+		add_timer(&ahc->platform_data->completeq_timer);
+	}
+}
+
+static __inline void
+ahc_schedule_runq(struct ahc_softc *ahc)
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+	tasklet_schedule(&ahc->platform_data->runq_tasklet);
+#else
+	/*
+	 * Tasklets are not available, so run inline.
+	 */
+	ahc_runq_tasklet((unsigned long)ahc);
+#endif
+}
+
+static __inline struct ahc_linux_device*
+ahc_linux_get_device(struct ahc_softc *ahc, u_int channel, u_int target,
+		     u_int lun, int alloc)
+{
+	struct ahc_linux_target *targ;
+	struct ahc_linux_device *dev;
+	u_int target_offset;
+
+	target_offset = target;
+	if (channel != 0)
+		target_offset += 8;
+	targ = ahc->platform_data->targets[target_offset];
+	if (targ == NULL) {
+		if (alloc != 0) {
+			targ = ahc_linux_alloc_target(ahc, channel, target);
+			if (targ == NULL)
+				return (NULL);
+		} else
+			return (NULL);
+	}
+	dev = targ->devices[lun];
+	if (dev == NULL && alloc != 0)
+		dev = ahc_linux_alloc_device(ahc, targ, lun);
+	return (dev);
+}
+
+#define AHC_LINUX_MAX_RETURNED_ERRORS 4
+static struct ahc_cmd *
+ahc_linux_run_complete_queue(struct ahc_softc *ahc, struct ahc_cmd *acmd)
+{	
+	u_long	done_flags;
+	int	with_errors;
+
+	ahc_done_lock(ahc, &done_flags);
+	with_errors = 0;
+	while (acmd != NULL) {
+		Scsi_Cmnd *cmd;
+
+		cmd = &acmd_scsi_cmd(acmd);
+		acmd = TAILQ_NEXT(acmd, acmd_links.tqe);
+		cmd->host_scribble = NULL;
+		if (ahc_cmd_get_transaction_status(cmd) != DID_OK
+		 || (cmd->result & 0xFF) != SCSI_STATUS_OK)
+			with_errors++;
+
+		cmd->scsi_done(cmd);
+
+		if (with_errors > AHC_LINUX_MAX_RETURNED_ERRORS) {
+			/*
+			 * Linux uses stack recursion to requeue
+			 * commands that need to be retried.  Avoid
+			 * blowing out the stack by "spoon feeding"
+			 * commands that completed with error back
+			 * the operating system in case they are going
+			 * to be retried. "ick"
+			 */
+			break;
+		}
+	}
+	ahc_done_unlock(ahc, &done_flags);
+	return (acmd);
+}
+
+static __inline void
+ahc_linux_check_device_queue(struct ahc_softc *ahc,
+			     struct ahc_linux_device *dev)
+{
+	if ((dev->flags & AHC_DEV_FREEZE_TIL_EMPTY) != 0
+	 && dev->active == 0) {
+		dev->flags &= ~AHC_DEV_FREEZE_TIL_EMPTY;
+		dev->qfrozen--;
+	}
+
+	if (TAILQ_FIRST(&dev->busyq) == NULL
+	 || dev->openings == 0 || dev->qfrozen != 0)
+		return;
+
+	ahc_linux_run_device_queue(ahc, dev);
+}
+
+static __inline struct ahc_linux_device *
+ahc_linux_next_device_to_run(struct ahc_softc *ahc)
+{
+	
+	if ((ahc->flags & AHC_RESOURCE_SHORTAGE) != 0
+	 || (ahc->platform_data->qfrozen != 0
+	  && AHC_DV_SIMQ_FROZEN(ahc) == 0))
+		return (NULL);
+	return (TAILQ_FIRST(&ahc->platform_data->device_runq));
+}
+
+static __inline void
+ahc_linux_run_device_queues(struct ahc_softc *ahc)
+{
+	struct ahc_linux_device *dev;
+
+	while ((dev = ahc_linux_next_device_to_run(ahc)) != NULL) {
+		TAILQ_REMOVE(&ahc->platform_data->device_runq, dev, links);
+		dev->flags &= ~AHC_DEV_ON_RUN_LIST;
+		ahc_linux_check_device_queue(ahc, dev);
+	}
+}
+
+static __inline void
+ahc_linux_unmap_scb(struct ahc_softc *ahc, struct scb *scb)
+{
+	Scsi_Cmnd *cmd;
+
+	cmd = scb->io_ctx;
+	ahc_sync_sglist(ahc, scb, BUS_DMASYNC_POSTWRITE);
+	if (cmd->use_sg != 0) {
+		struct scatterlist *sg;
+
+		sg = (struct scatterlist *)cmd->request_buffer;
+		pci_unmap_sg(ahc->dev_softc, sg, cmd->use_sg,
+			     scsi_to_pci_dma_dir(cmd->sc_data_direction));
+	} else if (cmd->request_bufflen != 0) {
+		pci_unmap_single(ahc->dev_softc,
+				 scb->platform_data->buf_busaddr,
+				 cmd->request_bufflen,
+				 scsi_to_pci_dma_dir(cmd->sc_data_direction));
+	}
+}
+
+static __inline int
+ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb,
+		  struct ahc_dma_seg *sg, bus_addr_t addr, bus_size_t len)
+{
+	int	 consumed;
+
+	if ((scb->sg_count + 1) > AHC_NSEG)
+		panic("Too few segs for dma mapping.  "
+		      "Increase AHC_NSEG\n");
+
+	consumed = 1;
+	sg->addr = ahc_htole32(addr & 0xFFFFFFFF);
+	scb->platform_data->xfer_len += len;
+	if (sizeof(bus_addr_t) > 4
+	 && (ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
+		/*
+		 * Due to DAC restrictions, we can't
+		 * cross a 4GB boundary.
+		 */
+		if ((addr ^ (addr + len - 1)) & ~0xFFFFFFFF) {
+			struct	 ahc_dma_seg *next_sg;
+			uint32_t next_len;
+
+			printf("Crossed Seg\n");
+			if ((scb->sg_count + 2) > AHC_NSEG)
+				panic("Too few segs for dma mapping.  "
+				      "Increase AHC_NSEG\n");
+
+			consumed++;
+			next_sg = sg + 1;
+			next_sg->addr = 0;
+			next_len = 0x100000000 - (addr & 0xFFFFFFFF);
+			len -= next_len;
+			next_len |= ((addr >> 8) + 0x1000000) & 0x7F000000;
+			next_sg->len = ahc_htole32(next_len);
+		}
+		len |= (addr >> 8) & 0x7F000000;
+	}
+	sg->len = ahc_htole32(len);
+	return (consumed);
+}
+
+/************************  Host template entry points *************************/
+static int	   ahc_linux_detect(Scsi_Host_Template *);
+static int	   ahc_linux_release(struct Scsi_Host *);
+static int	   ahc_linux_queue(Scsi_Cmnd *, void (*)(Scsi_Cmnd *));
+static const char *ahc_linux_info(struct Scsi_Host *);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+static int	   ahc_linux_slave_alloc(Scsi_Device *);
+static int	   ahc_linux_slave_configure(Scsi_Device *);
+static void	   ahc_linux_slave_destroy(Scsi_Device *);
+static int	   ahc_linux_biosparam(struct scsi_device*,
+				       struct block_device*,
+				       sector_t, int[]);
+#else
+static void	   ahc_linux_select_queue_depth(struct Scsi_Host *host,
+						Scsi_Device *scsi_devs);
+static int	   ahc_linux_biosparam(Disk *, kdev_t, int[]);
+#endif
+static int	   ahc_linux_bus_reset(Scsi_Cmnd *);
+static int	   ahc_linux_dev_reset(Scsi_Cmnd *);
+static int	   ahc_linux_abort(Scsi_Cmnd *);
+
+/*
+ * Try to detect an Adaptec 7XXX controller.
+ */
+static int
+ahc_linux_detect(Scsi_Host_Template *template)
+{
+	struct	ahc_softc *ahc;
+	int     found;
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	/*
+	 * It is a bug that the upper layer takes
+	 * this lock just prior to calling us.
+	 */
+	spin_unlock_irq(&io_request_lock);
+#endif
+
+	/*
+	 * Sanity checking of Linux SCSI data structures so
+	 * that some of our hacks^H^H^H^H^Hassumptions aren't
+	 * violated.
+	 */
+	if (offsetof(struct ahc_cmd_internal, end)
+	  > offsetof(struct scsi_cmnd, host_scribble)) {
+		printf("ahc_linux_detect: SCSI data structures changed.\n");
+		printf("ahc_linux_detect: Unable to attach\n");
+		return (0);
+	}
+#ifdef MODULE
+	/*
+	 * If we've been passed any parameters, process them now.
+	 */
+	if (aic7xxx)
+		aic7xxx_setup(aic7xxx);
+	if (dummy_buffer[0] != 'P')
+		printk(KERN_WARNING
+"aic7xxx: Please read the file /usr/src/linux/drivers/scsi/README.aic7xxx\n"
+"aic7xxx: to see the proper way to specify options to the aic7xxx module\n"
+"aic7xxx: Specifically, don't use any commas when passing arguments to\n"
+"aic7xxx: insmod or else it might trash certain memory areas.\n");
+#endif
+
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0)
+	template->proc_name = "aic7xxx";
+#else
+	template->proc_dir = &proc_scsi_aic7xxx;
+#endif
+
+	/*
+	 * Initialize our softc list lock prior to
+	 * probing for any adapters.
+	 */
+	ahc_list_lockinit();
+
+#ifdef CONFIG_PCI
+	ahc_linux_pci_probe(template);
+#endif
+
+	if (aic7xxx_no_probe == 0)
+		aic7770_linux_probe(template);
+
+	/*
+	 * Register with the SCSI layer all
+	 * controllers we've found.
+	 */
+	found = 0;
+	TAILQ_FOREACH(ahc, &ahc_tailq, links) {
+
+		if (ahc_linux_register_host(ahc, template) == 0)
+			found++;
+	}
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	spin_lock_irq(&io_request_lock);
+#endif
+	aic7xxx_detect_complete++;
+	return (found);
+}
+
+/*
+ * Free the passed in Scsi_Host memory structures prior to unloading the
+ * module.
+ */
+int
+ahc_linux_release(struct Scsi_Host * host)
+{
+	struct ahc_softc *ahc;
+	u_long l;
+
+	ahc_list_lock(&l);
+	if (host != NULL) {
+
+		/*
+		 * We should be able to just perform
+		 * the free directly, but check our
+		 * list for extra sanity.
+		 */
+		ahc = ahc_find_softc(*(struct ahc_softc **)host->hostdata);
+		if (ahc != NULL) {
+			u_long s;
+
+			ahc_lock(ahc, &s);
+			ahc_intr_enable(ahc, FALSE);
+			ahc_unlock(ahc, &s);
+			ahc_free(ahc);
+		}
+	}
+	ahc_list_unlock(&l);
+	return (0);
+}
+
+/*
+ * Return a string describing the driver.
+ */
+static const char *
+ahc_linux_info(struct Scsi_Host *host)
+{
+	static char buffer[512];
+	char	ahc_info[256];
+	char   *bp;
+	struct ahc_softc *ahc;
+
+	bp = &buffer[0];
+	ahc = *(struct ahc_softc **)host->hostdata;
+	memset(bp, 0, sizeof(buffer));
+	strcpy(bp, "Adaptec AIC7XXX EISA/VLB/PCI SCSI HBA DRIVER, Rev ");
+	strcat(bp, AIC7XXX_DRIVER_VERSION);
+	strcat(bp, "\n");
+	strcat(bp, "        <");
+	strcat(bp, ahc->description);
+	strcat(bp, ">\n");
+	strcat(bp, "        ");
+	ahc_controller_info(ahc, ahc_info);
+	strcat(bp, ahc_info);
+	strcat(bp, "\n");
+
+	return (bp);
+}
+
+/*
+ * Queue an SCB to the controller.
+ */
+static int
+ahc_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
+{
+	struct	 ahc_softc *ahc;
+	struct	 ahc_linux_device *dev;
+	u_long	 flags;
+
+	ahc = *(struct ahc_softc **)cmd->host->hostdata;
+
+	/*
+	 * Save the callback on completion function.
+	 */
+	cmd->scsi_done = scsi_done;
+
+	ahc_midlayer_entrypoint_lock(ahc, &flags);
+
+	/*
+	 * Close the race of a command that was in the process of
+	 * being queued to us just as our simq was frozen.  Let
+	 * DV commands through so long as we are only frozen to
+	 * perform DV.
+	 */
+	if (ahc->platform_data->qfrozen != 0
+	 && AHC_DV_CMD(cmd) == 0) {
+
+		ahc_cmd_set_transaction_status(cmd, CAM_REQUEUE_REQ);
+		ahc_linux_queue_cmd_complete(ahc, cmd);
+		ahc_schedule_completeq(ahc, NULL);
+		ahc_midlayer_entrypoint_unlock(ahc, &flags);
+		return (0);
+	}
+	dev = ahc_linux_get_device(ahc, cmd->channel, cmd->target,
+				   cmd->lun, /*alloc*/TRUE);
+	if (dev == NULL) {
+		ahc_midlayer_entrypoint_unlock(ahc, &flags);
+		printf("aic7xxx_linux_queue: Unable to allocate device!\n");
+		return (-ENOMEM);
+	}
+	cmd->result = CAM_REQ_INPROG << 16;
+	TAILQ_INSERT_TAIL(&dev->busyq, (struct ahc_cmd *)cmd, acmd_links.tqe);
+	if ((dev->flags & AHC_DEV_ON_RUN_LIST) == 0) {
+		TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq, dev, links);
+		dev->flags |= AHC_DEV_ON_RUN_LIST;
+		ahc_linux_run_device_queues(ahc);
+	}
+	ahc_midlayer_entrypoint_unlock(ahc, &flags);
+	return (0);
+}
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+static int
+ahc_linux_slave_alloc(Scsi_Device *device)
+{
+	struct	ahc_softc *ahc;
+
+	ahc = *((struct ahc_softc **)device->host->hostdata);
+	if (bootverbose)
+		printf("%s: Slave Alloc %d\n", ahc_name(ahc), device->id);
+	return (0);
+}
+
+static int
+ahc_linux_slave_configure(Scsi_Device *device)
+{
+	struct	ahc_softc *ahc;
+	struct	ahc_linux_device *dev;
+	u_long	flags;
+
+	ahc = *((struct ahc_softc **)device->host->hostdata);
+	if (bootverbose)
+		printf("%s: Slave Configure %d\n", ahc_name(ahc), device->id);
+	ahc_midlayer_entrypoint_lock(ahc, &flags);
+	/*
+	 * Since Linux has attached to the device, configure
+	 * it so we don't free and allocate the device
+	 * structure on every command.
+	 */
+	dev = ahc_linux_get_device(ahc, device->channel,
+				   device->id, device->lun,
+				   /*alloc*/TRUE);
+	if (dev != NULL) {
+		dev->flags &= ~AHC_DEV_UNCONFIGURED;
+		dev->scsi_device = device;
+		ahc_linux_device_queue_depth(ahc, dev);
+	}
+	ahc_midlayer_entrypoint_unlock(ahc, &flags);
+	return (0);
+}
+
+static void
+ahc_linux_slave_destroy(Scsi_Device *device)
+{
+	struct	ahc_softc *ahc;
+	struct	ahc_linux_device *dev;
+	u_long	flags;
+
+	ahc = *((struct ahc_softc **)device->host->hostdata);
+	if (bootverbose)
+		printf("%s: Slave Destroy %d\n", ahc_name(ahc), device->id);
+	ahc_midlayer_entrypoint_lock(ahc, &flags);
+	dev = ahc_linux_get_device(ahc, device->channel,
+				   device->id, device->lun,
+					   /*alloc*/FALSE);
+	/*
+	 * Filter out "silly" deletions of real devices by only
+	 * deleting devices that have had slave_configure()
+	 * called on them.  All other devices that have not
+	 * been configured will automatically be deleted by
+	 * the refcounting process.
+	 */
+	if (dev != NULL
+	 && (dev->flags & AHC_DEV_SLAVE_CONFIGURED) != 0) {
+		dev->flags |= AHC_DEV_UNCONFIGURED;
+		if (TAILQ_EMPTY(&dev->busyq)
+		 && dev->active == 0)
+			ahc_linux_free_device(ahc, dev);
+	}
+	ahc_midlayer_entrypoint_unlock(ahc, &flags);
+}
+#else
+/*
+ * Sets the queue depth for each SCSI device hanging
+ * off the input host adapter.
+ */
+static void
+ahc_linux_select_queue_depth(struct Scsi_Host * host,
+			     Scsi_Device * scsi_devs)
+{
+	Scsi_Device *device;
+	struct	ahc_softc *ahc;
+	u_long	flags;
+
+	ahc = *((struct ahc_softc **)host->hostdata);
+	ahc_midlayer_entrypoint_lock(ahc, &flags);
+	for (device = scsi_devs; device != NULL; device = device->next) {
+		if (device->host == host) {
+			struct	 ahc_linux_device *dev;
+
+			/*
+			 * Since Linux has attached to the device, configure
+			 * it so we don't free and allocate the device
+			 * structure on every command.
+			 */
+			dev = ahc_linux_get_device(ahc, device->channel,
+						   device->id, device->lun,
+						   /*alloc*/TRUE);
+			if (dev != NULL) {
+				dev->flags &= ~AHC_DEV_UNCONFIGURED;
+				dev->scsi_device = device;
+				ahc_linux_device_queue_depth(ahc, dev);
+				device->queue_depth = dev->openings
+						    + dev->active;
+				if ((dev->flags & (AHC_DEV_Q_BASIC
+						| AHC_DEV_Q_TAGGED)) == 0) {
+					/*
+					 * We allow the OS to queue 2 untagged
+					 * transactions to us at any time even
+					 * though we can only execute them
+					 * serially on the controller/device.
+					 * This should remove some latency.
+					 */
+					device->queue_depth = 2;
+				}
+			}
+		}
+	}
+	ahc_midlayer_entrypoint_unlock(ahc, &flags);
+}
+#endif
+
+/*
+ * Return the disk geometry for the given SCSI device.
+ */
+static int
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+ahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
+		    sector_t capacity, int geom[])
+{
+	uint8_t *bh;
+#else
+ahc_linux_biosparam(Disk *disk, kdev_t dev, int geom[])
+{
+	struct	scsi_device *sdev = disk->device;
+	u_long	capacity = disk->capacity;
+	struct	buffer_head *bh;
+#endif
+	int	 heads;
+	int	 sectors;
+	int	 cylinders;
+	int	 ret;
+	int	 extended;
+	struct	 ahc_softc *ahc;
+	u_int	 channel;
+
+	ahc = *((struct ahc_softc **)sdev->host->hostdata);
+	channel = sdev->channel;
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+	bh = scsi_bios_ptable(bdev);
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,17)
+	bh = bread(MKDEV(MAJOR(dev), MINOR(dev) & ~0xf), 0, block_size(dev));
+#else
+	bh = bread(MKDEV(MAJOR(dev), MINOR(dev) & ~0xf), 0, 1024);
+#endif
+
+	if (bh) {
+		ret = scsi_partsize(bh, capacity,
+				    &geom[2], &geom[0], &geom[1]);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+		kfree(bh);
+#else
+		brelse(bh);
+#endif
+		if (ret != -1)
+			return (ret);
+	}
+	heads = 64;
+	sectors = 32;
+	cylinders = aic_sector_div(capacity, heads, sectors);
+
+	if (aic7xxx_extended != 0)
+		extended = 1;
+	else if (channel == 0)
+		extended = (ahc->flags & AHC_EXTENDED_TRANS_A) != 0;
+	else
+		extended = (ahc->flags & AHC_EXTENDED_TRANS_B) != 0;
+	if (extended && cylinders >= 1024) {
+		heads = 255;
+		sectors = 63;
+		cylinders = aic_sector_div(capacity, heads, sectors);
+	}
+	geom[0] = heads;
+	geom[1] = sectors;
+	geom[2] = cylinders;
+	return (0);
+}
+
+/*
+ * Abort the current SCSI command(s).
+ */
+static int
+ahc_linux_abort(Scsi_Cmnd *cmd)
+{
+	int error;
+
+	error = ahc_linux_queue_recovery_cmd(cmd, SCB_ABORT);
+	if (error != 0)
+		printf("aic7xxx_abort returns 0x%x\n", error);
+	return (error);
+}
+
+/*
+ * Attempt to send a target reset message to the device that timed out.
+ */
+static int
+ahc_linux_dev_reset(Scsi_Cmnd *cmd)
+{
+	int error;
+
+	error = ahc_linux_queue_recovery_cmd(cmd, SCB_DEVICE_RESET);
+	if (error != 0)
+		printf("aic7xxx_dev_reset returns 0x%x\n", error);
+	return (error);
+}
+
+/*
+ * Reset the SCSI bus.
+ */
+static int
+ahc_linux_bus_reset(Scsi_Cmnd *cmd)
+{
+	struct ahc_softc *ahc;
+	struct ahc_cmd *acmd;
+	u_long s;
+	int    found;
+
+	ahc = *(struct ahc_softc **)cmd->host->hostdata;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	spin_unlock_irq(&io_request_lock);
+#endif
+	ahc_midlayer_entrypoint_lock(ahc, &s);
+	found = ahc_reset_channel(ahc, cmd->channel + 'A',
+				  /*initiate reset*/TRUE);
+	acmd = TAILQ_FIRST(&ahc->platform_data->completeq);
+	TAILQ_INIT(&ahc->platform_data->completeq);
+	ahc_midlayer_entrypoint_unlock(ahc, &s);
+	if (bootverbose)
+		printf("%s: SCSI bus reset delivered. "
+		       "%d SCBs aborted.\n", ahc_name(ahc), found);
+
+	if (acmd != NULL) {
+		acmd = ahc_linux_run_complete_queue(ahc, acmd);
+		if (acmd != NULL) {
+			ahc_midlayer_entrypoint_lock(ahc, &s);
+			ahc_schedule_completeq(ahc, acmd);
+			ahc_midlayer_entrypoint_unlock(ahc, &s);
+		}
+	}
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	spin_lock_irq(&io_request_lock);
+#endif
+	return SUCCESS;
+}
+
+Scsi_Host_Template aic7xxx_driver_template = {
+	.proc_info		= ahc_linux_proc_info,
+	.detect			= ahc_linux_detect,
+	.release		= ahc_linux_release,
+	.info			= ahc_linux_info,
+	.queuecommand		= ahc_linux_queue,
+	.eh_abort_handler	= ahc_linux_abort,
+	.eh_device_reset_handler = ahc_linux_dev_reset,
+	.eh_bus_reset_handler	= ahc_linux_bus_reset,
+#if defined(__i386__)
+	.bios_param		= ahc_linux_biosparam,
+#endif
+	.can_queue		= AHC_MAX_QUEUE,
+	.this_id		= -1,
+	.sg_tablesize		= AHC_NSEG,
+	.cmd_per_lun		= 2,
+	.use_clustering		= ENABLE_CLUSTERING,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,7)
+	/*
+	 * We can only map 16MB per-SG
+	 * so create a sector limit of
+	 * "16MB" in 2K sectors.
+	 */
+	.max_sectors		= 8192,
+#endif
+#if defined CONFIG_HIGHIO
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
+/* Assume RedHat Distribution with its different HIGHIO conventions. */
+	.can_dma_32		= 1,
+	.single_sg_okay		= 1,
+#else
+	.highmem_io		= 1,
+#endif
+#endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+	.name			= "aic7xxx",
+	.slave_alloc		= ahc_linux_slave_alloc,
+	.slave_configure	= ahc_linux_slave_configure,
+	.slave_destroy		= ahc_linux_slave_destroy,
+#else
+	.select_queue_depths	= ahc_linux_select_queue_depth,
+	.use_new_eh_code	= 1,
+#endif
+};
+
+#define driver_template aic7xxx_driver_template
+#include "scsi_module.c"
+
+/**************************** Tasklet Handler *********************************/
+
+static void
+ahc_runq_tasklet(unsigned long data)
+{
+	struct ahc_softc* ahc;
+	struct ahc_linux_device *dev;
+	u_long flags;
+
+	ahc = (struct ahc_softc *)data;
+	ahc_lock(ahc, &flags);
+	while ((dev = ahc_linux_next_device_to_run(ahc)) != NULL) {
+	
+		TAILQ_REMOVE(&ahc->platform_data->device_runq, dev, links);
+		dev->flags &= ~AHC_DEV_ON_RUN_LIST;
+		ahc_linux_check_device_queue(ahc, dev);
+		/* Yeild to our interrupt handler */
+		ahc_unlock(ahc, &flags);
+		ahc_lock(ahc, &flags);
+	}
+	ahc_unlock(ahc, &flags);
+}
+
+/************************ Shutdown/halt/reboot hook ***************************/
+#include <linux/notifier.h>
+#include <linux/reboot.h>
+
+static struct notifier_block ahc_linux_notifier = {
+	ahc_linux_halt, NULL, 0
+};
+
+static int ahc_linux_halt(struct notifier_block *nb, u_long event, void *buf)
+{
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	struct ahc_softc *ahc;
+
+	/*
+	 * In 2.5.X, this is called prior to the filesystems
+	 * being synced and the SCSI layer being properly
+	 * shutdown.  A different API is required there,
+	 * but the device hooks for this don't quite look
+	 * right.
+	 */
+	if (event == SYS_DOWN || event == SYS_HALT) {
+		TAILQ_FOREACH(ahc, &ahc_tailq, links) {
+			ahc_shutdown(ahc);
+		}
+	}
+#endif
+	return (NOTIFY_OK);
+}
+
+/******************************** Macros **************************************/
+#define BUILD_SCSIID(ahc, cmd)						\
+	((((cmd)->target << TID_SHIFT) & TID)				\
+	| (((cmd)->channel == 0) ? (ahc)->our_id : (ahc)->our_id_b)	\
+	| (((cmd)->channel == 0) ? 0 : TWIN_CHNLB))
+
+/******************************** Bus DMA *************************************/
+int
+ahc_dma_tag_create(struct ahc_softc *ahc, bus_dma_tag_t parent,
+		   bus_size_t alignment, bus_size_t boundary,
+		   bus_addr_t lowaddr, bus_addr_t highaddr,
+		   bus_dma_filter_t *filter, void *filterarg,
+		   bus_size_t maxsize, int nsegments,
+		   bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
+{
+	bus_dma_tag_t dmat;
+
+	dmat = malloc(sizeof(*dmat), M_DEVBUF, M_NOWAIT);
+	if (dmat == NULL)
+		return (ENOMEM);
+
+	/*
+	 * Linux is very simplistic about DMA memory.  For now don't
+	 * maintain all specification information.  Once Linux supplies
+	 * better facilities for doing these operations, or the
+	 * needs of this particular driver change, we might need to do
+	 * more here.
+	 */
+	dmat->alignment = alignment;
+	dmat->boundary = boundary;
+	dmat->maxsize = maxsize;
+	*ret_tag = dmat;
+	return (0);
+}
+
+void
+ahc_dma_tag_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat)
+{
+	free(dmat, M_DEVBUF);
+}
+
+int
+ahc_dmamem_alloc(struct ahc_softc *ahc, bus_dma_tag_t dmat, void** vaddr,
+		 int flags, bus_dmamap_t *mapp)
+{
+	bus_dmamap_t map;
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+	map = malloc(sizeof(*map), M_DEVBUF, M_NOWAIT);
+	if (map == NULL)
+		return (ENOMEM);
+	/*
+	 * Although we can dma data above 4GB, our
+	 * "consistent" memory is below 4GB for
+	 * space efficiency reasons (only need a 4byte
+	 * address).  For this reason, we have to reset
+	 * our dma mask when doing allocations.
+	 */
+	if (ahc->dev_softc != NULL)
+		ahc_pci_set_dma_mask(ahc->dev_softc, 0xFFFFFFFF);
+	*vaddr = pci_alloc_consistent(ahc->dev_softc,
+				      dmat->maxsize, &map->bus_addr);
+	if (ahc->dev_softc != NULL)
+		ahc_pci_set_dma_mask(ahc->dev_softc,
+				     ahc->platform_data->hw_dma_mask);
+#else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) */
+	/*
+	 * At least in 2.2.14, malloc is a slab allocator so all
+	 * allocations are aligned.  We assume for these kernel versions
+	 * that all allocations will be bellow 4Gig, physically contiguous,
+	 * and accessable via DMA by the controller.
+	 */
+	map = NULL; /* No additional information to store */
+	*vaddr = malloc(dmat->maxsize, M_DEVBUF, M_NOWAIT);
+#endif
+	if (*vaddr == NULL)
+		return (ENOMEM);
+	*mapp = map;
+	return(0);
+}
+
+void
+ahc_dmamem_free(struct ahc_softc *ahc, bus_dma_tag_t dmat,
+		void* vaddr, bus_dmamap_t map)
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+	pci_free_consistent(ahc->dev_softc, dmat->maxsize,
+			    vaddr, map->bus_addr);
+#else
+	free(vaddr, M_DEVBUF);
+#endif
+}
+
+int
+ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map,
+		void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
+		void *cb_arg, int flags)
+{
+	/*
+	 * Assume for now that this will only be used during
+	 * initialization and not for per-transaction buffer mapping.
+	 */
+	bus_dma_segment_t stack_sg;
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+	stack_sg.ds_addr = map->bus_addr;
+#else
+	stack_sg.ds_addr = VIRT_TO_BUS(buf);
+#endif
+	stack_sg.ds_len = dmat->maxsize;
+	cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
+	return (0);
+}
+
+void
+ahc_dmamap_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map)
+{
+	/*
+	 * The map may is NULL in our < 2.3.X implementation.
+	 */
+	if (map != NULL)
+		free(map, M_DEVBUF);
+}
+
+int
+ahc_dmamap_unload(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map)
+{
+	/* Nothing to do */
+	return (0);
+}
+
+/********************* Platform Dependent Functions ***************************/
+int
+ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc)
+{
+	int	value;
+	int	rvalue;
+	int	lvalue;
+
+	/*
+	 * Under Linux, cards are ordered as follows:
+	 *	1) VLB/EISA BIOS enabled devices sorted by BIOS address.
+	 *	2) PCI devices with BIOS enabled sorted by bus/slot/func.
+	 *	3) All remaining VLB/EISA devices sorted by ioport.
+	 *	4) All remaining PCI devices sorted by bus/slot/func.
+	 */
+	value = (lahc->flags & AHC_BIOS_ENABLED)
+	      - (rahc->flags & AHC_BIOS_ENABLED);
+	if (value != 0)
+		/* Controllers with BIOS enabled have a *higher* priority */
+		return (-value);
+
+	/*
+	 * Same BIOS setting, now sort based on bus type.
+	 * EISA and VL controllers sort together.  EISA/VL
+	 * have higher priority than PCI.
+	 */
+	rvalue = (rahc->chip & AHC_BUS_MASK);
+ 	if (rvalue == AHC_VL)
+		rvalue = AHC_EISA;
+	lvalue = (lahc->chip & AHC_BUS_MASK);
+ 	if (lvalue == AHC_VL)
+		lvalue = AHC_EISA;
+	value = lvalue - rvalue;
+	if (value != 0)
+		return (value);
+
+	/* Still equal.  Sort by BIOS address, ioport, or bus/slot/func. */
+	switch (rvalue) {
+	case AHC_PCI:
+	{
+		char primary_channel;
+
+		if (aic7xxx_reverse_scan != 0)
+			value = ahc_get_pci_bus(rahc->dev_softc)
+			      - ahc_get_pci_bus(lahc->dev_softc);
+		else
+			value = ahc_get_pci_bus(lahc->dev_softc)
+			      - ahc_get_pci_bus(rahc->dev_softc);
+		if (value != 0)
+			break;
+		if (aic7xxx_reverse_scan != 0)
+			value = ahc_get_pci_slot(rahc->dev_softc)
+			      - ahc_get_pci_slot(lahc->dev_softc);
+		else
+			value = ahc_get_pci_slot(lahc->dev_softc)
+			      - ahc_get_pci_slot(rahc->dev_softc);
+		if (value != 0)
+			break;
+		/*
+		 * On multi-function devices, the user can choose
+		 * to have function 1 probed before function 0.
+		 * Give whichever channel is the primary channel
+		 * the lowest priority.
+		 */
+		primary_channel = (lahc->flags & AHC_PRIMARY_CHANNEL) + 'A';
+		value = 1;
+		if (lahc->channel == primary_channel)
+			value = -1;
+		break;
+	}
+	case AHC_EISA:
+		if ((rahc->flags & AHC_BIOS_ENABLED) != 0) {
+			value = lahc->platform_data->bios_address
+			      - rahc->platform_data->bios_address; 
+		} else {
+			value = lahc->bsh.ioport
+			      - rahc->bsh.ioport; 
+		}
+		break;
+	default:
+		panic("ahc_softc_sort: invalid bus type");
+	}
+	return (value);
+}
+
+static void
+ahc_linux_setup_tag_info(char *p, char *end, char *s)
+{
+	char	*base;
+	char	*tok;
+	char	*tok_end;
+	char	*tok_end2;
+	int      i;
+	int      instance;
+	int	 targ;
+	int	 done;
+	char	 tok_list[] = {'.', ',', '{', '}', '\0'};
+
+	if (*p != ':')
+		return;
+
+	instance = -1;
+	targ = -1;
+	done = FALSE;
+	base = p;
+	/* Forward us just past the ':' */
+	tok = base + 1;
+	tok_end = strchr(tok, '\0');
+	if (tok_end < end)
+		*tok_end = ',';
+	while (!done) {
+		switch (*tok) {
+		case '{':
+			if (instance == -1)
+				instance = 0;
+			else if (targ == -1)
+				targ = 0;
+			tok++;
+			break;
+		case '}':
+			if (targ != -1)
+				targ = -1;
+			else if (instance != -1)
+				instance = -1;
+			tok++;
+			break;
+		case ',':
+		case '.':
+			if (instance == -1)
+				done = TRUE;
+			else if (targ >= 0)
+				targ++;
+			else if (instance >= 0)
+				instance++;
+			if ((targ >= AHC_NUM_TARGETS) ||
+			    (instance >= NUM_ELEMENTS(aic7xxx_tag_info)))
+				done = TRUE;
+			tok++;
+			if (!done) {
+				base = tok;
+			}
+			break;
+		case '\0':
+			done = TRUE;
+			break;
+		default:
+			done = TRUE;
+			tok_end = strchr(tok, '\0');
+			for (i = 0; tok_list[i]; i++) {
+				tok_end2 = strchr(tok, tok_list[i]);
+				if ((tok_end2) && (tok_end2 < tok_end)) {
+					tok_end = tok_end2;
+					done = FALSE;
+				}
+			}
+			if ((instance >= 0) && (targ >= 0)
+			 && (instance < NUM_ELEMENTS(aic7xxx_tag_info))
+			 && (targ < AHC_NUM_TARGETS)) {
+				aic7xxx_tag_info[instance].tag_commands[targ] =
+				    simple_strtoul(tok, NULL, 0) & 0xff;
+			}
+			tok = tok_end;
+			break;
+		}
+	}
+	while ((p != base) && (p != NULL))
+		p = strsep(&s, ",.");
+}
+
+static void
+ahc_linux_setup_tag_info_global(char *p)
+{
+	int tags, i, j;
+
+	tags = simple_strtoul(p + 1, NULL, 0) & 0xff;
+	printf("Setting Global Tags= %d\n", tags);
+
+	for (i = 0; i < NUM_ELEMENTS(aic7xxx_tag_info); i++) {
+		for (j = 0; j < AHC_NUM_TARGETS; j++) {
+			aic7xxx_tag_info[i].tag_commands[j] = tags;
+		}
+	}
+}
+
+static void
+ahc_linux_setup_dv(char *p, char *end, char *s)
+{
+	char	*base;
+	char	*tok;
+	char	*tok_end;
+	char	*tok_end2;
+	int      i;
+	int      instance;
+	int	 done;
+	char	 tok_list[] = {'.', ',', '{', '}', '\0'};
+
+	if (*p != ':')
+		return;
+
+	instance = -1;
+	done = FALSE;
+	base = p;
+	/* Forward us just past the ':' */
+	tok = base + 1;
+	tok_end = strchr(tok, '\0');
+	if (tok_end < end)
+		*tok_end = ',';
+	while (!done) {
+		switch (*tok) {
+		case '{':
+			if (instance == -1)
+				instance = 0;
+			tok++;
+			break;
+		case '}':
+			if (instance != -1)
+				instance = -1;
+			tok++;
+			break;
+		case ',':
+		case '.':
+			if (instance == -1)
+				done = TRUE;
+			else if (instance >= 0)
+				instance++;
+			if (instance >= NUM_ELEMENTS(aic7xxx_dv_settings))
+				done = TRUE;
+			tok++;
+			if (!done) {
+				base = tok;
+			}
+			break;
+		case '\0':
+			done = TRUE;
+			break;
+		default:
+			done = TRUE;
+			tok_end = strchr(tok, '\0');
+			for (i = 0; tok_list[i]; i++) {
+				tok_end2 = strchr(tok, tok_list[i]);
+				if ((tok_end2) && (tok_end2 < tok_end)) {
+					tok_end = tok_end2;
+					done = FALSE;
+				}
+			}
+			if ((instance >= 0)
+			 && (instance < NUM_ELEMENTS(aic7xxx_dv_settings))) {
+				aic7xxx_dv_settings[instance] =
+				    simple_strtol(tok, NULL, 0);
+			}
+			tok = tok_end;
+			break;
+		}
+	}
+	while ((p != base) && (p != NULL))
+		p = strsep(&s, ",.");
+}
+
+/*
+ * Handle Linux boot parameters. This routine allows for assigning a value
+ * to a parameter with a ':' between the parameter and the value.
+ * ie. aic7xxx=stpwlev:1,extended
+ */
+int
+aic7xxx_setup(char *s)
+{
+	int	i, n;
+	char   *p;
+	char   *end;
+
+	static struct {
+		const char *name;
+		uint32_t *flag;
+	} options[] = {
+		{ "extended", &aic7xxx_extended },
+		{ "no_reset", &aic7xxx_no_reset },
+		{ "verbose", &aic7xxx_verbose },
+		{ "allow_memio", &aic7xxx_allow_memio},
+#ifdef AHC_DEBUG
+		{ "debug", &ahc_debug },
+#endif
+		{ "reverse_scan", &aic7xxx_reverse_scan },
+		{ "no_probe", &aic7xxx_no_probe },
+		{ "periodic_otag", &aic7xxx_periodic_otag },
+		{ "pci_parity", &aic7xxx_pci_parity },
+		{ "seltime", &aic7xxx_seltime },
+		{ "tag_info", NULL },
+		{ "global_tag_depth", NULL },
+		{ "dv", NULL }
+	};
+
+	end = strchr(s, '\0');
+
+	while ((p = strsep(&s, ",.")) != NULL) {
+		if (*p == '\0')
+			continue;
+		for (i = 0; i < NUM_ELEMENTS(options); i++) {
+			n = strlen(options[i].name);
+
+			if (strncmp(options[i].name, p, n) != 0)
+				continue;
+
+			if (!strncmp(p, "global_tag_depth", n)) {
+				ahc_linux_setup_tag_info_global(p + n);
+			} else if (!strncmp(p, "tag_info", n)) {
+				ahc_linux_setup_tag_info(p + n, end, s);
+			} else if (strncmp(p, "dv", n) == 0) {
+				ahc_linux_setup_dv(p + n, end, s);
+			} else if (p[n] == ':') {
+				*(options[i].flag) =
+				    simple_strtoul(p + n + 1, NULL, 0);
+			} else if (!strncmp(p, "verbose", n)) {
+				*(options[i].flag) = 1;
+			} else {
+				*(options[i].flag) = ~(*(options[i].flag));
+			}
+			break;
+		}
+	}
+	return 1;
+}
+
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0)
+__setup("aic7xxx=", aic7xxx_setup);
+#endif
+
+int aic7xxx_verbose;
+
+int
+ahc_linux_register_host(struct ahc_softc *ahc, Scsi_Host_Template *template)
+{
+	char	 buf[80];
+	struct	 Scsi_Host *host;
+	char	*new_name;
+	u_long	 s;
+	u_int	 target;
+
+	template->name = ahc->description;
+	host = scsi_register(template, sizeof(struct ahc_softc *));
+	if (host == NULL)
+		return (ENOMEM);
+
+	*((struct ahc_softc **)host->hostdata) = ahc;
+	ahc_lock(ahc, &s);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+	scsi_assign_lock(host, &ahc->platform_data->spin_lock);
+#endif
+	ahc->platform_data->host = host;
+	host->can_queue = AHC_MAX_QUEUE;
+	host->cmd_per_lun = 2;
+	host->sg_tablesize = AHC_NSEG;
+	/* XXX No way to communicate the ID for multiple channels */
+	host->this_id = ahc->our_id;
+	host->irq = ahc->platform_data->irq;
+	host->max_id = (ahc->features & AHC_WIDE) ? 16 : 8;
+	host->max_lun = AHC_NUM_LUNS;
+	host->max_channel = (ahc->features & AHC_TWIN) ? 1 : 0;
+	ahc_set_unit(ahc, ahc_linux_next_unit());
+	sprintf(buf, "scsi%d", host->host_no);
+	new_name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
+	if (new_name != NULL) {
+		strcpy(new_name, buf);
+		ahc_set_name(ahc, new_name);
+	}
+	host->unique_id = ahc->unit;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,4)
+	scsi_set_pci_device(host, ahc->dev_softc);
+#endif
+	ahc_linux_initialize_scsi_bus(ahc);
+	ahc_unlock(ahc, &s);
+	ahc->platform_data->dv_pid = kernel_thread(ahc_linux_dv_thread, ahc, 0);
+	ahc_lock(ahc, &s);
+	if (ahc->platform_data->dv_pid < 0) {
+		printf("%s: Failed to create DV thread, error= %d\n",
+		       ahc_name(ahc), ahc->platform_data->dv_pid);
+		return (-ahc->platform_data->dv_pid);
+	}
+	/*
+	 * Initially allocate *all* of our linux target objects
+	 * so that the DV thread will scan them all in parallel
+	 * just after driver initialization.  Any device that
+	 * does not exist will have its target object destroyed
+	 * by the selection timeout handler.  In the case of a
+	 * device that appears after the initial DV scan, async
+	 * negotiation will occur for the first command, and DV
+	 * will comence should that first command be successful.
+	 */
+	for (target = 0; target < AHC_NUM_TARGETS; target++) {
+		u_int channel;
+
+		channel = 0;
+		if (target > 7
+		 && (ahc->features & AHC_TWIN) != 0)
+			channel = 1;
+		ahc_linux_alloc_target(ahc, channel, target);
+	}
+	ahc_intr_enable(ahc, TRUE);
+	ahc_linux_start_dv(ahc);
+	ahc_unlock(ahc, &s);
+	return (0);
+}
+
+uint64_t
+ahc_linux_get_memsize()
+{
+	struct sysinfo si;
+
+	si_meminfo(&si);
+	return ((uint64_t)si.totalram << PAGE_SHIFT);
+}
+
+/*
+ * Find the smallest available unit number to use
+ * for a new device.  We don't just use a static
+ * count to handle the "repeated hot-(un)plug"
+ * scenario.
+ */
+static int
+ahc_linux_next_unit()
+{
+	struct ahc_softc *ahc;
+	int unit;
+
+	unit = 0;
+retry:
+	TAILQ_FOREACH(ahc, &ahc_tailq, links) {
+		if (ahc->unit == unit) {
+			unit++;
+			goto retry;
+		}
+	}
+	return (unit);
+}
+
+/*
+ * Place the SCSI bus into a known state by either resetting it,
+ * or forcing transfer negotiations on the next command to any
+ * target.
+ */
+void
+ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc)
+{
+	int i;
+	int numtarg;
+
+	i = 0;
+	numtarg = 0;
+
+	if (aic7xxx_no_reset != 0)
+		ahc->flags &= ~(AHC_RESET_BUS_A|AHC_RESET_BUS_B);
+
+	if ((ahc->flags & AHC_RESET_BUS_A) != 0)
+		ahc_reset_channel(ahc, 'A', /*initiate_reset*/TRUE);
+	else
+		numtarg = (ahc->features & AHC_WIDE) ? 16 : 8;
+
+	if ((ahc->features & AHC_TWIN) != 0) {
+
+		if ((ahc->flags & AHC_RESET_BUS_B) != 0) {
+			ahc_reset_channel(ahc, 'B', /*initiate_reset*/TRUE);
+		} else {
+			if (numtarg == 0)
+				i = 8;
+			numtarg += 8;
+		}
+	}
+
+	/*
+	 * Force negotiation to async for all targets that
+	 * will not see an initial bus reset.
+	 */
+	for (; i < numtarg; i++) {
+		struct ahc_devinfo devinfo;
+		struct ahc_initiator_tinfo *tinfo;
+		struct ahc_tmode_tstate *tstate;
+		u_int our_id;
+		u_int target_id;
+		char channel;
+
+		channel = 'A';
+		our_id = ahc->our_id;
+		target_id = i;
+		if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
+			channel = 'B';
+			our_id = ahc->our_id_b;
+			target_id = i % 8;
+		}
+		tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
+					    target_id, &tstate);
+		ahc_compile_devinfo(&devinfo, our_id, target_id,
+				    CAM_LUN_WILDCARD, channel, ROLE_INITIATOR);
+		ahc_update_neg_request(ahc, &devinfo, tstate,
+				       tinfo, AHC_NEG_ALWAYS);
+	}
+	/* Give the bus some time to recover */
+	if ((ahc->flags & (AHC_RESET_BUS_A|AHC_RESET_BUS_B)) != 0) {
+		ahc_linux_freeze_simq(ahc);
+		init_timer(&ahc->platform_data->reset_timer);
+		ahc->platform_data->reset_timer.data = (u_long)ahc;
+		ahc->platform_data->reset_timer.expires =
+		    jiffies + (AIC7XXX_RESET_DELAY * HZ)/1000;
+		ahc->platform_data->reset_timer.function =
+		    ahc_linux_release_simq;
+		add_timer(&ahc->platform_data->reset_timer);
+	}
+}
+
+int
+ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg)
+{
+
+	ahc->platform_data =
+	    malloc(sizeof(struct ahc_platform_data), M_DEVBUF, M_NOWAIT);
+	if (ahc->platform_data == NULL)
+		return (ENOMEM);
+	memset(ahc->platform_data, 0, sizeof(struct ahc_platform_data));
+	TAILQ_INIT(&ahc->platform_data->completeq);
+	TAILQ_INIT(&ahc->platform_data->device_runq);
+	ahc->platform_data->irq = AHC_LINUX_NOIRQ;
+	ahc->platform_data->hw_dma_mask = 0xFFFFFFFF;
+	ahc_lockinit(ahc);
+	ahc_done_lockinit(ahc);
+	init_timer(&ahc->platform_data->completeq_timer);
+	ahc->platform_data->completeq_timer.data = (u_long)ahc;
+	ahc->platform_data->completeq_timer.function =
+	    (ahc_linux_callback_t *)ahc_linux_thread_run_complete_queue;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+	init_MUTEX_LOCKED(&ahc->platform_data->eh_sem);
+	init_MUTEX_LOCKED(&ahc->platform_data->dv_sem);
+	init_MUTEX_LOCKED(&ahc->platform_data->dv_cmd_sem);
+#else
+	ahc->platform_data->eh_sem = MUTEX_LOCKED;
+	ahc->platform_data->dv_sem = MUTEX_LOCKED;
+	ahc->platform_data->dv_cmd_sem = MUTEX_LOCKED;
+#endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+	tasklet_init(&ahc->platform_data->runq_tasklet, ahc_runq_tasklet,
+		     (unsigned long)ahc);
+#endif
+	ahc->seltime = (aic7xxx_seltime & 0x3) << 4;
+	ahc->seltime_b = (aic7xxx_seltime & 0x3) << 4;
+	if (TAILQ_EMPTY(&ahc_tailq))
+		register_reboot_notifier(&ahc_linux_notifier);
+	return (0);
+}
+
+void
+ahc_platform_free(struct ahc_softc *ahc)
+{
+	u_long s;
+
+	if (ahc->platform_data != NULL) {
+		/* Kill the DV kthread */
+		if (ahc->platform_data->dv_pid > 0) {
+			ahc_lock(ahc, &s);
+			ahc->platform_data->flags |= AHC_DV_SHUTDOWN;
+			ahc_unlock(ahc, &s);
+			up(&ahc->platform_data->dv_sem);
+			do {
+#ifdef AHC_DEBUG
+				if (ahc_debug & AHC_SHOW_DV) {
+					printf("%s: Waiting for DV thread to "
+					       "exit\n", ahc_name(ahc));
+				}
+#endif
+			} while (waitpid(ahc->platform_data->dv_pid, NULL,
+					 __WCLONE) == -ERESTARTSYS);
+		}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+		tasklet_kill(&ahc->platform_data->runq_tasklet);
+#endif
+		if (ahc->platform_data->host != NULL)
+			scsi_unregister(ahc->platform_data->host);
+		if (ahc->platform_data->irq != AHC_LINUX_NOIRQ)
+			free_irq(ahc->platform_data->irq, ahc);
+		if (ahc->tag == BUS_SPACE_PIO
+		 && ahc->bsh.ioport != 0)
+			release_region(ahc->bsh.ioport, 256);
+		if (ahc->tag == BUS_SPACE_MEMIO
+		 && ahc->bsh.maddr != NULL) {
+			u_long base_addr;
+
+			base_addr = (u_long)ahc->bsh.maddr;
+			base_addr &= PAGE_MASK;
+			iounmap((void *)base_addr);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+			release_mem_region(ahc->platform_data->mem_busaddr,
+					   0x1000);
+#endif
+		}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+		/* XXX Need an instance detach in the PCI code */
+		if (ahc->dev_softc != NULL)
+			ahc->dev_softc->driver = NULL;
+#endif
+		free(ahc->platform_data, M_DEVBUF);
+	}
+	if (TAILQ_EMPTY(&ahc_tailq)) {
+		unregister_reboot_notifier(&ahc_linux_notifier);
+#ifdef CONFIG_PCI
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+		pci_unregister_driver(&aic7xxx_pci_driver);
+#endif
+#endif
+	}
+}
+
+void
+ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
+{
+	ahc_platform_abort_scbs(ahc, SCB_GET_TARGET(ahc, scb),
+				SCB_GET_CHANNEL(ahc, scb),
+				SCB_GET_LUN(scb), SCB_LIST_NULL,
+				ROLE_UNKNOWN, CAM_REQUEUE_REQ);
+}
+
+void
+ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
+		      ahc_queue_alg alg)
+{
+	struct ahc_linux_device *dev;
+	int was_queuing;
+	int now_queuing;
+
+	dev = ahc_linux_get_device(ahc, devinfo->channel - 'A',
+				   devinfo->target,
+				   devinfo->lun, /*alloc*/FALSE);
+	if (dev == NULL)
+		return;
+	was_queuing = dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED);
+	now_queuing = alg != AHC_QUEUE_NONE;
+	if ((dev->flags & AHC_DEV_FREEZE_TIL_EMPTY) == 0
+	 && (was_queuing != now_queuing)
+	 && (dev->active != 0)) {
+		dev->flags |= AHC_DEV_FREEZE_TIL_EMPTY;
+		dev->qfrozen++;
+	}
+
+	dev->flags &= ~(AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED|AHC_DEV_PERIODIC_OTAG);
+	if (now_queuing) {
+		u_int usertags;
+
+		usertags = ahc_linux_user_tagdepth(ahc, devinfo);
+		if (!was_queuing) {
+			/*
+			 * Start out agressively and allow our
+			 * dynamic queue depth algorithm to take
+			 * care of the rest.
+			 */
+			dev->maxtags = usertags;
+			dev->openings = dev->maxtags - dev->active;
+		}
+		if (dev->maxtags == 0) {
+			/*
+			 * Queueing is disabled by the user.
+			 */
+			dev->openings = 1;
+		} else if (alg == AHC_QUEUE_TAGGED) {
+			dev->flags |= AHC_DEV_Q_TAGGED;
+			if (aic7xxx_periodic_otag != 0)
+				dev->flags |= AHC_DEV_PERIODIC_OTAG;
+		} else
+			dev->flags |= AHC_DEV_Q_BASIC;
+	} else {
+		/* We can only have one opening. */
+		dev->maxtags = 0;
+		dev->openings =  1 - dev->active;
+	}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+	if (dev->scsi_device != NULL) {
+		switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) {
+		case AHC_DEV_Q_BASIC:
+			scsi_adjust_queue_depth(dev->scsi_device,
+						MSG_SIMPLE_TASK,
+						dev->openings + dev->active);
+			break;
+		case AHC_DEV_Q_TAGGED:
+			scsi_adjust_queue_depth(dev->scsi_device,
+						MSG_ORDERED_TASK,
+						dev->openings + dev->active);
+			break;
+		default:
+			/*
+			 * We allow the OS to queue 2 untagged transactions to
+			 * us at any time even though we can only execute them
+			 * serially on the controller/device.  This should
+			 * remove some latency.
+			 */
+			scsi_adjust_queue_depth(dev->scsi_device,
+						/*NON-TAGGED*/0,
+						/*queue depth*/2);
+			break;
+		}
+	}
+#endif
+}
+
+int
+ahc_platform_abort_scbs(struct ahc_softc *ahc, int target, char channel,
+			int lun, u_int tag, role_t role, uint32_t status)
+{
+	int chan;
+	int maxchan;
+	int targ;
+	int maxtarg;
+	int clun;
+	int maxlun;
+	int count;
+
+	if (tag != SCB_LIST_NULL)
+		return (0);
+
+	chan = 0;
+	if (channel != ALL_CHANNELS) {
+		chan = channel - 'A';
+		maxchan = chan + 1;
+	} else {
+		maxchan = (ahc->features & AHC_TWIN) ? 2 : 1;
+	}
+	targ = 0;
+	if (target != CAM_TARGET_WILDCARD) {
+		targ = target;
+		maxtarg = targ + 1;
+	} else {
+		maxtarg = (ahc->features & AHC_WIDE) ? 16 : 8;
+	}
+	clun = 0;
+	if (lun != CAM_LUN_WILDCARD) {
+		clun = lun;
+		maxlun = clun + 1;
+	} else {
+		maxlun = AHC_NUM_LUNS;
+	}
+
+	count = 0;
+	for (; chan < maxchan; chan++) {
+
+		for (; targ < maxtarg; targ++) {
+
+			for (; clun < maxlun; clun++) {
+				struct ahc_linux_device *dev;
+				struct ahc_busyq *busyq;
+				struct ahc_cmd *acmd;
+
+				dev = ahc_linux_get_device(ahc, chan,
+							   targ, clun,
+							   /*alloc*/FALSE);
+				if (dev == NULL)
+					continue;
+
+				busyq = &dev->busyq;
+				while ((acmd = TAILQ_FIRST(busyq)) != NULL) {
+					Scsi_Cmnd *cmd;
+
+					cmd = &acmd_scsi_cmd(acmd);
+					TAILQ_REMOVE(busyq, acmd,
+						     acmd_links.tqe);
+					count++;
+					cmd->result = status << 16;
+					ahc_linux_queue_cmd_complete(ahc, cmd);
+				}
+			}
+		}
+	}
+
+	return (count);
+}
+
+static void
+ahc_linux_thread_run_complete_queue(struct ahc_softc *ahc)
+{
+	struct ahc_cmd *acmd;
+	u_long flags;
+
+	ahc_lock(ahc, &flags);
+	del_timer(&ahc->platform_data->completeq_timer);
+	ahc->platform_data->flags &= ~AHC_RUN_CMPLT_Q_TIMER;
+	acmd = TAILQ_FIRST(&ahc->platform_data->completeq);
+	TAILQ_INIT(&ahc->platform_data->completeq);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	ahc_unlock(ahc, &flags);
+#endif
+	if (acmd != NULL) {
+		acmd = ahc_linux_run_complete_queue(ahc, acmd);
+		if (acmd != NULL) {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+			ahc_lock(ahc, &flags);
+#endif
+			ahc_schedule_completeq(ahc, acmd);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+			ahc_unlock(ahc, &flags);
+#endif
+		}
+	}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+	ahc_unlock(ahc, &flags);
+#endif
+}
+
+static void
+ahc_linux_start_dv(struct ahc_softc *ahc)
+{
+
+	/*
+	 * Freeze the simq and signal ahc_linux_queue to not let any
+	 * more commands through
+	 */
+	if ((ahc->platform_data->flags & AHC_DV_ACTIVE) == 0) {
+#ifdef AHC_DEBUG
+		if (ahc_debug & AHC_SHOW_DV)
+			printf("%s: Waking DV thread\n", ahc_name(ahc));
+#endif
+
+		ahc->platform_data->flags |= AHC_DV_ACTIVE;
+		ahc_linux_freeze_simq(ahc);
+
+		/* Wake up the DV kthread */
+		up(&ahc->platform_data->dv_sem);
+	}
+}
+
+static int
+ahc_linux_dv_thread(void *data)
+{
+	struct	ahc_softc *ahc;
+	int	target;
+	u_long	s;
+
+	ahc = (struct ahc_softc *)data;
+
+#ifdef AHC_DEBUG
+	if (ahc_debug & AHC_SHOW_DV)
+		printf("Launching DV Thread\n");
+#endif
+
+	while (1) {
+		down(&ahc->platform_data->dv_sem);
+
+		/* Check to see if we've been signaled to exit */
+		ahc_lock(ahc, &s);
+		if ((ahc->platform_data->flags & AHC_DV_SHUTDOWN) != 0) {
+			ahc_unlock(ahc, &s);
+			return (0);
+		}
+		ahc_unlock(ahc, &s);
+
+#ifdef AHC_DEBUG
+		if (ahc_debug & AHC_SHOW_DV)
+			printf("%s: Beginning Domain Validation\n",
+			       ahc_name(ahc));
+#endif
+
+		/*
+		 * Wait for any pending commands to drain before proceeding.
+		 */
+		ahc_lock(ahc, &s);
+		while (LIST_FIRST(&ahc->pending_scbs) != NULL) {
+			ahc->platform_data->flags |= AHC_DV_WAIT_SIMQ_EMPTY;
+			ahc_unlock(ahc, &s);
+			down(&ahc->platform_data->dv_sem);
+			ahc_lock(ahc, &s);
+		}
+
+		/*
+		 * Wait for the SIMQ to be released so that DV is the
+		 * only reason the queue is frozen.
+		 */
+		while (AHC_DV_SIMQ_FROZEN(ahc) == 0) {
+			ahc->platform_data->flags |= AHC_DV_WAIT_SIMQ_RELEASE;
+			ahc_unlock(ahc, &s);
+			down(&ahc->platform_data->dv_sem);
+			ahc_lock(ahc, &s);
+		}
+		ahc_unlock(ahc, &s);
+
+		for (target = 0; target < AHC_NUM_TARGETS; target++)
+			ahc_linux_dv_target(ahc, target);
+
+		ahc_lock(ahc, &s);
+		ahc->platform_data->flags &= ~AHC_DV_ACTIVE;
+		ahc_unlock(ahc, &s);
+
+		/*
+		 * Release the SIMQ so that normal commands are
+		 * allowed to continue on the bus.
+		 */
+		ahc_linux_release_simq((u_long)ahc);
+	}
+
+	return (0);
+}
+
+#define AHC_LINUX_DV_INQ_SHORT_LEN	36
+#define AHC_LINUX_DV_INQ_LEN		256
+#define AHC_LINUX_DV_TIMEOUT		(HZ / 4)
+
+#define AHC_SET_DV_STATE(ahc, targ, newstate) \
+	ahc_set_dv_state(ahc, targ, newstate, __LINE__)
+
+static __inline void
+ahc_set_dv_state(struct ahc_softc *ahc, struct ahc_linux_target *targ,
+		 ahc_dv_state newstate, u_int line)
+{
+	ahc_dv_state oldstate;
+
+	oldstate = targ->dv_state;
+#ifdef AHC_DEBUG
+	if (ahc_debug & AHC_SHOW_DV)
+		printf("%s:%d: Going from state %d to state %d\n",
+		       ahc_name(ahc), line, oldstate, newstate);
+#endif
+
+	if (oldstate == newstate)
+		targ->dv_state_retry++;
+	else
+		targ->dv_state_retry = 0;
+	targ->dv_state = newstate;
+}
+
+static void
+ahc_linux_dv_target(struct ahc_softc *ahc, u_int target_offset)
+{
+	struct	 ahc_devinfo devinfo;
+	struct	 ahc_linux_target *targ;
+	struct	 scsi_cmnd *cmd;
+	struct	 scsi_sense_data *sense;
+	uint8_t *buffer;
+	u_long	 s;
+	u_int	 timeout;
+	int	 echo_size;
+
+	sense = NULL;
+	buffer = NULL;
+	echo_size = 0;
+	ahc_lock(ahc, &s);
+	targ = ahc->platform_data->targets[target_offset];
+	if (targ == NULL || (targ->flags & AHC_DV_REQUIRED) == 0) {
+		ahc_unlock(ahc, &s);
+		return;
+	}
+	ahc_compile_devinfo(&devinfo, ahc->our_id, targ->target, /*lun*/0,
+			    targ->channel + 'A', ROLE_INITIATOR);
+#ifdef AHC_DEBUG
+	if (ahc_debug & AHC_SHOW_DV) {
+		ahc_print_devinfo(ahc, &devinfo);
+		printf("Performing DV\n");
+	}
+#endif
+
+	ahc_unlock(ahc, &s);
+
+	cmd = malloc(sizeof(struct scsi_cmnd), M_DEVBUF, M_WAITOK);
+
+	AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_INQ_SHORT_ASYNC);
+
+	while (targ->dv_state != AHC_DV_STATE_EXIT) {
+		timeout = AHC_LINUX_DV_TIMEOUT;
+		switch (targ->dv_state) {
+		case AHC_DV_STATE_INQ_SHORT_ASYNC:
+		case AHC_DV_STATE_INQ_ASYNC:
+		case AHC_DV_STATE_INQ_ASYNC_VERIFY:
+			/*
+			 * Set things to async narrow to reduce the
+			 * chance that the INQ will fail.
+			 */
+			ahc_lock(ahc, &s);
+			ahc_set_syncrate(ahc, &devinfo, NULL, 0, 0, 0,
+					 AHC_TRANS_GOAL, /*paused*/FALSE);
+			ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
+				      AHC_TRANS_GOAL, /*paused*/FALSE);
+			ahc_unlock(ahc, &s);
+			timeout = 10 * HZ;
+			/* FALLTHROUGH */
+		case AHC_DV_STATE_INQ_VERIFY:
+		{
+			u_int inq_len;
+
+			if (targ->dv_state == AHC_DV_STATE_INQ_SHORT_ASYNC)
+				inq_len = AHC_LINUX_DV_INQ_SHORT_LEN;
+			else
+				inq_len = targ->inq_data->additional_length + 5;
+			ahc_linux_dv_inq(ahc, cmd, &devinfo, targ, inq_len);
+			break;
+		}
+		case AHC_DV_STATE_TUR:
+		case AHC_DV_STATE_BUSY:
+			ahc_linux_dv_tur(ahc, cmd, &devinfo);
+			break;
+		case AHC_DV_STATE_REBD:
+			ahc_linux_dv_rebd(ahc, cmd, &devinfo, targ);
+			break;
+		case AHC_DV_STATE_WEB:
+			ahc_linux_dv_web(ahc, cmd, &devinfo, targ);
+			break;
+
+		case AHC_DV_STATE_REB:
+			ahc_linux_dv_reb(ahc, cmd, &devinfo, targ);
+			break;
+
+		case AHC_DV_STATE_SU:
+			ahc_linux_dv_su(ahc, cmd, &devinfo, targ);
+			timeout = 50 * HZ;
+			break;
+
+		default:
+			ahc_print_devinfo(ahc, &devinfo);
+			printf("Unknown DV state %d\n", targ->dv_state);
+			goto out;
+		}
+
+		/* Queue the command and wait for it to complete */
+		/* Abuse eh_timeout in the scsi_cmnd struct for our purposes */
+		init_timer(&cmd->eh_timeout);
+#ifdef AHC_DEBUG
+		if ((ahc_debug & AHC_SHOW_MESSAGES) != 0)
+			/*
+			 * All of the printfs during negotiation
+			 * really slow down the negotiation.
+			 * Add a bit of time just to be safe.
+			 */
+			timeout += HZ;
+#endif
+		scsi_add_timer(cmd, timeout, ahc_linux_dv_timeout);
+		/*
+		 * In 2.5.X, it is assumed that all calls from the
+		 * "midlayer" (which we are emulating) will have the
+		 * ahc host lock held.
+		 */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+		ahc_lock(ahc, &s);
+#endif
+		ahc_linux_queue(cmd, ahc_linux_dv_complete);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+		ahc_unlock(ahc, &s);
+#endif
+		down(&ahc->platform_data->dv_cmd_sem);
+		/*
+		 * Wait for the SIMQ to be released so that DV is the
+		 * only reason the queue is frozen.
+		 */
+		ahc_lock(ahc, &s);
+		while (AHC_DV_SIMQ_FROZEN(ahc) == 0) {
+			ahc->platform_data->flags |= AHC_DV_WAIT_SIMQ_RELEASE;
+			ahc_unlock(ahc, &s);
+			down(&ahc->platform_data->dv_sem);
+			ahc_lock(ahc, &s);
+		}
+		ahc_unlock(ahc, &s);
+
+		ahc_linux_dv_transition(ahc, cmd, &devinfo, targ);
+	}
+
+out:
+	if (cmd != NULL)
+		free(cmd, M_DEVBUF);
+
+	ahc_lock(ahc, &s);
+	if (targ->dv_buffer != NULL)
+		free(targ->dv_buffer, M_DEVBUF);
+	if (targ->dv_buffer1 != NULL)
+		free(targ->dv_buffer1, M_DEVBUF);
+	targ->flags &= ~AHC_DV_REQUIRED;
+	if (targ->refcount == 0)
+		ahc_linux_free_target(ahc, targ);
+	ahc_unlock(ahc, &s);
+}
+
+static void
+ahc_linux_dv_transition(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
+			struct ahc_devinfo *devinfo,
+			struct ahc_linux_target *targ)
+{
+	u_int32_t status;
+
+	status = aic_dv_error_action(cmd, targ->inq_data);
+
+	
+#ifdef AHC_DEBUG
+	if (ahc_debug & AHC_SHOW_DV) {
+		ahc_print_devinfo(ahc, devinfo);
+		printf("Entering ahc_linux_dv_transition, state= %d, "
+		       "status= 0x%x, cmd->result= 0x%x\n", targ->dv_state,
+		       status, cmd->result);
+	}
+#endif
+
+	switch (targ->dv_state) {
+	case AHC_DV_STATE_INQ_SHORT_ASYNC:
+	case AHC_DV_STATE_INQ_ASYNC:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+		{
+			AHC_SET_DV_STATE(ahc, targ, targ->dv_state+1);
+			break;
+		}
+		case SS_INQ_REFRESH:
+			AHC_SET_DV_STATE(ahc, targ,
+					 AHC_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		case SS_TUR:
+		case SS_RETRY:
+			AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
+			if (ahc_cmd_get_transaction_status(cmd)
+			 == CAM_REQUEUE_REQ)
+				targ->dv_state_retry--;
+			if ((status & SS_ERRMASK) == EBUSY)
+				AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_BUSY);
+			if (targ->dv_state_retry < 10)
+				break;
+			/* FALLTHROUGH */
+		default:
+			AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
+#ifdef AHC_DEBUG
+			if (ahc_debug & AHC_SHOW_DV) {
+				ahc_print_devinfo(ahc, devinfo);
+				printf("Failed DV inquiry, skipping\n");
+			}
+#endif
+			break;
+		}
+		break;
+	case AHC_DV_STATE_INQ_ASYNC_VERIFY:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+		{
+			u_int spi3data;
+
+			if (memcmp(targ->inq_data, targ->dv_buffer,
+				   AHC_LINUX_DV_INQ_LEN) != 0) {
+				/*
+				 * Inquiry data must have changed.
+				 * Try from the top again.
+				 */
+				AHC_SET_DV_STATE(ahc, targ,
+						 AHC_DV_STATE_INQ_SHORT_ASYNC);
+				break;
+			}
+
+			if (ahc_linux_user_dv_setting(ahc) == 0) {
+				ahc_linux_filter_inquiry(ahc, devinfo);
+				AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
+				break;
+			}
+
+			spi3data = targ->inq_data->spi3data;
+			switch (spi3data & SID_SPI_CLOCK_DT_ST) {
+			default:
+			case SID_SPI_CLOCK_ST:
+				/* Assume only basic DV is supported. */
+				ahc_linux_filter_inquiry(ahc, devinfo);
+				AHC_SET_DV_STATE(ahc, targ,
+						 AHC_DV_STATE_INQ_VERIFY);
+				break;
+			case SID_SPI_CLOCK_DT:
+			case SID_SPI_CLOCK_DT_ST:
+				AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_REBD);
+				break;
+			}
+			break;
+		}
+		case SS_INQ_REFRESH:
+			AHC_SET_DV_STATE(ahc, targ,
+					 AHC_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		case SS_TUR:
+		case SS_RETRY:
+			AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
+			if (ahc_cmd_get_transaction_status(cmd)
+			 == CAM_REQUEUE_REQ)
+				targ->dv_state_retry--;
+
+			if ((status & SS_ERRMASK) == EBUSY)
+				AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_BUSY);
+			if (targ->dv_state_retry < 10)
+				break;
+			/* FALLTHROUGH */
+		default:
+			AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
+#ifdef AHC_DEBUG
+			if (ahc_debug & AHC_SHOW_DV) {
+				ahc_print_devinfo(ahc, devinfo);
+				printf("Failed DV inquiry, skipping\n");
+			}
+#endif
+			break;
+		}
+		break;
+	case AHC_DV_STATE_INQ_VERIFY:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+		{
+
+			if (memcmp(targ->inq_data, targ->dv_buffer,
+				   AHC_LINUX_DV_INQ_LEN) == 0) {
+				AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
+				break;
+			}
+
+			if (ahc_linux_fallback(ahc, devinfo) != 0) {
+				AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
+				break;
+			}
+			/*
+			 * Do not count "falling back"
+			 * against our retries.
+			 */
+			targ->dv_state_retry = 0;
+			AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
+			break;
+		}
+		case SS_INQ_REFRESH:
+			AHC_SET_DV_STATE(ahc, targ,
+					 AHC_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		case SS_TUR:
+		case SS_RETRY:
+			AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
+			if (ahc_cmd_get_transaction_status(cmd)
+			 == CAM_REQUEUE_REQ) {
+				targ->dv_state_retry--;
+			} else if ((status & SSQ_FALLBACK) != 0) {
+				if (ahc_linux_fallback(ahc, devinfo) != 0) {
+					AHC_SET_DV_STATE(ahc, targ,
+							 AHC_DV_STATE_EXIT);
+					break;
+				}
+				/*
+				 * Do not count "falling back"
+				 * against our retries.
+				 */
+				targ->dv_state_retry = 0;
+			} else if ((status & SS_ERRMASK) == EBUSY)
+				AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_BUSY);
+			if (targ->dv_state_retry < 10)
+				break;
+			/* FALLTHROUGH */
+		default:
+			AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
+#ifdef AHC_DEBUG
+			if (ahc_debug & AHC_SHOW_DV) {
+				ahc_print_devinfo(ahc, devinfo);
+				printf("Failed DV inquiry, skipping\n");
+			}
+#endif
+			break;
+		}
+		break;
+
+	case AHC_DV_STATE_TUR:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+			AHC_SET_DV_STATE(ahc, targ,
+					 AHC_DV_STATE_INQ_ASYNC);
+			break;
+		case SS_RETRY:
+		case SS_TUR:
+			if ((status & SS_ERRMASK) == EBUSY) {
+				AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_BUSY);
+				break;
+			}
+			AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
+			if (ahc_cmd_get_transaction_status(cmd)
+			 == CAM_REQUEUE_REQ) {
+				targ->dv_state_retry--;
+			} else if ((status & SSQ_FALLBACK) != 0) {
+				if (ahc_linux_fallback(ahc, devinfo) != 0) {
+					AHC_SET_DV_STATE(ahc, targ,
+							 AHC_DV_STATE_EXIT);
+					break;
+				}
+				/*
+				 * Do not count "falling back"
+				 * against our retries.
+				 */
+				targ->dv_state_retry = 0;
+			}
+			if (targ->dv_state_retry >= 10) {
+#ifdef AHC_DEBUG
+				if (ahc_debug & AHC_SHOW_DV) {
+					ahc_print_devinfo(ahc, devinfo);
+					printf("DV TUR reties exhausted\n");
+				}
+#endif
+				AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
+				break;
+			}
+			if (status & SSQ_DELAY)
+				scsi_sleep(1 * HZ);
+
+			break;
+		case SS_START:
+			AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_SU);
+			break;
+		case SS_INQ_REFRESH:
+			AHC_SET_DV_STATE(ahc, targ,
+					 AHC_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		default:
+			AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
+			break;
+		}
+		break;
+
+	case AHC_DV_STATE_REBD:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+		{
+			uint32_t echo_size;
+
+			AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_WEB);
+			echo_size = scsi_3btoul(&targ->dv_buffer[1]);
+			echo_size &= 0x1FFF;
+#ifdef AHC_DEBUG
+			if (ahc_debug & AHC_SHOW_DV) {
+				ahc_print_devinfo(ahc, devinfo);
+				printf("Echo buffer size= %d\n", echo_size);
+			}
+#endif
+			if (echo_size == 0) {
+				AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
+				break;
+			}
+
+			/* Generate the buffer pattern */
+			targ->dv_echo_size = echo_size;
+			ahc_linux_generate_dv_pattern(targ);
+			/*
+			 * Setup initial negotiation values.
+			 */
+			ahc_linux_filter_inquiry(ahc, devinfo);
+			break;
+		}
+		case SS_INQ_REFRESH:
+			AHC_SET_DV_STATE(ahc, targ,
+					 AHC_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		case SS_RETRY:
+			AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
+			if (ahc_cmd_get_transaction_status(cmd)
+			 == CAM_REQUEUE_REQ)
+				targ->dv_state_retry--;
+			if (targ->dv_state_retry <= 10)
+				break;
+#ifdef AHC_DEBUG
+			if (ahc_debug & AHC_SHOW_DV) {
+				ahc_print_devinfo(ahc, devinfo);
+				printf("DV REBD reties exhausted\n");
+			}
+#endif
+			/* FALLTHROUGH */
+		case SS_FATAL:
+		default:
+			/*
+			 * Setup initial negotiation values
+			 * and try level 1 DV.
+			 */
+			ahc_linux_filter_inquiry(ahc, devinfo);
+			AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_INQ_VERIFY);
+			targ->dv_echo_size = 0;
+			break;
+		}
+		break;
+
+	case AHC_DV_STATE_WEB:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+			AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_REB);
+			break;
+		case SS_INQ_REFRESH:
+			AHC_SET_DV_STATE(ahc, targ,
+					 AHC_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		case SS_RETRY:
+			AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
+			if (ahc_cmd_get_transaction_status(cmd)
+			 == CAM_REQUEUE_REQ) {
+				targ->dv_state_retry--;
+			} else if ((status & SSQ_FALLBACK) != 0) {
+				if (ahc_linux_fallback(ahc, devinfo) != 0) {
+					AHC_SET_DV_STATE(ahc, targ,
+							 AHC_DV_STATE_EXIT);
+					break;
+				}
+				/*
+				 * Do not count "falling back"
+				 * against our retries.
+				 */
+				targ->dv_state_retry = 0;
+			}
+			if (targ->dv_state_retry <= 10)
+				break;
+			/* FALLTHROUGH */
+#ifdef AHC_DEBUG
+			if (ahc_debug & AHC_SHOW_DV) {
+				ahc_print_devinfo(ahc, devinfo);
+				printf("DV WEB reties exhausted\n");
+			}
+#endif
+		default:
+			AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
+			break;
+		}
+		break;
+
+	case AHC_DV_STATE_REB:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+			if (memcmp(targ->dv_buffer, targ->dv_buffer1,
+				   targ->dv_echo_size) != 0) {
+				if (ahc_linux_fallback(ahc, devinfo) != 0)
+					AHC_SET_DV_STATE(ahc, targ,
+							 AHC_DV_STATE_EXIT);
+				else
+					AHC_SET_DV_STATE(ahc, targ,
+							 AHC_DV_STATE_WEB);
+				break;
+			}
+			
+			if (targ->dv_buffer != NULL) {
+				free(targ->dv_buffer, M_DEVBUF);
+				targ->dv_buffer = NULL;
+			}
+			if (targ->dv_buffer1 != NULL) {
+				free(targ->dv_buffer1, M_DEVBUF);
+				targ->dv_buffer1 = NULL;
+			}
+			AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
+			break;
+		case SS_INQ_REFRESH:
+			AHC_SET_DV_STATE(ahc, targ,
+					 AHC_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		case SS_RETRY:
+			AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
+			if (ahc_cmd_get_transaction_status(cmd)
+			 == CAM_REQUEUE_REQ) {
+				targ->dv_state_retry--;
+			} else if ((status & SSQ_FALLBACK) != 0) {
+				if (ahc_linux_fallback(ahc, devinfo) != 0) {
+					AHC_SET_DV_STATE(ahc, targ,
+							 AHC_DV_STATE_EXIT);
+					break;
+				}
+				AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_WEB);
+			}
+			if (targ->dv_state_retry <= 10) {
+				if ((status & (SSQ_DELAY_RANDOM|SSQ_DELAY))!= 0)
+					scsi_sleep(ahc->our_id*HZ/10);
+				break;
+			}
+#ifdef AHC_DEBUG
+			if (ahc_debug & AHC_SHOW_DV) {
+				ahc_print_devinfo(ahc, devinfo);
+				printf("DV REB reties exhausted\n");
+			}
+#endif
+			/* FALLTHROUGH */
+		default:
+			AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
+			break;
+		}
+		break;
+
+	case AHC_DV_STATE_SU:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+		case SS_INQ_REFRESH:
+			AHC_SET_DV_STATE(ahc, targ,
+					 AHC_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		default:
+			AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
+			break;
+		}
+		break;
+
+	case AHC_DV_STATE_BUSY:
+		switch (status & SS_MASK) {
+		case SS_NOP:
+		case SS_INQ_REFRESH:
+			AHC_SET_DV_STATE(ahc, targ,
+					 AHC_DV_STATE_INQ_SHORT_ASYNC);
+			break;
+		case SS_TUR:
+		case SS_RETRY:
+			AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
+			if (ahc_cmd_get_transaction_status(cmd)
+			 == CAM_REQUEUE_REQ) {
+				targ->dv_state_retry--;
+			} else if (targ->dv_state_retry < 60) {
+				if ((status & SSQ_DELAY) != 0)
+					scsi_sleep(1 * HZ);
+			} else {
+#ifdef AHC_DEBUG
+				if (ahc_debug & AHC_SHOW_DV) {
+					ahc_print_devinfo(ahc, devinfo);
+					printf("DV BUSY reties exhausted\n");
+				}
+#endif
+				AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
+			}
+			break;
+		default:
+			AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
+			break;
+		}
+		break;
+
+	default:
+		printf("%s: Invalid DV completion state %d\n", ahc_name(ahc),
+		       targ->dv_state);
+		AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
+		break;
+	}
+}
+
+static uint32_t
+aic_dv_error_action(struct scsi_cmnd *cmd, struct scsi_inquiry_data *inq_data)
+{
+	aic_sense_action  err_action;
+	cam_status	  status;
+	u_int		  scsi_status;
+	int		  sense;
+
+	status = ahc_cmd_get_transaction_status(cmd);
+	scsi_status = ahc_cmd_get_scsi_status(cmd);
+	sense  = (cmd->result >> 24) == DRIVER_SENSE;
+
+	switch (status) {
+	case CAM_REQ_CMP:
+		err_action = SS_NOP;
+		break;
+	case CAM_AUTOSENSE_FAIL:
+	case CAM_SCSI_STATUS_ERROR:
+
+		switch (scsi_status) {
+		case SCSI_STATUS_OK:
+		case SCSI_STATUS_COND_MET:
+		case SCSI_STATUS_INTERMED:
+		case SCSI_STATUS_INTERMED_COND_MET:
+			err_action = SS_NOP;
+			break;
+		case SCSI_STATUS_CMD_TERMINATED:
+		case SCSI_STATUS_CHECK_COND:
+			if (sense != 0) {
+				struct scsi_sense_data *sense;
+
+				sense = (struct scsi_sense_data *)
+				    &cmd->sense_buffer;
+				err_action =
+				    aic_sense_error_action(sense, inq_data, 0);
+
+			} else {
+				err_action = SS_RETRY|SSQ_FALLBACK
+					   | SSQ_DECREMENT_COUNT|EIO;
+			}
+			break;
+		case SCSI_STATUS_QUEUE_FULL:
+		case SCSI_STATUS_BUSY:
+			err_action = SS_RETRY|SSQ_DELAY|SSQ_MANY
+				   | SSQ_DECREMENT_COUNT|EBUSY;
+			break;
+		case SCSI_STATUS_RESERV_CONFLICT:
+		default:
+			err_action = SS_FAIL|EBUSY;
+			break;
+		}
+		break;
+	case CAM_REQ_CMP_ERR:
+	case CAM_CMD_TIMEOUT:
+	case CAM_UNEXP_BUSFREE:
+	case CAM_UNCOR_PARITY:
+	case CAM_DATA_RUN_ERR:
+		err_action = SS_RETRY|SSQ_FALLBACK|EIO;
+		break;
+	case CAM_UA_ABORT:
+	case CAM_UA_TERMIO:
+	case CAM_MSG_REJECT_REC:
+	case CAM_SEL_TIMEOUT:
+		err_action = SS_FAIL|EIO;
+		break;
+	case CAM_REQ_INVALID:
+	case CAM_PATH_INVALID:
+	case CAM_DEV_NOT_THERE:
+	case CAM_NO_HBA:
+	case CAM_PROVIDE_FAIL:
+	case CAM_REQ_TOO_BIG:		
+	case CAM_RESRC_UNAVAIL:
+	case CAM_BUSY:
+	default:
+		/* panic??  These should never occur in our application. */
+		err_action = SS_FAIL|EIO;
+		break;
+	case CAM_SCSI_BUS_RESET:
+	case CAM_BDR_SENT:		
+	case CAM_REQUEUE_REQ:
+		/* Unconditional requeue */
+		err_action = SS_RETRY;
+		break;
+	}
+
+	return (err_action);
+}
+
+static void
+ahc_linux_dv_fill_cmd(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
+		      struct ahc_devinfo *devinfo)
+{
+	memset(cmd, 0, sizeof(struct scsi_cmnd));
+	cmd->host = ahc->platform_data->host;
+	cmd->scsi_done = ahc_linux_dv_complete;
+	cmd->target = devinfo->target;
+	cmd->lun = devinfo->lun;
+	cmd->channel = devinfo->channel - 'A';
+}
+
+/*
+ * Synthesize an inquiry command.  On the return trip, it'll be
+ * sniffed and the device transfer settings set for us.
+ */
+static void
+ahc_linux_dv_inq(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
+		 struct ahc_devinfo *devinfo, struct ahc_linux_target *targ,
+		 u_int request_length)
+{
+
+#ifdef AHC_DEBUG
+	if (ahc_debug & AHC_SHOW_DV) {
+		ahc_print_devinfo(ahc, devinfo);
+		printf("Sending INQ\n");
+	}
+#endif
+	if (targ->inq_data == NULL)
+		targ->inq_data = malloc(AHC_LINUX_DV_INQ_LEN,
+					M_DEVBUF, M_WAITOK);
+	if (targ->dv_state > AHC_DV_STATE_INQ_ASYNC) {
+		if (targ->dv_buffer != NULL)
+			free(targ->dv_buffer, M_DEVBUF);
+		targ->dv_buffer = malloc(AHC_LINUX_DV_INQ_LEN,
+					 M_DEVBUF, M_WAITOK);
+	}
+
+	ahc_linux_dv_fill_cmd(ahc, cmd, devinfo);
+	cmd->sc_data_direction = SCSI_DATA_READ;
+	cmd->cmd_len = 6;
+	cmd->cmnd[0] = INQUIRY;
+	cmd->cmnd[4] = request_length;
+	cmd->request_bufflen = request_length;
+	if (targ->dv_state > AHC_DV_STATE_INQ_ASYNC)
+		cmd->request_buffer = targ->dv_buffer;
+	else
+		cmd->request_buffer = targ->inq_data;
+	memset(cmd->request_buffer, 0, AHC_LINUX_DV_INQ_LEN);
+}
+
+static void
+ahc_linux_dv_tur(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
+		 struct ahc_devinfo *devinfo)
+{
+
+#ifdef AHC_DEBUG
+	if (ahc_debug & AHC_SHOW_DV) {
+		ahc_print_devinfo(ahc, devinfo);
+		printf("Sending TUR\n");
+	}
+#endif
+	/* Do a TUR to clear out any non-fatal transitional state */
+	ahc_linux_dv_fill_cmd(ahc, cmd, devinfo);
+	cmd->sc_data_direction = SCSI_DATA_NONE;
+	cmd->cmd_len = 6;
+	cmd->cmnd[0] = TEST_UNIT_READY;
+}
+
+#define AHC_REBD_LEN 4
+
+static void
+ahc_linux_dv_rebd(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
+		 struct ahc_devinfo *devinfo, struct ahc_linux_target *targ)
+{
+
+#ifdef AHC_DEBUG
+	if (ahc_debug & AHC_SHOW_DV) {
+		ahc_print_devinfo(ahc, devinfo);
+		printf("Sending REBD\n");
+	}
+#endif
+	if (targ->dv_buffer != NULL)
+		free(targ->dv_buffer, M_DEVBUF);
+	targ->dv_buffer = malloc(AHC_REBD_LEN, M_DEVBUF, M_WAITOK);
+	ahc_linux_dv_fill_cmd(ahc, cmd, devinfo);
+	cmd->sc_data_direction = SCSI_DATA_READ;
+	cmd->cmd_len = 10;
+	cmd->cmnd[0] = READ_BUFFER;
+	cmd->cmnd[1] = 0x0b;
+	scsi_ulto3b(AHC_REBD_LEN, &cmd->cmnd[6]);
+	cmd->request_bufflen = AHC_REBD_LEN;
+	cmd->underflow = cmd->request_bufflen;
+	cmd->request_buffer = targ->dv_buffer;
+}
+
+static void
+ahc_linux_dv_web(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
+		 struct ahc_devinfo *devinfo, struct ahc_linux_target *targ)
+{
+
+#ifdef AHC_DEBUG
+	if (ahc_debug & AHC_SHOW_DV) {
+		ahc_print_devinfo(ahc, devinfo);
+		printf("Sending WEB\n");
+	}
+#endif
+	ahc_linux_dv_fill_cmd(ahc, cmd, devinfo);
+	cmd->sc_data_direction = SCSI_DATA_WRITE;
+	cmd->cmd_len = 10;
+	cmd->cmnd[0] = WRITE_BUFFER;
+	cmd->cmnd[1] = 0x0a;
+	scsi_ulto3b(targ->dv_echo_size, &cmd->cmnd[6]);
+	cmd->request_bufflen = targ->dv_echo_size;
+	cmd->underflow = cmd->request_bufflen;
+	cmd->request_buffer = targ->dv_buffer;
+}
+
+static void
+ahc_linux_dv_reb(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
+		 struct ahc_devinfo *devinfo, struct ahc_linux_target *targ)
+{
+
+#ifdef AHC_DEBUG
+	if (ahc_debug & AHC_SHOW_DV) {
+		ahc_print_devinfo(ahc, devinfo);
+		printf("Sending REB\n");
+	}
+#endif
+	ahc_linux_dv_fill_cmd(ahc, cmd, devinfo);
+	cmd->sc_data_direction = SCSI_DATA_READ;
+	cmd->cmd_len = 10;
+	cmd->cmnd[0] = READ_BUFFER;
+	cmd->cmnd[1] = 0x0a;
+	scsi_ulto3b(targ->dv_echo_size, &cmd->cmnd[6]);
+	cmd->request_bufflen = targ->dv_echo_size;
+	cmd->underflow = cmd->request_bufflen;
+	cmd->request_buffer = targ->dv_buffer1;
+}
+
+static void
+ahc_linux_dv_su(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
+		struct ahc_devinfo *devinfo,
+		struct ahc_linux_target *targ)
+{
+	u_int le;
+
+	le = SID_IS_REMOVABLE(targ->inq_data) ? SSS_LOEJ : 0;
+
+#ifdef AHC_DEBUG
+	if (ahc_debug & AHC_SHOW_DV) {
+		ahc_print_devinfo(ahc, devinfo);
+		printf("Sending SU\n");
+	}
+#endif
+	ahc_linux_dv_fill_cmd(ahc, cmd, devinfo);
+	cmd->sc_data_direction = SCSI_DATA_NONE;
+	cmd->cmd_len = 6;
+	cmd->cmnd[0] = START_STOP_UNIT;
+	cmd->cmnd[4] = le | SSS_START;
+}
+
+/*
+ * Return speed in KB/s.
+ */
+static u_int
+ahc_linux_calc_speed(u_int width, u_int period, u_int offset)
+{
+	u_int freq;
+
+	if (offset != 0)
+		freq  = aic_calc_syncsrate(period);
+	else
+		/* Roughly 3.3MB/s for async */
+		freq  = 3300;
+	freq <<= width;
+	return (freq);
+}
+
+static int
+ahc_linux_fallback(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
+{
+	struct	ahc_linux_target *targ;
+	struct	ahc_initiator_tinfo *tinfo;
+	struct	ahc_transinfo *goal;
+	struct	ahc_tmode_tstate *tstate;
+	struct	ahc_syncrate *syncrate;
+	u_long	s;
+	u_int	width;
+	u_int	period;
+	u_int	offset;
+	u_int	ppr_options;
+	u_int	cur_speed;
+	u_int	wide_speed;
+	u_int	narrow_speed;
+	u_int	fallback_speed;
+
+#ifdef AHC_DEBUG
+	if (ahc_debug & AHC_SHOW_DV) {
+		ahc_print_devinfo(ahc, devinfo);
+		printf("Trying to fallback\n");
+	}
+#endif
+	ahc_lock(ahc, &s);
+	targ = ahc->platform_data->targets[devinfo->target_offset];
+	tinfo = ahc_fetch_transinfo(ahc, devinfo->channel,
+				    devinfo->our_scsiid,
+				    devinfo->target, &tstate);
+	goal = &tinfo->goal;
+	width = goal->width;
+	period = goal->period;
+	offset = goal->offset;
+	ppr_options = goal->ppr_options;
+	if (offset == 0)
+		period = AHC_ASYNC_XFER_PERIOD;
+	if (targ->dv_next_narrow_period == 0)
+		targ->dv_next_narrow_period = MAX(period, AHC_SYNCRATE_ULTRA2);
+	if (targ->dv_next_wide_period == 0)
+		targ->dv_next_wide_period = period;
+	if (targ->dv_max_ppr_options == 0)
+		targ->dv_max_ppr_options = ppr_options;
+	if (targ->dv_last_ppr_options == 0)
+		targ->dv_last_ppr_options = ppr_options;
+
+	cur_speed = ahc_linux_calc_speed(width, period, offset);
+	wide_speed = ahc_linux_calc_speed(MSG_EXT_WDTR_BUS_16_BIT,
+					  targ->dv_next_wide_period,
+					  MAX_OFFSET);
+	narrow_speed = ahc_linux_calc_speed(MSG_EXT_WDTR_BUS_8_BIT,
+					    targ->dv_next_narrow_period,
+					    MAX_OFFSET);
+	fallback_speed = ahc_linux_calc_speed(width, period+1, offset);
+#ifdef AHC_DEBUG
+	if (ahc_debug & AHC_SHOW_DV) {
+		printf("cur_speed= %d, wide_speed= %d, narrow_speed= %d, "
+		       "fallback_speed= %d\n", cur_speed, wide_speed,
+		       narrow_speed, fallback_speed);
+	}
+#endif
+
+	if (cur_speed > 160000) {
+		/*
+		 * Paced/DT/IU_REQ only transfer speeds.  All we
+		 * can do is fallback in terms of syncrate.
+		 */
+		period++;
+	} else if (cur_speed > 80000) {
+		if ((ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
+			/*
+			 * Try without IU_REQ as it may be confusing
+			 * an expander.
+			 */
+			ppr_options &= ~MSG_EXT_PPR_IU_REQ;
+		} else {
+			/*
+			 * Paced/DT only transfer speeds.  All we
+			 * can do is fallback in terms of syncrate.
+			 */
+			period++;
+			ppr_options = targ->dv_max_ppr_options;
+		}
+	} else if (cur_speed > 3300) {
+
+		/*
+		 * In this range we the following
+		 * options ordered from highest to
+		 * lowest desireability:
+		 *
+		 * o Wide/DT
+		 * o Wide/non-DT
+		 * o Narrow at a potentally higher sync rate.
+		 *
+		 * All modes are tested with and without IU_REQ
+		 * set since using IUs may confuse an expander.
+		 */
+		if ((ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
+
+			ppr_options &= ~MSG_EXT_PPR_IU_REQ;
+		} else if ((ppr_options & MSG_EXT_PPR_DT_REQ) != 0) {
+			/*
+			 * Try going non-DT.
+			 */
+			ppr_options = targ->dv_max_ppr_options;
+			ppr_options &= ~MSG_EXT_PPR_DT_REQ;
+		} else if (targ->dv_last_ppr_options != 0) {
+			/*
+			 * Try without QAS or any other PPR options.
+			 * We may need a non-PPR message to work with
+			 * an expander.  We look at the "last PPR options"
+			 * so we will perform this fallback even if the
+			 * target responded to our PPR negotiation with
+			 * no option bits set.
+			 */
+			ppr_options = 0;
+		} else if (width == MSG_EXT_WDTR_BUS_16_BIT) {
+			/*
+			 * If the next narrow speed is greater than
+			 * the next wide speed, fallback to narrow.
+			 * Otherwise fallback to the next DT/Wide setting.
+			 * The narrow async speed will always be smaller
+			 * than the wide async speed, so handle this case
+			 * specifically.
+			 */
+			ppr_options = targ->dv_max_ppr_options;
+			if (narrow_speed > fallback_speed
+			 || period >= AHC_ASYNC_XFER_PERIOD) {
+				targ->dv_next_wide_period = period+1;
+				width = MSG_EXT_WDTR_BUS_8_BIT;
+				period = targ->dv_next_narrow_period;
+			} else {
+				period++;
+			}
+		} else if ((ahc->features & AHC_WIDE) != 0
+			&& tinfo->user.width != 0
+			&& wide_speed >= fallback_speed
+			&& (targ->dv_next_wide_period <= AHC_ASYNC_XFER_PERIOD
+			 || period >= AHC_ASYNC_XFER_PERIOD)) {
+
+			/*
+			 * We are narrow.  Try falling back
+			 * to the next wide speed with 
+			 * all supported ppr options set.
+			 */
+			targ->dv_next_narrow_period = period+1;
+			width = MSG_EXT_WDTR_BUS_16_BIT;
+			period = targ->dv_next_wide_period;
+			ppr_options = targ->dv_max_ppr_options;
+		} else {
+			/* Only narrow fallback is allowed. */
+			period++;
+			ppr_options = targ->dv_max_ppr_options;
+		}
+	} else {
+		ahc_unlock(ahc, &s);
+		return (-1);
+	}
+	offset = MAX_OFFSET;
+	syncrate = ahc_find_syncrate(ahc, &period, &ppr_options,
+				     AHC_SYNCRATE_DT);
+	ahc_set_width(ahc, devinfo, width, AHC_TRANS_GOAL, FALSE);
+	if (period == 0) {
+		period = 0;
+		offset = 0;
+		ppr_options = 0;
+		if (width == MSG_EXT_WDTR_BUS_8_BIT)
+			targ->dv_next_narrow_period = AHC_ASYNC_XFER_PERIOD;
+		else
+			targ->dv_next_wide_period = AHC_ASYNC_XFER_PERIOD;
+	}
+	ahc_set_syncrate(ahc, devinfo, syncrate, period, offset,
+			 ppr_options, AHC_TRANS_GOAL, FALSE);
+	targ->dv_last_ppr_options = ppr_options;
+	ahc_unlock(ahc, &s);
+	return (0);
+}
+
+static void
+ahc_linux_dv_timeout(struct scsi_cmnd *cmd)
+{
+	struct	ahc_softc *ahc;
+	struct	ahc_cmd *acmd;
+	struct	ahc_linux_device *next_dev;
+	struct	scb *scb;
+	u_long	flags;
+
+	ahc = *((struct ahc_softc **)cmd->host->hostdata);
+	ahc_lock(ahc, &flags);
+
+#ifdef AHC_DEBUG
+	if (ahc_debug & AHC_SHOW_DV)
+		printf("%s: Timeout while doing DV command %x.\n",
+		       ahc_name(ahc), cmd->cmnd[0]);
+#endif
+	
+	/*
+	 * Guard against "done race".  No action is
+	 * required if we just completed.
+	 */
+	if ((scb = (struct scb *)cmd->host_scribble) == NULL) {
+		ahc_unlock(ahc, &flags);
+		return;
+	}
+
+	/*
+	 * Command has not completed.  Mark this
+	 * SCB as having failing status prior to
+	 * resetting the bus, so we get the correct
+	 * error code.
+	 */
+	if ((scb->flags & SCB_SENSE) != 0)
+		ahc_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
+	else
+		ahc_set_transaction_status(scb, CAM_CMD_TIMEOUT);
+	ahc_reset_channel(ahc, cmd->channel + 'A', /*initiate*/TRUE);
+
+	/*
+	 * Add a minimal bus settle delay for devices that are slow to
+	 * respond after bus resets.
+	 */
+	ahc_linux_freeze_simq(ahc);
+	init_timer(&ahc->platform_data->reset_timer);
+	ahc->platform_data->reset_timer.data = (u_long)ahc;
+	ahc->platform_data->reset_timer.expires = jiffies + HZ / 2;
+	ahc->platform_data->reset_timer.function =
+	    (ahc_linux_callback_t *)ahc_linux_release_simq;
+	add_timer(&ahc->platform_data->reset_timer);
+	/*
+	 * In 2.5.X, the "done lock" is the ahc_lock.
+	 * Instead of dropping and re-acquiring the same
+	 * lock in the 2.5.X case, just hold our ahc_lock
+	 * the whole time.  ahc_done_lock() has been
+	 * made a no-op for 2.5.X too.
+	 */
+	acmd = TAILQ_FIRST(&ahc->platform_data->completeq);
+	TAILQ_INIT(&ahc->platform_data->completeq);
+	next_dev = ahc_linux_next_device_to_run(ahc);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	ahc_unlock(ahc, &flags);
+#endif
+	if (next_dev)
+		ahc_schedule_runq(ahc);
+	if (acmd != NULL) {
+		acmd = ahc_linux_run_complete_queue(ahc, acmd);
+		if (acmd != NULL) {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+			ahc_lock(ahc, &flags);
+#endif
+			ahc_schedule_completeq(ahc, acmd);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+			ahc_unlock(ahc, &flags);
+#endif
+		}
+	}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+	ahc_unlock(ahc, &flags);
+#endif
+}
+
+static void
+ahc_linux_dv_complete(struct scsi_cmnd *cmd)
+{
+	struct ahc_softc *ahc;
+
+	ahc = *((struct ahc_softc **)cmd->host->hostdata);
+
+	/* Delete the DV timer before it goes off! */
+	scsi_delete_timer(cmd);
+
+#ifdef AHC_DEBUG
+	if (ahc_debug & AHC_SHOW_DV)
+		printf("%s:%d:%d: Command completed, status= 0x%x\n",
+		       ahc_name(ahc), cmd->channel, cmd->target, cmd->result);
+#endif
+
+	/* Wake up the state machine */
+	up(&ahc->platform_data->dv_cmd_sem);
+}
+
+static void
+ahc_linux_generate_dv_pattern(struct ahc_linux_target *targ)
+{
+	uint16_t b;
+	u_int	 i;
+	u_int	 j;
+
+	if (targ->dv_buffer != NULL)
+		free(targ->dv_buffer, M_DEVBUF);
+	targ->dv_buffer = malloc(targ->dv_echo_size, M_DEVBUF, M_WAITOK);
+	if (targ->dv_buffer1 != NULL)
+		free(targ->dv_buffer1, M_DEVBUF);
+	targ->dv_buffer1 = malloc(targ->dv_echo_size, M_DEVBUF, M_WAITOK);
+
+	i = 0;
+	b = 0x0001;
+	for (j = 0 ; i < targ->dv_echo_size; j++) {
+		if (j < 32) {
+			/*
+			 * 32bytes of sequential numbers.
+			 */
+			targ->dv_buffer[i++] = j & 0xff;
+		} else if (j < 48) {
+			/*
+			 * 32bytes of repeating 0x0000, 0xffff.
+			 */
+			targ->dv_buffer[i++] = (j & 0x02) ? 0xff : 0x00;
+		} else if (j < 64) {
+			/*
+			 * 32bytes of repeating 0x5555, 0xaaaa.
+			 */
+			targ->dv_buffer[i++] = (j & 0x02) ? 0xaa : 0x55;
+		} else {
+			/*
+			 * Remaining buffer is filled with a repeating
+			 * patter of:
+			 *
+			 *	 0xffff
+			 *	~0x0001 << shifted once in each loop.
+			 */
+			if (j & 0x02) {
+				if (j & 0x01) {
+					targ->dv_buffer[i++] = ~(b >> 8) & 0xff;
+					b <<= 1;
+					if (b == 0x0000)
+						b = 0x0001;
+				} else {
+					targ->dv_buffer[i++] = (~b & 0xff);
+				}
+			} else {
+				targ->dv_buffer[i++] = 0xff;
+			}
+		}
+	}
+}
+
+static u_int
+ahc_linux_user_tagdepth(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
+{
+	static int warned_user;
+	u_int tags;
+
+	tags = 0;
+	if ((ahc->user_discenable & devinfo->target_mask) != 0) {
+		if (warned_user == 0
+		 && ahc->unit >= NUM_ELEMENTS(aic7xxx_tag_info)) {
+
+			printf("aic7xxx: WARNING, insufficient "
+			       "tag_info instances for installed "
+			       "controllers. Using defaults\n");
+			printf("aic7xxx: Please update the "
+			       "aic7xxx_tag_info array in the "
+			       "aic7xxx.c source file.\n");
+			tags = AHC_MAX_QUEUE;
+			warned_user++;
+		} else {
+			adapter_tag_info_t *tag_info;
+
+			tag_info = &aic7xxx_tag_info[ahc->unit];
+			tags = tag_info->tag_commands[devinfo->target_offset];
+			if (tags > AHC_MAX_QUEUE)
+				tags = AHC_MAX_QUEUE;
+		}
+	}
+	return (tags);
+}
+
+static u_int
+ahc_linux_user_dv_setting(struct ahc_softc *ahc)
+{
+	static int warned_user;
+	int dv;
+
+	if (warned_user == 0
+	 && ahc->unit >= NUM_ELEMENTS(aic7xxx_dv_settings)) {
+
+		printf("aic7xxx: WARNING, insufficient "
+		       "dv settings instances for installed "
+		       "controllers. Using defaults\n");
+		printf("aic7xxx: Please update the "
+		       "aic7xxx_dv_settings array in the "
+		       "aic7xxx.c source file.\n");
+		dv = -1;
+		warned_user++;
+	} else {
+
+		dv = aic7xxx_dv_settings[ahc->unit];
+	}
+
+	if (dv < 0) {
+		u_long s;
+
+		/*
+		 * Apply the default.
+		 */
+		/*
+		 * XXX - Enable DV on non-U160 controllers once it
+		 *       has been tested there.
+		 */
+		ahc_lock(ahc, &s);
+		dv = (ahc->features & AHC_DT);
+		if (ahc->seep_config != 0
+		 && ahc->seep_config->signature >= CFSIGNATURE2)
+			dv = (ahc->seep_config->adapter_control & CFENABLEDV);
+		ahc_unlock(ahc, &s);
+	}
+	return (dv);
+}
+
+/*
+ * Determines the queue depth for a given device.
+ */
+static void
+ahc_linux_device_queue_depth(struct ahc_softc *ahc,
+			     struct ahc_linux_device *dev)
+{
+	struct	ahc_devinfo devinfo;
+	u_int	tags;
+
+	ahc_compile_devinfo(&devinfo,
+			    dev->target->channel == 0
+			  ? ahc->our_id : ahc->our_id_b,
+			    dev->target->target, dev->lun,
+			    dev->target->channel == 0 ? 'A' : 'B',
+			    ROLE_INITIATOR);
+	tags = ahc_linux_user_tagdepth(ahc, &devinfo);
+	if (tags != 0
+	 && dev->scsi_device != NULL
+	 && dev->scsi_device->tagged_supported != 0) {
+
+		ahc_set_tags(ahc, &devinfo, AHC_QUEUE_TAGGED);
+		printf("scsi%d:%c:%d:%d: Tagged Queuing enabled.  Depth %d\n",
+	       	       ahc->platform_data->host->host_no, devinfo.channel,
+		       devinfo.target, devinfo.lun, tags);
+	} else {
+		ahc_set_tags(ahc, &devinfo, AHC_QUEUE_NONE);
+	}
+}
+
+static void
+ahc_linux_run_device_queue(struct ahc_softc *ahc, struct ahc_linux_device *dev)
+{
+	struct	 ahc_cmd *acmd;
+	struct	 scsi_cmnd *cmd;
+	struct	 scb *scb;
+	struct	 hardware_scb *hscb;
+	struct	 ahc_initiator_tinfo *tinfo;
+	struct	 ahc_tmode_tstate *tstate;
+	uint16_t mask;
+
+	if ((dev->flags & AHC_DEV_ON_RUN_LIST) != 0)
+		panic("running device on run list");
+
+	while ((acmd = TAILQ_FIRST(&dev->busyq)) != NULL
+	    && dev->openings > 0 && dev->qfrozen == 0) {
+
+		/*
+		 * Schedule us to run later.  The only reason we are not
+		 * running is because the whole controller Q is frozen.
+		 */
+		if (ahc->platform_data->qfrozen != 0
+	 	 && AHC_DV_SIMQ_FROZEN(ahc) == 0) {
+			TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq,
+					  dev, links);
+			dev->flags |= AHC_DEV_ON_RUN_LIST;
+			return;
+		}
+		/*
+		 * Get an scb to use.
+		 */
+		if ((scb = ahc_get_scb(ahc)) == NULL) {
+			TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq,
+					 dev, links);
+			dev->flags |= AHC_DEV_ON_RUN_LIST;
+			ahc->flags |= AHC_RESOURCE_SHORTAGE;
+			return;
+		}
+		TAILQ_REMOVE(&dev->busyq, acmd, acmd_links.tqe);
+		cmd = &acmd_scsi_cmd(acmd);
+		scb->io_ctx = cmd;
+		scb->platform_data->dev = dev;
+		hscb = scb->hscb;
+		cmd->host_scribble = (char *)scb;
+
+		/*
+		 * Fill out basics of the HSCB.
+		 */
+		hscb->control = 0;
+		hscb->scsiid = BUILD_SCSIID(ahc, cmd);
+		hscb->lun = cmd->lun;
+		mask = SCB_GET_TARGET_MASK(ahc, scb);
+		tinfo = ahc_fetch_transinfo(ahc, SCB_GET_CHANNEL(ahc, scb),
+					    SCB_GET_OUR_ID(scb),
+					    SCB_GET_TARGET(ahc, scb), &tstate);
+		hscb->scsirate = tinfo->scsirate;
+		hscb->scsioffset = tinfo->curr.offset;
+		if ((tstate->ultraenb & mask) != 0)
+			hscb->control |= ULTRAENB;
+
+		if ((ahc->user_discenable & mask) != 0)
+			hscb->control |= DISCENB;
+
+	 	if (AHC_DV_CMD(cmd) != 0)
+			scb->flags |= SCB_SILENT;
+
+		if ((tstate->auto_negotiate & mask) != 0) {
+			scb->flags |= SCB_AUTO_NEGOTIATE;
+			scb->hscb->control |= MK_MESSAGE;
+		}
+
+		if ((dev->flags & (AHC_DEV_Q_TAGGED|AHC_DEV_Q_BASIC)) != 0) {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+			int	msg_bytes;
+			uint8_t tag_msgs[2];
+
+			msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
+			if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
+				hscb->control |= tag_msgs[0];
+				if (tag_msgs[0] == MSG_ORDERED_TASK)
+					dev->commands_since_idle_or_otag = 0;
+			} else
+#endif
+			if (dev->commands_since_idle_or_otag == AHC_OTAG_THRESH
+			 && (dev->flags & AHC_DEV_Q_TAGGED) != 0) {
+				hscb->control |= MSG_ORDERED_TASK;
+				dev->commands_since_idle_or_otag = 0;
+			} else {
+				hscb->control |= MSG_SIMPLE_TASK;
+			}
+		}
+
+		hscb->cdb_len = cmd->cmd_len;
+		if (hscb->cdb_len <= 12) {
+			memcpy(hscb->shared_data.cdb, cmd->cmnd, hscb->cdb_len);
+		} else {
+			memcpy(hscb->cdb32, cmd->cmnd, hscb->cdb_len);
+			scb->flags |= SCB_CDB32_PTR;
+		}
+
+		scb->platform_data->xfer_len = 0;
+		ahc_set_residual(scb, 0);
+		ahc_set_sense_residual(scb, 0);
+		scb->sg_count = 0;
+		if (cmd->use_sg != 0) {
+			struct	ahc_dma_seg *sg;
+			struct	scatterlist *cur_seg;
+			struct	scatterlist *end_seg;
+			int	nseg;
+
+			cur_seg = (struct scatterlist *)cmd->request_buffer;
+			nseg = pci_map_sg(ahc->dev_softc, cur_seg, cmd->use_sg,
+				 scsi_to_pci_dma_dir(cmd ->sc_data_direction));
+			end_seg = cur_seg + nseg;
+			/* Copy the segments into the SG list. */
+			sg = scb->sg_list;
+			/*
+			 * The sg_count may be larger than nseg if
+			 * a transfer crosses a 32bit page.
+			 */ 
+			while (cur_seg < end_seg) {
+				bus_addr_t addr;
+				bus_size_t len;
+				int consumed;
+
+				addr = sg_dma_address(cur_seg);
+				len = sg_dma_len(cur_seg);
+				consumed = ahc_linux_map_seg(ahc, scb,
+							     sg, addr, len);
+				sg += consumed;
+				scb->sg_count += consumed;
+				cur_seg++;
+			}
+			sg--;
+			sg->len |= ahc_htole32(AHC_DMA_LAST_SEG);
+
+			/*
+			 * Reset the sg list pointer.
+			 */
+			scb->hscb->sgptr =
+			    ahc_htole32(scb->sg_list_phys | SG_FULL_RESID);
+
+			/*
+			 * Copy the first SG into the "current"
+			 * data pointer area.
+			 */
+			scb->hscb->dataptr = scb->sg_list->addr;
+			scb->hscb->datacnt = scb->sg_list->len;
+		} else if (cmd->request_bufflen != 0) {
+			struct	 ahc_dma_seg *sg;
+			bus_addr_t addr;
+
+			sg = scb->sg_list;
+			addr = pci_map_single(ahc->dev_softc,
+			       cmd->request_buffer,
+			       cmd->request_bufflen,
+			       scsi_to_pci_dma_dir(cmd->sc_data_direction));
+			scb->platform_data->buf_busaddr = addr;
+			scb->sg_count = ahc_linux_map_seg(ahc, scb,
+							  sg, addr,
+							  cmd->request_bufflen);
+			sg->len |= ahc_htole32(AHC_DMA_LAST_SEG);
+
+			/*
+			 * Reset the sg list pointer.
+			 */
+			scb->hscb->sgptr =
+			    ahc_htole32(scb->sg_list_phys | SG_FULL_RESID);
+
+			/*
+			 * Copy the first SG into the "current"
+			 * data pointer area.
+			 */
+			scb->hscb->dataptr = sg->addr;
+			scb->hscb->datacnt = sg->len;
+		} else {
+			scb->hscb->sgptr = ahc_htole32(SG_LIST_NULL);
+			scb->hscb->dataptr = 0;
+			scb->hscb->datacnt = 0;
+			scb->sg_count = 0;
+		}
+
+		ahc_sync_sglist(ahc, scb, BUS_DMASYNC_PREWRITE);
+		LIST_INSERT_HEAD(&ahc->pending_scbs, scb, pending_links);
+		dev->openings--;
+		dev->active++;
+		dev->commands_issued++;
+		if ((dev->flags & AHC_DEV_PERIODIC_OTAG) != 0)
+			dev->commands_since_idle_or_otag++;
+
+		/*
+		 * We only allow one untagged transaction
+		 * per target in the initiator role unless
+		 * we are storing a full busy target *lun*
+		 * table in SCB space.
+		 */
+		if ((scb->hscb->control & (TARGET_SCB|TAG_ENB)) == 0
+		 && (ahc->features & AHC_SCB_BTT) == 0) {
+			struct scb_tailq *untagged_q;
+			int target_offset;
+
+			target_offset = SCB_GET_TARGET_OFFSET(ahc, scb);
+			untagged_q = &(ahc->untagged_queues[target_offset]);
+			TAILQ_INSERT_TAIL(untagged_q, scb, links.tqe);
+			scb->flags |= SCB_UNTAGGEDQ;
+			if (TAILQ_FIRST(untagged_q) != scb)
+				continue;
+		}
+		scb->flags |= SCB_ACTIVE;
+		ahc_queue_scb(ahc, scb);
+	}
+}
+
+/*
+ * SCSI controller interrupt handler.
+ */
+void
+ahc_linux_isr(int irq, void *dev_id, struct pt_regs * regs)
+{
+	struct	ahc_softc *ahc;
+	struct	ahc_cmd *acmd;
+	u_long	flags;
+	struct	ahc_linux_device *next_dev;
+
+	ahc = (struct ahc_softc *) dev_id;
+	ahc_lock(ahc, &flags); 
+	ahc_intr(ahc);
+	acmd = TAILQ_FIRST(&ahc->platform_data->completeq);
+	TAILQ_INIT(&ahc->platform_data->completeq);
+	next_dev = ahc_linux_next_device_to_run(ahc);
+	/*
+	 * In 2.5.X, the "done lock" is the ahc_lock.
+	 * Instead of dropping and re-acquiring the same
+	 * lock in the 2.5.X case, just hold our ahc_lock
+	 * the whole time.  ahc_done_lock() has been
+	 * made a no-op for 2.5.X too.
+	 */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	ahc_unlock(ahc, &flags);
+#endif
+	if (next_dev)
+		ahc_schedule_runq(ahc);
+	if (acmd != NULL) {
+		acmd = ahc_linux_run_complete_queue(ahc, acmd);
+		if (acmd != NULL) {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+			ahc_lock(ahc, &flags);
+#endif
+			ahc_schedule_completeq(ahc, acmd);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+			ahc_unlock(ahc, &flags);
+#endif
+		}
+	}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
+	ahc_unlock(ahc, &flags);
+#endif
+}
+
+void
+ahc_platform_flushwork(struct ahc_softc *ahc)
+{
+	struct ahc_cmd *acmd;
+
+	acmd = TAILQ_FIRST(&ahc->platform_data->completeq);
+	TAILQ_INIT(&ahc->platform_data->completeq);
+	while (acmd != NULL)
+		acmd = ahc_linux_run_complete_queue(ahc, acmd);
+}
+
+static struct ahc_linux_target*
+ahc_linux_alloc_target(struct ahc_softc *ahc, u_int channel, u_int target)
+{
+	struct ahc_linux_target *targ;
+	u_int target_offset;
+
+	target_offset = target;
+	if (channel != 0)
+		target_offset += 8;
+	/*
+	 * Never allow allocation of a target object for
+	 * our own SCSIID.
+	 */
+	if ((channel == 0 && target == ahc->our_id)
+	 || (channel == 1 && target == ahc->our_id_b)) {
+		ahc->platform_data->targets[target_offset] = NULL;
+		return (NULL);
+	}
+
+	targ = malloc(sizeof(*targ), M_DEVBUG, M_NOWAIT);
+	if (targ == NULL)
+		return (NULL);
+	memset(targ, 0, sizeof(*targ));
+	targ->channel = channel;
+	targ->target = target;
+	targ->ahc = ahc;
+	targ->flags = AHC_DV_REQUIRED;
+	ahc->platform_data->targets[target_offset] = targ;
+	return (targ);
+}
+
+static void
+ahc_linux_free_target(struct ahc_softc *ahc, struct ahc_linux_target *targ)
+{
+	struct ahc_devinfo devinfo;
+	struct ahc_initiator_tinfo *tinfo;
+	struct ahc_tmode_tstate *tstate;
+	u_int our_id;
+	u_int target_offset;
+	char channel;
+
+	/*
+	 * Force a negotiation to async/narrow on any
+	 * future command to this device unless a bus
+	 * reset occurs between now and that command.
+	 */
+	channel = 'A' + targ->channel;
+	our_id = ahc->our_id;
+	target_offset = targ->target;
+	if (targ->channel != 0) {
+		target_offset += 8;
+		our_id = ahc->our_id_b;
+	}
+	tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
+				    targ->target, &tstate);
+	ahc_compile_devinfo(&devinfo, our_id, targ->target, CAM_LUN_WILDCARD,
+			    channel, ROLE_INITIATOR);
+	ahc_set_syncrate(ahc, &devinfo, NULL, 0, 0, 0,
+			 AHC_TRANS_GOAL, /*paused*/FALSE);
+	ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
+		      AHC_TRANS_GOAL, /*paused*/FALSE);
+	ahc_update_neg_request(ahc, &devinfo, tstate, tinfo, AHC_NEG_ALWAYS);
+	ahc->platform_data->targets[target_offset] = NULL;
+	if (targ->inq_data != NULL)
+		free(targ->inq_data, M_DEVBUF);
+	if (targ->dv_buffer != NULL)
+		free(targ->dv_buffer, M_DEVBUF);
+	if (targ->dv_buffer1 != NULL)
+		free(targ->dv_buffer1, M_DEVBUF);
+	free(targ, M_DEVBUF);
+}
+
+static struct ahc_linux_device*
+ahc_linux_alloc_device(struct ahc_softc *ahc,
+		 struct ahc_linux_target *targ, u_int lun)
+{
+	struct ahc_linux_device *dev;
+
+	dev = malloc(sizeof(*dev), M_DEVBUG, M_NOWAIT);
+	if (dev == NULL)
+		return (NULL);
+	memset(dev, 0, sizeof(*dev));
+	init_timer(&dev->timer);
+	TAILQ_INIT(&dev->busyq);
+	dev->flags = AHC_DEV_UNCONFIGURED;
+	dev->lun = lun;
+	dev->target = targ;
+
+	/*
+	 * We start out life using untagged
+	 * transactions of which we allow one.
+	 */
+	dev->openings = 1;
+
+	/*
+	 * Set maxtags to 0.  This will be changed if we
+	 * later determine that we are dealing with
+	 * a tagged queuing capable device.
+	 */
+	dev->maxtags = 0;
+	
+	targ->refcount++;
+	targ->devices[lun] = dev;
+	return (dev);
+}
+
+static void
+ahc_linux_free_device(struct ahc_softc *ahc, struct ahc_linux_device *dev)
+{
+	struct ahc_linux_target *targ;
+
+	del_timer(&dev->timer);
+	targ = dev->target;
+	targ->devices[dev->lun] = NULL;
+	free(dev, M_DEVBUF);
+	targ->refcount--;
+	if (targ->refcount == 0
+	 && (targ->flags & AHC_DV_REQUIRED) == 0)
+		ahc_linux_free_target(ahc, targ);
+}
+
+void
+ahc_send_async(struct ahc_softc *ahc, char channel,
+	       u_int target, u_int lun, ac_code code, void *arg)
+{
+	switch (code) {
+	case AC_TRANSFER_NEG:
+	{
+		char	buf[80];
+		struct	ahc_linux_target *targ;
+		struct	info_str info;
+		struct	ahc_initiator_tinfo *tinfo;
+		struct	ahc_tmode_tstate *tstate;
+		int	target_offset;
+
+		info.buffer = buf;
+		info.length = sizeof(buf);
+		info.offset = 0;
+		info.pos = 0;
+		tinfo = ahc_fetch_transinfo(ahc, channel,
+						channel == 'A' ? ahc->our_id
+							       : ahc->our_id_b,
+						target, &tstate);
+
+		/*
+		 * Don't bother reporting results while
+		 * negotiations are still pending.
+		 */
+		if (tinfo->curr.period != tinfo->goal.period
+		 || tinfo->curr.width != tinfo->goal.width
+		 || tinfo->curr.offset != tinfo->goal.offset
+		 || tinfo->curr.ppr_options != tinfo->goal.ppr_options)
+			if (bootverbose == 0)
+				break;
+
+		/*
+		 * Don't bother reporting results that
+		 * are identical to those last reported.
+		 */
+		target_offset = target;
+		if (channel == 'B')
+			target_offset += 8;
+		targ = ahc->platform_data->targets[target_offset];
+		if (targ == NULL)
+			break;
+		if (tinfo->curr.period == targ->last_tinfo.period
+		 && tinfo->curr.width == targ->last_tinfo.width
+		 && tinfo->curr.offset == targ->last_tinfo.offset
+		 && tinfo->curr.ppr_options == targ->last_tinfo.ppr_options)
+			if (bootverbose == 0)
+				break;
+
+		targ->last_tinfo.period = tinfo->curr.period;
+		targ->last_tinfo.width = tinfo->curr.width;
+		targ->last_tinfo.offset = tinfo->curr.offset;
+		targ->last_tinfo.ppr_options = tinfo->curr.ppr_options;
+
+		printf("(%s:%c:", ahc_name(ahc), channel);
+		if (target == CAM_TARGET_WILDCARD)
+			printf("*): ");
+		else
+			printf("%d): ", target);
+		ahc_format_transinfo(&info, &tinfo->curr);
+		if (info.pos < info.length)
+			*info.buffer = '\0';
+		else
+			buf[info.length - 1] = '\0';
+		printf("%s", buf);
+		break;
+	}
+        case AC_SENT_BDR:
+		break;
+        case AC_BUS_RESET:
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+		if (ahc->platform_data->host != NULL) {
+			scsi_report_bus_reset(ahc->platform_data->host,
+					      channel - 'A');
+		}
+#endif
+                break;
+        default:
+                panic("ahc_send_async: Unexpected async event");
+        }
+}
+
+/*
+ * Calls the higher level scsi done function and frees the scb.
+ */
+void
+ahc_done(struct ahc_softc *ahc, struct scb *scb)
+{
+	Scsi_Cmnd *cmd;
+	struct	   ahc_linux_device *dev;
+
+	LIST_REMOVE(scb, pending_links);
+	if ((scb->flags & SCB_UNTAGGEDQ) != 0) {
+		struct scb_tailq *untagged_q;
+		int target_offset;
+
+		target_offset = SCB_GET_TARGET_OFFSET(ahc, scb);
+		untagged_q = &(ahc->untagged_queues[target_offset]);
+		TAILQ_REMOVE(untagged_q, scb, links.tqe);
+		ahc_run_untagged_queue(ahc, untagged_q);
+	}
+
+	if ((scb->flags & SCB_ACTIVE) == 0) {
+		printf("SCB %d done'd twice\n", scb->hscb->tag);
+		ahc_dump_card_state(ahc);
+		panic("Stopping for safety");
+	}
+	cmd = scb->io_ctx;
+	dev = scb->platform_data->dev;
+	dev->active--;
+	dev->openings++;
+	if ((cmd->result & (CAM_DEV_QFRZN << 16)) != 0) {
+		cmd->result &= ~(CAM_DEV_QFRZN << 16);
+		dev->qfrozen--;
+	}
+	ahc_linux_unmap_scb(ahc, scb);
+
+	/*
+	 * Guard against stale sense data.
+	 * The Linux mid-layer assumes that sense
+	 * was retrieved anytime the first byte of
+	 * the sense buffer looks "sane".
+	 */
+	cmd->sense_buffer[0] = 0;
+	if (ahc_get_transaction_status(scb) == CAM_REQ_INPROG) {
+		uint32_t amount_xferred;
+
+		amount_xferred =
+		    ahc_get_transfer_length(scb) - ahc_get_residual(scb);
+		if ((scb->flags & SCB_TRANSMISSION_ERROR) != 0) {
+#ifdef AHC_DEBUG
+			if ((ahc_debug & AHC_SHOW_MISC) != 0) {
+				ahc_print_path(ahc, scb);
+				printf("Set CAM_UNCOR_PARITY\n");
+			}
+#endif
+			ahc_set_transaction_status(scb, CAM_UNCOR_PARITY);
+		} else if (amount_xferred < scb->io_ctx->underflow) {
+			printf("Saw underflow (%ld of %ld bytes). "
+			       "Treated as error\n",
+				ahc_get_residual(scb),
+				ahc_get_transfer_length(scb));
+			ahc_set_transaction_status(scb, CAM_DATA_RUN_ERR);
+		} else {
+			ahc_set_transaction_status(scb, CAM_REQ_CMP);
+		}
+	} else if (ahc_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
+		ahc_linux_handle_scsi_status(ahc, dev, scb);
+	} else if (ahc_get_transaction_status(scb) == CAM_SEL_TIMEOUT) {
+		dev->flags |= AHC_DEV_UNCONFIGURED;
+		if (AHC_DV_CMD(cmd) == FALSE)
+			dev->target->flags &= ~AHC_DV_REQUIRED;
+	}
+	/*
+	 * Start DV for devices that require it assuming the first command
+	 * sent does not result in a selection timeout.
+	 */
+	if (ahc_get_transaction_status(scb) != CAM_SEL_TIMEOUT
+	 && (dev->target->flags & AHC_DV_REQUIRED) != 0)
+		ahc_linux_start_dv(ahc);
+
+	if (dev->openings == 1
+	 && ahc_get_transaction_status(scb) == CAM_REQ_CMP
+	 && ahc_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL)
+		dev->tag_success_count++;
+	/*
+	 * Some devices deal with temporary internal resource
+	 * shortages by returning queue full.  When the queue
+	 * full occurrs, we throttle back.  Slowly try to get
+	 * back to our previous queue depth.
+	 */
+	if ((dev->openings + dev->active) < dev->maxtags
+	 && dev->tag_success_count > AHC_TAG_SUCCESS_INTERVAL) {
+		dev->tag_success_count = 0;
+		dev->openings++;
+	}
+
+	if (dev->active == 0)
+		dev->commands_since_idle_or_otag = 0;
+
+	if (TAILQ_EMPTY(&dev->busyq)) {
+		if ((dev->flags & AHC_DEV_UNCONFIGURED) != 0
+		 && dev->active == 0)
+			ahc_linux_free_device(ahc, dev);
+	} else if ((dev->flags & AHC_DEV_ON_RUN_LIST) == 0) {
+		TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq, dev, links);
+		dev->flags |= AHC_DEV_ON_RUN_LIST;
+	}
+
+	if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
+		printf("Recovery SCB completes\n");
+		if (ahc_get_transaction_status(scb) == CAM_BDR_SENT
+		 || ahc_get_transaction_status(scb) == CAM_REQ_ABORTED)
+			ahc_set_transaction_status(scb, CAM_CMD_TIMEOUT);
+		if ((scb->platform_data->flags & AHC_UP_EH_SEMAPHORE) != 0) {
+			scb->platform_data->flags &= ~AHC_UP_EH_SEMAPHORE;
+			up(&ahc->platform_data->eh_sem);
+		}
+	}
+
+	ahc_free_scb(ahc, scb);
+	ahc_linux_queue_cmd_complete(ahc, cmd);
+
+	if ((ahc->platform_data->flags & AHC_DV_WAIT_SIMQ_EMPTY) != 0
+	 && LIST_FIRST(&ahc->pending_scbs) == NULL) {
+		ahc->platform_data->flags &= ~AHC_DV_WAIT_SIMQ_EMPTY;
+		up(&ahc->platform_data->dv_sem);
+	}
+		
+}
+
+static void
+ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
+			     struct ahc_linux_device *dev, struct scb *scb)
+{
+	struct	ahc_devinfo devinfo;
+
+	ahc_compile_devinfo(&devinfo,
+			    ahc->our_id,
+			    dev->target->target, dev->lun,
+			    dev->target->channel == 0 ? 'A' : 'B',
+			    ROLE_INITIATOR);
+	
+	/*
+	 * We don't currently trust the mid-layer to
+	 * properly deal with queue full or busy.  So,
+	 * when one occurs, we tell the mid-layer to
+	 * unconditionally requeue the command to us
+	 * so that we can retry it ourselves.  We also
+	 * implement our own throttling mechanism so
+	 * we don't clobber the device with too many
+	 * commands.
+	 */
+	switch (ahc_get_scsi_status(scb)) {
+	default:
+		break;
+	case SCSI_STATUS_CHECK_COND:
+	case SCSI_STATUS_CMD_TERMINATED:
+	{
+		Scsi_Cmnd *cmd;
+
+		/*
+		 * Copy sense information to the OS's cmd
+		 * structure if it is available.
+		 */
+		cmd = scb->io_ctx;
+		if (scb->flags & SCB_SENSE) {
+			u_int sense_size;
+
+			sense_size = MIN(sizeof(struct scsi_sense_data)
+				       - ahc_get_sense_residual(scb),
+					 sizeof(cmd->sense_buffer));
+			memcpy(cmd->sense_buffer,
+			       ahc_get_sense_buf(ahc, scb), sense_size);
+			if (sense_size < sizeof(cmd->sense_buffer))
+				memset(&cmd->sense_buffer[sense_size], 0,
+				       sizeof(cmd->sense_buffer) - sense_size);
+			cmd->result |= (DRIVER_SENSE << 24);
+		}
+		break;
+	}
+	case SCSI_STATUS_QUEUE_FULL:
+	{
+		/*
+		 * By the time the core driver has returned this
+		 * command, all other commands that were queued
+		 * to us but not the device have been returned.
+		 * This ensures that dev->active is equal to
+		 * the number of commands actually queued to
+		 * the device.
+		 */
+		dev->tag_success_count = 0;
+		if (dev->active != 0) {
+			/*
+			 * Drop our opening count to the number
+			 * of commands currently outstanding.
+			 */
+			dev->openings = 0;
+/*
+			ahc_print_path(ahc, scb);
+			printf("Dropping tag count to %d\n", dev->active);
+ */
+			if (dev->active == dev->tags_on_last_queuefull) {
+
+				dev->last_queuefull_same_count++;
+				/*
+				 * If we repeatedly see a queue full
+				 * at the same queue depth, this
+				 * device has a fixed number of tag
+				 * slots.  Lock in this tag depth
+				 * so we stop seeing queue fulls from
+				 * this device.
+				 */
+				if (dev->last_queuefull_same_count
+				 == AHC_LOCK_TAGS_COUNT) {
+					dev->maxtags = dev->active;
+					ahc_print_path(ahc, scb);
+					printf("Locking max tag count at %d\n",
+					       dev->active);
+				}
+			} else {
+				dev->tags_on_last_queuefull = dev->active;
+				dev->last_queuefull_same_count = 0;
+			}
+			ahc_set_transaction_status(scb, CAM_REQUEUE_REQ);
+			ahc_set_scsi_status(scb, SCSI_STATUS_OK);
+			ahc_set_tags(ahc, &devinfo,
+				     (dev->flags & AHC_DEV_Q_BASIC)
+				   ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED);
+			break;
+		}
+		/*
+		 * Drop down to a single opening, and treat this
+		 * as if the target returned BUSY SCSI status.
+		 */
+		dev->openings = 1;
+		ahc_set_scsi_status(scb, SCSI_STATUS_BUSY);
+		ahc_set_tags(ahc, &devinfo,
+			     (dev->flags & AHC_DEV_Q_BASIC)
+			   ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED);
+		/* FALLTHROUGH */
+	}
+	case SCSI_STATUS_BUSY:
+	{
+		/*
+		 * Set a short timer to defer sending commands for
+		 * a bit since Linux will not delay in this case.
+		 */
+		if ((dev->flags & AHC_DEV_TIMER_ACTIVE) != 0) {
+			printf("%s:%c:%d: Device Timer still active during "
+			       "busy processing\n", ahc_name(ahc),
+				dev->target->channel, dev->target->target);
+			break;
+		}
+		dev->flags |= AHC_DEV_TIMER_ACTIVE;
+		dev->qfrozen++;
+		init_timer(&dev->timer);
+		dev->timer.data = (u_long)dev;
+		dev->timer.expires = jiffies + (HZ/2);
+		dev->timer.function = ahc_linux_dev_timed_unfreeze;
+		add_timer(&dev->timer);
+		break;
+	}
+	}
+}
+
+static void
+ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, Scsi_Cmnd *cmd)
+{
+	/*
+	 * Typically, the complete queue has very few entries
+	 * queued to it before the queue is emptied by
+	 * ahc_linux_run_complete_queue, so sorting the entries
+	 * by generation number should be inexpensive.
+	 * We perform the sort so that commands that complete
+	 * with an error are retuned in the order origionally
+	 * queued to the controller so that any subsequent retries
+	 * are performed in order.  The underlying ahc routines do
+	 * not guarantee the order that aborted commands will be
+	 * returned to us.
+	 */
+	struct ahc_completeq *completeq;
+	struct ahc_cmd *list_cmd;
+	struct ahc_cmd *acmd;
+
+	/*
+	 * Map CAM error codes into Linux Error codes.  We
+	 * avoid the conversion so that the DV code has the
+	 * full error information available when making
+	 * state change decisions.
+	 */
+	if (AHC_DV_CMD(cmd) == FALSE) {
+		u_int new_status;
+
+		switch (ahc_cmd_get_transaction_status(cmd)) {
+		case CAM_REQ_INPROG:
+		case CAM_REQ_CMP:
+		case CAM_SCSI_STATUS_ERROR:
+			new_status = DID_OK;
+			break;
+		case CAM_REQ_ABORTED:
+			new_status = DID_ABORT;
+			break;
+		case CAM_BUSY:
+			new_status = DID_BUS_BUSY;
+			break;
+		case CAM_REQ_INVALID:
+		case CAM_PATH_INVALID:
+			new_status = DID_BAD_TARGET;
+			break;
+		case CAM_SEL_TIMEOUT:
+			new_status = DID_NO_CONNECT;
+			break;
+		case CAM_SCSI_BUS_RESET:
+		case CAM_BDR_SENT:
+			new_status = DID_RESET;
+			break;
+		case CAM_UNCOR_PARITY:
+			new_status = DID_PARITY;
+			break;
+		case CAM_CMD_TIMEOUT:
+			new_status = DID_TIME_OUT;
+			break;
+		case CAM_UA_ABORT:
+		case CAM_REQ_CMP_ERR:
+		case CAM_AUTOSENSE_FAIL:
+		case CAM_NO_HBA:
+		case CAM_DATA_RUN_ERR:
+		case CAM_UNEXP_BUSFREE:
+		case CAM_SEQUENCE_FAIL:
+		case CAM_CCB_LEN_ERR:
+		case CAM_PROVIDE_FAIL:
+		case CAM_REQ_TERMIO:
+		case CAM_UNREC_HBA_ERROR:
+		case CAM_REQ_TOO_BIG:
+			new_status = DID_ERROR;
+			break;
+		case CAM_REQUEUE_REQ:
+			/*
+			 * If we want the request requeued, make sure there
+			 * are sufficent retries.  In the old scsi error code,
+			 * we used to be able to specify a result code that
+			 * bypassed the retry count.  Now we must use this
+			 * hack.  We also "fake" a check condition with
+			 * a sense code of ABORTED COMMAND.  This seems to
+			 * evoke a retry even if this command is being sent
+			 * via the eh thread.  Ick!  Ick!  Ick!
+			 */
+			cmd->retries--;
+			new_status = DID_OK;
+			ahc_cmd_set_scsi_status(cmd, SCSI_STATUS_CHECK_COND);
+			cmd->result |= (DRIVER_SENSE << 24);
+			memset(cmd->sense_buffer, 0,
+			       sizeof(cmd->sense_buffer));
+			cmd->sense_buffer[0] = SSD_ERRCODE_VALID
+					     | SSD_CURRENT_ERROR;
+			cmd->sense_buffer[2] = SSD_KEY_ABORTED_COMMAND;
+			break;
+		default:
+			/* We should never get here */
+			new_status = DID_ERROR;
+			break;
+		}
+
+		ahc_cmd_set_transaction_status(cmd, new_status);
+	}
+
+	completeq = &ahc->platform_data->completeq;
+	list_cmd = TAILQ_FIRST(completeq);
+	acmd = (struct ahc_cmd *)cmd;
+	while (list_cmd != NULL
+	    && acmd_scsi_cmd(list_cmd).serial_number
+	     < acmd_scsi_cmd(acmd).serial_number)
+		list_cmd = TAILQ_NEXT(list_cmd, acmd_links.tqe);
+	if (list_cmd != NULL)
+		TAILQ_INSERT_BEFORE(list_cmd, acmd, acmd_links.tqe);
+	else
+		TAILQ_INSERT_TAIL(completeq, acmd, acmd_links.tqe);
+}
+
+static void
+ahc_linux_filter_inquiry(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
+{
+	struct	scsi_inquiry_data *sid;
+	struct	ahc_initiator_tinfo *tinfo;
+	struct	ahc_transinfo *user;
+	struct	ahc_transinfo *goal;
+	struct	ahc_transinfo *curr;
+	struct	ahc_tmode_tstate *tstate;
+	struct	ahc_syncrate *syncrate;
+	struct	ahc_linux_device *dev;
+	u_int	maxsync;
+	u_int	width;
+	u_int	period;
+	u_int	offset;
+	u_int	ppr_options;
+	u_int	trans_version;
+	u_int	prot_version;
+
+	/*
+	 * Determine if this lun actually exists.  If so,
+	 * hold on to its corresponding device structure.
+	 * If not, make sure we release the device and
+	 * don't bother processing the rest of this inquiry
+	 * command.
+	 */
+	dev = ahc_linux_get_device(ahc, devinfo->channel - 'A',
+				   devinfo->target, devinfo->lun,
+				   /*alloc*/TRUE);
+
+	sid = (struct scsi_inquiry_data *)dev->target->inq_data;
+	if (SID_QUAL(sid) == SID_QUAL_LU_CONNECTED) {
+
+		dev->flags &= ~AHC_DEV_UNCONFIGURED;
+	} else {
+		dev->flags |= AHC_DEV_UNCONFIGURED;
+		return;
+	}
+
+	/*
+	 * Update our notion of this device's transfer
+	 * negotiation capabilities.
+	 */
+	tinfo = ahc_fetch_transinfo(ahc, devinfo->channel,
+				    devinfo->our_scsiid,
+				    devinfo->target, &tstate);
+	user = &tinfo->user;
+	goal = &tinfo->goal;
+	curr = &tinfo->curr;
+	width = user->width;
+	period = user->period;
+	offset = user->offset;
+	ppr_options = user->ppr_options;
+	trans_version = user->transport_version;
+	prot_version = MIN(user->protocol_version, SID_ANSI_REV(sid));
+
+	/*
+	 * Only attempt SPI3/4 once we've verified that
+	 * the device claims to support SPI3/4 features.
+	 */
+	if (prot_version < SCSI_REV_2)
+		trans_version = SID_ANSI_REV(sid);
+	else
+		trans_version = SCSI_REV_2;
+
+	if ((sid->flags & SID_WBus16) == 0)
+		width = MSG_EXT_WDTR_BUS_8_BIT;
+	if ((sid->flags & SID_Sync) == 0) {
+		period = 0;
+		offset = 0;
+		ppr_options = 0;
+	}
+	if ((sid->spi3data & SID_SPI_QAS) == 0)
+		ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
+	if ((sid->spi3data & SID_SPI_CLOCK_DT) == 0)
+		ppr_options &= MSG_EXT_PPR_QAS_REQ;
+	if ((sid->spi3data & SID_SPI_IUS) == 0)
+		ppr_options &= (MSG_EXT_PPR_DT_REQ
+			      | MSG_EXT_PPR_QAS_REQ);
+
+	if (prot_version > SCSI_REV_2
+	 && ppr_options != 0)
+		trans_version = user->transport_version;
+
+	ahc_validate_width(ahc, /*tinfo limit*/NULL, &width, ROLE_UNKNOWN);
+	if ((ahc->features & AHC_ULTRA2) != 0)
+		maxsync = AHC_SYNCRATE_DT;
+	else if ((ahc->features & AHC_ULTRA) != 0)
+		maxsync = AHC_SYNCRATE_ULTRA;
+	else
+		maxsync = AHC_SYNCRATE_FAST;
+
+	syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, maxsync);
+	ahc_validate_offset(ahc, /*tinfo limit*/NULL, syncrate,
+			    &offset, width, ROLE_UNKNOWN);
+	if (offset == 0 || period == 0) {
+		period = 0;
+		offset = 0;
+		ppr_options = 0;
+	}
+	/* Apply our filtered user settings. */
+	curr->transport_version = trans_version;
+	curr->protocol_version = prot_version;
+	ahc_set_width(ahc, devinfo, width, AHC_TRANS_GOAL, /*paused*/FALSE);
+	ahc_set_syncrate(ahc, devinfo, syncrate, period,
+			 offset, ppr_options, AHC_TRANS_GOAL,
+			 /*paused*/FALSE);
+}
+
+static void
+ahc_linux_sem_timeout(u_long arg)
+{
+	struct	ahc_softc *ahc;
+	u_long	s;
+
+	ahc = (struct ahc_softc *)arg;
+
+	ahc_lock(ahc, &s);
+	if ((ahc->platform_data->flags & AHC_UP_EH_SEMAPHORE) != 0) {
+		ahc->platform_data->flags &= ~AHC_UP_EH_SEMAPHORE;
+		up(&ahc->platform_data->eh_sem);
+	}
+	ahc_unlock(ahc, &s);
+}
+
+static void
+ahc_linux_freeze_simq(struct ahc_softc *ahc)
+{
+	ahc->platform_data->qfrozen++;
+	if (ahc->platform_data->qfrozen == 1) {
+		scsi_block_requests(ahc->platform_data->host);
+
+		/* XXX What about Twin channels? */
+		ahc_platform_abort_scbs(ahc, CAM_TARGET_WILDCARD, ALL_CHANNELS,
+					CAM_LUN_WILDCARD, SCB_LIST_NULL,
+					ROLE_INITIATOR, CAM_REQUEUE_REQ);
+	}
+}
+
+static void
+ahc_linux_release_simq(u_long arg)
+{
+	struct ahc_softc *ahc;
+	u_long s;
+	int    unblock_reqs;
+
+	ahc = (struct ahc_softc *)arg;
+
+	unblock_reqs = 0;
+	ahc_lock(ahc, &s);
+	if (ahc->platform_data->qfrozen > 0)
+		ahc->platform_data->qfrozen--;
+	if (ahc->platform_data->qfrozen == 0)
+		unblock_reqs = 1;
+	if (AHC_DV_SIMQ_FROZEN(ahc)
+	 && ((ahc->platform_data->flags & AHC_DV_WAIT_SIMQ_RELEASE) != 0)) {
+		ahc->platform_data->flags &= ~AHC_DV_WAIT_SIMQ_RELEASE;
+		up(&ahc->platform_data->dv_sem);
+	}
+	ahc_unlock(ahc, &s);
+	/*
+	 * There is still a race here.  The mid-layer
+	 * should keep its own freeze count and use
+	 * a bottom half handler to run the queues
+	 * so we can unblock with our own lock held.
+	 */
+	if (unblock_reqs)
+		scsi_unblock_requests(ahc->platform_data->host);
+
+	ahc_schedule_runq(ahc);
+}
+
+static void
+ahc_linux_dev_timed_unfreeze(u_long arg)
+{
+	struct ahc_linux_device *dev;
+	struct ahc_softc *ahc;
+	u_long s;
+
+	dev = (struct ahc_linux_device *)arg;
+	ahc = dev->target->ahc;
+	ahc_lock(ahc, &s);
+	dev->flags &= ~AHC_DEV_TIMER_ACTIVE;
+	if (dev->qfrozen > 0)
+		dev->qfrozen--;
+	if (dev->qfrozen == 0
+	 && (dev->flags & AHC_DEV_ON_RUN_LIST) == 0)
+		ahc_linux_run_device_queue(ahc, dev);
+	ahc_unlock(ahc, &s);
+}
+
+static int
+ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag)
+{
+	struct ahc_softc *ahc;
+	struct ahc_cmd *acmd;
+	struct ahc_cmd *list_acmd;
+	struct ahc_linux_device *dev;
+	struct scb *pending_scb;
+	u_long s;
+	u_int  saved_scbptr;
+	u_int  active_scb_index;
+	u_int  last_phase;
+	int    retval;
+	int    paused;
+	int    wait;
+	int    disconnected;
+
+	pending_scb = NULL;
+	paused = FALSE;
+	wait = FALSE;
+	ahc = *(struct ahc_softc **)cmd->host->hostdata;
+	acmd = (struct ahc_cmd *)cmd;
+
+	printf("%s:%d:%d:%d: Attempting to queue a%s message\n",
+	       ahc_name(ahc), cmd->channel, cmd->target, cmd->lun,
+	       flag == SCB_ABORT ? "n ABORT" : " TARGET RESET");
+
+	/*
+	 * In all versions of Linux, we have to work around
+	 * a major flaw in how the mid-layer is locked down
+	 * if we are to sleep successfully in our error handler
+	 * while allowing our interrupt handler to run.  Since
+	 * the midlayer acquires either the io_request_lock or
+	 * our lock prior to calling us, we must use the
+	 * spin_unlock_irq() method for unlocking our lock.
+	 * This will force interrupts to be enabled on the
+	 * current CPU.  Since the EH thread should not have
+	 * been running with CPU interrupts disabled other than
+	 * by acquiring either the io_request_lock or our own
+	 * lock, this *should* be safe.
+	 */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	spin_unlock_irq(&io_request_lock);
+#endif
+	ahc_midlayer_entrypoint_lock(ahc, &s);
+
+	/*
+	 * First determine if we currently own this command.
+	 * Start by searching the device queue.  If not found
+	 * there, check the pending_scb list.  If not found
+	 * at all, and the system wanted us to just abort the
+	 * command return success.
+	 */
+	dev = ahc_linux_get_device(ahc, cmd->channel, cmd->target,
+				   cmd->lun, /*alloc*/FALSE);
+
+	if (dev == NULL) {
+		/*
+		 * No target device for this command exists,
+		 * so we must not still own the command.
+		 */
+		printf("%s:%d:%d:%d: Is not an active device\n",
+		       ahc_name(ahc), cmd->channel, cmd->target, cmd->lun);
+		retval = SUCCESS;
+		goto no_cmd;
+	}
+
+	TAILQ_FOREACH(list_acmd, &dev->busyq, acmd_links.tqe) {
+		if (list_acmd == acmd)
+			break;
+	}
+
+	if (list_acmd != NULL) {
+		printf("%s:%d:%d:%d: Command found on device queue\n",
+		       ahc_name(ahc), cmd->channel, cmd->target, cmd->lun);
+		if (flag == SCB_ABORT) {
+			TAILQ_REMOVE(&dev->busyq, list_acmd, acmd_links.tqe);
+			cmd->result = DID_ABORT << 16;
+			ahc_linux_queue_cmd_complete(ahc, cmd);
+			retval = SUCCESS;
+			goto done;
+		}
+	}
+
+	if ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED)) == 0
+	 && ahc_search_untagged_queues(ahc, cmd, cmd->target,
+				       cmd->channel + 'A', cmd->lun,
+				       CAM_REQ_ABORTED, SEARCH_COMPLETE) != 0) {
+		printf("%s:%d:%d:%d: Command found on untagged queue\n",
+		       ahc_name(ahc), cmd->channel, cmd->target, cmd->lun);
+		retval = SUCCESS;
+		goto done;
+	}
+
+	/*
+	 * See if we can find a matching cmd in the pending list.
+	 */
+	LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) {
+		if (pending_scb->io_ctx == cmd)
+			break;
+	}
+
+	if (pending_scb == NULL && flag == SCB_DEVICE_RESET) {
+
+		/* Any SCB for this device will do for a target reset */
+		LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) {
+		  	if (ahc_match_scb(ahc, pending_scb, cmd->target,
+					  cmd->channel + 'A', CAM_LUN_WILDCARD,
+					  SCB_LIST_NULL, ROLE_INITIATOR) == 0)
+				break;
+		}
+	}
+
+	if (pending_scb == NULL) {
+		printf("%s:%d:%d:%d: Command not found\n",
+		       ahc_name(ahc), cmd->channel, cmd->target, cmd->lun);
+		goto no_cmd;
+	}
+
+	if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) {
+		/*
+		 * We can't queue two recovery actions using the same SCB
+		 */
+		retval = FAILED;
+		goto  done;
+	}
+
+	/*
+	 * Ensure that the card doesn't do anything
+	 * behind our back and that we didn't "just" miss
+	 * an interrupt that would affect this cmd.
+	 */
+	ahc_pause_and_flushwork(ahc);
+	paused = TRUE;
+
+	ahc_dump_card_state(ahc);
+
+	if ((pending_scb->flags & SCB_ACTIVE) == 0) {
+		printf("%s:%d:%d:%d: Command already completed\n",
+		       ahc_name(ahc), cmd->channel, cmd->target, cmd->lun);
+		goto no_cmd;
+	}
+
+	disconnected = TRUE;
+	if (flag == SCB_ABORT) {
+		if (ahc_search_qinfifo(ahc, cmd->target, cmd->channel + 'A',
+				       cmd->lun, pending_scb->hscb->tag,
+				       ROLE_INITIATOR, CAM_REQ_ABORTED,
+				       SEARCH_COMPLETE) > 0) {
+			printf("%s:%d:%d:%d: Cmd aborted from QINFIFO\n",
+			       ahc_name(ahc), cmd->channel, cmd->target,
+					cmd->lun);
+			retval = SUCCESS;
+			goto done;
+		}
+	} else if (ahc_search_qinfifo(ahc, cmd->target, cmd->channel + 'A',
+				      cmd->lun, pending_scb->hscb->tag,
+				      ROLE_INITIATOR, /*status*/0,
+				      SEARCH_COUNT) > 0) {
+		disconnected = FALSE;
+	}
+
+	if (disconnected && (ahc_inb(ahc, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) {
+		struct scb *bus_scb;
+
+		bus_scb = ahc_lookup_scb(ahc, ahc_inb(ahc, SCB_TAG));
+		if (bus_scb == pending_scb)
+			disconnected = FALSE;
+		else if (flag != SCB_ABORT
+		      && ahc_inb(ahc, SAVED_SCSIID) == pending_scb->hscb->scsiid
+		      && ahc_inb(ahc, SAVED_LUN) == pending_scb->hscb->lun)
+			disconnected = FALSE;
+	}
+
+	/*
+	 * At this point, pending_scb is the scb associated with the
+	 * passed in command.  That command is currently active on the
+	 * bus, is in the disconnected state, or we're hoping to find
+	 * a command for the same target active on the bus to abuse to
+	 * send a BDR.  Queue the appropriate message based on which of
+	 * these states we are in.
+	 */
+	last_phase = ahc_inb(ahc, LASTPHASE);
+	saved_scbptr = ahc_inb(ahc, SCBPTR);
+	active_scb_index = ahc_inb(ahc, SCB_TAG);
+	if (last_phase != P_BUSFREE
+	 && (pending_scb->hscb->tag == active_scb_index
+	  || (flag == SCB_DEVICE_RESET
+	   && SCSIID_TARGET(ahc, ahc_inb(ahc, SAVED_SCSIID)) == cmd->target))) {
+
+		/*
+		 * We're active on the bus, so assert ATN
+		 * and hope that the target responds.
+		 */
+		pending_scb = ahc_lookup_scb(ahc, active_scb_index);
+		pending_scb->flags |= SCB_RECOVERY_SCB|flag;
+		ahc_outb(ahc, MSG_OUT, HOST_MSG);
+		ahc_outb(ahc, SCSISIGO, last_phase|ATNO);
+		printf("%s:%d:%d:%d: Device is active, asserting ATN\n",
+		       ahc_name(ahc), cmd->channel, cmd->target, cmd->lun);
+		wait = TRUE;
+	} else if (disconnected) {
+
+		/*
+		 * Actually re-queue this SCB in an attempt
+		 * to select the device before it reconnects.
+		 * In either case (selection or reselection),
+		 * we will now issue the approprate message
+		 * to the timed-out device.
+		 *
+		 * Set the MK_MESSAGE control bit indicating
+		 * that we desire to send a message.  We
+		 * also set the disconnected flag since
+		 * in the paging case there is no guarantee
+		 * that our SCB control byte matches the
+		 * version on the card.  We don't want the
+		 * sequencer to abort the command thinking
+		 * an unsolicited reselection occurred.
+		 */
+		pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
+		pending_scb->flags |= SCB_RECOVERY_SCB|flag;
+
+		/*
+		 * Remove any cached copy of this SCB in the
+		 * disconnected list in preparation for the
+		 * queuing of our abort SCB.  We use the
+		 * same element in the SCB, SCB_NEXT, for
+		 * both the qinfifo and the disconnected list.
+		 */
+		ahc_search_disc_list(ahc, cmd->target, cmd->channel + 'A',
+				     cmd->lun, pending_scb->hscb->tag,
+				     /*stop_on_first*/TRUE,
+				     /*remove*/TRUE,
+				     /*save_state*/FALSE);
+
+		/*
+		 * In the non-paging case, the sequencer will
+		 * never re-reference the in-core SCB.
+		 * To make sure we are notified during
+		 * reslection, set the MK_MESSAGE flag in
+		 * the card's copy of the SCB.
+		 */
+		if ((ahc->flags & AHC_PAGESCBS) == 0) {
+			ahc_outb(ahc, SCBPTR, pending_scb->hscb->tag);
+			ahc_outb(ahc, SCB_CONTROL,
+				 ahc_inb(ahc, SCB_CONTROL)|MK_MESSAGE);
+		}
+
+		/*
+		 * Clear out any entries in the QINFIFO first
+		 * so we are the next SCB for this target
+		 * to run.
+		 */
+		ahc_search_qinfifo(ahc, cmd->target, cmd->channel + 'A',
+				   cmd->lun, SCB_LIST_NULL, ROLE_INITIATOR,
+				   CAM_REQUEUE_REQ, SEARCH_COMPLETE);
+		ahc_print_path(ahc, pending_scb);
+		printf("Queuing a recovery SCB\n");
+		ahc_qinfifo_requeue_tail(ahc, pending_scb);
+		ahc_outb(ahc, SCBPTR, saved_scbptr);
+		printf("%s:%d:%d:%d: Device is disconnected, re-queuing SCB\n",
+		       ahc_name(ahc), cmd->channel, cmd->target, cmd->lun);
+		wait = TRUE;
+	} else {
+		printf("%s:%d:%d:%d: Unable to deliver message\n",
+		       ahc_name(ahc), cmd->channel, cmd->target, cmd->lun);
+		retval = FAILED;
+		goto done;
+	}
+
+no_cmd:
+	/*
+	 * Our assumption is that if we don't have the command, no
+	 * recovery action was required, so we return success.  Again,
+	 * the semantics of the mid-layer recovery engine are not
+	 * well defined, so this may change in time.
+	 */
+	retval = SUCCESS;
+done:
+	if (paused)
+		ahc_unpause(ahc);
+	if (wait) {
+		struct timer_list timer;
+		int ret;
+
+		pending_scb->platform_data->flags |= AHC_UP_EH_SEMAPHORE;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+		ahc_unlock(ahc, &s);
+#else
+		spin_unlock_irq(ahc->platform_data->host->host_lock);
+#endif
+		init_timer(&timer);
+		timer.data = (u_long)ahc;
+		timer.expires = jiffies + (5 * HZ);
+		timer.function = ahc_linux_sem_timeout;
+		add_timer(&timer);
+		printf("Recovery code sleeping\n");
+		down(&ahc->platform_data->eh_sem);
+		printf("Recovery code awake\n");
+        	ret = del_timer(&timer);
+		if (ret == 0) {
+			printf("Timer Expired\n");
+			retval = FAILED;
+		}
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+		ahc_lock(ahc, &s);
+#else
+		spin_lock_irq(ahc->platform_data->host->host_lock);
+#endif
+	}
+	acmd = TAILQ_FIRST(&ahc->platform_data->completeq);
+	TAILQ_INIT(&ahc->platform_data->completeq);
+	ahc_midlayer_entrypoint_unlock(ahc, &s);
+	if (acmd != NULL) {
+		acmd = ahc_linux_run_complete_queue(ahc, acmd);
+		if (acmd != NULL) {
+			ahc_midlayer_entrypoint_lock(ahc, &s);
+			ahc_schedule_completeq(ahc, acmd);
+			ahc_midlayer_entrypoint_unlock(ahc, &s);
+		}
+	}
+	ahc_schedule_runq(ahc);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	spin_lock_irq(&io_request_lock);
+#endif
+	return (retval);
+}
+
+void
+ahc_platform_dump_card_state(struct ahc_softc *ahc)
+{
+	struct ahc_linux_device *dev;
+	int channel;
+	int maxchannel;
+	int target;
+	int maxtarget;
+	int lun;
+	int i;
+
+	maxchannel = (ahc->features & AHC_TWIN) ? 1 : 0;
+	maxtarget = (ahc->features & AHC_WIDE) ? 15 : 7;
+	for (channel = 0; channel <= maxchannel; channel++) {
+
+		for (target = 0; target <=maxtarget; target++) {
+
+			for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
+				struct ahc_cmd *acmd;
+
+				dev = ahc_linux_get_device(ahc, channel, target,
+							   lun, /*alloc*/FALSE);
+				if (dev == NULL)
+					continue;
+
+				printf("DevQ(%d:%d:%d): ",
+				       channel, target, lun);
+				i = 0;
+				TAILQ_FOREACH(acmd, &dev->busyq,
+					      acmd_links.tqe) {
+					if (i++ > AHC_SCB_MAX)
+						break;
+				}
+				printf("%d waiting\n", i);
+			}
+		}
+	}
+}
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx_osm.h b/drivers/scsi/aic7xxx/aic7xxx_osm.h
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.h	Mon Dec 23 21:21:53 2002
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.h	Mon Dec 23 21:21:53 2002
@@ -18,8 +18,6 @@
  * along with this program; see the file COPYING.  If not, write to
  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  * 
- * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_linux.h#72 $
- *
  * Copyright (c) 2000-2001 Adaptec Inc.
  * All rights reserved.
  *
@@ -55,7 +53,7 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_linux.h#72 $
+ * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_osm.h#111 $
  *
  */
 #ifndef _AIC7XXX_LINUX_H_
@@ -65,26 +63,32 @@
 #include <linux/blk.h>
 #include <linux/blkdev.h>
 #include <linux/delay.h>
-#include <linux/interrupt.h>
 #include <linux/ioport.h>
-#include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/version.h>
+#ifndef AHC_MODVERSION_FILE
+#define __NO_VERSION__
+#endif
 #include <linux/module.h>
 #include <asm/byteorder.h>
-#include <asm/io.h>
 
 #ifndef KERNEL_VERSION
 #define KERNEL_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
 #endif
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+#include <linux/interrupt.h> /* For tasklet support. */
 #include <linux/config.h>
+#include <linux/slab.h>
+#else
+#include <linux/malloc.h>
 #endif
 
 /* Core SCSI definitions */
-#include "../scsi.h"
-#include "../hosts.h"
+#define AIC_LIB_PREFIX ahc
+#include "scsi.h"
+#include "hosts.h"
+#include "aiclib.h"
 
 /* Name space conflict with BSD queue macros */
 #ifdef LIST_HEAD
@@ -95,6 +99,20 @@
 #include "queue.h"
 #include "scsi_message.h"
 
+/*********************************** Debugging ********************************/
+#ifdef CONFIG_AIC7XXX_DEBUG_ENABLE
+#ifdef CONFIG_AIC7XXX_DEBUG_MASK
+#define AHC_DEBUG 1
+#define AHC_DEBUG_OPTS CONFIG_AIC7XXX_DEBUG_MASK
+#else
+/*
+ * Compile in debugging code, but do not enable any printfs.
+ */
+#define AHC_DEBUG 1
+#endif
+/* No debugging code. */
+#endif
+
 /************************* Forward Declarations *******************************/
 struct ahc_softc;
 typedef struct pci_dev *ahc_dev_softc_t;
@@ -134,8 +152,9 @@
 
 /************************* Configuration Data *********************************/
 extern int aic7xxx_no_probe;
+extern int aic7xxx_allow_memio;
 extern int aic7xxx_detect_complete;
-extern Scsi_Host_Template* aic7xxx_driver_template;
+extern Scsi_Host_Template aic7xxx_driver_template;
 
 /***************************** Bus Space/DMA **********************************/
 
@@ -236,176 +255,52 @@
  */
 #define ahc_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op)
 
-/************************** SCSI Constants/Structures *************************/
-#define SCSI_REV_2 2
-#define	SCSI_STATUS_OK			0x00
-#define	SCSI_STATUS_CHECK_COND		0x02
-#define	SCSI_STATUS_COND_MET		0x04
-#define	SCSI_STATUS_BUSY		0x08
-#define SCSI_STATUS_INTERMED		0x10
-#define SCSI_STATUS_INTERMED_COND_MET	0x14
-#define SCSI_STATUS_RESERV_CONFLICT	0x18
-#define SCSI_STATUS_CMD_TERMINATED	0x22
-#define SCSI_STATUS_QUEUE_FULL		0x28
-
-/*
- * 6 byte request sense CDB format.
- */
-struct scsi_sense
-{
-	uint8_t opcode;
-	uint8_t byte2;
-	uint8_t unused[2];
-	uint8_t length;
-	uint8_t control;
-};
+/************************** Timer DataStructures ******************************/
+typedef struct timer_list ahc_timer_t;
 
-struct scsi_sense_data
-{
-	uint8_t	error_code;
-	uint8_t	segment;
-	uint8_t	flags;
-	uint8_t	info[4];
-	uint8_t	extra_len;
-	uint8_t	cmd_spec_info[4];
-	uint8_t add_sense_code;
-	uint8_t add_sense_code_qual;
-	uint8_t	fru;
-	uint8_t	sense_key_spec[3];
-	uint8_t	extra_bytes[14];
-};
+/********************************** Includes **********************************/
+#if CONFIG_AIC7XXX_REG_PRETTY_PRINT
+#define AIC_DEBUG_REGISTERS 1
+#else
+#define AIC_DEBUG_REGISTERS 0
+#endif
+#include "aic7xxx.h"
 
-struct scsi_inquiry
-{ 
-	u_int8_t opcode;
-	u_int8_t byte2;
-#define	SI_EVPD 0x01
-	u_int8_t page_code;
-	u_int8_t reserved;
-	u_int8_t length;
-	u_int8_t control;
-};
+/***************************** Timer Facilities *******************************/
+#define ahc_timer_init init_timer
+#define ahc_timer_stop del_timer
+typedef void ahc_linux_callback_t (u_long);  
+static __inline void ahc_timer_reset(ahc_timer_t *timer, int usec,
+				     ahc_callback_t *func, void *arg);
+static __inline void ahc_scb_timer_reset(struct scb *scb, u_int usec);
 
-struct scsi_inquiry_data
+static __inline void
+ahc_timer_reset(ahc_timer_t *timer, int usec, ahc_callback_t *func, void *arg)
 {
-	uint8_t device;
-#define	SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
-#define	SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
-#define	SID_QUAL_LU_CONNECTED	0x00	/*
-					 * The specified peripheral device
-					 * type is currently connected to
-					 * logical unit.  If the target cannot
-					 * determine whether or not a physical
-					 * device is currently connected, it
-					 * shall also use this peripheral
-					 * qualifier when returning the INQUIRY
-					 * data.  This peripheral qualifier
-					 * does not mean that the device is
-					 * ready for access by the initiator.
-					 */
-#define	SID_QUAL_LU_OFFLINE	0x01	/*
-					 * The target is capable of supporting
-					 * the specified peripheral device type
-					 * on this logical unit; however, the
-					 * physical device is not currently
-					 * connected to this logical unit.
-					 */
-#define SID_QUAL_RSVD		0x02
-#define	SID_QUAL_BAD_LU		0x03	/*
-					 * The target is not capable of
-					 * supporting a physical device on
-					 * this logical unit. For this
-					 * peripheral qualifier the peripheral
-					 * device type shall be set to 1Fh to
-					 * provide compatibility with previous
-					 * versions of SCSI. All other
-					 * peripheral device type values are
-					 * reserved for this peripheral
-					 * qualifier.
-					 */
-#define	SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
-	uint8_t dev_qual2;
-#define	SID_QUAL2	0x7F
-#define	SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
-	uint8_t version;
-#define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
-#define		SCSI_REV_0		0
-#define		SCSI_REV_CCS		1
-#define		SCSI_REV_2		2
-#define		SCSI_REV_SPC		3
-#define		SCSI_REV_SPC2		4
-
-#define SID_ECMA	0x38
-#define SID_ISO		0xC0
-	uint8_t response_format;
-#define SID_AENC	0x80
-#define SID_TrmIOP	0x40
-	uint8_t additional_length;
-	uint8_t reserved[2];
-	uint8_t flags;
-#define	SID_SftRe	0x01
-#define	SID_CmdQue	0x02
-#define	SID_Linked	0x08
-#define	SID_Sync	0x10
-#define	SID_WBus16	0x20
-#define	SID_WBus32	0x40
-#define	SID_RelAdr	0x80
-#define SID_VENDOR_SIZE   8
-	char	 vendor[SID_VENDOR_SIZE];
-#define SID_PRODUCT_SIZE  16
-	char	 product[SID_PRODUCT_SIZE];
-#define SID_REVISION_SIZE 4
-	char	 revision[SID_REVISION_SIZE];
-	/*
-	 * The following fields were taken from SCSI Primary Commands - 2
-	 * (SPC-2) Revision 14, Dated 11 November 1999
-	 */
-#define	SID_VENDOR_SPECIFIC_0_SIZE	20
-	u_int8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE];
-	/*
-	 * An extension of SCSI Parallel Specific Values
-	 */
-#define	SID_SPI_IUS		0x01
-#define	SID_SPI_QAS		0x02
-#define	SID_SPI_CLOCK_ST	0x00
-#define	SID_SPI_CLOCK_DT	0x04
-#define	SID_SPI_CLOCK_DT_ST	0x0C
-#define	SID_SPI_MASK		0x0F
-	uint8_t spi3data;
-	uint8_t reserved2;
-	/*
-	 * Version Descriptors, stored 2 byte values.
-	 */
-	uint8_t version1[2];
-	uint8_t version2[2];
-	uint8_t version3[2];
-	uint8_t version4[2];
-	uint8_t version5[2];
-	uint8_t version6[2];
-	uint8_t version7[2];
-	uint8_t version8[2];
-
-	uint8_t reserved3[22];
-
-#define	SID_VENDOR_SPECIFIC_1_SIZE	160
-	uint8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE];
-};
+	struct ahc_softc *ahc;
 
-/********************************** Includes **********************************/
-/* Host template and function declarations referenced by the template. */
-#include "aic7xxx_linux_host.h"
+	ahc = (struct ahc_softc *)arg;
+	del_timer(timer);
+	timer->data = (u_long)arg;
+	timer->expires = jiffies + (usec * HZ)/1000000;
+	timer->function = (ahc_linux_callback_t*)func;
+	add_timer(timer);
+}
 
-/* Core driver definitions */
-#include "aic7xxx.h"
+static __inline void
+ahc_scb_timer_reset(struct scb *scb, u_int usec)
+{
+	mod_timer(&scb->io_ctx->eh_timeout, jiffies + (usec * HZ)/1000000);
+}
 
-/* SMP support */
+/***************************** SMP support ************************************/
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,17)
 #include <linux/spinlock.h>
 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,93)
 #include <linux/smp.h>
 #endif
 
-#define AIC7XXX_DRIVER_VERSION  "6.2.4"
+#define AIC7XXX_DRIVER_VERSION "6.2.24"
 
 /**************************** Front End Queues ********************************/
 /*
@@ -452,8 +347,9 @@
 	AHC_DEV_ON_RUN_LIST	 = 0x08, /* Queued to be run later */
 	AHC_DEV_Q_BASIC		 = 0x10, /* Allow basic device queuing */
 	AHC_DEV_Q_TAGGED	 = 0x20, /* Allow full SCSI2 command queueing */
-	AHC_DEV_PERIODIC_OTAG	 = 0x40	 /* Send OTAG to prevent starvation */
-} ahc_dev_flags;
+	AHC_DEV_PERIODIC_OTAG	 = 0x40, /* Send OTAG to prevent starvation */
+	AHC_DEV_SLAVE_CONFIGURED = 0x80	 /* slave_configure() has been called */
+} ahc_linux_dev_flags;
 
 struct ahc_linux_target;
 struct ahc_linux_device {
@@ -464,7 +360,7 @@
 	 * The number of transactions currently
 	 * queued to the device.
 	 */
-	int		active;
+	int			active;
 
 	/*
 	 * The currently allowed number of 
@@ -474,18 +370,18 @@
 	 * mode where the device may have more
 	 * than one outstanding active transaction.
 	 */
-	int		openings;
+	int			openings;
 
 	/*
 	 * A positive count indicates that this
 	 * device's queue is halted.
 	 */
-	u_int		qfrozen;
+	u_int			qfrozen;
 	
 	/*
 	 * Cumulative command counter.
 	 */
-	u_long		commands_issued;
+	u_long			commands_issued;
 
 	/*
 	 * The number of tagged transactions when
@@ -493,21 +389,26 @@
 	 * that have been successfully received by
 	 * this device since the last QUEUE FULL.
 	 */
-	u_int		tag_success_count;
+	u_int			tag_success_count;
 #define AHC_TAG_SUCCESS_INTERVAL 50
 
-	ahc_dev_flags	flags;
+	ahc_linux_dev_flags	flags;
+
+	/*
+	 * Per device timer.
+	 */
+	struct timer_list	timer;
 
 	/*
 	 * The high limit for the tags variable.
 	 */
-	u_int		maxtags;
+	u_int			maxtags;
 
 	/*
 	 * The computed number of tags outstanding
 	 * at the time of the last QUEUE FULL event.
 	 */
-	u_int		tags_on_last_queuefull;
+	u_int			tags_on_last_queuefull;
 
 	/*
 	 * How many times we have seen a queue full
@@ -515,7 +416,7 @@
 	 * to stop our adaptive queue depth algorithm
 	 * on devices with a fixed number of tags.
 	 */
-	u_int		last_queuefull_same_count;
+	u_int			last_queuefull_same_count;
 #define AHC_LOCK_TAGS_COUNT 50
 
 	/*
@@ -527,19 +428,54 @@
 	 * if the AHC_DEV_PERIODIC_OTAG flag is set
 	 * on this device.
 	 */
-	u_int		commands_since_idle_or_otag;
+	u_int			commands_since_idle_or_otag;
 #define AHC_OTAG_THRESH	500
 
-	int		lun;
-	struct		ahc_linux_target *target;
+	int			lun;
+	Scsi_Device	       *scsi_device;
+	struct			ahc_linux_target *target;
 };
 
+typedef enum {
+	AHC_DV_REQUIRED		 = 0x01
+} ahc_linux_targ_flags;
+
+/* DV States */
+typedef enum {
+	AHC_DV_STATE_EXIT = 0,
+	AHC_DV_STATE_INQ_SHORT_ASYNC,
+	AHC_DV_STATE_TUR,
+	AHC_DV_STATE_INQ_ASYNC,
+	AHC_DV_STATE_INQ_ASYNC_VERIFY,
+	AHC_DV_STATE_REBD,
+	AHC_DV_STATE_INQ_VERIFY,
+	AHC_DV_STATE_WEB,
+	AHC_DV_STATE_REB,
+	AHC_DV_STATE_SU,
+	AHC_DV_STATE_BUSY
+} ahc_dv_state;
+
 struct ahc_linux_target {
-	struct	ahc_linux_device *devices[AHC_NUM_LUNS];
-	int	channel;
-	int	target;
-	int	refcount;
-	struct	ahc_transinfo last_tinfo;
+	struct ahc_linux_device	 *devices[AHC_NUM_LUNS];
+	int			  channel;
+	int			  target;
+	int			  refcount;
+	struct ahc_transinfo	  last_tinfo;
+	struct ahc_softc	 *ahc;
+	ahc_linux_targ_flags	  flags;
+	struct scsi_inquiry_data *inq_data;
+	/*
+	 * The next "fallback" period to use for narrow/wide transfers.
+	 */
+	u_int			  dv_next_narrow_period;
+	u_int			  dv_next_wide_period;
+	u_int			  dv_max_ppr_options;
+	u_int			  dv_last_ppr_options;
+	u_int			  dv_echo_size;
+	ahc_dv_state		  dv_state;
+	u_int			  dv_state_retry;
+	char			 *dv_buffer;
+	char			 *dv_buffer1;
 };
 
 /********************* Definitions Required by the Core ***********************/
@@ -554,12 +490,19 @@
 /*
  * Per-SCB OSM storage.
  */
+typedef enum {
+	AHC_UP_EH_SEMAPHORE
+} ahc_linux_scb_flags;
+
 struct scb_platform_data {
 	struct ahc_linux_device	*dev;
+	bus_addr_t		 buf_busaddr;
 	uint32_t		 xfer_len;
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
 	uint32_t		 resid;		/* Transfer residual */
 #endif
+	uint32_t		 sense_resid;	/* Auto-Sense residual */
+	ahc_linux_scb_flags	 flags;
 };
 
 /*
@@ -568,7 +511,16 @@
  * alignment restrictions of the various platforms supported by
  * this driver.
  */
+typedef enum {
+	AHC_DV_WAIT_SIMQ_EMPTY	 = 0x01,
+	AHC_DV_WAIT_SIMQ_RELEASE = 0x02,
+	AHC_DV_ACTIVE		 = 0x04,
+	AHC_DV_SHUTDOWN		 = 0x08,
+	AHC_RUN_CMPLT_Q_TIMER	 = 0x10
+} ahc_linux_softc_flags;
+
 TAILQ_HEAD(ahc_completeq, ahc_cmd);
+
 struct ahc_platform_data {
 	/*
 	 * Fields accessed from interrupt context.
@@ -577,14 +529,28 @@
 	TAILQ_HEAD(, ahc_linux_device) device_runq;
 	struct ahc_completeq	 completeq;
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,93)
+	spinlock_t		 spin_lock;
+#endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+	struct tasklet_struct	 runq_tasklet;
+#endif
 	u_int			 qfrozen;
+	pid_t			 dv_pid;
+	struct timer_list	 completeq_timer;
 	struct timer_list	 reset_timer;
 	struct semaphore	 eh_sem;
+	struct semaphore	 dv_sem;
+	struct semaphore	 dv_cmd_sem;	/* XXX This needs to be in
+						 * the target struct
+						 */
 	struct Scsi_Host        *host;		/* pointer to scsi host */
+#define AHC_LINUX_NOIRQ	((uint32_t)~0)
 	uint32_t		 irq;		/* IRQ for this adapter */
 	uint32_t		 bios_address;
 	uint32_t		 mem_busaddr;	/* Mem Base Addr */
 	bus_addr_t		 hw_dma_mask;
+	ahc_linux_softc_flags	 flags;
 };
 
 /************************** OS Utility Wrappers *******************************/
@@ -706,56 +672,116 @@
 static __inline void ahc_lock(struct ahc_softc *, unsigned long *flags);
 static __inline void ahc_unlock(struct ahc_softc *, unsigned long *flags);
 
+/* Lock acquisition and release of the above lock in midlayer entry points. */
+static __inline void ahc_midlayer_entrypoint_lock(struct ahc_softc *,
+						  unsigned long *flags);
+static __inline void ahc_midlayer_entrypoint_unlock(struct ahc_softc *,
+						    unsigned long *flags);
+
 /* Lock held during command compeletion to the upper layer */
 static __inline void ahc_done_lockinit(struct ahc_softc *);
 static __inline void ahc_done_lock(struct ahc_softc *, unsigned long *flags);
 static __inline void ahc_done_unlock(struct ahc_softc *, unsigned long *flags);
 
+/* Lock held during ahc_list manipulation and ahc softc frees */
+extern spinlock_t ahc_list_spinlock;
+static __inline void ahc_list_lockinit(void);
+static __inline void ahc_list_lock(unsigned long *flags);
+static __inline void ahc_list_unlock(unsigned long *flags);
+
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,93)
 static __inline void
 ahc_lockinit(struct ahc_softc *ahc)
 {
-	spin_lock_init(ahc->platform_data->host->host_lock);
+	spin_lock_init(&ahc->platform_data->spin_lock);
 }
 
 static __inline void
 ahc_lock(struct ahc_softc *ahc, unsigned long *flags)
 {
 	*flags = 0;
-	spin_lock_irqsave(ahc->platform_data->host->host_lock, *flags);
+	spin_lock_irqsave(&ahc->platform_data->spin_lock, *flags);
 }
 
 static __inline void
 ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
 {
-	spin_unlock_irqrestore(ahc->platform_data->host->host_lock, *flags);
+	spin_unlock_irqrestore(&ahc->platform_data->spin_lock, *flags);
+}
+
+static __inline void
+ahc_midlayer_entrypoint_lock(struct ahc_softc *ahc, unsigned long *flags)
+{
+	/*
+	 * In 2.5.X, the midlayer takes our lock just before
+	 * calling us, so avoid locking again.
+	 */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	ahc_lock(ahc, flags);
+#endif
+}
+
+static __inline void
+ahc_midlayer_entrypoint_unlock(struct ahc_softc *ahc, unsigned long *flags)
+{
+	/*
+	 * In 2.5.X, the midlayer takes our lock just before
+	 * calling us and unlocks when we return, so let it do the unlock.
+	 */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	ahc_unlock(ahc, flags);
+#endif
 }
 
 static __inline void
 ahc_done_lockinit(struct ahc_softc *ahc)
 {
-	/* We don't own the iorequest lock, so we don't initialize it. */
+	/*
+	 * In 2.5.X, our own lock is held during completions.
+	 * In previous versions, the io_request_lock is used.
+	 * In either case, we can't initialize this lock again.
+	 */
 }
 
 static __inline void
 ahc_done_lock(struct ahc_softc *ahc, unsigned long *flags)
 {
-	struct Scsi_Host *host = ahc->platform_data->host;
-
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
 	*flags = 0;
-	spin_lock_irqsave(host->host_lock, *flags);
+	spin_lock_irqsave(&io_request_lock, *flags);
+#endif
 }
 
 static __inline void
 ahc_done_unlock(struct ahc_softc *ahc, unsigned long *flags)
 {
-	struct Scsi_Host *host = ahc->platform_data->host;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	spin_unlock_irqrestore(&io_request_lock, *flags);
+#endif
+}
+
+static __inline void
+ahc_list_lockinit()
+{
+	spin_lock_init(&ahc_list_spinlock);
+}
+
+static __inline void
+ahc_list_lock(unsigned long *flags)
+{
+	*flags = 0;
+	spin_lock_irqsave(&ahc_list_spinlock, *flags);
+}
 
-	spin_unlock_irqrestore(host->host_lock, *flags);
+static __inline void
+ahc_list_unlock(unsigned long *flags)
+{
+	spin_unlock_irqrestore(&ahc_list_spinlock, *flags);
 }
 
-#else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0) */
+#else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,1,93) */
 
+static __inline void
 ahc_lockinit(struct ahc_softc *ahc)
 {
 }
@@ -774,6 +800,7 @@
 	restore_flags(*flags);
 }
 
+static __inline void
 ahc_done_lockinit(struct ahc_softc *ahc)
 {
 }
@@ -792,6 +819,25 @@
 ahc_done_unlock(struct ahc_softc *ahc, unsigned long *flags)
 {
 }
+
+static __inline void
+ahc_list_lockinit()
+{
+}
+
+static __inline void
+ahc_list_lock(unsigned long *flags)
+{
+	*flags = 0;
+	save_flags(*flags);
+	cli();
+}
+
+static __inline void
+ahc_list_unlock(unsigned long *flags)
+{
+	restore_flags(*flags);
+}
 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0) */
 
 /******************************* PCI Definitions ******************************/
@@ -846,7 +892,8 @@
 			    ahc_power_state new_state);
 /**************************** VL/EISA Routines ********************************/
 int			 aic7770_linux_probe(Scsi_Host_Template *);
-int			 aic7770_map_registers(struct ahc_softc *ahc);
+int			 aic7770_map_registers(struct ahc_softc *ahc,
+					       u_int port);
 int			 aic7770_map_int(struct ahc_softc *ahc, u_int irq);
 
 /******************************* PCI Routines *********************************/
@@ -959,38 +1006,99 @@
 #define pci_unmap_single(pdev, buffer, buflen, direction)
 #endif
 
-/*********************** Transaction Access Wrappers **************************/
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,3)
+#define ahc_pci_set_dma_mask pci_set_dma_mask
+#else
+/*
+ * Always "return" 0 for success.
+ */
+#define ahc_pci_set_dma_mask(dev_softc, mask)  			\
+	(((dev_softc)->dma_mask = mask) && 0)
+#endif
+/**************************** Proc FS Support *********************************/
+int	ahc_linux_proc_info(char *, char **, off_t, int, int, int);
+
+/*************************** Domain Validation ********************************/
+#define AHC_DV_CMD(cmd) ((cmd)->scsi_done == ahc_linux_dv_complete)
+#define AHC_DV_SIMQ_FROZEN(ahc)					\
+	((((ahc)->platform_data->flags & AHC_DV_ACTIVE) != 0)	\
+	 && (ahc)->platform_data->qfrozen == 1)
+
+/*********************** Transaction Access Wrappers *************************/
+static __inline void ahc_cmd_set_transaction_status(Scsi_Cmnd *, uint32_t);
 static __inline void ahc_set_transaction_status(struct scb *, uint32_t);
+static __inline void ahc_cmd_set_scsi_status(Scsi_Cmnd *, uint32_t);
+static __inline void ahc_set_scsi_status(struct scb *, uint32_t);
+static __inline uint32_t ahc_cmd_get_transaction_status(Scsi_Cmnd *cmd);
+static __inline uint32_t ahc_get_transaction_status(struct scb *);
+static __inline uint32_t ahc_cmd_get_scsi_status(Scsi_Cmnd *cmd);
+static __inline uint32_t ahc_get_scsi_status(struct scb *);
+static __inline void ahc_set_transaction_tag(struct scb *, int, u_int);
+static __inline u_long ahc_get_transfer_length(struct scb *);
+static __inline int ahc_get_transfer_dir(struct scb *);
+static __inline void ahc_set_residual(struct scb *, u_long);
+static __inline void ahc_set_sense_residual(struct scb *scb, u_long resid);
+static __inline u_long ahc_get_residual(struct scb *);
+static __inline u_long ahc_get_sense_residual(struct scb *);
+static __inline int ahc_perform_autosense(struct scb *);
+static __inline uint32_t ahc_get_sense_bufsize(struct ahc_softc *,
+					       struct scb *);
+static __inline void ahc_notify_xfer_settings_change(struct ahc_softc *,
+						     struct ahc_devinfo *);
+static __inline void ahc_platform_scb_free(struct ahc_softc *ahc,
+					   struct scb *scb);
+static __inline void ahc_freeze_scb(struct scb *scb);
+
+static __inline
+void ahc_cmd_set_transaction_status(Scsi_Cmnd *cmd, uint32_t status)
+{
+	cmd->result &= ~(CAM_STATUS_MASK << 16);
+	cmd->result |= status << 16;
+}
+
 static __inline
 void ahc_set_transaction_status(struct scb *scb, uint32_t status)
 {
-	scb->io_ctx->result &= ~(CAM_STATUS_MASK << 16);
-	scb->io_ctx->result |= status << 16;
+	ahc_cmd_set_transaction_status(scb->io_ctx,status);
+}
+
+static __inline
+void ahc_cmd_set_scsi_status(Scsi_Cmnd *cmd, uint32_t status)
+{
+	cmd->result &= ~0xFFFF;
+	cmd->result |= status;
 }
 
-static __inline void ahc_set_scsi_status(struct scb *, uint32_t);
 static __inline
 void ahc_set_scsi_status(struct scb *scb, uint32_t status)
 {
-	scb->io_ctx->result &= ~0xFFFF;
-	scb->io_ctx->result |= status;
+	ahc_cmd_set_scsi_status(scb->io_ctx, status);
+}
+
+static __inline
+uint32_t ahc_cmd_get_transaction_status(Scsi_Cmnd *cmd)
+{
+	return ((cmd->result >> 16) & CAM_STATUS_MASK);
 }
 
-static __inline uint32_t ahc_get_transaction_status(struct scb *);
 static __inline
 uint32_t ahc_get_transaction_status(struct scb *scb)
 {
-	return ((scb->io_ctx->result >> 16) & CAM_STATUS_MASK);
+	return (ahc_cmd_get_transaction_status(scb->io_ctx));
+}
+
+static __inline
+uint32_t ahc_cmd_get_scsi_status(Scsi_Cmnd *cmd)
+{
+	return (cmd->result & 0xFFFF);
 }
 
-static __inline uint32_t ahc_get_scsi_status(struct scb *);
 static __inline
 uint32_t ahc_get_scsi_status(struct scb *scb)
 {
-	return (scb->io_ctx->result & 0xFFFF);
+	return (ahc_cmd_get_scsi_status(scb->io_ctx));
 }
 
-static __inline void ahc_set_transaction_tag(struct scb *, int, u_int);
 static __inline
 void ahc_set_transaction_tag(struct scb *scb, int enabled, u_int type)
 {
@@ -1000,14 +1108,12 @@
 	 */
 }
 
-static __inline u_long ahc_get_transfer_length(struct scb *);
 static __inline
 u_long ahc_get_transfer_length(struct scb *scb)
 {
 	return (scb->platform_data->xfer_len);
 }
 
-static __inline int ahc_get_transfer_dir(struct scb *);
 static __inline
 int ahc_get_transfer_dir(struct scb *scb)
 {
@@ -1032,7 +1138,6 @@
 #endif
 }
 
-static __inline void ahc_set_residual(struct scb *, u_long);
 static __inline
 void ahc_set_residual(struct scb *scb, u_long resid)
 {
@@ -1043,14 +1148,12 @@
 #endif
 }
 
-static __inline void ahc_set_sense_residual(struct scb *, u_long);
 static __inline
 void ahc_set_sense_residual(struct scb *scb, u_long resid)
 {
-	/* This can't be reported in Linux */
+	scb->platform_data->sense_resid = resid;
 }
 
-static __inline u_long ahc_get_residual(struct scb *);
 static __inline
 u_long ahc_get_residual(struct scb *scb)
 {
@@ -1061,7 +1164,12 @@
 #endif
 }
 
-static __inline int ahc_perform_autosense(struct scb *);
+static __inline
+u_long ahc_get_sense_residual(struct scb *scb)
+{
+	return (scb->platform_data->sense_resid);
+}
+
 static __inline
 int ahc_perform_autosense(struct scb *scb)
 {
@@ -1079,8 +1187,6 @@
 	return (sizeof(struct scsi_sense_data));
 }
 
-static __inline void ahc_notify_xfer_settings_change(struct ahc_softc *,
-						     struct ahc_devinfo *);
 static __inline void
 ahc_notify_xfer_settings_change(struct ahc_softc *ahc,
 				struct ahc_devinfo *devinfo)
@@ -1088,8 +1194,6 @@
 	/* Nothing to do here for linux */
 }
 
-static __inline void ahc_platform_scb_free(struct ahc_softc *ahc,
-					   struct scb *scb);
 static __inline void
 ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb)
 {
@@ -1099,11 +1203,14 @@
 int	ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);
 void	ahc_platform_free(struct ahc_softc *ahc);
 void	ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb);
-static __inline void	ahc_freeze_scb(struct scb *scb);
+
 static __inline void
 ahc_freeze_scb(struct scb *scb)
 {
-	/* Noting to do here for linux */
+	if ((scb->io_ctx->result & (CAM_DEV_QFRZN << 16)) == 0) {
+                scb->io_ctx->result |= CAM_DEV_QFRZN << 16;
+                scb->platform_data->dev->qfrozen++;
+        }
 }
 
 void	ahc_platform_set_tags(struct ahc_softc *ahc,
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,412 @@
+/*
+ * Linux driver attachment glue for PCI based controllers.
+ *
+ * Copyright (c) 2000-2001 Adaptec Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c#41 $
+ */
+
+#include "aic7xxx_osm.h"
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
+struct pci_device_id
+{
+};
+#endif
+
+static int	ahc_linux_pci_dev_probe(struct pci_dev *pdev,
+					const struct pci_device_id *ent);
+static int	ahc_linux_pci_reserve_io_region(struct ahc_softc *ahc,
+						u_long *base);
+#ifdef MMAPIO
+static int	ahc_linux_pci_reserve_mem_region(struct ahc_softc *ahc,
+						 u_long *bus_addr,
+						 uint8_t **maddr);
+#endif /* MMAPIO */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+static void	ahc_linux_pci_dev_remove(struct pci_dev *pdev);
+
+/* We do our own ID filtering.  So, grab all SCSI storage class devices. */
+static struct pci_device_id ahc_linux_pci_id_table[] = {
+	{
+		0x9004, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
+		PCI_CLASS_STORAGE_SCSI << 8, 0xFFFF00, 0
+	},
+	{
+		0x9005, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
+		PCI_CLASS_STORAGE_SCSI << 8, 0xFFFF00, 0
+	},
+	{ 0 }
+};
+
+MODULE_DEVICE_TABLE(pci, ahc_linux_pci_id_table);
+
+struct pci_driver aic7xxx_pci_driver = {
+	name:		"aic7xxx",
+	probe:		ahc_linux_pci_dev_probe,
+	remove:		ahc_linux_pci_dev_remove,
+	id_table:	ahc_linux_pci_id_table
+};
+
+static void
+ahc_linux_pci_dev_remove(struct pci_dev *pdev)
+{
+	struct ahc_softc *ahc;
+	u_long l;
+
+	/*
+	 * We should be able to just perform
+	 * the free directly, but check our
+	 * list for extra sanity.
+	 */
+	ahc_list_lock(&l);
+	ahc = ahc_find_softc((struct ahc_softc *)pci_get_drvdata(pdev));
+	if (ahc != NULL) {
+		u_long s;
+
+		ahc_lock(ahc, &s);
+		ahc_intr_enable(ahc, FALSE);
+		ahc_unlock(ahc, &s);
+		ahc_free(ahc);
+	}
+	ahc_list_unlock(&l);
+}
+#endif /* !LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) */
+
+static int
+ahc_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
+{
+	char		 buf[80];
+	struct		 ahc_softc *ahc;
+	ahc_dev_softc_t	 pci;
+	struct		 ahc_pci_identity *entry;
+	char		*name;
+	int		 error;
+
+	/*
+	 * Some BIOSen report the same device multiple times.
+	 */
+	TAILQ_FOREACH(ahc, &ahc_tailq, links) {
+		struct pci_dev *probed_pdev;
+
+		probed_pdev = ahc->dev_softc;
+		if (probed_pdev->bus->number == pdev->bus->number
+		 && probed_pdev->devfn == pdev->devfn)
+			break;
+	}
+	if (ahc != NULL) {
+		/* Skip duplicate. */
+		return (-ENODEV);
+	}
+
+	pci = pdev;
+	entry = ahc_find_pci_device(pci);
+	if (entry == NULL)
+		return (-ENODEV);
+
+	/*
+	 * Allocate a softc for this card and
+	 * set it up for attachment by our
+	 * common detect routine.
+	 */
+	sprintf(buf, "ahc_pci:%d:%d:%d",
+		ahc_get_pci_bus(pci),
+		ahc_get_pci_slot(pci),
+		ahc_get_pci_function(pci));
+	name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
+	if (name == NULL)
+		return (-ENOMEM);
+	strcpy(name, buf);
+	ahc = ahc_alloc(NULL, name);
+	if (ahc == NULL)
+		return (-ENOMEM);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+	if (pci_enable_device(pdev)) {
+		ahc_free(ahc);
+		return (-ENODEV);
+	}
+	pci_set_master(pdev);
+
+	if (sizeof(bus_addr_t) > 4
+	 && ahc_linux_get_memsize() > 0x80000000
+	 && ahc_pci_set_dma_mask(pdev, 0x7FFFFFFFFFULL) == 0) {
+		ahc->flags |= AHC_39BIT_ADDRESSING;
+		ahc->platform_data->hw_dma_mask =
+		    (bus_addr_t)(0x7FFFFFFFFFULL & (bus_addr_t)~0);
+	}
+#endif
+	ahc->dev_softc = pci;
+	error = ahc_pci_config(ahc, entry);
+	if (error != 0) {
+		ahc_free(ahc);
+		return (-error);
+	}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+	pci_set_drvdata(pdev, ahc);
+	if (aic7xxx_detect_complete)
+		ahc_linux_register_host(ahc, &aic7xxx_driver_template);
+#endif
+	return (0);
+}
+
+int
+ahc_linux_pci_probe(Scsi_Host_Template *template)
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+	return (pci_module_init(&aic7xxx_pci_driver));
+#else
+	struct pci_dev *pdev;
+	u_int class;
+	int found;
+
+	/* If we don't have a PCI bus, we can't find any adapters. */
+	if (pci_present() == 0)
+		return (0);
+
+	found = 0;
+	pdev = NULL;
+	class = PCI_CLASS_STORAGE_SCSI << 8;
+	while ((pdev = pci_find_class(class, pdev)) != NULL) {
+		ahc_dev_softc_t pci;
+		int error;
+
+		pci = pdev;
+		error = ahc_linux_pci_dev_probe(pdev, /*pci_devid*/NULL);
+		if (error == 0)
+			found++;
+	}
+	return (found);
+#endif
+}
+
+static int
+ahc_linux_pci_reserve_io_region(struct ahc_softc *ahc, u_long *base)
+{
+	if (aic7xxx_allow_memio == 0)
+		return (ENOMEM);
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+	*base = pci_resource_start(ahc->dev_softc, 0);
+#else
+	*base = ahc_pci_read_config(ahc->dev_softc, PCIR_MAPS, 4);
+	*base &= PCI_BASE_ADDRESS_IO_MASK;
+#endif
+	if (*base == 0)
+		return (ENOMEM);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
+	if (check_region(*base, 256) != 0)
+		return (ENOMEM);
+	else
+		request_region(*base, 256, "aic7xxx");
+#else
+	if (request_region(*base, 256, "aic7xxx") == 0)
+		return (ENOMEM);
+#endif
+	return (0);
+}
+
+#ifdef MMAPIO
+static int
+ahc_linux_pci_reserve_mem_region(struct ahc_softc *ahc,
+				 u_long *bus_addr,
+				 uint8_t **maddr)
+{
+	u_long	start;
+	u_long	base_page;
+	u_long	base_offset;
+	int	error;
+
+	error = 0;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
+	start = pci_resource_start(ahc->dev_softc, 1);
+	base_page = start & PAGE_MASK;
+	base_offset = start - base_page;
+#else
+	start = ahc_pci_read_config(ahc->dev_softc, PCIR_MAPS+4, 4);
+	base_offset = start & PCI_BASE_ADDRESS_MEM_MASK;
+	base_page = base_offset & PAGE_MASK;
+	base_offset -= base_page;
+#endif
+	if (start != 0) {
+		*bus_addr = start;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+		if (request_mem_region(start, 0x1000, "aic7xxx") == 0)
+			error = ENOMEM;
+#endif
+		if (error == 0) {
+			*maddr = ioremap_nocache(base_page, base_offset + 256);
+			if (*maddr == NULL) {
+				error = ENOMEM;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+				release_mem_region(start, 0x1000);
+#endif
+			} else
+				*maddr += base_offset;
+		}
+	} else
+		error = ENOMEM;
+	return (error);
+}
+#endif /* MMAPIO */
+
+int
+ahc_pci_map_registers(struct ahc_softc *ahc)
+{
+	uint32_t command;
+	u_long	 base;
+	uint8_t	*maddr;
+	int	 error;
+
+	/*
+	 * If its allowed, we prefer memory mapped access.
+	 */
+	command = ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, 4);
+	command &= ~(PCIM_CMD_PORTEN|PCIM_CMD_MEMEN);
+	base = 0;
+	maddr = NULL;
+#ifdef MMAPIO
+	error = ahc_linux_pci_reserve_mem_region(ahc, &base, &maddr);
+	if (error == 0) {
+		ahc->platform_data->mem_busaddr = base;
+		ahc->tag = BUS_SPACE_MEMIO;
+		ahc->bsh.maddr = maddr;
+		ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND,
+				     command | PCIM_CMD_MEMEN, 4);
+
+		/*
+		 * Do a quick test to see if memory mapped
+		 * I/O is functioning correctly.
+		 */
+		if (ahc_pci_test_register_access(ahc) != 0) {
+
+			printf("aic7xxx: PCI Device %d:%d:%d "
+			       "failed memory mapped test.  Using PIO.\n",
+			       ahc_get_pci_bus(ahc->dev_softc),
+			       ahc_get_pci_slot(ahc->dev_softc),
+			       ahc_get_pci_function(ahc->dev_softc));
+			iounmap((void *)((u_long)maddr & PAGE_MASK));
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+			release_mem_region(ahc->platform_data->mem_busaddr,
+					   0x1000);
+#endif
+			ahc->bsh.maddr = NULL;
+			maddr = NULL;
+		} else
+			command |= PCIM_CMD_MEMEN;
+	} else {
+		printf("aic7xxx: PCI%d:%d:%d MEM region 0x%lx "
+		       "unavailable. Cannot memory map device.\n",
+		       ahc_get_pci_bus(ahc->dev_softc),
+		       ahc_get_pci_slot(ahc->dev_softc),
+		       ahc_get_pci_function(ahc->dev_softc),
+		       base);
+	}
+#endif /* MMAPIO */
+
+	/*
+	 * We always prefer memory mapped access.
+	 */
+	if (maddr == NULL) {
+
+		error = ahc_linux_pci_reserve_io_region(ahc, &base);
+		if (error == 0) {
+			ahc->tag = BUS_SPACE_PIO;
+			ahc->bsh.ioport = base;
+			command |= PCIM_CMD_PORTEN;
+		} else {
+			printf("aic7xxx: PCI%d:%d:%d IO region 0x%lx[0..255] "
+			       "unavailable. Cannot map device.\n",
+			       ahc_get_pci_bus(ahc->dev_softc),
+			       ahc_get_pci_slot(ahc->dev_softc),
+			       ahc_get_pci_function(ahc->dev_softc),
+			       base);
+		}
+	}
+	ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, command, 4);
+	return (error);
+}
+
+int
+ahc_pci_map_int(struct ahc_softc *ahc)
+{
+	int error;
+
+	error = request_irq(ahc->dev_softc->irq, ahc_linux_isr,
+			    SA_SHIRQ, "aic7xxx", ahc);
+	if (error == 0)
+		ahc->platform_data->irq = ahc->dev_softc->irq;
+	
+	return (-error);
+}
+
+void
+ahc_power_state_change(struct ahc_softc *ahc, ahc_power_state new_state)
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+	pci_set_power_state(ahc->dev_softc, new_state);
+#else
+	uint32_t cap;
+	u_int cap_offset;
+
+	/*
+	 * Traverse the capability list looking for
+	 * the power management capability.
+	 */
+	cap = 0;
+	cap_offset = ahc_pci_read_config(ahc->dev_softc,
+					 PCIR_CAP_PTR, /*bytes*/1);
+	while (cap_offset != 0) {
+
+		cap = ahc_pci_read_config(ahc->dev_softc,
+					  cap_offset, /*bytes*/4);
+		if ((cap & 0xFF) == 1
+		 && ((cap >> 16) & 0x3) > 0) {
+			uint32_t pm_control;
+
+			pm_control = ahc_pci_read_config(ahc->dev_softc,
+							 cap_offset + 4,
+							 /*bytes*/4);
+			pm_control &= ~0x3;
+			pm_control |= new_state;
+			ahc_pci_write_config(ahc->dev_softc,
+					     cap_offset + 4,
+					     pm_control, /*bytes*/2);
+			break;
+		}
+		cap_offset = (cap >> 8) & 0xFF;
+	}
+#endif 
+}
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx_pci.c b/drivers/scsi/aic7xxx/aic7xxx_pci.c
--- a/drivers/scsi/aic7xxx/aic7xxx_pci.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/scsi/aic7xxx/aic7xxx_pci.c	Mon Dec 23 21:21:51 2002
@@ -39,14 +39,20 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $Id: //depot/aic7xxx/aic7xxx/aic7xxx_pci.c#32 $
+ * $Id: //depot/aic7xxx/aic7xxx/aic7xxx_pci.c#54 $
  *
- * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx_pci.c,v 1.6 2000/11/10 20:13:41 gibbs Exp $
+ * $FreeBSD$
  */
 
+#ifdef __linux__
 #include "aic7xxx_osm.h"
 #include "aic7xxx_inline.h"
 #include "aic7xxx_93cx6.h"
+#else
+#include <dev/aic7xxx/aic7xxx_osm.h>
+#include <dev/aic7xxx/aic7xxx_inline.h>
+#include <dev/aic7xxx/aic7xxx_93cx6.h>
+#endif
 
 #define AHC_PCI_IOADDR	PCIR_MAPS	/* I/O Address */
 #define AHC_PCI_MEMADDR	(PCIR_MAPS + 4)	/* Mem I/O Address */
@@ -207,7 +213,7 @@
 	 : ((id) & 0x1000) >> 12)
 /*
  * Informational only. Should use chip register to be
- * ceratian, but may be use in identification strings.
+ * certain, but may be use in identification strings.
  */
 #define SUBID_9005_CARD_SCSIWIDTH_MASK	0x2000
 #define SUBID_9005_CARD_PCIWIDTH_MASK	0x4000
@@ -654,6 +660,14 @@
 #define		CACHESIZE	0x0000003ful	/* only 5 bits */
 #define		LATTIME		0x0000ff00ul
 
+/* PCI STATUS definitions */
+#define	DPE	0x80
+#define SSE	0x40
+#define	RMA	0x20
+#define	RTA	0x10
+#define STA	0x08
+#define DPR	0x01
+
 static int ahc_9005_subdevinfo_valid(uint16_t vendor, uint16_t device,
 				     uint16_t subvendor, uint16_t subdevice);
 static int ahc_ext_scbram_present(struct ahc_softc *ahc);
@@ -661,6 +675,8 @@
 				  int pcheck, int fast, int large);
 static void ahc_probe_ext_scbram(struct ahc_softc *ahc);
 static void check_extport(struct ahc_softc *ahc, u_int *sxfrctl1);
+static void ahc_parse_pci_eeprom(struct ahc_softc *ahc,
+				 struct seeprom_config *sc);
 static void configure_termination(struct ahc_softc *ahc,
 				  struct seeprom_descriptor *sd,
 				  u_int adapter_control,
@@ -679,9 +695,6 @@
 static void aic785X_cable_detect(struct ahc_softc *ahc, int *internal50_present,
 				 int *externalcable_present,
 				 int *eeprom_present);
-static int acquire_seeprom(struct ahc_softc *ahc,
-			   struct seeprom_descriptor *sd);
-static void release_seeprom(struct seeprom_descriptor *sd);
 static void write_brdctl(struct ahc_softc *ahc, uint8_t value);
 static uint8_t read_brdctl(struct ahc_softc *ahc);
 
@@ -766,27 +779,35 @@
 int
 ahc_pci_config(struct ahc_softc *ahc, struct ahc_pci_identity *entry)
 {
-	struct scb_data *shared_scb_data;
-	u_int		 command;
-	u_int		 our_id = 0;
-	u_int		 sxfrctl1;
-	u_int		 scsiseq;
-	u_int		 dscommand0;
-	int		 error;
-	uint8_t		 sblkctl;
+	u_long	 l;
+	u_int	 command;
+	u_int	 our_id;
+	u_int	 sxfrctl1;
+	u_int	 scsiseq;
+	u_int	 dscommand0;
+	int	 error;
+	uint8_t	 sblkctl;
 
-	shared_scb_data = NULL;
+	our_id = 0;
 	error = entry->setup(ahc);
 	if (error != 0)
 		return (error);
 	ahc->chip |= AHC_PCI;
 	ahc->description = entry->name;
 
+	ahc_power_state_change(ahc, AHC_POWER_STATE_D0);
+
 	error = ahc_pci_map_registers(ahc);
 	if (error != 0)
 		return (error);
 
-	ahc_power_state_change(ahc, AHC_POWER_STATE_D0);
+	/*
+	 * Before we continue probing the card, ensure that
+	 * its interrupts are *disabled*.  We don't want
+	 * a misstep to hang the machine in an interrupt
+	 * storm.
+	 */
+	ahc_intr_enable(ahc, FALSE);
 
 	/*
 	 * If we need to support high memory, enable dual
@@ -964,19 +985,18 @@
 		return (error);
 
 	/*
-	 * Link this softc in with all other ahc instances.
-	 */
-	ahc_softc_insert(ahc);
-
-	/*
 	 * Allow interrupts now that we are completely setup.
 	 */
 	error = ahc_pci_map_int(ahc);
 	if (error != 0)
 		return (error);
 
-	ahc_intr_enable(ahc, TRUE);
-
+	ahc_list_lock(&l);
+	/*
+	 * Link this softc in with all other ahc instances.
+	 */
+	ahc_softc_insert(ahc);
+	ahc_list_unlock(&l);
 	return (0);
 }
 
@@ -999,6 +1019,14 @@
 
 	if ((ahc->features & AHC_ULTRA2) != 0)
 		ramps = (ahc_inb(ahc, DSCOMMAND0) & RAMPS) != 0;
+	else if (chip == AHC_AIC7895 || chip == AHC_AIC7895C)
+		/*
+		 * External SCBRAM arbitration is flakey
+		 * on these chips.  Unfortunately this means
+		 * we don't use the extra SCB ram space on the
+		 * 3940AUW.
+		 */
+		ramps = 0;
 	else if (chip >= AHC_AIC7870)
 		ramps = (devconfig & RAMPSM) != 0;
 	else
@@ -1026,6 +1054,9 @@
 		ahc_outb(ahc, SCBBADDR, ahc_get_pci_function(ahc->dev_softc));
 	}
 
+	ahc->flags &= ~AHC_LSCBS_ENABLED;
+	if (large)
+		ahc->flags |= AHC_LSCBS_ENABLED;
 	devconfig = ahc_pci_read_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4);
 	if ((ahc->features & AHC_ULTRA2) != 0) {
 		u_int dscommand0;
@@ -1165,6 +1196,63 @@
 }
 
 /*
+ * Perform some simple tests that should catch situations where
+ * our registers are invalidly mapped.
+ */
+int
+ahc_pci_test_register_access(struct ahc_softc *ahc)
+{
+	int	error;
+	u_int	status1;
+	uint8_t	seqctl;
+
+	error = EIO;
+
+	/* Enable PCI error interrupt status */
+	seqctl = ahc_inb(ahc, SEQCTL);
+	ahc_outb(ahc, SEQCTL, seqctl & ~FAILDIS);
+
+	/*
+	 * First a simple test to see if any
+	 * registers can be read.  Reading
+	 * HCNTRL has no side effects and has
+	 * at least one bit that is guaranteed to
+	 * be zero so it is a good register to
+	 * use for this test.
+	 */
+	if (ahc_inb(ahc, HCNTRL) == 0xFF)
+		goto fail;
+
+	/*
+	 * Next create a situation where write combining
+	 * or read prefetching could be initiated by the
+	 * CPU or host bridge.  Our device does not support
+	 * either, so look for data corruption and/or flagged
+	 * PCI errors.
+	 */
+	ahc_outl(ahc, SRAM_BASE, 0x5aa555aa);
+	if (ahc_inl(ahc, SRAM_BASE) != 0x5aa555aa)
+		goto fail;
+
+	status1 = ahc_pci_read_config(ahc->dev_softc,
+				      PCIR_STATUS + 1, /*bytes*/1);
+	if ((status1 & STA) != 0)
+		goto fail;
+
+	error = 0;
+
+fail:
+	/* Silently clear any latched errors. */
+	status1 = ahc_pci_read_config(ahc->dev_softc,
+				      PCIR_STATUS + 1, /*bytes*/1);
+	ahc_pci_write_config(ahc->dev_softc, PCIR_STATUS + 1,
+			     status1, /*bytes*/1);
+	ahc_outb(ahc, CLRINT, CLRPARERR);
+	ahc_outb(ahc, SEQCTL, seqctl);
+	return (error);
+}
+
+/*
  * Check the external port logic for a serial eeprom
  * and termination/cable detection contrls.
  */
@@ -1172,9 +1260,7 @@
 check_extport(struct ahc_softc *ahc, u_int *sxfrctl1)
 {
 	struct	seeprom_descriptor sd;
-	struct	seeprom_config sc;
-	u_int	scsi_conf;
-	u_int	adapter_control;
+	struct	seeprom_config *sc;
 	int	have_seeprom;
 	int	have_autoterm;
 
@@ -1182,6 +1268,7 @@
 	sd.sd_control_offset = SEECTL;		
 	sd.sd_status_offset = SEECTL;		
 	sd.sd_dataout_offset = SEECTL;		
+	sc = ahc->seep_config;
 
 	/*
 	 * For some multi-channel devices, the c46 is simply too
@@ -1201,7 +1288,7 @@
 	sd.sd_DO = SEEDO;
 	sd.sd_DI = SEEDI;
 
-	have_seeprom = acquire_seeprom(ahc, &sd);
+	have_seeprom = ahc_acquire_seeprom(ahc, &sd);
 	if (have_seeprom) {
 
 		if (bootverbose) 
@@ -1212,11 +1299,12 @@
 
 			start_addr = 32 * (ahc->channel - 'A');
 
-			have_seeprom = read_seeprom(&sd, (uint16_t *)&sc,
-						    start_addr, sizeof(sc)/2);
+			have_seeprom = ahc_read_seeprom(&sd, (uint16_t *)sc,
+							start_addr,
+							sizeof(*sc)/2);
 
 			if (have_seeprom)
-				have_seeprom = verify_cksum(&sc);
+				have_seeprom = ahc_verify_cksum(sc);
 
 			if (have_seeprom != 0 || sd.sd_chip == C56_66) {
 				if (bootverbose) {
@@ -1229,7 +1317,7 @@
 			}
 			sd.sd_chip = C56_66;
 		}
-		release_seeprom(&sd);
+		ahc_release_seeprom(&sd);
 	}
 
 	if (!have_seeprom) {
@@ -1248,138 +1336,35 @@
 			uint16_t *sc_data;
 			int	  i;
 
-			sc_data = (uint16_t *)&sc;
-			for (i = 0; i < 32; i++) {
-				uint16_t val;
-				int	 j;
+			sc_data = (uint16_t *)sc;
+			for (i = 0; i < 32; i++, sc_data++) {
+				int	j;
 
 				j = i * 2;
-				val = ahc_inb(ahc, SRAM_BASE + j)
-				    | ahc_inb(ahc, SRAM_BASE + j + 1) << 8;
+				*sc_data = ahc_inb(ahc, SRAM_BASE + j)
+					 | ahc_inb(ahc, SRAM_BASE + j + 1) << 8;
 			}
-			have_seeprom = verify_cksum(&sc);
+			have_seeprom = ahc_verify_cksum(sc);
+			if (have_seeprom)
+				ahc->flags |= AHC_SCB_CONFIG_USED;
 		}
+		/*
+		 * Clear any SCB parity errors in case this data and
+		 * its associated parity was not initialized by the BIOS
+		 */
+		ahc_outb(ahc, CLRINT, CLRPARERR);
+		ahc_outb(ahc, CLRINT, CLRBRKADRINT);
 	}
 
 	if (!have_seeprom) {
 		if (bootverbose)
 			printf("%s: No SEEPROM available.\n", ahc_name(ahc));
 		ahc->flags |= AHC_USEDEFAULTS;
+		free(ahc->seep_config, M_DEVBUF);
+		ahc->seep_config = NULL;
+		sc = NULL;
 	} else {
-		/*
-		 * Put the data we've collected down into SRAM
-		 * where ahc_init will find it.
-		 */
-		int i;
-		int max_targ = sc.max_targets & CFMAXTARG;
-		uint16_t discenable;
-		uint16_t ultraenb;
-
-		discenable = 0;
-		ultraenb = 0;
-		if ((sc.adapter_control & CFULTRAEN) != 0) {
-			/*
-			 * Determine if this adapter has a "newstyle"
-			 * SEEPROM format.
-			 */
-			for (i = 0; i < max_targ; i++) {
-				if ((sc.device_flags[i] & CFSYNCHISULTRA) != 0){
-					ahc->flags |= AHC_NEWEEPROM_FMT;
-					break;
-				}
-			}
-		}
-
-		for (i = 0; i < max_targ; i++) {
-			u_int     scsirate;
-			uint16_t target_mask;
-
-			target_mask = 0x01 << i;
-			if (sc.device_flags[i] & CFDISC)
-				discenable |= target_mask;
-			if ((ahc->flags & AHC_NEWEEPROM_FMT) != 0) {
-				if ((sc.device_flags[i] & CFSYNCHISULTRA) != 0)
-					ultraenb |= target_mask;
-			} else if ((sc.adapter_control & CFULTRAEN) != 0) {
-				ultraenb |= target_mask;
-			}
-			if ((sc.device_flags[i] & CFXFER) == 0x04
-			 && (ultraenb & target_mask) != 0) {
-				/* Treat 10MHz as a non-ultra speed */
-				sc.device_flags[i] &= ~CFXFER;
-			 	ultraenb &= ~target_mask;
-			}
-			if ((ahc->features & AHC_ULTRA2) != 0) {
-				u_int offset;
-
-				if (sc.device_flags[i] & CFSYNCH)
-					offset = MAX_OFFSET_ULTRA2;
-				else 
-					offset = 0;
-				ahc_outb(ahc, TARG_OFFSET + i, offset);
-
-				/*
-				 * The ultra enable bits contain the
-				 * high bit of the ultra2 sync rate
-				 * field.
-				 */
-				scsirate = (sc.device_flags[i] & CFXFER)
-					 | ((ultraenb & target_mask)
-					    ? 0x8 : 0x0);
-				if (sc.device_flags[i] & CFWIDEB)
-					scsirate |= WIDEXFER;
-			} else {
-				scsirate = (sc.device_flags[i] & CFXFER) << 4;
-				if (sc.device_flags[i] & CFSYNCH)
-					scsirate |= SOFS;
-				if (sc.device_flags[i] & CFWIDEB)
-					scsirate |= WIDEXFER;
-			}
-			ahc_outb(ahc, TARG_SCSIRATE + i, scsirate);
-		}
-		ahc->our_id = sc.brtime_id & CFSCSIID;
-
-		scsi_conf = (ahc->our_id & 0x7);
-		if (sc.adapter_control & CFSPARITY)
-			scsi_conf |= ENSPCHK;
-		if (sc.adapter_control & CFRESETB)
-			scsi_conf |= RESET_SCSI;
-
-		ahc->flags |=
-		    (sc.adapter_control & CFBOOTCHAN) >> CFBOOTCHANSHIFT;
-
-		if (sc.bios_control & CFEXTEND)
-			ahc->flags |= AHC_EXTENDED_TRANS_A;
-
-		if (sc.bios_control & CFBIOSEN)
-			ahc->flags |= AHC_BIOS_ENABLED;
-		if (ahc->features & AHC_ULTRA
-		 && (ahc->flags & AHC_NEWEEPROM_FMT) == 0) {
-			/* Should we enable Ultra mode? */
-			if (!(sc.adapter_control & CFULTRAEN))
-				/* Treat us as a non-ultra card */
-				ultraenb = 0;
-		}
-
-		if (sc.signature == CFSIGNATURE
-		 || sc.signature == CFSIGNATURE2) {
-			uint32_t devconfig;
-
-			/* Honor the STPWLEVEL settings */
-			devconfig = ahc_pci_read_config(ahc->dev_softc,
-							DEVCONFIG, /*bytes*/4);
-			devconfig &= ~STPWLEVEL;
-			if ((sc.bios_control & CFSTPWLEVEL) != 0)
-				devconfig |= STPWLEVEL;
-			ahc_pci_write_config(ahc->dev_softc, DEVCONFIG,
-					     devconfig, /*bytes*/4);
-		}
-		/* Set SCSICONF info */
-		ahc_outb(ahc, SCSICONF, scsi_conf);
-		ahc_outb(ahc, DISC_DSB, ~(discenable & 0xff));
-		ahc_outb(ahc, DISC_DSB + 1, ~((discenable >> 8) & 0xff));
-		ahc_outb(ahc, ULTRA_ENB, ultraenb & 0xff);
-		ahc_outb(ahc, ULTRA_ENB + 1, (ultraenb >> 8) & 0xff);
+		ahc_parse_pci_eeprom(ahc, sc);
 	}
 
 	/*
@@ -1389,10 +1374,6 @@
 	 * hasn't failed yet...
 	 */
 	have_autoterm = have_seeprom;
-	if (have_seeprom)
-		adapter_control = sc.adapter_control;
-	else
-		adapter_control = CFAUTOTERM;
 
 	/*
 	 * Some low-cost chips have SEEPROM and auto-term control built
@@ -1400,20 +1381,144 @@
 	 * if the termination logic is enabled.
 	 */
 	if ((ahc->features & AHC_SPIOCAP) != 0) {
-		if ((ahc_inb(ahc, SPIOCAP) & SSPIOCPS) != 0)
-			have_autoterm = TRUE;
-		else
+		if ((ahc_inb(ahc, SPIOCAP) & SSPIOCPS) == 0)
 			have_autoterm = FALSE;
 	}
 
 	if (have_autoterm) {
-		acquire_seeprom(ahc, &sd);
-		configure_termination(ahc, &sd, adapter_control, sxfrctl1);
-		release_seeprom(&sd);
+		ahc_acquire_seeprom(ahc, &sd);
+		configure_termination(ahc, &sd, sc->adapter_control, sxfrctl1);
+		ahc_release_seeprom(&sd);
+	} else if (have_seeprom) {
+		*sxfrctl1 &= ~STPWEN;
+		if ((sc->adapter_control & CFSTERM) != 0)
+			*sxfrctl1 |= STPWEN;
+		if (bootverbose)
+			printf("%s: Low byte termination %sabled\n",
+			       ahc_name(ahc),
+			       (*sxfrctl1 & STPWEN) ? "en" : "dis");
 	}
 }
 
 static void
+ahc_parse_pci_eeprom(struct ahc_softc *ahc, struct seeprom_config *sc)
+{
+	/*
+	 * Put the data we've collected down into SRAM
+	 * where ahc_init will find it.
+	 */
+	int	 i;
+	int	 max_targ = sc->max_targets & CFMAXTARG;
+	u_int	 scsi_conf;
+	uint16_t discenable;
+	uint16_t ultraenb;
+
+	discenable = 0;
+	ultraenb = 0;
+	if ((sc->adapter_control & CFULTRAEN) != 0) {
+		/*
+		 * Determine if this adapter has a "newstyle"
+		 * SEEPROM format.
+		 */
+		for (i = 0; i < max_targ; i++) {
+			if ((sc->device_flags[i] & CFSYNCHISULTRA) != 0) {
+				ahc->flags |= AHC_NEWEEPROM_FMT;
+				break;
+			}
+		}
+	}
+
+	for (i = 0; i < max_targ; i++) {
+		u_int     scsirate;
+		uint16_t target_mask;
+
+		target_mask = 0x01 << i;
+		if (sc->device_flags[i] & CFDISC)
+			discenable |= target_mask;
+		if ((ahc->flags & AHC_NEWEEPROM_FMT) != 0) {
+			if ((sc->device_flags[i] & CFSYNCHISULTRA) != 0)
+				ultraenb |= target_mask;
+		} else if ((sc->adapter_control & CFULTRAEN) != 0) {
+			ultraenb |= target_mask;
+		}
+		if ((sc->device_flags[i] & CFXFER) == 0x04
+		 && (ultraenb & target_mask) != 0) {
+			/* Treat 10MHz as a non-ultra speed */
+			sc->device_flags[i] &= ~CFXFER;
+		 	ultraenb &= ~target_mask;
+		}
+		if ((ahc->features & AHC_ULTRA2) != 0) {
+			u_int offset;
+
+			if (sc->device_flags[i] & CFSYNCH)
+				offset = MAX_OFFSET_ULTRA2;
+			else 
+				offset = 0;
+			ahc_outb(ahc, TARG_OFFSET + i, offset);
+
+			/*
+			 * The ultra enable bits contain the
+			 * high bit of the ultra2 sync rate
+			 * field.
+			 */
+			scsirate = (sc->device_flags[i] & CFXFER)
+				 | ((ultraenb & target_mask) ? 0x8 : 0x0);
+			if (sc->device_flags[i] & CFWIDEB)
+				scsirate |= WIDEXFER;
+		} else {
+			scsirate = (sc->device_flags[i] & CFXFER) << 4;
+			if (sc->device_flags[i] & CFSYNCH)
+				scsirate |= SOFS;
+			if (sc->device_flags[i] & CFWIDEB)
+				scsirate |= WIDEXFER;
+		}
+		ahc_outb(ahc, TARG_SCSIRATE + i, scsirate);
+	}
+	ahc->our_id = sc->brtime_id & CFSCSIID;
+
+	scsi_conf = (ahc->our_id & 0x7);
+	if (sc->adapter_control & CFSPARITY)
+		scsi_conf |= ENSPCHK;
+	if (sc->adapter_control & CFRESETB)
+		scsi_conf |= RESET_SCSI;
+
+	ahc->flags |= (sc->adapter_control & CFBOOTCHAN) >> CFBOOTCHANSHIFT;
+
+	if (sc->bios_control & CFEXTEND)
+		ahc->flags |= AHC_EXTENDED_TRANS_A;
+
+	if (sc->bios_control & CFBIOSEN)
+		ahc->flags |= AHC_BIOS_ENABLED;
+	if (ahc->features & AHC_ULTRA
+	 && (ahc->flags & AHC_NEWEEPROM_FMT) == 0) {
+		/* Should we enable Ultra mode? */
+		if (!(sc->adapter_control & CFULTRAEN))
+			/* Treat us as a non-ultra card */
+			ultraenb = 0;
+	}
+
+	if (sc->signature == CFSIGNATURE
+	 || sc->signature == CFSIGNATURE2) {
+		uint32_t devconfig;
+
+		/* Honor the STPWLEVEL settings */
+		devconfig = ahc_pci_read_config(ahc->dev_softc,
+						DEVCONFIG, /*bytes*/4);
+		devconfig &= ~STPWLEVEL;
+		if ((sc->bios_control & CFSTPWLEVEL) != 0)
+			devconfig |= STPWLEVEL;
+		ahc_pci_write_config(ahc->dev_softc, DEVCONFIG,
+				     devconfig, /*bytes*/4);
+	}
+	/* Set SCSICONF info */
+	ahc_outb(ahc, SCSICONF, scsi_conf);
+	ahc_outb(ahc, DISC_DSB, ~(discenable & 0xff));
+	ahc_outb(ahc, DISC_DSB + 1, ~((discenable >> 8) & 0xff));
+	ahc_outb(ahc, ULTRA_ENB, ultraenb & 0xff);
+	ahc_outb(ahc, ULTRA_ENB + 1, (ultraenb >> 8) & 0xff);
+}
+
+static void
 configure_termination(struct ahc_softc *ahc,
 		      struct seeprom_descriptor *sd,
 		      u_int adapter_control,
@@ -1453,10 +1558,10 @@
 		enablePRI_high = 0;
 		if ((ahc->features & AHC_NEW_TERMCTL) != 0) {
 			ahc_new_term_detect(ahc, &enableSEC_low,
-					       &enableSEC_high,
-					       &enablePRI_low,
-					       &enablePRI_high,
-					       &eeprom_present);
+					    &enableSEC_high,
+					    &enablePRI_low,
+					    &enablePRI_high,
+					    &eeprom_present);
 			if ((adapter_control & CFSEAUTOTERM) == 0) {
 				if (bootverbose)
 					printf("%s: Manual SE Termination\n",
@@ -1480,6 +1585,8 @@
 			aic785X_cable_detect(ahc, &internal50_present,
 					     &externalcable_present,
 					     &eeprom_present);
+			/* Can never support a wide connector. */
+			internal68_present = 0;
 		} else {
 			aic787X_cable_detect(ahc, &internal50_present,
 					     &internal68_present,
@@ -1534,6 +1641,15 @@
 			       "Only two connectors on the "
 			       "adapter may be used at a "
 			       "time!\n", ahc_name(ahc));
+
+			/*
+			 * Pretend there are no cables in the hope
+			 * that having all of the termination on
+			 * gives us a more stable bus.
+			 */
+		 	internal50_present = 0;
+			internal68_present = 0;
+			externalcable_present = 0;
 		}
 
 		if ((ahc->features & AHC_WIDE) != 0
@@ -1696,7 +1812,12 @@
 		     int *externalcable_present, int *eeprom_present)
 {
 	uint8_t brdctl;
+	uint8_t spiocap;
 
+	spiocap = ahc_inb(ahc, SPIOCAP);
+	spiocap &= ~SOFTCMDEN;
+	spiocap |= EXT_BRDCTL;
+	ahc_outb(ahc, SPIOCAP, spiocap);
 	ahc_outb(ahc, BRDCTL, BRDRW|BRDCS);
 	ahc_outb(ahc, BRDCTL, 0);
 	brdctl = ahc_inb(ahc, BRDCTL);
@@ -1706,8 +1827,8 @@
 	*eeprom_present = (ahc_inb(ahc, SPIOCAP) & EEPROM) ? 1 : 0;
 }
 	
-static int
-acquire_seeprom(struct ahc_softc *ahc, struct seeprom_descriptor *sd)
+int
+ahc_acquire_seeprom(struct ahc_softc *ahc, struct seeprom_descriptor *sd)
 {
 	int wait;
 
@@ -1734,8 +1855,8 @@
 	return(1);
 }
 
-static void
-release_seeprom(struct seeprom_descriptor *sd)
+void
+ahc_release_seeprom(struct seeprom_descriptor *sd)
 {
 	/* Release access to the memory port and the serial EEPROM. */
 	SEEPROM_OUTB(sd, 0);
@@ -1796,13 +1917,6 @@
 	return (value);
 }
 
-#define	DPE	0x80
-#define SSE	0x40
-#define	RMA	0x20
-#define	RTA	0x10
-#define STA	0x08
-#define DPR	0x01
-
 void
 ahc_pci_intr(struct ahc_softc *ahc)
 {
@@ -1892,10 +2006,8 @@
 static int
 ahc_apa1480_setup(struct ahc_softc *ahc)
 {
-	ahc_dev_softc_t pci;
 	int error;
 
-	pci = ahc->dev_softc;
 	error = ahc_aic7860_setup(ahc);
 	if (error != 0)
 		return (error);
@@ -1906,9 +2018,7 @@
 static int
 ahc_aic7870_setup(struct ahc_softc *ahc)
 {
-	ahc_dev_softc_t pci;
 
-	pci = ahc->dev_softc;
 	ahc->channel = 'A';
 	ahc->chip = AHC_AIC7870;
 	ahc->features = AHC_AIC7870_FE;
@@ -1972,13 +2082,9 @@
 static int
 ahc_aha2940Pro_setup(struct ahc_softc *ahc)
 {
-	ahc_dev_softc_t pci;
-	int error;
 
-	pci = ahc->dev_softc;
 	ahc->flags |= AHC_INT50_SPEEDFLEX;
-	error = ahc_aic7880_setup(ahc);
-	return (0);
+	return (ahc_aic7880_setup(ahc));
 }
 
 static int
@@ -2023,9 +2129,7 @@
 static int
 ahc_aic7892_setup(struct ahc_softc *ahc)
 {
-	ahc_dev_softc_t pci;
 
-	pci = ahc->dev_softc;
 	ahc->channel = 'A';
 	ahc->chip = AHC_AIC7892;
 	ahc->features = AHC_AIC7892_FE;
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx_proc.c b/drivers/scsi/aic7xxx/aic7xxx_proc.c
--- a/drivers/scsi/aic7xxx/aic7xxx_proc.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/scsi/aic7xxx/aic7xxx_proc.c	Mon Dec 23 21:21:50 2002
@@ -37,20 +37,22 @@
  * String handling code courtesy of Gerard Roudier's <groudier@club-internet.fr>
  * sym driver.
  *
- * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_proc.c#13 $
+ * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_proc.c#23 $
  */
 #include "aic7xxx_osm.h"
 #include "aic7xxx_inline.h"
+#include "aic7xxx_93cx6.h"
 
 static void	copy_mem_info(struct info_str *info, char *data, int len);
 static int	copy_info(struct info_str *info, char *fmt, ...);
-static u_int	scsi_calc_syncsrate(u_int period_factor);
 static void	ahc_dump_target_state(struct ahc_softc *ahc,
 				      struct info_str *info,
 				      u_int our_id, char channel,
 				      u_int target_id, u_int target_offset);
 static void	ahc_dump_device_state(struct info_str *info,
 				      struct ahc_linux_device *dev);
+static int	ahc_proc_write_seeprom(struct ahc_softc *ahc,
+				       char *buffer, int length);
 
 static void
 copy_mem_info(struct info_str *info, char *data, int len)
@@ -94,47 +96,6 @@
 	return (len);
 }
 
-/*
- * Table of syncrates that don't follow the "divisible by 4"
- * rule. This table will be expanded in future SCSI specs.
- */
-static struct {
-	u_int period_factor;
-	u_int period;	/* in 10ths of ns */
-} scsi_syncrates[] = {
-	{ 0x09, 125 },	/* FAST-80 */
-	{ 0x0a, 250 },	/* FAST-40 40MHz */
-	{ 0x0b, 303 },	/* FAST-40 33MHz */
-	{ 0x0c, 500 }	/* FAST-20 */
-};
- 
-/*
- * Return the frequency in kHz corresponding to the given
- * sync period factor.
- */
-static u_int
-scsi_calc_syncsrate(u_int period_factor)
-{
-	int i; 
-	int num_syncrates;
- 
-	num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
-	/* See if the period is in the "exception" table */
-	for (i = 0; i < num_syncrates; i++) {
-
-		if (period_factor == scsi_syncrates[i].period_factor) {
-       			/* Period in kHz */
-			return (10000000 / scsi_syncrates[i].period);
-		}
-	}
-
-	/*
-	 * Wasn't in the table, so use the standard
-	 * 4 times conversion.
-	 */
-	return (10000000 / (period_factor * 4 * 10));
-}
-
 void
 ahc_format_transinfo(struct info_str *info, struct ahc_transinfo *tinfo)
 {
@@ -145,7 +106,7 @@
         speed = 3300;
         freq = 0;
 	if (tinfo->offset != 0) {
-		freq = scsi_calc_syncsrate(tinfo->period);
+		freq = aic_calc_syncsrate(tinfo->period);
 		speed = freq;
 	}
 	speed *= (0x01 << tinfo->width);
@@ -225,6 +186,104 @@
 	copy_info(info, "\t\tDevice Queue Frozen Count %d\n", dev->qfrozen);
 }
 
+static int
+ahc_proc_write_seeprom(struct ahc_softc *ahc, char *buffer, int length)
+{
+	struct seeprom_descriptor sd;
+	int have_seeprom;
+	u_long s;
+	int paused;
+	int written;
+
+	/* Default to failure. */
+	written = -EINVAL;
+	ahc_lock(ahc, &s);
+	paused = ahc_is_paused(ahc);
+	if (!paused)
+		ahc_pause(ahc);
+
+	if (length != sizeof(struct seeprom_config)) {
+		printf("ahc_proc_write_seeprom: incorrect buffer size\n");
+		goto done;
+	}
+
+	have_seeprom = ahc_verify_cksum((struct seeprom_config*)buffer);
+	if (have_seeprom == 0) {
+		printf("ahc_proc_write_seeprom: cksum verification failed\n");
+		goto done;
+	}
+
+	sd.sd_ahc = ahc;
+#if AHC_PCI_CONFIG > 0
+	if ((ahc->chip & AHC_PCI) != 0) {
+		sd.sd_control_offset = SEECTL;
+		sd.sd_status_offset = SEECTL;
+		sd.sd_dataout_offset = SEECTL;
+		if (ahc->flags & AHC_LARGE_SEEPROM)
+			sd.sd_chip = C56_66;
+		else
+			sd.sd_chip = C46;
+		sd.sd_MS = SEEMS;
+		sd.sd_RDY = SEERDY;
+		sd.sd_CS = SEECS;
+		sd.sd_CK = SEECK;
+		sd.sd_DO = SEEDO;
+		sd.sd_DI = SEEDI;
+		have_seeprom = ahc_acquire_seeprom(ahc, &sd);
+	} else
+#endif
+	if ((ahc->chip & AHC_VL) != 0) {
+		sd.sd_control_offset = SEECTL_2840;
+		sd.sd_status_offset = STATUS_2840;
+		sd.sd_dataout_offset = STATUS_2840;		
+		sd.sd_chip = C46;
+		sd.sd_MS = 0;
+		sd.sd_RDY = EEPROM_TF;
+		sd.sd_CS = CS_2840;
+		sd.sd_CK = CK_2840;
+		sd.sd_DO = DO_2840;
+		sd.sd_DI = DI_2840;
+		have_seeprom = TRUE;
+	} else {
+		printf("ahc_proc_write_seeprom: unsupported adapter type\n");
+		goto done;
+	}
+
+	if (!have_seeprom) {
+		printf("ahc_proc_write_seeprom: No Serial EEPROM\n");
+		goto done;
+	} else {
+		u_int start_addr;
+
+		if (ahc->seep_config == NULL) {
+			ahc->seep_config = malloc(sizeof(*ahc->seep_config),
+						  M_DEVBUF, M_NOWAIT);
+			if (ahc->seep_config == NULL) {
+				printf("aic7xxx: Unable to allocate serial "
+				       "eeprom buffer.  Write failing\n");
+				goto done;
+			}
+		}
+		printf("aic7xxx: Writing Serial EEPROM\n");
+		start_addr = 32 * (ahc->channel - 'A');
+		ahc_write_seeprom(&sd, (u_int16_t *)buffer, start_addr,
+				  sizeof(struct seeprom_config)/2);
+		ahc_read_seeprom(&sd, (uint16_t *)ahc->seep_config,
+				 start_addr, sizeof(struct seeprom_config)/2);
+#if AHC_PCI_CONFIG > 0
+		if ((ahc->chip & AHC_VL) == 0)
+			ahc_release_seeprom(&sd);
+#endif
+		written = length;
+	}
+
+done:
+	if (!paused)
+		ahc_unpause(ahc);
+	ahc_unlock(ahc, &s);
+	return (written);
+}
+
 /*
  * Return information to handle /proc support for the driver.
  */
@@ -235,20 +294,26 @@
 	struct	ahc_softc *ahc;
 	struct	info_str info;
 	char	ahc_info[256];
+	u_long	s;
 	u_int	max_targ;
 	u_int	i;
+	int	retval;
 
+	retval = -EINVAL;
+	ahc_list_lock(&s);
 	TAILQ_FOREACH(ahc, &ahc_tailq, links) {
 		if (ahc->platform_data->host->host_no == hostno)
 			break;
 	}
 
 	if (ahc == NULL)
-		return (-EINVAL);
+		goto done;
 
 	 /* Has data been written to the file? */ 
-	if (inout == TRUE)
-		return (-ENOSYS);
+	if (inout == TRUE) {
+		retval = ahc_proc_write_seeprom(ahc, buffer, length);
+		goto done;
+	}
 
 	if (start)
 		*start = buffer;
@@ -261,7 +326,22 @@
 	copy_info(&info, "Adaptec AIC7xxx driver version: %s\n",
 		  AIC7XXX_DRIVER_VERSION);
 	ahc_controller_info(ahc, ahc_info);
-	copy_info(&info, "%s\n", ahc_info);
+	copy_info(&info, "%s\n\n", ahc_info);
+
+	if (ahc->seep_config == NULL)
+		copy_info(&info, "No Serial EEPROM\n");
+	else {
+		copy_info(&info, "Serial EEPROM:\n");
+		for (i = 0; i < sizeof(*ahc->seep_config)/2; i++) {
+			if (((i % 8) == 0) && (i != 0)) {
+				copy_info(&info, "\n");
+			}
+			copy_info(&info, "0x%.4x ",
+				  ((uint16_t*)ahc->seep_config)[i]);
+		}
+		copy_info(&info, "\n");
+	}
+	copy_info(&info, "\n");
 
 	max_targ = 15;
 	if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0)
@@ -284,5 +364,8 @@
 		ahc_dump_target_state(ahc, &info, our_id,
 				      channel, target_id, i);
 	}
-	return (info.pos > info.offset ? info.pos - info.offset : 0);
+	retval = info.pos > info.offset ? info.pos - info.offset : 0;
+done:
+	ahc_list_unlock(&s);
+	return (retval);
 }
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx_reg.h_shipped b/drivers/scsi/aic7xxx/aic7xxx_reg.h_shipped
--- a/drivers/scsi/aic7xxx/aic7xxx_reg.h_shipped	Mon Dec 23 21:21:57 2002
+++ b/drivers/scsi/aic7xxx/aic7xxx_reg.h_shipped	Mon Dec 23 21:21:57 2002
@@ -2,9 +2,1073 @@
  * DO NOT EDIT - This file is automatically generated
  *		 from the following source files:
  *
- * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.seq#37 $
- * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.reg#24 $
+ * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.seq#52 $
+ * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.reg#36 $
  */
+typedef int (ahc_reg_print_t)(u_int, u_int *, u_int);
+typedef struct ahc_reg_parse_entry {
+	char	*name;
+	uint8_t	 value;
+	uint8_t	 mask;
+} ahc_reg_parse_entry_t;
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scsiseq_print;
+#else
+#define ahc_scsiseq_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCSISEQ", 0x00, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_sxfrctl0_print;
+#else
+#define ahc_sxfrctl0_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SXFRCTL0", 0x01, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_sxfrctl1_print;
+#else
+#define ahc_sxfrctl1_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SXFRCTL1", 0x02, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scsisigo_print;
+#else
+#define ahc_scsisigo_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCSISIGO", 0x03, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scsisigi_print;
+#else
+#define ahc_scsisigi_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCSISIGI", 0x03, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scsirate_print;
+#else
+#define ahc_scsirate_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCSIRATE", 0x04, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scsiid_print;
+#else
+#define ahc_scsiid_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCSIID", 0x05, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scsidatl_print;
+#else
+#define ahc_scsidatl_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCSIDATL", 0x06, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scsidath_print;
+#else
+#define ahc_scsidath_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCSIDATH", 0x07, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_stcnt_print;
+#else
+#define ahc_stcnt_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "STCNT", 0x08, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_optionmode_print;
+#else
+#define ahc_optionmode_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "OPTIONMODE", 0x08, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_targcrccnt_print;
+#else
+#define ahc_targcrccnt_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "TARGCRCCNT", 0x0a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_clrsint0_print;
+#else
+#define ahc_clrsint0_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "CLRSINT0", 0x0b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_sstat0_print;
+#else
+#define ahc_sstat0_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SSTAT0", 0x0b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_clrsint1_print;
+#else
+#define ahc_clrsint1_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "CLRSINT1", 0x0c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_sstat1_print;
+#else
+#define ahc_sstat1_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SSTAT1", 0x0c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_sstat2_print;
+#else
+#define ahc_sstat2_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SSTAT2", 0x0d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_sstat3_print;
+#else
+#define ahc_sstat3_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SSTAT3", 0x0e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scsiid_ultra2_print;
+#else
+#define ahc_scsiid_ultra2_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCSIID_ULTRA2", 0x0f, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_simode0_print;
+#else
+#define ahc_simode0_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SIMODE0", 0x10, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_simode1_print;
+#else
+#define ahc_simode1_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SIMODE1", 0x11, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scsibusl_print;
+#else
+#define ahc_scsibusl_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCSIBUSL", 0x12, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scsibush_print;
+#else
+#define ahc_scsibush_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCSIBUSH", 0x13, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_sxfrctl2_print;
+#else
+#define ahc_sxfrctl2_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SXFRCTL2", 0x13, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_shaddr_print;
+#else
+#define ahc_shaddr_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SHADDR", 0x14, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_seltimer_print;
+#else
+#define ahc_seltimer_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SELTIMER", 0x18, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_selid_print;
+#else
+#define ahc_selid_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SELID", 0x19, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scamctl_print;
+#else
+#define ahc_scamctl_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCAMCTL", 0x1a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_targid_print;
+#else
+#define ahc_targid_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "TARGID", 0x1b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_spiocap_print;
+#else
+#define ahc_spiocap_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SPIOCAP", 0x1b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_brdctl_print;
+#else
+#define ahc_brdctl_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "BRDCTL", 0x1d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_seectl_print;
+#else
+#define ahc_seectl_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SEECTL", 0x1e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_sblkctl_print;
+#else
+#define ahc_sblkctl_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SBLKCTL", 0x1f, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_busy_targets_print;
+#else
+#define ahc_busy_targets_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "BUSY_TARGETS", 0x20, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_ultra_enb_print;
+#else
+#define ahc_ultra_enb_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "ULTRA_ENB", 0x30, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_disc_dsb_print;
+#else
+#define ahc_disc_dsb_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "DISC_DSB", 0x32, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_cmdsize_table_tail_print;
+#else
+#define ahc_cmdsize_table_tail_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "CMDSIZE_TABLE_TAIL", 0x34, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_mwi_residual_print;
+#else
+#define ahc_mwi_residual_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "MWI_RESIDUAL", 0x38, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_next_queued_scb_print;
+#else
+#define ahc_next_queued_scb_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "NEXT_QUEUED_SCB", 0x39, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_msg_out_print;
+#else
+#define ahc_msg_out_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "MSG_OUT", 0x3a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_dmaparams_print;
+#else
+#define ahc_dmaparams_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "DMAPARAMS", 0x3b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_seq_flags_print;
+#else
+#define ahc_seq_flags_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SEQ_FLAGS", 0x3c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_saved_scsiid_print;
+#else
+#define ahc_saved_scsiid_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SAVED_SCSIID", 0x3d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_saved_lun_print;
+#else
+#define ahc_saved_lun_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SAVED_LUN", 0x3e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_lastphase_print;
+#else
+#define ahc_lastphase_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "LASTPHASE", 0x3f, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_waiting_scbh_print;
+#else
+#define ahc_waiting_scbh_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "WAITING_SCBH", 0x40, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_disconnected_scbh_print;
+#else
+#define ahc_disconnected_scbh_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "DISCONNECTED_SCBH", 0x41, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_free_scbh_print;
+#else
+#define ahc_free_scbh_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "FREE_SCBH", 0x42, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_complete_scbh_print;
+#else
+#define ahc_complete_scbh_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "COMPLETE_SCBH", 0x43, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_hscb_addr_print;
+#else
+#define ahc_hscb_addr_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "HSCB_ADDR", 0x44, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_shared_data_addr_print;
+#else
+#define ahc_shared_data_addr_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SHARED_DATA_ADDR", 0x48, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_kernel_qinpos_print;
+#else
+#define ahc_kernel_qinpos_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "KERNEL_QINPOS", 0x4c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_qinpos_print;
+#else
+#define ahc_qinpos_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "QINPOS", 0x4d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_qoutpos_print;
+#else
+#define ahc_qoutpos_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "QOUTPOS", 0x4e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_kernel_tqinpos_print;
+#else
+#define ahc_kernel_tqinpos_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "KERNEL_TQINPOS", 0x4f, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_tqinpos_print;
+#else
+#define ahc_tqinpos_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "TQINPOS", 0x50, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_arg_1_print;
+#else
+#define ahc_arg_1_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "ARG_1", 0x51, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_arg_2_print;
+#else
+#define ahc_arg_2_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "ARG_2", 0x52, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_last_msg_print;
+#else
+#define ahc_last_msg_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "LAST_MSG", 0x53, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scsiseq_template_print;
+#else
+#define ahc_scsiseq_template_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCSISEQ_TEMPLATE", 0x54, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_data_count_odd_print;
+#else
+#define ahc_data_count_odd_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "DATA_COUNT_ODD", 0x55, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_ha_274_biosglobal_print;
+#else
+#define ahc_ha_274_biosglobal_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "HA_274_BIOSGLOBAL", 0x56, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_seq_flags2_print;
+#else
+#define ahc_seq_flags2_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SEQ_FLAGS2", 0x57, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scsiconf_print;
+#else
+#define ahc_scsiconf_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCSICONF", 0x5a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_intdef_print;
+#else
+#define ahc_intdef_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "INTDEF", 0x5c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_hostconf_print;
+#else
+#define ahc_hostconf_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "HOSTCONF", 0x5d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_ha_274_biosctrl_print;
+#else
+#define ahc_ha_274_biosctrl_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "HA_274_BIOSCTRL", 0x5f, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_seqctl_print;
+#else
+#define ahc_seqctl_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SEQCTL", 0x60, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_seqram_print;
+#else
+#define ahc_seqram_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SEQRAM", 0x61, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_seqaddr0_print;
+#else
+#define ahc_seqaddr0_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SEQADDR0", 0x62, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_seqaddr1_print;
+#else
+#define ahc_seqaddr1_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SEQADDR1", 0x63, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_accum_print;
+#else
+#define ahc_accum_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "ACCUM", 0x64, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_sindex_print;
+#else
+#define ahc_sindex_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SINDEX", 0x65, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_dindex_print;
+#else
+#define ahc_dindex_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "DINDEX", 0x66, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_allones_print;
+#else
+#define ahc_allones_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "ALLONES", 0x69, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_allzeros_print;
+#else
+#define ahc_allzeros_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "ALLZEROS", 0x6a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_none_print;
+#else
+#define ahc_none_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "NONE", 0x6a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_flags_print;
+#else
+#define ahc_flags_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "FLAGS", 0x6b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_sindir_print;
+#else
+#define ahc_sindir_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SINDIR", 0x6c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_dindir_print;
+#else
+#define ahc_dindir_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "DINDIR", 0x6d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_function1_print;
+#else
+#define ahc_function1_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "FUNCTION1", 0x6e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_stack_print;
+#else
+#define ahc_stack_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "STACK", 0x6f, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_targ_offset_print;
+#else
+#define ahc_targ_offset_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "TARG_OFFSET", 0x70, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_sram_base_print;
+#else
+#define ahc_sram_base_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SRAM_BASE", 0x70, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_bctl_print;
+#else
+#define ahc_bctl_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "BCTL", 0x84, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_dscommand0_print;
+#else
+#define ahc_dscommand0_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "DSCOMMAND0", 0x84, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_bustime_print;
+#else
+#define ahc_bustime_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "BUSTIME", 0x85, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_dscommand1_print;
+#else
+#define ahc_dscommand1_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "DSCOMMAND1", 0x85, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_busspd_print;
+#else
+#define ahc_busspd_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "BUSSPD", 0x86, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_hs_mailbox_print;
+#else
+#define ahc_hs_mailbox_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "HS_MAILBOX", 0x86, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_dspcistatus_print;
+#else
+#define ahc_dspcistatus_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "DSPCISTATUS", 0x86, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_hcntrl_print;
+#else
+#define ahc_hcntrl_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "HCNTRL", 0x87, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_haddr_print;
+#else
+#define ahc_haddr_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "HADDR", 0x88, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_hcnt_print;
+#else
+#define ahc_hcnt_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "HCNT", 0x8c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scbptr_print;
+#else
+#define ahc_scbptr_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCBPTR", 0x90, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_intstat_print;
+#else
+#define ahc_intstat_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "INTSTAT", 0x91, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_clrint_print;
+#else
+#define ahc_clrint_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "CLRINT", 0x92, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_error_print;
+#else
+#define ahc_error_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "ERROR", 0x92, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_dfcntrl_print;
+#else
+#define ahc_dfcntrl_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "DFCNTRL", 0x93, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_dfstatus_print;
+#else
+#define ahc_dfstatus_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "DFSTATUS", 0x94, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_dfwaddr_print;
+#else
+#define ahc_dfwaddr_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "DFWADDR", 0x95, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_dfraddr_print;
+#else
+#define ahc_dfraddr_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "DFRADDR", 0x97, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_dfdat_print;
+#else
+#define ahc_dfdat_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "DFDAT", 0x99, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scbcnt_print;
+#else
+#define ahc_scbcnt_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCBCNT", 0x9a, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_qinfifo_print;
+#else
+#define ahc_qinfifo_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "QINFIFO", 0x9b, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_qincnt_print;
+#else
+#define ahc_qincnt_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "QINCNT", 0x9c, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_qoutfifo_print;
+#else
+#define ahc_qoutfifo_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "QOUTFIFO", 0x9d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_crccontrol1_print;
+#else
+#define ahc_crccontrol1_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "CRCCONTROL1", 0x9d, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_qoutcnt_print;
+#else
+#define ahc_qoutcnt_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "QOUTCNT", 0x9e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scsiphase_print;
+#else
+#define ahc_scsiphase_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCSIPHASE", 0x9e, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_sfunct_print;
+#else
+#define ahc_sfunct_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SFUNCT", 0x9f, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_base_print;
+#else
+#define ahc_scb_base_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_BASE", 0xa0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_cdb_ptr_print;
+#else
+#define ahc_scb_cdb_ptr_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_CDB_PTR", 0xa0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_residual_sgptr_print;
+#else
+#define ahc_scb_residual_sgptr_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_RESIDUAL_SGPTR", 0xa4, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_scsi_status_print;
+#else
+#define ahc_scb_scsi_status_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_SCSI_STATUS", 0xa8, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_target_phases_print;
+#else
+#define ahc_scb_target_phases_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_TARGET_PHASES", 0xa9, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_target_data_dir_print;
+#else
+#define ahc_scb_target_data_dir_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_TARGET_DATA_DIR", 0xaa, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_target_itag_print;
+#else
+#define ahc_scb_target_itag_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_TARGET_ITAG", 0xab, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_dataptr_print;
+#else
+#define ahc_scb_dataptr_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_DATAPTR", 0xac, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_datacnt_print;
+#else
+#define ahc_scb_datacnt_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_DATACNT", 0xb0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_sgptr_print;
+#else
+#define ahc_scb_sgptr_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_SGPTR", 0xb4, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_control_print;
+#else
+#define ahc_scb_control_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_CONTROL", 0xb8, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_scsiid_print;
+#else
+#define ahc_scb_scsiid_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_SCSIID", 0xb9, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_lun_print;
+#else
+#define ahc_scb_lun_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_LUN", 0xba, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_tag_print;
+#else
+#define ahc_scb_tag_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_TAG", 0xbb, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_cdb_len_print;
+#else
+#define ahc_scb_cdb_len_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_CDB_LEN", 0xbc, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_scsirate_print;
+#else
+#define ahc_scb_scsirate_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_SCSIRATE", 0xbd, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_scsioffset_print;
+#else
+#define ahc_scb_scsioffset_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_SCSIOFFSET", 0xbe, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_next_print;
+#else
+#define ahc_scb_next_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_NEXT", 0xbf, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_64_spare_print;
+#else
+#define ahc_scb_64_spare_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_64_SPARE", 0xc0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_seectl_2840_print;
+#else
+#define ahc_seectl_2840_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SEECTL_2840", 0xc0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_status_2840_print;
+#else
+#define ahc_status_2840_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "STATUS_2840", 0xc1, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scb_64_btt_print;
+#else
+#define ahc_scb_64_btt_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCB_64_BTT", 0xd0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_cchaddr_print;
+#else
+#define ahc_cchaddr_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "CCHADDR", 0xe0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_cchcnt_print;
+#else
+#define ahc_cchcnt_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "CCHCNT", 0xe8, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_ccsgram_print;
+#else
+#define ahc_ccsgram_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "CCSGRAM", 0xe9, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_ccsgaddr_print;
+#else
+#define ahc_ccsgaddr_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "CCSGADDR", 0xea, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_ccsgctl_print;
+#else
+#define ahc_ccsgctl_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "CCSGCTL", 0xeb, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_ccscbram_print;
+#else
+#define ahc_ccscbram_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "CCSCBRAM", 0xec, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_ccscbaddr_print;
+#else
+#define ahc_ccscbaddr_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "CCSCBADDR", 0xed, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_ccscbctl_print;
+#else
+#define ahc_ccscbctl_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "CCSCBCTL", 0xee, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_ccscbcnt_print;
+#else
+#define ahc_ccscbcnt_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "CCSCBCNT", 0xef, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_scbbaddr_print;
+#else
+#define ahc_scbbaddr_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SCBBADDR", 0xf0, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_ccscbptr_print;
+#else
+#define ahc_ccscbptr_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "CCSCBPTR", 0xf1, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_hnscb_qoff_print;
+#else
+#define ahc_hnscb_qoff_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "HNSCB_QOFF", 0xf4, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_snscb_qoff_print;
+#else
+#define ahc_snscb_qoff_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SNSCB_QOFF", 0xf6, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_sdscb_qoff_print;
+#else
+#define ahc_sdscb_qoff_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SDSCB_QOFF", 0xf8, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_qoff_ctlsta_print;
+#else
+#define ahc_qoff_ctlsta_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "QOFF_CTLSTA", 0xfa, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_dff_thrsh_print;
+#else
+#define ahc_dff_thrsh_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "DFF_THRSH", 0xfb, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_sg_cache_shadow_print;
+#else
+#define ahc_sg_cache_shadow_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SG_CACHE_SHADOW", 0xfc, regvalue, cur_col, wrap)
+#endif
+
+#if AIC_DEBUG_REGISTERS
+ahc_reg_print_t ahc_sg_cache_pre_print;
+#else
+#define ahc_sg_cache_pre_print(regvalue, cur_col, wrap) \
+    ahc_print_register(NULL, 0, "SG_CACHE_PRE", 0xfc, regvalue, cur_col, wrap)
+#endif
+
 
 #define	SCSISEQ         		0x00
 #define		TEMODE          	0x80
@@ -20,9 +1084,9 @@
 #define		CLRCHN          	0x02
 
 #define	SXFRCTL1        		0x02
+#define		STIMESEL        	0x18
 #define		BITBUCKET       	0x80
 #define		SWRAPEN         	0x40
-#define		STIMESEL        	0x18
 #define		ENSTIMER        	0x04
 #define		ACTNEGEN        	0x02
 #define		STPWEN          	0x01
@@ -47,12 +1111,12 @@
 #define		ACKI            	0x01
 
 #define	SCSIRATE        		0x04
-#define		WIDEXFER        	0x80
 #define		SXFR            	0x70
-#define		ENABLE_CRC      	0x40
-#define		SINGLE_EDGE     	0x10
 #define		SOFS            	0x0f
 #define		SXFR_ULTRA2     	0x0f
+#define		WIDEXFER        	0x80
+#define		ENABLE_CRC      	0x40
+#define		SINGLE_EDGE     	0x10
 
 #define	SCSIID          		0x05
 #define	SCSIOFFSET      		0x05
@@ -65,13 +1129,13 @@
 #define	STCNT           		0x08
 
 #define	OPTIONMODE      		0x08
+#define		OPTIONMODE_DEFAULTS	0x03
 #define		AUTORATEEN      	0x80
 #define		AUTOACKEN       	0x40
 #define		ATNMGMNTEN      	0x20
 #define		BUSFREEREV      	0x10
 #define		EXPPHASEDIS     	0x08
 #define		SCSIDATL_IMGEN  	0x04
-#define		OPTIONMODE_DEFAULTS	0x03
 #define		AUTO_MSGOUT_DE  	0x02
 #define		DIS_MSGIN_DUALEDGE	0x01
 
@@ -116,9 +1180,9 @@
 #define		REQINIT         	0x01
 
 #define	SSTAT2          		0x0d
+#define		SFCNT           	0x1f
 #define		OVERRUN         	0x80
 #define		SHVALID         	0x40
-#define		SFCNT           	0x1f
 #define		EXP_ACTIVE      	0x10
 #define		CRCVALERR       	0x08
 #define		CRCENDERR       	0x04
@@ -156,6 +1220,11 @@
 
 #define	SCSIBUSH        		0x13
 
+#define	SXFRCTL2        		0x13
+#define		ASYNC_SETUP     	0x07
+#define		AUTORSTDIS      	0x10
+#define		CMDDMAEN        	0x08
+
 #define	SHADDR          		0x14
 
 #define	SELTIMER        		0x18
@@ -172,11 +1241,11 @@
 #define		ONEBIT          	0x08
 
 #define	SCAMCTL         		0x1a
+#define		SCAMLVL         	0x03
 #define		ENSCAMSELO      	0x80
 #define		CLRSCAMSELID    	0x40
 #define		ALTSTIM         	0x20
 #define		DFLTTID         	0x10
-#define		SCAMLVL         	0x03
 
 #define	TARGID          		0x1b
 
@@ -184,7 +1253,7 @@
 #define		SOFT1           	0x80
 #define		SOFT0           	0x40
 #define		SOFTCMDEN       	0x20
-#define		HAS_BRDCTL      	0x10
+#define		EXT_BRDCTL      	0x10
 #define		SEEPROM         	0x08
 #define		EEPROM          	0x04
 #define		ROM             	0x02
@@ -228,8 +1297,6 @@
 #define	BUSY_TARGETS    		0x20
 #define	TARG_SCSIRATE   		0x20
 
-#define	SRAM_BASE       		0x20
-
 #define	ULTRA_ENB       		0x30
 #define	CMDSIZE_TABLE   		0x30
 
@@ -238,6 +1305,7 @@
 #define	CMDSIZE_TABLE_TAIL		0x34
 
 #define	MWI_RESIDUAL    		0x38
+#define	TARG_IMMEDIATE_SCB		0x38
 
 #define	NEXT_QUEUED_SCB 		0x39
 
@@ -256,7 +1324,8 @@
 #define		FIFORESET       	0x01
 
 #define	SEQ_FLAGS       		0x3c
-#define		IDENTIFY_SEEN   	0x80
+#define		NOT_IDENTIFIED  	0x80
+#define		NO_CDB_SENT     	0x40
 #define		TARGET_CMD_IS_TAGGED	0x40
 #define		DPHASE          	0x20
 #define		TARG_CMD_PENDING	0x10
@@ -275,12 +1344,12 @@
 #define		P_STATUS        	0xc0
 #define		P_MESGOUT       	0xa0
 #define		P_COMMAND       	0x80
-#define		CDI             	0x80
 #define		P_DATAIN        	0x40
-#define		IOI             	0x40
-#define		MSGI            	0x20
 #define		P_BUSFREE       	0x01
 #define		P_DATAOUT       	0x00
+#define		CDI             	0x80
+#define		IOI             	0x40
+#define		MSGI            	0x20
 
 #define	WAITING_SCBH    		0x40
 
@@ -329,22 +1398,24 @@
 
 #define	DATA_COUNT_ODD  		0x55
 
+#define	HA_274_BIOSGLOBAL		0x56
 #define	INITIATOR_TAG   		0x56
+#define		HA_274_EXTENDED_TRANS	0x01
 
 #define	SEQ_FLAGS2      		0x57
 #define		TARGET_MSG_PENDING	0x02
 #define		SCB_DMA         	0x01
 
 #define	SCSICONF        		0x5a
+#define		HWSCSIID        	0x0f
+#define		HSCSIID         	0x07
 #define		TERM_ENB        	0x80
 #define		RESET_SCSI      	0x40
 #define		ENSPCHK         	0x20
-#define		HWSCSIID        	0x0f
-#define		HSCSIID         	0x07
 
 #define	INTDEF          		0x5c
-#define		EDGE_TRIG       	0x80
 #define		VECTOR          	0x0f
+#define		EDGE_TRIG       	0x80
 
 #define	HOSTCONF        		0x5d
 
@@ -396,6 +1467,8 @@
 
 #define	TARG_OFFSET     		0x70
 
+#define	SRAM_BASE       		0x70
+
 #define	BCTL            		0x84
 #define		ACE             	0x08
 #define		ENABLE          	0x01
@@ -462,13 +1535,13 @@
 #define		PDATA_REINIT    	0x51
 #define		IGN_WIDE_RES    	0x41
 #define		NO_MATCH        	0x31
-#define		NO_IDENT        	0x21
+#define		PROTO_VIOLATION 	0x21
 #define		SEND_REJECT     	0x11
 #define		INT_PEND        	0x0f
+#define		BAD_PHASE       	0x01
 #define		BRKADRINT       	0x08
 #define		SCSIINT         	0x04
 #define		CMDCMPLT        	0x02
-#define		BAD_PHASE       	0x01
 #define		SEQINT          	0x01
 
 #define	CLRINT          		0x92
@@ -507,8 +1580,8 @@
 #define	DFDAT           		0x99
 
 #define	SCBCNT          		0x9a
-#define		SCBAUTO         	0x80
 #define		SCBCNT_MASK     	0x1f
+#define		SCBAUTO         	0x80
 
 #define	QINFIFO         		0x9b
 
@@ -527,11 +1600,11 @@
 #define	QOUTCNT         		0x9e
 
 #define	SCSIPHASE       		0x9e
+#define		DATA_PHASE_MASK 	0x03
 #define		STATUS_PHASE    	0x20
 #define		COMMAND_PHASE   	0x10
 #define		MSG_IN_PHASE    	0x08
 #define		MSG_OUT_PHASE   	0x04
-#define		DATA_PHASE_MASK 	0x03
 #define		DATA_IN_PHASE   	0x02
 #define		DATA_OUT_PHASE  	0x01
 
@@ -557,8 +1630,8 @@
 #define	SCB_DATAPTR     		0xac
 
 #define	SCB_DATACNT     		0xb0
-#define		SG_LAST_SEG     	0x80
 #define		SG_HIGH_ADDR_BITS	0x7f
+#define		SG_LAST_SEG     	0x80
 
 #define	SCB_SGPTR       		0xb4
 #define		SG_RESID_VALID  	0x04
@@ -566,19 +1639,20 @@
 #define		SG_LIST_NULL    	0x01
 
 #define	SCB_CONTROL     		0xb8
+#define		SCB_TAG_TYPE    	0x03
+#define		STATUS_RCVD     	0x80
 #define		TARGET_SCB      	0x80
 #define		DISCENB         	0x40
 #define		TAG_ENB         	0x20
 #define		MK_MESSAGE      	0x10
 #define		ULTRAENB        	0x08
 #define		DISCONNECTED    	0x04
-#define		SCB_TAG_TYPE    	0x03
 
 #define	SCB_SCSIID      		0xb9
 #define		TID             	0xf0
-#define		TWIN_CHNLB      	0x80
 #define		TWIN_TID        	0x70
 #define		OID             	0x0f
+#define		TWIN_CHNLB      	0x80
 
 #define	SCB_LUN         		0xba
 #define		LID             	0xff
@@ -601,9 +1675,9 @@
 #define		DO_2840         	0x01
 
 #define	STATUS_2840     		0xc1
-#define		EEPROM_TF       	0x80
 #define		BIOS_SEL        	0x60
 #define		ADSEL           	0x1e
+#define		EEPROM_TF       	0x80
 #define		DI_2840         	0x01
 
 #define	SCB_64_BTT      		0xd0
@@ -647,11 +1721,11 @@
 #define	SDSCB_QOFF      		0xf8
 
 #define	QOFF_CTLSTA     		0xfa
+#define		SCB_QSIZE       	0x07
+#define		SCB_QSIZE_256   	0x06
 #define		SCB_AVAIL       	0x40
 #define		SNSCB_ROLLOVER  	0x20
 #define		SDSCB_ROLLOVER  	0x10
-#define		SCB_QSIZE       	0x07
-#define		SCB_QSIZE_256   	0x06
 
 #define	DFF_THRSH       		0xfb
 #define		WR_DFTHRSH      	0x70
@@ -702,6 +1776,7 @@
 #define	SEQ_MAILBOX_SHIFT	0x00
 #define	TARGET_DATA_IN	0x01
 #define	HOST_MSG	0xff
+#define	MAX_OFFSET	0xff
 #define	BUS_16_BIT	0x01
 #define	SCB_UPLOAD_SIZE	0x20
 
@@ -714,3 +1789,7 @@
 #define	SG_PREFETCH_CNT	0x04
 #define	CACHESIZE_MASK	0x02
 #define	QINFIFO_OFFSET	0x01
+#define	DOWNLOAD_CONST_COUNT	0x07
+
+
+/* Exported Labels */
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx_reg_print.c_shipped b/drivers/scsi/aic7xxx/aic7xxx_reg_print.c_shipped
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aic7xxx_reg_print.c_shipped	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,1689 @@
+/*
+ * DO NOT EDIT - This file is automatically generated
+ *		 from the following source files:
+ *
+ * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.seq#52 $
+ * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.reg#36 $
+ */
+
+#include "aic7xxx_osm.h"
+
+static ahc_reg_parse_entry_t SCSISEQ_parse_table[] = {
+	{ "SCSIRSTO",		0x01, 0x01 },
+	{ "ENAUTOATNP",		0x02, 0x02 },
+	{ "ENAUTOATNI",		0x04, 0x04 },
+	{ "ENAUTOATNO",		0x08, 0x08 },
+	{ "ENRSELI",		0x10, 0x10 },
+	{ "ENSELI",		0x20, 0x20 },
+	{ "ENSELO",		0x40, 0x40 },
+	{ "TEMODE",		0x80, 0x80 }
+};
+
+int
+ahc_scsiseq_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SCSISEQ_parse_table, 8, "SCSISEQ",
+	    0x00, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SXFRCTL0_parse_table[] = {
+	{ "CLRCHN",		0x02, 0x02 },
+	{ "SCAMEN",		0x04, 0x04 },
+	{ "SPIOEN",		0x08, 0x08 },
+	{ "CLRSTCNT",		0x10, 0x10 },
+	{ "FAST20",		0x20, 0x20 },
+	{ "DFPEXP",		0x40, 0x40 },
+	{ "DFON",		0x80, 0x80 }
+};
+
+int
+ahc_sxfrctl0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SXFRCTL0_parse_table, 7, "SXFRCTL0",
+	    0x01, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SXFRCTL1_parse_table[] = {
+	{ "STPWEN",		0x01, 0x01 },
+	{ "ACTNEGEN",		0x02, 0x02 },
+	{ "ENSTIMER",		0x04, 0x04 },
+	{ "ENSPCHK",		0x20, 0x20 },
+	{ "SWRAPEN",		0x40, 0x40 },
+	{ "BITBUCKET",		0x80, 0x80 },
+	{ "STIMESEL",		0x18, 0x18 }
+};
+
+int
+ahc_sxfrctl1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SXFRCTL1_parse_table, 7, "SXFRCTL1",
+	    0x02, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SCSISIGO_parse_table[] = {
+	{ "ACKO",		0x01, 0x01 },
+	{ "REQO",		0x02, 0x02 },
+	{ "BSYO",		0x04, 0x04 },
+	{ "SELO",		0x08, 0x08 },
+	{ "ATNO",		0x10, 0x10 },
+	{ "MSGO",		0x20, 0x20 },
+	{ "IOO",		0x40, 0x40 },
+	{ "CDO",		0x80, 0x80 },
+	{ "P_DATAOUT",		0x00, 0x00 },
+	{ "P_DATAIN",		0x40, 0x40 },
+	{ "P_COMMAND",		0x80, 0x80 },
+	{ "P_MESGOUT",		0xa0, 0xa0 },
+	{ "P_STATUS",		0xc0, 0xc0 },
+	{ "PHASE_MASK",		0xe0, 0xe0 },
+	{ "P_MESGIN",		0xe0, 0xe0 }
+};
+
+int
+ahc_scsisigo_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SCSISIGO_parse_table, 15, "SCSISIGO",
+	    0x03, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SCSISIGI_parse_table[] = {
+	{ "ACKI",		0x01, 0x01 },
+	{ "REQI",		0x02, 0x02 },
+	{ "BSYI",		0x04, 0x04 },
+	{ "SELI",		0x08, 0x08 },
+	{ "ATNI",		0x10, 0x10 },
+	{ "MSGI",		0x20, 0x20 },
+	{ "IOI",		0x40, 0x40 },
+	{ "CDI",		0x80, 0x80 },
+	{ "P_DATAOUT",		0x00, 0x00 },
+	{ "P_DATAOUT_DT",	0x20, 0x20 },
+	{ "P_DATAIN",		0x40, 0x40 },
+	{ "P_DATAIN_DT",	0x60, 0x60 },
+	{ "P_COMMAND",		0x80, 0x80 },
+	{ "P_MESGOUT",		0xa0, 0xa0 },
+	{ "P_STATUS",		0xc0, 0xc0 },
+	{ "PHASE_MASK",		0xe0, 0xe0 },
+	{ "P_MESGIN",		0xe0, 0xe0 }
+};
+
+int
+ahc_scsisigi_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SCSISIGI_parse_table, 17, "SCSISIGI",
+	    0x03, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SCSIRATE_parse_table[] = {
+	{ "SINGLE_EDGE",	0x10, 0x10 },
+	{ "ENABLE_CRC",		0x40, 0x40 },
+	{ "WIDEXFER",		0x80, 0x80 },
+	{ "SXFR_ULTRA2",	0x0f, 0x0f },
+	{ "SOFS",		0x0f, 0x0f },
+	{ "SXFR",		0x70, 0x70 }
+};
+
+int
+ahc_scsirate_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SCSIRATE_parse_table, 6, "SCSIRATE",
+	    0x04, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SCSIID_parse_table[] = {
+	{ "TWIN_CHNLB",		0x80, 0x80 },
+	{ "OID",		0x0f, 0x0f },
+	{ "TWIN_TID",		0x70, 0x70 },
+	{ "SOFS_ULTRA2",	0x7f, 0x7f },
+	{ "TID",		0xf0, 0xf0 }
+};
+
+int
+ahc_scsiid_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SCSIID_parse_table, 5, "SCSIID",
+	    0x05, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scsidatl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCSIDATL",
+	    0x06, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scsidath_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCSIDATH",
+	    0x07, regvalue, cur_col, wrap));
+}
+
+int
+ahc_stcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "STCNT",
+	    0x08, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t OPTIONMODE_parse_table[] = {
+	{ "DIS_MSGIN_DUALEDGE",	0x01, 0x01 },
+	{ "AUTO_MSGOUT_DE",	0x02, 0x02 },
+	{ "SCSIDATL_IMGEN",	0x04, 0x04 },
+	{ "EXPPHASEDIS",	0x08, 0x08 },
+	{ "BUSFREEREV",		0x10, 0x10 },
+	{ "ATNMGMNTEN",		0x20, 0x20 },
+	{ "AUTOACKEN",		0x40, 0x40 },
+	{ "AUTORATEEN",		0x80, 0x80 },
+	{ "OPTIONMODE_DEFAULTS",0x03, 0x03 }
+};
+
+int
+ahc_optionmode_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(OPTIONMODE_parse_table, 9, "OPTIONMODE",
+	    0x08, regvalue, cur_col, wrap));
+}
+
+int
+ahc_targcrccnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "TARGCRCCNT",
+	    0x0a, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t CLRSINT0_parse_table[] = {
+	{ "CLRSPIORDY",		0x02, 0x02 },
+	{ "CLRSWRAP",		0x08, 0x08 },
+	{ "CLRIOERR",		0x08, 0x08 },
+	{ "CLRSELINGO",		0x10, 0x10 },
+	{ "CLRSELDI",		0x20, 0x20 },
+	{ "CLRSELDO",		0x40, 0x40 }
+};
+
+int
+ahc_clrsint0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(CLRSINT0_parse_table, 6, "CLRSINT0",
+	    0x0b, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SSTAT0_parse_table[] = {
+	{ "DMADONE",		0x01, 0x01 },
+	{ "SPIORDY",		0x02, 0x02 },
+	{ "SDONE",		0x04, 0x04 },
+	{ "SWRAP",		0x08, 0x08 },
+	{ "IOERR",		0x08, 0x08 },
+	{ "SELINGO",		0x10, 0x10 },
+	{ "SELDI",		0x20, 0x20 },
+	{ "SELDO",		0x40, 0x40 },
+	{ "TARGET",		0x80, 0x80 }
+};
+
+int
+ahc_sstat0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SSTAT0_parse_table, 9, "SSTAT0",
+	    0x0b, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t CLRSINT1_parse_table[] = {
+	{ "CLRREQINIT",		0x01, 0x01 },
+	{ "CLRPHASECHG",	0x02, 0x02 },
+	{ "CLRSCSIPERR",	0x04, 0x04 },
+	{ "CLRBUSFREE",		0x08, 0x08 },
+	{ "CLRSCSIRSTI",	0x20, 0x20 },
+	{ "CLRATNO",		0x40, 0x40 },
+	{ "CLRSELTIMEO",	0x80, 0x80 }
+};
+
+int
+ahc_clrsint1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(CLRSINT1_parse_table, 7, "CLRSINT1",
+	    0x0c, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SSTAT1_parse_table[] = {
+	{ "REQINIT",		0x01, 0x01 },
+	{ "PHASECHG",		0x02, 0x02 },
+	{ "SCSIPERR",		0x04, 0x04 },
+	{ "BUSFREE",		0x08, 0x08 },
+	{ "PHASEMIS",		0x10, 0x10 },
+	{ "SCSIRSTI",		0x20, 0x20 },
+	{ "ATNTARG",		0x40, 0x40 },
+	{ "SELTO",		0x80, 0x80 }
+};
+
+int
+ahc_sstat1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SSTAT1_parse_table, 8, "SSTAT1",
+	    0x0c, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SSTAT2_parse_table[] = {
+	{ "DUAL_EDGE_ERR",	0x01, 0x01 },
+	{ "CRCREQERR",		0x02, 0x02 },
+	{ "CRCENDERR",		0x04, 0x04 },
+	{ "CRCVALERR",		0x08, 0x08 },
+	{ "EXP_ACTIVE",		0x10, 0x10 },
+	{ "SHVALID",		0x40, 0x40 },
+	{ "OVERRUN",		0x80, 0x80 },
+	{ "SFCNT",		0x1f, 0x1f }
+};
+
+int
+ahc_sstat2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SSTAT2_parse_table, 8, "SSTAT2",
+	    0x0d, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SSTAT3_parse_table[] = {
+	{ "OFFCNT",		0x0f, 0x0f },
+	{ "U2OFFCNT",		0x7f, 0x7f },
+	{ "SCSICNT",		0xf0, 0xf0 }
+};
+
+int
+ahc_sstat3_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SSTAT3_parse_table, 3, "SSTAT3",
+	    0x0e, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SCSIID_ULTRA2_parse_table[] = {
+	{ "OID",		0x0f, 0x0f },
+	{ "TID",		0xf0, 0xf0 }
+};
+
+int
+ahc_scsiid_ultra2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SCSIID_ULTRA2_parse_table, 2, "SCSIID_ULTRA2",
+	    0x0f, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SIMODE0_parse_table[] = {
+	{ "ENDMADONE",		0x01, 0x01 },
+	{ "ENSPIORDY",		0x02, 0x02 },
+	{ "ENSDONE",		0x04, 0x04 },
+	{ "ENSWRAP",		0x08, 0x08 },
+	{ "ENIOERR",		0x08, 0x08 },
+	{ "ENSELINGO",		0x10, 0x10 },
+	{ "ENSELDI",		0x20, 0x20 },
+	{ "ENSELDO",		0x40, 0x40 }
+};
+
+int
+ahc_simode0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SIMODE0_parse_table, 8, "SIMODE0",
+	    0x10, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SIMODE1_parse_table[] = {
+	{ "ENREQINIT",		0x01, 0x01 },
+	{ "ENPHASECHG",		0x02, 0x02 },
+	{ "ENSCSIPERR",		0x04, 0x04 },
+	{ "ENBUSFREE",		0x08, 0x08 },
+	{ "ENPHASEMIS",		0x10, 0x10 },
+	{ "ENSCSIRST",		0x20, 0x20 },
+	{ "ENATNTARG",		0x40, 0x40 },
+	{ "ENSELTIMO",		0x80, 0x80 }
+};
+
+int
+ahc_simode1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SIMODE1_parse_table, 8, "SIMODE1",
+	    0x11, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scsibusl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCSIBUSL",
+	    0x12, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scsibush_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCSIBUSH",
+	    0x13, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SXFRCTL2_parse_table[] = {
+	{ "CMDDMAEN",		0x08, 0x08 },
+	{ "AUTORSTDIS",		0x10, 0x10 },
+	{ "ASYNC_SETUP",	0x07, 0x07 }
+};
+
+int
+ahc_sxfrctl2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SXFRCTL2_parse_table, 3, "SXFRCTL2",
+	    0x13, regvalue, cur_col, wrap));
+}
+
+int
+ahc_shaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SHADDR",
+	    0x14, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SELTIMER_parse_table[] = {
+	{ "STAGE1",		0x01, 0x01 },
+	{ "STAGE2",		0x02, 0x02 },
+	{ "STAGE3",		0x04, 0x04 },
+	{ "STAGE4",		0x08, 0x08 },
+	{ "STAGE5",		0x10, 0x10 },
+	{ "STAGE6",		0x20, 0x20 }
+};
+
+int
+ahc_seltimer_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SELTIMER_parse_table, 6, "SELTIMER",
+	    0x18, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SELID_parse_table[] = {
+	{ "ONEBIT",		0x08, 0x08 },
+	{ "SELID_MASK",		0xf0, 0xf0 }
+};
+
+int
+ahc_selid_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SELID_parse_table, 2, "SELID",
+	    0x19, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SCAMCTL_parse_table[] = {
+	{ "DFLTTID",		0x10, 0x10 },
+	{ "ALTSTIM",		0x20, 0x20 },
+	{ "CLRSCAMSELID",	0x40, 0x40 },
+	{ "ENSCAMSELO",		0x80, 0x80 },
+	{ "SCAMLVL",		0x03, 0x03 }
+};
+
+int
+ahc_scamctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SCAMCTL_parse_table, 5, "SCAMCTL",
+	    0x1a, regvalue, cur_col, wrap));
+}
+
+int
+ahc_targid_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "TARGID",
+	    0x1b, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SPIOCAP_parse_table[] = {
+	{ "SSPIOCPS",		0x01, 0x01 },
+	{ "ROM",		0x02, 0x02 },
+	{ "EEPROM",		0x04, 0x04 },
+	{ "SEEPROM",		0x08, 0x08 },
+	{ "EXT_BRDCTL",		0x10, 0x10 },
+	{ "SOFTCMDEN",		0x20, 0x20 },
+	{ "SOFT0",		0x40, 0x40 },
+	{ "SOFT1",		0x80, 0x80 }
+};
+
+int
+ahc_spiocap_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SPIOCAP_parse_table, 8, "SPIOCAP",
+	    0x1b, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t BRDCTL_parse_table[] = {
+	{ "BRDCTL0",		0x01, 0x01 },
+	{ "BRDSTB_ULTRA2",	0x01, 0x01 },
+	{ "BRDCTL1",		0x02, 0x02 },
+	{ "BRDRW_ULTRA2",	0x02, 0x02 },
+	{ "BRDRW",		0x04, 0x04 },
+	{ "BRDDAT2",		0x04, 0x04 },
+	{ "BRDCS",		0x08, 0x08 },
+	{ "BRDDAT3",		0x08, 0x08 },
+	{ "BRDSTB",		0x10, 0x10 },
+	{ "BRDDAT4",		0x10, 0x10 },
+	{ "BRDDAT5",		0x20, 0x20 },
+	{ "BRDDAT6",		0x40, 0x40 },
+	{ "BRDDAT7",		0x80, 0x80 }
+};
+
+int
+ahc_brdctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(BRDCTL_parse_table, 13, "BRDCTL",
+	    0x1d, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SEECTL_parse_table[] = {
+	{ "SEEDI",		0x01, 0x01 },
+	{ "SEEDO",		0x02, 0x02 },
+	{ "SEECK",		0x04, 0x04 },
+	{ "SEECS",		0x08, 0x08 },
+	{ "SEERDY",		0x10, 0x10 },
+	{ "SEEMS",		0x20, 0x20 },
+	{ "EXTARBREQ",		0x40, 0x40 },
+	{ "EXTARBACK",		0x80, 0x80 }
+};
+
+int
+ahc_seectl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SEECTL_parse_table, 8, "SEECTL",
+	    0x1e, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SBLKCTL_parse_table[] = {
+	{ "XCVR",		0x01, 0x01 },
+	{ "SELWIDE",		0x02, 0x02 },
+	{ "ENAB20",		0x04, 0x04 },
+	{ "SELBUSB",		0x08, 0x08 },
+	{ "ENAB40",		0x08, 0x08 },
+	{ "AUTOFLUSHDIS",	0x20, 0x20 },
+	{ "DIAGLEDON",		0x40, 0x40 },
+	{ "DIAGLEDEN",		0x80, 0x80 }
+};
+
+int
+ahc_sblkctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SBLKCTL_parse_table, 8, "SBLKCTL",
+	    0x1f, regvalue, cur_col, wrap));
+}
+
+int
+ahc_busy_targets_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "BUSY_TARGETS",
+	    0x20, regvalue, cur_col, wrap));
+}
+
+int
+ahc_ultra_enb_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "ULTRA_ENB",
+	    0x30, regvalue, cur_col, wrap));
+}
+
+int
+ahc_disc_dsb_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "DISC_DSB",
+	    0x32, regvalue, cur_col, wrap));
+}
+
+int
+ahc_cmdsize_table_tail_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "CMDSIZE_TABLE_TAIL",
+	    0x34, regvalue, cur_col, wrap));
+}
+
+int
+ahc_mwi_residual_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "MWI_RESIDUAL",
+	    0x38, regvalue, cur_col, wrap));
+}
+
+int
+ahc_next_queued_scb_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "NEXT_QUEUED_SCB",
+	    0x39, regvalue, cur_col, wrap));
+}
+
+int
+ahc_msg_out_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "MSG_OUT",
+	    0x3a, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t DMAPARAMS_parse_table[] = {
+	{ "FIFORESET",		0x01, 0x01 },
+	{ "FIFOFLUSH",		0x02, 0x02 },
+	{ "DIRECTION",		0x04, 0x04 },
+	{ "HDMAEN",		0x08, 0x08 },
+	{ "HDMAENACK",		0x08, 0x08 },
+	{ "SDMAEN",		0x10, 0x10 },
+	{ "SDMAENACK",		0x10, 0x10 },
+	{ "SCSIEN",		0x20, 0x20 },
+	{ "WIDEODD",		0x40, 0x40 },
+	{ "PRELOADEN",		0x80, 0x80 }
+};
+
+int
+ahc_dmaparams_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(DMAPARAMS_parse_table, 10, "DMAPARAMS",
+	    0x3b, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SEQ_FLAGS_parse_table[] = {
+	{ "NO_DISCONNECT",	0x01, 0x01 },
+	{ "SPHASE_PENDING",	0x02, 0x02 },
+	{ "DPHASE_PENDING",	0x04, 0x04 },
+	{ "CMDPHASE_PENDING",	0x08, 0x08 },
+	{ "TARG_CMD_PENDING",	0x10, 0x10 },
+	{ "DPHASE",		0x20, 0x20 },
+	{ "NO_CDB_SENT",	0x40, 0x40 },
+	{ "TARGET_CMD_IS_TAGGED",0x40, 0x40 },
+	{ "NOT_IDENTIFIED",	0x80, 0x80 }
+};
+
+int
+ahc_seq_flags_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SEQ_FLAGS_parse_table, 9, "SEQ_FLAGS",
+	    0x3c, regvalue, cur_col, wrap));
+}
+
+int
+ahc_saved_scsiid_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SAVED_SCSIID",
+	    0x3d, regvalue, cur_col, wrap));
+}
+
+int
+ahc_saved_lun_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SAVED_LUN",
+	    0x3e, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t LASTPHASE_parse_table[] = {
+	{ "MSGI",		0x20, 0x20 },
+	{ "IOI",		0x40, 0x40 },
+	{ "CDI",		0x80, 0x80 },
+	{ "P_DATAOUT",		0x00, 0x00 },
+	{ "P_BUSFREE",		0x01, 0x01 },
+	{ "P_DATAIN",		0x40, 0x40 },
+	{ "P_COMMAND",		0x80, 0x80 },
+	{ "P_MESGOUT",		0xa0, 0xa0 },
+	{ "P_STATUS",		0xc0, 0xc0 },
+	{ "PHASE_MASK",		0xe0, 0xe0 },
+	{ "P_MESGIN",		0xe0, 0xe0 }
+};
+
+int
+ahc_lastphase_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(LASTPHASE_parse_table, 11, "LASTPHASE",
+	    0x3f, regvalue, cur_col, wrap));
+}
+
+int
+ahc_waiting_scbh_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "WAITING_SCBH",
+	    0x40, regvalue, cur_col, wrap));
+}
+
+int
+ahc_disconnected_scbh_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "DISCONNECTED_SCBH",
+	    0x41, regvalue, cur_col, wrap));
+}
+
+int
+ahc_free_scbh_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "FREE_SCBH",
+	    0x42, regvalue, cur_col, wrap));
+}
+
+int
+ahc_complete_scbh_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "COMPLETE_SCBH",
+	    0x43, regvalue, cur_col, wrap));
+}
+
+int
+ahc_hscb_addr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "HSCB_ADDR",
+	    0x44, regvalue, cur_col, wrap));
+}
+
+int
+ahc_shared_data_addr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SHARED_DATA_ADDR",
+	    0x48, regvalue, cur_col, wrap));
+}
+
+int
+ahc_kernel_qinpos_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "KERNEL_QINPOS",
+	    0x4c, regvalue, cur_col, wrap));
+}
+
+int
+ahc_qinpos_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "QINPOS",
+	    0x4d, regvalue, cur_col, wrap));
+}
+
+int
+ahc_qoutpos_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "QOUTPOS",
+	    0x4e, regvalue, cur_col, wrap));
+}
+
+int
+ahc_kernel_tqinpos_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "KERNEL_TQINPOS",
+	    0x4f, regvalue, cur_col, wrap));
+}
+
+int
+ahc_tqinpos_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "TQINPOS",
+	    0x50, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t ARG_1_parse_table[] = {
+	{ "CONT_TARG_SESSION",	0x02, 0x02 },
+	{ "CONT_MSG_LOOP",	0x04, 0x04 },
+	{ "EXIT_MSG_LOOP",	0x08, 0x08 },
+	{ "MSGOUT_PHASEMIS",	0x10, 0x10 },
+	{ "SEND_REJ",		0x20, 0x20 },
+	{ "SEND_SENSE",		0x40, 0x40 },
+	{ "SEND_MSG",		0x80, 0x80 }
+};
+
+int
+ahc_arg_1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(ARG_1_parse_table, 7, "ARG_1",
+	    0x51, regvalue, cur_col, wrap));
+}
+
+int
+ahc_arg_2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "ARG_2",
+	    0x52, regvalue, cur_col, wrap));
+}
+
+int
+ahc_last_msg_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "LAST_MSG",
+	    0x53, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SCSISEQ_TEMPLATE_parse_table[] = {
+	{ "ENAUTOATNP",		0x02, 0x02 },
+	{ "ENAUTOATNI",		0x04, 0x04 },
+	{ "ENAUTOATNO",		0x08, 0x08 },
+	{ "ENRSELI",		0x10, 0x10 },
+	{ "ENSELI",		0x20, 0x20 },
+	{ "ENSELO",		0x40, 0x40 }
+};
+
+int
+ahc_scsiseq_template_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SCSISEQ_TEMPLATE_parse_table, 6, "SCSISEQ_TEMPLATE",
+	    0x54, regvalue, cur_col, wrap));
+}
+
+int
+ahc_data_count_odd_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "DATA_COUNT_ODD",
+	    0x55, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t HA_274_BIOSGLOBAL_parse_table[] = {
+	{ "HA_274_EXTENDED_TRANS",0x01, 0x01 }
+};
+
+int
+ahc_ha_274_biosglobal_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(HA_274_BIOSGLOBAL_parse_table, 1, "HA_274_BIOSGLOBAL",
+	    0x56, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SEQ_FLAGS2_parse_table[] = {
+	{ "SCB_DMA",		0x01, 0x01 },
+	{ "TARGET_MSG_PENDING",	0x02, 0x02 }
+};
+
+int
+ahc_seq_flags2_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SEQ_FLAGS2_parse_table, 2, "SEQ_FLAGS2",
+	    0x57, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SCSICONF_parse_table[] = {
+	{ "ENSPCHK",		0x20, 0x20 },
+	{ "RESET_SCSI",		0x40, 0x40 },
+	{ "TERM_ENB",		0x80, 0x80 },
+	{ "HSCSIID",		0x07, 0x07 },
+	{ "HWSCSIID",		0x0f, 0x0f }
+};
+
+int
+ahc_scsiconf_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SCSICONF_parse_table, 5, "SCSICONF",
+	    0x5a, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t INTDEF_parse_table[] = {
+	{ "EDGE_TRIG",		0x80, 0x80 },
+	{ "VECTOR",		0x0f, 0x0f }
+};
+
+int
+ahc_intdef_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(INTDEF_parse_table, 2, "INTDEF",
+	    0x5c, regvalue, cur_col, wrap));
+}
+
+int
+ahc_hostconf_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "HOSTCONF",
+	    0x5d, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t HA_274_BIOSCTRL_parse_table[] = {
+	{ "CHANNEL_B_PRIMARY",	0x08, 0x08 },
+	{ "BIOSMODE",		0x30, 0x30 },
+	{ "BIOSDISABLED",	0x30, 0x30 }
+};
+
+int
+ahc_ha_274_biosctrl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(HA_274_BIOSCTRL_parse_table, 3, "HA_274_BIOSCTRL",
+	    0x5f, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SEQCTL_parse_table[] = {
+	{ "LOADRAM",		0x01, 0x01 },
+	{ "SEQRESET",		0x02, 0x02 },
+	{ "STEP",		0x04, 0x04 },
+	{ "BRKADRINTEN",	0x08, 0x08 },
+	{ "FASTMODE",		0x10, 0x10 },
+	{ "FAILDIS",		0x20, 0x20 },
+	{ "PAUSEDIS",		0x40, 0x40 },
+	{ "PERRORDIS",		0x80, 0x80 }
+};
+
+int
+ahc_seqctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SEQCTL_parse_table, 8, "SEQCTL",
+	    0x60, regvalue, cur_col, wrap));
+}
+
+int
+ahc_seqram_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SEQRAM",
+	    0x61, regvalue, cur_col, wrap));
+}
+
+int
+ahc_seqaddr0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SEQADDR0",
+	    0x62, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SEQADDR1_parse_table[] = {
+	{ "SEQADDR1_MASK",	0x01, 0x01 }
+};
+
+int
+ahc_seqaddr1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SEQADDR1_parse_table, 1, "SEQADDR1",
+	    0x63, regvalue, cur_col, wrap));
+}
+
+int
+ahc_accum_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "ACCUM",
+	    0x64, regvalue, cur_col, wrap));
+}
+
+int
+ahc_sindex_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SINDEX",
+	    0x65, regvalue, cur_col, wrap));
+}
+
+int
+ahc_dindex_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "DINDEX",
+	    0x66, regvalue, cur_col, wrap));
+}
+
+int
+ahc_allones_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "ALLONES",
+	    0x69, regvalue, cur_col, wrap));
+}
+
+int
+ahc_allzeros_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "ALLZEROS",
+	    0x6a, regvalue, cur_col, wrap));
+}
+
+int
+ahc_none_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "NONE",
+	    0x6a, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t FLAGS_parse_table[] = {
+	{ "CARRY",		0x01, 0x01 },
+	{ "ZERO",		0x02, 0x02 }
+};
+
+int
+ahc_flags_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(FLAGS_parse_table, 2, "FLAGS",
+	    0x6b, regvalue, cur_col, wrap));
+}
+
+int
+ahc_sindir_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SINDIR",
+	    0x6c, regvalue, cur_col, wrap));
+}
+
+int
+ahc_dindir_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "DINDIR",
+	    0x6d, regvalue, cur_col, wrap));
+}
+
+int
+ahc_function1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "FUNCTION1",
+	    0x6e, regvalue, cur_col, wrap));
+}
+
+int
+ahc_stack_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "STACK",
+	    0x6f, regvalue, cur_col, wrap));
+}
+
+int
+ahc_targ_offset_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "TARG_OFFSET",
+	    0x70, regvalue, cur_col, wrap));
+}
+
+int
+ahc_sram_base_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SRAM_BASE",
+	    0x70, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t BCTL_parse_table[] = {
+	{ "ENABLE",		0x01, 0x01 },
+	{ "ACE",		0x08, 0x08 }
+};
+
+int
+ahc_bctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(BCTL_parse_table, 2, "BCTL",
+	    0x84, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t DSCOMMAND0_parse_table[] = {
+	{ "CIOPARCKEN",		0x01, 0x01 },
+	{ "USCBSIZE32",		0x02, 0x02 },
+	{ "RAMPS",		0x04, 0x04 },
+	{ "INTSCBRAMSEL",	0x08, 0x08 },
+	{ "EXTREQLCK",		0x10, 0x10 },
+	{ "MPARCKEN",		0x20, 0x20 },
+	{ "DPARCKEN",		0x40, 0x40 },
+	{ "CACHETHEN",		0x80, 0x80 }
+};
+
+int
+ahc_dscommand0_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(DSCOMMAND0_parse_table, 8, "DSCOMMAND0",
+	    0x84, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t BUSTIME_parse_table[] = {
+	{ "BON",		0x0f, 0x0f },
+	{ "BOFF",		0xf0, 0xf0 }
+};
+
+int
+ahc_bustime_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(BUSTIME_parse_table, 2, "BUSTIME",
+	    0x85, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t DSCOMMAND1_parse_table[] = {
+	{ "HADDLDSEL0",		0x01, 0x01 },
+	{ "HADDLDSEL1",		0x02, 0x02 },
+	{ "DSLATT",		0xfc, 0xfc }
+};
+
+int
+ahc_dscommand1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(DSCOMMAND1_parse_table, 3, "DSCOMMAND1",
+	    0x85, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t BUSSPD_parse_table[] = {
+	{ "STBON",		0x07, 0x07 },
+	{ "STBOFF",		0x38, 0x38 },
+	{ "DFTHRSH_75",		0x80, 0x80 },
+	{ "DFTHRSH",		0xc0, 0xc0 },
+	{ "DFTHRSH_100",	0xc0, 0xc0 }
+};
+
+int
+ahc_busspd_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(BUSSPD_parse_table, 5, "BUSSPD",
+	    0x86, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t HS_MAILBOX_parse_table[] = {
+	{ "SEQ_MAILBOX",	0x0f, 0x0f },
+	{ "HOST_TQINPOS",	0x80, 0x80 },
+	{ "HOST_MAILBOX",	0xf0, 0xf0 }
+};
+
+int
+ahc_hs_mailbox_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(HS_MAILBOX_parse_table, 3, "HS_MAILBOX",
+	    0x86, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t DSPCISTATUS_parse_table[] = {
+	{ "DFTHRSH_100",	0xc0, 0xc0 }
+};
+
+int
+ahc_dspcistatus_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(DSPCISTATUS_parse_table, 1, "DSPCISTATUS",
+	    0x86, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t HCNTRL_parse_table[] = {
+	{ "CHIPRST",		0x01, 0x01 },
+	{ "CHIPRSTACK",		0x01, 0x01 },
+	{ "INTEN",		0x02, 0x02 },
+	{ "PAUSE",		0x04, 0x04 },
+	{ "IRQMS",		0x08, 0x08 },
+	{ "SWINT",		0x10, 0x10 },
+	{ "POWRDN",		0x40, 0x40 }
+};
+
+int
+ahc_hcntrl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(HCNTRL_parse_table, 7, "HCNTRL",
+	    0x87, regvalue, cur_col, wrap));
+}
+
+int
+ahc_haddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "HADDR",
+	    0x88, regvalue, cur_col, wrap));
+}
+
+int
+ahc_hcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "HCNT",
+	    0x8c, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scbptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCBPTR",
+	    0x90, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t INTSTAT_parse_table[] = {
+	{ "SEQINT",		0x01, 0x01 },
+	{ "CMDCMPLT",		0x02, 0x02 },
+	{ "SCSIINT",		0x04, 0x04 },
+	{ "BRKADRINT",		0x08, 0x08 },
+	{ "BAD_PHASE",		0x01, 0x01 },
+	{ "INT_PEND",		0x0f, 0x0f },
+	{ "SEND_REJECT",	0x11, 0x11 },
+	{ "PROTO_VIOLATION",	0x21, 0x21 },
+	{ "NO_MATCH",		0x31, 0x31 },
+	{ "IGN_WIDE_RES",	0x41, 0x41 },
+	{ "PDATA_REINIT",	0x51, 0x51 },
+	{ "HOST_MSG_LOOP",	0x61, 0x61 },
+	{ "BAD_STATUS",		0x71, 0x71 },
+	{ "PERR_DETECTED",	0x81, 0x81 },
+	{ "DATA_OVERRUN",	0x91, 0x91 },
+	{ "MKMSG_FAILED",	0xa1, 0xa1 },
+	{ "MISSED_BUSFREE",	0xb1, 0xb1 },
+	{ "SCB_MISMATCH",	0xc1, 0xc1 },
+	{ "NO_FREE_SCB",	0xd1, 0xd1 },
+	{ "OUT_OF_RANGE",	0xe1, 0xe1 },
+	{ "SEQINT_MASK",	0xf1, 0xf1 }
+};
+
+int
+ahc_intstat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(INTSTAT_parse_table, 21, "INTSTAT",
+	    0x91, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t CLRINT_parse_table[] = {
+	{ "CLRSEQINT",		0x01, 0x01 },
+	{ "CLRCMDINT",		0x02, 0x02 },
+	{ "CLRSCSIINT",		0x04, 0x04 },
+	{ "CLRBRKADRINT",	0x08, 0x08 },
+	{ "CLRPARERR",		0x10, 0x10 }
+};
+
+int
+ahc_clrint_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(CLRINT_parse_table, 5, "CLRINT",
+	    0x92, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t ERROR_parse_table[] = {
+	{ "ILLHADDR",		0x01, 0x01 },
+	{ "ILLSADDR",		0x02, 0x02 },
+	{ "ILLOPCODE",		0x04, 0x04 },
+	{ "SQPARERR",		0x08, 0x08 },
+	{ "DPARERR",		0x10, 0x10 },
+	{ "MPARERR",		0x20, 0x20 },
+	{ "PCIERRSTAT",		0x40, 0x40 },
+	{ "CIOPARERR",		0x80, 0x80 }
+};
+
+int
+ahc_error_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(ERROR_parse_table, 8, "ERROR",
+	    0x92, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t DFCNTRL_parse_table[] = {
+	{ "FIFORESET",		0x01, 0x01 },
+	{ "FIFOFLUSH",		0x02, 0x02 },
+	{ "DIRECTION",		0x04, 0x04 },
+	{ "HDMAEN",		0x08, 0x08 },
+	{ "HDMAENACK",		0x08, 0x08 },
+	{ "SDMAEN",		0x10, 0x10 },
+	{ "SDMAENACK",		0x10, 0x10 },
+	{ "SCSIEN",		0x20, 0x20 },
+	{ "WIDEODD",		0x40, 0x40 },
+	{ "PRELOADEN",		0x80, 0x80 }
+};
+
+int
+ahc_dfcntrl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(DFCNTRL_parse_table, 10, "DFCNTRL",
+	    0x93, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t DFSTATUS_parse_table[] = {
+	{ "FIFOEMP",		0x01, 0x01 },
+	{ "FIFOFULL",		0x02, 0x02 },
+	{ "DFTHRESH",		0x04, 0x04 },
+	{ "HDONE",		0x08, 0x08 },
+	{ "MREQPEND",		0x10, 0x10 },
+	{ "FIFOQWDEMP",		0x20, 0x20 },
+	{ "DFCACHETH",		0x40, 0x40 },
+	{ "PRELOAD_AVAIL",	0x80, 0x80 }
+};
+
+int
+ahc_dfstatus_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(DFSTATUS_parse_table, 8, "DFSTATUS",
+	    0x94, regvalue, cur_col, wrap));
+}
+
+int
+ahc_dfwaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "DFWADDR",
+	    0x95, regvalue, cur_col, wrap));
+}
+
+int
+ahc_dfraddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "DFRADDR",
+	    0x97, regvalue, cur_col, wrap));
+}
+
+int
+ahc_dfdat_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "DFDAT",
+	    0x99, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SCBCNT_parse_table[] = {
+	{ "SCBAUTO",		0x80, 0x80 },
+	{ "SCBCNT_MASK",	0x1f, 0x1f }
+};
+
+int
+ahc_scbcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SCBCNT_parse_table, 2, "SCBCNT",
+	    0x9a, regvalue, cur_col, wrap));
+}
+
+int
+ahc_qinfifo_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "QINFIFO",
+	    0x9b, regvalue, cur_col, wrap));
+}
+
+int
+ahc_qincnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "QINCNT",
+	    0x9c, regvalue, cur_col, wrap));
+}
+
+int
+ahc_qoutfifo_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "QOUTFIFO",
+	    0x9d, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t CRCCONTROL1_parse_table[] = {
+	{ "TARGCRCCNTEN",	0x04, 0x04 },
+	{ "TARGCRCENDEN",	0x08, 0x08 },
+	{ "CRCREQCHKEN",	0x10, 0x10 },
+	{ "CRCENDCHKEN",	0x20, 0x20 },
+	{ "CRCVALCHKEN",	0x40, 0x40 },
+	{ "CRCONSEEN",		0x80, 0x80 }
+};
+
+int
+ahc_crccontrol1_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(CRCCONTROL1_parse_table, 6, "CRCCONTROL1",
+	    0x9d, regvalue, cur_col, wrap));
+}
+
+int
+ahc_qoutcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "QOUTCNT",
+	    0x9e, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SCSIPHASE_parse_table[] = {
+	{ "DATA_OUT_PHASE",	0x01, 0x01 },
+	{ "DATA_IN_PHASE",	0x02, 0x02 },
+	{ "MSG_OUT_PHASE",	0x04, 0x04 },
+	{ "MSG_IN_PHASE",	0x08, 0x08 },
+	{ "COMMAND_PHASE",	0x10, 0x10 },
+	{ "STATUS_PHASE",	0x20, 0x20 },
+	{ "DATA_PHASE_MASK",	0x03, 0x03 }
+};
+
+int
+ahc_scsiphase_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SCSIPHASE_parse_table, 7, "SCSIPHASE",
+	    0x9e, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SFUNCT_parse_table[] = {
+	{ "ALT_MODE",		0x80, 0x80 }
+};
+
+int
+ahc_sfunct_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SFUNCT_parse_table, 1, "SFUNCT",
+	    0x9f, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scb_base_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCB_BASE",
+	    0xa0, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scb_cdb_ptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCB_CDB_PTR",
+	    0xa0, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scb_residual_sgptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCB_RESIDUAL_SGPTR",
+	    0xa4, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scb_scsi_status_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCB_SCSI_STATUS",
+	    0xa8, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scb_target_phases_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCB_TARGET_PHASES",
+	    0xa9, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scb_target_data_dir_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCB_TARGET_DATA_DIR",
+	    0xaa, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scb_target_itag_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCB_TARGET_ITAG",
+	    0xab, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scb_dataptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCB_DATAPTR",
+	    0xac, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SCB_DATACNT_parse_table[] = {
+	{ "SG_LAST_SEG",	0x80, 0x80 },
+	{ "SG_HIGH_ADDR_BITS",	0x7f, 0x7f }
+};
+
+int
+ahc_scb_datacnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SCB_DATACNT_parse_table, 2, "SCB_DATACNT",
+	    0xb0, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SCB_SGPTR_parse_table[] = {
+	{ "SG_LIST_NULL",	0x01, 0x01 },
+	{ "SG_FULL_RESID",	0x02, 0x02 },
+	{ "SG_RESID_VALID",	0x04, 0x04 }
+};
+
+int
+ahc_scb_sgptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SCB_SGPTR_parse_table, 3, "SCB_SGPTR",
+	    0xb4, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SCB_CONTROL_parse_table[] = {
+	{ "DISCONNECTED",	0x04, 0x04 },
+	{ "ULTRAENB",		0x08, 0x08 },
+	{ "MK_MESSAGE",		0x10, 0x10 },
+	{ "TAG_ENB",		0x20, 0x20 },
+	{ "DISCENB",		0x40, 0x40 },
+	{ "TARGET_SCB",		0x80, 0x80 },
+	{ "STATUS_RCVD",	0x80, 0x80 },
+	{ "SCB_TAG_TYPE",	0x03, 0x03 }
+};
+
+int
+ahc_scb_control_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SCB_CONTROL_parse_table, 8, "SCB_CONTROL",
+	    0xb8, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SCB_SCSIID_parse_table[] = {
+	{ "TWIN_CHNLB",		0x80, 0x80 },
+	{ "OID",		0x0f, 0x0f },
+	{ "TWIN_TID",		0x70, 0x70 },
+	{ "TID",		0xf0, 0xf0 }
+};
+
+int
+ahc_scb_scsiid_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SCB_SCSIID_parse_table, 4, "SCB_SCSIID",
+	    0xb9, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SCB_LUN_parse_table[] = {
+	{ "LID",		0xff, 0xff }
+};
+
+int
+ahc_scb_lun_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SCB_LUN_parse_table, 1, "SCB_LUN",
+	    0xba, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scb_tag_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCB_TAG",
+	    0xbb, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scb_cdb_len_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCB_CDB_LEN",
+	    0xbc, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scb_scsirate_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCB_SCSIRATE",
+	    0xbd, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scb_scsioffset_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCB_SCSIOFFSET",
+	    0xbe, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scb_next_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCB_NEXT",
+	    0xbf, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scb_64_spare_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCB_64_SPARE",
+	    0xc0, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SEECTL_2840_parse_table[] = {
+	{ "DO_2840",		0x01, 0x01 },
+	{ "CK_2840",		0x02, 0x02 },
+	{ "CS_2840",		0x04, 0x04 }
+};
+
+int
+ahc_seectl_2840_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SEECTL_2840_parse_table, 3, "SEECTL_2840",
+	    0xc0, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t STATUS_2840_parse_table[] = {
+	{ "DI_2840",		0x01, 0x01 },
+	{ "EEPROM_TF",		0x80, 0x80 },
+	{ "ADSEL",		0x1e, 0x1e },
+	{ "BIOS_SEL",		0x60, 0x60 }
+};
+
+int
+ahc_status_2840_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(STATUS_2840_parse_table, 4, "STATUS_2840",
+	    0xc1, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scb_64_btt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCB_64_BTT",
+	    0xd0, regvalue, cur_col, wrap));
+}
+
+int
+ahc_cchaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "CCHADDR",
+	    0xe0, regvalue, cur_col, wrap));
+}
+
+int
+ahc_cchcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "CCHCNT",
+	    0xe8, regvalue, cur_col, wrap));
+}
+
+int
+ahc_ccsgram_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "CCSGRAM",
+	    0xe9, regvalue, cur_col, wrap));
+}
+
+int
+ahc_ccsgaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "CCSGADDR",
+	    0xea, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t CCSGCTL_parse_table[] = {
+	{ "CCSGRESET",		0x01, 0x01 },
+	{ "SG_FETCH_NEEDED",	0x02, 0x02 },
+	{ "CCSGEN",		0x08, 0x08 },
+	{ "CCSGDONE",		0x80, 0x80 }
+};
+
+int
+ahc_ccsgctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(CCSGCTL_parse_table, 4, "CCSGCTL",
+	    0xeb, regvalue, cur_col, wrap));
+}
+
+int
+ahc_ccscbram_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "CCSCBRAM",
+	    0xec, regvalue, cur_col, wrap));
+}
+
+int
+ahc_ccscbaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "CCSCBADDR",
+	    0xed, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t CCSCBCTL_parse_table[] = {
+	{ "CCSCBRESET",		0x01, 0x01 },
+	{ "CCSCBDIR",		0x04, 0x04 },
+	{ "CCSCBEN",		0x08, 0x08 },
+	{ "CCARREN",		0x10, 0x10 },
+	{ "ARRDONE",		0x40, 0x40 },
+	{ "CCSCBDONE",		0x80, 0x80 }
+};
+
+int
+ahc_ccscbctl_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(CCSCBCTL_parse_table, 6, "CCSCBCTL",
+	    0xee, regvalue, cur_col, wrap));
+}
+
+int
+ahc_ccscbcnt_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "CCSCBCNT",
+	    0xef, regvalue, cur_col, wrap));
+}
+
+int
+ahc_scbbaddr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SCBBADDR",
+	    0xf0, regvalue, cur_col, wrap));
+}
+
+int
+ahc_ccscbptr_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "CCSCBPTR",
+	    0xf1, regvalue, cur_col, wrap));
+}
+
+int
+ahc_hnscb_qoff_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "HNSCB_QOFF",
+	    0xf4, regvalue, cur_col, wrap));
+}
+
+int
+ahc_snscb_qoff_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SNSCB_QOFF",
+	    0xf6, regvalue, cur_col, wrap));
+}
+
+int
+ahc_sdscb_qoff_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(NULL, 0, "SDSCB_QOFF",
+	    0xf8, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t QOFF_CTLSTA_parse_table[] = {
+	{ "SDSCB_ROLLOVER",	0x10, 0x10 },
+	{ "SNSCB_ROLLOVER",	0x20, 0x20 },
+	{ "SCB_AVAIL",		0x40, 0x40 },
+	{ "SCB_QSIZE_256",	0x06, 0x06 },
+	{ "SCB_QSIZE",		0x07, 0x07 }
+};
+
+int
+ahc_qoff_ctlsta_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(QOFF_CTLSTA_parse_table, 5, "QOFF_CTLSTA",
+	    0xfa, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t DFF_THRSH_parse_table[] = {
+	{ "RD_DFTHRSH_MIN",	0x00, 0x00 },
+	{ "WR_DFTHRSH_MIN",	0x00, 0x00 },
+	{ "RD_DFTHRSH_25",	0x01, 0x01 },
+	{ "RD_DFTHRSH_50",	0x02, 0x02 },
+	{ "RD_DFTHRSH_63",	0x03, 0x03 },
+	{ "RD_DFTHRSH_75",	0x04, 0x04 },
+	{ "RD_DFTHRSH_85",	0x05, 0x05 },
+	{ "RD_DFTHRSH_90",	0x06, 0x06 },
+	{ "RD_DFTHRSH",		0x07, 0x07 },
+	{ "RD_DFTHRSH_MAX",	0x07, 0x07 },
+	{ "WR_DFTHRSH_25",	0x10, 0x10 },
+	{ "WR_DFTHRSH_50",	0x20, 0x20 },
+	{ "WR_DFTHRSH_63",	0x30, 0x30 },
+	{ "WR_DFTHRSH_75",	0x40, 0x40 },
+	{ "WR_DFTHRSH_85",	0x50, 0x50 },
+	{ "WR_DFTHRSH_90",	0x60, 0x60 },
+	{ "WR_DFTHRSH",		0x70, 0x70 },
+	{ "WR_DFTHRSH_MAX",	0x70, 0x70 }
+};
+
+int
+ahc_dff_thrsh_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(DFF_THRSH_parse_table, 18, "DFF_THRSH",
+	    0xfb, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SG_CACHE_SHADOW_parse_table[] = {
+	{ "LAST_SEG_DONE",	0x01, 0x01 },
+	{ "LAST_SEG",		0x02, 0x02 },
+	{ "ODD_SEG",		0x04, 0x04 },
+	{ "SG_ADDR_MASK",	0xf8, 0xf8 }
+};
+
+int
+ahc_sg_cache_shadow_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SG_CACHE_SHADOW_parse_table, 4, "SG_CACHE_SHADOW",
+	    0xfc, regvalue, cur_col, wrap));
+}
+
+static ahc_reg_parse_entry_t SG_CACHE_PRE_parse_table[] = {
+	{ "LAST_SEG_DONE",	0x01, 0x01 },
+	{ "LAST_SEG",		0x02, 0x02 },
+	{ "ODD_SEG",		0x04, 0x04 },
+	{ "SG_ADDR_MASK",	0xf8, 0xf8 }
+};
+
+int
+ahc_sg_cache_pre_print(u_int regvalue, u_int *cur_col, u_int wrap)
+{
+	return (ahc_print_register(SG_CACHE_PRE_parse_table, 4, "SG_CACHE_PRE",
+	    0xfc, regvalue, cur_col, wrap));
+}
+
diff -Nru a/drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped b/drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped
--- a/drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped	Mon Dec 23 21:22:03 2002
+++ b/drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped	Mon Dec 23 21:22:03 2002
@@ -2,13 +2,13 @@
  * DO NOT EDIT - This file is automatically generated
  *		 from the following source files:
  *
- * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.seq#37 $
- * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.reg#24 $
+ * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.seq#52 $
+ * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.reg#36 $
  */
 static uint8_t seqprog[] = {
 	0xb2, 0x00, 0x00, 0x08,
 	0xf7, 0x11, 0x22, 0x08,
-	0x00, 0x65, 0xe0, 0x59,
+	0x00, 0x65, 0xea, 0x59,
 	0xf7, 0x01, 0x02, 0x08,
 	0xff, 0x6a, 0x24, 0x08,
 	0x40, 0x00, 0x40, 0x68,
@@ -21,15 +21,15 @@
 	0x01, 0x4d, 0xc8, 0x30,
 	0x00, 0x4c, 0x12, 0x70,
 	0x01, 0x39, 0xa2, 0x30,
-	0x00, 0x6a, 0xb2, 0x5e,
+	0x00, 0x6a, 0xd2, 0x5e,
 	0x01, 0x51, 0x20, 0x31,
 	0x01, 0x57, 0xae, 0x00,
 	0x0d, 0x6a, 0x76, 0x00,
-	0x00, 0x51, 0x04, 0x5e,
+	0x00, 0x51, 0x24, 0x5e,
 	0x01, 0x51, 0xc8, 0x30,
 	0x00, 0x39, 0xc8, 0x60,
 	0x00, 0xbb, 0x30, 0x70,
-	0xc1, 0x6a, 0xca, 0x5e,
+	0xc1, 0x6a, 0xea, 0x5e,
 	0x01, 0xbf, 0x72, 0x30,
 	0x01, 0x40, 0x7e, 0x31,
 	0x01, 0x90, 0x80, 0x30,
@@ -42,17 +42,17 @@
 	0x08, 0x6a, 0x18, 0x00,
 	0x08, 0x11, 0x22, 0x00,
 	0x60, 0x0b, 0x00, 0x78,
-	0x40, 0x0b, 0xfc, 0x68,
+	0x40, 0x0b, 0xfa, 0x68,
 	0x80, 0x0b, 0xb6, 0x78,
 	0x20, 0x6a, 0x16, 0x00,
 	0xa4, 0x6a, 0x06, 0x00,
 	0x08, 0x3c, 0x78, 0x00,
 	0x01, 0x50, 0xc8, 0x30,
 	0xe0, 0x6a, 0xcc, 0x00,
-	0x48, 0x6a, 0xee, 0x5d,
+	0x48, 0x6a, 0x0e, 0x5e,
 	0x01, 0x6a, 0xdc, 0x01,
 	0x88, 0x6a, 0xcc, 0x00,
-	0x48, 0x6a, 0xee, 0x5d,
+	0x48, 0x6a, 0x0e, 0x5e,
 	0x01, 0x6a, 0x26, 0x01,
 	0xf0, 0x19, 0x7a, 0x08,
 	0x0f, 0x18, 0xc8, 0x08,
@@ -63,8 +63,8 @@
 	0x80, 0x3d, 0x7a, 0x00,
 	0x01, 0x3d, 0xd8, 0x31,
 	0x01, 0x3d, 0x32, 0x31,
-	0x10, 0x03, 0x46, 0x79,
-	0x00, 0x65, 0xf4, 0x58,
+	0x10, 0x03, 0x4c, 0x79,
+	0x00, 0x65, 0xf2, 0x58,
 	0x80, 0x66, 0xae, 0x78,
 	0x01, 0x66, 0xd8, 0x31,
 	0x01, 0x66, 0x32, 0x31,
@@ -72,29 +72,29 @@
 	0x40, 0x66, 0x82, 0x68,
 	0x01, 0x3c, 0x78, 0x00,
 	0x10, 0x03, 0x9e, 0x78,
-	0x00, 0x65, 0xf4, 0x58,
+	0x00, 0x65, 0xf2, 0x58,
 	0xe0, 0x66, 0xc8, 0x18,
 	0x00, 0x65, 0xaa, 0x50,
 	0xdd, 0x66, 0xc8, 0x18,
 	0x00, 0x65, 0xaa, 0x48,
 	0x01, 0x66, 0xd8, 0x31,
 	0x01, 0x66, 0x32, 0x31,
-	0x10, 0x03, 0x46, 0x79,
-	0x00, 0x65, 0xf4, 0x58,
+	0x10, 0x03, 0x4c, 0x79,
+	0x00, 0x65, 0xf2, 0x58,
 	0x01, 0x66, 0xd8, 0x31,
 	0x01, 0x66, 0x32, 0x31,
 	0x01, 0x66, 0xac, 0x30,
 	0x40, 0x3c, 0x78, 0x00,
 	0xff, 0x6a, 0xd8, 0x01,
 	0xff, 0x6a, 0x32, 0x01,
-	0x90, 0x3c, 0x78, 0x00,
-	0x02, 0x57, 0x3a, 0x69,
-	0x10, 0x03, 0x38, 0x69,
-	0x00, 0x65, 0x1e, 0x41,
+	0x10, 0x6a, 0x78, 0x00,
+	0x02, 0x57, 0x40, 0x69,
+	0x10, 0x03, 0x3e, 0x69,
+	0x00, 0x65, 0x20, 0x41,
 	0x02, 0x57, 0xae, 0x00,
 	0x00, 0x65, 0x9e, 0x40,
-	0x61, 0x6a, 0xca, 0x5e,
-	0x08, 0x51, 0x1e, 0x71,
+	0x61, 0x6a, 0xea, 0x5e,
+	0x08, 0x51, 0x20, 0x71,
 	0x02, 0x0b, 0xb2, 0x78,
 	0x00, 0x65, 0xae, 0x40,
 	0x1a, 0x01, 0x02, 0x00,
@@ -105,8 +105,8 @@
 	0x08, 0x1f, 0xc4, 0x78,
 	0x80, 0x3d, 0x7a, 0x00,
 	0x20, 0x6a, 0x16, 0x00,
-	0x00, 0x65, 0xc0, 0x41,
-	0x00, 0x65, 0xa4, 0x5e,
+	0x00, 0x65, 0xca, 0x41,
+	0x00, 0x65, 0xc4, 0x5e,
 	0x00, 0x65, 0x12, 0x40,
 	0x20, 0x11, 0xd2, 0x68,
 	0x20, 0x6a, 0x18, 0x00,
@@ -123,168 +123,173 @@
 	0x80, 0x65, 0xca, 0x00,
 	0x01, 0x65, 0x00, 0x34,
 	0x01, 0x54, 0x00, 0x34,
-	0x1a, 0x01, 0x02, 0x00,
-	0x08, 0xb8, 0xf0, 0x78,
+	0x08, 0xb8, 0xee, 0x78,
 	0x20, 0x01, 0x02, 0x00,
 	0x02, 0xbd, 0x08, 0x34,
 	0x01, 0xbd, 0x08, 0x34,
 	0x08, 0x01, 0x02, 0x00,
-	0x02, 0x0b, 0xf6, 0x78,
+	0x02, 0x0b, 0xf4, 0x78,
 	0xf7, 0x01, 0x02, 0x08,
 	0x01, 0x06, 0xcc, 0x34,
 	0xb2, 0x00, 0x00, 0x08,
-	0x40, 0x6a, 0x16, 0x00,
 	0x01, 0x40, 0x20, 0x31,
 	0x01, 0xbf, 0x80, 0x30,
 	0x01, 0xb9, 0x7a, 0x30,
 	0x01, 0xba, 0x7c, 0x30,
 	0x00, 0x65, 0xea, 0x58,
-	0x80, 0x0b, 0xbc, 0x79,
-	0xe4, 0x6a, 0x60, 0x5d,
-	0x80, 0xba, 0x76, 0x5d,
-	0x20, 0xb8, 0x16, 0x79,
-	0x20, 0x6a, 0x76, 0x5d,
-	0x00, 0xab, 0x76, 0x5d,
+	0x80, 0x0b, 0xc2, 0x79,
+	0x12, 0x01, 0x02, 0x00,
+	0x01, 0xab, 0xac, 0x30,
+	0xe4, 0x6a, 0x80, 0x5d,
+	0x40, 0x6a, 0x16, 0x00,
+	0x80, 0xba, 0x96, 0x5d,
+	0x20, 0xb8, 0x18, 0x79,
+	0x20, 0x6a, 0x96, 0x5d,
+	0x00, 0xab, 0x96, 0x5d,
 	0x01, 0xa9, 0x78, 0x30,
-	0x10, 0xb8, 0x1e, 0x79,
-	0xe4, 0x6a, 0x60, 0x5d,
+	0x10, 0xb8, 0x20, 0x79,
+	0xe4, 0x6a, 0x80, 0x5d,
 	0x00, 0x65, 0xae, 0x40,
-	0x10, 0x03, 0x36, 0x69,
-	0x08, 0x3c, 0x52, 0x69,
-	0x04, 0x3c, 0x8a, 0x69,
-	0x02, 0x3c, 0x90, 0x69,
-	0x01, 0x3c, 0x3c, 0x79,
-	0x01, 0x6a, 0xa2, 0x30,
-	0x00, 0x65, 0x9c, 0x59,
-	0x04, 0x51, 0x2c, 0x61,
-	0x00, 0x6a, 0xb2, 0x5e,
+	0x10, 0x03, 0x3c, 0x69,
+	0x08, 0x3c, 0x58, 0x69,
+	0x04, 0x3c, 0x90, 0x69,
+	0x02, 0x3c, 0x96, 0x69,
+	0x01, 0x3c, 0x42, 0x79,
+	0xff, 0x6a, 0x70, 0x00,
+	0x00, 0x65, 0xa2, 0x59,
+	0x00, 0x6a, 0xd2, 0x5e,
+	0xff, 0x38, 0x30, 0x71,
 	0x0d, 0x6a, 0x76, 0x00,
-	0x00, 0xbb, 0x04, 0x5e,
-	0x00, 0x65, 0x16, 0x41,
+	0x00, 0x38, 0x24, 0x5e,
+	0x00, 0x65, 0xea, 0x58,
+	0x12, 0x01, 0x02, 0x00,
+	0x00, 0x65, 0x18, 0x41,
 	0xa4, 0x6a, 0x06, 0x00,
-	0x00, 0x65, 0xf4, 0x58,
+	0x00, 0x65, 0xf2, 0x58,
 	0x00, 0x65, 0xae, 0x40,
-	0xe4, 0x6a, 0x60, 0x5d,
-	0x20, 0x3c, 0x42, 0x79,
-	0x02, 0x6a, 0x76, 0x5d,
-	0x04, 0x6a, 0x76, 0x5d,
-	0x01, 0x03, 0x44, 0x69,
+	0xe4, 0x6a, 0x80, 0x5d,
+	0x20, 0x3c, 0x48, 0x79,
+	0x02, 0x6a, 0x96, 0x5d,
+	0x04, 0x6a, 0x96, 0x5d,
+	0x01, 0x03, 0x4a, 0x69,
 	0xf7, 0x11, 0x22, 0x08,
 	0xff, 0x6a, 0x24, 0x08,
 	0xff, 0x6a, 0x06, 0x08,
 	0x01, 0x6a, 0x7e, 0x00,
-	0x00, 0x65, 0x9c, 0x59,
+	0x00, 0x65, 0xa2, 0x59,
 	0x00, 0x65, 0x04, 0x40,
 	0x80, 0x86, 0xc8, 0x08,
 	0x01, 0x4f, 0xc8, 0x30,
-	0x00, 0x50, 0x64, 0x61,
-	0xc4, 0x6a, 0x60, 0x5d,
-	0x40, 0x3c, 0x60, 0x79,
-	0x28, 0x6a, 0x76, 0x5d,
-	0x00, 0x65, 0x44, 0x41,
-	0x08, 0x6a, 0x76, 0x5d,
-	0x00, 0x65, 0x44, 0x41,
-	0x84, 0x6a, 0x60, 0x5d,
-	0x00, 0x65, 0xf4, 0x58,
+	0x00, 0x50, 0x6a, 0x61,
+	0xc4, 0x6a, 0x80, 0x5d,
+	0x40, 0x3c, 0x66, 0x79,
+	0x28, 0x6a, 0x96, 0x5d,
+	0x00, 0x65, 0x4a, 0x41,
+	0x08, 0x6a, 0x96, 0x5d,
+	0x00, 0x65, 0x4a, 0x41,
+	0x84, 0x6a, 0x80, 0x5d,
+	0x00, 0x65, 0xf2, 0x58,
 	0x01, 0x66, 0xc8, 0x30,
 	0x01, 0x64, 0xd8, 0x31,
 	0x01, 0x64, 0x32, 0x31,
 	0x5b, 0x64, 0xc8, 0x28,
 	0x30, 0x64, 0xca, 0x18,
 	0x01, 0x6c, 0xc8, 0x30,
-	0xff, 0x64, 0x86, 0x79,
+	0xff, 0x64, 0x8c, 0x79,
 	0x08, 0x01, 0x02, 0x00,
-	0x02, 0x0b, 0x78, 0x79,
-	0x01, 0x64, 0x7e, 0x61,
+	0x02, 0x0b, 0x7e, 0x79,
+	0x01, 0x64, 0x84, 0x61,
 	0xf7, 0x01, 0x02, 0x08,
 	0x01, 0x06, 0xd8, 0x31,
 	0x01, 0x06, 0x32, 0x31,
 	0xff, 0x64, 0xc8, 0x18,
-	0xff, 0x64, 0x78, 0x69,
+	0xff, 0x64, 0x7e, 0x69,
 	0xf7, 0x3c, 0x78, 0x08,
-	0x00, 0x65, 0x1e, 0x41,
+	0x00, 0x65, 0x20, 0x41,
 	0x40, 0xaa, 0x7e, 0x10,
-	0x04, 0xaa, 0x60, 0x5d,
-	0x00, 0x65, 0x52, 0x42,
-	0xc4, 0x6a, 0x60, 0x5d,
+	0x04, 0xaa, 0x80, 0x5d,
+	0x00, 0x65, 0x5c, 0x42,
+	0xc4, 0x6a, 0x80, 0x5d,
 	0xc0, 0x6a, 0x7e, 0x00,
-	0x00, 0xa8, 0x76, 0x5d,
+	0x00, 0xa8, 0x96, 0x5d,
 	0xe4, 0x6a, 0x06, 0x00,
-	0x00, 0x6a, 0x76, 0x5d,
-	0x00, 0x65, 0x44, 0x41,
-	0x10, 0x3c, 0xa0, 0x69,
-	0x00, 0xbb, 0x80, 0x44,
+	0x00, 0x6a, 0x96, 0x5d,
+	0x00, 0x65, 0x4a, 0x41,
+	0x10, 0x3c, 0xa6, 0x69,
+	0x00, 0xbb, 0x9c, 0x44,
 	0x18, 0x6a, 0xda, 0x01,
 	0x01, 0x69, 0xd8, 0x31,
 	0x1c, 0x6a, 0xd0, 0x01,
 	0x09, 0xee, 0xdc, 0x01,
-	0x80, 0xee, 0xa8, 0x79,
+	0x80, 0xee, 0xae, 0x79,
 	0xff, 0x6a, 0xdc, 0x09,
 	0x01, 0x93, 0x26, 0x01,
 	0x03, 0x6a, 0x2a, 0x01,
 	0x01, 0x69, 0x32, 0x31,
-	0x1c, 0x6a, 0xd2, 0x5d,
+	0x1c, 0x6a, 0xf2, 0x5d,
 	0x0a, 0x93, 0x26, 0x01,
-	0x00, 0x65, 0x9a, 0x5e,
+	0x00, 0x65, 0xba, 0x5e,
 	0x01, 0x50, 0xa0, 0x18,
 	0x02, 0x6a, 0x22, 0x05,
+	0x1a, 0x01, 0x02, 0x00,
 	0x80, 0x6a, 0x74, 0x00,
-	0x80, 0x3c, 0x78, 0x00,
-	0x00, 0x65, 0xca, 0x5d,
+	0x40, 0x6a, 0x78, 0x00,
+	0x40, 0x6a, 0x16, 0x00,
+	0x00, 0x65, 0xea, 0x5d,
 	0x01, 0x3f, 0xc8, 0x30,
-	0xbf, 0x64, 0x52, 0x7a,
-	0x80, 0x64, 0xa6, 0x73,
-	0xa0, 0x64, 0x04, 0x74,
-	0xc0, 0x64, 0xf8, 0x73,
-	0xe0, 0x64, 0x34, 0x74,
-	0x01, 0x6a, 0xca, 0x5e,
-	0x00, 0x65, 0xc0, 0x41,
+	0xbf, 0x64, 0x5c, 0x7a,
+	0x80, 0x64, 0xb0, 0x73,
+	0xa0, 0x64, 0x12, 0x74,
+	0xc0, 0x64, 0x06, 0x74,
+	0xe0, 0x64, 0x42, 0x74,
+	0x01, 0x6a, 0xea, 0x5e,
+	0x00, 0x65, 0xca, 0x41,
 	0xf7, 0x11, 0x22, 0x08,
 	0x01, 0x06, 0xd4, 0x30,
 	0xff, 0x6a, 0x24, 0x08,
 	0xf7, 0x01, 0x02, 0x08,
-	0x09, 0x0c, 0xda, 0x79,
+	0x09, 0x0c, 0xe4, 0x79,
 	0x08, 0x0c, 0x04, 0x68,
-	0xb1, 0x6a, 0xca, 0x5e,
+	0xb1, 0x6a, 0xea, 0x5e,
 	0xff, 0x6a, 0x26, 0x09,
 	0x12, 0x01, 0x02, 0x00,
 	0x02, 0x6a, 0x08, 0x30,
 	0xff, 0x6a, 0x08, 0x08,
 	0xdf, 0x01, 0x02, 0x08,
 	0x01, 0x6a, 0x7e, 0x00,
-	0xff, 0x6a, 0x78, 0x0c,
+	0xc0, 0x6a, 0x78, 0x04,
 	0xff, 0x6a, 0xc8, 0x08,
 	0x08, 0xa4, 0x48, 0x19,
 	0x00, 0xa5, 0x4a, 0x21,
 	0x00, 0xa6, 0x4c, 0x21,
 	0x00, 0xa7, 0x4e, 0x25,
-	0x08, 0xeb, 0xce, 0x7e,
-	0x80, 0xeb, 0xfa, 0x79,
+	0x08, 0xeb, 0xee, 0x7e,
+	0x80, 0xeb, 0x04, 0x7a,
 	0xff, 0x6a, 0xd6, 0x09,
-	0x08, 0xeb, 0xfe, 0x69,
+	0x08, 0xeb, 0x08, 0x6a,
 	0xff, 0x6a, 0xd4, 0x0c,
-	0x80, 0xa3, 0xce, 0x6e,
-	0x88, 0xeb, 0x14, 0x72,
-	0x08, 0xeb, 0xce, 0x6e,
-	0x04, 0xea, 0x18, 0xe2,
-	0x08, 0xee, 0xce, 0x6e,
+	0x80, 0xa3, 0xee, 0x6e,
+	0x88, 0xeb, 0x1e, 0x72,
+	0x08, 0xeb, 0xee, 0x6e,
+	0x04, 0xea, 0x22, 0xe2,
+	0x08, 0xee, 0xee, 0x6e,
 	0x04, 0x6a, 0xd0, 0x81,
 	0x05, 0xa4, 0xc0, 0x89,
 	0x03, 0xa5, 0xc2, 0x31,
 	0x09, 0x6a, 0xd6, 0x05,
-	0x00, 0x65, 0xfc, 0x59,
+	0x00, 0x65, 0x06, 0x5a,
 	0x06, 0xa4, 0xd4, 0x89,
-	0x80, 0x94, 0xce, 0x7e,
+	0x80, 0x94, 0xee, 0x7e,
 	0x07, 0xe9, 0x10, 0x31,
-	0x01, 0x8c, 0x20, 0x7a,
+	0x01, 0x8c, 0x2a, 0x7a,
 	0x01, 0x55, 0xaa, 0x10,
 	0x01, 0xe9, 0x46, 0x31,
-	0x00, 0xa3, 0xac, 0x5e,
-	0x00, 0x65, 0xee, 0x59,
+	0x00, 0xa3, 0xcc, 0x5e,
+	0x00, 0x65, 0xf8, 0x59,
 	0x01, 0xa4, 0xca, 0x30,
-	0x01, 0x55, 0x2c, 0x7a,
+	0x01, 0x55, 0x36, 0x7a,
 	0x04, 0x65, 0xca, 0x00,
-	0x80, 0xa3, 0x30, 0x7a,
+	0x80, 0xa3, 0x3a, 0x7a,
 	0x02, 0x65, 0xca, 0x00,
 	0x01, 0x65, 0xf8, 0x31,
 	0x80, 0x93, 0x26, 0x01,
@@ -292,168 +297,168 @@
 	0x01, 0x8c, 0xc8, 0x30,
 	0x00, 0x88, 0xc8, 0x18,
 	0x02, 0x64, 0xc8, 0x88,
-	0xff, 0x64, 0xce, 0x7e,
-	0xff, 0x8d, 0x46, 0x6a,
-	0xff, 0x8e, 0x46, 0x6a,
+	0xff, 0x64, 0xee, 0x7e,
+	0xff, 0x8d, 0x50, 0x6a,
+	0xff, 0x8e, 0x50, 0x6a,
 	0x03, 0x8c, 0xd4, 0x98,
-	0x00, 0x65, 0xce, 0x56,
+	0x00, 0x65, 0xee, 0x56,
 	0x01, 0x64, 0x70, 0x30,
 	0xff, 0x64, 0xc8, 0x10,
 	0x01, 0x64, 0xc8, 0x18,
 	0x00, 0x8c, 0x18, 0x19,
 	0xff, 0x8d, 0x1a, 0x21,
 	0xff, 0x8e, 0x1c, 0x25,
-	0x80, 0x3c, 0x56, 0x6a,
-	0x21, 0x6a, 0xca, 0x46,
+	0xc0, 0x3c, 0x60, 0x7a,
+	0x21, 0x6a, 0xea, 0x5e,
 	0xa8, 0x6a, 0x76, 0x00,
 	0x79, 0x6a, 0x76, 0x00,
-	0x40, 0x3f, 0x5e, 0x6a,
+	0x40, 0x3f, 0x68, 0x6a,
 	0x04, 0x3b, 0x76, 0x00,
 	0x04, 0x6a, 0xd4, 0x81,
-	0x20, 0x3c, 0x66, 0x7a,
-	0x51, 0x6a, 0xca, 0x5e,
-	0x00, 0x65, 0x80, 0x42,
+	0x20, 0x3c, 0x70, 0x7a,
+	0x51, 0x6a, 0xea, 0x5e,
+	0x00, 0x65, 0x8a, 0x42,
 	0x20, 0x3c, 0x78, 0x00,
-	0x00, 0xb3, 0xac, 0x5e,
+	0x00, 0xb3, 0xcc, 0x5e,
 	0x07, 0xac, 0x10, 0x31,
 	0x05, 0xb3, 0x46, 0x31,
 	0x88, 0x6a, 0xcc, 0x00,
-	0xac, 0x6a, 0xe0, 0x5d,
+	0xac, 0x6a, 0x00, 0x5e,
 	0xa3, 0x6a, 0xcc, 0x00,
-	0xb3, 0x6a, 0xe4, 0x5d,
-	0x00, 0x65, 0x36, 0x5a,
+	0xb3, 0x6a, 0x04, 0x5e,
+	0x00, 0x65, 0x40, 0x5a,
 	0xfd, 0xa4, 0x48, 0x09,
 	0x01, 0x8c, 0xaa, 0x08,
 	0x03, 0x8c, 0x10, 0x30,
-	0x00, 0x65, 0xd8, 0x5d,
-	0x01, 0xa4, 0x92, 0x7a,
+	0x00, 0x65, 0xf8, 0x5d,
+	0x01, 0xa4, 0x9c, 0x7a,
 	0x04, 0x3b, 0x76, 0x08,
 	0x01, 0x3b, 0x26, 0x31,
 	0x80, 0x02, 0x04, 0x00,
-	0x10, 0x0c, 0x88, 0x7a,
-	0x03, 0x9e, 0x8a, 0x6a,
+	0x10, 0x0c, 0x92, 0x7a,
+	0x03, 0x9e, 0x94, 0x6a,
 	0x7f, 0x02, 0x04, 0x08,
-	0x91, 0x6a, 0xca, 0x5e,
-	0x00, 0x65, 0xc0, 0x41,
+	0x91, 0x6a, 0xea, 0x5e,
+	0x00, 0x65, 0xca, 0x41,
 	0x01, 0xa4, 0xca, 0x30,
-	0x80, 0xa3, 0x98, 0x7a,
+	0x80, 0xa3, 0xa2, 0x7a,
 	0x02, 0x65, 0xca, 0x00,
-	0x01, 0x55, 0x9c, 0x7a,
+	0x01, 0x55, 0xa6, 0x7a,
 	0x04, 0x65, 0xca, 0x00,
 	0x01, 0x65, 0xf8, 0x31,
 	0x01, 0x3b, 0x26, 0x31,
-	0x00, 0x65, 0x02, 0x5a,
-	0x01, 0xfc, 0xaa, 0x6a,
-	0x80, 0x0b, 0xa0, 0x6a,
-	0x10, 0x0c, 0xa0, 0x7a,
-	0x20, 0x93, 0xa0, 0x6a,
+	0x00, 0x65, 0x0c, 0x5a,
+	0x01, 0xfc, 0xb4, 0x6a,
+	0x80, 0x0b, 0xaa, 0x6a,
+	0x10, 0x0c, 0xaa, 0x7a,
+	0x20, 0x93, 0xaa, 0x6a,
 	0x02, 0x93, 0x26, 0x01,
-	0x02, 0xfc, 0xb4, 0x7a,
-	0x40, 0x0d, 0xce, 0x6a,
+	0x02, 0xfc, 0xbe, 0x7a,
+	0x40, 0x0d, 0xd8, 0x6a,
 	0x01, 0xa4, 0x48, 0x01,
-	0x00, 0x65, 0xce, 0x42,
-	0x40, 0x0d, 0xba, 0x6a,
-	0x00, 0x65, 0x02, 0x5a,
-	0x00, 0x65, 0xac, 0x42,
-	0x80, 0xfc, 0xc4, 0x7a,
-	0x80, 0xa4, 0xc4, 0x6a,
+	0x00, 0x65, 0xd8, 0x42,
+	0x40, 0x0d, 0xc4, 0x6a,
+	0x00, 0x65, 0x0c, 0x5a,
+	0x00, 0x65, 0xb6, 0x42,
+	0x80, 0xfc, 0xce, 0x7a,
+	0x80, 0xa4, 0xce, 0x6a,
 	0xff, 0xa5, 0x4a, 0x19,
 	0xff, 0xa6, 0x4c, 0x21,
 	0xff, 0xa7, 0x4e, 0x21,
 	0xf8, 0xfc, 0x48, 0x09,
 	0xff, 0x6a, 0xaa, 0x08,
-	0x04, 0xfc, 0xcc, 0x7a,
+	0x04, 0xfc, 0xd6, 0x7a,
 	0x01, 0x55, 0xaa, 0x00,
 	0xff, 0x6a, 0x46, 0x09,
-	0x04, 0x3b, 0xe6, 0x6a,
+	0x04, 0x3b, 0xf0, 0x6a,
 	0x02, 0x93, 0x26, 0x01,
-	0x01, 0x94, 0xd0, 0x7a,
-	0x01, 0x94, 0xd0, 0x7a,
-	0x01, 0x94, 0xd0, 0x7a,
-	0x01, 0x94, 0xd0, 0x7a,
-	0x01, 0x94, 0xd0, 0x7a,
-	0x01, 0xa4, 0xe4, 0x7a,
-	0x01, 0xfc, 0xde, 0x7a,
-	0x01, 0x94, 0xe6, 0x6a,
-	0x00, 0x65, 0x80, 0x42,
-	0x01, 0x94, 0xe4, 0x7a,
-	0x10, 0x94, 0xe6, 0x6a,
+	0x01, 0x94, 0xda, 0x7a,
+	0x01, 0x94, 0xda, 0x7a,
+	0x01, 0x94, 0xda, 0x7a,
+	0x01, 0x94, 0xda, 0x7a,
+	0x01, 0x94, 0xda, 0x7a,
+	0x01, 0xa4, 0xee, 0x7a,
+	0x01, 0xfc, 0xe8, 0x7a,
+	0x01, 0x94, 0xf0, 0x6a,
+	0x00, 0x65, 0x8a, 0x42,
+	0x01, 0x94, 0xee, 0x7a,
+	0x10, 0x94, 0xf0, 0x6a,
 	0xd7, 0x93, 0x26, 0x09,
-	0x28, 0x93, 0xea, 0x6a,
+	0x28, 0x93, 0xf4, 0x6a,
 	0x01, 0x85, 0x0a, 0x01,
-	0x02, 0xfc, 0xf2, 0x6a,
+	0x02, 0xfc, 0xfc, 0x6a,
 	0x01, 0x14, 0x46, 0x31,
 	0xff, 0x6a, 0x10, 0x09,
 	0xfe, 0x85, 0x0a, 0x09,
-	0xff, 0x38, 0x00, 0x6b,
-	0x80, 0xa3, 0x00, 0x7b,
-	0x80, 0x0b, 0xfe, 0x7a,
-	0x04, 0x3b, 0x00, 0x7b,
+	0xff, 0x38, 0x0a, 0x6b,
+	0x80, 0xa3, 0x0a, 0x7b,
+	0x80, 0x0b, 0x08, 0x7b,
+	0x04, 0x3b, 0x0a, 0x7b,
 	0xbf, 0x3b, 0x76, 0x08,
 	0x01, 0x3b, 0x26, 0x31,
-	0x00, 0x65, 0x02, 0x5a,
-	0x01, 0x0b, 0x0e, 0x6b,
-	0x10, 0x0c, 0x02, 0x7b,
-	0x04, 0x93, 0x0c, 0x6b,
-	0x01, 0x94, 0x0a, 0x7b,
-	0x10, 0x94, 0x0c, 0x6b,
+	0x00, 0x65, 0x0c, 0x5a,
+	0x01, 0x0b, 0x18, 0x6b,
+	0x10, 0x0c, 0x0c, 0x7b,
+	0x04, 0x93, 0x16, 0x6b,
+	0x01, 0x94, 0x14, 0x7b,
+	0x10, 0x94, 0x16, 0x6b,
 	0xc7, 0x93, 0x26, 0x09,
 	0x01, 0x99, 0xd4, 0x30,
-	0x38, 0x93, 0x10, 0x6b,
-	0xff, 0x08, 0x62, 0x6b,
-	0xff, 0x09, 0x62, 0x6b,
-	0xff, 0x0a, 0x62, 0x6b,
-	0xff, 0x38, 0x2c, 0x7b,
+	0x38, 0x93, 0x1a, 0x6b,
+	0xff, 0x08, 0x6c, 0x6b,
+	0xff, 0x09, 0x6c, 0x6b,
+	0xff, 0x0a, 0x6c, 0x6b,
+	0xff, 0x38, 0x36, 0x7b,
 	0x04, 0x14, 0x10, 0x31,
 	0x01, 0x38, 0x18, 0x31,
 	0x02, 0x6a, 0x1a, 0x31,
 	0x88, 0x6a, 0xcc, 0x00,
-	0x14, 0x6a, 0xe6, 0x5d,
-	0x00, 0x38, 0xd2, 0x5d,
+	0x14, 0x6a, 0x06, 0x5e,
+	0x00, 0x38, 0xf2, 0x5d,
 	0xff, 0x6a, 0x70, 0x08,
-	0x00, 0x65, 0x58, 0x43,
-	0x80, 0xa3, 0x32, 0x7b,
-	0x01, 0xa4, 0x48, 0x01,
 	0x00, 0x65, 0x62, 0x43,
-	0x08, 0xeb, 0x38, 0x7b,
-	0x00, 0x65, 0x02, 0x5a,
-	0x08, 0xeb, 0x34, 0x6b,
+	0x80, 0xa3, 0x3c, 0x7b,
+	0x01, 0xa4, 0x48, 0x01,
+	0x00, 0x65, 0x6c, 0x43,
+	0x08, 0xeb, 0x42, 0x7b,
+	0x00, 0x65, 0x0c, 0x5a,
+	0x08, 0xeb, 0x3e, 0x6b,
 	0x07, 0xe9, 0x10, 0x31,
 	0x01, 0xe9, 0xca, 0x30,
 	0x01, 0x65, 0x46, 0x31,
-	0x00, 0x6a, 0xac, 0x5e,
+	0x00, 0x6a, 0xcc, 0x5e,
 	0x88, 0x6a, 0xcc, 0x00,
-	0xa4, 0x6a, 0xe6, 0x5d,
-	0x08, 0x6a, 0xd2, 0x5d,
+	0xa4, 0x6a, 0x06, 0x5e,
+	0x08, 0x6a, 0xf2, 0x5d,
 	0x0d, 0x93, 0x26, 0x01,
-	0x00, 0x65, 0x9a, 0x5e,
+	0x00, 0x65, 0xba, 0x5e,
 	0x88, 0x6a, 0xcc, 0x00,
-	0x00, 0x65, 0x7c, 0x5e,
+	0x00, 0x65, 0x9c, 0x5e,
 	0x01, 0x99, 0x46, 0x31,
-	0x00, 0xa3, 0xac, 0x5e,
+	0x00, 0xa3, 0xcc, 0x5e,
 	0x01, 0x88, 0x10, 0x31,
-	0x00, 0x65, 0x36, 0x5a,
-	0x00, 0x65, 0xee, 0x59,
+	0x00, 0x65, 0x40, 0x5a,
+	0x00, 0x65, 0xf8, 0x59,
 	0x03, 0x8c, 0x10, 0x30,
-	0x00, 0x65, 0xd8, 0x5d,
-	0x01, 0x8c, 0x60, 0x7b,
+	0x00, 0x65, 0xf8, 0x5d,
+	0x01, 0x8c, 0x6a, 0x7b,
 	0x01, 0x55, 0xaa, 0x10,
-	0x80, 0x0b, 0x80, 0x6a,
-	0x80, 0x0b, 0x6a, 0x6b,
-	0x01, 0x0c, 0x64, 0x7b,
-	0x10, 0x0c, 0x80, 0x7a,
-	0x03, 0x9e, 0x80, 0x6a,
-	0x00, 0x65, 0xf8, 0x59,
-	0x00, 0x6a, 0xac, 0x5e,
-	0x01, 0xa4, 0x8a, 0x6b,
-	0xff, 0x38, 0x80, 0x7b,
+	0x80, 0x0b, 0x8a, 0x6a,
+	0x80, 0x0b, 0x74, 0x6b,
+	0x01, 0x0c, 0x6e, 0x7b,
+	0x10, 0x0c, 0x8a, 0x7a,
+	0x03, 0x9e, 0x8a, 0x6a,
+	0x00, 0x65, 0x02, 0x5a,
+	0x00, 0x6a, 0xcc, 0x5e,
+	0x01, 0xa4, 0x94, 0x6b,
+	0xff, 0x38, 0x8a, 0x7b,
 	0x01, 0x38, 0xc8, 0x30,
 	0x00, 0x08, 0x40, 0x19,
 	0xff, 0x6a, 0xc8, 0x08,
 	0x00, 0x09, 0x42, 0x21,
 	0x00, 0x0a, 0x44, 0x21,
 	0xff, 0x6a, 0x70, 0x08,
-	0x00, 0x65, 0x82, 0x43,
+	0x00, 0x65, 0x8c, 0x43,
 	0x03, 0x08, 0x40, 0x31,
 	0x03, 0x08, 0x40, 0x31,
 	0x01, 0x08, 0x40, 0x31,
@@ -462,19 +467,19 @@
 	0xfd, 0xb4, 0x68, 0x09,
 	0x12, 0x01, 0x02, 0x00,
 	0x12, 0x01, 0x02, 0x00,
-	0x04, 0x3c, 0xc0, 0x79,
+	0x04, 0x3c, 0xca, 0x79,
 	0xfb, 0x3c, 0x78, 0x08,
-	0x04, 0x93, 0x1e, 0x79,
-	0x01, 0x0c, 0x96, 0x6b,
-	0x01, 0x55, 0x1e, 0x79,
-	0x80, 0x04, 0x1e, 0x79,
-	0xe4, 0x6a, 0x60, 0x5d,
-	0x23, 0x6a, 0x76, 0x5d,
-	0x01, 0x6a, 0x76, 0x5d,
-	0x00, 0x65, 0x1e, 0x41,
-	0x00, 0x65, 0xc0, 0x41,
-	0x80, 0x3c, 0xaa, 0x6b,
-	0x21, 0x6a, 0xca, 0x46,
+	0x04, 0x93, 0x20, 0x79,
+	0x01, 0x0c, 0xa0, 0x6b,
+	0x01, 0x55, 0x20, 0x79,
+	0x80, 0x04, 0x20, 0x79,
+	0xe4, 0x6a, 0x80, 0x5d,
+	0x23, 0x6a, 0x96, 0x5d,
+	0x01, 0x6a, 0x96, 0x5d,
+	0x00, 0x65, 0x20, 0x41,
+	0x00, 0x65, 0xca, 0x41,
+	0x80, 0x3c, 0xb4, 0x7b,
+	0x21, 0x6a, 0xea, 0x5e,
 	0x01, 0xbc, 0x18, 0x31,
 	0x02, 0x6a, 0x1a, 0x31,
 	0x02, 0x6a, 0xf8, 0x01,
@@ -484,16 +489,16 @@
 	0xff, 0x6a, 0x12, 0x08,
 	0xff, 0x6a, 0x14, 0x08,
 	0xf3, 0xbc, 0xd4, 0x18,
-	0xa0, 0x6a, 0xd0, 0x53,
+	0xa0, 0x6a, 0xda, 0x53,
 	0x04, 0xa0, 0x10, 0x31,
 	0xac, 0x6a, 0x26, 0x01,
 	0x04, 0xa0, 0x10, 0x31,
 	0x03, 0x08, 0x18, 0x31,
 	0x88, 0x6a, 0xcc, 0x00,
-	0xa0, 0x6a, 0xe6, 0x5d,
-	0x00, 0xbc, 0xd2, 0x5d,
+	0xa0, 0x6a, 0x06, 0x5e,
+	0x00, 0xbc, 0xf2, 0x5d,
 	0x3d, 0x6a, 0x26, 0x01,
-	0x00, 0x65, 0xe8, 0x43,
+	0x00, 0x65, 0xf2, 0x43,
 	0xff, 0x6a, 0x10, 0x09,
 	0xa4, 0x6a, 0x26, 0x01,
 	0x0c, 0xa0, 0x32, 0x31,
@@ -503,117 +508,128 @@
 	0x36, 0x6a, 0x26, 0x01,
 	0x02, 0x93, 0x26, 0x01,
 	0x35, 0x6a, 0x26, 0x01,
-	0x00, 0x65, 0x8e, 0x5e,
-	0x00, 0x65, 0x8e, 0x5e,
+	0x00, 0x65, 0xae, 0x5e,
+	0x00, 0x65, 0xae, 0x5e,
 	0x02, 0x93, 0x26, 0x01,
-	0x04, 0x0b, 0xec, 0x6b,
-	0x10, 0x0c, 0xe8, 0x7b,
-	0x01, 0x03, 0xec, 0x6b,
-	0x20, 0x93, 0xe8, 0x6b,
+	0xbf, 0x3c, 0x78, 0x08,
+	0x04, 0x0b, 0xf8, 0x6b,
+	0x10, 0x0c, 0xf4, 0x7b,
+	0x01, 0x03, 0xf8, 0x6b,
+	0x20, 0x93, 0xfa, 0x6b,
+	0x04, 0x0b, 0x00, 0x6c,
+	0x40, 0x3c, 0x78, 0x00,
 	0xc7, 0x93, 0x26, 0x09,
-	0x38, 0x93, 0xf2, 0x6b,
-	0x10, 0x01, 0x02, 0x00,
-	0x00, 0x65, 0xc0, 0x41,
-	0x80, 0x3c, 0xfc, 0x6b,
-	0x21, 0x6a, 0xca, 0x46,
+	0x38, 0x93, 0x02, 0x6c,
+	0x00, 0x65, 0xca, 0x41,
+	0x80, 0x3c, 0x68, 0x6c,
 	0x01, 0x06, 0x50, 0x31,
-	0x00, 0x65, 0xc0, 0x41,
+	0x80, 0xb8, 0x70, 0x01,
+	0x00, 0x65, 0xca, 0x41,
 	0x10, 0x3f, 0x06, 0x00,
 	0x10, 0x6a, 0x06, 0x00,
 	0x01, 0x3a, 0xca, 0x30,
-	0x80, 0x65, 0x20, 0x64,
-	0x10, 0xb8, 0x44, 0x6c,
+	0x80, 0x65, 0x2e, 0x64,
+	0x10, 0xb8, 0x52, 0x6c,
 	0xc0, 0xba, 0xca, 0x00,
-	0x40, 0xb8, 0x10, 0x6c,
+	0x40, 0xb8, 0x1e, 0x6c,
 	0xbf, 0x65, 0xca, 0x08,
-	0x20, 0xb8, 0x24, 0x7c,
+	0x20, 0xb8, 0x32, 0x7c,
 	0x01, 0x65, 0x0c, 0x30,
-	0x00, 0x65, 0xca, 0x5d,
-	0xa0, 0x3f, 0x2c, 0x64,
+	0x00, 0x65, 0xea, 0x5d,
+	0xa0, 0x3f, 0x3a, 0x64,
 	0x23, 0xb8, 0x0c, 0x08,
-	0x00, 0x65, 0xca, 0x5d,
-	0xa0, 0x3f, 0x2c, 0x64,
-	0x00, 0xbb, 0x24, 0x44,
-	0xff, 0x65, 0x24, 0x64,
-	0x00, 0x65, 0x44, 0x44,
+	0x00, 0x65, 0xea, 0x5d,
+	0xa0, 0x3f, 0x3a, 0x64,
+	0x00, 0xbb, 0x32, 0x44,
+	0xff, 0x65, 0x32, 0x64,
+	0x00, 0x65, 0x52, 0x44,
 	0x40, 0x6a, 0x18, 0x00,
 	0x01, 0x65, 0x0c, 0x30,
-	0x00, 0x65, 0xca, 0x5d,
-	0xa0, 0x3f, 0x00, 0x74,
+	0x00, 0x65, 0xea, 0x5d,
+	0xa0, 0x3f, 0x0e, 0x74,
 	0x40, 0x6a, 0x18, 0x00,
 	0x01, 0x3a, 0xa6, 0x30,
 	0x08, 0x6a, 0x74, 0x00,
-	0x00, 0x65, 0xc0, 0x41,
-	0x64, 0x6a, 0x5a, 0x5d,
-	0x80, 0x64, 0xca, 0x6c,
-	0x04, 0x64, 0x90, 0x74,
-	0x02, 0x64, 0x9e, 0x74,
-	0x00, 0x6a, 0x60, 0x74,
-	0x03, 0x64, 0xbc, 0x74,
-	0x23, 0x64, 0x4c, 0x74,
-	0x08, 0x64, 0x5c, 0x74,
-	0x61, 0x6a, 0xca, 0x5e,
-	0x00, 0x65, 0xca, 0x5d,
-	0x08, 0x51, 0xc2, 0x71,
-	0x00, 0x65, 0x44, 0x44,
-	0x80, 0x04, 0x5a, 0x7c,
-	0x51, 0x6a, 0x50, 0x5d,
-	0x01, 0x51, 0x5a, 0x64,
-	0x01, 0xa4, 0x56, 0x7c,
-	0x01, 0x55, 0x5c, 0x7c,
-	0x41, 0x6a, 0xca, 0x5e,
-	0x00, 0x65, 0x5c, 0x44,
-	0x07, 0x6a, 0x46, 0x5d,
+	0x00, 0x65, 0xca, 0x41,
+	0x64, 0x6a, 0x7a, 0x5d,
+	0x80, 0x64, 0xea, 0x6c,
+	0x04, 0x64, 0xac, 0x74,
+	0x02, 0x64, 0xbc, 0x74,
+	0x00, 0x6a, 0x72, 0x74,
+	0x03, 0x64, 0xda, 0x74,
+	0x23, 0x64, 0x5a, 0x74,
+	0x08, 0x64, 0x6e, 0x74,
+	0x61, 0x6a, 0xea, 0x5e,
+	0x00, 0x65, 0xea, 0x5d,
+	0x08, 0x51, 0xcc, 0x71,
+	0x00, 0x65, 0x52, 0x44,
+	0x80, 0x04, 0x6c, 0x7c,
+	0x51, 0x6a, 0x70, 0x5d,
+	0x01, 0x51, 0x6c, 0x64,
+	0x01, 0xa4, 0x64, 0x7c,
+	0x01, 0x55, 0x6e, 0x7c,
+	0x41, 0x6a, 0xea, 0x5e,
+	0x00, 0x65, 0x6e, 0x44,
+	0x21, 0x6a, 0xea, 0x5e,
+	0x00, 0x65, 0x6e, 0x44,
+	0x07, 0x6a, 0x66, 0x5d,
 	0x01, 0x06, 0xd4, 0x30,
-	0x00, 0x65, 0xc0, 0x41,
-	0x10, 0xb8, 0x64, 0x7c,
-	0xa1, 0x6a, 0xca, 0x5e,
-	0x01, 0xb4, 0x6a, 0x6c,
-	0x02, 0xb4, 0x6c, 0x6c,
-	0x01, 0xa4, 0x6c, 0x7c,
-	0xff, 0xa8, 0x7c, 0x7c,
+	0x00, 0x65, 0xca, 0x41,
+	0x80, 0xb8, 0x68, 0x7c,
+	0xc0, 0x3c, 0x7c, 0x7c,
+	0x80, 0x3c, 0x68, 0x6c,
+	0xff, 0xa8, 0x7c, 0x6c,
+	0x40, 0x3c, 0x68, 0x6c,
+	0x10, 0xb8, 0x80, 0x7c,
+	0xa1, 0x6a, 0xea, 0x5e,
+	0x01, 0xb4, 0x86, 0x6c,
+	0x02, 0xb4, 0x88, 0x6c,
+	0x01, 0xa4, 0x88, 0x7c,
+	0xff, 0xa8, 0x98, 0x7c,
 	0x04, 0xb4, 0x68, 0x01,
 	0x01, 0x6a, 0x76, 0x00,
-	0x00, 0xbb, 0x04, 0x5e,
-	0xff, 0xa8, 0x7c, 0x7c,
-	0x71, 0x6a, 0xca, 0x5e,
-	0x40, 0x51, 0x7c, 0x64,
-	0x00, 0x65, 0xa4, 0x5e,
-	0x00, 0x65, 0xd2, 0x41,
-	0x00, 0xbb, 0x80, 0x5c,
-	0x00, 0x65, 0xd2, 0x41,
-	0x00, 0x65, 0xa4, 0x5e,
+	0x00, 0xbb, 0x24, 0x5e,
+	0xff, 0xa8, 0x98, 0x7c,
+	0x71, 0x6a, 0xea, 0x5e,
+	0x40, 0x51, 0x98, 0x64,
+	0x00, 0x65, 0xc4, 0x5e,
+	0x00, 0x65, 0xdc, 0x41,
+	0x00, 0xbb, 0x9c, 0x5c,
+	0x00, 0x65, 0xdc, 0x41,
+	0x00, 0x65, 0xc4, 0x5e,
 	0x01, 0x65, 0xa2, 0x30,
 	0x01, 0xf8, 0xc8, 0x30,
 	0x01, 0x4e, 0xc8, 0x30,
-	0x00, 0x6a, 0xa8, 0xdd,
-	0x00, 0x51, 0xba, 0x5d,
+	0x00, 0x6a, 0xc8, 0xdd,
+	0x00, 0x51, 0xda, 0x5d,
 	0x01, 0x4e, 0x9c, 0x18,
 	0x02, 0x6a, 0x22, 0x05,
+	0xc0, 0x3c, 0x68, 0x6c,
 	0x04, 0xb8, 0x70, 0x01,
-	0x00, 0x65, 0xc6, 0x5e,
-	0x20, 0xb8, 0xd2, 0x69,
+	0x00, 0x65, 0xe6, 0x5e,
+	0x20, 0xb8, 0xdc, 0x69,
 	0x01, 0xbb, 0xa2, 0x30,
 	0x01, 0xba, 0x7c, 0x30,
-	0x00, 0xb9, 0xc0, 0x5c,
-	0x00, 0x65, 0xd2, 0x41,
+	0x00, 0xb9, 0xe0, 0x5c,
+	0x00, 0x65, 0xdc, 0x41,
 	0x01, 0x06, 0xd4, 0x30,
-	0x20, 0x3c, 0xc0, 0x79,
-	0x20, 0x3c, 0x5c, 0x7c,
-	0x01, 0xa4, 0xac, 0x7c,
+	0x20, 0x3c, 0xca, 0x79,
+	0x20, 0x3c, 0x6e, 0x7c,
+	0x01, 0xa4, 0xca, 0x7c,
 	0x01, 0xb4, 0x68, 0x01,
-	0x00, 0x65, 0xc0, 0x41,
-	0x00, 0x65, 0x5c, 0x44,
+	0x00, 0x65, 0xca, 0x41,
+	0x00, 0x65, 0x6e, 0x44,
 	0x04, 0x14, 0x58, 0x31,
 	0x01, 0x06, 0xd4, 0x30,
 	0x08, 0xa0, 0x60, 0x31,
 	0xac, 0x6a, 0xcc, 0x00,
-	0x14, 0x6a, 0xe6, 0x5d,
+	0x14, 0x6a, 0x06, 0x5e,
 	0x01, 0x06, 0xd4, 0x30,
-	0xa0, 0x6a, 0xde, 0x5d,
-	0x00, 0x65, 0xc0, 0x41,
+	0xa0, 0x6a, 0xfe, 0x5d,
+	0x00, 0x65, 0xca, 0x41,
 	0xdf, 0x3c, 0x78, 0x08,
-	0x00, 0x65, 0x5c, 0x44,
+	0x12, 0x01, 0x02, 0x00,
+	0x00, 0x65, 0x6e, 0x44,
 	0x4c, 0x65, 0xcc, 0x28,
 	0x01, 0x3e, 0x20, 0x31,
 	0xd0, 0x66, 0xcc, 0x18,
@@ -624,102 +640,102 @@
 	0xd0, 0x65, 0xca, 0x18,
 	0x01, 0x3e, 0x20, 0x31,
 	0x30, 0x65, 0xd4, 0x18,
-	0x00, 0x65, 0xd8, 0x4c,
+	0x00, 0x65, 0xf8, 0x4c,
 	0xe1, 0x6a, 0x22, 0x01,
 	0xff, 0x6a, 0xd4, 0x08,
 	0x20, 0x65, 0xd4, 0x18,
-	0x00, 0x65, 0xe0, 0x54,
+	0x00, 0x65, 0x00, 0x55,
 	0xe1, 0x6a, 0x22, 0x01,
 	0xff, 0x6a, 0xd4, 0x08,
 	0x20, 0x65, 0xca, 0x18,
 	0xe0, 0x65, 0xd4, 0x18,
-	0x00, 0x65, 0xea, 0x4c,
+	0x00, 0x65, 0x0a, 0x4d,
 	0xe1, 0x6a, 0x22, 0x01,
 	0xff, 0x6a, 0xd4, 0x08,
 	0xd0, 0x65, 0xd4, 0x18,
-	0x00, 0x65, 0xf2, 0x54,
+	0x00, 0x65, 0x12, 0x55,
 	0xe1, 0x6a, 0x22, 0x01,
 	0xff, 0x6a, 0xd4, 0x08,
 	0x01, 0x6c, 0xa2, 0x30,
-	0xff, 0x51, 0x04, 0x75,
-	0x00, 0x51, 0x80, 0x5d,
+	0xff, 0x51, 0x24, 0x75,
+	0x00, 0x51, 0xa0, 0x5d,
 	0x01, 0x51, 0x20, 0x31,
-	0x00, 0x65, 0x26, 0x45,
+	0x00, 0x65, 0x46, 0x45,
 	0x01, 0xba, 0xc8, 0x30,
-	0x00, 0x3e, 0x26, 0x75,
-	0x00, 0x65, 0xa2, 0x5e,
+	0x00, 0x3e, 0x46, 0x75,
+	0x00, 0x65, 0xc2, 0x5e,
 	0x80, 0x3c, 0x78, 0x00,
 	0x01, 0x06, 0xd4, 0x30,
-	0x00, 0x65, 0xca, 0x5d,
+	0x00, 0x65, 0xea, 0x5d,
 	0x01, 0x3c, 0x78, 0x00,
-	0xe0, 0x3f, 0x42, 0x65,
+	0xe0, 0x3f, 0x62, 0x65,
 	0x02, 0x3c, 0x78, 0x00,
-	0x20, 0x12, 0x42, 0x65,
-	0x51, 0x6a, 0x50, 0x5d,
-	0x00, 0x51, 0x80, 0x5d,
-	0x51, 0x6a, 0x50, 0x5d,
+	0x20, 0x12, 0x62, 0x65,
+	0x51, 0x6a, 0x70, 0x5d,
+	0x00, 0x51, 0xa0, 0x5d,
+	0x51, 0x6a, 0x70, 0x5d,
 	0x01, 0x51, 0x20, 0x31,
 	0x04, 0x3c, 0x78, 0x00,
 	0x01, 0xb9, 0xc8, 0x30,
-	0x00, 0x3d, 0x40, 0x65,
+	0x00, 0x3d, 0x60, 0x65,
 	0x08, 0x3c, 0x78, 0x00,
 	0x01, 0xba, 0xc8, 0x30,
-	0x00, 0x3e, 0x40, 0x65,
+	0x00, 0x3e, 0x60, 0x65,
 	0x10, 0x3c, 0x78, 0x00,
-	0x04, 0xb8, 0x40, 0x7d,
+	0x04, 0xb8, 0x60, 0x7d,
 	0xfb, 0xb8, 0x70, 0x09,
-	0x20, 0xb8, 0x36, 0x6d,
+	0x20, 0xb8, 0x56, 0x6d,
 	0x01, 0x90, 0xc8, 0x30,
 	0xff, 0x6a, 0xa2, 0x00,
-	0x00, 0x3d, 0xc0, 0x5c,
+	0x00, 0x3d, 0xe0, 0x5c,
 	0x01, 0x64, 0x20, 0x31,
-	0x80, 0x6a, 0x78, 0x00,
-	0x00, 0x65, 0xec, 0x58,
-	0x10, 0xb8, 0x5c, 0x7c,
-	0xff, 0x6a, 0x46, 0x5d,
-	0x00, 0x65, 0x5c, 0x44,
-	0x00, 0x65, 0xa2, 0x5e,
-	0x31, 0x6a, 0xca, 0x5e,
-	0x00, 0x65, 0x5c, 0x44,
+	0xff, 0x6a, 0x78, 0x08,
+	0x00, 0x65, 0xea, 0x58,
+	0x10, 0xb8, 0x6e, 0x7c,
+	0xff, 0x6a, 0x66, 0x5d,
+	0x00, 0x65, 0x6e, 0x44,
+	0x00, 0x65, 0xc2, 0x5e,
+	0x31, 0x6a, 0xea, 0x5e,
+	0x00, 0x65, 0x6e, 0x44,
 	0x10, 0x3f, 0x06, 0x00,
 	0x10, 0x6a, 0x06, 0x00,
 	0x01, 0x65, 0x74, 0x34,
-	0x81, 0x6a, 0xca, 0x5e,
-	0x00, 0x65, 0x52, 0x45,
+	0x81, 0x6a, 0xea, 0x5e,
+	0x00, 0x65, 0x72, 0x45,
 	0x01, 0x06, 0xd4, 0x30,
-	0x01, 0x0c, 0x52, 0x7d,
-	0x04, 0x0c, 0x4c, 0x6d,
+	0x01, 0x0c, 0x72, 0x7d,
+	0x04, 0x0c, 0x6c, 0x6d,
 	0xe0, 0x03, 0x7e, 0x08,
-	0xe0, 0x3f, 0xc0, 0x61,
+	0xe0, 0x3f, 0xca, 0x61,
 	0x01, 0x65, 0xcc, 0x30,
 	0x01, 0x12, 0xda, 0x34,
 	0x01, 0x06, 0xd4, 0x34,
-	0x01, 0x03, 0x60, 0x6d,
+	0x01, 0x03, 0x80, 0x6d,
 	0x40, 0x03, 0xcc, 0x08,
 	0x01, 0x65, 0x06, 0x30,
 	0x40, 0x65, 0xc8, 0x08,
-	0x00, 0x66, 0x6e, 0x75,
-	0x40, 0x65, 0x6e, 0x7d,
-	0x00, 0x65, 0x6e, 0x5d,
+	0x00, 0x66, 0x8e, 0x75,
+	0x40, 0x65, 0x8e, 0x7d,
+	0x00, 0x65, 0x8e, 0x5d,
 	0xff, 0x6a, 0xd4, 0x08,
 	0xff, 0x6a, 0xd4, 0x08,
 	0xff, 0x6a, 0xd4, 0x08,
 	0xff, 0x6a, 0xd4, 0x0c,
 	0x08, 0x01, 0x02, 0x00,
-	0x02, 0x0b, 0x78, 0x7d,
+	0x02, 0x0b, 0x98, 0x7d,
 	0x01, 0x65, 0x0c, 0x30,
-	0x02, 0x0b, 0x7c, 0x7d,
+	0x02, 0x0b, 0x9c, 0x7d,
 	0xf7, 0x01, 0x02, 0x0c,
 	0x01, 0x65, 0xc8, 0x30,
-	0xff, 0x41, 0xa0, 0x75,
+	0xff, 0x41, 0xc0, 0x75,
 	0x01, 0x41, 0x20, 0x31,
 	0xff, 0x6a, 0xa4, 0x00,
-	0x00, 0x65, 0x90, 0x45,
-	0xff, 0xbf, 0xa0, 0x75,
+	0x00, 0x65, 0xb0, 0x45,
+	0xff, 0xbf, 0xc0, 0x75,
 	0x01, 0x90, 0xa4, 0x30,
 	0x01, 0xbf, 0x20, 0x31,
-	0x00, 0xbb, 0x8a, 0x65,
-	0xff, 0x52, 0x9e, 0x75,
+	0x00, 0xbb, 0xaa, 0x65,
+	0xff, 0x52, 0xbe, 0x75,
 	0x01, 0xbf, 0xcc, 0x30,
 	0x01, 0x90, 0xca, 0x30,
 	0x01, 0x52, 0x20, 0x31,
@@ -727,28 +743,28 @@
 	0x01, 0x65, 0x20, 0x35,
 	0x01, 0xbf, 0x82, 0x34,
 	0x01, 0x64, 0xa2, 0x30,
-	0x00, 0x6a, 0xb2, 0x5e,
+	0x00, 0x6a, 0xd2, 0x5e,
 	0x0d, 0x6a, 0x76, 0x00,
-	0x00, 0x51, 0x04, 0x46,
+	0x00, 0x51, 0x24, 0x46,
 	0x01, 0x65, 0xa4, 0x30,
 	0xe0, 0x6a, 0xcc, 0x00,
-	0x48, 0x6a, 0xf8, 0x5d,
+	0x48, 0x6a, 0x18, 0x5e,
 	0x01, 0x6a, 0xd0, 0x01,
 	0x01, 0x6a, 0xdc, 0x05,
 	0x88, 0x6a, 0xcc, 0x00,
-	0x48, 0x6a, 0xf8, 0x5d,
-	0x01, 0x6a, 0xd2, 0x5d,
+	0x48, 0x6a, 0x18, 0x5e,
+	0x01, 0x6a, 0xf2, 0x5d,
 	0x01, 0x6a, 0x26, 0x05,
 	0x01, 0x65, 0xd8, 0x31,
 	0x09, 0xee, 0xdc, 0x01,
-	0x80, 0xee, 0xbe, 0x7d,
+	0x80, 0xee, 0xde, 0x7d,
 	0xff, 0x6a, 0xdc, 0x0d,
 	0x01, 0x65, 0x32, 0x31,
 	0x0a, 0x93, 0x26, 0x01,
-	0x00, 0x65, 0x9a, 0x46,
-	0x81, 0x6a, 0xca, 0x5e,
-	0x01, 0x0c, 0xca, 0x7d,
-	0x04, 0x0c, 0xc8, 0x6d,
+	0x00, 0x65, 0xba, 0x46,
+	0x81, 0x6a, 0xea, 0x5e,
+	0x01, 0x0c, 0xea, 0x7d,
+	0x04, 0x0c, 0xe8, 0x6d,
 	0xe0, 0x03, 0x06, 0x08,
 	0xe0, 0x03, 0x7e, 0x0c,
 	0x01, 0x65, 0x18, 0x31,
@@ -767,7 +783,7 @@
 	0x01, 0x6c, 0xda, 0x34,
 	0x3d, 0x64, 0xa4, 0x28,
 	0x55, 0x64, 0xc8, 0x28,
-	0x00, 0x65, 0xf8, 0x45,
+	0x00, 0x65, 0x18, 0x46,
 	0x2e, 0x64, 0xa4, 0x28,
 	0x66, 0x64, 0xc8, 0x28,
 	0x00, 0x6c, 0xda, 0x18,
@@ -778,63 +794,63 @@
 	0x00, 0x6c, 0xda, 0x24,
 	0x01, 0x65, 0xc8, 0x30,
 	0xe0, 0x6a, 0xcc, 0x00,
-	0x44, 0x6a, 0xf4, 0x5d,
+	0x44, 0x6a, 0x14, 0x5e,
 	0x01, 0x90, 0xe2, 0x31,
-	0x04, 0x3b, 0x18, 0x7e,
+	0x04, 0x3b, 0x38, 0x7e,
 	0x30, 0x6a, 0xd0, 0x01,
 	0x20, 0x6a, 0xd0, 0x01,
 	0x1d, 0x6a, 0xdc, 0x01,
-	0xdc, 0xee, 0x14, 0x66,
-	0x00, 0x65, 0x30, 0x46,
+	0xdc, 0xee, 0x34, 0x66,
+	0x00, 0x65, 0x50, 0x46,
 	0x20, 0x6a, 0xd0, 0x01,
 	0x01, 0x6a, 0xdc, 0x01,
 	0x20, 0xa0, 0xd8, 0x31,
 	0x09, 0xee, 0xdc, 0x01,
-	0x80, 0xee, 0x20, 0x7e,
+	0x80, 0xee, 0x40, 0x7e,
 	0x11, 0x6a, 0xdc, 0x01,
-	0x50, 0xee, 0x24, 0x66,
+	0x50, 0xee, 0x44, 0x66,
 	0x20, 0x6a, 0xd0, 0x01,
 	0x09, 0x6a, 0xdc, 0x01,
-	0x88, 0xee, 0x2a, 0x66,
+	0x88, 0xee, 0x4a, 0x66,
 	0x19, 0x6a, 0xdc, 0x01,
-	0xd8, 0xee, 0x2e, 0x66,
+	0xd8, 0xee, 0x4e, 0x66,
 	0xff, 0x6a, 0xdc, 0x09,
-	0x18, 0xee, 0x32, 0x6e,
+	0x18, 0xee, 0x52, 0x6e,
 	0xff, 0x6a, 0xd4, 0x0c,
 	0x88, 0x6a, 0xcc, 0x00,
-	0x44, 0x6a, 0xf4, 0x5d,
-	0x20, 0x6a, 0xd2, 0x5d,
+	0x44, 0x6a, 0x14, 0x5e,
+	0x20, 0x6a, 0xf2, 0x5d,
 	0x01, 0x3b, 0x26, 0x31,
-	0x04, 0x3b, 0x4c, 0x6e,
+	0x04, 0x3b, 0x6c, 0x6e,
 	0xa0, 0x6a, 0xca, 0x00,
 	0x20, 0x65, 0xc8, 0x18,
-	0x00, 0x65, 0x8a, 0x5e,
-	0x00, 0x65, 0x44, 0x66,
+	0x00, 0x65, 0xaa, 0x5e,
+	0x00, 0x65, 0x64, 0x66,
 	0x0a, 0x93, 0x26, 0x01,
-	0x00, 0x65, 0x9a, 0x46,
+	0x00, 0x65, 0xba, 0x46,
 	0xa0, 0x6a, 0xcc, 0x00,
 	0xff, 0x6a, 0xc8, 0x08,
-	0x20, 0x94, 0x50, 0x6e,
-	0x10, 0x94, 0x52, 0x6e,
-	0x08, 0x94, 0x6c, 0x6e,
-	0x08, 0x94, 0x6c, 0x6e,
-	0x08, 0x94, 0x6c, 0x6e,
+	0x20, 0x94, 0x70, 0x6e,
+	0x10, 0x94, 0x72, 0x6e,
+	0x08, 0x94, 0x8c, 0x6e,
+	0x08, 0x94, 0x8c, 0x6e,
+	0x08, 0x94, 0x8c, 0x6e,
 	0xff, 0x8c, 0xc8, 0x10,
 	0xc1, 0x64, 0xc8, 0x18,
 	0xf8, 0x64, 0xc8, 0x08,
 	0x01, 0x99, 0xda, 0x30,
-	0x00, 0x66, 0x60, 0x66,
-	0xc0, 0x66, 0x9c, 0x76,
+	0x00, 0x66, 0x80, 0x66,
+	0xc0, 0x66, 0xbc, 0x76,
 	0x60, 0x66, 0xc8, 0x18,
 	0x3d, 0x64, 0xc8, 0x28,
-	0x00, 0x65, 0x50, 0x46,
+	0x00, 0x65, 0x70, 0x46,
 	0xf7, 0x93, 0x26, 0x09,
-	0x08, 0x93, 0x6e, 0x6e,
+	0x08, 0x93, 0x8e, 0x6e,
 	0x00, 0x62, 0xc4, 0x18,
+	0x00, 0x65, 0xba, 0x5e,
+	0x00, 0x65, 0x9a, 0x5e,
+	0x00, 0x65, 0x9a, 0x5e,
 	0x00, 0x65, 0x9a, 0x5e,
-	0x00, 0x65, 0x7a, 0x5e,
-	0x00, 0x65, 0x7a, 0x5e,
-	0x00, 0x65, 0x7a, 0x5e,
 	0x01, 0x99, 0xda, 0x30,
 	0x01, 0x99, 0xda, 0x30,
 	0x01, 0x99, 0xda, 0x30,
@@ -851,11 +867,11 @@
 	0x01, 0x6c, 0x32, 0x31,
 	0x01, 0x6c, 0x32, 0x31,
 	0x01, 0x6c, 0x32, 0x35,
-	0x08, 0x94, 0x9a, 0x7e,
+	0x08, 0x94, 0xba, 0x7e,
 	0xf7, 0x93, 0x26, 0x09,
-	0x08, 0x93, 0x9e, 0x6e,
+	0x08, 0x93, 0xbe, 0x6e,
 	0xff, 0x6a, 0xd4, 0x0c,
-	0x04, 0xb8, 0xc6, 0x6e,
+	0x04, 0xb8, 0xe6, 0x6e,
 	0x01, 0x42, 0x7e, 0x31,
 	0xff, 0x6a, 0x76, 0x01,
 	0x01, 0x90, 0x84, 0x34,
@@ -863,14 +879,14 @@
 	0x01, 0x85, 0x0a, 0x01,
 	0x7f, 0x65, 0x10, 0x09,
 	0xfe, 0x85, 0x0a, 0x0d,
-	0xff, 0x42, 0xc2, 0x66,
-	0xff, 0x41, 0xba, 0x66,
-	0xd1, 0x6a, 0xca, 0x5e,
+	0xff, 0x42, 0xe2, 0x66,
+	0xff, 0x41, 0xda, 0x66,
+	0xd1, 0x6a, 0xea, 0x5e,
 	0xff, 0x6a, 0xca, 0x04,
 	0x01, 0x41, 0x20, 0x31,
 	0x01, 0xbf, 0x82, 0x30,
 	0x01, 0x6a, 0x76, 0x00,
-	0x00, 0xbb, 0x04, 0x46,
+	0x00, 0xbb, 0x24, 0x46,
 	0x01, 0x42, 0x20, 0x31,
 	0x01, 0xbf, 0x84, 0x34,
 	0x01, 0x41, 0x7e, 0x31,
@@ -880,7 +896,8 @@
 	0xff, 0x6a, 0xd4, 0x0c
 };
 
-static int ahc_patch23_func(struct ahc_softc *ahc);
+typedef int ahc_patch_func_t (struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch23_func;
 
 static int
 ahc_patch23_func(struct ahc_softc *ahc)
@@ -888,7 +905,7 @@
 	return ((ahc->bugs & AHC_SCBCHAN_UPLOAD_BUG) != 0);
 }
 
-static int ahc_patch22_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch22_func;
 
 static int
 ahc_patch22_func(struct ahc_softc *ahc)
@@ -896,7 +913,7 @@
 	return ((ahc->features & AHC_CMD_CHAN) == 0);
 }
 
-static int ahc_patch21_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch21_func;
 
 static int
 ahc_patch21_func(struct ahc_softc *ahc)
@@ -904,7 +921,7 @@
 	return ((ahc->features & AHC_QUEUE_REGS) == 0);
 }
 
-static int ahc_patch20_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch20_func;
 
 static int
 ahc_patch20_func(struct ahc_softc *ahc)
@@ -912,7 +929,7 @@
 	return ((ahc->features & AHC_WIDE) != 0);
 }
 
-static int ahc_patch19_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch19_func;
 
 static int
 ahc_patch19_func(struct ahc_softc *ahc)
@@ -920,7 +937,7 @@
 	return ((ahc->flags & AHC_SCB_BTT) != 0);
 }
 
-static int ahc_patch18_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch18_func;
 
 static int
 ahc_patch18_func(struct ahc_softc *ahc)
@@ -928,7 +945,7 @@
 	return ((ahc->bugs & AHC_PCI_2_1_RETRY_BUG) != 0);
 }
 
-static int ahc_patch17_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch17_func;
 
 static int
 ahc_patch17_func(struct ahc_softc *ahc)
@@ -936,7 +953,7 @@
 	return ((ahc->flags & AHC_TMODE_WIDEODD_BUG) != 0);
 }
 
-static int ahc_patch16_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch16_func;
 
 static int
 ahc_patch16_func(struct ahc_softc *ahc)
@@ -944,7 +961,7 @@
 	return ((ahc->bugs & AHC_AUTOFLUSH_BUG) != 0);
 }
 
-static int ahc_patch15_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch15_func;
 
 static int
 ahc_patch15_func(struct ahc_softc *ahc)
@@ -952,7 +969,7 @@
 	return ((ahc->features & AHC_ULTRA2) == 0);
 }
 
-static int ahc_patch14_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch14_func;
 
 static int
 ahc_patch14_func(struct ahc_softc *ahc)
@@ -960,7 +977,7 @@
 	return ((ahc->bugs & AHC_PCI_MWI_BUG) != 0 && ahc->pci_cachesize != 0);
 }
 
-static int ahc_patch13_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch13_func;
 
 static int
 ahc_patch13_func(struct ahc_softc *ahc)
@@ -968,7 +985,7 @@
 	return ((ahc->flags & AHC_39BIT_ADDRESSING) != 0);
 }
 
-static int ahc_patch12_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch12_func;
 
 static int
 ahc_patch12_func(struct ahc_softc *ahc)
@@ -976,7 +993,7 @@
 	return ((ahc->features & AHC_HS_MAILBOX) != 0);
 }
 
-static int ahc_patch11_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch11_func;
 
 static int
 ahc_patch11_func(struct ahc_softc *ahc)
@@ -984,7 +1001,7 @@
 	return ((ahc->features & AHC_ULTRA) != 0);
 }
 
-static int ahc_patch10_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch10_func;
 
 static int
 ahc_patch10_func(struct ahc_softc *ahc)
@@ -992,7 +1009,7 @@
 	return ((ahc->features & AHC_MULTI_TID) != 0);
 }
 
-static int ahc_patch9_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch9_func;
 
 static int
 ahc_patch9_func(struct ahc_softc *ahc)
@@ -1000,7 +1017,7 @@
 	return ((ahc->features & AHC_CMD_CHAN) != 0);
 }
 
-static int ahc_patch8_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch8_func;
 
 static int
 ahc_patch8_func(struct ahc_softc *ahc)
@@ -1008,7 +1025,7 @@
 	return ((ahc->flags & AHC_INITIATORROLE) != 0);
 }
 
-static int ahc_patch7_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch7_func;
 
 static int
 ahc_patch7_func(struct ahc_softc *ahc)
@@ -1016,7 +1033,7 @@
 	return ((ahc->flags & AHC_TARGETROLE) != 0);
 }
 
-static int ahc_patch6_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch6_func;
 
 static int
 ahc_patch6_func(struct ahc_softc *ahc)
@@ -1024,7 +1041,7 @@
 	return ((ahc->features & AHC_DT) == 0);
 }
 
-static int ahc_patch5_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch5_func;
 
 static int
 ahc_patch5_func(struct ahc_softc *ahc)
@@ -1032,7 +1049,7 @@
 	return ((ahc->flags & AHC_SEQUENCER_DEBUG) != 0);
 }
 
-static int ahc_patch4_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch4_func;
 
 static int
 ahc_patch4_func(struct ahc_softc *ahc)
@@ -1040,7 +1057,7 @@
 	return ((ahc->flags & AHC_PAGESCBS) != 0);
 }
 
-static int ahc_patch3_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch3_func;
 
 static int
 ahc_patch3_func(struct ahc_softc *ahc)
@@ -1048,7 +1065,7 @@
 	return ((ahc->features & AHC_QUEUE_REGS) != 0);
 }
 
-static int ahc_patch2_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch2_func;
 
 static int
 ahc_patch2_func(struct ahc_softc *ahc)
@@ -1056,7 +1073,7 @@
 	return ((ahc->features & AHC_TWIN) != 0);
 }
 
-static int ahc_patch1_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch1_func;
 
 static int
 ahc_patch1_func(struct ahc_softc *ahc)
@@ -1064,7 +1081,7 @@
 	return ((ahc->features & AHC_ULTRA2) != 0);
 }
 
-static int ahc_patch0_func(struct ahc_softc *ahc);
+static ahc_patch_func_t ahc_patch0_func;
 
 static int
 ahc_patch0_func(struct ahc_softc *ahc)
@@ -1072,12 +1089,11 @@
 	return (0);
 }
 
-typedef int patch_func_t (struct ahc_softc *);
-struct patch {
-	patch_func_t	*patch_func;
-	uint32_t	begin	   :10,
-			skip_instr :10,
-			skip_patch :12;
+static struct patch {
+	ahc_patch_func_t		*patch_func;
+	uint32_t		 begin		:10,
+				 skip_instr	:10,
+				 skip_patch	:12;
 } patches[] = {
 	{ ahc_patch1_func, 4, 1, 1 },
 	{ ahc_patch2_func, 6, 2, 1 },
@@ -1120,180 +1136,181 @@
 	{ ahc_patch0_func, 111, 1, 1 },
 	{ ahc_patch7_func, 112, 4, 2 },
 	{ ahc_patch0_func, 116, 1, 1 },
-	{ ahc_patch11_func, 118, 2, 1 },
-	{ ahc_patch1_func, 120, 1, 2 },
-	{ ahc_patch0_func, 121, 1, 1 },
-	{ ahc_patch7_func, 122, 4, 1 },
-	{ ahc_patch7_func, 133, 89, 11 },
+	{ ahc_patch11_func, 117, 2, 1 },
+	{ ahc_patch1_func, 119, 1, 2 },
+	{ ahc_patch0_func, 120, 1, 1 },
+	{ ahc_patch7_func, 121, 4, 1 },
+	{ ahc_patch7_func, 131, 94, 11 },
 	{ ahc_patch4_func, 151, 1, 1 },
-	{ ahc_patch1_func, 164, 1, 1 },
-	{ ahc_patch12_func, 169, 1, 2 },
-	{ ahc_patch0_func, 170, 1, 1 },
-	{ ahc_patch9_func, 181, 1, 2 },
-	{ ahc_patch0_func, 182, 1, 1 },
-	{ ahc_patch9_func, 191, 1, 2 },
-	{ ahc_patch0_func, 192, 1, 1 },
-	{ ahc_patch9_func, 208, 6, 2 },
-	{ ahc_patch0_func, 214, 6, 1 },
-	{ ahc_patch8_func, 222, 18, 2 },
-	{ ahc_patch1_func, 235, 1, 1 },
-	{ ahc_patch1_func, 242, 1, 2 },
-	{ ahc_patch0_func, 243, 2, 2 },
-	{ ahc_patch11_func, 244, 1, 1 },
-	{ ahc_patch9_func, 252, 31, 3 },
-	{ ahc_patch1_func, 268, 14, 2 },
-	{ ahc_patch13_func, 273, 1, 1 },
-	{ ahc_patch14_func, 283, 14, 1 },
-	{ ahc_patch1_func, 299, 1, 2 },
-	{ ahc_patch0_func, 300, 1, 1 },
-	{ ahc_patch9_func, 303, 1, 1 },
-	{ ahc_patch13_func, 308, 1, 1 },
-	{ ahc_patch9_func, 309, 2, 2 },
-	{ ahc_patch0_func, 311, 4, 1 },
-	{ ahc_patch14_func, 315, 1, 1 },
-	{ ahc_patch15_func, 318, 2, 3 },
-	{ ahc_patch9_func, 318, 1, 2 },
-	{ ahc_patch0_func, 319, 1, 1 },
-	{ ahc_patch6_func, 324, 1, 2 },
-	{ ahc_patch0_func, 325, 1, 1 },
-	{ ahc_patch1_func, 329, 50, 11 },
-	{ ahc_patch6_func, 338, 2, 4 },
-	{ ahc_patch7_func, 338, 1, 1 },
-	{ ahc_patch8_func, 339, 1, 1 },
-	{ ahc_patch0_func, 340, 1, 1 },
-	{ ahc_patch16_func, 341, 1, 1 },
-	{ ahc_patch6_func, 360, 6, 3 },
-	{ ahc_patch16_func, 360, 5, 1 },
-	{ ahc_patch0_func, 366, 5, 1 },
-	{ ahc_patch13_func, 374, 5, 1 },
-	{ ahc_patch0_func, 379, 54, 17 },
-	{ ahc_patch14_func, 379, 1, 1 },
-	{ ahc_patch7_func, 381, 2, 2 },
-	{ ahc_patch17_func, 382, 1, 1 },
-	{ ahc_patch9_func, 385, 1, 1 },
-	{ ahc_patch18_func, 392, 1, 1 },
-	{ ahc_patch14_func, 397, 9, 3 },
-	{ ahc_patch9_func, 398, 3, 2 },
-	{ ahc_patch0_func, 401, 3, 1 },
-	{ ahc_patch9_func, 409, 6, 2 },
-	{ ahc_patch0_func, 415, 9, 2 },
-	{ ahc_patch13_func, 415, 1, 1 },
-	{ ahc_patch13_func, 424, 2, 1 },
-	{ ahc_patch14_func, 426, 1, 1 },
-	{ ahc_patch9_func, 428, 1, 2 },
-	{ ahc_patch0_func, 429, 1, 1 },
-	{ ahc_patch7_func, 432, 1, 1 },
-	{ ahc_patch7_func, 433, 1, 1 },
-	{ ahc_patch8_func, 434, 3, 3 },
-	{ ahc_patch6_func, 435, 1, 2 },
-	{ ahc_patch0_func, 436, 1, 1 },
-	{ ahc_patch9_func, 437, 1, 1 },
-	{ ahc_patch15_func, 438, 1, 2 },
-	{ ahc_patch13_func, 438, 1, 1 },
-	{ ahc_patch14_func, 440, 9, 4 },
-	{ ahc_patch9_func, 440, 1, 1 },
-	{ ahc_patch9_func, 447, 2, 1 },
-	{ ahc_patch0_func, 449, 4, 3 },
-	{ ahc_patch9_func, 449, 1, 2 },
-	{ ahc_patch0_func, 450, 3, 1 },
-	{ ahc_patch1_func, 454, 2, 1 },
-	{ ahc_patch7_func, 456, 10, 2 },
-	{ ahc_patch0_func, 466, 1, 1 },
-	{ ahc_patch8_func, 467, 109, 23 },
-	{ ahc_patch1_func, 469, 3, 2 },
-	{ ahc_patch0_func, 472, 5, 3 },
-	{ ahc_patch9_func, 472, 2, 2 },
-	{ ahc_patch0_func, 474, 3, 1 },
-	{ ahc_patch1_func, 479, 2, 2 },
-	{ ahc_patch0_func, 481, 6, 3 },
-	{ ahc_patch9_func, 481, 2, 2 },
-	{ ahc_patch0_func, 483, 3, 1 },
-	{ ahc_patch1_func, 489, 2, 2 },
-	{ ahc_patch0_func, 491, 9, 7 },
-	{ ahc_patch9_func, 491, 5, 6 },
-	{ ahc_patch19_func, 491, 1, 2 },
-	{ ahc_patch0_func, 492, 1, 1 },
-	{ ahc_patch19_func, 494, 1, 2 },
-	{ ahc_patch0_func, 495, 1, 1 },
-	{ ahc_patch0_func, 496, 4, 1 },
-	{ ahc_patch6_func, 500, 3, 2 },
-	{ ahc_patch0_func, 503, 1, 1 },
-	{ ahc_patch1_func, 506, 1, 1 },
-	{ ahc_patch6_func, 512, 1, 2 },
-	{ ahc_patch0_func, 513, 1, 1 },
-	{ ahc_patch20_func, 550, 7, 1 },
-	{ ahc_patch3_func, 578, 1, 2 },
-	{ ahc_patch0_func, 579, 1, 1 },
-	{ ahc_patch21_func, 582, 1, 1 },
-	{ ahc_patch8_func, 584, 104, 33 },
-	{ ahc_patch4_func, 585, 1, 1 },
-	{ ahc_patch1_func, 591, 2, 2 },
+	{ ahc_patch1_func, 167, 1, 1 },
+	{ ahc_patch12_func, 172, 1, 2 },
+	{ ahc_patch0_func, 173, 1, 1 },
+	{ ahc_patch9_func, 184, 1, 2 },
+	{ ahc_patch0_func, 185, 1, 1 },
+	{ ahc_patch9_func, 194, 1, 2 },
+	{ ahc_patch0_func, 195, 1, 1 },
+	{ ahc_patch9_func, 211, 6, 2 },
+	{ ahc_patch0_func, 217, 6, 1 },
+	{ ahc_patch8_func, 225, 20, 2 },
+	{ ahc_patch1_func, 240, 1, 1 },
+	{ ahc_patch1_func, 247, 1, 2 },
+	{ ahc_patch0_func, 248, 2, 2 },
+	{ ahc_patch11_func, 249, 1, 1 },
+	{ ahc_patch9_func, 257, 31, 3 },
+	{ ahc_patch1_func, 273, 14, 2 },
+	{ ahc_patch13_func, 278, 1, 1 },
+	{ ahc_patch14_func, 288, 14, 1 },
+	{ ahc_patch1_func, 304, 1, 2 },
+	{ ahc_patch0_func, 305, 1, 1 },
+	{ ahc_patch9_func, 308, 1, 1 },
+	{ ahc_patch13_func, 313, 1, 1 },
+	{ ahc_patch9_func, 314, 2, 2 },
+	{ ahc_patch0_func, 316, 4, 1 },
+	{ ahc_patch14_func, 320, 1, 1 },
+	{ ahc_patch15_func, 323, 2, 3 },
+	{ ahc_patch9_func, 323, 1, 2 },
+	{ ahc_patch0_func, 324, 1, 1 },
+	{ ahc_patch6_func, 329, 1, 2 },
+	{ ahc_patch0_func, 330, 1, 1 },
+	{ ahc_patch1_func, 334, 50, 11 },
+	{ ahc_patch6_func, 343, 2, 4 },
+	{ ahc_patch7_func, 343, 1, 1 },
+	{ ahc_patch8_func, 344, 1, 1 },
+	{ ahc_patch0_func, 345, 1, 1 },
+	{ ahc_patch16_func, 346, 1, 1 },
+	{ ahc_patch6_func, 365, 6, 3 },
+	{ ahc_patch16_func, 365, 5, 1 },
+	{ ahc_patch0_func, 371, 5, 1 },
+	{ ahc_patch13_func, 379, 5, 1 },
+	{ ahc_patch0_func, 384, 54, 17 },
+	{ ahc_patch14_func, 384, 1, 1 },
+	{ ahc_patch7_func, 386, 2, 2 },
+	{ ahc_patch17_func, 387, 1, 1 },
+	{ ahc_patch9_func, 390, 1, 1 },
+	{ ahc_patch18_func, 397, 1, 1 },
+	{ ahc_patch14_func, 402, 9, 3 },
+	{ ahc_patch9_func, 403, 3, 2 },
+	{ ahc_patch0_func, 406, 3, 1 },
+	{ ahc_patch9_func, 414, 6, 2 },
+	{ ahc_patch0_func, 420, 9, 2 },
+	{ ahc_patch13_func, 420, 1, 1 },
+	{ ahc_patch13_func, 429, 2, 1 },
+	{ ahc_patch14_func, 431, 1, 1 },
+	{ ahc_patch9_func, 433, 1, 2 },
+	{ ahc_patch0_func, 434, 1, 1 },
+	{ ahc_patch7_func, 437, 1, 1 },
+	{ ahc_patch7_func, 438, 1, 1 },
+	{ ahc_patch8_func, 439, 3, 3 },
+	{ ahc_patch6_func, 440, 1, 2 },
+	{ ahc_patch0_func, 441, 1, 1 },
+	{ ahc_patch9_func, 442, 1, 1 },
+	{ ahc_patch15_func, 443, 1, 2 },
+	{ ahc_patch13_func, 443, 1, 1 },
+	{ ahc_patch14_func, 445, 9, 4 },
+	{ ahc_patch9_func, 445, 1, 1 },
+	{ ahc_patch9_func, 452, 2, 1 },
+	{ ahc_patch0_func, 454, 4, 3 },
+	{ ahc_patch9_func, 454, 1, 2 },
+	{ ahc_patch0_func, 455, 3, 1 },
+	{ ahc_patch1_func, 459, 2, 1 },
+	{ ahc_patch7_func, 461, 10, 2 },
+	{ ahc_patch0_func, 471, 1, 1 },
+	{ ahc_patch8_func, 472, 118, 22 },
+	{ ahc_patch1_func, 474, 3, 2 },
+	{ ahc_patch0_func, 477, 5, 3 },
+	{ ahc_patch9_func, 477, 2, 2 },
+	{ ahc_patch0_func, 479, 3, 1 },
+	{ ahc_patch1_func, 484, 2, 2 },
+	{ ahc_patch0_func, 486, 6, 3 },
+	{ ahc_patch9_func, 486, 2, 2 },
+	{ ahc_patch0_func, 488, 3, 1 },
+	{ ahc_patch1_func, 494, 2, 2 },
+	{ ahc_patch0_func, 496, 9, 7 },
+	{ ahc_patch9_func, 496, 5, 6 },
+	{ ahc_patch19_func, 496, 1, 2 },
+	{ ahc_patch0_func, 497, 1, 1 },
+	{ ahc_patch19_func, 499, 1, 2 },
+	{ ahc_patch0_func, 500, 1, 1 },
+	{ ahc_patch0_func, 501, 4, 1 },
+	{ ahc_patch6_func, 506, 3, 2 },
+	{ ahc_patch0_func, 509, 1, 1 },
+	{ ahc_patch6_func, 519, 1, 2 },
+	{ ahc_patch0_func, 520, 1, 1 },
+	{ ahc_patch20_func, 557, 7, 1 },
+	{ ahc_patch3_func, 592, 1, 2 },
 	{ ahc_patch0_func, 593, 1, 1 },
-	{ ahc_patch1_func, 596, 1, 2 },
-	{ ahc_patch0_func, 597, 1, 1 },
-	{ ahc_patch9_func, 598, 3, 3 },
-	{ ahc_patch15_func, 599, 1, 1 },
-	{ ahc_patch0_func, 601, 4, 1 },
-	{ ahc_patch19_func, 609, 2, 2 },
-	{ ahc_patch0_func, 611, 1, 1 },
-	{ ahc_patch19_func, 615, 10, 3 },
-	{ ahc_patch5_func, 617, 8, 1 },
-	{ ahc_patch0_func, 625, 9, 2 },
-	{ ahc_patch5_func, 626, 8, 1 },
-	{ ahc_patch4_func, 636, 1, 2 },
-	{ ahc_patch0_func, 637, 1, 1 },
-	{ ahc_patch19_func, 638, 1, 2 },
-	{ ahc_patch0_func, 639, 3, 2 },
-	{ ahc_patch4_func, 641, 1, 1 },
-	{ ahc_patch5_func, 642, 1, 1 },
-	{ ahc_patch5_func, 645, 1, 1 },
-	{ ahc_patch5_func, 647, 1, 1 },
-	{ ahc_patch4_func, 649, 2, 2 },
-	{ ahc_patch0_func, 651, 2, 1 },
-	{ ahc_patch5_func, 653, 1, 1 },
-	{ ahc_patch5_func, 656, 1, 1 },
-	{ ahc_patch5_func, 659, 1, 1 },
-	{ ahc_patch19_func, 663, 1, 1 },
-	{ ahc_patch19_func, 666, 1, 1 },
-	{ ahc_patch4_func, 672, 1, 1 },
-	{ ahc_patch6_func, 675, 1, 2 },
-	{ ahc_patch0_func, 676, 1, 1 },
-	{ ahc_patch7_func, 688, 16, 1 },
-	{ ahc_patch4_func, 704, 20, 1 },
-	{ ahc_patch9_func, 725, 4, 2 },
-	{ ahc_patch0_func, 729, 4, 1 },
-	{ ahc_patch9_func, 733, 4, 2 },
-	{ ahc_patch0_func, 737, 3, 1 },
-	{ ahc_patch6_func, 743, 1, 1 },
-	{ ahc_patch22_func, 745, 14, 1 },
-	{ ahc_patch7_func, 759, 3, 1 },
-	{ ahc_patch9_func, 771, 24, 8 },
-	{ ahc_patch19_func, 775, 1, 2 },
-	{ ahc_patch0_func, 776, 1, 1 },
-	{ ahc_patch15_func, 781, 4, 2 },
-	{ ahc_patch0_func, 785, 7, 3 },
-	{ ahc_patch23_func, 785, 5, 2 },
-	{ ahc_patch0_func, 790, 2, 1 },
-	{ ahc_patch0_func, 795, 42, 3 },
-	{ ahc_patch18_func, 807, 18, 2 },
-	{ ahc_patch0_func, 825, 1, 1 },
-	{ ahc_patch4_func, 849, 1, 1 },
-	{ ahc_patch4_func, 850, 3, 2 },
-	{ ahc_patch0_func, 853, 1, 1 },
-	{ ahc_patch13_func, 854, 3, 1 },
-	{ ahc_patch4_func, 857, 12, 1 }
+	{ ahc_patch21_func, 596, 1, 1 },
+	{ ahc_patch8_func, 598, 106, 33 },
+	{ ahc_patch4_func, 600, 1, 1 },
+	{ ahc_patch1_func, 606, 2, 2 },
+	{ ahc_patch0_func, 608, 1, 1 },
+	{ ahc_patch1_func, 611, 1, 2 },
+	{ ahc_patch0_func, 612, 1, 1 },
+	{ ahc_patch9_func, 613, 3, 3 },
+	{ ahc_patch15_func, 614, 1, 1 },
+	{ ahc_patch0_func, 616, 4, 1 },
+	{ ahc_patch19_func, 625, 2, 2 },
+	{ ahc_patch0_func, 627, 1, 1 },
+	{ ahc_patch19_func, 631, 10, 3 },
+	{ ahc_patch5_func, 633, 8, 1 },
+	{ ahc_patch0_func, 641, 9, 2 },
+	{ ahc_patch5_func, 642, 8, 1 },
+	{ ahc_patch4_func, 652, 1, 2 },
+	{ ahc_patch0_func, 653, 1, 1 },
+	{ ahc_patch19_func, 654, 1, 2 },
+	{ ahc_patch0_func, 655, 3, 2 },
+	{ ahc_patch4_func, 657, 1, 1 },
+	{ ahc_patch5_func, 658, 1, 1 },
+	{ ahc_patch5_func, 661, 1, 1 },
+	{ ahc_patch5_func, 663, 1, 1 },
+	{ ahc_patch4_func, 665, 2, 2 },
+	{ ahc_patch0_func, 667, 2, 1 },
+	{ ahc_patch5_func, 669, 1, 1 },
+	{ ahc_patch5_func, 672, 1, 1 },
+	{ ahc_patch5_func, 675, 1, 1 },
+	{ ahc_patch19_func, 679, 1, 1 },
+	{ ahc_patch19_func, 682, 1, 1 },
+	{ ahc_patch4_func, 688, 1, 1 },
+	{ ahc_patch6_func, 691, 1, 2 },
+	{ ahc_patch0_func, 692, 1, 1 },
+	{ ahc_patch7_func, 704, 16, 1 },
+	{ ahc_patch4_func, 720, 20, 1 },
+	{ ahc_patch9_func, 741, 4, 2 },
+	{ ahc_patch0_func, 745, 4, 1 },
+	{ ahc_patch9_func, 749, 4, 2 },
+	{ ahc_patch0_func, 753, 3, 1 },
+	{ ahc_patch6_func, 759, 1, 1 },
+	{ ahc_patch22_func, 761, 14, 1 },
+	{ ahc_patch7_func, 775, 3, 1 },
+	{ ahc_patch9_func, 787, 24, 8 },
+	{ ahc_patch19_func, 791, 1, 2 },
+	{ ahc_patch0_func, 792, 1, 1 },
+	{ ahc_patch15_func, 797, 4, 2 },
+	{ ahc_patch0_func, 801, 7, 3 },
+	{ ahc_patch23_func, 801, 5, 2 },
+	{ ahc_patch0_func, 806, 2, 1 },
+	{ ahc_patch0_func, 811, 42, 3 },
+	{ ahc_patch18_func, 823, 18, 2 },
+	{ ahc_patch0_func, 841, 1, 1 },
+	{ ahc_patch4_func, 865, 1, 1 },
+	{ ahc_patch4_func, 866, 3, 2 },
+	{ ahc_patch0_func, 869, 1, 1 },
+	{ ahc_patch13_func, 870, 3, 1 },
+	{ ahc_patch4_func, 873, 12, 1 }
 };
-struct cs {
-	u_int16_t	begin;
-	u_int16_t	end;
+
+static struct cs {
+	uint16_t	begin;
+	uint16_t	end;
 } critical_sections[] = {
 	{ 11, 18 },
 	{ 21, 30 },
-	{ 704, 720 },
-	{ 850, 853 },
-	{ 857, 863 },
-	{ 865, 867 },
-	{ 867, 869 }
+	{ 720, 736 },
+	{ 866, 869 },
+	{ 873, 879 },
+	{ 881, 883 },
+	{ 883, 885 }
 };
-const int num_critical_sections = sizeof(critical_sections)
-				 / sizeof(*critical_sections);
+
+static const int num_critical_sections = sizeof(critical_sections)
+				       / sizeof(*critical_sections);
diff -Nru a/drivers/scsi/aic7xxx/aicasm/Makefile b/drivers/scsi/aic7xxx/aicasm/Makefile
--- a/drivers/scsi/aic7xxx/aicasm/Makefile	Mon Dec 23 21:21:59 2002
+++ b/drivers/scsi/aic7xxx/aicasm/Makefile	Mon Dec 23 21:21:59 2002
@@ -1,15 +1,16 @@
 PROG=	aicasm
 
-.SUFFIXES= .l .y .c
+.SUFFIXES= .l .y .c .h
 
 CSRCS=	aicasm.c aicasm_symbol.c
-GENSRCS= aicasm_gram.c aicasm_scan.c
-GENHDRS= y.tab.h aicdb.h
+YSRCS=	aicasm_gram.y aicasm_macro_gram.y
+LSRCS=	aicasm_scan.l aicasm_macro_scan.l
 
-SRCS=	${GENSRCS} ${CSRCS}
+GENHDRS=	aicdb.h $(YSRCS:.y=.h)
+GENSRCS=	$(YSRCS:.y=.c) $(LSRCS:.l=.c)
 
-# Cleaned up by make clean
-clean-files := $(GENSRCS) $(GENHDRS) y.output $(PROG)
+SRCS=	${CSRCS} ${GENSRCS}
+CLEANFILES= ${GENSRCS} ${GENHDRS} $(YSRCS:.y=.output)
 # Override default kernel CFLAGS.  This is a userland app.
 AICASM_CFLAGS:= -I/usr/include -I. -ldb
 YFLAGS= -d
@@ -28,7 +29,7 @@
 LFLAGS= -d
 endif
 
-$(PROG):  $(SRCS) $(GENHDRS)
+$(PROG):  ${GENHDRS} $(SRCS)
 	$(AICASM_CC) $(AICASM_CFLAGS) $(SRCS) -o $(PROG)
 
 aicdb.h:
@@ -44,8 +45,21 @@
 		echo "*** Install db development libraries";	\
 	 fi
 
-y.tab.h aicasm_gram.c: aicasm_gram.y
-	$(YACC) $(YFLAGS) aicasm_gram.y
-	mv y.tab.c aicasm_gram.c
+clean:
+	rm -f $(CLEANFILES) $(PROG)
 
-aicasm_scan.c: y.tab.h
+aicasm_gram.c aicasm_gram.h: aicasm_gram.y
+	$(YACC) $(YFLAGS) -b $(<:.y=) $<
+	mv $(<:.y=).tab.c $(<:.y=.c)
+	mv $(<:.y=).tab.h $(<:.y=.h)
+
+aicasm_macro_gram.c aicasm_macro_gram.h: aicasm_macro_gram.y
+	$(YACC) $(YFLAGS) -b $(<:.y=) -p mm $<
+	mv $(<:.y=).tab.c $(<:.y=.c)
+	mv $(<:.y=).tab.h $(<:.y=.h)
+
+aicasm_scan.c: aicasm_scan.l
+	$(LEX) $(LFLAGS) -o$@ $<
+
+aicasm_macro_scan.c: aicasm_macro_scan.l
+	$(LEX) $(LFLAGS) -Pmm -o$@ $<
diff -Nru a/drivers/scsi/aic7xxx/aicasm/aicasm.c b/drivers/scsi/aic7xxx/aicasm/aicasm.c
--- a/drivers/scsi/aic7xxx/aicasm/aicasm.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/scsi/aic7xxx/aicasm/aicasm.c	Mon Dec 23 21:21:53 2002
@@ -2,7 +2,7 @@
  * Aic7xxx SCSI host adapter firmware asssembler
  *
  * Copyright (c) 1997, 1998, 2000, 2001 Justin T. Gibbs.
- * Copyright (c) 2001 Adaptec Inc.
+ * Copyright (c) 2001, 2002 Adaptec Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -37,15 +37,16 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm.c#11 $
+ * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm.c#22 $
  *
- * $FreeBSD: src/sys/dev/aic7xxx/aicasm/aicasm.c,v 1.29 2000/10/05 04:25:42 gibbs Exp $
+ * $FreeBSD$
  */
 #include <sys/types.h>
 #include <sys/mman.h>
 
 #include <ctype.h>
 #include <inttypes.h>
+#include <regex.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -84,12 +85,17 @@
 struct path_list search_path;
 int includes_search_curdir;
 char *appname;
+char *stock_include_file;
 FILE *ofile;
 char *ofilename;
 char *regfilename;
 FILE *regfile;
 char *listfilename;
 FILE *listfile;
+char *regdiagfilename;
+FILE *regdiagfile;
+int   src_mode;
+int   dst_mode;
 
 static STAILQ_HEAD(,instruction) seq_program;
 struct cs_tailq cs_tailq;
@@ -98,7 +104,9 @@
 
 #if DEBUG
 extern int yy_flex_debug;
+extern int mm_flex_debug;
 extern int yydebug;
+extern int mmdebug;
 #endif
 extern FILE *yyin;
 extern int yyparse(void);
@@ -131,16 +139,20 @@
 	listfile = NULL;
 #if DEBUG
 	yy_flex_debug = 0;
+	mm_flex_debug = 0;
 	yydebug = 0;
+	mmdebug = 0;
 #endif
-	while ((ch = getopt(argc, argv, "d:l:n:o:r:I:O:")) != -1) {
+	while ((ch = getopt(argc, argv, "d:i:l:n:o:p:r:I:")) != -1) {
 		switch(ch) {
 		case 'd':
 #if DEBUG
 			if (strcmp(optarg, "s") == 0) {
 				yy_flex_debug = 1;
+				mm_flex_debug = 1;
 			} else if (strcmp(optarg, "p") == 0) {
 				yydebug = 1;
+				mmdebug = 1;
 			} else {
 				fprintf(stderr, "%s: -d Requires either an "
 					"'s' or 'p' argument\n", appname);
@@ -151,6 +163,9 @@
 			     "information", EX_SOFTWARE);
 #endif
 			break;
+		case 'i':
+			stock_include_file = optarg;
+			break;
 		case 'l':
 			/* Create a program listing */
 			if ((listfile = fopen(optarg, "w")) == NULL) {
@@ -175,6 +190,14 @@
 			}
 			ofilename = optarg;
 			break;
+		case 'p':
+			/* Create Register Diagnostic "printing" Functions */
+			if ((regdiagfile = fopen(optarg, "w")) == NULL) {
+				perror(optarg);
+				stop(NULL, EX_CANTCREAT);
+			}
+			regdiagfilename = optarg;
+			break;
 		case 'r':
 			if ((regfile = fopen(optarg, "w")) == NULL) {
 				perror(optarg);
@@ -236,6 +259,14 @@
 		/* NOTREACHED */
 	}
 
+	if (regdiagfile != NULL
+	 && (regfile == NULL || stock_include_file == NULL)) {
+		fprintf(stderr,
+			"%s: The -p option requires the -r and -i options.\n",
+			appname);
+		usage();
+		/* NOTREACHED */
+	}
 	symtable_open();
 	inputfilename = *argv;
 	include_file(*argv, SOURCE_FILE);
@@ -243,8 +274,7 @@
 	if (retval == 0) {
 		if (SLIST_FIRST(&scope_stack) == NULL
 		 || SLIST_FIRST(&scope_stack)->type != SCOPE_ROOT) {
-			stop("Unterminated conditional expression",
-			     EX_DATAERR);
+			stop("Unterminated conditional expression", EX_DATAERR);
 			/* NOTREACHED */
 		}
 
@@ -263,9 +293,8 @@
 
 		if (ofile != NULL)
 			output_code();
-		if (regfile != NULL) {
-			symtable_dump(regfile);
-		}
+		if (regfile != NULL)
+			symtable_dump(regfile, regdiagfile);
 		if (listfile != NULL)
 			output_listing(inputfilename);
 	}
@@ -280,10 +309,10 @@
 {
 
 	(void)fprintf(stderr,
-"usage: %-16s [-nostdinc] [-I-] [-I directory] [-o output_file]
-			[-r register_output_file] [-l program_list_file]
-			input_file\n",
-			appname);
+"usage: %-16s [-nostdinc] [-I-] [-I directory] [-o output_file]\n"
+"	[-r register_output_file [-p register_diag_file -i includefile]]\n"
+"	[-l program_list_file]\n"
+"	input_file\n", appname);
 	exit(EX_USAGE);
 }
 
@@ -327,11 +356,11 @@
 
 	instrcount = 0;
 	fprintf(ofile,
-"/*
- * DO NOT EDIT - This file is automatically generated
- *		 from the following source files:
- *
-%s */\n", versions);
+"/*\n"
+" * DO NOT EDIT - This file is automatically generated\n"
+" *		 from the following source files:\n"
+" *\n"
+"%s */\n", versions);
 
 	fprintf(ofile, "static uint8_t seqprog[] = {\n");
 	for (cur_instr = STAILQ_FIRST(&seq_program);
@@ -355,64 +384,75 @@
 	}
 	fprintf(ofile, "\n};\n\n");
 
+	if (patch_arg_list == NULL)
+		stop("Patch argument list not defined",
+		     EX_DATAERR);
+
 	/*
 	 *  Output patch information.  Patch functions first.
 	 */
+	fprintf(ofile,
+"typedef int %spatch_func_t (%s);\n", prefix, patch_arg_list);
+
 	for (cur_node = SLIST_FIRST(&patch_functions);
 	     cur_node != NULL;
 	     cur_node = SLIST_NEXT(cur_node,links)) {
 		fprintf(ofile,
-"static int ahc_patch%d_func(struct ahc_softc *ahc);
-
-static int
-ahc_patch%d_func(struct ahc_softc *ahc)
-{
-	return (%s);
-}\n\n",
+"static %spatch_func_t %spatch%d_func;\n"
+"\n"
+"static int\n"
+"%spatch%d_func(%s)\n"
+"{\n"
+"	return (%s);\n"
+"}\n\n",
+			prefix,
+			prefix,
 			cur_node->symbol->info.condinfo->func_num,
+			prefix,
 			cur_node->symbol->info.condinfo->func_num,
+			patch_arg_list,
 			cur_node->symbol->name);
 	}
 
 	fprintf(ofile,
-"typedef int patch_func_t (struct ahc_softc *);
-struct patch {
-	patch_func_t	*patch_func;
-	uint32_t	begin	   :10,
-			skip_instr :10,
-			skip_patch :12;
-} patches[] = {\n");
-
-	for(cur_patch = STAILQ_FIRST(&patches);
-	    cur_patch != NULL;
-	    cur_patch = STAILQ_NEXT(cur_patch,links)) {
-		fprintf(ofile, "%s\t{ ahc_patch%d_func, %d, %d, %d }",
+"static struct patch {\n"
+"	%spatch_func_t		*patch_func;\n"
+"	uint32_t		 begin		:10,\n"
+"				 skip_instr	:10,\n"
+"				 skip_patch	:12;\n"
+"} patches[] = {\n", prefix);
+
+	for (cur_patch = STAILQ_FIRST(&patches);
+	     cur_patch != NULL;
+	     cur_patch = STAILQ_NEXT(cur_patch,links)) {
+		fprintf(ofile, "%s\t{ %spatch%d_func, %d, %d, %d }",
 			cur_patch == STAILQ_FIRST(&patches) ? "" : ",\n",
+			prefix,
 			cur_patch->patch_func, cur_patch->begin,
 			cur_patch->skip_instr, cur_patch->skip_patch);
 	}
 
-	fprintf(ofile, "\n};\n");
+	fprintf(ofile, "\n};\n\n");
 
 	fprintf(ofile,
-"struct cs {
-	u_int16_t	begin;
-	u_int16_t	end;
-} critical_sections[] = {\n");
-
-	for(cs = TAILQ_FIRST(&cs_tailq);
-	    cs != NULL;
-	    cs = TAILQ_NEXT(cs, links)) {
+"static struct cs {\n"
+"	uint16_t	begin;\n"
+"	uint16_t	end;\n"
+"} critical_sections[] = {\n");
+
+	for (cs = TAILQ_FIRST(&cs_tailq);
+	     cs != NULL;
+	     cs = TAILQ_NEXT(cs, links)) {
 		fprintf(ofile, "%s\t{ %d, %d }",
 			cs == TAILQ_FIRST(&cs_tailq) ? "" : ",\n",
 			cs->begin_addr, cs->end_addr);
 	}
 
-	fprintf(ofile, "\n};\n");
+	fprintf(ofile, "\n};\n\n");
 
 	fprintf(ofile,
-"const int num_critical_sections = sizeof(critical_sections)
-				 / sizeof(*critical_sections);\n");
+"static const int num_critical_sections = sizeof(critical_sections)\n"
+"				       / sizeof(*critical_sections);\n");
 
 	fprintf(stderr, "%s: %d instructions used\n", appname, instrcount);
 }
@@ -555,9 +595,9 @@
 
 	/* Now output the listing */
 	cur_patch = STAILQ_FIRST(&patches);
-	for(cur_instr = STAILQ_FIRST(&seq_program);
-	    cur_instr != NULL;
-	    cur_instr = STAILQ_NEXT(cur_instr, links), instrcount++) {
+	for (cur_instr = STAILQ_FIRST(&seq_program);
+	     cur_instr != NULL;
+	     cur_instr = STAILQ_NEXT(cur_instr, links), instrcount++) {
 
 		if (check_patch(&cur_patch, instrcount,
 				&skip_addr, func_values) == 0) {
diff -Nru a/drivers/scsi/aic7xxx/aicasm/aicasm.h b/drivers/scsi/aic7xxx/aicasm/aicasm.h
--- a/drivers/scsi/aic7xxx/aicasm/aicasm.h	Mon Dec 23 21:21:53 2002
+++ b/drivers/scsi/aic7xxx/aicasm/aicasm.h	Mon Dec 23 21:21:53 2002
@@ -2,7 +2,7 @@
  * Assembler for the sequencer program downloaded to Aic7xxx SCSI host adapters
  *
  * Copyright (c) 1997 Justin T. Gibbs.
- * Copyright (c) 2001 Adaptec Inc.
+ * Copyright (c) 2001, 2002 Adaptec Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -37,9 +37,9 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm.h#7 $
+ * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm.h#14 $
  *
- * $FreeBSD: src/sys/dev/aic7xxx/aicasm/aicasm.h,v 1.11 2000/09/22 22:19:54 gibbs Exp $
+ * $FreeBSD$
  */
 
 #ifdef __linux__
@@ -76,12 +76,19 @@
 extern struct symlist patch_functions;
 extern int includes_search_curdir;		/* False if we've seen -I- */
 extern char *appname;
+extern char *stock_include_file;
 extern int yylineno;
 extern char *yyfilename;
+extern char *prefix;
+extern char *patch_arg_list;
 extern char *versions;
+extern int   src_mode;
+extern int   dst_mode;
+struct symbol;
 
 void stop(const char *errstring, int err_code);
 void include_file(char *file_name, include_type type);
+void expand_macro(struct symbol *macro_symbol);
 struct instruction *seq_alloc(void);
 struct critical_section *cs_alloc(void);
 struct scope *scope_alloc(void);
diff -Nru a/drivers/scsi/aic7xxx/aicasm/aicasm_gram.y b/drivers/scsi/aic7xxx/aicasm/aicasm_gram.y
--- a/drivers/scsi/aic7xxx/aicasm/aicasm_gram.y	Mon Dec 23 21:21:51 2002
+++ b/drivers/scsi/aic7xxx/aicasm/aicasm_gram.y	Mon Dec 23 21:21:51 2002
@@ -3,7 +3,7 @@
  * Parser for the Aic7xxx SCSI Host adapter sequencer assembler.
  *
  * Copyright (c) 1997, 1998, 2000 Justin T. Gibbs.
- * Copyright (c) 2001 Adaptec Inc.
+ * Copyright (c) 2001, 2002 Adaptec Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -38,18 +38,20 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_gram.y#9 $
+ * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_gram.y#28 $
  *
- * $FreeBSD: src/sys/dev/aic7xxx/aicasm/aicasm_gram.y,v 1.12 2000/10/31 18:44:32 gibbs Exp $
+ * $FreeBSD$
  */
 
+#include <sys/types.h>
+
 #include <inttypes.h>
+#include <regex.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sysexits.h>
 
-#include <sys/types.h>
 #ifdef __linux__
 #include "../queue.h"
 #else
@@ -62,21 +64,34 @@
 
 int yylineno;
 char *yyfilename;
+char stock_prefix[] = "aic_";
+char *prefix = stock_prefix;
+char *patch_arg_list;
 char *versions;
+static char errbuf[255];
+static char regex_pattern[255];
 static symbol_t *cur_symbol;
+static symbol_t *field_symbol;
+static symbol_t *scb_or_sram_symbol;
 static symtype cur_symtype;
-static symbol_t *accumulator;
+static symbol_ref_t accumulator;
+static symbol_ref_t mode_ptr;
 static symbol_ref_t allones;
 static symbol_ref_t allzeros;
 static symbol_ref_t none;
 static symbol_ref_t sindex;
 static int instruction_ptr;
+static int num_srams;
 static int sram_or_scb_offset;
 static int download_constant_count;
 static int in_critical_section;
+static u_int enum_increment;
+static u_int enum_next_value;
 
-static void process_bitmask(int mask_type, symbol_t *sym, int mask);
+static void process_field(int field_type, symbol_t *sym, int mask);
 static void initialize_symbol(symbol_t *symbol);
+static void add_macro_arg(const char *argtext, int position);
+static void add_macro_body(const char *bodytext);
 static void process_register(symbol_t **p_symbol);
 static void format_1_instr(int opcode, symbol_ref_t *dest,
 			   expression_t *immed, symbol_ref_t *src, int ret);
@@ -92,13 +107,12 @@
 static void add_version(const char *verstring);
 static int  is_download_const(expression_t *immed);
 
-#define YYDEBUG 1
 #define SRAM_SYMNAME "SRAM_BASE"
 #define SCB_SYMNAME "SCB_BASE"
 %}
 
 %union {
-	int		value;
+	u_int		value;
 	char		*str;
 	symbol_t	*sym;
 	symbol_ref_t	sym_ref;
@@ -109,6 +123,8 @@
 
 %token <value> T_CONST
 
+%token T_EXPORT
+
 %token T_DOWNLOAD
 
 %token T_SCB
@@ -119,27 +135,41 @@
 
 %token T_SIZE
 
+%token T_EXPR_LSHIFT
+
+%token T_EXPR_RSHIFT
+
 %token <value> T_ADDRESS
 
 %token T_ACCESS_MODE
 
+%token T_MODES
+
+%token T_DEFINE
+
+%token T_SET_SRC_MODE
+
+%token T_SET_DST_MODE
+
 %token <value> T_MODE
 
 %token T_BEGIN_CS
 
 %token T_END_CS
 
-%token T_BIT
+%token T_FIELD
+
+%token T_ENUM
 
 %token T_MASK
 
 %token <value> T_NUMBER
 
-%token <str> T_PATH T_STRING
+%token <str> T_PATH T_STRING T_ARG T_MACROBODY
 
 %token <sym> T_CEXPR
 
-%token T_EOF T_INCLUDE T_VERSION
+%token T_EOF T_INCLUDE T_VERSION T_PREFIX T_PATCH_ARG_LIST
 
 %token <value> T_SHR T_SHL T_ROR T_ROL
 
@@ -163,7 +193,7 @@
 
 %token T_NOP
 
-%token T_ACCUM T_ALLONES T_ALLZEROS T_NONE T_SINDEX
+%token T_ACCUM T_ALLONES T_ALLZEROS T_NONE T_SINDEX T_MODE_PTR
 
 %token T_A
 
@@ -177,13 +207,15 @@
 
 %type <expression> expression immediate immediate_or_a
 
-%type <value> ret f1_opcode f2_opcode jmp_jc_jnc_call jz_jnz je_jne
+%type <value> export ret f1_opcode f2_opcode jmp_jc_jnc_call jz_jnz je_jne
 
-%type <value> numerical_value
+%type <value> numerical_value mode_value mode_list macro_arglist
 
 %left '|'
 %left '&'
+%left T_EXPR_LSHIFT T_EXPR_RSHIFT
 %left '+' '-'
+%left '*' '/'
 %right '~'
 %nonassoc UMINUS
 %%
@@ -191,18 +223,28 @@
 program:
 	include
 |	program include
+|	prefix
+|	program prefix
+|	patch_arg_list
+|	program patch_arg_list
 |	version
 |	program version
 |	register
 |	program register
 |	constant
 |	program constant
+|	macrodefn
+|	program macrodefn
 |	scratch_ram
 |	program scratch_ram
 |	scb
 |	program scb
 |	label
 |	program label
+|	set_src_mode
+|	program set_src_mode
+|	set_dst_mode
+|	program set_dst_mode
 |	critical_section_start
 |	program critical_section_start
 |	critical_section_end
@@ -224,6 +266,30 @@
 	}
 ;
 
+prefix:
+	T_PREFIX '=' T_STRING
+	{
+		if (prefix != stock_prefix)
+			stop("Prefix multiply defined",
+			     EX_DATAERR);
+		prefix = strdup($3);
+		if (prefix == NULL)
+			stop("Unable to record prefix", EX_SOFTWARE);
+	}
+;
+
+patch_arg_list:
+	T_PATCH_ARG_LIST '=' T_STRING
+	{
+		if (patch_arg_list != NULL)
+			stop("Patch argument list multiply defined",
+			     EX_DATAERR);
+		patch_arg_list = strdup($3);
+		if (patch_arg_list == NULL)
+			stop("Unable to record patch arg list", EX_SOFTWARE);
+	}
+;
+
 version:
 	T_VERSION '=' T_STRING
 	{ add_version($3); }
@@ -280,10 +346,13 @@
 	reg_address
 |	size
 |	access_mode
-|	bit_defn
+|	modes
+|	field_defn
+|	enum_defn
 |	mask_defn
 |	alias
 |	accumulator
+|	mode_pointer
 |	allones
 |	allzeros
 |	none
@@ -301,6 +370,18 @@
 	T_SIZE T_NUMBER
 	{
 		cur_symbol->info.rinfo->size = $2;
+		if (scb_or_sram_symbol != NULL) {
+			u_int max_addr;
+			u_int sym_max_addr;
+
+			max_addr = scb_or_sram_symbol->info.rinfo->address
+				 + scb_or_sram_symbol->info.rinfo->size;
+			sym_max_addr = cur_symbol->info.rinfo->address
+				     + cur_symbol->info.rinfo->size;
+
+			if (sym_max_addr > max_addr)
+				stop("SCB or SRAM space exhausted", EX_DATAERR);
+		}
 	}
 ;
 
@@ -311,17 +392,116 @@
 	}
 ;
 
-bit_defn:
-	T_BIT T_SYMBOL T_NUMBER
+modes:
+	T_MODES mode_list
 	{
-		process_bitmask(BIT, $2, $3);
+		cur_symbol->info.rinfo->modes = $2;
+	}
+;
+
+mode_list:
+	mode_value
+	{
+		$$ = $1;
+	}
+|	mode_list ',' mode_value
+	{
+		$$ = $1 | $3;
+	}
+;
+
+mode_value:
+	T_NUMBER
+	{
+		if ($1 > 4) {
+			stop("Valid register modes range between 0 and 4.",
+			     EX_DATAERR);
+			/* NOTREACHED */
+		}
+
+		$$ = (0x1 << $1);
+	}
+|	T_SYMBOL
+	{
+		symbol_t *symbol;
+
+		symbol = $1;
+		if (symbol->type != CONST) {
+			stop("Only \"const\" symbols allowed in "
+			     "mode definitions.", EX_DATAERR);
+			/* NOTREACHED */
+		}
+		if (symbol->info.cinfo->value > 4) {
+			stop("Valid register modes range between 0 and 4.",
+			     EX_DATAERR);
+			/* NOTREACHED */
+		}
+		$$ = (0x1 << symbol->info.cinfo->value);
+	}
+;
+
+field_defn:
+	T_FIELD
+		{
+			field_symbol = NULL;
+			enum_next_value = 0;
+			enum_increment = 1;
+		}
+	'{' enum_entry_list '}'
+|	T_FIELD T_SYMBOL expression
+		{
+			process_field(FIELD, $2, $3.value);
+			field_symbol = $2;
+			enum_next_value = 0;
+			enum_increment = 0x01 << (ffs($3.value) - 1);
+		}
+	'{' enum_entry_list '}'
+|	T_FIELD T_SYMBOL expression
+	{
+		process_field(FIELD, $2, $3.value);
+	}
+;
+
+enum_defn:
+	T_ENUM
+		{
+			field_symbol = NULL;
+			enum_next_value = 0;
+			enum_increment = 1;
+		}
+	'{' enum_entry_list '}'
+|	T_ENUM T_SYMBOL expression
+		{
+			process_field(ENUM, $2, $3.value);
+			field_symbol = $2;
+			enum_next_value = 0;
+			enum_increment = 0x01 << (ffs($3.value) - 1);
+		}
+	'{' enum_entry_list '}'
+;
+
+enum_entry_list:
+	enum_entry
+|	enum_entry_list ',' enum_entry
+;
+
+enum_entry:
+	T_SYMBOL
+	{
+		process_field(ENUM_ENTRY, $1, enum_next_value);
+		enum_next_value += enum_increment;
+	}
+|	T_SYMBOL expression
+	{
+		process_field(ENUM_ENTRY, $1, $2.value);
+		enum_next_value = $2.value + enum_increment;
 	}
 ;
 
 mask_defn:
 	T_MASK T_SYMBOL expression
 	{
-		process_bitmask(MASK, $2, $3.value);
+		process_field(MASK, $2, $3.value);
 	}
 ;
 
@@ -342,12 +522,24 @@
 accumulator:
 	T_ACCUM
 	{
-		if (accumulator != NULL) {
+		if (accumulator.symbol != NULL) {
 			stop("Only one accumulator definition allowed",
 			     EX_DATAERR);
 			/* NOTREACHED */
 		}
-		accumulator = cur_symbol;
+		accumulator.symbol = cur_symbol;
+	}
+;
+
+mode_pointer:
+	T_MODE_PTR
+	{
+		if (mode_ptr.symbol != NULL) {
+			stop("Only one mode pointer definition allowed",
+			     EX_DATAERR);
+			/* NOTREACHED */
+		}
+		mode_ptr.symbol = cur_symbol;
 	}
 ;
 
@@ -428,6 +620,34 @@
 			       &($1.referenced_syms),
 			       &($3.referenced_syms));
 	}
+|	expression '*' expression
+	{
+		$$.value = $1.value * $3.value;
+		symlist_merge(&($$.referenced_syms),
+			       &($1.referenced_syms),
+			       &($3.referenced_syms));
+	}
+|	expression '/' expression
+	{
+		$$.value = $1.value / $3.value;
+		symlist_merge(&($$.referenced_syms),
+			       &($1.referenced_syms),
+			       &($3.referenced_syms));
+	}
+| 	expression T_EXPR_LSHIFT expression
+	{
+		$$.value = $1.value << $3.value;
+		symlist_merge(&$$.referenced_syms,
+			       &$1.referenced_syms,
+			       &$3.referenced_syms);
+	}
+| 	expression T_EXPR_RSHIFT expression
+	{
+		$$.value = $1.value >> $3.value;
+		symlist_merge(&$$.referenced_syms,
+			       &$1.referenced_syms,
+			       &$3.referenced_syms);
+	}
 |	'(' expression ')'
 	{
 		$$ = $2;
@@ -461,8 +681,10 @@
 			$$.value = symbol->info.rinfo->address;
 			break;
 		case MASK:
-		case BIT:
-			$$.value = symbol->info.minfo->mask;
+		case FIELD:
+		case ENUM:
+		case ENUM_ENTRY:
+			$$.value = symbol->info.finfo->value;
 			break;
 		case DOWNLOAD_CONST:
 		case CONST:
@@ -471,12 +693,10 @@
 		case UNINITIALIZED:
 		default:
 		{
-			char buf[255];
-
-			snprintf(buf, sizeof(buf),
+			snprintf(errbuf, sizeof(errbuf),
 				 "Undefined symbol %s referenced",
 				 symbol->name);
-			stop(buf, EX_DATAERR);
+			stop(errbuf, EX_DATAERR);
 			/* NOTREACHED */
 			break;
 		}
@@ -487,7 +707,7 @@
 ;
 
 constant:
-	T_CONST T_SYMBOL numerical_value
+	T_CONST T_SYMBOL expression 
 	{
 		if ($2->type != UNINITIALIZED) {
 			stop("Re-definition of symbol as a constant",
@@ -496,8 +716,7 @@
 		}
 		$2->type = CONST;
 		initialize_symbol($2);
-		$2->info.cinfo->value = $3;
-		$2->info.cinfo->define = $1;
+		$2->info.cinfo->value = $3.value;
 	}
 |	T_CONST T_SYMBOL T_DOWNLOAD
 	{
@@ -514,7 +733,54 @@
 		$2->type = DOWNLOAD_CONST;
 		initialize_symbol($2);
 		$2->info.cinfo->value = download_constant_count++;
-		$2->info.cinfo->define = FALSE;
+	}
+;
+
+macrodefn_prologue:
+	T_DEFINE T_SYMBOL
+	{
+		if ($2->type != UNINITIALIZED) {
+			stop("Re-definition of symbol as a macro",
+			     EX_DATAERR);
+			/* NOTREACHED */
+		}
+		cur_symbol = $2;
+		cur_symbol->type = MACRO;
+		initialize_symbol(cur_symbol);
+	}
+;
+
+macrodefn:
+	macrodefn_prologue T_MACROBODY
+	{
+		add_macro_body($2);
+	}
+|	macrodefn_prologue '(' macro_arglist ')' T_MACROBODY
+	{
+		add_macro_body($5);
+		cur_symbol->info.macroinfo->narg = $3;
+	}
+;
+
+macro_arglist:
+	{
+		/* Macros can take no arguments */
+		$$ = 0;
+	}
+|	T_ARG
+	{
+		$$ = 1;
+		add_macro_arg($1, 0);
+	}
+|	macro_arglist ',' T_ARG
+	{
+		if ($1 == 0) {
+			stop("Comma without preceeding argument in arg list",
+			     EX_DATAERR);
+			/* NOTREACHED */
+		}
+		$$ = $1 + 1;
+		add_macro_arg($3, $1);
 	}
 ;
 
@@ -532,13 +798,10 @@
 scratch_ram:
 	T_SRAM '{'
 		{
+			snprintf(errbuf, sizeof(errbuf), "%s%d", SRAM_SYMNAME,
+				 num_srams);
 			cur_symbol = symtable_get(SRAM_SYMNAME);
 			cur_symtype = SRAMLOC;
-			if (cur_symbol->type != UNINITIALIZED) {
-				stop("Only one SRAM definition allowed",
-				     EX_DATAERR);
-				/* NOTREACHED */
-			}
 			cur_symbol->type = SRAMLOC;
 			initialize_symbol(cur_symbol);
 		}
@@ -546,10 +809,15 @@
 		{
 			sram_or_scb_offset = cur_symbol->info.rinfo->address;
 		}
-		scb_or_sram_reg_list
+		size
+		{
+			scb_or_sram_symbol = cur_symbol;
+		}
+		scb_or_sram_attributes
 	'}'
 		{
 			cur_symbol = NULL;
+			scb_or_sram_symbol = NULL;
 		}
 ;
 
@@ -572,13 +840,25 @@
 		{
 			sram_or_scb_offset = cur_symbol->info.rinfo->address;
 		}
-		scb_or_sram_reg_list
+		size
+		{
+			scb_or_sram_symbol = cur_symbol;
+		}
+		scb_or_sram_attributes
 	'}'
 		{
 			cur_symbol = NULL;
+			scb_or_sram_symbol = NULL;
 		}
 ;
 
+scb_or_sram_attributes:
+	/* NULL definition is okay */
+|	modes
+|	scb_or_sram_reg_list
+|	modes scb_or_sram_reg_list
+;
+
 scb_or_sram_reg_list:
 	reg_definition
 |	scb_or_sram_reg_list reg_definition
@@ -619,11 +899,11 @@
 	}
 |	T_A
 	{
-		if (accumulator == NULL) {
+		if (accumulator.symbol == NULL) {
 			stop("No accumulator has been defined", EX_DATAERR);
 			/* NOTREACHED */
 		}
-		$$.symbol = accumulator;
+		$$.symbol = accumulator.symbol;
 		$$.offset = 0;
 	}
 ;
@@ -644,11 +924,21 @@
 immediate_or_a:
 	expression
 	{
+		if ($1.value == 0 && is_download_const(&$1) == 0) {
+			snprintf(errbuf, sizeof(errbuf),
+				 "\nExpression evaluates to 0 and thus "
+				 "references the accumulator.\n "
+				 "If this is the desired effect, use 'A' "
+				 "instead.\n");
+			stop(errbuf, EX_DATAERR);
+		}
 		$$ = $1;
 	}
 |	T_A
 	{
 		SLIST_INIT(&$$.referenced_syms);
+		symlist_add(&$$.referenced_syms, accumulator.symbol,
+			    SYMLIST_INSERT_HEAD);
 		$$.value = 0;
 	}
 ;
@@ -676,8 +966,22 @@
 	{ $$ = 1; }
 ;
 
+set_src_mode:
+	T_SET_SRC_MODE T_NUMBER ';'
+	{
+		src_mode = $2;
+	}
+;
+
+set_dst_mode:
+	T_SET_DST_MODE T_NUMBER ';'
+	{
+		dst_mode = $2;
+	}
+;
+
 critical_section_start:
-	T_BEGIN_CS
+	T_BEGIN_CS ';'
 	{
 		critical_section_t *cs;
 
@@ -690,9 +994,10 @@
 		cs->begin_addr = instruction_ptr;
 		in_critical_section = TRUE;
 	}
+;
 
 critical_section_end:
-	T_END_CS
+	T_END_CS ';'
 	{
 		critical_section_t *cs;
 
@@ -704,17 +1009,25 @@
 		cs->end_addr = instruction_ptr;
 		in_critical_section = FALSE;
 	}
+;
+
+export:
+	{ $$ = 0; }
+|	T_EXPORT
+	{ $$ = 1; }
+;
 
 label:
-	T_SYMBOL ':'
+	export T_SYMBOL ':'
 	{
-		if ($1->type != UNINITIALIZED) {
+		if ($2->type != UNINITIALIZED) {
 			stop("Program label multiply defined", EX_DATAERR);
 			/* NOTREACHED */
 		}
-		$1->type = LABEL;
-		initialize_symbol($1);
-		$1->info.linfo->address = instruction_ptr;
+		$2->type = LABEL;
+		initialize_symbol($2);
+		$2->info.linfo->address = instruction_ptr;
+		$2->info.linfo->exported = $1;
 	}
 ;
 
@@ -927,9 +1240,22 @@
 ;
 
 code:
-	T_MVI destination ',' immediate_or_a ret ';'
+	T_MVI destination ',' immediate ret ';'
 	{
-		format_1_instr(AIC_OP_OR, &$2, &$4, &allzeros, $5);
+		if ($4.value == 0
+		 && is_download_const(&$4) == 0) {
+			expression_t immed;
+
+			/*
+			 * Allow move immediates of 0 so that macros,
+			 * that can't know the immediate's value and
+			 * otherwise compensate, still work.
+			 */
+			make_expression(&immed, 1);
+			format_1_instr(AIC_OP_BMOV, &$2, &immed, &allzeros, $5);
+		} else {
+			format_1_instr(AIC_OP_OR, &$2, &$4, &allzeros, $5);
+		}
 	}
 ;
 
@@ -1064,7 +1390,7 @@
 %%
 
 static void
-process_bitmask(int mask_type, symbol_t *sym, int mask)
+process_field(int field_type, symbol_t *sym, int value)
 {
 	/*
 	 * Add the current register to its
@@ -1074,52 +1400,54 @@
 	 * the "allowed bits" of this register.
 	 */
 	if (sym->type == UNINITIALIZED) {
-		sym->type = mask_type;
+		sym->type = field_type;
 		initialize_symbol(sym);
-		if (mask_type == BIT) {
-			if (mask == 0) {
-				stop("Bitmask with no bits set", EX_DATAERR);
-				/* NOTREACHED */
-			}
-			if ((mask & ~(0x01 << (ffs(mask) - 1))) != 0) {
-				stop("Bitmask with more than one bit set",
-				     EX_DATAERR);
+		sym->info.finfo->value = value;
+		if (field_type != ENUM_ENTRY) {
+			if (field_type != MASK && value == 0) {
+				stop("Empty Field, or Enum", EX_DATAERR);
 				/* NOTREACHED */
 			}
+			sym->info.finfo->value = value;
+			sym->info.finfo->mask = value;
+		} else if (field_symbol != NULL) {
+			sym->info.finfo->mask = field_symbol->info.finfo->value;
+		} else {
+			sym->info.finfo->mask = 0xFF;
 		}
-		sym->info.minfo->mask = mask;
-	} else if (sym->type != mask_type) {
-		stop("Bit definition mirrors a definition of the same "
+	} else if (sym->type != field_type) {
+		stop("Field definition mirrors a definition of the same "
 		     " name, but a different type", EX_DATAERR);
 		/* NOTREACHED */
-	} else if (mask != sym->info.minfo->mask) {
-		stop("Bitmask redefined with a conflicting value", EX_DATAERR);
+	} else if (value != sym->info.finfo->value) {
+		stop("Field redefined with a conflicting value", EX_DATAERR);
 		/* NOTREACHED */
 	}
 	/* Fail if this symbol is already listed */
-	if (symlist_search(&(sym->info.minfo->symrefs),
+	if (symlist_search(&(sym->info.finfo->symrefs),
 			   cur_symbol->name) != NULL) {
-		stop("Bitmask defined multiple times for register", EX_DATAERR);
+		stop("Field defined multiple times for register", EX_DATAERR);
 		/* NOTREACHED */
 	}
-	symlist_add(&(sym->info.minfo->symrefs), cur_symbol,
+	symlist_add(&(sym->info.finfo->symrefs), cur_symbol,
 		    SYMLIST_INSERT_HEAD);
-	cur_symbol->info.rinfo->valid_bitmask |= mask;
+	cur_symbol->info.rinfo->valid_bitmask |= sym->info.finfo->mask;
 	cur_symbol->info.rinfo->typecheck_masks = TRUE;
+	symlist_add(&(cur_symbol->info.rinfo->fields), sym, SYMLIST_SORT);
 }
 
 static void
 initialize_symbol(symbol_t *symbol)
 {
 	switch (symbol->type) {
-        case UNINITIALIZED:
+	case UNINITIALIZED:
 		stop("Call to initialize_symbol with type field unset",
 		     EX_SOFTWARE);
 		/* NOTREACHED */
 		break;
-        case REGISTER:
-        case SRAMLOC:
-        case SCBLOC:
+	case REGISTER:
+	case SRAMLOC:
+	case SCBLOC:
 		symbol->info.rinfo =
 		    (struct reg_info *)malloc(sizeof(struct reg_info));
 		if (symbol->info.rinfo == NULL) {
@@ -1128,8 +1456,19 @@
 		}
 		memset(symbol->info.rinfo, 0,
 		       sizeof(struct reg_info));
+		SLIST_INIT(&(symbol->info.rinfo->fields));
+		/*
+		 * Default to allowing access in all register modes
+		 * or to the mode specified by the SCB or SRAM space
+		 * we are in.
+		 */
+		if (scb_or_sram_symbol != NULL)
+			symbol->info.rinfo->modes =
+			    scb_or_sram_symbol->info.rinfo->modes;
+		else
+			symbol->info.rinfo->modes = ~0;
 		break;
-        case ALIAS:
+	case ALIAS:
 		symbol->info.ainfo =
 		    (struct alias_info *)malloc(sizeof(struct alias_info));
 		if (symbol->info.ainfo == NULL) {
@@ -1139,19 +1478,21 @@
 		memset(symbol->info.ainfo, 0,
 		       sizeof(struct alias_info));
 		break;
-        case MASK:
-        case BIT:
-		symbol->info.minfo =
-		    (struct mask_info *)malloc(sizeof(struct mask_info));
-		if (symbol->info.minfo == NULL) {
-			stop("Can't create bitmask info", EX_SOFTWARE);
+	case MASK:
+	case FIELD:
+	case ENUM:
+	case ENUM_ENTRY:
+		symbol->info.finfo =
+		    (struct field_info *)malloc(sizeof(struct field_info));
+		if (symbol->info.finfo == NULL) {
+			stop("Can't create field info", EX_SOFTWARE);
 			/* NOTREACHED */
 		}
-		memset(symbol->info.minfo, 0, sizeof(struct mask_info));
-		SLIST_INIT(&(symbol->info.minfo->symrefs));
+		memset(symbol->info.finfo, 0, sizeof(struct field_info));
+		SLIST_INIT(&(symbol->info.finfo->symrefs));
 		break;
-        case CONST:
-        case DOWNLOAD_CONST:
+	case CONST:
+	case DOWNLOAD_CONST:
 		symbol->info.cinfo =
 		    (struct const_info *)malloc(sizeof(struct const_info));
 		if (symbol->info.cinfo == NULL) {
@@ -1181,6 +1522,17 @@
 		memset(symbol->info.condinfo, 0,
 		       sizeof(struct cond_info));
 		break;
+	case MACRO:
+		symbol->info.macroinfo = 
+		    (struct macro_info *)malloc(sizeof(struct macro_info));
+		if (symbol->info.macroinfo == NULL) {
+			stop("Can't create macro info", EX_SOFTWARE);
+			/* NOTREACHED */
+		}
+		memset(symbol->info.macroinfo, 0,
+		       sizeof(struct macro_info));
+		STAILQ_INIT(&symbol->info.macroinfo->args);
+		break;
 	default:
 		stop("Call to initialize_symbol with invalid symbol type",
 		     EX_SOFTWARE);
@@ -1190,25 +1542,75 @@
 }
 
 static void
+add_macro_arg(const char *argtext, int argnum)
+{
+	struct macro_arg *marg;
+	int i;
+	int retval;
+		
+
+	if (cur_symbol == NULL || cur_symbol->type != MACRO) {
+		stop("Invalid current symbol for adding macro arg",
+		     EX_SOFTWARE);
+		/* NOTREACHED */
+	}
+
+	marg = (struct macro_arg *)malloc(sizeof(*marg));
+	if (marg == NULL) {
+		stop("Can't create macro_arg structure", EX_SOFTWARE);
+		/* NOTREACHED */
+	}
+	marg->replacement_text = NULL;
+	retval = snprintf(regex_pattern, sizeof(regex_pattern),
+			  "[^-/A-Za-z0-9_](%s)([^-/A-Za-z0-9_]|$)",
+			  argtext);
+	if (retval >= sizeof(regex_pattern)) {
+		stop("Regex text buffer too small for arg",
+		     EX_SOFTWARE);
+		/* NOTREACHED */
+	}
+	retval = regcomp(&marg->arg_regex, regex_pattern, REG_EXTENDED);
+	if (retval != 0) {
+		stop("Regex compilation failed", EX_SOFTWARE);
+		/* NOTREACHED */
+	}
+	STAILQ_INSERT_TAIL(&cur_symbol->info.macroinfo->args, marg, links);
+}
+
+static void
+add_macro_body(const char *bodytext)
+{
+	if (cur_symbol == NULL || cur_symbol->type != MACRO) {
+		stop("Invalid current symbol for adding macro arg",
+		     EX_SOFTWARE);
+		/* NOTREACHED */
+	}
+	cur_symbol->info.macroinfo->body = strdup(bodytext);
+	if (cur_symbol->info.macroinfo->body == NULL) {
+		stop("Can't duplicate macro body text", EX_SOFTWARE);
+		/* NOTREACHED */
+	}
+}
+
+static void
 process_register(symbol_t **p_symbol)
 {
-	char buf[255];
 	symbol_t *symbol = *p_symbol;
 
 	if (symbol->type == UNINITIALIZED) {
-		snprintf(buf, sizeof(buf), "Undefined register %s",
+		snprintf(errbuf, sizeof(errbuf), "Undefined register %s",
 			 symbol->name);
-		stop(buf, EX_DATAERR);
+		stop(errbuf, EX_DATAERR);
 		/* NOTREACHED */
 	} else if (symbol->type == ALIAS) {
 		*p_symbol = symbol->info.ainfo->parent;
 	} else if ((symbol->type != REGISTER)
 		&& (symbol->type != SCBLOC)
 		&& (symbol->type != SRAMLOC)) {
-		snprintf(buf, sizeof(buf),
+		snprintf(errbuf, sizeof(errbuf),
 			 "Specified symbol %s is not a register",
 			 symbol->name);
-		stop(buf, EX_DATAERR);
+		stop(errbuf, EX_DATAERR);
 	}
 }
 
@@ -1242,7 +1644,47 @@
 
 	if (is_download_const(immed))
 		f1_instr->parity = 1;
+	else if (dest->symbol == mode_ptr.symbol) {
+		u_int src_value;
+		u_int dst_value;
+
+		/*
+		 * Attempt to update mode information if
+		 * we are operating on the mode register.
+		 */
+		if (src->symbol == allones.symbol)
+			src_value = 0xFF;
+		else if (src->symbol == allzeros.symbol)
+			src_value = 0;
+		else if (src->symbol == mode_ptr.symbol)
+			src_value = (dst_mode << 4) | src_mode;
+		else
+			goto cant_update;
 
+		switch (opcode) {
+		case AIC_OP_AND:
+			dst_value = src_value & immed->value;
+			break;
+		case AIC_OP_XOR:
+			dst_value = src_value ^ immed->value;
+			break;
+		case AIC_OP_ADD:
+			dst_value = (src_value + immed->value) & 0xFF;
+			break;
+		case AIC_OP_OR:
+			dst_value = src_value | immed->value;
+			break;
+		case AIC_OP_BMOV:
+			dst_value = src_value;
+			break;
+		default:
+			goto cant_update;
+		}
+		src_mode = dst_value & 0xF;
+		dst_mode = (dst_value >> 4) & 0xF;
+	}
+
+cant_update:
 	symlist_free(&immed->referenced_syms);
 	instruction_ptr++;
 }
@@ -1350,6 +1792,14 @@
 static void
 test_readable_symbol(symbol_t *symbol)
 {
+	
+	if ((symbol->info.rinfo->modes & (0x1 << src_mode)) == 0) {
+		snprintf(errbuf, sizeof(errbuf),
+			"Register %s unavailable in source reg mode %d",
+			symbol->name, src_mode);
+		stop(errbuf, EX_DATAERR);
+	}
+
 	if (symbol->info.rinfo->mode == WO) {
 		stop("Write Only register specified as source",
 		     EX_DATAERR);
@@ -1360,6 +1810,14 @@
 static void
 test_writable_symbol(symbol_t *symbol)
 {
+	
+	if ((symbol->info.rinfo->modes & (0x1 << dst_mode)) == 0) {
+		snprintf(errbuf, sizeof(errbuf),
+			"Register %s unavailable in destination reg mode %d",
+			symbol->name, dst_mode);
+		stop(errbuf, EX_DATAERR);
+	}
+
 	if (symbol->info.rinfo->mode == RO) {
 		stop("Read Only register specified as destination",
 		     EX_DATAERR);
@@ -1372,7 +1830,6 @@
 {
 	symbol_node_t *node;
 	int and_op;
-	char buf[255];
 
 	and_op = FALSE;
 	if (opcode == AIC_OP_AND || opcode == AIC_OP_JNZ || AIC_OP_JZ)
@@ -1385,11 +1842,11 @@
 	 */
 	if (and_op == FALSE
 	 && (expression->value & ~symbol->info.rinfo->valid_bitmask) != 0) {
-		snprintf(buf, sizeof(buf),
+		snprintf(errbuf, sizeof(errbuf),
 			 "Invalid bit(s) 0x%x in immediate written to %s",
 			 expression->value & ~symbol->info.rinfo->valid_bitmask,
 			 symbol->name);
-		stop(buf, EX_DATAERR);
+		stop(errbuf, EX_DATAERR);
 		/* NOTREACHED */
 	}
 
@@ -1397,19 +1854,21 @@
 	 * Now make sure that all of the symbols referenced by the
 	 * expression are defined for this register.
 	 */
-	if(symbol->info.rinfo->typecheck_masks != FALSE) {
+	if (symbol->info.rinfo->typecheck_masks != FALSE) {
 		for(node = expression->referenced_syms.slh_first;
 		    node != NULL;
 		    node = node->links.sle_next) {
 			if ((node->symbol->type == MASK
-			  || node->symbol->type == BIT)
-			 && symlist_search(&node->symbol->info.minfo->symrefs,
+			  || node->symbol->type == FIELD
+			  || node->symbol->type == ENUM
+			  || node->symbol->type == ENUM_ENTRY)
+			 && symlist_search(&node->symbol->info.finfo->symrefs,
 					   symbol->name) == NULL) {
-				snprintf(buf, sizeof(buf),
-					 "Invalid bit or mask %s "
+				snprintf(errbuf, sizeof(errbuf),
+					 "Invalid field or mask %s "
 					 "for register %s",
 					 node->symbol->name, symbol->name);
-				stop(buf, EX_DATAERR);
+				stop(errbuf, EX_DATAERR);
 				/* NOTREACHED */
 			}
 		}
diff -Nru a/drivers/scsi/aic7xxx/aicasm/aicasm_insformat.h b/drivers/scsi/aic7xxx/aicasm/aicasm_insformat.h
--- a/drivers/scsi/aic7xxx/aicasm/aicasm_insformat.h	Mon Dec 23 21:22:00 2002
+++ b/drivers/scsi/aic7xxx/aicasm/aicasm_insformat.h	Mon Dec 23 21:22:00 2002
@@ -37,9 +37,9 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_insformat.h#7 $
+ * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_insformat.h#11 $
  *
- * $FreeBSD: src/sys/dev/aic7xxx/aicasm/aicasm_insformat.h,v 1.3 2000/09/22 22:19:54 gibbs Exp $
+ * $FreeBSD$
  */
 
 struct ins_format1 {
diff -Nru a/drivers/scsi/aic7xxx/aicasm/aicasm_macro_gram.y b/drivers/scsi/aic7xxx/aicasm/aicasm_macro_gram.y
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aicasm/aicasm_macro_gram.y	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,164 @@
+%{
+/*
+ * Sub-parser for macro invocation in the Aic7xxx SCSI
+ * Host adapter sequencer assembler.
+ *
+ * Copyright (c) 2001 Adaptec Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_macro_gram.y#5 $
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/types.h>
+
+#include <inttypes.h>
+#include <regex.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysexits.h>
+
+#ifdef __linux__
+#include "../queue.h"
+#else
+#include <sys/queue.h>
+#endif
+
+#include "aicasm.h"
+#include "aicasm_symbol.h"
+#include "aicasm_insformat.h"
+
+static symbol_t *macro_symbol;
+
+static void add_macro_arg(const char *argtext, int position);
+
+%}
+
+%union {
+	int		value;
+	char		*str;
+	symbol_t	*sym;
+}
+
+
+%token <str> T_ARG
+
+%token <sym> T_SYMBOL
+
+%type <value> macro_arglist
+
+%%
+
+macrocall:
+	T_SYMBOL '('
+	{
+		macro_symbol = $1;
+	}
+	macro_arglist ')'
+	{
+		if (macro_symbol->info.macroinfo->narg != $4) {
+			printf("Narg == %d", macro_symbol->info.macroinfo->narg);
+			stop("Too few arguments for macro invocation",
+			     EX_DATAERR);
+			/* NOTREACHED */
+		}
+		macro_symbol = NULL;
+		YYACCEPT;
+	}
+;
+
+macro_arglist:
+	{
+		/* Macros can take 0 arguments */
+		$$ = 0;
+	}
+|	T_ARG
+	{
+		$$ = 1;
+		add_macro_arg($1, 1);
+	}
+|	macro_arglist ',' T_ARG
+	{
+		if ($1 == 0) {
+			stop("Comma without preceeding argument in arg list",
+			     EX_DATAERR);
+			/* NOTREACHED */
+		}
+		$$ = $1 + 1;
+		add_macro_arg($3, $$);
+	}
+;
+
+%%
+
+static void
+add_macro_arg(const char *argtext, int argnum)
+{
+	struct macro_arg *marg;
+	int i;
+
+	if (macro_symbol == NULL || macro_symbol->type != MACRO) {
+		stop("Invalid current symbol for adding macro arg",
+		     EX_SOFTWARE);
+		/* NOTREACHED */
+	}
+	/*
+	 * Macro Invocation.  Find the appropriate argument and fill
+	 * in the replace ment text for this call.
+	 */
+	i = 0;
+	STAILQ_FOREACH(marg, &macro_symbol->info.macroinfo->args, links) {
+		i++;
+		if (i == argnum)
+			break;
+	}
+	if (marg == NULL) {
+		stop("Too many arguments for macro invocation", EX_DATAERR);
+		/* NOTREACHED */
+	}
+	marg->replacement_text = strdup(argtext);
+	if (marg->replacement_text == NULL) {
+		stop("Unable to replicate replacement text", EX_SOFTWARE);
+		/* NOTREACHED */
+	}
+}
+
+void
+mmerror(const char *string)
+{
+	stop(string, EX_DATAERR);
+}
diff -Nru a/drivers/scsi/aic7xxx/aicasm/aicasm_macro_scan.l b/drivers/scsi/aic7xxx/aicasm/aicasm_macro_scan.l
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aicasm/aicasm_macro_scan.l	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,155 @@
+%{
+/*
+ * Sub-Lexical Analyzer for macro invokation in 
+ * the Aic7xxx SCSI Host adapter sequencer assembler.
+ *
+ * Copyright (c) 2001 Adaptec Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_macro_scan.l#7 $
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/types.h>
+
+#include <inttypes.h>
+#include <limits.h>
+#include <regex.h>
+#include <stdio.h>
+#include <string.h>
+#include <sysexits.h>
+#ifdef __linux__
+#include "../queue.h"
+#else
+#include <sys/queue.h>
+#endif
+
+#include "aicasm.h"
+#include "aicasm_symbol.h"
+#include "aicasm_macro_gram.h"
+
+#define MAX_STR_CONST 4096
+static char string_buf[MAX_STR_CONST];
+static char *string_buf_ptr;
+static int  parren_count;
+static char buf[255];
+%}
+
+WORD		[A-Za-z_][-A-Za-z_0-9]*
+SPACE		[ \t]+
+MCARG		[^(), \t]+
+
+%x ARGLIST
+
+%%
+\n			{
+				++yylineno;
+			}
+<ARGLIST>{SPACE}	;
+<ARGLIST>\(		{
+				parren_count++;
+				if (parren_count == 1) {
+					string_buf_ptr = string_buf;
+					return ('(');
+				}
+				*string_buf_ptr++ = '(';
+			}
+<ARGLIST>\)		{
+				if (parren_count == 1) {
+					if (string_buf_ptr != string_buf) {
+						/*
+						 * Return an argument and
+						 * rescan this parren so we
+						 * can return it as well.
+						 */
+						*string_buf_ptr = '\0';
+						mmlval.str = string_buf;
+						string_buf_ptr = string_buf;
+						unput(')');
+						return T_ARG;
+					}
+					BEGIN INITIAL;
+					return (')');
+				}
+				parren_count--;
+				*string_buf_ptr++ = ')';
+			}
+<ARGLIST>{MCARG}	{
+				char *yptr;
+
+				yptr = mmtext;
+				while (*yptr)
+					*string_buf_ptr++ = *yptr++;
+			}
+<ARGLIST>\,		{
+				if (string_buf_ptr != string_buf) {
+					/*
+					 * Return an argument and
+					 * rescan this comma so we
+					 * can return it as well.
+					 */
+					*string_buf_ptr = '\0';
+					mmlval.str = string_buf;
+					string_buf_ptr = string_buf;
+					unput(',');
+					return T_ARG;
+				}
+				return ',';
+			}
+{WORD}[(]		{
+				/* May be a symbol or a macro invocation. */
+				mmlval.sym = symtable_get(mmtext);
+				if (mmlval.sym->type != MACRO) {
+					stop("Expecting Macro Name",
+					     EX_DATAERR);
+				}
+				unput('(');
+				parren_count = 0;
+				BEGIN ARGLIST;
+				return T_SYMBOL;
+			}
+.			{ 
+				snprintf(buf, sizeof(buf), "Invalid character "
+					 "'%c'", mmtext[0]);
+				stop(buf, EX_DATAERR);
+			}
+%%
+
+int
+mmwrap()
+{
+	stop("EOF encountered in macro call", EX_DATAERR);
+}
diff -Nru a/drivers/scsi/aic7xxx/aicasm/aicasm_scan.l b/drivers/scsi/aic7xxx/aicasm/aicasm_scan.l
--- a/drivers/scsi/aic7xxx/aicasm/aicasm_scan.l	Mon Dec 23 21:21:59 2002
+++ b/drivers/scsi/aic7xxx/aicasm/aicasm_scan.l	Mon Dec 23 21:21:59 2002
@@ -3,7 +3,7 @@
  * Lexical Analyzer for the Aic7xxx SCSI Host adapter sequencer assembler.
  *
  * Copyright (c) 1997, 1998, 2000 Justin T. Gibbs.
- * Copyright (c) 2001 Adaptec Inc.
+ * Copyright (c) 2001, 2002 Adaptec Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -38,14 +38,16 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_scan.l#7 $
+ * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_scan.l#18 $
  *
- * $FreeBSD: src/sys/dev/aic7xxx/aicasm/aicasm_scan.l,v 1.13 2000/09/22 22:19:54 gibbs Exp $
+ * $FreeBSD$
  */
 
 #include <sys/types.h>
 
+#include <inttypes.h>
 #include <limits.h>
+#include <regex.h>
 #include <stdio.h>
 #include <string.h>
 #include <sysexits.h>
@@ -57,23 +59,31 @@
 
 #include "aicasm.h"
 #include "aicasm_symbol.h"
-#include "y.tab.h"
+#include "aicasm_gram.h"
 
-#define MAX_STR_CONST 256
-char string_buf[MAX_STR_CONST];
-char *string_buf_ptr;
-int  parren_count;
-int  quote_count;
+/* This is used for macro body capture too, so err on the large size. */
+#define MAX_STR_CONST 4096
+static char string_buf[MAX_STR_CONST];
+static char *string_buf_ptr;
+static int  parren_count;
+static int  quote_count;
+static char buf[255];
 %}
 
-PATH		[-/A-Za-z0-9_.]*[./][-/A-Za-z0-9_.]*
+PATH		([/]*[-A-Za-z0-9_.])+
 WORD		[A-Za-z_][-A-Za-z_0-9]*
 SPACE		[ \t]+
+MCARG		[^(), \t]+
+MBODY		((\\[^\n])*[^\n\\]*)+
 
 %x COMMENT
 %x CEXPR
 %x INCLUDE
 %x STRING
+%x MACRODEF
+%x MACROARGLIST
+%x MACROCALLARGS
+%x MACROBODY
 
 %%
 \n			{ ++yylineno; }
@@ -122,6 +132,8 @@
 			}
 
 VERSION			{ return T_VERSION; }
+PREFIX			{ return T_PREFIX; }
+PATCH_ARG_LIST		{ return T_PATCH_ARG_LIST; }
 \"			{
 				string_buf_ptr = string_buf;
 				BEGIN STRING;
@@ -140,14 +152,16 @@
 				yylval.str = string_buf;
 				return T_STRING;
 			}
-{SPACE}			;
+{SPACE}			 ;
 
 	/* Register/SCB/SRAM definition keywords */
+export			{ return T_EXPORT; }
 register		{ return T_REGISTER; }
 const			{ yylval.value = FALSE; return T_CONST; }
 download		{ return T_DOWNLOAD; }
 address			{ return T_ADDRESS; }
 access_mode		{ return T_ACCESS_MODE; }
+modes			{ return T_MODES; }
 RW|RO|WO		{
 				 if (strcmp(yytext, "RW") == 0)
 					yylval.value = RW;
@@ -159,13 +173,17 @@
 			}
 BEGIN_CRITICAL		{ return T_BEGIN_CS; }
 END_CRITICAL		{ return T_END_CS; }
-bit			{ return T_BIT; }
+SET_SRC_MODE		{ return T_SET_SRC_MODE; }
+SET_DST_MODE		{ return T_SET_DST_MODE; }
+field			{ return T_FIELD; }
+enum			{ return T_ENUM; }
 mask			{ return T_MASK; }
 alias			{ return T_ALIAS; }
 size			{ return T_SIZE; }
 scb			{ return T_SCB; }
 scratch_ram		{ return T_SRAM; }
 accumulator		{ return T_ACCUM; }
+mode_pointer		{ return T_MODE_PTR; }
 allones			{ return T_ALLONES; }
 allzeros		{ return T_ALLZEROS; }
 none			{ return T_NONE; }
@@ -206,7 +224,9 @@
 else			{ return T_ELSE; }
 
 	/* Allowed Symbols */
-[-+,:()~|&."{};<>[\]!=]	{ return yytext[0]; }
+\<\<			{ return T_EXPR_LSHIFT; }
+\>\>			{ return T_EXPR_RSHIFT; }
+[-+,:()~|&."{};<>[\]/*!=] { return yytext[0]; }
 
 	/* Number processing */
 0[0-7]*			{
@@ -223,7 +243,6 @@
 				yylval.value = strtol(yytext, NULL, 10);
 				return T_NUMBER;
 			}
-
 	/* Include Files */
 #include{SPACE}		{
 				BEGIN INCLUDE;
@@ -238,13 +257,7 @@
 				quote_count++;
 				return yytext[0];
 			}
-<INCLUDE>.		{ stop("Invalid include line", EX_DATAERR); }
-
-	/* For parsing C include files with #define foo */
-#define			{ yylval.value = TRUE; return T_CONST; }
-	/* Throw away macros */
-#define[^\n]*[()]+[^\n]* ;
-<INITIAL,INCLUDE>{PATH}	{
+<INCLUDE>{PATH}		{
 				char *yptr;
 
 				yptr = yytext;
@@ -255,12 +268,158 @@
 				*string_buf_ptr = '\0';
 				return T_PATH;
 			}
+<INCLUDE>.		{ stop("Invalid include line", EX_DATAERR); }
+#define{SPACE}		{
+				BEGIN MACRODEF;
+				return T_DEFINE;
+			}
+<MACRODEF>{WORD}{SPACE}	{ 
+				char *yptr;
 
-{WORD}			{ yylval.sym = symtable_get(yytext);  return T_SYMBOL; }
+				/* Strip space and return as a normal symbol */
+				yptr = yytext;
+				while (*yptr != ' ' && *yptr != '\t')
+					yptr++;
+				*yptr = '\0';
+				yylval.sym = symtable_get(yytext);
+				string_buf_ptr = string_buf;
+				BEGIN MACROBODY;
+				return T_SYMBOL;
+			}
+<MACRODEF>{WORD}\(	{
+				/*
+				 * We store the symbol with its opening
+				 * parren so we can differentiate macros
+				 * that take args from macros with the
+				 * same name that do not take args as
+				 * is allowed in C.
+				 */
+				BEGIN MACROARGLIST;
+				yylval.sym = symtable_get(yytext);
+				unput('(');
+				return T_SYMBOL;
+			}
+<MACROARGLIST>{WORD}	{
+				yylval.str = yytext;
+				return T_ARG;
+			}
+<MACROARGLIST>{SPACE}   ;
+<MACROARGLIST>[(,]	{
+				return yytext[0];
+			}
+<MACROARGLIST>[)]	{
+				string_buf_ptr = string_buf;
+				BEGIN MACROBODY;
+				return ')';
+			}
+<MACROARGLIST>.		{
+				snprintf(buf, sizeof(buf), "Invalid character "
+					 "'%c' in macro argument list",
+					 yytext[0]);
+				stop(buf, EX_DATAERR);
+			}
+<MACROCALLARGS>{SPACE}  ;
+<MACROCALLARGS>\(	{
+				parren_count++;
+				if (parren_count == 1)
+					return ('(');
+				*string_buf_ptr++ = '(';
+			}
+<MACROCALLARGS>\)	{
+				parren_count--;
+				if (parren_count == 0) {
+					BEGIN INITIAL;
+					return (')');
+				}
+				*string_buf_ptr++ = ')';
+			}
+<MACROCALLARGS>{MCARG}	{
+				char *yptr;
 
-.			{ 
-				char buf[255];
+				yptr = yytext;
+				while (*yptr)
+					*string_buf_ptr++ = *yptr++;
+			}
+<MACROCALLARGS>\,	{
+				if (string_buf_ptr != string_buf) {
+					/*
+					 * Return an argument and
+					 * rescan this comma so we
+					 * can return it as well.
+					 */
+					*string_buf_ptr = '\0';
+					yylval.str = string_buf;
+					string_buf_ptr = string_buf;
+					unput(',');
+					return T_ARG;
+				}
+				return ',';
+			}
+<MACROBODY>\\\n		{
+				/* Eat escaped newlines. */
+				++yylineno;
+			}
+<MACROBODY>\n		{
+				/* Macros end on the first unescaped newline. */
+				BEGIN INITIAL;
+				*string_buf_ptr = '\0';
+				yylval.str = string_buf;
+				++yylineno;
+				return T_MACROBODY;
+			}
+<MACROBODY>{MBODY}	{
+				char *yptr;
+
+				yptr = yytext;
+				while (*yptr)
+					*string_buf_ptr++ = *yptr++;
+			}
+{WORD}\(		{
+				char *yptr;
+				char *ycopy;
 
+				/* May be a symbol or a macro invocation. */
+				yylval.sym = symtable_get(yytext);
+				if (yylval.sym->type == MACRO) {
+					YY_BUFFER_STATE old_state;
+					YY_BUFFER_STATE temp_state;
+
+					ycopy = strdup(yytext);
+					yptr = ycopy + yyleng;
+					while (yptr > ycopy)
+						unput(*--yptr);
+					old_state = YY_CURRENT_BUFFER;
+					temp_state =
+					    yy_create_buffer(stdin,
+							     YY_BUF_SIZE);
+					yy_switch_to_buffer(temp_state);
+					mm_switch_to_buffer(old_state);
+					mmparse();
+					mm_switch_to_buffer(temp_state);
+					yy_switch_to_buffer(old_state);
+					mm_delete_buffer(temp_state);
+					expand_macro(yylval.sym);
+				} else {
+					if (yylval.sym->type == UNINITIALIZED) {
+						/* Try without the '(' */
+						symbol_delete(yylval.sym);
+						yytext[yyleng-1] = '\0';
+						yylval.sym =
+						    symtable_get(yytext);
+					}
+					unput('(');
+					return T_SYMBOL;
+				}
+			}
+{WORD}			{
+				yylval.sym = symtable_get(yytext);
+				if (yylval.sym->type == MACRO) {
+					expand_macro(yylval.sym);
+				} else {
+					return T_SYMBOL;
+				}
+			}
+.			{ 
 				snprintf(buf, sizeof(buf), "Invalid character "
 					 "'%c'", yytext[0]);
 				stop(buf, EX_DATAERR);
@@ -327,6 +486,92 @@
 	yy_switch_to_buffer(yy_create_buffer(newfile, YY_BUF_SIZE));
 	yylineno = 1;
 	yyfilename = strdup(file_name);
+}
+
+static void next_substitution(struct symbol *mac_symbol, const char *body_pos,
+			      const char **next_match,
+			      struct macro_arg **match_marg, regmatch_t *match);
+
+void
+expand_macro(struct symbol *macro_symbol)
+{
+	struct macro_arg *marg;
+	struct macro_arg *match_marg;
+	const char *body_head;
+	const char *body_pos;
+	const char *next_match;
+
+	/*
+	 * Due to the nature of unput, we must work
+	 * backwards through the macro body performing
+	 * any expansions.
+	 */
+	body_head = macro_symbol->info.macroinfo->body;
+	body_pos = body_head + strlen(body_head);
+	while (body_pos > body_head) {
+		regmatch_t match;
+
+		next_match = body_head;
+		match_marg = NULL;
+		next_substitution(macro_symbol, body_pos, &next_match,
+				  &match_marg, &match);
+
+		/* Put back everything up until the replacement. */
+		while (body_pos > next_match)
+			unput(*--body_pos);
+
+		/* Perform the replacement. */
+		if (match_marg != NULL) {
+			const char *strp;
+
+			next_match = match_marg->replacement_text;
+			strp = next_match + strlen(next_match);
+			while (strp > next_match)
+				unput(*--strp);
+
+			/* Skip past the unexpanded macro arg. */
+			body_pos -= match.rm_eo - match.rm_so;
+		}
+	}
+
+	/* Cleanup replacement text. */
+	STAILQ_FOREACH(marg, &macro_symbol->info.macroinfo->args, links) {
+		free(marg->replacement_text);
+	}
+}
+
+/*
+ * Find the next substitution in the macro working backwards from
+ * body_pos until the beginning of the macro buffer.  next_match
+ * should be initialized to the beginning of the macro buffer prior
+ * to calling this routine.
+ */
+static void
+next_substitution(struct symbol *mac_symbol, const char *body_pos,
+		  const char **next_match, struct macro_arg **match_marg,
+		  regmatch_t *match)
+{
+	regmatch_t	  matches[2];
+	struct macro_arg *marg;
+	const char	 *search_pos;
+	int		  retval;
+
+	do {
+		search_pos = *next_match;
+
+		STAILQ_FOREACH(marg, &mac_symbol->info.macroinfo->args, links) {
+
+			retval = regexec(&marg->arg_regex, search_pos, 2,
+					 matches, 0);
+			if (retval == 0
+			 && (matches[1].rm_eo + search_pos) <= body_pos
+			 && (matches[1].rm_eo + search_pos) > *next_match) {
+				*match = matches[1];
+				*next_match = match->rm_eo + search_pos;
+				*match_marg = marg;
+			}
+		}
+	} while (search_pos != *next_match);
 }
 
 int
diff -Nru a/drivers/scsi/aic7xxx/aicasm/aicasm_symbol.c b/drivers/scsi/aic7xxx/aicasm/aicasm_symbol.c
--- a/drivers/scsi/aic7xxx/aicasm/aicasm_symbol.c	Mon Dec 23 21:22:01 2002
+++ b/drivers/scsi/aic7xxx/aicasm/aicasm_symbol.c	Mon Dec 23 21:22:01 2002
@@ -2,6 +2,7 @@
  * Aic7xxx SCSI host adapter firmware asssembler symbol table implementation
  *
  * Copyright (c) 1997 Justin T. Gibbs.
+ * Copyright (c) 2002 Adaptec Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -36,9 +37,9 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_symbol.c#9 $
+ * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_symbol.c#23 $
  *
- * $FreeBSD: src/sys/dev/aic7xxx/aicasm/aicasm_symbol.c,v 1.11 2000/09/22 22:19:54 gibbs Exp $
+ * $FreeBSD$
  */
 
 #include <sys/types.h>
@@ -49,6 +50,8 @@
 #include <db.h>
 #endif
 #include <fcntl.h>
+#include <inttypes.h>
+#include <regex.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -71,6 +74,8 @@
 	}
 	memset(new_symbol, 0, sizeof(*new_symbol));
 	new_symbol->name = strdup(name);
+	if (new_symbol->name == NULL)
+		 stop("Unable to strdup symbol name", EX_SOFTWARE);
 	new_symbol->type = UNINITIALIZED;
 	return (new_symbol);
 }
@@ -97,10 +102,12 @@
 			free(symbol->info.ainfo);
 		break;
 	case MASK:
-	case BIT:
-		if (symbol->info.minfo != NULL) {
-			symlist_free(&symbol->info.minfo->symrefs);
-			free(symbol->info.minfo);
+	case FIELD:
+	case ENUM:
+	case ENUM_ENTRY:
+		if (symbol->info.finfo != NULL) {
+			symlist_free(&symbol->info.finfo->symrefs);
+			free(symbol->info.finfo);
 		}
 		break;
 	case DOWNLOAD_CONST:
@@ -221,17 +228,19 @@
 	newnode->symbol = symbol;
 	if (how == SYMLIST_SORT) {
 		symbol_node_t *curnode;
-		int mask;
+		int field;
 
-		mask = FALSE;
+		field = FALSE;
 		switch(symbol->type) {
 		case REGISTER:
 		case SCBLOC:
 		case SRAMLOC:
 			break;
-		case BIT:
+		case FIELD:
 		case MASK:
-			mask = TRUE;
+		case ENUM:
+		case ENUM_ENTRY:
+			field = TRUE;
 			break;
 		default:
 			stop("symlist_add: Invalid symbol type for sorting",
@@ -241,9 +250,12 @@
 
 		curnode = SLIST_FIRST(symlist);
 		if (curnode == NULL
-		 || (mask && (curnode->symbol->info.minfo->mask >
-		              newnode->symbol->info.minfo->mask))
-		 || (!mask && (curnode->symbol->info.rinfo->address >
+		 || (field
+		  && (curnode->symbol->type > newnode->symbol->type
+		   || (curnode->symbol->type == newnode->symbol->type
+		    && (curnode->symbol->info.finfo->value >
+			newnode->symbol->info.finfo->value))))
+		 || (!field && (curnode->symbol->info.rinfo->address >
 		               newnode->symbol->info.rinfo->address))) {
 			SLIST_INSERT_HEAD(symlist, newnode, links);
 			return;
@@ -258,10 +270,14 @@
 				symbol_t *cursymbol;
 
 				cursymbol = SLIST_NEXT(curnode, links)->symbol;
-				if ((mask && (cursymbol->info.minfo->mask >
-				              symbol->info.minfo->mask))
-				 || (!mask &&(cursymbol->info.rinfo->address >
-				              symbol->info.rinfo->address))){
+				if ((field
+		  		  && (cursymbol->type > symbol->type
+				   || (cursymbol->type == symbol->type
+				    && (cursymbol->info.finfo->value >
+					symbol->info.finfo->value))))
+				 || (!field
+				   && (cursymbol->info.rinfo->address >
+				       symbol->info.rinfo->address))) {
 					SLIST_INSERT_AFTER(curnode, newnode,
 							   links);
 					break;
@@ -306,173 +322,356 @@
 }
 
 void
-symtable_dump(FILE *ofile)
+aic_print_file_prologue(FILE *ofile)
+{
+
+	if (ofile == NULL)
+		return;
+
+	fprintf(ofile,
+"/*\n"
+" * DO NOT EDIT - This file is automatically generated\n"
+" *		 from the following source files:\n"
+" *\n"
+"%s */\n",
+		versions);
+}
+
+void
+aic_print_include(FILE *dfile, char *include_file)
+{
+
+	if (dfile == NULL)
+		return;
+	fprintf(dfile, "\n#include \"%s\"\n\n", include_file);
+}
+
+void
+aic_print_reg_dump_types(FILE *ofile)
+{
+	if (ofile == NULL)
+		return;
+		
+	fprintf(ofile,
+"typedef int (%sreg_print_t)(u_int, u_int *, u_int);\n"
+"typedef struct %sreg_parse_entry {\n"
+"	char	*name;\n"
+"	uint8_t	 value;\n"
+"	uint8_t	 mask;\n"
+"} %sreg_parse_entry_t;\n"
+"\n",
+		prefix, prefix, prefix);
+}
+
+static void
+aic_print_reg_dump_start(FILE *dfile, symbol_node_t *regnode)
+{
+	if (dfile == NULL)
+		return;
+
+	fprintf(dfile,
+"static %sreg_parse_entry_t %s_parse_table[] = {\n",
+		prefix,
+		regnode->symbol->name);
+}
+
+static void
+aic_print_reg_dump_end(FILE *ofile, FILE *dfile,
+		       symbol_node_t *regnode, u_int num_entries)
+{
+	char *lower_name;
+	char *letter;
+
+	lower_name = strdup(regnode->symbol->name);
+	if (lower_name == NULL)
+		 stop("Unable to strdup symbol name", EX_SOFTWARE);
+	
+	for (letter = lower_name; *letter != '\0'; letter++)
+		*letter = tolower(*letter);
+
+	if (dfile != NULL) {
+		if (num_entries != 0)
+			fprintf(dfile,
+"\n"
+"};\n"
+"\n");
+
+		fprintf(dfile,
+"int\n"
+"%s%s_print(u_int regvalue, u_int *cur_col, u_int wrap)\n"
+"{\n"
+"	return (%sprint_register(%s%s, %d, \"%s\",\n"
+"	    0x%02x, regvalue, cur_col, wrap));\n"
+"}\n"
+"\n",
+			prefix,
+			lower_name,
+			prefix,
+			num_entries != 0 ? regnode->symbol->name : "NULL",
+			num_entries != 0 ? "_parse_table" : "",
+			num_entries,
+			regnode->symbol->name,
+			regnode->symbol->info.rinfo->address);
+	}
+
+	fprintf(ofile,
+"#if AIC_DEBUG_REGISTERS\n"
+"%sreg_print_t %s%s_print;\n"
+"#else\n"
+"#define %s%s_print(regvalue, cur_col, wrap) \\\n"
+"    %sprint_register(NULL, 0, \"%s\", 0x%02x, regvalue, cur_col, wrap)\n"
+"#endif\n"
+"\n",
+		prefix,
+		prefix,
+		lower_name,
+		prefix,
+		lower_name,
+		prefix,
+		regnode->symbol->name,
+		regnode->symbol->info.rinfo->address);
+}
+
+static void
+aic_print_reg_dump_entry(FILE *dfile, symbol_node_t *curnode)
+{
+	int num_tabs;
+
+	if (dfile == NULL)
+		return;
+
+	fprintf(dfile,
+"	{ \"%s\",",
+		curnode->symbol->name);
+
+	num_tabs = 3 - (strlen(curnode->symbol->name) + 5) / 8;
+
+	while (num_tabs-- > 0)
+		fputc('\t', dfile);
+	fprintf(dfile, "0x%02x, 0x%02x }",
+		curnode->symbol->info.finfo->value,
+		curnode->symbol->info.finfo->mask);
+}
+
+void
+symtable_dump(FILE *ofile, FILE *dfile)
 {
 	/*
 	 * Sort the registers by address with a simple insertion sort.
 	 * Put bitmasks next to the first register that defines them.
 	 * Put constants at the end.
 	 */
-	symlist_t registers;
-	symlist_t masks;
-	symlist_t constants;
-	symlist_t download_constants;
-	symlist_t aliases;
+	symlist_t	 registers;
+	symlist_t	 masks;
+	symlist_t	 constants;
+	symlist_t	 download_constants;
+	symlist_t	 aliases;
+	symlist_t	 exported_labels;
+	symbol_node_t	*curnode;
+	symbol_node_t	*regnode;
+	DBT		 key;
+	DBT		 data;
+	int		 flag;
+	u_int		 i;
+
+	if (symtable == NULL)
+		return;
 
 	SLIST_INIT(&registers);
 	SLIST_INIT(&masks);
 	SLIST_INIT(&constants);
 	SLIST_INIT(&download_constants);
 	SLIST_INIT(&aliases);
+	SLIST_INIT(&exported_labels);
+	flag = R_FIRST;
+	while (symtable->seq(symtable, &key, &data, flag) == 0) {
+		symbol_t *cursym;
 
-	if (symtable != NULL) {
-		DBT	 key;
-		DBT	 data;
-		int	 flag = R_FIRST;
+		memcpy(&cursym, data.data, sizeof(cursym));
+		switch(cursym->type) {
+		case REGISTER:
+		case SCBLOC:
+		case SRAMLOC:
+			symlist_add(&registers, cursym, SYMLIST_SORT);
+			break;
+		case MASK:
+		case FIELD:
+		case ENUM:
+		case ENUM_ENTRY:
+			symlist_add(&masks, cursym, SYMLIST_SORT);
+			break;
+		case CONST:
+			symlist_add(&constants, cursym,
+				    SYMLIST_INSERT_HEAD);
+			break;
+		case DOWNLOAD_CONST:
+			symlist_add(&download_constants, cursym,
+				    SYMLIST_INSERT_HEAD);
+			break;
+		case ALIAS:
+			symlist_add(&aliases, cursym,
+				    SYMLIST_INSERT_HEAD);
+			break;
+		case LABEL:
+			if (cursym->info.linfo->exported == 0)
+				break;
+			symlist_add(&exported_labels, cursym,
+				    SYMLIST_INSERT_HEAD);
+			break;
+		default:
+			break;
+		}
+		flag = R_NEXT;
+	}
 
-		while (symtable->seq(symtable, &key, &data, flag) == 0) {
-			symbol_t *cursym;
+	/* Register dianostic functions/declarations first. */
+	aic_print_file_prologue(ofile);
+	aic_print_reg_dump_types(ofile);
+	aic_print_file_prologue(dfile);
+	aic_print_include(dfile, stock_include_file);
+	SLIST_FOREACH(curnode, &registers, links) {
 
-			memcpy(&cursym, data.data, sizeof(cursym));
-			switch(cursym->type) {
-			case REGISTER:
-			case SCBLOC:
-			case SRAMLOC:
-				symlist_add(&registers, cursym, SYMLIST_SORT);
-				break;
-			case MASK:
-			case BIT:
-				symlist_add(&masks, cursym, SYMLIST_SORT);
-				break;
-			case CONST:
-				if (cursym->info.cinfo->define == FALSE) {
-					symlist_add(&constants, cursym,
-						    SYMLIST_INSERT_HEAD);
-				}
-				break;
-			case DOWNLOAD_CONST:
-				symlist_add(&download_constants, cursym,
-					    SYMLIST_INSERT_HEAD);
-				break;
-			case ALIAS:
-				symlist_add(&aliases, cursym,
-					    SYMLIST_INSERT_HEAD);
-				break;
-			default:
-				break;
+		switch(curnode->symbol->type) {
+		case REGISTER:
+		case SCBLOC:
+		case SRAMLOC:
+		{
+			symlist_t	*fields;
+			symbol_node_t	*fieldnode;
+			int		 num_entries;
+
+			num_entries = 0;
+			fields = &curnode->symbol->info.rinfo->fields;
+			SLIST_FOREACH(fieldnode, fields, links) {
+				if (num_entries == 0)
+					aic_print_reg_dump_start(dfile,
+								 curnode);
+				else
+					fputs(",\n", dfile);
+				num_entries++;
+				aic_print_reg_dump_entry(dfile, fieldnode);
 			}
-			flag = R_NEXT;
+			aic_print_reg_dump_end(ofile, dfile,
+					       curnode, num_entries);
+		}
+		default:
+			break;
 		}
+	}
 
-		/* Put in the masks and bits */
-		while (SLIST_FIRST(&masks) != NULL) {
-			symbol_node_t *curnode;
-			symbol_node_t *regnode;
-			char *regname;
+	/* Fold in the masks and bits */
+	while (SLIST_FIRST(&masks) != NULL) {
+		char *regname;
 
-			curnode = SLIST_FIRST(&masks);
-			SLIST_REMOVE_HEAD(&masks, links);
+		curnode = SLIST_FIRST(&masks);
+		SLIST_REMOVE_HEAD(&masks, links);
 
-			regnode =
-			    SLIST_FIRST(&curnode->symbol->info.minfo->symrefs);
-			regname = regnode->symbol->name;
-			regnode = symlist_search(&registers, regname);
-			SLIST_INSERT_AFTER(regnode, curnode, links);
-		}
+		regnode = SLIST_FIRST(&curnode->symbol->info.finfo->symrefs);
+		regname = regnode->symbol->name;
+		regnode = symlist_search(&registers, regname);
+		SLIST_INSERT_AFTER(regnode, curnode, links);
+	}
 
-		/* Add the aliases */
-		while (SLIST_FIRST(&aliases) != NULL) {
-			symbol_node_t *curnode;
-			symbol_node_t *regnode;
-			char *regname;
+	/* Add the aliases */
+	while (SLIST_FIRST(&aliases) != NULL) {
+		char *regname;
 
-			curnode = SLIST_FIRST(&aliases);
-			SLIST_REMOVE_HEAD(&aliases, links);
+		curnode = SLIST_FIRST(&aliases);
+		SLIST_REMOVE_HEAD(&aliases, links);
 
-			regname = curnode->symbol->info.ainfo->parent->name;
-			regnode = symlist_search(&registers, regname);
-			SLIST_INSERT_AFTER(regnode, curnode, links);
-		}
+		regname = curnode->symbol->info.ainfo->parent->name;
+		regnode = symlist_search(&registers, regname);
+		SLIST_INSERT_AFTER(regnode, curnode, links);
+	}
 
-		/* Output what we have */
-		fprintf(ofile,
-"/*
- * DO NOT EDIT - This file is automatically generated
- *		 from the following source files:
- *
-%s */\n", versions);
-		while (SLIST_FIRST(&registers) != NULL) {
-			symbol_node_t *curnode;
-			u_int8_t value;
-			char *tab_str;
-			char *tab_str2;
-
-			curnode = SLIST_FIRST(&registers);
-			SLIST_REMOVE_HEAD(&registers, links);
-			switch(curnode->symbol->type) {
-			case REGISTER:
-			case SCBLOC:
-			case SRAMLOC:
-				fprintf(ofile, "\n");
-				value = curnode->symbol->info.rinfo->address;
-				tab_str = "\t";
-				tab_str2 = "\t\t";
-				break;
-			case ALIAS:
-			{
-				symbol_t *parent;
-
-				parent = curnode->symbol->info.ainfo->parent;
-				value = parent->info.rinfo->address;
-				tab_str = "\t";
-				tab_str2 = "\t\t";
-				break;
-			}
-			case MASK:
-			case BIT:
-				value = curnode->symbol->info.minfo->mask;
-				tab_str = "\t\t";
-				tab_str2 = "\t";
-				break;
-			default:
-				value = 0; /* Quiet compiler */
-				tab_str = NULL;
-				tab_str2 = NULL;
-				stop("symtable_dump: Invalid symbol type "
-				     "encountered", EX_SOFTWARE);
-				break;
-			}
-			fprintf(ofile, "#define%s%-16s%s0x%02x\n",
-				tab_str, curnode->symbol->name, tab_str2,
-				value);
-			free(curnode);
-		}
-		fprintf(ofile, "\n\n");
-
-		while (SLIST_FIRST(&constants) != NULL) {
-			symbol_node_t *curnode;
-
-			curnode = SLIST_FIRST(&constants);
-			SLIST_REMOVE_HEAD(&constants, links);
-			fprintf(ofile, "#define\t%-8s\t0x%02x\n",
-				curnode->symbol->name,
-				curnode->symbol->info.cinfo->value);
-			free(curnode);
+	/* Output generated #defines. */
+	while (SLIST_FIRST(&registers) != NULL) {
+		symbol_node_t *curnode;
+		u_int value;
+		char *tab_str;
+		char *tab_str2;
+
+		curnode = SLIST_FIRST(&registers);
+		SLIST_REMOVE_HEAD(&registers, links);
+		switch(curnode->symbol->type) {
+		case REGISTER:
+		case SCBLOC:
+		case SRAMLOC:
+			fprintf(ofile, "\n");
+			value = curnode->symbol->info.rinfo->address;
+			tab_str = "\t";
+			tab_str2 = "\t\t";
+			break;
+		case ALIAS:
+		{
+			symbol_t *parent;
+
+			parent = curnode->symbol->info.ainfo->parent;
+			value = parent->info.rinfo->address;
+			tab_str = "\t";
+			tab_str2 = "\t\t";
+			break;
 		}
+		case MASK:
+		case FIELD:
+		case ENUM:
+		case ENUM_ENTRY:
+			value = curnode->symbol->info.finfo->value;
+			tab_str = "\t\t";
+			tab_str2 = "\t";
+			break;
+		default:
+			value = 0; /* Quiet compiler */
+			tab_str = NULL;
+			tab_str2 = NULL;
+			stop("symtable_dump: Invalid symbol type "
+			     "encountered", EX_SOFTWARE);
+			break;
+		}
+		fprintf(ofile, "#define%s%-16s%s0x%02x\n",
+			tab_str, curnode->symbol->name, tab_str2,
+			value);
+		free(curnode);
+	}
+	fprintf(ofile, "\n\n");
 
-		
-		fprintf(ofile, "\n\n/* Downloaded Constant Definitions */\n");
+	while (SLIST_FIRST(&constants) != NULL) {
+		symbol_node_t *curnode;
+
+		curnode = SLIST_FIRST(&constants);
+		SLIST_REMOVE_HEAD(&constants, links);
+		fprintf(ofile, "#define\t%-8s\t0x%02x\n",
+			curnode->symbol->name,
+			curnode->symbol->info.cinfo->value);
+		free(curnode);
+	}
 
-		while (SLIST_FIRST(&download_constants) != NULL) {
-			symbol_node_t *curnode;
+	
+	fprintf(ofile, "\n\n/* Downloaded Constant Definitions */\n");
 
-			curnode = SLIST_FIRST(&download_constants);
-			SLIST_REMOVE_HEAD(&download_constants, links);
-			fprintf(ofile, "#define\t%-8s\t0x%02x\n",
-				curnode->symbol->name,
-				curnode->symbol->info.cinfo->value);
-			free(curnode);
-		}
+	for (i = 0; SLIST_FIRST(&download_constants) != NULL; i++) {
+		symbol_node_t *curnode;
+
+		curnode = SLIST_FIRST(&download_constants);
+		SLIST_REMOVE_HEAD(&download_constants, links);
+		fprintf(ofile, "#define\t%-8s\t0x%02x\n",
+			curnode->symbol->name,
+			curnode->symbol->info.cinfo->value);
+		free(curnode);
+	}
+	fprintf(ofile, "#define\tDOWNLOAD_CONST_COUNT\t0x%02x\n", i);
+
+	fprintf(ofile, "\n\n/* Exported Labels */\n");
+
+	while (SLIST_FIRST(&exported_labels) != NULL) {
+		symbol_node_t *curnode;
+
+		curnode = SLIST_FIRST(&exported_labels);
+		SLIST_REMOVE_HEAD(&exported_labels, links);
+		fprintf(ofile, "#define\tLABEL_%-8s\t0x%02x\n",
+			curnode->symbol->name,
+			curnode->symbol->info.linfo->address);
+		free(curnode);
 	}
 }
 
diff -Nru a/drivers/scsi/aic7xxx/aicasm/aicasm_symbol.h b/drivers/scsi/aic7xxx/aicasm/aicasm_symbol.h
--- a/drivers/scsi/aic7xxx/aicasm/aicasm_symbol.h	Mon Dec 23 21:21:58 2002
+++ b/drivers/scsi/aic7xxx/aicasm/aicasm_symbol.h	Mon Dec 23 21:21:58 2002
@@ -2,6 +2,7 @@
  * Aic7xxx SCSI host adapter firmware asssembler symbol table definitions
  *
  * Copyright (c) 1997 Justin T. Gibbs.
+ * Copyright (c) 2002 Adaptec Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -36,9 +37,9 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_symbol.h#6 $
+ * $Id: //depot/aic7xxx/aic7xxx/aicasm/aicasm_symbol.h#17 $
  *
- * $FreeBSD: src/sys/dev/aic7xxx/aicasm/aicasm_symbol.h,v 1.11 2000/09/22 22:19:55 gibbs Exp $
+ * $FreeBSD$
  */
 
 #ifdef __linux__
@@ -53,13 +54,16 @@
 	ALIAS,
 	SCBLOC,
 	SRAMLOC,
+	ENUM_ENTRY,
+	FIELD,
 	MASK,
-	BIT,
+	ENUM,
 	CONST,
 	DOWNLOAD_CONST,
 	LABEL,
-	CONDITIONAL
-}symtype;
+	CONDITIONAL,
+	MACRO
+} symtype;
 
 typedef enum {
 	RO = 0x01,
@@ -67,24 +71,27 @@
 	RW = 0x03
 }amode_t;
 
+typedef SLIST_HEAD(symlist, symbol_node) symlist_t;
+
 struct reg_info {
-	u_int8_t address;
-	int	 size;
-	amode_t	 mode;
-	u_int8_t valid_bitmask;
-	int	 typecheck_masks;
+	u_int	  address;
+	int	  size;
+	amode_t	  mode;
+	symlist_t fields;
+	uint8_t	  valid_bitmask;
+	uint8_t	  modes;
+	int	  typecheck_masks;
 };
 
-typedef SLIST_HEAD(symlist, symbol_node) symlist_t;
-
-struct mask_info {
+struct field_info {
 	symlist_t symrefs;
-	u_int8_t mask;
+	uint8_t	  value;
+	uint8_t	  mask;
 };
 
 struct const_info {
-	u_int8_t value;
-	int	 define;
+	u_int	value;
+	int	define;
 };
 
 struct alias_info {
@@ -93,12 +100,26 @@
 
 struct label_info {
 	int	address;
+	int	exported;
 };
 
 struct cond_info {
 	int	func_num;
 };
 
+struct macro_arg {
+	STAILQ_ENTRY(macro_arg)	links;
+	regex_t	arg_regex;
+	char   *replacement_text;
+};
+STAILQ_HEAD(macro_arg_list, macro_arg) args;
+
+struct macro_info {
+	struct macro_arg_list args;
+	int   narg;
+	const char* body;
+};
+
 typedef struct expression_info {
         symlist_t       referenced_syms;
         int             value;
@@ -108,12 +129,13 @@
 	char	*name;
 	symtype	type;
 	union	{
-		struct reg_info *rinfo;
-		struct mask_info *minfo;
+		struct reg_info	  *rinfo;
+		struct field_info *finfo;
 		struct const_info *cinfo;
 		struct alias_info *ainfo;
 		struct label_info *linfo;
-		struct cond_info *condinfo;
+		struct cond_info  *condinfo;
+		struct macro_info *macroinfo;
 	}info;
 } symbol_t;
 
@@ -161,25 +183,25 @@
 SLIST_HEAD(scope_list, scope);
 TAILQ_HEAD(scope_tailq, scope);
 
-void	symbol_delete __P((symbol_t *symbol));
+void	symbol_delete(symbol_t *symbol);
 
-void	symtable_open __P((void));
+void	symtable_open(void);
 
-void	symtable_close __P((void));
+void	symtable_close(void);
 
 symbol_t *
-	symtable_get __P((char *name));
+	symtable_get(char *name);
 
 symbol_node_t *
-	symlist_search __P((symlist_t *symlist, char *symname));
+	symlist_search(symlist_t *symlist, char *symname);
 
 void
-	symlist_add __P((symlist_t *symlist, symbol_t *symbol, int how));
+	symlist_add(symlist_t *symlist, symbol_t *symbol, int how);
 #define SYMLIST_INSERT_HEAD	0x00
 #define SYMLIST_SORT		0x01
 
-void	symlist_free __P((symlist_t *symlist));
+void	symlist_free(symlist_t *symlist);
 
-void	symlist_merge __P((symlist_t *symlist_dest, symlist_t *symlist_src1,
-			   symlist_t *symlist_src2));
-void	symtable_dump __P((FILE *ofile));
+void	symlist_merge(symlist_t *symlist_dest, symlist_t *symlist_src1,
+		      symlist_t *symlist_src2);
+void	symtable_dump(FILE *ofile, FILE *dfile);
diff -Nru a/drivers/scsi/aic7xxx/aiclib.c b/drivers/scsi/aic7xxx/aiclib.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aiclib.c	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,1226 @@
+/*
+ * Implementation of Utility functions for all SCSI device types.
+ *
+ * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs.
+ * Copyright (c) 1997, 1998 Kenneth D. Merry.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification, immediately at the beginning of the file.
+ * 2. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/cam/scsi/scsi_all.c,v 1.38 2002/09/23 04:56:35 mjacob Exp $
+ * $Id$
+ */
+
+#include <linux/blk.h>
+#include <linux/blkdev.h>
+#include <linux/delay.h>
+#include <linux/version.h>
+
+/* Core SCSI definitions */
+#include "scsi.h"
+#include "hosts.h"
+#include "aiclib.h"
+#include "cam.h"
+
+#ifndef FALSE
+#define FALSE   0
+#endif /* FALSE */
+#ifndef TRUE
+#define TRUE    1
+#endif /* TRUE */
+#ifndef ERESTART
+#define ERESTART        -1              /* restart syscall */
+#endif
+#ifndef EJUSTRETURN
+#define EJUSTRETURN     -2              /* don't modify regs, just return */
+#endif
+
+static int	ascentrycomp(const void *key, const void *member);
+static int	senseentrycomp(const void *key, const void *member);
+static void	fetchtableentries(int sense_key, int asc, int ascq,
+				  struct scsi_inquiry_data *,
+				  const struct sense_key_table_entry **,
+				  const struct asc_table_entry **);
+static void *	scsibsearch(const void *key, const void *base, size_t nmemb,
+			    size_t size,
+			    int (*compar)(const void *, const void *));
+typedef int (cam_quirkmatch_t)(caddr_t, caddr_t);
+static int	cam_strmatch(const u_int8_t *str, const u_int8_t *pattern,
+			     int str_len);
+static caddr_t	cam_quirkmatch(caddr_t target, caddr_t quirk_table,
+			       int num_entries, int entry_size,
+			       cam_quirkmatch_t *comp_func);
+
+#define SCSI_NO_SENSE_STRINGS 1
+#if !defined(SCSI_NO_SENSE_STRINGS)
+#define SST(asc, ascq, action, desc) \
+	asc, ascq, action, desc
+#else 
+static const char empty_string[] = "";
+
+#define SST(asc, ascq, action, desc) \
+	asc, ascq, action, empty_string
+#endif 
+
+static const struct sense_key_table_entry sense_key_table[] = 
+{
+	{ SSD_KEY_NO_SENSE, SS_NOP, "NO SENSE" },
+	{ SSD_KEY_RECOVERED_ERROR, SS_NOP|SSQ_PRINT_SENSE, "RECOVERED ERROR" },
+	{
+	  SSD_KEY_NOT_READY, SS_TUR|SSQ_MANY|SSQ_DECREMENT_COUNT|EBUSY,
+	  "NOT READY"
+	},
+	{ SSD_KEY_MEDIUM_ERROR, SS_RDEF, "MEDIUM ERROR" },
+	{ SSD_KEY_HARDWARE_ERROR, SS_RDEF, "HARDWARE FAILURE" },
+	{ SSD_KEY_ILLEGAL_REQUEST, SS_FATAL|EINVAL, "ILLEGAL REQUEST" },
+	{ SSD_KEY_UNIT_ATTENTION, SS_FATAL|ENXIO, "UNIT ATTENTION" },
+	{ SSD_KEY_DATA_PROTECT, SS_FATAL|EACCES, "DATA PROTECT" },
+	{ SSD_KEY_BLANK_CHECK, SS_FATAL|ENOSPC, "BLANK CHECK" },
+	{ SSD_KEY_Vendor_Specific, SS_FATAL|EIO, "Vendor Specific" },
+	{ SSD_KEY_COPY_ABORTED, SS_FATAL|EIO, "COPY ABORTED" },
+	{ SSD_KEY_ABORTED_COMMAND, SS_RDEF, "ABORTED COMMAND" },
+	{ SSD_KEY_EQUAL, SS_NOP, "EQUAL" },
+	{ SSD_KEY_VOLUME_OVERFLOW, SS_FATAL|EIO, "VOLUME OVERFLOW" },
+	{ SSD_KEY_MISCOMPARE, SS_NOP, "MISCOMPARE" },
+	{ SSD_KEY_RESERVED, SS_FATAL|EIO, "RESERVED" }
+};
+
+static const int sense_key_table_size =
+    sizeof(sense_key_table)/sizeof(sense_key_table[0]);
+
+static struct asc_table_entry quantum_fireball_entries[] = {
+	{SST(0x04, 0x0b, SS_START|SSQ_DECREMENT_COUNT|ENXIO, 
+	     "Logical unit not ready, initializing cmd. required")}
+};
+
+static struct asc_table_entry sony_mo_entries[] = {
+	{SST(0x04, 0x00, SS_START|SSQ_DECREMENT_COUNT|ENXIO,
+	     "Logical unit not ready, cause not reportable")}
+};
+
+static struct scsi_sense_quirk_entry sense_quirk_table[] = {
+	{
+		/*
+		 * The Quantum Fireball ST and SE like to return 0x04 0x0b when
+		 * they really should return 0x04 0x02.  0x04,0x0b isn't
+		 * defined in any SCSI spec, and it isn't mentioned in the
+		 * hardware manual for these drives.
+		 */
+		{T_DIRECT, SIP_MEDIA_FIXED, "QUANTUM", "FIREBALL S*", "*"},
+		/*num_sense_keys*/0,
+		sizeof(quantum_fireball_entries)/sizeof(struct asc_table_entry),
+		/*sense key entries*/NULL,
+		quantum_fireball_entries
+	},
+	{
+		/*
+		 * This Sony MO drive likes to return 0x04, 0x00 when it
+		 * isn't spun up.
+		 */
+		{T_DIRECT, SIP_MEDIA_REMOVABLE, "SONY", "SMO-*", "*"},
+		/*num_sense_keys*/0,
+		sizeof(sony_mo_entries)/sizeof(struct asc_table_entry),
+		/*sense key entries*/NULL,
+		sony_mo_entries
+	}
+};
+
+static const int sense_quirk_table_size =
+    sizeof(sense_quirk_table)/sizeof(sense_quirk_table[0]);
+
+static struct asc_table_entry asc_table[] = {
+/*
+ * From File: ASC-NUM.TXT
+ * SCSI ASC/ASCQ Assignments
+ * Numeric Sorted Listing
+ * as of  5/12/97
+ *
+ * D - DIRECT ACCESS DEVICE (SBC)                     device column key
+ * .T - SEQUENTIAL ACCESS DEVICE (SSC)               -------------------
+ * . L - PRINTER DEVICE (SSC)                           blank = reserved
+ * .  P - PROCESSOR DEVICE (SPC)                     not blank = allowed
+ * .  .W - WRITE ONCE READ MULTIPLE DEVICE (SBC)
+ * .  . R - CD DEVICE (MMC)
+ * .  .  S - SCANNER DEVICE (SGC)
+ * .  .  .O - OPTICAL MEMORY DEVICE (SBC)
+ * .  .  . M - MEDIA CHANGER DEVICE (SMC)
+ * .  .  .  C - COMMUNICATION DEVICE (SSC)
+ * .  .  .  .A - STORAGE ARRAY DEVICE (SCC)
+ * .  .  .  . E - ENCLOSURE SERVICES DEVICE (SES)
+ * DTLPWRSOMCAE        ASC   ASCQ  Action  Description
+ * ------------        ----  ----  ------  -----------------------------------*/
+/* DTLPWRSOMCAE */{SST(0x00, 0x00, SS_NOP,
+			"No additional sense information") },
+/*  T    S      */{SST(0x00, 0x01, SS_RDEF,
+			"Filemark detected") },
+/*  T    S      */{SST(0x00, 0x02, SS_RDEF,
+			"End-of-partition/medium detected") },
+/*  T           */{SST(0x00, 0x03, SS_RDEF,
+			"Setmark detected") },
+/*  T    S      */{SST(0x00, 0x04, SS_RDEF,
+			"Beginning-of-partition/medium detected") },
+/*  T    S      */{SST(0x00, 0x05, SS_RDEF,
+			"End-of-data detected") },
+/* DTLPWRSOMCAE */{SST(0x00, 0x06, SS_RDEF,
+			"I/O process terminated") },
+/*      R       */{SST(0x00, 0x11, SS_FATAL|EBUSY,
+			"Audio play operation in progress") },
+/*      R       */{SST(0x00, 0x12, SS_NOP,
+			"Audio play operation paused") },
+/*      R       */{SST(0x00, 0x13, SS_NOP,
+			"Audio play operation successfully completed") },
+/*      R       */{SST(0x00, 0x14, SS_RDEF,
+			"Audio play operation stopped due to error") },
+/*      R       */{SST(0x00, 0x15, SS_NOP,
+			"No current audio status to return") },
+/* DTLPWRSOMCAE */{SST(0x00, 0x16, SS_FATAL|EBUSY,
+			"Operation in progress") },
+/* DTL WRSOM AE */{SST(0x00, 0x17, SS_RDEF,
+			"Cleaning requested") },
+/* D   W  O     */{SST(0x01, 0x00, SS_RDEF,
+			"No index/sector signal") },
+/* D   WR OM    */{SST(0x02, 0x00, SS_RDEF,
+			"No seek complete") },
+/* DTL W SO     */{SST(0x03, 0x00, SS_RDEF,
+			"Peripheral device write fault") },
+/*  T           */{SST(0x03, 0x01, SS_RDEF,
+			"No write current") },
+/*  T           */{SST(0x03, 0x02, SS_RDEF,
+			"Excessive write errors") },
+/* DTLPWRSOMCAE */{SST(0x04, 0x00,
+			SS_TUR|SSQ_DELAY|SSQ_MANY|SSQ_DECREMENT_COUNT|EIO,
+			"Logical unit not ready, cause not reportable") },
+/* DTLPWRSOMCAE */{SST(0x04, 0x01,
+			SS_TUR|SSQ_DELAY|SSQ_MANY|SSQ_DECREMENT_COUNT|EBUSY,
+			"Logical unit is in process of becoming ready") },
+/* DTLPWRSOMCAE */{SST(0x04, 0x02, SS_START|SSQ_DECREMENT_COUNT|ENXIO,
+			"Logical unit not ready, initializing cmd. required") },
+/* DTLPWRSOMCAE */{SST(0x04, 0x03, SS_FATAL|ENXIO,
+			"Logical unit not ready, manual intervention required")},
+/* DTL    O     */{SST(0x04, 0x04, SS_FATAL|EBUSY,
+			"Logical unit not ready, format in progress") },
+/* DT  W  OMCA  */{SST(0x04, 0x05, SS_FATAL|EBUSY,
+			"Logical unit not ready, rebuild in progress") },
+/* DT  W  OMCA  */{SST(0x04, 0x06, SS_FATAL|EBUSY,
+			"Logical unit not ready, recalculation in progress") },
+/* DTLPWRSOMCAE */{SST(0x04, 0x07, SS_FATAL|EBUSY,
+			"Logical unit not ready, operation in progress") },
+/*      R       */{SST(0x04, 0x08, SS_FATAL|EBUSY,
+			"Logical unit not ready, long write in progress") },
+/* DTL WRSOMCAE */{SST(0x05, 0x00, SS_RDEF,
+			"Logical unit does not respond to selection") },
+/* D   WR OM    */{SST(0x06, 0x00, SS_RDEF,
+			"No reference position found") },
+/* DTL WRSOM    */{SST(0x07, 0x00, SS_RDEF,
+			"Multiple peripheral devices selected") },
+/* DTL WRSOMCAE */{SST(0x08, 0x00, SS_RDEF,
+			"Logical unit communication failure") },
+/* DTL WRSOMCAE */{SST(0x08, 0x01, SS_RDEF,
+			"Logical unit communication time-out") },
+/* DTL WRSOMCAE */{SST(0x08, 0x02, SS_RDEF,
+			"Logical unit communication parity error") },
+/* DT   R OM    */{SST(0x08, 0x03, SS_RDEF,
+			"Logical unit communication crc error (ultra-dma/32)")},
+/* DT  WR O     */{SST(0x09, 0x00, SS_RDEF,
+			"Track following error") },
+/*     WR O     */{SST(0x09, 0x01, SS_RDEF,
+			"Tracking servo failure") },
+/*     WR O     */{SST(0x09, 0x02, SS_RDEF,
+			"Focus servo failure") },
+/*     WR O     */{SST(0x09, 0x03, SS_RDEF,
+			"Spindle servo failure") },
+/* DT  WR O     */{SST(0x09, 0x04, SS_RDEF,
+			"Head select fault") },
+/* DTLPWRSOMCAE */{SST(0x0A, 0x00, SS_FATAL|ENOSPC,
+			"Error log overflow") },
+/* DTLPWRSOMCAE */{SST(0x0B, 0x00, SS_RDEF,
+			"Warning") },
+/* DTLPWRSOMCAE */{SST(0x0B, 0x01, SS_RDEF,
+			"Specified temperature exceeded") },
+/* DTLPWRSOMCAE */{SST(0x0B, 0x02, SS_RDEF,
+			"Enclosure degraded") },
+/*  T   RS      */{SST(0x0C, 0x00, SS_RDEF,
+			"Write error") },
+/* D   W  O     */{SST(0x0C, 0x01, SS_NOP|SSQ_PRINT_SENSE,
+			"Write error - recovered with auto reallocation") },
+/* D   W  O     */{SST(0x0C, 0x02, SS_RDEF,
+			"Write error - auto reallocation failed") },
+/* D   W  O     */{SST(0x0C, 0x03, SS_RDEF,
+			"Write error - recommend reassignment") },
+/* DT  W  O     */{SST(0x0C, 0x04, SS_RDEF,
+			"Compression check miscompare error") },
+/* DT  W  O     */{SST(0x0C, 0x05, SS_RDEF,
+			"Data expansion occurred during compression") },
+/* DT  W  O     */{SST(0x0C, 0x06, SS_RDEF,
+			"Block not compressible") },
+/*      R       */{SST(0x0C, 0x07, SS_RDEF,
+			"Write error - recovery needed") },
+/*      R       */{SST(0x0C, 0x08, SS_RDEF,
+			"Write error - recovery failed") },
+/*      R       */{SST(0x0C, 0x09, SS_RDEF,
+			"Write error - loss of streaming") },
+/*      R       */{SST(0x0C, 0x0A, SS_RDEF,
+			"Write error - padding blocks added") },
+/* D   W  O     */{SST(0x10, 0x00, SS_RDEF,
+			"ID CRC or ECC error") },
+/* DT  WRSO     */{SST(0x11, 0x00, SS_RDEF,
+			"Unrecovered read error") },
+/* DT  W SO     */{SST(0x11, 0x01, SS_RDEF,
+			"Read retries exhausted") },
+/* DT  W SO     */{SST(0x11, 0x02, SS_RDEF,
+			"Error too long to correct") },
+/* DT  W SO     */{SST(0x11, 0x03, SS_RDEF,
+			"Multiple read errors") },
+/* D   W  O     */{SST(0x11, 0x04, SS_RDEF,
+			"Unrecovered read error - auto reallocate failed") },
+/*     WR O     */{SST(0x11, 0x05, SS_RDEF,
+			"L-EC uncorrectable error") },
+/*     WR O     */{SST(0x11, 0x06, SS_RDEF,
+			"CIRC unrecovered error") },
+/*     W  O     */{SST(0x11, 0x07, SS_RDEF,
+			"Data re-synchronization error") },
+/*  T           */{SST(0x11, 0x08, SS_RDEF,
+			"Incomplete block read") },
+/*  T           */{SST(0x11, 0x09, SS_RDEF,
+			"No gap found") },
+/* DT     O     */{SST(0x11, 0x0A, SS_RDEF,
+			"Miscorrected error") },
+/* D   W  O     */{SST(0x11, 0x0B, SS_RDEF,
+			"Unrecovered read error - recommend reassignment") },
+/* D   W  O     */{SST(0x11, 0x0C, SS_RDEF,
+			"Unrecovered read error - recommend rewrite the data")},
+/* DT  WR O     */{SST(0x11, 0x0D, SS_RDEF,
+			"De-compression CRC error") },
+/* DT  WR O     */{SST(0x11, 0x0E, SS_RDEF,
+			"Cannot decompress using declared algorithm") },
+/*      R       */{SST(0x11, 0x0F, SS_RDEF,
+			"Error reading UPC/EAN number") },
+/*      R       */{SST(0x11, 0x10, SS_RDEF,
+			"Error reading ISRC number") },
+/*      R       */{SST(0x11, 0x11, SS_RDEF,
+			"Read error - loss of streaming") },
+/* D   W  O     */{SST(0x12, 0x00, SS_RDEF,
+			"Address mark not found for id field") },
+/* D   W  O     */{SST(0x13, 0x00, SS_RDEF,
+			"Address mark not found for data field") },
+/* DTL WRSO     */{SST(0x14, 0x00, SS_RDEF,
+			"Recorded entity not found") },
+/* DT  WR O     */{SST(0x14, 0x01, SS_RDEF,
+			"Record not found") },
+/*  T           */{SST(0x14, 0x02, SS_RDEF,
+			"Filemark or setmark not found") },
+/*  T           */{SST(0x14, 0x03, SS_RDEF,
+			"End-of-data not found") },
+/*  T           */{SST(0x14, 0x04, SS_RDEF,
+			"Block sequence error") },
+/* DT  W  O     */{SST(0x14, 0x05, SS_RDEF,
+			"Record not found - recommend reassignment") },
+/* DT  W  O     */{SST(0x14, 0x06, SS_RDEF,
+			"Record not found - data auto-reallocated") },
+/* DTL WRSOM    */{SST(0x15, 0x00, SS_RDEF,
+			"Random positioning error") },
+/* DTL WRSOM    */{SST(0x15, 0x01, SS_RDEF,
+			"Mechanical positioning error") },
+/* DT  WR O     */{SST(0x15, 0x02, SS_RDEF,
+			"Positioning error detected by read of medium") },
+/* D   W  O     */{SST(0x16, 0x00, SS_RDEF,
+			"Data synchronization mark error") },
+/* D   W  O     */{SST(0x16, 0x01, SS_RDEF,
+			"Data sync error - data rewritten") },
+/* D   W  O     */{SST(0x16, 0x02, SS_RDEF,
+			"Data sync error - recommend rewrite") },
+/* D   W  O     */{SST(0x16, 0x03, SS_NOP|SSQ_PRINT_SENSE,
+			"Data sync error - data auto-reallocated") },
+/* D   W  O     */{SST(0x16, 0x04, SS_RDEF,
+			"Data sync error - recommend reassignment") },
+/* DT  WRSO     */{SST(0x17, 0x00, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data with no error correction applied") },
+/* DT  WRSO     */{SST(0x17, 0x01, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data with retries") },
+/* DT  WR O     */{SST(0x17, 0x02, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data with positive head offset") },
+/* DT  WR O     */{SST(0x17, 0x03, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data with negative head offset") },
+/*     WR O     */{SST(0x17, 0x04, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data with retries and/or CIRC applied") },
+/* D   WR O     */{SST(0x17, 0x05, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data using previous sector id") },
+/* D   W  O     */{SST(0x17, 0x06, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data without ECC - data auto-reallocated") },
+/* D   W  O     */{SST(0x17, 0x07, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data without ECC - recommend reassignment")},
+/* D   W  O     */{SST(0x17, 0x08, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data without ECC - recommend rewrite") },
+/* D   W  O     */{SST(0x17, 0x09, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data without ECC - data rewritten") },
+/* D   W  O     */{SST(0x18, 0x00, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data with error correction applied") },
+/* D   WR O     */{SST(0x18, 0x01, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data with error corr. & retries applied") },
+/* D   WR O     */{SST(0x18, 0x02, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data - data auto-reallocated") },
+/*      R       */{SST(0x18, 0x03, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data with CIRC") },
+/*      R       */{SST(0x18, 0x04, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data with L-EC") },
+/* D   WR O     */{SST(0x18, 0x05, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data - recommend reassignment") },
+/* D   WR O     */{SST(0x18, 0x06, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data - recommend rewrite") },
+/* D   W  O     */{SST(0x18, 0x07, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered data with ECC - data rewritten") },
+/* D      O     */{SST(0x19, 0x00, SS_RDEF,
+			"Defect list error") },
+/* D      O     */{SST(0x19, 0x01, SS_RDEF,
+			"Defect list not available") },
+/* D      O     */{SST(0x19, 0x02, SS_RDEF,
+			"Defect list error in primary list") },
+/* D      O     */{SST(0x19, 0x03, SS_RDEF,
+			"Defect list error in grown list") },
+/* DTLPWRSOMCAE */{SST(0x1A, 0x00, SS_RDEF,
+			"Parameter list length error") },
+/* DTLPWRSOMCAE */{SST(0x1B, 0x00, SS_RDEF,
+			"Synchronous data transfer error") },
+/* D      O     */{SST(0x1C, 0x00, SS_RDEF,
+			"Defect list not found") },
+/* D      O     */{SST(0x1C, 0x01, SS_RDEF,
+			"Primary defect list not found") },
+/* D      O     */{SST(0x1C, 0x02, SS_RDEF,
+			"Grown defect list not found") },
+/* D   W  O     */{SST(0x1D, 0x00, SS_FATAL,
+			"Miscompare during verify operation" )},
+/* D   W  O     */{SST(0x1E, 0x00, SS_NOP|SSQ_PRINT_SENSE,
+			"Recovered id with ecc correction") },
+/* D      O     */{SST(0x1F, 0x00, SS_RDEF,
+			"Partial defect list transfer") },
+/* DTLPWRSOMCAE */{SST(0x20, 0x00, SS_FATAL|EINVAL,
+			"Invalid command operation code") },
+/* DT  WR OM    */{SST(0x21, 0x00, SS_FATAL|EINVAL,
+			"Logical block address out of range" )},
+/* DT  WR OM    */{SST(0x21, 0x01, SS_FATAL|EINVAL,
+			"Invalid element address") },
+/* D            */{SST(0x22, 0x00, SS_FATAL|EINVAL,
+			"Illegal function") }, /* Deprecated. Use 20 00, 24 00, or 26 00 instead */
+/* DTLPWRSOMCAE */{SST(0x24, 0x00, SS_FATAL|EINVAL,
+			"Invalid field in CDB") },
+/* DTLPWRSOMCAE */{SST(0x25, 0x00, SS_FATAL|ENXIO,
+			"Logical unit not supported") },
+/* DTLPWRSOMCAE */{SST(0x26, 0x00, SS_FATAL|EINVAL,
+			"Invalid field in parameter list") },
+/* DTLPWRSOMCAE */{SST(0x26, 0x01, SS_FATAL|EINVAL,
+			"Parameter not supported") },
+/* DTLPWRSOMCAE */{SST(0x26, 0x02, SS_FATAL|EINVAL,
+			"Parameter value invalid") },
+/* DTLPWRSOMCAE */{SST(0x26, 0x03, SS_FATAL|EINVAL,
+			"Threshold parameters not supported") },
+/* DTLPWRSOMCAE */{SST(0x26, 0x04, SS_FATAL|EINVAL,
+			"Invalid release of active persistent reservation") },
+/* DT  W  O     */{SST(0x27, 0x00, SS_FATAL|EACCES,
+			"Write protected") },
+/* DT  W  O     */{SST(0x27, 0x01, SS_FATAL|EACCES,
+			"Hardware write protected") },
+/* DT  W  O     */{SST(0x27, 0x02, SS_FATAL|EACCES,
+			"Logical unit software write protected") },
+/*  T           */{SST(0x27, 0x03, SS_FATAL|EACCES,
+			"Associated write protect") },
+/*  T           */{SST(0x27, 0x04, SS_FATAL|EACCES,
+			"Persistent write protect") },
+/*  T           */{SST(0x27, 0x05, SS_FATAL|EACCES,
+			"Permanent write protect") },
+/* DTLPWRSOMCAE */{SST(0x28, 0x00, SS_RDEF,
+			"Not ready to ready change, medium may have changed") },
+/* DTLPWRSOMCAE */{SST(0x28, 0x01, SS_FATAL|ENXIO,
+			"Import or export element accessed") },
+/*
+ * XXX JGibbs - All of these should use the same errno, but I don't think
+ * ENXIO is the correct choice.  Should we borrow from the networking
+ * errnos?  ECONNRESET anyone?
+ */
+/* DTLPWRSOMCAE */{SST(0x29, 0x00, SS_RDEF,
+			"Power on, reset, or bus device reset occurred") },
+/* DTLPWRSOMCAE */{SST(0x29, 0x01, SS_RDEF,
+			"Power on occurred") },
+/* DTLPWRSOMCAE */{SST(0x29, 0x02, SS_RDEF,
+			"Scsi bus reset occurred") },
+/* DTLPWRSOMCAE */{SST(0x29, 0x03, SS_RDEF,
+			"Bus device reset function occurred") },
+/* DTLPWRSOMCAE */{SST(0x29, 0x04, SS_RDEF,
+			"Device internal reset") },
+/* DTLPWRSOMCAE */{SST(0x29, 0x05, SS_RDEF,
+			"Transceiver mode changed to single-ended") },
+/* DTLPWRSOMCAE */{SST(0x29, 0x06, SS_RDEF,
+			"Transceiver mode changed to LVD") },
+/* DTL WRSOMCAE */{SST(0x2A, 0x00, SS_RDEF,
+			"Parameters changed") },
+/* DTL WRSOMCAE */{SST(0x2A, 0x01, SS_RDEF,
+			"Mode parameters changed") },
+/* DTL WRSOMCAE */{SST(0x2A, 0x02, SS_RDEF,
+			"Log parameters changed") },
+/* DTLPWRSOMCAE */{SST(0x2A, 0x03, SS_RDEF,
+			"Reservations preempted") },
+/* DTLPWRSO C   */{SST(0x2B, 0x00, SS_RDEF,
+			"Copy cannot execute since host cannot disconnect") },
+/* DTLPWRSOMCAE */{SST(0x2C, 0x00, SS_RDEF,
+			"Command sequence error") },
+/*       S      */{SST(0x2C, 0x01, SS_RDEF,
+			"Too many windows specified") },
+/*       S      */{SST(0x2C, 0x02, SS_RDEF,
+			"Invalid combination of windows specified") },
+/*      R       */{SST(0x2C, 0x03, SS_RDEF,
+			"Current program area is not empty") },
+/*      R       */{SST(0x2C, 0x04, SS_RDEF,
+			"Current program area is empty") },
+/*  T           */{SST(0x2D, 0x00, SS_RDEF,
+			"Overwrite error on update in place") },
+/* DTLPWRSOMCAE */{SST(0x2F, 0x00, SS_RDEF,
+			"Commands cleared by another initiator") },
+/* DT  WR OM    */{SST(0x30, 0x00, SS_RDEF,
+			"Incompatible medium installed") },
+/* DT  WR O     */{SST(0x30, 0x01, SS_RDEF,
+			"Cannot read medium - unknown format") },
+/* DT  WR O     */{SST(0x30, 0x02, SS_RDEF,
+			"Cannot read medium - incompatible format") },
+/* DT           */{SST(0x30, 0x03, SS_RDEF,
+			"Cleaning cartridge installed") },
+/* DT  WR O     */{SST(0x30, 0x04, SS_RDEF,
+			"Cannot write medium - unknown format") },
+/* DT  WR O     */{SST(0x30, 0x05, SS_RDEF,
+			"Cannot write medium - incompatible format") },
+/* DT  W  O     */{SST(0x30, 0x06, SS_RDEF,
+			"Cannot format medium - incompatible medium") },
+/* DTL WRSOM AE */{SST(0x30, 0x07, SS_RDEF,
+			"Cleaning failure") },
+/*      R       */{SST(0x30, 0x08, SS_RDEF,
+			"Cannot write - application code mismatch") },
+/*      R       */{SST(0x30, 0x09, SS_RDEF,
+			"Current session not fixated for append") },
+/* DT  WR O     */{SST(0x31, 0x00, SS_RDEF,
+			"Medium format corrupted") },
+/* D L  R O     */{SST(0x31, 0x01, SS_RDEF,
+			"Format command failed") },
+/* D   W  O     */{SST(0x32, 0x00, SS_RDEF,
+			"No defect spare location available") },
+/* D   W  O     */{SST(0x32, 0x01, SS_RDEF,
+			"Defect list update failure") },
+/*  T           */{SST(0x33, 0x00, SS_RDEF,
+			"Tape length error") },
+/* DTLPWRSOMCAE */{SST(0x34, 0x00, SS_RDEF,
+			"Enclosure failure") },
+/* DTLPWRSOMCAE */{SST(0x35, 0x00, SS_RDEF,
+			"Enclosure services failure") },
+/* DTLPWRSOMCAE */{SST(0x35, 0x01, SS_RDEF,
+			"Unsupported enclosure function") },
+/* DTLPWRSOMCAE */{SST(0x35, 0x02, SS_RDEF,
+			"Enclosure services unavailable") },
+/* DTLPWRSOMCAE */{SST(0x35, 0x03, SS_RDEF,
+			"Enclosure services transfer failure") },
+/* DTLPWRSOMCAE */{SST(0x35, 0x04, SS_RDEF,
+			"Enclosure services transfer refused") },
+/*   L          */{SST(0x36, 0x00, SS_RDEF,
+			"Ribbon, ink, or toner failure") },
+/* DTL WRSOMCAE */{SST(0x37, 0x00, SS_RDEF,
+			"Rounded parameter") },
+/* DTL WRSOMCAE */{SST(0x39, 0x00, SS_RDEF,
+			"Saving parameters not supported") },
+/* DTL WRSOM    */{SST(0x3A, 0x00, SS_FATAL|ENXIO,
+			"Medium not present") },
+/* DT  WR OM    */{SST(0x3A, 0x01, SS_FATAL|ENXIO,
+			"Medium not present - tray closed") },
+/* DT  WR OM    */{SST(0x3A, 0x02, SS_FATAL|ENXIO,
+			"Medium not present - tray open") },
+/*  TL          */{SST(0x3B, 0x00, SS_RDEF,
+			"Sequential positioning error") },
+/*  T           */{SST(0x3B, 0x01, SS_RDEF,
+			"Tape position error at beginning-of-medium") },
+/*  T           */{SST(0x3B, 0x02, SS_RDEF,
+			"Tape position error at end-of-medium") },
+/*   L          */{SST(0x3B, 0x03, SS_RDEF,
+			"Tape or electronic vertical forms unit not ready") },
+/*   L          */{SST(0x3B, 0x04, SS_RDEF,
+			"Slew failure") },
+/*   L          */{SST(0x3B, 0x05, SS_RDEF,
+			"Paper jam") },
+/*   L          */{SST(0x3B, 0x06, SS_RDEF,
+			"Failed to sense top-of-form") },
+/*   L          */{SST(0x3B, 0x07, SS_RDEF,
+			"Failed to sense bottom-of-form") },
+/*  T           */{SST(0x3B, 0x08, SS_RDEF,
+			"Reposition error") },
+/*       S      */{SST(0x3B, 0x09, SS_RDEF,
+			"Read past end of medium") },
+/*       S      */{SST(0x3B, 0x0A, SS_RDEF,
+			"Read past beginning of medium") },
+/*       S      */{SST(0x3B, 0x0B, SS_RDEF,
+			"Position past end of medium") },
+/*  T    S      */{SST(0x3B, 0x0C, SS_RDEF,
+			"Position past beginning of medium") },
+/* DT  WR OM    */{SST(0x3B, 0x0D, SS_FATAL|ENOSPC,
+			"Medium destination element full") },
+/* DT  WR OM    */{SST(0x3B, 0x0E, SS_RDEF,
+			"Medium source element empty") },
+/*      R       */{SST(0x3B, 0x0F, SS_RDEF,
+			"End of medium reached") },
+/* DT  WR OM    */{SST(0x3B, 0x11, SS_RDEF,
+			"Medium magazine not accessible") },
+/* DT  WR OM    */{SST(0x3B, 0x12, SS_RDEF,
+			"Medium magazine removed") },
+/* DT  WR OM    */{SST(0x3B, 0x13, SS_RDEF,
+			"Medium magazine inserted") },
+/* DT  WR OM    */{SST(0x3B, 0x14, SS_RDEF,
+			"Medium magazine locked") },
+/* DT  WR OM    */{SST(0x3B, 0x15, SS_RDEF,
+			"Medium magazine unlocked") },
+/* DTLPWRSOMCAE */{SST(0x3D, 0x00, SS_RDEF,
+			"Invalid bits in identify message") },
+/* DTLPWRSOMCAE */{SST(0x3E, 0x00, SS_RDEF,
+			"Logical unit has not self-configured yet") },
+/* DTLPWRSOMCAE */{SST(0x3E, 0x01, SS_RDEF,
+			"Logical unit failure") },
+/* DTLPWRSOMCAE */{SST(0x3E, 0x02, SS_RDEF,
+			"Timeout on logical unit") },
+/* DTLPWRSOMCAE */{SST(0x3F, 0x00, SS_RDEF,
+			"Target operating conditions have changed") },
+/* DTLPWRSOMCAE */{SST(0x3F, 0x01, SS_RDEF,
+			"Microcode has been changed") },
+/* DTLPWRSOMC   */{SST(0x3F, 0x02, SS_RDEF,
+			"Changed operating definition") },
+/* DTLPWRSOMCAE */{SST(0x3F, 0x03, SS_INQ_REFRESH|SSQ_DECREMENT_COUNT,
+			"Inquiry data has changed") },
+/* DT  WR OMCAE */{SST(0x3F, 0x04, SS_RDEF,
+			"Component device attached") },
+/* DT  WR OMCAE */{SST(0x3F, 0x05, SS_RDEF,
+			"Device identifier changed") },
+/* DT  WR OMCAE */{SST(0x3F, 0x06, SS_RDEF,
+			"Redundancy group created or modified") },
+/* DT  WR OMCAE */{SST(0x3F, 0x07, SS_RDEF,
+			"Redundancy group deleted") },
+/* DT  WR OMCAE */{SST(0x3F, 0x08, SS_RDEF,
+			"Spare created or modified") },
+/* DT  WR OMCAE */{SST(0x3F, 0x09, SS_RDEF,
+			"Spare deleted") },
+/* DT  WR OMCAE */{SST(0x3F, 0x0A, SS_RDEF,
+			"Volume set created or modified") },
+/* DT  WR OMCAE */{SST(0x3F, 0x0B, SS_RDEF,
+			"Volume set deleted") },
+/* DT  WR OMCAE */{SST(0x3F, 0x0C, SS_RDEF,
+			"Volume set deassigned") },
+/* DT  WR OMCAE */{SST(0x3F, 0x0D, SS_RDEF,
+			"Volume set reassigned") },
+/* DTLPWRSOMCAE */{SST(0x3F, 0x0E, SS_RDEF,
+			"Reported luns data has changed") },
+/* DTLPWRSOMCAE */{SST(0x3F, 0x0F, SS_RETRY|SSQ_DECREMENT_COUNT
+				 | SSQ_DELAY_RANDOM|EBUSY,
+			"Echo buffer overwritten") },
+/* DT  WR OM   B*/{SST(0x3F, 0x0F, SS_RDEF, "Medium Loadable") },
+/* DT  WR OM   B*/{SST(0x3F, 0x0F, SS_RDEF,
+			"Medium auxiliary memory accessible") },
+/* D            */{SST(0x40, 0x00, SS_RDEF,
+			"Ram failure") }, /* deprecated - use 40 NN instead */
+/* DTLPWRSOMCAE */{SST(0x40, 0x80, SS_RDEF,
+			"Diagnostic failure: ASCQ = Component ID") },
+/* DTLPWRSOMCAE */{SST(0x40, 0xFF, SS_RDEF|SSQ_RANGE,
+			NULL) },/* Range 0x80->0xFF */
+/* D            */{SST(0x41, 0x00, SS_RDEF,
+			"Data path failure") }, /* deprecated - use 40 NN instead */
+/* D            */{SST(0x42, 0x00, SS_RDEF,
+			"Power-on or self-test failure") }, /* deprecated - use 40 NN instead */
+/* DTLPWRSOMCAE */{SST(0x43, 0x00, SS_RDEF,
+			"Message error") },
+/* DTLPWRSOMCAE */{SST(0x44, 0x00, SS_RDEF,
+			"Internal target failure") },
+/* DTLPWRSOMCAE */{SST(0x45, 0x00, SS_RDEF,
+			"Select or reselect failure") },
+/* DTLPWRSOMC   */{SST(0x46, 0x00, SS_RDEF,
+			"Unsuccessful soft reset") },
+/* DTLPWRSOMCAE */{SST(0x47, 0x00, SS_RDEF|SSQ_FALLBACK,
+			"SCSI parity error") },
+/* DTLPWRSOMCAE */{SST(0x47, 0x01, SS_RDEF|SSQ_FALLBACK,
+			"Data Phase CRC error detected") },
+/* DTLPWRSOMCAE */{SST(0x47, 0x02, SS_RDEF|SSQ_FALLBACK,
+			"SCSI parity error detected during ST data phase") },
+/* DTLPWRSOMCAE */{SST(0x47, 0x03, SS_RDEF|SSQ_FALLBACK,
+			"Information Unit iuCRC error") },
+/* DTLPWRSOMCAE */{SST(0x47, 0x04, SS_RDEF|SSQ_FALLBACK,
+			"Asynchronous information protection error detected") },
+/* DTLPWRSOMCAE */{SST(0x47, 0x05, SS_RDEF|SSQ_FALLBACK,
+			"Protocol server CRC error") },
+/* DTLPWRSOMCAE */{SST(0x48, 0x00, SS_RDEF|SSQ_FALLBACK,
+			"Initiator detected error message received") },
+/* DTLPWRSOMCAE */{SST(0x49, 0x00, SS_RDEF,
+			"Invalid message error") },
+/* DTLPWRSOMCAE */{SST(0x4A, 0x00, SS_RDEF,
+			"Command phase error") },
+/* DTLPWRSOMCAE */{SST(0x4B, 0x00, SS_RDEF,
+			"Data phase error") },
+/* DTLPWRSOMCAE */{SST(0x4C, 0x00, SS_RDEF,
+			"Logical unit failed self-configuration") },
+/* DTLPWRSOMCAE */{SST(0x4D, 0x00, SS_RDEF,
+			"Tagged overlapped commands: ASCQ = Queue tag ID") },
+/* DTLPWRSOMCAE */{SST(0x4D, 0xFF, SS_RDEF|SSQ_RANGE,
+			NULL)}, /* Range 0x00->0xFF */
+/* DTLPWRSOMCAE */{SST(0x4E, 0x00, SS_RDEF,
+			"Overlapped commands attempted") },
+/*  T           */{SST(0x50, 0x00, SS_RDEF,
+			"Write append error") },
+/*  T           */{SST(0x50, 0x01, SS_RDEF,
+			"Write append position error") },
+/*  T           */{SST(0x50, 0x02, SS_RDEF,
+			"Position error related to timing") },
+/*  T     O     */{SST(0x51, 0x00, SS_RDEF,
+			"Erase failure") },
+/*  T           */{SST(0x52, 0x00, SS_RDEF,
+			"Cartridge fault") },
+/* DTL WRSOM    */{SST(0x53, 0x00, SS_RDEF,
+			"Media load or eject failed") },
+/*  T           */{SST(0x53, 0x01, SS_RDEF,
+			"Unload tape failure") },
+/* DT  WR OM    */{SST(0x53, 0x02, SS_RDEF,
+			"Medium removal prevented") },
+/*    P         */{SST(0x54, 0x00, SS_RDEF,
+			"Scsi to host system interface failure") },
+/*    P         */{SST(0x55, 0x00, SS_RDEF,
+			"System resource failure") },
+/* D      O     */{SST(0x55, 0x01, SS_FATAL|ENOSPC,
+			"System buffer full") },
+/*      R       */{SST(0x57, 0x00, SS_RDEF,
+			"Unable to recover table-of-contents") },
+/*        O     */{SST(0x58, 0x00, SS_RDEF,
+			"Generation does not exist") },
+/*        O     */{SST(0x59, 0x00, SS_RDEF,
+			"Updated block read") },
+/* DTLPWRSOM    */{SST(0x5A, 0x00, SS_RDEF,
+			"Operator request or state change input") },
+/* DT  WR OM    */{SST(0x5A, 0x01, SS_RDEF,
+			"Operator medium removal request") },
+/* DT  W  O     */{SST(0x5A, 0x02, SS_RDEF,
+			"Operator selected write protect") },
+/* DT  W  O     */{SST(0x5A, 0x03, SS_RDEF,
+			"Operator selected write permit") },
+/* DTLPWRSOM    */{SST(0x5B, 0x00, SS_RDEF,
+			"Log exception") },
+/* DTLPWRSOM    */{SST(0x5B, 0x01, SS_RDEF,
+			"Threshold condition met") },
+/* DTLPWRSOM    */{SST(0x5B, 0x02, SS_RDEF,
+			"Log counter at maximum") },
+/* DTLPWRSOM    */{SST(0x5B, 0x03, SS_RDEF,
+			"Log list codes exhausted") },
+/* D      O     */{SST(0x5C, 0x00, SS_RDEF,
+			"RPL status change") },
+/* D      O     */{SST(0x5C, 0x01, SS_NOP|SSQ_PRINT_SENSE,
+			"Spindles synchronized") },
+/* D      O     */{SST(0x5C, 0x02, SS_RDEF,
+			"Spindles not synchronized") },
+/* DTLPWRSOMCAE */{SST(0x5D, 0x00, SS_RDEF,
+			"Failure prediction threshold exceeded") },
+/* DTLPWRSOMCAE */{SST(0x5D, 0xFF, SS_RDEF,
+			"Failure prediction threshold exceeded (false)") },
+/* DTLPWRSO CA  */{SST(0x5E, 0x00, SS_RDEF,
+			"Low power condition on") },
+/* DTLPWRSO CA  */{SST(0x5E, 0x01, SS_RDEF,
+			"Idle condition activated by timer") },
+/* DTLPWRSO CA  */{SST(0x5E, 0x02, SS_RDEF,
+			"Standby condition activated by timer") },
+/* DTLPWRSO CA  */{SST(0x5E, 0x03, SS_RDEF,
+			"Idle condition activated by command") },
+/* DTLPWRSO CA  */{SST(0x5E, 0x04, SS_RDEF,
+			"Standby condition activated by command") },
+/*       S      */{SST(0x60, 0x00, SS_RDEF,
+			"Lamp failure") },
+/*       S      */{SST(0x61, 0x00, SS_RDEF,
+			"Video acquisition error") },
+/*       S      */{SST(0x61, 0x01, SS_RDEF,
+			"Unable to acquire video") },
+/*       S      */{SST(0x61, 0x02, SS_RDEF,
+			"Out of focus") },
+/*       S      */{SST(0x62, 0x00, SS_RDEF,
+			"Scan head positioning error") },
+/*      R       */{SST(0x63, 0x00, SS_RDEF,
+			"End of user area encountered on this track") },
+/*      R       */{SST(0x63, 0x01, SS_FATAL|ENOSPC,
+			"Packet does not fit in available space") },
+/*      R       */{SST(0x64, 0x00, SS_RDEF,
+			"Illegal mode for this track") },
+/*      R       */{SST(0x64, 0x01, SS_RDEF,
+			"Invalid packet size") },
+/* DTLPWRSOMCAE */{SST(0x65, 0x00, SS_RDEF,
+			"Voltage fault") },
+/*       S      */{SST(0x66, 0x00, SS_RDEF,
+			"Automatic document feeder cover up") },
+/*       S      */{SST(0x66, 0x01, SS_RDEF,
+			"Automatic document feeder lift up") },
+/*       S      */{SST(0x66, 0x02, SS_RDEF,
+			"Document jam in automatic document feeder") },
+/*       S      */{SST(0x66, 0x03, SS_RDEF,
+			"Document miss feed automatic in document feeder") },
+/*           A  */{SST(0x67, 0x00, SS_RDEF,
+			"Configuration failure") },
+/*           A  */{SST(0x67, 0x01, SS_RDEF,
+			"Configuration of incapable logical units failed") },
+/*           A  */{SST(0x67, 0x02, SS_RDEF,
+			"Add logical unit failed") },
+/*           A  */{SST(0x67, 0x03, SS_RDEF,
+			"Modification of logical unit failed") },
+/*           A  */{SST(0x67, 0x04, SS_RDEF,
+			"Exchange of logical unit failed") },
+/*           A  */{SST(0x67, 0x05, SS_RDEF,
+			"Remove of logical unit failed") },
+/*           A  */{SST(0x67, 0x06, SS_RDEF,
+			"Attachment of logical unit failed") },
+/*           A  */{SST(0x67, 0x07, SS_RDEF,
+			"Creation of logical unit failed") },
+/*           A  */{SST(0x68, 0x00, SS_RDEF,
+			"Logical unit not configured") },
+/*           A  */{SST(0x69, 0x00, SS_RDEF,
+			"Data loss on logical unit") },
+/*           A  */{SST(0x69, 0x01, SS_RDEF,
+			"Multiple logical unit failures") },
+/*           A  */{SST(0x69, 0x02, SS_RDEF,
+			"Parity/data mismatch") },
+/*           A  */{SST(0x6A, 0x00, SS_RDEF,
+			"Informational, refer to log") },
+/*           A  */{SST(0x6B, 0x00, SS_RDEF,
+			"State change has occurred") },
+/*           A  */{SST(0x6B, 0x01, SS_RDEF,
+			"Redundancy level got better") },
+/*           A  */{SST(0x6B, 0x02, SS_RDEF,
+			"Redundancy level got worse") },
+/*           A  */{SST(0x6C, 0x00, SS_RDEF,
+			"Rebuild failure occurred") },
+/*           A  */{SST(0x6D, 0x00, SS_RDEF,
+			"Recalculate failure occurred") },
+/*           A  */{SST(0x6E, 0x00, SS_RDEF,
+			"Command to logical unit failed") },
+/*  T           */{SST(0x70, 0x00, SS_RDEF,
+			"Decompression exception short: ASCQ = Algorithm ID") },
+/*  T           */{SST(0x70, 0xFF, SS_RDEF|SSQ_RANGE,
+			NULL) }, /* Range 0x00 -> 0xFF */
+/*  T           */{SST(0x71, 0x00, SS_RDEF,
+			"Decompression exception long: ASCQ = Algorithm ID") },
+/*  T           */{SST(0x71, 0xFF, SS_RDEF|SSQ_RANGE,
+			NULL) }, /* Range 0x00 -> 0xFF */	
+/*      R       */{SST(0x72, 0x00, SS_RDEF,
+			"Session fixation error") },
+/*      R       */{SST(0x72, 0x01, SS_RDEF,
+			"Session fixation error writing lead-in") },
+/*      R       */{SST(0x72, 0x02, SS_RDEF,
+			"Session fixation error writing lead-out") },
+/*      R       */{SST(0x72, 0x03, SS_RDEF,
+			"Session fixation error - incomplete track in session") },
+/*      R       */{SST(0x72, 0x04, SS_RDEF,
+			"Empty or partially written reserved track") },
+/*      R       */{SST(0x73, 0x00, SS_RDEF,
+			"CD control error") },
+/*      R       */{SST(0x73, 0x01, SS_RDEF,
+			"Power calibration area almost full") },
+/*      R       */{SST(0x73, 0x02, SS_FATAL|ENOSPC,
+			"Power calibration area is full") },
+/*      R       */{SST(0x73, 0x03, SS_RDEF,
+			"Power calibration area error") },
+/*      R       */{SST(0x73, 0x04, SS_RDEF,
+			"Program memory area update failure") },
+/*      R       */{SST(0x73, 0x05, SS_RDEF,
+			"program memory area is full") }
+};
+
+static const int asc_table_size = sizeof(asc_table)/sizeof(asc_table[0]);
+
+struct asc_key
+{
+	int asc;
+	int ascq;
+};
+
+static int
+ascentrycomp(const void *key, const void *member)
+{
+	int asc;
+	int ascq;
+	const struct asc_table_entry *table_entry;
+
+	asc = ((const struct asc_key *)key)->asc;
+	ascq = ((const struct asc_key *)key)->ascq;
+	table_entry = (const struct asc_table_entry *)member;
+
+	if (asc >= table_entry->asc) {
+
+		if (asc > table_entry->asc)
+			return (1);
+
+		if (ascq <= table_entry->ascq) {
+			/* Check for ranges */
+			if (ascq == table_entry->ascq
+		 	 || ((table_entry->action & SSQ_RANGE) != 0
+		  	   && ascq >= (table_entry - 1)->ascq))
+				return (0);
+			return (-1);
+		}
+		return (1);
+	}
+	return (-1);
+}
+
+static int
+senseentrycomp(const void *key, const void *member)
+{
+	int sense_key;
+	const struct sense_key_table_entry *table_entry;
+
+	sense_key = *((const int *)key);
+	table_entry = (const struct sense_key_table_entry *)member;
+
+	if (sense_key >= table_entry->sense_key) {
+		if (sense_key == table_entry->sense_key)
+			return (0);
+		return (1);
+	}
+	return (-1);
+}
+
+static void
+fetchtableentries(int sense_key, int asc, int ascq,
+		  struct scsi_inquiry_data *inq_data,
+		  const struct sense_key_table_entry **sense_entry,
+		  const struct asc_table_entry **asc_entry)
+{
+	void *match;
+	const struct asc_table_entry *asc_tables[2];
+	const struct sense_key_table_entry *sense_tables[2];
+	struct asc_key asc_ascq;
+	size_t asc_tables_size[2];
+	size_t sense_tables_size[2];
+	int num_asc_tables;
+	int num_sense_tables;
+	int i;
+
+	/* Default to failure */
+	*sense_entry = NULL;
+	*asc_entry = NULL;
+	match = NULL;
+	if (inq_data != NULL)
+		match = cam_quirkmatch((void *)inq_data,
+				       (void *)sense_quirk_table,
+				       sense_quirk_table_size,
+				       sizeof(*sense_quirk_table),
+				       aic_inquiry_match);
+
+	if (match != NULL) {
+		struct scsi_sense_quirk_entry *quirk;
+
+		quirk = (struct scsi_sense_quirk_entry *)match;
+		asc_tables[0] = quirk->asc_info;
+		asc_tables_size[0] = quirk->num_ascs;
+		asc_tables[1] = asc_table;
+		asc_tables_size[1] = asc_table_size;
+		num_asc_tables = 2;
+		sense_tables[0] = quirk->sense_key_info;
+		sense_tables_size[0] = quirk->num_sense_keys;
+		sense_tables[1] = sense_key_table;
+		sense_tables_size[1] = sense_key_table_size;
+		num_sense_tables = 2;
+	} else {
+		asc_tables[0] = asc_table;
+		asc_tables_size[0] = asc_table_size;
+		num_asc_tables = 1;
+		sense_tables[0] = sense_key_table;
+		sense_tables_size[0] = sense_key_table_size;
+		num_sense_tables = 1;
+	}
+
+	asc_ascq.asc = asc;
+	asc_ascq.ascq = ascq;
+	for (i = 0; i < num_asc_tables; i++) {
+		void *found_entry;
+
+		found_entry = scsibsearch(&asc_ascq, asc_tables[i],
+					  asc_tables_size[i],
+					  sizeof(**asc_tables),
+					  ascentrycomp);
+
+		if (found_entry) {
+			*asc_entry = (struct asc_table_entry *)found_entry;
+			break;
+		}
+	}
+
+	for (i = 0; i < num_sense_tables; i++) {
+		void *found_entry;
+
+		found_entry = scsibsearch(&sense_key, sense_tables[i],
+					  sense_tables_size[i],
+					  sizeof(**sense_tables),
+					  senseentrycomp);
+
+		if (found_entry) {
+			*sense_entry =
+			    (struct sense_key_table_entry *)found_entry;
+			break;
+		}
+	}
+}
+
+static void *
+scsibsearch(const void *key, const void *base, size_t nmemb, size_t size,
+		 int (*compar)(const void *, const void *))
+{
+	const void *entry;
+	u_int l;
+	u_int u;
+	u_int m;
+
+	l = -1;
+	u = nmemb;
+	while (l + 1 != u) {
+		m = (l + u) / 2;
+		entry = base + m * size;
+		if (compar(key, entry) > 0)
+			l = m;
+		else
+			u = m;
+	}
+
+	entry = base + u * size;
+	if (u == nmemb
+	 || compar(key, entry) != 0)
+		return (NULL);
+
+	return ((void *)entry);
+}
+
+/*
+ * Compare string with pattern, returning 0 on match.
+ * Short pattern matches trailing blanks in name,
+ * wildcard '*' in pattern matches rest of name,
+ * wildcard '?' matches a single non-space character.
+ */
+static int
+cam_strmatch(const uint8_t *str, const uint8_t *pattern, int str_len)
+{
+
+	while (*pattern != '\0'&& str_len > 0) {  
+
+		if (*pattern == '*') {
+			return (0);
+		}
+		if ((*pattern != *str)
+		 && (*pattern != '?' || *str == ' ')) {
+			return (1);
+		}
+		pattern++;
+		str++;
+		str_len--;
+	}
+	while (str_len > 0 && *str++ == ' ')
+		str_len--;
+
+	return (str_len);
+}
+
+static caddr_t
+cam_quirkmatch(caddr_t target, caddr_t quirk_table, int num_entries,
+	       int entry_size, cam_quirkmatch_t *comp_func)
+{
+	for (; num_entries > 0; num_entries--, quirk_table += entry_size) {
+		if ((*comp_func)(target, quirk_table) == 0)
+			return (quirk_table);
+	}
+	return (NULL);
+}
+
+void
+aic_sense_desc(int sense_key, int asc, int ascq,
+	       struct scsi_inquiry_data *inq_data,
+	       const char **sense_key_desc, const char **asc_desc)
+{
+	const struct asc_table_entry *asc_entry;
+	const struct sense_key_table_entry *sense_entry;
+
+	fetchtableentries(sense_key, asc, ascq,
+			  inq_data,
+			  &sense_entry,
+			  &asc_entry);
+
+	*sense_key_desc = sense_entry->desc;
+
+	if (asc_entry != NULL)
+		*asc_desc = asc_entry->desc;
+	else if (asc >= 0x80 && asc <= 0xff)
+		*asc_desc = "Vendor Specific ASC";
+	else if (ascq >= 0x80 && ascq <= 0xff)
+		*asc_desc = "Vendor Specific ASCQ";
+	else
+		*asc_desc = "Reserved ASC/ASCQ pair";
+}
+
+/*
+ * Given sense and device type information, return the appropriate action.
+ * If we do not understand the specific error as identified by the ASC/ASCQ
+ * pair, fall back on the more generic actions derived from the sense key.
+ */
+aic_sense_action
+aic_sense_error_action(struct scsi_sense_data *sense_data,
+		       struct scsi_inquiry_data *inq_data, uint32_t sense_flags)
+{
+	const struct asc_table_entry *asc_entry;
+	const struct sense_key_table_entry *sense_entry;
+	int error_code, sense_key, asc, ascq;
+	aic_sense_action action;
+
+	scsi_extract_sense(sense_data, &error_code, &sense_key, &asc, &ascq);
+
+	if (error_code == SSD_DEFERRED_ERROR) {
+		/*
+		 * XXX dufault@FreeBSD.org
+		 * This error doesn't relate to the command associated
+		 * with this request sense.  A deferred error is an error
+		 * for a command that has already returned GOOD status
+		 * (see SCSI2 8.2.14.2).
+		 *
+		 * By my reading of that section, it looks like the current
+		 * command has been cancelled, we should now clean things up
+		 * (hopefully recovering any lost data) and then retry the
+		 * current command.  There are two easy choices, both wrong:
+		 *
+		 * 1. Drop through (like we had been doing), thus treating
+		 *    this as if the error were for the current command and
+		 *    return and stop the current command.
+		 * 
+		 * 2. Issue a retry (like I made it do) thus hopefully
+		 *    recovering the current transfer, and ignoring the
+		 *    fact that we've dropped a command.
+		 *
+		 * These should probably be handled in a device specific
+		 * sense handler or punted back up to a user mode daemon
+		 */
+		action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
+	} else {
+		fetchtableentries(sense_key, asc, ascq,
+				  inq_data,
+				  &sense_entry,
+				  &asc_entry);
+
+		/*
+		 * Override the 'No additional Sense' entry (0,0)
+		 * with the error action of the sense key.
+		 */
+		if (asc_entry != NULL
+		 && (asc != 0 || ascq != 0))
+			action = asc_entry->action;
+		else
+			action = sense_entry->action;
+
+		if (sense_key == SSD_KEY_RECOVERED_ERROR) {
+			/*
+			 * The action succeeded but the device wants
+			 * the user to know that some recovery action
+			 * was required.
+			 */
+			action &= ~(SS_MASK|SSQ_MASK|SS_ERRMASK);
+			action |= SS_NOP|SSQ_PRINT_SENSE;
+		} else if (sense_key == SSD_KEY_ILLEGAL_REQUEST) {
+			if ((sense_flags & SF_QUIET_IR) != 0)
+				action &= ~SSQ_PRINT_SENSE;
+		} else if (sense_key == SSD_KEY_UNIT_ATTENTION) {
+			if ((sense_flags & SF_RETRY_UA) != 0
+			 && (action & SS_MASK) == SS_FAIL) {
+				action &= ~(SS_MASK|SSQ_MASK);
+				action |= SS_RETRY|SSQ_DECREMENT_COUNT|
+					  SSQ_PRINT_SENSE;
+			}
+		}
+	}
+
+	if ((sense_flags & SF_PRINT_ALWAYS) != 0)
+		action |= SSQ_PRINT_SENSE;
+	else if ((sense_flags & SF_NO_PRINT) != 0)
+		action &= ~SSQ_PRINT_SENSE;
+
+	return (action);
+}
+
+/*      
+ * Try make as good a match as possible with
+ * available sub drivers
+ */
+int
+aic_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
+{
+	struct scsi_inquiry_pattern *entry;
+	struct scsi_inquiry_data *inq;
+ 
+	entry = (struct scsi_inquiry_pattern *)table_entry;
+	inq = (struct scsi_inquiry_data *)inqbuffer;
+
+	if (((SID_TYPE(inq) == entry->type)
+	  || (entry->type == T_ANY))
+	 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
+				   : entry->media_type & SIP_MEDIA_FIXED)
+	 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
+	 && (cam_strmatch(inq->product, entry->product,
+			  sizeof(inq->product)) == 0)
+	 && (cam_strmatch(inq->revision, entry->revision,
+			  sizeof(inq->revision)) == 0)) {
+		return (0);
+	}
+        return (-1);
+}
+
+/*
+ * Table of syncrates that don't follow the "divisible by 4"
+ * rule. This table will be expanded in future SCSI specs.
+ */
+static struct {
+	u_int period_factor;
+	u_int period;	/* in 100ths of ns */
+} scsi_syncrates[] = {
+	{ 0x08, 625 },	/* FAST-160 */
+	{ 0x09, 1250 },	/* FAST-80 */
+	{ 0x0a, 2500 },	/* FAST-40 40MHz */
+	{ 0x0b, 3030 },	/* FAST-40 33MHz */
+	{ 0x0c, 5000 }	/* FAST-20 */
+};
+
+/*
+ * Return the frequency in kHz corresponding to the given
+ * sync period factor.
+ */
+u_int
+aic_calc_syncsrate(u_int period_factor)
+{
+	int i;
+	int num_syncrates;
+
+	num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
+	/* See if the period is in the "exception" table */
+	for (i = 0; i < num_syncrates; i++) {
+
+		if (period_factor == scsi_syncrates[i].period_factor) {
+			/* Period in kHz */
+			return (100000000 / scsi_syncrates[i].period);
+		}
+	}
+
+	/*
+	 * Wasn't in the table, so use the standard
+	 * 4 times conversion.
+	 */
+	return (10000000 / (period_factor * 4 * 10));
+}
diff -Nru a/drivers/scsi/aic7xxx/aiclib.h b/drivers/scsi/aic7xxx/aiclib.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/aiclib.h	Mon Dec 23 21:22:03 2002
@@ -0,0 +1,990 @@
+/*
+ * Largely written by Julian Elischer (julian@tfs.com)
+ * for TRW Financial Systems.
+ *
+ * TRW Financial Systems, in accordance with their agreement with Carnegie
+ * Mellon University, makes this software available to CMU to distribute
+ * or use in any manner that they see fit as long as this message is kept with
+ * the software. For this reason TFS also grants any other persons or
+ * organisations permission to use or modify this software.
+ *
+ * TFS supplies this software to be publicly redistributed
+ * on the understanding that TFS is not responsible for the correct
+ * functioning of this software in any circumstances.
+ *
+ * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
+ *
+ * $FreeBSD: src/sys/cam/scsi/scsi_all.h,v 1.21 2002/10/08 17:12:44 ken Exp $
+ * $Id$
+ */
+
+/*
+ * SCSI general  interface description
+ */
+
+#ifndef	_SCSI_SCSI_ALL_H
+#define _SCSI_SCSI_ALL_H 1
+
+/*
+ * SCSI command format
+ */
+
+/*
+ * Define dome bits that are in ALL (or a lot of) scsi commands
+ */
+#define SCSI_CTL_LINK		0x01
+#define SCSI_CTL_FLAG		0x02
+#define SCSI_CTL_VENDOR		0xC0
+#define	SCSI_CMD_LUN		0xA0	/* these two should not be needed */
+#define	SCSI_CMD_LUN_SHIFT	5	/* LUN in the cmd is no longer SCSI */
+
+#define SCSI_MAX_CDBLEN		16	/* 
+					 * 16 byte commands are in the 
+					 * SCSI-3 spec 
+					 */
+/* 6byte CDBs special case 0 length to be 256 */
+#define SCSI_CDB6_LEN(len)	((len) == 0 ? 256 : len)
+
+/*
+ * This type defines actions to be taken when a particular sense code is
+ * received.  Right now, these flags are only defined to take up 16 bits,
+ * but can be expanded in the future if necessary.
+ */
+typedef enum {
+	SS_NOP		= 0x000000, /* Do nothing */
+	SS_RETRY	= 0x010000, /* Retry the command */
+	SS_FAIL		= 0x020000, /* Bail out */
+	SS_START	= 0x030000, /* Send a Start Unit command to the device,
+				     * then retry the original command.
+				     */
+	SS_TUR		= 0x040000, /* Send a Test Unit Ready command to the
+				     * device, then retry the original command.
+				     */
+	SS_REQSENSE	= 0x050000, /* Send a RequestSense command to the
+				     * device, then retry the original command.
+				     */
+	SS_INQ_REFRESH	= 0x060000,
+	SS_MASK		= 0xff0000
+} aic_sense_action;
+
+typedef enum {
+	SSQ_NONE		= 0x0000,
+	SSQ_DECREMENT_COUNT	= 0x0100,  /* Decrement the retry count */
+	SSQ_MANY		= 0x0200,  /* send lots of recovery commands */
+	SSQ_RANGE		= 0x0400,  /*
+					    * This table entry represents the
+					    * end of a range of ASCQs that
+					    * have identical error actions
+					    * and text.
+					    */
+	SSQ_PRINT_SENSE		= 0x0800,
+	SSQ_DELAY		= 0x1000,  /* Delay before retry. */
+	SSQ_DELAY_RANDOM	= 0x2000,  /* Randomized delay before retry. */
+	SSQ_FALLBACK		= 0x4000,  /* Do a speed fallback to recover */
+	SSQ_MASK		= 0xff00
+} aic_sense_action_qualifier;
+
+/* Mask for error status values */
+#define SS_ERRMASK	0xff
+
+/* The default, retyable, error action */
+#define SS_RDEF		SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE|EIO
+
+/* The retyable, error action, with table specified error code */
+#define SS_RET		SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE
+
+/* Fatal error action, with table specified error code */
+#define SS_FATAL	SS_FAIL|SSQ_PRINT_SENSE
+
+struct scsi_generic
+{
+	uint8_t opcode;
+	uint8_t bytes[11];
+};
+
+struct scsi_request_sense
+{
+	uint8_t opcode;
+	uint8_t byte2;
+	uint8_t unused[2];
+	uint8_t length;
+	uint8_t control;
+};
+
+struct scsi_test_unit_ready
+{
+	uint8_t opcode;
+	uint8_t byte2;
+	uint8_t unused[3];
+	uint8_t control;
+};
+
+struct scsi_send_diag
+{
+	uint8_t opcode;
+	uint8_t byte2;
+#define	SSD_UOL		0x01
+#define	SSD_DOL		0x02
+#define	SSD_SELFTEST	0x04
+#define	SSD_PF		0x10
+	uint8_t unused[1];
+	uint8_t paramlen[2];
+	uint8_t control;
+};
+
+struct scsi_sense
+{
+	uint8_t opcode;
+	uint8_t byte2;
+	uint8_t unused[2];
+	uint8_t length;
+	uint8_t control;
+};
+
+struct scsi_inquiry
+{
+	uint8_t opcode;
+	uint8_t byte2;
+#define	SI_EVPD 0x01
+	uint8_t page_code;
+	uint8_t reserved;
+	uint8_t length;
+	uint8_t control;
+};
+
+struct scsi_mode_sense_6
+{
+	uint8_t opcode;
+	uint8_t byte2;
+#define	SMS_DBD				0x08
+	uint8_t page;
+#define	SMS_PAGE_CODE 			0x3F
+#define SMS_VENDOR_SPECIFIC_PAGE	0x00
+#define SMS_DISCONNECT_RECONNECT_PAGE	0x02
+#define SMS_PERIPHERAL_DEVICE_PAGE	0x09
+#define SMS_CONTROL_MODE_PAGE		0x0A
+#define SMS_ALL_PAGES_PAGE		0x3F
+#define	SMS_PAGE_CTRL_MASK		0xC0
+#define	SMS_PAGE_CTRL_CURRENT 		0x00
+#define	SMS_PAGE_CTRL_CHANGEABLE 	0x40
+#define	SMS_PAGE_CTRL_DEFAULT 		0x80
+#define	SMS_PAGE_CTRL_SAVED 		0xC0
+	uint8_t unused;
+	uint8_t length;
+	uint8_t control;
+};
+
+struct scsi_mode_sense_10
+{
+	uint8_t opcode;
+	uint8_t byte2;		/* same bits as small version */
+	uint8_t page; 		/* same bits as small version */
+	uint8_t unused[4];
+	uint8_t length[2];
+	uint8_t control;
+};
+
+struct scsi_mode_select_6
+{
+	uint8_t opcode;
+	uint8_t byte2;
+#define	SMS_SP	0x01
+#define	SMS_PF	0x10
+	uint8_t unused[2];
+	uint8_t length;
+	uint8_t control;
+};
+
+struct scsi_mode_select_10
+{
+	uint8_t opcode;
+	uint8_t byte2;		/* same bits as small version */
+	uint8_t unused[5];
+	uint8_t length[2];
+	uint8_t control;
+};
+
+/*
+ * When sending a mode select to a tape drive, the medium type must be 0.
+ */
+struct scsi_mode_hdr_6
+{
+	uint8_t datalen;
+	uint8_t medium_type;
+	uint8_t dev_specific;
+	uint8_t block_descr_len;
+};
+
+struct scsi_mode_hdr_10
+{
+	uint8_t datalen[2];
+	uint8_t medium_type;
+	uint8_t dev_specific;
+	uint8_t reserved[2];
+	uint8_t block_descr_len[2];
+};
+
+struct scsi_mode_block_descr
+{
+	uint8_t density_code;
+	uint8_t num_blocks[3];
+	uint8_t reserved;
+	uint8_t block_len[3];
+};
+
+struct scsi_log_sense
+{
+	uint8_t opcode;
+	uint8_t byte2;
+#define	SLS_SP				0x01
+#define	SLS_PPC				0x02
+	uint8_t page;
+#define	SLS_PAGE_CODE 			0x3F
+#define	SLS_ALL_PAGES_PAGE		0x00
+#define	SLS_OVERRUN_PAGE		0x01
+#define	SLS_ERROR_WRITE_PAGE		0x02
+#define	SLS_ERROR_READ_PAGE		0x03
+#define	SLS_ERROR_READREVERSE_PAGE	0x04
+#define	SLS_ERROR_VERIFY_PAGE		0x05
+#define	SLS_ERROR_NONMEDIUM_PAGE	0x06
+#define	SLS_ERROR_LASTN_PAGE		0x07
+#define	SLS_PAGE_CTRL_MASK		0xC0
+#define	SLS_PAGE_CTRL_THRESHOLD		0x00
+#define	SLS_PAGE_CTRL_CUMULATIVE	0x40
+#define	SLS_PAGE_CTRL_THRESH_DEFAULT	0x80
+#define	SLS_PAGE_CTRL_CUMUL_DEFAULT	0xC0
+	uint8_t reserved[2];
+	uint8_t paramptr[2];
+	uint8_t length[2];
+	uint8_t control;
+};
+
+struct scsi_log_select
+{
+	uint8_t opcode;
+	uint8_t byte2;
+/*	SLS_SP				0x01 */
+#define	SLS_PCR				0x02
+	uint8_t page;
+/*	SLS_PAGE_CTRL_MASK		0xC0 */
+/*	SLS_PAGE_CTRL_THRESHOLD		0x00 */
+/*	SLS_PAGE_CTRL_CUMULATIVE	0x40 */
+/*	SLS_PAGE_CTRL_THRESH_DEFAULT	0x80 */
+/*	SLS_PAGE_CTRL_CUMUL_DEFAULT	0xC0 */
+	uint8_t reserved[4];
+	uint8_t length[2];
+	uint8_t control;
+};
+
+struct scsi_log_header
+{
+	uint8_t page;
+	uint8_t reserved;
+	uint8_t datalen[2];
+};
+
+struct scsi_log_param_header {
+	uint8_t param_code[2];
+	uint8_t param_control;
+#define	SLP_LP				0x01
+#define	SLP_LBIN			0x02
+#define	SLP_TMC_MASK			0x0C
+#define	SLP_TMC_ALWAYS			0x00
+#define	SLP_TMC_EQUAL			0x04
+#define	SLP_TMC_NOTEQUAL		0x08
+#define	SLP_TMC_GREATER			0x0C
+#define	SLP_ETC				0x10
+#define	SLP_TSD				0x20
+#define	SLP_DS				0x40
+#define	SLP_DU				0x80
+	uint8_t param_len;
+};
+
+struct scsi_control_page {
+	uint8_t page_code;
+	uint8_t page_length;
+	uint8_t rlec;
+#define SCB_RLEC			0x01	/*Report Log Exception Cond*/
+	uint8_t queue_flags;
+#define SCP_QUEUE_ALG_MASK		0xF0
+#define SCP_QUEUE_ALG_RESTRICTED	0x00
+#define SCP_QUEUE_ALG_UNRESTRICTED	0x10
+#define SCP_QUEUE_ERR			0x02	/*Queued I/O aborted for CACs*/
+#define SCP_QUEUE_DQUE			0x01	/*Queued I/O disabled*/
+	uint8_t eca_and_aen;
+#define SCP_EECA			0x80	/*Enable Extended CA*/
+#define SCP_RAENP			0x04	/*Ready AEN Permission*/
+#define SCP_UAAENP			0x02	/*UA AEN Permission*/
+#define SCP_EAENP			0x01	/*Error AEN Permission*/
+	uint8_t reserved;
+	uint8_t aen_holdoff_period[2];
+};
+
+struct scsi_reserve
+{
+	uint8_t opcode;
+	uint8_t byte2;
+	uint8_t unused[2];
+	uint8_t length;
+	uint8_t control;
+};
+
+struct scsi_release
+{
+	uint8_t opcode;
+	uint8_t byte2;
+	uint8_t unused[2];
+	uint8_t length;
+	uint8_t control;
+};
+
+struct scsi_prevent
+{
+	uint8_t opcode;
+	uint8_t byte2;
+	uint8_t unused[2];
+	uint8_t how;
+	uint8_t control;
+};
+#define	PR_PREVENT 0x01
+#define PR_ALLOW   0x00
+
+struct scsi_sync_cache
+{
+	uint8_t opcode;
+	uint8_t byte2;
+	uint8_t begin_lba[4];
+	uint8_t reserved;
+	uint8_t lb_count[2];
+	uint8_t control;	
+};
+
+
+struct scsi_changedef
+{
+	uint8_t opcode;
+	uint8_t byte2;
+	uint8_t unused1;
+	uint8_t how;
+	uint8_t unused[4];
+	uint8_t datalen;
+	uint8_t control;
+};
+
+struct scsi_read_buffer
+{
+	uint8_t opcode;
+	uint8_t byte2;
+#define	RWB_MODE		0x07
+#define	RWB_MODE_HDR_DATA	0x00
+#define	RWB_MODE_DATA		0x02
+#define	RWB_MODE_DOWNLOAD	0x04
+#define	RWB_MODE_DOWNLOAD_SAVE	0x05
+        uint8_t buffer_id;
+        uint8_t offset[3];
+        uint8_t length[3];
+        uint8_t control;
+};
+
+struct scsi_write_buffer
+{
+	uint8_t opcode;
+	uint8_t byte2;
+	uint8_t buffer_id;
+	uint8_t offset[3];
+	uint8_t length[3];
+	uint8_t control;
+};
+
+struct scsi_rw_6
+{
+	uint8_t opcode;
+	uint8_t addr[3];
+/* only 5 bits are valid in the MSB address byte */
+#define	SRW_TOPADDR	0x1F
+	uint8_t length;
+	uint8_t control;
+};
+
+struct scsi_rw_10
+{
+	uint8_t opcode;
+#define	SRW10_RELADDR	0x01
+#define SRW10_FUA	0x08
+#define	SRW10_DPO	0x10
+	uint8_t byte2;
+	uint8_t addr[4];
+	uint8_t reserved;
+	uint8_t length[2];
+	uint8_t control;
+};
+
+struct scsi_rw_12
+{
+	uint8_t opcode;
+#define	SRW12_RELADDR	0x01
+#define SRW12_FUA	0x08
+#define	SRW12_DPO	0x10
+	uint8_t byte2;
+	uint8_t addr[4];
+	uint8_t length[4];
+	uint8_t reserved;
+	uint8_t control;
+};
+
+struct scsi_start_stop_unit
+{
+	uint8_t opcode;
+	uint8_t byte2;
+#define	SSS_IMMED		0x01
+	uint8_t reserved[2];
+	uint8_t how;
+#define	SSS_START		0x01
+#define	SSS_LOEJ		0x02
+	uint8_t control;
+};
+
+#define SC_SCSI_1 0x01
+#define SC_SCSI_2 0x03
+
+/*
+ * Opcodes
+ */
+
+#define	TEST_UNIT_READY		0x00
+#define REQUEST_SENSE		0x03
+#define	READ_6			0x08
+#define WRITE_6			0x0a
+#define INQUIRY			0x12
+#define MODE_SELECT_6		0x15
+#define MODE_SENSE_6		0x1a
+#define START_STOP_UNIT		0x1b
+#define START_STOP		0x1b
+#define RESERVE      		0x16
+#define RELEASE      		0x17
+#define	RECEIVE_DIAGNOSTIC	0x1c
+#define	SEND_DIAGNOSTIC		0x1d
+#define PREVENT_ALLOW		0x1e
+#define	READ_CAPACITY		0x25
+#define	READ_10			0x28
+#define WRITE_10		0x2a
+#define POSITION_TO_ELEMENT	0x2b
+#define	SYNCHRONIZE_CACHE	0x35
+#define	WRITE_BUFFER            0x3b
+#define	READ_BUFFER             0x3c
+#define	CHANGE_DEFINITION	0x40
+#define	LOG_SELECT		0x4c
+#define	LOG_SENSE		0x4d
+#ifdef XXXCAM
+#define	MODE_SENSE_10		0x5A
+#endif
+#define	MODE_SELECT_10		0x55
+#define MOVE_MEDIUM     	0xa5
+#define READ_12			0xa8
+#define WRITE_12		0xaa
+#define READ_ELEMENT_STATUS	0xb8
+
+
+/*
+ * Device Types
+ */
+#define T_DIRECT	0x00
+#define T_SEQUENTIAL	0x01
+#define T_PRINTER	0x02
+#define T_PROCESSOR	0x03
+#define T_WORM		0x04
+#define T_CDROM		0x05
+#define T_SCANNER 	0x06
+#define T_OPTICAL 	0x07
+#define T_CHANGER	0x08
+#define T_COMM		0x09
+#define T_ASC0		0x0a
+#define T_ASC1		0x0b
+#define	T_STORARRAY	0x0c
+#define	T_ENCLOSURE	0x0d
+#define	T_RBC		0x0e
+#define	T_OCRW		0x0f
+#define T_NODEVICE	0x1F
+#define	T_ANY		0xFF	/* Used in Quirk table matches */
+
+#define T_REMOV		1
+#define	T_FIXED		0
+
+/*
+ * This length is the initial inquiry length used by the probe code, as    
+ * well as the legnth necessary for aic_print_inquiry() to function 
+ * correctly.  If either use requires a different length in the future, 
+ * the two values should be de-coupled.
+ */
+#define	SHORT_INQUIRY_LENGTH	36
+
+struct scsi_inquiry_data
+{
+	uint8_t device;
+#define	SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
+#define	SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
+#define	SID_QUAL_LU_CONNECTED	0x00	/*
+					 * The specified peripheral device
+					 * type is currently connected to
+					 * logical unit.  If the target cannot
+					 * determine whether or not a physical
+					 * device is currently connected, it
+					 * shall also use this peripheral
+					 * qualifier when returning the INQUIRY
+					 * data.  This peripheral qualifier
+					 * does not mean that the device is
+					 * ready for access by the initiator.
+					 */
+#define	SID_QUAL_LU_OFFLINE	0x01	/*
+					 * The target is capable of supporting
+					 * the specified peripheral device type
+					 * on this logical unit; however, the
+					 * physical device is not currently
+					 * connected to this logical unit.
+					 */
+#define SID_QUAL_RSVD		0x02
+#define	SID_QUAL_BAD_LU		0x03	/*
+					 * The target is not capable of
+					 * supporting a physical device on
+					 * this logical unit. For this
+					 * peripheral qualifier the peripheral
+					 * device type shall be set to 1Fh to
+					 * provide compatibility with previous
+					 * versions of SCSI. All other
+					 * peripheral device type values are
+					 * reserved for this peripheral
+					 * qualifier.
+					 */
+#define	SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
+	uint8_t dev_qual2;
+#define	SID_QUAL2	0x7F
+#define	SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
+	uint8_t version;
+#define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
+#define		SCSI_REV_0		0
+#define		SCSI_REV_CCS		1
+#define		SCSI_REV_2		2
+#define		SCSI_REV_SPC		3
+#define		SCSI_REV_SPC2		4
+
+#define SID_ECMA	0x38
+#define SID_ISO		0xC0
+	uint8_t response_format;
+#define SID_AENC	0x80
+#define SID_TrmIOP	0x40
+	uint8_t additional_length;
+	uint8_t reserved[2];
+	uint8_t flags;
+#define	SID_SftRe	0x01
+#define	SID_CmdQue	0x02
+#define	SID_Linked	0x08
+#define	SID_Sync	0x10
+#define	SID_WBus16	0x20
+#define	SID_WBus32	0x40
+#define	SID_RelAdr	0x80
+#define SID_VENDOR_SIZE   8
+	char	 vendor[SID_VENDOR_SIZE];
+#define SID_PRODUCT_SIZE  16
+	char	 product[SID_PRODUCT_SIZE];
+#define SID_REVISION_SIZE 4
+	char	 revision[SID_REVISION_SIZE];
+	/*
+	 * The following fields were taken from SCSI Primary Commands - 2
+	 * (SPC-2) Revision 14, Dated 11 November 1999
+	 */
+#define	SID_VENDOR_SPECIFIC_0_SIZE	20
+	uint8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE];
+	/*
+	 * An extension of SCSI Parallel Specific Values
+	 */
+#define	SID_SPI_IUS		0x01
+#define	SID_SPI_QAS		0x02
+#define	SID_SPI_CLOCK_ST	0x00
+#define	SID_SPI_CLOCK_DT	0x04
+#define	SID_SPI_CLOCK_DT_ST	0x0C
+#define	SID_SPI_MASK		0x0F
+	uint8_t spi3data;
+	uint8_t reserved2;
+	/*
+	 * Version Descriptors, stored 2 byte values.
+	 */
+	uint8_t version1[2];
+	uint8_t version2[2];
+	uint8_t version3[2];
+	uint8_t version4[2];
+	uint8_t version5[2];
+	uint8_t version6[2];
+	uint8_t version7[2];
+	uint8_t version8[2];
+
+	uint8_t reserved3[22];
+
+#define	SID_VENDOR_SPECIFIC_1_SIZE	160
+	uint8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE];
+};
+
+struct scsi_vpd_unit_serial_number
+{
+	uint8_t device;
+	uint8_t page_code;
+#define SVPD_UNIT_SERIAL_NUMBER	0x80
+	uint8_t reserved;
+	uint8_t length; /* serial number length */
+#define SVPD_SERIAL_NUM_SIZE 251
+	uint8_t serial_num[SVPD_SERIAL_NUM_SIZE];
+};
+
+struct scsi_read_capacity
+{
+	uint8_t opcode;
+	uint8_t byte2;
+	uint8_t addr[4];
+	uint8_t unused[3];
+	uint8_t control;
+};
+
+struct scsi_read_capacity_data
+{
+	uint8_t addr[4];
+	uint8_t length[4];
+};
+
+struct scsi_report_luns
+{
+	uint8_t opcode;
+	uint8_t byte2;
+	uint8_t unused[3];
+	uint8_t addr[4];
+	uint8_t control;
+};
+
+struct scsi_report_luns_data {
+	uint8_t length[4];	/* length of LUN inventory, in bytes */
+	uint8_t reserved[4];	/* unused */
+	/*
+	 * LUN inventory- we only support the type zero form for now.
+	 */
+	struct {
+		uint8_t lundata[8];
+	} luns[1];
+};
+#define	RPL_LUNDATA_ATYP_MASK	0xc0	/* MBZ for type 0 lun */
+#define	RPL_LUNDATA_T0LUN	1	/* @ lundata[1] */
+
+
+struct scsi_sense_data
+{
+	uint8_t error_code;
+#define	SSD_ERRCODE			0x7F
+#define		SSD_CURRENT_ERROR	0x70
+#define		SSD_DEFERRED_ERROR	0x71
+#define	SSD_ERRCODE_VALID	0x80	
+	uint8_t segment;
+	uint8_t flags;
+#define	SSD_KEY				0x0F
+#define		SSD_KEY_NO_SENSE	0x00
+#define		SSD_KEY_RECOVERED_ERROR	0x01
+#define		SSD_KEY_NOT_READY	0x02
+#define		SSD_KEY_MEDIUM_ERROR	0x03
+#define		SSD_KEY_HARDWARE_ERROR	0x04
+#define		SSD_KEY_ILLEGAL_REQUEST	0x05
+#define		SSD_KEY_UNIT_ATTENTION	0x06
+#define		SSD_KEY_DATA_PROTECT	0x07
+#define		SSD_KEY_BLANK_CHECK	0x08
+#define		SSD_KEY_Vendor_Specific	0x09
+#define		SSD_KEY_COPY_ABORTED	0x0a
+#define		SSD_KEY_ABORTED_COMMAND	0x0b		
+#define		SSD_KEY_EQUAL		0x0c
+#define		SSD_KEY_VOLUME_OVERFLOW	0x0d
+#define		SSD_KEY_MISCOMPARE	0x0e
+#define		SSD_KEY_RESERVED	0x0f			
+#define	SSD_ILI		0x20
+#define	SSD_EOM		0x40
+#define	SSD_FILEMARK	0x80
+	uint8_t info[4];
+	uint8_t extra_len;
+	uint8_t cmd_spec_info[4];
+	uint8_t add_sense_code;
+	uint8_t add_sense_code_qual;
+	uint8_t fru;
+	uint8_t sense_key_spec[3];
+#define	SSD_SCS_VALID		0x80
+#define SSD_FIELDPTR_CMD	0x40
+#define SSD_BITPTR_VALID	0x08
+#define SSD_BITPTR_VALUE	0x07
+#define SSD_MIN_SIZE 18
+	uint8_t extra_bytes[14];
+#define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
+};
+
+struct scsi_mode_header_6
+{
+	uint8_t data_length;	/* Sense data length */
+	uint8_t medium_type;
+	uint8_t dev_spec;
+	uint8_t blk_desc_len;
+};
+
+struct scsi_mode_header_10
+{
+	uint8_t data_length[2];/* Sense data length */
+	uint8_t medium_type;
+	uint8_t dev_spec;
+	uint8_t unused[2];
+	uint8_t blk_desc_len[2];
+};
+
+struct scsi_mode_page_header
+{
+	uint8_t page_code;
+	uint8_t page_length;
+};
+
+struct scsi_mode_blk_desc
+{
+	uint8_t density;
+	uint8_t nblocks[3];
+	uint8_t reserved;
+	uint8_t blklen[3];
+};
+
+#define	SCSI_DEFAULT_DENSITY	0x00	/* use 'default' density */
+#define	SCSI_SAME_DENSITY	0x7f	/* use 'same' density- >= SCSI-2 only */
+
+
+/*
+ * Status Byte
+ */
+#define	SCSI_STATUS_OK			0x00
+#define	SCSI_STATUS_CHECK_COND		0x02
+#define	SCSI_STATUS_COND_MET		0x04
+#define	SCSI_STATUS_BUSY		0x08
+#define SCSI_STATUS_INTERMED		0x10
+#define SCSI_STATUS_INTERMED_COND_MET	0x14
+#define SCSI_STATUS_RESERV_CONFLICT	0x18
+#define SCSI_STATUS_CMD_TERMINATED	0x22	/* Obsolete in SAM-2 */
+#define SCSI_STATUS_QUEUE_FULL		0x28
+#define SCSI_STATUS_ACA_ACTIVE		0x30
+#define SCSI_STATUS_TASK_ABORTED	0x40
+
+struct scsi_inquiry_pattern {
+	uint8_t   type;
+	uint8_t   media_type;
+#define	SIP_MEDIA_REMOVABLE	0x01
+#define	SIP_MEDIA_FIXED		0x02
+	const char *vendor;
+	const char *product;
+	const char *revision;
+}; 
+
+struct scsi_static_inquiry_pattern {
+	uint8_t   type;
+	uint8_t   media_type;
+	char       vendor[SID_VENDOR_SIZE+1];
+	char       product[SID_PRODUCT_SIZE+1];
+	char       revision[SID_REVISION_SIZE+1];
+};
+
+struct scsi_sense_quirk_entry {
+	struct scsi_inquiry_pattern	inq_pat;
+	int				num_sense_keys;
+	int				num_ascs;
+	struct sense_key_table_entry	*sense_key_info;
+	struct asc_table_entry		*asc_info;
+};
+
+struct sense_key_table_entry {
+	uint8_t    sense_key;
+	uint32_t   action;
+	const char *desc;
+};
+
+struct asc_table_entry {
+	uint8_t    asc;
+	uint8_t    ascq;
+	uint32_t   action;
+	const char *desc;
+};
+
+struct op_table_entry {
+	uint8_t    opcode;
+	uint16_t   opmask;
+	const char  *desc;
+};
+
+struct scsi_op_quirk_entry {
+	struct scsi_inquiry_pattern	inq_pat;
+	int				num_ops;
+	struct op_table_entry		*op_table;
+};
+
+typedef enum {
+	SSS_FLAG_NONE		= 0x00,
+	SSS_FLAG_PRINT_COMMAND	= 0x01
+} scsi_sense_string_flags;
+
+extern const char *scsi_sense_key_text[];
+
+/************************* Large Disk Handling ********************************/
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+static __inline int
+aic_sector_div(u_long capacity, int heads, int sectors)
+{
+	return (capacity / (heads * sectors));
+}
+#else
+static __inline int
+aic_sector_div(sector_t capacity, int heads, int sectors)
+{
+	/* ugly, ugly sector_div calling convention.. */
+	sector_div(capacity, (heads * sectors));
+	return (int)capacity;
+}
+#endif
+
+/**************************** Module Library Hack *****************************/
+/*
+ * What we'd like to do is have a single "scsi library" module that both the
+ * aic7xxx and aic79xx drivers could load and depend on.  A cursory examination
+ * of implementing module dependencies in Linux (handling the install and
+ * initrd cases) does not look promissing.  For now, we just duplicate this
+ * code in both drivers using a simple symbol renaming scheme that hides this
+ * hack from the drivers.
+ */
+#define AIC_LIB_ENTRY_CONCAT(x, prefix)	prefix ## x
+#define	AIC_LIB_ENTRY_EXPAND(x, prefix) AIC_LIB_ENTRY_CONCAT(x, prefix)
+#define AIC_LIB_ENTRY(x)		AIC_LIB_ENTRY_EXPAND(x, AIC_LIB_PREFIX)
+
+#define	aic_sense_desc			AIC_LIB_ENTRY(_sense_desc)
+#define	aic_sense_error_action		AIC_LIB_ENTRY(_sense_error_action)
+#define	aic_op_desc			AIC_LIB_ENTRY(_op_desc)
+#define	aic_cdb_string			AIC_LIB_ENTRY(_cdb_string)
+#define aic_print_inquiry		AIC_LIB_ENTRY(_print_inquiry)
+#define aic_calc_syncsrate		AIC_LIB_ENTRY(_calc_syncrate)
+#define	aic_calc_syncparam		AIC_LIB_ENTRY(_calc_syncparam)
+#define	aic_inquiry_match		AIC_LIB_ENTRY(_inquiry_match)
+#define	aic_static_inquiry_match	AIC_LIB_ENTRY(_static_inquiry_match)
+
+/******************************************************************************/
+
+void			aic_sense_desc(int /*sense_key*/, int /*asc*/,
+				       int /*ascq*/, struct scsi_inquiry_data*,
+				       const char** /*sense_key_desc*/,
+				       const char** /*asc_desc*/);
+aic_sense_action	aic_sense_error_action(struct scsi_sense_data*,
+					       struct scsi_inquiry_data*,
+					       uint32_t /*sense_flags*/);
+
+#define	SF_RETRY_UA	0x01
+#define SF_NO_PRINT	0x02
+#define SF_QUIET_IR	0x04	/* Be quiet about Illegal Request reponses */
+#define SF_PRINT_ALWAYS	0x08
+
+
+const char *	aic_op_desc(uint16_t /*opcode*/, struct scsi_inquiry_data*);
+char *		aic_cdb_string(uint8_t* /*cdb_ptr*/, char* /*cdb_string*/,
+			       size_t /*len*/);
+void		aic_print_inquiry(struct scsi_inquiry_data*);
+
+u_int		aic_calc_syncsrate(u_int /*period_factor*/);
+u_int		aic_calc_syncparam(u_int /*period*/);
+	
+int		aic_inquiry_match(caddr_t /*inqbuffer*/,
+				  caddr_t /*table_entry*/);
+int		aic_static_inquiry_match(caddr_t /*inqbuffer*/,
+					 caddr_t /*table_entry*/);
+
+
+static __inline void	 scsi_extract_sense(struct scsi_sense_data *sense,
+					    int *error_code, int *sense_key,
+					    int *asc, int *ascq);
+static __inline void	 scsi_ulto2b(uint32_t val, uint8_t *bytes);
+static __inline void	 scsi_ulto3b(uint32_t val, uint8_t *bytes);
+static __inline void	 scsi_ulto4b(uint32_t val, uint8_t *bytes);
+static __inline uint32_t scsi_2btoul(uint8_t *bytes);
+static __inline uint32_t scsi_3btoul(uint8_t *bytes);
+static __inline int32_t	 scsi_3btol(uint8_t *bytes);
+static __inline uint32_t scsi_4btoul(uint8_t *bytes);
+
+static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
+				       int *error_code, int *sense_key,
+				       int *asc, int *ascq)
+{
+	*error_code = sense->error_code & SSD_ERRCODE;
+	*sense_key = sense->flags & SSD_KEY;
+	*asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
+	*ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
+}
+
+static __inline void
+scsi_ulto2b(uint32_t val, uint8_t *bytes)
+{
+
+	bytes[0] = (val >> 8) & 0xff;
+	bytes[1] = val & 0xff;
+}
+
+static __inline void
+scsi_ulto3b(uint32_t val, uint8_t *bytes)
+{
+
+	bytes[0] = (val >> 16) & 0xff;
+	bytes[1] = (val >> 8) & 0xff;
+	bytes[2] = val & 0xff;
+}
+
+static __inline void
+scsi_ulto4b(uint32_t val, uint8_t *bytes)
+{
+
+	bytes[0] = (val >> 24) & 0xff;
+	bytes[1] = (val >> 16) & 0xff;
+	bytes[2] = (val >> 8) & 0xff;
+	bytes[3] = val & 0xff;
+}
+
+static __inline uint32_t
+scsi_2btoul(uint8_t *bytes)
+{
+	uint32_t rv;
+
+	rv = (bytes[0] << 8) |
+	     bytes[1];
+	return (rv);
+}
+
+static __inline uint32_t
+scsi_3btoul(uint8_t *bytes)
+{
+	uint32_t rv;
+
+	rv = (bytes[0] << 16) |
+	     (bytes[1] << 8) |
+	     bytes[2];
+	return (rv);
+}
+
+static __inline int32_t 
+scsi_3btol(uint8_t *bytes)
+{
+	uint32_t rc = scsi_3btoul(bytes);
+ 
+	if (rc & 0x00800000)
+		rc |= 0xff000000;
+
+	return (int32_t) rc;
+}
+
+static __inline uint32_t
+scsi_4btoul(uint8_t *bytes)
+{
+	uint32_t rv;
+
+	rv = (bytes[0] << 24) |
+	     (bytes[1] << 16) |
+	     (bytes[2] << 8) |
+	     bytes[3];
+	return (rv);
+}
+
+#endif /*_SCSI_SCSI_ALL_H*/
diff -Nru a/drivers/scsi/aic7xxx/cam.h b/drivers/scsi/aic7xxx/cam.h
--- a/drivers/scsi/aic7xxx/cam.h	Mon Dec 23 21:21:55 2002
+++ b/drivers/scsi/aic7xxx/cam.h	Mon Dec 23 21:21:55 2002
@@ -29,13 +29,13 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/cam.h#11 $
+ * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/cam.h#15 $
  */
 
 #ifndef _AIC7XXX_CAM_H
 #define _AIC7XXX_CAM_H 1
 
-/* Provide a mapping from CAM constructs to Linux SCSI constructs */
+#include <linux/types.h>
 
 #define	CAM_BUS_WILDCARD ((u_int)~0)
 #define	CAM_TARGET_WILDCARD ((u_int)~0)
@@ -43,56 +43,34 @@
 
 /* CAM Status field values */
 typedef enum {
-	/* CCB request is in progress */
-	CAM_REQ_INPROG		= 0x3F, /* Some value unused by Linux */
-	/* CCB request completed without error */
-	CAM_REQ_CMP		= DID_OK,
-	/* CCB request aborted by the host */
-	CAM_REQ_ABORTED		= DID_ABORT,
-	/* Unable to abort CCB request */
-	CAM_UA_ABORT		= DID_ERROR,
-	/* CCB request completed with an error */
-	CAM_REQ_CMP_ERR		= DID_ERROR,
-	/* CAM subsytem is busy */
-	CAM_BUSY		= DID_BUS_BUSY,
-	/* CCB request was invalid */
-	CAM_REQ_INVALID		= DID_BAD_TARGET,
-	/* Supplied Path ID is invalid */
-	CAM_PATH_INVALID	= DID_BAD_TARGET,
-	/* Target Selection Timeout */
-	CAM_SEL_TIMEOUT		= DID_NO_CONNECT,
-	/* Command timeout */
-	CAM_CMD_TIMEOUT		= DID_ERROR, /*
-					      * Should never occur in Linux
-					      * as the upper level code
-					      * handles all timeout processing.
-					      */
-	/* SCSI error, look at error code in CCB */
-	CAM_SCSI_STATUS_ERROR	= DID_OK, /* Linux looks at status byte */
-	/* SCSI Bus Reset Sent/Received */
-	CAM_SCSI_BUS_RESET	= DID_RESET,
-	/* Uncorrectable parity error occurred */
-	CAM_UNCOR_PARITY	= DID_PARITY,
-	/* Autosense: request sense cmd fail */
-	CAM_AUTOSENSE_FAIL	= DID_ERROR,
-	/* No HBA Detected Error */
-	CAM_NO_HBA		= DID_ERROR,
-	/* Data Overrun error */
-	CAM_DATA_RUN_ERR	= DID_ERROR,
-	/* Unexpected Bus Free */
-	CAM_UNEXP_BUSFREE	= DID_ERROR,
-	/* CCB length supplied is inadequate */
-	CAM_CCB_LEN_ERR		= DID_ERROR,
-	/* Unable to provide requested capability */
-	CAM_PROVIDE_FAIL	= DID_ERROR,
-	/* A SCSI BDR msg was sent to target */
-	CAM_BDR_SENT		= DID_RESET,
-	/* CCB request terminated by the host */
-	CAM_REQ_TERMIO		= DID_ERROR,
-	/* Unrecoverable Host Bus Adapter Error */
-	CAM_UNREC_HBA_ERROR	= DID_ERROR,
-	/* The request was too large for this host */
-	CAM_REQ_TOO_BIG		= DID_ERROR,
+	CAM_REQ_INPROG,		/* CCB request is in progress */
+	CAM_REQ_CMP,		/* CCB request completed without error */
+	CAM_REQ_ABORTED,	/* CCB request aborted by the host */
+	CAM_UA_ABORT,		/* Unable to abort CCB request */
+	CAM_REQ_CMP_ERR,	/* CCB request completed with an error */
+	CAM_BUSY,		/* CAM subsytem is busy */
+	CAM_REQ_INVALID,	/* CCB request was invalid */
+	CAM_PATH_INVALID,	/* Supplied Path ID is invalid */
+	CAM_SEL_TIMEOUT,	/* Target Selection Timeout */
+	CAM_CMD_TIMEOUT,	/* Command timeout */
+	CAM_SCSI_STATUS_ERROR,	/* SCSI error, look at error code in CCB */
+	CAM_SCSI_BUS_RESET,	/* SCSI Bus Reset Sent/Received */
+	CAM_UNCOR_PARITY,	/* Uncorrectable parity error occurred */
+	CAM_AUTOSENSE_FAIL,	/* Autosense: request sense cmd fail */
+	CAM_NO_HBA,		/* No HBA Detected Error */
+	CAM_DATA_RUN_ERR,	/* Data Overrun error */
+	CAM_UNEXP_BUSFREE,	/* Unexpected Bus Free */
+	CAM_SEQUENCE_FAIL,	/* Protocol Violation */
+	CAM_CCB_LEN_ERR,	/* CCB length supplied is inadequate */
+	CAM_PROVIDE_FAIL,	/* Unable to provide requested capability */
+	CAM_BDR_SENT,		/* A SCSI BDR msg was sent to target */
+	CAM_REQ_TERMIO,		/* CCB request terminated by the host */
+	CAM_UNREC_HBA_ERROR,	/* Unrecoverable Host Bus Adapter Error */
+	CAM_REQ_TOO_BIG,	/* The request was too large for this host */
+	CAM_UA_TERMIO,		/* Unable to terminate I/O CCB request */
+	CAM_MSG_REJECT_REC,	/* Message Reject Received */
+	CAM_DEV_NOT_THERE,	/* SCSI Device Not Installed/there */
+	CAM_RESRC_UNAVAIL,	/* Resource Unavailable */
 	/*
 	 * This request should be requeued to preserve
 	 * transaction ordering.  This typically occurs
@@ -101,7 +79,8 @@
 	 * requests for the target at the sim level
 	 * back into the XPT queue.
 	 */
-	CAM_REQUEUE_REQ		= DID_BUS_BUSY,
+	CAM_REQUEUE_REQ,
+	CAM_DEV_QFRZN		= 0x40,
 
 	CAM_STATUS_MASK		= 0x3F
 } cam_status;
diff -Nru a/drivers/scsi/aic7xxx/scsi_iu.h b/drivers/scsi/aic7xxx/scsi_iu.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/scsi/aic7xxx/scsi_iu.h	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,31 @@
+/*
+ * This file is in the public domain.
+ */
+#ifndef	_SCSI_SCSI_IU_H
+#define _SCSI_SCSI_IU_H 1
+
+struct scsi_status_iu_header
+{
+	u_int8_t reserved[2];
+	u_int8_t flags;
+#define	SIU_SNSVALID 0x2
+#define	SIU_RSPVALID 0x1
+	u_int8_t status;
+	u_int8_t sense_length[4];
+	u_int8_t pkt_failures_length[4];
+	u_int8_t pkt_failures[1];
+};
+
+#define SIU_PKTFAIL_OFFSET(siu) 12
+#define SIU_PKTFAIL_CODE(siu) (scsi_4btoul((siu)->pkt_failures) & 0xFF)
+#define		SIU_PFC_NONE			0
+#define		SIU_PFC_CIU_FIELDS_INVALID	2
+#define		SIU_PFC_TMF_NOT_SUPPORTED	4
+#define		SIU_PFC_TMF_FAILED		5
+#define		SIU_PFC_INVALID_TYPE_CODE	6
+#define		SIU_PFC_ILLEGAL_REQUEST		7
+#define SIU_SENSE_OFFSET(siu)				\
+    (12 + (((siu)->flags & SIU_RSPVALID)		\
+	? scsi_4btoul((siu)->pkt_failures_length)	\
+	: 0))
+#endif /*_SCSI_SCSI_IU_H*/
diff -Nru a/drivers/scsi/aic7xxx/scsi_message.h b/drivers/scsi/aic7xxx/scsi_message.h
--- a/drivers/scsi/aic7xxx/scsi_message.h	Mon Dec 23 21:21:51 2002
+++ b/drivers/scsi/aic7xxx/scsi_message.h	Mon Dec 23 21:21:51 2002
@@ -46,7 +46,7 @@
 #define MSG_IDENTIFY_DISCFLAG	0x40 
 #define MSG_IDENTIFY(lun, disc)	(((disc) ? 0xc0 : MSG_IDENTIFYFLAG) | (lun))
 #define MSG_ISIDENTIFY(m)	((m) & MSG_IDENTIFYFLAG)
-#define MSG_IDENTIFY_LUNMASK	0x03F 
+#define MSG_IDENTIFY_LUNMASK	0x3F 
 
 /* Extended messages (opcode and length) */
 #define MSG_EXT_SDTR		0x01
@@ -60,6 +60,11 @@
 
 #define MSG_EXT_PPR		0x04 /* SPI3 */
 #define MSG_EXT_PPR_LEN		0x06
-#define MSG_EXT_PPR_QAS_REQ	0x04
-#define MSG_EXT_PPR_DT_REQ	0x02
+#define	MSG_EXT_PPR_PCOMP_EN	0x80
+#define	MSG_EXT_PPR_RTI		0x40
+#define	MSG_EXT_PPR_RD_STRM	0x20
+#define	MSG_EXT_PPR_WR_FLOW	0x10
+#define	MSG_EXT_PPR_HOLD_MCS	0x08
+#define	MSG_EXT_PPR_QAS_REQ	0x04
+#define	MSG_EXT_PPR_DT_REQ	0x02
 #define MSG_EXT_PPR_IU_REQ	0x01
diff -Nru a/drivers/scsi/aic7xxx_old/aic7xxx.h b/drivers/scsi/aic7xxx_old/aic7xxx.h
--- a/drivers/scsi/aic7xxx_old/aic7xxx.h	Mon Dec 23 21:21:50 2002
+++ b/drivers/scsi/aic7xxx_old/aic7xxx.h	Mon Dec 23 21:21:50 2002
@@ -45,6 +45,7 @@
 	can_queue: 255,		/* max simultaneous cmds      */\
 	this_id: -1,		/* scsi id of host adapter    */\
 	sg_tablesize: 0,	/* max scatter-gather cmds    */\
+	max_sectors: 2048,	/* max physical sectors in 1 cmd */\
 	cmd_per_lun: 3,		/* cmds per lun (linked cmds) */\
 	present: 0,		/* number of 7xxx's present   */\
 	unchecked_isa_dma: 0,	/* no memory DMA restrictions */\
diff -Nru a/drivers/scsi/aic7xxx_old.c b/drivers/scsi/aic7xxx_old.c
--- a/drivers/scsi/aic7xxx_old.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/scsi/aic7xxx_old.c	Mon Dec 23 21:21:53 2002
@@ -6736,12 +6736,12 @@
  *   prepare for this device to go away
  *-F*************************************************************************/
 static void
-aic7xxx_slave_destroy(Scsi_Device *sdpnt)
+aic7xxx_slave_destroy(Scsi_Device *SDptr)
 {
-  struct aic_dev_data *aic_dev = sdpnt->hostdata;
+  struct aic_dev_data *aic_dev = SDptr->hostdata;
 
   list_del(&aic_dev->list);
-  sdpnt->hostdata = NULL;
+  SDptr->hostdata = NULL;
   kfree(aic_dev);
   return;
 }
@@ -6756,16 +6756,16 @@
  *   depths, allocate command structs, etc.
  *-F*************************************************************************/
 static int
-aic7xxx_slave_configure(Scsi_Device *sdpnt)
+aic7xxx_slave_configure(Scsi_Device *SDptr)
 {
-  struct aic7xxx_host *p = (struct aic7xxx_host *) sdpnt->host->hostdata;
+  struct aic7xxx_host *p = (struct aic7xxx_host *) SDptr->host->hostdata;
   struct aic_dev_data *aic_dev;
   int scbnum;
 
-  aic_dev = (struct aic_dev_data *)sdpnt->hostdata;
+  aic_dev = (struct aic_dev_data *)SDptr->hostdata;
 
   aic7xxx_init_transinfo(p, aic_dev);
-  aic7xxx_device_queue_depth(p, sdpnt);
+  aic7xxx_device_queue_depth(p, SDptr);
   if(list_empty(&aic_dev->list))
     list_add_tail(&aic_dev->list, &p->aic_devs);
 
@@ -9024,7 +9024,6 @@
 
   template->proc_name = "aic7xxx";
   template->sg_tablesize = AIC7XXX_MAX_SG;
-  template->max_sectors = 2048;
 
 
 #ifdef CONFIG_PCI
@@ -9246,12 +9245,22 @@
 	    {
               /* duplicate PCI entry, skip it */
 	      kfree(temp_p);
-	      temp_p = NULL;
+              continue;
 	    }
 	    current_p = current_p->next;
 	  }
-	  if ( temp_p == NULL )
+          if(pci_request_regions(temp_p->pdev, "aic7xxx"))
+          {
+            printk("aic7xxx: <%s> at PCI %d/%d/%d\n", 
+              board_names[aic_pdevs[i].board_name_index],
+              temp_p->pci_bus,
+              PCI_SLOT(temp_p->pci_device_fn),
+              PCI_FUNC(temp_p->pci_device_fn));
+            printk("aic7xxx: I/O ports already in use, ignoring.\n");
+            kfree(temp_p);
             continue;
+          }
+
           if (aic7xxx_verbose & VERBOSE_PROBE2)
             printk("aic7xxx: <%s> at PCI %d/%d\n", 
               board_names[aic_pdevs[i].board_name_index],
@@ -9283,20 +9292,6 @@
           pci_write_config_dword(pdev, DEVCONFIG, devconfig);
 #endif /* AIC7XXX_STRICT_PCI_SETUP */
 
-          if(temp_p->base && !request_region(temp_p->base, MAXREG - MINREG,
-				  "aic7xxx"))
-          {
-            printk("aic7xxx: <%s> at PCI %d/%d/%d\n", 
-              board_names[aic_pdevs[i].board_name_index],
-              temp_p->pci_bus,
-              PCI_SLOT(temp_p->pci_device_fn),
-              PCI_FUNC(temp_p->pci_device_fn));
-            printk("aic7xxx: I/O ports already in use, ignoring.\n");
-            kfree(temp_p);
-            temp_p = NULL;
-            continue;
-          }
-
           temp_p->unpause = INTEN;
           temp_p->pause = temp_p->unpause | PAUSE;
           if ( ((temp_p->base == 0) &&
@@ -9309,9 +9304,7 @@
               PCI_SLOT(temp_p->pci_device_fn),
               PCI_FUNC(temp_p->pci_device_fn));
             printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
-            kfree(temp_p);
-            temp_p = NULL;
-            continue;
+            goto skip_pci_controller;
           }
 
 #ifdef MMAPIO
@@ -9353,9 +9346,7 @@
                     PCI_SLOT(temp_p->pci_device_fn),
                     PCI_FUNC(temp_p->pci_device_fn));
                   printk("aic7xxx: Controller disabled by BIOS, ignoring.\n");
-                  kfree(temp_p);
-                  temp_p = NULL;
-                  continue;
+                  goto skip_pci_controller;
                 }
               }
             }
@@ -9398,10 +9389,7 @@
 
           if (aic7xxx_chip_reset(temp_p) == -1)
           {
-            release_region(temp_p->base, MAXREG - MINREG);
-            kfree(temp_p);
-            temp_p = NULL;
-            continue;
+            goto skip_pci_controller;
           }
           /*
            * Very quickly put the term setting back into the register since
@@ -9687,6 +9675,10 @@
           }
           temp_p->next = NULL;
           found++;
+	  continue;
+skip_pci_controller:
+	  pci_release_regions(temp_p->pdev);
+	  kfree(temp_p);
         }  /* Found an Adaptec PCI device. */
         else /* Well, we found one, but we couldn't get any memory */
         {
@@ -10969,14 +10961,16 @@
 
   if(p->irq)
     free_irq(p->irq, p);
-  if(p->base)
-    release_region(p->base, MAXREG - MINREG);
 #ifdef MMAPIO
   if(p->maddr)
   {
     iounmap((void *) (((unsigned long) p->maddr) & PAGE_MASK));
   }
 #endif /* MMAPIO */
+  if(!p->pdev)
+    release_region(p->base, MAXREG - MINREG);
+  else
+    pci_release_regions(p->pdev);
   prev = NULL;
   next = first_aic7xxx;
   while(next != NULL)
diff -Nru a/drivers/scsi/eata_pio_proc.c b/drivers/scsi/eata_pio_proc.c
--- a/drivers/scsi/eata_pio_proc.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/scsi/eata_pio_proc.c	Mon Dec 23 21:21:59 2002
@@ -85,7 +85,7 @@
     len += size; 
     pos = begin + len;
     
-    list_for_each_entry(scd, &HBA_ptr->my_devices; siblings) {
+    list_for_each_entry(scd, &HBA_ptr->my_devices, siblings) {
 	    proc_print_scsidevice(scd, buffer, &size, len);
 	    len += size; 
 	    pos = begin + len;
diff -Nru a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
--- a/drivers/scsi/hosts.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/scsi/hosts.c	Mon Dec 23 21:21:50 2002
@@ -485,13 +485,6 @@
 
 	BUG_ON(!shost_tp->detect);
 
-	if (!shost_tp->max_sectors) {
-		printk(KERN_WARNING
-		    "scsi HBA driver %s didn't set max_sectors, "
-		    "please fix the template\n", shost_tp->name);
-		shost_tp->max_sectors = 1024;
-	}
-
 	if (!shost_tp->release) {
 		printk(KERN_WARNING
 		    "scsi HBA driver %s didn't set a release method, "
diff -Nru a/drivers/scsi/hosts.h b/drivers/scsi/hosts.h
--- a/drivers/scsi/hosts.h	Mon Dec 23 21:21:53 2002
+++ b/drivers/scsi/hosts.h	Mon Dec 23 21:21:53 2002
@@ -554,9 +554,6 @@
     struct device_driver scsi_driverfs_driver;
 };
 
-void  scsi_initialize_queue(Scsi_Device *, struct Scsi_Host *);
-
-
 /*
  * Highlevel driver registration/unregistration.
  */
diff -Nru a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
--- a/drivers/scsi/ide-scsi.c	Mon Dec 23 21:21:57 2002
+++ b/drivers/scsi/ide-scsi.c	Mon Dec 23 21:21:57 2002
@@ -28,9 +28,10 @@
  * Ver 0.8   Feb 05 99   Optical media need translation too. Reverse 0.7.
  * Ver 0.9   Jul 04 99   Fix a bug in SG_SET_TRANSFORM.
  * Ver 0.91  Jun 10 02   Fix "off by one" error in transforms
+ * Ver 0.92  Dec 31 02   Implement new SCSI mid level API
  */
 
-#define IDESCSI_VERSION "0.9"
+#define IDESCSI_VERSION "0.92"
 
 #include <linux/module.h>
 #include <linux/config.h>
@@ -259,6 +260,42 @@
 	printk("]\n");
 }
 
+static int idescsi_check_condition(ide_drive_t *drive, struct request *failed_command)
+{
+	idescsi_scsi_t *scsi = drive->driver_data;
+	idescsi_pc_t   *pc;
+	struct request *rq;
+	u8             *buf;
+
+	/* stuff a sense request in front of our current request */
+	pc = kmalloc (sizeof (idescsi_pc_t), GFP_ATOMIC);
+	rq = kmalloc (sizeof (struct request), GFP_ATOMIC);
+	buf = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_ATOMIC);
+	if (pc == NULL || rq == NULL || buf == NULL) {
+		if (pc) kfree(pc);
+		if (rq) kfree(rq);
+		if (buf) kfree(buf);
+		return -ENOMEM;
+	}
+	memset (pc, 0, sizeof (idescsi_pc_t));
+	memset (buf, 0, SCSI_SENSE_BUFFERSIZE);
+	ide_init_drive_cmd(rq);
+	rq->special = (char *) pc;
+	pc->rq = rq;
+	pc->buffer = buf;
+	pc->c[0] = REQUEST_SENSE;
+	pc->c[4] = pc->request_transfer = pc->buffer_size = SCSI_SENSE_BUFFERSIZE;
+	rq->flags = REQ_SENSE;
+	pc->timeout = jiffies + WAIT_READY;
+	/* NOTE! Save the failed packet command in "rq->buffer" */
+	rq->buffer = (void *) failed_command->special;
+	if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) {
+		printk ("ide-scsi: %s: queue cmd = ", drive->name);
+		hexdump(pc->c, 6);
+	}
+	return ide_do_drive_cmd(drive, rq, ide_preempt);
+}
+
 static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
 {
 	idescsi_scsi_t *scsi = drive->driver_data;
@@ -269,19 +306,35 @@
 	u8 *scsi_buf;
 	unsigned long flags;
 
-	if (!(rq->flags & REQ_SPECIAL)) {
+	if (!(rq->flags & (REQ_SPECIAL|REQ_SENSE))) {
 		ide_end_request(drive, uptodate, nrsecs);
 		return 0;
 	}
 	ide_end_drive_cmd (drive, 0, 0);
-	if (rq->errors >= ERROR_MAX) {
+	if (rq->flags & REQ_SENSE) {
+		idescsi_pc_t *opc = (idescsi_pc_t *) rq->buffer;
+		if (log) {
+			printk ("ide-scsi: %s: wrap up check %lu, rst = ", drive->name, opc->scsi_cmd->serial_number);
+			hexdump(pc->buffer,16);
+		}
+		memcpy((void *) opc->scsi_cmd->sense_buffer, pc->buffer, SCSI_SENSE_BUFFERSIZE);
+		kfree(pc->buffer);
+		kfree(pc);
+		kfree(rq);
+		pc = opc;
+		rq = pc->rq;
+		pc->scsi_cmd->result = (CHECK_CONDITION << 1) | (DID_OK << 16);
+	} else if (rq->errors >= ERROR_MAX) {
 		pc->scsi_cmd->result = DID_ERROR << 16;
 		if (log)
 			printk ("ide-scsi: %s: I/O error for %lu\n", drive->name, pc->scsi_cmd->serial_number);
 	} else if (rq->errors) {
-		pc->scsi_cmd->result = (CHECK_CONDITION << 1) | (DID_OK << 16);
 		if (log)
 			printk ("ide-scsi: %s: check condition for %lu\n", drive->name, pc->scsi_cmd->serial_number);
+		if (!idescsi_check_condition(drive, rq))
+			/* we started a request sense, so we'll be back, exit for now */
+			return 0;
+		pc->scsi_cmd->result = (CHECK_CONDITION << 1) | (DID_OK << 16);
 	} else {
 		pc->scsi_cmd->result = DID_OK << 16;
 		idescsi_transform_pc2 (drive, pc);
@@ -489,11 +542,11 @@
 static ide_startstop_t idescsi_do_request (ide_drive_t *drive, struct request *rq, sector_t block)
 {
 #if IDESCSI_DEBUG_LOG
-	printk (KERN_INFO "rq_status: %d, dev: %s, cmd: %d, errors: %d\n",rq->rq_status, rq->rq_disk->disk_name,rq->cmd,rq->errors);
-	printk (KERN_INFO "sector: %ld, nr_sectors: %ld, current_nr_sectors: %ld\n",rq->sector,rq->nr_sectors,rq->current_nr_sectors);
+	printk (KERN_INFO "rq_status: %d, dev: %s, cmd: %x, errors: %d\n",rq->rq_status, rq->rq_disk->disk_name,rq->cmd[0],rq->errors);
+	printk (KERN_INFO "sector: %ld, nr_sectors: %ld, current_nr_sectors: %d\n",rq->sector,rq->nr_sectors,rq->current_nr_sectors);
 #endif /* IDESCSI_DEBUG_LOG */
 
-	if (rq->flags & REQ_SPECIAL) {
+	if (rq->flags & (REQ_SPECIAL|REQ_SENSE)) {
 		return idescsi_issue_pc (drive, (idescsi_pc_t *) rq->special);
 	}
 	blk_dump_rq_flags(rq, "ide-scsi: unsup command");
@@ -629,35 +682,10 @@
 	return 1;
 }
 
-int idescsi_detect (Scsi_Host_Template *host_template)
+int idescsi_slave_configure(Scsi_Device * sdp)
 {
-	struct Scsi_Host *host;
-	int id;
-	int last_lun = 0;
-
-	host_template->proc_name = "ide-scsi";
-	host = scsi_register(host_template, 0);
-	if(host == NULL)
-		return 0;
-		
-	for (id = 0; id < MAX_HWIFS * MAX_DRIVES && idescsi_drives[id]; id++)
-		last_lun = IDE_MAX(last_lun, idescsi_drives[id]->last_lun);
-	host->max_id = id;
-	host->max_lun = last_lun + 1;
-	host->can_queue = host->cmd_per_lun * id;
-	return 1;
-}
-
-int idescsi_release (struct Scsi_Host *host)
-{
-	ide_drive_t *drive;
-	int id;
-
-	for (id = 0; id < MAX_HWIFS * MAX_DRIVES; id++) {
-		drive = idescsi_drives[id];
-		if (drive)
-			DRIVER(drive)->busy--;
-	}
+	/* Configure detected device */
+	scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, sdp->host->cmd_per_lun);
 	return 0;
 }
 
@@ -832,17 +860,67 @@
 	if (rq) kfree (rq);
 	cmd->result = DID_ERROR << 16;
 	done(cmd);
-	return 0;
+	return 1;
 }
 
 int idescsi_abort (Scsi_Cmnd *cmd)
 {
-	return SCSI_ABORT_SNOOZE;
+	int countdown = 8;
+	unsigned long flags;
+	ide_drive_t *drive = idescsi_drives[cmd->target];
+	idescsi_scsi_t *scsi;
+
+	printk (KERN_ERR "ide-scsi: abort called for %lu\n", cmd->serial_number);
+	if (drive && (scsi = drive->driver_data))
+		while (countdown--) {
+			/* is cmd active?
+			 *  need to lock so this stuff doesn't change under us */
+			spin_lock_irqsave(&ide_lock, flags);
+			if (scsi->pc && scsi->pc->scsi_cmd->serial_number == cmd->serial_number) {
+				/* yep - let's give it some more time - 
+				 * we can do that, we're in _our_ error kernel thread */
+				spin_unlock_irqrestore(&ide_lock, flags);
+				scsi_sleep(HZ);
+				continue;
+			}
+			/* no, but is it queued in the ide subsystem? */
+			if (elv_queue_empty(&drive->queue)) {
+				spin_unlock_irqrestore(&ide_lock, flags);
+				return SUCCESS;
+			}
+			spin_unlock_irqrestore(&ide_lock, flags);
+			schedule_timeout(HZ/10);
+		}
+	return FAILED;
 }
 
-int idescsi_reset (Scsi_Cmnd *cmd, unsigned int resetflags)
+int idescsi_reset (Scsi_Cmnd *cmd)
 {
-	return SCSI_RESET_SUCCESS;
+	unsigned long flags;
+	struct request *req;
+	ide_drive_t *drive = idescsi_drives[cmd->target];
+
+	printk (KERN_ERR "ide-scsi: reset called for %lu\n", cmd->serial_number);
+	/* first null the handler for the drive and let any process
+	 * doing IO (on another CPU) run to (partial) completion
+	 * the lock prevents processing new requests */
+	spin_lock_irqsave(&ide_lock, flags);
+	while (HWGROUP(drive)->handler) {
+		HWGROUP(drive)->handler = NULL;
+		schedule_timeout(1);
+	}
+	/* now nuke the drive queue */
+	while ((req = elv_next_request(&drive->queue))) {
+		blkdev_dequeue_request(req);
+		end_that_request_last(req);
+	}
+	/* FIXME - this will probably leak memory */
+	HWGROUP(drive)->rq = NULL;
+	if (drive->driver_data) ((idescsi_scsi_t *)drive->driver_data)->pc = NULL;
+	spin_unlock_irqrestore(&ide_lock, flags);
+	/* finally, reset the drive (and its partner on the bus...) */
+	ide_do_reset (drive);	
+	return SUCCESS;
 }
 
 static int idescsi_bios(struct scsi_device *sdev, struct block_device *bdev,
@@ -859,32 +937,69 @@
 }
 
 static Scsi_Host_Template idescsi_template = {
-	.module		= THIS_MODULE,
-	.name		= "idescsi",
-	.detect		= idescsi_detect,
-	.release	= idescsi_release,
-	.info		= idescsi_info,
-	.ioctl		= idescsi_ioctl,
-	.queuecommand	= idescsi_queue,
-	.bios_param	= idescsi_bios,
-	.can_queue	= 10,
-	.this_id	= -1,
-	.sg_tablesize	= 256,
-	.cmd_per_lun	= 5,
-	.use_clustering	= DISABLE_CLUSTERING,
-	.emulated	= 1,
+	.module			= THIS_MODULE,
+	.name			= "idescsi",
+	.info			= idescsi_info,
+	.slave_configure        = idescsi_slave_configure,
+	.ioctl			= idescsi_ioctl,
+	.queuecommand		= idescsi_queue,
+	.eh_abort_handler	= idescsi_abort,
+	.eh_device_reset_handler = idescsi_reset,
+	.bios_param		= idescsi_bios,
+	.can_queue		= 40,
+	.this_id		= -1,
+	.sg_tablesize		= 256,
+	.cmd_per_lun		= 5,
+	.max_sectors		= 128,
+	.use_clustering		= DISABLE_CLUSTERING,
+	.emulated		= 1,
+};
+
+static struct Scsi_Host *idescsi_host;
+
+static struct device     idescsi_primary = {
+	.name		= "Ide-scsi Parent",
+	.bus_id		= "ide-scsi",
+};
+static struct bus_type   idescsi_emu_bus = {
+	.name		= "ide-scsi",
 };
 
 static int __init init_idescsi_module(void)
 {
+	int id;
+	int last_lun = 0;
+
 	ide_register_driver(&idescsi_driver);
-	scsi_register_host(&idescsi_template);
+	device_register(&idescsi_primary);
+	bus_register   (&idescsi_emu_bus);
+	idescsi_template.proc_name = "ide-scsi";
+	idescsi_host = scsi_register(&idescsi_template, 0);
+	if(idescsi_host == NULL)
+		return 1;
+		
+	for (id = 0; id < MAX_HWIFS * MAX_DRIVES && idescsi_drives[id]; id++)
+		last_lun = IDE_MAX(last_lun, idescsi_drives[id]->last_lun);
+	idescsi_host->max_id = id;
+	idescsi_host->max_lun = last_lun + 1;
+	scsi_add_host(idescsi_host, &idescsi_primary);
 	return 0;
 }
 
 static void __exit exit_idescsi_module(void)
 {
-	scsi_unregister_host(&idescsi_template);
+	ide_drive_t *drive;
+	int id;
+
+	scsi_remove_host(idescsi_host);
+	for (id = 0; id < MAX_HWIFS * MAX_DRIVES; id++) {
+		drive = idescsi_drives[id];
+		if (drive)
+			DRIVER(drive)->busy--;
+	}
+	scsi_unregister   (idescsi_host);
+	device_unregister(&idescsi_primary);
+	bus_unregister   (&idescsi_emu_bus);
 	ide_unregister_driver(&idescsi_driver);
 }
 
diff -Nru a/drivers/scsi/lasi700.c b/drivers/scsi/lasi700.c
--- a/drivers/scsi/lasi700.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/scsi/lasi700.c	Mon Dec 23 21:21:51 2002
@@ -114,7 +114,11 @@
 
 MODULE_DEVICE_TABLE(parisc, lasi700_scsi_tbl);
 
-static struct parisc_driver lasi700_driver = LASI700_DRIVER;
+static struct parisc_driver lasi700_driver = {
+	.name =		"Lasi SCSI",
+	.id_table =	lasi700_scsi_tbl,
+	.probe =	lasi700_driver_callback,
+};
 
 static int __init
 lasi700_detect(Scsi_Host_Template *tpnt)
@@ -145,6 +149,7 @@
 	} else {
 		driver_name = "lasi710";
 	}
+	snprintf(dev->dev.name, sizeof(dev->dev.name), "%s", driver_name);
 	if(hostdata == NULL) {
 		printk(KERN_ERR "%s: Failed to allocate host data\n",
 		       driver_name);
@@ -168,12 +173,14 @@
 		hostdata->chip710 = 1;
 		hostdata->dmode_extra = DMODE_FC2;
 	}
-	hostdata->pci_dev = ccio_get_fake(dev);
+	hostdata->dev = &dev->dev;
+	dma_set_mask(&dev->dev, 0xffffffffUL);
 	if((host = NCR_700_detect(host_tpnt, hostdata)) == NULL) {
 		kfree(hostdata);
 		release_mem_region(host->base, 64);
 		return 1;
 	}
+	scsi_set_device(host, &dev->dev);
 	host->irq = dev->irq;
 	if(request_irq(dev->irq, NCR_700_intr, SA_SHIRQ, driver_name, host)) {
 		printk(KERN_ERR "%s: irq problem, detaching\n",
diff -Nru a/drivers/scsi/lasi700.h b/drivers/scsi/lasi700.h
--- a/drivers/scsi/lasi700.h	Mon Dec 23 21:21:51 2002
+++ b/drivers/scsi/lasi700.h	Mon Dec 23 21:21:51 2002
@@ -55,12 +55,6 @@
 	.hversion_rev	= HVERSION_REV_ANY_ID,	\
 }
 
-#define LASI700_DRIVER {			\
-	.name		= "Lasi SCSI",		\
-	.id_table	= lasi700_scsi_tbl,	\
-	.probe		= lasi700_driver_callback,\
-}
-
 #define LASI700_CLOCK	25
 #define LASI710_CLOCK	40
 #define LASI_SCSI_CORE_OFFSET 0x100
diff -Nru a/drivers/scsi/osst.c b/drivers/scsi/osst.c
--- a/drivers/scsi/osst.c	Mon Dec 23 21:21:54 2002
+++ b/drivers/scsi/osst.c	Mon Dec 23 21:21:54 2002
@@ -24,7 +24,7 @@
 */
 
 static const char * cvsid = "$Id: osst.c,v 1.65 2001/11/11 20:38:56 riede Exp $";
-const char * osst_version = "0.99.0p3";
+const char * osst_version = "0.99.0p5";
 
 /* The "failure to reconnect" firmware bug */
 #define OSST_FW_NEED_POLL_MIN 10601 /*(107A)*/
@@ -60,7 +60,6 @@
    in the drivers are more widely classified, this may be changed to KERN_DEBUG. */
 #define OSST_DEB_MSG  KERN_NOTICE
 
-
 #include "scsi.h"
 #include "hosts.h"
 #include <scsi/scsi_ioctl.h>
@@ -85,7 +84,7 @@
 MODULE_PARM_DESC(max_dev, "Maximum number of OnStream Tape Drives to attach (4)");
 
 MODULE_PARM(write_threshold_kbs, "i");
-MODULE_PARM_DESC(write_threshold_kbs, "Asynchronous write threshold (KB; 30)");
+MODULE_PARM_DESC(write_threshold_kbs, "Asynchronous write threshold (KB; 32)");
 
 MODULE_PARM(max_sg_segs, "i");
 MODULE_PARM_DESC(max_sg_segs, "Maximum number of scatter/gather segments to use (9)");
@@ -170,8 +169,8 @@
 	.attach =       osst_attach,
 	.detach =       osst_detach,
 	.scsi_driverfs_driver = {
-		.name	= "osst",
-	},
+		.name =  "osst",
+	}
 };
 
 static int osst_int_ioctl(OS_Scsi_Tape *STp, Scsi_Request ** aSRpnt, unsigned int cmd_in,unsigned long arg);
@@ -221,7 +220,7 @@
 		if (scode) printk(OSST_DEB_MSG "%s:D: Sense: %02x, ASC: %02x, ASCQ: %02x\n",
 			       	name, scode, sense[12], sense[13]);
 		if (driver_byte(result) & DRIVER_SENSE)
-			print_req_sense("osst", SRpnt);
+			print_req_sense("osst ", SRpnt);
 	}
 //	else
 #endif
@@ -543,8 +542,6 @@
 				 STp->first_frame_position);
 		goto err_out;
 	}
-//	STp->frame_in_buffer = 1;
-
         if (frame_seq_number != -1 && ntohl(aux->frame_seq_num) != frame_seq_number) {
 		if (!quiet)
 #if DEBUG
@@ -749,7 +746,7 @@
 	Scsi_Request  * SRpnt;
 
 	int             result = 0;
-	int		delay  = OSST_WAIT_LONG_WRITE_COMPLETE;
+	int		delay  = OSST_WAIT_WRITE_COMPLETE;
 #if DEBUG
 	char *name = tape_name(STp);
 
@@ -763,17 +760,14 @@
 	SRpnt = osst_do_scsi(*aSRpnt, STp, cmd, 0, SCSI_DATA_NONE, STp->timeout, MAX_WRITE_RETRIES, TRUE);
 	*aSRpnt = SRpnt;
 	if (!SRpnt) return (-EBUSY);
-//printk(OSST_DEB_MSG "%s:X: Write filemark returned %x:%02x:%02x:%02x\n",dev,STp->buffer->syscall_result,SRpnt->sr_sense_buffer[2] & 0x0f,SRpnt->sr_sense_buffer[12],SRpnt->sr_sense_buffer[13]);
 	if (STp->buffer->syscall_result) {
 		if ((SRpnt->sr_sense_buffer[2] & 0x0f) == 2 && SRpnt->sr_sense_buffer[12] == 4) {
 			if (SRpnt->sr_sense_buffer[13] == 8) {
-//printk(OSST_DEB_MSG "%s:X: Long initial delay\n", dev);
 				delay = OSST_WAIT_LONG_WRITE_COMPLETE;
 			}
 		} else
 			result = osst_write_error_recovery(STp, aSRpnt, 0);
 	}
-//printk(OSST_DEB_MSG "%s:X: Entering wait ready (%d)\n",dev,delay);
 	result |= osst_wait_ready(STp, aSRpnt, 5 * 60, delay);
 	STp->ps[STp->partition].rw = OS_WRITING_COMPLETE;
 
@@ -1708,12 +1702,7 @@
 						 name, last_mark_ppos);
 				return (-EIO);
 			}
-			if (mt_op == MTBSFM) {
-				STp->frame_seq_number++;
-				STp->frame_in_buffer  = 0;
-				STp->logical_blk_num += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
-			}
-			return 0;
+			goto found;
 		}
 #if DEBUG
 		printk(OSST_DEB_MSG "%s:D: Reverting to scan filemark backwards\n", name);
@@ -1741,10 +1730,13 @@
 			return (-EIO);
 		}
 	}
+found:
 	if (mt_op == MTBSFM) {
 		STp->frame_seq_number++;
-		STp->frame_in_buffer  = 0;
-		STp->logical_blk_num += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
+		STp->frame_in_buffer      = 0;
+		STp->buffer->buffer_bytes = 0;
+		STp->buffer->read_pointer = 0;
+		STp->logical_blk_num     += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
 	}
 	return 0;
 }
@@ -1797,8 +1789,10 @@
 	}
 	if (mt_op == MTFSF) {
 		STp->frame_seq_number++;
-		STp->frame_in_buffer  = 0;
-		STp->logical_blk_num += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
+		STp->frame_in_buffer      = 0;
+		STp->buffer->buffer_bytes = 0;
+		STp->buffer->read_pointer = 0;
+		STp->logical_blk_num     += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
 	}
 	return 0;
 }
@@ -1944,9 +1938,10 @@
 	}
 	if (mt_op == MTFSF) {
 		STp->frame_seq_number++;
-		STp->frame_in_buffer  = 0;
+		STp->frame_in_buffer      = 0;
+		STp->buffer->buffer_bytes = 0;
 		STp->buffer->read_pointer = 0;
-		STp->logical_blk_num += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
+		STp->logical_blk_num     += ntohs(STp->buffer->aux->dat.dat_list[0].blk_cnt);
 	}
 	return 0;
 }
@@ -3215,8 +3210,8 @@
 
 	/* Write must be integral number of blocks */
 	if (STp->block_size != 0 && (count % STp->block_size) != 0) {
-		printk(KERN_ERR "%s:E: Write (%ld bytes) not multiple of tape block size (%d%c).\n",
-				       name, (unsigned long)count, STp->block_size<1024?
+		printk(KERN_ERR "%s:E: Write (%Zd bytes) not multiple of tape block size (%d%c).\n",
+				       name, count, STp->block_size<1024?
 				       STp->block_size:STp->block_size/1024, STp->block_size<1024?'b':'k');
 		retval = (-EINVAL);
 		goto out;
@@ -4140,8 +4135,14 @@
 
 		if (cmd_in == MTEOM)
 			STps->eof = ST_EOD;
-		else if ((cmd_in == MTFSFM || cmd_in == MTBSF) && STps->eof == ST_FM_HIT)
-			ioctl_result = osst_seek_logical_blk(STp, &SRpnt, STp->logical_blk_num - 1);
+		else if ((cmd_in == MTFSFM || cmd_in == MTBSF) && STps->eof == ST_FM_HIT) {
+			ioctl_result = osst_seek_logical_blk(STp, &SRpnt, STp->logical_blk_num-1);
+			STps->drv_block++;
+			STp->logical_blk_num++;
+			STp->frame_seq_number++;
+			STp->frame_in_buffer = 0;
+			STp->buffer->read_pointer = 0;
+		}
 		else if (cmd_in == MTFSF)
 			STps->eof = (STp->first_frame_position >= STp->eod_frame_ppos)?ST_EOD:ST_FM;
 		else if (chg_eof)
@@ -4233,8 +4234,7 @@
 #endif
 		return (-EBUSY);
 	}
-
-	if (!scsi_device_get(STp->device)) {
+	if (scsi_device_get(STp->device)) {
 		write_unlock(&os_scsi_tapes_lock);
 #if DEBUG
                 printk(OSST_DEB_MSG "%s:D: Failed scsi_device_get.\n", name);
@@ -4856,12 +4856,6 @@
 		}
 
 		if (mtc.mt_op == MTSETPART) {
-/*     if (!STp->can_partitions ||
-	   mtc.mt_count < 0 || mtc.mt_count >= ST_NBR_PARTITIONS)
-	 return (-EINVAL);
-		 if (mtc.mt_count >= STp->nbr_partitions &&
-	   (STp->nbr_partitions = nbr_partitions(inode)) < 0)
-	 return (-EIO);*/
 			if (mtc.mt_count >= STp->nbr_partitions)
 				retval = -EINVAL;
 			else {
@@ -4909,10 +4903,6 @@
 			goto out;
 		}
 			
-/*   if (STp->can_partitions && STp->ready == ST_READY &&
-	 (i = update_partition(inode)) < 0)
-		 {retval=i;goto out;}*/
-
 		if (mtc.mt_op == MTCOMPRESSION)
 			retval = -EINVAL /*osst_compression(STp, (mtc.mt_count & 1))*/;
 		else
@@ -4931,10 +4921,6 @@
 		goto out;
 	}
 
-/* if (STp->can_partitions &&
-		 (i = update_partition(inode)) < 0)
-	 {retval=i;goto out;}*/
-
 	if (cmd_type == _IOC_TYPE(MTIOCGET) && cmd_nr == _IOC_NR(MTIOCGET)) {
 		struct mtget mt_status;
 
@@ -5110,9 +5096,7 @@
 	for (segs=STbuffer->sg_segs=1, got=b_size;
 	     segs < max_segs && got < OS_FRAME_SIZE; ) {
 		STbuffer->sg[segs].page =
-			(OS_FRAME_SIZE - got <= PAGE_SIZE / 2) ?
-				kmalloc(OS_FRAME_SIZE - got, priority):
-				alloc_pages(priority, order);
+				alloc_pages(priority, (OS_FRAME_SIZE - got <= PAGE_SIZE) ? 0 : order);
 		STbuffer->sg[segs].offset = 0;
 		if (STbuffer->sg[segs].page == NULL) {
 			if (OS_FRAME_SIZE - got <= (max_segs - segs) * b_size / 2 && order) {
@@ -5320,10 +5304,8 @@
   if (max_sg_segs >= OSST_FIRST_SG)
 		osst_max_sg_segs = max_sg_segs;
 #if DEBUG
-  printk(OSST_DEB_MSG "osst :D: max tapes %d, write threshold %d, s/g segs %d.\n",
+  printk(OSST_DEB_MSG "osst :D: max tapes %d, write threshold %d, max s/g segs %d.\n",
 			   osst_max_dev, osst_write_threshold, osst_max_sg_segs);
-//printk(OSST_DEB_MSG "osst :D: sizeof(header) = %d (%s)\n",
-//		sizeof(os_header_t),sizeof(os_header_t)==OS_DATA_SIZE?"ok":"error");
 #endif
 }
 	
@@ -5446,7 +5428,7 @@
 	drive = alloc_disk(1);
 	if (!drive) {
 		printk(KERN_ERR "osst :E: Out of memory. Device not attached.\n");
-		return 1;
+		goto out_slave_detach;
 	}
 
 	/* if this is the first attach, build the infrastructure */
@@ -5458,7 +5440,7 @@
 		if (os_scsi_tapes == NULL) {
 			write_unlock(&os_scsi_tapes_lock);
 			printk(KERN_ERR "osst :E: Unable to allocate array for OnStream SCSI tapes.\n");
-			return 1;
+			goto out_put_disk;
 		}
 		for (i=0; i < osst_max_dev; ++i) os_scsi_tapes[i] = NULL;
 	}
@@ -5466,8 +5448,7 @@
 	if (osst_nr_dev >= osst_max_dev) {
 		write_unlock(&os_scsi_tapes_lock);
 		printk(KERN_ERR "osst :E: Too many tape devices (max. %d).\n", osst_max_dev);
-		put_disk(drive);
-		return 1;
+		goto out_put_disk;
 	}
 
 	/* find a free minor number */
@@ -5480,9 +5461,7 @@
 	if (tpnt == NULL) {
 		write_unlock(&os_scsi_tapes_lock);
 		printk(KERN_ERR "osst :E: Can't allocate device descriptor, device not attached.\n");
-		put_disk(drive);
-		scsi_slave_detach(SDp);
-		return 1;
+		goto out_put_disk;
 	}
 	memset(tpnt, 0, sizeof(OS_Scsi_Tape));
 
@@ -5495,9 +5474,7 @@
 		write_unlock(&os_scsi_tapes_lock);
 		printk(KERN_ERR "osst :E: Unable to allocate a tape buffer, device not attached.\n");
 		kfree(tpnt);
-		put_disk(drive);
-		scsi_slave_detach(SDp);
-		return 1;
+		goto out_put_disk;
 	}
 	os_scsi_tapes[dev_num] = tpnt;
 	tpnt->buffer = buffer;
@@ -5623,6 +5600,12 @@
 		SDp->model, SDp->host->host_no, SDp->channel, SDp->id, SDp->lun, tape_name(tpnt));
 
 	return 0;
+
+out_put_disk:
+        put_disk(drive);
+out_slave_detach:
+        scsi_slave_detach(SDp);
+        return 1;
 };
 
 static void osst_detach(Scsi_Device * SDp)
@@ -5630,48 +5613,46 @@
   OS_Scsi_Tape * tpnt;
   int i, mode;
 
+  if ((SDp->type != TYPE_TAPE) || (osst_nr_dev <= 0))
+	  return;
+
   write_lock(&os_scsi_tapes_lock);
-  if (os_scsi_tapes != NULL) {
-	  for(i=0; i<osst_max_dev; i++) {
-		tpnt = os_scsi_tapes[i];
-		if(tpnt != NULL && tpnt->device == SDp) {
-			tpnt->device = NULL;
-			for (mode = 0; mode < ST_NBR_MODES; ++mode) {
-				devfs_unregister (tpnt->de_r[mode]);
-				tpnt->de_r[mode] = NULL;
-				devfs_unregister (tpnt->de_n[mode]);
-				tpnt->de_n[mode] = NULL;
-			}
-			devfs_unregister_tape(tpnt->drive->number);
-			put_disk(tpnt->drive);
-			os_scsi_tapes[i] = NULL;
-			scsi_slave_detach(SDp);
-			osst_nr_dev--;
-			write_unlock(&os_scsi_tapes_lock);
-			for (mode = 0; mode < ST_NBR_MODES; ++mode) {
-				device_remove_file(&tpnt->driverfs_dev_r[mode],
-						&dev_attr_type);
-				device_remove_file(&tpnt->driverfs_dev_r[mode],
-						&dev_attr_kdev);
-				device_unregister(&tpnt->driverfs_dev_r[mode]);
-				device_remove_file(&tpnt->driverfs_dev_n[mode],
-						&dev_attr_type);
-				device_remove_file(&tpnt->driverfs_dev_n[mode],
-						&dev_attr_kdev);
-				device_unregister(&tpnt->driverfs_dev_n[mode]);
-			}
-			if (tpnt->header_cache != NULL)
-				vfree(tpnt->header_cache);
-			if (tpnt->buffer) {
-				normalize_buffer(tpnt->buffer);
-				kfree(tpnt->buffer);
-			}
-			kfree(tpnt);
-			break;
+  for(i=0; i < osst_max_dev; i++) {
+	if((tpnt = os_scsi_tapes[i]) && (tpnt->device == SDp)) {
+		tpnt->device = NULL;
+		for (mode = 0; mode < ST_NBR_MODES; ++mode) {
+			devfs_unregister (tpnt->de_r[mode]);
+			tpnt->de_r[mode] = NULL;
+			devfs_unregister (tpnt->de_n[mode]);
+			tpnt->de_n[mode] = NULL;
+		}
+		devfs_unregister_tape(tpnt->drive->number);
+		put_disk(tpnt->drive);
+		os_scsi_tapes[i] = NULL;
+		scsi_slave_detach(SDp);
+		osst_nr_dev--;
+		write_unlock(&os_scsi_tapes_lock);
+		for (mode = 0; mode < ST_NBR_MODES; ++mode) {
+			device_remove_file(&tpnt->driverfs_dev_r[mode],
+					&dev_attr_type);
+			device_remove_file(&tpnt->driverfs_dev_r[mode],
+					&dev_attr_kdev);
+			device_unregister(&tpnt->driverfs_dev_r[mode]);
+			device_remove_file(&tpnt->driverfs_dev_n[mode],
+					&dev_attr_type);
+			device_remove_file(&tpnt->driverfs_dev_n[mode],
+					&dev_attr_kdev);
+			device_unregister(&tpnt->driverfs_dev_n[mode]);
+			}
+		if (tpnt->header_cache != NULL) vfree(tpnt->header_cache);
+		if (tpnt->buffer) {
+			normalize_buffer(tpnt->buffer);
+			kfree(tpnt->buffer);
 		}
-	  }
+		kfree(tpnt);
+		return;
+	}
   }
-
   write_unlock(&os_scsi_tapes_lock);
   return;
 }
@@ -5681,12 +5662,8 @@
 	printk(KERN_INFO "osst :I: Tape driver with OnStream support version %s\nosst :I: %s\n", osst_version, cvsid);
 
 	validate_options();
-#if DEBUG
-	 printk(OSST_DEB_MSG "osst :D: %d s/g segments, write threshold %d bytes.\n",
-			 max_sg_segs, osst_write_threshold);
-#endif
-	if ((register_chrdev(OSST_MAJOR, "osst", &osst_fops) < 0) ||
-			scsi_register_device(&osst_template)) {
+	
+	if ((register_chrdev(OSST_MAJOR,"osst", &osst_fops) < 0) || scsi_register_device(&osst_template)) {
 		printk(KERN_ERR "osst :E: Unable to register major %d for OnStream tapes\n", OSST_MAJOR);
 		return 1;
 	}
diff -Nru a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
--- a/drivers/scsi/scsi.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/scsi/scsi.c	Mon Dec 23 21:21:55 2002
@@ -147,44 +147,6 @@
 extern void scsi_times_out(Scsi_Cmnd * SCpnt);
 void scsi_build_commandblocks(Scsi_Device * SDpnt);
 
-/*
- * Function:    scsi_initialize_queue()
- *
- * Purpose:     Sets up the block queue for a device.
- *
- * Arguments:   SDpnt   - device for which we need a handler function.
- *
- * Returns:     Nothing
- *
- * Lock status: No locking assumed or required.
- */
-void  scsi_initialize_queue(Scsi_Device * SDpnt, struct Scsi_Host * SHpnt)
-{
-	request_queue_t *q = &SDpnt->request_queue;
-
-	/*
-	 * tell block layer about assigned host_lock for this host
-	 */
-	blk_init_queue(q, scsi_request_fn, SHpnt->host_lock);
-
-	q->queuedata = (void *) SDpnt;
-
-	/* Hardware imposed limit. */
-	blk_queue_max_hw_segments(q, SHpnt->sg_tablesize);
-
-	/*
-	 * scsi_alloc_sgtable max
-	 */
-	blk_queue_max_phys_segments(q, MAX_PHYS_SEGMENTS);
-
-	blk_queue_max_sectors(q, SHpnt->max_sectors);
-
-	if (!SHpnt->use_clustering)
-		clear_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags);
-
-        blk_queue_prep_rq(q, scsi_prep_fn);
-}
-
 #ifdef MODULE
 MODULE_PARM(scsi_logging_level, "i");
 MODULE_PARM_DESC(scsi_logging_level, "SCSI logging level; should be zero or nonzero");
@@ -216,7 +178,7 @@
 static void scsi_wait_done(Scsi_Cmnd * SCpnt)
 {
 	struct request *req = SCpnt->request;
-        struct request_queue *q = &SCpnt->device->request_queue;
+        struct request_queue *q = SCpnt->device->request_queue;
         unsigned long flags;
 
         ASSERT_LOCK(q->queue_lock, 0);
@@ -649,17 +611,14 @@
  */
 void scsi_release_command(Scsi_Cmnd * SCpnt)
 {
-        request_queue_t *q = &SCpnt->device->request_queue;
-
         __scsi_release_command(SCpnt);
-
         /*
          * Finally, hit the queue request function to make sure that
          * the device is actually busy if there are requests present.
          * This won't block - if the device cannot take any more, life
          * will go on.  
          */
-        scsi_queue_next_request(q, NULL);                
+        scsi_queue_next_request(SCpnt->device->request_queue, NULL);
 }
 
 /*
@@ -803,13 +762,12 @@
  		  int timeout, int retries)
 {
 	DECLARE_COMPLETION(wait);
-	request_queue_t *q = &SRpnt->sr_device->request_queue;
 	
 	SRpnt->sr_request->waiting = &wait;
 	SRpnt->sr_request->rq_status = RQ_SCSI_BUSY;
 	scsi_do_req (SRpnt, (void *) cmnd,
 		buffer, bufflen, scsi_wait_done, timeout, retries);
-	generic_unplug_device(q);
+	generic_unplug_device(SRpnt->sr_device->request_queue);
 	wait_for_completion(&wait);
 	SRpnt->sr_request->waiting = NULL;
 	if( SRpnt->sr_command != NULL )
@@ -1905,10 +1863,8 @@
  */
 int scsi_slave_attach(struct scsi_device *sdev)
 {
+	/* all this code is now handled elsewhere 
 	if (sdev->attached++ == 0) {
-		/*
-		 * No one was attached.
-		 */
 		scsi_build_commandblocks(sdev);
 		if (sdev->current_queue_depth == 0) {
 			printk(KERN_ERR "scsi: Allocation failure during"
@@ -1928,6 +1884,8 @@
 			scsi_adjust_queue_depth(sdev, 0,
 						sdev->host->cmd_per_lun);
 	}
+		 */
+	sdev->attached++;
 	return 0;
 }
 
@@ -1943,9 +1901,12 @@
  */
 void scsi_slave_detach(struct scsi_device *sdev)
 {
+	/*
 	if (--sdev->attached == 0) {
 		scsi_release_commandblocks(sdev);
 	}
+	*/
+	sdev->attached--;
 }
 /*
  * This entry point should be called by a loadable module if it is trying
diff -Nru a/drivers/scsi/scsi.h b/drivers/scsi/scsi.h
--- a/drivers/scsi/scsi.h	Mon Dec 23 21:21:52 2002
+++ b/drivers/scsi/scsi.h	Mon Dec 23 21:21:52 2002
@@ -374,6 +374,14 @@
 #define SYNC_RESET      0x40
 
 /*
+ * This specifies "machine infinity" for host templates which don't
+ * limit the transfer size.  Note this limit represents an absolute
+ * maximum, and may be over the transfer limits allowed for individual
+ * devices (e.g. 256 for SCSI-1)
+ */
+#define SCSI_DEFAULT_MAX_SECTORS	1024
+
+/*
  * This is the crap from the old error handling code.  We have it in a special
  * place so that we can more easily delete it later on.
  */
@@ -503,6 +511,7 @@
  */
 extern int scsi_add_single_device(uint, uint, uint, uint);
 extern int scsi_remove_single_device(uint, uint, uint, uint);
+extern u64 scsi_calculate_bounce_limit(struct Scsi_Host *);
 
 /*
  * Prototypes for functions in constants.c
@@ -561,14 +570,12 @@
 	/*
 	 * This information is private to the scsi mid-layer.
 	 */
-	struct scsi_device *next;	/* Used for linked list */
-	struct scsi_device *prev;	/* Used for linked list */
 	struct list_head    siblings;   /* list of all devices on this host */
 	struct list_head    same_target_siblings; /* just the devices sharing same target id */
 	wait_queue_head_t   scpnt_wait;	/* Used to wait if
 					   device is busy */
 	struct Scsi_Host *host;
-	request_queue_t request_queue;
+	request_queue_t *request_queue;
         atomic_t                device_active; /* commands checked out for device */
 	volatile unsigned short device_busy;	/* commands actually active on low-level */
 	struct list_head free_cmnds;    /* list of available Scsi_Cmnd structs */
@@ -886,11 +893,9 @@
  *	would be adjustable from 0 to depth.
  **/
 static inline void scsi_activate_tcq(Scsi_Device *SDpnt, int depth) {
-        request_queue_t *q = &SDpnt->request_queue;
-
         if(SDpnt->tagged_supported) {
-		if(!blk_queue_tagged(q))
-			blk_queue_init_tags(q, depth);
+		if(!blk_queue_tagged(SDpnt->request_queue))
+			blk_queue_init_tags(SDpnt->request_queue, depth);
 		scsi_adjust_queue_depth(SDpnt, MSG_ORDERED_TAG, depth);
         }
 }
@@ -900,10 +905,8 @@
  * @SDpnt:	device to turn off TCQ for
  **/
 static inline void scsi_deactivate_tcq(Scsi_Device *SDpnt, int depth) {
-	request_queue_t *q = &SDpnt->request_queue;
-
-	if(blk_queue_tagged(q))
-		blk_queue_free_tags(q);
+	if(blk_queue_tagged(SDpnt->request_queue))
+		blk_queue_free_tags(SDpnt->request_queue);
 	scsi_adjust_queue_depth(SDpnt, 0, depth);
 }
 
@@ -949,7 +952,7 @@
                 /* single command, look in space */
                 return SDpnt->current_cmnd;
 
-        req = blk_queue_find_tag(&SDpnt->request_queue, tag);
+        req = blk_queue_find_tag(SDpnt->request_queue, tag);
 
         if(req == NULL)
                 return NULL;
diff -Nru a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
--- a/drivers/scsi/scsi_debug.c	Mon Dec 23 21:21:57 2002
+++ b/drivers/scsi/scsi_debug.c	Mon Dec 23 21:21:57 2002
@@ -20,6 +20,8 @@
  *        add timers for delayed responses [20020721]
  *   Patrick Mansfield <patmans@us.ibm.com> max_luns+scsi_level [20021031]
  *   Mike Anderson <andmike@us.ibm.com> sysfs work [20021118]
+ *   dpg: change style of boot options to "scsi_debug.num_devs=2" and
+ *        module options to "modprobe scsi_debug num_devs=2" [20021221]
  */
 
 #include <linux/config.h>
@@ -37,6 +39,7 @@
 #include <linux/proc_fs.h>
 #include <linux/smp_lock.h>
 #include <linux/vmalloc.h>
+#include <linux/moduleparam.h>
 
 #include <linux/blk.h>
 #include "scsi.h"
@@ -51,7 +54,7 @@
 
 #include "scsi_debug.h"
 
-static const char * scsi_debug_version_str = "Version: 1.66 (20021205)";
+static const char * scsi_debug_version_str = "Version: 1.67 (20021221)";
 
 #ifndef SCSI_CMD_READ_16
 #define SCSI_CMD_READ_16 0x88
@@ -63,7 +66,7 @@
 #define SDEBUG_TAGGED_QUEUING 0 /* 0 | MSG_SIMPLE_TAG | MSG_ORDERED_TAG */
 
 /* Default values for driver parameters */
-#define DEF_NR_FAKE_DEVS   1
+#define DEF_NUM_DEVS   1
 #define DEF_DEV_SIZE_MB   8
 #define DEF_EVERY_NTH   100
 #define DEF_DELAY   1
@@ -82,7 +85,7 @@
 #define OPT_MEDIUM_ERR_ADDR   0x1234
 
 static int scsi_debug_dev_size_mb = DEF_DEV_SIZE_MB;
-static int scsi_debug_num_devs = DEF_NR_FAKE_DEVS;
+static int scsi_debug_num_devs = DEF_NUM_DEVS;
 static int scsi_debug_opts = DEF_OPTS;
 static int scsi_debug_every_nth = DEF_EVERY_NTH;
 static int scsi_debug_cmnd_count = 0;
@@ -1100,159 +1103,32 @@
 	}
 }
 
-#ifndef MODULE
-static int __init num_devs_setup(char *str)
-{   
-    int tmp; 
-    
-    if (get_option(&str, &tmp) == 1) {
-        if (tmp > 0)
-            scsi_debug_num_devs = tmp;
-        return 1;
-    } else {
-        printk(KERN_INFO "scsi_debug_num_devs: usage scsi_debug_num_devs=<n> "
-               "(<n> can be from 1 to around 2000)\n");
-        return 0;
-    }
-}
-__setup("scsi_debug_num_devs=", num_devs_setup);
-
-static int __init max_luns_setup(char *str)
-{   
-    int tmp; 
-    
-    if (get_option(&str, &tmp) == 1) {
-        if (tmp > 0)
-            scsi_debug_max_luns = tmp;
-        return 1;
-    } else {
-        printk(KERN_INFO "scsi_debug_max_luns: usage scsi_debug_max_luns=<n> "
-               "(<n> is a postive integer (def=2))\n");
-        return 0;
-    }
-}
-__setup("scsi_debug_max_luns=", max_luns_setup);
-
-static int __init scsi_level_setup(char *str)
-{   
-    int tmp; 
-    
-    if (get_option(&str, &tmp) == 1) {
-        if (tmp > 0)
-            scsi_debug_scsi_level = tmp;
-        return 1;
-    } else {
-        printk(KERN_INFO "scsi_debug_scsi_level: usage "
-	"scsi_debug_scsi_level=<n> (<n> is 1..4 (def=3))\n");
-        return 0;
-    }
-}
-__setup("scsi_debug_scsi_level=", scsi_level_setup);
-
-static int __init dev_size_mb_setup(char *str)
-{   
-    int tmp; 
-    
-    if (get_option(&str, &tmp) == 1) {
-        if (tmp > 0)
-            scsi_debug_dev_size_mb = tmp;
-        return 1;
-    } else {
-        printk(KERN_INFO "scsi_debug_dev_size_mb: usage "
-	       "scsi_debug_dev_size_mb=<n>\n"
-               "    (<n> is number of MB ram shared by all devs\n");
-        return 0;
-    }
-}
-__setup("scsi_debug_dev_size_mb=", dev_size_mb_setup);
-
-static int __init opts_setup(char *str)
-{   
-    int tmp; 
-    
-    if (get_option(&str, &tmp) == 1) {
-        if (tmp > 0)
-            scsi_debug_opts = tmp;
-        return 1;
-    } else {
-        printk(KERN_INFO "scsi_debug_opts: usage "
-	       "scsi_debug_opts=<n>\n"
-               "    (1->noise, 2->medium_error, 4->... (can be or-ed)\n");
-        return 0;
-    }
-}
-__setup("scsi_debug_opts=", opts_setup);
-
-static int __init every_nth_setup(char *str)
-{
-    int tmp;
-
-    if (get_option(&str, &tmp) == 1) {
-        if (tmp > 0)
-            scsi_debug_every_nth = tmp;
-        return 1;
-    } else {
-        printk(KERN_INFO "scsi_debug_every_nth: usage "
-               "scsi_debug_every_nth=<n>\n"
-               "    timeout every nth command (when ...)\n");
-        return 0;
-    }
-}
-__setup("scsi_debug_every_nth=", every_nth_setup);
-
-static int __init delay_setup(char *str)
-{
-    int tmp;
-
-    if (get_option(&str, &tmp) == 1) {
-	scsi_debug_delay = tmp;
-        return 1;
-    } else {
-        printk(KERN_INFO "scsi_debug_delay: usage "
-               "scsi_debug_delay=<n>\n"
-               "    delay response <n> jiffies\n");
-        return 0;
-    }
-}
-__setup("scsi_debug_delay=", delay_setup);
-
-static int __init add_host_setup(char *str)
-{
-    int tmp;
-
-    if (get_option(&str, &tmp) == 1) {
-	scsi_debug_add_host = tmp;
-        return 1;
-    } else {
-        printk(KERN_INFO "scsi_debug_add_host: usage "
-               "scsi_debug_add_host=<n>\n"
-               "    <n> 0..127 (default 1)\n");
-        return 0;
-    }
-}
-__setup("scsi_debug_add_host=", add_host_setup);
-
-#endif
+/* Set 'perm' (4th argument) to 0 to disable module_param's definition
+ * of sysfs parameters (which module_param doesn't yet support).
+ * Sysfs parameters defined explicitly below. 
+ */
+module_param_named(num_devs, scsi_debug_num_devs, int, 0);
+module_param_named(max_luns, scsi_debug_max_luns, int, 0);
+module_param_named(scsi_level, scsi_debug_scsi_level, int, 0);
+module_param_named(dev_size_mb, scsi_debug_dev_size_mb, int, 0);
+module_param_named(opts, scsi_debug_opts, int, 0); /* perm=0644 */
+module_param_named(every_nth, scsi_debug_every_nth, int, 0);
+module_param_named(delay, scsi_debug_delay, int, 0); /* perm=0644 */
+module_param_named(add_host, scsi_debug_add_host, int, 0); /* perm=0644 */
 
 MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert");
 MODULE_DESCRIPTION("SCSI debug adapter driver");
-MODULE_PARM(scsi_debug_num_devs, "i");
-MODULE_PARM_DESC(scsi_debug_num_devs, "number of SCSI devices to simulate");
-MODULE_PARM(scsi_debug_max_luns, "i");
-MODULE_PARM_DESC(scsi_debug_max_luns, "number of SCSI LUNs per target to simulate");
-MODULE_PARM(scsi_debug_scsi_level, "i");
-MODULE_PARM_DESC(scsi_debug_scsi_level, "SCSI level to simulate");
-MODULE_PARM(scsi_debug_dev_size_mb, "i");
-MODULE_PARM_DESC(scsi_debug_dev_size_mb, "size in MB of ram shared by devs");
-MODULE_PARM(scsi_debug_opts, "i");
-MODULE_PARM_DESC(scsi_debug_opts, "1->noise, 2->medium_error, 4->...");
-MODULE_PARM(scsi_debug_every_nth, "i");
-MODULE_PARM_DESC(scsi_debug_every_nth, "timeout every nth command(def=100)");
-MODULE_PARM(scsi_debug_delay, "i");
-MODULE_PARM_DESC(scsi_debug_delay, "# of jiffies to delay response(def=1)");
-MODULE_PARM(scsi_debug_add_host, "i");
-MODULE_PARM_DESC(scsi_debug_add_host, "0..127 hosts allowed(def=1)");
 MODULE_LICENSE("GPL");
+
+MODULE_PARM_DESC(num_devs, "number of SCSI devices to simulate");
+MODULE_PARM_DESC(max_luns, "number of SCSI LUNs per target to simulate");
+MODULE_PARM_DESC(scsi_level, "SCSI level to simulate");
+MODULE_PARM_DESC(dev_size_mb, "size in MB of ram shared by devs");
+MODULE_PARM_DESC(opts, "1->noise, 2->medium_error, 4->...");
+MODULE_PARM_DESC(every_nth, "timeout every nth command(def=100)");
+MODULE_PARM_DESC(delay, "# of jiffies to delay response(def=1)");
+MODULE_PARM_DESC(add_host, "0..127 hosts allowed(def=1)");
+
 
 static char sdebug_info[256];
 
diff -Nru a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
--- a/drivers/scsi/scsi_error.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/scsi/scsi_error.c	Mon Dec 23 21:21:50 2002
@@ -1487,7 +1487,7 @@
 			break;
 		}
 
-		__blk_run_queue(&sdev->request_queue);
+		__blk_run_queue(sdev->request_queue);
 	}
 	spin_unlock_irqrestore(shost->host_lock, flags);
 }
diff -Nru a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
--- a/drivers/scsi/scsi_lib.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/scsi/scsi_lib.c	Mon Dec 23 21:21:55 2002
@@ -57,9 +57,8 @@
  */
 int scsi_insert_special_cmd(Scsi_Cmnd * SCpnt, int at_head)
 {
-	request_queue_t *q = &SCpnt->device->request_queue;
-
-	blk_insert_request(q, SCpnt->request, at_head, SCpnt);
+	blk_insert_request(SCpnt->device->request_queue, SCpnt->request,
+		       	   at_head, SCpnt);
 	return 0;
 }
 
@@ -85,16 +84,13 @@
  */
 int scsi_insert_special_req(Scsi_Request * SRpnt, int at_head)
 {
-	request_queue_t *q = &SRpnt->sr_device->request_queue;
-
 	/* This is used to insert SRpnt specials.  Because users of
 	 * this function are apt to reuse requests with no modification,
 	 * we have to sanitise the request flags here
 	 */
-
 	SRpnt->sr_request->flags &= ~REQ_DONTPREP;
-
-	blk_insert_request(q, SRpnt->sr_request, at_head, SRpnt);
+	blk_insert_request(SRpnt->sr_device->request_queue, SRpnt->sr_request,
+		       	   at_head, SRpnt);
 	return 0;
 }
 
@@ -215,7 +211,7 @@
 {
 	int all_clear;
 	unsigned long flags;
-	Scsi_Device *SDpnt;
+	Scsi_Device *SDpnt, *SDpnt2;
 	struct Scsi_Host *SHpnt;
 
 	ASSERT_LOCK(q->queue_lock, 0);
@@ -256,17 +252,17 @@
 	 * with special case code, then spin off separate versions and
 	 * use function pointers to pick the right one.
 	 */
-	if (SDpnt->single_lun && blk_queue_empty(q) && SDpnt->device_busy ==0) {
-		list_for_each_entry(SDpnt, &SHpnt->my_devices, siblings) {
-			if (((SHpnt->can_queue > 0)
-			     && (SHpnt->host_busy >= SHpnt->can_queue))
-			    || (SHpnt->host_blocked)
-			    || (SHpnt->host_self_blocked)
-			    || (SDpnt->device_blocked)) {
+	if (SDpnt->single_lun && blk_queue_empty(q) && SDpnt->device_busy ==0 &&
+			!SHpnt->host_blocked && !SHpnt->host_self_blocked &&
+			!((SHpnt->can_queue > 0) && (SHpnt->host_busy >=
+				       		     SHpnt->can_queue))) {
+		list_for_each_entry(SDpnt2, &SDpnt->same_target_siblings,
+			       same_target_siblings) {
+			if (!SDpnt2->device_blocked &&
+			    !blk_queue_empty(SDpnt2->request_queue)) {
+				__blk_run_queue(SDpnt2->request_queue);
 				break;
 			}
-
-			__blk_run_queue(&SDpnt->request_queue);
 		}
 	}
 
@@ -289,7 +285,7 @@
 			if (SDpnt->device_blocked || !SDpnt->starved) {
 				continue;
 			}
-			__blk_run_queue(&SDpnt->request_queue);
+			__blk_run_queue(SDpnt->request_queue);
 			all_clear = 0;
 		}
 		if (SDpnt == NULL && all_clear) {
@@ -327,7 +323,7 @@
 				     int sectors,
 				     int requeue)
 {
-	request_queue_t *q = &SCpnt->device->request_queue;
+	request_queue_t *q = SCpnt->device->request_queue;
 	struct request *req = SCpnt->request;
 	unsigned long flags;
 
@@ -497,7 +493,7 @@
 {
 	int result = SCpnt->result;
 	int this_count = SCpnt->bufflen >> 9;
-	request_queue_t *q = &SCpnt->device->request_queue;
+	request_queue_t *q = SCpnt->device->request_queue;
 	struct request *req = SCpnt->request;
 
 	/*
@@ -1094,7 +1090,7 @@
 	SHpnt->host_self_blocked = FALSE;
 	/* Now that we are unblocked, try to start the queues. */
 	list_for_each_entry(SDloop, &SHpnt->my_devices, siblings)
-		scsi_queue_next_request(&SDloop->request_queue, NULL);
+		scsi_queue_next_request(SDloop->request_queue, NULL);
 }
 
 /*
diff -Nru a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
--- a/drivers/scsi/scsi_scan.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/scsi/scsi_scan.c	Mon Dec 23 21:21:59 2002
@@ -28,7 +28,6 @@
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
-
 #include <linux/blk.h>
 
 #include "scsi.h"
@@ -365,34 +364,60 @@
 		printk("\n");
 }
 
-/**
- * scsi_initialize_merge_fn() -Æ£initialize merge function for a host
- * @sd:		host descriptor
- */
-static void scsi_initialize_merge_fn(struct scsi_device *sd)
+u64 scsi_calculate_bounce_limit(struct Scsi_Host *shost)
 {
-	request_queue_t *q = &sd->request_queue;
-	struct Scsi_Host *sh = sd->host;
-	struct device *dev = scsi_get_device(sh);
-	u64 bounce_limit;
-
-	if (sh->highmem_io) {
-		if (dev && dev->dma_mask && PCI_DMA_BUS_IS_PHYS) {
-			bounce_limit = *dev->dma_mask;
-		} else {
-			/*
-			 * Platforms with virtual-DMA translation
- 			 * hardware have no practical limit.
-			 */
-			bounce_limit = BLK_BOUNCE_ANY;
-		}
-	} else if (sh->unchecked_isa_dma) {
-		bounce_limit = BLK_BOUNCE_ISA;
-	} else {
-		bounce_limit = BLK_BOUNCE_HIGH;
+	if (shost->highmem_io) {
+		struct device *host_dev = scsi_get_device(shost);
+
+		if (PCI_DMA_BUS_IS_PHYS && host_dev && host_dev->dma_mask)
+			return *host_dev->dma_mask;
+
+		/*
+		 * Platforms with virtual-DMA translation
+ 		 * hardware have no practical limit.
+		 */
+		return BLK_BOUNCE_ANY;
+	} else if (shost->unchecked_isa_dma)
+		return BLK_BOUNCE_ISA;
+
+	return BLK_BOUNCE_HIGH;
+}
+
+static request_queue_t *scsi_alloc_queue(struct Scsi_Host *shost)
+{
+	request_queue_t *q;
+
+	q = kmalloc(sizeof(*q), GFP_ATOMIC);
+	if (!q)
+		return NULL;
+	memset(q, 0, sizeof(*q));
+
+	if (!shost->max_sectors) {
+		/*
+		 * Driver imposes no hard sector transfer limit.
+		 * start at machine infinity initially.
+		 */
+		shost->max_sectors = SCSI_DEFAULT_MAX_SECTORS;
 	}
 
-	blk_queue_bounce_limit(q, bounce_limit);
+	blk_init_queue(q, scsi_request_fn, shost->host_lock);
+	blk_queue_prep_rq(q, scsi_prep_fn);
+
+	blk_queue_max_hw_segments(q, shost->sg_tablesize);
+	blk_queue_max_phys_segments(q, MAX_PHYS_SEGMENTS);
+	blk_queue_max_sectors(q, shost->max_sectors);
+	blk_queue_bounce_limit(q, scsi_calculate_bounce_limit(shost));
+
+	if (!shost->use_clustering)
+		clear_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags);
+
+	return q;
+}
+
+static void scsi_free_queue(request_queue_t *q)
+{
+	blk_cleanup_queue(q);
+	kfree(q);
 }
 
 /**
@@ -407,14 +432,12 @@
  *     Scsi_Device pointer, or NULL on failure.
  **/
 static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost,
-					   uint channel, uint id, uint lun)
+	       	struct request_queue **q, uint channel, uint id, uint lun)
 {
 	struct scsi_device *sdev, *device;
 
 	sdev = kmalloc(sizeof(*sdev), GFP_ATOMIC);
-	if (sdev == NULL)
-		printk(ALLOC_FAILURE_MSG, __FUNCTION__);
-	else {
+	if (sdev != NULL) {
 		memset(sdev, 0, sizeof(Scsi_Device));
 		sdev->vendor = scsi_null_device_strs;
 		sdev->model = scsi_null_device_strs;
@@ -436,18 +459,28 @@
 		 * doesn't
 		 */
 		sdev->borken = 1;
-		if (shost->hostt->slave_alloc)
-			if (shost->hostt->slave_alloc(sdev)) {
-				kfree(sdev);
-				return NULL;
-			}
 
-		scsi_initialize_queue(sdev, shost);
-		sdev->request_queue.queuedata = (void *) sdev;
+		if (!q || *q == NULL) {
+			sdev->request_queue = scsi_alloc_queue(shost);
+			if (!sdev->request_queue)
+				goto out_bail;
+		} else {
+			sdev->request_queue = *q;
+			*q = NULL;
+		}
 
-		scsi_initialize_merge_fn(sdev);
+		sdev->request_queue->queuedata = sdev;
+		scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
+		scsi_build_commandblocks(sdev);
+		if (sdev->current_queue_depth == 0) {
+			goto out_bail;
+		}
 		init_waitqueue_head(&sdev->scpnt_wait);
 
+		if (shost->hostt->slave_alloc)
+			if (shost->hostt->slave_alloc(sdev)) {
+				goto out_bail;
+			}
 		/*
 		 * If there are any same target siblings, add this to the
 		 * sibling list
@@ -457,15 +490,34 @@
 			   device->channel == sdev->channel) {
 				list_add_tail(&sdev->same_target_siblings,
 					      &device->same_target_siblings);
+				sdev->scsi_level = device->scsi_level;
 				break;
 			}
 		}
 		/*
+		 * If there wasn't another lun already configured at this
+		 * target, then default this device to SCSI_2 until we
+		 * know better
+		 */
+		if(!sdev->scsi_level)
+			sdev->scsi_level = SCSI_2;
+		/*
 		 * Add it to the end of the shost->my_devices list.
 		 */
 		list_add_tail(&sdev->siblings, &shost->my_devices);
+		return (sdev);
 	}
-	return (sdev);
+out_bail:
+	printk(ALLOC_FAILURE_MSG, __FUNCTION__);
+	if (q && sdev->request_queue) {
+		*q = sdev->request_queue;
+		sdev->request_queue = NULL;
+	} else if (sdev->request_queue)
+		scsi_free_queue(sdev->request_queue);
+
+	scsi_release_commandblocks(sdev);
+	kfree(sdev);
+	return NULL;
 }
 
 /**
@@ -481,11 +533,12 @@
 	list_del(&sdev->siblings);
 	list_del(&sdev->same_target_siblings);
 
-	blk_cleanup_queue(&sdev->request_queue);
+	if (sdev->request_queue)
+		scsi_free_queue(sdev->request_queue);
 	scsi_release_commandblocks(sdev);
 	if (sdev->host->hostt->slave_destroy)
 		sdev->host->hostt->slave_destroy(sdev);
-	if (sdev->inquiry != NULL)
+	if (sdev->inquiry)
 		kfree(sdev->inquiry);
 	kfree(sdev);
 }
@@ -1188,18 +1241,11 @@
  *     SCSI_SCAN_NO_RESPONSE: could not allocate or setup a Scsi_Device
  *     SCSI_SCAN_LUN_PRESENT: a new Scsi_Device was allocated and initialized
  **/
-static int scsi_add_lun(Scsi_Device *sdevscan, Scsi_Device **sdevnew,
-			Scsi_Request *sreq, char *inq_result, int *bflags)
+static int scsi_add_lun(Scsi_Device *sdev, Scsi_Request *sreq,
+		char *inq_result, int *bflags)
 {
-	Scsi_Device *sdev;
 	char devname[64];
 
-	sdev = scsi_alloc_sdev(sdevscan->host, sdevscan->channel,
-				     sdevscan->id, sdevscan->lun);
-	if (sdev == NULL)
-		return SCSI_SCAN_NO_RESPONSE;
-
-	sdev->scsi_level = sdevscan->scsi_level;
 	/*
 	 * XXX do not save the inquiry, since it can change underneath us,
 	 * save just vendor/model/rev.
@@ -1210,10 +1256,8 @@
 	 * scanning run at their own risk, or supply a user level program
 	 * that can correctly scan.
 	 */
-	sdev->inquiry_len = sdevscan->inquiry_len;
 	sdev->inquiry = kmalloc(sdev->inquiry_len, GFP_ATOMIC);
 	if (sdev->inquiry == NULL) {
-		scsi_free_sdev(sdev);
 		return SCSI_SCAN_NO_RESPONSE;
 	}
 
@@ -1335,8 +1379,8 @@
 	 * function */
 	sdev->max_device_blocked = SCSI_DEFAULT_DEVICE_BLOCKED;
 
-	if (sdevnew != NULL)
-		*sdevnew = sdev;
+	if(sdev->host->hostt->slave_configure)
+		sdev->host->hostt->slave_configure(sdev);
 
 	return SCSI_SCAN_LUN_PRESENT;
 }
@@ -1365,8 +1409,9 @@
  *         attached at the LUN
  *     SCSI_SCAN_LUN_PRESENT: a new Scsi_Device was allocated and initialized
  **/
-static int scsi_probe_and_add_lun(Scsi_Device *sdevscan, Scsi_Device **sdevnew,
-				  int *bflagsp)
+static int scsi_probe_and_add_lun(struct Scsi_Host *host,
+		struct request_queue **q, uint channel, uint id,
+	       	uint lun, int *bflagsp)
 {
 	Scsi_Device *sdev = NULL;
 	Scsi_Request *sreq = NULL;
@@ -1374,47 +1419,27 @@
 	int bflags;
 	int res;
 
-	/*
-	 * Any command blocks allocated are fixed to use sdevscan->lun,
-	 * so they must be allocated and released if sdevscan->lun
-	 * changes.
-	 *
-	 * XXX optimize and don't call build/release commandblocks, instead
-	 * modify the LUN value of the existing command block - this means
-	 * the build/release calls would be moved to the alloc/free of
-	 * sdevscan, and the modifying function would be called here.
-	 *
-	 * XXX maybe change scsi_release_commandblocks to not reset
-	 * queue_depth to 0.
-	 */
-	sdevscan->new_queue_depth = 1;
-	scsi_build_commandblocks(sdevscan);
-	if (sdevscan->current_queue_depth == 0)
-		goto alloc_failed;
-
-	/*
-	 * Since we reuse the same sdevscan over and over with different
-	 * target and lun values, we have to destroy and then recreate
-	 * any possible low level attachments since they very will might
-	 * also store the id and lun numbers in some form and need updating
-	 * with each scan.
-	 */
-	if (sdevscan->host->hostt->slave_destroy)
-		sdevscan->host->hostt->slave_destroy(sdevscan);
-	if (sdevscan->host->hostt->slave_alloc)
-		sdevscan->host->hostt->slave_alloc(sdevscan);
-	sreq = scsi_allocate_request(sdevscan);
-	if (sreq == NULL)
-		goto alloc_failed;
+	sdev = scsi_alloc_sdev(host, q, channel, id, lun);
+	if (sdev == NULL)
+		return SCSI_SCAN_NO_RESPONSE;
+	sreq = scsi_allocate_request(sdev);
+	if (sreq == NULL) {
+		printk(ALLOC_FAILURE_MSG, __FUNCTION__);
+		res = SCSI_SCAN_NO_RESPONSE;
+		goto bail_out;
+	}
 	/*
 	 * The sreq is for use only with sdevscan.
 	 */
 
 	scsi_result = kmalloc(256, GFP_ATOMIC |
-			      (sdevscan->host->unchecked_isa_dma) ?
+			      (host->unchecked_isa_dma) ?
 			      GFP_DMA : 0);
-	if (scsi_result == NULL)
-		goto alloc_failed;
+	if (scsi_result == NULL) {
+		printk(ALLOC_FAILURE_MSG, __FUNCTION__);
+		res = SCSI_SCAN_NO_RESPONSE;
+		goto bail_out;
+	}
 
 	scsi_probe_lun(sreq, scsi_result, &bflags);
 	if (sreq->sr_result)
@@ -1439,10 +1464,8 @@
 					" no device added\n"));
 			res = SCSI_SCAN_TARGET_PRESENT;
 		} else {
-			res = scsi_add_lun(sdevscan, &sdev, sreq, scsi_result,
-					   &bflags);
+			res = scsi_add_lun(sdev, sreq, scsi_result, &bflags);
 			if (res == SCSI_SCAN_LUN_PRESENT) {
-				BUG_ON(sdev == NULL);
 				if ((bflags & BLIST_KEY) != 0) {
 					sdev->lockable = 0;
 					scsi_unlock_floptical(sreq,
@@ -1452,31 +1475,25 @@
 					 * the INQUIRY data.
 					 */
 				}
-				/*
-				 * "hardcoded" scans of a single LUN need
-				 * to know the sdev just allocated.
-				 */
-				if (sdevnew != NULL)
-					*sdevnew = sdev;
 				if (bflagsp != NULL)
 					*bflagsp = bflags;
 			}
 		}
 	}
-	kfree(scsi_result);
-	scsi_release_request(sreq);
-	scsi_release_commandblocks(sdevscan);
-	return res;
-
-alloc_failed:
-	printk(ALLOC_FAILURE_MSG, __FUNCTION__);
+bail_out:
 	if (scsi_result != NULL)
 		kfree(scsi_result);
 	if (sreq != NULL)
 		scsi_release_request(sreq);
-	if (sdevscan->current_queue_depth != 0)
-		scsi_release_commandblocks(sdevscan);
-	return SCSI_SCAN_NO_RESPONSE;
+	if (res != SCSI_SCAN_LUN_PRESENT) {
+		if(q) {
+			*q = sdev->request_queue;
+			sdev->request_queue = NULL;
+		}
+		scsi_free_sdev(sdev);
+	}
+	return res;
+
 }
 
 /**
@@ -1492,16 +1509,15 @@
  *
  *     Modifies sdevscan->lun.
  **/
-static void scsi_sequential_lun_scan(Scsi_Device *sdevscan, int bflags,
-				     int lun0_res)
+static void scsi_sequential_lun_scan(struct Scsi_Host *shost,
+	       	struct request_queue **q, uint channel, uint id,
+	       	int bflags, int lun0_res, int scsi_level)
 {
-	struct Scsi_Host *shost = sdevscan->host;
-	unsigned int sparse_lun;
-	unsigned int max_dev_lun;
+	unsigned int sparse_lun, lun, max_dev_lun;
 
 	SCSI_LOG_SCAN_BUS(3, printk(KERN_INFO "scsi scan: Sequential scan of"
-			" host %d channel %d id %d\n", sdevscan->host->host_no,
-			sdevscan->channel, sdevscan->id));
+			" host %d channel %d id %d\n", shost->host_no,
+			channel, id));
 
 	max_dev_lun = min(max_scsi_luns, shost->max_lun);
 	/*
@@ -1526,11 +1542,19 @@
 	 * If less than SCSI_1_CSS, and no special lun scaning, stop
 	 * scanning; this matches 2.4 behaviour, but could just be a bug
 	 * (to continue scanning a SCSI_1_CSS device).
-	 */
+	 *
+	 * This test is broken.  We might not have any device on lun0 for
+	 * a sparselun device, and if that's the case then how would we
+	 * know the real scsi_level, eh?  It might make sense to just not
+	 * scan any SCSI_1 device for non-0 luns, but that check would best
+	 * go into scsi_alloc_sdev() and just have it return null when asked
+	 * to alloc an sdev for lun > 0 on an already found SCSI_1 device.
+	 *
 	if ((sdevscan->scsi_level < SCSI_1_CCS) &&
 	    ((bflags & (BLIST_FORCELUN | BLIST_SPARSELUN | BLIST_MAX5LUN))
 	     == 0))
 		return;
+	 */
 	/*
 	 * If this device is known to support multiple units, override
 	 * the other settings, and scan all of them.
@@ -1546,7 +1570,7 @@
 	 * Do not scan SCSI-2 or lower device past LUN 7, unless
 	 * BLIST_LARGELUN.
 	 */
-	if ((sdevscan->scsi_level < SCSI_3) && !(bflags & BLIST_LARGELUN))
+	if (scsi_level < SCSI_3 && !(bflags & BLIST_LARGELUN))
 		max_dev_lun = min(8U, max_dev_lun);
 
 	/*
@@ -1554,8 +1578,8 @@
 	 * until we reach the max, or no LUN is found and we are not
 	 * sparse_lun.
 	 */
-	for (sdevscan->lun = 1; sdevscan->lun < max_dev_lun; ++sdevscan->lun)
-		if ((scsi_probe_and_add_lun(sdevscan, NULL, NULL)
+	for (lun = 1; lun < max_dev_lun; ++lun)
+		if ((scsi_probe_and_add_lun(shost, q, channel, id, lun, NULL)
 		     != SCSI_SCAN_LUN_PRESENT) && !sparse_lun)
 			return;
 }
@@ -1608,7 +1632,8 @@
  *     0: scan completed (or no memory, so further scanning is futile)
  *     1: no report lun scan, or not configured
  **/
-static int scsi_report_lun_scan(Scsi_Device *sdevscan)
+static int scsi_report_lun_scan(Scsi_Device *sdev, struct request_queue **q,
+		int bflags)
 {
 #ifdef CONFIG_SCSI_REPORT_LUNS
 
@@ -1625,38 +1650,19 @@
 	/*
 	 * Only support SCSI-3 and up devices.
 	 */
-	if (sdevscan->scsi_level < SCSI_3)
+	if (sdev->scsi_level < SCSI_3)
 		return 1;
+	if (bflags & BLIST_NOLUN)
+		return 0;
 
-	sdevscan->new_queue_depth = 1;
-	scsi_build_commandblocks(sdevscan);
-	if (sdevscan->current_queue_depth == 0) {
+	sreq = scsi_allocate_request(sdev);
+	if (sreq == NULL) {
 		printk(ALLOC_FAILURE_MSG, __FUNCTION__);
-		/*
-		 * We are out of memory, don't try scanning any further.
-		 */
 		return 0;
 	}
-	/*
-	 * Since we reuse the same sdevscan over and over with different
-	 * target and lun values, we have to destroy and then recreate
-	 * any possible low level attachments since they very will might
-	 * also store the id and lun numbers in some form and need updating
-	 * with each scan.
-	 *
-	 * This is normally handled in probe_and_add_lun, but since this
-	 * one particular function wants to scan lun 0 on each device
-	 * itself and will possibly pick up a resed sdevscan when doing
-	 * so, it also needs this hack.
-	 */
-	if (sdevscan->host->hostt->slave_destroy)
-		sdevscan->host->hostt->slave_destroy(sdevscan);
-	if (sdevscan->host->hostt->slave_alloc)
-		sdevscan->host->hostt->slave_alloc(sdevscan);
-	sreq = scsi_allocate_request(sdevscan);
 
-	sprintf(devname, "host %d channel %d id %d", sdevscan->host->host_no,
-		sdevscan->channel, sdevscan->id);
+	sprintf(devname, "host %d channel %d id %d", sdev->host->host_no,
+		sdev->channel, sdev->id);
 	/*
 	 * Allocate enough to hold the header (the same size as one ScsiLun)
 	 * plus the max number of luns we are requesting.
@@ -1669,11 +1675,11 @@
 	 */
 	length = (max_scsi_report_luns + 1) * sizeof(ScsiLun);
 	lun_data = (ScsiLun *) kmalloc(length, GFP_ATOMIC |
-					   (sdevscan->host->unchecked_isa_dma ?
+					   (sdev->host->unchecked_isa_dma ?
 					    GFP_DMA : 0));
 	if (lun_data == NULL) {
 		printk(ALLOC_FAILURE_MSG, __FUNCTION__);
-		scsi_release_commandblocks(sdevscan);
+		scsi_release_request(sreq);
 		/*
 		 * We are out of memory, don't try scanning any further.
 		 */
@@ -1723,7 +1729,6 @@
 		    || sreq->sr_sense_buffer[2] != UNIT_ATTENTION)
 			break;
 	}
-	scsi_release_commandblocks(sdevscan);
 
 	if (sreq->sr_result) {
 		/*
@@ -1751,8 +1756,8 @@
 		num_luns = (length / sizeof(ScsiLun));
 
 	SCSI_LOG_SCAN_BUS(3, printk (KERN_INFO "scsi scan: REPORT LUN scan of"
-			" host %d channel %d id %d\n", sdevscan->host->host_no,
-			sdevscan->channel, sdevscan->id));
+			" host %d channel %d id %d\n", sdev->host->host_no,
+			sdev->channel, sdev->id));
 	/*
 	 * Scan the luns in lun_data. The entry at offset 0 is really
 	 * the header, so start at 1 and go up to and including num_luns.
@@ -1782,22 +1787,22 @@
 			/*
 			 * LUN 0 has already been scanned.
 			 */
-		} else if (lun > sdevscan->host->max_lun) {
+		} else if (lun > sdev->host->max_lun) {
 			printk(KERN_WARNING "scsi: %s lun%d has a LUN larger"
 			       " than allowed by the host adapter\n",
 			       devname, lun);
 		} else {
 			int res;
 
-			sdevscan->lun = lun;
-			res = scsi_probe_and_add_lun(sdevscan, NULL, NULL);
+			res = scsi_probe_and_add_lun(sdev->host, q,
+				       	sdev->channel, sdev->id, lun, NULL);
 			if (res == SCSI_SCAN_NO_RESPONSE) {
 				/*
 				 * Got some results, but now none, abort.
 				 */
 				printk(KERN_ERR "scsi: Unexpected response"
 				       " from %s lun %d while scanning, scan"
-				       " aborted\n", devname, sdevscan->lun);
+				       " aborted\n", devname, lun);
 				break;
 			}
 		}
@@ -1814,38 +1819,22 @@
 
 int scsi_add_single_device(uint host, uint channel, uint id, uint lun)
 {
-	struct scsi_device *sdevscan, *sdev;
 	struct Scsi_Host *shost;
 	int error = -ENODEV;
+	struct scsi_device *sdev;
 
 	shost = scsi_host_hn_get(host);
 	if (!shost)
 		return -ENODEV;
-	sdev = scsi_find_device(shost, channel, id, lun);
-	if (sdev)
-		goto out;
-
-	error = -ENOMEM;
-	sdevscan = scsi_alloc_sdev(shost, channel, id, lun);
-	if (!sdevscan)
-		goto out;
-
-	if(!list_empty(&sdevscan->same_target_siblings)) {
-		sdev = list_entry(&sdevscan->same_target_siblings, Scsi_Device,
-					same_target_siblings);
-		sdevscan->scsi_level = sdev->scsi_level;
-		sdev = NULL;
-	} else
-		sdevscan->scsi_level = SCSI_2;
-	error = scsi_probe_and_add_lun(sdevscan, &sdev, NULL);
-	scsi_free_sdev(sdevscan);
-
-	if (error != SCSI_SCAN_LUN_PRESENT) 
+	if(scsi_find_device(shost, channel, id, lun) != NULL)
 		goto out;
 
-	scsi_attach_device(sdev);
-	error = 0;
-
+	if (scsi_probe_and_add_lun(shost, NULL, channel, id, lun, NULL) ==
+			SCSI_SCAN_LUN_PRESENT) {
+		error = 0;
+		sdev = scsi_find_device(shost, channel, id, lun);
+		scsi_attach_device(sdev);
+	}
 out:
 	scsi_host_put(shost);
 	return error;
@@ -1898,11 +1887,12 @@
  *     First try a REPORT LUN scan, if that does not scan the target, do a
  *     sequential scan of LUNs on the target id.
  **/
-static void scsi_scan_target(Scsi_Device *sdevscan, struct Scsi_Host *shost,
+static void scsi_scan_target(struct Scsi_Host *shost, struct request_queue **q,
 			     unsigned int channel, unsigned int id)
 {
-	int bflags;
+	int bflags = 0;
 	int res;
+	struct scsi_device *sdev;
 
 	if (shost->this_id == id)
 		/*
@@ -1910,36 +1900,29 @@
 		 */
 		return;
 
-	sdevscan->host = shost;
-	sdevscan->id = id;
-	sdevscan->channel = channel;
 	/*
 	 * Scan LUN 0, if there is some response, scan further. Ideally, we
 	 * would not configure LUN 0 until all LUNs are scanned.
-	 *
-	 * The scsi_level is set (in scsi_probe_lun) if a target responds.
 	 */
-	sdevscan->lun = 0;
-	res = scsi_probe_and_add_lun(sdevscan, NULL, &bflags);
-	if (res != SCSI_SCAN_NO_RESPONSE) {
-		/*
-		 * Some scsi devices cannot properly handle a lun != 0.
-		 * BLIST_NOLUN also prevents a REPORT LUN from being sent.
-		 * Any multi-lun SCSI-3 device that hangs because of a
-		 * REPORT LUN command is seriously broken.
-		 */
-		if (!(bflags & BLIST_NOLUN))
+	res = scsi_probe_and_add_lun(shost, q, channel, id, 0, &bflags);
+	if (res == SCSI_SCAN_LUN_PRESENT) {
+		sdev = scsi_find_device(shost, channel, id, 0);
+		if (scsi_report_lun_scan(sdev, q, bflags) != 0)
 			/*
-			 * Ending the scan here if max_scsi_luns == 1
-			 * breaks scanning of SPARSE, FORCE, MAX5 LUN
-			 * devices, and the report lun scan.
+			 * The REPORT LUN did not scan the target,
+			 * do a sequential scan.
 			 */
-			if (scsi_report_lun_scan(sdevscan) != 0)
-				/*
-				 * The REPORT LUN did not scan the target,
-				 * do a sequential scan.
-				 */
-				scsi_sequential_lun_scan(sdevscan, bflags, res);
+			scsi_sequential_lun_scan(shost, q, channel, id, bflags,
+				       	res, sdev->scsi_level);
+	} else if (res == SCSI_SCAN_TARGET_PRESENT) {
+		/*
+		 * There's a target here, but lun 0 is offline so we
+		 * can't use the report_lun scan.  Fall back to a
+		 * sequential lun scan with a bflags of SPARSELUN and
+		 * a default scsi level of SCSI_2
+		 */
+		scsi_sequential_lun_scan(shost, q, channel, id, BLIST_SPARSELUN,
+				SCSI_SCAN_TARGET_PRESENT, SCSI_2);
 	}
 }
 
@@ -1953,23 +1936,10 @@
  **/
 void scsi_scan_host(struct Scsi_Host *shost)
 {
-	struct scsi_device *sdevscan;
+	struct request_queue *q = NULL;
 	uint channel, id, order_id;
 
 	/*
-	 * The blk layer queue allocation is a bit expensive to
-	 * repeat for each channel and id - for FCP max_id is near
-	 * 255: each call to scsi_alloc_sdev() implies a call to
-	 * blk_init_queue, and then blk_init_free_list, where 2 *
-	 * queue_nr_requests requests are allocated. Don't do so
-	 * here for scsi_scan_selected_lun, since we end up
-	 * calling select_queue_depths with an extra Scsi_Device
-	 * on the host_queue list.
-	 */
-	sdevscan = scsi_alloc_sdev(shost, 0, 0, 0);
-	if (sdevscan == NULL)
-		return;
-	/*
 	 * The sdevscan host, channel, id and lun are filled in as
 	 * needed to scan.
 	 */
@@ -1991,11 +1961,12 @@
 				order_id = shost->max_id - id - 1;
 			else
 				order_id = id;
-			scsi_scan_target(sdevscan, shost, channel,
-					 order_id);
+			scsi_scan_target(shost, &q, channel, order_id);
 		}
 	}
-	scsi_free_sdev(sdevscan);
+
+	if (q)
+		scsi_free_queue(q);
 }
 
 void scsi_forget_host(struct Scsi_Host *shost)
@@ -2030,19 +2001,11 @@
 {
 	struct scsi_device *sdev;
 
-	sdev = scsi_alloc_sdev(shost, 0, shost->this_id, 0);
+	sdev = scsi_alloc_sdev(shost, NULL, 0, shost->this_id, 0);
 	if (sdev) {
-		scsi_build_commandblocks(sdev);
-		if (sdev->current_queue_depth == 0)
-			goto fail;
 		sdev->borken = 0;
 	}
-
 	return sdev;
-
-fail:
-	kfree(sdev);
-	return NULL;
 }
 
 /*
diff -Nru a/drivers/scsi/scsi_syms.c b/drivers/scsi/scsi_syms.c
--- a/drivers/scsi/scsi_syms.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/scsi/scsi_syms.c	Mon Dec 23 21:21:55 2002
@@ -98,6 +98,11 @@
 EXPORT_SYMBOL(scsi_device_types);
 
 /*
+ * This is for st to find the bounce limit
+ */
+EXPORT_SYMBOL(scsi_calculate_bounce_limit);
+
+/*
  * Externalize timers so that HBAs can safely start/restart commands.
  */
 extern void scsi_add_timer(Scsi_Cmnd *, int, void ((*) (Scsi_Cmnd *)));
diff -Nru a/drivers/scsi/sd.c b/drivers/scsi/sd.c
--- a/drivers/scsi/sd.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/scsi/sd.c	Mon Dec 23 21:21:59 2002
@@ -172,7 +172,7 @@
  **/
 static int sd_init_command(struct scsi_cmnd * SCpnt)
 {
-	int this_count, timeout;
+	unsigned int this_count, timeout;
 	struct gendisk *disk;
 	sector_t block;
 	struct scsi_device *sdp = SCpnt->device;
@@ -298,8 +298,23 @@
 		"writing" : "reading", this_count, SCpnt->request->nr_sectors));
 
 	SCpnt->cmnd[1] = 0;
-
-	if (((this_count > 0xff) || (block > 0x1fffff)) || SCpnt->device->ten) {
+	
+	if (block > 0xffffffff) {
+		SCpnt->cmnd[0] += READ_16 - READ_6;
+		SCpnt->cmnd[2] = sizeof(block) > 4 ? (unsigned char) (block >> 56) & 0xff : 0;
+		SCpnt->cmnd[3] = sizeof(block) > 4 ? (unsigned char) (block >> 48) & 0xff : 0;
+		SCpnt->cmnd[4] = sizeof(block) > 4 ? (unsigned char) (block >> 40) & 0xff : 0;
+		SCpnt->cmnd[5] = sizeof(block) > 4 ? (unsigned char) (block >> 32) & 0xff : 0;
+		SCpnt->cmnd[6] = (unsigned char) (block >> 24) & 0xff;
+		SCpnt->cmnd[7] = (unsigned char) (block >> 16) & 0xff;
+		SCpnt->cmnd[8] = (unsigned char) (block >> 8) & 0xff;
+		SCpnt->cmnd[9] = (unsigned char) block & 0xff;
+		SCpnt->cmnd[10] = (unsigned char) (this_count >> 24) & 0xff;
+		SCpnt->cmnd[11] = (unsigned char) (this_count >> 16) & 0xff;
+		SCpnt->cmnd[12] = (unsigned char) (this_count >> 8) & 0xff;
+		SCpnt->cmnd[13] = (unsigned char) this_count & 0xff;
+		SCpnt->cmnd[14] = SCpnt->cmnd[15] = 0;
+	} else if (((this_count > 0xff) || (block > 0x1fffff)) || SCpnt->device->ten) {
 		if (this_count > 0xffff)
 			this_count = 0xffff;
 
@@ -904,24 +919,34 @@
 static void
 sd_read_capacity(struct scsi_disk *sdkp, char *diskname,
 		 struct scsi_request *SRpnt, unsigned char *buffer) {
-	unsigned char cmd[10];
+	unsigned char cmd[16];
 	struct scsi_device *sdp = sdkp->device;
 	int the_result, retries;
-	int sector_size;
+	int sector_size = 0;
+	int longrc = 0;
 
+repeat:
 	retries = 3;
 	do {
-		cmd[0] = READ_CAPACITY;
-		memset((void *) &cmd[1], 0, 9);
-		memset((void *) buffer, 0, 8);
-
+		if (longrc) {
+			memset((void *) cmd, 0, 16);
+			cmd[0] = SERVICE_ACTION_IN;
+			cmd[1] = SAI_READ_CAPACITY_16;
+			cmd[13] = 12;
+			memset((void *) buffer, 0, 12);
+		} else {
+			cmd[0] = READ_CAPACITY;
+			memset((void *) &cmd[1], 0, 9);
+			memset((void *) buffer, 0, 8);
+		}
+		
 		SRpnt->sr_cmd_len = 0;
 		SRpnt->sr_sense_buffer[0] = 0;
 		SRpnt->sr_sense_buffer[2] = 0;
 		SRpnt->sr_data_direction = SCSI_DATA_READ;
 
 		scsi_wait_req(SRpnt, (void *) cmd, (void *) buffer,
-			      8, SD_TIMEOUT, SD_MAX_RETRIES);
+			      longrc ? 12 : 8, SD_TIMEOUT, SD_MAX_RETRIES);
 
 		if (media_not_present(sdkp, SRpnt))
 			return;
@@ -931,7 +956,7 @@
 
 	} while (the_result && retries);
 
-	if (the_result) {
+	if (the_result && !longrc) {
 		printk(KERN_NOTICE "%s : READ CAPACITY failed.\n"
 		       "%s : status=%x, message=%02x, host=%d, driver=%02x \n",
 		       diskname, diskname,
@@ -957,16 +982,55 @@
 		sdkp->capacity = 0x200000; /* 1 GB - random */
 
 		return;
-	}
-
-	sdkp->capacity = 1 + (((sector_t)buffer[0] << 24) |
-			      (buffer[1] << 16) |
-			      (buffer[2] << 8) |
-			      buffer[3]);
-
-	sector_size = (buffer[4] << 24) |
-		(buffer[5] << 16) | (buffer[6] << 8) | buffer[7];
+	} else if (the_result && longrc) {
+		/* READ CAPACITY(16) has been failed */
+		printk(KERN_NOTICE "%s : READ CAPACITY(16) failed.\n"
+		       "%s : status=%x, message=%02x, host=%d, driver=%02x \n",
+		       diskname, diskname,
+		       status_byte(the_result),
+		       msg_byte(the_result),
+		       host_byte(the_result),
+		       driver_byte(the_result));
+		printk(KERN_NOTICE "%s : use 0xffffffff as device size\n",
+		       diskname);
+		
+		sdkp->capacity = 1 + (sector_t) 0xffffffff;		
+		goto got_data;
+	}	
+	
+	if (!longrc) {
+		sector_size = (buffer[4] << 24) |
+			(buffer[5] << 16) | (buffer[6] << 8) | buffer[7];
+		if (buffer[0] == 0xff && buffer[1] == 0xff &&
+		    buffer[2] == 0xff && buffer[3] == 0xff) {
+			if(sizeof(sdkp->capacity) > 4) {
+				printk(KERN_NOTICE "%s : very big device. try to use"
+				       " READ CAPACITY(16).\n", diskname);
+				longrc = 1;
+				goto repeat;
+			} else {
+				printk(KERN_ERR "%s: too big for kernel.  Assuming maximum 2Tb\n", diskname);
+			}
+		}
+		sdkp->capacity = 1 + (((sector_t)buffer[0] << 24) |
+			(buffer[1] << 16) |
+			(buffer[2] << 8) |
+			buffer[3]);			
+	} else {
+		sdkp->capacity = 1 + (((u64)buffer[0] << 56) |
+			((u64)buffer[1] << 48) |
+			((u64)buffer[2] << 40) |
+			((u64)buffer[3] << 32) |
+			((sector_t)buffer[4] << 24) |
+			((sector_t)buffer[5] << 16) |
+			((sector_t)buffer[6] << 8)  |
+			(sector_t)buffer[7]);
+			
+		sector_size = (buffer[8] << 24) |
+			(buffer[9] << 16) | (buffer[10] << 8) | buffer[11];
+	}	
 
+got_data:
 	if (sector_size == 0) {
 		sector_size = 512;
 		printk(KERN_NOTICE "%s : sector size 0 reported, "
@@ -996,7 +1060,7 @@
 		 */
 		int hard_sector = sector_size;
 		sector_t sz = sdkp->capacity * (hard_sector/256);
-		request_queue_t *queue = &sdp->request_queue;
+		request_queue_t *queue = sdp->request_queue;
 		sector_t mb;
 
 		blk_queue_hardsect_size(queue, hard_sector);
@@ -1139,10 +1203,10 @@
 
 	if (sdkp->media_present)
 		sd_read_capacity(sdkp, disk->disk_name, SRpnt, buffer);
-
+	
 	if (sdp->removable && sdkp->media_present)
 		sd_read_write_protect_flag(sdkp, disk->disk_name, SRpnt, buffer);
-
+		
 	SRpnt->sr_device->ten = 1;
 	SRpnt->sr_device->remap = 1;
 
@@ -1231,7 +1295,7 @@
 	if (sdp->removable)
 		gd->flags |= GENHD_FL_REMOVABLE;
 	gd->private_data = &sdkp->driver;
-	gd->queue = &sdkp->device->request_queue;
+	gd->queue = sdkp->device->request_queue;
 
 	sd_devlist_insert(sdkp);
 	set_capacity(gd, sdkp->capacity);
diff -Nru a/drivers/scsi/sg.c b/drivers/scsi/sg.c
--- a/drivers/scsi/sg.c	Mon Dec 23 21:21:54 2002
+++ b/drivers/scsi/sg.c	Mon Dec 23 21:21:54 2002
@@ -695,7 +695,7 @@
 	}
 
 	srp->my_cmdp = SRpnt;
-	q = &SRpnt->sr_device->request_queue;
+	q = SRpnt->sr_device->request_queue;
 	SRpnt->sr_request->rq_disk = sdp->disk;
 	SRpnt->sr_sense_buffer[0] = 0;
 	SRpnt->sr_cmd_len = hp->cmd_len;
diff -Nru a/drivers/scsi/sr.c b/drivers/scsi/sr.c
--- a/drivers/scsi/sr.c	Mon Dec 23 21:21:52 2002
+++ b/drivers/scsi/sr.c	Mon Dec 23 21:21:52 2002
@@ -563,7 +563,7 @@
 	register_cdrom(&cd->cdi);
 	set_capacity(disk, cd->capacity);
 	disk->private_data = &cd->driver;
-	disk->queue = &sdev->request_queue;
+	disk->queue = sdev->request_queue;
 
 	add_disk(disk);
 	sr_devlist_insert(cd);
@@ -672,7 +672,7 @@
 		set_capacity(cd->disk, cd->capacity);
 	}
 
-	queue = &cd->device->request_queue;
+	queue = cd->device->request_queue;
 	blk_queue_hardsect_size(queue, sector_size);
 out:
 	kfree(buffer);
diff -Nru a/drivers/scsi/st.c b/drivers/scsi/st.c
--- a/drivers/scsi/st.c	Mon Dec 23 21:21:57 2002
+++ b/drivers/scsi/st.c	Mon Dec 23 21:21:57 2002
@@ -3764,21 +3764,9 @@
 	tpnt->nbr_partitions = 0;
 	tpnt->timeout = ST_TIMEOUT;
 	tpnt->long_timeout = ST_LONG_TIMEOUT;
-
 	tpnt->try_dio = try_direct_io && !SDp->host->unchecked_isa_dma;
-	bounce_limit = BLK_BOUNCE_HIGH; /* Borrowed from scsi_merge.c */
-	if (SDp->host->highmem_io) {
-		struct device *dev = scsi_get_device(SDp->host);
-		if (!PCI_DMA_BUS_IS_PHYS)
-			/* Platforms with virtual-DMA translation
-			 * hardware have no practical limit.
-			 */
-			bounce_limit = BLK_BOUNCE_ANY;
-		else if (dev && dev->dma_mask)
-			bounce_limit = *dev->dma_mask;
-	} else if (SDp->host->unchecked_isa_dma)
-		bounce_limit = BLK_BOUNCE_ISA;
-	bounce_limit >>= PAGE_SHIFT;
+
+	bounce_limit = scsi_calculate_bounce_limit(SDp->host) >> PAGE_SHIFT;
 	if (bounce_limit > ULONG_MAX)
 		bounce_limit = ULONG_MAX;
 	tpnt->max_pfn = bounce_limit;
diff -Nru a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
--- a/drivers/serial/sunsu.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/serial/sunsu.c	Mon Dec 23 21:21:51 2002
@@ -696,7 +696,7 @@
 				     SA_SHIRQ, su_typev[up->su_type], up);
 	}
 	if (retval) {
-		printk("su: Cannot register IRQ\n");
+		printk("su: Cannot register IRQ %d\n", up->irq);
 		return retval;
 	}
 
@@ -783,6 +783,8 @@
 	 * Read data port to reset things.
 	 */
 	(void) serial_in(up, UART_RX);
+
+	free_irq(up->irq, up);
 }
 
 static void
diff -Nru a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
--- a/drivers/usb/class/cdc-acm.c	Mon Dec 23 21:21:57 2002
+++ b/drivers/usb/class/cdc-acm.c	Mon Dec 23 21:21:57 2002
@@ -278,7 +278,7 @@
 	urb->actual_length = 0;
 	urb->dev = acm->dev;
 
-	if (usb_submit_urb(urb, GFP_KERNEL))
+	if (usb_submit_urb(urb, GFP_ATOMIC))
 		dbg("failed resubmitting read urb");
 }
 
diff -Nru a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
--- a/drivers/usb/core/hcd.c	Mon Dec 23 21:21:56 2002
+++ b/drivers/usb/core/hcd.c	Mon Dec 23 21:21:56 2002
@@ -389,8 +389,8 @@
 		break;
 	case DeviceOutRequest | USB_REQ_SET_ADDRESS:
 		// wValue == urb->dev->devaddr
-		dbg ("%s root hub device address %d",
-			hcd->self.bus_name, wValue);
+		dev_dbg (*hcd->controller, "root hub device address %d\n",
+			wValue);
 		break;
 
 	/* INTERFACE REQUESTS (no defined feature/status flags) */
@@ -1022,7 +1022,10 @@
 		 * they could clobber root hub response data.
 		 */
 		urb->transfer_flags |= URB_NO_DMA_MAP;
-		return rh_urb_enqueue (hcd, urb);
+		status = rh_urb_enqueue (hcd, urb);
+		if (status)
+			urb_unlink (urb);
+		return status;
 	}
 
 	/* lower level hcd code should use *_dma exclusively */
@@ -1043,7 +1046,10 @@
 					    : PCI_DMA_TODEVICE);
 	}
 
-	return hcd->driver->urb_enqueue (hcd, urb, mem_flags);
+	status = hcd->driver->urb_enqueue (hcd, urb, mem_flags);
+	if (status)
+		urb_unlink (urb);
+	return status;
 }
 
 /*-------------------------------------------------------------------------*/
@@ -1137,7 +1143,7 @@
 	 * FIXME use better explicit urb state
 	 */
 	if (urb->status != -EINPROGRESS) {
-		retval = -EINVAL;
+		retval = -EBUSY;
 		goto done;
 	}
 
@@ -1188,7 +1194,6 @@
 	if (urb->transfer_flags & URB_ASYNC_UNLINK)
 		return -EINPROGRESS;
 
-	dev_dbg (*sys, "wait for giveback urb %p\n", urb);
 	wait_for_completion (&splice.done);
 	return 0;
 
diff -Nru a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
--- a/drivers/usb/core/hub.c	Mon Dec 23 21:21:54 2002
+++ b/drivers/usb/core/hub.c	Mon Dec 23 21:21:54 2002
@@ -57,6 +57,12 @@
 }
 #endif
 
+/* for dev_info, dev_dbg, etc */
+static inline struct device *hubdev (struct usb_device *dev)
+{
+	return &dev->actconfig->interface [0].dev;
+}
+
 /* USB 2.0 spec Section 11.24.4.5 */
 static int usb_get_hub_descriptor(struct usb_device *dev, void *data, int size)
 {
@@ -273,12 +279,13 @@
 	struct usb_hub_status hubstatus;
 	unsigned int pipe;
 	int maxp, ret;
+	char *message;
 
 	hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL);
 	if (!hub->descriptor) {
-		err("Unable to kmalloc %Zd bytes for hub descriptor",
-			sizeof(*hub->descriptor));
-		return -1;
+		message = "can't kmalloc hub descriptor";
+		ret = -ENOMEM;
+		goto fail;
 	}
 
 	/* Request the entire hub descriptor.
@@ -288,17 +295,16 @@
 	ret = usb_get_hub_descriptor(dev, hub->descriptor,
 			sizeof(*hub->descriptor));
 	if (ret < 0) {
-		err("Unable to get hub descriptor (err = %d)", ret);
-		kfree(hub->descriptor);
-		return -1;
+		message = "can't read hub descriptor";
+		goto fail;
 	} else if (hub->descriptor->bNbrPorts > USB_MAXCHILDREN) {
-		err("Hub is too big! %d children", hub->descriptor->bNbrPorts);
-		kfree(hub->descriptor);
-		return -1;
+		message = "hub has too many ports!";
+		ret = -ENODEV;
+		goto fail;
 	}
 
 	dev->maxchild = hub->descriptor->bNbrPorts;
-	info("%d port%s detected", dev->maxchild,
+	dev_info (*hubdev (dev), "%d port%s detected\n", dev->maxchild,
 		(dev->maxchild == 1) ? "" : "s");
 
 	le16_to_cpus(&hub->descriptor->wHubCharacteristics);
@@ -390,9 +396,8 @@
 
 	ret = usb_get_hub_status(dev, &hubstatus);
 	if (ret < 0) {
-		err("Unable to get hub status (err = %d)", ret);
-		kfree(hub->descriptor);
-		return -1;
+		message = "can't get hub status";
+		goto fail;
 	}
 
 	le16_to_cpus(&hubstatus.wHubStatus);
@@ -413,18 +418,17 @@
 
 	hub->urb = usb_alloc_urb(0, GFP_KERNEL);
 	if (!hub->urb) {
-		err("couldn't allocate interrupt urb");
-		kfree(hub->descriptor);
-		return -1;
+		message = "couldn't allocate interrupt urb";
+		ret = -ENOMEM;
+		goto fail;
 	}
 
 	usb_fill_int_urb(hub->urb, dev, pipe, hub->buffer, maxp, hub_irq,
 		hub, endpoint->bInterval);
 	ret = usb_submit_urb(hub->urb, GFP_KERNEL);
 	if (ret) {
-		err("usb_submit_urb failed (%d)", ret);
-		kfree(hub->descriptor);
-		return -1;
+		message = "couldn't submit status urb";
+		goto fail;
 	}
 		
 	/* Wake up khubd */
@@ -433,6 +437,12 @@
 	usb_hub_power_on(hub);
 
 	return 0;
+
+fail:
+	dev_err (hub->intf->dev, "config failed, %s (err %d)\n",
+			message, ret);
+	/* hub_disconnect() frees urb and descriptor */
+	return ret;
 }
 
 static void hub_disconnect(struct usb_interface *intf)
@@ -491,37 +501,32 @@
 	/*  specs is not defined, but it works */
 	if ((desc->desc.bInterfaceSubClass != 0) &&
 	    (desc->desc.bInterfaceSubClass != 1)) {
-		err("invalid subclass (%d) for USB hub device #%d",
-			desc->desc.bInterfaceSubClass, dev->devnum);
+descriptor_error:
+		dev_err (intf->dev, "bad descriptor, ignoring hub\n");
 		return -EIO;
 	}
 
 	/* Multiple endpoints? What kind of mutant ninja-hub is this? */
 	if (desc->desc.bNumEndpoints != 1) {
-		err("invalid bNumEndpoints (%d) for USB hub device #%d",
-			desc->desc.bNumEndpoints, dev->devnum);
-		return -EIO;
+		goto descriptor_error;
 	}
 
 	endpoint = &desc->endpoint[0].desc;
 
 	/* Output endpoint? Curiousier and curiousier.. */
 	if (!(endpoint->bEndpointAddress & USB_DIR_IN)) {
-		err("Device #%d is hub class, but has output endpoint?",
-			dev->devnum);
-		return -EIO;
+		goto descriptor_error;
 	}
 
 	/* If it's not an interrupt endpoint, we'd better punt! */
 	if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
 			!= USB_ENDPOINT_XFER_INT) {
-		err("Device #%d is hub class, but endpoint is not interrupt?",
-			dev->devnum);
+		goto descriptor_error;
 		return -EIO;
 	}
 
 	/* We found a hub */
-	info("USB hub found at %s", dev->devpath);
+	dev_info (*hubdev (dev), "USB hub found\n");
 
 	hub = kmalloc(sizeof(*hub), GFP_KERNEL);
 	if (!hub) {
@@ -548,8 +553,6 @@
 		return 0;
 	}
 
-	err("hub configuration failed for device at %s", dev->devpath);
-
 	hub_disconnect (intf);
 	return -ENODEV;
 }
@@ -651,8 +654,6 @@
 		else {
 			*status = le16_to_cpu(portsts->wPortStatus);
 			*change = le16_to_cpu(portsts->wPortChange); 
-			dbg("port %d, portstatus %x, change %x, %s", port + 1,
-				*status, *change, portspeed(*status));
 			ret = 0;
 		}
 		kfree(portsts);
@@ -710,8 +711,9 @@
 		if (delay_time >= 2 * HUB_SHORT_RESET_TIME)
 			delay = HUB_LONG_RESET_TIME;
 
-		dbg("port %d of hub %s not reset yet, waiting %dms", port + 1,
-			hub->devpath, delay);
+		dev_dbg (*hubdev (hub),
+			"port %d not reset yet, waiting %dms\n",
+			port + 1, delay);
 	}
 
 	return -1;
@@ -735,14 +737,15 @@
 			return status;
 		}
 
-		dbg("port %d of hub %s not enabled, trying reset again...",
-			port + 1, hub->devpath);
+		dev_dbg (*hubdev (hub),
+			"port %d not enabled, trying reset again...\n",
+			port + 1);
 		delay = HUB_LONG_RESET_TIME;
 	}
 
-	err("Cannot enable port %i of hub %s, disabling port.",
-		port + 1, hub->devpath);
-	err("Maybe the USB cable is bad?");
+	dev_err (*hubdev (hub),
+		"Cannot enable port %i.  Maybe the USB cable is bad?\n",
+		port + 1);
 
 	return -1;
 }
@@ -808,8 +811,9 @@
 	}
 
 	/* XXX Replace this with dbg() when 2.6 is about to ship. */
-	info("debounce: hub %d port %d: delay %dms stable %d status 0x%x\n",
-	    hub->devnum, port, delay_time, stable_count, portstatus);
+	dev_info (*hubdev (hub),
+		"debounce: port %d: delay %dms stable %d status 0x%x\n",
+		port + 1, delay_time, stable_count, portstatus);
 
 	return ((portstatus&USB_PORT_STAT_CONNECTION)) ? 0 : 1;
 }
@@ -822,9 +826,9 @@
 	unsigned int delay = HUB_SHORT_RESET_TIME;
 	int i;
 
-	dbg("hub %s port %d, portstatus %x, change %x, %s",
-		hub->devpath, port + 1,
-		portstatus, portchange, portspeed (portstatus));
+	dev_dbg (hubstate->intf->dev,
+		"port %d, status %x, change %x, %s\n",
+		port + 1, portstatus, portchange, portspeed (portstatus));
 
 	/* Clear the connection change status */
 	usb_clear_port_feature(hub, port + 1, USB_PORT_FEAT_C_CONNECTION);
@@ -842,7 +846,9 @@
 	}
 
 	if (usb_hub_port_debounce(hub, port)) {
-		err("connect-debounce failed, port %d disabled", port+1);
+		dev_err (hubstate->intf->dev,
+			"connect-debounce failed, port %d disabled\n",
+			port+1);
 		usb_hub_port_disable(hub, port);
 		return;
 	}
@@ -861,7 +867,8 @@
 		/* Allocate a new device struct */
 		dev = usb_alloc_dev(hub, hub->bus);
 		if (!dev) {
-			err("couldn't allocate usb_device");
+			dev_err (hubstate->intf->dev,
+				"couldn't allocate usb_device\n");
 			break;
 		}
 
@@ -904,10 +911,12 @@
 			len = snprintf (dev->devpath, sizeof dev->devpath,
 				"%d", port + 1);
 		if (len == sizeof dev->devpath)
-			warn ("devpath size! usb/%03d/%03d path %s",
+			dev_err (hubstate->intf->dev,
+				"devpath size! usb/%03d/%03d path %s\n",
 				dev->bus->busnum, dev->devnum, dev->devpath);
-		info("new USB device %s-%s, assigned address %d",
-			dev->bus->bus_name, dev->devpath, dev->devnum);
+		dev_info (hubstate->intf->dev,
+			"new USB device on port %d, assigned address %d\n",
+			port + 1, dev->devnum);
 
 		/* put the device in the global device tree. the hub port
 		 * is the "bus_id"; hubs show in hierarchy like bridges
@@ -992,12 +1001,11 @@
 			}
 
 			if (portchange & USB_PORT_STAT_C_CONNECTION) {
-				dbg("hub %s port %d connection change",
-					dev->devpath, i + 1);
 				usb_hub_port_connect_change(hub, i, portstatus, portchange);
 			} else if (portchange & USB_PORT_STAT_C_ENABLE) {
-				dbg("hub %s port %d enable change, status %x",
-					dev->devpath, i + 1, portstatus);
+				dev_dbg (*hubdev (dev),
+					"port %d enable change, status %x\n",
+					i + 1, portstatus);
 				usb_clear_port_feature(dev,
 					i + 1, USB_PORT_FEAT_C_ENABLE);
 
diff -Nru a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
--- a/drivers/usb/core/inode.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/usb/core/inode.c	Mon Dec 23 21:21:51 2002
@@ -487,10 +487,15 @@
  * It will be removed when the 2.7.x development cycle is started.
  * You have been warned :)
  */
+static struct file_system_type usbdevice_fs_type;
 
 static struct super_block *usb_get_sb(struct file_system_type *fs_type,
 	int flags, char *dev_name, void *data)
 {
+	if (fs_type == &usbdevice_fs_type)
+		printk (KERN_INFO "Please use the 'usbfs' filetype instead, "
+				"the 'usbdevfs' name is deprecated.\n");
+
 	return get_sb_single(fs_type, flags, data, usbfs_fill_super);
 }
 
diff -Nru a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
--- a/drivers/usb/host/ehci-dbg.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/usb/host/ehci-dbg.c	Mon Dec 23 21:21:59 2002
@@ -18,21 +18,45 @@
 
 /* this file is part of ehci-hcd.c */
 
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,50)
+
 #define ehci_dbg(ehci, fmt, args...) \
 	dev_dbg (*(ehci)->hcd.controller, fmt, ## args )
+#define ehci_err(ehci, fmt, args...) \
+	dev_err (*(ehci)->hcd.controller, fmt, ## args )
+#define ehci_info(ehci, fmt, args...) \
+	dev_info (*(ehci)->hcd.controller, fmt, ## args )
+#define ehci_warn(ehci, fmt, args...) \
+	dev_warn (*(ehci)->hcd.controller, fmt, ## args )
 
-#ifdef EHCI_VERBOSE_DEBUG
-#define ehci_vdbg(ehci, fmt, args...) \
-	dev_dbg (*(ehci)->hcd.controller, fmt, ## args )
 #else
-#define ehci_vdbg(ehci, fmt, args...) do { } while (0)
+
+#ifdef DEBUG
+#define ehci_dbg(ehci, fmt, args...) \
+	printk(KERN_DEBUG "%s %s: " fmt, hcd_name, \
+		(ehci)->hcd.pdev->slot_name, ## args )
+#else
+#define ehci_dbg(ehci, fmt, args...) do { } while (0)
+#endif
+
+#define ehci_err(ehci, fmt, args...) \
+	printk(KERN_ERR "%s %s: " fmt, hcd_name, \
+		(ehci)->hcd.pdev->slot_name, ## args )
+#define ehci_info(ehci, fmt, args...) \
+	printk(KERN_INFO "%s %s: " fmt, hcd_name, \
+		(ehci)->hcd.pdev->slot_name, ## args )
+#define ehci_warn(ehci, fmt, args...) \
+	printk(KERN_WARNING "%s %s: " fmt, hcd_name, \
+		(ehci)->hcd.pdev->slot_name, ## args )
 #endif
 
 
 #ifdef EHCI_VERBOSE_DEBUG
 #	define vdbg dbg
+#	define ehci_vdbg ehci_dbg
 #else
-	static inline void vdbg (char *fmt, ...) { }
+#	define vdbg(fmt,args...) do { } while (0)
+#	define ehci_vdbg(ehci, fmt, args...) do { } while (0)
 #endif
 
 #ifdef	DEBUG
@@ -289,7 +313,8 @@
 
 	scratch = cpu_to_le32p (&qh->hw_info1);
 	hw_curr = cpu_to_le32p (&qh->hw_current);
-	temp = snprintf (next, size, "qh/%p dev%d %cs ep%d %08x %08x (%08x %08x)",
+	temp = snprintf (next, size,
+			"qh/%p dev%d %cs ep%d %08x %08x (%08x %08x)",
 			qh, scratch & 0x007f,
 			speed_char (scratch),
 			(scratch >> 8) & 0x000f,
diff -Nru a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
--- a/drivers/usb/host/ehci-hcd.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/usb/host/ehci-hcd.c	Mon Dec 23 21:21:58 2002
@@ -123,12 +123,6 @@
 MODULE_PARM (log2_irq_thresh, "i");
 MODULE_PARM_DESC (log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
 
-/* allow irqs at least every N URB completions */
-static int max_completions = 16;
-MODULE_PARM (max_completions, "i");
-MODULE_PARM_DESC (max_completions,
-		"limit for urb completions called with irqs disenabled");
-
 #define	INTR_MASK (STS_IAA | STS_FATAL | STS_ERR | STS_INT)
 
 /*-------------------------------------------------------------------------*/
@@ -202,7 +196,7 @@
 	dbg_cmd (ehci, "reset", command);
 	writel (command, &ehci->regs->command);
 	ehci->hcd.state = USB_STATE_HALT;
-	return handshake (&ehci->regs->command, CMD_RESET, 0, 250);
+	return handshake (&ehci->regs->command, CMD_RESET, 0, 250 * 1000);
 }
 
 /* idle the controller (from running) */
@@ -250,9 +244,7 @@
 
 /*-------------------------------------------------------------------------*/
 
-static void ehci_tasklet (unsigned long param);
-
-static void ehci_irq (struct usb_hcd *hcd, struct pt_regs *regs);
+static void ehci_work(struct ehci_hcd *ehci, struct pt_regs *regs);
 
 static void ehci_watchdog (unsigned long param)
 {
@@ -260,10 +252,25 @@
 	unsigned long		flags;
 
 	spin_lock_irqsave (&ehci->lock, flags);
-	/* guard against lost IAA, which wedges everything */
-	ehci_irq (&ehci->hcd, NULL);
+
+	/* lost IAA irqs wedge things badly; seen with a vt8235 */
+	if (ehci->reclaim) {
+		u32		status = readl (&ehci->regs->status);
+
+		if (status & STS_IAA) {
+			ehci_vdbg (ehci, "lost IAA\n");
+			writel (STS_IAA, &ehci->regs->status);
+			ehci->reclaim_ready = 1;
+		}
+	}
+
+	ehci_work (ehci, NULL);
+	if (ehci->reclaim && !timer_pending (&ehci->watchdog))
+		mod_timer (&ehci->watchdog,
+				jiffies + EHCI_WATCHDOG_JIFFIES);
+
  	/* stop async processing after it's idled a while */
- 	if (ehci->async_idle) {
+	else if (ehci->async_idle) {
  		start_unlink_async (ehci, ehci->async);
  		ehci->async_idle = 0;
 	}
@@ -289,8 +296,7 @@
 			pci_read_config_dword (ehci->hcd.pdev, where, &cap);
 		} while ((cap & (1 << 16)) && msec);
 		if (cap & (1 << 16)) {
-			dev_info (*ehci->hcd.controller,
-				"BIOS handoff failed (%d, %04x)\n",
+			ehci_err (ehci, "BIOS handoff failed (%d, %04x)\n",
 				where, cap);
 			return 1;
 		} 
@@ -333,8 +339,7 @@
 				return -EOPNOTSUPP;
 			break;
 		case 0:			/* illegal reserved capability */
-			dev_warn (*ehci->hcd.controller,
-					"illegal capability!\n");
+			ehci_warn (ehci, "illegal capability!\n");
 			cap = 0;
 			/* FALLTHROUGH */
 		default:		/* unknown */
@@ -381,6 +386,8 @@
 	 * dedicate a qh for the async ring head, since we couldn't unlink
 	 * a 'real' qh without stopping the async schedule [4.8].  use it
 	 * as the 'reclamation list head' too.
+	 * its dummy is used in hw_alt_next of many tds, to prevent the qh
+	 * from automatically advancing to the next td after short reads.
 	 */
 	ehci->async->qh_next.qh = 0;
 	ehci->async->hw_next = QH_NEXT (ehci->async->qh_dma);
@@ -388,8 +395,7 @@
 	ehci->async->hw_token = cpu_to_le32 (QTD_STS_HALT);
 	ehci->async->hw_qtd_next = EHCI_LIST_END;
 	ehci->async->qh_state = QH_STATE_LINKED;
-	ehci_qtd_free (ehci, ehci->async->dummy);
-	ehci->async->dummy = 0;
+	ehci->async->hw_alt_next = QTD_NEXT (ehci->async->dummy->qtd_dma);
 	writel ((u32)ehci->async->qh_dma, &ehci->regs->async_next);
 
 	/*
@@ -406,8 +412,7 @@
 	if (HCC_64BIT_ADDR (hcc_params)) {
 		writel (0, &ehci->regs->segment);
 		if (!pci_set_dma_mask (ehci->hcd.pdev, 0xffffffffffffffffULL))
-			dev_info (*ehci->hcd.controller,
-				"enabled 64bit PCI DMA (DAC)\n");
+			ehci_info (ehci, "enabled 64bit PCI DMA\n");
 	}
 
 	/* clear interrupt enables, set irq latency */
@@ -426,9 +431,6 @@
 
 	/* set async sleep time = 10 us ... ? */
 
-	ehci->tasklet.func = ehci_tasklet;
-	ehci->tasklet.data = (unsigned long) ehci;
-
 	init_timer (&ehci->watchdog);
 	ehci->watchdog.function = ehci_watchdog;
 	ehci->watchdog.data = (unsigned long) ehci;
@@ -454,7 +456,7 @@
         /* PCI Serial Bus Release Number is at 0x60 offset */
 	pci_read_config_byte (hcd->pdev, 0x60, &tempbyte);
 	temp = readw (&ehci->caps->hci_version);
-	dev_info (*hcd->controller,
+	ehci_info (ehci,
 		"USB %x.%x enabled, EHCI %x.%02x, driver %s\n",
 		((tempbyte & 0xf0)>>4), (tempbyte & 0x0f),
 		temp >> 8, temp & 0xff, DRIVER_VERSION);
@@ -494,10 +496,11 @@
 	/* no more interrupts ... */
 	if (hcd->state == USB_STATE_RUNNING)
 		ehci_ready (ehci);
-	if (in_interrupt ())		/* should not happen!! */
-		dev_err (*hcd->controller, "stopped %s!\n", RUN_CONTEXT);
-	else
-		del_timer_sync (&ehci->watchdog);
+	if (in_interrupt ()) {		/* must not happen!! */
+		ehci_err (ehci, "stopped in_interrupt!\n");
+		return;
+	}
+	del_timer_sync (&ehci->watchdog);
 	ehci_reset (ehci);
 
 	/* let companion controllers work when we aren't */
@@ -506,8 +509,9 @@
 	remove_debug_files (ehci);
 
 	/* root hub is shut down separately (first, when possible) */
-	tasklet_disable (&ehci->tasklet);
-	ehci_tasklet ((unsigned long) ehci);
+	spin_lock_irq (&ehci->lock);
+	ehci_work (ehci, NULL);
+	spin_unlock_irq (&ehci->lock);
 	ehci_mem_cleanup (ehci);
 
 #ifdef	EHCI_STATS
@@ -615,22 +619,16 @@
 /*-------------------------------------------------------------------------*/
 
 /*
- * tasklet scheduled by some interrupts and other events
- * calls driver completion functions ... but not in_irq()
+ * ehci_work is called from some interrupts, timers, and so on.
+ * it calls driver completion functions, after dropping ehci->lock.
  */
-static void ehci_tasklet (unsigned long param)
+static void ehci_work (struct ehci_hcd *ehci, struct pt_regs *regs)
 {
-	struct ehci_hcd		*ehci = (struct ehci_hcd *) param;
-
-	spin_lock_irq (&ehci->lock);
-
 	if (ehci->reclaim_ready)
-		end_unlink_async (ehci);
-	scan_async (ehci);
+		end_unlink_async (ehci, regs);
+	scan_async (ehci, regs);
 	if (ehci->next_uframe != -1)
-		scan_periodic (ehci);
-
-	spin_unlock_irq (&ehci->lock);
+		scan_periodic (ehci, regs);
 }
 
 /*-------------------------------------------------------------------------*/
@@ -643,7 +641,7 @@
 
 	/* e.g. cardbus physical eject */
 	if (status == ~(u32) 0) {
-		dbg ("%s: device removed!", hcd_to_bus (hcd)->bus_name);
+		ehci_dbg (ehci, "device removed\n");
 		goto dead;
 	}
 
@@ -651,6 +649,8 @@
 	if (!status)			/* irq sharing? */
 		return;
 
+	spin_lock (&ehci->lock);
+
 	/* clear (just) interrupts */
 	writel (status, &ehci->regs->status);
 	readl (&ehci->regs->command);	/* unblock posted write */
@@ -681,8 +681,7 @@
 
 	/* PCI errors [4.15.2.4] */
 	if (unlikely ((status & STS_FATAL) != 0)) {
-		err ("%s: fatal error, state %x",
-			hcd_to_bus (hcd)->bus_name, hcd->state);
+		ehci_err (ehci, "fatal error\n");
 dead:
 		ehci_reset (ehci);
 		/* generic layer kills/unlinks all urbs, then
@@ -691,9 +690,9 @@
 		bh = 1;
 	}
 
-	/* most work doesn't need to be in_irq() */
-	if (likely (bh == 1))
-		tasklet_schedule (&ehci->tasklet);
+	if (bh)
+		ehci_work (ehci, regs);
+	spin_unlock (&ehci->lock);
 }
 
 /*-------------------------------------------------------------------------*/
@@ -754,52 +753,52 @@
 static int ehci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
 {
 	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);
-	struct ehci_qh		*qh = (struct ehci_qh *) urb->hcpriv;
+	struct ehci_qh		*qh;
 	unsigned long		flags;
+	int			maybe_irq = 1;
 
-	ehci_vdbg (ehci, "urb_dequeue %p qh %p state %d\n",
-		urb, qh, qh->qh_state);
-
+	spin_lock_irqsave (&ehci->lock, flags);
 	switch (usb_pipetype (urb->pipe)) {
 	// case PIPE_CONTROL:
 	// case PIPE_BULK:
 	default:
-		spin_lock_irqsave (&ehci->lock, flags);
-		if (ehci->reclaim) {
-			vdbg ("dq %p: reclaim = %p, %s",
-				qh, ehci->reclaim, RUN_CONTEXT);
-			if (qh == ehci->reclaim) {
-				/* unlinking qh for another queued urb? */
-				spin_unlock_irqrestore (&ehci->lock, flags);
-				return 0;
-			}
-			if (in_interrupt ()) {
-				spin_unlock_irqrestore (&ehci->lock, flags);
-				return -EAGAIN;
-			}
-			while (qh->qh_state == QH_STATE_LINKED
-					&& ehci->reclaim
-					&& ehci->hcd.state != USB_STATE_HALT
-					) {
-				spin_unlock_irqrestore (&ehci->lock, flags);
-				/* let pending unlinks complete */
-				wait_ms (1);
-				spin_lock_irqsave (&ehci->lock, flags);
+		qh = (struct ehci_qh *) urb->hcpriv;
+		if (!qh)
+			break;
+		while (qh->qh_state == QH_STATE_LINKED
+				&& ehci->reclaim
+				&& HCD_IS_RUNNING (ehci->hcd.state)
+				) {
+			spin_unlock_irqrestore (&ehci->lock, flags);
+
+			if (maybe_irq) {
+				if (in_interrupt ())
+					return -EAGAIN;
+				maybe_irq = 0;
 			}
+			/* let pending unlinks complete, so this can start */
+			wait_ms (1);
+
+			spin_lock_irqsave (&ehci->lock, flags);
 		}
+		if (!HCD_IS_RUNNING (ehci->hcd.state) && ehci->reclaim)
+			end_unlink_async (ehci, NULL);
+
+		/* something else might have unlinked the qh by now */
 		if (qh->qh_state == QH_STATE_LINKED)
 			start_unlink_async (ehci, qh);
-		spin_unlock_irqrestore (&ehci->lock, flags);
 		break;
 
 	case PIPE_INTERRUPT:
-		spin_lock_irqsave (&ehci->lock, flags);
+		qh = (struct ehci_qh *) urb->hcpriv;
+		if (!qh)
+			break;
 		if (qh->qh_state == QH_STATE_LINKED) {
 			/* messy, can spin or block a microframe ... */
 			intr_deschedule (ehci, qh, 1);
 			/* qh_state == IDLE */
 		}
-		qh_completions (ehci, qh);
+		qh_completions (ehci, qh, NULL);
 
 		/* reschedule QH iff another request is queued */
 		if (!list_empty (&qh->qtd_list)
@@ -817,7 +816,6 @@
 			}
 			return status;
 		}
-		spin_unlock_irqrestore (&ehci->lock, flags);
 		break;
 
 	case PIPE_ISOCHRONOUS:
@@ -828,6 +826,7 @@
 		urb->transfer_flags |= EHCI_STATE_UNLINK;
 		break;
 	}
+	spin_unlock_irqrestore (&ehci->lock, flags);
 	return 0;
 }
 
@@ -885,11 +884,11 @@
 			 */
 			while (qh->qh_state == QH_STATE_LINKED
 					&& ehci->reclaim
-					&& ehci->hcd.state != USB_STATE_HALT
+					&& HCD_IS_RUNNING (ehci->hcd.state)
 					) {
 				spin_unlock_irqrestore (&ehci->lock, flags);
 				/* wait_ms() won't spin, we're a thread;
-				 * and we know IRQ+tasklet can progress
+				 * and we know IRQ/timer/... can progress
 				 */
 				wait_ms (1);
 				spin_lock_irqsave (&ehci->lock, flags);
diff -Nru a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
--- a/drivers/usb/host/ehci-hub.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/usb/host/ehci-hub.c	Mon Dec 23 21:22:00 2002
@@ -315,7 +315,7 @@
 					wIndex + 1);
 				temp |= PORT_OWNER;
 			} else {
-				ehci_vdbg (ehci, "port %d reset", wIndex + 1);
+				ehci_vdbg (ehci, "port %d reset\n", wIndex + 1);
 				temp |= PORT_RESET;
 				temp &= ~PORT_PE;
 
diff -Nru a/drivers/usb/host/ehci-mem.c b/drivers/usb/host/ehci-mem.c
--- a/drivers/usb/host/ehci-mem.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/usb/host/ehci-mem.c	Mon Dec 23 21:22:00 2002
@@ -58,7 +58,7 @@
 
 /* Allocate the key transfer structures from the previously allocated pool */
 
-static void ehci_qtd_init (struct ehci_qtd *qtd, dma_addr_t dma)
+static inline void ehci_qtd_init (struct ehci_qtd *qtd, dma_addr_t dma)
 {
 	memset (qtd, 0, sizeof *qtd);
 	qtd->qtd_dma = dma;
@@ -73,8 +73,11 @@
 	dma_addr_t		dma;
 
 	qtd = pci_pool_alloc (ehci->qtd_pool, flags, &dma);
-	if (qtd != 0)
+	if (qtd != 0) {
 		ehci_qtd_init (qtd, dma);
+		if (ehci->async)
+			qtd->hw_alt_next = ehci->async->hw_alt_next;
+	}
 	return qtd;
 }
 
diff -Nru a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
--- a/drivers/usb/host/ehci-q.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/usb/host/ehci-q.c	Mon Dec 23 21:21:59 2002
@@ -73,11 +73,6 @@
 	qtd->hw_token = cpu_to_le32 ((count << 16) | token);
 	qtd->length = count;
 
-#if 0
-	vdbg ("  qtd_fill %p, token %8x bytes %d dma %x",
-		qtd, le32_to_cpu (qtd->hw_token), count, qtd->hw_buf [0]);
-#endif
-
 	return count;
 }
 
@@ -85,11 +80,12 @@
 
 /* update halted (but potentially linked) qh */
 
-static void qh_update (struct ehci_qh *qh, struct ehci_qtd *qtd)
+static inline void
+qh_update (struct ehci_hcd *ehci, struct ehci_qh *qh, struct ehci_qtd *qtd)
 {
 	qh->hw_current = 0;
 	qh->hw_qtd_next = QTD_NEXT (qtd->qtd_dma);
-	qh->hw_alt_next = EHCI_LIST_END;
+	qh->hw_alt_next = ehci->async->hw_alt_next;
 
 	/* HC must see latest qtd and qh data before we clear ACTIVE+HALT */
 	wmb ();
@@ -98,14 +94,29 @@
 
 /*-------------------------------------------------------------------------*/
 
-static inline void qtd_copy_status (struct urb *urb, size_t length, u32 token)
+#define IS_SHORT_READ(token) (QTD_LENGTH (token) != 0 && QTD_PID (token) == 1)
+
+static inline void qtd_copy_status (
+	struct ehci_hcd *ehci,
+	struct urb *urb,
+	size_t length,
+	u32 token
+)
 {
 	/* count IN/OUT bytes, not SETUP (even short packets) */
 	if (likely (QTD_PID (token) != 2))
 		urb->actual_length += length - QTD_LENGTH (token);
 
 	/* don't modify error codes */
-	if (unlikely (urb->status == -EINPROGRESS && (token & QTD_STS_HALT))) {
+	if (unlikely (urb->status != -EINPROGRESS))
+		return;
+
+	/* force cleanup after short read; not always an error */
+	if (unlikely (IS_SHORT_READ (token)))
+		urb->status = -EREMOTEIO;
+
+	/* serious "can't proceed" faults reported by the hardware */
+	if (token & QTD_STS_HALT) {
 		if (token & QTD_STS_BABBLE) {
 			/* FIXME "must" disable babbling device's port too */
 			urb->status = -EOVERFLOW;
@@ -132,7 +143,7 @@
 
 		ehci_vdbg (ehci,
 			"dev%d ep%d%s qtd token %08x --> status %d\n",
-			usb_pipedev (urb->pipe),
+			usb_pipedevice (urb->pipe),
 			usb_pipeendpoint (urb->pipe),
 			usb_pipein (urb->pipe) ? "in" : "out",
 			token, urb->status);
@@ -159,7 +170,8 @@
 	}
 }
 
-static void ehci_urb_done (struct ehci_hcd *ehci, struct urb *urb)
+static void
+ehci_urb_done (struct ehci_hcd *ehci, struct urb *urb, struct pt_regs *regs)
 {
 	if (likely (urb->hcpriv != 0)) {
 		struct ehci_qh	*qh = (struct ehci_qh *) urb->hcpriv;
@@ -171,27 +183,31 @@
 			hcd_to_bus (&ehci->hcd)->bandwidth_int_reqs--;
 		}
 		qh_put (ehci, qh);
-		urb->hcpriv = 0;
 	}
 
-	if (likely (urb->status == -EINPROGRESS)) {
-		if (urb->actual_length != urb->transfer_buffer_length
-				&& (urb->transfer_flags & URB_SHORT_NOT_OK))
-			urb->status = -EREMOTEIO;
-		else
+	spin_lock (&urb->lock);
+	urb->hcpriv = 0;
+	switch (urb->status) {
+	case -EINPROGRESS:		/* success */
+		urb->status = 0;
+	default:			/* fault */
+		COUNT (ehci->stats.complete);
+		break;
+	case -EREMOTEIO:		/* fault or normal */
+		if (!(urb->transfer_flags & URB_SHORT_NOT_OK))
 			urb->status = 0;
-	}
-
-	if (likely (urb->status == 0))
 		COUNT (ehci->stats.complete);
-	else if (urb->status == -ECONNRESET || urb->status == -ENOENT)
+		break;
+	case -ECONNRESET:		/* canceled */
+	case -ENOENT:
 		COUNT (ehci->stats.unlink);
-	else
-		COUNT (ehci->stats.error);
+		break;
+	}
+	spin_unlock (&urb->lock);
 
 	/* complete() can reenter this HCD */
 	spin_unlock (&ehci->lock);
-	usb_hcd_giveback_urb (&ehci->hcd, urb, NULL);
+	usb_hcd_giveback_urb (&ehci->hcd, urb, regs);
 
 	spin_lock (&ehci->lock);
 }
@@ -202,128 +218,115 @@
  * Chases up to qh->hw_current.  Returns number of completions called,
  * indicating how much "real" work we did.
  */
+#define HALT_BIT cpu_to_le32(QTD_STS_HALT)
 static unsigned
-qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
+qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh, struct pt_regs *regs)
 {
-	struct ehci_qtd		*qtd, *last;
-	struct list_head	*next, *qtd_list = &qh->qtd_list;
-	int			unlink = 0, halted = 0;
+	struct ehci_qtd		*last = 0;
+	struct list_head	*entry, *tmp;
+	int			stopped = 0;
 	unsigned		count = 0;
 
-	if (unlikely (list_empty (qtd_list)))
+	if (unlikely (list_empty (&qh->qtd_list)))
 		return count;
 
-	/* scan QTDs till end of list, or we reach an active one */
-	for (qtd = list_entry (qtd_list->next, struct ehci_qtd, qtd_list),
-			    	last = 0, next = 0;
-			next != qtd_list;
-			last = qtd, qtd = list_entry (next,
-						struct ehci_qtd, qtd_list)) {
-		struct urb	*urb = qtd->urb;
+	/* remove de-activated QTDs from front of queue.
+	 * after faults (including short reads), cleanup this urb
+	 * then let the queue advance.
+	 * if queue is stopped, handles unlinks.
+	 */
+	list_for_each_safe (entry, tmp, &qh->qtd_list) {
+		struct ehci_qtd	*qtd;
+		struct urb	*urb;
 		u32		token = 0;
 
+		qtd = list_entry (entry, struct ehci_qtd, qtd_list);
+		urb = qtd->urb;
+
 		/* clean up any state from previous QTD ...*/
 		if (last) {
 			if (likely (last->urb != urb)) {
-				ehci_urb_done (ehci, last->urb);
+				ehci_urb_done (ehci, last->urb, regs);
 				count++;
 			}
 			ehci_qtd_free (ehci, last);
 			last = 0;
 		}
-		next = qtd->qtd_list.next;
 
-		/* QTDs at tail may be active if QH+HC are running,
-		 * or when unlinking some urbs queued to this QH
-		 */
+		/* hardware copies qtd out of qh overlay */
+		rmb ();
 		token = le32_to_cpu (qtd->hw_token);
-		halted = halted
-			|| (__constant_cpu_to_le32 (QTD_STS_HALT)
-				& qh->hw_token) != 0
-			|| (ehci->hcd.state == USB_STATE_HALT)
-			|| (qh->qh_state == QH_STATE_IDLE);
-
-		// FIXME Remove the automagic unlink mode.
-		// Drivers can now clean up safely; it's their job.
-		//
-		// FIXME Removing it should fix the short read scenarios
-		// with "huge" urb data (more than one 16+KByte td) with
-		// the short read someplace other than the last data TD.
-		// Except the control case: 'retrigger' status ACKs.
-
-		/* fault: unlink the rest, since this qtd saw an error? */
-		if (unlikely ((token & QTD_STS_HALT) != 0)) {
-			unlink = 1;
-			/* status copied below */
-
-		/* QH halts only because of fault (above) or unlink (here). */
-		} else if (unlikely (halted != 0)) {
-
-			/* unlinking everything because of HC shutdown? */
-			if (ehci->hcd.state == USB_STATE_HALT) {
-				unlink = 1;
-
-			/* explicit unlink, maybe starting here? */
-			} else if (qh->qh_state == QH_STATE_IDLE
-					&& (urb->status == -ECONNRESET
-						|| urb->status == -ESHUTDOWN
-						|| urb->status == -ENOENT)) {
-				unlink = 1;
-
-			/* QH halted to unlink urbs _after_ this?  */
-			} else if (!unlink && (token & QTD_STS_ACTIVE) != 0) {
-				qtd = 0;
-				continue;
-			}
+		stopped = stopped
+			|| (qh->qh_state == QH_STATE_IDLE)
+			|| (HALT_BIT & qh->hw_token) != 0
+			|| (ehci->hcd.state == USB_STATE_HALT);
+
+		/* always clean up qtds the hc de-activated */
+		if ((token & QTD_STS_ACTIVE) == 0) {
+
+			/* magic dummy for short reads; won't advance */
+			if (IS_SHORT_READ (token)
+					&& !(token & QTD_STS_HALT)
+					&& ehci->async->hw_alt_next
+						== qh->hw_alt_next)
+				goto halt;
 
-			/* unlink the rest?  once we start unlinking, after
-			 * a fault or explicit unlink, we unlink all later
-			 * urbs.  usb spec requires that for faults...
-			 */
-			if (unlink && urb->status == -EINPROGRESS)
-				urb->status = -ECONNRESET;
+		/* stop scanning when we reach qtds the hc is using */
+		} else if (likely (!stopped)) {
+			last = 0;
+			break;
 
-		/* Else QH is active, so we must not modify QTDs
-		 * that HC may be working on.  No more qtds to check.
-		 */
-		} else if (unlikely ((token & QTD_STS_ACTIVE) != 0)) {
-			next = qtd_list;
-			qtd = 0;
-			continue;
+		} else {
+			/* ignore active qtds unless some previous qtd
+			 * for the urb faulted (including short read) or
+			 * its urb was canceled.  we may patch qh or qtds.
+			 */
+			if ((token & QTD_STS_ACTIVE)
+					&& urb->status == -EINPROGRESS) {
+				last = 0;
+				continue;
+			}
+			if ((HALT_BIT & qh->hw_token) == 0) {
+halt:
+				qh->hw_token |= HALT_BIT;
+				wmb ();
+				stopped = 1;
+			}
 		}
-
+ 
+		/* remove it from the queue */
 		spin_lock (&urb->lock);
-		qtd_copy_status (urb, qtd->length, token);
+		qtd_copy_status (ehci, urb, qtd->length, token);
 		spin_unlock (&urb->lock);
 
+		if (stopped && qtd->qtd_list.prev != &qh->qtd_list) {
+			last = list_entry (qtd->qtd_list.prev,
+					struct ehci_qtd, qtd_list);
+			last->hw_next = qtd->hw_next;
+		}
 		list_del (&qtd->qtd_list);
-
-#if 0
-		if (urb->status == -EINPROGRESS)
-			vdbg ("  qtd %p ok, urb %p, token %8x, len %d",
-				qtd, urb, token, urb->actual_length);
-		else
-			vdbg ("urb %p status %d, qtd %p, token %8x, len %d",
-				urb, urb->status, qtd, token,
-				urb->actual_length);
-#endif
+		last = qtd;
 	}
 
 	/* last urb's completion might still need calling */
 	if (likely (last != 0)) {
-		ehci_urb_done (ehci, last->urb);
+		ehci_urb_done (ehci, last->urb, regs);
 		count++;
 		ehci_qtd_free (ehci, last);
 	}
 
-	/* reactivate queue after error and driver's cleanup */
-	if (unlikely (halted && !list_empty (qtd_list))) {
-		qh_update (qh, list_entry (qtd_list->next,
-				struct ehci_qtd, qtd_list));
+	/* update qh after fault cleanup */
+	if (unlikely ((HALT_BIT & qh->hw_token) != 0)) {
+		qh_update (ehci, qh,
+			list_empty (&qh->qtd_list)
+				? qh->dummy
+				: list_entry (qh->qtd_list.next,
+					struct ehci_qtd, qtd_list));
 	}
 
 	return count;
 }
+#undef HALT_BIT
 
 /*-------------------------------------------------------------------------*/
 
@@ -369,7 +372,6 @@
 	qtd = ehci_qtd_alloc (ehci, flags);
 	if (unlikely (!qtd))
 		return 0;
-	qtd_prev = 0;
 	list_add_tail (&qtd->qtd_list, head);
 	qtd->urb = urb;
 
@@ -377,6 +379,8 @@
 	token |= (EHCI_TUNE_CERR << 10);
 	/* for split transactions, SplitXState initialized to zero */
 
+	len = urb->transfer_buffer_length;
+	is_input = usb_pipein (urb->pipe);
 	if (usb_pipecontrol (urb->pipe)) {
 		/* SETUP pid */
 		qtd_fill (qtd, urb->setup_dma, sizeof (struct usb_ctrlrequest),
@@ -392,15 +396,14 @@
 		qtd_prev->hw_next = QTD_NEXT (qtd->qtd_dma);
 		list_add_tail (&qtd->qtd_list, head);
 
-		if (!(urb->transfer_flags & URB_SHORT_NOT_OK))
+		if (len > 0 && is_input
+				&& !(urb->transfer_flags & URB_SHORT_NOT_OK))
 			status_patch = 1;
 	} 
 
 	/*
 	 * data transfer stage:  buffer setup
 	 */
-	len = urb->transfer_buffer_length;
-	is_input = usb_pipein (urb->pipe);
 	if (likely (len > 0))
 		buf = urb->transfer_dma;
 	else
@@ -420,7 +423,6 @@
 	for (;;) {
 		int this_qtd_len;
 
-		qtd->urb = urb;
 		this_qtd_len = qtd_fill (qtd, buf, len, token);
 		len -= this_qtd_len;
 		buf += this_qtd_len;
@@ -532,10 +534,9 @@
  * there are additional complications: c-mask, maybe FSTNs.
  */
 static struct ehci_qh *
-ehci_qh_make (
+qh_make (
 	struct ehci_hcd		*ehci,
 	struct urb		*urb,
-	struct list_head	*qtd_list,
 	int			flags
 ) {
 	struct ehci_qh		*qh = ehci_qh_alloc (ehci, flags);
@@ -578,7 +579,6 @@
 			if (qh->period < 1) {
 				dbg ("intr period %d uframes, NYET!",
 						urb->interval);
-				qh = 0;
 				goto done;
 			}
 		} else {
@@ -639,34 +639,20 @@
 		break;
 	default:
  		dbg ("bogus dev %p speed %d", urb->dev, urb->dev->speed);
- 		return 0;
+done:
+		qh_put (ehci, qh);
+		return 0;
 	}
 
 	/* NOTE:  if (PIPE_INTERRUPT) { scheduler sets s-mask } */
 
+	/* init as halted, toggle clear, advance to dummy */
 	qh->qh_state = QH_STATE_IDLE;
 	qh->hw_info1 = cpu_to_le32 (info1);
 	qh->hw_info2 = cpu_to_le32 (info2);
-
-	/* initialize sw and hw queues with these qtds */
-	if (!list_empty (qtd_list)) {
-		struct ehci_qtd		*qtd;
-
-		/* hc's list view ends with dummy td; we might update it */
-		qtd = list_entry (qtd_list->prev, struct ehci_qtd, qtd_list);
-		qtd->hw_next = QTD_NEXT (qh->dummy->qtd_dma);
-
-		list_splice (qtd_list, &qh->qtd_list);
-		qtd = list_entry (qtd_list->next, struct ehci_qtd, qtd_list);
-		qh_update (qh, qtd);
-	} else {
-		qh->hw_qtd_next = qh->hw_alt_next = EHCI_LIST_END;
-	}
-
-	/* initialize data toggle state */
-	clear_toggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, qh);
-
-done:
+	qh_update (ehci, qh, qh->dummy);
+	qh->hw_token = cpu_to_le32 (QTD_STS_HALT);
+	usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, 1);
 	return qh;
 }
 #undef hb_mult
@@ -685,7 +671,7 @@
 	head = ehci->async;
 	if (ehci->async_idle)
 		del_timer (&ehci->watchdog);
-	else if (!head->qh_next.qh) {
+	if (!head->qh_next.qh) {
 		u32	cmd = readl (&ehci->regs->command);
 
 		if (!(cmd & CMD_ASE)) {
@@ -698,6 +684,8 @@
 		}
 	}
 
+	qh->hw_token &= ~__constant_cpu_to_le32 (QTD_STS_HALT);
+
 	/* splice right after start */
 	qh->qh_next = head->qh_next;
 	qh->hw_next = head->hw_next;
@@ -731,6 +719,11 @@
 	struct ehci_qh		*qh = 0;
 
 	qh = (struct ehci_qh *) *ptr;
+	if (unlikely (qh == 0)) {
+		/* can't sleep here, we have ehci->lock... */
+		qh = qh_make (ehci, urb, SLAB_ATOMIC);
+		*ptr = qh;
+	}
 	if (likely (qh != 0)) {
 		struct ehci_qtd	*qtd;
 
@@ -761,8 +754,34 @@
 			}
 		}
 
-		/* append to tds already queued to this qh? */
-		if (unlikely (!list_empty (&qh->qtd_list) && qtd)) {
+		/* FIXME:  changing config or interface setting is not
+		 * supported yet.  preferred fix is for usbcore to tell
+		 * us to clear out each endpoint's state, but...
+		 */
+
+		/* usb_clear_halt() means qh data toggle gets reset */
+		if (unlikely (!usb_gettoggle (urb->dev,
+					(epnum & 0x0f), !(epnum & 0x10)))
+				&& !usb_pipecontrol (urb->pipe)) {
+			/* "never happens": drivers do stall cleanup right */
+			if (qh->qh_state != QH_STATE_IDLE
+					&& (cpu_to_le32 (QTD_STS_HALT)
+						& qh->hw_token) == 0)
+				ehci_warn (ehci, "clear toggle dev%d "
+						"ep%d%s: not idle\n",
+						usb_pipedevice (urb->pipe),
+						epnum & 0x0f,
+						usb_pipein (urb->pipe)
+							? "in" : "out");
+			/* else we know this overlay write is safe */
+			clear_toggle (urb->dev,
+				epnum & 0x0f, !(epnum & 0x10), qh);
+		}
+
+		/* just one way to queue requests: swap with the dummy qtd.
+		 * only hc or qh_completions() usually modify the overlay.
+		 */
+		if (likely (qtd != 0)) {
 			struct ehci_qtd		*dummy;
 			dma_addr_t		dma;
 			u32			token;
@@ -774,19 +793,23 @@
 			 */
 			token = qtd->hw_token;
 			qtd->hw_token = 0;
+			wmb ();
 			dummy = qh->dummy;
-			// dbg ("swap td %p with dummy %p", qtd, dummy);
 
 			dma = dummy->qtd_dma;
 			*dummy = *qtd;
 			dummy->qtd_dma = dma;
+
 			list_del (&qtd->qtd_list);
 			list_add (&dummy->qtd_list, qtd_list);
+			__list_splice (qtd_list, qh->qtd_list.prev);
 
 			ehci_qtd_init (qtd, qtd->qtd_dma);
+			qtd->hw_alt_next = ehci->async->hw_alt_next;
 			qh->dummy = qtd;
 
 			/* hc must see the new dummy at list end */
+			dma = qtd->qtd_dma;
 			qtd = list_entry (qh->qtd_list.prev,
 					struct ehci_qtd, qtd_list);
 			qtd->hw_next = QTD_NEXT (dma);
@@ -795,37 +818,9 @@
 			wmb ();
 			dummy->hw_token = token;
 
-		/* no URB queued */
-		} else {
-			struct ehci_qtd		*last_qtd;
-
-			/* make sure hc sees current dummy at the end */
-			last_qtd = list_entry (qtd_list->prev,
-					struct ehci_qtd, qtd_list);
-			last_qtd->hw_next = QTD_NEXT (qh->dummy->qtd_dma);
-
-			// dbg_qh ("empty qh", ehci, qh);
-
-			/* usb_clear_halt() means qh data toggle gets reset */
-			if (unlikely (!usb_gettoggle (urb->dev,
-						(epnum & 0x0f),
-						!(epnum & 0x10)))) {
-				clear_toggle (urb->dev,
-					epnum & 0x0f, !(epnum & 0x10), qh);
-			}
-			if (qtd)
-				qh_update (qh, qtd);
+			urb->hcpriv = qh_get (qh);
 		}
-		list_splice (qtd_list, qh->qtd_list.prev);
-
-	} else {
-		/* can't sleep here, we have ehci->lock... */
-		qh = ehci_qh_make (ehci, urb, qtd_list, SLAB_ATOMIC);
-		// if (qh) dbg_qh ("new qh", ehci, qh);
-		*ptr = qh;
 	}
-	if (qh)
-		urb->hcpriv = qh_get (qh);
 	return qh;
 }
 
@@ -877,34 +872,38 @@
 /*-------------------------------------------------------------------------*/
 
 /* the async qh for the qtds being reclaimed are now unlinked from the HC */
-/* caller must not own ehci->lock */
 
-static void end_unlink_async (struct ehci_hcd *ehci)
+static void end_unlink_async (struct ehci_hcd *ehci, struct pt_regs *regs)
 {
 	struct ehci_qh		*qh = ehci->reclaim;
 
 	del_timer (&ehci->watchdog);
 
+	qh->hw_next = cpu_to_le32 (qh->qh_dma);
 	qh->qh_state = QH_STATE_IDLE;
 	qh->qh_next.qh = 0;
 	qh_put (ehci, qh);			// refcount from reclaim 
 	ehci->reclaim = 0;
 	ehci->reclaim_ready = 0;
 
-	qh_completions (ehci, qh);
+	qh_completions (ehci, qh, regs);
 
 	if (!list_empty (&qh->qtd_list)
 			&& HCD_IS_RUNNING (ehci->hcd.state))
 		qh_link_async (ehci, qh);
-	else
+	else {
 		qh_put (ehci, qh);		// refcount from async list
 
-	/* it's not free to turn the async schedule on/off, so we leave it
-	 * active but idle for a while once it empties.
-	 */
-	if (!ehci->async->qh_next.qh && !timer_pending (&ehci->watchdog)) {
-		ehci->async_idle = 1;
-		mod_timer (&ehci->watchdog, jiffies + EHCI_ASYNC_JIFFIES);
+		/* it's not free to turn the async schedule on/off; leave it
+		 * active but idle for a while once it empties.
+		 */
+		if (HCD_IS_RUNNING (ehci->hcd.state)
+				&& ehci->async->qh_next.qh == 0
+				&& !timer_pending (&ehci->watchdog)) {
+			ehci->async_idle = 1;
+			mod_timer (&ehci->watchdog,
+					jiffies + EHCI_ASYNC_JIFFIES);
+		}
 	}
 }
 
@@ -941,12 +940,6 @@
 	qh->qh_state = QH_STATE_UNLINK;
 	ehci->reclaim = qh = qh_get (qh);
 
-	if (unlikely (ehci->hcd.state == USB_STATE_HALT)) {
-		ehci->reclaim_ready = 1;
-		tasklet_schedule (&ehci->tasklet);
-		return;
-	}
-
 	prev = ehci->async;
 	while (prev->qh_next.qh != qh)
 		prev = prev->qh_next.qh;
@@ -955,6 +948,11 @@
 	prev->qh_next = qh->qh_next;
 	wmb ();
 
+	if (unlikely (ehci->hcd.state == USB_STATE_HALT)) {
+		end_unlink_async (ehci, NULL);
+		return;
+	}
+
 	ehci->reclaim_ready = 0;
 	cmd |= CMD_IAAD;
 	writel (cmd, &ehci->regs->command);
@@ -966,7 +964,7 @@
 /*-------------------------------------------------------------------------*/
 
 static void
-scan_async (struct ehci_hcd *ehci)
+scan_async (struct ehci_hcd *ehci, struct pt_regs *regs)
 {
 	struct ehci_qh		*qh;
 	unsigned		count;
@@ -984,7 +982,7 @@
 				 * reporting drops the lock.
 				 */
 				qh = qh_get (qh);
-				temp = qh_completions (ehci, qh);
+				temp = qh_completions (ehci, qh, regs);
 				qh_put (ehci, qh);
 				if (temp != 0) {
 					count += temp;
@@ -1000,14 +998,6 @@
 			 */
 			if (list_empty (&qh->qtd_list) && !ehci->reclaim) {
 				start_unlink_async (ehci, qh);
-			}
-
-			/* keep latencies down: let any irqs in */
-			if (count > max_completions) {
-				spin_unlock_irq (&ehci->lock);
-				cpu_relax ();
-				spin_lock_irq (&ehci->lock);
-				goto rescan;
 			}
 
 			qh = qh->qh_next.qh;
diff -Nru a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
--- a/drivers/usb/host/ehci-sched.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/usb/host/ehci-sched.c	Mon Dec 23 21:21:53 2002
@@ -190,7 +190,7 @@
 	/* posted write ... PSS happens later */
 	ehci->hcd.state = USB_STATE_RUNNING;
 
-	/* make sure tasklet scans these */
+	/* make sure ehci_work scans these */
 	ehci->next_uframe = readl (&ehci->regs->frame_index)
 				% (ehci->periodic_size << 3);
 	return 0;
@@ -495,7 +495,8 @@
 intr_complete (
 	struct ehci_hcd	*ehci,
 	unsigned	frame,
-	struct ehci_qh	*qh
+	struct ehci_qh	*qh,
+	struct pt_regs	*regs
 ) {
 	unsigned	count;
 
@@ -509,7 +510,7 @@
 	}
 	
 	/* handle any completions */
-	count = qh_completions (ehci, qh);
+	count = qh_completions (ehci, qh, regs);
 
 	if (unlikely (list_empty (&qh->qtd_list)))
 		intr_deschedule (ehci, qh, 0);
@@ -867,7 +868,8 @@
 itd_complete (
 	struct ehci_hcd	*ehci,
 	struct ehci_itd	*itd,
-	unsigned	uframe
+	unsigned	uframe,
+	struct pt_regs	*regs
 ) {
 	struct urb				*urb = itd->urb;
 	struct usb_iso_packet_descriptor	*desc;
@@ -922,7 +924,7 @@
 
 	/* complete() can reenter this HCD */
 	spin_unlock (&ehci->lock);
-	usb_hcd_giveback_urb (&ehci->hcd, urb, NULL);
+	usb_hcd_giveback_urb (&ehci->hcd, urb, regs);
 	spin_lock (&ehci->lock);
 
 	/* defer stopping schedule; completion can submit */
@@ -973,7 +975,7 @@
 /*-------------------------------------------------------------------------*/
 
 static void
-scan_periodic (struct ehci_hcd *ehci)
+scan_periodic (struct ehci_hcd *ehci, struct pt_regs *regs)
 {
 	unsigned	frame, clock, now_uframe, mod;
 	unsigned	count = 0;
@@ -999,14 +1001,6 @@
 		u32			type, *hw_p;
 		unsigned		uframes;
 
-		/* keep latencies down: let any irqs in */
-		if (count > max_completions) {
-			spin_unlock_irq (&ehci->lock);
-			cpu_relax ();
-			count = 0;
-			spin_lock_irq (&ehci->lock);
-		}
-
 restart:
 		/* scan schedule to _before_ current frame index */
 		if (frame == clock)
@@ -1031,7 +1025,7 @@
 				temp = q.qh->qh_next;
 				type = Q_NEXT_TYPE (q.qh->hw_next);
 				count += intr_complete (ehci, frame,
-						qh_get (q.qh));
+						qh_get (q.qh), regs);
 				qh_put (ehci, q.qh);
 				q = temp;
 				break;
@@ -1064,7 +1058,7 @@
 
 						/* might free q.itd ... */
 						count += itd_complete (ehci,
-							temp.itd, uf);
+							temp.itd, uf, regs);
 						break;
 					}
 				}
diff -Nru a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
--- a/drivers/usb/host/ehci.h	Mon Dec 23 21:21:59 2002
+++ b/drivers/usb/host/ehci.h	Mon Dec 23 21:21:59 2002
@@ -65,9 +65,6 @@
 	int			next_uframe;	/* scan periodic, start here */
 	unsigned		periodic_sched;	/* periodic activity count */
 
-	/* deferred work from IRQ, etc */
-	struct tasklet_struct	tasklet;
-
 	/* per root hub port */
 	unsigned long		reset_done [EHCI_MAX_ROOT_PORTS];
 
diff -Nru a/drivers/usb/image/scanner.c b/drivers/usb/image/scanner.c
--- a/drivers/usb/image/scanner.c	Mon Dec 23 21:21:52 2002
+++ b/drivers/usb/image/scanner.c	Mon Dec 23 21:21:52 2002
@@ -1,7 +1,7 @@
 /* -*- linux-c -*- */
 
 /* 
- * Driver for USB Scanners (linux-2.4.18)
+ * Driver for USB Scanners (linux-2.5.52)
  *
  * Copyright (C) 1999, 2000, 2001, 2002 David E. Nelson
  *
@@ -313,6 +313,19 @@
  *    - Changed maintainership from David E. Nelson to Brian
  *      Beattie <beattie@beattie-home.net>.
  *
+ * 0.4.9  12/19/2002
+ *    - Added vendor/product ids for Nikon, Mustek, Plustek, Genius, Epson,
+ *      Canon, Umax, Hewlett-Packard, Benq, Agfa, Minolta scanners.
+ *      Thanks to Dieter Faulbaum <faulbaum@mail.bessy.de>, Stian Jordet
+ *      <liste@jordet.nu>, "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>,
+ *      "Jaeger, Gerhard" <gerhard@gjaeger.de>, Ira Childress 
+ *      <ichildress@mn.rr.com>, Till Kamppeter <till.kamppeter@gmx.net>,
+ *      Ed Hamrick <EdHamrick@aol.com>, Oliver Schwartz
+ *	<Oliver.Schwartz@gmx.de> and everyone else who sent ids.
+ *    - Some Benq, Genius and Plustek ids are identified now.
+ *    - Accept scanners with only one bulk (in) endpoint (thanks to Sergey
+ *      Vlasov <vsu@mivlgu.murom.ru>).
+ *
  * TODO
  *    - Remove the 2/3 endpoint limitation
  *    - Performance
@@ -502,6 +515,12 @@
 
 	down(&(scn->sem));
 
+	if (!scn->bulk_out_ep) {
+		/* This scanner does not have a bulk-out endpoint */
+		up(&(scn->sem));
+		return -EINVAL;
+	}
+
 	scn_minor = scn->scn_minor;
 
 	obuf = scn->obuf;
@@ -896,15 +915,15 @@
 	interface = intf->altsetting;
 
 /*
- * Start checking for two bulk endpoints OR two bulk endpoints *and* one
+ * Start checking for one or two bulk endpoints and an optional
  * interrupt endpoint. If we have an interrupt endpoint go ahead and
  * setup the handler. FIXME: This is a future enhancement...
  */
 
 	dbg("probe_scanner: Number of Endpoints:%d", (int) interface->desc.bNumEndpoints);
 
-	if ((interface->desc.bNumEndpoints != 2) && (interface->desc.bNumEndpoints != 3)) {
-		info("probe_scanner: Only two or three endpoints supported.");
+	if ((interface->desc.bNumEndpoints < 1) || (interface->desc.bNumEndpoints > 3)) {
+		info("probe_scanner: Only 1, 2, or 3 endpoints supported.");
 		return -ENODEV;
 	}
 
@@ -944,6 +963,12 @@
  */
 
 	switch(interface->desc.bNumEndpoints) {
+	case 1:
+		if (!have_bulk_in) {
+			info("probe_scanner: One bulk-in endpoint required.");
+			return -EIO;
+		}
+		break;
 	case 2:
 		if (!have_bulk_in || !have_bulk_out) {
 			info("probe_scanner: Two bulk endpoints required.");
diff -Nru a/drivers/usb/image/scanner.h b/drivers/usb/image/scanner.h
--- a/drivers/usb/image/scanner.h	Mon Dec 23 21:21:53 2002
+++ b/drivers/usb/image/scanner.h	Mon Dec 23 21:21:53 2002
@@ -1,5 +1,5 @@
 /*
- * Driver for USB Scanners (linux-2.4.18)
+ * Driver for USB Scanners (linux-2.5.52)
  *
  * Copyright (C) 1999, 2000, 2001, 2002 David E. Nelson
  *
@@ -44,7 +44,7 @@
  */
 // #define PV8630 
 
-#define DRIVER_VERSION "0.4.6"
+#define DRIVER_VERSION "0.4.9"
 #define DRIVER_DESC "USB Scanner Driver"
 
 #include <linux/usb.h>
@@ -70,19 +70,19 @@
 // #define WR_DATA_DUMP /* DEBUG does not have to be defined. */
 
 static struct usb_device_id scanner_device_ids [] = {
-	/* Acer */
-	{ USB_DEVICE(0x04a5, 0x2060) },	/* Prisa Acerscan 620U & 640U (!)*/
-	{ USB_DEVICE(0x04a5, 0x2040) },	/* Prisa AcerScan 620U (!) */
-	{ USB_DEVICE(0x04a5, 0x20c0) },  /* Prisa AcerScan 1240UT */
-	{ USB_DEVICE(0x04a5, 0x2022) },	/* Vuego Scan Brisa 340U */
+	/* Acer (now Benq) */
+	{ USB_DEVICE(0x04a5, 0x2060) },	/* 620U & 640U (!)*/
+	{ USB_DEVICE(0x04a5, 0x2040) },	/* 620U (!) */
+	{ USB_DEVICE(0x04a5, 0x20c0) }, /* 1240UT, 1240U */
+	{ USB_DEVICE(0x04a5, 0x2022) },	/* 340U */
 	{ USB_DEVICE(0x04a5, 0x1a20) },	/* Unknown - Oliver Schwartz */
-	{ USB_DEVICE(0x04a5, 0x1a2a) },	/* Unknown - Oliver Schwartz */
-	{ USB_DEVICE(0x04a5, 0x207e) },	/* Prisa 640BU */
+	{ USB_DEVICE(0x04a5, 0x1a2a) },	/* Another 620U */
+	{ USB_DEVICE(0x04a5, 0x207e) },	/* 640BU */
 	{ USB_DEVICE(0x04a5, 0x20be) },	/* Unknown - Oliver Schwartz */
-	{ USB_DEVICE(0x04a5, 0x20c0) },	/* Unknown - Oliver Schwartz */
 	{ USB_DEVICE(0x04a5, 0x20de) },	/* S2W 3300U */
-	{ USB_DEVICE(0x04a5, 0x20b0) },	/* Unknown - Oliver Schwartz */
-	{ USB_DEVICE(0x04a5, 0x20fe) },	/* Unknown - Oliver Schwartz */
+	{ USB_DEVICE(0x04a5, 0x20b0) },	/* Benq 4300 */
+	{ USB_DEVICE(0x04a5, 0x20fe) },	/* Benq 5300 */
+	{ USB_DEVICE(0x04a5, 0x20fc) }, /* Benq 5000 */
 	/* Agfa */
 	{ USB_DEVICE(0x06bd, 0x0001) },	/* SnapScan 1212U */
 	{ USB_DEVICE(0x06bd, 0x0002) },	/* SnapScan 1236U */
@@ -92,24 +92,37 @@
 	{ USB_DEVICE(0x06bd, 0x2095) }, /* SnapScan e25 */
 	{ USB_DEVICE(0x06bd, 0x2097) }, /* SnapScan e26 */
 	{ USB_DEVICE(0x06bd, 0x208d) }, /* Snapscan e40 */
+	{ USB_DEVICE(0x06bd, 0x2093) }, /* SnapScan e10*/
+	{ USB_DEVICE(0x06bd, 0x20ff) }, /* SnapScan e42*/
+	{ USB_DEVICE(0x06bd, 0x208f) }, /* SnapScan e50*/
+	{ USB_DEVICE(0x06bd, 0x20fd) }, /* SnapScan e52*/
+	/* Benq: see Acer */
 	/* Canon */
+	{ USB_DEVICE(0x04a9, 0x2201) }, /* FB320U */
+	{ USB_DEVICE(0x04a9, 0x2205) }, /* FB1210U */
 	{ USB_DEVICE(0x04a9, 0x2202) }, /* CanoScan FB620U */
 	{ USB_DEVICE(0x04a9, 0x2204) }, /* CanoScan FB630U/FB636U */
 	{ USB_DEVICE(0x04a9, 0x2206) }, /* CanoScan N650U/N656U */
 	{ USB_DEVICE(0x04a9, 0x2207) }, /* CanoScan N1220U */
 	{ USB_DEVICE(0x04a9, 0x2208) }, /* CanoScan D660U */ 
 	{ USB_DEVICE(0x04a9, 0x220b) }, /* D646U */
+	{ USB_DEVICE(0x04a9, 0x220d) }, /* CanoScan N670U/N676U/LIDE 20 */
+	{ USB_DEVICE(0x04a9, 0x220e) }, /* CanoScan N1240U/LIDE 30 */
+	{ USB_DEVICE(0x04a9, 0x3042) }, /* FS4000US */
 	/* Colorado -- See Primax/Colorado below */
 	/* Epson -- See Seiko/Epson below */
 	/* Genius */
 	{ USB_DEVICE(0x0458, 0x2001) },	/* ColorPage-Vivid Pro */
 	{ USB_DEVICE(0x0458, 0x2007) },	/* ColorPage HR6 V2 */
-	{ USB_DEVICE(0x0458, 0x2008) },	/* Unknown */
-	{ USB_DEVICE(0x0458, 0x2009) },	/* Unknown */
-	{ USB_DEVICE(0x0458, 0x2013) },	/* Unknown */
-	{ USB_DEVICE(0x0458, 0x2015) },	/* Unknown  */
-	{ USB_DEVICE(0x0458, 0x2016) },	/* Unknown  */
+	{ USB_DEVICE(0x0458, 0x2008) }, /* ColorPage-HR6 V2 */
+	{ USB_DEVICE(0x0458, 0x2009) }, /* ColorPage-HR6A */
+	{ USB_DEVICE(0x0458, 0x2011) }, /* ColorPage-Vivid3x */
+	{ USB_DEVICE(0x0458, 0x2013) }, /* ColorPage-HR7 */
+	{ USB_DEVICE(0x0458, 0x2015) }, /* ColorPage-HR7LE */
+	{ USB_DEVICE(0x0458, 0x2016) }, /* ColorPage-HR6X */
 	/* Hewlett Packard */
+	{ USB_DEVICE(0x03f0, 0x0505) }, /* ScanJet 2100C */
+	{ USB_DEVICE(0x03f0, 0x0901) }, /* 2300C */
 	{ USB_DEVICE(0x03f0, 0x0205) },	/* 3300C */
 	{ USB_DEVICE(0x03f0, 0x0405) }, /* 3400C */
 	{ USB_DEVICE(0x03f0, 0x0101) },	/* 4100C */
@@ -124,6 +137,8 @@
 	{ USB_DEVICE(0x03f0, 0x605) },	/* 2200C */
 	/* iVina */
 	{ USB_DEVICE(0x0638, 0x0268) }, /* 1200U */
+	/* Lexmark */
+	{ USB_DEVICE(0x043d, 0x002d) }, /* X70/X73 */
 	/* Lifetec */
 	{ USB_DEVICE(0x05d8, 0x4002) }, /* Lifetec LT9385 */
 	/* Memorex */
@@ -138,31 +153,44 @@
 	//	{ USB_DEVICE(0x05da, 0x80ac) },	/* ScanMaker V6UL - SpicyU */
 	/* Minolta */
 	//	{ USB_DEVICE(0x0638,0x026a) }, /* Minolta Dimage Scan Dual II */
+	//	{ USB_DEVICE(0x0686, 0x4004) }, /* Scan Elite II (need interrupt ep) */
+	{ USB_DEVICE(0x0686, 0x400d) }, /* Scan Dual III */
 	/* Mustek */
-	{ USB_DEVICE(0x055f, 0x0001) },	/* 1200 CU */
+	{ USB_DEVICE(0x055f, 0x0001) },	/* ScanExpress 1200 CU */
 	{ USB_DEVICE(0x0400, 0x1000) },	/* BearPaw 1200 */
-	{ USB_DEVICE(0x055f, 0x0002) },	/* 600 CU */
-	{ USB_DEVICE(0x055f, 0x0873) }, /* 600 USB */
-	{ USB_DEVICE(0x055f, 0x0003) },	/* 1200 USB */
-	{ USB_DEVICE(0x055f, 0x0006) },	/* 1200 UB */
+	{ USB_DEVICE(0x055f, 0x0002) },	/* ScanExpress 600 CU */
+	{ USB_DEVICE(0x055f, 0x0873) }, /* ScanExpress 600 USB */
+	{ USB_DEVICE(0x055f, 0x0003) },	/* ScanExpress 1200 USB */
+	{ USB_DEVICE(0x055f, 0x0006) },	/* ScanExpress 1200 UB */
+	{ USB_DEVICE(0x055f, 0x0007) },	/* ScanExpress 1200 USB Plus */
+	{ USB_DEVICE(0x055f, 0x0210) },	/* ScanExpress A3 USB */
 	{ USB_DEVICE(0x0400, 0x1001) }, /* BearPaw 2400 */
-	{ USB_DEVICE(0x055f, 0x0008) }, /* 1200 CU Plus */
-	{ USB_DEVICE(0x0ff5, 0x0010) }, /* BearPaw 1200F */
+	{ USB_DEVICE(0x055f, 0x0008) }, /* ScanExpress 1200 CU Plus */
+	{ USB_DEVICE(0x055f, 0x0010) }, /* BearPaw 1200F */
 	{ USB_DEVICE(0x055f, 0x0218) }, /* BearPaw 2400 TA */
-	{ USB_DEVICE(0x05d8, 0x4002) }, /* 1200 CU and 1200 UB Plus */
+	{ USB_DEVICE(0x05d8, 0x4002) }, /* BearPaw 1200 CU and ScanExpress 1200 UB Plus */
+	{ USB_DEVICE(0x055f, 0x0219) }, /* BearPaw 2400 TA Plus */
+	{ USB_DEVICE(0x055f, 0x021c) }, /* BearPaw 1200 CU Plus */
+	{ USB_DEVICE(0x055f, 0x021d) }, /* Bearpaw 2400 CU Plus */
+	{ USB_DEVICE(0x055f, 0x021e) }, /* BearPaw 1200 TA/CS */
+	{ USB_DEVICE(0x055f, 0x0400) }, /* BearPaw 2400 TA PRO */
+	{ USB_DEVICE(0x055f, 0x1000) }, /* BearPaw 4800 TA PRO */
+	/* Nikon */
+	{ USB_DEVICE(0x04b0, 0x4000) }, /* Coolscan LS 40 ED */
 	/* Plustek */
-	{ USB_DEVICE(0x07b3, 0x0017) }, /* OpticPro UT12 */
-	{ USB_DEVICE(0x07b3, 0x0011) }, /* OpticPro UT24 */
+	{ USB_DEVICE(0x07b3, 0x0017) }, /* OpticPro UT12/UT16/UT24 */
+	{ USB_DEVICE(0x07b3, 0x0011) }, /* OpticPro U24 */
+	{ USB_DEVICE(0x07b3, 0x0010) }, /* OpticPro U12 */
+	{ USB_DEVICE(0x07b3, 0x0015) }, /* OpticPro U24 */
 	{ USB_DEVICE(0x07b3, 0x0005) }, /* Unknown */
 	{ USB_DEVICE(0x07b3, 0x0007) }, /* Unknown */
 	{ USB_DEVICE(0x07b3, 0x000F) }, /* Unknown */
-	{ USB_DEVICE(0x07b3, 0x0010) }, /* Unknown */
 	{ USB_DEVICE(0x07b3, 0x0012) }, /* Unknown */
 	{ USB_DEVICE(0x07b3, 0x0013) }, /* Unknown */
 	{ USB_DEVICE(0x07b3, 0x0014) }, /* Unknown */
-	{ USB_DEVICE(0x07b3, 0x0015) }, /* Unknown */
 	{ USB_DEVICE(0x07b3, 0x0016) }, /* Unknown */
 	{ USB_DEVICE(0x07b3, 0x0012) }, /* Unknown */
+	{ USB_DEVICE(0x07b3, 0x0401) }, /* OpticPro 1248U */
 	/* Primax/Colorado */
 	{ USB_DEVICE(0x0461, 0x0300) },	/* G2-300 #1 */
 	{ USB_DEVICE(0x0461, 0x0380) },	/* G2-600 #1 */
@@ -180,24 +208,32 @@
 	// { USB_DEVICE(0x0475, 0x0103) },	/* Episode - undetected endpoint */
 	/* Seiko/Epson Corp. */
 	{ USB_DEVICE(0x04b8, 0x0101) },	/* Perfection 636U and 636Photo */
+	{ USB_DEVICE(0x04b8, 0x0102) }, /* GT-2200 */
 	{ USB_DEVICE(0x04b8, 0x0103) },	/* Perfection 610 */
 	{ USB_DEVICE(0x04b8, 0x0104) },	/* Perfection 1200U and 1200Photo*/
+	{ USB_DEVICE(0x04b8, 0x0105) }, /* StylusScan 2000 */
 	{ USB_DEVICE(0x04b8, 0x0106) },	/* Stylus Scan 2500 */
 	{ USB_DEVICE(0x04b8, 0x0107) },	/* Expression 1600 */
+	{ USB_DEVICE(0x04b8, 0x0109) }, /* Expression 1640XL */
 	{ USB_DEVICE(0x04b8, 0x010a) }, /* Perfection 1640SU and 1640SU Photo */
 	{ USB_DEVICE(0x04b8, 0x010b) }, /* Perfection 1240U */
 	{ USB_DEVICE(0x04b8, 0x010c) }, /* Perfection 640U */
 	{ USB_DEVICE(0x04b8, 0x010e) }, /* Expression 1680 */
-	{ USB_DEVICE(0x04a9, 0x2204) }, /* FB630U */
+	{ USB_DEVICE(0x04b8, 0x010f) }, /* Perfection 1250U */
 	{ USB_DEVICE(0x04b8, 0x0110) }, /* Perfection 1650 */
 	{ USB_DEVICE(0x04b8, 0x0112) }, /* Perfection 2450 - GT-9700 for the Japanese mkt */
 	{ USB_DEVICE(0x04b8, 0x0114) }, /* Perfection 660 */
 	{ USB_DEVICE(0x04b8, 0x011b) }, /* Perfection 2400 Photo */
+	{ USB_DEVICE(0x04b8, 0x011c) }, /* Perfection 3200 */
+	{ USB_DEVICE(0x04b8, 0x011d) }, /* Perfection 1260 */
 	{ USB_DEVICE(0x04b8, 0x011e) }, /* Perfection 1660 Photo */
+	{ USB_DEVICE(0x04b8, 0x0802) }, /* Stylus CX3200 */
 	/* Umax */
 	{ USB_DEVICE(0x1606, 0x0010) },	/* Astra 1220U */
 	{ USB_DEVICE(0x1606, 0x0030) },	/* Astra 2000U */
+	{ USB_DEVICE(0x1606, 0x0060) }, /* Astra 3400U/3450U */
 	{ USB_DEVICE(0x1606, 0x0130) }, /* Astra 2100U */
+	{ USB_DEVICE(0x1606, 0x0160) }, /* Astra 5400U */
 	{ USB_DEVICE(0x1606, 0x0230) },	/* Astra 2200U */
 	/* Visioneer */
 	{ USB_DEVICE(0x04a7, 0x0221) },	/* OneTouch 5300 USB */
diff -Nru a/drivers/usb/media/ibmcam.c b/drivers/usb/media/ibmcam.c
--- a/drivers/usb/media/ibmcam.c	Mon Dec 23 21:21:52 2002
+++ b/drivers/usb/media/ibmcam.c	Mon Dec 23 21:21:52 2002
@@ -87,11 +87,11 @@
 } ibmcam_t;
 #define	IBMCAM_T(uvd)	((ibmcam_t *)((uvd)->user_data))
 
-usbvideo_t *cams = NULL;
+static struct usbvideo *cams;
 
-static int debug = 0;
+static int debug;
 
-static int flags = 0; /* FLAGS_DISPLAY_HINTS | FLAGS_OVERLAY_STATS; */
+static int flags; /* = FLAGS_DISPLAY_HINTS | FLAGS_OVERLAY_STATS; */
 
 static const int min_canvasWidth  = 8;
 static const int min_canvasHeight = 4;
@@ -249,7 +249,7 @@
  * History:
  * 1/21/00  Created.
  */
-static ParseState_t ibmcam_find_header(struct uvd *uvd) /* FIXME: Add frame here */
+static enum ParseState ibmcam_find_header(struct uvd *uvd) /* FIXME: Add frame here */
 {
 	struct usbvideo_frame *frame;
 	ibmcam_t *icam;
@@ -397,7 +397,7 @@
  * 21-Jan-2000 Created.
  * 12-Oct-2000 Reworked to reflect interlaced nature of the data.
  */
-static ParseState_t ibmcam_parse_lines(
+static enum ParseState ibmcam_parse_lines(
 	struct uvd *uvd,
 	struct usbvideo_frame *frame,
 	long *pcopylen)
@@ -662,7 +662,7 @@
  * them both as R component in attempt to at least partially recover the
  * lost resolution.
  */
-static ParseState_t ibmcam_model2_320x240_parse_lines(
+static enum ParseState ibmcam_model2_320x240_parse_lines(
 	struct uvd *uvd,
 	struct usbvideo_frame *frame,
 	long *pcopylen)
@@ -816,7 +816,7 @@
 		return scan_Continue;
 }
 
-static ParseState_t ibmcam_model3_parse_lines(
+static enum ParseState ibmcam_model3_parse_lines(
 	struct uvd *uvd,
 	struct usbvideo_frame *frame,
 	long *pcopylen)
@@ -961,7 +961,7 @@
  * History:
  * 10-Feb-2001 Created.
  */
-static ParseState_t ibmcam_model4_128x96_parse_lines(
+static enum ParseState ibmcam_model4_128x96_parse_lines(
 	struct uvd *uvd,
 	struct usbvideo_frame *frame,
 	long *pcopylen)
@@ -1051,7 +1051,7 @@
  */
 void ibmcam_ProcessIsocData(struct uvd *uvd, struct usbvideo_frame *frame)
 {
-	ParseState_t newstate;
+	enum ParseState newstate;
 	long copylen = 0;
 	int mod = IBMCAM_T(uvd)->camera_model;
 
diff -Nru a/drivers/usb/media/konicawc.c b/drivers/usb/media/konicawc.c
--- a/drivers/usb/media/konicawc.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/usb/media/konicawc.c	Mon Dec 23 21:21:50 2002
@@ -51,7 +51,7 @@
 
 #define MAX_FRAME_SIZE	SIZE_320X240
 
-static usbvideo_t *cams;
+static struct usbvideo *cams;
 
 #ifdef CONFIG_USB_DEBUG
 static int debug;
diff -Nru a/drivers/usb/media/pwc-ctrl.c b/drivers/usb/media/pwc-ctrl.c
--- a/drivers/usb/media/pwc-ctrl.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/usb/media/pwc-ctrl.c	Mon Dec 23 21:22:00 2002
@@ -446,8 +446,8 @@
 			Info("Video mode %s@%d fps is only supported with the decompressor module (pwcx).\n", size2name[size], frames);
 		else {
 			Err("Failed to set video mode %s@%d fps; return code = %d\n", size2name[size], frames, ret);
-			return ret;
 		}
+		return ret;
 	}
 	pdev->view.x = width;
 	pdev->view.y = height;
@@ -1534,7 +1534,15 @@
 		*dynnoise = ret;
 		break;
 	}
-	
+
+	case VIDIOCPWCGREALSIZE:
+	{
+		struct pwc_imagesize *size = arg;
+		
+		size->width = pdev->image.x;
+		size->height = pdev->image.y;
+		break;
+	}	
 
 	default:
 		ret = -ENOIOCTLCMD;
diff -Nru a/drivers/usb/media/pwc-if.c b/drivers/usb/media/pwc-if.c
--- a/drivers/usb/media/pwc-if.c	Mon Dec 23 21:21:59 2002
+++ b/drivers/usb/media/pwc-if.c	Mon Dec 23 21:21:59 2002
@@ -77,7 +77,7 @@
 	{ USB_DEVICE(0x0471, 0x0312) },
 	{ USB_DEVICE(0x069A, 0x0001) }, /* Askey */
 	{ USB_DEVICE(0x046D, 0x08b0) }, /* Logitech QuickCam Pro 3000 */
-	{ USB_DEVICE(0x046D, 0x08b1) }, /* Logitech QuickCam for Notebooks */
+	{ USB_DEVICE(0x046D, 0x08b1) }, /* Logitech QuickCam Notebook Pro */
 	{ USB_DEVICE(0x046D, 0x08b2) }, /* Logitech QuickCam Pro 4000 */
 	{ USB_DEVICE(0x046D, 0x08b3) }, /* Logitech QuickCam Zoom */
 	{ USB_DEVICE(0x055D, 0x9000) }, /* Samsung */
@@ -992,7 +992,7 @@
 			case 0x40:  sensor_type = "UPA 1021 sensor"; break;
 			case 0x100: sensor_type = "VGA sensor"; break;
 			case 0x101: sensor_type = "PAL MR sensor"; break;
-			default:   sensor_type = "unknown type of sensor"; break;
+			default:    sensor_type = "unknown type of sensor"; break;
 			}
 			if (sensor_type != NULL)
 				Info("This %s camera is equipped with a %s (%d).\n", pdev->vdev->name, sensor_type, i);
@@ -1064,7 +1064,6 @@
 	i = pwc_isoc_init(pdev);
 	if (i) {
 		Trace(TRACE_OPEN, "Failed to init ISOC stuff = %d.\n", i);
-		MOD_DEC_USE_COUNT;
 		up(&pdev->modlock);
 		return i;
 	}
@@ -1689,8 +1688,8 @@
 			type_id = 730;
 			break;
 		case 0x08b1:
-			Info("Logitech QuickCam for Noteboos USB webcam detected.\n");
-			name = "Logitech QuickCam Notebook";
+			Info("Logitech QuickCam Notebook Pro USB webcam detected.\n");
+			name = "Logitech QuickCam Notebook Pro";
 			type_id = 740; /* ?? unknown sensor */
 			break;
 		case 0x08b2:
diff -Nru a/drivers/usb/media/pwc-ioctl.h b/drivers/usb/media/pwc-ioctl.h
--- a/drivers/usb/media/pwc-ioctl.h	Mon Dec 23 21:21:54 2002
+++ b/drivers/usb/media/pwc-ioctl.h	Mon Dec 23 21:21:54 2002
@@ -18,12 +18,13 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
-/*         This is pwc-ioctl.h belonging to PWC 8.7                        */
+/*         This is pwc-ioctl.h belonging to PWC 8.10                        */
 
 /* 
    Changes
    2001/08/03  Alvarado   Added ioctl constants to access methods for 
                           changing white balance and red/blue gains
+   2002/12/15  G. H. Fernandez-Toribio   VIDIOCGREALSIZE
  */
 
 /* These are private ioctl() commands, specific for the Philips webcams.
@@ -104,7 +105,12 @@
 	int led_off;			/* Led off-time; range = 0..25000  */
 };
 
-
+/* Image size (used with GREALSIZE) */
+struct pwc_imagesize
+{
+	int width;
+	int height;
+};
 
  /* Restore user settings */
 #define VIDIOCPWCRUSER		_IO('v', 192)
@@ -173,4 +179,7 @@
 #define VIDIOCPWCSDYNNOISE	_IOW('v', 209, int)
 #define VIDIOCPWCGDYNNOISE	_IOR('v', 209, int)
 
+ /* Real image size as used by the camera; tells you whether or not there's a gray border around the image */
+#define VIDIOCPWCGREALSIZE	_IOR('v', 210, struct pwc_imagesize)
+ 
 #endif
diff -Nru a/drivers/usb/media/pwc-uncompress.h b/drivers/usb/media/pwc-uncompress.h
--- a/drivers/usb/media/pwc-uncompress.h	Mon Dec 23 21:21:52 2002
+++ b/drivers/usb/media/pwc-uncompress.h	Mon Dec 23 21:21:52 2002
@@ -20,8 +20,8 @@
    significant change should be reflected by increasing the 
    pwc_decompressor_version major number.
  */
-#ifndef PWC_DEC_H
-#define PWC_DEC_H
+#ifndef PWC_UNCOMPRESS_H
+#define PWC_UNCOMPRESS_H
 
 #include <linux/config.h>
 #include <linux/list.h>
diff -Nru a/drivers/usb/media/pwc.h b/drivers/usb/media/pwc.h
--- a/drivers/usb/media/pwc.h	Mon Dec 23 21:21:57 2002
+++ b/drivers/usb/media/pwc.h	Mon Dec 23 21:21:57 2002
@@ -60,8 +60,8 @@
 
 /* Version block */
 #define PWC_MAJOR	8
-#define PWC_MINOR	9
-#define PWC_VERSION 	"8.9"
+#define PWC_MINOR	10
+#define PWC_VERSION 	"8.10"
 #define PWC_NAME 	"pwc"
 
 /* Turn certain features on/off */
diff -Nru a/drivers/usb/media/stv680.h b/drivers/usb/media/stv680.h
--- a/drivers/usb/media/stv680.h	Mon Dec 23 21:21:59 2002
+++ b/drivers/usb/media/stv680.h	Mon Dec 23 21:21:59 2002
@@ -147,7 +147,7 @@
 };
 
 
-unsigned char red[256] = { 
+static unsigned char red[256] = { 
 	0, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 
 	18, 18, 18, 18, 18, 18, 18, 25, 30, 35, 38, 42, 
 	44, 47, 50, 53, 54, 57, 59, 61, 63, 65, 67, 69, 
@@ -172,7 +172,7 @@
 	220, 220, 221, 221 
 }; 
 
-unsigned char green[256] = {
+static unsigned char green[256] = {
 	0, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 
 	21, 21, 21, 21, 21, 21, 21, 28, 34, 39, 43, 47, 
 	50, 53, 56, 59, 61, 64, 66, 68, 71, 73, 75, 77, 
@@ -197,7 +197,7 @@
 	245, 245, 246, 246 
 }; 
 
-unsigned char blue[256] = {
+static unsigned char blue[256] = {
 	0, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 
 	23, 23, 23, 23, 23, 23, 23, 30, 37, 42, 47, 51, 
 	55, 58, 61, 64, 67, 70, 72, 74, 78, 80, 82, 84, 
diff -Nru a/drivers/usb/media/ultracam.c b/drivers/usb/media/ultracam.c
--- a/drivers/usb/media/ultracam.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/usb/media/ultracam.c	Mon Dec 23 21:21:51 2002
@@ -25,7 +25,7 @@
 } ultracam_t;
 #define	ULTRACAM_T(uvd)	((ultracam_t *)((uvd)->user_data))
 
-static usbvideo_t *cams = NULL;
+static struct usbvideo *cams = NULL;
 
 static int debug = 0;
 
diff -Nru a/drivers/usb/media/usbvideo.c b/drivers/usb/media/usbvideo.c
--- a/drivers/usb/media/usbvideo.c	Mon Dec 23 21:22:02 2002
+++ b/drivers/usb/media/usbvideo.c	Mon Dec 23 21:22:02 2002
@@ -42,8 +42,8 @@
  * Local prototypes.
  */
 #if USES_PROC_FS
-static void usbvideo_procfs_level1_create(usbvideo_t *ut);
-static void usbvideo_procfs_level1_destroy(usbvideo_t *ut);
+static void usbvideo_procfs_level1_create(struct usbvideo *ut);
+static void usbvideo_procfs_level1_destroy(struct usbvideo *ut);
 static void usbvideo_procfs_level2_create(struct uvd *uvd);
 static void usbvideo_procfs_level2_destroy(struct uvd *uvd);
 static int usbvideo_default_procfs_read_proc(
@@ -765,7 +765,7 @@
 }
 
 int usbvideo_register(
-	usbvideo_t **pCams,
+	struct usbvideo **pCams,
 	const int num_cams,
 	const int num_extra,
 	const char *driverName,
@@ -773,7 +773,7 @@
 	struct module *md,
 	const struct usb_device_id *id_table)
 {
-	usbvideo_t *cams;
+	struct usbvideo *cams;
 	int i, base_size;
 
 	/* Check parameters for sanity */
@@ -788,10 +788,10 @@
 		return -EINVAL;
 	}
 
-	base_size = num_cams * sizeof(struct uvd) + sizeof(usbvideo_t);
-	cams = (usbvideo_t *) kmalloc(base_size, GFP_KERNEL);
+	base_size = num_cams * sizeof(struct uvd) + sizeof(struct usbvideo);
+	cams = (struct usbvideo *) kmalloc(base_size, GFP_KERNEL);
 	if (cams == NULL) {
-		err("Failed to allocate %d. bytes for usbvideo_t", base_size);
+		err("Failed to allocate %d. bytes for usbvideo struct", base_size);
 		return -ENOMEM;
 	}
 	dbg("%s: Allocated $%p (%d. bytes) for %d. cameras",
@@ -823,7 +823,7 @@
 #else /* !USES_PROC_FS */
 	/* Report a warning so that user knows why there is no /proc entries */
 	if ((cams->cb.procfs_read != NULL) || (cams->cb.procfs_write == NULL)) {
-		dbg("%s: /proc fs support requested but not configured!", proc);
+		dbg("%s: /proc fs support requested but not configured!", __FUNCTION__);
 	}
 #endif
 	cams->num_cameras = num_cams;
@@ -889,9 +889,9 @@
  * if you had some dynamically allocated components in ->user field then
  * you should free them before calling here.
  */
-void usbvideo_Deregister(usbvideo_t **pCams)
+void usbvideo_Deregister(struct usbvideo **pCams)
 {
-	usbvideo_t *cams;
+	struct usbvideo *cams;
 	int i;
 
 	if (pCams == NULL) {
@@ -1049,12 +1049,12 @@
  * History:
  * 27-Jan-2000 Created.
  */
-static int usbvideo_find_struct(usbvideo_t *cams)
+static int usbvideo_find_struct(struct usbvideo *cams)
 {
 	int u, rv = -1;
 
 	if (cams == NULL) {
-		err("No usbvideo_t handle?");
+		err("No usbvideo handle?");
 		return -1;
 	}
 	down(&cams->lock);
@@ -1089,13 +1089,13 @@
 	.fops =       &usbvideo_fops,
 };
 
-struct uvd *usbvideo_AllocateDevice(usbvideo_t *cams)
+struct uvd *usbvideo_AllocateDevice(struct usbvideo *cams)
 {
 	int i, devnum;
 	struct uvd *uvd = NULL;
 
 	if (cams == NULL) {
-		err("No usbvideo_t handle?");
+		err("No usbvideo handle?");
 		return NULL;
 	}
 
@@ -2357,7 +2357,7 @@
 
 extern struct proc_dir_entry *video_proc_entry;
 
-static void usbvideo_procfs_level1_create(usbvideo_t *ut)
+static void usbvideo_procfs_level1_create(struct usbvideo *ut)
 {
 	if (ut == NULL) {
 		err("%s: ut == NULL", __FUNCTION__);
@@ -2376,7 +2376,7 @@
 	}
 }
 
-static void usbvideo_procfs_level1_destroy(usbvideo_t *ut)
+static void usbvideo_procfs_level1_destroy(struct usbvideo *ut)
 {
 	if (ut == NULL) {
 		err("%s: ut == NULL", __FUNCTION__);
diff -Nru a/drivers/usb/media/usbvideo.h b/drivers/usb/media/usbvideo.h
--- a/drivers/usb/media/usbvideo.h	Mon Dec 23 21:21:53 2002
+++ b/drivers/usb/media/usbvideo.h	Mon Dec 23 21:21:53 2002
@@ -126,37 +126,37 @@
 	wait_queue_head_t wqh;	/* Processes waiting */
 };
 
-typedef enum {
+enum ScanState {
 	ScanState_Scanning,	/* Scanning for header */
 	ScanState_Lines		/* Parsing lines */
-} ScanState_t;
+};
 
 /* Completion states of the data parser */
-typedef enum {
+enum ParseState {
 	scan_Continue,		/* Just parse next item */
 	scan_NextFrame,		/* Frame done, send it to V4L */
 	scan_Out,		/* Not enough data for frame */
 	scan_EndParse		/* End parsing */
-} ParseState_t;
+};
 
-typedef enum {
+enum FrameState {
 	FrameState_Unused,	/* Unused (no MCAPTURE) */
 	FrameState_Ready,	/* Ready to start grabbing */
 	FrameState_Grabbing,	/* In the process of being grabbed into */
 	FrameState_Done,	/* Finished grabbing, but not been synced yet */
 	FrameState_Done_Hold,	/* Are syncing or reading */
 	FrameState_Error,	/* Something bad happened while processing */
-} FrameState_t;
+};
 
 /*
  * Some frames may contain only even or odd lines. This type
  * specifies what type of deinterlacing is required.
  */
-typedef enum {
+enum Deinterlace {
 	Deinterlace_None=0,
 	Deinterlace_FillOddLines,
 	Deinterlace_FillEvenLines
-} Deinterlace_t;
+};
 
 #define USBVIDEO_NUMFRAMES	2	/* How many frames we work with */
 #define USBVIDEO_NUMSBUF	2	/* How many URBs linked in a ring */
@@ -175,9 +175,9 @@
 	videosize_t request;	/* That's what the application asked for */
 	unsigned short palette;	/* The desired format */
 
-	FrameState_t frameState;/* State of grabbing */
-	ScanState_t scanstate;	/* State of scanning */
-	Deinterlace_t deinterlace;
+	enum FrameState frameState;/* State of grabbing */
+	enum ScanState scanstate;	/* State of scanning */
+	enum Deinterlace deinterlace;
 	int flags;		/* USBVIDEO_FRAME_FLAG_xxx bit flags */
 
 	int curline;		/* Line of frame we're working on */
@@ -199,12 +199,12 @@
 	unsigned long iso_err_count;	/* How many bad ISO packets received */
 };
 
-struct s_usbvideo_t;
+struct usbvideo;
 
 struct uvd {
 	struct video_device vdev;	/* Must be the first field! */
 	struct usb_device *dev;
-	struct s_usbvideo_t *handle;	/* Points back to the usbvideo_t */
+	struct usbvideo *handle;	/* Points back to the struct usbvideo */
 	void *user_data;		/* Camera-dependent data */
 	int user_size;			/* Size of that camera-dependent data */
 	int debug;			/* Debug level for usbvideo */
@@ -273,7 +273,7 @@
 	int (*setVideoMode)(struct uvd *uvd, struct video_window *vw);
 };
 
-struct s_usbvideo_t {
+struct usbvideo {
 	int num_cameras;		/* As allocated */
 	struct usb_driver usbdrv;	/* Interface to the USB stack */
 	char drvName[80];		/* Driver name */
@@ -285,7 +285,7 @@
 	struct proc_dir_entry *procfs_dEntry;	/* /proc/video/MYDRIVER */
 	struct module *md_module;	/* Minidriver module */
 };
-typedef struct s_usbvideo_t usbvideo_t;
+
 
 /*
  * This macro retrieves callback address from the struct uvd object.
@@ -332,16 +332,16 @@
 unsigned long usbvideo_kvirt_to_pa(unsigned long adr);
 
 int usbvideo_register(
-	usbvideo_t **pCams,
+	struct usbvideo **pCams,
 	const int num_cams,
 	const int num_extra,
 	const char *driverName,
 	const struct usbvideo_cb *cbTable,
 	struct module *md,
 	const struct usb_device_id *id_table);
-struct uvd *usbvideo_AllocateDevice(usbvideo_t *cams);
+struct uvd *usbvideo_AllocateDevice(struct usbvideo *cams);
 int usbvideo_RegisterVideoDevice(struct uvd *uvd);
-void usbvideo_Deregister(usbvideo_t **uvt);
+void usbvideo_Deregister(struct usbvideo **uvt);
 
 int usbvideo_v4l_initialize(struct video_device *dev);
 
diff -Nru a/drivers/usb/misc/speedtouch.c b/drivers/usb/misc/speedtouch.c
--- a/drivers/usb/misc/speedtouch.c	Mon Dec 23 21:22:02 2002
+++ b/drivers/usb/misc/speedtouch.c	Mon Dec 23 21:22:02 2002
@@ -144,8 +144,10 @@
 static const char udsl_driver_name[] = "Alcatel SpeedTouch USB";
 
 /* data thread */
-static int datapid = 0;
 DECLARE_WAIT_QUEUE_HEAD (udsl_wqh);
+static DECLARE_COMPLETION(thread_grave);
+static DECLARE_MUTEX(udsl_usb_ioctl_lock);
+static unsigned int datapid;
 
 #ifdef DEBUG_PACKET
 int udsl_print_packet (const unsigned char *data, int len);
@@ -431,21 +433,36 @@
 	strcpy (current->comm, "kSpeedSARd");
 
 	add_wait_queue (&udsl_wqh, &wait);
+	set_current_state(TASK_INTERRUPTIBLE);
 
 	for (;;) {
-		interruptible_sleep_on (&udsl_wqh);
+		schedule();
 		if (signal_pending (current))
 			break;
 		PDEBUG ("SpeedSARd awoke\n");
+retry:
 		for (i = 0; i < MAX_UDSL; i++)
 			if (minor_data[i])
 				udsl_atm_processqueue (minor_data[i]);
+		set_current_state(TASK_INTERRUPTIBLE);
+		/* we must check for data recieved and restart processing if there's any */
+		for (i = 0; i < MAX_UDSL; i++) {
+			spin_lock_irq(&minor_data[i]->recvqlock);
+			if (!skb_queue_empty(&minor_data[i]->recvqueue)) {
+				spin_unlock_irq(&minor_data[i]->recvqlock);
+				set_current_state(TASK_RUNNING);
+				goto retry;
+			} else {
+				spin_unlock_irq(&minor_data[i]->recvqlock);
+			}
+		}
 	};
 
+	set_current_state(TASK_RUNNING);
 	remove_wait_queue (&udsl_wqh, &wait);
-	datapid = 0;
 	PDEBUG ("SpeedSARd is exiting\n");
-	return 0;
+	complete_and_exit(&thread_grave, 0);
+	return 0; //never reached
 }
 
 
@@ -461,16 +478,7 @@
 	/* Kill the thread */
 	ret = kill_proc (datapid, SIGTERM, 1);
 	if (!ret) {
-		/* Wait 10 seconds */
-		int count = 10 * 100;
-
-		while (datapid && --count) {
-			current->state = TASK_INTERRUPTIBLE;
-			schedule_timeout (1);
-		}
-
-		if (!count)
-			err ("giving up on killing SpeedSAR thread.");
+		wait_for_completion(&thread_grave);
 	}
 }
 
@@ -575,7 +583,6 @@
 	struct udsl_usb_send_data_context *ctx = (struct udsl_usb_send_data_context *) urb->context;
 	struct udsl_instance_data *instance = ctx->instance;
 	int err;
-	unsigned long flags;
 
 	PDEBUG ("udsl_usb_send_data_completion (vcc = %p, skb = %p, status %d)\n", ctx->vcc,
 		ctx->skb, urb->status);
@@ -583,22 +590,22 @@
 	ctx->vcc->pop (ctx->vcc, ctx->skb);
 	ctx->skb = NULL;
 
-	spin_lock_irqsave (&instance->sndqlock, flags);
+	spin_lock (&instance->sndqlock);
 	if (skb_queue_empty (&instance->sndqueue)) {
-		spin_unlock_irqrestore (&instance->sndqlock, flags);
+		spin_unlock (&instance->sndqlock);
 		return;
 	}
 	/* submit next skb */
 	ctx->skb = skb_dequeue (&(instance->sndqueue));
 	ctx->vcc = ((struct udsl_cb *) (ctx->skb->cb))->vcc;
-	spin_unlock_irqrestore (&instance->sndqlock, flags);
+	spin_unlock (&instance->sndqlock);
 	usb_fill_bulk_urb (urb,
 		       instance->usb_dev,
 		       usb_sndbulkpipe (instance->usb_dev, UDSL_ENDPOINT_DATA_OUT),
 		       (unsigned char *) ctx->skb->data,
 		       ctx->skb->len, udsl_usb_send_data_complete, ctx);
 
-	err = usb_submit_urb (urb, GFP_KERNEL);
+	err = usb_submit_urb (urb, GFP_ATOMIC);
 
 	PDEBUG ("udsl_usb_send_data_completion (send packet %p with length %d), retval = %d\n",
 		ctx->skb, ctx->skb->len, err);
@@ -607,9 +614,7 @@
 int udsl_usb_cancelsends (struct udsl_instance_data *instance, struct atm_vcc *vcc)
 {
 	int i;
-	unsigned long flags;
 
-	spin_lock_irqsave (&instance->sndqlock, flags);
 	for (i = 0; i < UDSL_NUMBER_SND_URBS; i++) {
 		if (!instance->send_ctx[i].skb)
 			continue;
@@ -621,7 +626,6 @@
 			instance->send_ctx[i].skb = NULL;
 		}
 	}
-	spin_unlock_irqrestore (&instance->sndqlock, flags);
 
 	return 0;
 }
@@ -695,7 +699,6 @@
 {
 	struct udsl_data_ctx *ctx;
 	struct udsl_instance_data *instance;
-	unsigned long flags;
 
 	if (!urb)
 		return;
@@ -717,9 +720,9 @@
 		skb_put (ctx->skb, urb->actual_length);
 
 		/* queue the skb for processing and wake the SAR */
-		spin_lock_irqsave (&instance->recvqlock, flags);
+		spin_lock (&instance->recvqlock);
 		skb_queue_tail (&instance->recvqueue, ctx->skb);
-		spin_unlock_irqrestore (&instance->recvqlock, flags);
+		spin_unlock (&instance->recvqlock);
 		wake_up (&udsl_wqh);
 		/* get a new skb */
 		ctx->skb = dev_alloc_skb (UDSL_RECEIVE_BUFFER_SIZE);
@@ -730,9 +733,6 @@
 			return;
 		}
 		break;
-	case -EPIPE:		/* stall or babble */
-		usb_clear_halt (urb->dev, usb_rcvbulkpipe (urb->dev, UDSL_ENDPOINT_DATA_IN));
-		break;
 	case -ENOENT:		/* buffer was unlinked */
 	case -EILSEQ:		/* unplug or timeout */
 	case -ETIMEDOUT:	/* unplug or timeout */
@@ -747,7 +747,7 @@
 		       usb_rcvbulkpipe (instance->usb_dev, UDSL_ENDPOINT_DATA_IN),
 		       (unsigned char *) ctx->skb->data,
 		       UDSL_RECEIVE_BUFFER_SIZE, udsl_usb_data_receive, ctx);
-	usb_submit_urb (urb, GFP_KERNEL);
+	usb_submit_urb (urb, GFP_ATOMIC);
 	return;
 };
 
@@ -845,8 +845,7 @@
 		if ((!ctx->urb) || (!ctx->skb))
 			continue;
 
-		if (ctx->urb->status == -EINPROGRESS)
-			usb_unlink_urb (ctx->urb);
+		usb_unlink_urb (ctx->urb);
 
 		usb_free_urb (ctx->urb);
 		kfree_skb (ctx->skb);
@@ -856,8 +855,7 @@
 	for (i = 0; i < UDSL_NUMBER_SND_URBS; i++) {
 		struct udsl_usb_send_data_context *ctx = &(instance->send_ctx[i]);
 
-		if (ctx->urb->status == -EINPROGRESS)
-			usb_unlink_urb (ctx->urb);
+		usb_unlink_urb (ctx->urb);
 
 		if (ctx->skb)
 			ctx->vcc->pop (ctx->vcc, ctx->skb);
@@ -890,7 +888,7 @@
 {
 	struct usb_device *dev = interface_to_usbdev (intf);
 	struct udsl_instance_data *instance;
-	int i;
+	int i,retval;
 
 	for (i = 0; i < MAX_UDSL; i++)
 		if (minor_data[i] && (minor_data[i]->usb_dev == dev))
@@ -901,17 +899,20 @@
 
 	instance = minor_data[i];
 
+	down(&udsl_usb_ioctl_lock);
 	switch (code) {
 	case UDSL_IOCTL_START:
-		return udsl_usb_data_init (instance);
+		retval = udsl_usb_data_init (instance);
 		break;
 	case UDSL_IOCTL_STOP:
-		return udsl_usb_data_exit (instance);
+		retval = udsl_usb_data_exit (instance);
 		break;
 	default:
+		retval = -ENOTTY;
 		break;
 	}
-	return -EINVAL;
+	up(&udsl_usb_ioctl_lock);
+	return retval;
 }
 
 static int udsl_usb_probe (struct usb_interface *intf, const struct usb_device_id *id)
@@ -992,11 +993,6 @@
 			udsl_atm_stopdevice (instance);
 
 		PDEBUG ("disconnecting minor %d\n", i);
-
-		while (MOD_IN_USE > 1) {
-			current->state = TASK_INTERRUPTIBLE;
-			schedule_timeout (1);
-		}
 
 		kfree (instance);
 		minor_data[i] = NULL;
diff -Nru a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c
--- a/drivers/usb/misc/usblcd.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/usb/misc/usblcd.c	Mon Dec 23 21:21:50 2002
@@ -98,7 +98,7 @@
 			return -EFAULT;
 		break;
 	default:
-		return -ENOIOCTLCMD;
+		return -ENOTTY;
 		break;
 	}
 
diff -Nru a/drivers/usb/net/cdc-ether.c b/drivers/usb/net/cdc-ether.c
--- a/drivers/usb/net/cdc-ether.c	Mon Dec 23 21:21:50 2002
+++ b/drivers/usb/net/cdc-ether.c	Mon Dec 23 21:21:50 2002
@@ -132,7 +132,7 @@
 
 	// Give this to the USB subsystem so it can tell us
 	// when more data arrives.
-	if ( (res = usb_submit_urb(ether_dev->rx_urb, GFP_KERNEL)) ) {
+	if ( (res = usb_submit_urb(ether_dev->rx_urb, GFP_ATOMIC)) ) {
 		warn("%s failed submint rx_urb %d", __FUNCTION__, res);
 	}
 
@@ -302,7 +302,7 @@
 	ether_dev->tx_urb->transfer_buffer_length = count;
 	
 	// Send the URB on its merry way.
-	if ((res = usb_submit_urb(ether_dev->tx_urb, GFP_KERNEL)))  {
+	if ((res = usb_submit_urb(ether_dev->tx_urb, GFP_ATOMIC)))  {
 		// Hmm...  It didn't go. Tell someone...
 		warn("failed tx_urb %d", res);
 		// update some stats...
diff -Nru a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c
--- a/drivers/usb/net/usbnet.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/usb/net/usbnet.c	Mon Dec 23 21:21:55 2002
@@ -35,7 +35,7 @@
  *	- GeneSys GL620USB-A
  *	- NetChip 1080 (interoperates with NetChip Win32 drivers)
  *	- Prolific PL-2301/2302 (replaces "plusb" driver)
- *	- SA-1100 based Linux PDAs like iPaq, Yopy, and Zaurus
+ *	- PXA-250 or SA-1100 Linux PDAs like iPaq, Yopy, and Zaurus
  *
  * USB devices can implement their side of this protocol at the cost
  * of two bulk endpoints; it's not restricted to "cable" applications.
@@ -61,8 +61,9 @@
  *   sheets, sometimes it's not needed and sometimes it hangs.  Prolific has
  *   not responded to repeated support/information requests.
  *
- * - SA-1100 PDAs ... the www.handhelds.org SA-1100 support works nicely.
- *   Zaurus support has some problems; it's made UHCI die.
+ * - SA-1100 PDAs ... the standard ARM Linux SA-1100 support works nicely,
+ *   as found in www.handhelds.org and other kernels.  The Sharp/Lineo
+ *   kernels use different drivers, which also talk to this code.
  *
  * Interop with more Win32 drivers may be a good thing.
  *
@@ -116,7 +117,10 @@
  * 07-may-2002	Generalize/cleanup keventd support, handling rx stalls (mostly
  *		for USB 2.0 TTs) and memory shortages (potential) too. (db)
  *		Use "locally assigned" IEEE802 address space. (Brad Hards)
- * 18-oct-2002  Support for Zaurus (Pavel Machek), related cleanup (db).
+ * 18-oct-2002	Support for Zaurus (Pavel Machek), related cleanup (db).
+ * 14-dec-2002	Remove Zaurus-private crc32 code (Pavel); 2.5 oops fix,
+ * 		cleanups and stubbed PXA-250 support (db), fix for framing
+ * 		issues on Z, net1080, and gl620a (Toby Milne)
  *
  *-------------------------------------------------------------------------*/
 
@@ -150,7 +154,8 @@
 #define	CONFIG_USB_GENESYS
 #define	CONFIG_USB_NET1080
 #define	CONFIG_USB_PL2301
-#define	CONFIG_USB_SA1110
+// #define	CONFIG_USB_PXA
+#define	CONFIG_USB_SA1100
 #define	CONFIG_USB_ZAURUS
 
 
@@ -162,6 +167,8 @@
  * Nineteen USB 1.1 max size bulk transactions per frame (ms), max.
  * Several dozen bytes of IPv4 data can fit in two such transactions.
  * One maximum size Ethernet packet takes twenty four of them.
+ * For high speed, each frame comfortably fits almost 36 max size
+ * Ethernet packets (so queues should be bigger).
  */
 #ifdef REALLY_QUEUE
 #define	RX_QLEN		4
@@ -233,6 +240,7 @@
 	int		flags;
 #define FLAG_FRAMING_NC	0x0001		/* guard against device dropouts */ 
 #define FLAG_FRAMING_GL	0x0002		/* genelink batches packets */
+#define FLAG_FRAMING_Z	0x0004		/* zaurus adds a trailer */
 #define FLAG_NO_SETINT	0x0010		/* device can't set_interface() */
 
 	/* reset device ... can sleep */
@@ -287,6 +295,12 @@
 #define	RUN_CONTEXT (in_irq () ? "in_irq" \
 			: (in_interrupt () ? "in_interrupt" : "can sleep"))
 
+/* mostly for PDA style devices, which are always present */
+static int always_connected (struct usbnet *dev)
+{
+	return 0;
+}
+
 /*-------------------------------------------------------------------------*/
 
 #ifdef DEBUG
@@ -364,6 +378,7 @@
 
 static const struct driver_info	epson2888_info = {
 	.description =	"Epson USB Device",
+	.check_connect = always_connected,
 
 	.in = 4, .out = 3,
 	.epsize = 64,
@@ -457,10 +472,12 @@
 	case -ENOENT:
 	case -ESHUTDOWN:
 		/* this urb is terminated, clean up */
-		dbg("%s - urb shutting down with status: %d", __FUNCTION__, status);
+		dbg("%s - urb shutting down with status: %d",
+				__FUNCTION__, status);
 		return;
 	default:
-		dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
+		dbg("%s - nonzero urb status received: %d",
+				__FUNCTION__, urb->status);
 	}
 
 	status = usb_submit_urb (urb, GFP_ATOMIC);
@@ -1224,22 +1241,44 @@
 
 
 
+#ifdef	CONFIG_USB_PXA
+
+/*-------------------------------------------------------------------------
+ *
+ * PXA250 and PXA210 use XScale cores (ARM v5TE) with better USB support,
+ * and different USB endpoint numbering than the SA1100 devices.
+ *
+ *-------------------------------------------------------------------------*/
+
+static const struct driver_info	pxa_info = {
+	.description =	"PXA-250 Linux Device",
+	.check_connect = always_connected,
+
+	.in = 1, .out = 2,
+	.epsize = 64,
+};
+
+#endif	/* CONFIG_USB_PXA */
+
+
+
 #ifdef	CONFIG_USB_SA1100
 
 /*-------------------------------------------------------------------------
  *
  * Intel's SA-1100 chip integrates basic USB support, and is used
  * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more.
- * When they runs Linux, arch/arm/sa1100/usb-eth.c may be used to
+ * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to
  * network using minimal USB framing data.
  *
- * This describes the driver currently in www.handhelds.org kernels.
+ * This describes the driver currently in standard ARM Linux kernels.
  * The Zaurus uses a different driver (see later).
  *
  *-------------------------------------------------------------------------*/
 
 static const struct driver_info	linuxdev_info = {
 	.description =	"SA-1100 Linux Device",
+	.check_connect = always_connected,
 
 	.in = 2, .out = 1,
 	.epsize = 64,
@@ -1247,6 +1286,7 @@
 
 static const struct driver_info	yopy_info = {
 	.description =	"Yopy",
+	.check_connect = always_connected,
 
 	.in = 2, .out = 1,
 	.epsize = 64,
@@ -1257,65 +1297,20 @@
 
 #ifdef CONFIG_USB_ZAURUS
 
+#include <linux/crc32.h>
+
 /*-------------------------------------------------------------------------
  *
  * Zaurus is also a SA-1110 based PDA, but one using a different driver
- * for its USB slave/target controller than the case above.
+ * (and framing) for its USB slave/gadget controller than the case above.
  *
- * The key differences are that (a) it's got a msft-friendly configuration,
- * and (b) the linux-friendly framing adds a crc32 to cope with some
- * memory corruption observed with usb-to-memory DMA in some cases.
+ * For the current version of that driver, the main way that framing is
+ * nonstandard (also from perspective of the CDC ethernet model!) is a
+ * crc32, added to help detect when some sa1100 usb-to-memory DMA errata
+ * haven't been fully worked around.
  *
  *-------------------------------------------------------------------------*/
 
-static const u32 crc32_table [256] = {
-    0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
-    0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
-    0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
-    0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
-    0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
-    0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
-    0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
-    0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
-    0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
-    0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
-    0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
-    0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
-    0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
-    0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
-    0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
-    0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
-    0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
-    0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
-    0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
-    0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
-    0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
-    0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
-    0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
-    0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
-    0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
-    0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
-    0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
-    0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
-    0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
-    0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
-    0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
-    0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
-};
-
-#define CRC32_INITFCS     0xffffffff  // Initial FCS value 
-#define CRC32_FCS(fcs, c) (((fcs) >> 8) ^ crc32_table[((fcs) ^ (c)) & 0xff])
-
-/* fcs_compute32 - memcpy and calculate fcs
- * Perform a memcpy and calculate fcs using ppp 32bit CRC algorithm.
- */
-static inline u32 fcs_compute32 (unsigned char *sp, int len, u32 fcs)
-{
-	for (;len-- > 0; fcs = CRC32_FCS (fcs, *sp++))
-		continue;
-	return fcs;
-}
-
 static struct sk_buff *
 zaurus_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
 {
@@ -1334,11 +1329,9 @@
 	if (skb) {
 		u32		fcs;
 done:
-		fcs = fcs_compute32 (skb->data, skb->len, CRC32_INITFCS);
+		fcs = crc32_le (~0, skb->data, skb->len);
 		fcs = ~fcs;
 
-		// ? add optional byte make addr even ?
-
 		*skb_put (skb, 1) = fcs       & 0xff;
 		*skb_put (skb, 1) = (fcs>> 8) & 0xff;
 		*skb_put (skb, 1) = (fcs>>16) & 0xff;
@@ -1349,6 +1342,8 @@
 
 static const struct driver_info	zaurus_sl5x00_info = {
 	.description =	"Sharp Zaurus SL-5x00",
+	.flags =	FLAG_FRAMING_Z,
+	.check_connect = always_connected,
 	.tx_fixup = 	zaurus_tx_fixup,
 
 	.in = 2, .out = 1,
@@ -1356,11 +1351,16 @@
 };
 static const struct driver_info	zaurus_sla300_info = {
 	.description =	"Sharp Zaurus SL-A300",
+	.flags =	FLAG_FRAMING_Z,
+	.check_connect = always_connected,
 	.tx_fixup = 	zaurus_tx_fixup,
 
 	.in = 1, .out = 2,
 	.epsize = 64,
 };
+
+// SL-5600 and C-700 are PXA based; should resemble A300
+
 #endif
 
 
@@ -1403,7 +1403,7 @@
 
 /*-------------------------------------------------------------------------*/
 
-/* urb completions are currently in_irq; avoid doing real work then. */
+/* urb completions may be in_irq; avoid doing real work then. */
 
 static void defer_bh (struct usbnet *dev, struct sk_buff *skb)
 {
@@ -1457,6 +1457,11 @@
 		size = GL_RCV_BUF_SIZE;
 	else
 #endif
+#ifdef CONFIG_USB_ZAURUS
+	if (dev->driver_info->flags & FLAG_FRAMING_Z)
+		size = 6 + (sizeof (struct ethhdr) + dev->net.mtu);
+	else
+#endif
 		size = (sizeof (struct ethhdr) + dev->net.mtu);
 
 	if ((skb = alloc_skb (size, flags)) == 0) {
@@ -1476,11 +1481,6 @@
 		usb_rcvbulkpipe (dev->udev, dev->driver_info->in),
 		skb->data, size, rx_complete, skb);
 	urb->transfer_flags |= URB_ASYNC_UNLINK;
-#if 0
-	// Idle-but-posted reads with UHCI really chew up
-	// PCI bandwidth unless FSBR is disabled
-	urb->transfer_flags |= URB_NO_FSBR;
-#endif
 
 	spin_lock_irqsave (&dev->rxq.lock, lockflags);
 
@@ -1524,8 +1524,6 @@
 	if (skb->len) {
 		int	status;
 
-// FIXME: eth_copy_and_csum "small" packets to new SKB (small < ~200 bytes) ?
-
 		skb->dev = &dev->net;
 		skb->protocol = eth_type_trans (skb, &dev->net);
 		dev->stats.rx_packets++;
@@ -1904,7 +1902,7 @@
 static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
 {
 	struct usbnet		*dev = (struct usbnet *) net->priv;
-	int			length = skb->len;
+	int			length;
 	int			retval = NET_XMIT_SUCCESS;
 	struct urb		*urb = 0;
 	struct skb_data		*entry;
@@ -1924,6 +1922,7 @@
 			goto drop;
 		}
 	}
+	length = skb->len;
 
 	if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) {
 		dbg ("no urb");
@@ -1938,6 +1937,7 @@
 
 	// FIXME: reorganize a bit, so that fixup() fills out NetChip
 	// framing too. (Packet ID update needs the spinlock...)
+	// [ BETTER:  we already own net->xmit_lock, that's enough ]
 
 #ifdef	CONFIG_USB_NET1080
 	if (info->flags & FLAG_FRAMING_NC) {
@@ -1958,7 +1958,6 @@
 			usb_sndbulkpipe (dev->udev, info->out),
 			skb->data, skb->len, tx_complete, skb);
 	urb->transfer_flags |= URB_ASYNC_UNLINK;
-	// FIXME urb->timeout = ... jiffies ... ;
 
 	spin_lock_irqsave (&dev->txq.lock, flags);
 
@@ -2198,7 +2197,7 @@
 #endif
 
 	// ok, it's ready to go.
-	dev_set_drvdata (&udev->dev, net);
+	dev_set_drvdata (&udev->dev, dev);
 	mutex_lock (&usbnet_mutex);
 	list_add (&dev->dev_list, &usbnet_list);
 	mutex_unlock (&dev->mutex);
@@ -2280,15 +2279,28 @@
 },
 #endif
 
+#ifdef	CONFIG_USB_PXA
+/*
+ * PXA250 or PXA210 ...  these use a "usb-eth" driver much like
+ * the sa1100 one.
+ */
+{
+	// Compaq "Itsy" vendor/product id, version "2.0"
+	USB_DEVICE_VER (0x049F, 0x505A, 0x0200, 0x0200),
+	.driver_info =	(unsigned long) &pxa_info,
+}, 
+#endif
+
 #ifdef	CONFIG_USB_SA1100
 /*
- * SA-1100 using www.handhelds.org kernels, or compatible.
+ * SA-1100 using standard ARM Linux kernels, or compatible.
  * Often used when talking to Linux PDAs (iPaq, Yopy, etc).
  * The sa-1100 "usb-eth" driver handles the basic framing.
  */
 {
 	// 1183 = 0x049F, both used as hex values?
-	USB_DEVICE (0x049F, 0x505A),	// iPaq: Compaq "Itsy"
+	// Compaq "Itsy" vendor/product id, version "0.0"
+	USB_DEVICE_VER (0x049F, 0x505A, 0, 0),
 	.driver_info =	(unsigned long) &linuxdev_info,
 }, {
 	USB_DEVICE (0x0E7E, 0x1001),	// G.Mate "Yopy"
@@ -2322,8 +2334,6 @@
 	.driver_info =  (unsigned long) &zaurus_sla300_info,
 },
 #endif
-
-/* KC2190 from www.sepoong.co.kr "InstaNET" */
 
 	{ },		// END
 };
diff -Nru a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
--- a/drivers/usb/serial/belkin_sa.c	Mon Dec 23 21:21:56 2002
+++ b/drivers/usb/serial/belkin_sa.c	Mon Dec 23 21:21:56 2002
@@ -126,6 +126,7 @@
 static struct usb_serial_device_type belkin_device = {
 	.owner =		THIS_MODULE,
 	.name =			"Belkin / Peracom / GoHubs USB Serial Adapter",
+	.short_name =		"belkin",
 	.id_table =		id_table_combined,
 	.num_interrupt_in =	1,
 	.num_bulk_in =		1,
diff -Nru a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c
--- a/drivers/usb/serial/bus.c	Mon Dec 23 21:22:02 2002
+++ b/drivers/usb/serial/bus.c	Mon Dec 23 21:22:02 2002
@@ -121,7 +121,10 @@
 {
 	int retval;
 
-	device->driver.name = (char *)device->name;
+	if (device->short_name)
+		device->driver.name = (char *)device->short_name;
+	else
+		device->driver.name = (char *)device->name;
 	device->driver.bus = &usb_serial_bus_type;
 	device->driver.probe = usb_serial_device_probe;
 	device->driver.remove = usb_serial_device_remove;
diff -Nru a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
--- a/drivers/usb/serial/cyberjack.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/usb/serial/cyberjack.c	Mon Dec 23 21:22:00 2002
@@ -83,6 +83,7 @@
 static struct usb_serial_device_type cyberjack_device = {
 	.owner =		THIS_MODULE,
 	.name =			"Reiner SCT Cyberjack USB card reader",
+	.short_name =		"cyberjack",
 	.id_table =		id_table,
 	.num_interrupt_in =	1,
 	.num_bulk_in =		1,
diff -Nru a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
--- a/drivers/usb/serial/generic.c	Mon Dec 23 21:21:51 2002
+++ b/drivers/usb/serial/generic.c	Mon Dec 23 21:21:51 2002
@@ -43,6 +43,7 @@
 struct usb_serial_device_type usb_serial_generic_device = {
 	.owner =		THIS_MODULE,
 	.name =			"Generic",
+	.short_name =		"generic",
 	.id_table =		generic_device_ids,
 	.num_interrupt_in =	NUM_DONT_CARE,
 	.num_bulk_in =		NUM_DONT_CARE,
diff -Nru a/drivers/usb/serial/io_tables.h b/drivers/usb/serial/io_tables.h
--- a/drivers/usb/serial/io_tables.h	Mon Dec 23 21:21:57 2002
+++ b/drivers/usb/serial/io_tables.h	Mon Dec 23 21:21:57 2002
@@ -100,6 +100,7 @@
 static struct usb_serial_device_type edgeport_1port_device = {
 	.owner			= THIS_MODULE,
 	.name			= "Edgeport 1 port adapter",
+	.short_name		= "edgeport_1",
 	.id_table		= edgeport_1port_id_table,
 	.num_interrupt_in	= 1,
 	.num_bulk_in		= 1,
@@ -122,6 +123,7 @@
 static struct usb_serial_device_type edgeport_2port_device = {
 	.owner			= THIS_MODULE,
 	.name			= "Edgeport 2 port adapter",
+	.short_name		= "edgeport_2",
 	.id_table		= edgeport_2port_id_table,
 	.num_interrupt_in	= 1,
 	.num_bulk_in		= 1,
@@ -144,6 +146,7 @@
 static struct usb_serial_device_type edgeport_4port_device = {
 	.owner			= THIS_MODULE,
 	.name			= "Edgeport 4 port adapter",
+	.short_name		= "edgeport_4",
 	.id_table		= edgeport_4port_id_table,
 	.num_interrupt_in	= 1,
 	.num_bulk_in		= 1,
@@ -166,6 +169,7 @@
 static struct usb_serial_device_type edgeport_8port_device = {
 	.owner			= THIS_MODULE,
 	.name			= "Edgeport 8 port adapter",
+	.short_name		= "edgeport_8",
 	.id_table		= edgeport_8port_id_table,
 	.num_interrupt_in	= 1,
 	.num_bulk_in		= 1,
diff -Nru a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
--- a/drivers/usb/serial/io_ti.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/usb/serial/io_ti.c	Mon Dec 23 21:22:00 2002
@@ -2635,6 +2635,7 @@
 static struct usb_serial_device_type edgeport_1port_device = {
 	.owner			= THIS_MODULE,
 	.name			= "Edgeport TI 1 port adapter",
+	.short_name		= "edgeport_ti_1",
 	.id_table		= edgeport_1port_id_table,
 	.num_interrupt_in	= 1,
 	.num_bulk_in		= 1,
@@ -2657,6 +2658,7 @@
 static struct usb_serial_device_type edgeport_2port_device = {
 	.owner			= THIS_MODULE,
 	.name			= "Edgeport TI 2 port adapter",
+	.short_name		= "edgeport_ti_2",
 	.id_table		= edgeport_2port_id_table,
 	.num_interrupt_in	= 1,
 	.num_bulk_in		= 2,
diff -Nru a/drivers/usb/serial/keyspan.h b/drivers/usb/serial/keyspan.h
--- a/drivers/usb/serial/keyspan.h	Mon Dec 23 21:21:58 2002
+++ b/drivers/usb/serial/keyspan.h	Mon Dec 23 21:21:58 2002
@@ -481,6 +481,7 @@
 static struct usb_serial_device_type keyspan_pre_device = {
 	.owner			= THIS_MODULE,
 	.name			= "Keyspan - (without firmware)",
+	.short_name		= "keyspan_no_firm",
 	.id_table		= keyspan_pre_ids,
 	.num_interrupt_in	= NUM_DONT_CARE,
 	.num_bulk_in		= NUM_DONT_CARE,
@@ -492,6 +493,7 @@
 static struct usb_serial_device_type keyspan_1port_device = {
 	.owner			= THIS_MODULE,
 	.name			= "Keyspan 1 port adapter",
+	.short_name		= "keyspan_1",
 	.id_table		= keyspan_1port_ids,
 	.num_interrupt_in	= NUM_DONT_CARE,
 	.num_bulk_in		= 3,
@@ -514,6 +516,7 @@
 static struct usb_serial_device_type keyspan_2port_device = {
 	.owner			= THIS_MODULE,
 	.name			= "Keyspan 2 port adapter",
+	.short_name		= "keyspan_2",
 	.id_table		= keyspan_2port_ids,
 	.num_interrupt_in	= NUM_DONT_CARE,
 	.num_bulk_in		= NUM_DONT_CARE,
@@ -536,6 +539,7 @@
 static struct usb_serial_device_type keyspan_4port_device = {
 	.owner			= THIS_MODULE,
 	.name			= "Keyspan 4 port adapter",
+	.short_name		= "keyspan_4",
 	.id_table		= keyspan_4port_ids,
 	.num_interrupt_in	= NUM_DONT_CARE,
 	.num_bulk_in		= 5,
diff -Nru a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
--- a/drivers/usb/serial/keyspan_pda.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/usb/serial/keyspan_pda.c	Mon Dec 23 21:21:58 2002
@@ -827,6 +827,7 @@
 static struct usb_serial_device_type keyspan_pda_fake_device = {
 	.owner =		THIS_MODULE,
 	.name =			"Keyspan PDA - (prerenumeration)",
+	.short_name =		"keyspan_pda_pre",
 	.id_table =		id_table_fake,
 	.num_interrupt_in =	NUM_DONT_CARE,
 	.num_bulk_in =		NUM_DONT_CARE,
@@ -840,6 +841,7 @@
 static struct usb_serial_device_type xircom_pgs_fake_device = {
 	.owner =		THIS_MODULE,
 	.name =			"Xircom / Entregra PGS - (prerenumeration)",
+	.short_name =		"xircom_no_firm",
 	.id_table =		id_table_fake_xircom,
 	.num_interrupt_in =	NUM_DONT_CARE,
 	.num_bulk_in =		NUM_DONT_CARE,
@@ -852,6 +854,7 @@
 static struct usb_serial_device_type keyspan_pda_device = {
 	.owner =		THIS_MODULE,
 	.name =			"Keyspan PDA",
+	.short_name =		"keyspan_pda",
 	.id_table =		id_table_std,
 	.num_interrupt_in =	1,
 	.num_bulk_in =		0,
diff -Nru a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
--- a/drivers/usb/serial/kl5kusb105.c	Mon Dec 23 21:21:55 2002
+++ b/drivers/usb/serial/kl5kusb105.c	Mon Dec 23 21:21:55 2002
@@ -127,6 +127,7 @@
 static struct usb_serial_device_type kl5kusb105d_device = {
 	.owner =             THIS_MODULE,
 	.name =		     "KL5KUSB105D / PalmConnect",
+	.short_name =	     "kl5kusb105d",
 	.id_table =	     id_table,
 	.num_interrupt_in =  1,
 	.num_bulk_in =	     1,
diff -Nru a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
--- a/drivers/usb/serial/mct_u232.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/usb/serial/mct_u232.c	Mon Dec 23 21:21:58 2002
@@ -149,6 +149,7 @@
 static struct usb_serial_device_type mct_u232_device = {
 	.owner =	     THIS_MODULE,
 	.name =		     "Magic Control Technology USB-RS232",
+	.short_name =	     "mct_u232",
 	.id_table =	     id_table_combined,
 	.num_interrupt_in =  2,
 	.num_bulk_in =	     0,
diff -Nru a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
--- a/drivers/usb/serial/omninet.c	Mon Dec 23 21:22:00 2002
+++ b/drivers/usb/serial/omninet.c	Mon Dec 23 21:22:00 2002
@@ -94,6 +94,7 @@
 static struct usb_serial_device_type zyxel_omninet_device = {
 	.owner =		THIS_MODULE,
 	.name =			"ZyXEL - omni.net lcd plus usb",
+	.short_name =		"omninet",
 	.id_table =		id_table,
 	.num_interrupt_in =	1,
 	.num_bulk_in =		1,
diff -Nru a/drivers/usb/serial/usb-serial.h b/drivers/usb/serial/usb-serial.h
--- a/drivers/usb/serial/usb-serial.h	Mon Dec 23 21:22:03 2002
+++ b/drivers/usb/serial/usb-serial.h	Mon Dec 23 21:22:03 2002
@@ -168,6 +168,9 @@
  * @owner: pointer to the module that owns this device.
  * @name: pointer to a string that describes this device.  This string used
  *	in the syslog messages when a device is inserted or removed.
+ * @short_name: a pointer to a string that describes this device in
+ *	KOBJ_NAME_LEN characters or less.  This is used for the sysfs interface
+ *	to describe the driver.
  * @id_table: pointer to a list of usb_device_id structures that define all
  *	of the devices this structure can support.
  * @num_interrupt_in: the number of interrupt in endpoints this device will
@@ -201,6 +204,7 @@
 struct usb_serial_device_type {
 	struct module *owner;
 	char	*name;
+	char	*short_name;
 	const struct usb_device_id *id_table;
 	char	num_interrupt_in;
 	char	num_bulk_in;
diff -Nru a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
--- a/drivers/usb/serial/visor.c	Mon Dec 23 21:21:52 2002
+++ b/drivers/usb/serial/visor.c	Mon Dec 23 21:21:52 2002
@@ -236,6 +236,7 @@
 static struct usb_serial_device_type handspring_device = {
 	.owner =		THIS_MODULE,
 	.name =			"Handspring Visor / Treo / Palm 4.0 / Clié 4.x",
+	.short_name =		"visor",
 	.id_table =		id_table,
 	.num_interrupt_in =	NUM_DONT_CARE,
 	.num_bulk_in =		2,
@@ -262,6 +263,7 @@
 static struct usb_serial_device_type clie_3_5_device = {
 	.owner =		THIS_MODULE,
 	.name =			"Sony Clié 3.5",
+	.short_name =		"clie_3.5",
 	.id_table =		clie_id_3_5_table,
 	.num_interrupt_in =	0,
 	.num_bulk_in =		1,
diff -Nru a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
--- a/drivers/usb/serial/whiteheat.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/usb/serial/whiteheat.c	Mon Dec 23 21:21:53 2002
@@ -156,6 +156,7 @@
 static struct usb_serial_device_type whiteheat_fake_device = {
 	.owner =		THIS_MODULE,
 	.name =			"Connect Tech - WhiteHEAT - (prerenumeration)",
+	.short_name =		"whiteheatnofirm",
 	.id_table =		id_table_prerenumeration,
 	.num_interrupt_in =	NUM_DONT_CARE,
 	.num_bulk_in =		NUM_DONT_CARE,
@@ -168,6 +169,7 @@
 static struct usb_serial_device_type whiteheat_device = {
 	.owner =		THIS_MODULE,
 	.name =			"Connect Tech - WhiteHEAT",
+	.short_name =		"whiteheat",
 	.id_table =		id_table_std,
 	.num_interrupt_in =	NUM_DONT_CARE,
 	.num_bulk_in =		NUM_DONT_CARE,
@@ -512,9 +514,11 @@
 no_rx_buf:
 			usb_free_urb(urb);
 no_rx_urb:
+			;
 		}
 		kfree(info);
 no_private:
+		;
 	}
 	return -ENOMEM;
 }
diff -Nru a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
--- a/drivers/usb/storage/transport.c	Mon Dec 23 21:21:53 2002
+++ b/drivers/usb/storage/transport.c	Mon Dec 23 21:21:53 2002
@@ -480,7 +480,7 @@
 	status = usb_stor_msg_common(us);
 
 	/* return the actual length of the data transferred if no error */
-	if (status >= 0)
+	if (status == 0)
 		status = us->current_urb->actual_length;
 	return status;
 }
@@ -583,50 +583,52 @@
 
 	US_DEBUGP("Status code %d; transferred %u/%u\n",
 			result, partial, length);
+	switch (result) {
 
-	/* stalled */
-	if (result == -EPIPE) {
+	/* no error code; did we send all the data? */
+	case 0:
+		if (partial != length) {
+			US_DEBUGP("-- short transfer\n");
+			return USB_STOR_XFER_SHORT;
+		}
+
+		US_DEBUGP("-- transfer complete\n");
+		return USB_STOR_XFER_GOOD;
 
-		/* for non-bulk (i.e., control) endpoints, a stall indicates
-		 * a protocol error */
-		if (!usb_pipebulk(pipe)) {
+	/* stalled */
+	case -EPIPE:
+		/* for control endpoints, a stall indicates a protocol error */
+		if (usb_pipecontrol(pipe)) {
 			US_DEBUGP("-- stall on control pipe\n");
 			return USB_STOR_XFER_ERROR;
 		}
 
-		/* for a bulk endpoint, clear the stall */
+		/* for other sorts of endpoint, clear the stall */
 		US_DEBUGP("clearing endpoint halt for pipe 0x%x\n", pipe);
 		if (usb_stor_clear_halt(us, pipe) < 0)
 			return USB_STOR_XFER_ERROR;
 		return USB_STOR_XFER_STALLED;
-	}
 
 	/* NAK - that means we've retried this a few times already */
-	if (result == -ETIMEDOUT) {
+	case -ETIMEDOUT:
 		US_DEBUGP("-- device NAKed\n");
 		return USB_STOR_XFER_ERROR;
-	}
 
 	/* the transfer was cancelled, presumably by an abort */
-	if (result == -ENODEV) {
+	case -ENODEV:
 		US_DEBUGP("-- transfer cancelled\n");
 		return USB_STOR_XFER_ERROR;
-	}
+
+	/* short scatter-gather read transfer */
+	case -EREMOTEIO:
+		US_DEBUGP("-- short read transfer\n");
+		return USB_STOR_XFER_SHORT;
 
 	/* the catch-all error case */
-	if (result < 0) {
+	default:
 		US_DEBUGP("-- unknown error\n");
 		return USB_STOR_XFER_ERROR;
 	}
-
-	/* no error code; did we send all the data? */
-	if (partial != length) {
-		US_DEBUGP("-- transferred only %u bytes\n", partial);
-		return USB_STOR_XFER_SHORT;
-	}
-
-	US_DEBUGP("-- transfer complete\n");
-	return USB_STOR_XFER_GOOD;
 }
 
 /*
diff -Nru a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
--- a/drivers/usb/storage/usb.c	Mon Dec 23 21:21:52 2002
+++ b/drivers/usb/storage/usb.c	Mon Dec 23 21:21:52 2002
@@ -728,9 +728,13 @@
 			USB_ENDPOINT_NUMBER_MASK;
 		ss->ep_out = ep_out->bEndpointAddress & 
 			USB_ENDPOINT_NUMBER_MASK;
-		ss->ep_int = ep_int->bEndpointAddress & 
-			USB_ENDPOINT_NUMBER_MASK;
-		ss->ep_bInterval = ep_int->bInterval;
+		if (ep_int) {
+			ss->ep_int = ep_int->bEndpointAddress & 
+				USB_ENDPOINT_NUMBER_MASK;
+			ss->ep_bInterval = ep_int->bInterval;
+		}
+		else
+			ss->ep_int = ss->ep_bInterval = 0;
 
 		/* allocate the URB, the usb_ctrlrequest, and the IRQ URB */
 		if (usb_stor_allocate_urbs(ss))
@@ -771,9 +775,13 @@
 			USB_ENDPOINT_NUMBER_MASK;
 		ss->ep_out = ep_out->bEndpointAddress & 
 			USB_ENDPOINT_NUMBER_MASK;
-		ss->ep_int = ep_int->bEndpointAddress & 
-			USB_ENDPOINT_NUMBER_MASK;
-		ss->ep_bInterval = ep_int->bInterval;
+		if (ep_int) {
+			ss->ep_int = ep_int->bEndpointAddress & 
+				USB_ENDPOINT_NUMBER_MASK;
+			ss->ep_bInterval = ep_int->bInterval;
+		}
+		else
+			ss->ep_int = ss->ep_bInterval = 0;
 
 		/* establish the connection to the new device */
 		ss->ifnum = ifnum;
diff -Nru a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
--- a/drivers/video/aty/atyfb_base.c	Mon Dec 23 21:21:58 2002
+++ b/drivers/video/aty/atyfb_base.c	Mon Dec 23 21:21:58 2002
@@ -984,7 +984,6 @@
 						var.yres_virtual =
 						    var.yres;
 				}
-				gen_set_var(&var, -1, info);
 			}
 		}
 	} 
@@ -1249,16 +1248,14 @@
 {
 	struct fb_info *info;
 	struct atyfb_par *par;
-	struct display *d;
 	int i;
 
-	for (i = 0; i < MAX_NR_CONSOLES; i++) {
-		d = &fb_display[i];
-		if (d->fb_info &&
-		    d->fb_info->fbops == &atyfb_ops &&
-		    d->fb_info->display_fg &&
-		    d->fb_info->display_fg->vc_num == i) {
-			info = d->fb_info;
+	for (i = 0; i < FB_MAX; i++) {
+		info = registered_fb[i];
+		if (info &&
+		    info->fbops == &atyfb_ops &&
+		    info->display_fg &&
+		    info->display_fg->vc_num == i) {
 			par = (struct atyfb_par *) info->par;
 			
 			atyfb_save_palette(par, enter);
diff -Nru a/drivers/video/console/promcon.c b/drivers/video/console/promcon.c
--- a/drivers/video/console/promcon.c	Mon Dec 23 21:21:56 2002
+++ b/drivers/video/console/promcon.c	Mon Dec 23 21:21:56 2002
@@ -183,7 +183,7 @@
 	}
 	if (!init) {
 		if (conp->vc_cols != pw + 1 || conp->vc_rows != ph + 1)
-			vc_resize(conp->unit, pw + 1, ph + 1);
+			vc_resize(conp->vc_num, pw + 1, ph + 1);
 	}
 }
 
diff -Nru a/fs/afs/file.c b/fs/afs/file.c
--- a/fs/afs/file.c	Mon Dec 23 21:21:58 2002
+++ b/fs/afs/file.c	Mon Dec 23 21:21:58 2002
@@ -37,7 +37,7 @@
 struct file_operations afs_file_file_operations = {
 	.read		= generic_file_read,
 	.write		= afs_file_write,
-	.mmap		= generic_file_mmap,
+	.mmap		= generic_file_readonly_mmap,
 #if 0
 	.open		= afs_file_open,
 	.release	= afs_file_release,
diff -Nru a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
--- a/fs/befs/linuxvfs.c	Mon Dec 23 21:21:53 2002
+++ b/fs/befs/linuxvfs.c	Mon Dec 23 21:21:53 2002
@@ -74,7 +74,7 @@
 struct file_operations befs_file_operations = {
 	.llseek		= default_llseek,
 	.read		= generic_file_read,
-	.mmap		= generic_file_mmap,
+	.mmap		= generic_file_readonly_mmap,
 };
 
 struct address_space_operations befs_aops = {
diff -Nru a/fs/bio.c b/fs/bio.c
--- a/fs/bio.c	Mon Dec 23 21:21:56 2002
+++ b/fs/bio.c	Mon Dec 23 21:21:56 2002
@@ -137,12 +137,10 @@
  **/
 struct bio *bio_alloc(int gfp_mask, int nr_iovecs)
 {
-	int pf_flags = current->flags;
 	struct bio_vec *bvl = NULL;
 	unsigned long idx;
 	struct bio *bio;
 
-	current->flags |= PF_NOWARN;
 	bio = mempool_alloc(bio_pool, gfp_mask);
 	if (unlikely(!bio))
 		goto out;
@@ -160,7 +158,6 @@
 		bio->bi_io_vec = bvl;
 		bio->bi_destructor = bio_destructor;
 out:
-		current->flags = pf_flags;
 		return bio;
 	}
 
diff -Nru a/fs/buffer.c b/fs/buffer.c
--- a/fs/buffer.c	Mon Dec 23 21:21:56 2002
+++ b/fs/buffer.c	Mon Dec 23 21:21:56 2002
@@ -221,9 +221,9 @@
 	lock_super(sb);
 	if (sb->s_dirt && sb->s_op->write_super)
 		sb->s_op->write_super(sb);
+	unlock_super(sb);
 	if (sb->s_op->sync_fs)
 		sb->s_op->sync_fs(sb, 1);
-	unlock_super(sb);
 	sync_blockdev(sb->s_bdev);
 	sync_inodes_sb(sb, 1);
 
@@ -923,11 +923,7 @@
 	head = NULL;
 	offset = PAGE_SIZE;
 	while ((offset -= size) >= 0) {
-		int pf_flags = current->flags;
-
-		current->flags |= PF_NOWARN;
 		bh = alloc_buffer_head();
-		current->flags = pf_flags;
 		if (!bh)
 			goto no_grow;
 
@@ -1453,6 +1449,7 @@
 	clear_buffer_mapped(bh);
 	clear_buffer_req(bh);
 	clear_buffer_new(bh);
+	clear_buffer_delay(bh);
 	unlock_buffer(bh);
 }
 
@@ -1871,7 +1868,7 @@
 				set_buffer_uptodate(bh);
 			continue; 
 		}
-		if (!buffer_uptodate(bh) &&
+		if (!buffer_uptodate(bh) && !buffer_delay(bh) &&
 		     (block_start < from || block_end > to)) {
 			ll_rw_block(READ, 1, &bh);
 			*wait_bh++=bh;
@@ -2457,7 +2454,7 @@
 	if (PageUptodate(page))
 		set_buffer_uptodate(bh);
 
-	if (!buffer_uptodate(bh)) {
+	if (!buffer_uptodate(bh) && !buffer_delay(bh)) {
 		err = -EIO;
 		ll_rw_block(READ, 1, &bh);
 		wait_on_buffer(bh);
diff -Nru a/fs/ext2/balloc.c b/fs/ext2/balloc.c
--- a/fs/ext2/balloc.c	Mon Dec 23 21:21:53 2002
+++ b/fs/ext2/balloc.c	Mon Dec 23 21:21:53 2002
@@ -315,9 +315,12 @@
     u32 * prealloc_count, u32 * prealloc_block, int * err)
 {
 	struct buffer_head *bitmap_bh = NULL;
-	struct buffer_head *bh2;
+	struct buffer_head *gdp_bh;	/* bh2 */
 	struct ext2_group_desc *desc;
-	int i, j, k, tmp;
+	int group_no;			/* i */
+	int ret_block;			/* j */
+	int bit;		/* k */
+	int target_block;		/* tmp */
 	int block = 0;
 	struct super_block *sb = inode->i_sb;
 	struct ext2_sb_info *sbi = EXT2_SB(sb);
@@ -353,82 +356,88 @@
 	if (goal < le32_to_cpu(es->s_first_data_block) ||
 	    goal >= le32_to_cpu(es->s_blocks_count))
 		goal = le32_to_cpu(es->s_first_data_block);
-	i = (goal - le32_to_cpu(es->s_first_data_block)) / group_size;
-	desc = ext2_get_group_desc (sb, i, &bh2);
+	group_no = (goal - le32_to_cpu(es->s_first_data_block)) / group_size;
+	desc = ext2_get_group_desc (sb, group_no, &gdp_bh);
 	if (!desc)
 		goto io_error;
 
-	group_alloc = group_reserve_blocks(desc, bh2, es_alloc);
+	group_alloc = group_reserve_blocks(desc, gdp_bh, es_alloc);
 	if (group_alloc) {
-		j = ((goal - le32_to_cpu(es->s_first_data_block)) % group_size);
+		ret_block = ((goal - le32_to_cpu(es->s_first_data_block)) %
+					group_size);
 		brelse(bitmap_bh);
-		bitmap_bh = read_block_bitmap(sb, i);
+		bitmap_bh = read_block_bitmap(sb, group_no);
 		if (!bitmap_bh)
 			goto io_error;
 		
-		ext2_debug ("goal is at %d:%d.\n", i, j);
+		ext2_debug("goal is at %d:%d.\n", group_no, ret_block);
 
-		j = grab_block(bitmap_bh->b_data, group_size, j);
-		if (j >= 0)
+		ret_block = grab_block(bitmap_bh->b_data,
+				group_size, ret_block);
+		if (ret_block >= 0)
 			goto got_block;
-		group_release_blocks(desc, bh2, group_alloc);
+		group_release_blocks(desc, gdp_bh, group_alloc);
 		group_alloc = 0;
 	}
 
-	ext2_debug ("Bit not found in block group %d.\n", i);
+	ext2_debug ("Bit not found in block group %d.\n", group_no);
 
 	/*
 	 * Now search the rest of the groups.  We assume that 
 	 * i and desc correctly point to the last group visited.
 	 */
-	for (k = 0; !group_alloc && k < sbi->s_groups_count; k++) {
-		i++;
-		if (i >= sbi->s_groups_count)
-			i = 0;
-		desc = ext2_get_group_desc (sb, i, &bh2);
+	for (bit = 0; !group_alloc &&
+			bit < sbi->s_groups_count; bit++) {
+		group_no++;
+		if (group_no >= sbi->s_groups_count)
+			group_no = 0;
+		desc = ext2_get_group_desc(sb, group_no, &gdp_bh);
 		if (!desc)
 			goto io_error;
-		group_alloc = group_reserve_blocks(desc, bh2, es_alloc);
+		group_alloc = group_reserve_blocks(desc, gdp_bh, es_alloc);
 	}
-	if (k >= sbi->s_groups_count)
+	if (bit >= sbi->s_groups_count)
 		goto out_release;
 	brelse(bitmap_bh);
-	bitmap_bh = read_block_bitmap(sb, i);
+	bitmap_bh = read_block_bitmap(sb, group_no);
 	if (!bitmap_bh)
 		goto io_error;
-	
-	j = grab_block(bitmap_bh->b_data, group_size, 0);
-	if (j < 0) {
+
+	ret_block = grab_block(bitmap_bh->b_data, group_size, 0);
+	if (ret_block < 0) {
 		ext2_error (sb, "ext2_new_block",
-			    "Free blocks count corrupted for block group %d", i);
+			"Free blocks count corrupted for block group %d",
+				group_no);
 		group_alloc = 0;
 		goto out_release;
 	}
 
 got_block:
-	ext2_debug("using block group %d(%d)\n", i, desc->bg_free_blocks_count);
+	ext2_debug("using block group %d(%d)\n",
+		group_no, desc->bg_free_blocks_count);
 
-	tmp = j + i * group_size + le32_to_cpu(es->s_first_data_block);
+	target_block = ret_block + group_no * group_size +
+			le32_to_cpu(es->s_first_data_block);
 
-	if (tmp == le32_to_cpu(desc->bg_block_bitmap) ||
-	    tmp == le32_to_cpu(desc->bg_inode_bitmap) ||
-	    in_range (tmp, le32_to_cpu(desc->bg_inode_table),
+	if (target_block == le32_to_cpu(desc->bg_block_bitmap) ||
+	    target_block == le32_to_cpu(desc->bg_inode_bitmap) ||
+	    in_range(target_block, le32_to_cpu(desc->bg_inode_table),
 		      sbi->s_itb_per_group))
 		ext2_error (sb, "ext2_new_block",
 			    "Allocating block in system zone - "
-			    "block = %u", tmp);
+			    "block = %u", target_block);
 
-	if (tmp >= le32_to_cpu(es->s_blocks_count)) {
+	if (target_block >= le32_to_cpu(es->s_blocks_count)) {
 		ext2_error (sb, "ext2_new_block",
 			    "block(%d) >= blocks count(%d) - "
-			    "block_group = %d, es == %p ",j,
-			le32_to_cpu(es->s_blocks_count), i, es);
+			    "block_group = %d, es == %p ", ret_block,
+			le32_to_cpu(es->s_blocks_count), group_no, es);
 		goto out_release;
 	}
-	block = tmp;
+	block = target_block;
 
 	/* OK, we _had_ allocated something */
-	ext2_debug ("found bit %d\n", j);
+	ext2_debug("found bit %d\n", ret_block);
 
 	dq_alloc--;
 	es_alloc--;
@@ -441,8 +450,8 @@
 	if (group_alloc && !*prealloc_count) {
 		unsigned n;
 
-		for (n = 0; n < group_alloc && ++j < group_size; n++) {
-			if (ext2_set_bit(j, bitmap_bh->b_data))
+		for (n = 0; n < group_alloc && ++ret_block < group_size; n++) {
+			if (ext2_set_bit(ret_block, bitmap_bh->b_data))
  				break;
 		}
 		*prealloc_block = block + 1;
@@ -462,7 +471,7 @@
 	ext2_debug ("allocating block %d. ", block);
 
 out_release:
-	group_release_blocks(desc, bh2, group_alloc);
+	group_release_blocks(desc, gdp_bh, group_alloc);
 	release_blocks(sb, es_alloc);
 	*err = 0;
 out_unlock:
diff -Nru a/fs/ext2/ext2.h b/fs/ext2/ext2.h
--- a/fs/ext2/ext2.h	Mon Dec 23 21:22:02 2002
+++ b/fs/ext2/ext2.h	Mon Dec 23 21:22:02 2002
@@ -14,8 +14,29 @@
 	__u32	i_file_acl;
 	__u32	i_dir_acl;
 	__u32	i_dtime;
+
+	/*
+	 * i_block_group is the number of the block group which contains
+	 * this file's inode.  Constant across the lifetime of the inode,
+	 * it is ued for making block allocation decisions - we try to
+	 * place a file's data blocks near its inode block, and new inodes
+	 * near to their parent directory's inode.
+	 */
 	__u32	i_block_group;
+
+	/*
+	 * i_next_alloc_block is the logical (file-relative) number of the
+	 * most-recently-allocated block in this file.  Yes, it is misnamed.
+	 * We use this for detecting linearly ascending allocation requests.
+	 */
 	__u32	i_next_alloc_block;
+
+	/*
+	 * i_next_alloc_goal is the *physical* companion to i_next_alloc_block.
+	 * it the the physical block number of the block which was most-recently
+	 * allocated to this file.  This give us the goal (target) for the next
+	 * allocation when we detect linearly ascending requests.
+	 */
 	__u32	i_next_alloc_goal;
 	__u32	i_prealloc_block;
 	__u32	i_prealloc_count;
diff -Nru a/fs/ext2/ialloc.c b/fs/ext2/ialloc.c
--- a/fs/ext2/ialloc.c	Mon Dec 23 21:21:55 2002
+++ b/fs/ext2/ialloc.c	Mon Dec 23 21:21:55 2002
@@ -388,24 +388,38 @@
 	 */
 	group = parent_group;
 	desc = ext2_get_group_desc (sb, group, &bh);
-	if (desc && le16_to_cpu(desc->bg_free_inodes_count))
+	if (desc && le16_to_cpu(desc->bg_free_inodes_count) &&
+			le16_to_cpu(desc->bg_free_blocks_count))
 		goto found;
 
 	/*
-	 * Use a quadratic hash to find a group with a
-	 * free inode
+	 * We're going to place this inode in a different blockgroup from its
+	 * parent.  We want to cause files in a common directory to all land in
+	 * the same blockgroup.  But we want files which are in a different
+	 * directory which shares a blockgroup with our parent to land in a
+	 * different blockgroup.
+	 *
+	 * So add our directory's i_ino into the starting point for the hash.
+	 */
+	group = (group + parent->i_ino) % ngroups;
+
+	/*
+	 * Use a quadratic hash to find a group with a free inode and some
+	 * free blocks.
 	 */
 	for (i = 1; i < ngroups; i <<= 1) {
 		group += i;
 		if (group >= ngroups)
 			group -= ngroups;
 		desc = ext2_get_group_desc (sb, group, &bh);
-		if (desc && le16_to_cpu(desc->bg_free_inodes_count))
+		if (desc && le16_to_cpu(desc->bg_free_inodes_count) &&
+				le16_to_cpu(desc->bg_free_blocks_count))
 			goto found;
 	}
 
 	/*
-	 * That failed: try linear search for a free inode
+	 * That failed: try linear search for a free inode, even if that group
+	 * has no free blocks.
 	 */
 	group = parent_group + 1;
 	for (i = 2; i < ngroups; i++) {
diff -Nru a/fs/ext2/inode.c b/fs/ext2/inode.c
--- a/fs/ext2/inode.c	Mon Dec 23 21:21:51 2002
+++ b/fs/ext2/inode.c	Mon Dec 23 21:21:51 2002
@@ -303,14 +303,22 @@
  *	  + if there is a block to the left of our position - allocate near it.
  *	  + if pointer will live in indirect block - allocate near that block.
  *	  + if pointer will live in inode - allocate in the same cylinder group.
+ *
+ * In the latter case we colour the starting block by the callers PID to
+ * prevent it from clashing with concurrent allocations for a different inode
+ * in the same block group.   The PID is used here so that functionally related
+ * files will be close-by on-disk.
+ *
  *	Caller must make sure that @ind is valid and will stay that way.
  */
 
-static inline unsigned long ext2_find_near(struct inode *inode, Indirect *ind)
+static unsigned long ext2_find_near(struct inode *inode, Indirect *ind)
 {
 	struct ext2_inode_info *ei = EXT2_I(inode);
 	u32 *start = ind->bh ? (u32*) ind->bh->b_data : ei->i_data;
 	u32 *p;
+	unsigned long bg_start;
+	unsigned long colour;
 
 	/* Try to find previous block */
 	for (p = ind->p - 1; p >= start; p--)
@@ -325,8 +333,11 @@
 	 * It is going to be refered from inode itself? OK, just put it into
 	 * the same cylinder group then.
 	 */
-	return (ei->i_block_group * EXT2_BLOCKS_PER_GROUP(inode->i_sb)) +
-	       le32_to_cpu(EXT2_SB(inode->i_sb)->s_es->s_first_data_block);
+	bg_start = (ei->i_block_group * EXT2_BLOCKS_PER_GROUP(inode->i_sb)) +
+		le32_to_cpu(EXT2_SB(inode->i_sb)->s_es->s_first_data_block);
+	colour = (current->pid % 16) *
+			(EXT2_BLOCKS_PER_GROUP(inode->i_sb) / 16);
+	return bg_start + colour;
 }
 
 /**
diff -Nru a/fs/ext3/ialloc.c b/fs/ext3/ialloc.c
--- a/fs/ext3/ialloc.c	Mon Dec 23 21:21:55 2002
+++ b/fs/ext3/ialloc.c	Mon Dec 23 21:21:55 2002
@@ -356,24 +356,38 @@
 	 */
 	group = parent_group;
 	desc = ext3_get_group_desc (sb, group, &bh);
-	if (desc && le16_to_cpu(desc->bg_free_inodes_count))
+	if (desc && le16_to_cpu(desc->bg_free_inodes_count) &&
+			le16_to_cpu(desc->bg_free_blocks_count))
 		return group;
 
 	/*
-	 * Use a quadratic hash to find a group with a
-	 * free inode
+	 * We're going to place this inode in a different blockgroup from its
+	 * parent.  We want to cause files in a common directory to all land in
+	 * the same blockgroup.  But we want files which are in a different
+	 * directory which shares a blockgroup with our parent to land in a
+	 * different blockgroup.
+	 *
+	 * So add our directory's i_ino into the starting point for the hash.
+	 */
+	group = (group + parent->i_ino) % ngroups;
+
+	/*
+	 * Use a quadratic hash to find a group with a free inode and some free
+	 * blocks.
 	 */
 	for (i = 1; i < ngroups; i <<= 1) {
 		group += i;
 		if (group >= ngroups)
 			group -= ngroups;
 		desc = ext3_get_group_desc (sb, group, &bh);
-		if (desc && le16_to_cpu(desc->bg_free_inodes_count))
+		if (desc && le16_to_cpu(desc->bg_free_inodes_count) &&
+				le16_to_cpu(desc->bg_free_blocks_count))
 			return group;
 	}
 
 	/*
-	 * That failed: try linear search for a free inode
+	 * That failed: try linear search for a free inode, even if that group
+	 * has no free blocks.
 	 */
 	group = parent_group + 1;
 	for (i = 2; i < ngroups; i++) {
diff -Nru a/fs/ext3/inode.c b/fs/ext3/inode.c
--- a/fs/ext3/inode.c	Mon Dec 23 21:21:58 2002
+++ b/fs/ext3/inode.c	Mon Dec 23 21:21:58 2002
@@ -40,13 +40,6 @@
 #include "acl.h"
 
 /*
- * SEARCH_FROM_ZERO forces each block allocation to search from the start
- * of the filesystem.  This is to force rapid reallocation of recently-freed
- * blocks.  The file fragmentation is horrendous.
- */
-#undef SEARCH_FROM_ZERO
-
-/*
  * Test whether an inode is a fast symlink.
  */
 static inline int ext3_inode_is_fast_symlink(struct inode *inode)
@@ -462,14 +455,22 @@
  *	  + if pointer will live in indirect block - allocate near that block.
  *	  + if pointer will live in inode - allocate in the same
  *	    cylinder group. 
+ *
+ * In the latter case we colour the starting block by the callers PID to
+ * prevent it from clashing with concurrent allocations for a different inode
+ * in the same block group.   The PID is used here so that functionally related
+ * files will be close-by on-disk.
+ *
  *	Caller must make sure that @ind is valid and will stay that way.
  */
 
-static inline unsigned long ext3_find_near(struct inode *inode, Indirect *ind)
+static unsigned long ext3_find_near(struct inode *inode, Indirect *ind)
 {
 	struct ext3_inode_info *ei = EXT3_I(inode);
 	u32 *start = ind->bh ? (u32*) ind->bh->b_data : ei->i_data;
 	u32 *p;
+	unsigned long bg_start;
+	unsigned long colour;
 
 	/* Try to find previous block */
 	for (p = ind->p - 1; p >= start; p--)
@@ -484,8 +485,11 @@
 	 * It is going to be refered from inode itself? OK, just put it into
 	 * the same cylinder group then.
 	 */
-	return (ei->i_block_group * EXT3_BLOCKS_PER_GROUP(inode->i_sb)) +
-	       le32_to_cpu(EXT3_SB(inode->i_sb)->s_es->s_first_data_block);
+	bg_start = (ei->i_block_group * EXT3_BLOCKS_PER_GROUP(inode->i_sb)) +
+		le32_to_cpu(EXT3_SB(inode->i_sb)->s_es->s_first_data_block);
+	colour = (current->pid % 16) *
+			(EXT3_BLOCKS_PER_GROUP(inode->i_sb) / 16);
+	return bg_start + colour;
 }
 
 /**
@@ -510,10 +514,6 @@
 		ei->i_next_alloc_block++;
 		ei->i_next_alloc_goal++;
 	}
-#ifdef SEARCH_FROM_ZERO
-	ei->i_next_alloc_block = 0;
-	ei->i_next_alloc_goal = 0;
-#endif
 	/* Writer: end */
 	/* Reader: pointers, ->i_next_alloc* */
 	if (verify_chain(chain, partial)) {
@@ -525,9 +525,6 @@
 			*goal = ei->i_next_alloc_goal;
 		if (!*goal)
 			*goal = ext3_find_near(inode, partial);
-#ifdef SEARCH_FROM_ZERO
-		*goal = 0;
-#endif
 		return 0;
 	}
 	/* Reader: end */
@@ -673,10 +670,6 @@
 	*where->p = where->key;
 	ei->i_next_alloc_block = block;
 	ei->i_next_alloc_goal = le32_to_cpu(where[num-1].key);
-#ifdef SEARCH_FROM_ZERO
-	ei->i_next_alloc_block = 0;
-	ei->i_next_alloc_goal = 0;
-#endif
 	/* Writer: end */
 
 	/* We are done with atomic stuff, now do the rest of housekeeping */
diff -Nru a/fs/ext3/namei.c b/fs/ext3/namei.c
--- a/fs/ext3/namei.c	Mon Dec 23 21:21:56 2002
+++ b/fs/ext3/namei.c	Mon Dec 23 21:21:56 2002
@@ -1566,8 +1566,11 @@
 {
 	int err = ext3_add_entry(handle, dentry, inode);
 	if (!err) {
-		d_instantiate(dentry, inode);
-		return 0;
+		err = ext3_mark_inode_dirty(handle, inode);
+		if (!err) {
+			d_instantiate(dentry, inode);
+			return 0;
+		}
 	}
 	ext3_dec_count(handle, inode);
 	iput(inode);
@@ -1609,7 +1612,6 @@
 		else
 			inode->i_mapping->a_ops = &ext3_aops;
 		err = ext3_add_nondir(handle, dentry, inode);
-		ext3_mark_inode_dirty(handle, inode);
 	}
 	ext3_journal_stop(handle, dir);
 	unlock_kernel();
@@ -1642,7 +1644,6 @@
 		inode->i_op = &ext3_special_inode_operations;
 #endif
 		err = ext3_add_nondir(handle, dentry, inode);
-		ext3_mark_inode_dirty(handle, inode);
 	}
 	ext3_journal_stop(handle, dir);
 	unlock_kernel();
@@ -2105,7 +2106,6 @@
 	}
 	EXT3_I(inode)->i_disksize = inode->i_size;
 	err = ext3_add_nondir(handle, dentry, inode);
-	ext3_mark_inode_dirty(handle, inode);
 out_stop:
 	ext3_journal_stop(handle, dir);
 	unlock_kernel();
@@ -2140,7 +2140,6 @@
 	atomic_inc(&inode->i_count);
 
 	err = ext3_add_nondir(handle, dentry, inode);
-	ext3_mark_inode_dirty(handle, inode);
 	ext3_journal_stop(handle, dir);
 	unlock_kernel();
 	return err;
diff -Nru a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
--- a/fs/hugetlbfs/inode.c	Mon Dec 23 21:22:00 2002
+++ b/fs/hugetlbfs/inode.c	Mon Dec 23 21:22:00 2002
@@ -44,6 +44,7 @@
 {
 	struct inode *inode =file->f_dentry->d_inode;
 	struct address_space *mapping = inode->i_mapping;
+	size_t len;
 	int ret;
 
 	if (!capable(CAP_IPC_LOCK))
@@ -64,9 +65,11 @@
 	vma->vm_flags |= VM_HUGETLB | VM_RESERVED;
 	vma->vm_ops = &hugetlb_vm_ops;
 	ret = hugetlb_prefault(mapping, vma);
+	len = (vma->vm_end - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
+	if (inode->i_size < len)
+		inode->i_size = len;
 
 	up(&inode->i_sem);
-
 	return ret;
 }
 
diff -Nru a/fs/intermezzo/Makefile b/fs/intermezzo/Makefile
--- a/fs/intermezzo/Makefile	Mon Dec 23 21:21:58 2002
+++ b/fs/intermezzo/Makefile	Mon Dec 23 21:21:58 2002
@@ -5,7 +5,7 @@
 obj-$(CONFIG_INTERMEZZO_FS) += intermezzo.o
 
 intermezzo-objs := cache.o dcache.o dir.o ext_attr.o file.o fileset.o \
-	           inode.o io_daemon.o journal.o journal_ext2.o journal_ext3.o \
+	           inode.o journal.o journal_ext2.o journal_ext3.o \
 	           journal_obdfs.o journal_reiserfs.o journal_tmpfs.o journal_xfs.o \
 	           kml_reint.o kml_unpack.o methods.o presto.o psdev.o replicator.o \
 	           super.o sysctl.o upcall.o vfs.o
diff -Nru a/fs/jbd/transaction.c b/fs/jbd/transaction.c
--- a/fs/jbd/transaction.c	Mon Dec 23 21:21:52 2002
+++ b/fs/jbd/transaction.c	Mon Dec 23 21:21:52 2002
@@ -2042,23 +2042,30 @@
 
 void __journal_refile_buffer(struct journal_head *jh)
 {
+	int was_dirty;
+
 	assert_spin_locked(&journal_datalist_lock);
-#ifdef __SMP__
-	J_ASSERT_JH(jh, current->lock_depth >= 0);
-#endif
-	__journal_unfile_buffer(jh);
+	J_ASSERT_JH(jh, kernel_locked());
 
-	/* If the buffer is now unused, just drop it.  If it has been
-	   modified by a later transaction, add it to the new
-	   transaction's metadata list. */
+	/* If the buffer is now unused, just drop it. */
+	if (jh->b_next_transaction == NULL) {
+		__journal_unfile_buffer(jh);
+		jh->b_transaction = NULL;
+		return;
+	}
+	
+	/* It has been modified by a later transaction: add it to the
+	 * new transaction's metadata list. */
 
+	was_dirty = test_clear_buffer_jbddirty(jh2bh(jh));
+	__journal_unfile_buffer(jh);
 	jh->b_transaction = jh->b_next_transaction;
 	jh->b_next_transaction = NULL;
+	__journal_file_buffer(jh, jh->b_transaction, BJ_Metadata);
+	J_ASSERT_JH(jh, jh->b_transaction->t_state == T_RUNNING);
 
-	if (jh->b_transaction != NULL) {
-		__journal_file_buffer(jh, jh->b_transaction, BJ_Metadata);
-		J_ASSERT_JH(jh, jh->b_transaction->t_state == T_RUNNING);
-	}
+	if (was_dirty)
+		set_buffer_jbddirty(jh2bh(jh));
 }
 
 /*
diff -Nru a/fs/jffs/inode-v23.c b/fs/jffs/inode-v23.c
--- a/fs/jffs/inode-v23.c	Mon Dec 23 21:21:56 2002
+++ b/fs/jffs/inode-v23.c	Mon Dec 23 21:21:56 2002
@@ -1641,7 +1641,7 @@
 	.read		= generic_file_read,
 	.write		= generic_file_write,
 	.ioctl		= jffs_ioctl,
-	.mmap		= generic_file_mmap,
+	.mmap		= generic_file_readonly_mmap,
 	.fsync		= jffs_fsync,
 	.sendfile	= generic_file_sendfile,
 };
diff -Nru a/fs/jffs2/file.c b/fs/jffs2/file.c
--- a/fs/jffs2/file.c	Mon Dec 23 21:22:02 2002
+++ b/fs/jffs2/file.c	Mon Dec 23 21:22:02 2002
@@ -58,7 +58,7 @@
 	.read =		generic_file_read,
 	.write =	generic_file_write,
 	.ioctl =	jffs2_ioctl,
-	.mmap =		generic_file_mmap,
+	.mmap =		generic_file_readonly_mmap,
 	.fsync =	jffs2_fsync,
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,29)
 	.sendfile =	generic_file_sendfile
diff -Nru a/fs/nfs/dir.c b/fs/nfs/dir.c
--- a/fs/nfs/dir.c	Mon Dec 23 21:21:55 2002
+++ b/fs/nfs/dir.c	Mon Dec 23 21:21:55 2002
@@ -208,7 +208,7 @@
 
 	/* NOTE: Someone else may have changed the READDIRPLUS flag */
 	desc->page = page;
-	desc->ptr = kmap(page);
+	desc->ptr = kmap(page);		/* matching kunmap in nfs_do_filldir */
 	status = find_dirent(desc, page);
 	if (status < 0)
 		dir_page_release(desc);
@@ -345,7 +345,7 @@
 						NFS_SERVER(inode)->dtsize,
 						desc->plus);
 	desc->page = page;
-	desc->ptr = kmap(page);
+	desc->ptr = kmap(page);		/* matching kunmap in nfs_do_filldir */
 	if (desc->error >= 0) {
 		if ((status = dir_decode(desc)) == 0)
 			desc->entry->prev_cookie = desc->target;
@@ -717,9 +717,9 @@
 
 		res = -EIO;
 		if (PageUptodate(page)) {
-			desc.ptr = kmap(page);
+			desc.ptr = kmap_atomic(page, KM_USER0);
 			res = find_dirent_name(&desc, page, dentry);
-			kunmap(page);
+			kunmap_atomic(desc.ptr, KM_USER0);
 		}
 		page_cache_release(page);
 
diff -Nru a/fs/nfs/file.c b/fs/nfs/file.c
--- a/fs/nfs/file.c	Mon Dec 23 21:21:58 2002
+++ b/fs/nfs/file.c	Mon Dec 23 21:21:58 2002
@@ -168,6 +168,7 @@
 struct address_space_operations nfs_file_aops = {
 	.readpage = nfs_readpage,
 	.readpages = nfs_readpages,
+	.set_page_dirty = __set_page_dirty_nobuffers,
 	.writepage = nfs_writepage,
 	.writepages = nfs_writepages,
 	.prepare_write = nfs_prepare_write,
diff -Nru a/fs/nfs/nfs2xdr.c b/fs/nfs/nfs2xdr.c
--- a/fs/nfs/nfs2xdr.c	Mon Dec 23 21:21:53 2002
+++ b/fs/nfs/nfs2xdr.c	Mon Dec 23 21:21:53 2002
@@ -378,7 +378,7 @@
 	int hdrlen, recvd;
 	int status, nr;
 	unsigned int len, pglen;
-	u32 *end, *entry;
+	u32 *end, *entry, *kaddr;
 
 	if ((status = ntohl(*p++)))
 		return -nfs_stat_to_errno(status);
@@ -398,7 +398,7 @@
 	if (pglen > recvd)
 		pglen = recvd;
 	page = rcvbuf->pages;
-	p = kmap(*page);
+	kaddr = p = (u32 *)kmap_atomic(*page, KM_USER0);
 	end = (u32 *)((char *)p + pglen);
 	entry = p;
 	for (nr = 0; *p++; nr++) {
@@ -419,7 +419,7 @@
 	if (!nr && (entry[0] != 0 || entry[1] == 0))
 		goto short_pkt;
  out:
-	kunmap(*page);
+	kunmap_atomic(kaddr, KM_USER0);
 	return nr;
  short_pkt:
 	entry[0] = entry[1] = 0;
@@ -430,8 +430,8 @@
 	}
 	goto out;
 err_unmap:
-	kunmap(*page);
-	return -errno_NFSERR_IO;
+	nr = -errno_NFSERR_IO;
+	goto out;
 }
 
 u32 *
@@ -542,7 +542,7 @@
 		xdr_shift_buf(rcvbuf, iov->iov_len - hdrlen);
 	}
 
-	strlen = (u32*)kmap(rcvbuf->pages[0]);
+	strlen = (u32*)kmap_atomic(rcvbuf->pages[0], KM_USER0);
 	/* Convert length of symlink */
 	len = ntohl(*strlen);
 	if (len > rcvbuf->page_len)
@@ -551,7 +551,7 @@
 	/* NULL terminate the string we got */
 	string = (char *)(strlen + 1);
 	string[len] = 0;
-	kunmap(rcvbuf->pages[0]);
+	kunmap_atomic(strlen, KM_USER0);
 	return 0;
 }
 
diff -Nru a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c
--- a/fs/nfs/nfs3proc.c	Mon Dec 23 21:21:55 2002
+++ b/fs/nfs/nfs3proc.c	Mon Dec 23 21:21:55 2002
@@ -67,6 +67,20 @@
 	return 1;
 }
 
+static void
+nfs3_write_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
+{
+	if (fattr->valid & NFS_ATTR_FATTR) {
+		if (!(fattr->valid & NFS_ATTR_WCC)) {
+			fattr->pre_size  = NFS_CACHE_ISIZE(inode);
+			fattr->pre_mtime = NFS_CACHE_MTIME(inode);
+			fattr->pre_ctime = NFS_CACHE_CTIME(inode);
+			fattr->valid |= NFS_ATTR_WCC;
+		}
+		nfs_refresh_inode(inode, fattr);
+	}
+}
+
 /*
  * Bare-bones access to getattr: this is for nfs_read_super.
  */
@@ -239,6 +253,8 @@
 	dprintk("NFS call  read %d @ %Ld\n", count, (long long)offset);
 	fattr->valid = 0;
 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
+	if (status >= 0)
+		nfs_refresh_inode(inode, fattr);
 	dprintk("NFS reply read: %d\n", status);
 	*eofp = res.eof;
 	return status;
@@ -279,6 +295,9 @@
 
 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, rpcflags);
 
+	if (status >= 0)
+		nfs3_write_refresh_inode(inode, fattr);
+
 	dprintk("NFS reply read: %d\n", status);
 	return status < 0? status : res.count;
 }
@@ -685,11 +704,14 @@
 static void
 nfs3_read_done(struct rpc_task *task)
 {
-	struct nfs_read_data *data = (struct nfs_read_data *) task->tk_calldata;
+	struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
 
 	if (nfs3_async_handle_jukebox(task))
 		return;
-	nfs_readpage_result(task, data->u.v3.res.count, data->u.v3.res.eof);
+	/* Call back common NFS readpage processing */
+	if (task->tk_status >= 0)
+		nfs_refresh_inode(data->inode, &data->fattr);
+	nfs_readpage_result(task);
 }
 
 static void
@@ -701,20 +723,20 @@
 	int			flags;
 	struct rpc_message	msg = {
 		.rpc_proc	= &nfs3_procedures[NFS3PROC_READ],
-		.rpc_argp	= &data->u.v3.args,
-		.rpc_resp	= &data->u.v3.res,
+		.rpc_argp	= &data->args,
+		.rpc_resp	= &data->res,
 		.rpc_cred	= data->cred,
 	};
 	
 	req = nfs_list_entry(data->pages.next);
-	data->u.v3.args.fh     = NFS_FH(inode);
-	data->u.v3.args.offset = req_offset(req) + req->wb_offset;
-	data->u.v3.args.pgbase = req->wb_offset;
-	data->u.v3.args.pages  = data->pagevec;
-	data->u.v3.args.count  = count;
-	data->u.v3.res.fattr   = &data->fattr;
-	data->u.v3.res.count   = count;
-	data->u.v3.res.eof     = 0;
+	data->args.fh     = NFS_FH(inode);
+	data->args.offset = req_offset(req);
+	data->args.pgbase = req->wb_offset;
+	data->args.pages  = data->pagevec;
+	data->args.count  = count;
+	data->res.fattr   = &data->fattr;
+	data->res.count   = count;
+	data->res.eof     = 0;
 	
 	/* N.B. Do we need to test? Never called for swapfile inode */
 	flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
@@ -735,8 +757,9 @@
 
 	if (nfs3_async_handle_jukebox(task))
 		return;
-	nfs_writeback_done(task, data->u.v3.args.stable,
-			   data->u.v3.args.count, data->u.v3.res.count);
+	if (task->tk_status >= 0)
+		nfs3_write_refresh_inode(data->inode, data->res.fattr);
+	nfs_writeback_done(task);
 }
 
 static void
@@ -749,8 +772,8 @@
 	int			flags;
 	struct rpc_message	msg = {
 		.rpc_proc	= &nfs3_procedures[NFS3PROC_WRITE],
-		.rpc_argp	= &data->u.v3.args,
-		.rpc_resp	= &data->u.v3.res,
+		.rpc_argp	= &data->args,
+		.rpc_resp	= &data->res,
 		.rpc_cred	= data->cred,
 	};
 
@@ -763,15 +786,15 @@
 		stable = NFS_UNSTABLE;
 	
 	req = nfs_list_entry(data->pages.next);
-	data->u.v3.args.fh     = NFS_FH(inode);
-	data->u.v3.args.offset = req_offset(req) + req->wb_offset;
-	data->u.v3.args.pgbase = req->wb_offset;
-	data->u.v3.args.count  = count;
-	data->u.v3.args.stable = stable;
-	data->u.v3.args.pages  = data->pagevec;
-	data->u.v3.res.fattr   = &data->fattr;
-	data->u.v3.res.count   = count;
-	data->u.v3.res.verf    = &data->verf;
+	data->args.fh     = NFS_FH(inode);
+	data->args.offset = req_offset(req);
+	data->args.pgbase = req->wb_offset;
+	data->args.count  = count;
+	data->args.stable = stable;
+	data->args.pages  = data->pagevec;
+	data->res.fattr   = &data->fattr;
+	data->res.count   = count;
+	data->res.verf    = &data->verf;
 
 	/* Set the initial flags for the task.  */
 	flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
@@ -788,8 +811,12 @@
 static void
 nfs3_commit_done(struct rpc_task *task)
 {
+	struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
+
 	if (nfs3_async_handle_jukebox(task))
 		return;
+	if (task->tk_status >= 0)
+		nfs3_write_refresh_inode(data->inode, data->res.fattr);
 	nfs_commit_done(task);
 }
 
@@ -801,17 +828,17 @@
 	int			flags;
 	struct rpc_message	msg = {
 		.rpc_proc	= &nfs3_procedures[NFS3PROC_COMMIT],
-		.rpc_argp	= &data->u.v3.args,
-		.rpc_resp	= &data->u.v3.res,
+		.rpc_argp	= &data->args,
+		.rpc_resp	= &data->res,
 		.rpc_cred	= data->cred,
 	};
 
-	data->u.v3.args.fh     = NFS_FH(data->inode);
-	data->u.v3.args.offset = start;
-	data->u.v3.args.count  = len;
-	data->u.v3.res.count   = len;
-	data->u.v3.res.fattr   = &data->fattr;
-	data->u.v3.res.verf    = &data->verf;
+	data->args.fh     = NFS_FH(data->inode);
+	data->args.offset = start;
+	data->args.count  = len;
+	data->res.count   = len;
+	data->res.fattr   = &data->fattr;
+	data->res.verf    = &data->verf;
 	
 	/* Set the initial flags for the task.  */
 	flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
diff -Nru a/fs/nfs/nfs3xdr.c b/fs/nfs/nfs3xdr.c
--- a/fs/nfs/nfs3xdr.c	Mon Dec 23 21:22:02 2002
+++ b/fs/nfs/nfs3xdr.c	Mon Dec 23 21:22:02 2002
@@ -488,7 +488,7 @@
 	int hdrlen, recvd;
 	int status, nr;
 	unsigned int len, pglen;
-	u32 *entry, *end;
+	u32 *entry, *end, *kaddr;
 
 	status = ntohl(*p++);
 	/* Decode post_op_attrs */
@@ -518,7 +518,7 @@
 	if (pglen > recvd)
 		pglen = recvd;
 	page = rcvbuf->pages;
-	p = kmap(*page);
+	kaddr = p = (u32 *)kmap_atomic(*page, KM_USER0);
 	end = (u32 *)((char *)p + pglen);
 	entry = p;
 	for (nr = 0; *p++; nr++) {
@@ -563,7 +563,7 @@
 	if (!nr && (entry[0] != 0 || entry[1] == 0))
 		goto short_pkt;
  out:
-	kunmap(*page);
+	kunmap_atomic(kaddr, KM_USER0);
 	return nr;
  short_pkt:
 	entry[0] = entry[1] = 0;
@@ -574,8 +574,8 @@
 	}
 	goto out;
 err_unmap:
-	kunmap(*page);
-	return -errno_NFSERR_IO;
+	nr = -errno_NFSERR_IO;
+	goto out;
 }
 
 u32 *
@@ -738,7 +738,7 @@
 		xdr_shift_buf(rcvbuf, iov->iov_len - hdrlen);
 	}
 
-	strlen = (u32*)kmap(rcvbuf->pages[0]);
+	strlen = (u32*)kmap_atomic(rcvbuf->pages[0], KM_USER0);
 	/* Convert length of symlink */
 	len = ntohl(*strlen);
 	if (len > rcvbuf->page_len)
@@ -747,7 +747,7 @@
 	/* NULL terminate the string we got */
 	string = (char *)(strlen + 1);
 	string[len] = 0;
-	kunmap(rcvbuf->pages[0]);
+	kunmap_atomic(strlen, KM_USER0);
 	return 0;
 }
 
diff -Nru a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
--- a/fs/nfs/nfs4proc.c	Mon Dec 23 21:21:58 2002
+++ b/fs/nfs/nfs4proc.c	Mon Dec 23 21:21:58 2002
@@ -94,19 +94,6 @@
 }
 
 static void
-nfs4_setup_commit(struct nfs4_compound *cp, u64 start, u32 len, struct nfs_writeverf *verf)
-{
-	struct nfs4_commit *commit = GET_OP(cp, commit);
-
-	commit->co_start = start;
-	commit->co_len = len;
-	commit->co_verifier = verf;
-
-	OPNUM(cp) = OP_COMMIT;
-	cp->req_nops++;
-}
-
-static void
 nfs4_setup_create_dir(struct nfs4_compound *cp, struct qstr *name,
 		      struct iattr *sattr, struct nfs4_change_info *info)
 {
@@ -402,23 +389,6 @@
 }
 
 static void
-nfs4_setup_read(struct nfs4_compound *cp, u64 offset, u32 length,
-		struct page **pages, unsigned int pgbase, u32 *eofp, u32 *bytes_read)
-{
-	struct nfs4_read *read = GET_OP(cp, read);
-
-	read->rd_offset = offset;
-	read->rd_length = length;
-	read->rd_pages = pages;
-	read->rd_pgbase = pgbase;
-	read->rd_eof = eofp;
-	read->rd_bytes_read = bytes_read;
-
-	OPNUM(cp) = OP_READ;
-	cp->req_nops++;
-}
-
-static void
 nfs4_setup_readdir(struct nfs4_compound *cp, u64 cookie, u32 *verifier,
 		     struct page **pages, unsigned int bufsize, struct dentry *dentry)
 {
@@ -447,7 +417,7 @@
 	 * when talking to the server, we always send cookie 0
 	 * instead of 1 or 2.
 	 */
-	start = p = (u32 *)kmap(*pages);
+	start = p = (u32 *)kmap_atomic(*pages, KM_USER0);
 	
 	if (cookie == 0) {
 		*p++ = xdr_one;                                  /* next */
@@ -475,7 +445,7 @@
 
 	readdir->rd_pgbase = (char *)p - (char *)start;
 	readdir->rd_count -= readdir->rd_pgbase;
-	kunmap(*pages);
+	kunmap_atomic(start, KM_USER0);
 }
 
 static void
@@ -594,30 +564,17 @@
 }
 
 static void
-nfs4_setup_write(struct nfs4_compound *cp, u64 offset, u32 length, int stable,
-		 struct page **pages, unsigned int pgbase, u32 *bytes_written,
-		 struct nfs_writeverf *verf)
-{
-	struct nfs4_write *write = GET_OP(cp, write);
-
-	write->wr_offset = offset;
-	write->wr_stable_how = stable;
-	write->wr_len = length;
-	write->wr_bytes_written = bytes_written;
-	write->wr_verf = verf;
-
-	write->wr_pages = pages;
-	write->wr_pgbase = pgbase;
-
-	OPNUM(cp) = OP_WRITE;
-	cp->req_nops++;
+renew_lease(struct nfs_server *server, unsigned long timestamp)
+{
+	spin_lock(&renew_lock);
+	if (time_before(server->last_renewal,timestamp))
+		server->last_renewal = timestamp;
+	spin_unlock(&renew_lock);
 }
 
 static inline void
 process_lease(struct nfs4_compound *cp)
 {
-	struct nfs_server *server;
-	
         /*
          * Generic lease processing: If this operation contains a
 	 * lease-renewing operation, and it succeeded, update the RENEW time
@@ -634,13 +591,8 @@
          */
 	if (!cp->renew_index)
 		return;
-	if (!cp->toplevel_status || cp->resp_nops > cp->renew_index) {
-		server = cp->server;
-		spin_lock(&renew_lock);
-		if (server->last_renewal < cp->timestamp)
-			server->last_renewal = cp->timestamp;
-		spin_unlock(&renew_lock);
-	}
+	if (!cp->toplevel_status || cp->resp_nops > cp->renew_index)
+		renew_lease(cp->server, cp->timestamp);
 }
 
 static int
@@ -1003,20 +955,39 @@
 	       unsigned int base, unsigned int count,
 	       struct page *page, int *eofp)
 {
-	u64			offset = page_offset(page) + base;
-	struct nfs4_compound	compound;
-	struct nfs4_op		ops[2];
-	u32			bytes_read;
-	int			status;
+	struct nfs_server *server = NFS_SERVER(inode);
+	uint64_t offset = page_offset(page) + base;
+	struct nfs_readargs arg = {
+		.fh		= NFS_FH(inode),
+		.offset		= offset,
+		.count		= count,
+		.pgbase		= base,
+		.pages		= &page,
+	};
+	struct nfs_readres res = {
+		.fattr		= fattr,
+		.count		= count,
+	};
+	struct rpc_message msg = {
+		.rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_READ],
+		.rpc_argp	= &arg,
+		.rpc_resp	= &res,
+		.rpc_cred	= cred,
+	};
+	unsigned long timestamp = jiffies;
+	int status;
 
+	dprintk("NFS call  read %d @ %Ld\n", count, (long long)offset);
 	fattr->valid = 0;
-	nfs4_setup_compound(&compound, ops, NFS_SERVER(inode), "read [sync]");
-	nfs4_setup_putfh(&compound, NFS_FH(inode));
-	nfs4_setup_read(&compound, offset, count, &page, base, eofp, &bytes_read);
-	status = nfs4_call_compound(&compound, cred, 0);
-
-	if (status >= 0)
-		status = bytes_read;
+	status = rpc_call_sync(server->client, &msg, flags);
+	if (!status) {
+		renew_lease(server, timestamp);
+		/* Check cache consistency */
+		if (fattr->change_attr != NFS_CHANGE_ATTR(inode))
+			nfs_zap_caches(inode);
+	}
+	dprintk("NFS reply read: %d\n", status);
+	*eofp = res.eof;
 	return status;
 }
 
@@ -1026,23 +997,32 @@
 		unsigned int base, unsigned int count,
 		struct page *page, struct nfs_writeverf *verf)
 {
-	u64			offset = page_offset(page) + base;
-	struct nfs4_compound	compound;
-	struct nfs4_op		ops[2];
-	u32			bytes_written;
-	int			stable = (flags & NFS_RW_SYNC) ? NFS_FILE_SYNC : NFS_UNSTABLE;
+	struct nfs_server *server = NFS_SERVER(inode);
+	uint64_t offset = page_offset(page) + base;
+	struct nfs_writeargs arg = {
+		.fh		= NFS_FH(inode),
+		.offset		= offset,
+		.count		= count,
+		.stable		= (flags & NFS_RW_SYNC) ? NFS_FILE_SYNC : NFS_UNSTABLE,
+		.pgbase		= base,
+		.pages		= &page,
+	};
+	struct nfs_writeres res = {
+		.fattr		= fattr,
+		.count		= count,
+		.verf		= verf,
+	};
+	struct rpc_message msg = {
+		.rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_WRITE],
+		.rpc_argp	= &arg,
+		.rpc_resp	= &res,
+		.rpc_cred	= cred,
+	};
 	int			rpcflags = (flags & NFS_RW_SWAP) ? NFS_RPC_SWAPFLAGS : 0;
-	int			status;
 
+	dprintk("NFS call  write %d @ %Ld\n", count, (long long)offset);
 	fattr->valid = 0;
-	nfs4_setup_compound(&compound, ops, NFS_SERVER(inode), "write [sync]");
-	nfs4_setup_putfh(&compound, NFS_FH(inode));
-	nfs4_setup_write(&compound, offset, count, stable, &page, base, &bytes_written, verf);
-	status = nfs4_call_compound(&compound, cred, rpcflags);
-	
-	if (status >= 0)
-		status = bytes_written;
-	return status;
+	return rpc_call_sync(server->client, &msg, rpcflags);
 }
 
 static int
@@ -1362,32 +1342,43 @@
 nfs4_read_done(struct rpc_task *task)
 {
 	struct nfs_read_data *data = (struct nfs_read_data *) task->tk_calldata;
+	struct inode *inode = data->inode;
+	struct nfs_fattr *fattr = data->res.fattr;
 
-	process_lease(&data->u.v4.compound);
-	nfs_readpage_result(task, data->u.v4.res_count, data->u.v4.res_eof);
+	if (task->tk_status > 0)
+		renew_lease(NFS_SERVER(inode), data->timestamp);
+	/* Check cache consistency */
+	if (fattr->change_attr != NFS_CHANGE_ATTR(inode))
+		nfs_zap_caches(inode);
+	if (fattr->bitmap[1] & FATTR4_WORD1_TIME_ACCESS)
+		inode->i_atime = fattr->atime;
+	/* Call back common NFS readpage processing */
+	nfs_readpage_result(task);
 }
 
 static void
 nfs4_proc_read_setup(struct nfs_read_data *data, unsigned int count)
 {
 	struct rpc_task	*task = &data->task;
-	struct nfs4_compound *cp = &data->u.v4.compound;
 	struct rpc_message msg = {
-		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMPOUND],
-		.rpc_argp = cp,
-		.rpc_resp = cp,
+		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ],
+		.rpc_argp = &data->args,
+		.rpc_resp = &data->res,
 		.rpc_cred = data->cred,
 	};
 	struct inode *inode = data->inode;
 	struct nfs_page *req = nfs_list_entry(data->pages.next);
 	int flags;
 
-	nfs4_setup_compound(cp, data->u.v4.ops, NFS_SERVER(inode), "read [async]");
-	nfs4_setup_putfh(cp, NFS_FH(inode));
-	nfs4_setup_read(cp, req_offset(req) + req->wb_offset,
-			count, data->pagevec, req->wb_offset,
-			&data->u.v4.res_eof,
-			&data->u.v4.res_count);
+	data->args.fh     = NFS_FH(inode);
+	data->args.offset = req_offset(req);
+	data->args.pgbase = req->wb_offset;
+	data->args.pages  = data->pagevec;
+	data->args.count  = count;
+	data->res.fattr   = &data->fattr;
+	data->res.count   = count;
+	data->res.eof     = 0;
+	data->timestamp   = jiffies;
 
 	/* N.B. Do we need to test? Never called for swapfile inode */
 	flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
@@ -1402,24 +1393,41 @@
 }
 
 static void
+nfs4_write_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
+{
+	/* Check cache consistency */
+	if (fattr->pre_change_attr != NFS_CHANGE_ATTR(inode))
+		nfs_zap_caches(inode);
+	NFS_CHANGE_ATTR(inode) = fattr->change_attr;
+	if (fattr->bitmap[1] & FATTR4_WORD1_SPACE_USED)
+		inode->i_blocks = (fattr->du.nfs3.used + 511) >> 9;
+	if (fattr->bitmap[1] & FATTR4_WORD1_TIME_METADATA)
+		inode->i_ctime = fattr->ctime;
+	if (fattr->bitmap[1] & FATTR4_WORD1_TIME_MODIFY)
+		inode->i_mtime = fattr->mtime;
+}
+
+static void
 nfs4_write_done(struct rpc_task *task)
 {
 	struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
+	struct inode *inode = data->inode;
 	
-	process_lease(&data->u.v4.compound);
-	nfs_writeback_done(task, data->u.v4.arg_stable,
-			   data->u.v4.arg_count, data->u.v4.res_count);
+	if (task->tk_status >= 0)
+		renew_lease(NFS_SERVER(inode), data->timestamp);
+	nfs4_write_refresh_inode(inode, data->res.fattr);
+	/* Call back common NFS writeback processing */
+	nfs_writeback_done(task);
 }
 
 static void
 nfs4_proc_write_setup(struct nfs_write_data *data, unsigned int count, int how)
 {
 	struct rpc_task	*task = &data->task;
-	struct nfs4_compound *cp = &data->u.v4.compound;
 	struct rpc_message msg = {
-		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMPOUND],
-		.rpc_argp = cp,
-		.rpc_resp = cp,
+		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE],
+		.rpc_argp = &data->args,
+		.rpc_resp = &data->res,
 		.rpc_cred = data->cred,
 	};
 	struct inode *inode = data->inode;
@@ -1435,11 +1443,16 @@
 	} else
 		stable = NFS_UNSTABLE;
 
-	nfs4_setup_compound(cp, data->u.v4.ops, NFS_SERVER(inode), "write [async]");
-	nfs4_setup_putfh(cp, NFS_FH(inode));
-	nfs4_setup_write(cp, req_offset(req) + req->wb_offset,
-			 count, stable, data->pagevec, req->wb_offset,
-			 &data->u.v4.res_count, &data->verf);
+	data->args.fh     = NFS_FH(inode);
+	data->args.offset = req_offset(req);
+	data->args.pgbase = req->wb_offset;
+	data->args.count  = count;
+	data->args.stable = stable;
+	data->args.pages  = data->pagevec;
+	data->res.fattr   = &data->fattr;
+	data->res.count   = count;
+	data->res.verf    = &data->verf;
+	data->timestamp   = jiffies;
 
 	/* Set the initial flags for the task.  */
 	flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
@@ -1458,7 +1471,8 @@
 {
 	struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
 	
-	process_lease(&data->u.v4.compound);
+	nfs4_write_refresh_inode(data->inode, data->res.fattr);
+	/* Call back common NFS writeback processing */
 	nfs_commit_done(task);
 }
 
@@ -1466,19 +1480,21 @@
 nfs4_proc_commit_setup(struct nfs_write_data *data, u64 start, u32 len, int how)
 {
 	struct rpc_task	*task = &data->task;
-	struct nfs4_compound *cp = &data->u.v4.compound;
 	struct rpc_message msg = {
-		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMPOUND],
-		.rpc_argp = cp,
-		.rpc_resp = cp,
+		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT],
+		.rpc_argp = &data->args,
+		.rpc_resp = &data->res,
 		.rpc_cred = data->cred,
 	};	
 	struct inode *inode = data->inode;
 	int flags;
 	
-	nfs4_setup_compound(cp, data->u.v4.ops, NFS_SERVER(inode), "commit [async]");
-	nfs4_setup_putfh(cp, NFS_FH(inode));
-	nfs4_setup_commit(cp, start, len, &data->verf);
+	data->args.fh     = NFS_FH(data->inode);
+	data->args.offset = start;
+	data->args.count  = len;
+	data->res.count   = len;
+	data->res.fattr   = &data->fattr;
+	data->res.verf    = &data->verf;
 	
 	/* Set the initial flags for the task.  */
 	flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
diff -Nru a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
--- a/fs/nfs/nfs4xdr.c	Mon Dec 23 21:22:02 2002
+++ b/fs/nfs/nfs4xdr.c	Mon Dec 23 21:22:02 2002
@@ -64,8 +64,58 @@
 
 extern int			nfs_stat_to_errno(int);
 
+/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
+#ifdef DEBUG
+#define NFS4_MAXTAGLEN		20
+#else
+#define NFS4_MAXTAGLEN		0
+#endif
+
+#define compound_encode_hdr_maxsz	3 + (NFS4_MAXTAGLEN >> 2)
+#define compound_decode_hdr_maxsz	2 + (NFS4_MAXTAGLEN >> 2)
+#define op_encode_hdr_maxsz	1
+#define op_decode_hdr_maxsz	2
+#define encode_putfh_maxsz	op_encode_hdr_maxsz + 1 + \
+				(NFS4_FHSIZE >> 2)
+#define decode_putfh_maxsz	op_decode_hdr_maxsz
+#define encode_read_getattr_maxsz	op_encode_hdr_maxsz + 2
+#define decode_read_getattr_maxsz	op_decode_hdr_maxsz + 8
+#define encode_pre_write_getattr_maxsz	op_encode_hdr_maxsz + 2
+#define decode_pre_write_getattr_maxsz	op_decode_hdr_maxsz + 5
+#define encode_post_write_getattr_maxsz	op_encode_hdr_maxsz + 2
+#define decode_post_write_getattr_maxsz	op_decode_hdr_maxsz + 13
+
 #define NFS4_enc_compound_sz	1024  /* XXX: large enough? */
 #define NFS4_dec_compound_sz	1024  /* XXX: large enough? */
+#define NFS4_enc_read_sz	compound_encode_hdr_maxsz + \
+				encode_putfh_maxsz + \
+				encode_read_getattr_maxsz + \
+				op_encode_hdr_maxsz + 7
+#define NFS4_dec_read_sz	compound_decode_hdr_maxsz + \
+				decode_putfh_maxsz + \
+				decode_read_getattr_maxsz + \
+				op_decode_hdr_maxsz + 2
+#define NFS4_enc_write_sz	compound_encode_hdr_maxsz + \
+				encode_putfh_maxsz + \
+				encode_pre_write_getattr_maxsz + \
+				op_encode_hdr_maxsz + 8 + \
+				encode_post_write_getattr_maxsz
+#define NFS4_dec_write_sz	compound_decode_hdr_maxsz + \
+				decode_putfh_maxsz + \
+				decode_pre_write_getattr_maxsz + \
+				op_decode_hdr_maxsz + 4 + \
+				decode_post_write_getattr_maxsz
+#define NFS4_enc_commit_sz	compound_encode_hdr_maxsz + \
+				encode_putfh_maxsz + \
+				encode_pre_write_getattr_maxsz + \
+				op_encode_hdr_maxsz + 3 + \
+				encode_post_write_getattr_maxsz
+#define NFS4_dec_commit_sz	compound_decode_hdr_maxsz + \
+				decode_putfh_maxsz + \
+				decode_pre_write_getattr_maxsz + \
+				op_decode_hdr_maxsz + 2 + \
+				decode_post_write_getattr_maxsz
+
 
 static struct {
 	unsigned int	mode;
@@ -131,6 +181,7 @@
 	uint32_t *p;
 
 	dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
+	BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
 	RESERVE_SPACE(12+XDR_QUADLEN(hdr->taglen));
 	WRITE32(hdr->taglen);
 	WRITEMEM(hdr->tag, hdr->taglen);
@@ -310,14 +361,14 @@
 }
 
 static int
-encode_commit(struct xdr_stream *xdr, struct nfs4_commit *commit)
+encode_commit(struct xdr_stream *xdr, struct nfs_writeargs *args)
 {
 	uint32_t *p;
         
         RESERVE_SPACE(16);
         WRITE32(OP_COMMIT);
-        WRITE64(commit->co_start);
-        WRITE32(commit->co_len);
+        WRITE64(args->offset);
+        WRITE32(args->count);
 
         return 0;
 }
@@ -356,19 +407,69 @@
 }
 
 static int
-encode_getattr(struct xdr_stream *xdr, struct nfs4_getattr *getattr)
+encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
+{
+        uint32_t *p;
+
+        RESERVE_SPACE(12);
+        WRITE32(OP_GETATTR);
+        WRITE32(1);
+        WRITE32(bitmap);
+        return 0;
+}
+
+static int
+encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
 {
         uint32_t *p;
 
         RESERVE_SPACE(16);
         WRITE32(OP_GETATTR);
         WRITE32(2);
-        WRITE32(getattr->gt_bmval[0]);
-        WRITE32(getattr->gt_bmval[1]);
-
+        WRITE32(bm0);
+        WRITE32(bm1);
         return 0;
 }
 
+static inline int
+encode_getattr(struct xdr_stream *xdr, struct nfs4_getattr *getattr)
+{
+	return encode_getattr_two(xdr, getattr->gt_bmval[0],
+					getattr->gt_bmval[1]);
+}
+
+/*
+ * Request the change attribute in order to check attribute+cache consistency
+ */
+static inline int
+encode_read_getattr(struct xdr_stream *xdr)
+{
+	return encode_getattr_two(xdr, FATTR4_WORD0_CHANGE,
+			FATTR4_WORD1_TIME_ACCESS);
+}
+
+/*
+ * Request the change attribute prior to doing a write operation
+ */
+static inline int
+encode_pre_write_getattr(struct xdr_stream *xdr)
+{
+	/* Request the change attribute */
+	return encode_getattr_one(xdr, FATTR4_WORD0_CHANGE);
+}
+
+/*
+ * Request the change attribute, size, and [cm]time after a write operation
+ */
+static inline int
+encode_post_write_getattr(struct xdr_stream *xdr)
+{
+	return encode_getattr_two(xdr, FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE,
+			FATTR4_WORD1_SPACE_USED |
+			FATTR4_WORD1_TIME_METADATA |
+			FATTR4_WORD1_TIME_MODIFY);
+}
+
 static int
 encode_getfh(struct xdr_stream *xdr)
 {
@@ -472,15 +573,15 @@
 }
 
 static int
-encode_putfh(struct xdr_stream *xdr, struct nfs4_putfh *putfh)
+encode_putfh(struct xdr_stream *xdr, struct nfs_fh *fh)
 {
-	int len = putfh->pf_fhandle->size;
+	int len = fh->size;
 	uint32_t *p;
 
 	RESERVE_SPACE(8 + len);
 	WRITE32(OP_PUTFH);
 	WRITE32(len);
-	WRITEMEM(putfh->pf_fhandle->data, len);
+	WRITEMEM(fh->data, len);
 
 	return 0;
 }
@@ -497,10 +598,8 @@
 }
 
 static int
-encode_read(struct xdr_stream *xdr, struct nfs4_read *read, struct rpc_rqst *req)
+encode_read(struct xdr_stream *xdr, struct nfs_readargs *args)
 {
-	struct rpc_auth	*auth = req->rq_task->tk_auth;
-	int		replen;
 	uint32_t *p;
 
 	RESERVE_SPACE(32);
@@ -509,16 +608,8 @@
 	WRITE32(0);
 	WRITE32(0);
 	WRITE32(0);
-	WRITE64(read->rd_offset);
-	WRITE32(read->rd_length);
-
-	/* set up reply iovec
-	 *    toplevel status + taglen + rescount + OP_PUTFH + status
-	 *       + OP_READ + status + eof + datalen = 9
-	 */
-	replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
-	xdr_inline_pages(&req->rq_rcv_buf, replen,
-			 read->rd_pages, read->rd_pgbase, read->rd_length);
+	WRITE64(args->offset);
+	WRITE32(args->count);
 
 	return 0;
 }
@@ -693,9 +784,8 @@
 }
 
 static int
-encode_write(struct xdr_stream *xdr, struct nfs4_write *write, struct rpc_rqst *req)
+encode_write(struct xdr_stream *xdr, struct nfs_writeargs *args)
 {
-	struct xdr_buf *sndbuf = &req->rq_snd_buf;
 	uint32_t *p;
 
 	RESERVE_SPACE(36);
@@ -704,11 +794,11 @@
 	WRITE32(0xffffffff);
 	WRITE32(0xffffffff);
 	WRITE32(0xffffffff);
-	WRITE64(write->wr_offset);
-	WRITE32(write->wr_stable_how);
-	WRITE32(write->wr_len);
+	WRITE64(args->offset);
+	WRITE32(args->stable);
+	WRITE32(args->count);
 
-	xdr_encode_pages(sndbuf, write->wr_pages, write->wr_pgbase, write->wr_len);
+	xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
 
 	return 0;
 }
@@ -734,9 +824,6 @@
 		case OP_CLOSE:
 			status = encode_close(xdr, &cp->ops[i].u.close);
 			break;
-		case OP_COMMIT:
-			status = encode_commit(xdr, &cp->ops[i].u.commit);
-			break;
 		case OP_CREATE:
 			status = encode_create(xdr, &cp->ops[i].u.create);
 			break;
@@ -759,14 +846,11 @@
 			status = encode_open_confirm(xdr, &cp->ops[i].u.open_confirm);
 			break;
 		case OP_PUTFH:
-			status = encode_putfh(xdr, &cp->ops[i].u.putfh);
+			status = encode_putfh(xdr, cp->ops[i].u.putfh.pf_fhandle);
 			break;
 		case OP_PUTROOTFH:
 			status = encode_putrootfh(xdr);
 			break;
-		case OP_READ:
-			status = encode_read(xdr, &cp->ops[i].u.read, req);
-			break;
 		case OP_READDIR:
 			status = encode_readdir(xdr, &cp->ops[i].u.readdir, req);
 			break;
@@ -797,9 +881,6 @@
 		case OP_SETCLIENTID_CONFIRM:
 			status = encode_setclientid_confirm(xdr, cp->ops[i].u.setclientid_confirm);
 			break;
-		case OP_WRITE:
-			status = encode_write(xdr, &cp->ops[i].u.write, req);
-			break;
 		default:
 			BUG();
 		}
@@ -829,6 +910,96 @@
 	return status;
 }
 
+/*
+ * Encode a READ request
+ */
+static int
+nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
+{
+	struct rpc_auth	*auth = req->rq_task->tk_auth;
+	struct xdr_stream xdr;
+	struct compound_hdr hdr = {
+		.nops	= 3,
+	};
+	int replen, status;
+
+	xdr_init_encode(&xdr, &req->rq_snd_buf, p);
+	encode_compound_hdr(&xdr, &hdr);
+	status = encode_putfh(&xdr, args->fh);
+	if (status)
+		goto out;
+	status = encode_read(&xdr, args);
+	if (status)
+		goto out;
+	status = encode_read_getattr(&xdr);
+
+	/* set up reply iovec
+	 *    toplevel status + taglen=0 + rescount + OP_PUTFH + status
+	 *       + OP_READ + status + eof + datalen = 9
+	 */
+	replen = (RPC_REPHDRSIZE + auth->au_rslack +
+			NFS4_dec_read_sz - decode_read_getattr_maxsz) << 2;
+	xdr_inline_pages(&req->rq_rcv_buf, replen,
+			 args->pages, args->pgbase, args->count);
+out:
+	return status;
+}
+
+/*
+ * Encode a WRITE request
+ */
+static int
+nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
+{
+	struct xdr_stream xdr;
+	struct compound_hdr hdr = {
+		.nops   = 4,
+	};
+	int status;
+
+	xdr_init_encode(&xdr, &req->rq_snd_buf, p);
+	encode_compound_hdr(&xdr, &hdr);
+	status = encode_putfh(&xdr, args->fh);
+	if (status)
+		goto out;
+	status = encode_pre_write_getattr(&xdr);
+	if (status)
+		goto out;
+	status = encode_write(&xdr, args);
+	if (status)
+		goto out;
+	status = encode_post_write_getattr(&xdr);
+out:
+	return status;
+}
+
+/*
+ * Encode a COMMIT request
+ */
+static int
+nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
+{
+	struct xdr_stream xdr;
+	struct compound_hdr hdr = {
+		.nops   = 4,
+	};
+	int status;
+
+	xdr_init_encode(&xdr, &req->rq_snd_buf, p);
+	encode_compound_hdr(&xdr, &hdr);
+	status = encode_putfh(&xdr, args->fh);
+	if (status)
+		goto out;
+	status = encode_pre_write_getattr(&xdr);
+	if (status)
+		goto out;
+	status = encode_commit(&xdr, args);
+	if (status)
+		goto out;
+	status = encode_post_write_getattr(&xdr);
+out:
+	return status;
+}
 
 /*
  * START OF "GENERIC" DECODE ROUTINES.
@@ -982,7 +1153,7 @@
 }
 
 static int
-decode_commit(struct xdr_stream *xdr, struct nfs4_commit *commit)
+decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
 {
 	uint32_t *p;
 	int status;
@@ -991,7 +1162,7 @@
 	if (status)
 		return status;
 	READ_BUF(8);
-	COPYMEM(commit->co_verifier->verifier, 8);
+	COPYMEM(res->verf->verifier, 8);
 	return 0;
 }
 
@@ -1271,6 +1442,139 @@
 }
 
 static int
+decode_change_attr(struct xdr_stream *xdr, uint64_t *change_attr)
+{
+	uint32_t *p;
+	uint32_t attrlen, bmlen, bmval = 0;
+	int status;
+
+	status = decode_op_hdr(xdr, OP_GETATTR);
+	if (status)
+		return status;
+	READ_BUF(4);
+	READ32(bmlen);
+	if (bmlen < 1)
+		return -EIO;
+	READ_BUF(bmlen << 2);
+	READ32(bmval);
+	if (bmval != FATTR4_WORD0_CHANGE) {
+		printk(KERN_NOTICE "decode_change_attr: server returned bad attribute bitmap 0x%x\n",
+			(unsigned int)bmval);
+		return -EIO;
+	}
+	READ_BUF(4);
+	READ32(attrlen);
+	READ_BUF(attrlen);
+	if (attrlen < 8) {
+		printk(KERN_NOTICE "decode_change_attr: server returned bad attribute length %u\n",
+				(unsigned int)attrlen);
+		return -EIO;
+	}
+	READ64(*change_attr);
+	return 0;
+}
+
+static int
+decode_read_getattr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
+{
+	uint32_t *p;
+	uint32_t attrlen, bmlen, bmval0 = 0, bmval1 = 0;
+	int status;
+
+	status = decode_op_hdr(xdr, OP_GETATTR);
+	if (status)
+		return status;
+	READ_BUF(4);
+	READ32(bmlen);
+	if (bmlen < 1)
+		return -EIO;
+	READ_BUF(bmlen << 2);
+	READ32(bmval0);
+	if (bmval0 != FATTR4_WORD0_CHANGE)
+		goto out_bad_bitmap;
+	if (bmlen > 1) {
+		READ32(bmval1);
+		if (bmval1 & ~(FATTR4_WORD1_TIME_ACCESS))
+			goto out_bad_bitmap;
+	}
+	READ_BUF(4);
+	READ32(attrlen);
+	READ_BUF(attrlen);
+	if (attrlen < 16) {
+		printk(KERN_NOTICE "decode_post_write_getattr: server returned bad attribute length %u\n",
+				(unsigned int)attrlen);
+		return -EIO;
+	}
+	READ64(fattr->change_attr);
+	if (bmval1 & FATTR4_WORD1_TIME_ACCESS)
+		READTIME(fattr->atime);
+	fattr->bitmap[0] = bmval0;
+	fattr->bitmap[1] = bmval1;
+	return 0;
+out_bad_bitmap:
+	printk(KERN_NOTICE "decode_read_getattr: server returned bad attribute bitmap 0x%x/0x%x\n",
+			(unsigned int)bmval0, (unsigned int)bmval1);
+	return -EIO;
+}
+
+static int
+decode_pre_write_getattr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
+{
+	return decode_change_attr(xdr, &fattr->pre_change_attr);
+}
+
+static int
+decode_post_write_getattr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
+{
+	uint32_t *p;
+	uint32_t attrlen, bmlen, bmval0 = 0, bmval1 = 0;
+	int status;
+
+	status = decode_op_hdr(xdr, OP_GETATTR);
+	if (status)
+		return status;
+	READ_BUF(4);
+	READ32(bmlen);
+	if (bmlen < 1)
+		return -EIO;
+	READ_BUF(bmlen << 2);
+	READ32(bmval0);
+	if (bmval0 != (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE))
+		goto out_bad_bitmap;
+	if (bmlen > 1) {
+		READ32(bmval1);
+		if (bmval1 & ~(FATTR4_WORD1_SPACE_USED |
+					FATTR4_WORD1_TIME_METADATA |
+					FATTR4_WORD1_TIME_MODIFY))
+			goto out_bad_bitmap;
+	}
+	READ_BUF(4);
+	READ32(attrlen);
+	READ_BUF(attrlen);
+	if (attrlen < 16) {
+		printk(KERN_NOTICE "decode_post_write_getattr: server returned bad attribute length %u\n",
+				(unsigned int)attrlen);
+		return -EIO;
+	}
+	READ64(fattr->change_attr);
+	READ64(fattr->size);
+	if (bmval1 & FATTR4_WORD1_SPACE_USED)
+		READ64(fattr->du.nfs3.used);
+	if (bmval1 & FATTR4_WORD1_TIME_METADATA)
+		READTIME(fattr->ctime);
+	if (bmval1 & FATTR4_WORD1_TIME_MODIFY)
+		READTIME(fattr->mtime);
+	fattr->bitmap[0] = bmval0;
+	fattr->bitmap[1] = bmval1;
+	return 0;
+out_bad_bitmap:
+	printk(KERN_NOTICE "decode_post_write_getattr: server returned bad attribute bitmap 0x%x/0x%x\n",
+			(unsigned int)bmval0, (unsigned int)bmval1);
+	return -EIO;
+}
+
+
+static int
 decode_getfh(struct xdr_stream *xdr, struct nfs4_getfh *getfh)
 {
 	struct nfs_fh *fh = getfh->gf_fhandle;
@@ -1368,7 +1672,7 @@
 }
 
 static int
-decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_read *read)
+decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
 {
 	struct iovec *iov = req->rq_rvec;
 	uint32_t *p;
@@ -1382,14 +1686,6 @@
 	READ32(eof);
 	READ32(count);
 	hdrlen = (u8 *) p - (u8 *) iov->iov_base;
-	if (iov->iov_len < hdrlen) {
-		printk(KERN_WARNING "NFS: READ reply header overflowed:"
-				"length %u > %Zu\n", hdrlen, iov->iov_len);
-		return -errno_NFSERR_IO;
-	} else if (iov->iov_len != hdrlen) {
-		dprintk("NFS: READ header is short. iovec will be shifted.\n");
-		xdr_shift_buf(&req->rq_rcv_buf, iov->iov_len - hdrlen);
-	}
 	recvd = req->rq_received - hdrlen;
 	if (count > recvd) {
 		printk(KERN_WARNING "NFS: server cheating in read reply: "
@@ -1397,9 +1693,9 @@
 		count = recvd;
 		eof = 0;
 	}
-	if (read->rd_eof)
-		*read->rd_eof = eof;
-	*read->rd_bytes_read = count;
+	xdr_read_pages(xdr, count);
+	res->eof = eof;
+	res->count = count;
 	return 0;
 }
 
@@ -1410,7 +1706,7 @@
 	struct page	*page = *rcvbuf->pages;
 	struct iovec	*iov = rcvbuf->head;
 	unsigned int	nr, pglen = rcvbuf->page_len;
-	uint32_t	*end, *entry, *p;
+	uint32_t	*end, *entry, *p, *kaddr;
 	uint32_t	len, attrlen, word;
 	int 		i, hdrlen, recvd, status;
 
@@ -1421,20 +1717,13 @@
 	COPYMEM(readdir->rd_resp_verifier, 8);
 
 	hdrlen = (char *) p - (char *) iov->iov_base;
-	if (iov->iov_len < hdrlen) {
-		printk(KERN_WARNING "NFS: READDIR reply header overflowed:"
-				"length %d > %Zu\n", hdrlen, iov->iov_len);
-		return -EIO;
-	} else if (iov->iov_len != hdrlen) {
-		dprintk("NFS: READDIR header is short. iovec will be shifted.\n");
-		xdr_shift_buf(rcvbuf, iov->iov_len - hdrlen);
-	}
 	recvd = req->rq_received - hdrlen;
 	if (pglen > recvd)
 		pglen = recvd;
+	xdr_read_pages(xdr, pglen);
 
 	BUG_ON(pglen + readdir->rd_pgbase > PAGE_CACHE_SIZE);
-	p   = (uint32_t *) kmap(page);
+	kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0);
 	end = (uint32_t *) ((char *)p + pglen + readdir->rd_pgbase);
 	entry = p;
 	for (nr = 0; *p++; nr++) {
@@ -1480,7 +1769,7 @@
 	if (!nr && (entry[0] != 0 || entry[1] == 0))
 		goto short_pkt;
 out:	
-	kunmap(page);
+	kunmap_atomic(kaddr, KM_USER0);
 	return 0;
 short_pkt:
 	entry[0] = entry[1] = 0;
@@ -1491,7 +1780,7 @@
 	}
 	goto out;
 err_unmap:
-	kunmap(page);
+	kunmap_atomic(kaddr, KM_USER0);
 	return -errno_NFSERR_IO;
 }
 
@@ -1522,18 +1811,18 @@
 	 * and and null-terminate the text (the VFS expects
 	 * null-termination).
 	 */
-	strlen = (uint32_t *) kmap(rcvbuf->pages[0]);
+	strlen = (uint32_t *) kmap_atomic(rcvbuf->pages[0], KM_USER0);
 	len = ntohl(*strlen);
 	if (len > PAGE_CACHE_SIZE - 5) {
 		printk(KERN_WARNING "nfs: server returned giant symlink!\n");
-		kunmap(rcvbuf->pages[0]);
+		kunmap_atomic(strlen, KM_USER0);
 		return -EIO;
 	}
 	*strlen = len;
 
 	string = (char *)(strlen + 1);
 	string[len] = '\0';
-	kunmap(rcvbuf->pages[0]);
+	kunmap_atomic(strlen, KM_USER0);
 	return 0;
 }
 
@@ -1647,7 +1936,7 @@
 }
 
 static int
-decode_write(struct xdr_stream *xdr, struct nfs4_write *write)
+decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
 {
 	uint32_t *p;
 	int status;
@@ -1657,11 +1946,9 @@
 		return status;
 
 	READ_BUF(16);
-	READ32(*write->wr_bytes_written);
-	if (*write->wr_bytes_written > write->wr_len)
-		return -EIO;
-	READ32(write->wr_verf->committed);
-	COPYMEM(write->wr_verf->verifier, 8);
+	READ32(res->count);
+	READ32(res->verf->committed);
+	COPYMEM(res->verf->verifier, 8);
 	return 0;
 }
 
@@ -1701,9 +1988,6 @@
 		case OP_CLOSE:
 			status = decode_close(xdr, &op->u.close);
 			break;
-		case OP_COMMIT:
-			status = decode_commit(xdr, &op->u.commit);
-			break;
 		case OP_CREATE:
 			status = decode_create(xdr, &op->u.create);
 			break;
@@ -1731,9 +2015,6 @@
 		case OP_PUTROOTFH:
 			status = decode_putrootfh(xdr);
 			break;
-		case OP_READ:
-			status = decode_read(xdr, req, &op->u.read);
-			break;
 		case OP_READDIR:
 			status = decode_readdir(xdr, req, &op->u.readdir);
 			break;
@@ -1764,9 +2045,6 @@
 		case OP_SETCLIENTID_CONFIRM:
 			status = decode_setclientid_confirm(xdr);
 			break;
-		case OP_WRITE:
-			status = decode_write(xdr, &op->u.write);
-			break;
 		default:
 			BUG();
 			return -EIO;
@@ -1802,6 +2080,95 @@
 	return status;
 }
 
+/*
+ * Decode Read response
+ */
+static int
+nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *res)
+{
+	struct xdr_stream xdr;
+	struct compound_hdr hdr;
+	int status;
+
+	xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
+	status = decode_compound_hdr(&xdr, &hdr);
+	if (status)
+		goto out;
+	status = decode_putfh(&xdr);
+	if (status)
+		goto out;
+	status = decode_read(&xdr, rqstp, res);
+	if (status)
+		goto out;
+	status = decode_read_getattr(&xdr, res->fattr);
+	if (!status)
+		status = -nfs_stat_to_errno(hdr.status);
+out:
+	return status;
+}
+
+/*
+ * Decode WRITE response
+ */
+static int
+nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
+{
+	struct xdr_stream xdr;
+	struct compound_hdr hdr;
+	int status;
+
+	xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
+	status = decode_compound_hdr(&xdr, &hdr);
+	if (status)
+		goto out;
+	status = decode_putfh(&xdr);
+	if (status)
+		goto out;
+	status = decode_pre_write_getattr(&xdr, res->fattr);
+	if (status)
+		goto out;
+	status = decode_write(&xdr, res);
+	if (status)
+		goto out;
+	status = decode_post_write_getattr(&xdr, res->fattr);
+	if (!status)
+		status = -nfs_stat_to_errno(hdr.status);
+	if (!status)
+		status = res->count;
+out:
+	return status;
+}
+
+/*
+ * Decode COMMIT response
+ */
+static int
+nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
+{
+	struct xdr_stream xdr;
+	struct compound_hdr hdr;
+	int status;
+
+	xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
+	status = decode_compound_hdr(&xdr, &hdr);
+	if (status)
+		goto out;
+	status = decode_putfh(&xdr);
+	if (status)
+		goto out;
+	status = decode_pre_write_getattr(&xdr, res->fattr);
+	if (status)
+		goto out;
+	status = decode_commit(&xdr, res);
+	if (status)
+		goto out;
+	status = decode_post_write_getattr(&xdr, res->fattr);
+	if (!status)
+		status = -nfs_stat_to_errno(hdr.status);
+out:
+	return status;
+}
+
 uint32_t *
 nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
 {
@@ -1854,6 +2221,9 @@
 
 struct rpc_procinfo	nfs4_procedures[] = {
   PROC(COMPOUND,	enc_compound,	dec_compound),
+  PROC(READ,		enc_read,	dec_read),
+  PROC(WRITE,		enc_write,	dec_write),
+  PROC(COMMIT,		enc_commit,	dec_commit),
 };
 
 struct rpc_version		nfs_version4 = {
diff -Nru a/fs/nfs/proc.c b/fs/nfs/proc.c
--- a/fs/nfs/proc.c	Mon Dec 23 21:22:00 2002
+++ b/fs/nfs/proc.c	Mon Dec 23 21:22:00 2002
@@ -48,6 +48,18 @@
 
 extern struct rpc_procinfo nfs_procedures[];
 
+static void
+nfs_write_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
+{
+	if (!(fattr->valid & NFS_ATTR_WCC)) {
+		fattr->pre_size  = NFS_CACHE_ISIZE(inode);
+		fattr->pre_mtime = NFS_CACHE_MTIME(inode);
+		fattr->pre_ctime = NFS_CACHE_CTIME(inode);
+		fattr->valid |= NFS_ATTR_WCC;
+	}
+	nfs_refresh_inode(inode, fattr);
+}
+
 /*
  * Bare-bones access to getattr: this is for nfs_read_super.
  */
@@ -166,6 +178,8 @@
 	fattr->valid = 0;
 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
 
+	if (status >= 0)
+		nfs_refresh_inode(inode, fattr);
 	dprintk("NFS reply read: %d\n", status);
 	*eofp = res.eof;
 	return status;
@@ -205,6 +219,9 @@
 		flags |= NFS_RPC_SWAPFLAGS;
 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
 
+	if (status >= 0)
+		nfs_write_refresh_inode(inode, fattr);
+
 	dprintk("NFS reply write: %d\n", status);
 	verf->committed = NFS_FILE_SYNC;      /* NFSv2 always syncs data */
 	return status < 0? status : count;
@@ -524,7 +541,10 @@
 nfs_read_done(struct rpc_task *task)
 {
 	struct nfs_read_data *data = (struct nfs_read_data *) task->tk_calldata;
-	nfs_readpage_result(task, data->u.v3.res.count, data->u.v3.res.eof);
+
+	if (task->tk_status >= 0)
+		nfs_refresh_inode(data->inode, data->res.fattr);
+	nfs_readpage_result(task);
 }
 
 static void
@@ -536,20 +556,20 @@
 	int			flags;
 	struct rpc_message	msg = {
 		.rpc_proc	= &nfs_procedures[NFSPROC_READ],
-		.rpc_argp	= &data->u.v3.args,
-		.rpc_resp	= &data->u.v3.res,
+		.rpc_argp	= &data->args,
+		.rpc_resp	= &data->res,
 		.rpc_cred	= data->cred,
 	};
 	
 	req = nfs_list_entry(data->pages.next);
-	data->u.v3.args.fh     = NFS_FH(inode);
-	data->u.v3.args.offset = req_offset(req) + req->wb_offset;
-	data->u.v3.args.pgbase = req->wb_offset;
-	data->u.v3.args.pages  = data->pagevec;
-	data->u.v3.args.count  = count;
-	data->u.v3.res.fattr   = &data->fattr;
-	data->u.v3.res.count   = count;
-	data->u.v3.res.eof     = 0;
+	data->args.fh     = NFS_FH(inode);
+	data->args.offset = req_offset(req);
+	data->args.pgbase = req->wb_offset;
+	data->args.pages  = data->pagevec;
+	data->args.count  = count;
+	data->res.fattr   = &data->fattr;
+	data->res.count   = count;
+	data->res.eof     = 0;
 	
 	/* N.B. Do we need to test? Never called for swapfile inode */
 	flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
@@ -567,8 +587,10 @@
 nfs_write_done(struct rpc_task *task)
 {
 	struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
-	nfs_writeback_done(task, data->u.v3.args.stable,
-			   data->u.v3.args.count, data->u.v3.res.count);
+
+	if (task->tk_status >= 0)
+		nfs_write_refresh_inode(data->inode, data->res.fattr);
+	nfs_writeback_done(task);
 }
 
 static void
@@ -580,23 +602,23 @@
 	int			flags;
 	struct rpc_message	msg = {
 		.rpc_proc	= &nfs_procedures[NFSPROC_WRITE],
-		.rpc_argp	= &data->u.v3.args,
-		.rpc_resp	= &data->u.v3.res,
+		.rpc_argp	= &data->args,
+		.rpc_resp	= &data->res,
 		.rpc_cred	= data->cred,
 	};
 
 	/* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */
 	
 	req = nfs_list_entry(data->pages.next);
-	data->u.v3.args.fh     = NFS_FH(inode);
-	data->u.v3.args.offset = req_offset(req) + req->wb_offset;
-	data->u.v3.args.pgbase = req->wb_offset;
-	data->u.v3.args.count  = count;
-	data->u.v3.args.stable = NFS_FILE_SYNC;
-	data->u.v3.args.pages  = data->pagevec;
-	data->u.v3.res.fattr   = &data->fattr;
-	data->u.v3.res.count   = count;
-	data->u.v3.res.verf    = &data->verf;
+	data->args.fh     = NFS_FH(inode);
+	data->args.offset = req_offset(req);
+	data->args.pgbase = req->wb_offset;
+	data->args.count  = count;
+	data->args.stable = NFS_FILE_SYNC;
+	data->args.pages  = data->pagevec;
+	data->res.fattr   = &data->fattr;
+	data->res.count   = count;
+	data->res.verf    = &data->verf;
 
 	/* Set the initial flags for the task.  */
 	flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
diff -Nru a/fs/nfs/read.c b/fs/nfs/read.c
--- a/fs/nfs/read.c	Mon Dec 23 21:21:50 2002
+++ b/fs/nfs/read.c	Mon Dec 23 21:21:50 2002
@@ -100,7 +100,6 @@
 		lock_kernel();
 		result = NFS_PROTO(inode)->read(inode, cred, &fattr, flags,
 						offset, rsize, page, &eof);
-		nfs_refresh_inode(inode, &fattr);
 		unlock_kernel();
 
 		/*
@@ -118,12 +117,8 @@
 			break;
 	} while (count);
 
-	if (count) {
-		char *kaddr = kmap(page);
-		memset(kaddr + offset, 0, count);
-		kunmap(page);
-	}
-	flush_dcache_page(page);
+	if (count)
+		memclear_highpage_flush(page, offset, count);
 	SetPageUptodate(page);
 	if (PageError(page))
 		ClearPageError(page);
@@ -182,7 +177,7 @@
 			inode->i_sb->s_id,
 			(long long)NFS_FILEID(inode),
 			count,
-			(unsigned long long)req_offset(req) + req->wb_offset);
+			(unsigned long long)req_offset(req));
 }
 
 static void
@@ -255,16 +250,15 @@
  * received or some error occurred (timeout or socket shutdown).
  */
 void
-nfs_readpage_result(struct rpc_task *task, unsigned int count, int eof)
+nfs_readpage_result(struct rpc_task *task)
 {
 	struct nfs_read_data	*data = (struct nfs_read_data *) task->tk_calldata;
-	struct inode		*inode = data->inode;
 	struct nfs_fattr	*fattr = &data->fattr;
+	unsigned int count = data->res.count;
 
 	dprintk("NFS: %4d nfs_readpage_result, (status %d)\n",
 		task->tk_pid, task->tk_status);
 
-	nfs_refresh_inode(inode, fattr);
 	while (!list_empty(&data->pages)) {
 		struct nfs_page *req = nfs_list_entry(data->pages.next);
 		struct page *page = req->wb_page;
@@ -272,16 +266,13 @@
 
 		if (task->tk_status >= 0) {
 			if (count < PAGE_CACHE_SIZE) {
-				char *p = kmap(page);
-
-				if (count < req->wb_bytes)
-					memset(p + req->wb_offset + count, 0,
+				memclear_highpage_flush(page,
+							req->wb_offset + count,
 							req->wb_bytes - count);
-				kunmap(page);
 
-				if (eof ||
+				if (data->res.eof ||
 				    ((fattr->valid & NFS_ATTR_FATTR) &&
-				     ((req_offset(req) + req->wb_offset + count) >= fattr->size)))
+				     ((req_offset(req) + count) >= fattr->size)))
 					SetPageUptodate(page);
 				else
 					if (count < req->wb_bytes)
@@ -293,14 +284,13 @@
 			}
 		} else
 			SetPageError(page);
-		flush_dcache_page(page);
 		unlock_page(page);
 
 		dprintk("NFS: read (%s/%Ld %d@%Ld)\n",
                         req->wb_inode->i_sb->s_id,
                         (long long)NFS_FILEID(req->wb_inode),
                         req->wb_bytes,
-                        (long long)(req_offset(req) + req->wb_offset));
+                        (long long)req_offset(req));
 		nfs_clear_request(req);
 		nfs_release_request(req);
 		nfs_unlock_request(req);
diff -Nru a/fs/nfs/write.c b/fs/nfs/write.c
--- a/fs/nfs/write.c	Mon Dec 23 21:21:58 2002
+++ b/fs/nfs/write.c	Mon Dec 23 21:21:58 2002
@@ -125,23 +125,6 @@
 }
 
 /*
- * This function will be used to simulate weak cache consistency
- * under NFSv2 when the NFSv3 attribute patch is included.
- * For the moment, we just call nfs_refresh_inode().
- */
-static __inline__ int
-nfs_write_attributes(struct inode *inode, struct nfs_fattr *fattr)
-{
-	if ((fattr->valid & NFS_ATTR_FATTR) && !(fattr->valid & NFS_ATTR_WCC)) {
-		fattr->pre_size  = NFS_CACHE_ISIZE(inode);
-		fattr->pre_mtime = NFS_CACHE_MTIME(inode);
-		fattr->pre_ctime = NFS_CACHE_CTIME(inode);
-		fattr->valid |= NFS_ATTR_WCC;
-	}
-	return nfs_refresh_inode(inode, fattr);
-}
-
-/*
  * Write a page synchronously.
  * Offset is the data offset within the page.
  */
@@ -178,7 +161,6 @@
 
 		result = NFS_PROTO(inode)->write(inode, cred, &fattr, flags,
 						 offset, wsize, page, &verf);
-		nfs_write_attributes(inode, &fattr);
 
 		if (result < 0) {
 			/* Must mark the page invalid after I/O error */
@@ -768,7 +750,7 @@
 		inode->i_sb->s_id,
 		(long long)NFS_FILEID(inode),
 		count,
-		(unsigned long long)req_offset(req) + req->wb_offset);
+		(unsigned long long)req_offset(req));
 }
 
 /*
@@ -841,10 +823,11 @@
  * This function is called when the WRITE call is complete.
  */
 void
-nfs_writeback_done(struct rpc_task *task, int stable,
-		   unsigned int arg_count, unsigned int res_count)
+nfs_writeback_done(struct rpc_task *task)
 {
 	struct nfs_write_data	*data = (struct nfs_write_data *) task->tk_calldata;
+	struct nfs_writeargs	*argp = &data->args;
+	struct nfs_writeres	*resp = &data->res;
 	struct inode		*inode = data->inode;
 	struct nfs_page		*req;
 	struct page		*page;
@@ -853,7 +836,7 @@
 		task->tk_pid, task->tk_status);
 
 	/* We can't handle that yet but we check for it nevertheless */
-	if (res_count < arg_count && task->tk_status >= 0) {
+	if (resp->count < argp->count && task->tk_status >= 0) {
 		static unsigned long    complain;
 		if (time_before(complain, jiffies)) {
 			printk(KERN_WARNING
@@ -865,7 +848,7 @@
 		task->tk_status = -EIO;
 	}
 #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
-	if (data->verf.committed < stable && task->tk_status >= 0) {
+	if (data->verf.committed < argp->stable && task->tk_status >= 0) {
 		/* We tried a write call, but the server did not
 		 * commit data to stable storage even though we
 		 * requested it.
@@ -880,7 +863,7 @@
 			dprintk("NFS: faulty NFS server %s:"
 				" (committed = %d) != (stable = %d)\n",
 				NFS_SERVER(inode)->hostname,
-				data->verf.committed, stable);
+				data->verf.committed, argp->stable);
 			complain = jiffies + 300 * HZ;
 		}
 	}
@@ -892,7 +875,6 @@
 	 *	  writebacks since the page->count is kept > 1 for as long
 	 *	  as the page has a write request pending.
 	 */
-	nfs_write_attributes(inode, &data->fattr);
 	while (!list_empty(&data->pages)) {
 		req = nfs_list_entry(data->pages.next);
 		nfs_list_remove_request(req);
@@ -902,7 +884,7 @@
 			req->wb_inode->i_sb->s_id,
 			(long long)NFS_FILEID(req->wb_inode),
 			req->wb_bytes,
-			(long long)(req_offset(req) + req->wb_offset));
+			(long long)req_offset(req));
 
 		if (task->tk_status < 0) {
 			ClearPageUptodate(page);
@@ -917,7 +899,7 @@
 		end_page_writeback(page);
 
 #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
-		if (stable != NFS_UNSTABLE || data->verf.committed == NFS_FILE_SYNC) {
+		if (argp->stable != NFS_UNSTABLE || data->verf.committed == NFS_FILE_SYNC) {
 			nfs_inode_remove_request(req);
 			dprintk(" OK\n");
 			goto next;
@@ -958,8 +940,8 @@
 	 * Determine the offset range of requests in the COMMIT call.
 	 * We rely on the fact that data->pages is an ordered list...
 	 */
-	start = req_offset(first) + first->wb_offset;
-	end = req_offset(last) + (last->wb_offset + last->wb_bytes);
+	start = req_offset(first);
+	end = req_offset(last) + last->wb_bytes;
 	len = end - start;
 	/* If 'len' is not a 32-bit quantity, pass '0' in the COMMIT call */
 	if (end >= inode->i_size || len < 0 || len > (~((u32)0) >> 1))
@@ -1017,12 +999,10 @@
 {
 	struct nfs_write_data	*data = (struct nfs_write_data *)task->tk_calldata;
 	struct nfs_page		*req;
-	struct inode		*inode = data->inode;
 
         dprintk("NFS: %4d nfs_commit_done (status %d)\n",
                                 task->tk_pid, task->tk_status);
 
-	nfs_write_attributes(inode, &data->fattr);
 	while (!list_empty(&data->pages)) {
 		req = nfs_list_entry(data->pages.next);
 		nfs_list_remove_request(req);
@@ -1031,7 +1011,7 @@
 			req->wb_inode->i_sb->s_id,
 			(long long)NFS_FILEID(req->wb_inode),
 			req->wb_bytes,
-			(long long)(req_offset(req) + req->wb_offset));
+			(long long)req_offset(req));
 		if (task->tk_status < 0) {
 			if (req->wb_file)
 				req->wb_file->f_error = task->tk_status;
diff -Nru a/fs/read_write.c b/fs/read_write.c
--- a/fs/read_write.c	Mon Dec 23 21:21:57 2002
+++ b/fs/read_write.c	Mon Dec 23 21:21:57 2002
@@ -19,7 +19,7 @@
 struct file_operations generic_ro_fops = {
 	.llseek		= generic_file_llseek,
 	.read		= generic_file_read,
-	.mmap		= generic_file_mmap,
+	.mmap		= generic_file_readonly_mmap,
 	.sendfile	= generic_file_sendfile,
 };
 
diff -Nru a/fs/select.c b/fs/select.c
--- a/fs/select.c	Mon Dec 23 21:21:50 2002
+++ b/fs/select.c	Mon Dec 23 21:21:50 2002
@@ -360,7 +360,13 @@
 	return ret;
 }
 
-#define POLLFD_PER_PAGE  ((PAGE_SIZE) / sizeof(struct pollfd))
+struct poll_list {
+	struct poll_list *next;
+	int len;
+	struct pollfd entries[0];
+};
+
+#define POLLFD_PER_PAGE  ((PAGE_SIZE-sizeof(struct poll_list)) / sizeof(struct pollfd))
 
 static void do_pollfd(unsigned int num, struct pollfd * fdpage,
 	poll_table ** pwait, int *count)
@@ -394,21 +400,23 @@
 	}
 }
 
-static int do_poll(unsigned int nfds, unsigned int nchunks, unsigned int nleft, 
-	struct pollfd *fds[], struct poll_wqueues *wait, long timeout)
+static int do_poll(unsigned int nfds,  struct poll_list *list,
+			struct poll_wqueues *wait, long timeout)
 {
-	int count;
+	int count = 0;
 	poll_table* pt = &wait->pt;
 
+	if (!timeout)
+		pt = NULL;
+ 
 	for (;;) {
-		unsigned int i;
-
+		struct poll_list *walk;
 		set_current_state(TASK_INTERRUPTIBLE);
-		count = 0;
-		for (i=0; i < nchunks; i++)
-			do_pollfd(POLLFD_PER_PAGE, fds[i], &pt, &count);
-		if (nleft)
-			do_pollfd(nleft, fds[nchunks], &pt, &count);
+		walk = list;
+		while(walk != NULL) {
+			do_pollfd( walk->len, walk->entries, &pt, &count);
+			walk = walk->next;
+		}
 		pt = NULL;
 		if (count || !timeout || signal_pending(current))
 			break;
@@ -423,13 +431,14 @@
 
 asmlinkage long sys_poll(struct pollfd * ufds, unsigned int nfds, long timeout)
 {
-	int i, j, fdcount, err;
-	struct pollfd **fds;
-	struct poll_wqueues table, *wait;
-	int nchunks, nleft;
+	struct poll_wqueues table;
+ 	int fdcount, err;
+ 	unsigned int i;
+	struct poll_list *head;
+ 	struct poll_list *walk;
 
 	/* Do a sanity check on nfds ... */
-	if (nfds > NR_OPEN)
+	if (nfds > current->files->max_fdset && nfds > OPEN_MAX)
 		return -EINVAL;
 
 	if (timeout) {
@@ -441,68 +450,59 @@
 	}
 
 	poll_initwait(&table);
-	wait = &table;
-	if (!timeout)
-		wait = NULL;
 
+	head = NULL;
+	walk = NULL;
+	i = nfds;
 	err = -ENOMEM;
-	fds = NULL;
-	if (nfds != 0) {
-		fds = (struct pollfd **)kmalloc(
-			(1 + (nfds - 1) / POLLFD_PER_PAGE) * sizeof(struct pollfd *),
-			GFP_KERNEL);
-		if (fds == NULL)
-			goto out;
-	}
-
-	nchunks = 0;
-	nleft = nfds;
-	while (nleft > POLLFD_PER_PAGE) { /* allocate complete PAGE_SIZE chunks */
-		fds[nchunks] = (struct pollfd *)__get_free_page(GFP_KERNEL);
-		if (fds[nchunks] == NULL)
+	while(i!=0) {
+		struct poll_list *pp;
+		pp = kmalloc(sizeof(struct poll_list)+
+				sizeof(struct pollfd)*
+				(i>POLLFD_PER_PAGE?POLLFD_PER_PAGE:i),
+					GFP_KERNEL);
+		if(pp==NULL)
 			goto out_fds;
-		nchunks++;
-		nleft -= POLLFD_PER_PAGE;
-	}
-	if (nleft) { /* allocate last PAGE_SIZE chunk, only nleft elements used */
-		fds[nchunks] = (struct pollfd *)__get_free_page(GFP_KERNEL);
-		if (fds[nchunks] == NULL)
+		pp->next=NULL;
+		pp->len = (i>POLLFD_PER_PAGE?POLLFD_PER_PAGE:i);
+		if (head == NULL)
+			head = pp;
+		else
+			walk->next = pp;
+
+		walk = pp;
+		if (copy_from_user(pp+1, ufds + nfds-i, 
+				sizeof(struct pollfd)*pp->len)) {
+			err = -EFAULT;
 			goto out_fds;
+		}
+		i -= pp->len;
 	}
-
-	err = -EFAULT;
-	for (i=0; i < nchunks; i++)
-		if (copy_from_user(fds[i], ufds + i*POLLFD_PER_PAGE, PAGE_SIZE))
-			goto out_fds1;
-	if (nleft) {
-		if (copy_from_user(fds[nchunks], ufds + nchunks*POLLFD_PER_PAGE, 
-				nleft * sizeof(struct pollfd)))
-			goto out_fds1;
-	}
-
-	fdcount = do_poll(nfds, nchunks, nleft, fds, wait, timeout);
+	fdcount = do_poll(nfds, head, &table, timeout);
 
 	/* OK, now copy the revents fields back to user space. */
-	for(i=0; i < nchunks; i++)
-		for (j=0; j < POLLFD_PER_PAGE; j++, ufds++)
-			__put_user((fds[i] + j)->revents, &ufds->revents);
-	if (nleft)
-		for (j=0; j < nleft; j++, ufds++)
-			__put_user((fds[nchunks] + j)->revents, &ufds->revents);
-
+	walk = head;
+	err = -EFAULT;
+	while(walk != NULL) {
+		struct pollfd *fds = walk->entries;
+		int j;
+
+		for (j=0; j < walk->len; j++, ufds++) {
+			if(__put_user(fds[j].revents, &ufds->revents))
+				goto out_fds;
+		}
+		walk = walk->next;
+  	}
 	err = fdcount;
 	if (!fdcount && signal_pending(current))
 		err = -EINTR;
-
-out_fds1:
-	if (nleft)
-		free_page((unsigned long)(fds[nchunks]));
 out_fds:
-	for (i=0; i < nchunks; i++)
-		free_page((unsigned long)(fds[i]));
-	if (nfds != 0)
-		kfree(fds);
-out:
+	walk = head;
+	while(walk!=NULL) {
+		struct poll_list *pp = walk->next;
+		kfree(walk);
+		walk = pp;
+	}
 	poll_freewait(&table);
 	return err;
 }
diff -Nru a/fs/super.c b/fs/super.c
--- a/fs/super.c	Mon Dec 23 21:21:54 2002
+++ b/fs/super.c	Mon Dec 23 21:21:54 2002
@@ -192,8 +192,6 @@
 
 		if (sop->write_super && sb->s_dirt)
 			sop->write_super(sb);
-		if (sop->sync_fs)
-			sop->sync_fs(sb, 1);
 		if (sop->put_super)
 			sop->put_super(sb);
 
@@ -327,11 +325,12 @@
 			continue;
 		sb->s_need_sync_fs = 0;
 		if (sb->s_flags & MS_RDONLY)
-			continue;	/* hm.  Was remounted r/w meanwhile */
+			continue;	/* hm.  Was remounted r/o meanwhile */
 		sb->s_count++;
 		spin_unlock(&sb_lock);
 		down_read(&sb->s_umount);
-		sb->s_op->sync_fs(sb, wait);
+		if (sb->s_root)
+			sb->s_op->sync_fs(sb, wait);
 		drop_super(sb);
 		goto restart;
 	}
diff -Nru a/fs/xfs/Makefile b/fs/xfs/Makefile
--- a/fs/xfs/Makefile	Mon Dec 23 21:21:58 2002
+++ b/fs/xfs/Makefile	Mon Dec 23 21:21:58 2002
@@ -51,23 +51,22 @@
 obj-$(CONFIG_XFS_FS)		+= xfs.o
 
 
-xfs-obj-$(CONFIG_XFS_RT)	+= xfs_rtalloc.o
+xfs-$(CONFIG_XFS_RT)		+= xfs_rtalloc.o
 
-xfs-obj-$(CONFIG_XFS_QUOTA)	+= xfs_dquot.o \
+xfs-$(CONFIG_XFS_QUOTA)		+= xfs_dquot.o \
 				   xfs_dquot_item.o \
 				   xfs_trans_dquot.o \
 				   xfs_qm_syscalls.o \
 				   xfs_qm.o
 
-xfs-obj-$(CONFIG_XFS_POSIX_ACL)	+= xfs_acl.o
-xfs-obj-$(CONFIG_FS_POSIX_CAP)	+= xfs_cap.o
-xfs-obj-$(CONFIG_FS_POSIX_MAC)	+= xfs_mac.o
-xfs-obj-$(CONFIG_PROC_FS)	+= linux/xfs_stats.o
-xfs-obj-$(CONFIG_SYSCTL)	+= linux/xfs_sysctl.o
+xfs-$(CONFIG_XFS_POSIX_ACL)	+= xfs_acl.o
+xfs-$(CONFIG_FS_POSIX_CAP)	+= xfs_cap.o
+xfs-$(CONFIG_FS_POSIX_MAC)	+= xfs_mac.o
+xfs-$(CONFIG_PROC_FS)		+= linux/xfs_stats.o
+xfs-$(CONFIG_SYSCTL)		+= linux/xfs_sysctl.o
 
 
-xfs-objs			+= $(xfs-obj-y) \
-				   xfs_alloc.o \
+xfs-y				+= xfs_alloc.o \
 				   xfs_alloc_btree.o \
 				   xfs_attr.o \
 				   xfs_attr_fetch.o \
@@ -115,12 +114,12 @@
 				   xfs_rw.o
 
 # Objects in pagebuf/
-xfs-objs			+= $(addprefix pagebuf/, \
+xfs-y				+= $(addprefix pagebuf/, \
 				   page_buf.o \
 				   page_buf_locking.o)
 
 # Objects in linux/
-xfs-objs			+= $(addprefix linux/, \
+xfs-y				+= $(addprefix linux/, \
 				   xfs_aops.o \
 				   xfs_behavior.o \
 				   xfs_file.o \
@@ -134,7 +133,7 @@
 				   xfs_vnode.o)
 
 # Objects in support/
-xfs-objs			+= $(addprefix support/, \
+xfs-y				+= $(addprefix support/, \
 				   debug.o \
 				   kmem.o \
 				   ktrace.o \
diff -Nru a/fs/xfs/linux/xfs_aops.c b/fs/xfs/linux/xfs_aops.c
--- a/fs/xfs/linux/xfs_aops.c	Mon Dec 23 21:22:00 2002
+++ b/fs/xfs/linux/xfs_aops.c	Mon Dec 23 21:22:00 2002
@@ -48,6 +48,9 @@
 	vnode_t			*vp = LINVFS_GET_VP(inode);
 	int			error, nmaps = 1;
 
+	if (((flags & (PBF_DIRECT|PBF_SYNC)) == PBF_DIRECT) &&
+	    (offset >= inode->i_size))
+		count = max(count, XFS_WRITE_IO_LOG);
 retry:
 	VOP_BMAP(vp, offset, count, flags, pbmapp, &nmaps, error);
 	if (flags & PBF_WRITE) {
@@ -145,9 +148,8 @@
 			struct buffer_head	*bh, *head;
 			bh = head = page_buffers(page);
 			do {
-				if (buffer_mapped(bh) || !buffer_uptodate(bh)) {
+				if (buffer_mapped(bh) || !buffer_uptodate(bh))
 					break;
-				}
 				ret += bh->b_size;
 				if (ret >= pg_offset)
 					break;
@@ -289,7 +291,7 @@
 	bh = head = page_buffers(page);
 	do {
 		offset = i << bbits;
-		if (!buffer_uptodate(bh))
+		if (!(PageUptodate(page) || buffer_uptodate(bh)))
 			continue;
 		if (buffer_mapped(bh) && !buffer_delay(bh) && all_bh) {
 			if (startio && (offset < end)) {
@@ -372,7 +374,7 @@
 	page_buf_bmap_t		*mp, map;
 	unsigned long		p_offset = 0, end_index;
 	loff_t			offset, end_offset;
-	int			len, err, i, cnt = 0;
+	int			len, err, i, cnt = 0, uptodate = 1;
 
 	/* Are we off the end of the file ? */
 	end_index = inode->i_size >> PAGE_CACHE_SHIFT;
@@ -396,7 +398,7 @@
 
 	len = bh->b_size;
 	do {
-		if (!buffer_uptodate(bh) && !startio) {
+		if (!(PageUptodate(page) || buffer_uptodate(bh)) && !startio) {
 			goto next_bh;
 		}
 
@@ -423,48 +425,57 @@
 					unlock_buffer(bh);
 				}
 			}
-		} else if (!buffer_mapped(bh) && 
-			   (buffer_uptodate(bh) || PageUptodate(page))
-			   && (allocate_space || startio)) {
-			int	size;
-
-			/* Getting here implies an unmapped buffer was found,
-			 * and we are in a path where we need to write the
-			 * whole page out.
-			 */
-			if (!mp) {
-				size = probe_unmapped_cluster(inode, page,
-								bh, head);
-				err = map_blocks(inode, offset, size, &map,
-						PBF_WRITE|PBF_DIRECT);
-				if (err) {
-					goto error;
+		} else if ((buffer_uptodate(bh) || PageUptodate(page)) &&
+			   (allocate_space || startio)) {
+			if (!buffer_mapped(bh)) {
+				int	size;
+				
+				/*
+				 * Getting here implies an unmapped buffer
+				 * was found, and we are in a path where we
+				 * need to write the whole page out.
+				 */
+				if (!mp) {
+					size = probe_unmapped_cluster(
+							inode, page, bh, head);
+					err = map_blocks(inode, offset,
+							size, &map,
+							PBF_WRITE | PBF_DIRECT);
+					if (err) {
+						goto error;
+					}
+					mp = match_offset_to_mapping(page, &map,
+								     p_offset);
 				}
-				mp = match_offset_to_mapping(page, &map,
-								p_offset);
-			}
-			if (mp) {
-				map_buffer_at_offset(page, bh, p_offset,
-					inode->i_blkbits, mp);
-				if (startio) {
+				if (mp) {
+					map_buffer_at_offset(page,
+							bh, p_offset,
+							inode->i_blkbits, mp);
+					if (startio) {
+						bh_arr[cnt++] = bh;
+					} else {
+						unlock_buffer(bh);
+					}
+				}
+			} else if (startio && buffer_mapped(bh)) {
+				if (buffer_uptodate(bh) && allocate_space) {
+					lock_buffer(bh);
 					bh_arr[cnt++] = bh;
-				} else {
-					unlock_buffer(bh);
 				}
 			}
-		} else if (startio && buffer_mapped(bh)) {
-			if(buffer_uptodate(bh) && allocate_space) {
-				lock_buffer(bh);
-				bh_arr[cnt++] = bh;
-			}
 		}
 
 next_bh:
+		if (!buffer_uptodate(bh))
+			uptodate = 0;
 		offset += len;
 		p_offset += len;
 		bh = bh->b_this_page;
 	} while (offset < end_offset);
 
+	if (uptodate)
+		SetPageUptodate(page);
+
 	if (startio) {
 		submit_page(page, bh_arr, cnt);
 	}
@@ -509,17 +520,15 @@
 	ssize_t			size;
 	loff_t			offset = (loff_t)iblock << inode->i_blkbits;
 
-	if (blocks) {
+	/* If we are doing writes at the end of the file,
+	 * allocate in chunks
+	 */
+	if (blocks)
 		size = blocks << inode->i_blkbits;
-	} else {
-		/* If we are doing writes at the end of the file,
-		 * allocate in chunks
-		 */
-		if (create && (offset >= inode->i_size) && !(flags & PBF_SYNC))
-			size = 1 << XFS_WRITE_IO_LOG;
-		else
-			size = 1 << inode->i_blkbits;
-	}
+	else if (create && (offset >= inode->i_size))
+		size = 1 << XFS_WRITE_IO_LOG;
+	else
+		size = 1 << inode->i_blkbits;
 
 	VOP_BMAP(vp, offset, size,
 		create ? flags : PBF_READ,
@@ -534,15 +543,20 @@
 		page_buf_daddr_t	bn;
 		loff_t			delta;
 
-		delta = offset - pbmap.pbm_offset;
-		delta >>= inode->i_blkbits;
-
-		bn = pbmap.pbm_bn >> (inode->i_blkbits - 9);
-		bn += delta;
-
-		bh_result->b_blocknr = bn;
-		bh_result->b_bdev = pbmap.pbm_target->pbr_bdev;
-		set_buffer_mapped(bh_result);
+		/* For unwritten extents do not report a disk address on
+		 * the read case.
+		 */
+		if (create || ((pbmap.pbm_flags & PBMF_UNWRITTEN) == 0)) {
+			delta = offset - pbmap.pbm_offset;
+			delta >>= inode->i_blkbits;
+
+			bn = pbmap.pbm_bn >> (inode->i_blkbits - 9);
+			bn += delta;
+
+			bh_result->b_blocknr = bn;
+			bh_result->b_bdev = pbmap.pbm_target->pbr_bdev;
+			set_buffer_mapped(bh_result);
+		}
 	}
 
 	/* If we previously allocated a block out beyond eof and
diff -Nru a/fs/xfs/linux/xfs_iomap.c b/fs/xfs/linux/xfs_iomap.c
--- a/fs/xfs/linux/xfs_iomap.c	Mon Dec 23 21:21:55 2002
+++ b/fs/xfs/linux/xfs_iomap.c	Mon Dec 23 21:21:55 2002
@@ -29,362 +29,13 @@
  *
  * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  */
-/*
- *  fs/xfs/linux/xfs_lrw.c (Linux Read Write stuff)
- *
- */
 
 #include <xfs.h>
-#include <linux/pagemap.h>
-#include <linux/capability.h>
-
 
 #define XFS_WRITEIO_ALIGN(mp,off)	(((off) >> mp->m_writeio_log) \
 						<< mp->m_writeio_log)
 #define XFS_STRAT_WRITE_IMAPS	2
-
-STATIC int xfs_iomap_read(xfs_iocore_t *, loff_t, size_t, int, page_buf_bmap_t *,
-			int *);
-STATIC int xfs_iomap_write(xfs_iocore_t *, loff_t, size_t, page_buf_bmap_t *,
-			int *, int);
-STATIC int xfs_iomap_write_delay(xfs_iocore_t *, loff_t, size_t, page_buf_bmap_t *,
-			int *, int, int);
-STATIC int xfs_iomap_write_direct(xfs_iocore_t *, loff_t, size_t, page_buf_bmap_t *,
-			int *, int, int);
-STATIC int _xfs_imap_to_bmap(xfs_iocore_t *, xfs_off_t, xfs_bmbt_irec_t *,
-			page_buf_bmap_t *, int, int);
-
-
-int
-xfs_strategy(
-	xfs_inode_t	*ip,
-	xfs_off_t	offset,
-	ssize_t		count,
-	int		flags,
-	page_buf_bmap_t	*pbmapp,
-	int		*npbmaps)
-{
-	xfs_iocore_t	*io;
-	xfs_mount_t	*mp;
-	int		error;
-	xfs_fileoff_t	offset_fsb;
-	xfs_fileoff_t	end_fsb;
-	xfs_fileoff_t	map_start_fsb;
-	xfs_fileoff_t	last_block;
-	xfs_fsblock_t	first_block;
-	xfs_bmap_free_t free_list;
-	xfs_filblks_t	count_fsb;
-	int		committed, i, loops, nimaps;
-	int		is_xfs;
-	xfs_bmbt_irec_t imap[XFS_MAX_RW_NBMAPS];
-	xfs_trans_t	*tp;
-
-	mp = ip->i_mount;
-	io = &ip->i_iocore;
-	is_xfs = IO_IS_XFS(io);
-	ASSERT((ip->i_d.di_mode & IFMT) == IFREG);
-	ASSERT(((ip->i_d.di_flags & XFS_DIFLAG_REALTIME) != 0) ==
-	       ((io->io_flags & XFS_IOCORE_RT) != 0));
-
-	if (XFS_FORCED_SHUTDOWN(mp))
-		return XFS_ERROR(EIO);
-
-	offset_fsb = XFS_B_TO_FSBT(mp, offset);
-	nimaps = min(XFS_MAX_RW_NBMAPS, *npbmaps);
-	end_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)(offset + count)));
-	first_block = NULLFSBLOCK;
-
-	XFS_ILOCK(mp, io, XFS_ILOCK_SHARED | XFS_EXTSIZE_RD);
-	error = XFS_BMAPI(mp, NULL, io, offset_fsb,
-			(xfs_filblks_t)(end_fsb - offset_fsb),
-			XFS_BMAPI_ENTIRE, &first_block, 0, imap,
-			&nimaps, NULL);
-	XFS_IUNLOCK(mp, io, XFS_ILOCK_SHARED | XFS_EXTSIZE_RD);
-	if (error) {
-		return XFS_ERROR(error);
-	}
-
-	if (nimaps && !ISNULLSTARTBLOCK(imap[0].br_startblock)) {
-		*npbmaps = _xfs_imap_to_bmap(&ip->i_iocore, offset, imap,
-				pbmapp, nimaps, *npbmaps);
-		return 0;
-	}
-
-	/*
-	 * Make sure that the dquots are there.
-	 */
-
-	if (XFS_IS_QUOTA_ON(mp)) {
-		if (XFS_NOT_DQATTACHED(mp, ip)) {
-			if ((error = xfs_qm_dqattach(ip, 0))) {
-				return XFS_ERROR(error);
-			}
-		}
-	}
-	XFS_STATS_ADD(xfsstats.xs_xstrat_bytes,
-		XFS_FSB_TO_B(mp, imap[0].br_blockcount));
-
-	offset_fsb = imap[0].br_startoff;
-	count_fsb = imap[0].br_blockcount;
-	map_start_fsb = offset_fsb;
-	while (count_fsb != 0) {
-		/*
-		 * Set up a transaction with which to allocate the
-		 * backing store for the file.	Do allocations in a
-		 * loop until we get some space in the range we are
-		 * interested in.  The other space that might be allocated
-		 * is in the delayed allocation extent on which we sit
-		 * but before our buffer starts.
-		 */
-		nimaps = 0;
-		loops = 0;
-		while (nimaps == 0) {
-			if (is_xfs) {
-				tp = xfs_trans_alloc(mp, XFS_TRANS_STRAT_WRITE);
-				error = xfs_trans_reserve(tp, 0,
-						XFS_WRITE_LOG_RES(mp),
-						0, XFS_TRANS_PERM_LOG_RES,
-						XFS_WRITE_LOG_COUNT);
-				if (error) {
-					xfs_trans_cancel(tp, 0);
-					goto error0;
-				}
-				xfs_ilock(ip, XFS_ILOCK_EXCL);
-				xfs_trans_ijoin(tp, ip,
-						XFS_ILOCK_EXCL);
-				xfs_trans_ihold(tp, ip);
-			} else {
-				tp = NULL;
-				XFS_ILOCK(mp, io, XFS_ILOCK_EXCL |
-						XFS_EXTSIZE_WR);
-			}
-
-
-			/*
-			 * Allocate the backing store for the file.
-			 */
-			XFS_BMAP_INIT(&(free_list),
-					&(first_block));
-			nimaps = XFS_STRAT_WRITE_IMAPS;
-
-			/*
-			 * Ensure we don't go beyond eof - it is possible
-			 * the extents changed since we did the read call,
-			 * we dropped the ilock in the interim.
-			 */
-
-			end_fsb = XFS_B_TO_FSB(mp, XFS_SIZE(mp, io));
-			xfs_bmap_last_offset(NULL, ip, &last_block,
-				XFS_DATA_FORK);
-			last_block = XFS_FILEOFF_MAX(last_block, end_fsb);
-			if ((map_start_fsb + count_fsb) > last_block) {
-				count_fsb = last_block - map_start_fsb;
-				if (count_fsb == 0) {
-					if (is_xfs) {
-						xfs_bmap_cancel(&free_list);
-						xfs_trans_cancel(tp,
-						  (XFS_TRANS_RELEASE_LOG_RES |
-							 XFS_TRANS_ABORT));
-					}
-					XFS_IUNLOCK(mp, io, XFS_ILOCK_EXCL |
-							    XFS_EXTSIZE_WR);
-					return XFS_ERROR(EAGAIN);
-				}
-			}
-
-			error = XFS_BMAPI(mp, tp, io, map_start_fsb, count_fsb,
-					XFS_BMAPI_WRITE, &first_block, 1,
-					imap, &nimaps, &free_list);
-			if (error) {
-				xfs_bmap_cancel(&free_list);
-				xfs_trans_cancel(tp,
-					(XFS_TRANS_RELEASE_LOG_RES |
-					 XFS_TRANS_ABORT));
-				XFS_IUNLOCK(mp, io, XFS_ILOCK_EXCL |
-						    XFS_EXTSIZE_WR);
-
-				goto error0;
-			}
-
-			if (is_xfs) {
-				error = xfs_bmap_finish(&(tp), &(free_list),
-						first_block, &committed);
-				if (error) {
-					xfs_bmap_cancel(&free_list);
-					xfs_trans_cancel(tp,
-						(XFS_TRANS_RELEASE_LOG_RES |
-						XFS_TRANS_ABORT));
-					xfs_iunlock(ip, XFS_ILOCK_EXCL);
-					goto error0;
-				}
-
-				error = xfs_trans_commit(tp,
-						XFS_TRANS_RELEASE_LOG_RES,
-						NULL);
-				if (error) {
-					xfs_iunlock(ip, XFS_ILOCK_EXCL);
-					goto error0;
-				}
-			}
-
-			if (nimaps == 0) {
-				XFS_IUNLOCK(mp, io,
-						XFS_ILOCK_EXCL|XFS_EXTSIZE_WR);
-			} /* else hold 'till we maybe loop again below */
-		}
-
-		/*
-		 * See if we were able to allocate an extent that
-		 * covers at least part of the user's requested size.
-		 */
-
-		offset_fsb = XFS_B_TO_FSBT(mp, offset);
-		for (i = 0; i < nimaps; i++) {
-			int	maps;
-
-			if ((offset_fsb >= imap[i].br_startoff) &&
-			    (offset_fsb <
-			     (imap[i].br_startoff + imap[i].br_blockcount))) {
-
-				XFS_IUNLOCK(mp, io,
-						XFS_ILOCK_EXCL|XFS_EXTSIZE_WR);
-				maps = min(nimaps, *npbmaps);
-				*npbmaps = _xfs_imap_to_bmap(io, offset,
-							     &imap[i], pbmapp,
-							     maps, *npbmaps);
-				XFS_STATS_INC(xfsstats.xs_xstrat_quick);
-				return 0;
-			}
-			count_fsb -= imap[i].br_blockcount; /* for next bmapi,
-								if needed. */
-		}
-
-		/*
-		 * We didn't get an extent the caller can write into so
-		 * loop around and try starting after the last imap we got back.
-		 */
-
-		nimaps--; /* Index of last entry  */
-		ASSERT(nimaps >= 0);
-		ASSERT(offset_fsb >=
-			imap[nimaps].br_startoff + imap[nimaps].br_blockcount);
-		ASSERT(count_fsb);
-		offset_fsb =
-			imap[nimaps].br_startoff + imap[nimaps].br_blockcount;
-		map_start_fsb = offset_fsb;
-		XFS_STATS_INC(xfsstats.xs_xstrat_split);
-		XFS_IUNLOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_WR);
-	}
-
-	ASSERT(0);	/* Should never get here */
-
- error0:
-	if (error) {
-		ASSERT(count_fsb != 0);
-		ASSERT(is_xfs || XFS_FORCED_SHUTDOWN(mp));
-	}
-
-	return XFS_ERROR(error);
-}
-
-
-/*
- * xfs_bmap() is the same as the irix xfs_bmap from xfs_rw.c
- * execpt for slight changes to the params
- */
-int
-xfs_bmap(bhv_desc_t	*bdp,
-	xfs_off_t	offset,
-	ssize_t		count,
-	int		flags,
-	page_buf_bmap_t	*pbmapp,
-	int		*npbmaps)
-{
-	xfs_inode_t	*ip;
-	int		error;
-	int		lockmode;
-	int		fsynced = 0;
-	vnode_t		*vp;
-
-	ip = XFS_BHVTOI(bdp);
-	ASSERT((ip->i_d.di_mode & IFMT) == IFREG);
-	ASSERT(((ip->i_d.di_flags & XFS_DIFLAG_REALTIME) != 0) ==
-	       ((ip->i_iocore.io_flags & XFS_IOCORE_RT) != 0));
-
-	if (XFS_FORCED_SHUTDOWN(ip->i_iocore.io_mount))
-		return XFS_ERROR(EIO);
-
-	if (flags & PBF_READ) {
-		lockmode = xfs_ilock_map_shared(ip);
-		error = xfs_iomap_read(&ip->i_iocore, offset, count,
-				 XFS_BMAPI_ENTIRE, pbmapp, npbmaps);
-		xfs_iunlock_map_shared(ip, lockmode);
-	} else if (flags & PBF_FILE_ALLOCATE) {
-		error = xfs_strategy(ip, offset, count, flags,
-				pbmapp, npbmaps);
-	} else { /* PBF_WRITE */
-		ASSERT(flags & PBF_WRITE);
-		vp = BHV_TO_VNODE(bdp);
-		xfs_ilock(ip, XFS_ILOCK_EXCL);
-
-		/*
-		 * Make sure that the dquots are there. This doesn't hold
-		 * the ilock across a disk read.
-		 */
-
-		if (XFS_IS_QUOTA_ON(ip->i_mount)) {
-			if (XFS_NOT_DQATTACHED(ip->i_mount, ip)) {
-				if ((error = xfs_qm_dqattach(ip, XFS_QMOPT_ILOCKED))) {
-					xfs_iunlock(ip, XFS_ILOCK_EXCL);
-					return XFS_ERROR(error);
-				}
-			}
-		}
-retry:
-		error = xfs_iomap_write(&ip->i_iocore, offset, count,
-					pbmapp, npbmaps, flags);
-		/* xfs_iomap_write unlocks/locks/unlocks */
-
-		if (error == ENOSPC) {
-			switch (fsynced) {
-			case 0:
-				if (ip->i_delayed_blks) {
-					filemap_fdatawrite(LINVFS_GET_IP(vp)->i_mapping);
-					fsynced = 1;
-				} else {
-					fsynced = 2;
-					flags |= PBF_SYNC;
-				}
-				error = 0;
-				xfs_ilock(ip, XFS_ILOCK_EXCL);
-				goto retry;
-			case 1:
-				fsynced = 2;
-				if (!(flags & PBF_SYNC)) {
-					flags |= PBF_SYNC;
-					error = 0;
-					xfs_ilock(ip, XFS_ILOCK_EXCL);
-					goto retry;
-				}
-			case 2:
-				sync_blockdev(vp->v_vfsp->vfs_super->s_bdev);
-				xfs_log_force(ip->i_mount, (xfs_lsn_t)0,
-						XFS_LOG_FORCE|XFS_LOG_SYNC);
-
-				error = 0;
-/**
-				delay(HZ);
-**/
-				fsynced++;
-				xfs_ilock(ip, XFS_ILOCK_EXCL);
-				goto retry;
-			}
-		}
-	}
-
-	return XFS_ERROR(error);
-}
-
+#define XFS_WRITE_IMAPS		XFS_BMAP_MAX_NMAP
 
 STATIC int
 _xfs_imap_to_bmap(
@@ -397,7 +48,7 @@
 {
 	xfs_mount_t	*mp;
 	xfs_fsize_t	nisize;
-	int		im, pbm;
+	int		pbm;
 	xfs_fsblock_t	start_block;
 
 	mp = io->io_mount;
@@ -405,7 +56,7 @@
 	if (io->io_new_size > nisize)
 		nisize = io->io_new_size;
 
-	for (im=pbm=0; im < imaps && pbm < pbmaps; im++,pbmapp++,imap++,pbm++) {
+	for (pbm = 0; imaps && pbm < pbmaps; imaps--, pbmapp++, imap++, pbm++) {
 		pbmapp->pbm_target = io->io_flags & XFS_IOCORE_RT ?
 			mp->m_rtdev_targp : mp->m_ddev_targp;
 		pbmapp->pbm_offset = XFS_FSB_TO_B(mp, imap->br_startoff);
@@ -422,9 +73,8 @@
 			pbmapp->pbm_flags = PBMF_DELAY;
 		} else {
 			pbmapp->pbm_bn = XFS_FSB_TO_DB_IO(io, start_block);
-			if (ISUNWRITTEN(imap)) {
+			if (ISUNWRITTEN(imap))
 				pbmapp->pbm_flags |= PBMF_UNWRITTEN;
-			}
 		}
 
 		if ((pbmapp->pbm_offset + pbmapp->pbm_bsize) >= nisize) {
@@ -436,149 +86,344 @@
 	return pbm;	/* Return the number filled */
 }
 
-STATIC int
-xfs_iomap_read(
+int
+xfs_iomap(
 	xfs_iocore_t	*io,
-	loff_t		offset,
-	size_t		count,
+	xfs_off_t	offset,
+	ssize_t		count,
 	int		flags,
 	page_buf_bmap_t	*pbmapp,
 	int		*npbmaps)
 {
-	xfs_fileoff_t	offset_fsb;
-	xfs_fileoff_t	end_fsb;
-	int		nimaps;
+	xfs_mount_t	*mp = io->io_mount;
+	xfs_fileoff_t	offset_fsb, end_fsb;
 	int		error;
-	xfs_mount_t	*mp;
-	xfs_bmbt_irec_t imap[XFS_MAX_RW_NBMAPS];
+	int		lockmode = 0;
+	xfs_bmbt_irec_t	imap;
+	int		nimaps = 1;
+	int		bmap_flags = 0;
 
-	ASSERT(ismrlocked(io->io_lock, MR_UPDATE | MR_ACCESS) != 0);
+	if (XFS_FORCED_SHUTDOWN(mp))
+		return XFS_ERROR(EIO);
+
+	switch (flags &
+		(PBF_READ|PBF_WRITE|PBF_FILE_ALLOCATE|PBF_FILE_UNWRITTEN)) {
+	case PBF_READ:
+		lockmode = XFS_LCK_MAP_SHARED(mp, io);
+		bmap_flags = XFS_BMAPI_ENTIRE;
+		break;
+	case PBF_WRITE:
+		lockmode = XFS_ILOCK_EXCL|XFS_EXTSIZE_WR;
+		bmap_flags = 0;
+		XFS_ILOCK(mp, io, lockmode);
+		break;
+	case PBF_FILE_ALLOCATE:
+		lockmode = XFS_ILOCK_SHARED|XFS_EXTSIZE_RD;
+		bmap_flags = XFS_BMAPI_ENTIRE;
+		XFS_ILOCK(mp, io, lockmode);
+		break;
+	case PBF_FILE_UNWRITTEN:
+		lockmode = XFS_ILOCK_EXCL|XFS_EXTSIZE_WR;
+		bmap_flags = XFS_BMAPI_ENTIRE|XFS_BMAPI_IGSTATE;
+		XFS_ILOCK(mp, io, lockmode);
+		break;
+	default:
+		BUG();
+	}
 
-	mp = io->io_mount;
 	offset_fsb = XFS_B_TO_FSBT(mp, offset);
-	nimaps = sizeof(imap) / sizeof(imap[0]);
-	nimaps = min(nimaps, *npbmaps); /* Don't ask for more than caller has */
 	end_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)(offset + count)));
+
 	error = XFS_BMAPI(mp, NULL, io, offset_fsb,
-				(xfs_filblks_t)(end_fsb - offset_fsb),
-				flags, NULL, 0, imap,
-				&nimaps, NULL);
-	if (error) {
-		return XFS_ERROR(error);
+			(xfs_filblks_t)(end_fsb - offset_fsb) ,
+			bmap_flags,  NULL, 0, &imap,
+			&nimaps, NULL);
+
+	if (error)
+		goto out;
+
+	switch (flags & (PBF_WRITE|PBF_FILE_ALLOCATE)) {
+	case PBF_WRITE:
+		/* If we found an extent, return it */
+		if (nimaps && (imap.br_startblock != HOLESTARTBLOCK))
+			break;
+
+		if (flags & PBF_DIRECT) {
+			error = XFS_IOMAP_WRITE_DIRECT(mp, io, offset,
+					count, flags, &imap, &nimaps, nimaps);
+		} else {
+			error = XFS_IOMAP_WRITE_DELAY(mp, io, offset, count,
+					flags, &imap, &nimaps);
+		}
+		break;
+	case PBF_FILE_ALLOCATE:
+		/* If we found an extent, return it */
+		XFS_IUNLOCK(mp, io, lockmode);
+		lockmode = 0;
+
+		if (nimaps && !ISNULLSTARTBLOCK(imap.br_startblock))
+			break;
+
+		error = XFS_IOMAP_WRITE_ALLOCATE(mp, io, &imap, &nimaps);
+		break;
 	}
 
-	if(nimaps) {
-		*npbmaps = _xfs_imap_to_bmap(io, offset, imap, pbmapp, nimaps,
-			*npbmaps);
-	} else
+	if (nimaps) {
+		*npbmaps = _xfs_imap_to_bmap(io, offset, &imap,
+						pbmapp, nimaps, *npbmaps);
+	} else {
 		*npbmaps = 0;
+	}
+
+out:
+	if (lockmode)
+		XFS_IUNLOCK(mp, io, lockmode);
 	return XFS_ERROR(error);
 }
 
-/*
- * xfs_iomap_write: return pagebuf_bmap_t's telling higher layers
- *	where to write.
- * There are 2 main cases:
- *	1 the extents already exist
- *	2 must allocate.
- *	There are 3 cases when we allocate:
- *		delay allocation (doesn't really allocate or use transactions)
- *		direct allocation (no previous delay allocation)
- *		convert delay to real allocations
- */
-
 STATIC int
-xfs_iomap_write(
-	xfs_iocore_t	*io,
+xfs_flush_space(
+	xfs_inode_t	*ip,
+	int		*fsynced,
+	int		*ioflags)
+{
+	vnode_t		*vp = XFS_ITOV(ip);
+
+	switch (*fsynced) {
+	case 0:
+		if (ip->i_delayed_blks) {
+			xfs_iunlock(ip, XFS_ILOCK_EXCL);
+			filemap_fdatawrite(LINVFS_GET_IP(vp)->i_mapping);
+			xfs_ilock(ip, XFS_ILOCK_EXCL);
+			*fsynced = 1;
+		} else {
+			*ioflags |= PBF_SYNC;
+			*fsynced = 2;
+		}
+		return 0;
+	case 1:
+		*fsynced = 2;
+		*ioflags |= PBF_SYNC;
+		return 0;
+	case 2:
+		xfs_iunlock(ip, XFS_ILOCK_EXCL);
+		sync_blockdev(vp->v_vfsp->vfs_super->s_bdev);
+		xfs_log_force(ip->i_mount, (xfs_lsn_t)0,
+						XFS_LOG_FORCE|XFS_LOG_SYNC);
+		xfs_ilock(ip, XFS_ILOCK_EXCL);
+		*fsynced = 3;
+		return 0;
+	}
+	return 1;
+}
+
+int
+xfs_iomap_write_direct(
+	xfs_inode_t	*ip,
 	loff_t		offset,
 	size_t		count,
-	page_buf_bmap_t	*pbmapp,
-	int		*npbmaps,
-	int		ioflag)
+	int		ioflag,
+	xfs_bmbt_irec_t *ret_imap,
+	int		*nmaps,
+	int		found)
 {
-	int		maps;
-	int		error = 0;
-	int		found;
-	int		flags = 0;
+	xfs_mount_t	*mp = ip->i_mount;
+	xfs_iocore_t	*io = &ip->i_iocore;
+	xfs_fileoff_t	offset_fsb;
+	xfs_fileoff_t	last_fsb;
+	xfs_filblks_t	count_fsb;
+	xfs_fsize_t	isize;
+	xfs_fsblock_t	firstfsb;
+	int		nimaps, maps;
+	int		error;
+	int		bmapi_flag;
+	int		rt;
+	xfs_trans_t	*tp;
+	xfs_bmbt_irec_t imap[XFS_WRITE_IMAPS], *imapp;
+	xfs_bmap_free_t free_list;
+	int		aeof;
+	xfs_filblks_t	datablocks;
+	int		committed;
+	int		numrtextents;
+	uint		resblks;
 
-	maps = *npbmaps;
-	if (!maps)
-		goto out;
+	/*
+	 * Make sure that the dquots are there. This doesn't hold
+	 * the ilock across a disk read.
+	 */
+
+	if (XFS_IS_QUOTA_ON(mp) && XFS_NOT_DQATTACHED(mp, ip)) {
+		if ((error = xfs_qm_dqattach(ip, XFS_QMOPT_ILOCKED))) {
+			return XFS_ERROR(error);
+		}
+	}
+	maps = min(XFS_WRITE_IMAPS, *nmaps);
+	nimaps = maps;
+
+	isize = ip->i_d.di_size; 
+	aeof = (offset + count) > isize;
+
+	if (io->io_new_size > isize)
+		isize = io->io_new_size;
+
+	offset_fsb = XFS_B_TO_FSBT(mp, offset);
+	last_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)(offset + count)));
+	count_fsb = last_fsb - offset_fsb;
+	if (found && (ret_imap->br_startblock == HOLESTARTBLOCK)) {
+		xfs_fileoff_t	map_last_fsb;
+
+		map_last_fsb = ret_imap->br_blockcount + ret_imap->br_startoff;
+
+		if (map_last_fsb < last_fsb) {
+			last_fsb = map_last_fsb;
+			count_fsb = last_fsb - offset_fsb;
+		}
+		ASSERT(count_fsb > 0);
+	}
 
 	/*
-	 * If we have extents that are allocated for this range,
-	 * return them.
+	 * determine if reserving space on
+	 * the data or realtime partition.
 	 */
+	if ((rt = ip->i_d.di_flags & XFS_DIFLAG_REALTIME)) {
+		int	sbrtextsize, iprtextsize;
 
-	found = 0;
-	error = xfs_iomap_read(io, offset, count, flags, pbmapp, npbmaps);
-	if (error)
-		goto out;
+		sbrtextsize = mp->m_sb.sb_rextsize;
+		iprtextsize =
+			ip->i_d.di_extsize ? ip->i_d.di_extsize : sbrtextsize;
+		numrtextents = (count_fsb + iprtextsize - 1);
+		do_div(numrtextents, sbrtextsize);
+		datablocks = 0;
+	} else {
+		datablocks = count_fsb;
+		numrtextents = 0;
+	}
 
 	/*
-	 * If we found mappings and they can just have data written
-	 * without conversion,
-	 * let the caller write these and call us again.
-	 *
-	 * If we have a HOLE or UNWRITTEN, proceed down lower to
-	 * get the space or to convert to written.
+	 * allocate and setup the transaction
 	 */
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	tp = xfs_trans_alloc(mp, XFS_TRANS_DIOSTRAT);
+
+	resblks = XFS_DIOSTRAT_SPACE_RES(mp, datablocks);
+
+	error = xfs_trans_reserve(tp, resblks,
+			XFS_WRITE_LOG_RES(mp), numrtextents,
+			XFS_TRANS_PERM_LOG_RES,
+			XFS_WRITE_LOG_COUNT);
+
+	/*
+	 * check for running out of space
+	 */
+	if (error)
+		/*
+		 * Free the transaction structure.
+		 */
+		xfs_trans_cancel(tp, 0);
+
+	xfs_ilock(ip, XFS_ILOCK_EXCL);
 
-	if (*npbmaps) {
-		if (!(pbmapp->pbm_flags & PBMF_HOLE)) {
-			*npbmaps = 1; /* Only checked the first one. */
-					/* We could check more, ... */
-			goto out;
+	if (error)
+		goto error_out; /* Don't return in above if .. trans ..,
+					need lock to return */
+
+	if (XFS_IS_QUOTA_ON(mp)) {
+		if (xfs_trans_reserve_blkquota(tp, ip, resblks)) {
+			error = (EDQUOT);
+			goto error1;
 		}
 	}
-	found = *npbmaps;
-	*npbmaps = maps; /* Restore to original requested */
+	nimaps = 1;
 
-	if (ioflag & PBF_DIRECT) {
-		error = xfs_iomap_write_direct(io, offset, count, pbmapp,
-					npbmaps, ioflag, found);
-	} else {
-		error = xfs_iomap_write_delay(io, offset, count, pbmapp,
-				npbmaps, ioflag, found);
+	bmapi_flag = XFS_BMAPI_WRITE;
+	xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
+	xfs_trans_ihold(tp, ip);
+
+	if (offset < ip->i_d.di_size || rt)
+		bmapi_flag |= XFS_BMAPI_PREALLOC;
+
+	/*
+	 * issue the bmapi() call to allocate the blocks
+	 */
+	XFS_BMAP_INIT(&free_list, &firstfsb);
+	imapp = &imap[0];
+	error = xfs_bmapi(tp, ip, offset_fsb, count_fsb,
+		bmapi_flag, &firstfsb, 0, imapp, &nimaps, &free_list);
+	if (error) {
+		goto error0;
 	}
 
-out:
-	XFS_IUNLOCK(io->io_mount, io, XFS_ILOCK_EXCL);
+	/*
+	 * complete the transaction
+	 */
+
+	error = xfs_bmap_finish(&tp, &free_list, firstfsb, &committed);
+	if (error) {
+		goto error0;
+	}
+
+	error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES, NULL);
+	if (error) {
+		goto error_out;
+	}
+
+	/* copy any maps to caller's array and return any error. */
+	if (nimaps == 0) {
+		error = (ENOSPC);
+		goto error_out;
+	}
+
+	*ret_imap = imap[0];
+	*nmaps = 1;
+	return 0;
+
+ error0:	/* Cancel bmap, unlock inode, and cancel trans */
+	xfs_bmap_cancel(&free_list);
+
+ error1:	/* Just cancel transaction */
+	xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT);
+	*nmaps = 0;	/* nothing set-up here */
+
+error_out:
 	return XFS_ERROR(error);
 }
 
-STATIC int
+int
 xfs_iomap_write_delay(
-	xfs_iocore_t	*io,
+	xfs_inode_t	*ip,
 	loff_t		offset,
 	size_t		count,
-	page_buf_bmap_t	*pbmapp,
-	int		*npbmaps,
 	int		ioflag,
-	int		found)
+	xfs_bmbt_irec_t *ret_imap,
+	int		*nmaps)
 {
+	xfs_mount_t	*mp = ip->i_mount;
+	xfs_iocore_t	*io = &ip->i_iocore;
 	xfs_fileoff_t	offset_fsb;
-	xfs_fileoff_t	ioalign;
 	xfs_fileoff_t	last_fsb;
-	xfs_fileoff_t	start_fsb;
-	xfs_filblks_t	count_fsb;
-	xfs_off_t	aligned_offset;
 	xfs_fsize_t	isize;
 	xfs_fsblock_t	firstblock;
 	int		nimaps;
 	int		error;
-	int		n;
-	unsigned int	iosize;
-	xfs_mount_t	*mp;
-#define XFS_WRITE_IMAPS XFS_BMAP_MAX_NMAP
 	xfs_bmbt_irec_t imap[XFS_WRITE_IMAPS];
 	int		aeof;
+	int		fsynced = 0;
 
-	ASSERT(ismrlocked(io->io_lock, MR_UPDATE) != 0);
+	ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE) != 0);
 
-	mp = io->io_mount;
+	/*
+	 * Make sure that the dquots are there. This doesn't hold
+	 * the ilock across a disk read.
+	 */
 
-	isize = XFS_SIZE(mp, io);
+	if (XFS_IS_QUOTA_ON(mp) && XFS_NOT_DQATTACHED(mp, ip)) {
+		if ((error = xfs_qm_dqattach(ip, XFS_QMOPT_ILOCKED))) {
+			return XFS_ERROR(error);
+		}
+	}
+
+retry:
+	isize = ip->i_d.di_size;
 	if (io->io_new_size > isize) {
 		isize = io->io_new_size;
 	}
@@ -591,50 +436,22 @@
 	 * then extend the allocation (and the buffer used for the write)
 	 * out to the file system's write iosize.  We clean up any extra
 	 * space left over when the file is closed in xfs_inactive().
-	 * We can only do this if we are sure that we will create buffers
-	 * over all of the space we allocate beyond the end of the file.
-	 * Not doing so would allow us to create delalloc blocks with
-	 * no pages in memory covering them.  So, we need to check that
-	 * there are not any real blocks in the area beyond the end of
-	 * the file which we are optimistically going to preallocate. If
-	 * there are then our buffers will stop when they encounter them
-	 * and we may accidentally create delalloc blocks beyond them
-	 * that we never cover with a buffer.  All of this is because
-	 * we are not actually going to write the extra blocks preallocated
-	 * at this point.
 	 *
 	 * We don't bother with this for sync writes, because we need
 	 * to minimize the amount we write for good performance.
 	 */
-	if (!(ioflag & PBF_SYNC) && ((offset + count) > XFS_SIZE(mp, io))) {
-		start_fsb = XFS_B_TO_FSBT(mp,
-				  ((xfs_ufsize_t)(offset + count - 1)));
-		count_fsb = mp->m_writeio_blocks;
-		while (count_fsb > 0) {
-			nimaps = XFS_WRITE_IMAPS;
-			error = XFS_BMAPI(mp, NULL, io, start_fsb, count_fsb,
-					  0, NULL, 0, imap, &nimaps,
-					  NULL);
-			if (error) {
-				return error;
-			}
-			for (n = 0; n < nimaps; n++) {
-				if ((imap[n].br_startblock != HOLESTARTBLOCK) &&
-				    (imap[n].br_startblock != DELAYSTARTBLOCK)) {
-					goto write_map;
-				}
-				start_fsb += imap[n].br_blockcount;
-				count_fsb -= imap[n].br_blockcount;
-				ASSERT(count_fsb < 0xffff000);
-			}
-		}
+	if (!(ioflag & PBF_SYNC) && ((offset + count) > ip->i_d.di_size)) {
+		xfs_off_t	aligned_offset;
+		unsigned int	iosize;
+		xfs_fileoff_t	ioalign;
+
 		iosize = mp->m_writeio_blocks;
 		aligned_offset = XFS_WRITEIO_ALIGN(mp, (offset + count - 1));
 		ioalign = XFS_B_TO_FSBT(mp, aligned_offset);
 		last_fsb = ioalign + iosize;
 		aeof = 1;
 	}
- write_map:
+
 	nimaps = XFS_WRITE_IMAPS;
 	firstblock = NULLFSBLOCK;
 
@@ -642,11 +459,11 @@
 	 * roundup the allocation request to m_dalign boundary if file size
 	 * is greater that 512K and we are allocating past the allocation eof
 	 */
-	if (mp->m_dalign && (XFS_SIZE(mp, io) >= mp->m_dalign) && aeof) {
+	if (mp->m_dalign && (isize >= mp->m_dalign) && aeof) {
 		int eof;
 		xfs_fileoff_t new_last_fsb;
 		new_last_fsb = roundup_64(last_fsb, mp->m_dalign);
-		error = XFS_BMAP_EOF(mp, io, new_last_fsb, XFS_DATA_FORK, &eof);
+		error = xfs_bmap_eof(ip, new_last_fsb, XFS_DATA_FORK, &eof);
 		if (error) {
 			return error;
 		}
@@ -655,7 +472,7 @@
 		}
 	}
 
-	error = XFS_BMAPI(mp, NULL, io, offset_fsb,
+	error = xfs_bmapi(NULL, ip, offset_fsb,
 			  (xfs_filblks_t)(last_fsb - offset_fsb),
 			  XFS_BMAPI_DELAY | XFS_BMAPI_WRITE |
 			  XFS_BMAPI_ENTIRE, &firstblock, 1, imap,
@@ -663,235 +480,255 @@
 	/*
 	 * This can be EDQUOT, if nimaps == 0
 	 */
-	if (error) {
+	if (error && (error != ENOSPC)) {
 		return XFS_ERROR(error);
 	}
 	/*
 	 * If bmapi returned us nothing, and if we didn't get back EDQUOT,
 	 * then we must have run out of space.
 	 */
+
 	if (nimaps == 0) {
-		return XFS_ERROR(ENOSPC);
+		if (xfs_flush_space(ip, &fsynced, &ioflag))
+			return XFS_ERROR(ENOSPC);
+
+		error = 0;
+		goto retry;
 	}
 
-	/*
-	 * Now map our desired I/O size and alignment over the
-	 * extents returned by xfs_bmapi().
-	 */
-	*npbmaps = _xfs_imap_to_bmap(io, offset, imap, pbmapp,
-						nimaps, *npbmaps);
+	*ret_imap = imap[0];
+	*nmaps = 1;
 	return 0;
 }
 
-STATIC int
-xfs_iomap_write_direct(
-	xfs_iocore_t	*io,
-	loff_t		offset,
-	size_t		count,
-	page_buf_bmap_t	*pbmapp,
-	int		*npbmaps,
-	int		ioflag,
-	int		found)
+/*
+ * Pass in a delayed allocate extent, convert it to real extents;
+ * return to the caller the extent we create which maps on top of
+ * the originating callers request.
+ *
+ * Called without a lock on the inode.
+ */
+int
+xfs_iomap_write_allocate(
+	xfs_inode_t	*ip,
+	xfs_bmbt_irec_t *map,
+	int		*retmap)
 {
-	xfs_inode_t	*ip = XFS_IO_INODE(io);
-	xfs_mount_t	*mp;
-	xfs_fileoff_t	offset_fsb;
-	xfs_fileoff_t	last_fsb;
+	xfs_mount_t	*mp = ip->i_mount;
+	xfs_fileoff_t	offset_fsb, last_block;
+	xfs_fileoff_t	end_fsb, map_start_fsb;
+	xfs_fsblock_t	first_block;
+	xfs_bmap_free_t	free_list;
 	xfs_filblks_t	count_fsb;
-	xfs_fsize_t	isize;
-	xfs_fsblock_t	firstfsb;
-	int		nimaps, maps;
-	int		error;
+	xfs_bmbt_irec_t	imap[XFS_STRAT_WRITE_IMAPS];
 	xfs_trans_t	*tp;
+	int		i, nimaps, committed;
+	int		error = 0;
 
-#define XFS_WRITE_IMAPS XFS_BMAP_MAX_NMAP
-	xfs_bmbt_irec_t imap[XFS_WRITE_IMAPS], *imapp;
-	xfs_bmap_free_t free_list;
-	int		aeof;
-	int		bmapi_flags;
-	xfs_filblks_t	datablocks;
-	int		rt;
-	int		committed;
-	int		numrtextents;
-	uint		resblks;
-	int		rtextsize;
+	*retmap = 0;
 
-	maps = min(XFS_WRITE_IMAPS, *npbmaps);
-	nimaps = maps;
+	/*
+	 * Make sure that the dquots are there.
+	 */
 
-	mp = io->io_mount;
-	isize = XFS_SIZE(mp, io);
-	if (io->io_new_size > isize)
-		isize = io->io_new_size;
+	if (XFS_IS_QUOTA_ON(mp) && XFS_NOT_DQATTACHED(mp, ip)) {
+		if ((error = xfs_qm_dqattach(ip, 0))) {
+			return XFS_ERROR(error);
+		}
+	}
 
-	aeof = ((offset + count) > isize) ? 1 : 0;
+	offset_fsb = map->br_startoff;
+	count_fsb = map->br_blockcount;
+	map_start_fsb = offset_fsb;
 
-	offset_fsb = XFS_B_TO_FSBT(mp, offset);
-	last_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)(offset + count)));
-	count_fsb = last_fsb - offset_fsb;
-	if (found && (pbmapp->pbm_flags & PBMF_HOLE)) {
-		xfs_fileoff_t	map_last_fsb;
+	XFS_STATS_ADD(xfsstats.xs_xstrat_bytes, XFS_FSB_TO_B(mp, count_fsb));
 
-		map_last_fsb = XFS_B_TO_FSB(mp,
-			(pbmapp->pbm_bsize + pbmapp->pbm_offset));
+	while (count_fsb != 0) {
+		/*
+		 * Set up a transaction with which to allocate the
+		 * backing store for the file.  Do allocations in a
+		 * loop until we get some space in the range we are
+		 * interested in.  The other space that might be allocated
+		 * is in the delayed allocation extent on which we sit
+		 * but before our buffer starts.
+		 */
 
-		if (map_last_fsb < last_fsb) {
-			last_fsb = map_last_fsb;
-			count_fsb = last_fsb - offset_fsb;
-		}
-		ASSERT(count_fsb > 0);
-	}
+		nimaps = 0;
+		while (nimaps == 0) {
+			tp = xfs_trans_alloc(mp, XFS_TRANS_STRAT_WRITE);
+			error = xfs_trans_reserve(tp, 0, XFS_WRITE_LOG_RES(mp),
+					0, XFS_TRANS_PERM_LOG_RES,
+					XFS_WRITE_LOG_COUNT);
+			if (error) {
+				xfs_trans_cancel(tp, 0);
+				return XFS_ERROR(error);
+			}
+			xfs_ilock(ip, XFS_ILOCK_EXCL);
+			xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
+			xfs_trans_ihold(tp, ip);
 
-	/*
-	 * roundup the allocation request to m_dalign boundary if file size
-	 * is greater that 512K and we are allocating past the allocation eof
-	 */
-	if (!found && mp->m_dalign && (isize >= 524288) && aeof) {
-		int		eof;
-		xfs_fileoff_t	new_last_fsb;
+			XFS_BMAP_INIT(&free_list, &first_block);
 
-		new_last_fsb = roundup_64(last_fsb, mp->m_dalign);
-		printk("xfs_iomap_write_direct: about to XFS_BMAP_EOF %Ld\n",
-			new_last_fsb);
-		error = XFS_BMAP_EOF(mp, io, new_last_fsb, XFS_DATA_FORK, &eof);
-		if (error)
-			goto error_out;
-		if (eof)
-			last_fsb = new_last_fsb;
-	}
+			nimaps = XFS_STRAT_WRITE_IMAPS;
+			/*
+			 * Ensure we don't go beyond eof - it is possible
+			 * the extents changed since we did the read call,
+			 * we dropped the ilock in the interim.
+			 */
 
-	bmapi_flags = XFS_BMAPI_WRITE|XFS_BMAPI_DIRECT_IO|XFS_BMAPI_ENTIRE;
-	bmapi_flags &= ~XFS_BMAPI_DIRECT_IO;
+			end_fsb = XFS_B_TO_FSB(mp, ip->i_d.di_size);
+			xfs_bmap_last_offset(NULL, ip, &last_block,
+				XFS_DATA_FORK);
+			last_block = XFS_FILEOFF_MAX(last_block, end_fsb);
+			if ((map_start_fsb + count_fsb) > last_block) {
+				count_fsb = last_block - map_start_fsb;
+				if (count_fsb == 0) {
+					error = EAGAIN;
+					goto trans_cancel;
+				}
+			}
 
-	/*
-	 * determine if this is a realtime file
-	 */
-	if ((rt = (ip->i_d.di_flags & XFS_DIFLAG_REALTIME)) != 0) {
-		rtextsize = mp->m_sb.sb_rextsize;
-	} else
-		rtextsize = 0;
+			/* Go get the actual blocks */
+			error = xfs_bmapi(tp, ip, map_start_fsb, count_fsb,
+					XFS_BMAPI_WRITE, &first_block, 1,
+					imap, &nimaps, &free_list);
 
-	error = 0;
+			if (error)
+				goto trans_cancel;
 
-	/*
-	 * allocate file space for the bmapp entries passed in.
-	 */
+			error = xfs_bmap_finish(&tp, &free_list,
+					first_block, &committed);
 
-	/*
-	 * determine if reserving space on
-	 * the data or realtime partition.
-	 */
-	if (rt) {
-		numrtextents = (count_fsb + rtextsize - 1);
-		do_div(numrtextents, rtextsize);
-		datablocks = 0;
-	} else {
-		datablocks = count_fsb;
-		numrtextents = 0;
-	}
+			if (error)
+				goto trans_cancel;
 
-	/*
-	 * allocate and setup the transaction
-	 */
-	tp = xfs_trans_alloc(mp, XFS_TRANS_DIOSTRAT);
-	resblks = XFS_DIOSTRAT_SPACE_RES(mp, datablocks);
+			error = xfs_trans_commit(tp,
+					XFS_TRANS_RELEASE_LOG_RES, NULL);
 
-	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+			if (error)
+				goto error0;
 
-	error = xfs_trans_reserve(tp,
-				  resblks,
-				  XFS_WRITE_LOG_RES(mp),
-				  numrtextents,
-				  XFS_TRANS_PERM_LOG_RES,
-				  XFS_WRITE_LOG_COUNT);
+			xfs_iunlock(ip, XFS_ILOCK_EXCL);
+		}
 
-	/*
-	 * check for running out of space
-	 */
-	if (error) {
 		/*
-		 * Free the transaction structure.
+		 * See if we were able to allocate an extent that
+		 * covers at least part of the callers request
 		 */
-		xfs_trans_cancel(tp, 0);
-	}
 
-	xfs_ilock(ip, XFS_ILOCK_EXCL);
+		for (i = 0; i < nimaps; i++) {
+			if ((map->br_startoff >= imap[i].br_startoff) &&
+			    (map->br_startoff < (imap[i].br_startoff +
+					         imap[i].br_blockcount))) {
+				*map = imap[i];
+				*retmap = 1;
+				XFS_STATS_INC(xfsstats.xs_xstrat_quick);
+				return 0;
+			}
+			count_fsb -= imap[i].br_blockcount;
+		}
 
-	if (error)  {
-		goto error_out; /* Don't return in above if .. trans ..,
-					need lock to return */
+		/* So far we have not mapped the requested part of the
+		 * file, just surrounding data, try again.
+		 */
+		nimaps--;
+		offset_fsb = imap[nimaps].br_startoff +
+			     imap[nimaps].br_blockcount;
+		map_start_fsb = offset_fsb;
 	}
 
-	if (XFS_IS_QUOTA_ON(mp)) {
-		if (xfs_trans_reserve_quota(tp,
-					    ip->i_udquot,
-					    ip->i_gdquot,
-					    resblks, 0, 0)) {
-			error = (EDQUOT);
-			goto error1;
-		}
-		nimaps = 1;
-	} else {
-		nimaps = 2;
-	}
+trans_cancel:
+	xfs_bmap_cancel(&free_list);
+	xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT);
+error0:
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	return XFS_ERROR(error);
+}
 
-	xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
-	xfs_trans_ihold(tp, ip);
+int
+xfs_iomap_write_unwritten(
+	xfs_inode_t	*ip,
+	loff_t		offset,
+	size_t		count)
+{
+	xfs_mount_t	*mp = ip->i_mount;
+	xfs_trans_t	*tp;
+	xfs_fileoff_t	offset_fsb;
+	xfs_filblks_t	count_fsb;
+	xfs_filblks_t	numblks_fsb;
+	xfs_bmbt_irec_t	imap;
+	int		committed;
+	int		error;
+	int		nres;
+	int		nimaps;
+	xfs_fsblock_t	firstfsb;
+	xfs_bmap_free_t	free_list;
 
-	/*
-	 * issue the bmapi() call to allocate the blocks
-	 */
-	XFS_BMAP_INIT(&free_list, &firstfsb);
-	imapp = &imap[0];
-	error = XFS_BMAPI(mp, tp, io, offset_fsb, count_fsb,
-		bmapi_flags, &firstfsb, 1, imapp, &nimaps, &free_list);
-	if (error) {
-		goto error0;
-	}
+	offset_fsb = XFS_B_TO_FSBT(mp, offset);
+	count_fsb = XFS_B_TO_FSB(mp, count);
 
-	/*
-	 * complete the transaction
-	 */
+	do {
+		nres = XFS_DIOSTRAT_SPACE_RES(mp, 0);
 
-	error = xfs_bmap_finish(&tp, &free_list, firstfsb, &committed);
-	if (error) {
-		goto error0;
-	}
+		/*
+		 * set up a transaction to convert the range of extents
+		 * from unwritten to real. Do allocations in a loop until
+		 * we have covered the range passed in.
+		 */
 
-	error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES, NULL);
-	if (error) {
-		goto error_out;
-	}
+		tp = xfs_trans_alloc(mp, XFS_TRANS_STRAT_WRITE);
+		error = xfs_trans_reserve(tp, nres,
+				XFS_WRITE_LOG_RES(mp), 0,
+				XFS_TRANS_PERM_LOG_RES,
+				XFS_WRITE_LOG_COUNT);
+		if (error) {
+			xfs_trans_cancel(tp, 0);
+			goto error0;
+		}
 
-	/* copy any maps to caller's array and return any error. */
-	if (nimaps == 0) {
-		error = (ENOSPC);
-		goto error_out;
-	}
+		xfs_ilock(ip, XFS_ILOCK_EXCL);
+		xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
+		xfs_trans_ihold(tp, ip);
 
-	maps = min(nimaps, maps);
-	*npbmaps = _xfs_imap_to_bmap(io, offset, &imap[0], pbmapp, maps,
-								*npbmaps);
-	if (*npbmaps) {
 		/*
-		 * this is new since xfs_iomap_read
-		 * didn't find it.
+		 * Modify the unwritten extent state of the buffer.
 		 */
-		if (*npbmaps != 1) {
-			/* NEED MORE WORK FOR MULTIPLE BMAPS (which are new) */
-			BUG();
-		}
-	}
-	goto out;
+		XFS_BMAP_INIT(&free_list, &firstfsb);
+		nimaps = 1;
+		error = xfs_bmapi(tp, ip, offset_fsb, count_fsb,
+				  XFS_BMAPI_WRITE, &firstfsb,
+				  1, &imap, &nimaps, &free_list);
+		if (error)
+			goto error_on_bmapi_transaction;
 
- error0:	/* Cancel bmap, unlock inode, and cancel trans */
-	xfs_bmap_cancel(&free_list);
+		error = xfs_bmap_finish(&(tp), &(free_list),
+				firstfsb, &committed);
+		if (error)
+			goto error_on_bmapi_transaction;
 
- error1:	/* Just cancel transaction */
-	xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT);
-	*npbmaps = 0;	/* nothing set-up here */
+		error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES, NULL);
+		xfs_iunlock(ip, XFS_ILOCK_EXCL);
+		if (error)
+			goto error0;
 
-error_out:
-out:	/* Just return error and any tracing at end of routine */
+		if ((numblks_fsb = imap.br_blockcount) == 0) {
+			/*
+			 * The numblks_fsb value should always get
+			 * smaller, otherwise the loop is stuck.
+			 */
+			ASSERT(imap.br_blockcount);
+			break;
+		}
+		offset_fsb += numblks_fsb;
+		count_fsb -= numblks_fsb;
+	} while (count_fsb > 0);
+
+	return 0;
+
+error_on_bmapi_transaction:
+	xfs_bmap_cancel(&free_list);
+	xfs_trans_cancel(tp, (XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT));
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+error0:
 	return XFS_ERROR(error);
 }
diff -Nru a/fs/xfs/linux/xfs_iops.c b/fs/xfs/linux/xfs_iops.c
--- a/fs/xfs/linux/xfs_iops.c	Mon Dec 23 21:21:53 2002
+++ b/fs/xfs/linux/xfs_iops.c	Mon Dec 23 21:21:53 2002
@@ -575,7 +575,7 @@
 linvfs_setxattr(
 	struct dentry	*dentry,
 	const char	*name,
-	void		*data,
+	const void	*data,
 	size_t		size,
 	int		flags)
 {
@@ -593,13 +593,15 @@
 		error = -ENOATTR;
 		p += xfs_namespaces[SYSTEM_NAMES].namelen;
 		if (strcmp(p, POSIXACL_ACCESS) == 0) {
-			error = xfs_acl_vset(vp, data, size, _ACL_TYPE_ACCESS);
+			error = xfs_acl_vset(vp, (void *) data, size,
+						_ACL_TYPE_ACCESS);
 		}
 		else if (strcmp(p, POSIXACL_DEFAULT) == 0) {
-			error = xfs_acl_vset(vp, data, size, _ACL_TYPE_DEFAULT);
+			error = xfs_acl_vset(vp, (void *) data, size,
+						_ACL_TYPE_DEFAULT);
 		}
 		else if (strcmp(p, POSIXCAP) == 0) {
-			error = xfs_cap_vset(vp, data, size);
+			error = xfs_cap_vset(vp, (void *) data, size);
 		}
 		if (!error) {
 			error = vn_revalidate(vp);
@@ -619,7 +621,7 @@
 			return -EPERM;
 		xflags |= ATTR_ROOT;
 		p += xfs_namespaces[ROOT_NAMES].namelen;
-		VOP_ATTR_SET(vp, p, data, size, xflags, NULL, error);
+		VOP_ATTR_SET(vp, p, (void *) data, size, xflags, NULL, error);
 		return -error;
 	}
 	if (strncmp(name, xfs_namespaces[USER_NAMES].name,
@@ -627,7 +629,7 @@
 		if (!capable_user_xattr(inode))
 			return -EPERM;
 		p += xfs_namespaces[USER_NAMES].namelen;
-		VOP_ATTR_SET(vp, p, data, size, xflags, NULL, error);
+		VOP_ATTR_SET(vp, p, (void *) data, size, xflags, NULL, error);
 		return -error;
 	}
 	return -ENOATTR;
diff -Nru a/fs/xfs/linux/xfs_lrw.c b/fs/xfs/linux/xfs_lrw.c
--- a/fs/xfs/linux/xfs_lrw.c	Mon Dec 23 21:21:50 2002
+++ b/fs/xfs/linux/xfs_lrw.c	Mon Dec 23 21:21:50 2002
@@ -808,6 +808,25 @@
 	}
 }
 
+
+int
+xfs_bmap(bhv_desc_t	*bdp,
+	xfs_off_t	offset,
+	ssize_t		count,
+	int		flags,
+	page_buf_bmap_t	*pbmapp,
+	int		*npbmaps)
+{
+	xfs_inode_t	*ip = XFS_BHVTOI(bdp);
+	xfs_iocore_t	*io = &ip->i_iocore;
+
+	ASSERT((ip->i_d.di_mode & IFMT) == IFREG);
+	ASSERT(((ip->i_d.di_flags & XFS_DIFLAG_REALTIME) != 0) ==
+	       ((ip->i_iocore.io_flags & XFS_IOCORE_RT) != 0));
+
+	return xfs_iomap(io, offset, count, flags, pbmapp, npbmaps);
+}
+
 /*
  * Wrapper around bdstrat so that we can stop data
  * from going to disk in case we are shutting down the filesystem.
diff -Nru a/fs/xfs/linux/xfs_lrw.h b/fs/xfs/linux/xfs_lrw.h
--- a/fs/xfs/linux/xfs_lrw.h	Mon Dec 23 21:21:51 2002
+++ b/fs/xfs/linux/xfs_lrw.h	Mon Dec 23 21:21:51 2002
@@ -36,6 +36,8 @@
 struct bhv_desc;
 struct xfs_mount;
 struct xfs_iocore;
+struct xfs_inode;
+struct xfs_bmbt_irec;
 struct page_buf_s;
 struct page_buf_bmap_s;
 
@@ -61,6 +63,16 @@
 extern ssize_t xfs_sendfile (struct bhv_desc *, struct file *,
 				loff_t *, size_t, read_actor_t,
 				void *, struct cred *);
+
+extern int xfs_iomap (struct xfs_iocore *, xfs_off_t, ssize_t, int,
+				struct page_buf_bmap_s *, int *);
+extern int xfs_iomap_write_direct (struct xfs_inode *, loff_t, size_t,
+				int, struct xfs_bmbt_irec *, int *, int);
+extern int xfs_iomap_write_delay (struct xfs_inode *, loff_t, size_t,
+				int, struct xfs_bmbt_irec *, int *);
+extern int xfs_iomap_write_allocate (struct xfs_inode *,
+				struct xfs_bmbt_irec *, int *);
+extern int xfs_iomap_write_unwritten (struct xfs_inode *, loff_t, size_t);
 
 extern int xfs_dev_is_read_only (struct xfs_mount *, char *);
 
diff -Nru a/fs/xfs/linux/xfs_super.c b/fs/xfs/linux/xfs_super.c
--- a/fs/xfs/linux/xfs_super.c	Mon Dec 23 21:22:00 2002
+++ b/fs/xfs/linux/xfs_super.c	Mon Dec 23 21:22:00 2002
@@ -507,8 +507,15 @@
 	truncate_inode_pages(btp->pbr_mapping, 0LL);
 }
 
+unsigned int
+xfs_getsize_buftarg(
+	xfs_buftarg_t		*btp)
+{
+	return block_size(btp->pbr_bdev);
+}
+
 void
-xfs_size_buftarg(
+xfs_setsize_buftarg(
 	xfs_buftarg_t		*btp,
 	unsigned int		blocksize,
 	unsigned int		sectorsize)
@@ -535,7 +542,7 @@
 	btp->pbr_dev =  bdev->bd_dev;
 	btp->pbr_bdev = bdev;
 	btp->pbr_mapping = bdev->bd_inode->i_mapping;
-	xfs_size_buftarg(btp, PAGE_CACHE_SIZE, bdev_hardsect_size(bdev));
+	xfs_setsize_buftarg(btp, PAGE_CACHE_SIZE, bdev_hardsect_size(bdev));
 
 	return btp;
 }
diff -Nru a/fs/xfs/linux/xfs_super.h b/fs/xfs/linux/xfs_super.h
--- a/fs/xfs/linux/xfs_super.h	Mon Dec 23 21:21:52 2002
+++ b/fs/xfs/linux/xfs_super.h	Mon Dec 23 21:21:52 2002
@@ -82,15 +82,17 @@
 struct pb_target;
 struct block_device;
 
-extern void xfs_initialize_vnode (bhv_desc_t *, vnode_t *, bhv_desc_t *, int);
+extern void xfs_initialize_vnode(bhv_desc_t *, vnode_t *, bhv_desc_t *, int);
 
-extern int  xfs_blkdev_get (struct xfs_mount *, const char *,
+extern int  xfs_blkdev_get(struct xfs_mount *, const char *,
 				struct block_device **);
-extern void xfs_blkdev_put (struct block_device *);
+extern void xfs_blkdev_put(struct block_device *);
 
-extern struct pb_target *xfs_alloc_buftarg (struct block_device *);
-extern void xfs_size_buftarg (struct pb_target *, unsigned int, unsigned int);
-extern void xfs_relse_buftarg (struct pb_target *);
-extern void xfs_free_buftarg (struct pb_target *);
+extern struct pb_target *xfs_alloc_buftarg(struct block_device *);
+extern void xfs_relse_buftarg(struct pb_target *);
+extern void xfs_free_buftarg(struct pb_target *);
+
+extern void xfs_setsize_buftarg(struct pb_target *, unsigned int, unsigned int);
+extern unsigned int xfs_getsize_buftarg(struct pb_target *);
 
 #endif	/* __XFS_SUPER_H__ */
diff -Nru a/fs/xfs/pagebuf/page_buf.c b/fs/xfs/pagebuf/page_buf.c
--- a/fs/xfs/pagebuf/page_buf.c	Mon Dec 23 21:21:50 2002
+++ b/fs/xfs/pagebuf/page_buf.c	Mon Dec 23 21:21:50 2002
@@ -67,7 +67,7 @@
 #define BN_ALIGN_MASK	((1 << (PAGE_CACHE_SHIFT - BBSHIFT)) - 1)
 
 #ifndef GFP_READAHEAD
-#define GFP_READAHEAD	0
+#define GFP_READAHEAD	__GFP_NOWARN
 #endif
 
 /*
@@ -806,11 +806,7 @@
 		return;
 
 	flags |= (PBF_TRYLOCK|PBF_READ|PBF_ASYNC|PBF_MAPPABLE|PBF_READ_AHEAD);
-
-	/* don't complain on allocation failure, it's fine with us */
-	current->flags |= PF_NOWARN;
 	pagebuf_get(target, ioff, isize, flags);
-	current->flags &= ~PF_NOWARN;
 }
 
 page_buf_t *
diff -Nru a/fs/xfs/pagebuf/page_buf.h b/fs/xfs/pagebuf/page_buf.h
--- a/fs/xfs/pagebuf/page_buf.h	Mon Dec 23 21:21:56 2002
+++ b/fs/xfs/pagebuf/page_buf.h	Mon Dec 23 21:21:56 2002
@@ -48,9 +48,6 @@
 #include <linux/buffer_head.h>
 #include <linux/uio.h>
 
-enum xfs_buffer_state { BH_Delay = BH_PrivateStart };
-BUFFER_FNS(Delay, delay);
-
 /*
  * Turn this on to get pagebuf lock ownership
 #define PAGEBUF_LOCK_TRACKING
@@ -83,7 +80,7 @@
 	PBMF_HOLE =		0x02,	/* mapping covers a hole	*/
 	PBMF_DELAY =		0x04,	/* mapping covers delalloc region  */
 	PBMF_UNWRITTEN =	0x20	/* mapping covers allocated	*/
-					/* but uninitialized XFS data	*/
+					/* but uninitialized file data	*/
 } bmap_flags_t;
 
 typedef enum page_buf_flags_e {		/* pb_flags values */
@@ -105,19 +102,17 @@
 	PBF_TRYLOCK = (1 << 14), /* lock requested, but do not wait	   */
 	PBF_FILE_ALLOCATE = (1 << 15), /* allocate all file space	   */
 	PBF_DONT_BLOCK = (1 << 16), /* do not block in current thread	   */
-	PBF_DIRECT = (1 << 17),	  /* direct I/O desired			   */
+	PBF_DIRECT = (1 << 17),	/* direct I/O desired			   */
+	PBF_FILE_UNWRITTEN = (1 << 18), /* convert unwritten extent space  */
 
 	/* flags used only internally */
 	_PBF_LOCKABLE = (1 << 19), /* page_buf_t may be locked		   */
-	_PBF_ALL_PAGES_MAPPED = (1 << 21),
-				/* all pages in rage are mapped		   */
-	_PBF_ADDR_ALLOCATED = (1 << 22),
-				/* pb_addr space was allocated		   */
-	_PBF_MEM_ALLOCATED = (1 << 23),
-				/* pb_mem and underlying pages allocated   */
+	_PBF_ALL_PAGES_MAPPED = (1 << 21), /* all pages in range mapped	   */
+	_PBF_ADDR_ALLOCATED = (1 << 22), /* pb_addr space was allocated	   */
+	_PBF_MEM_ALLOCATED = (1 << 23), /* pb_mem+underlying pages alloc'd */
 
 	PBF_FORCEIO = (1 << 24),
-	PBF_FLUSH = (1 << 25),	/* flush disk write cache */
+	PBF_FLUSH = (1 << 25),	/* flush disk write cache		   */
 	PBF_READ_AHEAD = (1 << 26),
 
 } page_buf_flags_t;
diff -Nru a/fs/xfs/xfs_alloc_btree.h b/fs/xfs/xfs_alloc_btree.h
--- a/fs/xfs/xfs_alloc_btree.h	Mon Dec 23 21:22:00 2002
+++ b/fs/xfs/xfs_alloc_btree.h	Mon Dec 23 21:22:00 2002
@@ -104,8 +104,8 @@
 #define XFS_MAX_BLOCKSIZE_LOG	16	/* i.e. 65536 bytes */
 #define XFS_MIN_BLOCKSIZE	(1 << XFS_MIN_BLOCKSIZE_LOG)
 #define XFS_MAX_BLOCKSIZE	(1 << XFS_MAX_BLOCKSIZE_LOG)
-#define XFS_MIN_SECTORSIZE_LOG	9       /* i.e. 512 bytes */
-#define XFS_MAX_SECTORSIZE_LOG	15      /* i.e. 32768 bytes */
+#define XFS_MIN_SECTORSIZE_LOG	9	/* i.e. 512 bytes */
+#define XFS_MAX_SECTORSIZE_LOG	15	/* i.e. 32768 bytes */
 #define XFS_MIN_SECTORSIZE	(1 << XFS_MIN_SECTORSIZE_LOG)
 #define XFS_MAX_SECTORSIZE	(1 << XFS_MAX_SECTORSIZE_LOG)
 
diff -Nru a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h
--- a/fs/xfs/xfs_buf.h	Mon Dec 23 21:22:00 2002
+++ b/fs/xfs/xfs_buf.h	Mon Dec 23 21:22:00 2002
@@ -35,28 +35,34 @@
 /* These are just for xfs_syncsub... it sets an internal variable
  * then passes it to VOP_FLUSH_PAGES or adds the flags to a newly gotten buf_t
  */
-#define XFS_B_ASYNC  PBF_ASYNC
-#define XFS_B_DELWRI PBF_DELWRI
-#define XFS_B_READ   PBF_READ
-#define XFS_B_WRITE  PBF_WRITE
-#define XFS_B_STALE  PBF_STALE
+#define XFS_B_ASYNC		PBF_ASYNC
+#define XFS_B_DELWRI		PBF_DELWRI
+#define XFS_B_READ		PBF_READ
+#define XFS_B_WRITE		PBF_WRITE
+#define XFS_B_STALE		PBF_STALE
+
 #define XFS_BUF_TRYLOCK		PBF_TRYLOCK
 #define XFS_INCORE_TRYLOCK	PBF_TRYLOCK
 #define XFS_BUF_LOCK		PBF_LOCK
 #define XFS_BUF_MAPPED		PBF_MAPPED
 
-#define BUF_BUSY	PBF_DONT_BLOCK
+#define BUF_BUSY		PBF_DONT_BLOCK
 
-#define XFS_BUF_BFLAGS(x)	 ((x)->pb_flags)  /* debugging routines might need this */
+#define XFS_BUF_BFLAGS(x)	((x)->pb_flags)
 #define XFS_BUF_ZEROFLAGS(x)	\
 	((x)->pb_flags &= ~(PBF_READ|PBF_WRITE|PBF_ASYNC|PBF_SYNC|PBF_DELWRI))
 
-#define XFS_BUF_STALE(x)	     ((x)->pb_flags |= XFS_B_STALE)
-#define XFS_BUF_UNSTALE(x)	     ((x)->pb_flags &= ~XFS_B_STALE)
-#define XFS_BUF_ISSTALE(x)	     ((x)->pb_flags & XFS_B_STALE)
-#define XFS_BUF_SUPER_STALE(x)	 (x)->pb_flags |= XFS_B_STALE;\
-				 xfs_buf_undelay(x);\
-				 (x)->pb_flags &= ~(PBF_PARTIAL|PBF_NONE)
+#define XFS_BUF_STALE(x)	((x)->pb_flags |= XFS_B_STALE)
+#define XFS_BUF_UNSTALE(x)	((x)->pb_flags &= ~XFS_B_STALE)
+#define XFS_BUF_ISSTALE(x)	((x)->pb_flags & XFS_B_STALE)
+#define XFS_BUF_SUPER_STALE(x)	do {				\
+					XFS_BUF_STALE(x);	\
+					xfs_buf_undelay(x);	\
+					XFS_BUF_DONE(x);	\
+				} while (0)
+
+#define XFS_BUF_MANAGE		PBF_FS_MANAGED
+#define XFS_BUF_UNMANAGE(x)	((x)->pb_flags &= ~PBF_FS_MANAGED)
 
 static inline void xfs_buf_undelay(page_buf_t *pb)
 {
diff -Nru a/fs/xfs/xfs_dmapi.h b/fs/xfs/xfs_dmapi.h
--- a/fs/xfs/xfs_dmapi.h	Mon Dec 23 21:22:00 2002
+++ b/fs/xfs/xfs_dmapi.h	Mon Dec 23 21:22:00 2002
@@ -165,13 +165,6 @@
 	vrwlock_t	*locktype);
 
 extern int
-xfs_dm_send_create_event(
-	bhv_desc_t	*dir_bdp,
-	char		*name,
-	mode_t		new_mode,
-	int		*good_event_sent);
-
-extern int
 xfs_dm_send_mmap_event(
 	struct vm_area_struct *vma,
 	unsigned int	wantflag);
@@ -248,16 +241,6 @@
 /*
  *	Stubs for XFS DMAPI utility routines.
  */
-
-static __inline int
-xfs_dm_send_create_event(
-	bhv_desc_t	*dir_bdp,
-	char		*name,
-	mode_t		new_mode,
-	int		*good_event_sent)
-{
-	return 0;
-}
 
 static __inline int
 xfs_dm_send_data_event(
diff -Nru a/fs/xfs/xfs_iget.c b/fs/xfs/xfs_iget.c
--- a/fs/xfs/xfs_iget.c	Mon Dec 23 21:22:00 2002
+++ b/fs/xfs/xfs_iget.c	Mon Dec 23 21:22:00 2002
@@ -246,9 +246,7 @@
 
 	/*
 	 * Read the disk inode attributes into a new inode structure and get
-	 * a new vnode for it.	Initialize the inode lock so we can idestroy
-	 * it soon if it's a dup.  This should also initialize i_ino, i_bno,
-	 * i_mount, and i_index.
+	 * a new vnode for it. This should also initialize i_ino and i_mount.
 	 */
 	error = xfs_iread(mp, tp, ino, &ip, bno);
 	if (error) {
diff -Nru a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
--- a/fs/xfs/xfs_inode.c	Mon Dec 23 21:22:00 2002
+++ b/fs/xfs/xfs_inode.c	Mon Dec 23 21:22:00 2002
@@ -142,7 +142,7 @@
 		}
 		if (INT_ISZERO(dip->di_next_unlinked, ARCH_CONVERT))  {
 			cmn_err(CE_WARN,
-"Bad next_unlinked field (0) in XFS inode buffer 0x%x, starting blockno %Ld, offset 0x%x",
+"Bad next_unlinked field (0) in XFS inode buffer 0x%p, starting blockno %Ld, offset 0x%x",
 				(__uint64_t)(__psunsigned_t) bp,
 				(__int64_t) XFS_BUF_ADDR(bp),
 				xfs_buf_offset(bp, i * mp->m_sb.sb_inodesize));
diff -Nru a/fs/xfs/xfs_iocore.c b/fs/xfs/xfs_iocore.c
--- a/fs/xfs/xfs_iocore.c	Mon Dec 23 21:21:59 2002
+++ b/fs/xfs/xfs_iocore.c	Mon Dec 23 21:21:59 2002
@@ -41,14 +41,24 @@
 }
 
 xfs_ioops_t	xfs_iocore_xfs = {
+	.xfs_ioinit		= (xfs_ioinit_t) fs_noerr,
 	.xfs_bmapi_func		= (xfs_bmapi_t) xfs_bmapi,
 	.xfs_bmap_eof_func	= (xfs_bmap_eof_t) xfs_bmap_eof,
+	.xfs_iomap_write_direct =
+			(xfs_iomap_write_direct_t) xfs_iomap_write_direct,
+	.xfs_iomap_write_delay =
+			(xfs_iomap_write_delay_t) xfs_iomap_write_delay,
+	.xfs_iomap_write_allocate =
+			(xfs_iomap_write_allocate_t) xfs_iomap_write_allocate,
+	.xfs_iomap_write_unwritten =
+			(xfs_iomap_write_unwritten_t) xfs_iomap_write_unwritten,
 	.xfs_ilock		= (xfs_lock_t) xfs_ilock,
+	.xfs_lck_map_shared	= (xfs_lck_map_shared_t) xfs_ilock_map_shared,
 	.xfs_ilock_demote	= (xfs_lock_demote_t) xfs_ilock_demote,
 	.xfs_ilock_nowait	= (xfs_lock_nowait_t) xfs_ilock_nowait,
 	.xfs_unlock		= (xfs_unlk_t) xfs_iunlock,
 	.xfs_size_func		= (xfs_size_t) xfs_size_fn,
-	.xfs_lastbyte		= (xfs_lastbyte_t) xfs_file_last_byte,
+	.xfs_iodone		= (xfs_iodone_t) fs_noerr,
 };
 
 void
@@ -83,4 +93,3 @@
 
 	xfs_iocore_inode_reinit(ip);
 }
-
diff -Nru a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
--- a/fs/xfs/xfs_mount.c	Mon Dec 23 21:21:53 2002
+++ b/fs/xfs/xfs_mount.c	Mon Dec 23 21:21:53 2002
@@ -419,42 +419,64 @@
 int
 xfs_readsb(xfs_mount_t *mp)
 {
+	unsigned int	sector_size;
+	unsigned int	extra_flags;
 	xfs_buf_t	*bp;
 	xfs_sb_t	*sbp;
-	int		error = 0;
+	int		error;
 
-	ASSERT(mp->m_sb_bp == 0);
+	ASSERT(mp->m_sb_bp == NULL);
+	ASSERT(mp->m_ddev_targp != NULL);
 
 	/*
 	 * Allocate a (locked) buffer to hold the superblock.
-	 * This will be kept around at all time to optimize
+	 * This will be kept around at all times to optimize
 	 * access to the superblock.
 	 */
-	bp = xfs_buf_read_flags(mp->m_ddev_targp, XFS_SB_DADDR, 1,
-		PBF_LOCK|PBF_READ|PBF_MAPPED|PBF_MAPPABLE|PBF_FS_MANAGED);
-	ASSERT(bp != NULL);
-	ASSERT(XFS_BUF_ISBUSY(bp) && XFS_BUF_VALUSEMA(bp) <= 0);
+	sector_size = xfs_getsize_buftarg(mp->m_ddev_targp);
+	extra_flags = XFS_BUF_LOCK | XFS_BUF_MANAGE | XFS_BUF_MAPPED;
+
+	bp = xfs_buf_read_flags(mp->m_ddev_targp, XFS_SB_DADDR,
+				BTOBB(sector_size), extra_flags);
+	ASSERT(bp);
+	ASSERT(XFS_BUF_ISBUSY(bp));
+	ASSERT(XFS_BUF_VALUSEMA(bp) <= 0);
 
 	/*
 	 * Initialize the mount structure from the superblock.
 	 * But first do some basic consistency checking.
 	 */
 	sbp = XFS_BUF_TO_SBP(bp);
-	xfs_xlatesb(XFS_BUF_PTR(bp), &(mp->m_sb), 1, ARCH_CONVERT, XFS_SB_ALL_BITS);
-	if ((error = xfs_mount_validate_sb(mp, &(mp->m_sb)))) {
+	xfs_xlatesb(XFS_BUF_PTR(bp), &(mp->m_sb), 1,
+				ARCH_CONVERT, XFS_SB_ALL_BITS);
+
+	error = xfs_mount_validate_sb(mp, &(mp->m_sb));
+	if (error) {
 		cmn_err(CE_WARN, "XFS: SB validate failed");
-		goto err;
+		XFS_BUF_UNMANAGE(bp);
+		xfs_buf_relse(bp);
+		return error;
+	}
+
+	/*
+	 * Re-read the superblock so that our buffer is correctly sized.
+	 * We only need to do this if sector size on-disk is different.
+	 */
+	if (sector_size != mp->m_sb.sb_sectsize) {
+		XFS_BUF_UNMANAGE(bp);
+		xfs_buf_relse(bp);
+		sector_size = mp->m_sb.sb_sectsize;
+		bp = xfs_buf_read_flags(mp->m_ddev_targp, XFS_SB_DADDR,
+					BTOBB(sector_size), extra_flags);
+		ASSERT(bp);
+		ASSERT(XFS_BUF_ISBUSY(bp));
+		ASSERT(XFS_BUF_VALUSEMA(bp) <= 0);
 	}
 
 	mp->m_sb_bp = bp;
 	xfs_buf_relse(bp);
 	ASSERT(XFS_BUF_VALUSEMA(bp) > 0);
 	return 0;
-
- err:
-	bp->pb_flags &= ~PBF_FS_MANAGED;
-	xfs_buf_relse(bp);
-	return error;
 }
 
 
@@ -1531,10 +1553,10 @@
 
 	/*
 	 * Use xfs_getsb() so that the buffer will be locked
-	 * when we call nfreerbuf().
+	 * when we call xfs_buf_relse().
 	 */
 	bp = xfs_getsb(mp, 0);
-	bp->pb_flags &= ~PBF_FS_MANAGED;
+	XFS_BUF_UNMANAGE(bp);
 	xfs_buf_relse(bp);
 	mp->m_sb_bp = NULL;
 }
diff -Nru a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
--- a/fs/xfs/xfs_mount.h	Mon Dec 23 21:21:50 2002
+++ b/fs/xfs/xfs_mount.h	Mon Dec 23 21:21:50 2002
@@ -87,41 +87,60 @@
 #define AIL_LOCK(mp,s)		s=mutex_spinlock(&(mp)->m_ail_lock)
 #define AIL_UNLOCK(mp,s)	mutex_spinunlock(&(mp)->m_ail_lock, s)
 
-
-/* Prototypes and functions for I/O core modularization, a vector
- * of functions is used to indirect from xfs/cxfs independent code
- * to the xfs/cxfs dependent code.
- * The vector is placed in the mount structure so that we can
- * minimize the number of memory indirections involved.
+/*
+ * Prototypes and functions for I/O core modularization.
  */
+ 
+struct flid;
+struct buf;
 
+typedef int		(*xfs_ioinit_t)(struct vfs *,
+				struct xfs_mount_args *, int *);
 typedef int		(*xfs_bmapi_t)(struct xfs_trans *, void *,
 				xfs_fileoff_t, xfs_filblks_t, int,
 				xfs_fsblock_t *, xfs_extlen_t,
 				struct xfs_bmbt_irec *, int *,
 				struct xfs_bmap_free *);
 typedef int		(*xfs_bmap_eof_t)(void *, xfs_fileoff_t, int, int *);
+typedef int		(*xfs_iomap_write_direct_t)(
+				void *, loff_t, size_t, int,
+				struct xfs_bmbt_irec *, int *, int);
+typedef int		(*xfs_iomap_write_delay_t)(
+				void *, loff_t, size_t, int,
+				struct xfs_bmbt_irec *, int *);
+typedef int		(*xfs_iomap_write_allocate_t)(
+				void *, struct xfs_bmbt_irec *, int *);
+typedef int		(*xfs_iomap_write_unwritten_t)(
+				void *, loff_t, size_t);
+typedef uint		(*xfs_lck_map_shared_t)(void *);
 typedef void		(*xfs_lock_t)(void *, uint);
 typedef void		(*xfs_lock_demote_t)(void *, uint);
 typedef int		(*xfs_lock_nowait_t)(void *, uint);
 typedef void		(*xfs_unlk_t)(void *, unsigned int);
-typedef void		(*xfs_chgtime_t)(void *, int);
 typedef xfs_fsize_t	(*xfs_size_t)(void *);
-typedef xfs_fsize_t	(*xfs_lastbyte_t)(void *);
+typedef xfs_fsize_t	(*xfs_iodone_t)(struct vfs *);
 
 typedef struct xfs_ioops {
-	xfs_bmapi_t		xfs_bmapi_func;
-	xfs_bmap_eof_t		xfs_bmap_eof_func;
-	xfs_lock_t		xfs_ilock;
-	xfs_lock_demote_t	xfs_ilock_demote;
-	xfs_lock_nowait_t	xfs_ilock_nowait;
-	xfs_unlk_t		xfs_unlock;
-	xfs_chgtime_t		xfs_chgtime;
-	xfs_size_t		xfs_size_func;
-	xfs_lastbyte_t		xfs_lastbyte;
+	xfs_ioinit_t			xfs_ioinit;
+	xfs_bmapi_t			xfs_bmapi_func;
+	xfs_bmap_eof_t			xfs_bmap_eof_func;
+	xfs_iomap_write_direct_t	xfs_iomap_write_direct;
+	xfs_iomap_write_delay_t		xfs_iomap_write_delay;
+	xfs_iomap_write_allocate_t	xfs_iomap_write_allocate;
+	xfs_iomap_write_unwritten_t	xfs_iomap_write_unwritten;
+	xfs_lock_t			xfs_ilock;
+	xfs_lck_map_shared_t		xfs_lck_map_shared;
+	xfs_lock_demote_t		xfs_ilock_demote;
+	xfs_lock_nowait_t		xfs_ilock_nowait;
+	xfs_unlk_t			xfs_unlock;
+	xfs_size_t			xfs_size_func;
+	xfs_iodone_t			xfs_iodone;
 } xfs_ioops_t;
 
 
+#define XFS_IOINIT(vfsp, args, flags) \
+	(*(mp)->m_io_ops.xfs_ioinit)(vfsp, args, flags)
+
 #define XFS_BMAPI(mp, trans,io,bno,len,f,first,tot,mval,nmap,flist)	\
 	(*(mp)->m_io_ops.xfs_bmapi_func) \
 		(trans,(io)->io_obj,bno,len,f,first,tot,mval,nmap,flist)
@@ -130,9 +149,31 @@
 	(*(mp)->m_io_ops.xfs_bmap_eof_func) \
 		((io)->io_obj, endoff, whichfork, eof)
 
+#define XFS_IOMAP_WRITE_DIRECT(mp, io, offset, count, flags, mval, nmap, found)\
+	(*(mp)->m_io_ops.xfs_iomap_write_direct) \
+		((io)->io_obj, offset, count, flags, mval, nmap, found)
+
+#define XFS_IOMAP_WRITE_DELAY(mp, io, offset, count, flags, mval, nmap) \
+	(*(mp)->m_io_ops.xfs_iomap_write_delay) \
+		((io)->io_obj, offset, count, flags, mval, nmap)
+
+#define XFS_IOMAP_WRITE_ALLOCATE(mp, io, mval, nmap) \
+	(*(mp)->m_io_ops.xfs_iomap_write_allocate) \
+		((io)->io_obj, mval, nmap)
+
+#define XFS_IOMAP_WRITE_UNWRITTEN(mp, io, offset, count) \
+	(*(mp)->m_io_ops.xfs_iomap_write_unwritten) \
+		((io)->io_obj, offset, count)
+
+#define XFS_LCK_MAP_SHARED(mp, io) \
+	(*(mp)->m_io_ops.xfs_lck_map_shared)((io)->io_obj)
+
 #define XFS_ILOCK(mp, io, mode) \
 	(*(mp)->m_io_ops.xfs_ilock)((io)->io_obj, mode)
 
+#define XFS_ILOCK_NOWAIT(mp, io, mode) \
+	(*(mp)->m_io_ops.xfs_ilock_nowait)((io)->io_obj, mode)
+
 #define XFS_IUNLOCK(mp, io, mode) \
 	(*(mp)->m_io_ops.xfs_unlock)((io)->io_obj, mode)
 
@@ -142,8 +183,13 @@
 #define XFS_SIZE(mp, io) \
 	(*(mp)->m_io_ops.xfs_size_func)((io)->io_obj)
 
-#define XFS_LASTBYTE(mp, io) \
-	(*(mp)->m_io_ops.xfs_lastbyte)((io)->io_obj)
+#define XFS_IODONE(vfsp) \
+	(*(mp)->m_io_ops.xfs_iodone)(vfsp)
+
+
+/*
+ * Prototypes and functions for the XFS realtime subsystem.
+ */
 
 
 typedef struct xfs_mount {
@@ -303,8 +349,8 @@
 /*
  * Default minimum read and write sizes.
  */
-#define XFS_READIO_LOG_LARGE	12
-#define XFS_WRITEIO_LOG_LARGE	12
+#define XFS_READIO_LOG_LARGE	16
+#define XFS_WRITEIO_LOG_LARGE	16
 /*
  * Default allocation size
  */
diff -Nru a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
--- a/fs/xfs/xfs_rtalloc.c	Mon Dec 23 21:21:51 2002
+++ b/fs/xfs/xfs_rtalloc.c	Mon Dec 23 21:21:51 2002
@@ -2287,7 +2287,7 @@
 		return XFS_ERROR(E2BIG);
 	}
 	error = xfs_read_buf(mp, mp->m_rtdev_targp,
-				XFS_FSB_TO_BB(mp, d - 1),
+				d - XFS_FSB_TO_BB(mp, 1),
 				XFS_FSB_TO_BB(mp, 1), 0, &bp);
 	if (error) {
 		cmn_err(CE_WARN,
diff -Nru a/fs/xfs/xfs_rw.c b/fs/xfs/xfs_rw.c
--- a/fs/xfs/xfs_rw.c	Mon Dec 23 21:22:01 2002
+++ b/fs/xfs/xfs_rw.c	Mon Dec 23 21:22:01 2002
@@ -97,7 +97,7 @@
 
 	if (!(flags & XFS_FORCE_UMOUNT)) {
 		cmn_err(CE_NOTE,
-		"xfs_force_shutdown(%s,0x%x) called from line %d of file %s.  Return address = 0x%x",
+		"xfs_force_shutdown(%s,0x%x) called from line %d of file %s.  Return address = 0x%p",
 			mp->m_fsname,flags,lnnum,fname,__return_address);
 	}
 	/*
diff -Nru a/fs/xfs/xfs_trans_buf.c b/fs/xfs/xfs_trans_buf.c
--- a/fs/xfs/xfs_trans_buf.c	Mon Dec 23 21:21:51 2002
+++ b/fs/xfs/xfs_trans_buf.c	Mon Dec 23 21:21:51 2002
@@ -472,7 +472,7 @@
 	 */
 #if defined(DEBUG)
 	if (XFS_BUF_ISSTALE(bp) && XFS_BUF_ISDELAYWRITE(bp))
-		cmn_err(CE_NOTE, "about to pop assert, bp == 0x%x", bp);
+		cmn_err(CE_NOTE, "about to pop assert, bp == 0x%p", bp);
 #endif
 	ASSERT((XFS_BUF_BFLAGS(bp) & (XFS_B_STALE|XFS_B_DELWRI)) !=
 						(XFS_B_STALE|XFS_B_DELWRI));
diff -Nru a/fs/xfs/xfs_vfsops.c b/fs/xfs/xfs_vfsops.c
--- a/fs/xfs/xfs_vfsops.c	Mon Dec 23 21:21:51 2002
+++ b/fs/xfs/xfs_vfsops.c	Mon Dec 23 21:21:51 2002
@@ -451,18 +451,19 @@
 		goto error;
 	}
 
-	xfs_size_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
-			 mp->m_sb.sb_sectsize);
+	xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
+			    mp->m_sb.sb_sectsize);
 	if (logdev && logdev != ddev) {
-		unsigned int	ss = BBSIZE;
+		unsigned int	log_sector_size = BBSIZE;
 
 		if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
-			ss = mp->m_sb.sb_logsectsize;
-		xfs_size_buftarg(mp->m_logdev_targp, mp->m_sb.sb_blocksize, ss);
+			log_sector_size = mp->m_sb.sb_logsectsize;
+		xfs_setsize_buftarg(mp->m_logdev_targp, mp->m_sb.sb_blocksize,
+				    log_sector_size);
 	}
 	if (rtdev)
-		xfs_size_buftarg(mp->m_rtdev_targp, mp->m_sb.sb_blocksize,
-				 mp->m_sb.sb_blocksize);
+		xfs_setsize_buftarg(mp->m_rtdev_targp, mp->m_sb.sb_blocksize,
+				    mp->m_sb.sb_blocksize);
 
 	error = xfs_mountfs(vfsp, mp, ddev->bd_dev, flags);
 	if (error)
diff -Nru a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c
--- a/fs/xfs/xfs_vnodeops.c	Mon Dec 23 21:22:02 2002
+++ b/fs/xfs/xfs_vnodeops.c	Mon Dec 23 21:22:02 2002
@@ -44,15 +44,6 @@
 			unsigned int, unsigned long);
 
 
-#ifdef XFS_RW_TRACE
-STATIC void
-xfs_ctrunc_trace(
-	int		tag,
-	xfs_inode_t	*ip);
-#else
-#define xfs_ctrunc_trace(tag, ip)
-#endif /* DEBUG */
-
 /*
  * For xfs, we check that the file isn't too big to be opened by this kernel.
  * No other open action is required for regular files.	Devices are handled
@@ -1880,7 +1871,6 @@
 	cred_t			*credp)
 {
 	xfs_inode_t		*dp, *ip;
-	struct vnode		*vp;
 	xfs_ino_t		e_inum;
 	int			error;
 	uint			lock_mode;
@@ -1896,58 +1886,19 @@
 
 	lock_mode = xfs_ilock_map_shared(dp);
 	error = xfs_dir_lookup_int(dir_bdp, lock_mode, dentry, &e_inum, &ip);
-	if (error) {
-		xfs_iunlock_map_shared(dp, lock_mode);
-		return error;
+	if (!error) {
+		*vpp = XFS_ITOV(ip);
+		ITRACE(ip);
 	}
-
-	vp = XFS_ITOV(ip);
-
-	ITRACE(ip);
-
 	xfs_iunlock_map_shared(dp, lock_mode);
-
-	*vpp = vp;
-
-	return 0;
+	return error;
 }
 
-#ifdef XFS_RW_TRACE
-STATIC void
-xfs_ctrunc_trace(
-	int		tag,
-	xfs_inode_t	*ip)
-{
-	if (ip->i_rwtrace == NULL) {
-		return;
-	}
-
-	ktrace_enter(ip->i_rwtrace,
-		     (void*)((long)tag),
-		     (void*)ip,
-		     (void*)((long)private.p_cpuid),
-		     (void*)0,
-		     (void*)0,
-		     (void*)0,
-		     (void*)0,
-		     (void*)0,
-		     (void*)0,
-		     (void*)0,
-		     (void*)0,
-		     (void*)0,
-		     (void*)0,
-		     (void*)0,
-		     (void*)0,
-		     (void*)0);
-}
-#endif /* XFS_RW_TRACE */
 
 #define XFS_CREATE_NEW_MAXTRIES 10000
 
 /*
  * xfs_create (create a new file).
- *   It might still find name exists out there, though.
- *	But vpp, doens't point at a vnode.
  */
 STATIC int
 xfs_create(
@@ -1968,7 +1919,6 @@
 	xfs_bmap_free_t		free_list;
 	xfs_fsblock_t		first_block;
 	boolean_t		dp_joined_to_trans;
-	int			dm_event_sent = 0;
 	uint			cancel_flags;
 	int			committed;
 	xfs_prid_t		prid;
@@ -1989,8 +1939,10 @@
 		return XFS_ERROR(ENAMETOOLONG);
 
 	if (DM_EVENT_ENABLED(dir_vp->v_vfsp, dp, DM_EVENT_CREATE)) {
-		error = xfs_dm_send_create_event(dir_bdp, name,
-				dm_di_mode, &dm_event_sent);
+		error = dm_send_namesp_event(DM_EVENT_CREATE,
+				dir_bdp, DM_RIGHT_NULL, NULL,
+				DM_RIGHT_NULL, name, NULL,
+				dm_di_mode, 0, 0);
 		if (error)
 			return error;
 	}
@@ -2161,7 +2113,7 @@
 	/* Fallthrough to std_return with error = 0  */
 
 std_return:
-	if ((error != 0 && dm_event_sent != 0) &&
+	if ((error != 0) &&
 			DM_EVENT_ENABLED(dir_vp->v_vfsp, XFS_BHVTOI(dir_bdp),
 							DM_EVENT_POSTCREATE)) {
 		(void) dm_send_namesp_event(DM_EVENT_POSTCREATE,
@@ -2227,16 +2179,7 @@
  * vnode ref count will still include that from the .. entry in
  * this case.
  *
- * The inode passed in will have been looked up using xfs_get_dir_entry().
- * Since that lookup the directory lock will have been dropped, so
- * we need to validate that the inode given is still pointed to by the
- * directory.  We use the directory inode in memory generation count
- * as an optimization to tell if a new lookup is necessary.  If the
- * directory no longer points to the given inode with the given name,
- * then we drop the directory lock, set the entry_changed parameter to 1,
- * and return.	It is up to the caller to drop the reference to the inode.
- *
- * There is a dealock we need to worry about. If the locked directory is
+ * There is a deadlock we need to worry about. If the locked directory is
  * in the AIL, it might be blocking up the log. The next inode we lock
  * could be already locked by another thread waiting for log space (e.g
  * a permanent log reservation with a long running transaction (see
@@ -2249,8 +2192,7 @@
 xfs_lock_dir_and_entry(
 	xfs_inode_t	*dp,
 	vname_t		*dentry,
-	xfs_inode_t	*ip,	/* inode of entry 'name' */
-	int		*entry_changed)
+	xfs_inode_t	*ip)	/* inode of entry 'name' */
 {
 	int		attempts;
 	xfs_ino_t	e_inum;
@@ -2263,7 +2205,6 @@
 	attempts = 0;
 
 again:
-	*entry_changed = 0;
 	xfs_ilock(dp, XFS_ILOCK_EXCL);
 
 	e_inum = ip->i_ino;
@@ -2477,7 +2418,6 @@
 	xfs_fsblock_t		first_block;
 	int			cancel_flags;
 	int			committed;
-	int			entry_changed;
 	int			dm_di_mode = 0;
 	int			link_zero;
 	uint			resblks;
@@ -2504,7 +2444,6 @@
 	}
 
 	/* From this point on, return through std_return */
- retry:
 	ip = NULL;
 
 	/*
@@ -2571,7 +2510,7 @@
 		return error;
 	}
 
-	error = xfs_lock_dir_and_entry(dp, dentry, ip, &entry_changed);
+	error = xfs_lock_dir_and_entry(dp, dentry, ip);
 	if (error) {
 		REMOVE_DEBUG_TRACE(__LINE__);
 		xfs_trans_cancel(tp, cancel_flags);
@@ -2580,17 +2519,6 @@
 	}
 
 	/*
-	 * If the inode we found in the first pass is no longer
-	 * the entry with the given name, then drop our transaction and
-	 * inode reference and start over.
-	 */
-	if (entry_changed) {
-		xfs_trans_cancel(tp, cancel_flags);
-		IRELE(ip);
-		goto retry;
-	}
-
-	/*
 	 * At this point, we've gotten both the directory and the entry
 	 * inodes locked.
 	 */
@@ -2610,28 +2538,6 @@
 		goto error_return;
 	}
 
-	if ((ip->i_d.di_mode & IFMT) == IFDIR) {
-		error = XFS_ERROR(EPERM);
-		REMOVE_DEBUG_TRACE(__LINE__);
-		goto error_return;
-	}
-
-	/*
-	 * Return error when removing . and ..
-	 */
-	if (name[0] == '.') {
-		if (name[1] == '\0') {
-			error = XFS_ERROR(EINVAL);
-			REMOVE_DEBUG_TRACE(__LINE__);
-			goto error_return;
-		}
-		else if (name[1] == '.' && name[2] == '\0') {
-			error = XFS_ERROR(EEXIST);
-			REMOVE_DEBUG_TRACE(__LINE__);
-			goto error_return;
-		}
-	}
-
 	/*
 	 * Entry must exist since we did a lookup in xfs_lock_dir_and_entry.
 	 */
@@ -2696,8 +2602,7 @@
 	IRELE(ip);
 
 /*	Fall through to std_return with error = 0 */
-
-std_return:
+ std_return:
 	if (DM_EVENT_ENABLED(dir_vp->v_vfsp, dp,
 						DM_EVENT_POSTREMOVE)) {
 		(void) dm_send_namesp_event(DM_EVENT_POSTREMOVE,
@@ -2938,7 +2843,6 @@
 	vnode_t			*dir_vp;
 	boolean_t		dp_joined_to_trans;
 	boolean_t		created = B_FALSE;
-	int			dm_event_sent = 0;
 	xfs_prid_t		prid;
 	xfs_dquot_t		*udqp, *gdqp;
 	uint			resblks;
@@ -2961,8 +2865,10 @@
 	dm_di_mode = vap->va_mode|VTTOIF(vap->va_type);
 
 	if (DM_EVENT_ENABLED(dir_vp->v_vfsp, dp, DM_EVENT_CREATE)) {
-		error = xfs_dm_send_create_event(dir_bdp, dir_name,
-					dm_di_mode, &dm_event_sent);
+		error = dm_send_namesp_event(DM_EVENT_CREATE,
+					dir_bdp, DM_RIGHT_NULL, NULL,
+					DM_RIGHT_NULL, dir_name, NULL,
+					dm_di_mode, 0, 0);
 		if (error)
 			return error;
 	}
@@ -3127,7 +3033,7 @@
 	 * xfs_trans_commit. */
 
 std_return:
-	if ( (created || (error != 0 && dm_event_sent != 0)) &&
+	if ( (created || (error != 0)) &&
 			DM_EVENT_ENABLED(dir_vp->v_vfsp, XFS_BHVTOI(dir_bdp),
 						DM_EVENT_POSTCREATE)) {
 		(void) dm_send_namesp_event(DM_EVENT_POSTCREATE,
@@ -3180,7 +3086,6 @@
 	xfs_fsblock_t		first_block;
 	int			cancel_flags;
 	int			committed;
-	int			entry_changed;
 	vnode_t			*dir_vp;
 	int			dm_di_mode = 0;
 	int			last_cdp_link;
@@ -3209,7 +3114,6 @@
 
 	/* Return through std_return after this point. */
 
- retry:
 	cdp = NULL;
 
 	/*
@@ -3281,24 +3185,13 @@
 	 * that the directory entry for the child directory inode has
 	 * not changed while we were obtaining a log reservation.
 	 */
-	error = xfs_lock_dir_and_entry(dp, dentry, cdp, &entry_changed);
+	error = xfs_lock_dir_and_entry(dp, dentry, cdp);
 	if (error) {
 		xfs_trans_cancel(tp, cancel_flags);
 		IRELE(cdp);
 		goto std_return;
 	}
 
-	/*
-	 * If the inode we found in the first pass is no longer
-	 * the entry with the given name, then drop our transaction and
-	 * inode reference and start over.
-	 */
-	if (entry_changed) {
-		xfs_trans_cancel(tp, cancel_flags);
-		IRELE(cdp);
-		goto retry;
-	}
-
 	xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
 	if (dp != cdp) {
 		/*
@@ -3455,20 +3348,12 @@
 	}
 
 	lock_mode = xfs_ilock_map_shared(dp);
-
-	if ((dp->i_d.di_mode & IFMT) != IFDIR) {
-		xfs_iunlock_map_shared(dp, lock_mode);
-		return XFS_ERROR(ENOTDIR);
-	}
-
 	start_offset = uiop->uio_offset;
 	error = XFS_DIR_GETDENTS(dp->i_mount, tp, dp, uiop, eofp);
 	if (start_offset != uiop->uio_offset) {
 		xfs_ichgtime(dp, XFS_ICHGTIME_ACC);
 	}
-
 	xfs_iunlock_map_shared(dp, lock_mode);
-
 	return error;
 }
 
diff -Nru a/fs/xfs/xfsidbg.c b/fs/xfs/xfsidbg.c
--- a/fs/xfs/xfsidbg.c	Mon Dec 23 21:21:59 2002
+++ b/fs/xfs/xfsidbg.c	Mon Dec 23 21:21:59 2002
@@ -1637,9 +1637,9 @@
 	if (ip == NULL)
 		return;
 
-	kdb_printf(" i_ino = %lu i_count = %u i_dev = 0x%x i_size %Ld\n",
+	kdb_printf(" i_ino = %lu i_count = %u i_size %Ld\n",
 					ip->i_ino, atomic_read(&ip->i_count),
-					ip->i_sb->s_dev, ip->i_size);
+					ip->i_size);
 
 	kdb_printf(
 		" i_mode = 0x%x	 i_nlink = %d  i_rdev = 0x%x i_state = 0x%lx\n",
diff -Nru a/include/asm-alpha/dma-mapping.h b/include/asm-alpha/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-alpha/dma-mapping.h	Mon Dec 23 21:22:04 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-alpha/dma.h b/include/asm-alpha/dma.h
--- a/include/asm-alpha/dma.h	Mon Dec 23 21:21:59 2002
+++ b/include/asm-alpha/dma.h	Mon Dec 23 21:21:59 2002
@@ -112,9 +112,9 @@
 # elif defined(CONFIG_ALPHA_RUFFIAN)
 #  define MAX_ISA_DMA_ADDRESS		ALPHA_RUFFIAN_MAX_ISA_DMA_ADDRESS
 # elif defined(CONFIG_ALPHA_SABLE)
-#  define MAX_ISA_DMA_ADDRESS		ALPHA_SABLE_MAX_DMA_ISA_ADDRESS
+#  define MAX_ISA_DMA_ADDRESS		ALPHA_SABLE_MAX_ISA_DMA_ADDRESS
 # elif defined(CONFIG_ALPHA_ALCOR)
-#  define MAX_ISA_DMA_ADDRESS		ALPHA_ALCOR_MAX_DMA_ISA_ADDRESS
+#  define MAX_ISA_DMA_ADDRESS		ALPHA_ALCOR_MAX_ISA_DMA_ADDRESS
 # else
 #  define MAX_ISA_DMA_ADDRESS		ALPHA_MAX_ISA_DMA_ADDRESS
 # endif
diff -Nru a/include/asm-alpha/uaccess.h b/include/asm-alpha/uaccess.h
--- a/include/asm-alpha/uaccess.h	Mon Dec 23 21:21:59 2002
+++ b/include/asm-alpha/uaccess.h	Mon Dec 23 21:21:59 2002
@@ -126,7 +126,7 @@
 	__asm__("1: ldq %0,%2\n"			\
 	"2:\n"						\
 	".section __ex_table,\"a\"\n"			\
-	"	.gprel32 1b\n"				\
+	"	.long 1b - .\n"				\
 	"	lda %0, 2b-1b(%1)\n"			\
 	".previous"					\
 		: "=r"(__gu_val), "=r"(__gu_err)	\
@@ -136,7 +136,7 @@
 	__asm__("1: ldl %0,%2\n"			\
 	"2:\n"						\
 	".section __ex_table,\"a\"\n"			\
-	"	.gprel32 1b\n"				\
+	"	.long 1b - .\n"				\
 	"	lda %0, 2b-1b(%1)\n"			\
 	".previous"					\
 		: "=r"(__gu_val), "=r"(__gu_err)	\
@@ -149,7 +149,7 @@
 	__asm__("1: ldwu %0,%2\n"			\
 	"2:\n"						\
 	".section __ex_table,\"a\"\n"			\
-	"	.gprel32 1b\n"				\
+	"	.long 1b - .\n"				\
 	"	lda %0, 2b-1b(%1)\n"			\
 	".previous"					\
 		: "=r"(__gu_val), "=r"(__gu_err)	\
@@ -159,7 +159,7 @@
 	__asm__("1: ldbu %0,%2\n"			\
 	"2:\n"						\
 	".section __ex_table,\"a\"\n"			\
-	"	.gprel32 1b\n"				\
+	"	.long 1b - .\n"				\
 	"	lda %0, 2b-1b(%1)\n"			\
 	".previous"					\
 		: "=r"(__gu_val), "=r"(__gu_err)	\
@@ -178,10 +178,10 @@
 	"	or %0,%1,%0\n"						\
 	"3:\n"								\
 	".section __ex_table,\"a\"\n"					\
-	"	.gprel32 1b\n"						\
+	"	.long 1b - .\n"						\
 	"	lda %0, 3b-1b(%2)\n"					\
-	"	.gprel32 2b\n"						\
-	"	lda %0, 2b-1b(%2)\n"					\
+	"	.long 2b - .\n"						\
+	"	lda %0, 3b-2b(%2)\n"					\
 	".previous"							\
 		: "=&r"(__gu_val), "=&r"(__gu_tmp), "=r"(__gu_err)	\
 		: "r"(addr), "2"(__gu_err));				\
@@ -192,7 +192,7 @@
 	"	extbl %0,%2,%0\n"					\
 	"2:\n"								\
 	".section __ex_table,\"a\"\n"					\
-	"	.gprel32 1b\n"						\
+	"	.long 1b - .\n"						\
 	"	lda %0, 2b-1b(%1)\n"					\
 	".previous"							\
 		: "=&r"(__gu_val), "=r"(__gu_err)			\
@@ -240,7 +240,7 @@
 __asm__ __volatile__("1: stq %r2,%1\n"				\
 	"2:\n"							\
 	".section __ex_table,\"a\"\n"				\
-	"	.gprel32 1b\n"					\
+	"	.long 1b - .\n"					\
 	"	lda $31,2b-1b(%0)\n"				\
 	".previous"						\
 		: "=r"(__pu_err)				\
@@ -250,7 +250,7 @@
 __asm__ __volatile__("1: stl %r2,%1\n"				\
 	"2:\n"							\
 	".section __ex_table,\"a\"\n"				\
-	"	.gprel32 1b\n"					\
+	"	.long 1b - .\n"					\
 	"	lda $31,2b-1b(%0)\n"				\
 	".previous"						\
 		: "=r"(__pu_err)				\
@@ -263,7 +263,7 @@
 __asm__ __volatile__("1: stw %r2,%1\n"				\
 	"2:\n"							\
 	".section __ex_table,\"a\"\n"				\
-	"	.gprel32 1b\n"					\
+	"	.long 1b - .\n"					\
 	"	lda $31,2b-1b(%0)\n"				\
 	".previous"						\
 		: "=r"(__pu_err)				\
@@ -273,7 +273,7 @@
 __asm__ __volatile__("1: stb %r2,%1\n"				\
 	"2:\n"							\
 	".section __ex_table,\"a\"\n"				\
-	"	.gprel32 1b\n"					\
+	"	.long 1b - .\n"					\
 	"	lda $31,2b-1b(%0)\n"				\
 	".previous"						\
 		: "=r"(__pu_err)				\
@@ -298,13 +298,13 @@
 	"4:	stq_u %1,0(%5)\n"				\
 	"5:\n"							\
 	".section __ex_table,\"a\"\n"				\
-	"	.gprel32 1b\n"					\
+	"	.long 1b - .\n"					\
 	"	lda $31, 5b-1b(%0)\n"				\
-	"	.gprel32 2b\n"					\
+	"	.long 2b - .\n"					\
 	"	lda $31, 5b-2b(%0)\n"				\
-	"	.gprel32 3b\n"					\
+	"	.long 3b - .\n"					\
 	"	lda $31, 5b-3b(%0)\n"				\
-	"	.gprel32 4b\n"					\
+	"	.long 4b - .\n"					\
 	"	lda $31, 5b-4b(%0)\n"				\
 	".previous"						\
 		: "=r"(__pu_err), "=&r"(__pu_tmp1),		\
@@ -324,9 +324,9 @@
 	"2:	stq_u %1,0(%4)\n"				\
 	"3:\n"							\
 	".section __ex_table,\"a\"\n"				\
-	"	.gprel32 1b\n"					\
+	"	.long 1b - .\n"					\
 	"	lda $31, 3b-1b(%0)\n"				\
-	"	.gprel32 2b\n"					\
+	"	.long 2b - .\n"					\
 	"	lda $31, 3b-2b(%0)\n"				\
 	".previous"						\
 		: "=r"(__pu_err),				\
@@ -356,7 +356,7 @@
 	register long __cu_len __asm__("$0") = len;
 
 	__asm__ __volatile__(
-		"jsr $28,(%3),__copy_user\n\tldgp $29,0($28)"
+		"jsr $28,(%3),__copy_user"
 		: "=r" (__cu_len), "=r" (__cu_from), "=r" (__cu_to), "=r"(pv)
 		: "0" (__cu_len), "1" (__cu_from), "2" (__cu_to), "3"(pv)
 		: "$1","$2","$3","$4","$5","$28","memory");
@@ -373,7 +373,7 @@
 		register const void * __cu_from __asm__("$7") = from;
 		register long __cu_len __asm__("$0") = len;
 		__asm__ __volatile__(
-			"jsr $28,(%3),__copy_user\n\tldgp $29,0($28)"
+			"jsr $28,(%3),__copy_user"
 			: "=r"(__cu_len), "=r"(__cu_from), "=r"(__cu_to),
 			  "=r" (pv)
 			: "0" (__cu_len), "1" (__cu_from), "2" (__cu_to), 
@@ -413,7 +413,7 @@
 	register void * __cl_to __asm__("$6") = to;
 	register long __cl_len __asm__("$0") = len;
 	__asm__ __volatile__(
-		"jsr $28,(%2),__do_clear_user\n\tldgp $29,0($28)"
+		"jsr $28,(%2),__do_clear_user"
 		: "=r"(__cl_len), "=r"(__cl_to), "=r"(pv)
 		: "0"(__cl_len), "1"(__cl_to), "2"(pv)
 		: "$1","$2","$3","$4","$5","$28","memory");
@@ -428,7 +428,7 @@
 		register void * __cl_to __asm__("$6") = to;
 		register long __cl_len __asm__("$0") = len;
 		__asm__ __volatile__(
-			"jsr $28,(%2),__do_clear_user\n\tldgp $29,0($28)"
+			"jsr $28,(%2),__do_clear_user"
 			: "=r"(__cl_len), "=r"(__cl_to), "=r"(pv)
 			: "0"(__cl_len), "1"(__cl_to), "2"(pv)
 			: "$1","$2","$3","$4","$5","$28","memory");
@@ -471,7 +471,7 @@
 /*
  * About the exception table:
  *
- * - insn is a 32-bit offset off of the kernel's or module's gp.
+ * - insn is a 32-bit pc-relative offset from the faulting insn.
  * - nextinsn is a 16-bit offset off of the faulting instruction
  *   (not off of the *next* instruction as branches are).
  * - errreg is the register in which to place -EFAULT.
@@ -502,7 +502,7 @@
 };
 
 /* Returns 0 if exception not found and fixup.unit otherwise.  */
-extern unsigned search_exception_table(unsigned long, unsigned long);
+extern unsigned search_exception_table(unsigned long);
 
 /* Returns the new pc */
 #define fixup_exception(map_reg, fixup_unit, pc)		\
diff -Nru a/include/asm-arm/dma-mapping.h b/include/asm-arm/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-arm/dma-mapping.h	Mon Dec 23 21:22:03 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-cris/dma-mapping.h b/include/asm-cris/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-cris/dma-mapping.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-generic/dma-mapping.h b/include/asm-generic/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-generic/dma-mapping.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,156 @@
+/* Copyright (C) 2002 by James.Bottomley@HansenPartnership.com 
+ *
+ * Implements the generic device dma API via the existing pci_ one
+ * for unconverted architectures
+ */
+
+#ifndef _ASM_GENERIC_DMA_MAPPING_H
+#define _ASM_GENERIC_DMA_MAPPING_H
+
+/* we implement the API below in terms of the existing PCI one,
+ * so include it */
+#include <linux/pci.h>
+/* need struct page definitions */
+#include <linux/mm.h>
+
+static inline int
+dma_supported(struct device *dev, u64 mask)
+{
+	BUG_ON(dev->bus != &pci_bus_type);
+
+	return pci_dma_supported(to_pci_dev(dev), mask);
+}
+
+static inline int
+dma_set_mask(struct device *dev, u64 dma_mask)
+{
+	BUG_ON(dev->bus != &pci_bus_type);
+
+	return pci_set_dma_mask(to_pci_dev(dev), dma_mask);
+}
+
+static inline void *
+dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle)
+{
+	BUG_ON(dev->bus != &pci_bus_type);
+
+	return pci_alloc_consistent(to_pci_dev(dev), size, dma_handle);
+}
+
+static inline void
+dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
+		    dma_addr_t dma_handle)
+{
+	BUG_ON(dev->bus != &pci_bus_type);
+
+	pci_free_consistent(to_pci_dev(dev), size, cpu_addr, dma_handle);
+}
+
+static inline dma_addr_t
+dma_map_single(struct device *dev, void *cpu_addr, size_t size,
+	       enum dma_data_direction direction)
+{
+	BUG_ON(dev->bus != &pci_bus_type);
+
+	return pci_map_single(to_pci_dev(dev), cpu_addr, size, (int)direction);
+}
+
+static inline void
+dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
+		 enum dma_data_direction direction)
+{
+	BUG_ON(dev->bus != &pci_bus_type);
+
+	pci_unmap_single(to_pci_dev(dev), dma_addr, size, (int)direction);
+}
+
+static inline dma_addr_t
+dma_map_page(struct device *dev, struct page *page,
+	     unsigned long offset, size_t size,
+	     enum dma_data_direction direction)
+{
+	BUG_ON(dev->bus != &pci_bus_type);
+
+	return pci_map_page(to_pci_dev(dev), page, offset, size, (int)direction);
+}
+
+static inline void
+dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
+	       enum dma_data_direction direction)
+{
+	BUG_ON(dev->bus != &pci_bus_type);
+
+	pci_unmap_page(to_pci_dev(dev), dma_address, size, (int)direction);
+}
+
+static inline int
+dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
+	   enum dma_data_direction direction)
+{
+	BUG_ON(dev->bus != &pci_bus_type);
+
+	return pci_map_sg(to_pci_dev(dev), sg, nents, (int)direction);
+}
+
+static inline void
+dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
+	     enum dma_data_direction direction)
+{
+	BUG_ON(dev->bus != &pci_bus_type);
+
+	pci_unmap_sg(to_pci_dev(dev), sg, nhwentries, (int)direction);
+}
+
+static inline void
+dma_sync_single(struct device *dev, dma_addr_t dma_handle, size_t size,
+		enum dma_data_direction direction)
+{
+	BUG_ON(dev->bus != &pci_bus_type);
+
+	pci_dma_sync_single(to_pci_dev(dev), dma_handle, size, (int)direction);
+}
+
+static inline void
+dma_sync_sg(struct device *dev, struct scatterlist *sg, int nelems,
+	    enum dma_data_direction direction)
+{
+	BUG_ON(dev->bus != &pci_bus_type);
+
+	pci_dma_sync_sg(to_pci_dev(dev), sg, nelems, (int)direction);
+}
+
+/* Now for the API extensions over the pci_ one */
+
+#define dma_alloc_noncoherent(d, s, h) dma_alloc_coherent(d, s, h)
+#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
+#define dma_is_consistent(d)	(1)
+
+static inline int
+dma_get_cache_alignment(void)
+{
+	/* no easy way to get cache size on all processors, so return
+	 * the maximum possible, to be safe */
+	return (1 << L1_CACHE_SHIFT_MAX);
+}
+
+static inline void
+dma_sync_single_range(struct device *dev, dma_addr_t dma_handle,
+		      unsigned long offset, size_t size,
+		      enum dma_data_direction direction)
+{
+	/* just sync everything, that's all the pci API can do */
+	dma_sync_single(dev, dma_handle, offset+size, direction);
+}
+
+static inline void
+dma_cache_sync(void *vaddr, size_t size,
+	       enum dma_data_direction direction)
+{
+	/* could define this in terms of the dma_cache ... operations,
+	 * but if you get this on a platform, you should convert the platform
+	 * to using the generic device DMA API */
+	BUG();
+}
+
+#endif
+
diff -Nru a/include/asm-generic/pci-dma-compat.h b/include/asm-generic/pci-dma-compat.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-generic/pci-dma-compat.h	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,87 @@
+/* include this file if the platform implements the dma_ DMA Mapping API
+ * and wants to provide the pci_ DMA Mapping API in terms of it */
+
+#ifndef _ASM_GENERIC_PCI_DMA_COMPAT_H
+#define _ASM_GENERIC_PCI_DMA_COMPAT_H
+
+#include <linux/dma-mapping.h>
+
+/* note pci_set_dma_mask isn't here, since it's a public function
+ * exported from drivers/pci, use dma_supported instead */
+
+static inline int
+pci_dma_supported(struct pci_dev *hwdev, u64 mask)
+{
+	return dma_supported(&hwdev->dev, mask);
+}
+
+static inline void *
+pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
+		     dma_addr_t *dma_handle)
+{
+	return dma_alloc_coherent(&hwdev->dev, size, dma_handle);
+}
+
+static inline void
+pci_free_consistent(struct pci_dev *hwdev, size_t size,
+		    void *vaddr, dma_addr_t dma_handle)
+{
+	dma_free_coherent(&hwdev->dev, size, vaddr, dma_handle);
+}
+
+static inline dma_addr_t
+pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size, int direction)
+{
+	return dma_map_single(&hwdev->dev, ptr, size, (enum dma_data_direction)direction);
+}
+
+static inline void
+pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
+		 size_t size, int direction)
+{
+	dma_unmap_single(&hwdev->dev, dma_addr, size, (enum dma_data_direction)direction);
+}
+
+static inline dma_addr_t
+pci_map_page(struct pci_dev *hwdev, struct page *page,
+	     unsigned long offset, size_t size, int direction)
+{
+	return dma_map_page(&hwdev->dev, page, offset, size, (enum dma_data_direction)direction);
+}
+
+static inline void
+pci_unmap_page(struct pci_dev *hwdev, dma_addr_t dma_address,
+	       size_t size, int direction)
+{
+	dma_unmap_page(&hwdev->dev, dma_address, size, (enum dma_data_direction)direction);
+}
+
+static inline int
+pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
+	   int nents, int direction)
+{
+	return dma_map_sg(&hwdev->dev, sg, nents, (enum dma_data_direction)direction);
+}
+
+static inline void
+pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
+	     int nents, int direction)
+{
+	dma_unmap_sg(&hwdev->dev, sg, nents, (enum dma_data_direction)direction);
+}
+
+static inline void
+pci_dma_sync_single(struct pci_dev *hwdev, dma_addr_t dma_handle,
+		    size_t size, int direction)
+{
+	dma_sync_single(&hwdev->dev, dma_handle, size, (enum dma_data_direction)direction);
+}
+
+static inline void
+pci_dma_sync_sg(struct pci_dev *hwdev, struct scatterlist *sg,
+		int nelems, int direction)
+{
+	dma_sync_sg(&hwdev->dev, sg, nelems, (enum dma_data_direction)direction);
+}
+
+#endif
diff -Nru a/include/asm-i386/cpufeature.h b/include/asm-i386/cpufeature.h
--- a/include/asm-i386/cpufeature.h	Mon Dec 23 21:21:58 2002
+++ b/include/asm-i386/cpufeature.h	Mon Dec 23 21:21:58 2002
@@ -7,6 +7,8 @@
 #ifndef __ASM_I386_CPUFEATURE_H
 #define __ASM_I386_CPUFEATURE_H
 
+#include <linux/bitops.h>
+
 #define NCAPINTS	4	/* Currently we have 4 32-bit words worth of info */
 
 /* Intel-defined CPU features, CPUID level 0x00000001, word 0 */
@@ -74,6 +76,7 @@
 #define cpu_has_pae		boot_cpu_has(X86_FEATURE_PAE)
 #define cpu_has_pge		boot_cpu_has(X86_FEATURE_PGE)
 #define cpu_has_apic		boot_cpu_has(X86_FEATURE_APIC)
+#define cpu_has_sep		boot_cpu_has(X86_FEATURE_SEP)
 #define cpu_has_mtrr		boot_cpu_has(X86_FEATURE_MTRR)
 #define cpu_has_mmx		boot_cpu_has(X86_FEATURE_MMX)
 #define cpu_has_fxsr		boot_cpu_has(X86_FEATURE_FXSR)
diff -Nru a/include/asm-i386/dma-mapping.h b/include/asm-i386/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/dma-mapping.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,137 @@
+#ifndef _ASM_I386_DMA_MAPPING_H
+#define _ASM_I386_DMA_MAPPING_H
+
+#include <asm/cache.h>
+
+#define dma_alloc_noncoherent(d, s, h) dma_alloc_coherent(d, s, h)
+#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
+
+void *dma_alloc_coherent(struct device *dev, size_t size,
+			   dma_addr_t *dma_handle);
+
+void dma_free_coherent(struct device *dev, size_t size,
+			 void *vaddr, dma_addr_t dma_handle);
+
+static inline dma_addr_t
+dma_map_single(struct device *dev, void *ptr, size_t size,
+	       enum dma_data_direction direction)
+{
+	BUG_ON(direction == DMA_NONE);
+	flush_write_buffers();
+	return virt_to_phys(ptr);
+}
+
+static inline void
+dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
+		 enum dma_data_direction direction)
+{
+	BUG_ON(direction == DMA_NONE);
+}
+
+static inline int
+dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
+	   enum dma_data_direction direction)
+{
+	int i;
+
+	BUG_ON(direction == DMA_NONE);
+
+	for (i = 0; i < nents; i++ ) {
+		BUG_ON(!sg[i].page);
+
+		sg[i].dma_address = page_to_phys(sg[i].page) + sg[i].offset;
+	}
+
+	flush_write_buffers();
+	return nents;
+}
+
+static inline dma_addr_t
+dma_map_page(struct device *dev, struct page *page, unsigned long offset,
+	     size_t size, enum dma_data_direction direction)
+{
+	BUG_ON(direction == DMA_NONE);
+	return (dma_addr_t)(page_to_pfn(page)) * PAGE_SIZE + offset;
+}
+
+static inline void
+dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
+	       enum dma_data_direction direction)
+{
+	BUG_ON(direction == DMA_NONE);
+}
+
+
+static inline void
+dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
+	     enum dma_data_direction direction)
+{
+	BUG_ON(direction == DMA_NONE);
+}
+
+static inline void
+dma_sync_single(struct device *dev, dma_addr_t dma_handle, size_t size,
+		enum dma_data_direction direction)
+{
+	flush_write_buffers();
+}
+
+static inline void
+dma_sync_single_range(struct device *dev, dma_addr_t dma_handle,
+		      unsigned long offset, size_t size,
+		      enum dma_data_direction direction)
+{
+	flush_write_buffers();
+}
+
+
+static inline void
+dma_sync_sg(struct device *dev, struct scatterlist *sg, int nelems,
+		 enum dma_data_direction direction)
+{
+	flush_write_buffers();
+}
+
+static inline int
+dma_supported(struct device *dev, u64 mask)
+{
+        /*
+         * we fall back to GFP_DMA when the mask isn't all 1s,
+         * so we can't guarantee allocations that must be
+         * within a tighter range than GFP_DMA..
+         */
+        if(mask < 0x00ffffff)
+                return 0;
+
+	return 1;
+}
+
+static inline int
+dma_set_mask(struct device *dev, u64 mask)
+{
+	if(!dev->dma_mask || !dma_supported(dev, mask))
+		return -EIO;
+
+	*dev->dma_mask = mask;
+
+	return 0;
+}
+
+static inline int
+dma_get_cache_alignment(void)
+{
+	/* no easy way to get cache size on all x86, so return the
+	 * maximum possible, to be safe */
+	return (1 << L1_CACHE_SHIFT_MAX);
+}
+
+#define dma_is_consistent(d)	(1)
+
+static inline void
+dma_cache_sync(void *vaddr, size_t size,
+	       enum dma_data_direction direction)
+{
+	flush_write_buffers();
+}
+
+#endif
diff -Nru a/include/asm-i386/elf.h b/include/asm-i386/elf.h
--- a/include/asm-i386/elf.h	Mon Dec 23 21:21:58 2002
+++ b/include/asm-i386/elf.h	Mon Dec 23 21:21:58 2002
@@ -100,6 +100,12 @@
 
 #define ELF_PLATFORM  (system_utsname.machine)
 
+/*
+ * Architecture-neutral AT_ values in 0-17, leave some room
+ * for more of them, start the x86-specific ones at 32.
+ */
+#define AT_SYSINFO	32
+
 #ifdef __KERNEL__
 #define SET_PERSONALITY(ex, ibcs2) set_personality((ibcs2)?PER_SVR4:PER_LINUX)
 
@@ -115,6 +121,11 @@
 extern void dump_smp_unlazy_fpu(void);
 #define ELF_CORE_SYNC dump_smp_unlazy_fpu
 #endif
+
+#define ARCH_DLINFO					\
+do {							\
+		NEW_AUX_ENT(AT_SYSINFO, 0xffffe000);	\
+} while (0)
 
 #endif
 
diff -Nru a/include/asm-i386/fixmap.h b/include/asm-i386/fixmap.h
--- a/include/asm-i386/fixmap.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-i386/fixmap.h	Mon Dec 23 21:21:51 2002
@@ -42,6 +42,8 @@
  * task switches.
  */
 enum fixed_addresses {
+	FIX_HOLE,
+	FIX_VSYSCALL,
 #ifdef CONFIG_X86_LOCAL_APIC
 	FIX_APIC_BASE,	/* local (CPU) APIC) -- required for SMP or not */
 #endif
@@ -96,10 +98,9 @@
  * used by vmalloc.c.
  *
  * Leave one empty page between vmalloc'ed areas and
- * the start of the fixmap, and leave one page empty
- * at the top of mem..
+ * the start of the fixmap.
  */
-#define FIXADDR_TOP	(0xffffe000UL)
+#define FIXADDR_TOP	(0xfffff000UL)
 #define __FIXADDR_SIZE	(__end_of_permanent_fixed_addresses << PAGE_SHIFT)
 #define FIXADDR_START	(FIXADDR_TOP - __FIXADDR_SIZE)
 
diff -Nru a/include/asm-i386/irq.h b/include/asm-i386/irq.h
--- a/include/asm-i386/irq.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-i386/irq.h	Mon Dec 23 21:21:51 2002
@@ -23,6 +23,7 @@
 extern void disable_irq(unsigned int);
 extern void disable_irq_nosync(unsigned int);
 extern void enable_irq(unsigned int);
+extern void release_x86_irqs(struct task_struct *);
 
 #ifdef CONFIG_X86_LOCAL_APIC
 #define ARCH_HAS_NMI_WATCHDOG		/* See include/linux/nmi.h */
diff -Nru a/include/asm-i386/mach-default/do_timer.h b/include/asm-i386/mach-default/do_timer.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-default/do_timer.h	Mon Dec 23 21:22:00 2002
@@ -0,0 +1,82 @@
+/* defines for inline arch setup functions */
+
+#include <asm/apic.h>
+
+/**
+ * do_timer_interrupt_hook - hook into timer tick
+ * @regs:	standard registers from interrupt
+ *
+ * Description:
+ *	This hook is called immediately after the timer interrupt is ack'd.
+ *	It's primary purpose is to allow architectures that don't possess
+ *	individual per CPU clocks (like the CPU APICs supply) to broadcast the
+ *	timer interrupt as a means of triggering reschedules etc.
+ **/
+
+static inline void do_timer_interrupt_hook(struct pt_regs *regs)
+{
+	do_timer(regs);
+/*
+ * In the SMP case we use the local APIC timer interrupt to do the
+ * profiling, except when we simulate SMP mode on a uniprocessor
+ * system, in that case we have to call the local interrupt handler.
+ */
+#ifndef CONFIG_X86_LOCAL_APIC
+	x86_do_profile(regs);
+#else
+	if (!using_apic_timer)
+		smp_local_timer_interrupt(regs);
+#endif
+}
+
+
+/* you can safely undefine this if you don't have the Neptune chipset */
+
+#define BUGGY_NEPTUN_TIMER
+
+/**
+ * do_timer_overflow - process a detected timer overflow condition
+ * @count:	hardware timer interrupt count on overflow
+ *
+ * Description:
+ *	This call is invoked when the jiffies count has not incremented but
+ *	the hardware timer interrupt has.  It means that a timer tick interrupt
+ *	came along while the previous one was pending, thus a tick was missed
+ **/
+static inline int do_timer_overflow(int count)
+{
+	int i;
+
+	spin_lock(&i8259A_lock);
+	/*
+	 * This is tricky when I/O APICs are used;
+	 * see do_timer_interrupt().
+	 */
+	i = inb(0x20);
+	spin_unlock(&i8259A_lock);
+	
+	/* assumption about timer being IRQ0 */
+	if (i & 0x01) {
+		/*
+		 * We cannot detect lost timer interrupts ... 
+		 * well, that's why we call them lost, don't we? :)
+		 * [hmm, on the Pentium and Alpha we can ... sort of]
+		 */
+		count -= LATCH;
+	} else {
+#ifdef BUGGY_NEPTUN_TIMER
+		/*
+		 * for the Neptun bug we know that the 'latch'
+		 * command doesnt latch the high and low value
+		 * of the counter atomically. Thus we have to 
+		 * substract 256 from the counter 
+		 * ... funny, isnt it? :)
+		 */
+		
+		count -= 256;
+#else
+		printk("do_slow_gettimeoffset(): hardware timer problem?\n");
+#endif
+	}
+	return count;
+}
diff -Nru a/include/asm-i386/mach-default/entry_arch.h b/include/asm-i386/mach-default/entry_arch.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-default/entry_arch.h	Mon Dec 23 21:21:50 2002
@@ -0,0 +1,34 @@
+/*
+ * This file is designed to contain the BUILD_INTERRUPT specifications for
+ * all of the extra named interrupt vectors used by the architecture.
+ * Usually this is the Inter Process Interrupts (IPIs)
+ */
+
+/*
+ * The following vectors are part of the Linux architecture, there
+ * is no hardware IRQ pin equivalent for them, they are triggered
+ * through the ICC by us (IPIs)
+ */
+#ifdef CONFIG_X86_SMP
+BUILD_INTERRUPT(reschedule_interrupt,RESCHEDULE_VECTOR)
+BUILD_INTERRUPT(invalidate_interrupt,INVALIDATE_TLB_VECTOR)
+BUILD_INTERRUPT(call_function_interrupt,CALL_FUNCTION_VECTOR)
+#endif
+
+/*
+ * every pentium local APIC has two 'local interrupts', with a
+ * soft-definable vector attached to both interrupts, one of
+ * which is a timer interrupt, the other one is error counter
+ * overflow. Linux uses the local APIC timer interrupt to get
+ * a much simpler SMP time architecture:
+ */
+#ifdef CONFIG_X86_LOCAL_APIC
+BUILD_INTERRUPT(apic_timer_interrupt,LOCAL_TIMER_VECTOR)
+BUILD_INTERRUPT(error_interrupt,ERROR_APIC_VECTOR)
+BUILD_INTERRUPT(spurious_interrupt,SPURIOUS_APIC_VECTOR)
+
+#ifdef CONFIG_X86_MCE_P4THERMAL
+BUILD_INTERRUPT(thermal_interrupt,THERMAL_APIC_VECTOR)
+#endif
+
+#endif
diff -Nru a/include/asm-i386/mach-default/irq_vectors.h b/include/asm-i386/mach-default/irq_vectors.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-default/irq_vectors.h	Mon Dec 23 21:21:52 2002
@@ -0,0 +1,85 @@
+/*
+ * This file should contain #defines for all of the interrupt vector
+ * numbers used by this architecture.
+ *
+ * In addition, there are some standard defines:
+ *
+ *	FIRST_EXTERNAL_VECTOR:
+ *		The first free place for external interrupts
+ *
+ *	SYSCALL_VECTOR:
+ *		The IRQ vector a syscall makes the user to kernel transition
+ *		under.
+ *
+ *	TIMER_IRQ:
+ *		The IRQ number the timer interrupt comes in at.
+ *
+ *	NR_IRQS:
+ *		The total number of interrupt vectors (including all the
+ *		architecture specific interrupts) needed.
+ *
+ */			
+#ifndef _ASM_IRQ_VECTORS_H
+#define _ASM_IRQ_VECTORS_H
+
+/*
+ * IDT vectors usable for external interrupt sources start
+ * at 0x20:
+ */
+#define FIRST_EXTERNAL_VECTOR	0x20
+
+#define SYSCALL_VECTOR		0x80
+
+/*
+ * Vectors 0x20-0x2f are used for ISA interrupts.
+ */
+
+/*
+ * Special IRQ vectors used by the SMP architecture, 0xf0-0xff
+ *
+ *  some of the following vectors are 'rare', they are merged
+ *  into a single vector (CALL_FUNCTION_VECTOR) to save vector space.
+ *  TLB, reschedule and local APIC vectors are performance-critical.
+ *
+ *  Vectors 0xf0-0xfa are free (reserved for future Linux use).
+ */
+#define SPURIOUS_APIC_VECTOR	0xff
+#define ERROR_APIC_VECTOR	0xfe
+#define INVALIDATE_TLB_VECTOR	0xfd
+#define RESCHEDULE_VECTOR	0xfc
+#define CALL_FUNCTION_VECTOR	0xfb
+
+#define THERMAL_APIC_VECTOR	0xf0
+/*
+ * Local APIC timer IRQ vector is on a different priority level,
+ * to work around the 'lost local interrupt if more than 2 IRQ
+ * sources per level' errata.
+ */
+#define LOCAL_TIMER_VECTOR	0xef
+
+/*
+ * First APIC vector available to drivers: (vectors 0x30-0xee)
+ * we start at 0x31 to spread out vectors evenly between priority
+ * levels. (0x80 is the syscall vector)
+ */
+#define FIRST_DEVICE_VECTOR	0x31
+#define FIRST_SYSTEM_VECTOR	0xef
+
+#define TIMER_IRQ 0
+
+/*
+ * 16 8259A IRQ's, 208 potential APIC interrupt sources.
+ * Right now the APIC is mostly only used for SMP.
+ * 256 vectors is an architectural limit. (we can have
+ * more than 256 devices theoretically, but they will
+ * have to use shared interrupts)
+ * Since vectors 0x00-0x1f are used/reserved for the CPU,
+ * the usable vector space is 0x20-0xff (224 vectors)
+ */
+#ifdef CONFIG_X86_IO_APIC
+#define NR_IRQS 224
+#else
+#define NR_IRQS 16
+#endif
+
+#endif /* _ASM_IRQ_VECTORS_H */
diff -Nru a/include/asm-i386/mach-default/mach_apic.h b/include/asm-i386/mach-default/mach_apic.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-default/mach_apic.h	Mon Dec 23 21:22:02 2002
@@ -0,0 +1,83 @@
+#ifndef __ASM_MACH_APIC_H
+#define __ASM_MACH_APIC_H
+
+#define APIC_DFR_VALUE	(APIC_DFR_FLAT)
+
+#ifdef CONFIG_SMP
+ #define TARGET_CPUS (cpu_online_map)
+#else
+ #define TARGET_CPUS 0x01
+#endif
+
+#define no_balance_irq (0)
+
+#define APIC_BROADCAST_ID      0x0F
+#define check_apicid_used(bitmap, apicid) (bitmap & (1 << apicid))
+
+static inline int apic_id_registered(void)
+{
+	return (test_bit(GET_APIC_ID(apic_read(APIC_ID)), 
+						&phys_cpu_present_map));
+}
+
+/*
+ * Set up the logical destination ID.
+ *
+ * Intel recommends to set DFR, LDR and TPR before enabling
+ * an APIC.  See e.g. "AP-388 82489DX User's Manual" (Intel
+ * document number 292116).  So here it goes...
+ */
+static inline void init_apic_ldr(void)
+{
+	unsigned long val;
+
+	apic_write_around(APIC_DFR, APIC_DFR_VALUE);
+	val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
+	val |= SET_APIC_LOGICAL_ID(1UL << smp_processor_id());
+	apic_write_around(APIC_LDR, val);
+}
+
+static inline ulong ioapic_phys_id_map(ulong phys_map)
+{
+	return phys_map;
+}
+
+static inline void clustered_apic_check(void)
+{
+	printk("Enabling APIC mode:  %s.  Using %d I/O APICs\n",
+					"Flat", nr_ioapics);
+}
+
+static inline int multi_timer_check(int apic, int irq)
+{
+	return 0;
+}
+
+static inline int cpu_present_to_apicid(int mps_cpu)
+{
+	return  mps_cpu;
+}
+
+static inline unsigned long apicid_to_cpu_present(int phys_apicid)
+{
+	return (1ul << phys_apicid);
+}
+
+static inline int mpc_apic_id(struct mpc_config_processor *m, int quad)
+{
+	printk("Processor #%d %ld:%ld APIC version %d\n",
+			m->mpc_apicid,
+			(m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
+			(m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
+			m->mpc_apicver);
+	return (m->mpc_apicid);
+}
+
+#define wakeup_secondary_cpu(apicid, start_eip) \
+	wakeup_secondary_via_INIT(apicid, start_eip)
+
+static inline void setup_portio_remap(void)
+{
+}
+
+#endif /* __ASM_MACH_APIC_H */
diff -Nru a/include/asm-i386/mach-default/mach_ipi.h b/include/asm-i386/mach-default/mach_ipi.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-default/mach_ipi.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,30 @@
+#ifndef __ASM_MACH_IPI_H
+#define __ASM_MACH_IPI_H
+
+static inline void send_IPI_mask_bitmask(int mask, int vector);
+static inline void __send_IPI_shortcut(unsigned int shortcut, int vector);
+
+static inline void send_IPI_mask(int mask, int vector)
+{
+	send_IPI_mask_bitmask(mask, vector);
+}
+
+static inline void send_IPI_allbutself(int vector)
+{
+	/*
+	 * if there are no other CPUs in the system then we get an APIC send 
+	 * error if we try to broadcast, thus avoid sending IPIs in this case.
+	 */
+	if (!(num_online_cpus() > 1))
+		return;
+
+	__send_IPI_shortcut(APIC_DEST_ALLBUT, vector);
+	return;
+}
+
+static inline void send_IPI_all(int vector)
+{
+	__send_IPI_shortcut(APIC_DEST_ALLINC, vector);
+}
+
+#endif /* __ASM_MACH_IPI_H */
diff -Nru a/include/asm-i386/mach-default/mach_mpparse.h b/include/asm-i386/mach-default/mach_mpparse.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-default/mach_mpparse.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,20 @@
+#ifndef __ASM_MACH_MPPARSE_H
+#define __ASM_MACH_MPPARSE_H
+
+static inline void mpc_oem_bus_info(struct mpc_config_bus *m, char *name, 
+				struct mpc_config_translation *translation)
+{
+	Dprintk("Bus #%d is %s\n", m->mpc_busid, name);
+}
+
+static inline void mpc_oem_pci_bus(struct mpc_config_bus *m, 
+				struct mpc_config_translation *translation)
+{
+}
+
+static inline void mps_oem_check(struct mp_config_table *mpc, char *oem, 
+		char *productid)
+{
+}
+
+#endif /* __ASM_MACH_MPPARSE_H */
diff -Nru a/include/asm-i386/mach-default/setup_arch_post.h b/include/asm-i386/mach-default/setup_arch_post.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-default/setup_arch_post.h	Mon Dec 23 21:21:59 2002
@@ -0,0 +1,40 @@
+/**
+ * machine_specific_memory_setup - Hook for machine specific memory setup.
+ *
+ * Description:
+ *	This is included late in kernel/setup.c so that it can make
+ *	use of all of the static functions.
+ **/
+
+static inline char * __init machine_specific_memory_setup(void)
+{
+	char *who;
+
+
+	who = "BIOS-e820";
+
+	/*
+	 * Try to copy the BIOS-supplied E820-map.
+	 *
+	 * Otherwise fake a memory map; one section from 0k->640k,
+	 * the next section from 1mb->appropriate_mem_k
+	 */
+	sanitize_e820_map(E820_MAP, &E820_MAP_NR);
+	if (copy_e820_map(E820_MAP, E820_MAP_NR) < 0) {
+		unsigned long mem_size;
+
+		/* compare results from other methods and take the greater */
+		if (ALT_MEM_K < EXT_MEM_K) {
+			mem_size = EXT_MEM_K;
+			who = "BIOS-88";
+		} else {
+			mem_size = ALT_MEM_K;
+			who = "BIOS-e801";
+		}
+
+		e820.nr_map = 0;
+		add_memory_region(0, LOWMEMSIZE(), E820_RAM);
+		add_memory_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
+  	}
+	return who;
+}
diff -Nru a/include/asm-i386/mach-default/setup_arch_pre.h b/include/asm-i386/mach-default/setup_arch_pre.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-default/setup_arch_pre.h	Mon Dec 23 21:21:51 2002
@@ -0,0 +1,5 @@
+/* Hook to call BIOS initialisation function */
+
+/* no action for generic */
+
+#define ARCH_SETUP
diff -Nru a/include/asm-i386/mach-default/smpboot_hooks.h b/include/asm-i386/mach-default/smpboot_hooks.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-default/smpboot_hooks.h	Mon Dec 23 21:21:52 2002
@@ -0,0 +1,33 @@
+/* two abstractions specific to kernel/smpboot.c, mainly to cater to visws
+ * which needs to alter them. */
+
+static inline void smpboot_clear_io_apic_irqs(void)
+{
+	io_apic_irqs = 0;
+}
+
+static inline void smpboot_setup_warm_reset_vector(void)
+{
+	/*
+	 * Install writable page 0 entry to set BIOS data area.
+	 */
+	local_flush_tlb();
+
+	/*
+	 * Paranoid:  Set warm reset code and vector here back
+	 * to default values.
+	 */
+	CMOS_WRITE(0, 0xf);
+
+	*((volatile long *) phys_to_virt(0x467)) = 0;
+}
+
+static inline void smpboot_setup_io_apic(void)
+{
+	/*
+	 * Here we can be sure that there is an IO-APIC in the system. Let's
+	 * go and set it up:
+	 */
+	if (!skip_ioapic_setup && nr_ioapics)
+		setup_IO_APIC();
+}
diff -Nru a/include/asm-i386/mach-numaq/mach_apic.h b/include/asm-i386/mach-numaq/mach_apic.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-numaq/mach_apic.h	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,86 @@
+#ifndef __ASM_MACH_APIC_H
+#define __ASM_MACH_APIC_H
+
+#define APIC_DFR_VALUE	(APIC_DFR_FLAT)
+
+#define TARGET_CPUS (0xf)
+
+#define no_balance_irq (1)
+
+#define APIC_BROADCAST_ID      0x0F
+#define check_apicid_used(bitmap, apicid) (bitmap & (1 << apicid))
+
+static inline int apic_id_registered(void)
+{
+	return (1);
+}
+
+static inline void init_apic_ldr(void)
+{
+	/* Already done in NUMA-Q firmware */
+}
+
+static inline void clustered_apic_check(void)
+{
+	printk("Enabling APIC mode:  %s.  Using %d I/O APICs\n",
+		"NUMA-Q", nr_ioapics);
+}
+
+static inline int multi_timer_check(int apic, int irq)
+{
+	return (apic != 0 && irq == 0);
+}
+
+static inline ulong ioapic_phys_id_map(ulong phys_map)
+{
+	/* We don't have a good way to do this yet - hack */
+	return 0xf;
+}
+
+static inline int cpu_present_to_apicid(int mps_cpu)
+{
+	return ( ((mps_cpu/4)*16) + (1<<(mps_cpu%4)) );
+}
+
+static inline int generate_logical_apicid(int quad, int phys_apicid)
+{
+	return ( (quad << 4) + (phys_apicid ? phys_apicid << 1 : 1) );
+}
+
+static inline int apicid_to_quad(int logical_apicid) 
+{
+	return (logical_apicid >> 4);
+}
+
+static inline unsigned long apicid_to_cpu_present(int logical_apicid)
+{
+	return ( (logical_apicid&0xf) << (4*apicid_to_quad(logical_apicid)) );
+}
+
+static inline int mpc_apic_id(struct mpc_config_processor *m, int quad)
+{
+	int logical_apicid = generate_logical_apicid(quad, m->mpc_apicid);
+
+	printk("Processor #%d %ld:%ld APIC version %d (quad %d, apic %d)\n",
+			m->mpc_apicid,
+			(m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
+			(m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
+			m->mpc_apicver, quad, logical_apicid);
+	return logical_apicid;
+}
+
+#define wakeup_secondary_cpu(apicid, start_eip) \
+	wakeup_secondary_via_NMI(apicid)
+
+static inline void setup_portio_remap(void)
+{
+	if (numnodes <= 1)
+       		return;
+
+	printk("Remapping cross-quad port I/O for %d quads\n", numnodes);
+	xquad_portio = ioremap (XQUAD_PORTIO_BASE, numnodes*XQUAD_PORTIO_QUAD);
+	printk("xquad_portio vaddr 0x%08lx, len %08lx\n",
+		(u_long) xquad_portio, (u_long) numnodes*XQUAD_PORTIO_QUAD);
+}
+
+#endif /* __ASM_MACH_APIC_H */
diff -Nru a/include/asm-i386/mach-numaq/mach_ipi.h b/include/asm-i386/mach-numaq/mach_ipi.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-numaq/mach_ipi.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,24 @@
+#ifndef __ASM_MACH_IPI_H
+#define __ASM_MACH_IPI_H
+
+static inline void send_IPI_mask_sequence(int mask, int vector);
+
+static inline void send_IPI_mask(int mask, int vector)
+{
+	send_IPI_mask_sequence(mask, vector);
+}
+
+static inline void send_IPI_allbutself(int vector)
+{
+	unsigned long mask = cpu_online_map & ~(1 << smp_processor_id());
+
+	if (mask)
+		send_IPI_mask(mask, vector);
+}
+
+static inline void send_IPI_all(int vector)
+{
+	send_IPI_mask(cpu_online_map, vector);
+}
+
+#endif /* __ASM_MACH_IPI_H */
diff -Nru a/include/asm-i386/mach-numaq/mach_mpparse.h b/include/asm-i386/mach-numaq/mach_mpparse.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-numaq/mach_mpparse.h	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,37 @@
+#ifndef __ASM_MACH_MPPARSE_H
+#define __ASM_MACH_MPPARSE_H
+
+static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable,
+		        unsigned short oemsize);
+
+static inline void mpc_oem_bus_info(struct mpc_config_bus *m, char *name, 
+				struct mpc_config_translation *translation)
+{
+	int quad = translation->trans_quad;
+	int local = translation->trans_local;
+
+	mp_bus_id_to_node[m->mpc_busid] = quad;
+	mp_bus_id_to_local[m->mpc_busid] = local;
+	printk("Bus #%d is %s (node %d)\n", m->mpc_busid, name, quad);
+}
+
+static inline void mpc_oem_pci_bus(struct mpc_config_bus *m, 
+				struct mpc_config_translation *translation)
+{
+	int quad = translation->trans_quad;
+	int local = translation->trans_local;
+
+	quad_local_to_mp_bus_id[quad][local] = m->mpc_busid;
+}
+
+static inline void mps_oem_check(struct mp_config_table *mpc, char *oem, 
+		char *productid)
+{
+	if (strncmp(oem, "IBM NUMA", 8))
+		printk("Warning!  May not be a NUMA-Q system!\n");
+	if (mpc->mpc_oemptr)
+		smp_read_mpc_oem((struct mp_config_oemtable *) mpc->mpc_oemptr, 
+				mpc->mpc_oemsize);
+}
+
+#endif /* __ASM_MACH_MPPARSE_H */
diff -Nru a/include/asm-i386/mach-summit/mach_apic.h b/include/asm-i386/mach-summit/mach_apic.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-summit/mach_apic.h	Mon Dec 23 21:21:57 2002
@@ -0,0 +1,64 @@
+#ifndef __ASM_MACH_APIC_H
+#define __ASM_MACH_APIC_H
+
+extern int x86_summit;
+
+#define XAPIC_DEST_CPUS_MASK    0x0Fu
+#define XAPIC_DEST_CLUSTER_MASK 0xF0u
+
+#define xapic_phys_to_log_apicid(phys_apic) ( (1ul << ((phys_apic) & 0x3)) |\
+		((phys_apic) & XAPIC_DEST_CLUSTER_MASK) )
+
+static inline unsigned long calculate_ldr(unsigned long old)
+{
+	unsigned long id;
+
+	if (x86_summit)
+		id = xapic_phys_to_log_apicid(hard_smp_processor_id());
+	else
+		id = 1UL << smp_processor_id();
+	return ((old & ~APIC_LDR_MASK) | SET_APIC_LOGICAL_ID(id));
+}
+
+#define APIC_DFR_VALUE	(x86_summit ? APIC_DFR_CLUSTER : APIC_DFR_FLAT)
+#define TARGET_CPUS	(x86_summit ? XAPIC_DEST_CPUS_MASK : cpu_online_map)
+
+#define APIC_BROADCAST_ID     (x86_summit ? 0xFF : 0x0F)
+#define check_apicid_used(bitmap, apicid) (0)
+
+static inline void clustered_apic_check(void)
+{
+	printk("Enabling APIC mode:  %s.  Using %d I/O APICs\n",
+		(x86_summit ? "Summit" : "Flat"), nr_ioapics);
+}
+
+static inline int cpu_present_to_apicid(int mps_cpu)
+{
+	if (x86_summit)
+		return (int) raw_phys_apicid[mps_cpu];
+	else
+		return mps_cpu;
+}
+
+static inline ulong ioapic_phys_id_map(ulong phys_map)
+{
+	/* For clustered we don't have a good way to do this yet - hack */
+	return (x86_summit ? 0x0F : phys_map);
+}
+
+static inline unsigned long apicid_to_phys_cpu_present(int apicid)
+{
+	if (x86_summit)
+		return (1ul << (((apicid >> 4) << 2) | (apicid & 0x3)));
+	else
+		return (1ul << apicid);
+}
+
+#define wakeup_secondary_cpu(apicid, start_eip) \
+	wakeup_secondary_via_INIT(apicid, start_eip)
+
+static inline void setup_portio_remap(void)
+{
+}
+
+#endif /* __ASM_MACH_APIC_H */
diff -Nru a/include/asm-i386/mach-summit/mach_ipi.h b/include/asm-i386/mach-summit/mach_ipi.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-summit/mach_ipi.h	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,24 @@
+#ifndef __ASM_MACH_IPI_H
+#define __ASM_MACH_IPI_H
+
+static inline void send_IPI_mask_sequence(int mask, int vector);
+
+static inline void send_IPI_mask(int mask, int vector)
+{
+	send_IPI_mask_sequence(mask, vector);
+}
+
+static inline void send_IPI_allbutself(int vector)
+{
+	unsigned long mask = cpu_online_map & ~(1 << smp_processor_id());
+
+	if (mask)
+		send_IPI_mask(mask, vector);
+}
+
+static inline void send_IPI_all(int vector)
+{
+	send_IPI_mask(cpu_online_map, vector);
+}
+
+#endif /* __ASM_MACH_IPI_H */
diff -Nru a/include/asm-i386/mach-summit/mach_mpparse.h b/include/asm-i386/mach-summit/mach_mpparse.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-summit/mach_mpparse.h	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,22 @@
+#ifndef __ASM_MACH_MPPARSE_H
+#define __ASM_MACH_MPPARSE_H
+
+static inline void mpc_oem_bus_info(struct mpc_config_bus *m, char *name, 
+				struct mpc_config_translation *translation)
+{
+	Dprintk("Bus #%d is %s\n", m->mpc_busid, name);
+}
+
+static inline void mpc_oem_pci_bus(struct mpc_config_bus *m, 
+				struct mpc_config_translation *translation)
+{
+}
+
+static inline void mps_oem_check(struct mp_config_table *mpc, char *oem, 
+		char *productid)
+{
+	if (!strncmp(oem, "IBM ENSW", 8) && !strncmp(str, "VIGIL SMP", 9))
+		x86_summit = 1;
+}
+
+#endif /* __ASM_MACH_MPPARSE_H */
diff -Nru a/include/asm-i386/mach-visws/do_timer.h b/include/asm-i386/mach-visws/do_timer.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-visws/do_timer.h	Mon Dec 23 21:21:52 2002
@@ -0,0 +1,49 @@
+/* defines for inline arch setup functions */
+
+#include <asm/fixmap.h>
+#include <asm/cobalt.h>
+
+static inline void do_timer_interrupt_hook(struct pt_regs *regs)
+{
+	/* Clear the interrupt */
+	co_cpu_write(CO_CPU_STAT,co_cpu_read(CO_CPU_STAT) & ~CO_STAT_TIMEINTR);
+
+	do_timer(regs);
+/*
+ * In the SMP case we use the local APIC timer interrupt to do the
+ * profiling, except when we simulate SMP mode on a uniprocessor
+ * system, in that case we have to call the local interrupt handler.
+ */
+#ifndef CONFIG_X86_LOCAL_APIC
+	x86_do_profile(regs);
+#else
+	if (!using_apic_timer)
+		smp_local_timer_interrupt(regs);
+#endif
+}
+
+static inline int do_timer_overflow(int count)
+{
+	int i;
+
+	spin_lock(&i8259A_lock);
+	/*
+	 * This is tricky when I/O APICs are used;
+	 * see do_timer_interrupt().
+	 */
+	i = inb(0x20);
+	spin_unlock(&i8259A_lock);
+	
+	/* assumption about timer being IRQ0 */
+	if (i & 0x01) {
+		/*
+		 * We cannot detect lost timer interrupts ... 
+		 * well, that's why we call them lost, don't we? :)
+		 * [hmm, on the Pentium and Alpha we can ... sort of]
+		 */
+		count -= LATCH;
+	} else {
+		printk("do_slow_gettimeoffset(): hardware timer problem?\n");
+	}
+	return count;
+}
diff -Nru a/include/asm-i386/mach-visws/entry_arch.h b/include/asm-i386/mach-visws/entry_arch.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-visws/entry_arch.h	Mon Dec 23 21:22:00 2002
@@ -0,0 +1,23 @@
+/*
+ * The following vectors are part of the Linux architecture, there
+ * is no hardware IRQ pin equivalent for them, they are triggered
+ * through the ICC by us (IPIs)
+ */
+#ifdef CONFIG_X86_SMP
+BUILD_INTERRUPT(reschedule_interrupt,RESCHEDULE_VECTOR)
+BUILD_INTERRUPT(invalidate_interrupt,INVALIDATE_TLB_VECTOR)
+BUILD_INTERRUPT(call_function_interrupt,CALL_FUNCTION_VECTOR)
+#endif
+
+/*
+ * every pentium local APIC has two 'local interrupts', with a
+ * soft-definable vector attached to both interrupts, one of
+ * which is a timer interrupt, the other one is error counter
+ * overflow. Linux uses the local APIC timer interrupt to get
+ * a much simpler SMP time architecture:
+ */
+#ifdef CONFIG_X86_LOCAL_APIC
+BUILD_INTERRUPT(apic_timer_interrupt,LOCAL_TIMER_VECTOR)
+BUILD_INTERRUPT(error_interrupt,ERROR_APIC_VECTOR)
+BUILD_INTERRUPT(spurious_interrupt,SPURIOUS_APIC_VECTOR)
+#endif
diff -Nru a/include/asm-i386/mach-visws/irq_vectors.h b/include/asm-i386/mach-visws/irq_vectors.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-visws/irq_vectors.h	Mon Dec 23 21:21:51 2002
@@ -0,0 +1,64 @@
+#ifndef _ASM_IRQ_VECTORS_H
+#define _ASM_IRQ_VECTORS_H
+
+/*
+ * IDT vectors usable for external interrupt sources start
+ * at 0x20:
+ */
+#define FIRST_EXTERNAL_VECTOR	0x20
+
+#define SYSCALL_VECTOR		0x80
+
+/*
+ * Vectors 0x20-0x2f are used for ISA interrupts.
+ */
+
+/*
+ * Special IRQ vectors used by the SMP architecture, 0xf0-0xff
+ *
+ *  some of the following vectors are 'rare', they are merged
+ *  into a single vector (CALL_FUNCTION_VECTOR) to save vector space.
+ *  TLB, reschedule and local APIC vectors are performance-critical.
+ *
+ *  Vectors 0xf0-0xfa are free (reserved for future Linux use).
+ */
+#define SPURIOUS_APIC_VECTOR	0xff
+#define ERROR_APIC_VECTOR	0xfe
+#define INVALIDATE_TLB_VECTOR	0xfd
+#define RESCHEDULE_VECTOR	0xfc
+#define CALL_FUNCTION_VECTOR	0xfb
+
+#define THERMAL_APIC_VECTOR	0xf0
+/*
+ * Local APIC timer IRQ vector is on a different priority level,
+ * to work around the 'lost local interrupt if more than 2 IRQ
+ * sources per level' errata.
+ */
+#define LOCAL_TIMER_VECTOR	0xef
+
+/*
+ * First APIC vector available to drivers: (vectors 0x30-0xee)
+ * we start at 0x31 to spread out vectors evenly between priority
+ * levels. (0x80 is the syscall vector)
+ */
+#define FIRST_DEVICE_VECTOR	0x31
+#define FIRST_SYSTEM_VECTOR	0xef
+
+#define TIMER_IRQ 0
+
+/*
+ * 16 8259A IRQ's, 208 potential APIC interrupt sources.
+ * Right now the APIC is mostly only used for SMP.
+ * 256 vectors is an architectural limit. (we can have
+ * more than 256 devices theoretically, but they will
+ * have to use shared interrupts)
+ * Since vectors 0x00-0x1f are used/reserved for the CPU,
+ * the usable vector space is 0x20-0xff (224 vectors)
+ */
+#ifdef CONFIG_X86_IO_APIC
+#define NR_IRQS 224
+#else
+#define NR_IRQS 16
+#endif
+
+#endif /* _ASM_IRQ_VECTORS_H */
diff -Nru a/include/asm-i386/mach-visws/setup_arch_post.h b/include/asm-i386/mach-visws/setup_arch_post.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-visws/setup_arch_post.h	Mon Dec 23 21:21:55 2002
@@ -0,0 +1,37 @@
+/* Hook for machine specific memory setup.
+ *
+ * This is included late in kernel/setup.c so that it can make use of all of
+ * the static functions. */
+
+static inline char * __init machine_specific_memory_setup(void)
+{
+	char *who;
+
+
+	who = "BIOS-e820";
+
+	/*
+	 * Try to copy the BIOS-supplied E820-map.
+	 *
+	 * Otherwise fake a memory map; one section from 0k->640k,
+	 * the next section from 1mb->appropriate_mem_k
+	 */
+	sanitize_e820_map(E820_MAP, &E820_MAP_NR);
+	if (copy_e820_map(E820_MAP, E820_MAP_NR) < 0) {
+		unsigned long mem_size;
+
+		/* compare results from other methods and take the greater */
+		if (ALT_MEM_K < EXT_MEM_K) {
+			mem_size = EXT_MEM_K;
+			who = "BIOS-88";
+		} else {
+			mem_size = ALT_MEM_K;
+			who = "BIOS-e801";
+		}
+
+		e820.nr_map = 0;
+		add_memory_region(0, LOWMEMSIZE(), E820_RAM);
+		add_memory_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
+  	}
+	return who;
+}
diff -Nru a/include/asm-i386/mach-visws/setup_arch_pre.h b/include/asm-i386/mach-visws/setup_arch_pre.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-visws/setup_arch_pre.h	Mon Dec 23 21:21:53 2002
@@ -0,0 +1,5 @@
+/* Hook to call BIOS initialisation function */
+
+/* no action for visws */
+
+#define ARCH_SETUP
diff -Nru a/include/asm-i386/mach-visws/smpboot_hooks.h b/include/asm-i386/mach-visws/smpboot_hooks.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-visws/smpboot_hooks.h	Mon Dec 23 21:21:51 2002
@@ -0,0 +1,13 @@
+/* for visws do nothing for any of these */
+
+static inline void smpboot_clear_io_apic_irqs(void)
+{
+}
+
+static inline void smpboot_setup_warm_reset_vector(void)
+{
+}
+
+static inline void smpboot_setup_io_apic(void)
+{
+}
diff -Nru a/include/asm-i386/mach-voyager/do_timer.h b/include/asm-i386/mach-voyager/do_timer.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-voyager/do_timer.h	Mon Dec 23 21:21:59 2002
@@ -0,0 +1,22 @@
+/* defines for inline arch setup functions */
+#include <asm/voyager.h>
+
+static inline void do_timer_interrupt_hook(struct pt_regs *regs)
+{
+	do_timer(regs);
+
+	voyager_timer_interrupt(regs);
+}
+
+static inline int do_timer_overflow(int count)
+{
+	/* can't read the ISR, just assume 1 tick
+	   overflow */
+	if(count > LATCH || count < 0) {
+		printk(KERN_ERR "VOYAGER PROBLEM: count is %d, latch is %d\n", count, LATCH);
+		count = LATCH;
+	}
+	count -= LATCH;
+
+	return count;
+}
diff -Nru a/include/asm-i386/mach-voyager/entry_arch.h b/include/asm-i386/mach-voyager/entry_arch.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-voyager/entry_arch.h	Mon Dec 23 21:21:59 2002
@@ -0,0 +1,26 @@
+/* -*- mode: c; c-basic-offset: 8 -*- */
+
+/* Copyright (C) 2002
+ *
+ * Author: James.Bottomley@HansenPartnership.com
+ *
+ * linux/arch/i386/voyager/entry_arch.h
+ *
+ * This file builds the VIC and QIC CPI gates
+ */
+
+/* initialise the voyager interrupt gates 
+ *
+ * This uses the macros in irq.h to set up assembly jump gates.  The
+ * calls are then redirected to the same routine with smp_ prefixed */
+BUILD_INTERRUPT(vic_sys_interrupt, VIC_SYS_INT)
+BUILD_INTERRUPT(vic_cmn_interrupt, VIC_CMN_INT)
+BUILD_INTERRUPT(vic_cpi_interrupt, VIC_CPI_LEVEL0);
+
+/* do all the QIC interrupts */
+BUILD_INTERRUPT(qic_timer_interrupt, QIC_TIMER_CPI);
+BUILD_INTERRUPT(qic_invalidate_interrupt, QIC_INVALIDATE_CPI);
+BUILD_INTERRUPT(qic_reschedule_interrupt, QIC_RESCHEDULE_CPI);
+BUILD_INTERRUPT(qic_enable_irq_interrupt, QIC_ENABLE_IRQ_CPI);
+BUILD_INTERRUPT(qic_call_function_interrupt, QIC_CALL_FUNCTION_CPI);
+
diff -Nru a/include/asm-i386/mach-voyager/irq_vectors.h b/include/asm-i386/mach-voyager/irq_vectors.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-voyager/irq_vectors.h	Mon Dec 23 21:21:52 2002
@@ -0,0 +1,71 @@
+/* -*- mode: c; c-basic-offset: 8 -*- */
+
+/* Copyright (C) 2002
+ *
+ * Author: James.Bottomley@HansenPartnership.com
+ *
+ * linux/arch/i386/voyager/irq_vectors.h
+ *
+ * This file provides definitions for the VIC and QIC CPIs
+ */
+
+#ifndef _ASM_IRQ_VECTORS_H
+#define _ASM_IRQ_VECTORS_H
+
+/*
+ * IDT vectors usable for external interrupt sources start
+ * at 0x20:
+ */
+#define FIRST_EXTERNAL_VECTOR	0x20
+
+#define SYSCALL_VECTOR		0x80
+
+/*
+ * Vectors 0x20-0x2f are used for ISA interrupts.
+ */
+
+/* These define the CPIs we use in linux */
+#define VIC_CPI_LEVEL0			0
+#define VIC_CPI_LEVEL1			1
+/* now the fake CPIs */
+#define VIC_TIMER_CPI			2
+#define VIC_INVALIDATE_CPI		3
+#define VIC_RESCHEDULE_CPI		4
+#define VIC_ENABLE_IRQ_CPI		5
+#define VIC_CALL_FUNCTION_CPI		6
+
+/* Now the QIC CPIs:  Since we don't need the two initial levels,
+ * these are 2 less than the VIC CPIs */
+#define QIC_CPI_OFFSET			1
+#define QIC_TIMER_CPI			(VIC_TIMER_CPI - QIC_CPI_OFFSET)
+#define QIC_INVALIDATE_CPI		(VIC_INVALIDATE_CPI - QIC_CPI_OFFSET)
+#define QIC_RESCHEDULE_CPI		(VIC_RESCHEDULE_CPI - QIC_CPI_OFFSET)
+#define QIC_ENABLE_IRQ_CPI		(VIC_ENABLE_IRQ_CPI - QIC_CPI_OFFSET)
+#define QIC_CALL_FUNCTION_CPI		(VIC_CALL_FUNCTION_CPI - QIC_CPI_OFFSET)
+
+#define VIC_START_FAKE_CPI		VIC_TIMER_CPI
+#define VIC_END_FAKE_CPI		VIC_CALL_FUNCTION_CPI
+
+/* this is the SYS_INT CPI. */
+#define VIC_SYS_INT			8
+#define VIC_CMN_INT			15
+
+/* This is the boot CPI for alternate processors.  It gets overwritten
+ * by the above once the system has activated all available processors */
+#define VIC_CPU_BOOT_CPI		VIC_CPI_LEVEL0
+#define VIC_CPU_BOOT_ERRATA_CPI		(VIC_CPI_LEVEL0 + 8)
+
+#define NR_IRQS 224
+
+#ifndef __ASSEMBLY__
+extern asmlinkage void vic_cpi_interrupt(void);
+extern asmlinkage void vic_sys_interrupt(void);
+extern asmlinkage void vic_cmn_interrupt(void);
+extern asmlinkage void qic_timer_interrupt(void);
+extern asmlinkage void qic_invalidate_interrupt(void);
+extern asmlinkage void qic_reschedule_interrupt(void);
+extern asmlinkage void qic_enable_irq_interrupt(void);
+extern asmlinkage void qic_call_function_interrupt(void);
+#endif /* !__ASSEMBLY__ */
+
+#endif /* _ASM_IRQ_VECTORS_H */
diff -Nru a/include/asm-i386/mach-voyager/setup_arch_post.h b/include/asm-i386/mach-voyager/setup_arch_post.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-voyager/setup_arch_post.h	Mon Dec 23 21:21:53 2002
@@ -0,0 +1,73 @@
+/* Hook for machine specific memory setup.
+ *
+ * This is included late in kernel/setup.c so that it can make use of all of
+ * the static functions. */
+
+static inline char * __init machine_specific_memory_setup(void)
+{
+	char *who;
+
+	who = "NOT VOYAGER";
+
+	if(voyager_level == 5) {
+		__u32 addr, length;
+		int i;
+
+		who = "Voyager-SUS";
+
+		e820.nr_map = 0;
+		for(i=0; voyager_memory_detect(i, &addr, &length); i++) {
+			add_memory_region(addr, length, E820_RAM);
+		}
+		return who;
+	} else if(voyager_level == 4) {
+		__u32 tom;
+		__u16 catbase = inb(VOYAGER_SSPB_RELOCATION_PORT)<<8;
+		/* select the DINO config space */
+		outb(VOYAGER_DINO, VOYAGER_CAT_CONFIG_PORT);
+		/* Read DINO top of memory register */
+		tom = ((inb(catbase + 0x4) & 0xf0) << 16)
+			+ ((inb(catbase + 0x5) & 0x7f) << 24);
+
+		if(inb(catbase) != VOYAGER_DINO) {
+			printk(KERN_ERR "Voyager: Failed to get DINO for L4, setting tom to EXT_MEM_K\n");
+			tom = (EXT_MEM_K)<<10;
+		}
+		who = "Voyager-TOM";
+		add_memory_region(0, 0x9f000, E820_RAM);
+		/* map from 1M to top of memory */
+		add_memory_region(1*1024*1024, tom - 1*1024*1024, E820_RAM);
+		/* FIXME: Should check the ASICs to see if I need to
+		 * take out the 8M window.  Just do it at the moment
+		 * */
+		add_memory_region(8*1024*1024, 8*1024*1024, E820_RESERVED);
+		return who;
+	}
+
+	who = "BIOS-e820";
+
+	/*
+	 * Try to copy the BIOS-supplied E820-map.
+	 *
+	 * Otherwise fake a memory map; one section from 0k->640k,
+	 * the next section from 1mb->appropriate_mem_k
+	 */
+	sanitize_e820_map(E820_MAP, &E820_MAP_NR);
+	if (copy_e820_map(E820_MAP, E820_MAP_NR) < 0) {
+		unsigned long mem_size;
+
+		/* compare results from other methods and take the greater */
+		if (ALT_MEM_K < EXT_MEM_K) {
+			mem_size = EXT_MEM_K;
+			who = "BIOS-88";
+		} else {
+			mem_size = ALT_MEM_K;
+			who = "BIOS-e801";
+		}
+
+		e820.nr_map = 0;
+		add_memory_region(0, LOWMEMSIZE(), E820_RAM);
+		add_memory_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
+  	}
+	return who;
+}
diff -Nru a/include/asm-i386/mach-voyager/setup_arch_pre.h b/include/asm-i386/mach-voyager/setup_arch_pre.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-i386/mach-voyager/setup_arch_pre.h	Mon Dec 23 21:21:53 2002
@@ -0,0 +1,10 @@
+#include <asm/voyager.h>
+#define VOYAGER_BIOS_INFO ((struct voyager_bios_info *)(PARAM+0x40))
+
+/* Hook to call BIOS initialisation function */
+
+/* for voyager, pass the voyager BIOS/SUS info area to the detection 
+ * routines */
+
+#define ARCH_SETUP	voyager_detect(VOYAGER_BIOS_INFO);
+
diff -Nru a/include/asm-i386/msr.h b/include/asm-i386/msr.h
--- a/include/asm-i386/msr.h	Mon Dec 23 21:21:50 2002
+++ b/include/asm-i386/msr.h	Mon Dec 23 21:21:50 2002
@@ -53,6 +53,10 @@
 
 #define MSR_IA32_BBL_CR_CTL		0x119
 
+#define MSR_IA32_SYSENTER_CS		0x174
+#define MSR_IA32_SYSENTER_ESP		0x175
+#define MSR_IA32_SYSENTER_EIP		0x176
+
 #define MSR_IA32_MCG_CAP		0x179
 #define MSR_IA32_MCG_STATUS		0x17a
 #define MSR_IA32_MCG_CTL		0x17b
diff -Nru a/include/asm-i386/mtrr.h b/include/asm-i386/mtrr.h
--- a/include/asm-i386/mtrr.h	Mon Dec 23 21:21:54 2002
+++ b/include/asm-i386/mtrr.h	Mon Dec 23 21:21:54 2002
@@ -31,7 +31,7 @@
 struct mtrr_sentry
 {
     unsigned long base;    /*  Base address     */
-    unsigned long size;    /*  Size of region   */
+    unsigned int size;    /*  Size of region   */
     unsigned int type;     /*  Type of region   */
 };
 
@@ -39,7 +39,7 @@
 {
     unsigned int regnum;   /*  Register number  */
     unsigned long base;    /*  Base address     */
-    unsigned long size;    /*  Size of region   */
+    unsigned int size;    /*  Size of region   */
     unsigned int type;     /*  Type of region   */
 };
 
@@ -65,20 +65,9 @@
 #define MTRR_TYPE_WRBACK     6
 #define MTRR_NUM_TYPES       7
 
-#ifdef MTRR_NEED_STRINGS
-static char *mtrr_strings[MTRR_NUM_TYPES] =
-{
-    "uncachable",               /* 0 */
-    "write-combining",          /* 1 */
-    "?",                        /* 2 */
-    "?",                        /* 3 */
-    "write-through",            /* 4 */
-    "write-protect",            /* 5 */
-    "write-back",               /* 6 */
-};
-#endif
-
 #ifdef __KERNEL__
+
+extern char *mtrr_strings[]; 
 
 /*  The following functions are for use by other drivers  */
 # ifdef CONFIG_MTRR
diff -Nru a/include/asm-i386/pci.h b/include/asm-i386/pci.h
--- a/include/asm-i386/pci.h	Mon Dec 23 21:21:53 2002
+++ b/include/asm-i386/pci.h	Mon Dec 23 21:21:53 2002
@@ -46,78 +46,6 @@
  */
 #define PCI_DMA_BUS_IS_PHYS	(1)
 
-/* Allocate and map kernel buffer using consistent mode DMA for a device.
- * hwdev should be valid struct pci_dev pointer for PCI devices,
- * NULL for PCI-like buses (ISA, EISA).
- * Returns non-NULL cpu-view pointer to the buffer if successful and
- * sets *dma_addrp to the pci side dma address as well, else *dma_addrp
- * is undefined.
- */
-extern void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
-				  dma_addr_t *dma_handle);
-
-/* Free and unmap a consistent DMA buffer.
- * cpu_addr is what was returned from pci_alloc_consistent,
- * size must be the same as what as passed into pci_alloc_consistent,
- * and likewise dma_addr must be the same as what *dma_addrp was set to.
- *
- * References to the memory and mappings associated with cpu_addr/dma_addr
- * past this call are illegal.
- */
-extern void pci_free_consistent(struct pci_dev *hwdev, size_t size,
-				void *vaddr, dma_addr_t dma_handle);
-
-/* Map a single buffer of the indicated size for DMA in streaming mode.
- * The 32-bit bus address to use is returned.
- *
- * Once the device is given the dma address, the device owns this memory
- * until either pci_unmap_single or pci_dma_sync_single is performed.
- */
-static inline dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr,
-					size_t size, int direction)
-{
-	if (direction == PCI_DMA_NONE)
-		BUG();
-	flush_write_buffers();
-	return virt_to_phys(ptr);
-}
-
-/* Unmap a single streaming mode DMA translation.  The dma_addr and size
- * must match what was provided for in a previous pci_map_single call.  All
- * other usages are undefined.
- *
- * After this call, reads by the cpu to the buffer are guarenteed to see
- * whatever the device wrote there.
- */
-static inline void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
-				    size_t size, int direction)
-{
-	if (direction == PCI_DMA_NONE)
-		BUG();
-	/* Nothing to do */
-}
-
-/*
- * pci_{map,unmap}_single_page maps a kernel page to a dma_addr_t. identical
- * to pci_map_single, but takes a struct page instead of a virtual address
- */
-static inline dma_addr_t pci_map_page(struct pci_dev *hwdev, struct page *page,
-				      unsigned long offset, size_t size, int direction)
-{
-	if (direction == PCI_DMA_NONE)
-		BUG();
-
-	return (dma_addr_t)(page_to_pfn(page)) * PAGE_SIZE + offset;
-}
-
-static inline void pci_unmap_page(struct pci_dev *hwdev, dma_addr_t dma_address,
-				  size_t size, int direction)
-{
-	if (direction == PCI_DMA_NONE)
-		BUG();
-	/* Nothing to do */
-}
-
 /* pci_unmap_{page,single} is a nop so... */
 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME)
@@ -126,103 +54,6 @@
 #define pci_unmap_len(PTR, LEN_NAME)		(0)
 #define pci_unmap_len_set(PTR, LEN_NAME, VAL)	do { } while (0)
 
-/* Map a set of buffers described by scatterlist in streaming
- * mode for DMA.  This is the scather-gather version of the
- * above pci_map_single interface.  Here the scatter gather list
- * elements are each tagged with the appropriate dma address
- * and length.  They are obtained via sg_dma_{address,length}(SG).
- *
- * NOTE: An implementation may be able to use a smaller number of
- *       DMA address/length pairs than there are SG table elements.
- *       (for example via virtual mapping capabilities)
- *       The routine returns the number of addr/length pairs actually
- *       used, at most nents.
- *
- * Device ownership issues as mentioned above for pci_map_single are
- * the same here.
- */
-static inline int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
-			     int nents, int direction)
-{
-	int i;
-
-	if (direction == PCI_DMA_NONE)
-		BUG();
-
-	for (i = 0; i < nents; i++ ) {
-		if (!sg[i].page)
-			BUG();
-
-		sg[i].dma_address = page_to_phys(sg[i].page) + sg[i].offset;
-	}
-
-	flush_write_buffers();
-	return nents;
-}
-
-/* Unmap a set of streaming mode DMA translations.
- * Again, cpu read rules concerning calls here are the same as for
- * pci_unmap_single() above.
- */
-static inline void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
-				int nents, int direction)
-{
-	if (direction == PCI_DMA_NONE)
-		BUG();
-	/* Nothing to do */
-}
-
-/* Make physical memory consistent for a single
- * streaming mode DMA translation after a transfer.
- *
- * If you perform a pci_map_single() but wish to interrogate the
- * buffer using the cpu, yet do not wish to teardown the PCI dma
- * mapping, you must call this function before doing so.  At the
- * next point you give the PCI dma address back to the card, the
- * device again owns the buffer.
- */
-static inline void pci_dma_sync_single(struct pci_dev *hwdev,
-				       dma_addr_t dma_handle,
-				       size_t size, int direction)
-{
-	if (direction == PCI_DMA_NONE)
-		BUG();
-	flush_write_buffers();
-}
-
-/* Make physical memory consistent for a set of streaming
- * mode DMA translations after a transfer.
- *
- * The same as pci_dma_sync_single but for a scatter-gather list,
- * same rules and usage.
- */
-static inline void pci_dma_sync_sg(struct pci_dev *hwdev,
-				   struct scatterlist *sg,
-				   int nelems, int direction)
-{
-	if (direction == PCI_DMA_NONE)
-		BUG();
-	flush_write_buffers();
-}
-
-/* Return whether the given PCI device DMA address mask can
- * be supported properly.  For example, if your device can
- * only drive the low 24-bits during PCI bus mastering, then
- * you would pass 0x00ffffff as the mask to this function.
- */
-static inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
-{
-        /*
-         * we fall back to GFP_DMA when the mask isn't all 1s,
-         * so we can't guarantee allocations that must be
-         * within a tighter range than GFP_DMA..
-         */
-        if(mask < 0x00ffffff)
-                return 0;
-
-	return 1;
-}
-
 /* This is always fine. */
 #define pci_dac_dma_supported(pci_dev, mask)	(1)
 
@@ -270,5 +101,8 @@
 			       enum pci_mmap_state mmap_state, int write_combine);
 
 #endif /* __KERNEL__ */
+
+/* implement the pci_ DMA API in terms of the generic device dma_ one */
+#include <asm-generic/pci-dma-compat.h>
 
 #endif /* __i386_PCI_H */
diff -Nru a/include/asm-i386/processor.h b/include/asm-i386/processor.h
--- a/include/asm-i386/processor.h	Mon Dec 23 21:21:50 2002
+++ b/include/asm-i386/processor.h	Mon Dec 23 21:21:50 2002
@@ -14,6 +14,7 @@
 #include <asm/types.h>
 #include <asm/sigcontext.h>
 #include <asm/cpufeature.h>
+#include <asm/msr.h>
 #include <linux/cache.h>
 #include <linux/config.h>
 #include <linux/threads.h>
@@ -77,6 +78,7 @@
  */
 
 extern struct cpuinfo_x86 boot_cpu_data;
+extern struct cpuinfo_x86 new_cpu_data;
 extern struct tss_struct init_tss[NR_CPUS];
 
 #ifdef CONFIG_SMP
@@ -414,6 +416,21 @@
 	GDT_ENTRY_LDT,0, /* ldt */					\
 	0, INVALID_IO_BITMAP_OFFSET, /* tace, bitmap */		\
 	{~0, } /* ioperm */					\
+}
+
+static inline void load_esp0(struct tss_struct *tss, unsigned long esp0)
+{
+	tss->esp0 = esp0;
+	if (cpu_has_sep) {
+		wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0);
+		wrmsr(MSR_IA32_SYSENTER_ESP, esp0, 0);
+	}
+}
+
+static inline void disable_sysenter(void)
+{
+	if (cpu_has_sep)  
+		wrmsr(MSR_IA32_SYSENTER_CS, 0, 0);
 }
 
 #define start_thread(regs, new_eip, new_esp) do {		\
diff -Nru a/include/asm-i386/segment.h b/include/asm-i386/segment.h
--- a/include/asm-i386/segment.h	Mon Dec 23 21:21:52 2002
+++ b/include/asm-i386/segment.h	Mon Dec 23 21:21:52 2002
@@ -9,8 +9,8 @@
  *   2 - reserved
  *   3 - reserved
  *
- *   4 - default user CS		<==== new cacheline
- *   5 - default user DS
+ *   4 - unused			<==== new cacheline
+ *   5 - unused
  *
  *  ------- start of TLS (Thread-Local Storage) segments:
  *
@@ -25,16 +25,18 @@
  *
  *  12 - kernel code segment		<==== new cacheline
  *  13 - kernel data segment
- *  14 - TSS
- *  15 - LDT
- *  16 - PNPBIOS support (16->32 gate)
- *  17 - PNPBIOS support
- *  18 - PNPBIOS support
+ *  14 - default user CS
+ *  15 - default user DS
+ *  16 - TSS
+ *  17 - LDT
+ *  18 - PNPBIOS support (16->32 gate)
  *  19 - PNPBIOS support
  *  20 - PNPBIOS support
- *  21 - APM BIOS support
- *  22 - APM BIOS support
- *  23 - APM BIOS support 
+ *  21 - PNPBIOS support
+ *  22 - PNPBIOS support
+ *  23 - APM BIOS support
+ *  24 - APM BIOS support
+ *  25 - APM BIOS support 
  */
 #define GDT_ENTRY_TLS_ENTRIES	3
 #define GDT_ENTRY_TLS_MIN	6
@@ -42,10 +44,10 @@
 
 #define TLS_SIZE (GDT_ENTRY_TLS_ENTRIES * 8)
 
-#define GDT_ENTRY_DEFAULT_USER_CS	4
+#define GDT_ENTRY_DEFAULT_USER_CS	14
 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS * 8 + 3)
 
-#define GDT_ENTRY_DEFAULT_USER_DS	5
+#define GDT_ENTRY_DEFAULT_USER_DS	15
 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS * 8 + 3)
 
 #define GDT_ENTRY_KERNEL_BASE	12
@@ -56,16 +58,16 @@
 #define GDT_ENTRY_KERNEL_DS		(GDT_ENTRY_KERNEL_BASE + 1)
 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS * 8)
 
-#define GDT_ENTRY_TSS			(GDT_ENTRY_KERNEL_BASE + 2)
-#define GDT_ENTRY_LDT			(GDT_ENTRY_KERNEL_BASE + 3)
+#define GDT_ENTRY_TSS			(GDT_ENTRY_KERNEL_BASE + 4)
+#define GDT_ENTRY_LDT			(GDT_ENTRY_KERNEL_BASE + 5)
 
-#define GDT_ENTRY_PNPBIOS_BASE		(GDT_ENTRY_KERNEL_BASE + 4)
-#define GDT_ENTRY_APMBIOS_BASE		(GDT_ENTRY_KERNEL_BASE + 9)
+#define GDT_ENTRY_PNPBIOS_BASE		(GDT_ENTRY_KERNEL_BASE + 6)
+#define GDT_ENTRY_APMBIOS_BASE		(GDT_ENTRY_KERNEL_BASE + 11)
 
 /*
- * The GDT has 21 entries but we pad it to cacheline boundary:
+ * The GDT has 25 entries but we pad it to cacheline boundary:
  */
-#define GDT_ENTRIES 24
+#define GDT_ENTRIES 28
 
 #define GDT_SIZE (GDT_ENTRIES * 8)
 
diff -Nru a/include/asm-i386/spinlock.h b/include/asm-i386/spinlock.h
--- a/include/asm-i386/spinlock.h	Mon Dec 23 21:21:52 2002
+++ b/include/asm-i386/spinlock.h	Mon Dec 23 21:21:52 2002
@@ -48,8 +48,8 @@
 	"js 2f\n" \
 	LOCK_SECTION_START("") \
 	"2:\t" \
-	"cmpb $0,%0\n\t" \
 	"rep;nop\n\t" \
+	"cmpb $0,%0\n\t" \
 	"jle 2b\n\t" \
 	"jmp 1b\n" \
 	LOCK_SECTION_END
diff -Nru a/include/asm-i386/thread_info.h b/include/asm-i386/thread_info.h
--- a/include/asm-i386/thread_info.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-i386/thread_info.h	Mon Dec 23 21:21:51 2002
@@ -109,6 +109,7 @@
 #define TIF_NOTIFY_RESUME	1	/* resumption notification requested */
 #define TIF_SIGPENDING		2	/* signal pending */
 #define TIF_NEED_RESCHED	3	/* rescheduling necessary */
+#define TIF_SINGLESTEP		4	/* restore singlestep on return to user mode */
 #define TIF_USEDFPU		16	/* FPU was used by this task this quantum (SMP) */
 #define TIF_POLLING_NRFLAG	17	/* true if poll_idle() is polling TIF_NEED_RESCHED */
 
@@ -116,6 +117,7 @@
 #define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
 #define _TIF_SIGPENDING		(1<<TIF_SIGPENDING)
 #define _TIF_NEED_RESCHED	(1<<TIF_NEED_RESCHED)
+#define _TIF_SINGLESTEP		(1<<TIF_SINGLESTEP)
 #define _TIF_USEDFPU		(1<<TIF_USEDFPU)
 #define _TIF_POLLING_NRFLAG	(1<<TIF_POLLING_NRFLAG)
 
diff -Nru a/include/asm-ia64/acpi.h b/include/asm-ia64/acpi.h
--- a/include/asm-ia64/acpi.h	Mon Dec 23 21:22:00 2002
+++ b/include/asm-ia64/acpi.h	Mon Dec 23 21:22:00 2002
@@ -56,7 +56,7 @@
 
 #define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \
 	do { \
-	__asm__ volatile ("1:  ld4      r29=%1\n"  \
+	__asm__ volatile ("1:  ld4      r29=[%1]\n"  \
 		";;\n"                  \
 		"mov    ar.ccv=r29\n"   \
 		"mov    r2=r29\n"       \
@@ -68,7 +68,7 @@
 		";;\n"                  \
 		"add    r29=r29,r30\n"  \
 		";;\n"                  \
-		"cmpxchg4.acq   r30=%1,r29,ar.ccv\n" \
+		"cmpxchg4.acq   r30=[%1],r29,ar.ccv\n" \
 		";;\n"                  \
 		"cmp.eq p6,p7=r2,r30\n" \
 		"(p7) br.dpnt.few 1b\n" \
@@ -76,24 +76,24 @@
 		";;\n"                  \
 		"(p8) mov %0=-1\n"      \
 		"(p9) mov %0=r0\n"      \
-		:"=r"(Acq):"m"(GLptr):"r2","r29","r30","memory"); \
+		:"=r"(Acq):"r"(GLptr):"r2","r29","r30","memory"); \
 	} while (0)
 
 #define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq) \
 	do { \
-	__asm__ volatile ("1:  ld4      r29=%1\n" \
+	__asm__ volatile ("1:  ld4      r29=[%1]\n" \
 		";;\n"                  \
 		"mov    ar.ccv=r29\n"   \
 		"mov    r2=r29\n"       \
 		"and    r29=-4,r29\n"   \
 		";;\n"                  \
-		"cmpxchg4.acq   r30=%1,r29,ar.ccv\n" \
+		"cmpxchg4.acq   r30=[%1],r29,ar.ccv\n" \
 		";;\n"                  \
 		"cmp.eq p6,p7=r2,r30\n" \
 		"(p7) br.dpnt.few 1b\n" \
 		"and    %0=1,r2\n"      \
 		";;\n"                  \
-		:"=r"(Acq):"m"(GLptr):"r2","r29","r30","memory"); \
+		:"=r"(Acq):"r"(GLptr):"r2","r29","r30","memory"); \
 	} while (0)
 
 const char *acpi_get_sysname (void);
diff -Nru a/include/asm-ia64/atomic.h b/include/asm-ia64/atomic.h
--- a/include/asm-ia64/atomic.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-ia64/atomic.h	Mon Dec 23 21:21:51 2002
@@ -14,7 +14,7 @@
  */
 #include <linux/types.h>
 
-#include <asm/system.h>
+#include <asm/intrinsics.h>
 
 /*
  * On IA-64, counter must always be volatile to ensure that that the
diff -Nru a/include/asm-ia64/bitops.h b/include/asm-ia64/bitops.h
--- a/include/asm-ia64/bitops.h	Mon Dec 23 21:22:00 2002
+++ b/include/asm-ia64/bitops.h	Mon Dec 23 21:22:00 2002
@@ -9,9 +9,10 @@
  *	    scheduler patch
  */
 
+#include <linux/compiler.h>
 #include <linux/types.h>
 
-#include <asm/system.h>
+#include <asm/intrinsics.h>
 
 /**
  * set_bit - Atomically set a bit in memory
diff -Nru a/include/asm-ia64/compat.h b/include/asm-ia64/compat.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-ia64/compat.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,56 @@
+#ifndef _ASM_IA64_COMPAT_H
+#define _ASM_IA64_COMPAT_H
+/*
+ * Architecture specific compatibility types
+ */
+#include <linux/types.h>
+
+#define COMPAT_USER_HZ	100
+
+typedef u32		compat_size_t;
+typedef s32		compat_ssize_t;
+typedef s32		compat_time_t;
+typedef s32		compat_clock_t;
+typedef s32		compat_pid_t;
+typedef u16		compat_uid_t;
+typedef u16		compat_gid_t;
+typedef u16		compat_mode_t;
+typedef u32		compat_ino_t;
+typedef u16		compat_dev_t;
+typedef s32		compat_off_t;
+typedef u16		compat_nlink_t;
+
+struct compat_timespec {
+	compat_time_t	tv_sec;
+	s32		tv_nsec;
+};
+
+struct compat_timeval {
+	compat_time_t	tv_sec;
+	s32		tv_usec;
+};
+
+struct compat_stat {
+	compat_dev_t	st_dev;
+	u16		__pad1;
+	compat_ino_t	st_ino;
+	compat_mode_t	st_mode;
+	compat_nlink_t	st_nlink;
+	compat_uid_t	st_uid;
+	compat_gid_t	st_gid;
+	compat_dev_t	st_rdev;
+	u16		__pad2;
+	u32		st_size;
+	u32		st_blksize;
+	u32		st_blocks;
+	u32		st_atime;
+	u32		st_atime_nsec;
+	u32		st_mtime;
+	u32		st_mtime_nsec;
+	u32		st_ctime;
+	u32		st_ctime_nsec;
+	u32		__unused4;
+	u32		__unused5;
+};
+
+#endif /* _ASM_IA64_COMPAT_H */
diff -Nru a/include/asm-ia64/dma-mapping.h b/include/asm-ia64/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-ia64/dma-mapping.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-ia64/ia32.h b/include/asm-ia64/ia32.h
--- a/include/asm-ia64/ia32.h	Mon Dec 23 21:22:01 2002
+++ b/include/asm-ia64/ia32.h	Mon Dec 23 21:22:01 2002
@@ -6,30 +6,19 @@
 #ifdef CONFIG_IA32_SUPPORT
 
 #include <linux/binfmts.h>
+#include <linux/compat.h>
 
 /*
  * 32 bit structures for IA32 support.
  */
 
 /* 32bit compatibility types */
-typedef unsigned int	__kernel_size_t32;
-typedef int		__kernel_ssize_t32;
-typedef int		__kernel_ptrdiff_t32;
-typedef int		__kernel_time_t32;
-typedef int		__kernel_clock_t32;
-typedef int		__kernel_pid_t32;
 typedef unsigned short	__kernel_ipc_pid_t32;
-typedef unsigned short	__kernel_uid_t32;
 typedef unsigned int	__kernel_uid32_t32;
-typedef unsigned short	__kernel_gid_t32;
 typedef unsigned int	__kernel_gid32_t32;
-typedef unsigned short	__kernel_dev_t32;
-typedef unsigned int	__kernel_ino_t32;
-typedef unsigned short	__kernel_mode_t32;
 typedef unsigned short	__kernel_umode_t32;
 typedef short		__kernel_nlink_t32;
 typedef int		__kernel_daddr_t32;
-typedef int		__kernel_off_t32;
 typedef unsigned int	__kernel_caddr_t32;
 typedef long		__kernel_loff_t32;
 typedef __kernel_fsid_t	__kernel_fsid_t32;
@@ -39,20 +28,14 @@
 #define IA32_PAGE_MASK		(~(IA32_PAGE_SIZE - 1))
 #define IA32_PAGE_ALIGN(addr)	(((addr) + IA32_PAGE_SIZE - 1) & IA32_PAGE_MASK)
 #define IA32_CLOCKS_PER_SEC	100	/* Cast in stone for IA32 Linux */
-#define IA32_TICK(tick)		((unsigned long long)(tick) * IA32_CLOCKS_PER_SEC / CLOCKS_PER_SEC)
-
-struct timespec32 {
-	int	tv_sec;
-	int	tv_nsec;
-};
 
 /* fcntl.h */
 struct flock32 {
        short l_type;
        short l_whence;
-       __kernel_off_t32 l_start;
-       __kernel_off_t32 l_len;
-       __kernel_pid_t32 l_pid;
+       compat_off_t l_start;
+       compat_off_t l_len;
+       compat_pid_t l_pid;
 };
 
 #define F_GETLK64	12
@@ -130,6 +113,44 @@
        unsigned int cr2;
 };
 
+/* user.h */
+/*
+ * IA32 (Pentium III/4) FXSR, SSE support
+ *
+ * Provide support for the GDB 5.0+ PTRACE_{GET|SET}FPXREGS requests for
+ * interacting with the FXSR-format floating point environment.  Floating
+ * point data can be accessed in the regular format in the usual manner,
+ * and both the standard and SIMD floating point data can be accessed via
+ * the new ptrace requests.  In either case, changes to the FPU environment
+ * will be reflected in the task's state as expected.
+ */
+struct ia32_user_i387_struct {
+	int	cwd;
+	int	swd;
+	int	twd;
+	int	fip;
+	int	fcs;
+	int	foo;
+	int	fos;
+	int	st_space[20];	/* 8*10 bytes for each FP-reg = 80 bytes */
+};
+
+struct ia32_user_fxsr_struct {
+	unsigned short	cwd;
+	unsigned short	swd;
+	unsigned short	twd;
+	unsigned short	fop;
+	int	fip;
+	int	fcs;
+	int	foo;
+	int	fos;
+	int	mxcsr;
+	int	reserved;
+	int	st_space[32];	/* 8*16 bytes for each FP-reg = 128 bytes */
+	int	xmm_space[32];	/* 8*16 bytes for each XMM-reg = 128 bytes */
+	int	padding[56];
+};
+
 /* signal.h */
 #define _IA32_NSIG	       64
 #define _IA32_NSIG_BPW	       32
@@ -177,29 +198,6 @@
 	sigset_t	  uc_sigmask;	/* mask last for extensibility */
 };
 
-struct stat32 {
-       unsigned short st_dev;
-       unsigned short __pad1;
-       unsigned int st_ino;
-       unsigned short st_mode;
-       unsigned short st_nlink;
-       unsigned short st_uid;
-       unsigned short st_gid;
-       unsigned short st_rdev;
-       unsigned short __pad2;
-       unsigned int  st_size;
-       unsigned int  st_blksize;
-       unsigned int  st_blocks;
-       unsigned int  st_atime;
-       unsigned int  __unused1;
-       unsigned int  st_mtime;
-       unsigned int  __unused2;
-       unsigned int  st_ctime;
-       unsigned int  __unused3;
-       unsigned int  __unused4;
-       unsigned int  __unused5;
-};
-
 struct stat64 {
 	unsigned short	st_dev;
 	unsigned char	__pad0[10];
@@ -216,11 +214,11 @@
 	unsigned int	st_blocks;	/* Number 512-byte blocks allocated. */
 	unsigned int	__pad4;		/* future possible st_blocks high bits */
 	unsigned int	st_atime;
-	unsigned int	__pad5;
+	unsigned int	st_atime_nsec;
 	unsigned int	st_mtime;
-	unsigned int	__pad6;
+	unsigned int	st_mtime_nsec;
 	unsigned int	st_ctime;
-	unsigned int	__pad7;		/* will be high 32 bits of ctime someday */
+	unsigned int	st_ctime_nsec;
 	unsigned int	st_ino_lo;
 	unsigned int	st_ino_hi;
 };
@@ -275,8 +273,8 @@
 			unsigned int _pid;	/* which child */
 			unsigned int _uid;	/* sender's uid */
 			int _status;		/* exit code */
-			__kernel_clock_t32 _utime;
-			__kernel_clock_t32 _stime;
+			compat_clock_t _utime;
+			compat_clock_t _stime;
 		} _sigchld;
 
 		/* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
@@ -462,6 +460,8 @@
 #define IA32_PTRACE_SETREGS	13
 #define IA32_PTRACE_GETFPREGS	14
 #define IA32_PTRACE_SETFPREGS	15
+#define IA32_PTRACE_GETFPXREGS	18
+#define IA32_PTRACE_SETFPXREGS	19
 
 #define ia32_start_thread(regs,new_ip,new_sp) do {				\
 	set_fs(USER_DS);							\
diff -Nru a/include/asm-ia64/intrinsics.h b/include/asm-ia64/intrinsics.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-ia64/intrinsics.h	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,174 @@
+#ifndef _ASM_IA64_INTRINSICS_H
+#define _ASM_IA64_INTRINSICS_H
+
+/*
+ * Compiler-dependent intrinsics.
+ *
+ * Copyright (C) 2002 Hewlett-Packard Co
+ *	David Mosberger-Tang <davidm@hpl.hp.com>
+ */
+
+/*
+ * Force an unresolved reference if someone tries to use
+ * ia64_fetch_and_add() with a bad value.
+ */
+extern unsigned long __bad_size_for_ia64_fetch_and_add (void);
+extern unsigned long __bad_increment_for_ia64_fetch_and_add (void);
+
+#define IA64_FETCHADD(tmp,v,n,sz)						\
+({										\
+	switch (sz) {								\
+	      case 4:								\
+		__asm__ __volatile__ ("fetchadd4.rel %0=[%1],%2"		\
+				      : "=r"(tmp) : "r"(v), "i"(n) : "memory");	\
+		break;								\
+										\
+	      case 8:								\
+		__asm__ __volatile__ ("fetchadd8.rel %0=[%1],%2"		\
+				      : "=r"(tmp) : "r"(v), "i"(n) : "memory");	\
+		break;								\
+										\
+	      default:								\
+		__bad_size_for_ia64_fetch_and_add();				\
+	}									\
+})
+
+#define ia64_fetch_and_add(i,v)							\
+({										\
+	__u64 _tmp;								\
+	volatile __typeof__(*(v)) *_v = (v);					\
+	switch (i) {								\
+	      case -16:	IA64_FETCHADD(_tmp, _v, -16, sizeof(*(v))); break;	\
+	      case  -8:	IA64_FETCHADD(_tmp, _v,  -8, sizeof(*(v))); break;	\
+	      case  -4:	IA64_FETCHADD(_tmp, _v,  -4, sizeof(*(v))); break;	\
+	      case  -1:	IA64_FETCHADD(_tmp, _v,  -1, sizeof(*(v))); break;	\
+	      case   1:	IA64_FETCHADD(_tmp, _v,   1, sizeof(*(v))); break;	\
+	      case   4:	IA64_FETCHADD(_tmp, _v,   4, sizeof(*(v))); break;	\
+	      case   8:	IA64_FETCHADD(_tmp, _v,   8, sizeof(*(v))); break;	\
+	      case  16:	IA64_FETCHADD(_tmp, _v,  16, sizeof(*(v))); break;	\
+	      default:								\
+		_tmp = __bad_increment_for_ia64_fetch_and_add();		\
+		break;								\
+	}									\
+	(__typeof__(*(v))) (_tmp + (i));	/* return new value */		\
+})
+
+/*
+ * This function doesn't exist, so you'll get a linker error if
+ * something tries to do an invalid xchg().
+ */
+extern void __xchg_called_with_bad_pointer (void);
+
+static __inline__ unsigned long
+__xchg (unsigned long x, volatile void *ptr, int size)
+{
+	unsigned long result;
+
+	switch (size) {
+	      case 1:
+		__asm__ __volatile ("xchg1 %0=[%1],%2" : "=r" (result)
+				    : "r" (ptr), "r" (x) : "memory");
+		return result;
+
+	      case 2:
+		__asm__ __volatile ("xchg2 %0=[%1],%2" : "=r" (result)
+				    : "r" (ptr), "r" (x) : "memory");
+		return result;
+
+	      case 4:
+		__asm__ __volatile ("xchg4 %0=[%1],%2" : "=r" (result)
+				    : "r" (ptr), "r" (x) : "memory");
+		return result;
+
+	      case 8:
+		__asm__ __volatile ("xchg8 %0=[%1],%2" : "=r" (result)
+				    : "r" (ptr), "r" (x) : "memory");
+		return result;
+	}
+	__xchg_called_with_bad_pointer();
+	return x;
+}
+
+#define xchg(ptr,x)							     \
+  ((__typeof__(*(ptr))) __xchg ((unsigned long) (x), (ptr), sizeof(*(ptr))))
+
+/*
+ * Atomic compare and exchange.  Compare OLD with MEM, if identical,
+ * store NEW in MEM.  Return the initial value in MEM.  Success is
+ * indicated by comparing RETURN with OLD.
+ */
+
+#define __HAVE_ARCH_CMPXCHG 1
+
+/*
+ * This function doesn't exist, so you'll get a linker error
+ * if something tries to do an invalid cmpxchg().
+ */
+extern long __cmpxchg_called_with_bad_pointer(void);
+
+#define ia64_cmpxchg(sem,ptr,old,new,size)						\
+({											\
+	__typeof__(ptr) _p_ = (ptr);							\
+	__typeof__(new) _n_ = (new);							\
+	__u64 _o_, _r_;									\
+											\
+	switch (size) {									\
+	      case 1: _o_ = (__u8 ) (long) (old); break;				\
+	      case 2: _o_ = (__u16) (long) (old); break;				\
+	      case 4: _o_ = (__u32) (long) (old); break;				\
+	      case 8: _o_ = (__u64) (long) (old); break;				\
+	      default: break;								\
+	}										\
+	 __asm__ __volatile__ ("mov ar.ccv=%0;;" :: "rO"(_o_));				\
+	switch (size) {									\
+	      case 1:									\
+		__asm__ __volatile__ ("cmpxchg1."sem" %0=[%1],%2,ar.ccv"		\
+				      : "=r"(_r_) : "r"(_p_), "r"(_n_) : "memory");	\
+		break;									\
+											\
+	      case 2:									\
+		__asm__ __volatile__ ("cmpxchg2."sem" %0=[%1],%2,ar.ccv"		\
+				      : "=r"(_r_) : "r"(_p_), "r"(_n_) : "memory");	\
+		break;									\
+											\
+	      case 4:									\
+		__asm__ __volatile__ ("cmpxchg4."sem" %0=[%1],%2,ar.ccv"		\
+				      : "=r"(_r_) : "r"(_p_), "r"(_n_) : "memory");	\
+		break;									\
+											\
+	      case 8:									\
+		__asm__ __volatile__ ("cmpxchg8."sem" %0=[%1],%2,ar.ccv"		\
+				      : "=r"(_r_) : "r"(_p_), "r"(_n_) : "memory");	\
+		break;									\
+											\
+	      default:									\
+		_r_ = __cmpxchg_called_with_bad_pointer();				\
+		break;									\
+	}										\
+	(__typeof__(old)) _r_;								\
+})
+
+#define cmpxchg_acq(ptr,o,n)	ia64_cmpxchg("acq", (ptr), (o), (n), sizeof(*(ptr)))
+#define cmpxchg_rel(ptr,o,n)	ia64_cmpxchg("rel", (ptr), (o), (n), sizeof(*(ptr)))
+
+/* for compatibility with other platforms: */
+#define cmpxchg(ptr,o,n)	cmpxchg_acq(ptr,o,n)
+
+#ifdef CONFIG_IA64_DEBUG_CMPXCHG
+# define CMPXCHG_BUGCHECK_DECL	int _cmpxchg_bugcheck_count = 128;
+# define CMPXCHG_BUGCHECK(v)							\
+  do {										\
+	if (_cmpxchg_bugcheck_count-- <= 0) {					\
+		void *ip;							\
+		extern int printk(const char *fmt, ...);			\
+		asm ("mov %0=ip" : "=r"(ip));					\
+		printk("CMPXCHG_BUGCHECK: stuck at %p on word %p\n", ip, (v));	\
+		break;								\
+	}									\
+  } while (0)
+#else /* !CONFIG_IA64_DEBUG_CMPXCHG */
+# define CMPXCHG_BUGCHECK_DECL
+# define CMPXCHG_BUGCHECK(v)
+#endif /* !CONFIG_IA64_DEBUG_CMPXCHG */
+
+#endif /* _ASM_IA64_INTRINSICS_H */
diff -Nru a/include/asm-ia64/machvec_sn2.h b/include/asm-ia64/machvec_sn2.h
--- a/include/asm-ia64/machvec_sn2.h	Mon Dec 23 21:21:53 2002
+++ b/include/asm-ia64/machvec_sn2.h	Mon Dec 23 21:21:53 2002
@@ -33,34 +33,33 @@
 #ifndef _ASM_IA64_MACHVEC_SN2_H
 #define _ASM_IA64_MACHVEC_SN2_H
 
-extern ia64_mv_setup_t sn1_setup;
+extern ia64_mv_setup_t sn_setup;
 extern ia64_mv_cpu_init_t sn_cpu_init;
-extern ia64_mv_irq_init_t sn1_irq_init;
+extern ia64_mv_irq_init_t sn_irq_init;
 extern ia64_mv_map_nr_t sn2_map_nr;
 extern ia64_mv_send_ipi_t sn2_send_IPI;
 extern ia64_mv_global_tlb_purge_t sn2_global_tlb_purge;
-extern ia64_mv_irq_desc sn1_irq_desc;
-extern ia64_mv_irq_to_vector sn1_irq_to_vector;
-extern ia64_mv_local_vector_to_irq sn1_local_vector_to_irq;
-extern ia64_mv_valid_irq sn1_valid_irq;
-extern ia64_mv_pci_fixup_t sn1_pci_fixup;
-#ifdef Colin /* We are using the same is Generic IA64 calls defined in io.h */
-extern ia64_mv_inb_t sn1_inb;
-extern ia64_mv_inw_t sn1_inw;
-extern ia64_mv_inl_t sn1_inl;
-extern ia64_mv_outb_t sn1_outb;
-extern ia64_mv_outw_t sn1_outw;
-extern ia64_mv_outl_t sn1_outl;
-#endif
-extern ia64_mv_pci_alloc_consistent	sn1_pci_alloc_consistent;
-extern ia64_mv_pci_free_consistent	sn1_pci_free_consistent;
-extern ia64_mv_pci_map_single		sn1_pci_map_single;
-extern ia64_mv_pci_unmap_single		sn1_pci_unmap_single;
-extern ia64_mv_pci_map_sg		sn1_pci_map_sg;
-extern ia64_mv_pci_unmap_sg		sn1_pci_unmap_sg;
-extern ia64_mv_pci_dma_sync_single	sn1_pci_dma_sync_single;
-extern ia64_mv_pci_dma_sync_sg		sn1_pci_dma_sync_sg;
-extern ia64_mv_pci_dma_address		sn1_dma_address;
+extern ia64_mv_irq_desc sn_irq_desc;
+extern ia64_mv_irq_to_vector sn_irq_to_vector;
+extern ia64_mv_local_vector_to_irq sn_local_vector_to_irq;
+extern ia64_mv_pci_fixup_t sn_pci_fixup;
+extern ia64_mv_inb_t sn_inb;
+extern ia64_mv_inw_t sn_inw;
+extern ia64_mv_inl_t sn_inl;
+extern ia64_mv_outb_t sn_outb;
+extern ia64_mv_outw_t sn_outw;
+extern ia64_mv_outl_t sn_outl;
+extern ia64_mv_mmiob_t			sn2_mmiob;
+extern ia64_mv_pci_alloc_consistent	sn_pci_alloc_consistent;
+extern ia64_mv_pci_free_consistent	sn_pci_free_consistent;
+extern ia64_mv_pci_map_single		sn_pci_map_single;
+extern ia64_mv_pci_unmap_single		sn_pci_unmap_single;
+extern ia64_mv_pci_map_sg		sn_pci_map_sg;
+extern ia64_mv_pci_unmap_sg		sn_pci_unmap_sg;
+extern ia64_mv_pci_dma_sync_single	sn_pci_dma_sync_single;
+extern ia64_mv_pci_dma_sync_sg		sn_pci_dma_sync_sg;
+extern ia64_mv_pci_dma_address		sn_dma_address;
+extern ia64_mv_pci_dma_supported	sn_pci_dma_supported;
 
 /*
  * This stuff has dual use!
@@ -69,33 +68,34 @@
  * platform's machvec structure.  When compiling a non-generic kernel,
  * the macros are used directly.
  */
-#define platform_name		"sn2"
-#define platform_setup		sn1_setup
-#define platform_cpu_init	sn_cpu_init
-#define platform_irq_init	sn1_irq_init
-#define platform_send_ipi	sn2_send_IPI
+#define platform_name			"sn2"
+#define platform_setup			sn_setup
+#define platform_cpu_init		sn_cpu_init
+#define platform_irq_init		sn_irq_init
+#define platform_map_nr			sn2_map_nr
+#define platform_send_ipi		sn2_send_IPI
 #define platform_global_tlb_purge       sn2_global_tlb_purge
-#ifdef Colin /* We are using the same is Generic IA64 calls defined in io.h */
-#define platform_inb		sn1_inb
-#define platform_inw		sn1_inw
-#define platform_inl		sn1_inl
-#define platform_outb		sn1_outb
-#define platform_outw		sn1_outw
-#define platform_outl		sn1_outl
-#endif
-#define platform_irq_desc	sn1_irq_desc
-#define platform_irq_to_vector	sn1_irq_to_vector
-#define platform_local_vector_to_irq	sn1_local_vector_to_irq
-#define platform_valid_irq	sn1_valid_irq
-#define platform_pci_dma_init	machvec_noop
-#define platform_pci_alloc_consistent	sn1_pci_alloc_consistent
-#define platform_pci_free_consistent	sn1_pci_free_consistent
-#define platform_pci_map_single		sn1_pci_map_single
-#define platform_pci_unmap_single	sn1_pci_unmap_single
-#define platform_pci_map_sg		sn1_pci_map_sg
-#define platform_pci_unmap_sg		sn1_pci_unmap_sg
-#define platform_pci_dma_sync_single	sn1_pci_dma_sync_single
-#define platform_pci_dma_sync_sg	sn1_pci_dma_sync_sg
-#define platform_pci_dma_address	sn1_dma_address
+#define platform_pci_fixup		sn_pci_fixup
+#define platform_inb			sn_inb
+#define platform_inw			sn_inw
+#define platform_inl			sn_inl
+#define platform_outb			sn_outb
+#define platform_outw			sn_outw
+#define platform_outl			sn_outl
+#define platform_mmiob			sn2_mmiob
+#define platform_irq_desc		sn_irq_desc
+#define platform_irq_to_vector		sn_irq_to_vector
+#define platform_local_vector_to_irq	sn_local_vector_to_irq
+#define platform_pci_dma_init		machvec_noop
+#define platform_pci_alloc_consistent	sn_pci_alloc_consistent
+#define platform_pci_free_consistent	sn_pci_free_consistent
+#define platform_pci_map_single		sn_pci_map_single
+#define platform_pci_unmap_single	sn_pci_unmap_single
+#define platform_pci_map_sg		sn_pci_map_sg
+#define platform_pci_unmap_sg		sn_pci_unmap_sg
+#define platform_pci_dma_sync_single	sn_pci_dma_sync_single
+#define platform_pci_dma_sync_sg	sn_pci_dma_sync_sg
+#define platform_pci_dma_address	sn_dma_address
+#define platform_pci_dma_supported	sn_pci_dma_supported
 
 #endif /* _ASM_IA64_MACHVEC_SN2_H */
diff -Nru a/include/asm-ia64/mca.h b/include/asm-ia64/mca.h
--- a/include/asm-ia64/mca.h	Mon Dec 23 21:21:52 2002
+++ b/include/asm-ia64/mca.h	Mon Dec 23 21:21:52 2002
@@ -103,6 +103,8 @@
 	IA64_MCA_NEW_CONTEXT	=	-1	/* SAL to return to new context */
 };
 
+#define MIN_STATE_AREA_SIZE     57
+
 typedef struct ia64_mca_os_to_sal_state_s {
 	u64		imots_os_status;	/*   OS status to SAL as to what happened
 						 *   with the MCA handling.
@@ -133,7 +135,7 @@
 extern void ia64_mca_cpe_int_handler(int,void *,struct pt_regs *);
 extern int  ia64_log_print(int,prfunc_t);
 extern void ia64_mca_cmc_vector_setup(void);
-extern void ia64_mca_check_errors( void );
+extern int  ia64_mca_check_errors(void);
 extern u64  ia64_log_get(int, prfunc_t);
 
 #define PLATFORM_CALL(fn, args)	printk("Platform call TBD\n")
diff -Nru a/include/asm-ia64/mca_asm.h b/include/asm-ia64/mca_asm.h
--- a/include/asm-ia64/mca_asm.h	Mon Dec 23 21:22:00 2002
+++ b/include/asm-ia64/mca_asm.h	Mon Dec 23 21:22:00 2002
@@ -16,6 +16,7 @@
 #define PSR_I		14
 #define	PSR_DT		17
 #define PSR_RT		27
+#define PSR_MC		35
 #define PSR_IT		36
 #define PSR_BN		44
 
@@ -106,6 +107,8 @@
 	dep	temp1 = 0, temp1, PSR_I, 1;						\
 	;;										\
 	dep	temp1 = 0, temp1, PSR_IC, 1;						\
+	;;										\
+	dep	temp1 = -1, temp1, PSR_MC, 1;						\
 	;;										\
 	movl	temp2 = start_addr;							\
 	mov	cr.ipsr = temp1;							\
diff -Nru a/include/asm-ia64/mman.h b/include/asm-ia64/mman.h
--- a/include/asm-ia64/mman.h	Mon Dec 23 21:21:55 2002
+++ b/include/asm-ia64/mman.h	Mon Dec 23 21:21:55 2002
@@ -18,12 +18,14 @@
 #define MAP_FIXED	0x10		/* Interpret addr exactly */
 #define MAP_ANONYMOUS	0x20		/* don't use a file */
 
-#define MAP_GROWSDOWN	0x0100		/* stack-like segment */
-#define MAP_GROWSUP	0x0200		/* register stack-like segment */
-#define MAP_DENYWRITE	0x0800		/* ETXTBSY */
-#define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
-#define MAP_LOCKED	0x2000		/* pages are locked */
-#define MAP_NORESERVE	0x4000		/* don't check for reservations */
+#define MAP_GROWSDOWN	0x00100		/* stack-like segment */
+#define MAP_GROWSUP	0x00200		/* register stack-like segment */
+#define MAP_DENYWRITE	0x00800		/* ETXTBSY */
+#define MAP_EXECUTABLE	0x01000		/* mark it as an executable */
+#define MAP_LOCKED	0x02000		/* pages are locked */
+#define MAP_NORESERVE	0x04000		/* don't check for reservations */
+#define MAP_POPULATE	0x08000		/* populate (prefault) pagetables */
+#define MAP_NONBLOCK	0x10000		/* do not block on IO */
 
 #define MS_ASYNC	1		/* sync memory asynchronously */
 #define MS_INVALIDATE	2		/* invalidate the caches */
diff -Nru a/include/asm-ia64/mmu.h b/include/asm-ia64/mmu.h
--- a/include/asm-ia64/mmu.h	Mon Dec 23 21:21:50 2002
+++ b/include/asm-ia64/mmu.h	Mon Dec 23 21:21:50 2002
@@ -1,7 +1,11 @@
 #ifndef __MMU_H
 #define __MMU_H
 
-/* Default "unsigned long" context */
-typedef unsigned long mm_context_t;
+/*
+ * Type for a context number.  We declare it volatile to ensure proper ordering when it's
+ * accessed outside of spinlock'd critical sections (e.g., as done in activate_mm() and
+ * init_new_context()).
+ */
+typedef volatile unsigned long mm_context_t;
 
 #endif
diff -Nru a/include/asm-ia64/mmu_context.h b/include/asm-ia64/mmu_context.h
--- a/include/asm-ia64/mmu_context.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-ia64/mmu_context.h	Mon Dec 23 21:21:51 2002
@@ -54,33 +54,40 @@
 static inline void
 delayed_tlb_flush (void)
 {
-	extern void __flush_tlb_all (void);
+	extern void local_flush_tlb_all (void);
 
 	if (unlikely(__get_cpu_var(ia64_need_tlb_flush))) {
-		__flush_tlb_all();
+		local_flush_tlb_all();
 		__get_cpu_var(ia64_need_tlb_flush) = 0;
 	}
 }
 
-static inline void
-get_new_mmu_context (struct mm_struct *mm)
+static inline mm_context_t
+get_mmu_context (struct mm_struct *mm)
 {
+	mm_context_t context = mm->context;
+
+	if (context)
+		return context;
+
 	spin_lock(&ia64_ctx.lock);
 	{
-		if (ia64_ctx.next >= ia64_ctx.limit)
-			wrap_mmu_context(mm);
-		mm->context = ia64_ctx.next++;
+		/* re-check, now that we've got the lock: */
+		context = mm->context;
+		if (context == 0) {
+			if (ia64_ctx.next >= ia64_ctx.limit)
+				wrap_mmu_context(mm);
+			mm->context = context = ia64_ctx.next++;
+		}
 	}
 	spin_unlock(&ia64_ctx.lock);
+	return context;
 }
 
-static inline void
-get_mmu_context (struct mm_struct *mm)
-{
-	if (mm->context == 0)
-		get_new_mmu_context(mm);
-}
-
+/*
+ * Initialize context number to some sane value.  MM is guaranteed to be a brand-new
+ * address-space, so no TLB flushing is needed, ever.
+ */
 static inline int
 init_new_context (struct task_struct *p, struct mm_struct *mm)
 {
@@ -95,13 +102,13 @@
 }
 
 static inline void
-reload_context (struct mm_struct *mm)
+reload_context (mm_context_t context)
 {
 	unsigned long rid;
 	unsigned long rid_incr = 0;
 	unsigned long rr0, rr1, rr2, rr3, rr4;
 
-	rid = mm->context << 3;	/* make space for encoding the region number */
+	rid = context << 3;	/* make space for encoding the region number */
 	rid_incr = 1 << 8;
 
 	/* encode the region id, preferred page size, and VHPT enable bit: */
@@ -124,6 +131,18 @@
 	ia64_insn_group_barrier();
 }
 
+static inline void
+activate_context (struct mm_struct *mm)
+{
+	mm_context_t context;
+
+	do {
+		context = get_mmu_context(mm);
+		reload_context(context);
+		/* in the unlikely event of a TLB-flush by another thread, redo the load: */
+	} while (unlikely(context != mm->context));
+}
+
 /*
  * Switch from address space PREV to address space NEXT.
  */
@@ -133,12 +152,11 @@
 	delayed_tlb_flush();
 
 	/*
-	 * We may get interrupts here, but that's OK because interrupt
-	 * handlers cannot touch user-space.
+	 * We may get interrupts here, but that's OK because interrupt handlers cannot
+	 * touch user-space.
 	 */
 	ia64_set_kr(IA64_KR_PT_BASE, __pa(next->pgd));
-	get_mmu_context(next);
-	reload_context(next);
+	activate_context(next);
 }
 
 #define switch_mm(prev_mm,next_mm,next_task,cpu)	activate_mm(prev_mm, next_mm)
diff -Nru a/include/asm-ia64/mmzone.h b/include/asm-ia64/mmzone.h
--- a/include/asm-ia64/mmzone.h	Mon Dec 23 21:22:02 2002
+++ b/include/asm-ia64/mmzone.h	Mon Dec 23 21:22:02 2002
@@ -104,12 +104,22 @@
 
 /*
  * Bank definitions.
- * Current settings for DIG: 512MB/bank, 16GB/node.
+ * Configurable settings for DIG: 512MB/bank:  16GB/node,
+ *                               2048MB/bank:  64GB/node,
+ *                               8192MB/bank: 256GB/node.
  */
 #define NR_BANKS_PER_NODE	32
-#define BANK_OFFSET(addr)	((unsigned long)(addr) & (BANKSIZE-1))
-#define DIG_BANKSHIFT		29
+#if defined(CONFIG_IA64_NODESIZE_16GB)
+# define DIG_BANKSHIFT		29
+#elif defined(CONFIG_IA64_NODESIZE_64GB)
+# define DIG_BANKSHIFT		31
+#elif defined(CONFIG_IA64_NODESIZE_256GB)
+# define DIG_BANKSHIFT		33
+#else
+# error Unsupported bank and nodesize!
+#endif
 #define BANKSIZE		(1UL << DIG_BANKSHIFT)
+#define BANK_OFFSET(addr)	((unsigned long)(addr) & (BANKSIZE-1))
 #define NR_BANKS		(NR_BANKS_PER_NODE * NR_NODES)
 
 /*
diff -Nru a/include/asm-ia64/module.h b/include/asm-ia64/module.h
--- a/include/asm-ia64/module.h	Mon Dec 23 21:21:53 2002
+++ b/include/asm-ia64/module.h	Mon Dec 23 21:21:53 2002
@@ -1,111 +1,6 @@
 #ifndef _ASM_IA64_MODULE_H
 #define _ASM_IA64_MODULE_H
-/*
- * This file contains the ia64 architecture specific module code.
- *
- * Copyright (C) 2000 Intel Corporation.
- * Copyright (C) 2000 Mike Stephens <mike.stephens@intel.com>
- */
 
-#include <linux/module.h>
-#include <linux/vmalloc.h>
-#include <asm/unwind.h>
-
-#define module_map(x)		vmalloc(x)
-#define module_unmap(x)		ia64_module_unmap(x)
-#define module_arch_init(x)	ia64_module_init(x)
-
-/*
- * This must match in size and layout the data created by
- * modutils/obj/obj-ia64.c
- */
-struct archdata {
-	const char *unw_table;
-	const char *segment_base;
-	const char *unw_start;
-	const char *unw_end;
-	const char *gp;
-};
-
-static inline void
-arch_init_modules (struct module *kmod)
-{
-	static struct archdata archdata;
-	register char *kernel_gp asm ("gp");
-
-	archdata.gp = kernel_gp;
-	kmod->archdata_start = (const char *) &archdata;
-	kmod->archdata_end   = (const char *) (&archdata + 1);
-}
-
-/*
- * functions to add/remove a modules unwind info when
- * it is loaded or unloaded.
- */
-static inline int
-ia64_module_init (struct module *mod)
-{
-	struct archdata *archdata;
-
-	if (!mod_member_present(mod, archdata_start) || !mod->archdata_start)
-		return 0;
-	archdata = (struct archdata *)(mod->archdata_start);
-
-	if (archdata->unw_start == 0)
-		return 0;
-
-	/*
-	 * Make sure the unwind pointers are sane.
-	 */
-
-	if (archdata->unw_table) {
-		printk(KERN_ERR "module_arch_init: archdata->unw_table must be zero.\n");
-		return 1;
-	}
-	if (!mod_bound(archdata->gp, 0, mod)) {
-		printk(KERN_ERR "module_arch_init: archdata->gp out of bounds.\n");
-		return 1;
-	}
-	if (!mod_bound(archdata->unw_start, 0, mod)) {
-		printk(KERN_ERR "module_arch_init: archdata->unw_start out of bounds.\n");
-		return 1;
-	}
-	if (!mod_bound(archdata->unw_end, 0, mod)) {
-		printk(KERN_ERR "module_arch_init: archdata->unw_end out of bounds.\n");
-		return 1;
-	}
-	if (!mod_bound(archdata->segment_base, 0, mod)) {
-		printk(KERN_ERR "module_arch_init: archdata->segment_base out of bounds.\n");
-		return 1;
-	}
-
-	/*
-	 * Pointers are reasonable, add the module unwind table
-	 */
-	archdata->unw_table = unw_add_unwind_table(mod->name,
-						   (unsigned long) archdata->segment_base,
-						   (unsigned long) archdata->gp,
-						   archdata->unw_start, archdata->unw_end);
-	return 0;
-}
-
-static inline void
-ia64_module_unmap (void * addr)
-{
-	struct module *mod = (struct module *) addr;
-	struct archdata *archdata;
-
-	/*
-	 * Before freeing the module memory remove the unwind table entry
-	 */
-	if (mod_member_present(mod, archdata_start) && mod->archdata_start) {
-		archdata = (struct archdata *)(mod->archdata_start);
-
-		if (archdata->unw_table != NULL)
-			unw_remove_unwind_table((void *) archdata->unw_table);
-	}
-
-	vfree(addr);
-}
+/* Module support currently broken (due to in-kernel module loader).  */
 
 #endif /* _ASM_IA64_MODULE_H */
diff -Nru a/include/asm-ia64/numa.h b/include/asm-ia64/numa.h
--- a/include/asm-ia64/numa.h	Mon Dec 23 21:21:53 2002
+++ b/include/asm-ia64/numa.h	Mon Dec 23 21:21:53 2002
@@ -62,6 +62,8 @@
 
 extern int paddr_to_nid(unsigned long paddr);
 
+#define local_nodeid (cpu_to_node_map[smp_processor_id()])
+
 #endif /* CONFIG_NUMA */
 
 #endif /* _ASM_IA64_NUMA_H */
diff -Nru a/include/asm-ia64/processor.h b/include/asm-ia64/processor.h
--- a/include/asm-ia64/processor.h	Mon Dec 23 21:21:53 2002
+++ b/include/asm-ia64/processor.h	Mon Dec 23 21:21:53 2002
@@ -17,7 +17,6 @@
 
 #include <asm/ptrace.h>
 #include <asm/kregs.h>
-#include <asm/system.h>
 #include <asm/types.h>
 
 #define IA64_NUM_DBG_REGS	8
@@ -79,12 +78,12 @@
 
 #include <linux/cache.h>
 #include <linux/compiler.h>
-#include <linux/percpu.h>
 #include <linux/threads.h>
 
 #include <asm/fpu.h>
 #include <asm/offsets.h>
 #include <asm/page.h>
+#include <asm/percpu.h>
 #include <asm/rse.h>
 #include <asm/unwind.h>
 #include <asm/atomic.h>
diff -Nru a/include/asm-ia64/sn/addrs.h b/include/asm-ia64/sn/addrs.h
--- a/include/asm-ia64/sn/addrs.h	Mon Dec 23 21:21:58 2002
+++ b/include/asm-ia64/sn/addrs.h	Mon Dec 23 21:21:58 2002
@@ -58,14 +58,14 @@
 #define NODE_OFFSET(_n)		(UINT64_CAST (_n) << NODE_SIZE_BITS)
 #endif
 
-#define NODE_CAC_BASE(_n)	(CAC_BASE   + NODE_OFFSET(_n))
+#define NODE_CAC_BASE(_n)	(CAC_BASE  + NODE_OFFSET(_n))
 #define NODE_HSPEC_BASE(_n)	(HSPEC_BASE + NODE_OFFSET(_n))
 #define NODE_IO_BASE(_n)	(IO_BASE    + NODE_OFFSET(_n))
 #define NODE_MSPEC_BASE(_n)	(MSPEC_BASE + NODE_OFFSET(_n))
 #define NODE_UNCAC_BASE(_n)	(UNCAC_BASE + NODE_OFFSET(_n))
 
 #define TO_NODE(_n, _x)		(NODE_OFFSET(_n)     | ((_x)		   ))
-#define TO_NODE_CAC(_n, _x)	(NODE_CAC_BASE(_n)   | ((_x) & TO_PHYS_MASK))
+#define TO_NODE_CAC(_n, _x)	(NODE_CAC_BASE(_n) | ((_x) & TO_PHYS_MASK))
 #define TO_NODE_UNCAC(_n, _x)	(NODE_UNCAC_BASE(_n) | ((_x) & TO_PHYS_MASK))
 #define TO_NODE_MSPEC(_n, _x)	(NODE_MSPEC_BASE(_n) | ((_x) & TO_PHYS_MASK))
 #define TO_NODE_HSPEC(_n, _x)	(NODE_HSPEC_BASE(_n) | ((_x) & TO_PHYS_MASK))
@@ -227,8 +227,8 @@
 
 #ifndef __ASSEMBLY__
 
-#define HUB_L(_a)			*(_a)
-#define	HUB_S(_a, _d)			*(_a) = (_d)
+#define HUB_L(_a)			(*((volatile typeof(*_a) *)_a))
+#define	HUB_S(_a, _d)			(*((volatile typeof(*_a) *)_a) = (_d))
 
 #define LOCAL_HUB_L(_r)			HUB_L(LOCAL_HUB_ADDR(_r))
 #define LOCAL_HUB_S(_r, _d)		HUB_S(LOCAL_HUB_ADDR(_r), (_d))
@@ -326,7 +326,7 @@
 #define GDA_SIZE(nasid)		KLD_GDA(nasid)->size
 
 #define NODE_OFFSET_TO_K0(_nasid, _off)					\
-	(PAGE_OFFSET | NODE_OFFSET(_nasid) | (_off))
+	(CACHEABLE_MEM_SPACE | NODE_OFFSET(_nasid) | (_off))
 
 #endif /* __ASSEMBLY__ */
 
diff -Nru a/include/asm-ia64/sn/alenlist.h b/include/asm-ia64/sn/alenlist.h
--- a/include/asm-ia64/sn/alenlist.h	Mon Dec 23 21:21:55 2002
+++ b/include/asm-ia64/sn/alenlist.h	Mon Dec 23 21:21:55 2002
@@ -15,7 +15,7 @@
 
 /*
  * An Address/Length List is used when setting up for an I/O DMA operation.
- * A driver creates an Address/Length List that describes to the DMA 
+ * A driver creates an Address/Length List that describes to the the DMA 
  * interface where in memory the DMA should go.  The bus interface sets up 
  * mapping registers, if required, and returns a suitable list of "physical 
  * addresses" or "I/O address" to the driver.  The driver then uses these 
diff -Nru a/include/asm-ia64/sn/arch.h b/include/asm-ia64/sn/arch.h
--- a/include/asm-ia64/sn/arch.h	Mon Dec 23 21:21:53 2002
+++ b/include/asm-ia64/sn/arch.h	Mon Dec 23 21:21:53 2002
@@ -33,6 +33,7 @@
 typedef u64	hubreg_t;
 typedef u64	mmr_t;
 typedef u64	nic_t;
+typedef char cnodeid_t;
 
 #define CNODE_TO_CPU_BASE(_cnode)	(NODEPDA(_cnode)->node_first_cpu)
 
@@ -43,6 +44,7 @@
 #define INVALID_NASID		((nasid_t)-1)
 #define INVALID_CNODEID		((cnodeid_t)-1)
 #define INVALID_PNODEID		((pnodeid_t)-1)
+#define INVALID_SLAB            (slabid_t)-1
 #define INVALID_MODULE		((moduleid_t)-1)
 #define	INVALID_PARTID		((partid_t)-1)
 
diff -Nru a/include/asm-ia64/sn/ate_utils.h b/include/asm-ia64/sn/ate_utils.h
--- a/include/asm-ia64/sn/ate_utils.h	Mon Dec 23 21:21:58 2002
+++ b/include/asm-ia64/sn/ate_utils.h	Mon Dec 23 21:21:58 2002
@@ -1,7 +1,7 @@
 #ifndef _ASM_IA64_SN_ATE_UTILS_H
 #define _ASM_IA64_SN_ATE_UTILS_H
 
-/* $Id$
+/* $Id: ate_utils.h,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
diff -Nru a/include/asm-ia64/sn/bte.h b/include/asm-ia64/sn/bte.h
--- a/include/asm-ia64/sn/bte.h	Mon Dec 23 21:21:55 2002
+++ b/include/asm-ia64/sn/bte.h	Mon Dec 23 21:21:55 2002
@@ -1,26 +1,52 @@
 /*
- * 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.
+ *
+ *
+ * Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
+ * 
+ * This program is free software; you can redistribute it and/or modify it 
+ * under the terms of version 2 of the GNU General Public License 
+ * as published by the Free Software Foundation.
+ * 
+ * This program is distributed in the hope that it would be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
+ * 
+ * Further, this software is distributed without any warranty that it is 
+ * free of the rightful claim of any third person regarding infringement 
+ * or the like.  Any license provided herein, whether implied or 
+ * otherwise, applies only to this software file.  Patent licenses, if 
+ * any, provided herein do not apply to combinations of this program with 
+ * other software, or any other product whatsoever.
+ * 
+ * You should have received a copy of the GNU General Public 
+ * License along with this program; if not, write the Free Software 
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ * 
+ * Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 
+ * Mountain View, CA  94043, or:
  * 
- * Copyright (c) 2001-2002 Silicon Graphics, Inc.  All rights reserved.
+ * http://www.sgi.com 
+ * 
+ * For further information regarding this notice, see: 
+ * 
+ * http://oss.sgi.com/projects/GenInfo/NoticeExplan
  */
 
+
 #ifndef _ASM_IA64_SN_BTE_H
 #define _ASM_IA64_SN_BTE_H
 
-#ident "$Revision: $"
+#ident "$Revision: 1.1 $"
 
 #include <linux/spinlock.h>
 #include <linux/cache.h>
 #include <asm/sn/io.h>
 
-#define L1_CACHE_MASK (L1_CACHE_BYTES - 1)	/* Mask to retrieve
-						 * the offset into this
-						 * cache line.*/
-
 /* BTE status register only supports 16 bits for length field */
-#define BTE_LEN_MASK ((1 << 16) - 1)
+#define BTE_LEN_BITS (16)
+#define BTE_LEN_MASK ((1 << BTE_LEN_BITS) - 1)
+#define BTE_MAX_XFER ((1 << BTE_LEN_BITS) * L1_CACHE_BYTES)
+
 
 /*
  * Constants used in determining the best and worst case transfer
@@ -68,13 +94,14 @@
 	u64 volatile notify ____cacheline_aligned;
 	char *bte_base_addr ____cacheline_aligned;
 	spinlock_t spinlock;
-	u64 idealTransferTimeout;
-	u64 idealTransferTimeoutReached;
-	u64 mostRecentSrc;
-	u64 mostRecentDest;
-	u64 mostRecentLen;
-	u64 mostRecentMode;
-	u64 volatile *mostRecentNotification;
+	u64 ideal_xfr_tmo;	/* Time out */
+	u64 ideal_xfr_tmo_cnt;
+	/* u64 most_recent_src;
+	 * u64 most_recent_dest;
+	 * u64 most_recent_len;
+	 * u64 most_recent_mode; */
+	u64 volatile *most_rcnt_na;
+	void *bte_test_buf;
 } bteinfo_t;
 
 /* Possible results from bte_copy and bte_unaligned_copy */
@@ -84,5 +111,7 @@
 	BTEFAIL_ERROR,		/* Generic error */
 	BTEFAIL_DIR		/* Diretory error */
 } bte_result_t;
+
+void bte_reset_nasid(nasid_t);
 
 #endif				/* _ASM_IA64_SN_BTE_H */
diff -Nru a/include/asm-ia64/sn/bte_copy.h b/include/asm-ia64/sn/bte_copy.h
--- a/include/asm-ia64/sn/bte_copy.h	Mon Dec 23 21:21:56 2002
+++ b/include/asm-ia64/sn/bte_copy.h	Mon Dec 23 21:21:56 2002
@@ -1,31 +1,79 @@
 /*
- * 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.
+ *
+ *
+ * Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
+ * 
+ * This program is free software; you can redistribute it and/or modify it 
+ * under the terms of version 2 of the GNU General Public License 
+ * as published by the Free Software Foundation.
+ * 
+ * This program is distributed in the hope that it would be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
+ * 
+ * Further, this software is distributed without any warranty that it is 
+ * free of the rightful claim of any third person regarding infringement 
+ * or the like.  Any license provided herein, whether implied or 
+ * otherwise, applies only to this software file.  Patent licenses, if 
+ * any, provided herein do not apply to combinations of this program with 
+ * other software, or any other product whatsoever.
  * 
- * Copyright (c) 2001-2002 Silicon Graphics, Inc.  All rights reserved.
+ * You should have received a copy of the GNU General Public 
+ * License along with this program; if not, write the Free Software 
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ * 
+ * Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 
+ * Mountain View, CA  94043, or:
+ * 
+ * http://www.sgi.com 
+ * 
+ * For further information regarding this notice, see: 
+ * 
+ * http://oss.sgi.com/projects/GenInfo/NoticeExplan
  */
 
 #ifndef _ASM_IA64_SN_BTE_COPY_H
 #define _ASM_IA64_SN_BTE_COPY_H
 
-#ident "$Revision: $"
+#ident "$Revision: 1.1 $"
 
+#include <linux/timer.h>
+#include <linux/cache.h>
 #include <asm/sn/bte.h>
 #include <asm/sn/sgi.h>
 #include <asm/sn/pda.h>
 #include <asm/delay.h>
 
+#define L1_CACHE_MASK (L1_CACHE_BYTES - 1)
+
 /*
- * BTE_LOCKING support - Undefining the following line will
- * adapt the bte_copy code to support one bte per cpu in
+ * BTE_LOCKING support - When CONFIG_IA64_SGI_BTE_LOCKING is
+ * not defined, the bte_copy code supports one bte per cpu in
  * synchronous mode.  Even if bte_copy is called with a
  * notify address, the bte will spin and wait for the transfer
  * to complete.  By defining the following, spin_locks and
  * busy checks are placed around the initiation of a BTE
  * transfer and multiple bte's per cpu are supported.
  */
+#if 0
 #define CONFIG_IA64_SGI_BTE_LOCKING 1
+#endif
+
+/*
+ * Handle locking of the bte interfaces.
+ *
+ * All transfers spinlock the interface before setting up the SHUB
+ * registers.  Sync transfers hold the lock until all processing is
+ * complete.  Async transfers release the lock as soon as the transfer
+ * is initiated.
+ *
+ * To determine if an interface is available, we must check both the
+ * busy bit and the spinlock for that interface.
+ */
+#define BTE_LOCK_IF_AVAIL(_x) (\
+	(*pda.cpu_bte_if[_x]->most_rcnt_na & IBLS_BUSY) && \
+	(!(spin_trylock(&(pda.cpu_bte_if[_x]->spinlock)))) \
+	)
 
 /*
  * Some macros to simplify reading.
@@ -33,39 +81,71 @@
  * Start with macros to locate the BTE control registers.
  */
 
-#define BTEREG_LNSTAT_ADDR (bte->bte_base_addr)
-#define BTEREG_SOURCE_ADDR (bte->bte_base_addr + IIO_IBSA0 - IIO_IBLS0)
-#define BTEREG_DEST_ADDR (bte->bte_base_addr + IIO_IBDA0 - IIO_IBLS0)
-#define BTEREG_CTRL_ADDR (bte->bte_base_addr + IIO_IBCT0 - IIO_IBLS0)
-#define BTEREG_NOTIF_ADDR (bte->bte_base_addr + IIO_IBNA0 - IIO_IBLS0)
+#define BTEREG_LNSTAT_ADDR ((u64 *)(bte->bte_base_addr))
+#define BTEREG_SRC_ADDR ((u64 *)(bte->bte_base_addr + BTEOFF_SRC))
+#define BTEREG_DEST_ADDR ((u64 *)(bte->bte_base_addr + BTEOFF_DEST))
+#define BTEREG_CTRL_ADDR ((u64 *)(bte->bte_base_addr + BTEOFF_CTRL))
+#define BTEREG_NOTIF_ADDR ((u64 *)(bte->bte_base_addr + BTEOFF_NOTIFY))
 
 /* Some macros to force the IBCT0 value valid. */
 
 #define BTE_VALID_MODES BTE_NOTIFY
 #define BTE_VLD_MODE(x) (x & BTE_VALID_MODES)
 
-// #define DEBUG_BTE
-// #define DEBUG_BTE_VERBOSE
-// #define DEBUG_TIME_BTE
-
-#ifdef DEBUG_BTE
-#  define DPRINTK(x) printk x	// Terse
-#  ifdef DEBUG_BTE_VERBOSE
-#    define DPRINTKV(x) printk x	// Verbose
+// #define BTE_DEBUG
+// #define BTE_DEBUG_VERBOSE
+// #define BTE_TIME
+
+#ifdef BTE_DEBUG
+#  define BTE_PRINTK(x) printk x	/* Terse */
+#  ifdef BTE_DEBUG_VERBOSE
+#    define BTE_PRINTKV(x) printk x	/* Verbose */
 #  else
-#    define DPRINTKV(x)
-#  endif
+#    define BTE_PRINTKV(x)
+#  endif /* BTE_DEBUG_VERBOSE */
 #else
-#  define DPRINTK(x)
-#  define DPRINTKV(x)
-#endif
-
-#ifdef DEBUG_TIME_BTE
-extern u64 BteSetupTime;
-extern u64 BteTransferTime;
-extern u64 BteTeardownTime;
-extern u64 BteExecuteTime;
-#endif
+#  define BTE_PRINTK(x)
+#  define BTE_PRINTKV(x)
+#endif /* BTE_DEBUG */
+
+#define BTE_IDEAL_TMO(x) (jiffies + \
+	(HZ / BTE_MAXT_LINES_PER_SECOND * x))
+
+#ifdef BTE_TIME
+volatile extern u64 bte_setup_time;
+volatile extern u64 bte_transfer_time;
+volatile extern u64 bte_tear_down_time;
+volatile extern u64 bte_execute_time;
+
+#define BTE_TIME_DECLARE() \
+	u64 btcp_strt_tm = 0; \
+	u64 btcp_cplt_tm = 0; \
+	u64 xfr_strt_tm = 0; \
+	u64 xfr_cplt_tm = 0; \
+
+#define BTE_TIME_START() \
+	btcp_strt_tm = xfr_strt_tm = xfr_cplt_tm = ia64_get_itc();
+
+#define BTE_TIME_XFR_START() \
+	xfr_strt_tm = ia64_get_itc();
+
+#define BTE_TIME_XFR_STOP() \
+	xfr_cplt_tm = ia64_get_itc();
+
+#define BTE_TIME_STOP() \
+	btcp_cplt_tm = ia64_get_itc(); \
+	bte_setup_time = xfr_strt_tm - btcp_strt_tm; \
+	bte_transfer_time = xfr_cplt_tm - xfr_strt_tm; \
+	bte_tear_down_time = btcp_cplt_tm - xfr_cplt_tm; \
+	bte_execute_time = btcp_cplt_tm - btcp_strt_tm; \
+
+#else /* BTE_TIME */
+#define BTE_TIME_DECLARE()
+#define BTE_TIME_START()
+#define BTE_TIME_XFR_START()
+#define BTE_TIME_XFR_STOP()
+#define BTE_TIME_STOP()
+#endif /* BTE_TIME */
 
 /*
  * bte_copy(src, dest, len, mode, notification)
@@ -91,25 +171,19 @@
 {
 #ifdef CONFIG_IA64_SGI_BTE_LOCKING
 	int bte_to_use;
-#endif
-
-#ifdef DEBUG_TIME_BTE
-	u64 invokeTime = 0;
-	u64 completeTime = 0;
-	u64 xferStartTime = 0;
-	u64 xferCompleteTime = 0;
-#endif
-	u64 transferSize;
+#endif /* CONFIG_IA64_SGI_BTE_LOCKING */
+	u64 transfer_size;
+	u64 lines_remaining;
 	bteinfo_t *bte;
+	BTE_TIME_DECLARE();
 
-#ifdef DEBUG_TIME_BTE
-	invokeTime = ia64_get_itc();
-#endif
+	BTE_TIME_START();
 
-	DPRINTK(("bte_copy (0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx)\n",
-		 src, dest, len, mode, notification));
+	BTE_PRINTK(("bte_copy (0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx)\n",
+		    src, dest, len, mode, notification));
 
 	if (len == 0) {
+		BTE_TIME_STOP();
 		return (BTE_SUCCESS);
 	}
 
@@ -123,17 +197,15 @@
 		bte_to_use = 0;
 
 		/* Attempt to lock one of the BTE interfaces */
-		while ((*pda.cpubte[bte_to_use]->
-			mostRecentNotification & IBLS_BUSY)
-		       &&
-		       (!(spin_trylock
-			  (&(pda.cpubte[bte_to_use]->spinlock))))
-		       && (bte_to_use < BTES_PER_NODE)) {
+		while ((bte_to_use < BTES_PER_NODE) &&
+		       BTE_LOCK_IF_AVAIL(bte_to_use)) {
+
 			bte_to_use++;
 		}
 
 		if ((bte_to_use >= BTES_PER_NODE) &&
 		    !(mode & BTE_WACQUIRE)) {
+			BTE_TIME_STOP();
 			return (BTEFAIL_NOTAVAIL);
 		}
 
@@ -141,12 +213,12 @@
 	}
 	while (bte_to_use >= BTES_PER_NODE);
 
-	bte = pda.cpubte[bte_to_use];
-	DPRINTKV(("Got a lock on bte %d\n", bte_to_use));
+	bte = pda.cpu_bte_if[bte_to_use];
+	BTE_PRINTKV(("Got a lock on bte %d\n", bte_to_use));
 #else
 	/* Assuming one BTE per CPU. */
-	bte = pda.cpubte[0];
-#endif
+	bte = pda->cpu_bte_if[0];
+#endif /* CONFIG_IA64_SGI_BTE_LOCKING */
 
 	/*
 	 * The following are removed for optimization but is
@@ -160,65 +232,51 @@
 	 */
 	if (notification == NULL) {
 		/* User does not want to be notified. */
-		bte->mostRecentNotification = &bte->notify;
+		bte->most_rcnt_na = &bte->notify;
 	} else {
-		bte->mostRecentNotification = notification;
+		bte->most_rcnt_na = notification;
 	}
 
 	/* Calculate the number of cache lines to transfer. */
-	transferSize = ((len >> L1_CACHE_SHIFT) & BTE_LEN_MASK);
+	transfer_size = ((len >> L1_CACHE_SHIFT) & BTE_LEN_MASK);
 
-	DPRINTKV(("Calculated transfer size of %d cache lines\n",
-		  transferSize));
+	BTE_PRINTKV(("Calculated transfer size of %d cache lines\n",
+		     transfer_size));
 
 	/* Initialize the notification to a known value. */
-	*bte->mostRecentNotification = -1L;
+	*bte->most_rcnt_na = -1L;
 
 
-	DPRINTKV(("Before, status is 0x%lx and notify is 0x%lx\n",
-		  HUB_L(BTEREG_LNSTAT_ADDR),
-		  *bte->mostRecentNotification));
+	BTE_PRINTKV(("Before, status is 0x%lx and notify is 0x%lx\n",
+		     HUB_L(BTEREG_LNSTAT_ADDR),
+		     *bte->most_rcnt_na));
 
 	/* Set the status reg busy bit and transfer length */
-	DPRINTKV(("IBLS - HUB_S(0x%lx, 0x%lx)\n",
-		  BTEREG_LNSTAT_ADDR, IBLS_BUSY | transferSize));
-	HUB_S(BTEREG_LNSTAT_ADDR, IBLS_BUSY | transferSize);
-
-
-	DPRINTKV(("After setting status, status is 0x%lx and notify is 0x%lx\n", HUB_L(BTEREG_LNSTAT_ADDR), *bte->mostRecentNotification));
+	BTE_PRINTKV(("IBLS - HUB_S(0x%lx, 0x%lx)\n",
+		     BTEREG_LNSTAT_ADDR, IBLS_BUSY | transfer_size));
+	HUB_S(BTEREG_LNSTAT_ADDR, (IBLS_BUSY | transfer_size));
 
 	/* Set the source and destination registers */
-	DPRINTKV(("IBSA - HUB_S(0x%lx, 0x%lx)\n", BTEREG_SOURCE_ADDR,
-		  src));
-	HUB_S(BTEREG_SOURCE_ADDR, src);
-	DPRINTKV(("IBDA - HUB_S(0x%lx, 0x%lx)\n", BTEREG_DEST_ADDR, dest));
-	HUB_S(BTEREG_DEST_ADDR, dest);
-
+	BTE_PRINTKV(("IBSA - HUB_S(0x%lx, 0x%lx)\n", BTEREG_SRC_ADDR,
+		     (TO_PHYS(src))));
+	HUB_S(BTEREG_SRC_ADDR, (TO_PHYS(src)));
+	BTE_PRINTKV(("IBDA - HUB_S(0x%lx, 0x%lx)\n", BTEREG_DEST_ADDR,
+		     (TO_PHYS(dest))));
+	HUB_S(BTEREG_DEST_ADDR, (TO_PHYS(dest)));
 
 	/* Set the notification register */
-	DPRINTKV(("IBNA - HUB_S(0x%lx, 0x%lx)\n", BTEREG_NOTIF_ADDR,
-		  __pa(bte->mostRecentNotification)));
-	HUB_S(BTEREG_NOTIF_ADDR, (__pa(bte->mostRecentNotification)));
-
-
-	DPRINTKV(("Set Notify, status is 0x%lx and notify is 0x%lx\n",
-		  HUB_L(BTEREG_LNSTAT_ADDR),
-		  *bte->mostRecentNotification));
+	BTE_PRINTKV(("IBNA - HUB_S(0x%lx, 0x%lx)\n", BTEREG_NOTIF_ADDR,
+		     (TO_PHYS(__pa(bte->most_rcnt_na)))));
+	HUB_S(BTEREG_NOTIF_ADDR, (TO_PHYS(__pa(bte->most_rcnt_na))));
 
 	/* Initiate the transfer */
-	DPRINTKV(("IBCT - HUB_S(0x%lx, 0x%lx)\n", BTEREG_CTRL_ADDR, mode));
-#ifdef DEBUG_TIME_BTE
-	xferStartTime = ia64_get_itc();
-#endif
+	BTE_PRINTKV(("IBCT - HUB_S(0x%lx, 0x%lx)\n", BTEREG_CTRL_ADDR, mode));
+	BTE_TIME_XFR_START();
 	HUB_S(BTEREG_CTRL_ADDR, BTE_VLD_MODE(mode));
 
-	DPRINTKV(("Initiated, status is 0x%lx and notify is 0x%lx\n",
-		  HUB_L(BTEREG_LNSTAT_ADDR),
-		  *bte->mostRecentNotification));
-
-	// >>> Temporarily work around not getting a notification
-	// from medusa.
-	// *bte->mostRecentNotification = HUB_L(bte->bte_base_addr);
+	BTE_PRINTKV(("Initiated, status is 0x%lx and notify is 0x%lx\n",
+		     HUB_L(BTEREG_LNSTAT_ADDR),
+		     *bte->most_rcnt_na));
 
 	if (notification == NULL) {
 		/*
@@ -240,56 +298,75 @@
 		 * delay from hardware completing our request and
 		 * our detecting the failure.
 		 */
-		bte->idealTransferTimeout = jiffies +
-		    (HZ / BTE_MAXT_LINES_PER_SECOND * transferSize);
+		bte->ideal_xfr_tmo = BTE_IDEAL_TMO(transfer_size);
 
-		while ((IBLS_BUSY & bte->notify)) {
+		while (bte->notify == -1UL) {
 			/*
 			 * Notification Workaround: When the max
 			 * theoretical time has elapsed, read the hub
 			 * status register into the notification area.
 			 * This fakes the shub performing the copy.
 			 */
-			if (time_after(jiffies, bte->idealTransferTimeout)) {
-				bte->notify = HUB_L(bte->bte_base_addr);
-				bte->idealTransferTimeoutReached++;
-				bte->idealTransferTimeout = jiffies +
-				    (HZ / BTE_MAXT_LINES_PER_SECOND *
-				     (bte->notify & BTE_LEN_MASK));
+			BTE_PRINTKV(("  Timing.  IBLS = 0x%lx, "
+				     "notify= 0x%lx\n",
+				     HUB_L(BTEREG_LNSTAT_ADDR),
+				     bte->notify));
+			if (time_after(jiffies, bte->ideal_xfr_tmo)) {
+				lines_remaining = HUB_L(BTEREG_LNSTAT_ADDR) &
+					BTE_LEN_MASK;
+				bte->ideal_xfr_tmo_cnt++;
+				bte->ideal_xfr_tmo =
+					BTE_IDEAL_TMO(lines_remaining);
+
+				BTE_PRINTKV(("  Timeout.  cpu %d "
+					     "IBLS = 0x%lx, "
+					     "notify= 0x%lx, "
+					     "Lines remaining = %d. "
+					     "New timeout = %d.\n",
+					     smp_processor_id(),
+					     HUB_L(BTEREG_LNSTAT_ADDR),
+					     bte->notify,
+					     lines_remaining,
+					     bte->ideal_xfr_tmo));
 			}
 		}
-#ifdef DEBUG_TIME_BTE
-		xferCompleteTime = ia64_get_itc();
-#endif
+		BTE_PRINTKV((" Delay Done.  IBLS = 0x%lx, notify= 0x%lx\n",
+			     HUB_L(BTEREG_LNSTAT_ADDR),
+			  bte->notify));
+		BTE_TIME_XFR_STOP();
 		if (bte->notify & IBLS_ERROR) {
 			/* >>> Need to do real error checking. */
-			transferSize = 0;
+			transfer_size = 0;
 
 #ifdef CONFIG_IA64_SGI_BTE_LOCKING
 			spin_unlock(&(bte->spinlock));
-#endif
+#endif /* CONFIG_IA64_SGI_BTE_LOCKING */
+			BTE_PRINTKV(("Erroring status is 0x%lx and "
+				     "notify is 0x%lx\n",
+				     HUB_L(BTEREG_LNSTAT_ADDR),
+				     bte->notify));
+
+			BTE_TIME_STOP();
+			bte->notify = 0L;
 			return (BTEFAIL_ERROR);
 		}
 
 	}
 #ifdef CONFIG_IA64_SGI_BTE_LOCKING
 	spin_unlock(&(bte->spinlock));
-#endif
-#ifdef DEBUG_TIME_BTE
-	completeTime = ia64_get_itc();
+#endif /* CONFIG_IA64_SGI_BTE_LOCKING */
+	BTE_TIME_STOP();
+	BTE_PRINTKV(("Returning status is 0x%lx and notify is 0x%lx\n",
+		     HUB_L(BTEREG_LNSTAT_ADDR),
+		     *bte->most_rcnt_na));
 
-	BteSetupTime = xferStartTime - invokeTime;
-	BteTransferTime = xferCompleteTime - xferStartTime;
-	BteTeardownTime = completeTime - xferCompleteTime;
-	BteExecuteTime = completeTime - invokeTime;
-#endif
 	return (BTE_SUCCESS);
 }
 
 /*
  * Define the bte_unaligned_copy as an extern.
  */
-extern bte_result_t bte_unaligned_copy(u64, u64, u64, u64, char *);
+extern bte_result_t bte_unaligned_copy(u64, u64, u64, u64);
 
 /*
  * The following is the prefered way of calling bte_unaligned_copy
@@ -299,13 +376,10 @@
  * until the transfer is complete.  In order to get the asynch
  * version of bte_copy, you must perform this check yourself.
  */
-#define BTE_UNALIGNED_COPY(src, dest, len, mode, bteBlock) \
-	if ((len & L1_CACHE_MASK) || \
-	    (src & L1_CACHE_MASK) || \
-	    (dest & L1_CACHE_MASK)) { \
-		bte_unaligned_copy (src, dest, len, mode, bteBlock); \
-	} else { \
-		bte_copy(src, dest, len, mode, NULL); \
-	}
+#define BTE_UNALIGNED_COPY(src, dest, len, mode)			\
+	(((len & L1_CACHE_MASK) || (src & L1_CACHE_MASK) ||		\
+	  (dest & L1_CACHE_MASK)) ?					\
+		bte_unaligned_copy(src, dest, len, mode) :		\
+		bte_copy(src, dest, len, mode, NULL))
 
-#endif				/* _ASM_IA64_SN_BTE_COPY_H */
+#endif /* _ASM_IA64_SN_BTE_COPY_H */
diff -Nru a/include/asm-ia64/sn/clksupport.h b/include/asm-ia64/sn/clksupport.h
--- a/include/asm-ia64/sn/clksupport.h	Mon Dec 23 21:21:58 2002
+++ b/include/asm-ia64/sn/clksupport.h	Mon Dec 23 21:21:58 2002
@@ -29,22 +29,30 @@
 #include <asm/sn/addrs.h>
 
 typedef long clkreg_t;
-extern long sn_rtc_cycles_per_second;
+extern unsigned long sn_rtc_cycles_per_second;
 
 
 #if defined(CONFIG_IA64_SGI_SN1)
 #include <asm/sn/sn1/bedrock.h>
 #include <asm/sn/sn1/hubpi_next.h>
+
+extern nasid_t master_nasid;
+
+#define RTC_MASK		(0x007fffffffffffff)
 /* clocks are not synchronized yet on SN1  - used node 0 (problem if no NASID 0) */
-#define RTC_COUNTER_ADDR	((clkreg_t*)REMOTE_HUB_ADDR(0, PI_RT_COUNTER))
-#define RTC_COMPARE_A_ADDR      ((clkreg_t*)REMOTE_HUB_ADDR(0, PI_RT_COMPARE_A))
-#define RTC_COMPARE_B_ADDR      ((clkreg_t*)REMOTE_HUB_ADDR(0, PI_RT_COMPARE_B))
-#define RTC_INT_PENDING_A_ADDR  ((clkreg_t*)REMOTE_HUB_ADDR(0, PI_RT_INT_PEND_A))
-#define RTC_INT_PENDING_B_ADDR  ((clkreg_t*)REMOTE_HUB_ADDR(0, PI_RT_INT_PEND_B))
-#define RTC_INT_ENABLED_A_ADDR  ((clkreg_t*)REMOTE_HUB_ADDR(0, PI_RT_INT_EN_A))
-#define RTC_INT_ENABLED_B_ADDR  ((clkreg_t*)REMOTE_HUB_ADDR(0, PI_RT_INT_EN_B))
-#else
+#define RTC_COUNTER_ADDR	((clkreg_t*)REMOTE_HUB_ADDR(master_nasid, PI_RT_COUNTER))
+#define RTC_COMPARE_A_ADDR      ((clkreg_t*)REMOTE_HUB_ADDR(master_nasid, PI_RT_COMPARE_A))
+#define RTC_COMPARE_B_ADDR      ((clkreg_t*)REMOTE_HUB_ADDR(master_nasid, PI_RT_COMPARE_B))
+#define RTC_INT_PENDING_A_ADDR  ((clkreg_t*)REMOTE_HUB_ADDR(master_nasid, PI_RT_INT_PEND_A))
+#define RTC_INT_PENDING_B_ADDR  ((clkreg_t*)REMOTE_HUB_ADDR(master_nasid, PI_RT_INT_PEND_B))
+#define RTC_INT_ENABLED_A_ADDR  ((clkreg_t*)REMOTE_HUB_ADDR(master_nasid, PI_RT_INT_EN_A))
+#define RTC_INT_ENABLED_B_ADDR  ((clkreg_t*)REMOTE_HUB_ADDR(master_nasid, PI_RT_INT_EN_B))
+#else	/* !CONFIG_IA64_SGI_SN1 */
+#include <asm/sn/addrs.h>
+#include <asm/sn/sn2/addrs.h>
+#include <asm/sn/sn2/shubio.h>
 #include <asm/sn/sn2/shub_mmr.h>
+#define RTC_MASK		(SH_RTC_MASK)
 #define RTC_COUNTER_ADDR	((clkreg_t*)LOCAL_MMR_ADDR(SH_RTC))
 #define RTC_COMPARE_A_ADDR      ((clkreg_t*)LOCAL_MMR_ADDR(SH_RTC))
 #define RTC_COMPARE_B_ADDR      ((clkreg_t*)LOCAL_MMR_ADDR(SH_RTC))
@@ -52,7 +60,7 @@
 #define RTC_INT_PENDING_B_ADDR  ((clkreg_t*)LOCAL_MMR_ADDR(SH_RTC))
 #define RTC_INT_ENABLED_A_ADDR  ((clkreg_t*)LOCAL_MMR_ADDR(SH_RTC))
 #define RTC_INT_ENABLED_B_ADDR  ((clkreg_t*)LOCAL_MMR_ADDR(SH_RTC))
-#endif
+#endif	/* CONFIG_IA64_SGI_SN1 */
 
 
 #define GET_RTC_COUNTER()	(*RTC_COUNTER_ADDR)
diff -Nru a/include/asm-ia64/sn/eeprom.h b/include/asm-ia64/sn/eeprom.h
--- a/include/asm-ia64/sn/eeprom.h	Mon Dec 23 21:21:55 2002
+++ b/include/asm-ia64/sn/eeprom.h	Mon Dec 23 21:21:55 2002
@@ -11,6 +11,7 @@
 #ifndef _ASM_IA64_SN_EEPROM_H
 #define _ASM_IA64_SN_EEPROM_H
 
+#include <linux/config.h>
 #include <asm/sn/sgi.h>
 #include <asm/sn/vector.h>
 #include <asm/sn/xtalk/xbow.h>
@@ -291,6 +292,8 @@
 /* functions & macros for obtaining "NIC-like" strings from EEPROMs
  */
 
+#ifdef CONFIG_IA64_SGI_SN1
+
 int eeprom_str( char *nic_str, nasid_t nasid, int component );
 int vector_eeprom_str( char *nic_str, nasid_t nasid,
 		       int component, net_vec_t path );
@@ -300,6 +303,7 @@
 #define RBRICK_EEPROM_STR(s,n,p)  vector_eeprom_str((s),(n),R_BRICK,p)
 #define VECTOR_EEPROM_STR(s,n,p)  vector_eeprom_str((s),(n),VECTOR,p)
 
+#endif	/* CONFIG_IA64_SGI_SN1 */
 
 
 /* functions for obtaining formatted records from EEPROMs
@@ -313,13 +317,6 @@
 			net_vec_t path, int component );
 
 
-/* functions providing unique id's for duplonet and i/o discovery
- */
-
-int cbrick_uid_get( nasid_t nasid, uint64_t *uid );
-int rbrick_uid_get( nasid_t nasid, net_vec_t path, uint64_t *uid );
-int iobrick_uid_get( nasid_t nasid, uint64_t *uid );
-
 
 /* retrieve the ethernet MAC address for an I-brick
  */
@@ -383,9 +380,5 @@
     ( IS_IOBRICK((r)) ? eeprom_vertex_info_set \
 		          ( IO_BRICK, NASID_GET((r)), (v), 0 ) \
 		      : nic_bridge_vertex_info((v), (r)) )
-
-#define HUB_UID_GET(n,v,p)	cbrick_uid_get((n),(p))
-#define ROUTER_UID_GET(d,p)	rbrick_uid_get(get_nasid(),(d),(p))
-#define XBOW_UID_GET(n,p)	iobrick_uid_get((n),(p))
 
 #endif /* _ASM_IA64_SN_EEPROM_H */
diff -Nru a/include/asm-ia64/sn/fetchop.h b/include/asm-ia64/sn/fetchop.h
--- a/include/asm-ia64/sn/fetchop.h	Mon Dec 23 21:21:57 2002
+++ b/include/asm-ia64/sn/fetchop.h	Mon Dec 23 21:21:57 2002
@@ -7,10 +7,11 @@
  * Copyright (c) 2001-2002 Silicon Graphics, Inc.  All rights reserved.
  */
 
-
 #ifndef _ASM_IA64_SN_FETCHOP_H
 #define _ASM_IA64_SN_FETCHOP_H
 
+#include <linux/config.h>
+
 #define FETCHOP_BASENAME	"sgi_fetchop"
 #define FETCHOP_FULLNAME	"/dev/sgi_fetchop"
 
@@ -30,11 +31,71 @@
 #define FETCHOP_CLEAR_CACHE	56
 
 #define FETCHOP_LOAD_OP(addr, op) ( \
-         *(long *)((char*) (addr) + (op)))
+         *(volatile long *)((char*) (addr) + (op)))
 
 #define FETCHOP_STORE_OP(addr, op, x) ( \
-         *(long *)((char*) (addr) + (op)) = \
-              (long) (x))
+         *(volatile long *)((char*) (addr) + (op)) = (long) (x))
+
+#ifdef __KERNEL__
+
+/*
+ * Initialize a FETCHOP line. The argument should point to the beginning
+ * of the line.
+ * 	SN1 - region mask is in word 0, data in word 1
+ * 	SN2 - no region mask. Data in word 0
+ */
+#ifdef CONFIG_IA64_SGI_SN1
+#define FETCHOP_INIT_LINE(p)	*(p) = 0xffffffffffffffffUL
+#elif CONFIG_IA64_SGI_SN2
+#define FETCHOP_INIT_LINE(p)
+#endif
+
+/*
+ * Convert a region 7 (kaddr) address to the address of the fetchop variable
+ */
+#define FETCHOP_KADDR_TO_MSPEC_ADDR(kaddr)	TO_MSPEC(kaddr)
+
+/*
+ * Convert a page struct (page) address to the address of the first
+ * fetchop variable in the page
+ */
+#define FETCHOP_PAGE_TO_MSPEC_ADDR(page)	FETCHOP_KADDR_TO_MSPEC_ADDR(__pa(page_address(page)))
+
+
+/*
+ * Each Atomic Memory Operation (AMO formerly known as fetchop)
+ * variable is 64 bytes long.  The first 8 bytes are used.  The
+ * remaining 56 bytes are unaddressable due to the operation taking
+ * that portion of the address.
+ * 
+ * NOTE: The AMO_t _MUST_ be placed in either the first or second half
+ * of the cache line.  The cache line _MUST NOT_ be used for anything
+ * other than additional AMO_t entries.  This is because there are two
+ * addresses which reference the same physical cache line.  One will
+ * be a cached entry with the memory type bits all set.  This address
+ * may be loaded into processor cache.  The AMO_t will be referenced
+ * uncached via the memory special memory type.  If any portion of the
+ * cached cache-line is modified, when that line is flushed, it will
+ * overwrite the uncached value in physical memory and lead to
+ * inconsistency.
+ */
+typedef struct {
+
+#ifdef CONFIG_IA64_SGI_SN1
+	u64 permissions;
+#endif
+        u64 variable;
+
+#ifdef CONFIG_IA64_SGI_SN1
+        u64 unused[6];
+#else
+        u64 unused[7];
+#endif
+
+} AMO_t;
+
+
+#endif /* __KERNEL__ */
 
 #endif /* _ASM_IA64_SN_FETCHOP_H */
 
diff -Nru a/include/asm-ia64/sn/hack.h b/include/asm-ia64/sn/hack.h
--- a/include/asm-ia64/sn/hack.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-ia64/sn/hack.h	Mon Dec 23 21:21:51 2002
@@ -11,6 +11,8 @@
 #ifndef _ASM_IA64_SN_HACK_H
 #define _ASM_IA64_SN_HACK_H
 
+#include <linux/mmzone.h>
+#include <asm/sn/arch.h>
 #include <asm/sn/types.h>
 #include <asm/uaccess.h>		/* for copy_??_user */
 
@@ -22,9 +24,6 @@
 struct cred { int x; };
 
 
-#define mrlock(_s, _t, _u)
-#define mrunlock(_s)
-
 /*
  * Hardware Graph routines that are currently stubbed!
  */
@@ -60,9 +59,9 @@
 extern void * snia_kmem_alloc_node(register size_t, register int, cnodeid_t);
 extern void * snia_kmem_zalloc(size_t, int);
 extern void * snia_kmem_zalloc_node(register size_t, register int, cnodeid_t );
-extern void * snia_kmem_zone_alloc(register zone_t *, int);
-extern zone_t * snia_kmem_zone_init(register int , char *);
-extern void snia_kmem_zone_free(register zone_t *, void *);
+extern void * snia_kmem_zone_alloc(register struct zone *, int);
+extern struct zone * snia_kmem_zone_init(register int , char *);
+extern void snia_kmem_zone_free(register struct zone *, void *);
 extern int is_specified(char *);
 extern int cap_able(uint64_t);
 extern int compare_and_swap_ptr(void **, void *, void *);
diff -Nru a/include/asm-ia64/sn/idle.h b/include/asm-ia64/sn/idle.h
--- a/include/asm-ia64/sn/idle.h	Mon Dec 23 21:21:55 2002
+++ b/include/asm-ia64/sn/idle.h	Mon Dec 23 21:21:55 2002
@@ -15,13 +15,13 @@
 
 static __inline__ void
 snidle(void) {
-
+#if 0
 #ifdef CONFIG_IA64_SGI_AUTOTEST
 	{
 		extern int	autotest_enabled;
 		if (autotest_enabled) {
-			extern void llsc_main(int, long, long);
-			llsc_main(smp_processor_id(), 0xe000000000000000LL, 0xe000000001000000LL);
+			extern void llsc_main(int);
+			llsc_main(smp_processor_id());
 		}
 	}
 #endif
@@ -39,16 +39,19 @@
 #endif
 
 	pda.idle_flag = 1;
+#endif
 }
 
 static __inline__ void
 snidleoff(void) {
+#if 0
 	/* 
 	 * Turn the activity LED on.
 	 */
 	set_led_bits(LED_CPU_ACTIVITY, LED_CPU_ACTIVITY);
 
 	pda.idle_flag = 0;
+#endif
 }
 
 #endif /* _ASM_IA64_SN_IDLE_H */
diff -Nru a/include/asm-ia64/sn/intr.h b/include/asm-ia64/sn/intr.h
--- a/include/asm-ia64/sn/intr.h	Mon Dec 23 21:21:52 2002
+++ b/include/asm-ia64/sn/intr.h	Mon Dec 23 21:21:52 2002
@@ -4,7 +4,7 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (C) 1992 - 1997, 2000-2001 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 1992 - 1997, 2000-2002 Silicon Graphics, Inc. All rights reserved.
  */
 #ifndef _ASM_IA64_SN_INTR_H
 #define _ASM_IA64_SN_INTR_H
@@ -16,5 +16,9 @@
 #elif defined(CONFIG_IA64_SGI_SN2)
 #include <asm/sn/sn2/intr.h>
 #endif
+
+extern void sn_send_IPI_phys(long, int, int);
+
+#define CPU_VECTOR_TO_IRQ(cpuid,vector) ((cpuid) << 8 | (vector))
 
 #endif /* _ASM_IA64_SN_INTR_H */
diff -Nru a/include/asm-ia64/sn/ioerror.h b/include/asm-ia64/sn/ioerror.h
--- a/include/asm-ia64/sn/ioerror.h	Mon Dec 23 21:21:52 2002
+++ b/include/asm-ia64/sn/ioerror.h	Mon Dec 23 21:21:52 2002
@@ -121,7 +121,7 @@
  */
 
 typedef struct io_error_s {
-    /* Bit fields indicating which sturcture fields are valid */
+    /* Bit fields indicating which structure fields are valid */
     union {
 	struct {
 	    unsigned                ievb_errortype:1;
@@ -138,6 +138,7 @@
 	    unsigned                ievb_memaddr:1;
 	    unsigned		    ievb_epc:1;
 	    unsigned		    ievb_ef:1;
+	    unsigned		    ievb_tnum:1;
 	} iev_b;
 	unsigned                iev_a;
     } ie_v;
@@ -156,13 +157,14 @@
     paddr_t                 ie_memaddr;		/* Physical memory address       */
     caddr_t		    ie_epc;		/* pc when error reported	 */
     caddr_t		    ie_ef;		/* eframe when error reported	 */
-
+    short		    ie_tnum;		/* Xtalk TNUM field */
 } ioerror_t;
 
 #define	IOERROR_INIT(e)		do { (e)->ie_v.iev_a = 0; } while (0)
 #define	IOERROR_SETVALUE(e,f,v)	do { (e)->ie_ ## f = (v); (e)->ie_v.iev_b.ievb_ ## f = 1; } while (0)
-#define	IOERROR_FIELDVALID(e,f)	(((e)->ie_v.iev_b.ievb_ ## f) != 0)
-#define	IOERROR_GETVALUE(e,f)	(ASSERT(IOERROR_FIELDVALID(e,f)),((e)->ie_ ## f))
+#define	IOERROR_FIELDVALID(e,f)	((unsigned long long)((e)->ie_v.iev_b.ievb_ ## f) != (unsigned long long) 0)
+#define	IOERROR_NOGETVALUE(e,f)	(ASSERT(IOERROR_FIELDVALID(e,f)), ((e)->ie_ ## f))
+#define	IOERROR_GETVALUE(p,e,f)	ASSERT(IOERROR_FIELDVALID(e,f)); p=((e)->ie_ ## f)
 
 /* hub code likes to call the SysAD address "hubaddr" ... */
 #define	ie_hubaddr	ie_sysioaddr
diff -Nru a/include/asm-ia64/sn/iograph.h b/include/asm-ia64/sn/iograph.h
--- a/include/asm-ia64/sn/iograph.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-ia64/sn/iograph.h	Mon Dec 23 21:21:51 2002
@@ -32,6 +32,7 @@
 #define EDGE_LBL_CONTROLLER		"controller"
 #define EDGE_LBL_CPU			"cpu"
 #define EDGE_LBL_CPUNUM			"cpunum"
+#define EDGE_LBL_DIRECT			"direct"
 #define EDGE_LBL_DISABLED		"disabled"
 #define EDGE_LBL_DISK			"disk"
 #define EDGE_LBL_DMA_ENGINE             "dma_engine"    /* Only available on
@@ -67,6 +68,7 @@
 #define EDGE_LBL_HPC			"hpc"
 #define EDGE_LBL_GFX			"gfx"
 #define EDGE_LBL_HUB			"hub"		/* For SN0 */
+#define EDGE_LBL_HW			"hw"
 #define EDGE_LBL_SYNERGY		"synergy"	/* For SNIA only */
 #define EDGE_LBL_IBUS			"ibus"		/* For EVEREST */
 #define EDGE_LBL_INTERCONNECT		"link"
@@ -74,6 +76,8 @@
 #define EDGE_LBL_IO4			"io4"		/* For EVEREST */
 #define EDGE_LBL_IOC3			"ioc3"
 #define EDGE_LBL_LUN                    "lun"
+#define EDGE_LBL_LINUX                  "linux"
+#define EDGE_LBL_LINUX_BUS              EDGE_LBL_LINUX "/busnum"
 #define EDGE_LBL_MACE                   "mace" 		/* O2 mace */
 #define EDGE_LBL_MACHDEP                "machdep"       /* Platform depedent devices */
 #define EDGE_LBL_MASTER			".master"
@@ -86,6 +90,9 @@
 #define EDGE_LBL_NVRAM			"nvram"
 #define EDGE_LBL_PARTITION		"partition"
 #define EDGE_LBL_PCI			"pci"
+#define EDGE_LBL_PCIX			"pci-x"
+#define EDGE_LBL_PCIX_0			EDGE_LBL_PCIX "/0"
+#define EDGE_LBL_PCIX_1			EDGE_LBL_PCIX "/1"
 #define EDGE_LBL_PORT			"port"
 #define EDGE_LBL_PROM			"prom"
 #define EDGE_LBL_RACK			"rack"
@@ -112,6 +119,7 @@
 #define EDGE_LBL_XPLINK			"xplink" 	/* Cross partition */
 #define	EDGE_LBL_XPLINK_NET		"net" 		/* XP network devs */
 #define	EDGE_LBL_XPLINK_RAW		"raw"		/* XP Raw devs */
+#define EDGE_LBL_SLAB			"slab"		/* Slab of a module */
 #define	EDGE_LBL_XPLINK_KERNEL		"kernel"	/* XP kernel devs */
 #define	EDGE_LBL_XPLINK_ADMIN		"admin"	   	/* Partition admin */
 #define	EDGE_LBL_KAIO			"kaio"	   	/* Kernel async i/o poll */
@@ -202,7 +210,7 @@
 
 #include <asm/sn/xtalk/xbow.h>	/* For get MAX_PORT_NUM */
 
-int io_brick_map_widget(char, int);
+int io_brick_map_widget(int, int);
 int io_path_map_widget(devfs_handle_t);
 
 /*
@@ -210,8 +218,7 @@
  */
 
 struct io_brick_map_s {
-    char                ibm_type;                  /* brick type, e.g. */
-                                                   /* 'I' for Ibrick   */
+    int                 ibm_type;                  /* brick type */
     int                 ibm_map_wid[MAX_PORT_NUM]; /* wid to int map */
 };
 
diff -Nru a/include/asm-ia64/sn/klclock.h b/include/asm-ia64/sn/klclock.h
--- a/include/asm-ia64/sn/klclock.h	Mon Dec 23 21:21:54 2002
+++ b/include/asm-ia64/sn/klclock.h	Mon Dec 23 21:21:54 2002
@@ -10,6 +10,7 @@
 #define _ASM_IA64_SN_KLCLOCK_H
 
 #include <asm/sn/ioc3.h>
+#include <asm/sn/ioc4.h>
 
 #define RTC_BASE_ADDR		(unsigned char *)(nvram_base)
 
diff -Nru a/include/asm-ia64/sn/klconfig.h b/include/asm-ia64/sn/klconfig.h
--- a/include/asm-ia64/sn/klconfig.h	Mon Dec 23 21:21:52 2002
+++ b/include/asm-ia64/sn/klconfig.h	Mon Dec 23 21:21:52 2002
@@ -55,6 +55,10 @@
 #include <asm/sn/sn2/shub_md.h>
 #endif
 
+#ifdef CONFIG_IA64_SGI_SN2
+#include <asm/sn/geo.h>
+#endif
+
 #define KLCFGINFO_MAGIC	0xbeedbabe
 
 typedef s32 klconf_off_t;
@@ -335,8 +339,8 @@
 
 #define KLCLASS_IOBRICK	0x70		/* IP35 iobrick */
 
-#define KLCLASS_MAX	7		/* Bump this if a new CLASS is added */
-#define KLTYPE_MAX	10		/* Bump this if a new CLASS is added */
+#define KLCLASS_MAX	8		/* Bump this if a new CLASS is added */
+#define KLTYPE_MAX	11		/* Bump this if a new CLASS is added */
 
 #define KLCLASS_UNKNOWN	0xf0
 
@@ -353,7 +357,7 @@
 #define KLTYPE_WEIRDCPU (KLCLASS_CPU | 0x0)
 #define KLTYPE_SNIA	(KLCLASS_CPU | 0x1)
 
-#define KLTYPE_WEIRDIO	(KLCLASS_IO  | 0x0)
+#define KLTYPE_WEIRDIO	(KLCLASS_IOBRICK  | 0x0)
 #define KLTYPE_BASEIO	(KLCLASS_IO  | 0x1) /* IOC3, SuperIO, Bridge, SCSI */
 #define KLTYPE_IO6	KLTYPE_BASEIO       /* Additional name */
 #define KLTYPE_4CHSCSI	(KLCLASS_IO  | 0x2)
@@ -433,7 +437,11 @@
  	unsigned char 	brd_flags;        /* Enabled, Disabled etc */
 	unsigned char 	brd_slot;         /* slot number */
 	unsigned short	brd_debugsw;      /* Debug switches */
+#ifdef CONFIG_IA64_SGI_SN2
+	geoid_t		brd_geoid;	  /* geo id */
+#else
 	moduleid_t	brd_module;       /* module to which it belongs */
+#endif
 	partid_t 	brd_partition;    /* Partition number */
         unsigned short 	brd_diagval;      /* diagnostic value */
         unsigned short 	brd_diagparm;     /* diagnostic parameter */
@@ -448,6 +456,9 @@
 	confidence_t	brd_confidence;	  /* confidence that the board is bad */
 	nasid_t		brd_owner;        /* who owns this board */
 	unsigned char 	brd_nic_flags;    /* To handle 8 more NICs */
+#ifdef CONFIG_IA64_SGI_SN2
+	char		pad[32];	  /* future expansion */
+#endif
 	char		brd_name[32];
 } lboard_t;
 
@@ -570,6 +581,10 @@
 #define KLSTRUCT_USB		34
 #define KLSTRUCT_USBKBD		35
 #define KLSTRUCT_USBMS		36
+#define KLSTRUCT_SCSI_CTLR	37
+#define KLSTRUCT_PEBRICK	38
+#define KLSTRUCT_GIGE           39
+#define KLSTRUCT_IDE		40
 
 /*
  * These are the indices of various components within a lboard structure.
@@ -611,6 +626,9 @@
 	nasid_t		port_nasid;
 	unsigned char	port_flag;
 	klconf_off_t	port_offset;
+#ifdef CONFIG_IA64_SGI_SN2
+	short		port_num;
+#endif
 } klport_t;
 
 typedef struct klcpu_s {                          /* CPU */
@@ -620,6 +638,9 @@
     	unsigned short 	cpu_speed;	/* Speed in MHZ */
     	unsigned short 	cpu_scachesz;	/* secondary cache size in MB */
     	unsigned short 	cpu_scachespeed;/* secondary cache speed in MHz */
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klcpu_t ;
 
 #define CPU_STRUCT_VERSION   2
@@ -627,16 +648,28 @@
 typedef struct klhub_s {			/* HUB */
 	klinfo_t 	hub_info;
 	uint 		hub_flags;		/* PCFG_HUB_xxx flags */
+#ifdef CONFIG_IA64_SGI_SN2
+#define MAX_NI_PORTS                    2
+	klport_t	hub_port[MAX_NI_PORTS + 1];/* hub is connected to this */
+#else
 	klport_t	hub_port;		/* hub is connected to this */
+#endif
 	nic_t		hub_box_nic;		/* nic of containing box */
 	klconf_off_t	hub_mfg_nic;		/* MFG NIC string */
 	u64		hub_speed;		/* Speed of hub in HZ */
+#ifdef CONFIG_IA64_SGI_SN2
+	moduleid_t	hub_io_module;		/* attached io module */
+	unsigned long	pad;
+#endif
 } klhub_t ;
 
 typedef struct klhub_uart_s {			/* HUB */
 	klinfo_t 	hubuart_info;
 	uint 		hubuart_flags;		/* PCFG_HUB_xxx flags */
 	nic_t		hubuart_box_nic;	/* nic of containing box */
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klhub_uart_t ;
 
 #define MEMORY_STRUCT_VERSION   2
@@ -647,6 +680,9 @@
 	short		membnk_dimm_select; /* bank to physical addr mapping*/
 	short		membnk_bnksz[MD_MEM_BANKS]; /* Memory bank sizes */
 	short		membnk_attr;
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klmembnk_t ;
 
 #define KLCONFIG_MEMBNK_SIZE(_info, _bank)	\
@@ -665,6 +701,9 @@
               char snum_str[MAX_SERIAL_NUM_SIZE];
               unsigned long long       snum_int;
       } snum;
+#ifdef CONFIG_IA64_SGI_SN2
+      unsigned long   pad;
+#endif
 } klmod_serial_num_t;
 
 /* Macros needed to access serial number structure in lboard_t.
@@ -682,6 +721,9 @@
     	klport_t	xbow_port_info[MAX_XBOW_LINKS] ; /* Module number */
         int		xbow_master_hub_link;
         /* type of brd connected+component struct ptr+flags */
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klxbow_t ;
 
 #define MAX_PCI_SLOTS 8
@@ -700,6 +742,9 @@
     	pci_t    	pci_specific  ;    /* PCI Board config info */
 	klpci_device_t	bri_devices[MAX_PCI_DEVS] ;	/* PCI IDs */
 	klconf_off_t	bri_mfg_nic ;
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klbri_t ;
 
 #define MAX_IOC3_TTY	2
@@ -713,6 +758,9 @@
 	klinfo_t	ioc3_enet ;
 	klconf_off_t	ioc3_enet_off ;
 	klconf_off_t	ioc3_kbd_off ;
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klioc3_t ;
 
 #define MAX_VME_SLOTS 8
@@ -721,12 +769,18 @@
 	klinfo_t 	vmeb_info ;
 	vmeb_t		vmeb_specific ;
     	klconf_off_t   	vmeb_brdinfo[MAX_VME_SLOTS]   ;    /* VME Board config info */
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klvmeb_t ;
 
 typedef struct klvmed_s {                          /* VME DEVICE - VME BOARD */
 	klinfo_t	vmed_info ;
 	vmed_t		vmed_specific ;
     	klconf_off_t   	vmed_brdinfo[MAX_VME_SLOTS]   ;    /* VME Board config info */
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klvmed_t ;
 
 #define ROUTER_VECTOR_VERS	2
@@ -739,6 +793,9 @@
     	klport_t 	rou_port[MAX_ROUTER_PORTS + 1] ; /* array index 1 to 6 */
 	klconf_off_t	rou_mfg_nic ;     /* MFG NIC string */
 	u64	rou_vector;	  /* vector from master node */
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long   pad;
+#endif
 } klrou_t ;
 
 /*
@@ -763,16 +820,25 @@
 	graphics_t	gfx_specific;
 	klconf_off_t    pad0;		/* for compatibility with older proms */
 	klconf_off_t    gfx_mfg_nic;
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klgfx_t;
 
 typedef struct klxthd_s {   
 	klinfo_t 	xthd_info ;
 	klconf_off_t	xthd_mfg_nic ;        /* MFG NIC string */
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klxthd_t ;
 
 typedef struct kltpu_s {                     /* TPU board */
 	klinfo_t 	tpu_info ;
 	klconf_off_t	tpu_mfg_nic ;        /* MFG NIC string */
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } kltpu_t ;
 
 typedef struct klgsn_s {                     /* GSN board */
@@ -789,36 +855,64 @@
  * that as the size to be klmalloced.
  */
 
-typedef struct klscsi_s {                          /* SCSI Controller */
+typedef struct klscsi_s {                          /* SCSI Bus */
 	klinfo_t 	scsi_info ;
     	scsi_t       	scsi_specific   ; 
 	unsigned char 	scsi_numdevs ;
 	klconf_off_t	scsi_devinfo[MAX_SCSI_DEVS] ; 
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klscsi_t ;
 
+typedef struct klscctl_s {                          /* SCSI Controller */
+	klinfo_t 	scsi_info ;
+	uint		type;
+	uint		scsi_buscnt;                        /* # busses this cntlr */
+	void		*scsi_bus[2];                       /* Pointer to 2 klscsi_t's */
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
+} klscctl_t ;
+
 typedef struct klscdev_s {                          /* SCSI device */
 	klinfo_t 	scdev_info ;
 	struct scsidisk_data *scdev_cfg ; /* driver fills up this */
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klscdev_t ;
 
 typedef struct klttydev_s {                          /* TTY device */
 	klinfo_t 	ttydev_info ;
 	struct terminal_data *ttydev_cfg ; /* driver fills up this */
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klttydev_t ;
 
 typedef struct klenetdev_s {                          /* ENET device */
 	klinfo_t 	enetdev_info ;
 	struct net_data *enetdev_cfg ; /* driver fills up this */
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klenetdev_t ;
 
 typedef struct klkbddev_s {                          /* KBD device */
 	klinfo_t 	kbddev_info ;
 	struct keyboard_data *kbddev_cfg ; /* driver fills up this */
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klkbddev_t ;
 
 typedef struct klmsdev_s {                          /* mouse device */
         klinfo_t        msdev_info ;
         void 		*msdev_cfg ; 
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klmsdev_t ;
 
 #define MAX_FDDI_DEVS 10 /* XXX Is this true */
@@ -827,11 +921,17 @@
 	klinfo_t 	fddi_info ;
     	fddi_t        	fddi_specific ;       
 	klconf_off_t	fddi_devinfo[MAX_FDDI_DEVS] ;
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klfddi_t ;
 
 typedef struct klmio_s {                          /* MIO */
 	klinfo_t 	mio_info ;
     	mio_t       	mio_specific   ; 
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klmio_t ;
 
 /*
@@ -842,6 +942,9 @@
 	klinfo_t	usb_info;	/* controller info */
 	void		*usb_bus;	/* handle to usb_bus_t */
 	uint64_t	usb_controller;	/* ptr to controller info */
+#ifdef CONFIG_IA64_SGI_SN2
+	unsigned long	pad;
+#endif
 } klusb_t ; 
 
 typedef union klcomp_s {
@@ -856,6 +959,7 @@
 	klrou_t		kc_rou;
 	klgfx_t		kc_gfx;
 	klscsi_t	kc_scsi;
+	klscctl_t	kc_scsi_ctl;
 	klscdev_t	kc_scsi_dev;
 	klfddi_t	kc_fddi;
 	klmio_t		kc_mio;
@@ -929,26 +1033,38 @@
 extern lboard_t *find_gfxpipe(int pipenum);
 extern void setup_gfxpipe_link(devfs_handle_t vhdl,int pipenum);
 extern lboard_t *find_lboard_class(lboard_t *start, unsigned char brd_class);
+#ifdef CONFIG_IA64_SGI_SN2
+extern lboard_t *find_lboard_module_class(lboard_t *start, geoid_t geoid,
+						unsigned char brd_class);
+#else
 extern lboard_t *find_lboard_module_class(lboard_t *start, moduleid_t mod,
                                                unsigned char brd_class);
+#endif
 extern lboard_t *find_nic_lboard(lboard_t *, nic_t);
 extern lboard_t *find_nic_type_lboard(nasid_t, unsigned char, nic_t);
+#ifdef CONFIG_IA64_SGI_SN2
+extern lboard_t *find_lboard_modslot(lboard_t *start, geoid_t geoid);
+extern lboard_t *find_lboard_module(lboard_t *start, geoid_t geoid);
+extern lboard_t *get_board_name(nasid_t nasid, geoid_t geoid, slotid_t slot, char *name);
+#else
 extern lboard_t *find_lboard_modslot(lboard_t *start, moduleid_t mod, slotid_t slot);
 extern lboard_t *find_lboard_module(lboard_t *start, moduleid_t mod);
 extern lboard_t *get_board_name(nasid_t nasid, moduleid_t mod, slotid_t slot, char *name);
+#endif
 extern int	config_find_nic_router(nasid_t, nic_t, lboard_t **, klrou_t**);
 extern int	config_find_nic_hub(nasid_t, nic_t, lboard_t **, klhub_t**);
 extern int	config_find_xbow(nasid_t, lboard_t **, klxbow_t**);
 extern int 	update_klcfg_cpuinfo(nasid_t, int);
 extern void 	board_to_path(lboard_t *brd, char *path);
+#ifdef CONFIG_IA64_SGI_SN2
 extern moduleid_t get_module_id(nasid_t nasid);
+#endif
 extern void 	nic_name_convert(char *old_name, char *new_name);
 extern int 	module_brds(nasid_t nasid, lboard_t **module_brds, int n);
 extern lboard_t *brd_from_key(uint64_t key);
 extern void 	device_component_canonical_name_get(lboard_t *,klinfo_t *,
 						    char *);
 extern int	board_serial_number_get(lboard_t *,char *);
-extern int	is_master_baseio(nasid_t,moduleid_t,slotid_t);
 extern nasid_t	get_actual_nasid(lboard_t *brd) ;
 extern net_vec_t klcfg_discover_route(lboard_t *, lboard_t *, int);
 
diff -Nru a/include/asm-ia64/sn/ksys/elsc.h b/include/asm-ia64/sn/ksys/elsc.h
--- a/include/asm-ia64/sn/ksys/elsc.h	Mon Dec 23 21:21:59 2002
+++ b/include/asm-ia64/sn/ksys/elsc.h	Mon Dec 23 21:21:59 2002
@@ -9,8 +9,11 @@
 #ifndef _ASM_SN_KSYS_ELSC_H
 #define _ASM_SN_KSYS_ELSC_H
 
+#include <linux/config.h>
 #include <asm/sn/ksys/l1.h>
 
+#ifdef CONFIG_IA64_SGI_SN1
+
 #define ELSC_ACP_MAX		86		/* 84+cr+lf */
 #define ELSC_LINE_MAX		(ELSC_ACP_MAX - 2)
 
@@ -73,7 +76,6 @@
 int	elsc_power_cycle(elsc_t *e);
 int	elsc_system_reset(elsc_t *e);
 int	elsc_dip_switches(elsc_t *e);
-int	elsc_nic_get(elsc_t *e, uint64_t *nic, int verbose);
 
 int	_elsc_hbt(elsc_t *e, int ival, int rdly);
 
@@ -82,6 +84,9 @@
 #define	elsc_hbt_send(e)		_elsc_hbt(e, 0, 1)
 
 elsc_t	       *get_elsc(void);
+
+#endif	/* CONFIG_IA64_SGI_SN1 */
+
 
 /*
  * Error codes
diff -Nru a/include/asm-ia64/sn/ksys/l1.h b/include/asm-ia64/sn/ksys/l1.h
--- a/include/asm-ia64/sn/ksys/l1.h	Mon Dec 23 21:21:53 2002
+++ b/include/asm-ia64/sn/ksys/l1.h	Mon Dec 23 21:21:53 2002
@@ -10,11 +10,15 @@
 #ifndef _ASM_SN_KSYS_L1_H
 #define _ASM_SN_KSYS_L1_H
 
+#include <linux/config.h>
 #include <asm/sn/vector.h>
 #include <asm/sn/addrs.h>
 #include <asm/atomic.h>
 #include <asm/sn/sv.h>
 
+
+#ifdef CONFIG_IA64_SGI_SN1
+
 #define BRL1_QSIZE	128	/* power of 2 is more efficient */
 #define BRL1_BUFSZ	264	/* needs to be large enough
 				 * to hold 2 flags, escaped
@@ -109,8 +113,6 @@
 #define BRL1_RESET	7
 
 
-#ifndef __ASSEMBLY__
-
 /*
  * l1sc_t structure-- tracks protocol state, open subchannels, etc.
  */
@@ -148,7 +150,6 @@
 
     sc_cq_t	 garbage_q;	/* a place to put unsolicited packets */
     sc_cq_t	 oq[BRL1_OQS];	/* elscuart output queues */
-
 } l1sc_t;
 
 
@@ -169,6 +170,7 @@
 #define SC_TIMEDOUT	(-9)
 #define SC_NSUBCH	(-10)
 
+#endif	/* CONFIG_IA64_SGI_SN1 */
 
 /* L1 Target Addresses */
 /*
@@ -179,21 +181,38 @@
  * id (L1 functionality is divided into several independent "tasks"
  * that can each receive command requests and transmit responses)
  */
+#ifdef CONFIG_IA64_SGI_SN1
 #define L1_ADDR_TYPE_SHFT	28
 #define L1_ADDR_TYPE_MASK	0xF0000000
+#else
+#define L1_ADDR_TYPE_SHFT	8
+#define L1_ADDR_TYPE_MASK	0xFF00
+#endif	/* CONFIG_IA64_SGI_SN1 */
 #define L1_ADDR_TYPE_L1		0x00	/* L1 system controller */
 #define L1_ADDR_TYPE_L2		0x01	/* L2 system controller */
 #define L1_ADDR_TYPE_L3		0x02	/* L3 system controller */
 #define L1_ADDR_TYPE_CBRICK	0x03	/* attached C brick	*/
 #define L1_ADDR_TYPE_IOBRICK	0x04	/* attached I/O brick	*/
 
+#ifdef CONFIG_IA64_SGI_SN1
 #define L1_ADDR_RACK_SHFT	18
 #define L1_ADDR_RACK_MASK	0x0FFC0000
 #define	L1_ADDR_RACK_LOCAL	0x3ff	/* local brick's rack	*/
+#else
+#define L1_ADDR_RACK_SHFT	16
+#define L1_ADDR_RACK_MASK	0xFFFF00
+#define	L1_ADDR_RACK_LOCAL	0xffff	/* local brick's rack	*/
+#endif /* CONFIG_IA64_SGI_SN1 */
 
+#ifdef CONFIG_IA64_SGI_SN1
 #define L1_ADDR_BAY_SHFT	12
 #define L1_ADDR_BAY_MASK	0x0003F000
 #define	L1_ADDR_BAY_LOCAL	0x3f	/* local brick's bay	*/
+#else
+#define L1_ADDR_BAY_SHFT	0
+#define L1_ADDR_BAY_MASK	0xFF
+#define	L1_ADDR_BAY_LOCAL	0xff	/* local brick's bay	*/
+#endif	/* CONFIG_IA64_SGI_SN1 */
 
 #define L1_ADDR_TASK_SHFT	0
 #define L1_ADDR_TASK_MASK	0x0000001F
@@ -268,13 +287,16 @@
 #define L1_REQ_EXEC_CMD		0x0000	/* interpret and execute an ASCII
 					   command string */
 
-
 /* brick type response codes */
-#define L1_BRICKTYPE_C	0x43
-#define L1_BRICKTYPE_I	0x49
-#define L1_BRICKTYPE_P	0x50
-#define L1_BRICKTYPE_R  0x52
-#define L1_BRICKTYPE_X  0x58
+#define L1_BRICKTYPE_IP45       0x34            /* 4 */
+#define L1_BRICKTYPE_C          0x43            /* C */
+#define L1_BRICKTYPE_I          0x49            /* I */
+#define L1_BRICKTYPE_P          0x50            /* P */
+#define L1_BRICKTYPE_R          0x52            /* R */
+#define L1_BRICKTYPE_X          0x58            /* X */
+#define L1_BRICKTYPE_X2         0x59            /* Y */
+#define L1_BRICKTYPE_N          0x4e            /* N */
+#define L1_BRICKTYPE_PX		0x23		/* # */
 
 /* EEPROM codes (for the "read EEPROM" request) */
 /* c brick */
@@ -306,7 +328,6 @@
     (*(l1addr_t *)(addr) = (l1addr_t)(trb) |				\
     			     ((l1addr_t)(tsk) << L1_ADDR_TASK_SHFT))
 
-
 #define L1_DISPLAY_LINE_LENGTH	12	/* L1 display characters/line */
 
 #ifdef L1_DISP_2LINES
@@ -316,10 +337,12 @@
 					 * to system software */
 #endif
 
-#define SC_EVENT_CLASS_MASK ((unsigned short)0xff00)
-
 #define bzero(d, n)	memset((d), 0, (n))
 
+#ifdef CONFIG_IA64_SGI_SN1
+
+#define SC_EVENT_CLASS_MASK ((unsigned short)0xff00)
+
 /* public interfaces to L1 system controller */
 
 int	sc_open( l1sc_t *sc, uint target );
@@ -348,15 +371,18 @@
 #define get_l1sc	get_elsc
 #define get_master_l1sc get_l1sc
 
-int	router_module_get( nasid_t nasid, net_vec_t path );
-
 int	iobrick_rack_bay_type_get( l1sc_t *sc, uint *rack,
 				   uint *bay, uint *brick_type );
 int	iobrick_module_get( l1sc_t *sc );
 int	iobrick_pci_slot_pwr( l1sc_t *sc, int bus, int slot, int up );
 int	iobrick_pci_bus_pwr( l1sc_t *sc, int bus, int up );
 int	iobrick_sc_version( l1sc_t *sc, char *result );
+#else
+int	elsc_display_line(nasid_t nasid, char *line, int lnum);
+int	iobrick_rack_bay_type_get( nasid_t nasid, uint *rack,
+				   uint *bay, uint *brick_type );
+int	iobrick_module_get( nasid_t nasid );
+#endif	/* CONFIG_IA64_SGI_SN1 */
 
 
-#endif /* !__ASSEMBLY__ */
 #endif /* _ASM_SN_KSYS_L1_H */
diff -Nru a/include/asm-ia64/sn/leds.h b/include/asm-ia64/sn/leds.h
--- a/include/asm-ia64/sn/leds.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-ia64/sn/leds.h	Mon Dec 23 21:21:51 2002
@@ -5,7 +5,7 @@
  * 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.
- * Copyright (C) 2000-2001 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 2000-2002 Silicon Graphics, Inc. All rights reserved.
  */
 
 #include <linux/config.h>
@@ -15,7 +15,7 @@
 #include <asm/sn/pda.h>
 
 #ifdef CONFIG_IA64_SGI_SN1
-#define LED0		0xc0000b00100000c0LL	/* ZZZ fixme */
+#define LED0		0xc0000b00100000c0LL
 #define LED_CPU_SHIFT	3
 #else
 #include <asm/sn/sn2/shub.h>
@@ -25,7 +25,13 @@
 
 #define LED_CPU_HEARTBEAT	0x01
 #define LED_CPU_ACTIVITY	0x02
+#ifdef LED_WAR
+#define LED_ALWAYS_SET		0x64	/* SN2 hw workaround: always set 0x60 */
+#define LED_MASK_AUTOTEST	0x9e
+#else /* LED_WAR */
+#define LED_ALWAYS_SET		0x00
 #define LED_MASK_AUTOTEST	0xfe
+#endif /* LED_WAR */
 
 /*
  * Basic macros for flashing the LEDS on an SGI, SN1.
@@ -34,8 +40,14 @@
 static __inline__ void
 set_led_bits(u8 value, u8 mask)
 {
+#if 0
 	pda.led_state = (pda.led_state & ~mask) | (value & mask);
+#ifdef CONFIG_IA64_SGI_SN1
 	*pda.led_address = (long) pda.led_state;
+#else
+	*pda.led_address = (short) pda.led_state;
+#endif
+#endif
 }
 
 #endif /* _ASM_IA64_SN_LEDS_H */
diff -Nru a/include/asm-ia64/sn/module.h b/include/asm-ia64/sn/module.h
--- a/include/asm-ia64/sn/module.h	Mon Dec 23 21:21:53 2002
+++ b/include/asm-ia64/sn/module.h	Mon Dec 23 21:21:53 2002
@@ -13,12 +13,13 @@
 #endif
 
 
+#include <linux/config.h>
 #include <asm/sn/systeminfo.h>
 #include <asm/sn/klconfig.h>
 #include <asm/sn/ksys/elsc.h>
 
 #define MODULE_MAX			128
-#define MODULE_MAX_NODES		1
+#define MODULE_MAX_NODES		2
 #define MODULE_HIST_CNT			16
 #define MAX_MODULE_LEN			16
 
@@ -32,6 +33,127 @@
 #define MODULE_FORMAT_LONG	2
 
 
+#ifdef CONFIG_IA64_SGI_SN2
+
+/*
+ *	Module id format
+ *
+ *	31-16	Rack ID (encoded class, group, number - 16-bit unsigned int)
+ *	 15-8	Brick type (8-bit ascii character)
+ *	  7-0	Bay (brick position in rack (0-63) - 8-bit unsigned int)
+ *
+ */
+
+/*
+ * Macros for getting the brick type
+ */
+#define MODULE_BTYPE_MASK	0xff00
+#define MODULE_BTYPE_SHFT	8
+#define MODULE_GET_BTYPE(_m)	(((_m) & MODULE_BTYPE_MASK) >> MODULE_BTYPE_SHFT)
+#define MODULE_BT_TO_CHAR(_b)	((char)(_b))
+#define MODULE_GET_BTCHAR(_m)	(MODULE_BT_TO_CHAR(MODULE_GET_BTYPE(_m)))
+
+/*
+ * Macros for getting the rack ID.
+ */
+#define MODULE_RACK_MASK	0xffff0000
+#define MODULE_RACK_SHFT	16
+#define MODULE_GET_RACK(_m)	(((_m) & MODULE_RACK_MASK) >> MODULE_RACK_SHFT)
+
+/*
+ * Macros for getting the brick position
+ */
+#define MODULE_BPOS_MASK	0x00ff
+#define MODULE_BPOS_SHFT	0
+#define MODULE_GET_BPOS(_m)	(((_m) & MODULE_BPOS_MASK) >> MODULE_BPOS_SHFT)
+
+/*
+ * Macros for constructing moduleid_t's
+ */
+#define RBT_TO_MODULE(_r, _b, _t) ((_r) << MODULE_RACK_SHFT | \
+				   (_b) << MODULE_BPOS_SHFT | \
+				   (_t) << MODULE_BTYPE_SHFT)
+
+/*
+ * Macros for encoding and decoding rack IDs
+ * A rack number consists of three parts:
+ *   class (0==CPU/mixed, 1==I/O), group, number
+ *
+ * Rack number is stored just as it is displayed on the screen:
+ * a 3-decimal-digit number.
+ */
+#define RACK_CLASS_DVDR		100
+#define RACK_GROUP_DVDR		10
+#define RACK_NUM_DVDR		1
+
+#define RACK_CREATE_RACKID(_c, _g, _n)	((_c) * RACK_CLASS_DVDR +	\
+	(_g) * RACK_GROUP_DVDR + (_n) * RACK_NUM_DVDR)
+
+#define RACK_GET_CLASS(_r)              ((_r) / RACK_CLASS_DVDR)
+#define RACK_GET_GROUP(_r)              (((_r) - RACK_GET_CLASS(_r) *   \
+            RACK_CLASS_DVDR) / RACK_GROUP_DVDR)
+#define RACK_GET_NUM(_r)                (((_r) - RACK_GET_CLASS(_r) *   \
+            RACK_CLASS_DVDR - RACK_GET_GROUP(_r) *      \
+            RACK_GROUP_DVDR) / RACK_NUM_DVDR)
+
+/*
+ * Macros for encoding and decoding rack IDs
+ * A rack number consists of three parts:
+ *   class	1 bit, 0==CPU/mixed, 1==I/O
+ *   group	2 bits for CPU/mixed, 3 bits for I/O
+ *   number	3 bits for CPU/mixed, 2 bits for I/O (1 based)
+ */
+#define RACK_GROUP_BITS(_r)	(RACK_GET_CLASS(_r) ? 3 : 2)
+#define RACK_NUM_BITS(_r)	(RACK_GET_CLASS(_r) ? 2 : 3)
+
+#define RACK_CLASS_MASK(_r)	0x20
+#define RACK_CLASS_SHFT(_r)	5
+#define RACK_ADD_CLASS(_r, _c)	\
+	((_r) |= (_c) << RACK_CLASS_SHFT(_r) & RACK_CLASS_MASK(_r))
+
+#define RACK_GROUP_SHFT(_r)	RACK_NUM_BITS(_r)
+#define RACK_GROUP_MASK(_r)	\
+	( (((unsigned)1<<RACK_GROUP_BITS(_r)) - 1) << RACK_GROUP_SHFT(_r) )
+#define RACK_ADD_GROUP(_r, _g)	\
+	((_r) |= (_g) << RACK_GROUP_SHFT(_r) & RACK_GROUP_MASK(_r))
+
+#define RACK_NUM_SHFT(_r)	0
+#define RACK_NUM_MASK(_r)	\
+	( (((unsigned)1<<RACK_NUM_BITS(_r)) - 1) << RACK_NUM_SHFT(_r) )
+#define RACK_ADD_NUM(_r, _n)	\
+	((_r) |= ((_n) - 1) << RACK_NUM_SHFT(_r) & RACK_NUM_MASK(_r))
+
+
+/*
+ * Brick type definitions
+ */
+#define MAX_BRICK_TYPES         256 /* brick type is stored as uchar */
+
+extern char brick_types[];
+
+#define MODULE_CBRICK           0
+#define MODULE_RBRICK           1
+#define MODULE_IBRICK           2
+#define MODULE_KBRICK           3
+#define MODULE_XBRICK           4
+#define MODULE_DBRICK           5
+#define MODULE_PBRICK           6
+#define MODULE_NBRICK           7
+#define MODULE_PEBRICK          8
+#define MODULE_PXBRICK          9
+
+/*
+ * Moduleid_t comparison macros
+ */
+/* Don't compare the brick type:  only the position is significant */
+#define MODULE_CMP(_m1, _m2)    (((_m1)&(MODULE_RACK_MASK|MODULE_BPOS_MASK)) -\
+                                 ((_m2)&(MODULE_RACK_MASK|MODULE_BPOS_MASK)))
+#define MODULE_MATCH(_m1, _m2)  (MODULE_CMP((_m1),(_m2)) == 0)
+
+
+#else
+#if defined(CONFIG_IA64_SGI_SN1) || defined(CONFIG_IA64_GENERIC)
+
 /*
  *	Module id format
  *
@@ -116,6 +238,9 @@
 #define MODULE_XBRICK		4
 #define MODULE_DBRICK		5
 #define MODULE_PBRICK		6
+#define MODULE_NBRICK           7
+#define MODULE_PEBRICK          8
+#define MODULE_PXBRICK          9
 
 /*
  * Moduleid_t comparison macros
@@ -125,6 +250,18 @@
 				 ((_m2)&(MODULE_RACK_MASK|MODULE_BPOS_MASK)))
 #define MODULE_MATCH(_m1, _m2)	(MODULE_CMP((_m1),(_m2)) == 0)
 
+#else
+
+/*
+ * Some code that uses this macro will not be conditionally compiled.
+ */
+#define MODULE_GET_BTCHAR(_m)	('?')
+#define MODULE_CMP(_m1, _m2)	((_m1) - (_m2))
+#define MODULE_MATCH(_m1, _m2)	(MODULE_CMP((_m1),(_m2)) == 0)
+
+#endif /* SN1 */
+#endif /* SN2 */
+
 typedef struct module_s module_t;
 
 struct module_s {
@@ -134,6 +271,9 @@
 
     /* List of nodes in this module */
     cnodeid_t		nodes[MODULE_MAX_NODES];
+#ifdef CONFIG_IA64_SGI_SN2
+    geoid_t		geoid[MODULE_MAX_NODES];
+#endif
     int			nodecnt;	/* Number of nodes in array        */
 
     /* Fields for Module System Controller */
@@ -141,9 +281,10 @@
     int			shutdown;	/* Shutdown in progress            */
     struct semaphore	thdcnt;		/* Threads finished counter        */
 
+#ifdef CONFIG_IA64_SGI_SN1
     elsc_t		elsc;
     spinlock_t		elsclock;
-
+#endif
     time_t		intrhist[MODULE_HIST_CNT];
     int			histptr;
 
@@ -171,7 +312,9 @@
 
 extern module_t	       *module_lookup(moduleid_t id);
 
+#if defined(CONFIG_IA64_SGI_SN1)
 extern elsc_t	       *get_elsc(void);
+#endif
 
 extern int		get_kmod_info(cmoduleid_t cmod,
 				      module_info_t *mod_info);
diff -Nru a/include/asm-ia64/sn/nodepda.h b/include/asm-ia64/sn/nodepda.h
--- a/include/asm-ia64/sn/nodepda.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-ia64/sn/nodepda.h	Mon Dec 23 21:21:51 2002
@@ -70,7 +70,11 @@
 	nasid_t		xbow_peer;	/* NASID of our peer hub on xbow */
 	struct semaphore xbow_sema;	/* Sema for xbow synchronization */
 	slotid_t	slotdesc;
+#ifdef CONFIG_IA64_SGI_SN2
+	geoid_t		geoid;
+#else
 	moduleid_t	module_id;	/* Module ID (redundant local copy) */
+#endif
 	module_t	*module;	/* Pointer to containing module */
 	xwidgetnum_t 	basew_id;
 	devfs_handle_t 	basew_xc;
@@ -91,7 +95,8 @@
 	/*
 	 * The BTEs on this node are shared by the local cpus
 	 */
-	bteinfo_t	node_bte_info[BTES_PER_NODE];
+	bteinfo_t	bte_if[BTES_PER_NODE];	/* Virtual Interface */
+	char		bte_cleanup[5 * L1_CACHE_BYTES] ____cacheline_aligned;
 
 #if defined(CONFIG_IA64_SGI_SN1)
 	subnode_pda_t	snpda[NUM_SUBNODES];
@@ -122,9 +127,10 @@
 typedef struct nodepda_s nodepda_t;
 
 #ifdef CONFIG_IA64_SGI_SN2
+#define NR_IVECS 256
 struct irqpda_s {
 	int num_irq_used;
-	char irq_flags[NR_IRQS];
+	char irq_flags[NR_IVECS];
 };
 
 typedef struct irqpda_s irqpda_t;
@@ -147,7 +153,7 @@
  *	SUBNODEPDA(cnode,sn)	-> to access subnode PDA for cnodeid/subnode
  */
 
-#define	nodepda		pda.p_nodepda		/* Ptr to this node's PDA */
+#define	nodepda		pda->p_nodepda		/* Ptr to this node's PDA */
 #define	NODEPDA(cnode)		(nodepda->pernode_pdaindr[cnode])
 
 #if defined(CONFIG_IA64_SGI_SN1)
@@ -160,7 +166,11 @@
 /*
  * Macros to access data structures inside nodepda 
  */
+#ifdef CONFIG_IA64_SGI_SN2
+#define NODE_MODULEID(cnode)    geo_module((NODEPDA(cnode)->geoid))
+#else
 #define NODE_MODULEID(cnode)	(NODEPDA(cnode)->module_id)
+#endif
 #define NODE_SLOTID(cnode)	(NODEPDA(cnode)->slotdesc)
 
 
@@ -174,8 +184,8 @@
  * Check if given a compact node id the corresponding node has all the
  * cpus disabled. 
  */
-#define is_headless_node(cnode)		((cnode == CNODEID_NONE) ||			\
-					 (node_data(cnode)->active_cpu_count == 0))
+#define is_headless_node(cnode)		0 /*((cnode == CNODEID_NONE) ||			\
+					    (node_data(cnode)->active_cpu_count == 0)) */
 
 /*
  * Check if given a node vertex handle the corresponding node has all the
diff -Nru a/include/asm-ia64/sn/pci/bridge.h b/include/asm-ia64/sn/pci/bridge.h
--- a/include/asm-ia64/sn/pci/bridge.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-ia64/sn/pci/bridge.h	Mon Dec 23 21:21:51 2002
@@ -12,9 +12,40 @@
 
 /*
  * bridge.h - header file for bridge chip and bridge portion of xbridge chip
+ *
+ * Also including offsets for unique PIC registers.
+ * The PIC asic is a follow-on to Xbridge and most of it's registers are
+ * identical to those of Xbridge.  PIC is different than Xbridge in that
+ * it will accept 64 bit register access and that, in some cases, data
+ * is kept in bits 63:32.   PIC registers that are identical to Xbridge
+ * may be accessed identically to the Xbridge registers, allowing for lots
+ * of code reuse.  Here are the access rules as described in the PIC
+ * manual:
+ * 
+ * 	o Read a word on a DW boundary returns D31:00 of reg.
+ * 	o Read a DW on a DW boundary returns D63:00 of reg.
+ * 	o Write a word on a DW boundary loads D31:00 of reg.
+ * 	o Write a DW on a DW boundary loads D63:00 of reg.
+ * 	o No support for word boundary access that is not double word
+ *           aligned.
+ * 
+ * So we can reuse a lot of bridge_s for PIC.  In bridge_s are included
+ * #define tags and unions for 64 bit access to PIC registers.
+ * For a detailed PIC register layout see pic.h.
  */
 
+#include <linux/config.h>
 #include <asm/sn/xtalk/xwidget.h>
+#ifndef CONFIG_IA64_SGI_SN1
+#include <asm/sn/pci/pic.h>
+
+extern int io_get_sh_swapper(nasid_t);
+#define BRIDGE_REG_GET32(reg) \
+                __swab32( *(volatile uint32_t *) (((uint64_t)reg)^4) )
+
+#define BRIDGE_REG_SET32(reg) \
+                *(volatile uint32_t *) (((uint64_t)reg)^4)
+#endif	/* CONFIG_IA64_SGI_SN1 */
 
 /* I/O page size */
 
@@ -36,6 +67,8 @@
 #define BRIDGE_ATE_RAM_SIZE     (BRIDGE_INTERNAL_ATES<<3)	/* 1kB ATE */
 #define XBRIDGE_ATE_RAM_SIZE    (XBRIDGE_INTERNAL_ATES<<3)	/* 8kB ATE */
 
+#define PIC_WR_REQ_BUFSIZE      256
+
 #define BRIDGE_CONFIG_BASE	0x20000		/* start of bridge's */
 						/* map to each device's */
 						/* config space */
@@ -78,7 +111,502 @@
  * Generated from Bridge spec dated 04oct95
  */
 
-#ifdef LITTLE_ENDIAN
+#ifndef CONFIG_IA64_SGI_SN1
+
+/*
+ * pic_widget_cfg_s is a local definition of widget_cfg_t but with
+ * a union of 64bit & 32bit registers, since PIC has 64bit widget
+ * registers but BRIDGE and XBRIDGE have 32bit.	 PIC registers that
+ * have valid bits (ie. not just reserved) in the upper 32bits are
+ * defined as a union so we can access them as 64bit for PIC and
+ * as 32bit for BRIDGE and XBRIDGE.
+ */ 
+typedef volatile struct pic_widget_cfg_s {
+    bridgereg_t		    _b_wid_id;		    /* 0x000004 */
+    bridgereg_t		    _pad_000000;
+
+    union {
+	picreg_t	    _p_wid_stat;	    /* 0x000008 */
+	struct {
+	    bridgereg_t	    _b_wid_stat;	    /* 0x00000C */
+	    bridgereg_t	    _b_pad_000008;
+	} _b;
+    } u_wid_stat;
+    #define __p_wid_stat_64 u_wid_stat._p_wid_stat
+    #define __b_wid_stat u_wid_stat._b._b_wid_stat
+
+    bridgereg_t		    _b_wid_err_upper;	    /* 0x000014 */
+    bridgereg_t		    _pad_000010;
+
+    union {
+	picreg_t	    _p_wid_err_lower;	    /* 0x000018 */
+	struct {
+	    bridgereg_t	    _b_wid_err_lower;	    /* 0x00001C */
+	    bridgereg_t	    _b_pad_000018;
+	} _b;
+    } u_wid_err_lower;
+    #define __p_wid_err_64 u_wid_err_lower._p_wid_err_lower
+    #define __b_wid_err_lower u_wid_err_lower._b._b_wid_err_lower
+
+    union {
+	picreg_t	    _p_wid_control;	    /* 0x000020 */
+	struct {
+	    bridgereg_t	    _b_wid_control;	    /* 0x000024 */
+	    bridgereg_t	    _b_pad_000020;
+	} _b;
+    } u_wid_control;
+    #define __p_wid_control_64 u_wid_control._p_wid_control
+    #define __b_wid_control u_wid_control._b._b_wid_control
+
+    bridgereg_t		    _b_wid_req_timeout;	    /* 0x00002C */
+    bridgereg_t		    _pad_000028;
+
+    bridgereg_t		    _b_wid_int_upper;	    /* 0x000034 */
+    bridgereg_t		    _pad_000030;
+
+    union {
+	picreg_t	    _p_wid_int_lower;	    /* 0x000038 */
+	struct {
+	    bridgereg_t	    _b_wid_int_lower;	    /* 0x00003C */
+	    bridgereg_t	    _b_pad_000038;
+	} _b;
+    } u_wid_int_lower;
+    #define __p_wid_int_64 u_wid_int_lower._p_wid_int_lower
+    #define __b_wid_int_lower u_wid_int_lower._b._b_wid_int_lower
+
+    bridgereg_t		    _b_wid_err_cmdword;	    /* 0x000044 */
+    bridgereg_t		    _pad_000040;
+
+    bridgereg_t		    _b_wid_llp;		    /* 0x00004C */
+    bridgereg_t		    _pad_000048;
+
+    bridgereg_t		    _b_wid_tflush;	    /* 0x000054 */
+    bridgereg_t		    _pad_000050;
+} pic_widget_cfg_t;
+
+/*
+ * BRIDGE, XBRIDGE, PIC register definitions.  NOTE: Prior to PIC, registers
+ * were a 32bit quantity and double word aligned (and only accessable as a
+ * 32bit word.  PIC registers are 64bits and accessable as words or double
+ * words.  PIC registers that have valid bits (ie. not just reserved) in the
+ * upper 32bits are defined as a union of one 64bit picreg_t and two 32bit
+ * bridgereg_t so we can access them both ways.
+ *
+ * It is generally preferred that hardware registers on the bridge are
+ * located from C code via this structure.
+ *
+ * Generated from Bridge spec dated 04oct95
+ */
+
+typedef volatile struct bridge_s {
+
+    /* 0x000000-0x00FFFF -- Local Registers */
+
+    /* 0x000000-0x000057 -- Standard Widget Configuration */
+    union {
+	widget_cfg_t	    xtalk_widget_def;	    /* 0x000000 */
+	pic_widget_cfg_t    local_widget_def;	    /* 0x000000 */
+    } u_wid;
+
+    /* 32bit widget register access via the widget_cfg_t */
+    #define b_widget u_wid.xtalk_widget_def
+
+    /* 32bit widget register access via the pic_widget_cfg_t */
+    #define b_wid_id u_wid.local_widget_def._b_wid_id
+    #define b_wid_stat u_wid.local_widget_def.__b_wid_stat
+    #define b_wid_err_upper u_wid.local_widget_def._b_wid_err_upper
+    #define b_wid_err_lower u_wid.local_widget_def.__b_wid_err_lower
+    #define b_wid_control u_wid.local_widget_def.__b_wid_control
+    #define b_wid_req_timeout u_wid.local_widget_def._b_wid_req_timeout
+    #define b_wid_int_upper u_wid.local_widget_def._b_wid_int_upper
+    #define b_wid_int_lower u_wid.local_widget_def.__b_wid_int_lower
+    #define b_wid_err_cmdword u_wid.local_widget_def._b_wid_err_cmdword
+    #define b_wid_llp u_wid.local_widget_def._b_wid_llp
+    #define b_wid_tflush u_wid.local_widget_def._b_wid_tflush
+
+    /* 64bit widget register access via the pic_widget_cfg_t */
+    #define p_wid_stat_64 u_wid.local_widget_def.__p_wid_stat_64
+    #define p_wid_err_64 u_wid.local_widget_def.__p_wid_err_64
+    #define p_wid_control_64 u_wid.local_widget_def.__p_wid_control_64
+    #define p_wid_int_64 u_wid.local_widget_def.__p_wid_int_64
+
+    /* 0x000058-0x00007F -- Bridge-specific Widget Configuration */
+    bridgereg_t             b_wid_aux_err;          /* 0x00005C */
+    bridgereg_t             _pad_000058;
+
+    bridgereg_t             b_wid_resp_upper;       /* 0x000064 */
+    bridgereg_t             _pad_000060;
+
+    union {
+        picreg_t            _p_wid_resp_lower;      /* 0x000068 */
+        struct {
+            bridgereg_t     _b_wid_resp_lower;      /* 0x00006C */
+            bridgereg_t     _b_pad_000068;
+        } _b;
+    } u_wid_resp_lower;
+    #define p_wid_resp_64 u_wid_resp_lower._p_wid_resp_lower
+    #define b_wid_resp_lower u_wid_resp_lower._b._b_wid_resp_lower
+
+    bridgereg_t             b_wid_tst_pin_ctrl;     /* 0x000074 */
+    bridgereg_t             _pad_000070;
+
+    union {
+        picreg_t            _p_addr_lkerr;          /* 0x000078 */
+        struct {
+            bridgereg_t     _b_pad_00007C;
+            bridgereg_t     _b_pad_000078;
+        } _b;
+    } u_addr_lkerr;
+    #define p_addr_lkerr_64 u_addr_lkerr._p_addr_lkerr
+
+    /* 0x000080-0x00008F -- PMU */
+    bridgereg_t		    b_dir_map;		    /* 0x000084 */
+    bridgereg_t		    _pad_000080;
+
+    bridgereg_t		    _pad_00008C;
+    bridgereg_t		    _pad_000088;
+
+    /* 0x000090-0x00009F -- SSRAM */
+    bridgereg_t             b_ram_perr_or_map_fault;/* 0x000094 */
+    bridgereg_t		    _pad_000090;
+    #define b_ram_perr  b_ram_perr_or_map_fault     /* Bridge */
+    #define b_map_fault b_ram_perr_or_map_fault     /* Xbridge & PIC */
+
+    bridgereg_t		    _pad_00009C;
+    bridgereg_t		    _pad_000098;
+
+    /* 0x0000A0-0x0000AF -- Arbitration */
+    bridgereg_t		    b_arb;		    /* 0x0000A4 */
+    bridgereg_t		    _pad_0000A0;
+
+    bridgereg_t		    _pad_0000AC;
+    bridgereg_t		    _pad_0000A8;
+
+    /* 0x0000B0-0x0000BF -- Number In A Can or ATE Parity Error */
+    union {
+	picreg_t	    _p_ate_parity_err;	    /* 0x0000B0 */
+	struct {
+	    bridgereg_t	    _b_nic;		    /* 0x0000B4 */
+	    bridgereg_t	    _b_pad_0000B0;
+	} _b;
+    } u_ate_parity_err_or_nic;
+    #define p_ate_parity_err_64 u_ate_parity_err_or_nic._p_ate_parity_err
+    #define b_nic u_ate_parity_err_or_nic._b._b_nic
+
+    bridgereg_t		    _pad_0000BC;
+    bridgereg_t		    _pad_0000B8;
+
+    /* 0x0000C0-0x0000FF -- PCI/GIO */
+    bridgereg_t		    b_bus_timeout;	    /* 0x0000C4 */
+    bridgereg_t		    _pad_0000C0;
+    #define b_pci_bus_timeout b_bus_timeout
+
+    bridgereg_t		    b_pci_cfg;		    /* 0x0000CC */
+    bridgereg_t		    _pad_0000C8;
+
+    bridgereg_t		    b_pci_err_upper;	    /* 0x0000D4 */
+    bridgereg_t		    _pad_0000D0;
+    #define b_gio_err_upper b_pci_err_upper
+
+    union {
+	picreg_t	    _p_pci_err_lower;	    /* 0x0000D8 */
+	struct {
+	    bridgereg_t	    _b_pci_err_lower;	    /* 0x0000DC */
+	    bridgereg_t	    _b_pad_0000D8;
+	} _b;
+    } u_pci_err_lower;
+    #define p_pci_err_64 u_pci_err_lower._p_pci_err_lower
+    #define b_pci_err_lower u_pci_err_lower._b._b_pci_err_lower
+    #define b_gio_err_lower b_pci_err_lower
+
+    bridgereg_t		    _pad_0000E0[8];
+
+    /* 0x000100-0x0001FF -- Interrupt */
+    union {
+	picreg_t	    _p_int_status;	    /* 0x000100 */		
+	struct {
+	    bridgereg_t	    _b_int_status;	    /* 0x000104 */
+	    bridgereg_t	    _b_pad_000100;
+	} _b;
+    } u_int_status;
+    #define p_int_status_64 u_int_status._p_int_status
+    #define b_int_status u_int_status._b._b_int_status
+
+    union {
+	picreg_t	    _p_int_enable;	    /* 0x000108 */		
+	struct {
+	    bridgereg_t	    _b_int_enable;	    /* 0x00010C */
+	    bridgereg_t	    _b_pad_000108;
+	} _b;
+    } u_int_enable;
+    #define p_int_enable_64 u_int_enable._p_int_enable
+    #define b_int_enable u_int_enable._b._b_int_enable
+
+    union {
+	picreg_t	    _p_int_rst_stat;	    /* 0x000110 */		
+	struct {
+	    bridgereg_t	    _b_int_rst_stat;	    /* 0x000114 */
+	    bridgereg_t	    _b_pad_000110;
+	} _b;
+    } u_int_rst_stat;
+    #define p_int_rst_stat_64 u_int_rst_stat._p_int_rst_stat
+    #define b_int_rst_stat u_int_rst_stat._b._b_int_rst_stat
+
+    bridgereg_t		    b_int_mode;		    /* 0x00011C */
+    bridgereg_t		    _pad_000118;
+
+    bridgereg_t		    b_int_device;	    /* 0x000124 */
+    bridgereg_t		    _pad_000120;
+
+    bridgereg_t		    b_int_host_err;	    /* 0x00012C */
+    bridgereg_t		    _pad_000128;
+
+    union {
+	picreg_t	    _p_int_addr[8];	    /* 0x0001{30,,,68} */
+	struct {
+	    bridgereg_t	    addr;		    /* 0x0001{34,,,6C} */
+	    bridgereg_t	    _b_pad;
+	} _b[8];
+    } u_int_addr;
+    #define p_int_addr_64 u_int_addr._p_int_addr
+    #define b_int_addr u_int_addr._b
+
+    union {
+	picreg_t	    _p_err_int_view;	    /* 0x000170 */
+	struct {
+	    bridgereg_t	    _b_err_int_view;	    /* 0x000174 */
+	    bridgereg_t	    _b_pad_000170;
+	} _b;
+    } u_err_int_view;
+    #define p_err_int_view_64 u_err_int_view._p_err_int_view
+    #define b_err_int_view u_err_int_view._b._b_err_int_view
+
+    union {
+	picreg_t	    _p_mult_int;	    /* 0x000178 */
+	struct {
+	    bridgereg_t	    _b_mult_int;	    /* 0x00017C */
+	    bridgereg_t	    _b_pad_000178;
+	} _b;
+    } u_mult_int;
+    #define p_mult_int_64 u_mult_int._p_mult_int
+    #define b_mult_int u_mult_int._b._b_mult_int
+
+    struct {
+	bridgereg_t	    intr;		    /* 0x0001{84,,,BC} */
+	bridgereg_t	    __pad;
+    } b_force_always[8];
+
+    struct {
+	bridgereg_t	    intr;		    /* 0x0001{C4,,,FC} */
+	bridgereg_t	    __pad;
+    } b_force_pin[8];
+
+    /* 0x000200-0x0003FF -- Device */
+    struct {
+	bridgereg_t	    reg;		    /* 0x0002{04,,,3C} */
+	bridgereg_t	    __pad;
+    } b_device[8];
+
+    struct {
+	bridgereg_t	    reg;		    /* 0x0002{44,,,7C} */
+	bridgereg_t	    __pad;
+    } b_wr_req_buf[8];
+
+    struct {
+	bridgereg_t	    reg;		    /* 0x0002{84,,,8C} */
+	bridgereg_t	    __pad;
+    } b_rrb_map[2];
+    #define b_even_resp	b_rrb_map[0].reg	    /* 0x000284 */
+    #define b_odd_resp	b_rrb_map[1].reg	    /* 0x00028C */
+
+    bridgereg_t		    b_resp_status;	    /* 0x000294 */
+    bridgereg_t		    _pad_000290;
+
+    bridgereg_t		    b_resp_clear;	    /* 0x00029C */
+    bridgereg_t		    _pad_000298;
+
+    bridgereg_t		    _pad_0002A0[24];
+
+    /* Xbridge/PIC only */
+    union {
+	struct {
+	    picreg_t	    lower;		    /* 0x0003{08,,,F8} */
+	    picreg_t	    upper;		    /* 0x0003{00,,,F0} */
+	} _p[16];
+	struct {
+	    bridgereg_t	    upper;		    /* 0x0003{04,,,F4} */
+	    bridgereg_t	    _b_pad1;
+	    bridgereg_t	    lower;		    /* 0x0003{0C,,,FC} */
+	    bridgereg_t	    _b_pad2;
+	} _b[16];
+    } u_buf_addr_match;
+    #define p_buf_addr_match_64 u_buf_addr_match._p
+    #define b_buf_addr_match u_buf_addr_match._b
+
+    /* 0x000400-0x0005FF -- Performance Monitor Registers (even only) */
+    struct {
+	bridgereg_t	    flush_w_touch;	    /* 0x000{404,,,5C4} */
+	bridgereg_t	    __pad1;
+	bridgereg_t	    flush_wo_touch;	    /* 0x000{40C,,,5CC} */
+	bridgereg_t	    __pad2;
+	bridgereg_t	    inflight;		    /* 0x000{414,,,5D4} */
+	bridgereg_t	    __pad3;
+	bridgereg_t	    prefetch;		    /* 0x000{41C,,,5DC} */
+	bridgereg_t	    __pad4;
+	bridgereg_t	    total_pci_retry;	    /* 0x000{424,,,5E4} */
+	bridgereg_t	    __pad5;
+	bridgereg_t	    max_pci_retry;	    /* 0x000{42C,,,5EC} */
+	bridgereg_t	    __pad6;
+	bridgereg_t	    max_latency;	    /* 0x000{434,,,5F4} */
+	bridgereg_t	    __pad7;
+	bridgereg_t	    clear_all;		    /* 0x000{43C,,,5FC} */
+	bridgereg_t	    __pad8;
+    } b_buf_count[8];
+
+    /*
+     * "PCI/X registers that are specific to PIC".   See pic.h.
+     */
+
+    /* 0x000600-0x0009FF -- PCI/X registers */
+    picreg_t		    p_pcix_bus_err_addr_64;     /* 0x000600 */
+    picreg_t		    p_pcix_bus_err_attr_64;     /* 0x000608 */
+    picreg_t		    p_pcix_bus_err_data_64;     /* 0x000610 */
+    picreg_t		    p_pcix_pio_split_addr_64;	/* 0x000618 */
+    picreg_t		    p_pcix_pio_split_attr_64;	/* 0x000620 */
+    picreg_t		    p_pcix_dma_req_err_attr_64; /* 0x000628 */
+    picreg_t		    p_pcix_dma_req_err_addr_64;	/* 0x000630 */
+    picreg_t		    p_pcix_timeout_64;		/* 0x000638 */
+
+    picreg_t		    _pad_000600[120];
+
+    /* 0x000A00-0x000BFF -- PCI/X Read&Write Buffer */
+    struct {
+    	picreg_t	    p_buf_attr;		    /* 0X000{A08,,,AF8} */
+    	picreg_t	    p_buf_addr;		    /* 0x000{A00,,,AF0} */
+    } p_pcix_read_buf_64[16];
+
+    struct {
+	picreg_t	    p_buf_attr;		    /* 0x000{B08,,,BE8} */
+	picreg_t	    p_buf_addr;		    /* 0x000{B00,,,BE0} */
+	picreg_t	    __pad1;		    /* 0x000{B18,,,BF8} */
+	picreg_t	    p_buf_valid;	    /* 0x000{B10,,,BF0} */
+    } p_pcix_write_buf_64[8];
+
+    /* 
+     * end "PCI/X registers that are specific to PIC"
+     */
+
+    char		    _pad_000c00[0x010000 - 0x000c00];
+
+    /* 0x010000-0x011fff -- Internal Address Translation Entry RAM */
+    /*
+     * Xbridge and PIC have 1024 internal ATE's and the Bridge has 128.
+     * Make enough room for the Xbridge/PIC ATE's and depend on runtime
+     * checks to limit access to bridge ATE's.
+     *
+     * In [X]bridge the internal ATE Ram is writen as double words only,
+     * but due to internal design issues it is read back as single words. 
+     * i.e:
+     *   b_int_ate_ram[index].hi.rd << 32 | xb_int_ate_ram_lo[index].rd
+     */
+    union {
+	bridge_ate_t	    wr;	/* write-only */    /* 0x01{0000,,,1FF8} */
+	struct {
+	    bridgereg_t	    rd; /* read-only */     /* 0x01{0004,,,1FFC} */
+	    bridgereg_t	    _p_pad;
+	} hi;
+    } b_int_ate_ram[XBRIDGE_INTERNAL_ATES];
+    #define b_int_ate_ram_lo(idx) b_int_ate_ram[idx+512].hi.rd
+
+    /* 0x012000-0x013fff -- Internal Address Translation Entry RAM LOW */
+    struct {
+	bridgereg_t	    rd; /* read-only */	    /* 0x01{2004,,,3FFC} */
+	bridgereg_t	    _p_pad;
+    } xb_int_ate_ram_lo[XBRIDGE_INTERNAL_ATES];
+
+    char		    _pad_014000[0x18000 - 0x014000];
+
+    /* 0x18000-0x197F8 -- PIC Write Request Ram */
+				/* 0x18000 - 0x187F8 */
+    picreg_t		    p_wr_req_lower[PIC_WR_REQ_BUFSIZE];
+				/* 0x18800 - 0x18FF8 */
+    picreg_t		    p_wr_req_upper[PIC_WR_REQ_BUFSIZE];
+				/* 0x19000 - 0x197F8 */
+    picreg_t		    p_wr_req_parity[PIC_WR_REQ_BUFSIZE];
+
+    char		    _pad_019800[0x20000 - 0x019800];
+
+    /* 0x020000-0x027FFF -- PCI Device Configuration Spaces */
+    union {				/* make all access sizes available. */
+	uchar_t		    c[0x1000 / 1];	    /* 0x02{0000,,,7FFF} */
+	uint16_t	    s[0x1000 / 2];	    /* 0x02{0000,,,7FFF} */
+	uint32_t	    l[0x1000 / 4];	    /* 0x02{0000,,,7FFF} */
+	uint64_t	    d[0x1000 / 8];	    /* 0x02{0000,,,7FFF} */
+	union {
+	    uchar_t	    c[0x100 / 1];
+	    uint16_t	    s[0x100 / 2];
+	    uint32_t	    l[0x100 / 4];
+	    uint64_t	    d[0x100 / 8];
+	} f[8];
+    } b_type0_cfg_dev[8];			    /* 0x02{0000,,,7FFF} */
+
+    /* 0x028000-0x028FFF -- PCI Type 1 Configuration Space */
+    union {				/* make all access sizes available. */
+	uchar_t		    c[0x1000 / 1];
+	uint16_t	    s[0x1000 / 2];
+	uint32_t	    l[0x1000 / 4];
+	uint64_t	    d[0x1000 / 8];
+        union {
+            uchar_t         c[0x100 / 1];
+            uint16_t        s[0x100 / 2];
+            uint32_t        l[0x100 / 4];
+            uint64_t        d[0x100 / 8];
+	} f[8];
+    } b_type1_cfg;				    /* 0x028000-0x029000 */
+
+    char		    _pad_029000[0x007000];  /* 0x029000-0x030000 */
+
+    /* 0x030000-0x030007 -- PCI Interrupt Acknowledge Cycle */
+    union {
+	uchar_t		    c[8 / 1];
+	uint16_t	    s[8 / 2];
+	uint32_t	    l[8 / 4];
+	uint64_t	    d[8 / 8];
+    } b_pci_iack;				    /* 0x030000-0x030007 */
+
+    uchar_t		    _pad_030007[0x04fff8];  /* 0x030008-0x07FFFF */
+
+    /* 0x080000-0x0FFFFF -- External Address Translation Entry RAM */
+    bridge_ate_t	    b_ext_ate_ram[0x10000];
+
+    /* 0x100000-0x1FFFFF -- Reserved */
+    char		    _pad_100000[0x200000-0x100000];
+
+    /* 0x200000-0xBFFFFF -- PCI/GIO Device Spaces */
+    union {				/* make all access sizes available. */
+	uchar_t		    c[0x100000 / 1];
+	uint16_t	    s[0x100000 / 2];
+	uint32_t	    l[0x100000 / 4];
+	uint64_t	    d[0x100000 / 8];
+    } b_devio_raw[10];
+
+    /* b_devio macro is a bit strange; it reflects the
+     * fact that the Bridge ASIC provides 2M for the
+     * first two DevIO windows and 1M for the other six.
+     */
+    #define b_devio(n)	b_devio_raw[((n)<2)?(n*2):(n+2)]
+
+    /* 0xC00000-0xFFFFFF -- External Flash Proms 1,0 */
+    union {				/* make all access sizes available. */
+	uchar_t		    c[0x400000 / 1];	/* read-only */
+	uint16_t	    s[0x400000 / 2];	/* read-write */
+	uint32_t	    l[0x400000 / 4];	/* read-only */
+	uint64_t	    d[0x400000 / 8];	/* read-only */
+    } b_external_flash;
+} bridge_t;
+
+#else	/* CONFIG_IA64_SGI_SN1 */
+
 
 typedef volatile struct bridge_s {
 
@@ -311,6 +839,12 @@
 	uint16_t		s[0x1000 / 2];
 	uint32_t		l[0x1000 / 4];
 	uint64_t		d[0x1000 / 8];
+        union {
+            uchar_t         c[0x100 / 1];
+            uint16_t        s[0x100 / 2];
+            uint32_t        l[0x100 / 4];
+            uint64_t        d[0x100 / 8];
+	} f[8];
     } b_type1_cfg;				    /* 0x028000-0x029000 */
 
     char		    _pad_029000[0x007000];  /* 0x029000-0x030000 */
@@ -354,286 +888,7 @@
     } b_external_flash;			/* 0xC00000 */
 } bridge_t;
 
-#else
-
-/*
- * Field formats for Error Command Word and Auxillary Error Command Word
- * of bridge.
- */
-typedef struct bridge_err_cmdword_s {
-    union {
-	uint32_t		cmd_word;
-	struct {
-	    uint32_t		    didn:4,	/* Destination ID */
-				    sidn:4,	/* SOurce ID	  */
-				    pactyp:4,	/* Packet type	  */
-				    tnum:5,	/* Trans Number	  */
-				    coh:1,	/* Coh Transacti  */
-				    ds:2,	/* Data size	  */
-				    gbr:1,	/* GBR enable	  */
-				    vbpm:1,	/* VBPM message	  */
-				    error:1,	/* Error occurred */
-				    barr:1,	/* Barrier op	  */
-				    rsvd:8;
-	} berr_st;
-    } berr_un;
-} bridge_err_cmdword_t;
-
-typedef volatile struct bridge_s {
-
-    /* Local Registers                                 0x000000-0x00FFFF */
-
-    /* standard widget configuration                   0x000000-0x000057 */
-    widget_cfg_t            b_widget;               /* 0x000000 */
-
-    /* helper fieldnames for accessing bridge widget */
-
-#define b_wid_id                        b_widget.w_id
-#define b_wid_stat                      b_widget.w_status
-#define b_wid_err_upper                 b_widget.w_err_upper_addr
-#define b_wid_err_lower                 b_widget.w_err_lower_addr
-#define b_wid_control                   b_widget.w_control
-#define b_wid_req_timeout               b_widget.w_req_timeout
-#define b_wid_int_upper                 b_widget.w_intdest_upper_addr
-#define b_wid_int_lower                 b_widget.w_intdest_lower_addr
-#define b_wid_err_cmdword               b_widget.w_err_cmd_word
-#define b_wid_llp                       b_widget.w_llp_cfg
-#define b_wid_tflush                    b_widget.w_tflush
-
-    /* bridge-specific widget configuration            0x000058-0x00007F */
-    bridgereg_t             _pad_000058;
-    bridgereg_t             b_wid_aux_err;          /* 0x00005C */
-    bridgereg_t             _pad_000060;
-    bridgereg_t             b_wid_resp_upper;       /* 0x000064 */
-    bridgereg_t             _pad_000068;
-    bridgereg_t             b_wid_resp_lower;       /* 0x00006C */
-    bridgereg_t             _pad_000070;
-    bridgereg_t             b_wid_tst_pin_ctrl;     /* 0x000074 */
-    bridgereg_t             _pad_000078[2];
-
-    /* PMU & Map                                       0x000080-0x00008F */
-    bridgereg_t             _pad_000080;
-    bridgereg_t             b_dir_map;              /* 0x000084 */
-    bridgereg_t             _pad_000088[2];
-
-    /* SSRAM                                           0x000090-0x00009F */
-    bridgereg_t             _pad_000090;
-    bridgereg_t             b_ram_perr_or_map_fault;/* 0x000094 */
-#define b_ram_perr  b_ram_perr_or_map_fault     /* Bridge */
-#define b_map_fault b_ram_perr_or_map_fault     /* Xbridge */
-    bridgereg_t             _pad_000098[2];
-
-    /* Arbitration                                     0x0000A0-0x0000AF */
-    bridgereg_t             _pad_0000A0;
-    bridgereg_t             b_arb;                  /* 0x0000A4 */
-    bridgereg_t             _pad_0000A8[2];
-
-    /* Number In A Can                                 0x0000B0-0x0000BF */
-    bridgereg_t             _pad_0000B0;
-    bridgereg_t             b_nic;                  /* 0x0000B4 */
-    bridgereg_t             _pad_0000B8[2];
-
-    /* PCI/GIO                                         0x0000C0-0x0000FF */
-    bridgereg_t             _pad_0000C0;
-    bridgereg_t             b_bus_timeout;          /* 0x0000C4 */
-#define b_pci_bus_timeout b_bus_timeout
-
-    bridgereg_t             _pad_0000C8;
-    bridgereg_t             b_pci_cfg;              /* 0x0000CC */
-    bridgereg_t             _pad_0000D0;
-    bridgereg_t             b_pci_err_upper;        /* 0x0000D4 */
-    bridgereg_t             _pad_0000D8;
-    bridgereg_t             b_pci_err_lower;        /* 0x0000DC */
-    bridgereg_t             _pad_0000E0[8];
-#define b_gio_err_lower b_pci_err_lower
-#define b_gio_err_upper b_pci_err_upper
-
-    /* Interrupt                                       0x000100-0x0001FF */
-    bridgereg_t             _pad_000100;
-    bridgereg_t             b_int_status;           /* 0x000104 */
-    bridgereg_t             _pad_000108;
-    bridgereg_t             b_int_enable;           /* 0x00010C */
-    bridgereg_t             _pad_000110;
-    bridgereg_t             b_int_rst_stat;         /* 0x000114 */
-    bridgereg_t             _pad_000118;
-    bridgereg_t             b_int_mode;             /* 0x00011C */
-    bridgereg_t             _pad_000120;
-    bridgereg_t             b_int_device;           /* 0x000124 */
-    bridgereg_t             _pad_000128;
-    bridgereg_t             b_int_host_err;         /* 0x00012C */
-
-    struct {
-        bridgereg_t             __pad;              /* 0x0001{30,,,68} */
-        bridgereg_t             addr;               /* 0x0001{34,,,6C} */
-    } b_int_addr[8];                                /* 0x000130 */
-
-    bridgereg_t             _pad_000170;
-    bridgereg_t             b_err_int_view;         /* 0x000174 */
-    bridgereg_t             _pad_000178;
-    bridgereg_t             b_mult_int;             /* 0x00017c */
-
-    struct {
-        bridgereg_t             __pad;              /* 0x0001{80,,,B8} */
-        bridgereg_t             intr;               /* 0x0001{84,,,BC} */
-    } b_force_always[8];                            /* 0x000180 */
-
-    struct {
-        bridgereg_t             __pad;              /* 0x0001{C0,,,F8} */
-        bridgereg_t             intr;               /* 0x0001{C4,,,FC} */
-    } b_force_pin[8];                               /* 0x0001C0 */
-
-    /* Device                                          0x000200-0x0003FF */
-    struct {
-        bridgereg_t             __pad;              /* 0x0002{00,,,38} */
-        bridgereg_t             reg;                /* 0x0002{04,,,3C} */
-    } b_device[8];                                  /* 0x000200 */
-
-    struct {
-        bridgereg_t             __pad;              /* 0x0002{40,,,78} */
-        bridgereg_t             reg;                /* 0x0002{44,,,7C} */
-    } b_wr_req_buf[8];                              /* 0x000240 */
-
-    struct {
-        bridgereg_t             __pad;              /* 0x0002{80,,,88} */
-        bridgereg_t             reg;                /* 0x0002{84,,,8C} */
-    } b_rrb_map[2];                                 /* 0x000280 */
-#define b_even_resp     b_rrb_map[0].reg            /* 0x000284 */
-#define b_odd_resp      b_rrb_map[1].reg            /* 0x00028C */
-
-    bridgereg_t             _pad_000290;
-    bridgereg_t             b_resp_status;          /* 0x000294 */
-    bridgereg_t             _pad_000298;
-    bridgereg_t             b_resp_clear;           /* 0x00029C */
-
-    bridgereg_t             _pad_0002A0[24];
-
-    /* Xbridge only */
-    struct {
-        bridgereg_t             __pad1;             /* 0x0003{00,,,F0} */
-        bridgereg_t             upper;              /* 0x0003{04,,,F4} */
-        bridgereg_t             __pad2;             /* 0x0003{08,,,F8} */
-        bridgereg_t             lower;              /* 0x0003{0C,,,FC} */
-    } b_buf_addr_match[16];
-
-    /* Performance Monitor Registers (even only) */
-    struct {
-        bridgereg_t             __pad1;             /* 0x000400,,,5C0 */
-        bridgereg_t             flush_w_touch;      /* 0x000404,,,5C4 */
-        bridgereg_t             __pad2;             /* 0x000408,,,5C8 */
-        bridgereg_t             flush_wo_touch;     /* 0x00040C,,,5CC */
-        bridgereg_t             __pad3;             /* 0x000410,,,5D0 */
-        bridgereg_t             inflight;           /* 0x000414,,,5D4 */
-        bridgereg_t             __pad4;             /* 0x000418,,,5D8 */
-        bridgereg_t             prefetch;           /* 0x00041C,,,5DC */
-        bridgereg_t             __pad5;             /* 0x000420,,,5E0 */
-        bridgereg_t             total_pci_retry;    /* 0x000424,,,5E4 */
-        bridgereg_t             __pad6;             /* 0x000428,,,5E8 */
-        bridgereg_t             max_pci_retry;      /* 0x00042C,,,5EC */
-        bridgereg_t             __pad7;             /* 0x000430,,,5F0 */
-        bridgereg_t             max_latency;        /* 0x000434,,,5F4 */
-        bridgereg_t             __pad8;             /* 0x000438,,,5F8 */
-        bridgereg_t             clear_all;          /* 0x00043C,,,5FC */
-    } b_buf_count[8];
-
-    char                    _pad_000600[0x010000 - 0x000600];
-
-    /*
-     * The Xbridge has 1024 internal ATE's and the Bridge has 128.
-     * Make enough room for the Xbridge ATE's and depend on runtime
-     * checks to limit access to bridge ATE's.
-     */
-
-    /* Internal Address Translation Entry RAM          0x010000-0x011fff */
-    union {
-        bridge_ate_t            wr;             /* write-only */
-        struct {
-            bridgereg_t             _p_pad;
-            bridgereg_t             rd;         /* read-only */
-        }                       hi;
-    }                       b_int_ate_ram[XBRIDGE_INTERNAL_ATES];
-
-#define b_int_ate_ram_lo(idx) b_int_ate_ram[idx+512].hi.rd
-
-    /* the xbridge read path for internal ates starts at 0x12000.
-     * I don't believe we ever try to read the ates.
-     */
-    /* Internal Address Translation Entry RAM LOW       0x012000-0x013fff */
-    struct {
-        bridgereg_t             _p_pad;
-        bridgereg_t             rd;             /* read-only */
-    }                       xb_int_ate_ram_lo[XBRIDGE_INTERNAL_ATES];
-
-    char                    _pad_014000[0x20000 - 0x014000];
-
-    /* PCI Device Configuration Spaces                 0x020000-0x027FFF */
-    union {                             /* make all access sizes available. */
-        uchar_t                 c[0x1000 / 1];
-        uint16_t                s[0x1000 / 2];
-        uint32_t              l[0x1000 / 4];
-        uint64_t              d[0x1000 / 8];
-        union {
-            uchar_t             c[0x100 / 1];
-            uint16_t            s[0x100 / 2];
-            uint32_t          l[0x100 / 4];
-            uint64_t          d[0x100 / 8];
-        }                       f[8];
-    } b_type0_cfg_dev[8];                           /* 0x020000 */
-
-
-    /* PCI Type 1 Configuration Space                  0x028000-0x028FFF */
-    union {                             /* make all access sizes available. */
-        uchar_t                 c[0x1000 / 1];
-        uint16_t                s[0x1000 / 2];
-        uint32_t              l[0x1000 / 4];
-        uint64_t              d[0x1000 / 8];
-    } b_type1_cfg;                                  /* 0x028000-0x029000 */
-
-    char                    _pad_029000[0x007000];  /* 0x029000-0x030000 */
-
-    /* PCI Interrupt Acknowledge Cycle                 0x030000 */
-    union {
-        uchar_t                 c[8 / 1];
-        uint16_t                s[8 / 2];
-        uint32_t              l[8 / 4];
-        uint64_t              d[8 / 8];
-    } b_pci_iack;                                   /* 0x030000 */
-
-    uchar_t                 _pad_030007[0x04fff8];  /* 0x030008-0x07FFFF */
-
-    /* External Address Translation Entry RAM          0x080000-0x0FFFFF */
-    bridge_ate_t            b_ext_ate_ram[0x10000];
-
-    /* Reserved                                        0x100000-0x1FFFFF */
-    char                    _pad_100000[0x200000-0x100000];
-
-    /* PCI/GIO Device Spaces                           0x200000-0xBFFFFF */
-    union {                             /* make all access sizes available. */
-        uchar_t                 c[0x100000 / 1];
-        uint16_t                s[0x100000 / 2];
-        uint32_t              l[0x100000 / 4];
-        uint64_t              d[0x100000 / 8];
-    } b_devio_raw[10];                  /* 0x200000 */
-
-    /* b_devio macro is a bit strange; it reflects the
-     * fact that the Bridge ASIC provides 2M for the
-     * first two DevIO windows and 1M for the other six.
-     */
-#define b_devio(n)      b_devio_raw[((n)<2)?(n*2):(n+2)]
-
-    /* External Flash Proms 1,0                        0xC00000-0xFFFFFF */
-    union {                             /* make all access sizes available. */
-        uchar_t                 c[0x400000 / 1];        /* read-only */
-        uint16_t                s[0x400000 / 2];        /* read-write */
-        uint32_t              l[0x400000 / 4];        /* read-only */
-        uint64_t              d[0x400000 / 8];        /* read-only */
-    } b_external_flash;                 /* 0xC00000 */
-} bridge_t;
-
-#endif
-
-
-
-
+#endif	/* CONFIG_IA64_SGI_SN1 */
 
 
 #define berr_field	berr_un.berr_st
@@ -873,7 +1128,12 @@
 
 /* end of Performance Monitor Registers */
 
-/* Byte offset macros for Bridge I/O space */
+/* Byte offset macros for Bridge I/O space.
+ *
+ * NOTE: Where applicable please use the PCIBR_xxx or PCIBRIDGE_xxx
+ * macros (below) as they will handle [X]Bridge and PIC. For example,
+ * PCIBRIDGE_TYPE0_CFG_DEV0() vs BRIDGE_TYPE0_CFG_DEV0
+ */
 
 #define BRIDGE_ATE_RAM		0x00010000	/* Internal Addr Xlat Ram */
 
@@ -905,7 +1165,55 @@
 #ifndef __ASSEMBLY__
 
 #define BRIDGE_DEVIO(x)		((x)<=1 ? BRIDGE_DEVIO0+(x)*BRIDGE_DEVIO_2MB : BRIDGE_DEVIO2+((x)-2)*BRIDGE_DEVIO_1MB)
-#endif				/* __ASSEMBLY__ */
+
+/*
+ * The device space macros for PIC are more complicated because the PIC has
+ * two PCI/X bridges under the same widget.  For PIC bus 0, the addresses are
+ * basically the same as for the [X]Bridge.  For PIC bus 1, the addresses are
+ * offset by 0x800000.   Here are two sets of macros.  They are 
+ * "PCIBRIDGE_xxx" that return the address based on the supplied bus number
+ * and also equivalent "PCIBR_xxx" macros that may be used with a
+ * pcibr_soft_s structure.   Both should work with all bridges.
+ */
+#define PIC_BUS1_OFFSET 0x800000
+
+#define PCIBRIDGE_TYPE0_CFG_DEV0(busnum) \
+    ((busnum) ? BRIDGE_TYPE0_CFG_DEV0 + PIC_BUS1_OFFSET : \
+                    BRIDGE_TYPE0_CFG_DEV0)
+#define PCIBRIDGE_TYPE1_CFG(busnum) \
+    ((busnum) ? BRIDGE_TYPE1_CFG + PIC_BUS1_OFFSET : BRIDGE_TYPE1_CFG)
+#define PCIBRIDGE_TYPE0_CFG_DEV(busnum, s) \
+        (PCIBRIDGE_TYPE0_CFG_DEV0(busnum)+\
+        (s)*BRIDGE_TYPE0_CFG_SLOT_OFF)
+#define PCIBRIDGE_TYPE0_CFG_DEVF(busnum, s, f) \
+        (PCIBRIDGE_TYPE0_CFG_DEV0(busnum)+\
+        (s)*BRIDGE_TYPE0_CFG_SLOT_OFF+\
+        (f)*BRIDGE_TYPE0_CFG_FUNC_OFF)
+#define PCIBRIDGE_DEVIO0(busnum) ((busnum) ? \
+        (BRIDGE_DEVIO0 + PIC_BUS1_OFFSET) : BRIDGE_DEVIO0)
+#define PCIBRIDGE_DEVIO1(busnum) ((busnum) ? \
+        (BRIDGE_DEVIO1 + PIC_BUS1_OFFSET) : BRIDGE_DEVIO1)
+#define PCIBRIDGE_DEVIO2(busnum) ((busnum) ? \
+        (BRIDGE_DEVIO2 + PIC_BUS1_OFFSET) : BRIDGE_DEVIO2)
+#define PCIBRIDGE_DEVIO(busnum, x) \
+    ((x)<=1 ? PCIBRIDGE_DEVIO0(busnum)+(x)*BRIDGE_DEVIO_2MB : \
+        PCIBRIDGE_DEVIO2(busnum)+((x)-2)*BRIDGE_DEVIO_1MB)
+
+#define PCIBR_BRIDGE_DEVIO0(ps)     PCIBRIDGE_DEVIO0((ps)->bs_busnum)
+#define PCIBR_BRIDGE_DEVIO1(ps)     PCIBRIDGE_DEVIO1((ps)->bs_busnum)
+#define PCIBR_BRIDGE_DEVIO2(ps)     PCIBRIDGE_DEVIO2((ps)->bs_busnum)
+#define PCIBR_BRIDGE_DEVIO(ps, s)   PCIBRIDGE_DEVIO((ps)->bs_busnum, s)
+
+#define PCIBR_TYPE1_CFG(ps)         PCIBRIDGE_TYPE1_CFG((ps)->bs_busnum)
+#define PCIBR_BUS_TYPE0_CFG_DEV0(ps) PCIBR_TYPE0_CFG_DEV(ps, 0)
+#define PCIBR_TYPE0_CFG_DEV(ps, s) \
+    ((IS_PIC_SOFT(ps)) ? PCIBRIDGE_TYPE0_CFG_DEV((ps)->bs_busnum, s+1) : \
+		  	     PCIBRIDGE_TYPE0_CFG_DEV((ps)->bs_busnum, s))
+#define PCIBR_BUS_TYPE0_CFG_DEVF(ps,s,f) \
+    ((IS_PIC_SOFT(ps)) ? PCIBRIDGE_TYPE0_CFG_DEVF((ps)->bs_busnum,(s+1),f) : \
+			     PCIBRIDGE_TYPE0_CFG_DEVF((ps)->bs_busnum,s,f))
+
+#endif				/* LANGUAGE_C */
 
 #define BRIDGE_EXTERNAL_FLASH	0x00C00000	/* External Flash PROMS */
 
@@ -929,6 +1237,17 @@
 #define XBRIDGE_REV_A			0x1
 #define XBRIDGE_REV_B			0x2
 
+/* macros to determine bridge type. 'wid' == widget identification */
+#define IS_BRIDGE(wid) (XWIDGET_PART_NUM(wid) == BRIDGE_WIDGET_PART_NUM && \
+			XWIDGET_MFG_NUM(wid) == BRIDGE_WIDGET_MFGR_NUM)
+#define IS_XBRIDGE(wid) (XWIDGET_PART_NUM(wid) == XBRIDGE_WIDGET_PART_NUM && \
+			XWIDGET_MFG_NUM(wid) == XBRIDGE_WIDGET_MFGR_NUM)
+#define IS_PIC_BUS0(wid) (XWIDGET_PART_NUM(wid) == PIC_WIDGET_PART_NUM_BUS0 && \
+			XWIDGET_MFG_NUM(wid) == PIC_WIDGET_MFGR_NUM)
+#define IS_PIC_BUS1(wid) (XWIDGET_PART_NUM(wid) == PIC_WIDGET_PART_NUM_BUS1 && \
+			XWIDGET_MFG_NUM(wid) == PIC_WIDGET_MFGR_NUM)
+#define IS_PIC_BRIDGE(wid) (IS_PIC_BUS0(wid) || IS_PIC_BUS1(wid))
+
 /* Part + Rev numbers allows distinction and acscending sequence */
 #define BRIDGE_PART_REV_A	(BRIDGE_WIDGET_PART_NUM << 4 | BRIDGE_REV_A)
 #define BRIDGE_PART_REV_B	(BRIDGE_WIDGET_PART_NUM << 4 | BRIDGE_REV_B)
@@ -938,7 +1257,8 @@
 #define XBRIDGE_PART_REV_B	(XBRIDGE_WIDGET_PART_NUM << 4 | XBRIDGE_REV_B)
 
 /* Bridge widget status register bits definition */
-
+#define PIC_STAT_PCIX_SPEED             (0x3ull << 34)
+#define PIC_STAT_PCIX_ACTIVE            (0x1ull << 33)
 #define BRIDGE_STAT_LLP_REC_CNT		(0xFFu << 24)
 #define BRIDGE_STAT_LLP_TX_CNT		(0xFF << 16)
 #define BRIDGE_STAT_FLASH_SELECT	(0x1 << 6)
@@ -946,7 +1266,18 @@
 #define BRIDGE_STAT_PENDING		(0x1F << 0)
 
 /* Bridge widget control register bits definition */
-#define BRIDGE_CTRL_FLASH_WR_EN		(0x1ul << 31)
+#define PIC_CTRL_NO_SNOOP		(0x1ull << 62)
+#define PIC_CTRL_RELAX_ORDER		(0x1ull << 61)
+#define PIC_CTRL_BUS_NUM(x)		((unsigned long long)(x) << 48)
+#define PIC_CTRL_BUS_NUM_MASK		(PIC_CTRL_BUS_NUM(0xff))
+#define PIC_CTRL_DEV_NUM(x)		((unsigned long long)(x) << 43)
+#define PIC_CTRL_DEV_NUM_MASK		(PIC_CTRL_DEV_NUM(0x1f))
+#define PIC_CTRL_FUN_NUM(x)		((unsigned long long)(x) << 40)
+#define PIC_CTRL_FUN_NUM_MASK		(PIC_CTRL_FUN_NUM(0x7))
+#define PIC_CTRL_PAR_EN_REQ		(0x1ull << 29)
+#define PIC_CTRL_PAR_EN_RESP		(0x1ull << 30)
+#define PIC_CTRL_PAR_EN_ATE		(0x1ull << 31)
+#define BRIDGE_CTRL_FLASH_WR_EN		(0x1ul << 31)   /* bridge only */
 #define BRIDGE_CTRL_EN_CLK50		(0x1 << 30)
 #define BRIDGE_CTRL_EN_CLK40		(0x1 << 29)
 #define BRIDGE_CTRL_EN_CLK33		(0x1 << 28)
@@ -970,6 +1301,8 @@
 #define BRIDGE_CTRL_CLR_RLLP_CNT	(0x1 << 11)
 #define BRIDGE_CTRL_CLR_TLLP_CNT	(0x1 << 10)
 #define BRIDGE_CTRL_SYS_END		(0x1 << 9)
+#define BRIDGE_CTRL_PCI_SPEED		(0x3 << 4)
+
 #define BRIDGE_CTRL_BUS_SPEED(n)        ((n) << 4)
 #define BRIDGE_CTRL_BUS_SPEED_MASK      (BRIDGE_CTRL_BUS_SPEED(0x3))
 #define BRIDGE_CTRL_BUS_SPEED_33        0x00
@@ -1023,6 +1356,20 @@
 #define BRIDGE_BUS_PCI_RETRY_MASK	BRIDGE_BUS_PCI_RETRY_CNT(0x3ff)
 
 /* Bridge interrupt status register bits definition */
+#define PIC_ISR_PCIX_SPLIT_MSG_PE	(0x1ull << 45)
+#define PIC_ISR_PCIX_SPLIT_EMSG		(0x1ull << 44)
+#define PIC_ISR_PCIX_SPLIT_TO		(0x1ull << 43)
+#define PIC_ISR_PCIX_UNEX_COMP		(0x1ull << 42)
+#define PIC_ISR_INT_RAM_PERR		(0x1ull << 41)
+#define PIC_ISR_PCIX_ARB_ERR		(0x1ull << 40)
+#define PIC_ISR_PCIX_REQ_TOUT		(0x1ull << 39)
+#define PIC_ISR_PCIX_TABORT		(0x1ull << 38)
+#define PIC_ISR_PCIX_PERR		(0x1ull << 37)
+#define PIC_ISR_PCIX_SERR		(0x1ull << 36)
+#define PIC_ISR_PCIX_MRETRY		(0x1ull << 35)
+#define PIC_ISR_PCIX_MTOUT		(0x1ull << 34)
+#define PIC_ISR_PCIX_DA_PARITY		(0x1ull << 33)
+#define PIC_ISR_PCIX_AD_PARITY		(0x1ull << 32)
 #define BRIDGE_ISR_MULTI_ERR		(0x1u << 31)	/* bridge only */
 #define BRIDGE_ISR_PMU_ESIZE_FAULT	(0x1 << 30)	/* bridge only */
 #define BRIDGE_ISR_PAGE_FAULT		(0x1 << 30)	/* xbridge only */
@@ -1058,12 +1405,18 @@
 		 BRIDGE_ISR_LLP_TCTY)
 
 #define BRIDGE_ISR_PCIBUS_PIOERR	\
-		(BRIDGE_ISR_PCI_MST_TIMEOUT|BRIDGE_ISR_PCI_ABORT)
+		(BRIDGE_ISR_PCI_MST_TIMEOUT|BRIDGE_ISR_PCI_ABORT|	\
+		 PIC_ISR_PCIX_MTOUT|PIC_ISR_PCIX_TABORT)
 
 #define BRIDGE_ISR_PCIBUS_ERROR		\
 		(BRIDGE_ISR_PCIBUS_PIOERR|BRIDGE_ISR_PCI_PERR|		\
 		 BRIDGE_ISR_PCI_SERR|BRIDGE_ISR_PCI_RETRY_CNT|		\
-		 BRIDGE_ISR_PCI_PARITY)
+		 BRIDGE_ISR_PCI_PARITY|PIC_ISR_PCIX_PERR|		\
+		 PIC_ISR_PCIX_SERR|PIC_ISR_PCIX_MRETRY|			\
+		 PIC_ISR_PCIX_AD_PARITY|PIC_ISR_PCIX_DA_PARITY|		\
+		 PIC_ISR_PCIX_REQ_TOUT|PIC_ISR_PCIX_UNEX_COMP|		\
+		 PIC_ISR_PCIX_SPLIT_TO|PIC_ISR_PCIX_SPLIT_EMSG|		\
+		 PIC_ISR_PCIX_SPLIT_MSG_PE)
 
 #define BRIDGE_ISR_XTALK_ERROR		\
 		(BRIDGE_ISR_XREAD_REQ_TIMEOUT|BRIDGE_ISR_XREQ_FIFO_OFLOW|\
@@ -1075,20 +1428,39 @@
 #define BRIDGE_ISR_ERRORS		\
 		(BRIDGE_ISR_LINK_ERROR|BRIDGE_ISR_PCIBUS_ERROR|		\
 		 BRIDGE_ISR_XTALK_ERROR|BRIDGE_ISR_SSRAM_PERR|		\
-		 BRIDGE_ISR_PMU_ESIZE_FAULT)
+		 BRIDGE_ISR_PMU_ESIZE_FAULT|PIC_ISR_PCIX_ARB_ERR|	\
+		 PIC_ISR_INT_RAM_PERR)
 
 /*
  * List of Errors which are fatal and kill the sytem
  */
 #define BRIDGE_ISR_ERROR_FATAL		\
 		((BRIDGE_ISR_XTALK_ERROR & ~BRIDGE_ISR_XREAD_REQ_TIMEOUT)|\
-		 BRIDGE_ISR_PCI_SERR|BRIDGE_ISR_PCI_PARITY )
+		 BRIDGE_ISR_PCI_SERR|BRIDGE_ISR_PCI_PARITY|		  \
+		 PIC_ISR_PCIX_SERR|PIC_ISR_PCIX_AD_PARITY|		  \
+		 PIC_ISR_PCIX_DA_PARITY|				  \
+		 PIC_ISR_INT_RAM_PERR|PIC_ISR_PCIX_SPLIT_MSG_PE )
 
 #define BRIDGE_ISR_ERROR_DUMP		\
 		(BRIDGE_ISR_PCIBUS_ERROR|BRIDGE_ISR_PMU_ESIZE_FAULT|	\
-		 BRIDGE_ISR_XTALK_ERROR|BRIDGE_ISR_SSRAM_PERR)
+		 BRIDGE_ISR_XTALK_ERROR|BRIDGE_ISR_SSRAM_PERR|		\
+		 PIC_ISR_PCIX_ARB_ERR|PIC_ISR_INT_RAM_PERR)
 
 /* Bridge interrupt enable register bits definition */
+#define PIC_IMR_PCIX_SPLIT_MSG_PE	PIC_ISR_PCIX_SPLIT_MSG_PE
+#define PIC_IMR_PCIX_SPLIT_EMSG		PIC_ISR_PCIX_SPLIT_EMSG
+#define PIC_IMR_PCIX_SPLIT_TO		PIC_ISR_PCIX_SPLIT_TO
+#define PIC_IMR_PCIX_UNEX_COMP		PIC_ISR_PCIX_UNEX_COMP
+#define PIC_IMR_INT_RAM_PERR		PIC_ISR_INT_RAM_PERR
+#define PIC_IMR_PCIX_ARB_ERR		PIC_ISR_PCIX_ARB_ERR
+#define PIC_IMR_PCIX_REQ_TOUR		PIC_ISR_PCIX_REQ_TOUT
+#define PIC_IMR_PCIX_TABORT		PIC_ISR_PCIX_TABORT
+#define PIC_IMR_PCIX_PERR		PIC_ISR_PCIX_PERR
+#define PIC_IMR_PCIX_SERR		PIC_ISR_PCIX_SERR
+#define PIC_IMR_PCIX_MRETRY		PIC_ISR_PCIX_MRETRY
+#define PIC_IMR_PCIX_MTOUT		PIC_ISR_PCIX_MTOUT
+#define PIC_IMR_PCIX_DA_PARITY		PIC_ISR_PCIX_DA_PARITY
+#define PIC_IMR_PCIX_AD_PARITY		PIC_ISR_PCIX_AD_PARITY
 #define BRIDGE_IMR_UNEXP_RESP		BRIDGE_ISR_UNEXP_RESP
 #define BRIDGE_IMR_PMU_ESIZE_FAULT	BRIDGE_ISR_PMU_ESIZE_FAULT
 #define BRIDGE_IMR_BAD_XRESP_PKT	BRIDGE_ISR_BAD_XRESP_PKT
@@ -1116,7 +1488,46 @@
 #define BRIDGE_IMR_INT_MSK		BRIDGE_ISR_INT_MSK
 #define BRIDGE_IMR_INT(x)		BRIDGE_ISR_INT(x)
 
-/* Bridge interrupt reset register bits definition */
+/* 
+ * Bridge interrupt reset register bits definition.  Note, PIC can
+ * reset indiviual error interrupts, BRIDGE & XBRIDGE can only do 
+ * groups of them.
+ */
+#define PIC_IRR_PCIX_SPLIT_MSG_PE	PIC_ISR_PCIX_SPLIT_MSG_PE
+#define PIC_IRR_PCIX_SPLIT_EMSG		PIC_ISR_PCIX_SPLIT_EMSG
+#define PIC_IRR_PCIX_SPLIT_TO		PIC_ISR_PCIX_SPLIT_TO
+#define PIC_IRR_PCIX_UNEX_COMP		PIC_ISR_PCIX_UNEX_COMP
+#define PIC_IRR_INT_RAM_PERR		PIC_ISR_INT_RAM_PERR
+#define PIC_IRR_PCIX_ARB_ERR		PIC_ISR_PCIX_ARB_ERR
+#define PIC_IRR_PCIX_REQ_TOUT		PIC_ISR_PCIX_REQ_TOUT
+#define PIC_IRR_PCIX_TABORT		PIC_ISR_PCIX_TABORT
+#define PIC_IRR_PCIX_PERR		PIC_ISR_PCIX_PERR
+#define PIC_IRR_PCIX_SERR		PIC_ISR_PCIX_SERR
+#define PIC_IRR_PCIX_MRETRY		PIC_ISR_PCIX_MRETRY
+#define PIC_IRR_PCIX_MTOUT		PIC_ISR_PCIX_MTOUT
+#define PIC_IRR_PCIX_DA_PARITY		PIC_ISR_PCIX_DA_PARITY
+#define PIC_IRR_PCIX_AD_PARITY		PIC_ISR_PCIX_AD_PARITY
+#define PIC_IRR_PAGE_FAULT		BRIDGE_ISR_PAGE_FAULT
+#define PIC_IRR_UNEXP_RESP		BRIDGE_ISR_UNEXP_RESP
+#define PIC_IRR_BAD_XRESP_PKT		BRIDGE_ISR_BAD_XRESP_PKT
+#define PIC_IRR_BAD_XREQ_PKT		BRIDGE_ISR_BAD_XREQ_PKT
+#define PIC_IRR_RESP_XTLK_ERR		BRIDGE_ISR_RESP_XTLK_ERR
+#define PIC_IRR_REQ_XTLK_ERR		BRIDGE_ISR_REQ_XTLK_ERR
+#define PIC_IRR_INVLD_ADDR		BRIDGE_ISR_INVLD_ADDR
+#define PIC_IRR_UNSUPPORTED_XOP		BRIDGE_ISR_UNSUPPORTED_XOP
+#define PIC_IRR_XREQ_FIFO_OFLOW		BRIDGE_ISR_XREQ_FIFO_OFLOW
+#define PIC_IRR_LLP_REC_SNERR		BRIDGE_ISR_LLP_REC_SNERR
+#define PIC_IRR_LLP_REC_CBERR		BRIDGE_ISR_LLP_REC_CBERR
+#define PIC_IRR_LLP_RCTY		BRIDGE_ISR_LLP_RCTY
+#define PIC_IRR_LLP_TX_RETRY		BRIDGE_ISR_LLP_TX_RETRY
+#define PIC_IRR_LLP_TCTY		BRIDGE_ISR_LLP_TCTY
+#define PIC_IRR_PCI_ABORT		BRIDGE_ISR_PCI_ABORT
+#define PIC_IRR_PCI_PARITY		BRIDGE_ISR_PCI_PARITY
+#define PIC_IRR_PCI_SERR		BRIDGE_ISR_PCI_SERR
+#define PIC_IRR_PCI_PERR		BRIDGE_ISR_PCI_PERR
+#define PIC_IRR_PCI_MST_TIMEOUT		BRIDGE_ISR_PCI_MST_TIMEOUT
+#define PIC_IRR_PCI_RETRY_CNT		BRIDGE_ISR_PCI_RETRY_CNT
+#define PIC_IRR_XREAD_REQ_TIMEOUT	BRIDGE_ISR_XREAD_REQ_TIMEOUT
 #define BRIDGE_IRR_MULTI_CLR		(0x1 << 6)
 #define BRIDGE_IRR_CRP_GRP_CLR		(0x1 << 5)
 #define BRIDGE_IRR_RESP_BUF_GRP_CLR	(0x1 << 4)
@@ -1153,6 +1564,21 @@
 #define BRIDGE_IRR_GIO_GRP		(BRIDGE_ISR_GIO_B_ENBL_ERR | \
 					 BRIDGE_ISR_GIO_MST_TIMEOUT)
 
+#define PIC_IRR_RAM_GRP			PIC_ISR_INT_RAM_PERR
+
+#define PIC_PCIX_GRP_CLR		(PIC_IRR_PCIX_AD_PARITY | \
+					 PIC_IRR_PCIX_DA_PARITY | \
+					 PIC_IRR_PCIX_MTOUT | \
+					 PIC_IRR_PCIX_MRETRY | \
+					 PIC_IRR_PCIX_SERR | \
+					 PIC_IRR_PCIX_PERR | \
+					 PIC_IRR_PCIX_TABORT | \
+					 PIC_ISR_PCIX_REQ_TOUT | \
+					 PIC_ISR_PCIX_UNEX_COMP | \
+					 PIC_ISR_PCIX_SPLIT_TO | \
+					 PIC_ISR_PCIX_SPLIT_EMSG | \
+					 PIC_ISR_PCIX_SPLIT_MSG_PE)
+
 /* Bridge INT_DEV register bits definition */
 #define BRIDGE_INT_DEV_SHFT(n)		((n)*3)
 #define BRIDGE_INT_DEV_MASK(n)		(0x7 << BRIDGE_INT_DEV_SHFT(n))
@@ -1162,6 +1588,10 @@
 #define BRIDGE_INT_ADDR_HOST		0x0003FF00
 #define BRIDGE_INT_ADDR_FLD		0x000000FF
 
+/* PIC interrupt(x) register bits definition */
+#define PIC_INT_ADDR_FLD                0x00FF000000000000
+#define PIC_INT_ADDR_HOST               0x0000FFFFFFFFFFFF
+
 #define BRIDGE_TMO_PCI_RETRY_HLD_MASK	0x1f0000
 #define BRIDGE_TMO_GIO_TIMEOUT_MASK	0x001000
 #define BRIDGE_TMO_PCI_RETRY_CNT_MASK	0x0003ff
@@ -1239,8 +1669,13 @@
 /* RRB assignment register */
 #define	BRIDGE_RRB_EN	0x8	/* after shifting down */
 #define	BRIDGE_RRB_DEV	0x7	/* after shifting down */
-#define	BRIDGE_RRB_VDEV	0x4	/* after shifting down */
-#define	BRIDGE_RRB_PDEV	0x3	/* after shifting down */
+#define	BRIDGE_RRB_VDEV	0x4	/* after shifting down, 2 virtual channels */
+#define	BRIDGE_RRB_PDEV	0x3	/* after shifting down, 8 devices */
+
+#define	PIC_RRB_EN	0x8	/* after shifting down */
+#define	PIC_RRB_DEV	0x7	/* after shifting down */
+#define	PIC_RRB_VDEV	0x6	/* after shifting down, 4 virtual channels */
+#define	PIC_RRB_PDEV	0x1	/* after shifting down, 4 devices */
 
 /* RRB status register */
 #define	BRIDGE_RRB_VALID(r)	(0x00010000<<(r))
@@ -1249,6 +1684,15 @@
 /* RRB clear register */
 #define	BRIDGE_RRB_CLEAR(r)	(0x00000001<<(r))
 
+/* Defines for the virtual channels so we dont hardcode 0-3 within code */
+#define VCHAN0	0	/* virtual channel 0 (ie. the "normal" channel) */
+#define VCHAN1	1	/* virtual channel 1 */
+#define VCHAN2	2	/* virtual channel 2 - PIC only */
+#define VCHAN3	3	/* virtual channel 3 - PIC only */
+
+/* PIC: PCI-X Read Buffer Attribute Register (RBAR) */
+#define NUM_RBAR 16	/* number of RBAR registers */
+
 /* xbox system controller declarations */
 #define XBOX_BRIDGE_WID         8
 #define FLASH_PROM1_BASE        0xE00000 /* To read the xbox sysctlr status */
@@ -1401,8 +1845,10 @@
 #define ATE_SWAP_ON(x)		((x) |= (1 << ATE_SWAPSHIFT))
 #define ATE_SWAP_OFF(x)		((x) &= ~(1 << ATE_SWAPSHIFT))
 
-#define is_xbridge(bridge) \
-        (XWIDGET_PART_NUM(bridge->b_wid_id) == XBRIDGE_WIDGET_PART_NUM)
+#define is_xbridge(bridge) IS_XBRIDGE(bridge->b_wid_id)
+#define is_pic(bridge) IS_PIC_BRIDGE(bridge->b_wid_id)
+
+/* extern declarations */
 
 #ifndef __ASSEMBLY__
 
diff -Nru a/include/asm-ia64/sn/pci/pci_bus_cvlink.h b/include/asm-ia64/sn/pci/pci_bus_cvlink.h
--- a/include/asm-ia64/sn/pci/pci_bus_cvlink.h	Mon Dec 23 21:22:00 2002
+++ b/include/asm-ia64/sn/pci/pci_bus_cvlink.h	Mon Dec 23 21:22:00 2002
@@ -35,30 +35,33 @@
 #define MAX_ATE_MAPS 1024
 
 #define SET_PCIA64(dev) \
-	(((struct sn1_device_sysdata *)((dev)->sysdata))->isa64) = 1
+	(((struct sn_device_sysdata *)((dev)->sysdata))->isa64) = 1
 #define IS_PCIA64(dev)	(((dev)->dma_mask == 0xffffffffffffffffUL) || \
-		(((struct sn1_device_sysdata *)((dev)->sysdata))->isa64))
+		(((struct sn_device_sysdata *)((dev)->sysdata))->isa64))
 #define IS_PCI32G(dev)	((dev)->dma_mask >= 0xffffffff)
 #define IS_PCI32L(dev)	((dev)->dma_mask < 0xffffffff)
 
+#define IS_PIC_DEVICE(dev) ((struct sn_device_sysdata *)dev->sysdata)->isPIC
+
 #define PCIDEV_VERTEX(pci_dev) \
-	(((struct sn1_device_sysdata *)((pci_dev)->sysdata))->vhdl)
+	(((struct sn_device_sysdata *)((pci_dev)->sysdata))->vhdl)
 
 #define PCIBUS_VERTEX(pci_bus) \
-	(((struct sn1_widget_sysdata *)((pci_bus)->sysdata))->vhdl)
+	(((struct sn_widget_sysdata *)((pci_bus)->sysdata))->vhdl)
 
-struct sn1_widget_sysdata {
+struct sn_widget_sysdata {
         devfs_handle_t  vhdl;
 };
 
-struct sn1_device_sysdata {
+struct sn_device_sysdata {
         devfs_handle_t  vhdl;
 	int		isa64;
+	int		isPIC;
 	volatile unsigned int *dma_buf_sync;
 	volatile unsigned int *xbow_buf_sync;
 };
 
-struct sn1_dma_maps_s{
+struct sn_dma_maps_s{
 	struct pcibr_dmamap_s dma_map;
         dma_addr_t      dma_addr;
 };
diff -Nru a/include/asm-ia64/sn/pci/pci_defs.h b/include/asm-ia64/sn/pci/pci_defs.h
--- a/include/asm-ia64/sn/pci/pci_defs.h	Mon Dec 23 21:21:52 2002
+++ b/include/asm-ia64/sn/pci/pci_defs.h	Mon Dec 23 21:21:52 2002
@@ -39,7 +39,7 @@
  * the PCI spec.
  */
 #define	PCI_TYPE1_BUS_MASK	0x00FF0000
-#define	PCI_TYPE1_SLOT_MASK	0x0000F100
+#define	PCI_TYPE1_SLOT_MASK	0x0000F800
 #define	PCI_TYPE1_FUNC_MASK	0x00000700
 #define	PCI_TYPE1_REG_MASK	0x000000FF
 
@@ -68,14 +68,14 @@
 
 /* NOTE: if you are using a C "switch" statement to
  * differentiate between the Config space registers, be
- * aware that PCI_CFG_CLASS_CODE and PCI_CFG_BASE_CLASS
+ * aware that PCI_CFG_CLASS_CODE and PCI_CFG_PROG_IF
  * are the same offset.
  */
 #define	PCI_CFG_REV_ID		0x08		/* Revision Id (1 byte) */
 #define	PCI_CFG_CLASS_CODE	0x09		/* Class Code (3 bytes) */
-#define	PCI_CFG_BASE_CLASS	0x09		/* Base Class (1 byte) */
+#define	PCI_CFG_PROG_IF		0x09		/* Prog Interface (1 byte) */
 #define	PCI_CFG_SUB_CLASS	0x0A		/* Sub Class (1 byte) */
-#define	PCI_CFG_PROG_IF		0x0B		/* Prog Interface (1 byte) */
+#define	PCI_CFG_BASE_CLASS	0x0B		/* Base Class (1 byte) */
 
 #define	PCI_CFG_CACHE_LINE	0x0C		/* Cache line size (1 byte) */
 #define	PCI_CFG_LATENCY_TIMER	0x0D		/* Latency Timer (1 byte) */
@@ -99,11 +99,10 @@
 #define	PCI_CFG_SUBSYS_ID	0x2E		/* Subsystem ID */
 
 #define	PCI_EXPANSION_ROM	0x30		/* Expansion Rom Base (4B) */
+#define	PCI_CAPABILITIES_PTR	0x34		/* Capabilities Pointer */
 
 #define	PCI_INTR_LINE		0x3C		/* Interrupt Line (1B) */
 #define	PCI_INTR_PIN		0x3D		/* Interrupt Pin (1B) */
-#define	PCI_MIN_GNT		0x3E		/* Minimum Grant (1B) */
-#define	PCI_MAX_LAT		0x3F		/* Maximum Latency (1B) */
 
 #define PCI_CFG_VEND_SPECIFIC	0x40		/* first vendor specific reg */
 
@@ -126,6 +125,8 @@
 #define PCI_CFG_PPB_IOLIMHI		0x32	/* IO Limit Addr bits 16..31 */
 #define	PCI_CFG_PPB_SUB_VENDOR		0x34	/* Subsystem Vendor ID */
 #define	PCI_CFG_PPB_SUB_DEVICE		0x36	/* Subsystem Device ID */
+#define	PCI_CFG_PPB_ROM_BASE		0x38	/* ROM base address */
+#define	PCI_CFG_PPB_INT_LINE		0x3C	/* Interrupt Line */
 #define	PCI_CFG_PPB_INT_PIN		0x3D	/* Interrupt Pin */
 #define	PCI_CFG_PPB_BRIDGE_CTRL		0x3E	/* Bridge Control */
      /* XXX- these might be DEC 21152 specific */
@@ -165,6 +166,7 @@
 #define	PCI_STAT_F_BK_BK_CAP	0x0080		/* Fast Back-to-Back Capable */
 #define	PCI_STAT_UDF_SUPP	0x0040		/* UDF Supported */
 #define	PCI_STAT_66MHZ_CAP	0x0020		/* 66 MHz Capable */
+#define	PCI_STAT_CAP_LIST	0x0010		/* Capabilities List */
 
 /* BIST Register Layout (0x0F) */
 #define	PCI_BIST_BIST_CAP	0x80		/* BIST Capable */
@@ -173,13 +175,63 @@
 #define	PCI_BIST_CMPL_OK	0x00		/* 0 value is completion OK */
 
 /* Base Address Register 0x10 */
+#define PCI_BA_IO_CODEMASK	0x3		/* bottom 2 bits encode I/O BAR type */
 #define	PCI_BA_IO_SPACE		0x1		/* I/O Space Marker */
+
+#define PCI_BA_MEM_CODEMASK	0xf		/* bottom 4 bits encode MEM BAR type */
 #define	PCI_BA_MEM_LOCATION	0x6		/* 2 bits for location avail */
 #define	PCI_BA_MEM_32BIT	0x0		/* Anywhere in 32bit space */
 #define	PCI_BA_MEM_1MEG		0x2		/* Locate below 1 Meg */
 #define	PCI_BA_MEM_64BIT	0x4		/* Anywhere in 64bit space */
 #define	PCI_BA_PREFETCH		0x8		/* Prefetchable, no side effect */
 
+#define PCI_BA_ROM_CODEMASK	0x1		/* bottom bit control expansion ROM enable */
+#define PCI_BA_ROM_ENABLE	0x1		/* enable expansion ROM */
+
+/* Bridge Control Register 0x3e */
+#define PCI_BCTRL_DTO_SERR	0x0800		/* Discard Timer timeout generates SERR on primary bus */
+#define PCI_BCTRL_DTO		0x0400		/* Discard Timer timeout status */
+#define PCI_BCTRL_DTO_SEC	0x0200		/* Secondary Discard Timer: 0 => 2^15 PCI clock cycles, 1 => 2^10 */
+#define PCI_BCTRL_DTO_PRI	0x0100		/* Primary Discard Timer: 0 => 2^15 PCI clock cycles, 1 => 2^10 */
+#define PCI_BCTRL_F_BK_BK_ENABLE 0x0080		/* Enable Fast Back-to-Back on secondary bus */
+#define PCI_BCTRL_RESET_SEC	0x0040		/* Reset Secondary bus */
+#define PCI_BCTRL_MSTR_ABT_MODE	0x0020		/* Master Abort Mode: 0 => do not report Master-Aborts */
+#define PCI_BCTRL_VGA_AF_ENABLE	0x0008		/* Enable VGA Address Forwarding */
+#define PCI_BCTRL_ISA_AF_ENABLE	0x0004		/* Enable ISA Address Forwarding */
+#define PCI_BCTRL_SERR_ENABLE	0x0002		/* Enable forwarding of SERR from secondary bus to primary bus */
+#define PCI_BCTRL_PAR_ERR_RESP	0x0001		/* Enable Parity Error Response reporting on secondary interface */
+
+/*
+ * PCI 2.2 introduces the concept of ``capability lists.''  Capability lists
+ * provide a flexible mechanism for a device or bridge to advertise one or
+ * more standardized capabilities such as the presense of a power management
+ * interface, etc.  The presense of a capability list is indicated by
+ * PCI_STAT_CAP_LIST being non-zero in the PCI_CFG_STATUS register.  If
+ * PCI_STAT_CAP_LIST is set, then PCI_CFG_CAP_PTR is a ``pointer'' into the
+ * device-specific portion of the configuration header where the first
+ * capability block is stored.  This ``pointer'' is a single byte which
+ * contains an offset from the beginning of the configuration header.  The
+ * bottom two bits of the pointer are reserved and should be masked off to
+ * determine the offset.  Each capability block contains a capability ID, a
+ * ``pointer'' to the next capability (another offset where a zero terminates
+ * the list) and capability-specific data.  Each capability block starts with
+ * the capability ID and the ``next capability pointer.''  All data following
+ * this are capability-dependent.
+ */
+#define PCI_CAP_ID		0x00		/* Capability ID (1B) */
+#define PCI_CAP_PTR		0x01		/* Capability ``pointer'' (1B) */
+
+/* PCI Capability IDs */
+#define	PCI_CAP_PM		0x01		/* PCI Power Management */
+#define	PCI_CAP_AGP		0x02		/* Accelerated Graphics Port */
+#define	PCI_CAP_VPD		0x03		/* Vital Product Data (VPD) */
+#define	PCI_CAP_SID		0x04		/* Slot Identification */
+#define PCI_CAP_MSI		0x05		/* Message Signaled Intr */
+#define	PCI_CAP_HS		0x06		/* CompactPCI Hot Swap */
+#define	PCI_CAP_PCIX		0x07		/* PCI-X */
+#define PCI_CAP_ID_HT		0x08		/* HyperTransport */
+
+
 /* PIO interface macros */
 
 #ifndef IOC3_EMULATION
@@ -210,10 +262,6 @@
 #endif /* !IOC3_EMULATION */
 						/* effects on reads, merges */
 
-#ifdef CONFIG_SGI_IP22
-#define BYTECOUNT_W_GIO	    0xbf400000
-#endif
-
 /*
  * Definition of address layouts for PCI Config mechanism #1
  * XXX- These largely duplicate PCI_TYPE1 constants at the top
@@ -240,4 +288,139 @@
 #define PCI_IO_MAP_INCR			0x1000
 #endif /* CONFIG_SGI_IP32 */
 
+/*
+ * Class codes
+ */
+#define PCI_CFG_CLASS_PRE20	0x00
+#define PCI_CFG_CLASS_STORAGE	0x01
+#define PCI_CFG_CLASS_NETWORK	0x02
+#define PCI_CFG_CLASS_DISPLAY	0x03
+#define PCI_CFG_CLASS_MMEDIA	0x04
+#define PCI_CFG_CLASS_MEMORY	0x05
+#define PCI_CFG_CLASS_BRIDGE	0x06
+#define PCI_CFG_CLASS_COMM	0x07
+#define PCI_CFG_CLASS_BASE	0x08
+#define PCI_CFG_CLASS_INPUT	0x09
+#define PCI_CFG_CLASS_DOCK	0x0A
+#define PCI_CFG_CLASS_PROC	0x0B
+#define PCI_CFG_CLASS_SERIALBUS	0x0C
+#define PCI_CFG_CLASS_OTHER	0xFF
+
+/*
+ * Important Subclasses
+ */
+#define PCI_CFG_SUBCLASS_BRIDGE_HOST	0x00
+#define PCI_CFG_SUBCLASS_BRIDGE_ISA	0x01
+#define PCI_CFG_SUBCLASS_BRIDGE_EISA	0x02
+#define PCI_CFG_SUBCLASS_BRIDGE_MC	0x03
+#define PCI_CFG_SUBCLASS_BRIDGE_PCI	0x04
+#define PCI_CFG_SUBCLASS_BRIDGE_PCMCIA	0x05
+#define PCI_CFG_SUBCLASS_BRIDGE_NUBUS	0x06
+#define PCI_CFG_SUBCLASS_BRIDGE_CARDBUS	0x07
+#define PCI_CFG_SUBCLASS_BRIDGE_OTHER	0x80
+
+#ifndef __ASSEMBLY__
+
+/*
+ * PCI config space definition
+ */
+typedef volatile struct pci_cfg_s {
+	uint16_t	dev_id;
+	uint16_t	vendor_id;
+	uint16_t	status;
+	uint16_t	cmd;
+	uchar_t		class;
+	uchar_t		sub_class;
+	uchar_t		prog_if;
+	uchar_t		rev;
+	uchar_t		bist;
+	uchar_t		hdr_type;
+	uchar_t		lt;
+	uchar_t		line_size;
+	uint32_t	bar[6];
+	uint32_t	cardbus;
+	uint16_t	subsys_dev_id;
+	uint16_t	subsys_vendor_id;
+	uint32_t	exp_rom;
+	uint32_t	res[2];
+	uchar_t		max_lat;
+	uchar_t		min_gnt;
+	uchar_t		int_pin;
+	uchar_t		int_line;
+} pci_cfg_t;
+
+/*
+ * PCI Type 1 config space definition for PCI to PCI Bridges (PPBs)
+ */
+typedef volatile struct pci_cfg1_s {
+	uint16_t	dev_id;
+	uint16_t	vendor_id;
+	uint16_t	status;
+	uint16_t	cmd;
+	uchar_t		class;
+	uchar_t		sub_class;
+	uchar_t		prog_if;
+	uchar_t		rev;
+	uchar_t		bist;
+	uchar_t		hdr_type;
+	uchar_t		lt;
+	uchar_t		line_size;
+	uint32_t	bar[2];
+	uchar_t		slt;
+	uchar_t		sub_bus_num;
+	uchar_t		snd_bus_num;
+	uchar_t		pri_bus_num;
+	uint16_t	snd_status;
+	uchar_t		io_limit;
+	uchar_t		io_base;
+	uint16_t	mem_limit;
+	uint16_t	mem_base;
+	uint16_t	pmem_limit;
+	uint16_t	pmem_base;
+	uint32_t	pmem_limit_upper;
+	uint32_t	pmem_base_upper;
+	uint16_t	io_limit_upper;
+	uint16_t	io_base_upper;
+	uint32_t	res;
+	uint32_t	exp_rom;
+	uint16_t	ppb_control;
+	uchar_t		int_pin;
+	uchar_t		int_line;
+} pci_cfg1_t;
+
+/*
+ * PCI-X Capability
+ */
+typedef volatile struct cap_pcix_cmd_reg_s {
+	uint16_t	reserved1:              9,
+			max_split:		3,
+			max_mem_read_cnt:	2,
+			enable_relaxed_order:	1,
+			data_parity_enable:	1;
+} cap_pcix_cmd_reg_t;
+
+typedef volatile struct cap_pcix_stat_reg_s {
+	uint32_t	reserved1:		2,
+			split_complt_err:	1,
+			max_cum_read:		3,
+			max_out_split:		3,
+			max_mem_read_cnt:	2,
+			device_complex:		1,
+			unexpect_split_complt:	1,
+			split_complt_discard:	1,
+			mhz133_capable:		1,
+			bit64_device:		1,
+			bus_num:		8,
+			dev_num:		5,
+			func_num:		3;
+} cap_pcix_stat_reg_t;
+
+typedef volatile struct cap_pcix_type0_s {
+	cap_pcix_cmd_reg_t	pcix_type0_command;
+	uchar_t			pcix_cap_nxt;
+	uchar_t			pcix_cap_id;
+	cap_pcix_stat_reg_t	pcix_type0_status;
+} cap_pcix_type0_t;
+
+#endif	/* __ASSEMBLY__ */
 #endif /* _ASM_SN_PCI_PCI_DEFS_H */
diff -Nru a/include/asm-ia64/sn/pci/pciba.h b/include/asm-ia64/sn/pci/pciba.h
--- a/include/asm-ia64/sn/pci/pciba.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-ia64/sn/pci/pciba.h	Mon Dec 23 21:21:51 2002
@@ -91,6 +91,13 @@
 #define	PCIIOCDMAALLOC		_IOWR(0,1,uint64_t)
 #define	PCIIOCDMAFREE		_IOW(0,1,uint64_t)
 
+/* pio cache-mode ioctl defines.  current only uncached accelerated */
+#define PCIBA_CACHE_MODE_SET	1
+#define PCIBA_CACHE_MODE_CLEAR	2
+#ifdef PIOMAP_UNC_ACC
+#define PCIBA_UNCACHED_ACCEL	PIOMAP_UNC_ACC
+#endif
+
 /* The parameter for PCIIOCDMAALLOC needs to contain
  * both the size of the request and the flag values
  * to be used in setting up the DMA.
diff -Nru a/include/asm-ia64/sn/pci/pcibr.h b/include/asm-ia64/sn/pci/pcibr.h
--- a/include/asm-ia64/sn/pci/pcibr.h	Mon Dec 23 21:21:59 2002
+++ b/include/asm-ia64/sn/pci/pcibr.h	Mon Dec 23 21:21:59 2002
@@ -11,6 +11,7 @@
 
 #if defined(__KERNEL__)
 
+#include <linux/config.h>
 #include <asm/sn/dmamap.h>
 #include <asm/sn/driver.h>
 #include <asm/sn/pio.h>
@@ -75,6 +76,7 @@
  */
 
 extern pciio_provider_t pcibr_provider;
+extern pciio_provider_t pci_pic_provider;
 
 /* =====================================================================
  *    secondary entry points: pcibr PCI bus provider
@@ -182,7 +184,11 @@
 
 extern void		pcibr_intr_free(pcibr_intr_t intr);
 
+#ifdef CONFIG_IA64_SGI_SN1
 extern int		pcibr_intr_connect(pcibr_intr_t intr);
+#else
+extern int		pcibr_intr_connect(pcibr_intr_t intr, intr_func_t, intr_arg_t);
+#endif
 
 extern void		pcibr_intr_disconnect(pcibr_intr_t intr);
 
@@ -215,9 +221,11 @@
 extern int		pcibr_error_devenable(devfs_handle_t pconn_vhdl,
 					      int error_code);
 
+#ifdef PIC_LATER
 extern pciio_slot_t	pcibr_error_extract(devfs_handle_t pcibr_vhdl,
 					    pciio_space_t *spacep,
 					    iopaddr_t *addrp);
+#endif
 
 extern int		pcibr_wrb_flush(devfs_handle_t pconn_vhdl);
 extern int		pcibr_rrb_check(devfs_handle_t pconn_vhdl,
@@ -226,11 +234,13 @@
 					int *count_reserved,
 					int *count_pool);
 
+#ifndef CONFIG_IA64_SGI_SN1
 extern int		pcibr_alloc_all_rrbs(devfs_handle_t vhdl, int even_odd,
 					     int dev_1_rrbs, int virt1,
 					     int dev_2_rrbs, int virt2,
 					     int dev_3_rrbs, int virt3,
 					     int dev_4_rrbs, int virt4);
+#endif
 
 typedef void
 rrb_alloc_funct_f	(devfs_handle_t xconn_vhdl,
@@ -340,7 +350,11 @@
 extern void		pcibr_hints_subdevs(devfs_handle_t, pciio_slot_t, ulong);
 extern void		pcibr_hints_handsoff(devfs_handle_t);
 
+#ifdef CONFIG_IA64_SGI_SN1
 typedef unsigned	pcibr_intr_bits_f(pciio_info_t, pciio_intr_line_t);
+#else
+typedef unsigned	pcibr_intr_bits_f(pciio_info_t, pciio_intr_line_t, int);
+#endif
 extern void		pcibr_hints_intr_bits(devfs_handle_t, pcibr_intr_bits_f *);
 
 extern int		pcibr_asic_rev(devfs_handle_t);
@@ -414,13 +428,9 @@
     char                    resp_l1_msg[L1_QSIZE + 1];
 };
 
-struct pcibr_slot_info_req_s {
-   int                      req_slot;
-   pcibr_slot_info_resp_t   req_respp;
-   int                      req_size;
-};
-
 struct pcibr_slot_info_resp_s {
+    short		    resp_bs_bridge_type;
+    short		    resp_bs_bridge_mode;
     int                     resp_has_host;
     char                    resp_host_slot;
     devfs_handle_t            resp_slot_conn;
@@ -438,17 +448,22 @@
     unsigned                resp_bss_d64_flags;
     iopaddr_t               resp_bss_d32_base;
     unsigned                resp_bss_d32_flags;
-    int                     resp_bss_ext_ates_active;
+    atomic_t                resp_bss_ext_ates_active;
     volatile unsigned      *resp_bss_cmd_pointer;
     unsigned                resp_bss_cmd_shadow;
     int                     resp_bs_rrb_valid;
-    int                     resp_bs_rrb_valid_v;
+    int                     resp_bs_rrb_valid_v1;
+    int                     resp_bs_rrb_valid_v2;
+    int                     resp_bs_rrb_valid_v3;
     int                     resp_bs_rrb_res;
     bridgereg_t             resp_b_resp;
     bridgereg_t             resp_b_int_device;
     bridgereg_t             resp_b_int_enable;
     bridgereg_t             resp_b_int_host;
-
+#ifndef CONFIG_IA64_SGI_SN1
+    picreg_t		    resp_p_int_enable;
+    picreg_t		    resp_p_int_host;
+#endif
     struct pcibr_slot_func_info_resp_s {
         int                     resp_f_status;
         char                    resp_f_slot_name[MAXDEVNAME];
@@ -507,6 +522,9 @@
 #define PCI_SLOT_RRB_ALLOC_ERR   24     /* slot initial rrb alloc error */
 #define PCI_SLOT_DRV_ATTACH_ERR  25     /* driver attach error */
 #define PCI_SLOT_DRV_DETACH_ERR  26     /* driver detach error */
+/* EFBIG                         27    */
+#define PCI_MULTI_FUNC_ERR       28     /* multi-function card error */
+#define PCI_SLOT_RBAR_ALLOC_ERR  29     /* slot PCI-X RBAR alloc error */
 /* ERANGE                        34    */
 /* EUNATCH                       42    */
 
diff -Nru a/include/asm-ia64/sn/pci/pcibr_private.h b/include/asm-ia64/sn/pci/pcibr_private.h
--- a/include/asm-ia64/sn/pci/pcibr_private.h	Mon Dec 23 21:21:50 2002
+++ b/include/asm-ia64/sn/pci/pcibr_private.h	Mon Dec 23 21:21:50 2002
@@ -15,6 +15,7 @@
  * should ever peek into this file.
  */
 
+#include <linux/config.h>
 #include <asm/sn/pci/pcibr.h>
 #include <asm/sn/pci/pciio_private.h>
 #include <asm/sn/ksys/l1.h>
@@ -34,6 +35,68 @@
 typedef struct pcibr_intr_wrap_s *pcibr_intr_wrap_t;
 typedef struct pcibr_intr_cbuf_s *pcibr_intr_cbuf_t;
 
+typedef volatile unsigned *cfg_p;
+typedef volatile bridgereg_t *reg_p;
+
+/*
+ * extern functions
+ */
+cfg_p pcibr_slot_config_addr(bridge_t *, pciio_slot_t, int);
+cfg_p pcibr_func_config_addr(bridge_t *, pciio_bus_t bus, pciio_slot_t, pciio_function_t, int);
+unsigned pcibr_slot_config_get(bridge_t *, pciio_slot_t, int);
+unsigned pcibr_func_config_get(bridge_t *, pciio_slot_t, pciio_function_t, int);
+void pcibr_debug(uint32_t, devfs_handle_t, char *, ...);
+void pcibr_slot_config_set(bridge_t *, pciio_slot_t, int, unsigned);
+void pcibr_func_config_set(bridge_t *, pciio_slot_t, pciio_function_t, int, 
+								unsigned);
+/*
+ * PCIBR_DEBUG() macro and debug bitmask defines
+ */
+/* low freqency debug events (ie. initialization, resource allocation,...) */
+#define PCIBR_DEBUG_INIT	0x00000001  /* bridge init */
+#define PCIBR_DEBUG_HINTS	0x00000002  /* bridge hints */
+#define PCIBR_DEBUG_ATTACH	0x00000004  /* bridge attach */
+#define PCIBR_DEBUG_DETACH	0x00000008  /* bridge detach */
+#define PCIBR_DEBUG_ATE		0x00000010  /* bridge ATE allocation */
+#define PCIBR_DEBUG_RRB		0x00000020  /* bridge RRB allocation */
+#define PCIBR_DEBUG_RBAR	0x00000040  /* bridge RBAR allocation */
+#define PCIBR_DEBUG_PROBE	0x00000080  /* bridge device probing */
+#define PCIBR_DEBUG_INTR_ERROR  0x00000100  /* bridge error interrupt */
+#define PCIBR_DEBUG_ERROR_HDLR  0x00000200  /* bridge error handler */
+#define PCIBR_DEBUG_CONFIG	0x00000400  /* device's config space */
+#define PCIBR_DEBUG_BAR		0x00000800  /* device's BAR allocations */
+#define PCIBR_DEBUG_INTR_ALLOC	0x00001000  /* device's intr allocation */
+#define PCIBR_DEBUG_DEV_ATTACH	0x00002000  /* device's attach */
+#define PCIBR_DEBUG_DEV_DETACH	0x00004000  /* device's detach */
+#define PCIBR_DEBUG_HOTPLUG	0x00008000
+
+/* high freqency debug events (ie. map allocation, direct translation,...) */
+#define PCIBR_DEBUG_DEVREG	0x04000000  /* bridges device reg sets */
+#define PCIBR_DEBUG_PIOMAP	0x08000000  /* pcibr_piomap */
+#define PCIBR_DEBUG_PIODIR	0x10000000  /* pcibr_piotrans */
+#define PCIBR_DEBUG_DMAMAP	0x20000000  /* pcibr_dmamap */
+#define PCIBR_DEBUG_DMADIR	0x40000000  /* pcibr_dmatrans */
+#define PCIBR_DEBUG_INTR	0x80000000  /* interrupts */
+
+extern char	 *pcibr_debug_module;
+extern int	  pcibr_debug_widget;
+extern int	  pcibr_debug_slot;
+extern uint32_t pcibr_debug_mask;
+
+/* For low frequency events (ie. initialization, resource allocation,...) */
+#define PCIBR_DEBUG_ALWAYS(args) pcibr_debug args ;
+
+/* XXX: habeck: maybe make PCIBR_DEBUG() always available?  Even in non-
+ * debug kernels?  If tracing isn't enabled (i.e pcibr_debug_mask isn't
+ * set, then the overhead for this macro is just an extra 'if' check.
+ */
+/* For high frequency events (ie. map allocation, direct translation,...) */
+#if 1 || DEBUG
+#define PCIBR_DEBUG(args) PCIBR_DEBUG_ALWAYS(args)
+#else	/* DEBUG */
+#define PCIBR_DEBUG(args)
+#endif	/* DEBUG */
+
 /*
  * Bridge sets up PIO using this information.
  */
@@ -100,6 +163,8 @@
 #define	bi_flags	bi_pi.pi_flags	/* PCIBR_INTR flags */
 #define	bi_dev		bi_pi.pi_dev	/* associated pci card */
 #define	bi_lines	bi_pi.pi_lines	/* which PCI interrupt line(s) */
+#define bi_func		bi_pi.pi_func	/* handler function (when connected) */
+#define bi_arg		bi_pi.pi_arg	/* handler parameter (when connected) */
 #define bi_mustruncpu	bi_pi.pi_mustruncpu /* Where we must run. */
 #define bi_irq		bi_pi.pi_irq	/* IRQ assigned. */
 #define bi_cpu		bi_pi.pi_cpu	/* cpu assigned. */
@@ -108,9 +173,43 @@
     struct pcibr_intr_cbuf_s bi_ibuf;	/* circular buffer of wrap ptrs */
 };
 
+
+/* 
+ * PCIBR_INFO_SLOT_GET_EXT returns the external slot number that the card
+ * resides in.  (i.e the slot number silk screened on the back of the I/O 
+ * brick).  PCIBR_INFO_SLOT_GET_INT returns the internal slot (or device)
+ * number used by the pcibr code to represent that external slot (i.e to 
+ * set bit patterns in BRIDGE/PIC registers to represent the device, or to
+ * offset into an array, or ...).
+ *
+ * In BRIDGE and XBRIDGE the external slot and internal device numbering 
+ * are the same.  (0->0, 1->1, 2->2,... 7->7)  BUT in the PIC the external
+ * slot number is always 1 greater than the internal device number (1->0, 
+ * 2->1, 3->2, 4->3).  This is due to the fact that the PCI-X spec requires
+ * that the 'bridge' (i.e PIC) be designated as 'device 0', thus external
+ * slot numbering can't start at zero.
+ *
+ * PCIBR_DEVICE_TO_SLOT converts an internal device number to an external
+ * slot number.  NOTE: PCIIO_SLOT_NONE stays as PCIIO_SLOT_NONE.
+ *
+ * PCIBR_SLOT_TO_DEVICE converts an external slot number to an internal
+ * device number.  NOTE: PCIIO_SLOT_NONE stays as PCIIO_SLOT_NONE.
+ */
+#define PCIBR_INFO_SLOT_GET_EXT(info)	    (((pcibr_info_t)info)->f_slot)
+#define PCIBR_INFO_SLOT_GET_INT(info)	    (((pcibr_info_t)info)->f_dev)
+
+#define PCIBR_DEVICE_TO_SLOT(pcibr_soft, dev_num) \
+	(((dev_num) != PCIIO_SLOT_NONE) ? \
+	    (IS_PIC_SOFT((pcibr_soft)) ? ((dev_num) + 1) : (dev_num)) : \
+	    PCIIO_SLOT_NONE)
+
+#define PCIBR_SLOT_TO_DEVICE(pcibr_soft, slot) \
+        (((slot) != PCIIO_SLOT_NONE) ? \
+            (IS_PIC_SOFT((pcibr_soft)) ? ((slot) - 1) : (slot)) : \
+            PCIIO_SLOT_NONE)
+
 /*
- * per-connect point pcibr data, including
- * standard pciio data in-line:
+ * per-connect point pcibr data, including standard pciio data in-line:
  */
 struct pcibr_info_s {
     struct pciio_info_s	    f_c;	/* MUST BE FIRST. */
@@ -125,15 +224,18 @@
 #define	f_pops		f_c.c_pops	/* cached provider from c_master */
 #define	f_efunc		f_c.c_efunc	/* error handling function */
 #define	f_einfo		f_c.c_einfo	/* first parameter for efunc */
-#define	f_window	f_c.c_window	/* state of BASE regs */
-#define	f_rbase		f_c.c_rbase	/* expansion rom base */
-#define	f_rsize		f_c.c_rsize	/* expansion rom size */
-#define	f_piospace	f_c.c_piospace	/* additional I/O spaces allocated */
+#define f_window        f_c.c_window    /* state of BASE regs */
+#define	f_rwindow	f_c.c_rwindow	/* expansion ROM BASE regs */
+#define	f_rbase		f_c.c_rbase	/* expansion ROM base */
+#define	f_rsize		f_c.c_rsize	/* expansion ROM size */
+#define f_piospace      f_c.c_piospace  /* additional I/O spaces allocated */
 
     /* pcibr-specific connection state */
     int			    f_ibit[4];	/* Bridge bit for each INTx */
     pcibr_piomap_t	    f_piomap;
     int                     f_att_det_error;
+    pciio_slot_t	    f_dev;	/* which device the card represents */
+    cap_pcix_type0_t	   *f_pcix_cap;	/* pointer to the pcix capability */
 };
 
 /* =====================================================================
@@ -152,15 +254,91 @@
 struct pcibr_intr_wrap_s {
     pcibr_soft_t            iw_soft;	/* which bridge */
     volatile bridgereg_t   *iw_stat;	/* ptr to b_int_status */
+#ifdef CONFIG_IA64_SGI_SN1
     bridgereg_t             iw_intr;	/* bit in b_int_status */
+#else
+    bridgereg_t             iw_ibit;	/* bit in b_int_status */
+#endif
     pcibr_intr_list_t       iw_list;	/* ghostbusters! */
     int			    iw_hdlrcnt;	/* running handler count */
     int			    iw_shared;  /* if Bridge bit is shared */
     int			    iw_connected; /* if already connected */
 };
 
-#define	PCIBR_ISR_ERR_START	8
-#define PCIBR_ISR_MAX_ERRS 	32
+#define	PCIBR_ISR_ERR_START		8
+#define PCIBR_ISR_MAX_ERRS_BRIDGE 	32
+#define PCIBR_ISR_MAX_ERRS_PIC		45
+#define PCIBR_ISR_MAX_ERRS	PCIBR_ISR_MAX_ERRS_PIC
+
+/*
+ * PCI Base Address Register window allocation constants.
+ * To reduce the size of the internal resource mapping structures, do
+ * not use the entire PCI bus I/O address space
+ */ 
+#define PCIBR_BUS_IO_BASE      0x100000
+#define PCIBR_BUS_IO_MAX       0x0FFFFFFF
+#define PCIBR_BUS_IO_PAGE      0x100000
+
+#define PCIBR_BUS_SWIN_BASE    _PAGESZ
+#define PCIBR_BUS_SWIN_MAX     0x000FFFFF
+#define PCIBR_BUS_SWIN_PAGE    _PAGESZ
+
+#define PCIBR_BUS_MEM_BASE     0x200000
+#define PCIBR_BUS_MEM_MAX      0x3FFFFFFF
+#define PCIBR_BUS_MEM_PAGE     0x100000
+
+/* defines for pcibr_soft_s->bs_bridge_type */
+#define PCIBR_BRIDGETYPE_BRIDGE		0
+#define PCIBR_BRIDGETYPE_XBRIDGE	1
+#define PCIBR_BRIDGETYPE_PIC		2
+#define IS_XBRIDGE_SOFT(ps) (ps->bs_bridge_type == PCIBR_BRIDGETYPE_XBRIDGE)
+#define IS_PIC_SOFT(ps)     (ps->bs_bridge_type == PCIBR_BRIDGETYPE_PIC)
+#define IS_BRIDGE_SOFT(ps)  (ps->bs_bridge_type == PCIBR_BRIDGETYPE_BRIDGE)
+#define IS_XBRIDGE_OR_PIC_SOFT(ps) (IS_XBRIDGE_SOFT(ps) || IS_PIC_SOFT(ps))
+
+/*
+ * Runtime checks for workarounds.
+ */
+#define PCIBR_WAR_ENABLED(pv, pcibr_soft) \
+	((1 << XWIDGET_PART_REV_NUM_REV(pcibr_soft->bs_rev_num)) & pv)
+/*
+ * Defines for individual WARs. Each is a bitmask of applicable
+ * part revision numbers. (1 << 1) == rev A, (1 << 2) == rev B, etc.
+ */
+#define PV854697 (~0)     /* PIC: write 64bit regs as 64bits. permanent */
+#define PV854827 (~0)     /* PIC: fake widget 0xf presence bit. permanent */
+#define PV855271 (~0)     /* PIC: use virt chan iff 64-bit device. permanent */
+#define PV855272 (1 << 1) /* PIC: runaway interrupt WAR */
+#define PV856155 (1 << 1) /* PIC: arbitration WAR */
+#define PV856864 (1 << 1) /* PIC: lower timeout to free TNUMs quicker */
+#define PV856866 (1 << 1) /* PIC: avoid rrb's 0/1/8/9. */
+#define PV862253 (1 << 1) /* PIC: don't enable write req RAM parity checking */
+#define PV867308 (3 << 1) /* PIC: make LLP error interrupts FATAL for PIC */
+
+
+/* defines for pcibr_soft_s->bs_bridge_mode */
+#define PCIBR_BRIDGEMODE_PCI_33		0x0
+#define PCIBR_BRIDGEMODE_PCI_66		0x2
+#define PCIBR_BRIDGEMODE_PCIX_66	0x3
+#define PCIBR_BRIDGEMODE_PCIX_100	0x5
+#define PCIBR_BRIDGEMODE_PCIX_133	0x7
+#define BUSSPEED_MASK			0x6
+#define BUSTYPE_MASK			0x1
+
+#define IS_PCI(ps)	(!IS_PCIX(ps))
+#define IS_PCIX(ps)	((ps)->bs_bridge_mode & BUSTYPE_MASK)
+
+#define IS_33MHZ(ps)	((ps)->bs_bridge_mode == PCIBR_BRIDGEMODE_PCI_33)
+#define IS_66MHZ(ps)	(((ps)->bs_bridge_mode == PCIBR_BRIDGEMODE_PCI_66) || \
+			 ((ps)->bs_bridge_mode == PCIBR_BRIDGEMODE_PCIX_66))
+#define IS_100MHZ(ps)	((ps)->bs_bridge_mode == PCIBR_BRIDGEMODE_PCIX_100)
+#define IS_133MHZ(ps)	((ps)->bs_bridge_mode == PCIBR_BRIDGEMODE_PCIX_133)
+
+
+/* Number of PCI slots.   NOTE: this works as long as the first slot
+ * is zero.  Otherwise use ((ps->bs_max_slot+1) - ps->bs_min_slot)
+ */
+#define PCIBR_NUM_SLOTS(ps) (ps->bs_max_slot+1)
 
 /* =====================================================================
  *            Bridge Device State structure
@@ -172,7 +350,7 @@
 struct pcibr_soft_s {
     devfs_handle_t          bs_conn;		/* xtalk connection point */
     devfs_handle_t          bs_vhdl;		/* vertex owned by pcibr */
-    int                     bs_int_enable;	/* Mask of enabled intrs */
+    uint64_t                bs_int_enable;	/* Mask of enabled intrs */
     bridge_t               *bs_base;		/* PIO pointer to Bridge chip */
     char                   *bs_name;		/* hw graph name */
     xwidgetnum_t            bs_xid;		/* Bridge's xtalk ID number */
@@ -180,7 +358,11 @@
     xwidgetnum_t            bs_mxid;		/* master's xtalk ID number */
     pciio_slot_t            bs_first_slot;      /* first existing slot */
     pciio_slot_t            bs_last_slot;       /* last existing slot */
-
+    pciio_slot_t            bs_last_reset;      /* last slot to reset */
+    pciio_slot_t	    bs_min_slot;	/* lowest possible slot */
+    pciio_slot_t	    bs_max_slot;	/* highest possible slot */
+    pcibr_soft_t	    bs_peers_soft;	/* PICs other bus's soft */
+    int			    bs_busnum;		/* PIC has two pci busses */
 
     iopaddr_t               bs_dir_xbase;	/* xtalk address for 32-bit PCI direct map */
     xwidgetnum_t	    bs_dir_xport;	/* xtalk port for 32-bit PCI direct map */
@@ -188,14 +370,23 @@
     struct map             *bs_int_ate_map;	/* rmalloc map for internal ATEs */
     struct map             *bs_ext_ate_map;	/* rmalloc map for external ATEs */
     short		    bs_int_ate_size;	/* number of internal ates */
-    short		    bs_xbridge;		/* if 1 then xbridge */
-
+    short		    bs_bridge_type;	/* see defines above */
+    short		    bs_bridge_mode;	/* see defines above */
+#ifdef CONFIG_IA64_SGI_SN1
+#define bs_xbridge	    bs_bridge_type
+#endif
     int                     bs_rev_num;		/* revision number of Bridge */
 
-    unsigned                bs_dma_flags;	/* revision-implied DMA flags */
+    /* bs_dma_flags are the forced dma flags used on all DMAs. Used for
+     * working around ASIC rev issues and protocol specific requirements
+     */
+    unsigned                bs_dma_flags;	/* forced DMA flags */
 
+#ifdef CONFIG_IA64_SGI_SN1
     l1sc_t                 *bs_l1sc;            /* io brick l1 system cntr */
+#endif
     moduleid_t		    bs_moduleid;	/* io brick moduleid */
+    short		    bs_bricktype;	/* io brick type */
 
     /*
      * Lock used primarily to get mutual exclusion while managing any
@@ -222,7 +413,8 @@
 	pciio_slot_t            host_slot;
 	devfs_handle_t		slot_conn;
 
-	int			slot_status;
+        /* PCI Hot-Plug status word */
+        int 			slot_status;
 
 	/* Potentially several connection points
 	 * for this slot. bss_ninfo is how many,
@@ -299,24 +491,53 @@
 
     pcibr_intr_bits_f	       *bs_intr_bits;
 
+    /* PIC PCI-X Read Buffer Management :
+     * bs_pcix_num_funcs: the total number of PCI-X functions
+     *  on the bus
+     * bs_pcix_split_tot: total number of outstanding split
+     *  transactions requested by all functions on the bus
+     * bs_pcix_rbar_percent_allowed: the percentage of the
+     *  total number of buffers a function requested that are 
+     *  available to it, not including the 1 RBAR guaranteed 
+     *  to it.
+     * bs_pcix_rbar_inuse: number of RBARs in use.
+     * bs_pcix_rbar_avail: number of RBARs available.  NOTE:
+     *  this value can go negative if we oversubscribe the 
+     *  RBARs.  (i.e.  We have 16 RBARs but 17 functions).
+     */
+    int			    bs_pcix_num_funcs;
+    int			    bs_pcix_split_tot;
+    int			    bs_pcix_rbar_percent_allowed;
+
+    int			    bs_pcix_rbar_inuse;
+    int			    bs_pcix_rbar_avail;
+
+
     /* RRB MANAGEMENT
      * bs_rrb_fixed: bitmap of slots whose RRB
      *	allocations we should not "automatically" change
      * bs_rrb_avail: number of RRBs that have not
      *  been allocated or reserved for {even,odd} slots
-     * bs_rrb_res: number of RRBs reserved for the
+     * bs_rrb_res: number of RRBs currently reserved for the
      *	use of the index slot number
-     * bs_rrb_valid: number of RRBs marked valid
-     *	for the indexed slot number; indexes 8-15
-     *	are for the virtual channels for slots 0-7.
+     * bs_rrb_res_dflt: number of RRBs reserved at boot
+     *  time for the use of the index slot number
+     * bs_rrb_valid: number of RRBs currently marked valid
+     *	for the indexed slot/vchan number; array[slot][vchan]
+     * bs_rrb_valid_dflt: number of RRBs marked valid at boot
+     *  time for the indexed slot/vchan number; array[slot][vchan]
      */
     int                     bs_rrb_fixed;
-    int			    bs_rrb_avail[2];
-    int			    bs_rrb_res[8];
+    int                     bs_rrb_avail[2];
+    int                     bs_rrb_res[8];
     int                     bs_rrb_res_dflt[8];
+#ifdef CONFIG_IA64_SGI_SN1
     int                     bs_rrb_valid[16];
     int                     bs_rrb_valid_dflt[16];
-
+#else
+    int			    bs_rrb_valid[8][4];
+    int			    bs_rrb_valid_dflt[8][4];
+#endif
     struct {
 	/* Each Bridge interrupt bit has a single XIO
 	 * interrupt channel allocated.
@@ -347,35 +568,55 @@
      * Note that there is no locking while looking at this data structure.
      * There should not be any race between bus error code and
      * error interrupt code.. will look into this if needed.
+     *
+     * NOTE: The above discussion of error interrupt processing is
+     *       no longer true. Whether it should again be true, is
+     *       being looked into.
      */
     struct br_errintr_info {
 	int                     bserr_toutcnt;
 #ifdef LATER
 	toid_t                  bserr_toutid;	/* Timeout started by errintr */
-#endif
-	iopaddr_t               bserr_addr;	/* Address where error occurred */
-	bridgereg_t             bserr_intstat;	/* interrupts active at error time */
+#endif	/* LATER */
+	iopaddr_t               bserr_addr;	/* Address where error occured */
+	uint64_t		bserr_intstat;	/* interrupts active at error dump */
     } bs_errinfo;
 
     /*
      * PCI Bus Space allocation data structure.
-     * This info is used to satisfy the callers of pcibr_piospace_alloc
-     * interface. Most of these users need "large" amounts of PIO
-     * space (typically in Megabytes), and they generally tend to
-     * take once and never release..
-     * For Now use a simple algorithm to manage it. On allocation,
-     * Update the _base field to reflect next free address.
      *
-     * Freeing does nothing.. So, once allocated, it's gone for good.
+     * The resource mapping functions rmalloc() and rmfree() are used
+     * to manage the PCI bus I/O, small window, and memory  address 
+     * spaces.
+     *
+     * This info is used to assign PCI bus space addresses to cards
+     * via their BARs and to the callers of the pcibr_piospace_alloc()
+     * interface.
+     *
+     * Users of the pcibr_piospace_alloc() interface, such as the VME
+     * Universe chip, need PCI bus space that is not acquired by BARs.
+     * Most of these users need "large" amounts of PIO space (typically
+     * in Megabytes), and they generally tend to take once and never
+     * release. 
      */
+#ifdef CONFIG_IA64_SGI_SN1
     struct br_pcisp_info {
-	iopaddr_t               pci_io_base;
-	iopaddr_t               pci_io_last;
-	iopaddr_t               pci_swin_base;
-	iopaddr_t               pci_swin_last;
-	iopaddr_t               pci_mem_base;
-	iopaddr_t               pci_mem_last;
+        iopaddr_t               pci_io_base;
+        iopaddr_t               pci_io_last;
+        iopaddr_t               pci_swin_base;
+        iopaddr_t               pci_swin_last;
+        iopaddr_t               pci_mem_base;
+        iopaddr_t               pci_mem_last;
     } bs_spinfo;
+#endif	/* CONFIG_IA64_SGI_SN1 */
+    struct pciio_win_map_s	bs_io_win_map;	/* I/O addr space */
+    struct pciio_win_map_s	bs_swin_map;	/* Small window addr space */
+    struct pciio_win_map_s	bs_mem_win_map;	/* Memory addr space */
+
+    int                   bs_bus_addr_status;    /* Bus space status */
+
+#define PCIBR_BUS_ADDR_MEM_FREED       1  /* Reserved PROM mem addr freed */
+#define PCIBR_BUS_ADDR_IO_FREED        2  /* Reserved PROM I/O addr freed */
 
     struct bs_errintr_stat_s {
 	uint32_t              bs_errcount_total;
@@ -437,13 +678,6 @@
 #define pcibr_soft_get(v)       ((pcibr_soft_t)hwgraph_fastinfo_get((v)))
 #define pcibr_soft_set(v,i)     (hwgraph_fastinfo_set((v), (arbitrary_info_t)(i)))
 
-/* Use io spin locks. This ensures that all the PIO writes from a particular
- * CPU to a particular IO device are synched before the start of the next
- * set of PIO operations to the same device.
- */
-#define pcibr_lock(pcibr_soft)		io_splock(&pcibr_soft->bs_lock)
-#define pcibr_unlock(pcibr_soft,s)	io_spunlock(&pcibr_soft->bs_lock,s)
-
 /*
  * mem alloc/free macros
  */
@@ -455,13 +689,37 @@
 #define NEW(ptr)	NEWA(ptr,1)
 #define DEL(ptr)	DELA(ptr,1)
 
-typedef volatile unsigned *cfg_p;
-typedef volatile bridgereg_t *reg_p;
+#ifndef CONFIG_IA64_SGI_SN1
+/*
+ * Additional PIO spaces per slot are
+ * recorded in this structure.
+ */
+struct pciio_piospace_s {
+    pciio_piospace_t        next;	/* another space for this device */
+    char                    free;	/* 1 if free, 0 if in use */
+    pciio_space_t           space;	/* Which space is in use */
+    iopaddr_t               start;	/* Starting address of the PIO space */
+    size_t                  count;	/* size of PIO space */
+};
+#endif	/* CONFIG_IA64_SGI_SN1 */
 
-#define PCIBR_RRB_SLOT_VIRTUAL  8
-#define PCIBR_VALID_SLOT(s)     (s < 8)
+/* Use io spin locks. This ensures that all the PIO writes from a particular
+ * CPU to a particular IO device are synched before the start of the next
+ * set of PIO operations to the same device.
+ */
+#ifdef PCI_LATER
+#define pcibr_lock(pcibr_soft)		io_splock(pcibr_soft->bs_lock)
+#define pcibr_unlock(pcibr_soft, s)	io_spunlock(pcibr_soft->bs_lock,s)
+#else
+#define pcibr_lock(pcibr_soft)		1
+#define pcibr_unlock(pcibr_soft, s)	
+#endif	/* PCI_LATER */
+
+#ifndef CONFIG_IA64_SGI_SN1
+#define PCIBR_VALID_SLOT(ps, s)     (s < PCIBR_NUM_SLOTS(ps))
 #define PCIBR_D64_BASE_UNSET    (0xFFFFFFFFFFFFFFFF)
 #define PCIBR_D32_BASE_UNSET    (0xFFFFFFFF)
+#endif
 #define INFO_LBL_PCIBR_ASIC_REV "_pcibr_asic_rev"
 
 #define PCIBR_SOFT_LIST 1
diff -Nru a/include/asm-ia64/sn/pci/pciio.h b/include/asm-ia64/sn/pci/pciio.h
--- a/include/asm-ia64/sn/pci/pciio.h	Mon Dec 23 21:21:50 2002
+++ b/include/asm-ia64/sn/pci/pciio.h	Mon Dec 23 21:21:50 2002
@@ -13,6 +13,7 @@
  * pciio.h -- platform-independent PCI interface
  */
 
+#include <linux/config.h>
 #include <asm/sn/ioerror.h>
 #include <asm/sn/driver.h>
 #include <asm/sn/hcl.h>
@@ -207,6 +208,9 @@
 typedef struct pciio_intr_s *pciio_intr_t;
 typedef struct pciio_info_s *pciio_info_t;
 typedef struct pciio_piospace_s *pciio_piospace_t;
+typedef struct pciio_win_info_s *pciio_win_info_t;
+typedef struct pciio_win_map_s *pciio_win_map_t;
+typedef struct pciio_win_alloc_s *pciio_win_alloc_t;
 
 /* PIO MANAGEMENT */
 
@@ -382,8 +386,13 @@
 typedef void
 pciio_intr_free_f       (pciio_intr_t intr_hdl);
 
+#ifdef CONFIG_IA64_SGI_SN1
 typedef int
 pciio_intr_connect_f    (pciio_intr_t intr_hdl);	/* pciio intr resource handle */
+#else
+typedef int
+pciio_intr_connect_f    (pciio_intr_t intr_hdl, intr_func_t intr_func, intr_arg_t intr_arg);	/* pciio intr resource handle */
+#endif
 
 typedef void
 pciio_intr_disconnect_f (pciio_intr_t intr_hdl);
@@ -627,6 +636,44 @@
 			devfs_handle_t pcicard,   /* vertex created by pciio_device_register */
                         int drv_flags);
 
+
+/* create and initialize empty window mapping resource */
+extern pciio_win_map_t
+pciio_device_win_map_new(pciio_win_map_t win_map,	/* preallocated win map structure */
+			 size_t region_size,		/* size of region to be tracked */
+			 size_t page_size);		/* allocation page size */
+
+/* destroy window mapping resource freeing up ancillary resources */
+extern void
+pciio_device_win_map_free(pciio_win_map_t win_map);	/* preallocated win map structure */
+
+/* populate window mapping with free range of addresses */
+extern void
+pciio_device_win_populate(pciio_win_map_t win_map,	/* win map */
+			  iopaddr_t ioaddr,		/* base address of free range */
+			  size_t size);			/* size of free range */
+
+/* allocate window from mapping resource */
+#ifdef CONFIG_IA64_SGI_SN1
+extern iopaddr_t
+pciio_device_win_alloc(pciio_win_map_t win_map,		/* win map */
+		       pciio_win_alloc_t win_alloc,	/* opaque allocation cookie */
+		       size_t size,			/* size of allocation */
+		       size_t align);			/* alignment of allocation */
+#else
+extern iopaddr_t
+pciio_device_win_alloc(pciio_win_map_t win_map,		/* win map */
+		       pciio_win_alloc_t win_alloc,	/* opaque allocation cookie */
+		       size_t start,			/* start unit, or 0 */
+		       size_t size,			/* size of allocation */
+		       size_t align);			/* alignment of allocation */
+#endif
+
+/* free previously allocated window */
+extern void
+pciio_device_win_free(pciio_win_alloc_t win_alloc);	/* opaque allocation cookie */
+
+
 /*
  * Generic PCI interface, for use with all PCI providers
  * and all PCI devices.
@@ -644,52 +691,6 @@
 extern ulong            pciio_pio_mapsz_get(pciio_piomap_t pciio_piomap);
 extern caddr_t          pciio_pio_kvaddr_get(pciio_piomap_t pciio_piomap);
 
-#ifdef LATER
-#ifdef USE_PCI_PIO
-extern uint8_t 		pciio_pio_read8(volatile uint8_t *addr);
-extern uint16_t 	pciio_pio_read16(volatile uint16_t *addr);
-extern uint32_t 	pciio_pio_read32(volatile uint32_t *addr);
-extern uint64_t 	pciio_pio_read64(volatile uint64_t *addr);
-extern void 		pciio_pio_write8(uint8_t val, volatile uint8_t *addr);
-extern void 		pciio_pio_write16(uint16_t val, volatile uint16_t *addr);
-extern void 		pciio_pio_write32(uint32_t val, volatile uint32_t *addr);
-extern void 		pciio_pio_write64(uint64_t val, volatile uint64_t *addr);
-#else /* !USE_PCI_PIO */
-__inline uint8_t pciio_pio_read8(volatile uint8_t *addr)
-{ 
-	return *addr; 
-}
-__inline uint16_t pciio_pio_read16(volatile uint16_t *addr)
-{
-	return *addr; 
-}
-__inline uint32_t pciio_pio_read32(volatile uint32_t *addr)
-{
-	return *addr; 
-}
-__inline uint64_t pciio_pio_read64(volatile uint64_t *addr)
-{
-	return *addr;
-}
-__inline void pciio_pio_write8(uint8_t val, volatile uint8_t *addr)
-{
-	*addr = val;
-}
-__inline void pciio_pio_write16(uint16_t val, volatile uint16_t *addr)
-{
-	*addr = val;
-}
-__inline void pciio_pio_write32(uint32_t val, volatile uint32_t *addr)
-{
-	*addr = val;
-}
-__inline void pciio_pio_write64(uint64_t val, volatile uint64_t *addr)
-{
-	*addr = val;
-}
-#endif /* USE_PCI_PIO */
-#endif	/* LATER */
-
 /* Generic PCI dma interfaces */
 extern devfs_handle_t     pciio_dma_dev_get(pciio_dmamap_t pciio_dmamap);
 
@@ -701,8 +702,10 @@
 /* Generic pci slot information access interface */
 extern pciio_info_t     pciio_info_chk(devfs_handle_t vhdl);
 extern pciio_info_t     pciio_info_get(devfs_handle_t vhdl);
+extern pciio_info_t     pciio_hostinfo_get(devfs_handle_t vhdl);
 extern void             pciio_info_set(devfs_handle_t vhdl, pciio_info_t widget_info);
 extern devfs_handle_t     pciio_info_dev_get(pciio_info_t pciio_info);
+extern devfs_handle_t     pciio_info_hostdev_get(pciio_info_t pciio_info);
 extern pciio_bus_t	pciio_info_bus_get(pciio_info_t pciio_info);
 extern pciio_slot_t     pciio_info_slot_get(pciio_info_t pciio_info);
 extern pciio_function_t	pciio_info_function_get(pciio_info_t pciio_info);
@@ -718,7 +721,7 @@
 extern size_t		pciio_info_bar_size_get(pciio_info_t, int);
 extern iopaddr_t	pciio_info_rom_base_get(pciio_info_t);
 extern size_t		pciio_info_rom_size_get(pciio_info_t);
-
+extern int		pciio_info_type1_get(pciio_info_t);
 extern int              pciio_error_handler(devfs_handle_t, int, ioerror_mode_t, ioerror_t *);
 extern int		pciio_dma_enabled(devfs_handle_t);
 
diff -Nru a/include/asm-ia64/sn/pci/pciio_private.h b/include/asm-ia64/sn/pci/pciio_private.h
--- a/include/asm-ia64/sn/pci/pciio_private.h	Mon Dec 23 21:21:55 2002
+++ b/include/asm-ia64/sn/pci/pciio_private.h	Mon Dec 23 21:21:55 2002
@@ -10,6 +10,7 @@
 #define _ASM_SN_PCI_PCIIO_PRIVATE_H
 
 #include <asm/sn/pci/pciio.h>
+#include <asm/sn/pci/pci_defs.h>
 
 /*
  * pciio_private.h -- private definitions for pciio
@@ -49,6 +50,8 @@
     devfs_handle_t            pi_dev;	/* associated pci card */
     device_desc_t	    pi_dev_desc;	/* override device descriptor */
     pciio_intr_line_t       pi_lines;	/* which interrupt line(s) */
+    intr_func_t             pi_func;	/* handler function (when connected) */
+    intr_arg_t              pi_arg;	/* handler parameter (when connected) */
     cpuid_t                 pi_mustruncpu; /* Where we must run. */
     int                     pi_irq;     /* IRQ assigned */
     int                     pi_cpu;     /* cpu assigned */
@@ -59,6 +62,39 @@
 #define PCIIO_INTR_NOTHREAD	2	/* interrupt handler wants to be called at interrupt level */
 
 /*
+ * Some PCI provider implementations keep track of PCI window Base Address
+ * Register (BAR) address range assignment via the rmalloc()/rmfree() arena
+ * management routines.  These implementations use the following data
+ * structure for each allocation address space (e.g. memory, I/O, small
+ * window, etc.).
+ *
+ * The ``page size'' encodes the minimum allocation unit and must be a power
+ * of 2.  The main use of this allocation ``page size'' is to control the
+ * number of free address ranges that the mapping allocation software will
+ * need to track.  Smaller values will allow more efficient use of the address
+ * ranges but will result in much larger allocation map structures ...  For
+ * instance, if we want to manage allocations for a 256MB address range,
+ * choosing a 1MB allocation page size will result in up to 1MB being wasted
+ * for allocation requests smaller than 1MB.  The worst case allocation
+ * pattern for the allocation software to track would be a pattern of 1MB
+ * allocated, 1MB free.  This results in the need to track up to 128 free
+ * ranges.
+ */
+struct pciio_win_map_s {
+	struct map	*wm_map;	/* window address map */
+	int		wm_page_size;	/* allocation ``page size'' */
+};
+
+/*
+ * Opaque structure used to keep track of window allocation information.
+ */
+struct pciio_win_alloc_s {
+	pciio_win_map_t	wa_map;		/* window map allocation is from */
+	unsigned long	wa_base;	/* allocation starting page number */
+	size_t		wa_pages;	/* number of pages in allocation */
+};
+
+/*
  * Each PCI Card has one of these.
  */
 
@@ -76,17 +112,17 @@
     error_handler_f        *c_efunc;	/* error handling function */
     error_handler_arg_t     c_einfo;	/* first parameter for efunc */
 
-    struct {				/* state of BASE regs */
-	pciio_space_t		w_space;
-	iopaddr_t		w_base;
-	size_t			w_size;
-        int                     w_devio_index;  /* DevIO[] register used to
-                                                   access this window */
-    }			    c_window[6];
-
-    unsigned		    c_rbase;	/* EXPANSION ROM base addr */
-    unsigned		    c_rsize;	/* EXPANSION ROM size (bytes) */
-
+    struct pciio_win_info_s {           /* state of BASE regs */
+        pciio_space_t           w_space;
+        iopaddr_t               w_base;
+        size_t                  w_size;
+        int                     w_devio_index;   /* DevIO[] register used to
+                                                    access this window */
+	struct pciio_win_alloc_s w_win_alloc;    /* window allocation cookie */
+    }                       c_window[PCI_CFG_BASE_ADDRS + 1];
+#define c_rwindow	c_window[PCI_CFG_BASE_ADDRS]	/* EXPANSION ROM window */
+#define c_rbase		c_rwindow.w_base		/* EXPANSION ROM base addr */
+#define c_rsize		c_rwindow.w_size		/* EXPANSION ROM size (bytes) */
     pciio_piospace_t	    c_piospace;	/* additional I/O spaces allocated */
 };
 
diff -Nru a/include/asm-ia64/sn/pda.h b/include/asm-ia64/sn/pda.h
--- a/include/asm-ia64/sn/pda.h	Mon Dec 23 21:22:00 2002
+++ b/include/asm-ia64/sn/pda.h	Mon Dec 23 21:22:00 2002
@@ -10,6 +10,7 @@
 
 #include <linux/config.h>
 #include <linux/cache.h>
+#include <asm/percpu.h>
 #include <asm/system.h>
 #include <asm/processor.h>
 #include <asm/page.h>
@@ -25,7 +26,14 @@
  * all SN per-cpu data structures. 
  */
 
-
+#ifdef BUS_INT_WAR
+#define POLL_ENTRIES	50
+typedef struct {
+	int	irq;
+	int	interval;
+	short	tick;
+} sn_poll_entry_t;
+#endif
 
 typedef struct pda_s {
 
@@ -38,11 +46,15 @@
 	struct subnodepda_s *p_subnodepda;	/* Pointer to CPU  subnode PDA */
 
 	/*
-	 * Support for blinking SN LEDs
+	 * Support for SN LEDs
 	 */
-	long		*led_address;
+#ifdef CONFIG_IA64_SGI_SN1
+	volatile long	*led_address;
+#else
+	volatile short	*led_address;
+#endif
 	u8		led_state;
-	char		hb_state;	/* supports blinking heartbeat leds */
+	u8		hb_state;	/* supports blinking heartbeat leds */
 	unsigned int	hb_count;
 
 	unsigned int	idle_flag;
@@ -52,8 +64,15 @@
 #endif
 	volatile unsigned long *bedrock_rev_id;
 	volatile unsigned long *pio_write_status_addr;
+	volatile unsigned long *pio_shub_war_cam_addr;
+	volatile unsigned long *mem_write_status_addr;
 
-	bteinfo_t *cpubte[BTES_PER_NODE];
+	bteinfo_t *cpu_bte_if[BTES_PER_NODE];	/* cpu interface order */
+
+#ifdef BUS_INT_WAR
+	sn_poll_entry_t	pda_poll_entries[POLL_ENTRIES];
+	int		pda_poll_entry_count;
+#endif
 } pda_t;
 
 
@@ -71,10 +90,11 @@
  * size of the cpu_data area dont change cache layout. Should we align to 32, 64, 128
  * or 512 boundary. Each has merits. For now, pick 128 but should be revisited later.
  */
-#define CPU_DATA_END	CACHE_ALIGN((long)&(((struct cpuinfo_ia64*)0)->platform_specific))
-#define PDAADDR		(PERCPU_ADDR+CPU_DATA_END)
+DECLARE_PER_CPU(struct pda_s, pda_percpu);
+
+#define pda		(&__get_cpu_var(pda_percpu))
 
-#define pda		(*((pda_t *) PDAADDR))
+#define pdacpu(cpu)	(&per_cpu(pda_percpu, cpu))
 
 
 #endif /* _ASM_IA64_SN_PDA_H */
diff -Nru a/include/asm-ia64/sn/sgi.h b/include/asm-ia64/sn/sgi.h
--- a/include/asm-ia64/sn/sgi.h	Mon Dec 23 21:21:50 2002
+++ b/include/asm-ia64/sn/sgi.h	Mon Dec 23 21:21:50 2002
@@ -18,82 +18,6 @@
 #include <linux/mm.h>
 #include <linux/devfs_fs_kernel.h>
 
-// This devfs stuff needs a better home .....
-
-struct directory_type
-{
-    struct devfs_entry *first;
-    struct devfs_entry *last;
-    unsigned int num_removable;
-};
-
-struct file_type
-{
-    unsigned long size;
-};
-
-struct device_type
-{
-    unsigned short major;
-    unsigned short minor;
-};
-
-struct fcb_type  /*  File, char, block type  */
-{
-    uid_t default_uid;
-    gid_t default_gid;
-    void *ops;
-    union 
-    {
-	struct file_type file;
-	struct device_type device;
-    }
-    u;
-    unsigned char auto_owner:1;
-    unsigned char aopen_notify:1;
-    unsigned char removable:1;  /*  Belongs in device_type, but save space   */
-    unsigned char open:1;       /*  Not entirely correct                     */
-};
-
-struct symlink_type
-{
-    unsigned int length;  /*  Not including the NULL-termimator  */
-    char *linkname;       /*  This is NULL-terminated            */
-};
-
-struct fifo_type
-{
-    uid_t uid;
-    gid_t gid;
-};
-
-struct devfs_entry
-{
-    void *info;
-    union 
-    {
-	struct directory_type dir;
-	struct fcb_type fcb;
-	struct symlink_type symlink;
-	struct fifo_type fifo;
-    }
-    u;
-    struct devfs_entry *prev;    /*  Previous entry in the parent directory  */
-    struct devfs_entry *next;    /*  Next entry in the parent directory      */
-    struct devfs_entry *parent;  /*  The parent directory                    */
-    struct devfs_entry *slave;   /*  Another entry to unregister             */
-    struct devfs_inode *first_inode;
-    struct devfs_inode *last_inode;
-    umode_t mode;
-    unsigned short namelen;  /*  I think 64k+ filenames are a way off...  */
-    unsigned char registered:1;
-    unsigned char show_unreg:1;
-    unsigned char hide:1;
-    unsigned char no_persistence /*:1*/;
-    char name[1];            /*  This is just a dummy: the allocated array is
-				 bigger. This is NULL-terminated  */
-};
-
 typedef int64_t  __psint_t;	/* needed by klgraph.c */
 
 typedef enum { B_FALSE, B_TRUE } boolean_t;
@@ -222,6 +146,31 @@
 #else
 #define cpu_enabled(cpu)	(1)
 #endif
+
+/* print_register() defs */
+
+/*
+ * register values
+ * map between numeric values and symbolic values
+ */
+struct reg_values {
+	unsigned long long rv_value;
+	char *rv_name;
+};
+
+/*
+ * register descriptors are used for formatted prints of register values
+ * rd_mask and rd_shift must be defined, other entries may be null
+ */
+struct reg_desc {
+	unsigned long long rd_mask;	/* mask to extract field */
+	int rd_shift;		/* shift for extracted value, - >>, + << */
+	char *rd_name;		/* field name */
+	char *rd_format;	/* format to print field */
+	struct reg_values *rd_values;	/* symbolic names of values */
+};
+
+extern void print_register(unsigned long long, struct reg_desc *);
 
 #include <asm/sn/hack.h>	/* for now */
 
diff -Nru a/include/asm-ia64/sn/sn1/addrs.h b/include/asm-ia64/sn/sn1/addrs.h
--- a/include/asm-ia64/sn/sn1/addrs.h	Mon Dec 23 21:21:54 2002
+++ b/include/asm-ia64/sn/sn1/addrs.h	Mon Dec 23 21:21:54 2002
@@ -41,7 +41,8 @@
  * use some new ANSI preprocessor stuff to paste these on where needed.
  */
 
-#define CAC_BASE                0xe000000000000000
+#define CACHEABLE_MEM_SPACE     0xe000000000000000
+#define CAC_BASE		CACHEABLE_MEM_SPACE
 #define HSPEC_BASE              0xc0000b0000000000
 #define HSPEC_SWIZ_BASE         0xc000030000000000
 #define IO_BASE                 0xc0000a0000000000
diff -Nru a/include/asm-ia64/sn/sn1/intr.h b/include/asm-ia64/sn/sn1/intr.h
--- a/include/asm-ia64/sn/sn1/intr.h	Mon Dec 23 21:21:52 2002
+++ b/include/asm-ia64/sn/sn1/intr.h	Mon Dec 23 21:21:52 2002
@@ -1,4 +1,4 @@
-/* $Id$
+/* $Id: intr.h,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
diff -Nru a/include/asm-ia64/sn/sn1/intr_public.h b/include/asm-ia64/sn/sn1/intr_public.h
--- a/include/asm-ia64/sn/sn1/intr_public.h	Mon Dec 23 21:21:59 2002
+++ b/include/asm-ia64/sn/sn1/intr_public.h	Mon Dec 23 21:21:59 2002
@@ -1,4 +1,4 @@
-/* $Id$
+/* $Id: intr_public.h,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
diff -Nru a/include/asm-ia64/sn/sn1/mmzone_sn1.h b/include/asm-ia64/sn/sn1/mmzone_sn1.h
--- a/include/asm-ia64/sn/sn1/mmzone_sn1.h	Mon Dec 23 21:22:00 2002
+++ b/include/asm-ia64/sn/sn1/mmzone_sn1.h	Mon Dec 23 21:22:00 2002
@@ -98,7 +98,7 @@
  * absent. Each node consists of a number of possibly discontiguous chunks.
  */
 #define SN1_CHUNKSHIFT			26			/* 64 MB */
-#define SN1_CHUNKSIZE			(1UL << SN1_CHUNKSHIFT)
+#define PLAT_CHUNKSIZE			(1UL << SN1_CHUNKSHIFT)
 #define PLAT_CHUNKNUM(addr)		(((addr) & (PLAT_MAX_PHYS_MEMORY-1)) >> SN1_CHUNKSHIFT)
 
 
@@ -134,8 +134,8 @@
  * This macro takes an address of the end of previous allocation, rounds it to a page boundary & 
  * changes the node number.
  */
-#define PLAT_BOOTMEM_ALLOC_GOAL(cnode,kaddr)	SN1_KADDR(PLAT_PXM_TO_PHYS_NODE_NUMBER(nid_to_pxm_map[cnodeid]),	\
-						  (SN1_NODE_OFFSET(kaddr) + PAGE_SIZE - 1) >> PAGE_SHIFT << PAGE_SHIFT)
+#define PLAT_BOOTMEM_ALLOC_GOAL(cnode,kaddr)	__pa(SN1_KADDR(PLAT_PXM_TO_PHYS_NODE_NUMBER(nid_to_pxm_map[cnode]),		\
+						  (SN1_NODE_OFFSET(kaddr) + PAGE_SIZE - 1) >> PAGE_SHIFT << PAGE_SHIFT))
 
 
 
diff -Nru a/include/asm-ia64/sn/sn1/sn_private.h b/include/asm-ia64/sn/sn1/sn_private.h
--- a/include/asm-ia64/sn/sn1/sn_private.h	Mon Dec 23 21:21:53 2002
+++ b/include/asm-ia64/sn/sn1/sn_private.h	Mon Dec 23 21:21:53 2002
@@ -1,4 +1,4 @@
-/* $Id$
+/* $Id: sn_private.h,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
diff -Nru a/include/asm-ia64/sn/sn1/synergy.h b/include/asm-ia64/sn/sn1/synergy.h
--- a/include/asm-ia64/sn/sn1/synergy.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-ia64/sn/sn1/synergy.h	Mon Dec 23 21:21:51 2002
@@ -54,9 +54,6 @@
 
 #define WRITE_LOCAL_SYNERGY_REG(addr, value)	__synergy_out(addr, value)
 
-#define HUB_L(_a)               *(_a)
-#define HUB_S(_a, _d)           *(_a) = (_d)
-
 #define HSPEC_SYNERGY0_0        0x04000000    /* Synergy0 Registers     */
 #define HSPEC_SYNERGY1_0        0x05000000    /* Synergy1 Registers     */
 #define HS_SYNERGY_STRIDE       (HSPEC_SYNERGY1_0 - HSPEC_SYNERGY0_0)
diff -Nru a/include/asm-ia64/sn/sn2/addrs.h b/include/asm-ia64/sn/sn2/addrs.h
--- a/include/asm-ia64/sn/sn2/addrs.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-ia64/sn/sn2/addrs.h	Mon Dec 23 21:21:51 2002
@@ -4,7 +4,7 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  *
- * Copyright (c) 2001 Silicon Graphics, Inc.  All rights reserved.
+ * Copyright (c) 2001-2002 Silicon Graphics, Inc.  All rights reserved.
  */
 
 #ifndef _ASM_IA64_SN_SN2_ADDRS_H
@@ -53,19 +53,26 @@
 
 /* Regions determined by AS */
 #define LOCAL_MMR_SPACE		0xc000008000000000	/* Local MMR space */
+#define LOCAL_PHYS_MMR_SPACE	0x8000008000000000	/* Local PhysicalMMR space */
 #define LOCAL_MEM_SPACE		0xc000010000000000	/* Local Memory space */
 #define GLOBAL_MMR_SPACE	0xc000000800000000	/* Global MMR space */
+#define GLOBAL_PHYS_MMR_SPACE	0x0000000800000000	/* Global Physical MMR space */
 #define GET_SPACE		0xc000001000000000	/* GET space */
 #define AMO_SPACE		0xc000002000000000	/* AMO space */
 #define CACHEABLE_MEM_SPACE	0xe000003000000000	/* Cacheable memory space */
 #define UNCACHED                0xc000000000000000      /* UnCacheable memory space */
+#define UNCACHED_PHYS           0x8000000000000000      /* UnCacheable physical memory space */
+
+#define PHYS_MEM_SPACE		0x0000003000000000	/* physical memory space */
 
 /* SN2 address macros */
 #define NID_SHFT		38
 #define LOCAL_MMR_ADDR(a)	(UNCACHED | LOCAL_MMR_SPACE | (a))
+#define LOCAL_MMR_PHYS_ADDR(a)	(UNCACHED_PHYS | LOCAL_PHYS_MMR_SPACE | (a))
 #define LOCAL_MEM_ADDR(a)	(LOCAL_MEM_SPACE | (a))
 #define REMOTE_ADDR(n,a)	((((unsigned long)(n))<<NID_SHFT) | (a))
 #define GLOBAL_MMR_ADDR(n,a)	(UNCACHED | GLOBAL_MMR_SPACE | REMOTE_ADDR(n,a))
+#define GLOBAL_MMR_PHYS_ADDR(n,a) (UNCACHED_PHYS | GLOBAL_PHYS_MMR_SPACE | REMOTE_ADDR(n,a))
 #define GET_ADDR(n,a)		(GET_SPACE | REMOTE_ADDR(n,a))
 #define AMO_ADDR(n,a)		(UNCACHED | AMO_SPACE | REMOTE_ADDR(n,a))
 #define GLOBAL_MEM_ADDR(n,a)	(CACHEABLE_MEM_SPACE | REMOTE_ADDR(n,a))
@@ -104,8 +111,18 @@
 #define NASID_MASK              (UINT64_CAST NASID_BITMASK << NASID_SHFT)
 #define NASID_GET(_pa)          (int) ((UINT64_CAST (_pa) >>            \
                                         NASID_SHFT) & NASID_BITMASK)
+#define PHYS_TO_DMA(x)          ( ((x & NASID_MASK) >> 2) |             \
+                                  (x & (NODE_ADDRSPACE_SIZE - 1)) )
 
 #define CHANGE_NASID(n,x)	({ia64_sn2_pa_t _v; _v.l = (long) (x); _v.f.nasid = n; _v.p;})
+
+/*
+ * Determine if a physical address should be referenced as cached or uncached. 
+ * For now, assume all memory is cached and everything else is noncached.
+ * (Later, we may need to special case areas of memory to be reference uncached).
+ */
+#define IS_CACHED_ADDRESS(x)	(((x) & PHYS_MEM_SPACE) == PHYS_MEM_SPACE)
+
 
 #ifndef __ASSEMBLY__
 #define NODE_SWIN_BASE(nasid, widget)                                   \
diff -Nru a/include/asm-ia64/sn/sn2/arch.h b/include/asm-ia64/sn/sn2/arch.h
--- a/include/asm-ia64/sn/sn2/arch.h	Mon Dec 23 21:21:53 2002
+++ b/include/asm-ia64/sn/sn2/arch.h	Mon Dec 23 21:21:53 2002
@@ -1,4 +1,4 @@
-/* $Id$
+/* $Id: arch.h,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
@@ -60,7 +60,5 @@
 #define LOCALCPU(slice)	(((slice) & LOCALCPU_MASK) >> LOCALCPU_SHFT)
 #define TO_SLICE(subn, local)	(((subn) << SUBNODE_SHFT) | \
 				 ((local) << LOCALCPU_SHFT))
-
-typedef u64 mmr_t;
 
 #endif /* _ASM_IA64_SN_SN2_ARCH_H */
diff -Nru a/include/asm-ia64/sn/sn2/intr.h b/include/asm-ia64/sn/sn2/intr.h
--- a/include/asm-ia64/sn/sn2/intr.h	Mon Dec 23 21:21:59 2002
+++ b/include/asm-ia64/sn/sn2/intr.h	Mon Dec 23 21:21:59 2002
@@ -1,4 +1,4 @@
-/* $Id$
+/* $Id: intr.h,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
@@ -13,13 +13,15 @@
 #define SGI_SHUB_ERROR_VECTOR   (0xea)
 
 // These two IRQ's are used by partitioning.
+#define SGI_XPC_ACTIVATE		(0x30)
 #define SGI_XPC_NOTIFY			(0xe7)
-#define SGI_XPART_ACTIVATE		(0x30)
 
 #define IA64_SN2_FIRST_DEVICE_VECTOR	(0x31)
 #define IA64_SN2_LAST_DEVICE_VECTOR	(0xe6)
 
 #define SN2_IRQ_RESERVED        (0x1)
 #define SN2_IRQ_CONNECTED       (0x2)
+
+#define SN2_IRQ_PER_HUB         (2048)
 
 #endif /* _ASM_IA64_SN_SN2_INTR_H */
diff -Nru a/include/asm-ia64/sn/sn2/mmzone_sn2.h b/include/asm-ia64/sn/sn2/mmzone_sn2.h
--- a/include/asm-ia64/sn/sn2/mmzone_sn2.h	Mon Dec 23 21:22:00 2002
+++ b/include/asm-ia64/sn/sn2/mmzone_sn2.h	Mon Dec 23 21:22:00 2002
@@ -103,7 +103,7 @@
  * absent. Each node consists of a number of possibly contiguous chunks.
  */
 #define SN2_CHUNKSHIFT			25			/* 32 MB */
-#define SN2_CHUNKSIZE			(1UL << SN2_CHUNKSHIFT)
+#define PLAT_CHUNKSIZE			(1UL << SN2_CHUNKSHIFT)
 #define PLAT_CHUNKNUM(addr)		({unsigned long _p=(unsigned long)(addr);		\
 						(((_p&SN2_NODE_MASK)>>2) | 			\
 						(_p&SN2_NODE_OFFSET_MASK)) >>SN2_CHUNKSHIFT;})
@@ -141,8 +141,8 @@
  * This macro takes an address of the end of previous allocation, rounds it to a page boundary & 
  * changes the node number.
  */
-#define PLAT_BOOTMEM_ALLOC_GOAL(cnode,kaddr)	SN2_KADDR(PLAT_PXM_TO_PHYS_NODE_NUMBER(nid_to_pxm_map[cnodeid]),       \
-						 (SN2_NODE_OFFSET(kaddr) + PAGE_SIZE - 1) >> PAGE_SHIFT << PAGE_SHIFT)
+#define PLAT_BOOTMEM_ALLOC_GOAL(cnode,kaddr)	__pa(SN2_KADDR(PLAT_PXM_TO_PHYS_NODE_NUMBER(nid_to_pxm_map[cnode]),	       \
+						 (SN2_NODE_OFFSET(kaddr) + PAGE_SIZE - 1) >> PAGE_SHIFT << PAGE_SHIFT))
 
 
 
diff -Nru a/include/asm-ia64/sn/sn2/shubio.h b/include/asm-ia64/sn/sn2/shubio.h
--- a/include/asm-ia64/sn/sn2/shubio.h	Mon Dec 23 21:21:54 2002
+++ b/include/asm-ia64/sn/sn2/shubio.h	Mon Dec 23 21:21:54 2002
@@ -1,4 +1,4 @@
-/* $Id$
+/* $Id: shubio.h,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  *
  * 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
@@ -493,8 +493,8 @@
 		shubreg_t       i_rsvd_3                  :      4;
 		shubreg_t	i_enable		  :	 1;
 		shubreg_t	i_rsvd_2		  :	 3;
-		shubreg_t	i_int_sent		  :	 1;
-		shubreg_t       i_rsvd_1                  :      3;
+		shubreg_t	i_int_sent		  :	 2;
+		shubreg_t       i_rsvd_1                  :      2;
 		shubreg_t	i_pi0_forward_int	  :	 1;
 		shubreg_t	i_pi1_forward_int	  :	 1;
 		shubreg_t	i_rsvd			  :	30;
@@ -3089,11 +3089,11 @@
         #define IIO_FIRST_PC_ENTRY 12
  */
 
-#define IIO_ICRB_A(_x)  (IIO_ICRB_0 + (6 * IIO_ICRB_OFFSET * (_x)))
-#define IIO_ICRB_B(_x)  (IIO_ICRB_A(_x) + 1*IIO_ICRB_OFFSET)
-#define IIO_ICRB_C(_x)  (IIO_ICRB_A(_x) + 2*IIO_ICRB_OFFSET)
-#define IIO_ICRB_D(_x)  (IIO_ICRB_A(_x) + 3*IIO_ICRB_OFFSET)
-#define IIO_ICRB_E(_x)  (IIO_ICRB_A(_x) + 4*IIO_ICRB_OFFSET)
+#define IIO_ICRB_A(_x)  ((u64)(IIO_ICRB_0 + (6 * IIO_ICRB_OFFSET * (_x))))
+#define IIO_ICRB_B(_x)  ((u64)((char *)IIO_ICRB_A(_x) + 1*IIO_ICRB_OFFSET))
+#define IIO_ICRB_C(_x)  ((u64)((char *)IIO_ICRB_A(_x) + 2*IIO_ICRB_OFFSET))
+#define IIO_ICRB_D(_x)  ((u64)((char *)IIO_ICRB_A(_x) + 3*IIO_ICRB_OFFSET))
+#define IIO_ICRB_E(_x)  ((u64)((char *)IIO_ICRB_A(_x) + 4*IIO_ICRB_OFFSET))
 
 #define TNUM_TO_WIDGET_DEV(_tnum)	(_tnum & 0x7)
 
@@ -3288,12 +3288,9 @@
 #ifndef __ASSEMBLY__
 
 /*
- * Easy access macros for CRBs, all 4 registers (A-D)
+ * Easy access macros for CRBs, all 5 registers (A-E)
  */
 typedef ii_icrb0_a_u_t icrba_t;
-#define a_lnetuce       ii_icrb0_a_fld_s.ia_ln_uce
-#define a_mark          ii_icrb0_a_fld_s.ia_mark
-#define a_xerr          ii_icrb0_a_fld_s.ia_xt_err
 #define a_sidn          ii_icrb0_a_fld_s.ia_sidn
 #define a_tnum          ii_icrb0_a_fld_s.ia_tnum
 #define a_addr          ii_icrb0_a_fld_s.ia_addr
@@ -3302,35 +3299,56 @@
 #define a_regvalue	ii_icrb0_a_regval
 
 typedef ii_icrb0_b_u_t icrbb_t;
-#define b_error         ii_icrb0_b_fld_s.ib_error
-#define b_ecode         ii_icrb0_b_fld_s.ib_errcode
-#define b_cohtrans      ii_icrb0_b_fld_s.ib_ct
-#define b_xtsize        ii_icrb0_b_fld_s.ib_size
-#define b_source        ii_icrb0_b_fld_s.ib_source
+#define b_use_old       ii_icrb0_b_fld_s.ib_use_old
 #define b_imsgtype      ii_icrb0_b_fld_s.ib_imsgtype
 #define b_imsg          ii_icrb0_b_fld_s.ib_imsg
 #define b_initiator     ii_icrb0_b_fld_s.ib_init
+#define b_exc           ii_icrb0_b_fld_s.ib_exc
+#define b_ackcnt        ii_icrb0_b_fld_s.ib_ack_cnt
+#define b_resp          ii_icrb0_b_fld_s.ib_resp
+#define b_ack           ii_icrb0_b_fld_s.ib_ack
+#define b_hold          ii_icrb0_b_fld_s.ib_hold
+#define b_wb            ii_icrb0_b_fld_s.ib_wb
+#define b_intvn         ii_icrb0_b_fld_s.ib_intvn
+#define b_stall_ib      ii_icrb0_b_fld_s.ib_stall_ib
+#define b_stall_int     ii_icrb0_b_fld_s.ib_stall__intr
+#define b_stall_bte_0   ii_icrb0_b_fld_s.ib_stall__bte_0
+#define b_stall_bte_1   ii_icrb0_b_fld_s.ib_stall__bte_1
+#define b_error         ii_icrb0_b_fld_s.ib_error
+#define b_ecode         ii_icrb0_b_fld_s.ib_errcode
+#define b_lnetuce       ii_icrb0_b_fld_s.ib_ln_uce
+#define b_mark          ii_icrb0_b_fld_s.ib_mark
+#define b_xerr          ii_icrb0_b_fld_s.ib_xt_err
 #define b_regvalue	ii_icrb0_b_regval
 
 typedef ii_icrb0_c_u_t icrbc_t;
-#define c_btenum        ii_icrb0_c_fld_s.ic_bte_num
-#define c_pricnt        ii_icrb0_c_fld_s.ic_pr_cnt
-#define c_pripsc        ii_icrb0_c_fld_s.ic_pr_psc
-#define c_bteaddr       ii_icrb0_c_fld_s.ic_pa_be /* ic_pa_be fld has 2 names*/
-#define c_benable       ii_icrb0_c_fld_s.ic_pa_be /* ic_pa_be fld has 2 names*/
 #define c_suppl         ii_icrb0_c_fld_s.ic_suppl
 #define c_barrop        ii_icrb0_c_fld_s.ic_bo
 #define c_doresp        ii_icrb0_c_fld_s.ic_resprqd
 #define c_gbr           ii_icrb0_c_fld_s.ic_gbr
+#define c_btenum        ii_icrb0_c_fld_s.ic_bte_num
+#define c_cohtrans      ii_icrb0_c_fld_s.ic_ct
+#define c_xtsize        ii_icrb0_c_fld_s.ic_size
+#define c_source        ii_icrb0_c_fld_s.ic_source
 #define c_regvalue	ii_icrb0_c_regval
 
+
 typedef ii_icrb0_d_u_t icrbd_t;
+#define d_sleep         ii_icrb0_d_fld_s.id_sleep
+#define d_pricnt        ii_icrb0_d_fld_s.id_pr_cnt
+#define d_pripsc        ii_icrb0_d_fld_s.id_pr_psc
 #define d_bteop         ii_icrb0_d_fld_s.id_bte_op
-#define icrbd_ctxtvld   ii_icrb0_d_fld_s.id_cvld
-#define icrbd_toutvld   ii_icrb0_d_fld_s.id_tvld
-#define icrbd_context   ii_icrb0_d_fld_s.id_context
+#define d_bteaddr       ii_icrb0_d_fld_s.id_pa_be /* ic_pa_be fld has 2 names*/
+#define d_benable       ii_icrb0_d_fld_s.id_pa_be /* ic_pa_be fld has 2 names*/
 #define d_regvalue	ii_icrb0_d_regval
 
+typedef ii_icrb0_e_u_t icrbe_t;
+#define icrbe_ctxtvld   ii_icrb0_e_fld_s.ie_cvld
+#define icrbe_toutvld   ii_icrb0_e_fld_s.ie_tvld
+#define icrbe_context   ii_icrb0_e_fld_s.ie_context
+#define icrbe_timeout   ii_icrb0_e_fld_s.ie_timeout
+#define e_regvalue	ii_icrb0_e_regval
+
 #endif /* __ASSEMBLY__ */
 
 /* Number of widgets supported by shub */
@@ -3391,15 +3409,15 @@
 
 /* IO Interrupt Destination Register */
 #define IIO_IIDSR_SENT_SHIFT    28
-#define IIO_IIDSR_SENT_MASK     0x10000000
+#define IIO_IIDSR_SENT_MASK     0x30000000
 #define IIO_IIDSR_ENB_SHIFT     24
 #define IIO_IIDSR_ENB_MASK      0x01000000
-#define IIO_IIDSR_NODE_SHIFT    8
-#define IIO_IIDSR_NODE_MASK     0x0000ff00
+#define IIO_IIDSR_NODE_SHIFT    9
+#define IIO_IIDSR_NODE_MASK     0x000ff700
 #define IIO_IIDSR_PI_ID_SHIFT   8
-#define IIO_IIDSR_PI_ID_MASK    0x00000010
+#define IIO_IIDSR_PI_ID_MASK    0x00000100
 #define IIO_IIDSR_LVL_SHIFT     0
-#define IIO_IIDSR_LVL_MASK      0x0000007f
+#define IIO_IIDSR_LVL_MASK      0x000000ff
 
 /* Xtalk timeout threshhold register (IIO_IXTT) */
 #define IXTT_RRSP_TO_SHFT	55	   /* read response timeout */
@@ -3570,8 +3588,9 @@
 
 extern int
 hub_intr_connect(       hub_intr_t intr_hdl,    /* xtalk intr resource hndl */
-                        xtalk_intr_setfunc_t setfunc,
-                                                /* func to set intr hw */
+			intr_func_t intr_func,          /* xtalk intr handler */
+			void *intr_arg,                 /* arg to intr handler */
+                        xtalk_intr_setfunc_t setfunc, /* func to set intr hw */
                         void *setfunc_arg);     /* arg to setfunc */
 
 extern void
diff -Nru a/include/asm-ia64/sn/sn2/sn_private.h b/include/asm-ia64/sn/sn2/sn_private.h
--- a/include/asm-ia64/sn/sn2/sn_private.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-ia64/sn/sn2/sn_private.h	Mon Dec 23 21:21:51 2002
@@ -1,4 +1,4 @@
-/* $Id$
+/* $Id: sn_private.h,v 1.1 2002/02/28 17:31:26 marcelo Exp $
  *
  * 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
@@ -27,7 +27,7 @@
 extern nasid_t get_console_nasid(void);
 extern char get_console_pcislot(void);
 
-extern int is_master_nasid_widget(nasid_t test_nasid, xwidgetnum_t test_wid);
+extern int is_master_baseio_nasid_widget(nasid_t test_nasid, xwidgetnum_t test_wid);
 
 /* memsupport.c */
 extern void poison_state_alter_range(__psunsigned_t start, int len, int poison);
@@ -43,8 +43,10 @@
 extern void set_dir_state_UNOWNED(paddr_t);
 extern int is_POISONED_dir_state(paddr_t);
 extern int is_UNOWNED_dir_state(paddr_t);
+#ifdef LATER
 extern void get_dir_ent(paddr_t paddr, int *state,
 			uint64_t *vec_ptr, hubreg_t *elo);
+#endif
 
 /* intr.c */
 extern int intr_reserve_level(cpuid_t cpu, int level, int err, devfs_handle_t owner_dev, char *name);
diff -Nru a/include/asm-ia64/sn/sn_cpuid.h b/include/asm-ia64/sn/sn_cpuid.h
--- a/include/asm-ia64/sn/sn_cpuid.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-ia64/sn/sn_cpuid.h	Mon Dec 23 21:21:51 2002
@@ -121,13 +121,19 @@
 #endif
 
 /*
- * NOTE: id & eid refer to Intels definitions of the LID register
- *	(id = NASID, eid = slice)
+ * NOTE: id & eid refer to Intel's definitions of the LID register
+ * 
  * NOTE: on non-MP systems, only cpuid 0 exists
  */
-#define id_eid_to_cpu_physical_id(id,eid)       (((id)<<8) | (eid))
-#define id_eid_to_cpuid(id,eid)         	(cpu_logical_id(id_eid_to_cpu_physical_id((id),(eid))))
+#define id_eid_to_cpu_physical_id(id,eid)	 	(((id)<<8) | (eid))
 
+#define nasid_slice_to_cpuid(nasid,slice)		(cpu_logical_id(nasid_slice_to_cpu_physical_id((nasid),(slice))))
+
+#ifdef CONFIG_IA64_SGI_SN1
+#define nasid_slice_to_cpu_physical_id(nasid, slice)	(((nasid)<<8) | (slice))
+#else
+#define nasid_slice_to_cpu_physical_id(nasid, slice)	(((slice)<<12) | (nasid))
+#endif
 
 /*
  * The following table/struct  is used for managing PTC coherency domains.
@@ -190,13 +196,14 @@
 /*
  * nasid_to_cnodeid - convert a NASID to a cnodeid
  */
-#define nasid_to_cnodeid(nasid)		(local_node_data->physical_node_map[nasid])
+#define nasid_to_cnodeid(nasid)		(nasid) /* (local_node_data->physical_node_map[nasid]) */
 
 
 /*
  * cnode_slice_to_cpuid - convert a codeid & slice to a cpuid
  */
-#define cnode_slice_to_cpuid(cnodeid,slice) (id_eid_to_cpuid(cnodeid_to_nasid(cnodeid),(slice)))
+
+#define cnode_slice_to_cpuid(cnodeid,slice) (nasid_slice_to_cpuid(cnodeid_to_nasid(cnodeid),(slice)))
  
 
 /*
diff -Nru a/include/asm-ia64/sn/sn_sal.h b/include/asm-ia64/sn/sn_sal.h
--- a/include/asm-ia64/sn/sn_sal.h	Mon Dec 23 21:22:02 2002
+++ b/include/asm-ia64/sn/sn_sal.h	Mon Dec 23 21:22:02 2002
@@ -12,20 +12,107 @@
  */
 
 
+#include <linux/config.h>
 #include <asm/sal.h>
 #include <asm/sn/sn_cpuid.h>
+#include <asm/sn/arch.h>
 
 
 // SGI Specific Calls
 #define  SN_SAL_POD_MODE                           0x02000001
 #define  SN_SAL_SYSTEM_RESET                       0x02000002
 #define  SN_SAL_PROBE                              0x02000003
-#define  SN_SAL_GET_CONSOLE_NASID                  0x02000004
+#define  SN_SAL_GET_MASTER_NASID                   0x02000004
 #define	 SN_SAL_GET_KLCONFIG_ADDR		   0x02000005
 #define  SN_SAL_LOG_CE				   0x02000006
 #define  SN_SAL_REGISTER_CE			   0x02000007
+#define  SN_SAL_GET_PARTITION_ADDR		   0x02000009
+#define  SN_SAL_PRINT_ERROR			   0x02000012
+#define  SN_SAL_CONSOLE_PUTC                       0x02000021
+#define  SN_SAL_CONSOLE_GETC                       0x02000022
+#define  SN_SAL_CONSOLE_PUTS                       0x02000023
+#define  SN_SAL_CONSOLE_GETS                       0x02000024
+#define  SN_SAL_CONSOLE_GETS_TIMEOUT               0x02000025
+#define  SN_SAL_CONSOLE_POLL                       0x02000026
+#define  SN_SAL_CONSOLE_INTR                       0x02000027
+#define  SN_SAL_CONSOLE_PUTB			   0x02000028
+#define  SN_SAL_SYSCTL_MODID_GET	           0x02000031
+#define  SN_SAL_SYSCTL_GET                         0x02000032
+#define  SN_SAL_SYSCTL_IOBRICK_MODULE_GET          0x02000033
+#define  SN_SAL_SYSCTL_IO_PORTSPEED_GET            0x02000035
+#define  SN_SAL_SYSCTL_SLAB_GET                    0x02000036
+#define  SN_SAL_BUS_CONFIG		   	   0x02000037
+#define  SN_SAL_SYS_SERIAL_GET			   0x02000038
+#define  SN_SAL_PARTITION_SERIAL_GET		   0x02000039
+#define  SN_SAL_SYSCTL_PARTITION_GET		   0x0200003a
+#define  SN_SAL_SYSTEM_POWER_DOWN		   0x0200003b
+#define  SN_SAL_GET_MASTER_BASEIO_NASID		   0x0200003c
 
 
+/*
+ * Service-specific constants
+ */
+#define SAL_CONSOLE_INTR_IN     0       /* manipulate input interrupts */
+#define SAL_CONSOLE_INTR_OUT    1       /* manipulate output low-water
+                                         * interrupts
+                                         */
+#define SAL_CONSOLE_INTR_OFF    0       /* turn the interrupt off */
+#define SAL_CONSOLE_INTR_ON     1       /* turn the interrupt on */
+
+
+/*
+ * SN_SAL_GET_PARTITION_ADDR return constants
+ */
+#define SALRET_MORE_PASSES	1
+#define SALRET_OK		0
+#define SALRET_INVALID_ARG	-2
+#define SALRET_ERROR		-3
+
+
+/**
+ * sn_sal_rev_major - get the major SGI SAL revision number
+ *
+ * The SGI PROM stores its version in sal_[ab]_rev_(major|minor).
+ * This routine simply extracts the major value from the
+ * @ia64_sal_systab structure constructed by ia64_sal_init().
+ */
+static inline int
+sn_sal_rev_major(void)
+{
+	struct ia64_sal_systab *systab = efi.sal_systab;
+
+	return (int)systab->sal_b_rev_major;
+}
+
+/**
+ * sn_sal_rev_minor - get the minor SGI SAL revision number
+ *
+ * The SGI PROM stores its version in sal_[ab]_rev_(major|minor).
+ * This routine simply extracts the minor value from the
+ * @ia64_sal_systab structure constructed by ia64_sal_init().
+ */
+static inline int
+sn_sal_rev_minor(void)
+{
+	struct ia64_sal_systab *systab = efi.sal_systab;
+	
+	return (int)systab->sal_b_rev_minor;
+}
+
+/*
+ * Specify the minimum PROM revsion required for this kernel.
+ * Note that they're stored in hex format...
+ */
+#ifdef CONFIG_IA64_SGI_SN1
+#define SN_SAL_MIN_MAJOR	0x0
+#define SN_SAL_MIN_MINOR	0x03 /* SN1 PROMs are stuck at rev 0.03 */
+#elif defined(CONFIG_IA64_SGI_SN2)
+#define SN_SAL_MIN_MAJOR	0x0
+#define SN_SAL_MIN_MINOR	0x11
+#else
+#error "must specify which PROM revisions this kernel needs"
+#endif /* CONFIG_IA64_SGI_SN1 */
+
 u64 ia64_sn_probe_io_slot(long paddr, long size, void *data_ptr);
 
 /*
@@ -41,7 +128,7 @@
 	ret_stuff.v0 = (uint64_t)0;
 	ret_stuff.v1 = (uint64_t)0;
 	ret_stuff.v2 = (uint64_t)0;
-	SAL_CALL(ret_stuff, SN_SAL_GET_CONSOLE_NASID, 0, 0, 0, 0, 0, 0, 0);
+	SAL_CALL(ret_stuff, SN_SAL_GET_MASTER_NASID, 0, 0, 0, 0, 0, 0, 0);
 
 	if (ret_stuff.status < 0)
 		return ret_stuff.status;
@@ -50,6 +137,28 @@
 	return ret_stuff.v0;
 }
 
+/*
+ * Returns the master baseio nasid, if the call fails, return an illegal
+ * value.
+ */
+static inline u64
+ia64_sn_get_master_baseio_nasid(void)
+{
+	struct ia64_sal_retval ret_stuff;
+
+	ret_stuff.status = (uint64_t)0;
+	ret_stuff.v0 = (uint64_t)0;
+	ret_stuff.v1 = (uint64_t)0;
+	ret_stuff.v2 = (uint64_t)0;
+	SAL_CALL(ret_stuff, SN_SAL_GET_MASTER_BASEIO_NASID, 0, 0, 0, 0, 0, 0, 0);
+
+	if (ret_stuff.status < 0)
+		return ret_stuff.status;
+
+	/* Master baseio nasid is in 'v0' */
+	return ret_stuff.v0;
+}
+
 static inline u64
 ia64_sn_get_klconfig_addr(nasid_t nasid)
 {
@@ -57,7 +166,7 @@
 	extern u64 klgraph_addr[];
 	int cnodeid;
 
-	cnodeid = nasid_to_cnodeid(nasid);
+	cnodeid = 0 /* nasid_to_cnodeid(nasid) */;
 	if (klgraph_addr[cnodeid] == 0) {
 		ret_stuff.status = (uint64_t)0;
 		ret_stuff.v0 = (uint64_t)0;
@@ -76,6 +185,245 @@
 		klgraph_addr[cnodeid] = ret_stuff.v0;
 	}
 	return(klgraph_addr[cnodeid]);
+}
 
+/*
+ * Returns the next console character.
+ */
+static inline u64
+ia64_sn_console_getc(int *ch)
+{
+	struct ia64_sal_retval ret_stuff;
+
+	ret_stuff.status = (uint64_t)0;
+	ret_stuff.v0 = (uint64_t)0;
+	ret_stuff.v1 = (uint64_t)0;
+	ret_stuff.v2 = (uint64_t)0;
+	__SAL_CALL(ret_stuff, SN_SAL_CONSOLE_GETC, 0, 0, 0, 0, 0, 0, 0);
+
+	/* character is in 'v0' */
+	*ch = (int)ret_stuff.v0;
+
+	return ret_stuff.status;
 }
+
+/*
+ * Sends the given character to the console.
+ */
+static inline u64
+ia64_sn_console_putc(char ch)
+{
+	struct ia64_sal_retval ret_stuff;
+
+	ret_stuff.status = (uint64_t)0;
+	ret_stuff.v0 = (uint64_t)0;
+	ret_stuff.v1 = (uint64_t)0;
+	ret_stuff.v2 = (uint64_t)0;
+	__SAL_CALL(ret_stuff, SN_SAL_CONSOLE_PUTC, (uint64_t)ch, 0, 0, 0, 0, 0, 0);
+
+	return ret_stuff.status;
+}
+
+/*
+ * Sends the given buffer to the console.
+ */
+static inline u64
+ia64_sn_console_putb(char *buf, int len)
+{
+	struct ia64_sal_retval ret_stuff;
+
+	ret_stuff.status = (uint64_t)0;
+	ret_stuff.v0 = (uint64_t)0;
+	ret_stuff.v1 = (uint64_t)0;
+	ret_stuff.v2 = (uint64_t)0;
+	__SAL_CALL(ret_stuff, SN_SAL_CONSOLE_PUTB, (uint64_t)buf, (uint64_t)len, 0, 0, 0, 0, 0);
+
+	return ret_stuff.status;
+}
+
+/*
+ * Print a platform error record
+ */
+static inline u64
+ia64_sn_plat_specific_err_print(int (*hook)(const char*, ...), char *rec)
+{
+	struct ia64_sal_retval ret_stuff;
+
+	ret_stuff.status = (uint64_t)0;
+	ret_stuff.v0 = (uint64_t)0;
+	ret_stuff.v1 = (uint64_t)0;
+	ret_stuff.v2 = (uint64_t)0;
+	__SAL_CALL(ret_stuff, SN_SAL_PRINT_ERROR, (uint64_t)hook, (uint64_t)rec, 0, 0, 0, 0, 0);
+
+	return ret_stuff.status;
+}
+
+/*
+ * Check for Platform errors
+ */
+static inline u64
+ia64_sn_plat_cpei_handler(void)
+{
+	struct ia64_sal_retval ret_stuff;
+
+	ret_stuff.status = (uint64_t)0;
+	ret_stuff.v0 = (uint64_t)0;
+	ret_stuff.v1 = (uint64_t)0;
+	ret_stuff.v2 = (uint64_t)0;
+	__SAL_CALL(ret_stuff, SN_SAL_LOG_CE, 0, 0, 0, 0, 0, 0, 0);
+
+	return ret_stuff.status;
+}
+
+/*
+ * Checks for console input.
+ */
+static inline u64
+ia64_sn_console_check(int *result)
+{
+	struct ia64_sal_retval ret_stuff;
+
+	ret_stuff.status = (uint64_t)0;
+	ret_stuff.v0 = (uint64_t)0;
+	ret_stuff.v1 = (uint64_t)0;
+	ret_stuff.v2 = (uint64_t)0;
+	__SAL_CALL(ret_stuff, SN_SAL_CONSOLE_POLL, 0, 0, 0, 0, 0, 0, 0);
+
+	/* result is in 'v0' */
+	*result = (int)ret_stuff.v0;
+
+	return ret_stuff.status;
+}
+
+/*
+ * Returns the iobrick module Id
+ */
+static inline u64
+ia64_sn_sysctl_iobrick_module_get(nasid_t nasid, int *result)
+{
+	struct ia64_sal_retval ret_stuff;
+
+	ret_stuff.status = (uint64_t)0;
+	ret_stuff.v0 = (uint64_t)0;
+	ret_stuff.v1 = (uint64_t)0;
+	ret_stuff.v2 = (uint64_t)0;
+	SAL_CALL(ret_stuff, SN_SAL_SYSCTL_IOBRICK_MODULE_GET, nasid, 0, 0, 0, 0, 0, 0);
+
+	/* result is in 'v0' */
+	*result = (int)ret_stuff.v0;
+
+	return ret_stuff.status;
+}
+
+/**
+ * ia64_sn_pod_mode - call the SN_SAL_POD_MODE function
+ *
+ * SN_SAL_POD_MODE actually takes an argument, but it's always
+ * 0 when we call it from the kernel, so we don't have to expose
+ * it to the caller.
+ */
+static inline u64
+ia64_sn_pod_mode(void)
+{
+	struct ia64_sal_retval isrv;
+	SAL_CALL(isrv, SN_SAL_POD_MODE, 0, 0, 0, 0, 0, 0, 0);
+	if (isrv.status)
+		return 0;
+	return isrv.v0;
+}
+
+/*
+ * Retrieve the system serial number as an ASCII string.
+ */
+static inline u64
+ia64_sn_sys_serial_get(char *buf)
+{
+	struct ia64_sal_retval ret_stuff;
+	SAL_CALL(ret_stuff, SN_SAL_SYS_SERIAL_GET, buf, 0, 0, 0, 0, 0, 0);
+	return ret_stuff.status;
+}
+
+extern char sn_system_serial_number_string[];
+extern u64 sn_partition_serial_number;
+
+static inline char *
+sn_system_serial_number(void) {
+	if (sn_system_serial_number_string[0]) {
+		return(sn_system_serial_number_string);
+	} else {
+		ia64_sn_sys_serial_get(sn_system_serial_number_string);
+		return(sn_system_serial_number_string);
+	}
+}
+	
+
+/*
+ * Returns a unique id number for this system and partition (suitable for
+ * use with license managers), based in part on the system serial number.
+ */
+static inline u64
+ia64_sn_partition_serial_get(void)
+{
+	struct ia64_sal_retval ret_stuff;
+	SAL_CALL(ret_stuff, SN_SAL_PARTITION_SERIAL_GET, 0, 0, 0, 0, 0, 0, 0);
+	if (ret_stuff.status != 0)
+	    return 0;
+	return ret_stuff.v0;
+}
+
+static inline u64
+sn_partition_serial_number_val(void) {
+	if (sn_partition_serial_number) {
+		return(sn_partition_serial_number);
+	} else {
+		return(sn_partition_serial_number = ia64_sn_partition_serial_get());
+	}
+}
+
+/*
+ * Returns the partition id of the nasid passed in as an argument,
+ * or INVALID_PARTID if the partition id cannot be retrieved.
+ */
+static inline partid_t
+ia64_sn_sysctl_partition_get(nasid_t nasid)
+{
+	struct ia64_sal_retval ret_stuff;
+	SAL_CALL(ret_stuff, SN_SAL_SYSCTL_PARTITION_GET, nasid,
+		 0, 0, 0, 0, 0, 0);
+	if (ret_stuff.status != 0)
+	    return INVALID_PARTID;
+	return ((partid_t)ret_stuff.v0);
+}
+
+#ifdef CONFIG_IA64_SGI_SN2
+/*
+ * Returns the partition id of the current processor.
+ */
+
+extern partid_t sn_partid;
+
+static inline partid_t
+sn_local_partid(void) {
+	if (sn_partid < 0) {
+		return (sn_partid = ia64_sn_sysctl_partition_get(cpuid_to_nasid(smp_processor_id())));
+	} else {
+		return sn_partid;
+	}
+}
+
+#endif /* CONFIG_IA64_SGI_SN2 */
+
+/*
+ * Turns off system power.
+ */
+static inline void
+ia64_sn_power_down(void)
+{
+	struct ia64_sal_retval ret_stuff;
+	SAL_CALL(ret_stuff, SN_SAL_SYSTEM_POWER_DOWN, 0, 0, 0, 0, 0, 0, 0);
+	while(1);
+	/* never returns */
+}
+
+
 #endif /* _ASM_IA64_SN_SN_SAL_H */
diff -Nru a/include/asm-ia64/sn/sndrv.h b/include/asm-ia64/sn/sndrv.h
--- a/include/asm-ia64/sn/sndrv.h	Mon Dec 23 21:21:55 2002
+++ b/include/asm-ia64/sn/sndrv.h	Mon Dec 23 21:21:55 2002
@@ -27,6 +27,13 @@
 #define SNDRV_SYNERGY_ENABLE		34
 #define SNDRV_SYNERGY_FREQ		35
 
+/* see shubstats_ioctl() */
+#define SNDRV_SHUB_INFOSIZE		40
+#define SNDRV_SHUB_CONFIGURE		41
+#define SNDRV_SHUB_RESETSTATS		42
+#define SNDRV_SHUB_GETSTATS		43
+#define SNDRV_SHUB_GETNASID		44
+
 /* Devices */
 #define SNDRV_UKNOWN_DEVICE		-1
 #define SNDRV_ROUTER_DEVICE		1
diff -Nru a/include/asm-ia64/sn/types.h b/include/asm-ia64/sn/types.h
--- a/include/asm-ia64/sn/types.h	Mon Dec 23 21:22:00 2002
+++ b/include/asm-ia64/sn/types.h	Mon Dec 23 21:22:00 2002
@@ -9,14 +9,21 @@
 #ifndef _ASM_IA64_SN_TYPES_H
 #define _ASM_IA64_SN_TYPES_H
 
+#include <linux/config.h>
 #include <linux/types.h>
 
 typedef unsigned long 	cpuid_t;
 typedef unsigned long 	cpumask_t;
 typedef signed short	nasid_t;	/* node id in numa-as-id space */
 typedef signed char	partid_t;	/* partition ID type */
+#ifdef CONFIG_IA64_SGI_SN2
+typedef unsigned int    moduleid_t;     /* user-visible module number type */
+typedef unsigned int    cmoduleid_t;    /* kernel compact module id type */
+#else
 typedef signed short	moduleid_t;	/* user-visible module number type */
 typedef signed short	cmoduleid_t;	/* kernel compact module id type */
+#endif
+typedef signed char slabid_t;
 typedef unsigned char	clusterid_t;	/* Clusterid of the cell */
 
 typedef uint64_t __psunsigned_t;
diff -Nru a/include/asm-ia64/sn/vector.h b/include/asm-ia64/sn/vector.h
--- a/include/asm-ia64/sn/vector.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-ia64/sn/vector.h	Mon Dec 23 21:21:51 2002
@@ -10,6 +10,7 @@
 #define _ASM_IA64_SN_VECTOR_H
 
 #include <linux/config.h>
+#include <asm/sn/arch.h>
 
 #define NET_VEC_NULL            ((net_vec_t)  0)
 #define NET_VEC_BAD             ((net_vec_t) -1)
diff -Nru a/include/asm-ia64/sn/xtalk/xbow.h b/include/asm-ia64/sn/xtalk/xbow.h
--- a/include/asm-ia64/sn/xtalk/xbow.h	Mon Dec 23 21:21:52 2002
+++ b/include/asm-ia64/sn/xtalk/xbow.h	Mon Dec 23 21:21:52 2002
@@ -14,6 +14,7 @@
  * xbow.h - header file for crossbow chip and xbow section of xbridge
  */
 
+#include <linux/config.h>
 #include <asm/sn/xtalk/xtalk.h>
 #include <asm/sn/xtalk/xwidget.h>
 #include <asm/sn/xtalk/xswitch.h>
@@ -42,6 +43,13 @@
 #define MAX_PORT_NUM	0x10	/* maximum port number + 1 */
 #define XBOW_WIDGET_ID	0	/* xbow is itself widget 0 */
 
+#define XBOW_HUBLINK_LOW  0xa
+#define XBOW_HUBLINK_HIGH 0xb
+
+#define XBOW_PEER_LINK(link) (link == XBOW_HUBLINK_LOW) ? \
+                                XBOW_HUBLINK_HIGH : XBOW_HUBLINK_LOW
+
+
 #define	XBOW_CREDIT	4
 
 #define MAX_XBOW_NAME 	16
@@ -384,6 +392,7 @@
 #define XXBOW_WIDGET_PART_NUM	0xd000		/* Xbridge */
 #define	XBOW_WIDGET_MFGR_NUM	0x0
 #define	XXBOW_WIDGET_MFGR_NUM	0x0
+#define PXBOW_WIDGET_PART_NUM   0xd100          /* PIC */
 
 #define	XBOW_REV_1_0		0x1	/* xbow rev 1.0 is "1" */
 #define	XBOW_REV_1_1		0x2	/* xbow rev 1.1 is "2" */
@@ -398,8 +407,22 @@
 #define	XBOW_WID_ARB_RELOAD_INT	0x3f	/* GBR reload interval */
 
 
-#define nasid_has_xbridge(nasid)	\
-	(XWIDGET_PART_NUM(XWIDGET_ID_READ(nasid, 0)) == XXBOW_WIDGET_PART_NUM)
+#ifdef	CONFIG_IA64_SGI_SN1
+#define nasid_has_xbridge(nasid)        \
+        (XWIDGET_PART_NUM(XWIDGET_ID_READ(nasid, 0)) == XXBOW_WIDGET_PART_NUM)
+#endif
+
+#define IS_XBRIDGE_XBOW(wid) \
+        (XWIDGET_PART_NUM(wid) == XXBOW_WIDGET_PART_NUM && \
+                        XWIDGET_MFG_NUM(wid) == XXBOW_WIDGET_MFGR_NUM)
+
+#define IS_PIC_XBOW(wid) \
+        (XWIDGET_PART_NUM(wid) == PXBOW_WIDGET_PART_NUM && \
+                        XWIDGET_MFG_NUM(wid) == XXBOW_WIDGET_MFGR_NUM)
+
+#define XBOW_WAR_ENABLED(pv, widid) ((1 << XWIDGET_REV_NUM(widid)) & pv)
+#define PV854827 (~0)     /* PIC: fake widget 0xf presence bit. permanent */
+#define PV863579 (1 << 1) /* PIC: PIO to PIC register */
 
 
 #ifndef __ASSEMBLY__
diff -Nru a/include/asm-ia64/sn/xtalk/xtalk.h b/include/asm-ia64/sn/xtalk/xtalk.h
--- a/include/asm-ia64/sn/xtalk/xtalk.h	Mon Dec 23 21:21:57 2002
+++ b/include/asm-ia64/sn/xtalk/xtalk.h	Mon Dec 23 21:21:57 2002
@@ -8,6 +8,7 @@
  */
 #ifndef _ASM_SN_XTALK_XTALK_H
 #define _ASM_SN_XTALK_XTALK_H
+#include <linux/config.h>
 
 /*
  * xtalk.h -- platform-independent crosstalk interface
@@ -202,10 +203,19 @@
 typedef void
 xtalk_intr_free_f       (xtalk_intr_t intr_hdl);
 
+#ifdef CONFIG_IA64_SGI_SN1
 typedef int
 xtalk_intr_connect_f    (xtalk_intr_t intr_hdl,		/* xtalk intr resource handle */
 			 xtalk_intr_setfunc_f *setfunc,		/* func to set intr hw */
 			 void *setfunc_arg);	/* arg to setfunc */
+#else
+typedef int
+xtalk_intr_connect_f    (xtalk_intr_t intr_hdl,		/* xtalk intr resource handle */
+			intr_func_t intr_func,         /* xtalk intr handler */
+			void *intr_arg,	/* arg to intr handler */
+			xtalk_intr_setfunc_f *setfunc,		/* func to set intr hw */
+			void *setfunc_arg);	/* arg to setfunc */
+#endif
 
 typedef void
 xtalk_intr_disconnect_f (xtalk_intr_t intr_hdl);
@@ -390,9 +400,6 @@
 typedef void		xtalk_iter_f(devfs_handle_t vhdl);
 
 extern void		xtalk_iterate(char *prefix, xtalk_iter_f *func);
-
-extern int		xtalk_device_powerup(devfs_handle_t, xwidgetnum_t);
-extern int		xtalk_device_shutdown(devfs_handle_t, xwidgetnum_t);
 
 #endif				/* __KERNEL__ */
 #endif				/* _ASM_SN_XTALK_XTALK_H */
diff -Nru a/include/asm-ia64/sn/xtalk/xtalk_private.h b/include/asm-ia64/sn/xtalk/xtalk_private.h
--- a/include/asm-ia64/sn/xtalk/xtalk_private.h	Mon Dec 23 21:21:58 2002
+++ b/include/asm-ia64/sn/xtalk/xtalk_private.h	Mon Dec 23 21:21:58 2002
@@ -60,12 +60,12 @@
 		 ((_hwid)->mfg_num == XBOW_WIDGET_MFGR_NUM ))
 
 #define	xwidget_hwid_is_sn1_xswitch(_hwid)	\
-		(((_hwid)->part_num == XXBOW_WIDGET_PART_NUM ) &&  	\
+		(((_hwid)->part_num == XXBOW_WIDGET_PART_NUM ||		\
+		  (_hwid)->part_num == PXBOW_WIDGET_PART_NUM) &&  	\
 		 ((_hwid)->mfg_num == XXBOW_WIDGET_MFGR_NUM ))
 
 #define	xwidget_hwid_is_xswitch(_hwid)	\
-		(xwidget_hwid_is_sn0_xswitch(_hwid) ||			\
-			xwidget_hwid_is_sn1_xswitch(_hwid))
+			xwidget_hwid_is_sn1_xswitch(_hwid)
 
 /* common iograph info for all widgets,
  * stashed in FASTINFO of widget connection points.
diff -Nru a/include/asm-ia64/sn/xtalk/xwidget.h b/include/asm-ia64/sn/xtalk/xwidget.h
--- a/include/asm-ia64/sn/xtalk/xwidget.h	Mon Dec 23 21:21:50 2002
+++ b/include/asm-ia64/sn/xtalk/xwidget.h	Mon Dec 23 21:21:50 2002
@@ -58,6 +58,7 @@
 #define XWIDGET_MFG_NUM(widgetid) (((widgetid) & WIDGET_MFG_NUM) >> WIDGET_MFG_NUM_SHFT)
 #define XWIDGET_PART_REV_NUM(widgetid) ((XWIDGET_PART_NUM(widgetid) << 4) | \
 					XWIDGET_REV_NUM(widgetid))
+#define XWIDGET_PART_REV_NUM_REV(partrev) (partrev & 0xf)
 
 /* WIDGET_STATUS */
 #define WIDGET_LLP_REC_CNT		0xff000000
diff -Nru a/include/asm-ia64/system.h b/include/asm-ia64/system.h
--- a/include/asm-ia64/system.h	Mon Dec 23 21:21:53 2002
+++ b/include/asm-ia64/system.h	Mon Dec 23 21:21:53 2002
@@ -185,169 +185,6 @@
 	(flags & IA64_PSR_I) == 0;		\
 })
 
-/*
- * Force an unresolved reference if someone tries to use
- * ia64_fetch_and_add() with a bad value.
- */
-extern unsigned long __bad_size_for_ia64_fetch_and_add (void);
-extern unsigned long __bad_increment_for_ia64_fetch_and_add (void);
-
-#define IA64_FETCHADD(tmp,v,n,sz)						\
-({										\
-	switch (sz) {								\
-	      case 4:								\
-		__asm__ __volatile__ ("fetchadd4.rel %0=[%1],%2"		\
-				      : "=r"(tmp) : "r"(v), "i"(n) : "memory");	\
-		break;								\
-										\
-	      case 8:								\
-		__asm__ __volatile__ ("fetchadd8.rel %0=[%1],%2"		\
-				      : "=r"(tmp) : "r"(v), "i"(n) : "memory");	\
-		break;								\
-										\
-	      default:								\
-		__bad_size_for_ia64_fetch_and_add();				\
-	}									\
-})
-
-#define ia64_fetch_and_add(i,v)							\
-({										\
-	__u64 _tmp;								\
-	volatile __typeof__(*(v)) *_v = (v);					\
-	switch (i) {								\
-	      case -16:	IA64_FETCHADD(_tmp, _v, -16, sizeof(*(v))); break;	\
-	      case  -8:	IA64_FETCHADD(_tmp, _v,  -8, sizeof(*(v))); break;	\
-	      case  -4:	IA64_FETCHADD(_tmp, _v,  -4, sizeof(*(v))); break;	\
-	      case  -1:	IA64_FETCHADD(_tmp, _v,  -1, sizeof(*(v))); break;	\
-	      case   1:	IA64_FETCHADD(_tmp, _v,   1, sizeof(*(v))); break;	\
-	      case   4:	IA64_FETCHADD(_tmp, _v,   4, sizeof(*(v))); break;	\
-	      case   8:	IA64_FETCHADD(_tmp, _v,   8, sizeof(*(v))); break;	\
-	      case  16:	IA64_FETCHADD(_tmp, _v,  16, sizeof(*(v))); break;	\
-	      default:								\
-		_tmp = __bad_increment_for_ia64_fetch_and_add();		\
-		break;								\
-	}									\
-	(__typeof__(*(v))) (_tmp + (i));	/* return new value */		\
-})
-
-/*
- * This function doesn't exist, so you'll get a linker error if
- * something tries to do an invalid xchg().
- */
-extern void __xchg_called_with_bad_pointer (void);
-
-static __inline__ unsigned long
-__xchg (unsigned long x, volatile void *ptr, int size)
-{
-	unsigned long result;
-
-	switch (size) {
-	      case 1:
-		__asm__ __volatile ("xchg1 %0=[%1],%2" : "=r" (result)
-				    : "r" (ptr), "r" (x) : "memory");
-		return result;
-
-	      case 2:
-		__asm__ __volatile ("xchg2 %0=[%1],%2" : "=r" (result)
-				    : "r" (ptr), "r" (x) : "memory");
-		return result;
-
-	      case 4:
-		__asm__ __volatile ("xchg4 %0=[%1],%2" : "=r" (result)
-				    : "r" (ptr), "r" (x) : "memory");
-		return result;
-
-	      case 8:
-		__asm__ __volatile ("xchg8 %0=[%1],%2" : "=r" (result)
-				    : "r" (ptr), "r" (x) : "memory");
-		return result;
-	}
-	__xchg_called_with_bad_pointer();
-	return x;
-}
-
-#define xchg(ptr,x)							     \
-  ((__typeof__(*(ptr))) __xchg ((unsigned long) (x), (ptr), sizeof(*(ptr))))
-
-/*
- * Atomic compare and exchange.  Compare OLD with MEM, if identical,
- * store NEW in MEM.  Return the initial value in MEM.  Success is
- * indicated by comparing RETURN with OLD.
- */
-
-#define __HAVE_ARCH_CMPXCHG 1
-
-/*
- * This function doesn't exist, so you'll get a linker error
- * if something tries to do an invalid cmpxchg().
- */
-extern long __cmpxchg_called_with_bad_pointer(void);
-
-#define ia64_cmpxchg(sem,ptr,old,new,size)						\
-({											\
-	__typeof__(ptr) _p_ = (ptr);							\
-	__typeof__(new) _n_ = (new);							\
-	__u64 _o_, _r_;									\
-											\
-	switch (size) {									\
-	      case 1: _o_ = (__u8 ) (long) (old); break;				\
-	      case 2: _o_ = (__u16) (long) (old); break;				\
-	      case 4: _o_ = (__u32) (long) (old); break;				\
-	      case 8: _o_ = (__u64) (long) (old); break;				\
-	      default: break;								\
-	}										\
-	 __asm__ __volatile__ ("mov ar.ccv=%0;;" :: "rO"(_o_));				\
-	switch (size) {									\
-	      case 1:									\
-		__asm__ __volatile__ ("cmpxchg1."sem" %0=[%1],%2,ar.ccv"		\
-				      : "=r"(_r_) : "r"(_p_), "r"(_n_) : "memory");	\
-		break;									\
-											\
-	      case 2:									\
-		__asm__ __volatile__ ("cmpxchg2."sem" %0=[%1],%2,ar.ccv"		\
-				      : "=r"(_r_) : "r"(_p_), "r"(_n_) : "memory");	\
-		break;									\
-											\
-	      case 4:									\
-		__asm__ __volatile__ ("cmpxchg4."sem" %0=[%1],%2,ar.ccv"		\
-				      : "=r"(_r_) : "r"(_p_), "r"(_n_) : "memory");	\
-		break;									\
-											\
-	      case 8:									\
-		__asm__ __volatile__ ("cmpxchg8."sem" %0=[%1],%2,ar.ccv"		\
-				      : "=r"(_r_) : "r"(_p_), "r"(_n_) : "memory");	\
-		break;									\
-											\
-	      default:									\
-		_r_ = __cmpxchg_called_with_bad_pointer();				\
-		break;									\
-	}										\
-	(__typeof__(old)) _r_;								\
-})
-
-#define cmpxchg_acq(ptr,o,n)	ia64_cmpxchg("acq", (ptr), (o), (n), sizeof(*(ptr)))
-#define cmpxchg_rel(ptr,o,n)	ia64_cmpxchg("rel", (ptr), (o), (n), sizeof(*(ptr)))
-
-/* for compatibility with other platforms: */
-#define cmpxchg(ptr,o,n)	cmpxchg_acq(ptr,o,n)
-
-#ifdef CONFIG_IA64_DEBUG_CMPXCHG
-# define CMPXCHG_BUGCHECK_DECL	int _cmpxchg_bugcheck_count = 128;
-# define CMPXCHG_BUGCHECK(v)							\
-  do {										\
-	if (_cmpxchg_bugcheck_count-- <= 0) {					\
-		void *ip;							\
-		extern int printk(const char *fmt, ...);			\
-		asm ("mov %0=ip" : "=r"(ip));					\
-		printk("CMPXCHG_BUGCHECK: stuck at %p on word %p\n", ip, (v));	\
-		break;								\
-	}									\
-  } while (0)
-#else /* !CONFIG_IA64_DEBUG_CMPXCHG */
-# define CMPXCHG_BUGCHECK_DECL
-# define CMPXCHG_BUGCHECK(v)
-#endif /* !CONFIG_IA64_DEBUG_CMPXCHG */
-
 #ifdef __KERNEL__
 
 #define prepare_to_switch()    do { } while(0)
@@ -431,6 +268,38 @@
 	__switch_to(prev,next,last);						\
 } while (0)
 #endif
+
+/*
+ * On IA-64, we don't want to hold the runqueue's lock during the low-level context-switch,
+ * because that could cause a deadlock.  Here is an example by Erich Focht:
+ *
+ * Example:
+ * CPU#0:
+ * schedule()
+ *    -> spin_lock_irq(&rq->lock)
+ *    -> context_switch()
+ *       -> wrap_mmu_context()
+ *          -> read_lock(&tasklist_lock)
+ *
+ * CPU#1:
+ * sys_wait4() or release_task() or forget_original_parent()
+ *    -> write_lock(&tasklist_lock)
+ *    -> do_notify_parent()
+ *       -> wake_up_parent()
+ *          -> try_to_wake_up()
+ *             -> spin_lock_irq(&parent_rq->lock)
+ *
+ * If the parent's rq happens to be on CPU#0, we'll wait for the rq->lock
+ * of that CPU which will not be released, because there we wait for the
+ * tasklist_lock to become available.
+ */
+#define prepare_arch_switch(rq, next)		\
+do {						\
+	spin_lock(&(next)->switch_lock);	\
+	spin_unlock(&(rq)->lock);		\
+} while (0)
+#define finish_arch_switch(rq, prev)	spin_unlock_irq(&(prev)->switch_lock)
+#define task_running(rq, p) 		((rq)->curr == (p) || spin_is_locked(&(p)->switch_lock))
 
 #endif /* __KERNEL__ */
 
diff -Nru a/include/asm-ia64/thread_info.h b/include/asm-ia64/thread_info.h
--- a/include/asm-ia64/thread_info.h	Mon Dec 23 21:22:02 2002
+++ b/include/asm-ia64/thread_info.h	Mon Dec 23 21:22:02 2002
@@ -30,6 +30,7 @@
 	__u32 cpu;			/* current CPU */
 	mm_segment_t addr_limit;	/* user-level address space limit */
 	__s32 preempt_count;		/* 0=premptable, <0=BUG; will also serve as bh-counter */
+	struct restart_block restart_block;
 };
 
 #define INIT_THREAD_SIZE		/* tell sched.h not to declare the thread_union */
@@ -42,6 +43,9 @@
 	.cpu		= 0,			\
 	.addr_limit	= KERNEL_DS,		\
 	.preempt_count	= 0,			\
+	.restart_block = {			\
+		.fn = do_no_restart_syscall,	\
+	},					\
 }
 
 /* how to get the thread information struct from C */
diff -Nru a/include/asm-ia64/tlbflush.h b/include/asm-ia64/tlbflush.h
--- a/include/asm-ia64/tlbflush.h	Mon Dec 23 21:22:00 2002
+++ b/include/asm-ia64/tlbflush.h	Mon Dec 23 21:22:00 2002
@@ -22,29 +22,44 @@
  * Flush everything (kernel mapping may also have changed due to
  * vmalloc/vfree).
  */
-extern void __flush_tlb_all (void);
+extern void local_flush_tlb_all (void);
 
 #ifdef CONFIG_SMP
   extern void smp_flush_tlb_all (void);
+  extern void smp_flush_tlb_mm (struct mm_struct *mm);
 # define flush_tlb_all()	smp_flush_tlb_all()
 #else
-# define flush_tlb_all()	__flush_tlb_all()
+# define flush_tlb_all()	local_flush_tlb_all()
 #endif
 
+static inline void
+local_finish_flush_tlb_mm (struct mm_struct *mm)
+{
+	if (mm == current->active_mm)
+		activate_context(mm);
+}
+
 /*
- * Flush a specified user mapping
+ * Flush a specified user mapping.  This is called, e.g., as a result of fork() and
+ * exit().  fork() ends up here because the copy-on-write mechanism needs to write-protect
+ * the PTEs of the parent task.
  */
 static inline void
 flush_tlb_mm (struct mm_struct *mm)
 {
-	if (mm) {
-		mm->context = 0;
-		if (mm == current->active_mm) {
-			/* This is called, e.g., as a result of exec().  */
-			get_new_mmu_context(mm);
-			reload_context(mm);
-		}
-	}
+	if (!mm)
+		return;
+
+	mm->context = 0;
+
+	if (atomic_read(&mm->mm_users) == 0)
+		return;		/* happens as a result of exit_mmap() */
+
+#ifdef CONFIG_SMP
+	smp_flush_tlb_mm(mm);
+#else
+	local_finish_flush_tlb_mm(mm);
+#endif
 }
 
 extern void flush_tlb_range (struct vm_area_struct *vma, unsigned long start, unsigned long end);
diff -Nru a/include/asm-ia64/unistd.h b/include/asm-ia64/unistd.h
--- a/include/asm-ia64/unistd.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-ia64/unistd.h	Mon Dec 23 21:21:51 2002
@@ -114,18 +114,18 @@
 /* 1122 was __NR_old_fstat */
 #define __NR_vhangup			1123
 #define __NR_lchown			1124
-#define __NR_vm86			1125
+#define __NR_remap_file_pages		1125
 #define __NR_wait4			1126
 #define __NR_sysinfo			1127
 #define __NR_clone			1128
 #define __NR_setdomainname		1129
 #define __NR_uname			1130
 #define __NR_adjtimex			1131
-#define __NR_create_module		1132
+/* 1132 was __NR_create_module */
 #define __NR_init_module		1133
 #define __NR_delete_module		1134
-#define __NR_get_kernel_syms		1135
-#define __NR_query_module		1136
+/* 1135 was __NR_get_kernel_syms */
+/* 1136 was __NR_query_module */
 #define __NR_quotactl			1137
 #define __NR_bdflush			1138
 #define __NR_sysfs			1139
@@ -222,7 +222,7 @@
 #define __NR_futex			1230
 #define __NR_sched_setaffinity		1231
 #define __NR_sched_getaffinity		1232
-/* 1233 currently unused */
+#define __NR_set_tid_address		1233
 #define __NR_alloc_hugepages		1234
 #define __NR_free_hugepages		1235
 #define __NR_exit_group			1236
@@ -235,7 +235,8 @@
 #define __NR_epoll_create		1243
 #define __NR_epoll_ctl			1244
 #define __NR_epoll_wait			1245
-#define __NR_semtimedop			1246
+#define __NR_restart_syscall		1246
+#define __NR_semtimedop			1247
 
 #if !defined(__ASSEMBLY__) && !defined(ASSEMBLER)
 
diff -Nru a/include/asm-m68k/dma-mapping.h b/include/asm-m68k/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-m68k/dma-mapping.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-m68knommu/dma-mapping.h b/include/asm-m68knommu/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-m68knommu/dma-mapping.h	Mon Dec 23 21:22:03 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-mips/dma-mapping.h b/include/asm-mips/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-mips/dma-mapping.h	Mon Dec 23 21:22:04 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-mips64/dma-mapping.h b/include/asm-mips64/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-mips64/dma-mapping.h	Mon Dec 23 21:22:04 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-ppc/dma-mapping.h b/include/asm-ppc/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-ppc/dma-mapping.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-ppc64/dma-mapping.h b/include/asm-ppc64/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-ppc64/dma-mapping.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-s390/dma-mapping.h b/include/asm-s390/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-s390/dma-mapping.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-s390x/dma-mapping.h b/include/asm-s390x/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-s390x/dma-mapping.h	Mon Dec 23 21:22:04 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-sh/dma-mapping.h b/include/asm-sh/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-sh/dma-mapping.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-sparc/dma-mapping.h b/include/asm-sparc/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-sparc/dma-mapping.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-sparc/fbio.h b/include/asm-sparc/fbio.h
--- a/include/asm-sparc/fbio.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-sparc/fbio.h	Mon Dec 23 21:21:51 2002
@@ -90,23 +90,6 @@
 #define FBIOSVIDEO _IOW('F', 7, int)
 #define FBIOGVIDEO _IOR('F', 8, int)
 
-/* Cursor position */
-struct fbcurpos {
-#ifdef __KERNEL__
-	short fbx, fby;
-#else
-        short x, y;
-#endif
-};
-
-/* Cursor operations */
-#define FB_CUR_SETCUR   0x01	/* Enable/disable cursor display */
-#define FB_CUR_SETPOS   0x02	/* set cursor position */
-#define FB_CUR_SETHOT   0x04	/* set cursor hotspot */
-#define FB_CUR_SETCMAP  0x08	/* set color map for the cursor */
-#define FB_CUR_SETSHAPE 0x10	/* set shape */
-#define FB_CUR_SETALL   0x1F	/* all of the above */
-
 struct fbcursor {
         short set;              /* what to set, choose from the list above */
         short enable;           /* cursor on/off */
diff -Nru a/include/asm-sparc64/compat.h b/include/asm-sparc64/compat.h
--- a/include/asm-sparc64/compat.h	Mon Dec 23 21:21:57 2002
+++ b/include/asm-sparc64/compat.h	Mon Dec 23 21:21:57 2002
@@ -5,9 +5,32 @@
  */
 #include <linux/types.h>
 
+#define COMPAT_USER_HZ 100
+
 typedef u32		compat_size_t;
 typedef s32		compat_ssize_t;
 typedef s32		compat_time_t;
+typedef s32		compat_clock_t;
+
+struct compat_stat {
+	__kernel_dev_t32	st_dev;
+	__kernel_ino_t32	st_ino;
+	__kernel_mode_t32	st_mode;
+	s16			st_nlink;
+	__kernel_uid_t32	st_uid;
+	__kernel_gid_t32	st_gid;
+	__kernel_dev_t32	st_rdev;
+	__kernel_off_t32	st_size;
+	compat_time_t		st_atime;
+	u32			__unused1;
+	compat_time_t		st_mtime;
+	u32			__unused2;
+	compat_time_t		st_ctime;
+	u32			__unused3;
+	__kernel_off_t32	st_blksize;
+	__kernel_off_t32	st_blocks;
+	u32			__unused4[2];
+};
 
 struct compat_timespec {
 	compat_time_t	tv_sec;
diff -Nru a/include/asm-sparc64/dma-mapping.h b/include/asm-sparc64/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-sparc64/dma-mapping.h	Mon Dec 23 21:22:04 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-sparc64/fbio.h b/include/asm-sparc64/fbio.h
--- a/include/asm-sparc64/fbio.h	Mon Dec 23 21:21:50 2002
+++ b/include/asm-sparc64/fbio.h	Mon Dec 23 21:21:50 2002
@@ -93,23 +93,6 @@
 #define FBIOSVIDEO _IOW('F', 7, int)
 #define FBIOGVIDEO _IOR('F', 8, int)
 
-/* Cursor position */
-struct fbcurpos {
-#ifdef __KERNEL__
-	short fbx, fby;
-#else
-        short x, y;
-#endif
-};
-
-/* Cursor operations */
-#define FB_CUR_SETCUR   0x01	/* Enable/disable cursor display */
-#define FB_CUR_SETPOS   0x02	/* set cursor position */
-#define FB_CUR_SETHOT   0x04	/* set cursor hotspot */
-#define FB_CUR_SETCMAP  0x08	/* set color map for the cursor */
-#define FB_CUR_SETSHAPE 0x10	/* set shape */
-#define FB_CUR_SETALL   0x1F	/* all of the above */
-
 struct fbcursor {
         short set;              /* what to set, choose from the list above */
         short enable;           /* cursor on/off */
diff -Nru a/include/asm-sparc64/io.h b/include/asm-sparc64/io.h
--- a/include/asm-sparc64/io.h	Mon Dec 23 21:22:00 2002
+++ b/include/asm-sparc64/io.h	Mon Dec 23 21:22:00 2002
@@ -304,6 +304,17 @@
 	return ret;
 }
 
+static __inline__ u64 _sbus_readq(unsigned long addr)
+{
+	u64 ret;
+
+	__asm__ __volatile__("ldxa\t[%1] %2, %0\t/* sbus_readq */"
+			     : "=r" (ret)
+			     : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
+
+	return ret;
+}
+
 static __inline__ void _sbus_writeb(u8 b, unsigned long addr)
 {
 	__asm__ __volatile__("stba\t%r0, [%1] %2\t/* sbus_writeb */"
@@ -325,12 +336,21 @@
 			     : "Jr" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
 }
 
+static __inline__ void _sbus_writeq(u64 l, unsigned long addr)
+{
+	__asm__ __volatile__("stxa\t%r0, [%1] %2\t/* sbus_writeq */"
+			     : /* no outputs */
+			     : "Jr" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
+}
+
 #define sbus_readb(__addr)		(_sbus_readb((unsigned long)(__addr)))
 #define sbus_readw(__addr)		(_sbus_readw((unsigned long)(__addr)))
 #define sbus_readl(__addr)		(_sbus_readl((unsigned long)(__addr)))
+#define sbus_readq(__addr)		(_sbus_readq((unsigned long)(__addr)))
 #define sbus_writeb(__b, __addr)	(_sbus_writeb((__b), (unsigned long)(__addr)))
 #define sbus_writew(__w, __addr)	(_sbus_writew((__w), (unsigned long)(__addr)))
 #define sbus_writel(__l, __addr)	(_sbus_writel((__l), (unsigned long)(__addr)))
+#define sbus_writeq(__l, __addr)	(_sbus_writeq((__l), (unsigned long)(__addr)))
 
 static inline void *_sbus_memset_io(unsigned long dst, int c, __kernel_size_t n)
 {
diff -Nru a/include/asm-sparc64/posix_types.h b/include/asm-sparc64/posix_types.h
--- a/include/asm-sparc64/posix_types.h	Mon Dec 23 21:22:00 2002
+++ b/include/asm-sparc64/posix_types.h	Mon Dec 23 21:22:00 2002
@@ -49,7 +49,6 @@
 
 /* Now 32bit compatibility types */
 typedef int                    __kernel_ptrdiff_t32;
-typedef int                    __kernel_clock_t32;
 typedef int                    __kernel_pid_t32;
 typedef unsigned short         __kernel_ipc_pid_t32;
 typedef unsigned short         __kernel_uid_t32;
diff -Nru a/include/asm-sparc64/processor.h b/include/asm-sparc64/processor.h
--- a/include/asm-sparc64/processor.h	Mon Dec 23 21:21:50 2002
+++ b/include/asm-sparc64/processor.h	Mon Dec 23 21:21:50 2002
@@ -18,7 +18,6 @@
 #include <asm/a.out.h>
 #include <asm/pstate.h>
 #include <asm/ptrace.h>
-#include <asm/signal.h>
 #include <asm/segment.h>
 #include <asm/page.h>
 #include <asm/delay.h>
@@ -92,6 +91,8 @@
 #endif /* !(CONFIG_DEBUG_SPINLOCK) */
 
 #ifndef __ASSEMBLY__
+
+#include <linux/types.h>
 
 /* Return saved PC of a blocked thread. */
 struct task_struct;
diff -Nru a/include/asm-sparc64/siginfo.h b/include/asm-sparc64/siginfo.h
--- a/include/asm-sparc64/siginfo.h	Mon Dec 23 21:21:58 2002
+++ b/include/asm-sparc64/siginfo.h	Mon Dec 23 21:21:58 2002
@@ -13,6 +13,8 @@
 
 #ifdef __KERNEL__
 
+#include <asm/compat.h>
+
 typedef union sigval32 {
 	int sival_int;
 	u32 sival_ptr;
@@ -50,8 +52,8 @@
 			__kernel_pid_t32 _pid;		/* which child */
 			unsigned int _uid;		/* sender's uid */
 			int _status;			/* exit code */
-			__kernel_clock_t32 _utime;
-			__kernel_clock_t32 _stime;
+			compat_clock_t _utime;
+			compat_clock_t _stime;
 		} _sigchld;
 
 		/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGEMT */
diff -Nru a/include/asm-sparc64/stat.h b/include/asm-sparc64/stat.h
--- a/include/asm-sparc64/stat.h	Mon Dec 23 21:22:02 2002
+++ b/include/asm-sparc64/stat.h	Mon Dec 23 21:22:02 2002
@@ -3,28 +3,6 @@
 #define _SPARC64_STAT_H
 
 #include <linux/types.h>
-#include <linux/compat.h>
-#include <linux/time.h>
-
-struct stat32 {
-	__kernel_dev_t32   st_dev;
-	__kernel_ino_t32   st_ino;
-	__kernel_mode_t32  st_mode;
-	short   	   st_nlink;
-	__kernel_uid_t32   st_uid;
-	__kernel_gid_t32   st_gid;
-	__kernel_dev_t32   st_rdev;
-	__kernel_off_t32   st_size;
-	compat_time_t    st_atime;
-	unsigned int       __unused1;
-	compat_time_t    st_mtime;
-	unsigned int       __unused2;
-	compat_time_t    st_ctime;
-	unsigned int       __unused3;
-	__kernel_off_t32   st_blksize;
-	__kernel_off_t32   st_blocks;
-	unsigned int  __unused4[2];
-};
 
 struct stat {
 	dev_t   st_dev;
diff -Nru a/include/asm-um/dma-mapping.h b/include/asm-um/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-um/dma-mapping.h	Mon Dec 23 21:22:04 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-v850/current.h b/include/asm-v850/current.h
--- a/include/asm-v850/current.h	Mon Dec 23 21:21:55 2002
+++ b/include/asm-v850/current.h	Mon Dec 23 21:21:55 2002
@@ -14,8 +14,11 @@
 #ifndef __V850_CURRENT_H__
 #define __V850_CURRENT_H__
 
+#ifndef __ASSEMBLY__ /* <linux/thread_info.h> is not asm-safe.  */
+#include <linux/thread_info.h>
+#endif
+
 #include <asm/macrology.h>
-#include <asm/thread_info.h>
 
 
 /* Register used to hold the current task pointer while in the kernel.
diff -Nru a/include/asm-v850/dma-mapping.h b/include/asm-v850/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-v850/dma-mapping.h	Mon Dec 23 21:22:04 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-v850/elf.h b/include/asm-v850/elf.h
--- a/include/asm-v850/elf.h	Mon Dec 23 21:21:58 2002
+++ b/include/asm-v850/elf.h	Mon Dec 23 21:21:58 2002
@@ -22,6 +22,31 @@
 #define elf_check_arch(x)  \
   ((x)->e_machine == EM_V850 || (x)->e_machine == EM_CYGNUS_V850)
 
+
+/* v850 relocation types.  */
+#define R_V850_NONE		0
+#define R_V850_9_PCREL		1
+#define R_V850_22_PCREL		2
+#define R_V850_HI16_S		3
+#define R_V850_HI16		4
+#define R_V850_LO16		5
+#define R_V850_32		6
+#define R_V850_16		7
+#define R_V850_8		8
+#define R_V850_SDA_16_16_OFFSET	9	/* For ld.b, st.b, set1, clr1,
+					   not1, tst1, movea, movhi */
+#define R_V850_SDA_15_16_OFFSET	10	/* For ld.w, ld.h, ld.hu, st.w, st.h */
+#define R_V850_ZDA_16_16_OFFSET	11	/* For ld.b, st.b, set1, clr1,
+					   not1, tst1, movea, movhi */
+#define R_V850_ZDA_15_16_OFFSET	12	/* For ld.w, ld.h, ld.hu, st.w, st.h */
+#define R_V850_TDA_6_8_OFFSET	13	/* For sst.w, sld.w */
+#define R_V850_TDA_7_8_OFFSET	14	/* For sst.h, sld.h */
+#define R_V850_TDA_7_7_OFFSET	15	/* For sst.b, sld.b */
+#define R_V850_TDA_16_16_OFFSET	16	/* For set1, clr1, not1, tst1,
+					   movea, movhi */
+#define R_V850_NUM		17
+
+
 /*
  * These are used to set parameters in the core dumps.
  */
diff -Nru a/include/asm-v850/mmu_context.h b/include/asm-v850/mmu_context.h
--- a/include/asm-v850/mmu_context.h	Mon Dec 23 21:21:54 2002
+++ b/include/asm-v850/mmu_context.h	Mon Dec 23 21:21:54 2002
@@ -1,8 +1,6 @@
 #ifndef __V850_MMU_CONTEXT_H__
 #define __V850_MMU_CONTEXT_H__
 
-#include <linux/sched.h>
-
 #define destroy_context(mm)		((void)0)
 #define init_new_context(tsk,mm)	0
 #define switch_mm(prev,next,tsk,cpu)	((void)0)
diff -Nru a/include/asm-v850/processor.h b/include/asm-v850/processor.h
--- a/include/asm-v850/processor.h	Mon Dec 23 21:21:52 2002
+++ b/include/asm-v850/processor.h	Mon Dec 23 21:21:52 2002
@@ -15,9 +15,11 @@
 #define __V850_PROCESSOR_H__
 
 #include <linux/config.h>
+#ifndef __ASSEMBLY__ /* <linux/thread_info.h> is not asm-safe.  */
+#include <linux/thread_info.h>
+#endif
 
 #include <asm/ptrace.h>
-#include <asm/thread_info.h>
 #include <asm/entry.h>
 
 /* Some code expects `segment' stuff to be defined here.  */
diff -Nru a/include/asm-v850/thread_info.h b/include/asm-v850/thread_info.h
--- a/include/asm-v850/thread_info.h	Mon Dec 23 21:21:53 2002
+++ b/include/asm-v850/thread_info.h	Mon Dec 23 21:21:53 2002
@@ -31,15 +31,19 @@
 	unsigned long		flags;		/* low level flags */
 	int			cpu;		/* cpu we're on */
 	int			preempt_count;
+	struct restart_block	restart_block;
 };
 
-#define INIT_THREAD_INFO(tsk)			\
-{						\
-	.task =		&tsk,			\
-	.exec_domain =	&default_exec_domain,	\
-	.flags =	0,			\
-	.cpu =		0,			\
-	.preempt_count = 1			\
+#define INIT_THREAD_INFO(tsk)						      \
+{									      \
+	.task =		&tsk,						      \
+	.exec_domain =	&default_exec_domain,				      \
+	.flags =	0,						      \
+	.cpu =		0,						      \
+	.preempt_count = 1,						      \
+	.restart_block = {						      \
+		.fn = do_no_restart_syscall,				      \
+	},								      \
 }
 
 #define init_thread_info	(init_thread_union.thread_info)
@@ -67,8 +71,6 @@
 #define TI_FLAGS	8
 #define TI_CPU		12
 #define TI_PREEMPT	16
-#define TI_SOFTIRQ	20
-#define TI_HARDIRQ	24
 
 #define PREEMPT_ACTIVE		0x4000000
 
diff -Nru a/include/asm-v850/uaccess.h b/include/asm-v850/uaccess.h
--- a/include/asm-v850/uaccess.h	Mon Dec 23 21:21:59 2002
+++ b/include/asm-v850/uaccess.h	Mon Dec 23 21:21:59 2002
@@ -4,7 +4,9 @@
 /*
  * User space memory access functions
  */
-#include <linux/sched.h>
+
+#include <linux/errno.h>
+#include <linux/string.h>
 
 #include <asm/segment.h>
 #include <asm/machdep.h>
diff -Nru a/include/asm-v850/unistd.h b/include/asm-v850/unistd.h
--- a/include/asm-v850/unistd.h	Mon Dec 23 21:22:00 2002
+++ b/include/asm-v850/unistd.h	Mon Dec 23 21:22:00 2002
@@ -16,6 +16,7 @@
 
 #include <asm/clinkage.h>
 
+#define __NR_restart_syscall	  0
 #define __NR_exit		  1
 #define __NR_fork		  2
 #define __NR_read		  3
diff -Nru a/include/asm-x86_64/bitops.h b/include/asm-x86_64/bitops.h
--- a/include/asm-x86_64/bitops.h	Mon Dec 23 21:21:53 2002
+++ b/include/asm-x86_64/bitops.h	Mon Dec 23 21:21:53 2002
@@ -89,7 +89,7 @@
 
 /**
  * __change_bit - Toggle a bit in memory
- * @nr: the bit to set
+ * @nr: the bit to change
  * @addr: the address to start counting from
  *
  * Unlike change_bit(), this function is non-atomic and may be reordered.
@@ -106,7 +106,7 @@
 
 /**
  * change_bit - Toggle a bit in memory
- * @nr: Bit to clear
+ * @nr: Bit to change
  * @addr: Address to start counting from
  *
  * change_bit() is atomic and may not be reordered.
@@ -162,7 +162,7 @@
 
 /**
  * test_and_clear_bit - Clear a bit and return its old value
- * @nr: Bit to set
+ * @nr: Bit to clear
  * @addr: Address to count from
  *
  * This operation is atomic and cannot be reordered.  
@@ -181,7 +181,7 @@
 
 /**
  * __test_and_clear_bit - Clear a bit and return its old value
- * @nr: Bit to set
+ * @nr: Bit to clear
  * @addr: Address to count from
  *
  * This operation is non-atomic and can be reordered.  
@@ -213,7 +213,7 @@
 
 /**
  * test_and_change_bit - Change a bit and return its new value
- * @nr: Bit to set
+ * @nr: Bit to change
  * @addr: Address to count from
  *
  * This operation is atomic and cannot be reordered.  
@@ -259,6 +259,8 @@
 (__builtin_constant_p(nr) ? \
  constant_test_bit((nr),(addr)) : \
  variable_test_bit((nr),(addr)))
+
+#undef ADDR
 
 /**
  * find_first_zero_bit - find the first zero bit in a memory region
diff -Nru a/include/asm-x86_64/calling.h b/include/asm-x86_64/calling.h
--- a/include/asm-x86_64/calling.h	Mon Dec 23 21:21:58 2002
+++ b/include/asm-x86_64/calling.h	Mon Dec 23 21:21:58 2002
@@ -29,6 +29,7 @@
 #define RSP 152
 #define SS 160
 #define ARGOFFSET R11
+#define SWFRAME ORIG_RAX
 
 	.macro SAVE_ARGS addskip=0,norcx=0 	
 	subq  $9*8+\addskip,%rsp
@@ -47,8 +48,11 @@
 	.endm
 
 #define ARG_SKIP 9*8
-	.macro RESTORE_ARGS skiprax=0,addskip=0,skiprcx=0
+	.macro RESTORE_ARGS skiprax=0,addskip=0,skiprcx=0,skipr11=0
+	.if \skipr11
+	.else
 	movq (%rsp),%r11
+	.endif
 	movq 1*8(%rsp),%r10
 	movq 2*8(%rsp),%r9
 	movq 3*8(%rsp),%r8
diff -Nru a/include/asm-x86_64/compat.h b/include/asm-x86_64/compat.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-x86_64/compat.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,57 @@
+#ifndef _ASM_X86_64_COMPAT_H
+#define _ASM_X86_64_COMPAT_H
+/*
+ * Architecture specific compatibility types
+ */
+#include <linux/types.h>
+
+#define COMPAT_USER_HZ	100
+
+typedef u32		compat_size_t;
+typedef s32		compat_ssize_t;
+typedef s32		compat_time_t;
+typedef s32		compat_suseconds_t;
+typedef s32		compat_clock_t;
+typedef s32		compat_pid_t;
+typedef u16		compat_uid_t;
+typedef u16		compat_gid_t;
+typedef u16		compat_mode_t;
+typedef u32		compat_ino_t;
+typedef u16		compat_dev_t;
+typedef s32		compat_off_t;
+typedef u16		compat_nlink_t;
+
+struct compat_timespec {
+	compat_time_t	tv_sec;
+	s32		tv_nsec;
+};
+
+struct compat_timeval {
+	compat_time_t	tv_sec;
+	s32		tv_usec;
+};
+
+struct compat_stat {
+	compat_dev_t	st_dev;
+	u16		__pad1;
+	compat_ino_t	st_ino;
+	compat_mode_t	st_mode;
+	compat_nlink_t	st_nlink;
+	compat_uid_t	st_uid;
+	compat_gid_t	st_gid;
+	compat_dev_t	st_rdev;
+	u16		__pad2;
+	u32		st_size;
+	u32		st_blksize;
+	u32		st_blocks;
+	u32		st_atime;
+	u32		st_atime_nsec;
+	u32		st_mtime;
+	u32		st_mtime_nsec;
+	u32		st_ctime;
+	u32		st_ctime_nsec;
+	u32		__unused4;
+	u32		__unused5;
+};
+
+#endif /* _ASM_X86_64_COMPAT_H */
diff -Nru a/include/asm-x86_64/desc.h b/include/asm-x86_64/desc.h
--- a/include/asm-x86_64/desc.h	Mon Dec 23 21:22:03 2002
+++ b/include/asm-x86_64/desc.h	Mon Dec 23 21:22:03 2002
@@ -165,30 +165,13 @@
 # error update this code.
 #endif
 
-
-static inline u64 load_TLS(struct thread_struct *t, int cpu) 
+static inline void load_TLS(struct thread_struct *t, unsigned int cpu)
 {
-	u64 *p, old, new, change; 
-	union u { 
-		struct desc_struct d;
-		u64 i; 
-	}; 
-	change = 0; 
-
-	/* check assembly! */
-#define C(i) \
-	p = ((u64 *)cpu_gdt_table[cpu]) + GDT_ENTRY_TLS_MIN + i; \
-	old = *p; \
-	new = t->tls_array[i]; \
-	change |= old - new;  \
-	*p = new;
-
-	C(0); C(1); C(2); 
-	return change; 
+	u64 *gdt = (u64 *)(cpu_gdt_table[cpu] + GDT_ENTRY_TLS_MIN);
+	gdt[0] = t->tls_array[0];
+	gdt[1] = t->tls_array[1];
+	gdt[2] = t->tls_array[2];
 } 
-
-#undef C
-
 
 /*
  * load one particular LDT into the current CPU
diff -Nru a/include/asm-x86_64/dma-mapping.h b/include/asm-x86_64/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/asm-x86_64/dma-mapping.h	Mon Dec 23 21:22:04 2002
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
diff -Nru a/include/asm-x86_64/elf.h b/include/asm-x86_64/elf.h
--- a/include/asm-x86_64/elf.h	Mon Dec 23 21:21:59 2002
+++ b/include/asm-x86_64/elf.h	Mon Dec 23 21:21:59 2002
@@ -7,6 +7,7 @@
 
 #include <asm/ptrace.h>
 #include <asm/user.h>
+#include <asm/processor.h>
 
 typedef unsigned long elf_greg_t;
 
@@ -14,7 +15,6 @@
 typedef elf_greg_t elf_gregset_t[ELF_NGREG];
 
 typedef struct user_i387_struct elf_fpregset_t;
-typedef struct user_fxsr_struct elf_fpxregset_t;
 
 /*
  * This is used to ensure we don't load something for the wrong architecture.
@@ -123,6 +123,17 @@
 extern void set_personality_64bit(void);
 #define SET_PERSONALITY(ex, ibcs2) set_personality_64bit()
 	
+extern int dump_task_regs (struct task_struct *, elf_gregset_t *);
+extern int dump_task_fpu (struct task_struct *, elf_fpregset_t *);
+
+#define ELF_CORE_COPY_TASK_REGS(tsk, elf_regs) dump_task_regs(tsk, elf_regs)
+#define ELF_CORE_COPY_FPREGS(tsk, elf_fpregs) dump_task_fpu(tsk, elf_fpregs)
+
+#ifdef CONFIG_SMP
+extern void dump_smp_unlazy_fpu(void);
+#define ELF_CORE_SYNC dump_smp_unlazy_fpu
+#endif
+
 #endif
 
 #endif
diff -Nru a/include/asm-x86_64/hardirq.h b/include/asm-x86_64/hardirq.h
--- a/include/asm-x86_64/hardirq.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-x86_64/hardirq.h	Mon Dec 23 21:21:51 2002
@@ -77,6 +77,9 @@
 #define hardirq_endlock()	do { } while (0)
 
 #define irq_enter()		(preempt_count() += HARDIRQ_OFFSET)
+#define nmi_enter()		(irq_enter())
+#define nmi_exit()		(preempt_count() -= HARDIRQ_OFFSET)
+
 
 #if CONFIG_PREEMPT
 # define in_atomic()   ((preempt_count() & ~PREEMPT_ACTIVE) != kernel_locked())
diff -Nru a/include/asm-x86_64/i387.h b/include/asm-x86_64/i387.h
--- a/include/asm-x86_64/i387.h	Mon Dec 23 21:21:55 2002
+++ b/include/asm-x86_64/i387.h	Mon Dec 23 21:21:55 2002
@@ -43,6 +43,12 @@
 		save_init_fpu(tsk); \
 } while (0)
 
+#define unlazy_current_fpu() do { \
+	if (test_thread_flag(TIF_USEDFPU)) \
+		save_init_fpu(tsk); \
+} while (0)
+
+
 #define clear_fpu(tsk) do { \
 	if (test_tsk_thread_flag(tsk, TIF_USEDFPU)) {		\
 		asm volatile("fwait");				\
@@ -63,12 +69,6 @@
 		      struct task_struct *tsk);
 extern int set_fpregs(struct task_struct *tsk,
 		      struct user_i387_struct *buf);
-
-/*
- * FPU state for core dumps...
- */
-extern int dump_fpu(struct pt_regs *regs,
-		    struct user_i387_struct *fpu);
 
 /*
  * i387 state interaction
diff -Nru a/include/asm-x86_64/ia32.h b/include/asm-x86_64/ia32.h
--- a/include/asm-x86_64/ia32.h	Mon Dec 23 21:22:00 2002
+++ b/include/asm-x86_64/ia32.h	Mon Dec 23 21:22:00 2002
@@ -5,29 +5,18 @@
 
 #ifdef CONFIG_IA32_EMULATION
 
+#include <linux/compat.h>
+
 /*
  * 32 bit structures for IA32 support.
  */
 
 /* 32bit compatibility types */
-typedef unsigned int	       __kernel_size_t32;
-typedef int		       __kernel_ssize_t32;
-typedef int		       __kernel_ptrdiff_t32;
-typedef int		       __kernel_time_t32;
-typedef int		       __kernel_clock_t32;
-typedef int		       __kernel_pid_t32;
 typedef unsigned short	       __kernel_ipc_pid_t32;
-typedef unsigned short	       __kernel_uid_t32;
 typedef unsigned 				__kernel_uid32_t32;
-typedef unsigned short	       __kernel_gid_t32;
 typedef unsigned 				__kernel_gid32_t32;
-typedef unsigned short	       __kernel_dev_t32;
-typedef unsigned int	       __kernel_ino_t32;
-typedef unsigned short	       __kernel_mode_t32;
 typedef unsigned short	       __kernel_umode_t32;
-typedef short		       __kernel_nlink_t32;
 typedef int		       __kernel_daddr_t32;
-typedef int		       __kernel_off_t32;
 typedef unsigned int	       __kernel_caddr_t32;
 typedef long		       __kernel_loff_t32;
 typedef __kernel_fsid_t	       __kernel_fsid_t32;
@@ -37,9 +26,9 @@
 struct flock32 {
        short l_type;
        short l_whence;
-       __kernel_off_t32 l_start;
-       __kernel_off_t32 l_len;
-       __kernel_pid_t32 l_pid;
+       compat_off_t l_start;
+       compat_off_t l_len;
+       compat_pid_t l_pid;
 };
 
 
@@ -98,30 +87,6 @@
 	sigset32_t	  uc_sigmask;	/* mask last for extensibility */
 };
 
-struct stat32 {
-       unsigned short st_dev;
-       unsigned short __pad1;
-       unsigned int st_ino;
-       unsigned short st_mode;
-       unsigned short st_nlink;
-       unsigned short st_uid;
-       unsigned short st_gid;
-       unsigned short st_rdev;
-       unsigned short __pad2;
-       unsigned int  st_size;
-       unsigned int  st_blksize;
-       unsigned int  st_blocks;
-       unsigned int  st_atime;
-       unsigned int  __unused1;
-       unsigned int  st_mtime;
-       unsigned int  __unused2;
-       unsigned int  st_ctime;
-       unsigned int  __unused3;
-       unsigned int  __unused4;
-       unsigned int  __unused5;
-};
-
-
 /* This matches struct stat64 in glibc2.2, hence the absolutely
  * insane amounts of padding around dev_t's.
  */
@@ -146,9 +111,12 @@
 
 	long long		st_blocks;/* Number 512-byte blocks allocated. */
 
-	unsigned long long	st_atime;
-	unsigned long long	st_mtime;
-	unsigned long long	st_ctime;
+	unsigned 		st_atime;
+	unsigned 		st_atime_nsec;
+	unsigned 		st_mtime;
+	unsigned 		st_mtime_nsec;
+	unsigned 		st_ctime;
+	unsigned 		st_ctime_nsec;
 
 	unsigned long long	st_ino;
 } __attribute__((packed));
@@ -204,8 +172,8 @@
 			unsigned int _pid;	/* which child */
 			unsigned int _uid;	/* sender's uid */
 			int _status;		/* exit code */
-			__kernel_clock_t32 _utime;
-			__kernel_clock_t32 _stime;
+			compat_clock_t _utime;
+			compat_clock_t _stime;
 		} _sigchld;
 
 		/* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
@@ -224,7 +192,7 @@
 
 struct ustat32 {
 	__u32	f_tfree;
-	__kernel_ino_t32		f_tinode;
+	compat_ino_t		f_tinode;
 	char			f_fname[6];
 	char			f_fpack[6];
 };
@@ -234,6 +202,8 @@
 	int iov_len; 
 };
 
+#define IA32_PAGE_OFFSET 0xffff0000
+#define IA32_STACK_TOP IA32_PAGE_OFFSET
 
 #endif /* !CONFIG_IA32_SUPPORT */
  
diff -Nru a/include/asm-x86_64/ia32_unistd.h b/include/asm-x86_64/ia32_unistd.h
--- a/include/asm-x86_64/ia32_unistd.h	Mon Dec 23 21:21:57 2002
+++ b/include/asm-x86_64/ia32_unistd.h	Mon Dec 23 21:21:57 2002
@@ -6,6 +6,7 @@
  * this is for the kernel only.
  */
 
+#define __NR_ia32_restart_syscall 0
 #define __NR_ia32_exit		  1
 #define __NR_ia32_fork		  2
 #define __NR_ia32_read		  3
@@ -259,7 +260,13 @@
 #define __NR_ia32_alloc_hugepages		250
 #define __NR_ia32_free_hugepages		251
 #define __NR_ia32_exit_group		252
+#define __NR_ia32_lookup_dcookie	253
+#define __NR_ia32_sys_epoll_create	254
+#define __NR_ia32_sys_epoll_ctl	255
+#define __NR_ia32_sys_epoll_wait	256
+#define __NR_ia32_remap_file_pages	257
+#define __NR_ia32_set_tid_address	258
 
-#define IA32_NR_syscalls 260	/* must be > than biggest syscall! */	
+#define IA32_NR_syscalls 265	/* must be > than biggest syscall! */	
 
 #endif /* _ASM_X86_64_IA32_UNISTD_H_ */
diff -Nru a/include/asm-x86_64/ide.h b/include/asm-x86_64/ide.h
--- a/include/asm-x86_64/ide.h	Mon Dec 23 21:21:55 2002
+++ b/include/asm-x86_64/ide.h	Mon Dec 23 21:21:55 2002
@@ -70,6 +70,7 @@
 	int index;
 
 	for(index = 0; index < MAX_HWIFS; index++) {
+		memset(&hw, 0, sizeof hw);
 		ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, NULL);
 		hw.irq = ide_default_irq(ide_default_io_base(index));
 		ide_register_hw(&hw, NULL);
diff -Nru a/include/asm-x86_64/io.h b/include/asm-x86_64/io.h
--- a/include/asm-x86_64/io.h	Mon Dec 23 21:21:53 2002
+++ b/include/asm-x86_64/io.h	Mon Dec 23 21:21:53 2002
@@ -178,19 +178,23 @@
 #define readb(addr) (*(volatile unsigned char *) __io_virt(addr))
 #define readw(addr) (*(volatile unsigned short *) __io_virt(addr))
 #define readl(addr) (*(volatile unsigned int *) __io_virt(addr))
+#define readq(addr) (*(volatile unsigned long *) __io_virt(addr))
 #define __raw_readb readb
 #define __raw_readw readw
 #define __raw_readl readl
+#define __raw_readq readq
 
 #define writeb(b,addr) (*(volatile unsigned char *) __io_virt(addr) = (b))
 #define writew(b,addr) (*(volatile unsigned short *) __io_virt(addr) = (b))
 #define writel(b,addr) (*(volatile unsigned int *) __io_virt(addr) = (b))
+#define writeq(b,addr) (*(volatile unsigned long *) __io_virt(addr) = (b))
 #define __raw_writeb writeb
 #define __raw_writew writew
 #define __raw_writel writel
+#define __raw_writeq writeq
 
-void *memcpy_fromio(void*,void*,unsigned); 
-void *memcpy_toio(void*,void*,unsigned); 
+void *memcpy_fromio(void*,const void*,unsigned); 
+void *memcpy_toio(void*,const void*,unsigned); 
 #define memset_io(a,b,c)	memset(__io_virt(a),(b),(c))
 
 /*
@@ -215,7 +219,7 @@
 
 
 /*
- * Again, i386 does not require mem IO specific function.
+ * Again, x86-64 does not require mem IO specific function.
  */
 
 #define eth_io_copy_and_sum(a,b,c,d)		eth_copy_and_sum((a),__io_virt(b),(c),(d))
diff -Nru a/include/asm-x86_64/io_apic.h b/include/asm-x86_64/io_apic.h
--- a/include/asm-x86_64/io_apic.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-x86_64/io_apic.h	Mon Dec 23 21:21:51 2002
@@ -155,6 +155,8 @@
 extern int io_apic_set_pci_routing (int ioapic, int pin, int irq);
 #endif
 
+extern int sis_apic_bug; /* dummy */ 
+
 
 #else  /* !CONFIG_X86_IO_APIC */
 #define io_apic_assign_pci_irqs 0
diff -Nru a/include/asm-x86_64/mmu_context.h b/include/asm-x86_64/mmu_context.h
--- a/include/asm-x86_64/mmu_context.h	Mon Dec 23 21:21:52 2002
+++ b/include/asm-x86_64/mmu_context.h	Mon Dec 23 21:21:52 2002
@@ -12,8 +12,8 @@
 /*
  * possibly do the LDT unload here?
  */
-#define destroy_context(mm)		do { } while(0)
 int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
+void destroy_context(struct mm_struct *mm);
 
 #ifdef CONFIG_SMP
 
diff -Nru a/include/asm-x86_64/module.h b/include/asm-x86_64/module.h
--- a/include/asm-x86_64/module.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-x86_64/module.h	Mon Dec 23 21:21:51 2002
@@ -1,15 +1,10 @@
 #ifndef _ASM_X8664_MODULE_H
 #define _ASM_X8664_MODULE_H
 
-/*
- * This file contains the x8664 architecture specific module code.
- * Modules need to be mapped near the kernel code to allow 32bit relocations.
- */
+struct mod_arch_specific {}; 
 
-extern void *module_map(unsigned long);
-extern void module_unmap(void *);
-
-#define module_arch_init(x)	(0)
-#define arch_init_modules(x)	do { } while (0)
+#define Elf_Shdr Elf64_Shdr
+#define Elf_Sym Elf64_Sym
+#define Elf_Ehdr Elf64_Ehdr
 
 #endif 
diff -Nru a/include/asm-x86_64/mtrr.h b/include/asm-x86_64/mtrr.h
--- a/include/asm-x86_64/mtrr.h	Mon Dec 23 21:21:51 2002
+++ b/include/asm-x86_64/mtrr.h	Mon Dec 23 21:21:51 2002
@@ -30,16 +30,16 @@
 
 struct mtrr_sentry
 {
-    __u64 base;    /*  Base address     */
-    __u32 size;    /*  Size of region   */
+    unsigned long base;    /*  Base address     */
+    unsigned int size;    /*  Size of region   */
     unsigned int type;     /*  Type of region   */
 };
 
 struct mtrr_gentry
 {
-    __u64 base;    /*  Base address     */
-    __u32 size;    /*  Size of region   */
+    unsigned long base;    /*  Base address     */
     unsigned int regnum;   /*  Register number  */
+    unsigned int size;    /*  Size of region   */
     unsigned int type;     /*  Type of region   */
 };
 
@@ -65,49 +65,44 @@
 #define MTRR_TYPE_WRBACK     6
 #define MTRR_NUM_TYPES       7
 
-#ifdef MTRR_NEED_STRINGS
-static char *mtrr_strings[MTRR_NUM_TYPES] =
-{
-    "uncachable",               /* 0 */
-    "write-combining",          /* 1 */
-    "?",                        /* 2 */
-    "?",                        /* 3 */
-    "write-through",            /* 4 */
-    "write-protect",            /* 5 */
-    "write-back",               /* 6 */
-};
-#endif
-
 #ifdef __KERNEL__
 
+extern char *mtrr_strings[MTRR_NUM_TYPES];
+
 /*  The following functions are for use by other drivers  */
-#ifdef CONFIG_MTRR
-extern int mtrr_add (__u64 base, __u32 size, unsigned int type, char increment);
-extern int mtrr_add_page (__u64 base, __u32 size, unsigned int type, char increment);
-extern int mtrr_del (int reg, __u64 base, __u32 size);
-extern int mtrr_del_page (int reg, __u64 base, __u32 size);
-#else
-static __inline__ int mtrr_add (__u64 base, __u32 size,
+# ifdef CONFIG_MTRR
+extern int mtrr_add (unsigned long base, unsigned long size,
+		     unsigned int type, char increment);
+extern int mtrr_add_page (unsigned long base, unsigned long size,
+		     unsigned int type, char increment);
+extern int mtrr_del (int reg, unsigned long base, unsigned long size);
+extern int mtrr_del_page (int reg, unsigned long base, unsigned long size);
+extern void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi);
+#  else
+static __inline__ int mtrr_add (unsigned long base, unsigned long size,
 				unsigned int type, char increment)
 {
     return -ENODEV;
 }
-static __inline__ int mtrr_add_page (__u64 base, __u32 size,
+static __inline__ int mtrr_add_page (unsigned long base, unsigned long size,
 				unsigned int type, char increment)
 {
     return -ENODEV;
 }
-static __inline__ int mtrr_del (int reg, __u64 base, __u32 size)
+static __inline__ int mtrr_del (int reg, unsigned long base,
+				unsigned long size)
 {
     return -ENODEV;
 }
-static __inline__ int mtrr_del_page (int reg, __u64 base, __u32 size)
+static __inline__ int mtrr_del_page (int reg, unsigned long base,
+				unsigned long size)
 {
     return -ENODEV;
 }
-#endif
 
-extern void mtrr_init_cpu(int cpu);
+static __inline__ void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi) {;}
+
+#  endif
 
 #endif
 
diff -Nru a/include/asm-x86_64/page.h b/include/asm-x86_64/page.h
--- a/include/asm-x86_64/page.h	Mon Dec 23 21:21:50 2002
+++ b/include/asm-x86_64/page.h	Mon Dec 23 21:21:50 2002
@@ -16,6 +16,11 @@
 #define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1))
 #define LARGE_PAGE_SIZE (1UL << PMD_SHIFT)
 
+#define HPAGE_SHIFT PMD_SHIFT
+#define HPAGE_SIZE	((1UL) << HPAGE_SHIFT)
+#define HPAGE_MASK	(~(HPAGE_SIZE - 1))
+#define HUGETLB_PAGE_ORDER	(HPAGE_SHIFT - PAGE_SHIFT)
+
 #ifdef __KERNEL__
 #ifndef __ASSEMBLY__
 
diff -Nru a/include/asm-x86_64/pgtable.h b/include/asm-x86_64/pgtable.h
--- a/include/asm-x86_64/pgtable.h	Mon Dec 23 21:21:58 2002
+++ b/include/asm-x86_64/pgtable.h	Mon Dec 23 21:21:58 2002
@@ -23,6 +23,7 @@
 extern pmd_t level2_kernel_pgt[512];
 extern pml4_t init_level4_pgt[];
 extern pgd_t boot_vmalloc_pgt[];
+extern unsigned long __supported_pte_mask;
 
 #define swapper_pg_dir NULL
 
@@ -97,7 +98,7 @@
 }
 
 #define pgd_page(pgd) \
-((unsigned long) __va(pgd_val(pgd) & PAGE_MASK))
+((unsigned long) __va(pgd_val(pgd) & PHYSICAL_PAGE_MASK))
 
 #define ptep_get_and_clear(xp)	__pte(xchg(&(xp)->pte, 0))
 #define pte_same(a, b)		((a).pte == (b).pte)
@@ -159,46 +160,53 @@
 #define _PAGE_CHG_MASK	(PTE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
 
 #define PAGE_NONE	__pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED)
-#define PAGE_SHARED	__pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED)
-#define PAGE_COPY	__pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
-#define PAGE_READONLY	__pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
+#define PAGE_SHARED	__pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED | _PAGE_NX)
+#define PAGE_SHARED_EXEC __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED)
+#define PAGE_COPY    __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | _PAGE_NX)
+#define PAGE_COPY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
+#define PAGE_READONLY	__pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | _PAGE_NX)
+#define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
 
 #define __PAGE_KERNEL \
+	(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_NX)
+#define __PAGE_KERNEL_EXECUTABLE \
 	(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
 #define __PAGE_KERNEL_NOCACHE \
-	(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_PCD | _PAGE_ACCESSED)
+	(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_PCD | _PAGE_ACCESSED | _PAGE_NX)
 #define __PAGE_KERNEL_RO \
-	(_PAGE_PRESENT | _PAGE_DIRTY | _PAGE_ACCESSED)
+	(_PAGE_PRESENT | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_NX)
 #define __PAGE_KERNEL_VSYSCALL \
 	(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
 #define __PAGE_KERNEL_LARGE \
-	(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | _PAGE_PSE)
+	(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | _PAGE_PSE | _PAGE_NX)
 
 #define MAKE_GLOBAL(x) __pgprot((x) | _PAGE_GLOBAL)
 
 #define PAGE_KERNEL MAKE_GLOBAL(__PAGE_KERNEL)
+#define PAGE_KERNEL_EXECUTABLE MAKE_GLOBAL(__PAGE_KERNEL_EXECUTABLE)
 #define PAGE_KERNEL_RO MAKE_GLOBAL(__PAGE_KERNEL_RO)
 #define PAGE_KERNEL_NOCACHE MAKE_GLOBAL(__PAGE_KERNEL_NOCACHE)
 #define PAGE_KERNEL_VSYSCALL MAKE_GLOBAL(__PAGE_KERNEL_VSYSCALL)
 #define PAGE_KERNEL_LARGE MAKE_GLOBAL(__PAGE_KERNEL_LARGE)
 
+/*         xwr */
 #define __P000	PAGE_NONE
 #define __P001	PAGE_READONLY
 #define __P010	PAGE_COPY
 #define __P011	PAGE_COPY
-#define __P100	PAGE_READONLY
-#define __P101	PAGE_READONLY
-#define __P110	PAGE_COPY
-#define __P111	PAGE_COPY
+#define __P100	PAGE_READONLY_EXEC
+#define __P101	PAGE_READONLY_EXEC
+#define __P110	PAGE_COPY_EXEC
+#define __P111	PAGE_COPY_EXEC
 
 #define __S000	PAGE_NONE
 #define __S001	PAGE_READONLY
 #define __S010	PAGE_SHARED
 #define __S011	PAGE_SHARED
-#define __S100	PAGE_READONLY
-#define __S101	PAGE_READONLY
-#define __S110	PAGE_SHARED
-#define __S111	PAGE_SHARED
+#define __S100	PAGE_READONLY_EXEC
+#define __S101	PAGE_READONLY_EXEC
+#define __S110	PAGE_SHARED_EXEC
+#define __S111	PAGE_SHARED_EXEC
 
 static inline unsigned long pgd_bad(pgd_t pgd) 
 { 
@@ -220,11 +228,12 @@
 static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot)
 {
 	pte_t pte;
-	pte_val(pte) = (page_nr << PAGE_SHIFT) | pgprot_val(pgprot); 
+	pte_val(pte) = (page_nr << PAGE_SHIFT);
+	pte_val(pte) |= pgprot_val(pgprot);
+	pte_val(pte) &= __supported_pte_mask;
 	return pte;
 }
 
-
 /*
  * The following only work if pte_present() is true.
  * Undefined behaviour if not..
@@ -303,10 +312,6 @@
 	addr &= PHYSICAL_PAGE_MASK;
 	return __pgd_offset_k((pgd_t *)__va(addr), address);
 }
-
-#if 0 /* disabled because of confusing/wrong naming. */
-#define __pgd_offset(address) pgd_index(address)
-#endif
 
 #define pgd_offset(mm, address) ((mm)->pgd+pgd_index(address))
 
diff -Nru a/include/asm-x86_64/processor.h b/include/asm-x86_64/processor.h
--- a/include/asm-x86_64/processor.h	Mon Dec 23 21:22:00 2002
+++ b/include/asm-x86_64/processor.h	Mon Dec 23 21:22:00 2002
@@ -68,6 +68,7 @@
 #define X86_VENDOR_CENTAUR 5
 #define X86_VENDOR_RISE 6
 #define X86_VENDOR_TRANSMETA 7
+#define X86_VENDOR_NUM 8
 #define X86_VENDOR_UNKNOWN 0xff
 
 extern struct cpuinfo_x86 boot_cpu_data;
@@ -256,7 +257,7 @@
  * space during mmap's.
  */
 #define TASK_UNMAPPED_32 0x40000000
-#define TASK_UNMAPPED_64 (TASK_SIZE/3) 
+#define TASK_UNMAPPED_64 PAGE_ALIGN(TASK_SIZE/3) 
 #define TASK_UNMAPPED_BASE	\
 	(test_thread_flag(TIF_IA32) ? TASK_UNMAPPED_32 : TASK_UNMAPPED_64)  
 
@@ -337,8 +338,8 @@
 #define EXCEPTION_STKSZ 1024
 
 #define start_thread(regs,new_rip,new_rsp) do { \
-	__asm__("movl %0,%%fs; movl %0,%%es; movl %0,%%ds": :"r" (0));		 \
-	wrmsrl(MSR_KERNEL_GS_BASE, 0);						 \
+	asm volatile("movl %0,%%fs; movl %0,%%es; movl %0,%%ds": :"r" (0));	 \
+	load_gs_index(0);							\
 	(regs)->rip = (new_rip);						 \
 	(regs)->rsp = (new_rsp);						 \
 	write_pda(oldrsp, (new_rsp));						 \
@@ -358,7 +359,7 @@
  */
 extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
 
-extern void release_segments(struct mm_struct * mm);
+static inline void release_segments(struct mm_struct *mm) { }
 
 /*
  * Return saved PC of a blocked thread.
@@ -388,5 +389,32 @@
 #define spin_lock_prefetch(x)  prefetchw(x)
 #define cpu_relax()   rep_nop()
 
+
+/*
+ *      NSC/Cyrix CPU configuration register indexes
+ */
+#define CX86_CCR0 0xc0
+#define CX86_CCR1 0xc1
+#define CX86_CCR2 0xc2
+#define CX86_CCR3 0xc3
+#define CX86_CCR4 0xe8
+#define CX86_CCR5 0xe9
+#define CX86_CCR6 0xea
+#define CX86_CCR7 0xeb
+#define CX86_DIR0 0xfe
+#define CX86_DIR1 0xff
+#define CX86_ARR_BASE 0xc4
+#define CX86_RCR_BASE 0xdc
+
+/*
+ *      NSC/Cyrix CPU indexed register access macros
+ */
+
+#define getCx86(reg) ({ outb((reg), 0x22); inb(0x23); })
+
+#define setCx86(reg, data) do { \
+	outb((reg), 0x22); \
+	outb((data), 0x23); \
+} while (0)
 
 #endif /* __ASM_X86_64_PROCESSOR_H */
diff -Nru a/include/asm-x86_64/scatterlist.h b/include/asm-x86_64/scatterlist.h
--- a/include/asm-x86_64/scatterlist.h	Mon Dec 23 21:22:00 2002
+++ b/include/asm-x86_64/scatterlist.h	Mon Dec 23 21:22:00 2002
@@ -4,8 +4,8 @@
 struct scatterlist {
     struct page		*page;
     unsigned int	offset;
-    dma_addr_t		dma_address;
     unsigned int	length;
+    dma_addr_t		dma_address;
 };
 
 #define ISA_DMA_THRESHOLD (0x00ffffff)
diff -Nru a/include/asm-x86_64/socket32.h b/include/asm-x86_64/socket32.h
--- a/include/asm-x86_64/socket32.h	Mon Dec 23 21:21:52 2002
+++ b/include/asm-x86_64/socket32.h	Mon Dec 23 21:21:52 2002
@@ -1,6 +1,8 @@
 #ifndef SOCKET32_H
 #define SOCKET32_H 1
 
+#include <linux/compat.h>
+
 /* XXX This really belongs in some header file... -DaveM */
 #define MAX_SOCK_ADDR	128		/* 108 for Unix domain - 
 					   16 for IP, 16 for IPX,
@@ -11,14 +13,14 @@
         u32               msg_name;
         int               msg_namelen;
         u32               msg_iov;
-        __kernel_size_t32 msg_iovlen;
+        compat_size_t msg_iovlen;
         u32               msg_control;
-        __kernel_size_t32 msg_controllen;
+        compat_size_t msg_controllen;
         unsigned          msg_flags;
 };
 
 struct cmsghdr32 {
-        __kernel_size_t32 cmsg_len;
+        compat_size_t cmsg_len;
         int               cmsg_level;
         int               cmsg_type;
 };
diff -Nru a/include/asm-x86_64/suspend.h b/include/asm-x86_64/suspend.h
--- a/include/asm-x86_64/suspend.h	Mon Dec 23 21:21:55 2002
+++ b/include/asm-x86_64/suspend.h	Mon Dec 23 21:21:55 2002
@@ -1,6 +1,67 @@
-#ifndef SUSPEND_H
-#define SUSPEND_H 1
+/*
+ * Copyright 2001-2002 Pavel Machek <pavel@suse.cz>
+ * Based on code
+ * Copyright 2001 Patrick Mochel <mochel@osdl.org>
+ */
+#include <asm/desc.h>
+#include <asm/i387.h>
 
-/* dummy for now */
+static inline void
+arch_prepare_suspend(void)
+{
+}
 
+/* image of the saved processor state */
+struct saved_context {
+  	u16 ds, es, fs, gs, ss;
+	unsigned long gs_base, fs_base;
+	unsigned long cr0, cr2, cr3, cr4;
+	u16 gdt_pad;
+	u16 gdt_limit;
+	unsigned long gdt_base;
+	u16 idt_pad;
+	u16 idt_limit;
+	unsigned long idt_base;
+	u16 ldt;
+	u16 tss;
+	unsigned long tr;
+	unsigned long safety;
+	unsigned long return_address;
+	unsigned long eflags;
+} __attribute__((packed));
+
+/* We'll access these from assembly, so we'd better have them outside struct */
+extern unsigned long saved_context_eax, saved_context_ebx, saved_context_ecx, saved_context_edx;
+extern unsigned long saved_context_esp, saved_context_ebp, saved_context_esi, saved_context_edi;
+extern unsigned long saved_context_r08, saved_context_r09, saved_context_r10, saved_context_r11;
+extern unsigned long saved_context_r12, saved_context_r13, saved_context_r14, saved_context_r15;
+extern unsigned long saved_context_eflags;
+
+
+#define loaddebug(thread,register) \
+               __asm__("movq %0,%%db" #register  \
+                       : /* no output */ \
+                       :"r" ((thread)->debugreg[register]))
+
+extern void fix_processor_context(void);
+extern void do_magic(int resume);
+
+#ifdef CONFIG_ACPI_SLEEP
+extern unsigned long saved_eip;
+extern unsigned long saved_esp;
+extern unsigned long saved_ebp;
+extern unsigned long saved_ebx;
+extern unsigned long saved_esi;
+extern unsigned long saved_edi;
+
+static inline void acpi_save_register_state(unsigned long return_point)
+{
+	/* FIXME: This is probably no longer correct: we need to save all caller-saved registers */
+}
+
+#define acpi_restore_register_state()  do {} while (0)
+
+/* routines for saving/restoring kernel state */
+extern int acpi_save_state_mem(void);
+extern int acpi_save_state_disk(void);
 #endif
diff -Nru a/include/asm-x86_64/system.h b/include/asm-x86_64/system.h
--- a/include/asm-x86_64/system.h	Mon Dec 23 21:21:59 2002
+++ b/include/asm-x86_64/system.h	Mon Dec 23 21:21:59 2002
@@ -19,8 +19,25 @@
 #define __PUSH(x) "pushq %%" __STR(x) "\n\t"
 #define __POP(x)  "popq  %%" __STR(x) "\n\t"
 
-/* frame pointer must be last for get_wchan */
+struct save_context_frame { 
+	unsigned long rbp; 
+	unsigned long rbx;
+	unsigned long rcx;
+	unsigned long rdx;	
+	unsigned long rsi;
+	unsigned long rdi; 
+	unsigned long rax;
+	unsigned long r15;
+	unsigned long r14;
+	unsigned long r13;
+	unsigned long r12;
+	unsigned long r11;
+	unsigned long r10;
+	unsigned long r9;
+	unsigned long r8; 
+}; 
 
+/* frame pointer must be last for get_wchan */
 /* It would be more efficient to let the compiler clobber most of these registers.
    Clobbering all is not possible because that lets reload freak out. Even just 
    clobbering six generates wrong code with gcc 3.1 for me so do it this way for now.
@@ -44,10 +61,11 @@
 	asm volatile(SAVE_CONTEXT						    \
 		     "movq %%rsp,%[prevrsp]\n\t"				    \
 		     "movq %[nextrsp],%%rsp\n\t"				    \
-		     "movq $1f,%[prevrip]\n\t"					    \
+		     "movq $thread_return,%[prevrip]\n\t"			   \
 		     "pushq %[nextrip]\n\t"					    \
 		     "jmp __switch_to\n\t"		\
-		     "1:\n\t"							    \
+		     ".globl thread_return\n"					\
+		     "thread_return:\n\t"					    \
 		     RESTORE_CONTEXT						    \
 		     :[prevrsp] "=m" (prev->thread.rsp), 			    \
 		      [prevrip] "=m" (prev->thread.rip)			    	    \
@@ -88,25 +106,31 @@
  * Clear and set 'TS' bit respectively
  */
 #define clts() __asm__ __volatile__ ("clts")
-#define read_cr0() ({ \
-	unsigned long __dummy; \
-	__asm__( \
-		"movq %%cr0,%0\n\t" \
-		:"=r" (__dummy)); \
-	__dummy; \
-})
-#define write_cr0(x) \
-	__asm__("movq %0,%%cr0": :"r" (x));
-
-#define read_cr4() ({ \
-	unsigned long __dummy; \
-	__asm__( \
-		"movq %%cr4,%0\n\t" \
-		:"=r" (__dummy)); \
-	__dummy; \
-})
-#define write_cr4(x) \
-	__asm__("movq %0,%%cr4": :"r" (x));
+
+static inline unsigned long read_cr0(void)
+{ 
+	unsigned long cr0;
+	asm volatile("movq %%cr0,%0" : "=r" (cr0));
+	return cr0;
+} 
+
+static inline void write_cr0(unsigned long val) 
+{ 
+	asm volatile("movq %0,%%cr0" :: "r" (val));
+} 
+
+static inline unsigned long read_cr4(void)
+{ 
+	unsigned long cr4;
+	asm("movq %%cr4,%0" : "=r" (cr4));
+	return cr4;
+} 
+
+static inline void write_cr4(unsigned long val)
+{ 
+	asm volatile("movq %0,%%cr4" :: "r" (val));
+} 
+
 #define stts() write_cr0(8 | read_cr0())
 
 #define wbinvd() \
@@ -209,7 +233,6 @@
 #define cmpxchg(ptr,o,n)\
 	((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
 					(unsigned long)(n),sizeof(*(ptr))))
-
 
 #ifdef CONFIG_SMP
 #define smp_mb()	mb()
diff -Nru a/include/asm-x86_64/thread_info.h b/include/asm-x86_64/thread_info.h
--- a/include/asm-x86_64/thread_info.h	Mon Dec 23 21:21:58 2002
+++ b/include/asm-x86_64/thread_info.h	Mon Dec 23 21:21:58 2002
@@ -29,6 +29,7 @@
 	int 			preempt_count;
 
 	mm_segment_t		addr_limit;	
+	struct restart_block    restart_block;
 };
 
 #endif
@@ -46,6 +47,9 @@
 	.cpu	       = 0,			\
 	.preempt_count = 1,			\
 	.addr_limit     = KERNEL_DS,		\
+	.restart_block = {			\
+		.fn = do_no_restart_syscall,	\
+	},					\
 }
 
 #define init_thread_info	(init_thread_union.thread_info)
diff -Nru a/include/asm-x86_64/unistd.h b/include/asm-x86_64/unistd.h
--- a/include/asm-x86_64/unistd.h	Mon Dec 23 21:21:58 2002
+++ b/include/asm-x86_64/unistd.h	Mon Dec 23 21:21:58 2002
@@ -399,15 +399,15 @@
 __SYSCALL(__NR_ioperm, sys_ioperm)
 
 #define __NR_create_module                     174
-__SYSCALL(__NR_create_module, sys_create_module)
+__SYSCALL(__NR_create_module, sys_ni_syscall)
 #define __NR_init_module                       175
 __SYSCALL(__NR_init_module, sys_init_module)
 #define __NR_delete_module                     176
 __SYSCALL(__NR_delete_module, sys_delete_module)
 #define __NR_get_kernel_syms                   177
-__SYSCALL(__NR_get_kernel_syms, sys_get_kernel_syms)
+__SYSCALL(__NR_get_kernel_syms, sys_ni_syscall)
 #define __NR_query_module                      178
-__SYSCALL(__NR_query_module, sys_query_module)
+__SYSCALL(__NR_query_module, sys_ni_syscall)
 
 #define __NR_quotactl                          179
 __SYSCALL(__NR_quotactl, sys_quotactl)
@@ -426,7 +426,8 @@
 #define __NR_tuxcall      		184 /* reserved for tux */
 __SYSCALL(__NR_tuxcall, sys_ni_syscall)
 
-/* 165 currently unused */
+#define __NR_security			185
+__SYSCALL(__NR_security, sys_ni_syscall)
 
 #define __NR_gettid		186
 __SYSCALL(__NR_gettid, sys_gettid)
@@ -483,8 +484,24 @@
 __SYSCALL(__NR_get_thread_area, sys_get_thread_area)
 #define __NR_lookup_dcookie	212
 __SYSCALL(__NR_lookup_dcookie, sys_lookup_dcookie)
+#define __NR_epoll_create	213
+__SYSCALL(__NR_epoll_create, sys_epoll_create)
+#define __NR_epoll_ctl	214
+__SYSCALL(__NR_epoll_ctl, sys_epoll_ctl)
+#define __NR_epoll_wait	215
+__SYSCALL(__NR_epoll_wait, sys_epoll_wait)
+#define __NR_remap_file_pages	216
+__SYSCALL(__NR_remap_file_pages, sys_remap_file_pages)
+#define __NR_getdents64	217
+__SYSCALL(__NR_getdents64, sys_getdents64)
+#define __NR_set_tid_address	218
+__SYSCALL(__NR_set_tid_address, sys_set_tid_address)
+#define __NR_restart_syscall	219
+__SYSCALL(__NR_restart_syscall, sys_restart_syscall)
+#define __NR_semtimedop		220
+__SYSCALL(__NR_semtimedop, sys_semtimedop)
 
-#define __NR_syscall_max __NR_lookup_dcookie
+#define __NR_syscall_max __NR_semtimedop
 #ifndef __NO_STUBS
 
 /* user-visible error numbers are in the range -1 - -4095 */
@@ -605,7 +622,7 @@
 	return sys_setsid();
 }
 
-extern ssize_t sys_write(unsigned int, char *, size_t);
+long sys_write(int fd, const char *buf, size_t size);
 static inline ssize_t write(unsigned int fd, char * buf, size_t count)
 {
 	return sys_write(fd, buf, count);
@@ -651,7 +668,7 @@
 }
 
 struct rusage; 
-asmlinkage long sys_wait4(pid_t pid,unsigned int * stat_addr, 
+long sys_wait4(pid_t pid,unsigned int * stat_addr, 
 			int options, struct rusage * ru);
 static inline pid_t waitpid(int pid, int * wait_stat, int flags)
 {
diff -Nru a/include/linux/agp_backend.h b/include/linux/agp_backend.h
--- a/include/linux/agp_backend.h	Mon Dec 23 21:21:59 2002
+++ b/include/linux/agp_backend.h	Mon Dec 23 21:21:59 2002
@@ -51,6 +51,7 @@
 	INTEL_I850,
 	INTEL_I860,
 	INTEL_460GX,
+	INTEL_I7505,
 	VIA_GENERIC,
 	VIA_VP3,
 	VIA_MVP3,
diff -Nru a/include/linux/amigaffs.h b/include/linux/amigaffs.h
--- a/include/linux/amigaffs.h	Mon Dec 23 21:21:51 2002
+++ b/include/linux/amigaffs.h	Mon Dec 23 21:21:51 2002
@@ -28,7 +28,7 @@
 static inline struct buffer_head *
 affs_bread(struct super_block *sb, int block)
 {
-	pr_debug(KERN_DEBUG "affs_bread: %d\n", block);
+	pr_debug("affs_bread: %d\n", block);
 	if (block >= AFFS_SB(sb)->s_reserved && block < AFFS_SB(sb)->s_partition_size)
 		return sb_bread(sb, block);
 	return NULL;
@@ -36,7 +36,7 @@
 static inline struct buffer_head *
 affs_getblk(struct super_block *sb, int block)
 {
-	pr_debug(KERN_DEBUG "affs_getblk: %d\n", block);
+	pr_debug("affs_getblk: %d\n", block);
 	if (block >= AFFS_SB(sb)->s_reserved && block < AFFS_SB(sb)->s_partition_size)
 		return sb_getblk(sb, block);
 	return NULL;
@@ -45,7 +45,7 @@
 affs_getzeroblk(struct super_block *sb, int block)
 {
 	struct buffer_head *bh;
-	pr_debug(KERN_DEBUG "affs_getzeroblk: %d\n", block);
+	pr_debug("affs_getzeroblk: %d\n", block);
 	if (block >= AFFS_SB(sb)->s_reserved && block < AFFS_SB(sb)->s_partition_size) {
 		bh = sb_getblk(sb, block);
 		lock_buffer(bh);
@@ -60,7 +60,7 @@
 affs_getemptyblk(struct super_block *sb, int block)
 {
 	struct buffer_head *bh;
-	pr_debug(KERN_DEBUG "affs_getemptyblk: %d\n", block);
+	pr_debug("affs_getemptyblk: %d\n", block);
 	if (block >= AFFS_SB(sb)->s_reserved && block < AFFS_SB(sb)->s_partition_size) {
 		bh = sb_getblk(sb, block);
 		wait_on_buffer(bh);
@@ -73,7 +73,7 @@
 affs_brelse(struct buffer_head *bh)
 {
 	if (bh)
-		pr_debug(KERN_DEBUG "affs_brelse: %ld\n", bh->b_blocknr);
+		pr_debug("affs_brelse: %ld\n", bh->b_blocknr);
 	brelse(bh);
 }
 
diff -Nru a/include/linux/buffer_head.h b/include/linux/buffer_head.h
--- a/include/linux/buffer_head.h	Mon Dec 23 21:21:50 2002
+++ b/include/linux/buffer_head.h	Mon Dec 23 21:21:50 2002
@@ -22,6 +22,7 @@
 	BH_New,		/* Disk mapping was newly created by get_block */
 	BH_Async_Read,	/* Is under end_buffer_async_read I/O */
 	BH_Async_Write,	/* Is under end_buffer_async_write I/O */
+	BH_Delay,	/* Buffer is not yet allocated on disk */
 
 	BH_Boundary,	/* Block is followed by a discontiguity */
 	BH_PrivateStart,/* not a state bit, but the first bit available
@@ -105,6 +106,7 @@
 BUFFER_FNS(New, new)
 BUFFER_FNS(Async_Read, async_read)
 BUFFER_FNS(Async_Write, async_write)
+BUFFER_FNS(Delay, delay);
 BUFFER_FNS(Boundary, boundary)
 
 #define bh_offset(bh)		((unsigned long)(bh)->b_data & ~PAGE_MASK)
diff -Nru a/include/linux/device-mapper.h b/include/linux/device-mapper.h
--- a/include/linux/device-mapper.h	Mon Dec 23 21:21:58 2002
+++ b/include/linux/device-mapper.h	Mon Dec 23 21:21:58 2002
@@ -7,13 +7,6 @@
 #ifndef _LINUX_DEVICE_MAPPER_H
 #define _LINUX_DEVICE_MAPPER_H
 
-#define DM_DIR "mapper"	/* Slashes not supported */
-#define DM_MAX_TYPE_NAME 16
-#define DM_NAME_LEN 128
-#define DM_UUID_LEN 129
-
-#ifdef __KERNEL__
-
 struct dm_target;
 struct dm_table;
 struct dm_dev;
@@ -100,7 +93,5 @@
 
 int dm_register_target(struct target_type *t);
 int dm_unregister_target(struct target_type *t);
-
-#endif				/* __KERNEL__ */
 
 #endif				/* _LINUX_DEVICE_MAPPER_H */
diff -Nru a/include/linux/device.h b/include/linux/device.h
--- a/include/linux/device.h	Mon Dec 23 21:22:00 2002
+++ b/include/linux/device.h	Mon Dec 23 21:22:00 2002
@@ -396,22 +396,21 @@
 extern void firmware_unregister(struct subsystem *);
 
 /* debugging and troubleshooting/diagnostic helpers. */
+#define dev_printk(sev, dev, format, arg...)	\
+	printk(sev "%s %s: " format , (dev).driver->name , (dev).bus_id , ## arg)
+
 #ifdef DEBUG
 #define dev_dbg(dev, format, arg...)		\
-	printk (KERN_DEBUG "%s %s: " format ,	\
-		(dev).driver->name , (dev).bus_id , ## arg)
+	dev_printk(KERN_DEBUG , (dev) , format , ## arg)
 #else
 #define dev_dbg(dev, format, arg...) do {} while (0)
 #endif
 
 #define dev_err(dev, format, arg...)		\
-	printk (KERN_ERR "%s %s: " format ,	\
-		(dev).driver->name , (dev).bus_id , ## arg)
+	dev_printk(KERN_ERR , (dev) , format , ## arg)
 #define dev_info(dev, format, arg...)		\
-	printk (KERN_INFO "%s %s: " format ,	\
-		(dev).driver->name , (dev).bus_id , ## arg)
+	dev_printk(KERN_INFO , (dev) , format , ## arg)
 #define dev_warn(dev, format, arg...)		\
-	printk (KERN_WARNING "%s %s: " format ,	\
-		(dev).driver->name , (dev).bus_id , ## arg)
+	dev_printk(KERN_WARNING , (dev) , format , ## arg)
 
 #endif /* _DEVICE_H_ */
diff -Nru a/include/linux/dm-ioctl.h b/include/linux/dm-ioctl.h
--- a/include/linux/dm-ioctl.h	Mon Dec 23 21:21:50 2002
+++ b/include/linux/dm-ioctl.h	Mon Dec 23 21:21:50 2002
@@ -7,8 +7,12 @@
 #ifndef _LINUX_DM_IOCTL_H
 #define _LINUX_DM_IOCTL_H
 
-#include <linux/device-mapper.h>
 #include <linux/types.h>
+
+#define DM_DIR "mapper"	/* Slashes not supported */
+#define DM_MAX_TYPE_NAME 16
+#define DM_NAME_LEN 128
+#define DM_UUID_LEN 129
 
 /*
  * Implements a traditional ioctl interface to the device mapper.
diff -Nru a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/linux/dma-mapping.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,17 @@
+#ifndef _ASM_LINUX_DMA_MAPPING_H
+#define _ASM_LINUX_DMA_MAPPING_H
+
+/* These definitions mirror those in pci.h, so they can be used
+ * interchangeably with their PCI_ counterparts */
+enum dma_data_direction {
+	DMA_BIDIRECTIONAL = 0,
+	DMA_TO_DEVICE = 1,
+	DMA_FROM_DEVICE = 2,
+	DMA_NONE = 3,
+};
+
+#include <asm/dma-mapping.h>
+
+#endif
+
+
diff -Nru a/include/linux/elf.h b/include/linux/elf.h
--- a/include/linux/elf.h	Mon Dec 23 21:21:51 2002
+++ b/include/linux/elf.h	Mon Dec 23 21:21:51 2002
@@ -90,6 +90,9 @@
  */
 #define EM_ALPHA	0x9026
 
+/* Bogus old v850 magic number, used by old tools.  */
+#define EM_CYGNUS_V850	0x9080
+
 /*
  * This is the old interim value for S/390 architecture
  */
@@ -447,6 +450,27 @@
 #define R_390_GOTENT	26	       /* 32 bit PC rel. to GOT entry >> 1. */
 /* Keep this the last entry.  */
 #define R_390_NUM	27
+
+/* x86-64 relocation types */
+#define R_X86_64_NONE		0	/* No reloc */
+#define R_X86_64_64		1	/* Direct 64 bit  */
+#define R_X86_64_PC32		2	/* PC relative 32 bit signed */
+#define R_X86_64_GOT32		3	/* 32 bit GOT entry */
+#define R_X86_64_PLT32		4	/* 32 bit PLT address */
+#define R_X86_64_COPY		5	/* Copy symbol at runtime */
+#define R_X86_64_GLOB_DAT	6	/* Create GOT entry */
+#define R_X86_64_JUMP_SLOT	7	/* Create PLT entry */
+#define R_X86_64_RELATIVE	8	/* Adjust by program base */
+#define R_X86_64_GOTPCREL	9	/* 32 bit signed pc relative
+					   offset to GOT */
+#define R_X86_64_32		10	/* Direct 32 bit zero extended */
+#define R_X86_64_32S		11	/* Direct 32 bit sign extended */
+#define R_X86_64_16		12	/* Direct 16 bit zero extended */
+#define R_X86_64_PC16		13	/* 16 bit sign extended pc relative */
+#define R_X86_64_8		14	/* Direct 8 bit sign extended  */
+#define R_X86_64_PC8		15	/* 8 bit sign extended pc relative */
+
+#define R_X86_64_NUM		16
 
 /* s390 relocations defined by the ABIs */
 #define R_390_NONE	0	       /* No reloc.  */
diff -Nru a/include/linux/ext3_fs_i.h b/include/linux/ext3_fs_i.h
--- a/include/linux/ext3_fs_i.h	Mon Dec 23 21:21:50 2002
+++ b/include/linux/ext3_fs_i.h	Mon Dec 23 21:21:50 2002
@@ -32,9 +32,30 @@
 	__u32	i_file_acl;
 	__u32	i_dir_acl;
 	__u32	i_dtime;
+
+	/*
+	 * i_block_group is the number of the block group which contains
+	 * this file's inode.  Constant across the lifetime of the inode,
+	 * it is ued for making block allocation decisions - we try to
+	 * place a file's data blocks near its inode block, and new inodes
+	 * near to their parent directory's inode.
+	 */
 	__u32	i_block_group;
 	__u32	i_state;		/* Dynamic state flags for ext3 */
+
+	/*
+	 * i_next_alloc_block is the logical (file-relative) number of the
+	 * most-recently-allocated block in this file.  Yes, it is misnamed.
+	 * We use this for detecting linearly ascending allocation requests.
+	 */
 	__u32	i_next_alloc_block;
+
+	/*
+	 * i_next_alloc_goal is the *physical* companion to i_next_alloc_block.
+	 * it the the physical block number of the block which was most-recently
+	 * allocated to this file.  This give us the goal (target) for the next
+	 * allocation when we detect linearly ascending requests.
+	 */
 	__u32	i_next_alloc_goal;
 #ifdef EXT3_PREALLOCATE
 	__u32	i_prealloc_block;
diff -Nru a/include/linux/fb.h b/include/linux/fb.h
--- a/include/linux/fb.h	Mon Dec 23 21:21:52 2002
+++ b/include/linux/fb.h	Mon Dec 23 21:21:52 2002
@@ -412,9 +412,11 @@
 #define fb_readb sbus_readb
 #define fb_readw sbus_readw
 #define fb_readl sbus_readl
+#define fb_readq sbus_readq
 #define fb_writeb sbus_writeb
 #define fb_writew sbus_writew
 #define fb_writel sbus_writel
+#define fb_writeq sbus_writeq
 #define fb_memset sbus_memset_io
 
 #elif defined(__i386__) || defined(__alpha__) || defined(__x86_64__) || defined(__hppa__)
diff -Nru a/include/linux/fs.h b/include/linux/fs.h
--- a/include/linux/fs.h	Mon Dec 23 21:21:52 2002
+++ b/include/linux/fs.h	Mon Dec 23 21:21:52 2002
@@ -1233,6 +1233,7 @@
 extern int sb_min_blocksize(struct super_block *, int);
 
 extern int generic_file_mmap(struct file *, struct vm_area_struct *);
+extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *);
 extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size);
 extern int file_send_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size);
 extern ssize_t generic_file_read(struct file *, char *, size_t, loff_t *);
diff -Nru a/include/linux/gfp.h b/include/linux/gfp.h
--- a/include/linux/gfp.h	Mon Dec 23 21:21:52 2002
+++ b/include/linux/gfp.h	Mon Dec 23 21:21:52 2002
@@ -18,6 +18,7 @@
 #define __GFP_HIGHIO	0x80	/* Can start high mem physical IO? */
 #define __GFP_FS	0x100	/* Can call down to low-level FS? */
 #define __GFP_COLD	0x200	/* Cache-cold page required */
+#define __GFP_NOWARN	0x400	/* Suppress page allocation failure warning */
 
 #define GFP_NOHIGHIO	(             __GFP_WAIT | __GFP_IO)
 #define GFP_NOIO	(             __GFP_WAIT)
diff -Nru a/include/linux/if_bonding.h b/include/linux/if_bonding.h
--- a/include/linux/if_bonding.h	Mon Dec 23 21:21:59 2002
+++ b/include/linux/if_bonding.h	Mon Dec 23 21:21:59 2002
@@ -37,9 +37,10 @@
 
 #define BOND_CHECK_MII_STATUS	(SIOCGMIIPHY)
 
-#define BOND_MODE_ROUNDROBIN    0
-#define BOND_MODE_ACTIVEBACKUP  1
-#define BOND_MODE_XOR           2 
+#define BOND_MODE_ROUNDROBIN	0
+#define BOND_MODE_ACTIVEBACKUP	1
+#define BOND_MODE_XOR		2
+#define BOND_MODE_BROADCAST	3
 
 /* each slave's link has 4 states */
 #define BOND_LINK_UP    0           /* link is up and running */
@@ -74,6 +75,7 @@
 	struct slave *prev;
 	struct net_device *dev;
 	short  delay;
+	unsigned long jiffies;	
 	char   link;    /* one of BOND_LINK_XXXX */
 	char   state;   /* one of BOND_STATE_XXXX */
 	unsigned short original_flags;
@@ -93,6 +95,8 @@
 	slave_t *next;
 	slave_t *prev;
 	slave_t *current_slave;
+	slave_t *primary_slave;
+	slave_t *current_arp_slave;
 	__s32 slave_cnt;
 	rwlock_t lock;
 	rwlock_t ptrlock;
diff -Nru a/include/linux/init_task.h b/include/linux/init_task.h
--- a/include/linux/init_task.h	Mon Dec 23 21:21:51 2002
+++ b/include/linux/init_task.h	Mon Dec 23 21:21:51 2002
@@ -63,7 +63,7 @@
 	.prio		= MAX_PRIO-20,					\
 	.static_prio	= MAX_PRIO-20,					\
 	.policy		= SCHED_NORMAL,					\
-	.cpus_allowed	= -1,						\
+	.cpus_allowed	= ~0UL,						\
 	.mm		= NULL,						\
 	.active_mm	= &init_mm,					\
 	.run_list	= LIST_HEAD_INIT(tsk.run_list),			\
diff -Nru a/include/linux/mmzone.h b/include/linux/mmzone.h
--- a/include/linux/mmzone.h	Mon Dec 23 21:21:50 2002
+++ b/include/linux/mmzone.h	Mon Dec 23 21:21:50 2002
@@ -193,16 +193,6 @@
 extern int numnodes;
 extern struct pglist_data *pgdat_list;
 
-static inline int
-memclass(struct zone *pgzone, struct zone *classzone)
-{
-	if (pgzone->zone_pgdat != classzone->zone_pgdat)
-		return 0;
-	if (pgzone > classzone)
-		return 0;
-	return 1;
-}
-
 void get_zone_counts(unsigned long *active, unsigned long *inactive);
 void build_all_zonelists(void);
 void wakeup_kswapd(struct zone *zone);
@@ -335,11 +325,6 @@
 #define num_online_memblks()		1
 
 #endif /* CONFIG_DISCONTIGMEM || CONFIG_NUMA */
-
-
-#define MAP_ALIGN(x)	((((x) % sizeof(struct page)) == 0) ? (x) : ((x) + \
-		sizeof(struct page) - ((x) % sizeof(struct page))))
-
 #endif /* !__ASSEMBLY__ */
 #endif /* __KERNEL__ */
 #endif /* _LINUX_MMZONE_H */
diff -Nru a/include/linux/nfs4.h b/include/linux/nfs4.h
--- a/include/linux/nfs4.h	Mon Dec 23 21:21:55 2002
+++ b/include/linux/nfs4.h	Mon Dec 23 21:21:55 2002
@@ -203,6 +203,9 @@
 enum {
 	NFSPROC4_CLNT_NULL = 0,		/* Unused */
 	NFSPROC4_CLNT_COMPOUND,		/* Soon to be unused */
+	NFSPROC4_CLNT_READ,
+	NFSPROC4_CLNT_WRITE,
+	NFSPROC4_CLNT_COMMIT,
 };
 
 #endif
diff -Nru a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h
--- a/include/linux/nfs_fs.h	Mon Dec 23 21:21:53 2002
+++ b/include/linux/nfs_fs.h	Mon Dec 23 21:21:53 2002
@@ -222,7 +222,7 @@
 static inline
 loff_t req_offset(struct nfs_page *req)
 {
-	return ((loff_t)req->wb_index) << PAGE_CACHE_SHIFT;
+	return (((loff_t)req->wb_index) << PAGE_CACHE_SHIFT) + req->wb_offset;
 }
 
 /*
@@ -295,8 +295,7 @@
 extern int  nfs_writepages(struct address_space *, struct writeback_control *);
 extern int  nfs_flush_incompatible(struct file *file, struct page *page);
 extern int  nfs_updatepage(struct file *, struct page *, unsigned int, unsigned int);
-extern void nfs_writeback_done(struct rpc_task *task, int stable,
-			       unsigned int arg_count, unsigned int res_count);
+extern void nfs_writeback_done(struct rpc_task *task);
 extern void nfs_writedata_release(struct rpc_task *task);
 
 #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
@@ -369,7 +368,7 @@
 extern int  nfs_readpages(struct file *, struct address_space *,
 		struct list_head *, unsigned);
 extern int  nfs_pagein_list(struct list_head *, int);
-extern void nfs_readpage_result(struct rpc_task *, unsigned int count, int eof);
+extern void nfs_readpage_result(struct rpc_task *);
 extern void nfs_readdata_release(struct rpc_task *);
 
 /*
diff -Nru a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
--- a/include/linux/nfs_xdr.h	Mon Dec 23 21:21:59 2002
+++ b/include/linux/nfs_xdr.h	Mon Dec 23 21:21:59 2002
@@ -35,6 +35,7 @@
 	struct timespec		atime;
 	struct timespec		mtime;
 	struct timespec		ctime;
+	__u32			bitmap[2];	/* NFSv4 returned attribute bitmap */
 	__u64			change_attr;	/* NFSv4 change attribute */
 	__u64			pre_change_attr;/* pre-op NFSv4 change attribute */
 	unsigned long		timestamp;
@@ -346,12 +347,6 @@
 	u32				cl_seqid;          /* request */
 };
 
-struct nfs4_commit {
-	u64				co_start;          /* request */
-	u32				co_len;            /* request */
-	struct nfs_writeverf *		co_verifier;       /* response */
-};
-
 struct nfs4_create {
 	u32				cr_ftype;          /* request */
 	union {                                            /* request */
@@ -422,15 +417,6 @@
 	struct nfs_fh *			pf_fhandle;       /* request */
 };
 
-struct nfs4_read {
-	u64				rd_offset;        /* request */
-	u32				rd_length;        /* request */
-	u32				*rd_eof;          /* response */
-	u32				*rd_bytes_read;   /* response */
-	struct page **			rd_pages;   /* zero-copy data */
-	unsigned int			rd_pgbase;  /* zero-copy data */
-};
-
 struct nfs4_readdir {
 	u64				rd_cookie;        /* request */
 	nfs4_verifier			rd_req_verifier;  /* request */
@@ -476,22 +462,11 @@
 	struct nfs4_client *		sc_state;	  /* response */
 };
 
-struct nfs4_write {
-	u64				wr_offset;        /* request */
-	u32				wr_stable_how;    /* request */
-	u32				wr_len;           /* request */
-	u32 *				wr_bytes_written; /* response */
-	struct nfs_writeverf *		wr_verf;          /* response */
-	struct page **			wr_pages;   /* zero-copy data */
-	unsigned int			wr_pgbase;  /* zero-copy data */
-};
-
 struct nfs4_op {
 	u32				opnum;
 	union {
 		struct nfs4_access	access;
 		struct nfs4_close	close;
-		struct nfs4_commit	commit;
 		struct nfs4_create	create;
 		struct nfs4_getattr	getattr;
 		struct nfs4_getfh	getfh;
@@ -500,7 +475,6 @@
 		struct nfs4_open	open;
 		struct nfs4_open_confirm open_confirm;
 		struct nfs4_putfh	putfh;
-		struct nfs4_read	read;
 		struct nfs4_readdir	readdir;
 		struct nfs4_readlink	readlink;
 		struct nfs4_remove	remove;
@@ -509,7 +483,6 @@
 		struct nfs4_setattr	setattr;
 		struct nfs4_setclientid	setclientid;
 		struct nfs4_client *	setclientid_confirm;
-		struct nfs4_write	write;
 	} u;
 };
 
@@ -548,20 +521,11 @@
 	struct nfs_fattr	fattr;	/* fattr storage */
 	struct list_head	pages;	/* Coalesced read requests */
 	struct page		*pagevec[NFS_READ_MAXIOV];
-	union {
-		struct {
-			struct nfs_readargs args;
-			struct nfs_readres  res;
-		} v3;   /* also v2 */
+	struct nfs_readargs args;
+	struct nfs_readres  res;
 #ifdef CONFIG_NFS_V4
-		struct {
-			struct nfs4_compound  compound;
-			struct nfs4_op        ops[3];
-			u32                   res_count;
-			u32                   res_eof;
-		} v4;
+	unsigned long		timestamp;	/* For lease renewal */
 #endif
-	} u;
 };
 
 struct nfs_write_data {
@@ -572,21 +536,11 @@
 	struct nfs_writeverf	verf;
 	struct list_head	pages;		/* Coalesced requests we wish to flush */
 	struct page		*pagevec[NFS_WRITE_MAXIOV];
-	union {
-		struct {
-			struct nfs_writeargs	args;		/* argument struct */
-			struct nfs_writeres	res;		/* result struct */
-		} v3;
+	struct nfs_writeargs	args;		/* argument struct */
+	struct nfs_writeres	res;		/* result struct */
 #ifdef CONFIG_NFS_V4
-		struct {
-			struct nfs4_compound  compound;
-			struct nfs4_op        ops[3];
-			u32                   arg_count;
-			u32                   arg_stable;
-			u32                   res_count;
-		} v4;
+	unsigned long		timestamp;	/* For lease renewal */
 #endif
-	} u;
 };
 
 /*
diff -Nru a/include/linux/oprofile.h b/include/linux/oprofile.h
--- a/include/linux/oprofile.h	Mon Dec 23 21:21:57 2002
+++ b/include/linux/oprofile.h	Mon Dec 23 21:21:57 2002
@@ -55,7 +55,7 @@
  * Add a sample. This may be called from any context. Pass
  * smp_processor_id() as cpu.
  */
-extern void FASTCALL(oprofile_add_sample(unsigned long eip, unsigned long event, int cpu));
+extern void oprofile_add_sample(unsigned long eip, unsigned long event, int cpu);
 
 /**
  * Create a file of the given name as a child of the given root, with
diff -Nru a/include/linux/pci.h b/include/linux/pci.h
--- a/include/linux/pci.h	Mon Dec 23 21:21:54 2002
+++ b/include/linux/pci.h	Mon Dec 23 21:21:54 2002
@@ -558,8 +558,16 @@
 /* Generic PCI functions used internally */
 
 int pci_bus_exists(const struct list_head *list, int nr);
-struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, void *sysdata);
-struct pci_bus *pci_alloc_primary_bus(int bus);
+struct pci_bus *pci_scan_bus_parented(struct device *parent, int bus, struct pci_ops *ops, void *sysdata);
+static inline struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, void *sysdata)
+{
+	return pci_scan_bus_parented(NULL, bus, ops, sysdata);
+}
+struct pci_bus *pci_alloc_primary_bus_parented(struct device * parent, int bus);
+static inline struct pci_bus *pci_alloc_primary_bus(int bus)
+{
+	return pci_alloc_primary_bus_parented(NULL, bus);
+}
 struct pci_dev *pci_scan_slot(struct pci_dev *temp);
 int pci_proc_attach_device(struct pci_dev *dev);
 int pci_proc_detach_device(struct pci_dev *dev);
@@ -825,6 +833,7 @@
 #define PCIPCI_NATOMA		4
 #define PCIPCI_VIAETBF		8
 #define PCIPCI_VSFX		16
+
 
 #endif /* __KERNEL__ */
 #endif /* LINUX_PCI_H */
diff -Nru a/include/linux/pci_ids.h b/include/linux/pci_ids.h
--- a/include/linux/pci_ids.h	Mon Dec 23 21:21:53 2002
+++ b/include/linux/pci_ids.h	Mon Dec 23 21:21:53 2002
@@ -410,6 +410,7 @@
 #define PCI_DEVICE_ID_AMD_8111_IDE	0x7469
 #define PCI_DEVICE_ID_AMD_8111_AUDIO	0x746d
 #define PCI_DEVICE_ID_AMD_8151_0	0x7454
+#define PCI_DEVICE_ID_AMD_8131_APIC     0x7450
 
 #define PCI_VENDOR_ID_TRIDENT		0x1023
 #define PCI_DEVICE_ID_TRIDENT_4DWAVE_DX	0x2000
@@ -1727,6 +1728,9 @@
 #define PCI_DEVICE_ID_INTEL_82092AA_0	0x1221
 #define PCI_DEVICE_ID_INTEL_82092AA_1	0x1222
 #define PCI_DEVICE_ID_INTEL_7116	0x1223
+#define PCI_DEVICE_ID_INTEL_7505_0	0x2550  
+#define PCI_DEVICE_ID_INTEL_7505_1	0x2552  
+#define PCI_DEVICE_ID_INTEL_7205_0	0x255d
 #define PCI_DEVICE_ID_INTEL_82596	0x1226
 #define PCI_DEVICE_ID_INTEL_82865	0x1227
 #define PCI_DEVICE_ID_INTEL_82557	0x1229
diff -Nru a/include/linux/sched.h b/include/linux/sched.h
--- a/include/linux/sched.h	Mon Dec 23 21:21:51 2002
+++ b/include/linux/sched.h	Mon Dec 23 21:21:51 2002
@@ -419,13 +419,12 @@
 #define PF_MEMALLOC	0x00000800	/* Allocating memory */
 #define PF_MEMDIE	0x00001000	/* Killed for out-of-memory */
 #define PF_FLUSHER	0x00002000	/* responsible for disk writeback */
-#define PF_NOWARN	0x00004000	/* debug: don't warn if alloc fails */
 
-#define PF_FREEZE	0x00008000	/* this task should be frozen for suspend */
-#define PF_IOTHREAD	0x00010000	/* this thread is needed for doing I/O to swap */
-#define PF_FROZEN	0x00020000	/* frozen for system suspend */
-#define PF_FSTRANS	0x00040000	/* inside a filesystem transaction */
-#define PF_KSWAPD	0x00080000	/* I am kswapd */
+#define PF_FREEZE	0x00004000	/* this task should be frozen for suspend */
+#define PF_IOTHREAD	0x00008000	/* this thread is needed for doing I/O to swap */
+#define PF_FROZEN	0x00010000	/* frozen for system suspend */
+#define PF_FSTRANS	0x00020000	/* inside a filesystem transaction */
+#define PF_KSWAPD	0x00040000	/* I am kswapd */
 
 /*
  * Ptrace flags
diff -Nru a/include/linux/slab.h b/include/linux/slab.h
--- a/include/linux/slab.h	Mon Dec 23 21:22:02 2002
+++ b/include/linux/slab.h	Mon Dec 23 21:22:02 2002
@@ -23,7 +23,7 @@
 #define	SLAB_KERNEL		GFP_KERNEL
 #define	SLAB_DMA		GFP_DMA
 
-#define SLAB_LEVEL_MASK		(__GFP_WAIT|__GFP_HIGH|__GFP_IO|__GFP_HIGHIO|__GFP_FS)
+#define SLAB_LEVEL_MASK		(__GFP_WAIT|__GFP_HIGH|__GFP_IO|__GFP_HIGHIO|__GFP_FS|__GFP_COLD|__GFP_NOWARN)
 #define	SLAB_NO_GROW		0x00001000UL	/* don't grow a cache */
 
 /* flags to pass to kmem_cache_create().
diff -Nru a/include/linux/swap.h b/include/linux/swap.h
--- a/include/linux/swap.h	Mon Dec 23 21:21:50 2002
+++ b/include/linux/swap.h	Mon Dec 23 21:21:50 2002
@@ -7,12 +7,18 @@
 #include <linux/linkage.h>
 #include <linux/mmzone.h>
 #include <linux/list.h>
+#include <linux/sched.h>
 #include <asm/atomic.h>
 #include <asm/page.h>
 
 #define SWAP_FLAG_PREFER	0x8000	/* set if swap priority specified */
 #define SWAP_FLAG_PRIO_MASK	0x7fff
 #define SWAP_FLAG_PRIO_SHIFT	0
+
+static inline int current_is_kswapd(void)
+{
+	return current->flags & PF_KSWAPD;
+}
 
 /*
  * MAX_SWAPFILES defines the maximum number of swaptypes: things which can
diff -Nru a/include/linux/sysctl.h b/include/linux/sysctl.h
--- a/include/linux/sysctl.h	Mon Dec 23 21:21:55 2002
+++ b/include/linux/sysctl.h	Mon Dec 23 21:21:55 2002
@@ -544,7 +544,8 @@
 	NET_SCTP_PATH_MAX_RETRANS        =  8,
 	NET_SCTP_MAX_INIT_RETRANSMITS    =  9,
 	NET_SCTP_HB_INTERVAL             = 10,
-	NET_SCTP_MAX_BURST               = 11,
+	NET_SCTP_PRESERVE_ENABLE         = 11,
+	NET_SCTP_MAX_BURST               = 12,
 };
 
 /* CTL_PROC names: */
diff -Nru a/include/net/dst.h b/include/net/dst.h
--- a/include/net/dst.h	Mon Dec 23 21:22:00 2002
+++ b/include/net/dst.h	Mon Dec 23 21:22:00 2002
@@ -10,6 +10,7 @@
 
 #include <linux/config.h>
 #include <linux/rtnetlink.h>
+#include <linux/rcupdate.h>
 #include <net/neighbour.h>
 #include <asm/processor.h>
 
@@ -71,6 +72,7 @@
 #endif
 
 	struct  dst_ops	        *ops;
+	struct rcu_head		rcu_head;
 		
 	char			info[0];
 };
diff -Nru a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
--- a/include/net/sctp/sctp.h	Mon Dec 23 21:21:52 2002
+++ b/include/net/sctp/sctp.h	Mon Dec 23 21:21:52 2002
@@ -123,8 +123,8 @@
 extern struct sock *sctp_get_ctl_sock(void);
 extern int sctp_copy_local_addr_list(sctp_protocol_t *, sctp_bind_addr_t *,
 				     sctp_scope_t, int priority, int flags);
-extern sctp_pf_t *sctp_get_pf_specific(int family);
-extern void sctp_set_pf_specific(int family, sctp_pf_t *);
+extern struct sctp_pf *sctp_get_pf_specific(sa_family_t family);
+extern int sctp_register_pf(struct sctp_pf *, sa_family_t);
 
 /*
  * sctp_socket.c
diff -Nru a/include/net/sctp/sm.h b/include/net/sctp/sm.h
--- a/include/net/sctp/sm.h	Mon Dec 23 21:21:54 2002
+++ b/include/net/sctp/sm.h	Mon Dec 23 21:21:54 2002
@@ -140,6 +140,8 @@
 sctp_state_fn_t sctp_sf_do_5_2_4_dupcook;
 sctp_state_fn_t sctp_sf_unk_chunk;
 sctp_state_fn_t sctp_sf_do_8_5_1_E_sa;
+sctp_state_fn_t sctp_sf_cookie_echoed_err;
+sctp_state_fn_t sctp_sf_do_5_2_6_stale;
 
 /* Prototypes for primitive event state functions.  */
 sctp_state_fn_t sctp_sf_do_prm_asoc;
@@ -175,7 +177,6 @@
  */
 
 /* Prototypes for chunk state functions.  Not in use. */
-sctp_state_fn_t sctp_sf_do_5_2_6_stale;
 sctp_state_fn_t sctp_sf_do_9_2_reshutack;
 sctp_state_fn_t sctp_sf_do_9_2_reshut;
 sctp_state_fn_t sctp_sf_do_9_2_shutack;
@@ -211,7 +212,7 @@
 /* Prototypes for chunk-building functions.  */
 sctp_chunk_t *sctp_make_init(const sctp_association_t *,
 			     const sctp_bind_addr_t *,
-			     int priority);
+			     int priority, int vparam_len);
 sctp_chunk_t *sctp_make_init_ack(const sctp_association_t *,
 				 const sctp_chunk_t *,
 				 const int priority,
@@ -322,9 +323,15 @@
 		 const __u8 *, int addrs_len);
 sctp_association_t *sctp_unpack_cookie(const sctp_endpoint_t *,
 				       const sctp_association_t *,
-				       sctp_chunk_t *, int priority, int *err);
+				       sctp_chunk_t *, int priority, int *err,
+				       sctp_chunk_t **err_chk_p);
 int sctp_addip_addr_config(sctp_association_t *, sctp_param_t,
 			   struct sockaddr_storage*, int);
+void sctp_send_stale_cookie_err(const sctp_endpoint_t *ep,
+				const sctp_association_t *asoc,
+				const sctp_chunk_t *chunk,
+				sctp_cmd_seq_t *commands,
+				sctp_chunk_t *err_chunk);
 
 /* 3rd level prototypes */
 __u32 sctp_generate_tag(const sctp_endpoint_t *);
diff -Nru a/include/net/sctp/structs.h b/include/net/sctp/structs.h
--- a/include/net/sctp/structs.h	Mon Dec 23 21:22:02 2002
+++ b/include/net/sctp/structs.h	Mon Dec 23 21:22:02 2002
@@ -42,6 +42,7 @@
  *    Sridhar Samudrala     <sri@us.ibm.com>
  *    Daisy Chang	    <daisyc@us.ibm.com>
  *    Dajiang Zhang         <dajiang.zhang@nokia.com>
+ *    Ardelle Fan           <ardelle.fan@intel.com> 
  *
  * Any bugs reported given to us we will try to fix... any fixes shared will
  * be incorporated into the next SCTP release.
@@ -182,6 +183,9 @@
 
 	/* Valid.Cookie.Life        - 60  seconds  */
 	int valid_cookie_life;
+	
+	/* Whether Cookie Preservative is enabled(1) or not(0) */ 
+	int cookie_preserve_enable;
 
 	/* Association.Max.Retrans  - 10 attempts
 	 * Path.Max.Retrans         - 5  attempts (per destination address)
@@ -234,7 +238,7 @@
  * Pointers to address related SCTP functions.
  * (i.e. things that depend on the address family.)
  */
-typedef struct sctp_func {
+struct sctp_af {
 	int		(*queue_xmit)	(struct sk_buff *skb);
 	int 		(*setsockopt)	(struct sock *sk,
 					 int level,
@@ -259,27 +263,34 @@
 	void            (*from_skb)     (union sctp_addr *,
 					 struct sk_buff *skb,
 					 int saddr);
+	void            (*from_sk)      (union sctp_addr *,
+					 struct sock *sk);
+	void            (*to_sk)        (union sctp_addr *,
+					 struct sock *sk);
 	int             (*addr_valid)   (union sctp_addr *);
 	sctp_scope_t    (*scope) (union sctp_addr *);
 	void            (*inaddr_any)   (union sctp_addr *, unsigned short);
 	int             (*is_any)       (const union sctp_addr *);
+	int             (*available)    (const union sctp_addr *);
 	__u16		net_header_len;
 	int		sockaddr_len;
 	sa_family_t	sa_family;
 	struct list_head list;
-} sctp_func_t;
+};
 
-sctp_func_t *sctp_get_af_specific(sa_family_t);
+struct sctp_af *sctp_get_af_specific(sa_family_t);
+int sctp_register_af(struct sctp_af *);
 
 /* Protocol family functions. */
 typedef struct sctp_pf {
 	void (*event_msgname)(sctp_ulpevent_t *, char *, int *);
-	void (*skb_msgname)(struct sk_buff *, char *, int *);
-	int  (*af_supported)(sa_family_t);
+	void (*skb_msgname)  (struct sk_buff *, char *, int *);
+	int  (*af_supported) (sa_family_t);
 	int  (*cmp_addr) (const union sctp_addr *,
 			  const union sctp_addr *,
 			  struct sctp_opt *);
-	struct sctp_func *af;
+	int  (*bind_verify) (struct sctp_opt *, union sctp_addr *);
+	struct sctp_af *af;
 } sctp_pf_t;
 
 /* SCTP Socket type: UDP or TCP style. */
@@ -623,7 +634,7 @@
 	union sctp_addr ipaddr;
 
 	/* These are the functions we call to handle LLP stuff.  */
-	sctp_func_t *af_specific;
+	struct sctp_af *af_specific;
 
 	/* Which association do we belong to?  */
 	sctp_association_t *asoc;
@@ -1271,7 +1282,6 @@
 
 	/* The cookie life I award for any cookie.  */
 	struct timeval cookie_life;
-	__u32 cookie_preserve;
 
 	/* Overall     : The overall association error count.
 	 * Error Count : [Clear this any time I get something.]
@@ -1349,6 +1359,9 @@
 	 * to set a_rwnd field in an INIT or a SACK chunk.
 	 */
 	__u32 rwnd;
+
+	/* This is the last advertised value of rwnd over a SACK chunk. */
+	__u32 a_rwnd;
 
 	/* Number of bytes by which the rwnd has slopped.  The rwnd is allowed
 	 * to slop over a maximum of the association's frag_point.
diff -Nru a/include/scsi/scsi.h b/include/scsi/scsi.h
--- a/include/scsi/scsi.h	Mon Dec 23 21:22:01 2002
+++ b/include/scsi/scsi.h	Mon Dec 23 21:22:01 2002
@@ -96,6 +96,12 @@
 #define READ_ELEMENT_STATUS   0xb8
 #define SEND_VOLUME_TAG       0xb6
 #define WRITE_LONG_2          0xea
+#define READ_16               0x88
+#define WRITE_16              0x8a
+#define SERVICE_ACTION_IN     0x9e
+/* values for service action in */
+#define	SAI_READ_CAPACITY_16  0x10
+
 
 /*
  *  Status codes
diff -Nru a/include/sound/ac97_codec.h b/include/sound/ac97_codec.h
--- a/include/sound/ac97_codec.h	Mon Dec 23 21:21:55 2002
+++ b/include/sound/ac97_codec.h	Mon Dec 23 21:21:55 2002
@@ -199,6 +199,10 @@
 #define AC97_ALC650_MULTICH	0x6a
 #define AC97_ALC650_CLOCK	0x7a
 
+/* specific - Yamaha YMF753 */
+#define AC97_YMF753_DIT_CTRL2	0x66	/* DIT Control 2 */
+#define AC97_YMF753_3D_MODE_SEL	0x68	/* 3D Mode Select */
+
 /* ac97->scaps */
 #define AC97_SCAP_AUDIO		(1<<0)	/* audio AC'97 codec */
 #define AC97_SCAP_MODEM		(1<<1)	/* modem AC'97 codec */
diff -Nru a/include/sound/control.h b/include/sound/control.h
--- a/include/sound/control.h	Mon Dec 23 21:21:55 2002
+++ b/include/sound/control.h	Mon Dec 23 21:21:55 2002
@@ -111,6 +111,8 @@
 snd_kcontrol_t *snd_ctl_find_id(snd_card_t * card, snd_ctl_elem_id_t *id);
 
 int snd_ctl_register(snd_card_t *card);
+int snd_ctl_disconnect(snd_card_t *card);
+int snd_ctl_can_unregister(snd_card_t *card);
 int snd_ctl_unregister(snd_card_t *card);
 int snd_ctl_register_ioctl(snd_kctl_ioctl_func_t fcn);
 int snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn);
diff -Nru a/include/sound/core.h b/include/sound/core.h
--- a/include/sound/core.h	Mon Dec 23 21:22:02 2002
+++ b/include/sound/core.h	Mon Dec 23 21:22:02 2002
@@ -24,6 +24,7 @@
 
 #include <linux/sched.h>		/* wake_up() */
 #include <asm/semaphore.h>		/* struct semaphore */
+#include <linux/rwsem.h>		/* struct rw_semaphore */
 
 /* Typedef's */
 typedef struct timeval snd_timestamp_t;
@@ -58,8 +59,9 @@
 } snd_device_type_t;
 
 typedef enum {
-	SNDRV_DEV_BUILD = 0,
-	SNDRV_DEV_REGISTERED = 1
+	SNDRV_DEV_BUILD,
+	SNDRV_DEV_REGISTERED,
+	SNDRV_DEV_DISCONNECTED
 } snd_device_state_t;
 
 typedef enum {
@@ -73,11 +75,13 @@
 
 typedef int (snd_dev_free_t)(snd_device_t *device);
 typedef int (snd_dev_register_t)(snd_device_t *device);
+typedef int (snd_dev_disconnect_t)(snd_device_t *device);
 typedef int (snd_dev_unregister_t)(snd_device_t *device);
 
 typedef struct {
 	snd_dev_free_t *dev_free;
 	snd_dev_register_t *dev_register;
+	snd_dev_disconnect_t *dev_disconnect;
 	snd_dev_unregister_t *dev_unregister;
 } snd_device_ops_t;
 
@@ -109,6 +113,15 @@
 typedef struct _snd_oss_mixer snd_mixer_oss_t;
 #endif
 
+/* monitor files for graceful shutdown (hotplug) */
+
+struct snd_monitor_file {
+	struct file *file;
+	struct snd_monitor_file *next;
+};
+
+struct snd_shutdown_f_ops;	/* define it later */
+
 /* main structure for soundcard */
 
 struct _snd_card {
@@ -129,8 +142,8 @@
 	struct list_head devices;	/* devices */
 
 	unsigned int last_numid;	/* last used numeric ID */
-	rwlock_t control_rwlock;	/* control list lock */
-	rwlock_t control_owner_lock;	/* control list lock */
+	struct rw_semaphore controls_rwsem;	/* controls list lock */
+	rwlock_t ctl_files_rwlock;	/* ctl_files list lock */
 	int controls_count;		/* count of all controls */
 	struct list_head controls;	/* all controls for this card */
 	struct list_head ctl_files;	/* active control files */
@@ -139,6 +152,12 @@
 	snd_info_entry_t *proc_id;	/* the card id */
 	struct proc_dir_entry *proc_root_link;	/* number link to real id */
 
+	struct snd_monitor_file *files; /* all files associated to this card */
+	struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown state */
+	spinlock_t files_lock;		/* lock the files for this card */
+	int shutdown;			/* this card is going down */
+	wait_queue_head_t shutdown_sleep;
+
 #ifdef CONFIG_PM
 	int (*set_power_state) (snd_card_t *card, unsigned int state);
 	void *power_state_private_data;
@@ -285,19 +304,27 @@
 /* init.c */
 
 extern int snd_cards_count;
+extern unsigned int snd_cards_lock;
 extern snd_card_t *snd_cards[SNDRV_CARDS];
 extern rwlock_t snd_card_rwlock;
 #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
-extern int (*snd_mixer_oss_notify_callback)(snd_card_t *card, int free_flag);
+#define SND_MIXER_OSS_NOTIFY_REGISTER	0
+#define SND_MIXER_OSS_NOTIFY_DISCONNECT	1
+#define SND_MIXER_OSS_NOTIFY_FREE	2
+extern int (*snd_mixer_oss_notify_callback)(snd_card_t *card, int cmd);
 #endif
 
 snd_card_t *snd_card_new(int idx, const char *id,
 			 struct module *module, int extra_size);
+int snd_card_disconnect(snd_card_t *card);
 int snd_card_free(snd_card_t *card);
+int snd_card_free_in_thread(snd_card_t *card);
 int snd_card_register(snd_card_t *card);
 int snd_card_info_init(void);
 int snd_card_info_done(void);
 int snd_component_add(snd_card_t *card, const char *component);
+int snd_card_file_add(snd_card_t *card, struct file *file);
+int snd_card_file_remove(snd_card_t *card, struct file *file);
 
 /* device.c */
 
@@ -305,6 +332,8 @@
 		   void *device_data, snd_device_ops_t *ops);
 int snd_device_register(snd_card_t *card, void *device_data);
 int snd_device_register_all(snd_card_t *card);
+int snd_device_disconnect(snd_card_t *card, void *device_data);
+int snd_device_disconnect_all(snd_card_t *card);
 int snd_device_free(snd_card_t *card, void *device_data);
 int snd_device_free_all(snd_card_t *card, snd_device_cmd_t cmd);
 
diff -Nru a/include/sound/cs46xx.h b/include/sound/cs46xx.h
--- a/include/sound/cs46xx.h	Mon Dec 23 21:21:53 2002
+++ b/include/sound/cs46xx.h	Mon Dec 23 21:21:53 2002
@@ -1663,6 +1663,8 @@
 	snd_pcm_substream_t *substream;
 
 	pcm_channel_descriptor_t * pcm_channel;
+
+	int pcm_channel_id;    /* Fron Rear, Center Lfe  ... */
 } cs46xx_pcm_t;
 
 typedef struct {
diff -Nru a/include/sound/cs46xx_dsp_spos.h b/include/sound/cs46xx_dsp_spos.h
--- a/include/sound/cs46xx_dsp_spos.h	Mon Dec 23 21:21:56 2002
+++ b/include/sound/cs46xx_dsp_spos.h	Mon Dec 23 21:21:56 2002
@@ -63,7 +63,6 @@
 #define DSP_SPDIF_STATUS_OUTPUT_ENABLED 1
 #define DSP_SPDIF_STATUS_PLAYBACK_OPEN  2
 #define DSP_SPDIF_STATUS_HW_ENABLED     4
-#define DSP_SPDIF_STATUS_AC3_MODE       8
 
 struct _dsp_module_desc_t;
 
@@ -141,7 +140,6 @@
 	dsp_scb_descriptor_t * pcm_reader_scb;
 	dsp_scb_descriptor_t * src_scb;
 	dsp_scb_descriptor_t * mixer_scb;
-	int pcm_channel_id;
 
 	void * private_data;
 } pcm_channel_descriptor_t;
@@ -196,6 +194,10 @@
 	int spdif_status_in;
 	u16 spdif_input_volume_right;
 	u16 spdif_input_volume_left;
+	/* spdif channel status,
+	   left right and user validity bits */
+	int spdif_csuv_default;
+	int spdif_csuv_stream;
 
 	/* SPDIF input sample rate converter */
 	dsp_scb_descriptor_t * spdif_in_src;
diff -Nru a/include/sound/initval.h b/include/sound/initval.h
--- a/include/sound/initval.h	Mon Dec 23 21:21:50 2002
+++ b/include/sound/initval.h	Mon Dec 23 21:21:50 2002
@@ -155,12 +155,15 @@
 		return 0;
 	for (s = *str; isalpha(*s) || isdigit(*s) || *s == '_'; s++);
 	if (s != *str) {
-		*dst = (char *)kmalloc(s - *str, GFP_KERNEL);
-		if ((d = *dst) != NULL) {
-			s = *str;
-			while (isalpha(*s) || isdigit(*s) || *s == '_')
-				*d++ = *s++;
+		*dst = (char *)kmalloc((s - *str) + 1, GFP_KERNEL);
+		s = *str; d = *dst;
+		while (isalpha(*s) || isdigit(*s) || *s == '_') {
+			if (d != NULL)
+				*d++ = *s;
+			s++;
 		}
+		if (d != NULL)
+			*d = '\0';
 	}
 	*str = s;
 	if (*s == ',') {
diff -Nru a/include/sound/mixer_oss.h b/include/sound/mixer_oss.h
--- a/include/sound/mixer_oss.h	Mon Dec 23 21:21:55 2002
+++ b/include/sound/mixer_oss.h	Mon Dec 23 21:21:55 2002
@@ -61,6 +61,7 @@
 	void (*private_free_recsrc)(snd_mixer_oss_t *mixer);
 	struct semaphore reg_mutex;
 	snd_info_entry_t *proc_entry;
+	int oss_dev_alloc;
 	/* --- */
 	int oss_recsrc;
 };
diff -Nru a/include/sound/mpu401.h b/include/sound/mpu401.h
--- a/include/sound/mpu401.h	Mon Dec 23 21:22:00 2002
+++ b/include/sound/mpu401.h	Mon Dec 23 21:22:00 2002
@@ -41,6 +41,7 @@
 #define MPU401_HW_CMIPCI		15	/* CMIPCI MPU-401 UART */
 #define MPU401_HW_ALS4000		16	/* Avance Logic ALS4000 */
 #define MPU401_HW_INTEL8X0		17	/* Intel8x0 driver */
+#define MPU401_HW_PC98II		18	/* Roland PC98II */
 
 #define MPU401_MODE_BIT_INPUT		0
 #define MPU401_MODE_BIT_OUTPUT		1
@@ -64,6 +65,7 @@
 
 	unsigned short hardware;	/* MPU401_HW_XXXX */
 	unsigned long port;		/* base port of MPU-401 chip */
+	unsigned long cport;		/* port + 1 (usually) */
 	struct resource *res;		/* port resource */
 	int irq;			/* IRQ number of MPU-401 chip (-1 = poll) */
 	int irq_flags;
@@ -89,8 +91,8 @@
 
 /* I/O ports */
 
-#define MPU401C(mpu) ((mpu)->port + 1)
-#define MPU401D(mpu) ((mpu)->port + 0)
+#define MPU401C(mpu) (mpu)->cport
+#define MPU401D(mpu) (mpu)->port
 
 /*
 
diff -Nru a/include/sound/opl3.h b/include/sound/opl3.h
--- a/include/sound/opl3.h	Mon Dec 23 21:21:51 2002
+++ b/include/sound/opl3.h	Mon Dec 23 21:21:51 2002
@@ -229,6 +229,7 @@
 #define OPL3_HW_OPL3_CS		0x0302	/* CS4232/CS4236+ */
 #define OPL3_HW_OPL3_FM801	0x0303	/* FM801 */
 #define OPL3_HW_OPL3_CS4281	0x0304	/* CS4281 */
+#define OPL3_HW_OPL3_PC98	0x0305	/* PC9800 */
 #define OPL3_HW_OPL4		0x0400
 #define OPL3_HW_MASK		0xff00
 
diff -Nru a/include/sound/pcm.h b/include/sound/pcm.h
--- a/include/sound/pcm.h	Mon Dec 23 21:21:55 2002
+++ b/include/sound/pcm.h	Mon Dec 23 21:21:55 2002
@@ -443,8 +443,9 @@
 };
 
 typedef struct _snd_pcm_notify {
-	int (*n_register) (unsigned short minor, snd_pcm_t * pcm);
-	int (*n_unregister) (unsigned short minor, snd_pcm_t * pcm);
+	int (*n_register) (snd_pcm_t * pcm);
+	int (*n_disconnect) (snd_pcm_t * pcm);
+	int (*n_unregister) (snd_pcm_t * pcm);
 	struct list_head list;
 } snd_pcm_notify_t;
 
diff -Nru a/include/sound/pcm_oss.h b/include/sound/pcm_oss.h
--- a/include/sound/pcm_oss.h	Mon Dec 23 21:21:58 2002
+++ b/include/sound/pcm_oss.h	Mon Dec 23 21:21:58 2002
@@ -77,6 +77,7 @@
 
 typedef struct _snd_pcm_oss {
 	int reg;
+	unsigned int reg_mask;
 } snd_pcm_oss_t;
 
 #endif /* __SOUND_PCM_OSS_H */
diff -Nru a/include/sound/sb.h b/include/sound/sb.h
--- a/include/sound/sb.h	Mon Dec 23 21:21:54 2002
+++ b/include/sound/sb.h	Mon Dec 23 21:21:54 2002
@@ -225,7 +225,6 @@
 #define SB_DT019X_MIC_DEV	0x6a
 #define SB_DT019X_SPKR_DEV	0x6a
 #define SB_DT019X_LINE_DEV	0x6e
-#define SB_DT019X_OUTPUT_SW1	0x3c
 #define SB_DT019X_OUTPUT_SW2	0x4c
 #define SB_DT019X_CAPTURE_SW	0x6c
 
@@ -234,6 +233,14 @@
 #define SB_DT019X_CAP_LINE	0x06
 #define SB_DT019X_CAP_SYNTH	0x07
 #define SB_DT019X_CAP_MAIN	0x07
+
+#define SB_ALS4000_MONO_IO_CTRL	0x4b
+#define SB_ALS4000_MIC_IN_GAIN	0x4d
+#define SB_ALS4000_FMDAC	0x4f
+#define SB_ALS4000_3D_SND_FX	0x50
+#define SB_ALS4000_3D_TIME_DELAY	0x51
+#define SB_ALS4000_3D_AUTO_MUTE	0x52
+#define SB_ALS4000_QSOUND	0xdb
 
 /* IRQ setting bitmap */
 #define SB_IRQSETUP_IRQ9	0x01
diff -Nru a/include/sound/trident.h b/include/sound/trident.h
--- a/include/sound/trident.h	Mon Dec 23 21:21:56 2002
+++ b/include/sound/trident.h	Mon Dec 23 21:21:56 2002
@@ -101,10 +101,18 @@
 /* Global registers */
 
 enum global_control_bits {
-	CHANNEL_IDX = 0x0000003f, OVERRUN_IE = 0x00000400,
-	UNDERRUN_IE = 0x00000800, ENDLP_IE   = 0x00001000,
-	MIDLP_IE    = 0x00002000, ETOG_IE    = 0x00004000,
-	EDROP_IE    = 0x00008000, BANK_B_EN  = 0x00010000
+	CHANNEL_IDX	= 0x0000003f,
+	OVERRUN_IE	= 0x00000400,	/* interrupt enable: capture overrun */
+	UNDERRUN_IE	= 0x00000800,	/* interrupt enable: playback underrun */
+	ENDLP_IE	= 0x00001000,	/* interrupt enable: end of buffer */
+	MIDLP_IE	= 0x00002000,	/* interrupt enable: middle buffer */
+	ETOG_IE		= 0x00004000,	/* interrupt enable: envelope toggling */
+	EDROP_IE	= 0x00008000,	/* interrupt enable: envelope drop */
+	BANK_B_EN	= 0x00010000,	/* SiS: enable bank B (64 channels) */
+	PCMIN_B_MIX	= 0x00020000,	/* SiS: PCM IN B mixing enable */
+	I2S_OUT_ASSIGN	= 0x00040000,	/* SiS: I2S Out contains surround PCM */
+	SPDIF_OUT_ASSIGN= 0x00080000,	/* SiS: 0=S/PDIF L/R | 1=PCM Out FIFO */
+	MAIN_OUT_ASSIGN = 0x00100000,	/* SiS: 0=PCM Out FIFO | 1=MMC Out buffer */
 };
 
 enum miscint_bits {
@@ -422,6 +430,8 @@
         
         int ChanPCM;			/* max number of PCM channels */
 	int ChanPCMcnt;			/* actual number of PCM channels */
+
+	int ac97_detect;		/* 1 = AC97 in detection phase */
 
 	struct _snd_4dwave synth;	/* synth specific variables */
 
diff -Nru a/include/sound/version.h b/include/sound/version.h
--- a/include/sound/version.h	Mon Dec 23 21:21:53 2002
+++ b/include/sound/version.h	Mon Dec 23 21:21:53 2002
@@ -1,3 +1,3 @@
 /* include/version.h.  Generated automatically by configure.  */
-#define CONFIG_SND_VERSION "0.9.0rc5"
-#define CONFIG_SND_DATE " (Sun Nov 10 19:48:18 2002 UTC)"
+#define CONFIG_SND_VERSION "0.9.0rc6"
+#define CONFIG_SND_DATE " (Tue Dec 17 19:01:13 2002 UTC)"
diff -Nru a/init/main.c b/init/main.c
--- a/init/main.c	Mon Dec 23 21:21:51 2002
+++ b/init/main.c	Mon Dec 23 21:21:51 2002
@@ -259,6 +259,22 @@
 	return 0;
 }
 
+static int __init init_setup(char *str)
+{
+	unsigned int i;
+
+	execute_command = str;
+	/* In case LILO is going to boot us with default command line,
+	 * it prepends "auto" before the whole cmdline which makes
+	 * the shell think it should execute a script with such name.
+	 * So we ignore all arguments entered _before_ init=... [MJ]
+	 */
+	for (i = 1; i < MAX_INIT_ARGS; i++)
+		argv_init[i] = NULL;
+	return 1;
+}
+__setup("init=", init_setup);
+
 extern void setup_arch(char **);
 extern void cpu_idle(void);
 
diff -Nru a/ipc/shm.c b/ipc/shm.c
--- a/ipc/shm.c	Mon Dec 23 21:21:55 2002
+++ b/ipc/shm.c	Mon Dec 23 21:21:55 2002
@@ -465,7 +465,10 @@
 		tbuf.shm_ctime	= shp->shm_ctim;
 		tbuf.shm_cpid	= shp->shm_cprid;
 		tbuf.shm_lpid	= shp->shm_lprid;
-		tbuf.shm_nattch	= shp->shm_nattch;
+		if (!is_file_hugepages(shp->shm_file))
+			tbuf.shm_nattch	= shp->shm_nattch;
+		else
+			tbuf.shm_nattch = file_count(shp->shm_file) - 1;
 		shm_unlock(shp);
 		if(copy_shmid_to_user (buf, &tbuf, version))
 			err = -EFAULT;
@@ -746,7 +749,7 @@
 				shp->shm_segsz,
 				shp->shm_cprid,
 				shp->shm_lprid,
-				shp->shm_nattch,
+				is_file_hugepages(shp->shm_file) ? (file_count(shp->shm_file) - 1) : shp->shm_nattch,
 				shp->shm_perm.uid,
 				shp->shm_perm.gid,
 				shp->shm_perm.cuid,
diff -Nru a/kernel/capability.c b/kernel/capability.c
--- a/kernel/capability.c	Mon Dec 23 21:21:51 2002
+++ b/kernel/capability.c	Mon Dec 23 21:21:51 2002
@@ -84,13 +84,15 @@
 			      kernel_cap_t *inheritable,
 			      kernel_cap_t *permitted)
 {
-     task_t *g, *target;
+	task_t *g, *target;
+	struct list_head *l;
+	struct pid *pid;
 
-     do_each_thread(g, target) {
-             if (target->pgrp != pgrp)
-                     continue;
-	     security_capset_set(target, effective, inheritable, permitted);
-     } while_each_thread(g, target);
+	for_each_task_pid(pgrp, PIDTYPE_PGID, g, l, pid) {
+		target = g;
+		while_each_thread(g, target)
+			security_capset_set(target, effective, inheritable, permitted);
+	}
 }
 
 /*
diff -Nru a/kernel/ksyms.c b/kernel/ksyms.c
--- a/kernel/ksyms.c	Mon Dec 23 21:21:50 2002
+++ b/kernel/ksyms.c	Mon Dec 23 21:21:50 2002
@@ -228,6 +228,7 @@
 EXPORT_SYMBOL(generic_file_write);
 EXPORT_SYMBOL(generic_file_write_nolock);
 EXPORT_SYMBOL(generic_file_mmap);
+EXPORT_SYMBOL(generic_file_readonly_mmap);
 EXPORT_SYMBOL(generic_ro_fops);
 EXPORT_SYMBOL(file_lock_list);
 EXPORT_SYMBOL(locks_init_lock);
@@ -327,7 +328,9 @@
 /* for stackable file systems (lofs, wrapfs, cryptfs, etc.) */
 EXPORT_SYMBOL(default_llseek);
 EXPORT_SYMBOL(dentry_open);
+#ifdef CONFIG_MMU
 EXPORT_SYMBOL(filemap_nopage);
+#endif
 EXPORT_SYMBOL(filemap_fdatawrite);
 EXPORT_SYMBOL(filemap_fdatawait);
 EXPORT_SYMBOL(lock_page);
@@ -523,7 +526,9 @@
 EXPORT_SYMBOL(single_release);
 
 /* Program loader interfaces */
+#ifdef CONFIG_MMU
 EXPORT_SYMBOL(setup_arg_pages);
+#endif
 EXPORT_SYMBOL(copy_strings_kernel);
 EXPORT_SYMBOL(do_execve);
 EXPORT_SYMBOL(flush_old_exec);
diff -Nru a/kernel/module.c b/kernel/module.c
--- a/kernel/module.c	Mon Dec 23 21:21:58 2002
+++ b/kernel/module.c	Mon Dec 23 21:21:58 2002
@@ -210,7 +210,7 @@
 	struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
 	setscheduler(current->pid, SCHED_FIFO, &param);
 #endif
-	set_cpus_allowed(current, 1 << (unsigned long)cpu);
+	set_cpus_allowed(current, 1UL << (unsigned long)cpu);
 
 	/* Ack: we are alive */
 	atomic_inc(&stopref_thread_ack);
@@ -271,7 +271,7 @@
 
 	/* FIXME: racy with set_cpus_allowed. */
 	old_allowed = current->cpus_allowed;
-	set_cpus_allowed(current, 1 << (unsigned long)cpu);
+	set_cpus_allowed(current, 1UL << (unsigned long)cpu);
 
 	atomic_set(&stopref_thread_ack, 0);
 	stopref_num_threads = 0;
diff -Nru a/kernel/params.c b/kernel/params.c
--- a/kernel/params.c	Mon Dec 23 21:21:59 2002
+++ b/kernel/params.c	Mon Dec 23 21:21:59 2002
@@ -24,7 +24,7 @@
 #if 0
 #define DEBUGP printk
 #else
-#define DEBUGP(fmt , ...)
+#define DEBUGP(fmt, a...)
 #endif
 
 static int parse_one(char *param,
diff -Nru a/lib/radix-tree.c b/lib/radix-tree.c
--- a/lib/radix-tree.c	Mon Dec 23 21:21:52 2002
+++ b/lib/radix-tree.c	Mon Dec 23 21:21:52 2002
@@ -363,7 +363,7 @@
 {
 	radix_tree_node_cachep = kmem_cache_create("radix_tree_node",
 			sizeof(struct radix_tree_node), 0,
-			SLAB_HWCACHE_ALIGN, radix_tree_node_ctor, NULL);
+			0, radix_tree_node_ctor, NULL);
 	if (!radix_tree_node_cachep)
 		panic ("Failed to create radix_tree_node cache\n");
 	radix_tree_node_pool = mempool_create(512, radix_tree_node_pool_alloc,
diff -Nru a/mm/filemap.c b/mm/filemap.c
--- a/mm/filemap.c	Mon Dec 23 21:21:53 2002
+++ b/mm/filemap.c	Mon Dec 23 21:21:53 2002
@@ -1293,8 +1293,20 @@
 	vma->vm_ops = &generic_file_vm_ops;
 	return 0;
 }
+
+int generic_file_readonly_mmap(struct file *file, struct vm_area_struct *vma)
+{
+	if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_WRITE))
+		return -EINVAL;
+	vma->vm_flags &= ~VM_MAYWRITE;
+	return generic_file_mmap(file, vma);
+}
 #else
 int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
+{
+	return -ENOSYS;
+}
+int generic_file_readonly_mmap(struct file * file, struct vm_area_struct * vma)
 {
 	return -ENOSYS;
 }
diff -Nru a/mm/highmem.c b/mm/highmem.c
--- a/mm/highmem.c	Mon Dec 23 21:21:57 2002
+++ b/mm/highmem.c	Mon Dec 23 21:21:57 2002
@@ -452,8 +452,6 @@
 	mempool_t *pool;
 	int bio_gfp;
 
-	BUG_ON((*bio_orig)->bi_idx);
-
 	/*
 	 * for non-isa bounce case, just check if the bounce pfn is equal
 	 * to or bigger than the highest pfn in the system -- in that case,
diff -Nru a/mm/madvise.c b/mm/madvise.c
--- a/mm/madvise.c	Mon Dec 23 21:21:52 2002
+++ b/mm/madvise.c	Mon Dec 23 21:21:52 2002
@@ -57,7 +57,7 @@
 {
 	struct file *file = vma->vm_file;
 
-	if (!vma->vm_file)
+	if (!file)
 		return -EBADF;
 
 	start = ((start - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
diff -Nru a/mm/mempool.c b/mm/mempool.c
--- a/mm/mempool.c	Mon Dec 23 21:21:57 2002
+++ b/mm/mempool.c	Mon Dec 23 21:21:57 2002
@@ -187,12 +187,9 @@
 	unsigned long flags;
 	DEFINE_WAIT(wait);
 	int gfp_nowait = gfp_mask & ~(__GFP_WAIT | __GFP_IO);
-	int pf_flags = current->flags;
 
 repeat_alloc:
-	current->flags |= PF_NOWARN;
-	element = pool->alloc(gfp_nowait, pool->pool_data);
-	current->flags = pf_flags;
+	element = pool->alloc(gfp_nowait|__GFP_NOWARN, pool->pool_data);
 	if (likely(element != NULL))
 		return element;
 
diff -Nru a/mm/mremap.c b/mm/mremap.c
--- a/mm/mremap.c	Mon Dec 23 21:21:55 2002
+++ b/mm/mremap.c	Mon Dec 23 21:21:55 2002
@@ -227,6 +227,10 @@
 	}
 
 	if (!move_page_tables(vma, new_addr, addr, old_len)) {
+		unsigned long must_fault_in;
+		unsigned long fault_in_start;
+		unsigned long fault_in_end;
+
 		if (allocated_vma) {
 			*new_vma = *vma;
 			INIT_LIST_HEAD(&new_vma->shared);
@@ -251,19 +255,25 @@
 		} else
 			vma = NULL;		/* nothing more to do */
 
+		must_fault_in = new_vma->vm_flags & VM_LOCKED;
+		fault_in_start = new_vma->vm_start;
+		fault_in_end = new_vma->vm_end;
+
 		do_munmap(current->mm, addr, old_len);
 
+		/* new_vma could have been invalidated by do_munmap */
+
 		/* Restore VM_ACCOUNT if one or two pieces of vma left */
 		if (vma) {
 			vma->vm_flags |= VM_ACCOUNT;
 			if (split)
 				vma->vm_next->vm_flags |= VM_ACCOUNT;
 		}
+
 		current->mm->total_vm += new_len >> PAGE_SHIFT;
-		if (new_vma->vm_flags & VM_LOCKED) {
+		if (must_fault_in) {
 			current->mm->locked_vm += new_len >> PAGE_SHIFT;
-			make_pages_present(new_vma->vm_start,
-					   new_vma->vm_end);
+			make_pages_present(fault_in_start, fault_in_end);
 		}
 		return new_addr;
 	}
diff -Nru a/mm/page_alloc.c b/mm/page_alloc.c
--- a/mm/page_alloc.c	Mon Dec 23 21:21:51 2002
+++ b/mm/page_alloc.c	Mon Dec 23 21:21:51 2002
@@ -543,7 +543,7 @@
 	}
 
 nopage:
-	if (!(current->flags & PF_NOWARN)) {
+	if (!(gfp_mask & __GFP_NOWARN)) {
 		printk("%s: page allocation failure."
 			" order:%d, mode:0x%x\n",
 			current->comm, order, gfp_mask);
diff -Nru a/mm/slab.c b/mm/slab.c
--- a/mm/slab.c	Mon Dec 23 21:21:59 2002
+++ b/mm/slab.c	Mon Dec 23 21:21:59 2002
@@ -339,8 +339,9 @@
 #define	RED_MAGIC2	0x170FC2A5UL	/* when obj is inactive */
 
 /* ...and for poisoning */
-#define	POISON_BYTE	0x5a		/* byte value for poisoning */
-#define	POISON_END	0xa5		/* end-byte of poisoning */
+#define	POISON_BEFORE	0x5a	/* for use-uninitialised poisoning */
+#define POISON_AFTER	0x6b	/* for use-after-free poisoning */
+#define	POISON_END	0xa5	/* end-byte of poisoning */
 
 #endif
 
@@ -744,14 +745,14 @@
 }
 
 #if DEBUG
-static void poison_obj (kmem_cache_t *cachep, void *addr)
+static void poison_obj(kmem_cache_t *cachep, void *addr, unsigned char val)
 {
 	int size = cachep->objsize;
 	if (cachep->flags & SLAB_RED_ZONE) {
 		addr += BYTES_PER_WORD;
 		size -= 2*BYTES_PER_WORD;
 	}
-	memset(addr, POISON_BYTE, size);
+	memset(addr, val, size);
 	*(unsigned char *)(addr+size-1) = POISON_END;
 }
 
@@ -1266,7 +1267,7 @@
 #if DEBUG
 		/* need to poison the objs? */
 		if (cachep->flags & SLAB_POISON)
-			poison_obj(cachep, objp);
+			poison_obj(cachep, objp, POISON_BEFORE);
 
 		if (cachep->flags & SLAB_RED_ZONE) {
 			*((unsigned long*)(objp)) = RED_MAGIC1;
@@ -1481,9 +1482,8 @@
 		else
 			cachep->dtor(objp, cachep, 0);
 	}
-	if (cachep->flags & SLAB_POISON) {
-		poison_obj(cachep, objp);
-	}
+	if (cachep->flags & SLAB_POISON)
+		poison_obj(cachep, objp, POISON_AFTER);
 #endif
 	return objp;
 }
diff -Nru a/mm/swap.c b/mm/swap.c
--- a/mm/swap.c	Mon Dec 23 21:21:53 2002
+++ b/mm/swap.c	Mon Dec 23 21:21:53 2002
@@ -21,7 +21,6 @@
 #include <linux/init.h>
 #include <linux/mm_inline.h>
 #include <linux/buffer_head.h>
-#include <linux/prefetch.h>
 #include <linux/percpu.h>
 
 /* How many pages do we try to swap or page in/out together? */
diff -Nru a/mm/swap_state.c b/mm/swap_state.c
--- a/mm/swap_state.c	Mon Dec 23 21:21:53 2002
+++ b/mm/swap_state.c	Mon Dec 23 21:21:53 2002
@@ -145,15 +145,12 @@
 
 		pf_flags = current->flags;
 		current->flags &= ~PF_MEMALLOC;
-		current->flags |= PF_NOWARN;
 
 		/*
 		 * Add it to the swap cache and mark it dirty
 		 */
 		err = add_to_page_cache(page, &swapper_space, entry.val);
 
-		if (!(pf_flags & PF_NOWARN))
-			current->flags &= ~PF_NOWARN;
 		if (pf_flags & PF_MEMALLOC)
 			current->flags |= PF_MEMALLOC;
 
diff -Nru a/mm/vmscan.c b/mm/vmscan.c
--- a/mm/vmscan.c	Mon Dec 23 21:21:51 2002
+++ b/mm/vmscan.c	Mon Dec 23 21:21:51 2002
@@ -204,6 +204,19 @@
 	return page_count(page) - !!PagePrivate(page) == 2;
 }
 
+static int may_write_to_queue(struct backing_dev_info *bdi)
+{
+	if (current_is_kswapd())
+		return 1;
+	if (current_is_pdflush())	/* This is unlikely, but why not... */
+		return 1;
+	if (!bdi_write_congested(bdi))
+		return 1;
+	if (bdi == current->backing_dev_info)
+		return 1;
+	return 0;
+}
+
 /*
  * shrink_list returns the number of reclaimed pages
  */
@@ -303,8 +316,6 @@
 		 * See swapfile.c:page_queue_congested().
 		 */
 		if (PageDirty(page)) {
-			struct backing_dev_info *bdi;
-
 			if (!is_page_cache_freeable(page))
 				goto keep_locked;
 			if (!mapping)
@@ -313,10 +324,9 @@
 				goto activate_locked;
 			if (!may_enter_fs)
 				goto keep_locked;
-			bdi = mapping->backing_dev_info;
-			if (bdi != current->backing_dev_info &&
-					bdi_write_congested(bdi))
+			if (!may_write_to_queue(mapping->backing_dev_info))
 				goto keep_locked;
+			write_lock(&mapping->page_lock);
 			if (test_clear_page_dirty(page)) {
 				int res;
 				struct writeback_control wbc = {
@@ -326,7 +336,6 @@
 					.for_reclaim = 1,
 				};
 
-				write_lock(&mapping->page_lock);
 				list_move(&page->list, &mapping->locked_pages);
 				write_unlock(&mapping->page_lock);
 
@@ -343,6 +352,7 @@
 				}
 				goto keep;
 			}
+			write_unlock(&mapping->page_lock);
 		}
 
 		/*
@@ -423,7 +433,7 @@
 	if (pagevec_count(&freed_pvec))
 		__pagevec_release_nonlru(&freed_pvec);
 	mod_page_state(pgsteal, ret);
-	if (current->flags & PF_KSWAPD)
+	if (current_is_kswapd())
 		mod_page_state(kswapd_steal, ret);
 	mod_page_state(pgactivate, pgactivate);
 	return ret;
diff -Nru a/net/core/netfilter.c b/net/core/netfilter.c
--- a/net/core/netfilter.c	Mon Dec 23 21:21:54 2002
+++ b/net/core/netfilter.c	Mon Dec 23 21:21:54 2002
@@ -574,7 +574,15 @@
 	/* Release those devices we held, or Alexey will kill me. */
 	if (info->indev) dev_put(info->indev);
 	if (info->outdev) dev_put(info->outdev);
-	
+#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
+	if (skb->nf_bridge) {
+		if (skb->nf_bridge->physindev)
+			dev_put(skb->nf_bridge->physindev);
+		if (skb->nf_bridge->physoutdev)
+			dev_put(skb->nf_bridge->physoutdev);
+	}
+#endif
+
 	kfree(info);
 	return;
 }
diff -Nru a/net/core/pktgen.c b/net/core/pktgen.c
--- a/net/core/pktgen.c	Mon Dec 23 21:21:58 2002
+++ b/net/core/pktgen.c	Mon Dec 23 21:21:58 2002
@@ -207,13 +207,13 @@
 
 
 /** Convert to miliseconds */
-inline __u64 tv_to_ms(const struct timeval* tv) {
+static inline __u64 tv_to_ms(const struct timeval* tv) {
 	__u64 ms = tv->tv_usec / 1000;
 	ms += (__u64)tv->tv_sec * (__u64)1000;
 	return ms;
 }
 
-inline __u64 getCurMs(void) {
+static inline __u64 getCurMs(void) {
 	struct timeval tv;
 	do_gettimeofday(&tv);
 	return tv_to_ms(&tv);
@@ -1277,7 +1277,7 @@
 }
 
 
-int create_proc_dir(void)
+static int create_proc_dir(void)
 {
 	int     len;
 	/*  does proc_dir already exists */
@@ -1295,7 +1295,7 @@
 	return 1;
 }
 
-int remove_proc_dir(void)
+static int remove_proc_dir(void)
 {
 	remove_proc_entry(PG_PROC_DIR, proc_net);
 	return 1;
diff -Nru a/net/ipv4/route.c b/net/ipv4/route.c
--- a/net/ipv4/route.c	Mon Dec 23 21:22:01 2002
+++ b/net/ipv4/route.c	Mon Dec 23 21:22:01 2002
@@ -86,6 +86,7 @@
 #include <linux/mroute.h>
 #include <linux/netfilter_ipv4.h>
 #include <linux/random.h>
+#include <linux/rcupdate.h>
 #include <net/protocol.h>
 #include <net/ip.h>
 #include <net/route.h>
@@ -178,7 +179,7 @@
 
 /* The locking scheme is rather straight forward:
  *
- * 1) A BH protected rwlocks protect buckets of the central route hash.
+ * 1) Read-Copy Update protects the buckets of the central route hash.
  * 2) Only writers remove entries, and they hold the lock
  *    as they look at rtable reference counts.
  * 3) Only readers acquire references to rtable entries,
@@ -188,7 +189,7 @@
 
 struct rt_hash_bucket {
 	struct rtable	*chain;
-	rwlock_t	lock;
+	spinlock_t	lock;
 } __attribute__((__aligned__(8)));
 
 static struct rt_hash_bucket 	*rt_hash_table;
@@ -220,11 +221,11 @@
 	struct rt_cache_iter_state *st = seq->private;
 
 	for (st->bucket = rt_hash_mask; st->bucket >= 0; --st->bucket) {
-		read_lock_bh(&rt_hash_table[st->bucket].lock);
+		rcu_read_lock();
 		r = rt_hash_table[st->bucket].chain;
 		if (r)
 			break;
-		read_unlock_bh(&rt_hash_table[st->bucket].lock);
+		rcu_read_unlock();
 	}
 	return r;
 }
@@ -233,12 +234,13 @@
 {
 	struct rt_cache_iter_state *st = seq->private;
 
+	read_barrier_depends();
 	r = r->u.rt_next;
 	while (!r) {
-		read_unlock_bh(&rt_hash_table[st->bucket].lock);
+		rcu_read_unlock();
 		if (--st->bucket < 0)
 			break;
-		read_lock_bh(&rt_hash_table[st->bucket].lock);
+		rcu_read_lock();
 		r = rt_hash_table[st->bucket].chain;
 	}
 	return r;
@@ -276,7 +278,7 @@
 	if (v && v != (void *)1) {
 		struct rt_cache_iter_state *st = seq->private;
 
-		read_unlock_bh(&rt_hash_table[st->bucket].lock);
+		rcu_read_unlock();
 	}
 }
 
@@ -406,13 +408,13 @@
   
 static __inline__ void rt_free(struct rtable *rt)
 {
-	dst_free(&rt->u.dst);
+	call_rcu(&rt->u.dst.rcu_head, (void (*)(void *))dst_free, &rt->u.dst);
 }
 
 static __inline__ void rt_drop(struct rtable *rt)
 {
 	ip_rt_put(rt);
-	dst_free(&rt->u.dst);
+	call_rcu(&rt->u.dst.rcu_head, (void (*)(void *))dst_free, &rt->u.dst);
 }
 
 static __inline__ int rt_fast_clean(struct rtable *rth)
@@ -465,7 +467,7 @@
 		i = (i + 1) & rt_hash_mask;
 		rthp = &rt_hash_table[i].chain;
 
-		write_lock(&rt_hash_table[i].lock);
+		spin_lock(&rt_hash_table[i].lock);
 		while ((rth = *rthp) != NULL) {
 			if (rth->u.dst.expires) {
 				/* Entry is expired even if it is in use */
@@ -484,7 +486,7 @@
 			*rthp = rth->u.rt_next;
 			rt_free(rth);
 		}
-		write_unlock(&rt_hash_table[i].lock);
+		spin_unlock(&rt_hash_table[i].lock);
 
 		/* Fallback loop breaker. */
 		if ((jiffies - now) > 0)
@@ -507,11 +509,11 @@
 	rt_deadline = 0;
 
 	for (i = rt_hash_mask; i >= 0; i--) {
-		write_lock_bh(&rt_hash_table[i].lock);
+		spin_lock_bh(&rt_hash_table[i].lock);
 		rth = rt_hash_table[i].chain;
 		if (rth)
 			rt_hash_table[i].chain = NULL;
-		write_unlock_bh(&rt_hash_table[i].lock);
+		spin_unlock_bh(&rt_hash_table[i].lock);
 
 		for (; rth; rth = next) {
 			next = rth->u.rt_next;
@@ -635,7 +637,7 @@
 
 			k = (k + 1) & rt_hash_mask;
 			rthp = &rt_hash_table[k].chain;
-			write_lock_bh(&rt_hash_table[k].lock);
+			spin_lock_bh(&rt_hash_table[k].lock);
 			while ((rth = *rthp) != NULL) {
 				if (!rt_may_expire(rth, tmo, expire)) {
 					tmo >>= 1;
@@ -646,7 +648,7 @@
 				rt_free(rth);
 				goal--;
 			}
-			write_unlock_bh(&rt_hash_table[k].lock);
+			spin_unlock_bh(&rt_hash_table[k].lock);
 			if (goal <= 0)
 				break;
 		}
@@ -714,7 +716,7 @@
 restart:
 	rthp = &rt_hash_table[hash].chain;
 
-	write_lock_bh(&rt_hash_table[hash].lock);
+	spin_lock_bh(&rt_hash_table[hash].lock);
 	while ((rth = *rthp) != NULL) {
 		if (compare_keys(&rth->fl, &rt->fl)) {
 			/* Put it first */
@@ -725,7 +727,7 @@
 			rth->u.dst.__use++;
 			dst_hold(&rth->u.dst);
 			rth->u.dst.lastuse = now;
-			write_unlock_bh(&rt_hash_table[hash].lock);
+			spin_unlock_bh(&rt_hash_table[hash].lock);
 
 			rt_drop(rt);
 			*rp = rth;
@@ -741,7 +743,7 @@
 	if (rt->rt_type == RTN_UNICAST || rt->fl.iif == 0) {
 		int err = arp_bind_neighbour(&rt->u.dst);
 		if (err) {
-			write_unlock_bh(&rt_hash_table[hash].lock);
+			spin_unlock_bh(&rt_hash_table[hash].lock);
 
 			if (err != -ENOBUFS) {
 				rt_drop(rt);
@@ -782,7 +784,7 @@
 	}
 #endif
 	rt_hash_table[hash].chain = rt;
-	write_unlock_bh(&rt_hash_table[hash].lock);
+	spin_unlock_bh(&rt_hash_table[hash].lock);
 	*rp = rt;
 	return 0;
 }
@@ -849,7 +851,7 @@
 {
 	struct rtable **rthp;
 
-	write_lock_bh(&rt_hash_table[hash].lock);
+	spin_lock_bh(&rt_hash_table[hash].lock);
 	ip_rt_put(rt);
 	for (rthp = &rt_hash_table[hash].chain; *rthp;
 	     rthp = &(*rthp)->u.rt_next)
@@ -858,7 +860,7 @@
 			rt_free(rt);
 			break;
 		}
-	write_unlock_bh(&rt_hash_table[hash].lock);
+	spin_unlock_bh(&rt_hash_table[hash].lock);
 }
 
 void ip_rt_redirect(u32 old_gw, u32 daddr, u32 new_gw,
@@ -897,10 +899,11 @@
 
 			rthp=&rt_hash_table[hash].chain;
 
-			read_lock(&rt_hash_table[hash].lock);
+			rcu_read_lock();
 			while ((rth = *rthp) != NULL) {
 				struct rtable *rt;
 
+				read_barrier_depends();
 				if (rth->fl.fl4_dst != daddr ||
 				    rth->fl.fl4_src != skeys[i] ||
 				    rth->fl.fl4_tos != tos ||
@@ -918,7 +921,7 @@
 					break;
 
 				dst_clone(&rth->u.dst);
-				read_unlock(&rt_hash_table[hash].lock);
+				rcu_read_unlock();
 
 				rt = dst_alloc(&ipv4_dst_ops);
 				if (rt == NULL) {
@@ -929,6 +932,7 @@
 
 				/* Copy all the information. */
 				*rt = *rth;
+ 				INIT_RCU_HEAD(&rt->u.dst.rcu_head);
 				rt->u.dst.__use		= 1;
 				atomic_set(&rt->u.dst.__refcnt, 1);
 				if (rt->u.dst.dev)
@@ -964,7 +968,7 @@
 					ip_rt_put(rt);
 				goto do_next;
 			}
-			read_unlock(&rt_hash_table[hash].lock);
+			rcu_read_unlock();
 		do_next:
 			;
 		}
@@ -1144,9 +1148,10 @@
 	for (i = 0; i < 2; i++) {
 		unsigned hash = rt_hash_code(daddr, skeys[i], tos);
 
-		read_lock(&rt_hash_table[hash].lock);
+		rcu_read_lock();
 		for (rth = rt_hash_table[hash].chain; rth;
 		     rth = rth->u.rt_next) {
+			read_barrier_depends();
 			if (rth->fl.fl4_dst == daddr &&
 			    rth->fl.fl4_src == skeys[i] &&
 			    rth->rt_dst  == daddr &&
@@ -1182,7 +1187,7 @@
 				}
 			}
 		}
-		read_unlock(&rt_hash_table[hash].lock);
+		rcu_read_unlock();
 	}
 	return est_mtu ? : new_mtu;
 }
@@ -1736,8 +1741,9 @@
 	tos &= IPTOS_RT_MASK;
 	hash = rt_hash_code(daddr, saddr ^ (iif << 5), tos);
 
-	read_lock(&rt_hash_table[hash].lock);
+	rcu_read_lock();
 	for (rth = rt_hash_table[hash].chain; rth; rth = rth->u.rt_next) {
+		read_barrier_depends();
 		if (rth->fl.fl4_dst == daddr &&
 		    rth->fl.fl4_src == saddr &&
 		    rth->fl.iif == iif &&
@@ -1750,12 +1756,12 @@
 			dst_hold(&rth->u.dst);
 			rth->u.dst.__use++;
 			rt_cache_stat[smp_processor_id()].in_hit++;
-			read_unlock(&rt_hash_table[hash].lock);
+			rcu_read_unlock();
 			skb->dst = (struct dst_entry*)rth;
 			return 0;
 		}
 	}
-	read_unlock(&rt_hash_table[hash].lock);
+	rcu_read_unlock();
 
 	/* Multicast recognition logic is moved from route cache to here.
 	   The problem was that too many Ethernet cards have broken/missing
@@ -2100,8 +2106,9 @@
 
 	hash = rt_hash_code(flp->fl4_dst, flp->fl4_src ^ (flp->oif << 5), flp->fl4_tos);
 
-	read_lock_bh(&rt_hash_table[hash].lock);
+	rcu_read_lock();
 	for (rth = rt_hash_table[hash].chain; rth; rth = rth->u.rt_next) {
+		read_barrier_depends();
 		if (rth->fl.fl4_dst == flp->fl4_dst &&
 		    rth->fl.fl4_src == flp->fl4_src &&
 		    rth->fl.iif == 0 &&
@@ -2115,12 +2122,12 @@
 			dst_hold(&rth->u.dst);
 			rth->u.dst.__use++;
 			rt_cache_stat[smp_processor_id()].out_hit++;
-			read_unlock_bh(&rt_hash_table[hash].lock);
+			rcu_read_unlock();
 			*rp = rth;
 			return 0;
 		}
 	}
-	read_unlock_bh(&rt_hash_table[hash].lock);
+	rcu_read_unlock();
 
 	return ip_route_output_slow(rp, flp);
 }
@@ -2328,9 +2335,10 @@
 		if (h < s_h) continue;
 		if (h > s_h)
 			s_idx = 0;
-		read_lock_bh(&rt_hash_table[h].lock);
+		rcu_read_lock();
 		for (rt = rt_hash_table[h].chain, idx = 0; rt;
 		     rt = rt->u.rt_next, idx++) {
+			read_barrier_depends();
 			if (idx < s_idx)
 				continue;
 			skb->dst = dst_clone(&rt->u.dst);
@@ -2338,12 +2346,12 @@
 					 cb->nlh->nlmsg_seq,
 					 RTM_NEWROUTE, 1) <= 0) {
 				dst_release(xchg(&skb->dst, NULL));
-				read_unlock_bh(&rt_hash_table[h].lock);
+				rcu_read_unlock();
 				goto done;
 			}
 			dst_release(xchg(&skb->dst, NULL));
 		}
-		read_unlock_bh(&rt_hash_table[h].lock);
+		rcu_read_unlock();
 	}
 
 done:
@@ -2627,7 +2635,7 @@
 
 	rt_hash_mask--;
 	for (i = 0; i <= rt_hash_mask; i++) {
-		rt_hash_table[i].lock = RW_LOCK_UNLOCKED;
+		rt_hash_table[i].lock = SPIN_LOCK_UNLOCKED;
 		rt_hash_table[i].chain = NULL;
 	}
 
diff -Nru a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
--- a/net/ipv4/tcp_ipv4.c	Mon Dec 23 21:21:53 2002
+++ b/net/ipv4/tcp_ipv4.c	Mon Dec 23 21:21:53 2002
@@ -2236,6 +2236,7 @@
 			goto get_req;
 		}
 		read_unlock_bh(&tp->syn_wait_lock);
+		sk = sk->next;
 	}
 	if (++st->bucket < TCP_LHTABLE_SIZE) {
 		sk = tcp_listening_hash[st->bucket];
diff -Nru a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
--- a/net/ipv6/ndisc.c	Mon Dec 23 21:21:56 2002
+++ b/net/ipv6/ndisc.c	Mon Dec 23 21:21:56 2002
@@ -871,6 +871,7 @@
 	}
 
 	if (!ndisc_parse_options(opt, optlen, &ndopts)) {
+		in6_dev_put(in6_dev);
 		if (net_ratelimit())
 			ND_PRINTK2(KERN_WARNING
 				   "ICMP6 RA: invalid ND option, ignored.\n");
diff -Nru a/net/key/af_key.c b/net/key/af_key.c
--- a/net/key/af_key.c	Mon Dec 23 21:21:52 2002
+++ b/net/key/af_key.c	Mon Dec 23 21:21:52 2002
@@ -1,5 +1,5 @@
 /*
- * net/key/pfkeyv2.c	An implemenation of PF_KEYv2 sockets.
+ * net/key/af_key.c	An implementation of PF_KEYv2 sockets.
  *
  *		This program is free software; you can redistribute it and/or
  *		modify it under the terms of the GNU General Public License
diff -Nru a/net/sctp/associola.c b/net/sctp/associola.c
--- a/net/sctp/associola.c	Mon Dec 23 21:21:50 2002
+++ b/net/sctp/associola.c	Mon Dec 23 21:21:50 2002
@@ -128,8 +128,9 @@
 	asoc->state_timestamp = jiffies;
 
 	/* Set things that have constant value.  */
-	asoc->cookie_life.tv_sec = SCTP_DEFAULT_COOKIE_LIFE_SEC;
-	asoc->cookie_life.tv_usec = SCTP_DEFAULT_COOKIE_LIFE_USEC;
+	asoc->cookie_life.tv_sec = sctp_proto.valid_cookie_life / HZ;
+	asoc->cookie_life.tv_usec = (sctp_proto.valid_cookie_life % HZ) *
+					1000000L / HZ;
 
 	asoc->pmtu = 0;
 	asoc->frag_point = 0;
@@ -185,6 +186,8 @@
 	else
 		asoc->rwnd = sk->rcvbuf;
 
+	asoc->a_rwnd = 0;
+
 	asoc->rwnd_over = 0;
 
 	/* Use my own max window until I learn something better.  */
@@ -642,7 +645,7 @@
 int sctp_cmp_addr_exact(const union sctp_addr *ss1,
 			const union sctp_addr *ss2)
 {
-	struct sctp_func *af;
+	struct sctp_af *af;
 
 	af = sctp_get_af_specific(ss1->sa.sa_family);
 	if (!af)
diff -Nru a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c
--- a/net/sctp/bind_addr.c	Mon Dec 23 21:21:59 2002
+++ b/net/sctp/bind_addr.c	Mon Dec 23 21:21:59 2002
@@ -327,7 +327,7 @@
 /* Is this a wildcard address?  */
 int sctp_is_any(const union sctp_addr *addr)
 {
-	struct sctp_func *af = sctp_get_af_specific(addr->sa.sa_family);
+	struct sctp_af *af = sctp_get_af_specific(addr->sa.sa_family);
 	if (!af)
 		return 0;
 	return af->is_any(addr);
@@ -362,7 +362,7 @@
 /* What is the scope of 'addr'?  */
 sctp_scope_t sctp_scope(const union sctp_addr *addr)
 {
-	struct sctp_func *af;
+	struct sctp_af *af;
 
 	af = sctp_get_af_specific(addr->sa.sa_family);
 	if (!af)
diff -Nru a/net/sctp/input.c b/net/sctp/input.c
--- a/net/sctp/input.c	Mon Dec 23 21:21:51 2002
+++ b/net/sctp/input.c	Mon Dec 23 21:21:51 2002
@@ -42,6 +42,7 @@
  *    Hui Huang <hui.huang@nokia.com>
  *    Daisy Chang <daisyc@us.ibm.com>
  *    Sridhar Samudrala <sri@us.ibm.com>
+ *    Ardelle Fan <ardelle.fan@intel.com>
  *
  * Any bugs reported given to us we will try to fix... any fixes shared will
  * be incorporated into the next SCTP release.
@@ -96,7 +97,7 @@
 	struct sctphdr *sh;
 	union sctp_addr src;
 	union sctp_addr dest;
-	struct sctp_func *af;
+	struct sctp_af *af;
 	int ret = 0;
 
 	if (skb->pkt_type!=PACKET_HOST)
@@ -279,6 +280,7 @@
 {
 	sctp_chunkhdr_t *ch;
 	__u8 *ch_end;
+	sctp_errhdr_t *err;
 
 	ch = (sctp_chunkhdr_t *) skb->data;
 
@@ -308,8 +310,9 @@
 			goto discard;
 
 		if (ch->type == SCTP_CID_ERROR) {
-			/* FIXME - Need to check the "Stale cookie" ERROR. */
-			goto discard;
+			err = (sctp_errhdr_t *)(ch + sizeof(sctp_chunkhdr_t));
+			if (SCTP_ERROR_STALE_COOKIE == err->cause)
+				goto discard;
 		}
 
 		ch = (sctp_chunkhdr_t *) ch_end;
diff -Nru a/net/sctp/ipv6.c b/net/sctp/ipv6.c
--- a/net/sctp/ipv6.c	Mon Dec 23 21:21:56 2002
+++ b/net/sctp/ipv6.c	Mon Dec 23 21:21:56 2002
@@ -76,8 +76,19 @@
 
 #include <asm/uaccess.h>
 
-/* FIXME: Cleanup so we don't need TEST_FRAME here. */
-#ifndef TEST_FRAME
+extern struct notifier_block sctp_inetaddr_notifier;
+
+/* FIXME: This macro needs to be moved to a common header file. */
+#define NIP6(addr) \
+        ntohs((addr)->s6_addr16[0]), \
+        ntohs((addr)->s6_addr16[1]), \
+        ntohs((addr)->s6_addr16[2]), \
+        ntohs((addr)->s6_addr16[3]), \
+        ntohs((addr)->s6_addr16[4]), \
+        ntohs((addr)->s6_addr16[5]), \
+        ntohs((addr)->s6_addr16[6]), \
+        ntohs((addr)->s6_addr16[7])
+
 /* FIXME: Comments. */
 static inline void sctp_v6_err(struct sk_buff *skb,
 			       struct inet6_skb_parm *opt,
@@ -92,13 +103,38 @@
 	struct sock *sk = skb->sk;
 	struct ipv6_pinfo *np = inet6_sk(sk);
 	struct flowi fl;
-	struct dst_entry *dst;
+	struct dst_entry *dst = skb->dst;
+	struct rt6_info *rt6 = (struct rt6_info *)dst;
 	struct in6_addr saddr;
-	int err = 0;
+	int err;
 
 	fl.proto = sk->protocol;
-	fl.fl6_dst = &np->daddr;
-	fl.fl6_src = NULL;
+	fl.fl6_dst = &rt6->rt6i_dst.addr;
+
+	/* FIXME: Currently, ip6_route_output() doesn't fill in the source
+	 * address in the returned route entry. So we call ipv6_get_saddr()
+	 * to get an appropriate source address. It is possible that this address
+	 * may not be part of the bind address list of the association.
+	 * Once ip6_route_ouput() is fixed so that it returns a route entry
+	 * with an appropriate source address, the following if condition can
+	 * be removed. With ip6_route_output() returning a source address filled
+	 * route entry, sctp_transport_route() can do real source address 
+	 * selection for v6.
+	 */ 
+	if (ipv6_addr_any(&rt6->rt6i_src.addr)) {
+		err = ipv6_get_saddr(dst, fl.fl6_dst, &saddr);
+
+		if (err) {
+			printk(KERN_ERR "%s: No saddr available for "
+			       "DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
+			       __FUNCTION__, NIP6(fl.fl6_src));
+			return err;
+		}
+
+		fl.fl6_src = &saddr;
+	} else {
+		fl.fl6_src = &rt6->rt6i_src.addr;
+	}
 
 	fl.fl6_flowlabel = np->flow_label;
 	IP6_ECN_flow_xmit(sk, fl.fl6_flowlabel);
@@ -111,63 +147,8 @@
 		fl.nl_u.ip6_u.daddr = rt0->addr;
 	}
 
-	dst = __sk_dst_check(sk, np->dst_cookie);
-
-	if (dst == NULL) {
-		dst = ip6_route_output(sk, &fl);
-
-		if (dst->error) {
-			sk->err_soft = -dst->error;
-			dst_release(dst);
-			return -sk->err_soft;
-		}
-		ip6_dst_store(sk, dst, NULL);
-	}
-
-	skb->dst = dst_clone(dst);
-
-	/* FIXME: This is all temporary until real source address
-	 * selection is done.
-	 */
-	if (ipv6_addr_any(&np->saddr)) {
-		err = ipv6_get_saddr(dst, fl.fl6_dst, &saddr);
-
-		if (err)
-			printk(KERN_ERR "sctp_v6_xmit: no saddr available\n");
-
-		/* FIXME: This is a workaround until we get
-		 * real source address selection done.  This is here
-		 * to disallow loopback when the scoping rules have
-		 * not bound loopback to the endpoint.
-		 */
-		if (sctp_ipv6_addr_type(&saddr) & IPV6_ADDR_LOOPBACK) {
-			if (!(sctp_ipv6_addr_type(&np->daddr) &
-			      IPV6_ADDR_LOOPBACK)) {
-				ipv6_addr_copy(&saddr, &np->daddr);
-			}
-		}
-		fl.fl6_src = &saddr;
-	} else {
-		fl.fl6_src = &np->saddr;
-	}
-
-	/* Restore final destination back after routing done */
-	fl.nl_u.ip6_u.daddr = &np->daddr;
-
 	return ip6_xmit(sk, skb, &fl, np->opt);
 }
-#endif /* TEST_FRAME */
-
-/* FIXME: This macro needs to be moved to a common header file. */
-#define NIP6(addr) \
-        ntohs((addr)->s6_addr16[0]), \
-        ntohs((addr)->s6_addr16[1]), \
-        ntohs((addr)->s6_addr16[2]), \
-        ntohs((addr)->s6_addr16[3]), \
-        ntohs((addr)->s6_addr16[4]), \
-        ntohs((addr)->s6_addr16[5]), \
-        ntohs((addr)->s6_addr16[6]), \
-        ntohs((addr)->s6_addr16[7])
 
 /* Returns the dst cache entry for the given source and destination ip
  * addresses.
@@ -176,7 +157,7 @@
 				  union sctp_addr *saddr)
 {
 	struct dst_entry *dst;
-	struct flowi fl = { 
+	struct flowi fl = {
 		.nl_u = { .ip6_u = { .daddr = &daddr->v6.sin6_addr, } } };
 
 
@@ -261,6 +242,20 @@
 	ipv6_addr_copy(&addr->v6.sin6_addr, from);
 }
 
+/* Initialize an sctp_addr from a socket. */
+static void sctp_v6_from_sk(union sctp_addr *addr, struct sock *sk)
+{
+	addr->v6.sin6_family = AF_INET6;
+	addr->v6.sin6_port = inet_sk(sk)->num;
+	addr->v6.sin6_addr = inet6_sk(sk)->rcv_saddr;
+}
+
+/* Initialize sk->rcv_saddr from sctp_addr. */
+static void sctp_v6_to_sk(union sctp_addr *addr, struct sock *sk)
+{
+	inet6_sk(sk)->rcv_saddr = addr->v6.sin6_addr;
+}
+
 /* Initialize a sctp_addr from a dst_entry. */
 static void sctp_v6_dst_saddr(union sctp_addr *addr, struct dst_entry *dst)
 {
@@ -270,15 +265,15 @@
 }
 
 /* Compare addresses exactly.  Well.. almost exactly; ignore scope_id
- * for now.  FIXME.
+ * for now.  FIXME: v4-mapped-v6.
  */
-static int sctp_v6_cmp_addr(const union sctp_addr *addr1, 
+static int sctp_v6_cmp_addr(const union sctp_addr *addr1,
 			    const union sctp_addr *addr2)
 {
 	int match;
 	if (addr1->sa.sa_family != addr2->sa.sa_family)
 		return 0;
-	match = !ipv6_addr_cmp((struct in6_addr *)&addr1->v6.sin6_addr, 
+	match = !ipv6_addr_cmp((struct in6_addr *)&addr1->v6.sin6_addr,
 			       (struct in6_addr *)&addr2->v6.sin6_addr);
 
 	return match;
@@ -300,6 +295,22 @@
 	return IPV6_ADDR_ANY == type;
 }
 
+/* Should this be available for binding?   */
+static int sctp_v6_available(const union sctp_addr *addr)
+{
+	int type;
+	struct in6_addr *in6 = (struct in6_addr *)&addr->v6.sin6_addr;
+
+	type = ipv6_addr_type(in6);
+	if (IPV6_ADDR_ANY == type)
+		return 1;
+	if (!(type & IPV6_ADDR_UNICAST))
+		return 0;
+
+	return ipv6_chk_addr(in6, NULL);
+}
+
+
 /* This function checks if the address is a valid address to be used for
  * SCTP.
  *
@@ -309,7 +320,7 @@
  */
 static int sctp_v6_addr_valid(union sctp_addr *addr)
 {
-	int ret = sctp_ipv6_addr_type(&addr->v6.sin6_addr);
+	int ret = ipv6_addr_type(&addr->v6.sin6_addr);
 
 	/* FIXME:  v4-mapped-v6 address support. */
 
@@ -442,14 +453,14 @@
 
 /* Address matching with wildcards allowed.  This extra level
  * of indirection lets us choose whether a PF_INET6 should
- * disallow any v4 addresses if we so choose. 
+ * disallow any v4 addresses if we so choose.
  */
-static int sctp_inet6_cmp_addr(const union sctp_addr *addr1, 
+static int sctp_inet6_cmp_addr(const union sctp_addr *addr1,
 			       const union sctp_addr *addr2,
 			       struct sctp_opt *opt)
 {
-	struct sctp_func *af1, *af2;
-	
+	struct sctp_af *af1, *af2;
+
 	af1 = sctp_get_af_specific(addr1->sa.sa_family);
 	af2 = sctp_get_af_specific(addr2->sa.sa_family);
 
@@ -461,11 +472,25 @@
 
 	if (addr1->sa.sa_family != addr2->sa.sa_family)
 		return 0;
-	
+
 	return af1->cmp_addr(addr1, addr2);
 }
 
+/* Verify that the provided sockaddr looks bindable.   Common verification,
+ * has already been taken care of.
+ */
+static int sctp_inet6_bind_verify(struct sctp_opt *opt, union sctp_addr *addr)
+{
+	struct sctp_af *af;
+
+	/* ASSERT: address family has already been verified. */
+	if (addr->sa.sa_family != AF_INET6) {
+		af = sctp_get_af_specific(addr->sa.sa_family);
+	} else
+		af = opt->pf->af;
 
+	return af->available(addr);
+}
 
 static struct proto_ops inet6_seqpacket_ops = {
 	.family     = PF_INET6,
@@ -501,29 +526,33 @@
 	.err_handler  = sctp_v6_err,
 };
 
-static sctp_func_t sctp_ipv6_specific = {
+static struct sctp_af sctp_ipv6_specific = {
 	.queue_xmit      = sctp_v6_xmit,
-	.setsockopt      = ipv6_setsockopt,
+	.setsockopt    = ipv6_setsockopt,
 	.getsockopt      = ipv6_getsockopt,
 	.get_dst	 = sctp_v6_get_dst,
 	.copy_addrlist   = sctp_v6_copy_addrlist,
 	.from_skb        = sctp_v6_from_skb,
+	.from_sk         = sctp_v6_from_sk,
+	.to_sk           = sctp_v6_to_sk,
 	.dst_saddr       = sctp_v6_dst_saddr,
 	.cmp_addr        = sctp_v6_cmp_addr,
 	.scope           = sctp_v6_scope,
 	.addr_valid      = sctp_v6_addr_valid,
 	.inaddr_any      = sctp_v6_inaddr_any,
 	.is_any          = sctp_v6_is_any,
+	.available       = sctp_v6_available,
 	.net_header_len  = sizeof(struct ipv6hdr),
 	.sockaddr_len    = sizeof(struct sockaddr_in6),
 	.sa_family       = AF_INET6,
 };
 
-static sctp_pf_t sctp_pf_inet6_specific = {
+static struct sctp_pf sctp_pf_inet6_specific = {
 	.event_msgname = sctp_inet6_event_msgname,
 	.skb_msgname   = sctp_inet6_skb_msgname,
 	.af_supported  = sctp_inet6_af_supported,
 	.cmp_addr      = sctp_inet6_cmp_addr,
+	.bind_verify   = sctp_inet6_bind_verify,
 	.af            = &sctp_ipv6_specific,
 };
 
@@ -538,11 +567,13 @@
 	inet6_register_protosw(&sctpv6_protosw);
 
 	/* Register the SCTP specfic PF_INET6 functions. */
-	sctp_set_pf_specific(PF_INET6, &sctp_pf_inet6_specific);
+	sctp_register_pf(&sctp_pf_inet6_specific, PF_INET6);
+
+	/* Register the SCTP specfic AF_INET6 functions. */
+	sctp_register_af(&sctp_ipv6_specific);
 
-	/* Fill in address family info.  */
-	INIT_LIST_HEAD(&sctp_ipv6_specific.list);
-	list_add_tail(&sctp_ipv6_specific.list, &sctp_proto.address_families);
+	/* Register notifier for inet6 address additions/deletions. */ 
+	register_inet6addr_notifier(&sctp_inetaddr_notifier);
 
 	return 0;
 }
@@ -553,4 +584,5 @@
 	list_del(&sctp_ipv6_specific.list);
 	inet6_del_protocol(&sctpv6_protocol, IPPROTO_SCTP);
 	inet6_unregister_protosw(&sctpv6_protosw);
+	unregister_inet6addr_notifier(&sctp_inetaddr_notifier);
 }
diff -Nru a/net/sctp/protocol.c b/net/sctp/protocol.c
--- a/net/sctp/protocol.c	Mon Dec 23 21:21:56 2002
+++ b/net/sctp/protocol.c	Mon Dec 23 21:21:56 2002
@@ -40,6 +40,7 @@
  *    Jon Grimm <jgrimm@us.ibm.com>
  *    Sridhar Samudrala <sri@us.ibm.com>
  *    Daisy Chang <daisyc@us.ibm.com>
+ *    Ardelle Fan <ardelle.fan@intel.com>
  *
  * Any bugs reported given to us we will try to fix... any fixes shared will
  * be incorporated into the next SCTP release.
@@ -67,8 +68,10 @@
  */
 static struct socket *sctp_ctl_socket;
 
-static sctp_pf_t *sctp_pf_inet6_specific;
-static sctp_pf_t *sctp_pf_inet_specific;
+static struct sctp_pf *sctp_pf_inet6_specific;
+static struct sctp_pf *sctp_pf_inet_specific;
+static struct sctp_af *sctp_af_v4_specific;
+static struct sctp_af *sctp_af_v6_specific;
 
 extern struct net_proto_family inet_family_ops;
 
@@ -140,12 +143,12 @@
 {
 	struct net_device *dev;
 	struct list_head *pos;
-	struct sctp_func *af;
+	struct sctp_af *af;
 
 	read_lock(&dev_base_lock);
 	for (dev = dev_base; dev; dev = dev->next) {
 		list_for_each(pos, &proto->address_families) {
-			af = list_entry(pos, sctp_func_t, list);
+			af = list_entry(pos, struct sctp_af, list);
 			af->copy_addrlist(&proto->local_addr_list, dev);
 		}
 	}
@@ -251,7 +254,6 @@
 	return &rt->u.dst;
 }
 
-
 /* Initialize a sctp_addr from in incoming skb.  */
 static void sctp_v4_from_skb(union sctp_addr *addr, struct sk_buff *skb,
 			     int is_saddr)
@@ -274,6 +276,21 @@
 	memcpy(&addr->v4.sin_addr.s_addr, from, sizeof(struct in_addr));
 }
 
+/* Initialize an sctp_addr from a socket. */
+static void sctp_v4_from_sk(union sctp_addr *addr, struct sock *sk)
+{
+	addr->v4.sin_family = AF_INET;
+	addr->v4.sin_port = inet_sk(sk)->num;
+	addr->v4.sin_addr.s_addr = inet_sk(sk)->rcv_saddr;
+}
+
+/* Initialize sk->rcv_saddr from sctp_addr. */
+static void sctp_v4_to_sk(union sctp_addr *addr, struct sock *sk)
+{
+	inet_sk(sk)->rcv_saddr = addr->v4.sin_addr.s_addr;
+}
+
+
 /* Initialize a sctp_addr from a dst_entry. */
 static void sctp_v4_dst_saddr(union sctp_addr *saddr, struct dst_entry *dst)
 {
@@ -311,7 +328,7 @@
 }
 
 /* This function checks if the address is a valid address to be used for
- * SCTP.
+ * SCTP binding.
  *
  * Output:
  * Return 0 - If the address is a non-unicast or an illegal address.
@@ -326,6 +343,18 @@
 	return 1;
 }
 
+/* Should this be available for binding?   */
+static int sctp_v4_available(const union sctp_addr *addr)
+{
+	int ret = inet_addr_type(addr->v4.sin_addr.s_addr);
+	
+	/* FIXME: ip_nonlocal_bind sysctl support. */
+
+	if (addr->v4.sin_addr.s_addr != INADDR_ANY && ret != RTN_LOCAL)
+		return 0;
+	return 1;
+}
+
 /* Checking the loopback, private and other address scopes as defined in
  * RFC 1918.   The IPv4 scoping is based on the draft for SCTP IPv4
  * scoping <draft-stewart-tsvwg-sctp-ipv4-00.txt>.
@@ -365,11 +394,11 @@
 	return retval;
 }
 
-/* Event handler for inet device events.
+/* Event handler for inet address addition/deletion events.
  * Basically, whenever there is an event, we re-build our local address list.
  */
-static int sctp_netdev_event(struct notifier_block *this, unsigned long event,
-			     void *ptr)
+static int sctp_inetaddr_event(struct notifier_block *this, unsigned long event,
+			       void *ptr)
 {
 	long flags __attribute__ ((unused));
 
@@ -405,29 +434,42 @@
 	return 0;
 }
 
+/* Register address family specific functions. */
+int sctp_register_af(struct sctp_af *af)
+{
+	switch (af->sa_family) {
+	case AF_INET:
+		if (sctp_af_v4_specific)
+			return 0;
+		sctp_af_v4_specific = af;
+		break;
+	case AF_INET6:
+		if (sctp_af_v6_specific)
+			return 0;
+		sctp_af_v6_specific = af;
+		break;
+	default:
+		return 0;
+	}
+
+	INIT_LIST_HEAD(&af->list);
+	list_add_tail(&af->list, &sctp_proto.address_families);
+	return 1;
+}
+
 /* Get the table of functions for manipulating a particular address
  * family.
  */
-sctp_func_t *sctp_get_af_specific(sa_family_t family)
+struct sctp_af *sctp_get_af_specific(sa_family_t family)
 {
-	struct list_head *pos;
-	sctp_protocol_t *proto = sctp_get_protocol();
-	struct sctp_func *retval, *af;
-
-	retval = NULL;
-
-	/* Cycle through all AF specific functions looking for a
-	 * match.
-	 */
-	list_for_each(pos, &proto->address_families) {
-		af = list_entry(pos, sctp_func_t, list);
-		if (family == af->sa_family) {
-			retval = af;
-			break;
-		}
+	switch (family) {
+	case AF_INET:
+		return sctp_af_v4_specific;
+	case AF_INET6:
+		return sctp_af_v6_specific;
+	default:
+		return NULL;
 	}
-
-	return retval;
 }
 
 /* Common code to initialize a AF_INET msg_name. */
@@ -495,21 +537,28 @@
 	return 0;
 }
 
+/* Verify that provided sockaddr looks bindable.  Common verification has
+ * already been taken care of.
+ */
+static int sctp_inet_bind_verify(struct sctp_opt *opt, union sctp_addr *addr)
+{
+	return sctp_v4_available(addr);
+}
 
-struct sctp_func sctp_ipv4_specific;
+struct sctp_af sctp_ipv4_specific;
 
-static sctp_pf_t sctp_pf_inet = {
+static struct sctp_pf sctp_pf_inet = {
 	.event_msgname = sctp_inet_event_msgname,
 	.skb_msgname   = sctp_inet_skb_msgname,
 	.af_supported  = sctp_inet_af_supported,
 	.cmp_addr      = sctp_inet_cmp_addr,
+	.bind_verify   = sctp_inet_bind_verify,
 	.af            = &sctp_ipv4_specific,
 };
 
-
-/* Registration for netdev events.  */
-struct notifier_block sctp_netdev_notifier = {
-	.notifier_call = sctp_netdev_event,
+/* Notifier for inetaddr addition/deletion events.  */
+struct notifier_block sctp_inetaddr_notifier = {
+	.notifier_call = sctp_inetaddr_event,
 };
 
 /* Socket operations.  */
@@ -551,25 +600,28 @@
 };
 
 /* IPv4 address related functions.  */
-struct sctp_func sctp_ipv4_specific = {
+struct sctp_af sctp_ipv4_specific = {
 	.queue_xmit     = ip_queue_xmit,
 	.setsockopt     = ip_setsockopt,
 	.getsockopt     = ip_getsockopt,
 	.get_dst	= sctp_v4_get_dst,
 	.copy_addrlist  = sctp_v4_copy_addrlist,
 	.from_skb       = sctp_v4_from_skb,
+	.from_sk        = sctp_v4_from_sk,
+	.to_sk          = sctp_v4_to_sk,
 	.dst_saddr      = sctp_v4_dst_saddr,
 	.cmp_addr       = sctp_v4_cmp_addr,
 	.addr_valid     = sctp_v4_addr_valid,
 	.inaddr_any     = sctp_v4_inaddr_any,
 	.is_any         = sctp_v4_is_any,
+	.available      = sctp_v4_available,
 	.scope          = sctp_v4_scope,
 	.net_header_len = sizeof(struct iphdr),
 	.sockaddr_len   = sizeof(struct sockaddr_in),
 	.sa_family      = AF_INET,
 };
 
-sctp_pf_t *sctp_get_pf_specific(int family) {
+struct sctp_pf *sctp_get_pf_specific(sa_family_t family) {
 
 	switch (family) {
 	case PF_INET:
@@ -581,20 +633,24 @@
 	}
 }
 
-/* Set the PF specific function table.  */
-void sctp_set_pf_specific(int family, sctp_pf_t *pf)
+/* Register the PF specific function table.  */
+int sctp_register_pf(struct sctp_pf *pf, sa_family_t family)
 {
 	switch (family) {
 	case PF_INET:
+		if (sctp_pf_inet_specific)
+			return 0;
 		sctp_pf_inet_specific = pf;
 		break;
 	case PF_INET6:
+		if (sctp_pf_inet6_specific)
+			return 0;
 		sctp_pf_inet6_specific = pf;
 		break;
 	default:
-		BUG();
-		break;
+		return 0;
 	}
+	return 1;
 }
 
 /* Initialize the universe into something sensible.  */
@@ -617,7 +673,7 @@
 	sctp_dbg_objcnt_init();
 
 	/* Initialize the SCTP specific PF functions. */
-	sctp_set_pf_specific(PF_INET, &sctp_pf_inet);
+	sctp_register_pf(&sctp_pf_inet, PF_INET);
 	/*
 	 * 14. Suggested SCTP Protocol Parameter Values
 	 */
@@ -636,6 +692,9 @@
 	/* Valid.Cookie.Life        - 60  seconds */
 	sctp_proto.valid_cookie_life	= 60 * HZ;
 
+	/* Whether Cookie Preservative is enabled(1) or not(0) */ 
+	sctp_proto.cookie_preserve_enable = 1;
+
 	/* Max.Burst		    - 4 */
 	sctp_proto.max_burst = SCTP_MAX_BURST;
 
@@ -709,8 +768,7 @@
 	sctp_sysctl_register();
 
 	INIT_LIST_HEAD(&sctp_proto.address_families);
-	INIT_LIST_HEAD(&sctp_ipv4_specific.list);
-	list_add_tail(&sctp_ipv4_specific.list, &sctp_proto.address_families);
+	sctp_register_af(&sctp_ipv4_specific);
 
 	status = sctp_v6_init();
 	if (status)
@@ -727,7 +785,9 @@
 	INIT_LIST_HEAD(&sctp_proto.local_addr_list);
 	sctp_proto.local_addr_lock = SPIN_LOCK_UNLOCKED;
 
-	register_inetaddr_notifier(&sctp_netdev_notifier);
+	/* Register notifier for inet address additions/deletions. */ 
+	register_inetaddr_notifier(&sctp_inetaddr_notifier);
+
 	sctp_get_local_addr_list(&sctp_proto);
 
 	return 0;
@@ -757,8 +817,10 @@
 	 * up all the remaining associations and all that memory.
 	 */
 
+	/* Unregister notifier for inet address additions/deletions. */
+	unregister_inetaddr_notifier(&sctp_inetaddr_notifier);
+
 	/* Free the local address list.  */
-	unregister_inetaddr_notifier(&sctp_netdev_notifier);
 	sctp_free_local_addr_list(&sctp_proto);
 
 	/* Free the control endpoint.  */
diff -Nru a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
--- a/net/sctp/sm_make_chunk.c	Mon Dec 23 21:21:51 2002
+++ b/net/sctp/sm_make_chunk.c	Mon Dec 23 21:21:51 2002
@@ -77,13 +77,18 @@
 	{
 		SCTP_PARAM_SUPPORTED_ADDRESS_TYPES,
 		__constant_htons(SCTP_SAT_LEN),
-	},
-	{               /* types[] */
-		SCTP_PARAM_IPV4_ADDRESS,
-		SCTP_V6(SCTP_PARAM_IPV6_ADDRESS,)
 	}
 };
 
+/* gcc 3.2 doesn't allow initialization of zero-length arrays. So the above
+ * structure is split and the address types array is initialized using a
+ * fixed length array. 
+ */
+static const __u16 sat_addr_types[2] = {
+	SCTP_PARAM_IPV4_ADDRESS,
+	SCTP_V6(SCTP_PARAM_IPV6_ADDRESS,)
+};			
+
 /* RFC 2960 3.3.2 Initiation (INIT) (1)
  *
  * Note 2: The ECN capable field is reserved for future use of
@@ -163,7 +168,7 @@
  */
 sctp_chunk_t *sctp_make_init(const sctp_association_t *asoc,
 			     const sctp_bind_addr_t *bp,
-			     int priority)
+			     int priority, int vparam_len)
 {
 	sctp_inithdr_t init;
 	union sctp_params addrs;
@@ -192,6 +197,7 @@
 
 	chunksize = sizeof(init) + addrs_len + SCTP_SAT_LEN;
 	chunksize += sizeof(ecap_param);
+	chunksize += vparam_len;
 
 	/* RFC 2960 3.3.2 Initiation (INIT) (1)
 	 *
@@ -213,7 +219,10 @@
 		sctp_addto_chunk(retval, sizeof(init), &init);
 	retval->param_hdr.v =
 		sctp_addto_chunk(retval, addrs_len, addrs.v);
-	sctp_addto_chunk(retval, SCTP_SAT_LEN, &sat_param);
+
+	sctp_addto_chunk(retval, sizeof(sctp_paramhdr_t), &sat_param);
+	sctp_addto_chunk(retval, sizeof(sat_addr_types), sat_addr_types);
+
 	sctp_addto_chunk(retval, sizeof(ecap_param), &ecap_param);
 
 nodata:
@@ -1337,7 +1346,7 @@
 sctp_association_t *sctp_unpack_cookie(const sctp_endpoint_t *ep,
 				       const sctp_association_t *asoc,
 				       sctp_chunk_t *chunk, int priority,
-				       int *error)
+				       int *error, sctp_chunk_t **err_chk_p)
 {
 	sctp_association_t *retval = NULL;
 	sctp_signed_cookie_t *cookie;
@@ -1394,7 +1403,29 @@
 	 * for init collision case of lost COOKIE ACK.
 	 */
 	if (!asoc && tv_lt(bear_cookie->expiration, chunk->skb->stamp)) {
-		*error = -SCTP_IERROR_STALE_COOKIE;
+		/*
+		 * Section 3.3.10.3 Stale Cookie Error (3)
+		 *
+		 * Cause of error
+		 * ---------------
+		 * Stale Cookie Error:  Indicates the receipt of a valid State
+		 * Cookie that has expired.
+		 */
+		*err_chk_p = sctp_make_op_error_space(asoc, chunk,
+						ntohs(chunk->chunk_hdr->length));
+		if (*err_chk_p) {
+			suseconds_t usecs = (chunk->skb->stamp.tv_sec -
+				bear_cookie->expiration.tv_sec) * 1000000L +
+				chunk->skb->stamp.tv_usec -
+				bear_cookie->expiration.tv_usec;
+
+			usecs = htonl(usecs);
+			sctp_init_cause(*err_chk_p, SCTP_ERROR_STALE_COOKIE,
+					&usecs, sizeof(usecs));
+			*error = -SCTP_IERROR_STALE_COOKIE;
+		} else
+			*error = -SCTP_IERROR_NOMEM;
+
 		goto fail;
 	}
 
@@ -1751,6 +1782,7 @@
 	__u16 sat;
 	int retval = 1;
 	sctp_scope_t scope;
+	time_t stale;
 
 	/* We maintain all INIT parameters in network byte order all the
 	 * time.  This allows us to not worry about whether the parameters
@@ -1770,8 +1802,16 @@
 		break;
 
 	case SCTP_PARAM_COOKIE_PRESERVATIVE:
-		asoc->cookie_preserve =
-			ntohl(param.life->lifespan_increment);
+		if (!sctp_proto.cookie_preserve_enable)
+			break;
+
+		stale = ntohl(param.life->lifespan_increment);
+
+		/* Suggested Cookie Life span increment's unit is msec,
+		 * (1/1000sec).
+		 */
+		asoc->cookie_life.tv_sec += stale / 1000;
+		asoc->cookie_life.tv_usec += (stale % 1000) * 1000;
 		break;
 
 	case SCTP_PARAM_HOST_NAME_ADDRESS:
diff -Nru a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
--- a/net/sctp/sm_sideeffect.c	Mon Dec 23 21:21:58 2002
+++ b/net/sctp/sm_sideeffect.c	Mon Dec 23 21:21:58 2002
@@ -68,7 +68,8 @@
 					 sctp_transport_t *transport);
 static void sctp_cmd_init_failed(sctp_cmd_seq_t *, sctp_association_t *asoc);
 static void sctp_cmd_assoc_failed(sctp_cmd_seq_t *, sctp_association_t *asoc,
-				  sctp_event_t event_type, sctp_chunk_t *chunk);
+				  sctp_event_t event_type, sctp_subtype_t stype,
+				  sctp_chunk_t *chunk);
 static int sctp_cmd_process_init(sctp_cmd_seq_t *, sctp_association_t *asoc,
 				 sctp_chunk_t *chunk,
 				 sctp_init_chunk_t *peer_init,
@@ -517,7 +518,7 @@
 
 		case SCTP_CMD_ASSOC_FAILED:
 			sctp_cmd_assoc_failed(commands, asoc, event_type,
-					      chunk);
+					      subtype, chunk);
 			break;
 
 		case SCTP_CMD_COUNTER_INC:
@@ -736,6 +737,9 @@
 		if (!sack)
 			goto nomem;
 
+		/* Update the last advertised rwnd value. */
+		asoc->a_rwnd = asoc->rwnd;
+
 		asoc->peer.sack_needed = 0;
 		asoc->peer.next_dup_tsn = 0;
 
@@ -1046,18 +1050,27 @@
 static void sctp_cmd_assoc_failed(sctp_cmd_seq_t *commands,
 				  sctp_association_t *asoc,
 				  sctp_event_t event_type,
+				  sctp_subtype_t subtype,
 				  sctp_chunk_t *chunk)
 {
 	sctp_ulpevent_t *event;
 	__u16 error = 0;
 
-	if (event_type == SCTP_EVENT_T_PRIMITIVE)
-		error = SCTP_ERROR_USER_ABORT;
-
-	if (chunk && (SCTP_CID_ABORT == chunk->chunk_hdr->type) &&
-	    (ntohs(chunk->chunk_hdr->length) >= (sizeof(struct sctp_chunkhdr) +
-				 		 sizeof(struct sctp_errhdr)))) {
-		error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
+	switch(event_type) {
+	case SCTP_EVENT_T_PRIMITIVE:
+		if (SCTP_PRIMITIVE_ABORT == subtype.primitive)
+			error = SCTP_ERROR_USER_ABORT;
+		break;
+	case SCTP_EVENT_T_CHUNK:
+		if (chunk && (SCTP_CID_ABORT == chunk->chunk_hdr->type) &&
+	    	    (ntohs(chunk->chunk_hdr->length) >=
+			(sizeof(struct sctp_chunkhdr) +
+				sizeof(struct sctp_errhdr)))) {
+			error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
+		}
+		break;
+	default:
+		break;
 	}
 
 	event = sctp_ulpevent_make_assoc_change(asoc,
diff -Nru a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
--- a/net/sctp/sm_statefuns.c	Mon Dec 23 21:21:51 2002
+++ b/net/sctp/sm_statefuns.c	Mon Dec 23 21:21:51 2002
@@ -2,6 +2,7 @@
  * Copyright (c) 1999-2000 Cisco, Inc.
  * Copyright (c) 1999-2001 Motorola, Inc.
  * Copyright (c) 2001-2002 International Business Machines, Corp.
+ * Copyright (c) 2001-2002 Intel Corp.
  * Copyright (c) 2002      Nokia Corp.
  *
  * This file is part of the SCTP kernel reference Implementation
@@ -502,6 +503,7 @@
 	sctp_chunk_t *repl;
 	sctp_ulpevent_t *ev;
 	int error = 0;
+	sctp_chunk_t *err_chk_p;
 
 	/* If the packet is an OOTB packet which is temporarily on the
 	 * control endpoint, responding with an ABORT.
@@ -521,7 +523,8 @@
 	 * "Z" will reply with a COOKIE ACK chunk after building a TCB
 	 * and moving to the ESTABLISHED state.
 	 */
-	new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error);
+	new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
+				      &err_chk_p);
 
 	/* FIXME:
 	 * If the re-build failed, what is the proper error path
@@ -537,6 +540,11 @@
 		case -SCTP_IERROR_NOMEM:
 			goto nomem;
 
+		case -SCTP_IERROR_STALE_COOKIE:
+			sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
+						   err_chk_p);
+			return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
+
 		case -SCTP_IERROR_BAD_SIG:
 		default:
 			return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
@@ -862,8 +870,8 @@
 	/* Check if the timestamp looks valid.  */
 	if (time_after(hbinfo->sent_at, jiffies) ||
 	    time_after(jiffies, hbinfo->sent_at + max_interval)) {
-		SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp
-				   received for transport: %p\n",
+		SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp"
+				  "received for transport: %p\n",
 				   __FUNCTION__, link);
 		return SCTP_DISPOSITION_DISCARD;
 	}
@@ -1562,6 +1570,7 @@
 	sctp_association_t *new_asoc;
 	int error = 0;
 	char action;
+	sctp_chunk_t *err_chk_p;
 
 	/* "Decode" the chunk.  We have no optional parameters so we
 	 * are in good shape.
@@ -1575,7 +1584,8 @@
 	 * current association, consider the State Cookie valid even if
 	 * the lifespan is exceeded.
 	 */
-	new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error);
+	new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
+				      &err_chk_p);
 
 	/* FIXME:
 	 * If the re-build failed, what is the proper error path
@@ -1591,6 +1601,12 @@
 		case -SCTP_IERROR_NOMEM:
 			goto nomem;
 
+		case -SCTP_IERROR_STALE_COOKIE:
+			sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
+						   err_chk_p);
+			return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
+
+			break;
 		case -SCTP_IERROR_BAD_SIG:
 		default:
 			return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
@@ -1706,7 +1722,47 @@
 	return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands);
 }
 
-#if 0
+/*
+ * Handle an Error received in COOKIE_ECHOED state.
+ *
+ * Only handle the error type of stale COOKIE Error, the other errors will
+ * be ignored.
+ *
+ * Inputs
+ * (endpoint, asoc, chunk)
+ *
+ * Outputs
+ * (asoc, reply_msg, msg_up, timers, counters)
+ *
+ * The return value is the disposition of the chunk.
+ */
+sctp_disposition_t sctp_sf_cookie_echoed_err(const sctp_endpoint_t *ep,
+					     const sctp_association_t *asoc,
+					     const sctp_subtype_t type,
+					     void *arg,
+					     sctp_cmd_seq_t *commands)
+{
+	sctp_chunk_t *chunk = arg;
+	sctp_errhdr_t *err;
+
+	/* If we have gotten too many failures, give up.  */
+	if (1 + asoc->counters[SCTP_COUNTER_INIT_ERROR] >
+					 asoc->max_init_attempts) {
+		/* INIT_FAILED will issue an ulpevent.  */
+		sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, SCTP_NULL());
+		return SCTP_DISPOSITION_DELETE_TCB;
+	}
+	err = (sctp_errhdr_t *)(chunk->skb->data);
+
+	/* Process the error here */
+	switch (err->cause) {
+	case SCTP_ERROR_STALE_COOKIE:
+		return sctp_sf_do_5_2_6_stale(ep, asoc, type, arg, commands);
+	default:
+		return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
+	}
+}
+
 /*
  * Handle a Stale COOKIE Error
  *
@@ -1732,47 +1788,30 @@
  *
  * The return value is the disposition of the chunk.
  */
-sctp_disposition_t do_5_2_6_stale(const sctp_endpoint_t *ep,
-				  const sctp_association_t *asoc,
-				  const sctp_subtype_t type,
-				  void *arg,
-				  sctp_cmd_seq_t *commands)
+sctp_disposition_t sctp_sf_do_5_2_6_stale(const sctp_endpoint_t *ep,
+					  const sctp_association_t *asoc,
+					  const sctp_subtype_t type,
+					  void *arg,
+					  sctp_cmd_seq_t *commands)
 {
 	sctp_chunk_t *chunk = arg;
+	time_t stale;
+	sctp_cookie_preserve_param_t bht;
+	sctp_errhdr_t *err;
+	struct list_head *pos;
+	sctp_transport_t *t;
+	sctp_chunk_t *reply;
+	sctp_bind_addr_t *bp;
+	int attempts;
 
-	/* This is not a real chunk type.  It is a subtype of the
-	 * ERROR chunk type.  The ERROR chunk processing will bring us
-	 * here.
-	 */
-	sctp_chunk_t *in_packet;
-	stp_chunk_t *reply;
-	sctp_inithdr_t initack;
-	__u8 *addrs;
-	int addrs_len;
-	time_t rtt;
-	struct sctpCookiePreserve bht;
+	attempts = asoc->counters[SCTP_COUNTER_INIT_ERROR] + 1;
 
-	/* If we have gotten too many failures, give up.  */
-	if (1 + asoc->counters[SctpCounterInits] > asoc->max_init_attempts) {
-		/* FIXME: Move to new ulpevent.  */
-		retval->event_up = sctp_make_ulp_init_timeout(asoc);
-		if (!retval->event_up)
-			goto nomem;
-		sctp_add_cmd_sf(retval->commands, SCTP_CMD_DELETE_TCB,
-				SCTP_NULL());
+	if (attempts >= asoc->max_init_attempts) {
+		sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, SCTP_NULL());
 		return SCTP_DISPOSITION_DELETE_TCB;
 	}
 
-	retval->counters[0] = SCTP_COUNTER_INCR;
-	retval->counters[0] = SctpCounterInits;
-	retval->counters[1] = 0;
-	retval->counters[1] = 0;
-
-	/* Calculate the RTT in ms.  */
-	/* BUG--we should get the send time of the HEARTBEAT REQUEST.  */
-	in_packet = chunk;
-	rtt = 1000 * timeval_sub(in_packet->skb->stamp,
-				 asoc->c.state_timestamp);
+	err = (sctp_errhdr_t *)(chunk->skb->data);
 
 	/* When calculating the time extension, an implementation
 	 * SHOULD use the RTT information measured based on the
@@ -1780,28 +1819,48 @@
 	 * more than 1 second beyond the measured RTT, due to long
 	 * State Cookie lifetimes making the endpoint more subject to
 	 * a replay attack.
-	 */
-	bht.p = {SCTP_COOKIE_PRESERVE, 8};
-	bht.extraTime = htonl(rtt + 1000);
-
-	initack.init_tag		= htonl(asoc->c.my_vtag);
-	initack.a_rwnd 		        = htonl(atomic_read(&asoc->rnwd));
-	initack.num_outbound_streams    = htons(asoc->streamoutcnt);
-	initack.num_inbound_streams     = htons(asoc->streamincnt);
-	initack.initial_tsn             = htonl(asoc->c.initSeqNumber);
-
-	sctp_get_my_addrs(asoc, &addrs, &addrs_len);
+	 * Measure of Staleness's unit is usec. (1/1000000 sec)
+	 * Suggested Cookie Life-span Increment's unit is msec.
+	 * (1/1000 sec)
+	 * In general, if you use the suggested cookie life, the value
+	 * found in the field of measure of staleness should be doubled
+	 * to give ample time to retransmit the new cookie and thus
+	 * yield a higher probability of success on the reattempt.
+	 */
+	stale = ntohl(*(suseconds_t *)((u8 *)err + sizeof(sctp_errhdr_t)));
+	stale = stale << 1 / 1000;
+
+	bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
+	bht.param_hdr.length = htons(sizeof(bht));
+	bht.lifespan_increment = htonl(stale);
 
 	/* Build that new INIT chunk.  */
-	reply = sctp_make_chunk(SCTP_INITIATION, 0,
-				sizeof(initack)
-				+ sizeof(bht)
-				+ addrs_len);
+	bp = (sctp_bind_addr_t *) &asoc->base.bind_addr;
+	reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
 	if (!reply)
 		goto nomem;
-	sctp_addto_chunk(reply, sizeof(initack), &initack);
+
 	sctp_addto_chunk(reply, sizeof(bht), &bht);
-	sctp_addto_chunk(reply, addrs_len, addrs);
+
+	/* Cast away the const modifier, as we want to just
+	 * rerun it through as a sideffect.
+	 */
+	sctp_add_cmd_sf(commands, SCTP_CMD_COUNTER_INC,
+			SCTP_COUNTER(SCTP_COUNTER_INIT_ERROR));
+
+	/* If we've sent any data bundled with COOKIE-ECHO we need to resend. */
+	list_for_each(pos, &asoc->peer.transport_addr_list) {
+		t = list_entry(pos, sctp_transport_t, transports);
+		sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(t));
+	}
+
+	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
+			SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
+	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
+			SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
+	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
+			SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
+
 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
 
 	return SCTP_DISPOSITION_CONSUME;
@@ -1809,7 +1868,6 @@
 nomem:
 	return SCTP_DISPOSITION_NOMEM;
 }
-#endif /* 0 */
 
 /*
  * Process an ABORT.
@@ -3220,7 +3278,7 @@
 	 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
 	 */
 
-	repl = sctp_make_init(asoc, bp, GFP_ATOMIC);
+	repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
 	if (!repl)
 		goto nomem;
 
@@ -3992,7 +4050,7 @@
 		switch (timer) {
 		case SCTP_EVENT_TIMEOUT_T1_INIT:
 			bp = (sctp_bind_addr_t *) &asoc->base.bind_addr;
-			repl = sctp_make_init(asoc, bp, GFP_ATOMIC);
+			repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
 			break;
 
 		case SCTP_EVENT_TIMEOUT_T1_COOKIE:
@@ -4333,4 +4391,26 @@
 {
 	sctp_transport_free(packet->transport);
 	sctp_packet_free(packet);
+}
+
+/* Send a stale cookie error when a invalid COOKIE ECHO chunk is found  */
+void sctp_send_stale_cookie_err(const sctp_endpoint_t *ep,
+				const sctp_association_t *asoc,
+				const sctp_chunk_t *chunk,
+				sctp_cmd_seq_t *commands,
+				sctp_chunk_t *err_chunk)
+{
+	sctp_packet_t *packet;
+
+	if (err_chunk) {
+		packet = sctp_ootb_pkt_new(asoc, chunk);
+		if (packet) {
+			/* Set the skb to the belonging sock for accounting. */
+			err_chunk->skb->sk = ep->base.sk;
+			sctp_packet_append_chunk(packet, err_chunk);
+			sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
+					SCTP_PACKET(packet));
+		} else
+			sctp_free_chunk (err_chunk);
+	}
 }
diff -Nru a/net/sctp/sm_statetable.c b/net/sctp/sm_statetable.c
--- a/net/sctp/sm_statetable.c	Mon Dec 23 21:22:01 2002
+++ b/net/sctp/sm_statetable.c	Mon Dec 23 21:22:01 2002
@@ -295,7 +295,7 @@
 	/* SCTP_STATE_COOKIE_WAIT */ \
 	{.fn = sctp_sf_not_impl, .name = "sctp_sf_not_impl"}, \
 	/* SCTP_STATE_COOKIE_ECHOED */ \
-	{.fn = sctp_sf_not_impl, .name = "sctp_sf_not_impl"}, \
+	{.fn = sctp_sf_cookie_echoed_err, .name = "sctp_sf_cookie_echoed_err"}, \
 	/* SCTP_STATE_ESTABLISHED */ \
 	{.fn = sctp_sf_operr_notify, .name = "sctp_sf_operr_notify"}, \
 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
diff -Nru a/net/sctp/socket.c b/net/sctp/socket.c
--- a/net/sctp/socket.c	Mon Dec 23 21:22:03 2002
+++ b/net/sctp/socket.c	Mon Dec 23 21:22:03 2002
@@ -87,12 +87,7 @@
 				int msg_len);
 static int sctp_wait_for_packet(struct sock * sk, int *err, long *timeo_p);
 static int sctp_wait_for_connect(sctp_association_t *asoc, long *timeo_p);
-static inline void sctp_sk_addr_set(struct sock *,
-				    const union sctp_addr *newaddr,
-				    union sctp_addr *saveaddr);
-static inline void sctp_sk_addr_restore(struct sock *,
-					const union sctp_addr *);
-static inline int sctp_verify_addr(struct sock *, struct sockaddr *, int);
+static inline int sctp_verify_addr(struct sock *, union sctp_addr *, int);
 static int sctp_bindx_add(struct sock *, struct sockaddr_storage *, int);
 static int sctp_bindx_rem(struct sock *, struct sockaddr_storage *, int);
 static int sctp_do_bind(struct sock *, union sctp_addr *, int);
@@ -133,101 +128,75 @@
 	return retval;
 }
 
-static long sctp_get_port_local(struct sock *, unsigned short);
+static long sctp_get_port_local(struct sock *, union sctp_addr *);
 
-/* Bind a local address either to an endpoint or to an association.  */
-SCTP_STATIC int sctp_do_bind(struct sock *sk, union sctp_addr *newaddr,
-			     int addr_len)
+/* Verify this is a valid sockaddr. */
+static struct sctp_af *sctp_sockaddr_af(struct sctp_opt *opt, 
+					union sctp_addr *addr, int len)
 {
-	sctp_opt_t *sp = sctp_sk(sk);
-	sctp_endpoint_t *ep = sp->ep;
-	sctp_bind_addr_t *bp = &ep->base.bind_addr;
-	unsigned short sa_family = newaddr->sa.sa_family;
-	union sctp_addr tmpaddr, saveaddr;
-	unsigned short *snum;
-	int ret = 0;
+	struct sctp_af *af;
 
-	SCTP_DEBUG_PRINTK("sctp_do_bind(sk: %p, newaddr: %p, addr_len: %d)\n",
-			  sk, newaddr, addr_len);
+	/* Check minimum size.  */
+	if (len < sizeof (struct sockaddr))
+		return NULL;
 
-	/* FIXME: This function needs to handle v4-mapped-on-v6
-	 * addresses!
-	 */
-	if (PF_INET == sk->family) {
-		if (sa_family != AF_INET)
-			return -EINVAL;
-	}
+	/* Does this PF support this AF? */
+	if (!opt->pf->af_supported(addr->sa.sa_family))
+		return NULL;
 
-	/* Make a local copy of the new address.  */
-	tmpaddr = *newaddr;
+	/* If we get this far, af is valid. */
+	af = sctp_get_af_specific(addr->sa.sa_family);
 
-	switch (sa_family) {
-	case AF_INET:
-		if (addr_len < sizeof(struct sockaddr_in))
-			return -EINVAL;
+	if (len < af->sockaddr_len)
+		return NULL;
 
-		ret = inet_addr_type(newaddr->v4.sin_addr.s_addr);
+	return af;
+}
 
-		/* FIXME:
-		 * Should we allow apps to bind to non-local addresses by
-		 * checking the IP sysctl parameter "ip_nonlocal_bind"?
-		 */
-		if (newaddr->v4.sin_addr.s_addr != INADDR_ANY &&
-		    ret != RTN_LOCAL)
-			return -EADDRNOTAVAIL;
-
-		tmpaddr.v4.sin_port = htons(tmpaddr.v4.sin_port);
-		snum = &tmpaddr.v4.sin_port;
-		break;
 
-	case AF_INET6:
-		SCTP_V6(
-			/* FIXME: Hui, please verify this.   Looking at
-			 * the ipv6 code I see a SIN6_LEN_RFC2133 check.
-			 * I'm guessing that scope_id is a newer addition.
-			 */
-			if (addr_len < sizeof(struct sockaddr_in6))
-				return -EINVAL;
+/* Bind a local address either to an endpoint or to an association.  */
+SCTP_STATIC int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
+{
+	sctp_opt_t *sp = sctp_sk(sk);
+	sctp_endpoint_t *ep = sp->ep;
+	sctp_bind_addr_t *bp = &ep->base.bind_addr;
+	struct sctp_af *af;
+	unsigned short snum;
+	int ret = 0;
 
-			/* FIXME - The support for IPv6 multiple types
-			 * of addresses need to be added later.
-			 */
-			ret = sctp_ipv6_addr_type(&newaddr->v6.sin6_addr);
-			tmpaddr.v6.sin6_port = htons(tmpaddr.v6.sin6_port);
-			snum = &tmpaddr.v6.sin6_port;
-			break;
-		)
+	SCTP_DEBUG_PRINTK("sctp_do_bind(sk: %p, newaddr: %p, len: %d)\n",
+			  sk, addr, len);
 
-	default:
+	/* Common sockaddr verification. */
+	af = sctp_sockaddr_af(sp, addr, len);
+	if (!af)
 		return -EINVAL;
-	};
+
+	/* PF specific bind() address verification. */
+	if (!sp->pf->bind_verify(sp, addr))
+		return -EADDRNOTAVAIL;
+
+	snum= ntohs(addr->v4.sin_port);
 
 	SCTP_DEBUG_PRINTK("sctp_do_bind: port: %d, new port: %d\n",
-			  bp->port, *snum);
+			  bp->port, snum);
 
 	/* We must either be unbound, or bind to the same port.  */
-	if (bp->port && (*snum != bp->port)) {
+	if (bp->port && (snum != bp->port)) {
 		SCTP_DEBUG_PRINTK("sctp_do_bind:"
 				  " New port %d does not match existing port "
-				  "%d.\n", *snum, bp->port);
+				  "%d.\n", snum, bp->port);
 		return -EINVAL;
 	}
 
-	if (*snum && *snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE))
+	if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE))
 		return -EACCES;
 
-	/* FIXME - Make socket understand that there might be multiple bind
-	 * addresses and there will be multiple source addresses involved in
-	 * routing and failover decisions.
-	 */
-	sctp_sk_addr_set(sk, &tmpaddr, &saveaddr);
-
 	/* Make sure we are allowed to bind here.
 	 * The function sctp_get_port_local() does duplicate address
 	 * detection.
 	 */
-	if ((ret = sctp_get_port_local(sk, *snum))) {
-		sctp_sk_addr_restore(sk, &saveaddr);
+	if ((ret = sctp_get_port_local(sk, addr))) {
 		if (ret == (long) sk) {
 			/* This endpoint has a conflicting address. */
 			return -EINVAL;
@@ -237,25 +206,32 @@
 	}
 
 	/* Refresh ephemeral port.  */
-	if (!*snum)
-		*snum = inet_sk(sk)->num;
+	if (!snum)
+		snum = inet_sk(sk)->num;
+
+
 
-	/* The getsockname() API depends on 'sport' being set.  */
-	inet_sk(sk)->sport = htons(inet_sk(sk)->num);
 
 	/* Add the address to the bind address list.  */
 	sctp_local_bh_disable();
 	sctp_write_lock(&ep->base.addr_lock);
 
 	/* Use GFP_ATOMIC since BHs are disabled.  */
-	if ((ret = sctp_add_bind_addr(bp, &tmpaddr, GFP_ATOMIC))) {
-		sctp_sk_addr_restore(sk, &saveaddr);
-	} else if (!bp->port) {
-		bp->port = *snum;
-	}
+	addr->v4.sin_port = ntohs(addr->v4.sin_port);
+	ret = sctp_add_bind_addr(bp, addr, GFP_ATOMIC);
+	addr->v4.sin_port = htons(addr->v4.sin_port);
+	if (!ret && !bp->port)
+		bp->port = snum;
 
 	sctp_write_unlock(&ep->base.addr_lock);
 	sctp_local_bh_enable();
+
+	/* Copy back into socket for getsockname() use. */
+	if (!ret) {
+		inet_sk(sk)->sport = htons(inet_sk(sk)->num);
+		af->to_sk(addr, sk);
+	}
+
 	return ret;
 }
 
@@ -735,7 +711,7 @@
 SCTP_STATIC int sctp_msghdr_parse(const struct msghdr *, sctp_cmsgs_t *);
 
 SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
-			     struct msghdr *msg, int size)
+			     struct msghdr *msg, int msg_len)
 {
 	sctp_opt_t *sp;
 	sctp_endpoint_t *ep;
@@ -750,13 +726,12 @@
 	sctp_assoc_t associd = NULL;
 	sctp_cmsgs_t cmsgs = { 0 };
 	int err;
-	size_t msg_len;
 	sctp_scope_t scope;
 	long timeo;
 	__u16 sinfo_flags = 0;
 
-	SCTP_DEBUG_PRINTK("sctp_sendmsg(sk: %p, msg: %p, "
-			  "size: %d)\n", sk, msg, size);
+	SCTP_DEBUG_PRINTK("sctp_sendmsg(sk: %p, msg: %p, msg_len: %d)\n",
+			  sk, msg, msg_len);
 
 	err = 0;
 	sp = sctp_sk(sk);
@@ -778,12 +753,16 @@
 	 * For a peeled-off socket, msg_name is ignored.
 	 */
 	if ((SCTP_SOCKET_UDP_HIGH_BANDWIDTH != sp->type) && msg->msg_name) {
-		err = sctp_verify_addr(sk, (struct sockaddr *)msg->msg_name,
-				       msg->msg_namelen);
+		int msg_namelen = msg->msg_namelen;
+	
+		err = sctp_verify_addr(sk, (union sctp_addr *)msg->msg_name, 
+				       msg_namelen);
 		if (err)
 			return err;
 
-		memcpy(&to, msg->msg_name, msg->msg_namelen);
+		if (msg_namelen > sizeof(to))
+			msg_namelen = sizeof(to);
+		memcpy(&to, msg->msg_name, msg_namelen);
 		SCTP_DEBUG_PRINTK("Just memcpy'd. msg_name is "
 				  "0x%x:%u.\n",
 				  to.v4.sin_addr.s_addr, to.v4.sin_port);
@@ -792,8 +771,6 @@
 		msg_name = msg->msg_name;
 	}
 
-	msg_len = get_user_iov_size(msg->msg_iov, msg->msg_iovlen);
-
 	sinfo = cmsgs.info;
 	sinit = cmsgs.init;
 
@@ -1216,9 +1193,11 @@
 	 * Otherwise, set MSG_EOR indicating the end of a message. 
 	 */
 	if (skb_len > copied) {
+		msg->msg_flags &= ~MSG_EOR;
+		if (flags & MSG_PEEK)
+			goto out_free;	
 		sctp_skb_pull(skb, copied);
 		skb_queue_head(&sk->receive_queue, skb);
-		msg->msg_flags &= ~MSG_EOR;
 		goto out;
 	} else {
 		 msg->msg_flags |= MSG_EOR;
@@ -1335,6 +1314,16 @@
 	return 0;
 }
 
+static inline int sctp_setsockopt_initmsg(struct sock *sk, char *optval,
+					  int optlen)
+{
+	if (optlen != sizeof(struct sctp_initmsg))
+		return -EINVAL;
+	if (copy_from_user(&sctp_sk(sk)->initmsg, optval, optlen))
+		return -EFAULT;
+	return 0;
+}
+
 /* API 6.2 setsockopt(), getsockopt()
  *
  * Applications use setsockopt() and getsockopt() to set or retrieve
@@ -1355,13 +1344,10 @@
  *   optlen  - the size of the buffer.
  */
 SCTP_STATIC int sctp_setsockopt(struct sock *sk, int level, int optname,
-			   char *optval, int optlen)
+				char *optval, int optlen)
 {
 	int retval = 0;
 	char *tmp;
-	sctp_protocol_t *proto = sctp_get_protocol();
-	struct list_head *pos;
-	sctp_func_t *af;
 
 	SCTP_DEBUG_PRINTK("sctp_setsockopt(sk: %p... optname: %d)\n",
 			  sk, optname);
@@ -1373,14 +1359,9 @@
 	 * are at all well-founded.
 	 */
 	if (level != SOL_SCTP) {
-		list_for_each(pos, &proto->address_families) {
-			af = list_entry(pos, sctp_func_t, list);
-
-			retval = af->setsockopt(sk, level, optname, optval,
-						optlen);
-			if (retval < 0)
-				goto out_nounlock;
-		}
+		struct sctp_af *af = sctp_sk(sk)->pf->af;
+		retval = af->setsockopt(sk, level, optname, optval, optlen);
+		goto out_nounlock;
 	}
 
 	sctp_lock_sock(sk);
@@ -1430,6 +1411,10 @@
 							      optlen);
 		break;
 
+	case SCTP_INITMSG:
+		retval = sctp_setsockopt_initmsg(sk, optval, optlen);
+		break;
+
 	default:
 		retval = -ENOPROTOOPT;
 		break;
@@ -1484,7 +1469,7 @@
 		goto out_unlock;
 	}
 
-	err = sctp_verify_addr(sk, uaddr, addr_len);
+	err = sctp_verify_addr(sk, (union sctp_addr *)uaddr, addr_len);
 	if (err)
 		goto out_unlock;	
 
@@ -1938,13 +1923,19 @@
 	return 0;
 }
 
+static inline int sctp_getsockopt_initmsg(struct sock *sk, int len, char *optval, int *optlen)
+{
+	if (len != sizeof(struct sctp_initmsg))
+		return -EINVAL;
+	if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
+		return -EFAULT;
+	return 0;
+}
+
 SCTP_STATIC int sctp_getsockopt(struct sock *sk, int level, int optname,
 				char *optval, int *optlen)
 {
 	int retval = 0;
-	sctp_protocol_t *proto = sctp_get_protocol();
-	sctp_func_t *af;
-	struct list_head *pos;
 	int len;
 
 	SCTP_DEBUG_PRINTK("sctp_getsockopt(sk: %p, ...)\n", sk);
@@ -1956,13 +1947,10 @@
 	 * are at all well-founded.
 	 */
 	if (level != SOL_SCTP) {
-		list_for_each(pos, &proto->address_families) {
-			af = list_entry(pos, sctp_func_t, list);
-			retval = af->getsockopt(sk, level, optname,
-						optval, optlen);
-			if (retval < 0)
-				return retval;
-		}
+		struct sctp_af *af = sctp_sk(sk)->pf->af;
+
+		retval = af->getsockopt(sk, level, optname, optval, optlen);
+		return retval;
 	}
 
 	if (get_user(len, optlen))
@@ -1997,6 +1985,10 @@
 							      optlen);
 		break;
 
+	case SCTP_INITMSG:
+		retval = sctp_getsockopt_initmsg(sk, len, optval, optlen);
+		break;
+
 	default:
 		retval = -ENOPROTOOPT;
 		break;
@@ -2030,12 +2022,17 @@
  */
 static sctp_bind_bucket_t *sctp_bucket_create(sctp_bind_hashbucket_t *head,
 					      unsigned short snum);
-static long sctp_get_port_local(struct sock *sk, unsigned short snum)
+static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
 {
 	sctp_bind_hashbucket_t *head; /* hash list */
 	sctp_bind_bucket_t *pp; /* hash list port iterator */
 	sctp_protocol_t *sctp = sctp_get_protocol();
+	unsigned short snum;
 	int ret;
+	
+	/* NOTE:  Remember to put this back to net order. */
+	addr->v4.sin_port = ntohs(addr->v4.sin_port);
+	snum = addr->v4.sin_port;
 
 	SCTP_DEBUG_PRINTK("sctp_get_port() begins, snum=%d\n", snum);
 
@@ -2101,6 +2098,7 @@
 		}
 	}
 
+	
 	if (pp != NULL && pp->sk != NULL) {
 		/* We had a port hash table hit - there is an
 		 * available port (pp != NULL) and it is being
@@ -2108,7 +2106,6 @@
 		 * socket is going to be sk2.
 		 */
 		int sk_reuse = sk->reuse;
-		union sctp_addr tmpaddr;
 		struct sock *sk2 = pp->sk;
 
 		SCTP_DEBUG_PRINTK("sctp_get_port() found a "
@@ -2116,27 +2113,6 @@
 		if (pp->fastreuse != 0 && sk->reuse != 0)
 			goto success;
 
-		/* FIXME - multiple addresses need to be supported
-		 * later.
-		 */
-		switch (sk->family) {
-		case PF_INET:
-			tmpaddr.v4.sin_family = AF_INET;
-			tmpaddr.v4.sin_port = snum;
-			tmpaddr.v4.sin_addr.s_addr = inet_sk(sk)->rcv_saddr;
-			break;
-
-		case PF_INET6:
-			SCTP_V6(tmpaddr.v6.sin6_family = AF_INET6;
-				tmpaddr.v6.sin6_port = snum;
-				tmpaddr.v6.sin6_addr = inet6_sk(sk)->rcv_saddr;
-			)
-			break;
-
-		default:
-			break;
-		};
-
 		/* Run through the list of sockets bound to the port
 		 * (pp->port) [via the pointers bind_next and
 		 * bind_pprev in the struct sock *sk2 (pp->sk)]. On each one,
@@ -2154,8 +2130,7 @@
 			if (sk_reuse && sk2->reuse)
 				continue;
 			
-			if (sctp_bind_addr_match(&ep2->base.bind_addr, 
-						 &tmpaddr,
+			if (sctp_bind_addr_match(&ep2->base.bind_addr, addr,
 						 sctp_sk(sk)))
 				goto found;
 		}
@@ -2207,12 +2182,25 @@
 	sctp_local_bh_enable();
 
 	SCTP_DEBUG_PRINTK("sctp_get_port() ends, ret=%d\n", ret);
+	addr->v4.sin_port = htons(addr->v4.sin_port);
 	return ret;
 }
 
+/* Assign a 'snum' port to the socket.  If snum == 0, an ephemeral
+ * port is requested.  
+ */
 static int sctp_get_port(struct sock *sk, unsigned short snum)
 {
-	long ret = sctp_get_port_local(sk, snum);
+	long ret;
+	union sctp_addr addr;
+	struct sctp_af *af = sctp_sk(sk)->pf->af;
+
+	/* Set up a dummy address struct from the sk. */
+	af->from_sk(&addr, sk);
+	addr.v4.sin_port = htons(snum);
+
+	/* Note: sk->num gets filled in if ephemeral port request. */
+	ret = sctp_get_port_local(sk, &addr);
 
 	return (ret ? 1 : 0);
 }
@@ -2413,7 +2401,7 @@
 static int sctp_autobind(struct sock *sk)
 {
 	union sctp_addr autoaddr;
-	struct sctp_func *af;
+	struct sctp_af *af;
 	unsigned short port;
 
 	/* Initialize a local sockaddr structure to INADDR_ANY. */
@@ -2537,58 +2525,6 @@
 	return 0;
 }
 
-/* Setup sk->rcv_saddr before calling get_port().  */
-static inline void sctp_sk_addr_set(struct sock *sk,
-				    const union sctp_addr *newaddr,
-				    union sctp_addr *saveaddr)
-{
-	struct inet_opt *inet = inet_sk(sk);
-
-	saveaddr->sa.sa_family = newaddr->sa.sa_family;
-
-	switch (newaddr->sa.sa_family) {
-	case AF_INET:
-		saveaddr->v4.sin_addr.s_addr = inet->rcv_saddr;
-		inet->rcv_saddr = inet->saddr = newaddr->v4.sin_addr.s_addr;
-		break;
-
-	case AF_INET6:
-		SCTP_V6({
-			struct ipv6_pinfo *np = inet6_sk(sk);
-
-			saveaddr->v6.sin6_addr = np->rcv_saddr;
-			np->rcv_saddr = np->saddr = newaddr->v6.sin6_addr;
-			break;
-		})
-
-	default:
-		break;
-	};
-}
-
-/* Restore sk->rcv_saddr after failing get_port().  */
-static inline void sctp_sk_addr_restore(struct sock *sk, const union sctp_addr *addr)
-{
-	struct inet_opt *inet = inet_sk(sk);
-
-	switch (addr->sa.sa_family) {
-	case AF_INET:
-		inet->rcv_saddr = inet->saddr = addr->v4.sin_addr.s_addr;
-		break;
-
-	case AF_INET6:
-		SCTP_V6({
-			struct ipv6_pinfo *np = inet6_sk(sk);
-
-			np->rcv_saddr = np->saddr = addr->v6.sin6_addr;
-			break;
-		})
-
-	default:
-		break;
-	};
-}
-
 /*
  * Wait for a packet..
  * Note: This function is the same function as in core/datagram.c
@@ -2711,25 +2647,13 @@
 }
 
 /* Verify that this is a valid address. */
-static int sctp_verify_addr(struct sock *sk, struct sockaddr *addr, int len)
+static int sctp_verify_addr(struct sock *sk, union sctp_addr *addr, int len)
 {
-	struct sctp_func *af;
-
-	/* Check minimum size.  */
-	if (len < sizeof (struct sockaddr))
-		return -EINVAL;
+	struct sctp_af *af;
 
-	/* Do we support this address family in general? */
-	af = sctp_get_af_specific(addr->sa_family);
+	/* Verify basic sockaddr. */
+	af = sctp_sockaddr_af(sctp_sk(sk), addr, len);
 	if (!af)
-		return -EINVAL;
-
-	/* Does this PF support this AF? */
-	if (!sctp_sk(sk)->pf->af_supported(addr->sa_family))
-		return -EINVAL;
-     
-	/* Verify the minimum for this AF sockaddr. */
-	if (len < af->sockaddr_len)
 		return -EINVAL;
 
 	/* Is this a valid SCTP address?  */
diff -Nru a/net/sctp/sysctl.c b/net/sctp/sysctl.c
--- a/net/sctp/sysctl.c	Mon Dec 23 21:21:53 2002
+++ b/net/sctp/sysctl.c	Mon Dec 23 21:21:53 2002
@@ -1,5 +1,6 @@
 /* SCTP kernel reference Implementation 
  * Copyright (c) 2002 International Business Machines Corp.
+ * Copyright (c) 2002 Intel Corp.
  * 
  * This file is part of the SCTP kernel reference Implementation
  * 
@@ -32,6 +33,7 @@
  * Written or modified by: 
  *    Mingqin Liu           <liuming@us.ibm.com>
  *    Jon Grimm             <jgrimm@us.ibm.com>
+ *    Ardelle Fan           <ardelle.fan@intel.com>
  *
  * Any bugs reported given to us we will try to fix... any fixes shared will
  * be incorporated into the next SCTP release.
@@ -69,6 +71,9 @@
 	  &proc_dointvec },
 	{ NET_SCTP_HB_INTERVAL, "hb_interval",
 	  &sctp_proto.hb_interval, sizeof(int), 0644, NULL,
+	  &proc_dointvec_jiffies, &sysctl_jiffies },
+	{ NET_SCTP_PRESERVE_ENABLE, "cookie_preserve_enable",
+	  &sctp_proto.cookie_preserve_enable, sizeof(int), 0644, NULL,
 	  &proc_dointvec_jiffies, &sysctl_jiffies },
 	{ NET_SCTP_RTO_ALPHA, "rto_alpha_exp_divisor",
 	  &sctp_proto.rto_alpha, sizeof(int), 0644, NULL,
diff -Nru a/net/sctp/transport.c b/net/sctp/transport.c
--- a/net/sctp/transport.c	Mon Dec 23 21:21:51 2002
+++ b/net/sctp/transport.c	Mon Dec 23 21:21:51 2002
@@ -207,7 +207,7 @@
 			  struct sctp_opt *opt)
 {
 	sctp_association_t *asoc = transport->asoc;
-	struct sctp_func *af = transport->af_specific;
+	struct sctp_af *af = transport->af_specific;
 	union sctp_addr *daddr = &transport->ipaddr;
 	sctp_bind_addr_t *bp;
 	rwlock_t *addr_lock;
diff -Nru a/net/sctp/ulpevent.c b/net/sctp/ulpevent.c
--- a/net/sctp/ulpevent.c	Mon Dec 23 21:21:51 2002
+++ b/net/sctp/ulpevent.c	Mon Dec 23 21:21:51 2002
@@ -762,6 +762,8 @@
 {
 	sctp_association_t *asoc;
 	sctp_ulpevent_t *event;
+	sctp_chunk_t *sack;
+	struct timer_list *timer;
 
 	/* Current stack structures assume that the rcv buffer is
 	 * per socket.   For UDP style sockets this is not true as
@@ -782,9 +784,39 @@
 		asoc->rwnd += skb->len;
 	}
 
-	SCTP_DEBUG_PRINTK("rwnd increased by %d to (%u, %u)\n",
-			  skb->len, asoc->rwnd, asoc->rwnd_over);
+	SCTP_DEBUG_PRINTK("rwnd increased by %d to (%u, %u) - %u\n",
+			  skb->len, asoc->rwnd, asoc->rwnd_over, asoc->a_rwnd);
 
+	/* Send a window update SACK if the rwnd has increased by at least the
+	 * minimum of the association's PMTU and half of the receive buffer.
+	 * The algorithm used is similar to the one described in Section 4.2.3.3
+	 * of RFC 1122.
+	 */
+	if ((asoc->state == SCTP_STATE_ESTABLISHED) &&
+	    (asoc->rwnd > asoc->a_rwnd) &&
+	    ((asoc->rwnd - asoc->a_rwnd) >=
+		     min_t(__u32, (asoc->base.sk->rcvbuf >> 1), asoc->pmtu))) {
+		SCTP_DEBUG_PRINTK("Sending window update SACK- rwnd: %u "
+				  "a_rwnd: %u\n", asoc->rwnd, asoc->a_rwnd);
+		sack = sctp_make_sack(asoc); 
+		if (!sack)
+			goto out;
+
+		/* Update the last advertised rwnd value. */
+		asoc->a_rwnd = asoc->rwnd;
+
+		asoc->peer.sack_needed = 0;
+		asoc->peer.next_dup_tsn = 0;
+
+		sctp_push_outqueue(&asoc->outqueue, sack);
+
+		/* Stop the SACK timer.  */
+		timer = &asoc->timers[SCTP_EVENT_TIMEOUT_SACK];
+		if (timer_pending(timer) && del_timer(timer))
+			sctp_association_put(asoc);
+	} 
+
+out:
 	sctp_association_put(asoc);
 }
 
diff -Nru a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
--- a/net/sunrpc/xdr.c	Mon Dec 23 21:21:58 2002
+++ b/net/sunrpc/xdr.c	Mon Dec 23 21:21:58 2002
@@ -306,6 +306,7 @@
 				len = pglen;
 			ret = copy_actor(desc, kaddr, len);
 		}
+		flush_dcache_page(*ppage);
 		kunmap_atomic(kaddr, KM_SKB_SUNRPC_DATA);
 		if (ret != len || !desc->count)
 			return;
diff -Nru a/security/Kconfig b/security/Kconfig
--- a/security/Kconfig	Mon Dec 23 21:21:58 2002
+++ b/security/Kconfig	Mon Dec 23 21:21:58 2002
@@ -27,8 +27,11 @@
 	depends on SECURITY!=n
 	help
 	  This is a sample LSM module that should only be used as such.
-	  It enables control over processes being created by root users
-	  if a specific USB device is not present in the system.
+	  It prevents any programs running with egid == 0 if a specific
+	  USB device is not present in the system.
+
+	  See <http://www.linuxjournal.com/article.php?sid=6279> for
+	  more information about this module.
 	  
 	  If you are unsure how to answer this question, answer N.
 
diff -Nru a/security/dummy.c b/security/dummy.c
--- a/security/dummy.c	Mon Dec 23 21:21:51 2002
+++ b/security/dummy.c	Mon Dec 23 21:21:51 2002
@@ -3,7 +3,7 @@
  * security model is loaded.
  *
  * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com>
- * Copyright (C) 2001 Greg Kroah-Hartman <greg@kroah.com>
+ * Copyright (C) 2001-2002  Greg Kroah-Hartman <greg@kroah.com>
  * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
  *
  *	This program is free software; you can redistribute it and/or modify
@@ -542,111 +542,7 @@
 	return -EINVAL;
 }
 
-struct security_operations dummy_security_ops = {
-	.ptrace =			dummy_ptrace,
-	.capget =			dummy_capget,
-	.capset_check =			dummy_capset_check,
-	.capset_set =			dummy_capset_set,
-	.acct =				dummy_acct,
-	.capable =			dummy_capable,
-	.quotactl =			dummy_quotactl,
-	.quota_on =			dummy_quota_on,
-
-	.bprm_alloc_security =		dummy_bprm_alloc_security,
-	.bprm_free_security =		dummy_bprm_free_security,
-	.bprm_compute_creds =		dummy_bprm_compute_creds,
-	.bprm_set_security =		dummy_bprm_set_security,
-	.bprm_check_security =		dummy_bprm_check_security,
-
-	.sb_alloc_security =		dummy_sb_alloc_security,
-	.sb_free_security =		dummy_sb_free_security,
-	.sb_statfs =			dummy_sb_statfs,
-	.sb_mount =			dummy_sb_mount,
-	.sb_check_sb =			dummy_sb_check_sb,
-	.sb_umount =			dummy_sb_umount,
-	.sb_umount_close =		dummy_sb_umount_close,
-	.sb_umount_busy =		dummy_sb_umount_busy,
-	.sb_post_remount =		dummy_sb_post_remount,
-	.sb_post_mountroot =		dummy_sb_post_mountroot,
-	.sb_post_addmount =		dummy_sb_post_addmount,
-	.sb_pivotroot =			dummy_sb_pivotroot,
-	.sb_post_pivotroot =		dummy_sb_post_pivotroot,
-	
-	.inode_alloc_security =		dummy_inode_alloc_security,
-	.inode_free_security =		dummy_inode_free_security,
-	.inode_create =			dummy_inode_create,
-	.inode_post_create =		dummy_inode_post_create,
-	.inode_link =			dummy_inode_link,
-	.inode_post_link =		dummy_inode_post_link,
-	.inode_unlink =			dummy_inode_unlink,
-	.inode_symlink =		dummy_inode_symlink,
-	.inode_post_symlink =		dummy_inode_post_symlink,
-	.inode_mkdir =			dummy_inode_mkdir,
-	.inode_post_mkdir =		dummy_inode_post_mkdir,
-	.inode_rmdir =			dummy_inode_rmdir,
-	.inode_mknod =			dummy_inode_mknod,
-	.inode_post_mknod =		dummy_inode_post_mknod,
-	.inode_rename =			dummy_inode_rename,
-	.inode_post_rename =		dummy_inode_post_rename,
-	.inode_readlink =		dummy_inode_readlink,
-	.inode_follow_link =		dummy_inode_follow_link,
-	.inode_permission =		dummy_inode_permission,
-	.inode_permission_lite =	dummy_inode_permission_lite,
-	.inode_setattr =		dummy_inode_setattr,
-	.inode_getattr =		dummy_inode_getattr,
-	.inode_post_lookup =		dummy_inode_post_lookup,
-	.inode_delete =			dummy_inode_delete,
-	.inode_setxattr =		dummy_inode_setxattr,
-	.inode_getxattr =		dummy_inode_getxattr,
-	.inode_listxattr =		dummy_inode_listxattr,
-	.inode_removexattr =		dummy_inode_removexattr,
-
-	.file_permission =		dummy_file_permission,
-	.file_alloc_security =		dummy_file_alloc_security,
-	.file_free_security =		dummy_file_free_security,
-	.file_ioctl =			dummy_file_ioctl,
-	.file_mmap =			dummy_file_mmap,
-	.file_mprotect =		dummy_file_mprotect,
-	.file_lock =			dummy_file_lock,
-	.file_fcntl =			dummy_file_fcntl,
-	.file_set_fowner =		dummy_file_set_fowner,
-	.file_send_sigiotask =		dummy_file_send_sigiotask,
-	.file_receive =			dummy_file_receive,
-
-	.task_create =			dummy_task_create,
-	.task_alloc_security =		dummy_task_alloc_security,
-	.task_free_security =		dummy_task_free_security,
-	.task_setuid =			dummy_task_setuid,
-	.task_post_setuid =		dummy_task_post_setuid,
-	.task_setgid =			dummy_task_setgid,
-	.task_setpgid =			dummy_task_setpgid,
-	.task_getpgid =			dummy_task_getpgid,
-	.task_getsid =			dummy_task_getsid,
-	.task_setgroups =		dummy_task_setgroups,
-	.task_setnice =			dummy_task_setnice,
-	.task_setrlimit =		dummy_task_setrlimit,
-	.task_setscheduler =		dummy_task_setscheduler,
-	.task_getscheduler =		dummy_task_getscheduler,
-	.task_wait =			dummy_task_wait,
-	.task_kill =			dummy_task_kill,
-	.task_prctl =			dummy_task_prctl,
-	.task_kmod_set_label =		dummy_task_kmod_set_label,
-	.task_reparent_to_init =	dummy_task_reparent_to_init,
-
-	.ipc_permission =		dummy_ipc_permission,
-	
-	.msg_queue_alloc_security =	dummy_msg_queue_alloc_security,
-	.msg_queue_free_security =	dummy_msg_queue_free_security,
-	
-	.shm_alloc_security =		dummy_shm_alloc_security,
-	.shm_free_security =		dummy_shm_free_security,
-	
-	.sem_alloc_security =		dummy_sem_alloc_security,
-	.sem_free_security =		dummy_sem_free_security,
-
-	.register_security =		dummy_register_security,
-	.unregister_security =		dummy_unregister_security,
-};
+struct security_operations dummy_security_ops;
 
 #define set_to_dummy_if_null(ops, function)				\
 	do {								\
diff -Nru a/security/root_plug.c b/security/root_plug.c
--- a/security/root_plug.c	Mon Dec 23 21:22:00 2002
+++ b/security/root_plug.c	Mon Dec 23 21:22:00 2002
@@ -13,6 +13,9 @@
  * If you want to turn this into something with a semblance of security,
  * you need to hook the task_* functions also.
  *
+ * See http://www.linuxjournal.com/article.php?sid=6279 for more information
+ * about this code.
+ *
  *	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, version 2 of the
diff -Nru a/security/security.c b/security/security.c
--- a/security/security.c	Mon Dec 23 21:21:50 2002
+++ b/security/security.c	Mon Dec 23 21:21:50 2002
@@ -2,7 +2,7 @@
  * Security plug functions
  *
  * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com>
- * Copyright (C) 2001 Greg Kroah-Hartman <greg@kroah.com>
+ * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
  * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
  *
  *	This program is free software; you can redistribute it and/or modify
@@ -47,6 +47,12 @@
 {
 	printk (KERN_INFO "Security Scaffold v" SECURITY_SCAFFOLD_VERSION
 		" initialized\n");
+
+	if (verify (&dummy_security_ops)) {
+		printk (KERN_ERR "%s could not verify "
+			"dummy_security_ops structure.\n", __FUNCTION__);
+		return -EIO;
+	}
 
 	security_ops = &dummy_security_ops;
 
diff -Nru a/sound/arm/sa11xx-uda1341.c b/sound/arm/sa11xx-uda1341.c
--- a/sound/arm/sa11xx-uda1341.c	Mon Dec 23 21:21:51 2002
+++ b/sound/arm/sa11xx-uda1341.c	Mon Dec 23 21:21:51 2002
@@ -15,7 +15,7 @@
  * 2002-04-04   Tomas Kasparek  better rates handling (allow non-standard rates)
  */
 
-/* $Id: sa11xx-uda1341.c,v 1.5 2002/10/21 18:28:19 perex Exp $ */
+/* $Id: sa11xx-uda1341.c,v 1.6 2002/12/04 18:52:05 perex Exp $ */
 
 #include <sound/driver.h>
 #include <linux/module.h>
diff -Nru a/sound/core/control.c b/sound/core/control.c
--- a/sound/core/control.c	Mon Dec 23 21:21:51 2002
+++ b/sound/core/control.c	Mon Dec 23 21:21:51 2002
@@ -37,7 +37,7 @@
 
 #define snd_kctl_ioctl(n) list_entry(n, snd_kctl_ioctl_t, list)
 
-static rwlock_t snd_ioctl_rwlock = RW_LOCK_UNLOCKED;
+static DECLARE_RWSEM(snd_ioctl_rwsem);
 static LIST_HEAD(snd_control_ioctls);
 
 static inline void dec_mod_count(struct module *module)
@@ -62,9 +62,14 @@
 		err = -ENODEV;
 		goto __error1;
 	}
+	err = snd_card_file_add(card, file);
+	if (err < 0) {
+		err = -ENODEV;
+		goto __error1;
+	}
 	if (!try_inc_mod_count(card->module)) {
 		err = -EFAULT;
-		goto __error1;
+		goto __error2;
 	}
 	ctl = snd_magic_kcalloc(snd_ctl_file_t, 0, GFP_KERNEL);
 	if (ctl == NULL) {
@@ -77,13 +82,15 @@
 	ctl->card = card;
 	ctl->pid = current->pid;
 	file->private_data = ctl;
-	write_lock_irqsave(&card->control_rwlock, flags);
+	write_lock_irqsave(&card->ctl_files_rwlock, flags);
 	list_add_tail(&ctl->list, &card->ctl_files);
-	write_unlock_irqrestore(&card->control_rwlock, flags);
+	write_unlock_irqrestore(&card->ctl_files_rwlock, flags);
 	return 0;
 
       __error:
       	dec_mod_count(card->module);
+      __error2:
+	snd_card_file_remove(card, file);
       __error1:
 #ifdef LINUX_2_2
       	MOD_DEC_USE_COUNT;
@@ -116,19 +123,20 @@
 	fasync_helper(-1, file, 0, &ctl->fasync);
 	file->private_data = NULL;
 	card = ctl->card;
-	write_lock_irqsave(&card->control_rwlock, flags);
+	write_lock_irqsave(&card->ctl_files_rwlock, flags);
 	list_del(&ctl->list);
-	write_unlock_irqrestore(&card->control_rwlock, flags);
-	write_lock(&card->control_owner_lock);
+	write_unlock_irqrestore(&card->ctl_files_rwlock, flags);
+	down_write(&card->controls_rwsem);
 	list_for_each(list, &card->controls) {
 		control = snd_kcontrol(list);
 		if (control->owner == ctl)
 			control->owner = NULL;
 	}
-	write_unlock(&card->control_owner_lock);
+	up_write(&card->controls_rwsem);
 	snd_ctl_empty_read_queue(ctl);
 	snd_magic_kfree(ctl);
 	dec_mod_count(card->module);
+	snd_card_file_remove(card, file);
 #ifdef LINUX_2_2
 	MOD_DEC_USE_COUNT;
 #endif
@@ -143,7 +151,7 @@
 	snd_kctl_event_t *ev;
 	
 	snd_runtime_check(card != NULL && id != NULL, return);
-	read_lock_irqsave(&card->control_rwlock, flags);
+	read_lock(&card->ctl_files_rwlock);
 #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
 	card->mixer_oss_change_count++;
 #endif
@@ -152,7 +160,7 @@
 		ctl = snd_ctl_file(flist);
 		if (!ctl->subscribed)
 			continue;
-		spin_lock(&ctl->read_lock);
+		spin_lock_irqsave(&ctl->read_lock, flags);
 		list_for_each(elist, &ctl->events) {
 			ev = snd_kctl_event(elist);
 			if (ev->id.numid == id->numid) {
@@ -171,9 +179,9 @@
 	_found:
 		wake_up(&ctl->change_sleep);
 		kill_fasync(&ctl->fasync, SIGIO, POLL_IN);
-		spin_unlock(&ctl->read_lock);
+		spin_unlock_irqrestore(&ctl->read_lock, flags);
 	}
-	read_unlock_irqrestore(&card->control_rwlock, flags);
+	read_unlock(&card->ctl_files_rwlock);
 }
 
 snd_kcontrol_t *snd_ctl_new(snd_kcontrol_t * control)
@@ -225,11 +233,11 @@
 	snd_assert(kcontrol->info != NULL, return -EINVAL);
 	snd_assert(!(kcontrol->access & SNDRV_CTL_ELEM_ACCESS_READ) || kcontrol->get != NULL, return -EINVAL);
 	snd_assert(!(kcontrol->access & SNDRV_CTL_ELEM_ACCESS_WRITE) || kcontrol->put != NULL, return -EINVAL);
-	write_lock(&card->control_rwlock);
+	down_write(&card->controls_rwsem);
 	list_add_tail(&kcontrol->list, &card->controls);
 	card->controls_count++;
 	kcontrol->id.numid = ++card->last_numid;
-	write_unlock(&card->control_rwlock);
+	up_write(&card->controls_rwsem);
 	snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_ADD, &kcontrol->id);
 	return 0;
 }
@@ -237,10 +245,10 @@
 int snd_ctl_remove(snd_card_t * card, snd_kcontrol_t * kcontrol)
 {
 	snd_runtime_check(card != NULL && kcontrol != NULL, return -EINVAL);
-	write_lock(&card->control_rwlock);
+	down_write(&card->controls_rwsem);
 	list_del(&kcontrol->list);
 	card->controls_count--;
-	write_unlock(&card->control_rwlock);
+	up_write(&card->controls_rwsem);
 	snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_REMOVE, &kcontrol->id);
 	snd_ctl_free_one(kcontrol);
 	return 0;
@@ -256,47 +264,46 @@
 	return snd_ctl_remove(card, kctl);
 }
 
+static snd_kcontrol_t *_ctl_find_id(snd_card_t * card, snd_ctl_elem_id_t *id); /* w/o lock */
+
 int snd_ctl_rename_id(snd_card_t * card, snd_ctl_elem_id_t *src_id, snd_ctl_elem_id_t *dst_id)
 {
 	snd_kcontrol_t *kctl;
 
-	kctl = snd_ctl_find_id(card, src_id);
-	if (kctl == NULL)
+	down_write(&card->controls_rwsem);
+	kctl = _ctl_find_id(card, src_id);
+	if (kctl == NULL) {
+		up_write(&card->controls_rwsem);
 		return -ENOENT;
-	write_lock(&card->control_rwlock);
+	}
 	kctl->id = *dst_id;
 	kctl->id.numid = ++card->last_numid;
-	write_unlock(&card->control_rwlock);
+	up_write(&card->controls_rwsem);
 	return 0;
 }
 
-snd_kcontrol_t *snd_ctl_find_numid(snd_card_t * card, unsigned int numid)
+static snd_kcontrol_t *_ctl_find_numid(snd_card_t * card, unsigned int numid)
 {
 	struct list_head *list;
 	snd_kcontrol_t *kctl;
 
 	snd_runtime_check(card != NULL && numid != 0, return NULL);
-	read_lock(&card->control_rwlock);
 	list_for_each(list, &card->controls) {
 		kctl = snd_kcontrol(list);
-		if (kctl->id.numid == numid) {
-			read_unlock(&card->control_rwlock);
+		if (kctl->id.numid == numid)
 			return kctl;
-		}
 	}
-	read_unlock(&card->control_rwlock);
 	return NULL;
 }
 
-snd_kcontrol_t *snd_ctl_find_id(snd_card_t * card, snd_ctl_elem_id_t *id)
+static snd_kcontrol_t *_ctl_find_id(snd_card_t * card, snd_ctl_elem_id_t *id)
 {
 	struct list_head *list;
 	snd_kcontrol_t *kctl;
 
 	snd_runtime_check(card != NULL && id != NULL, return NULL);
 	if (id->numid != 0)
-		return snd_ctl_find_numid(card, id->numid);
-	read_lock(&card->control_rwlock);
+		return _ctl_find_numid(card, id->numid);
 	list_for_each(list, &card->controls) {
 		kctl = snd_kcontrol(list);
 		if (kctl->id.iface != id->iface)
@@ -309,20 +316,38 @@
 			continue;
 		if (kctl->id.index != id->index)
 			continue;
-		read_unlock(&card->control_rwlock);
 		return kctl;
 	}
-	read_unlock(&card->control_rwlock);
 	return NULL;
 }
 
+/* exported: with read lock */
+snd_kcontrol_t *snd_ctl_find_id(snd_card_t * card, snd_ctl_elem_id_t *id)
+{
+	snd_kcontrol_t *kctl;
+	down_read(&card->controls_rwsem);
+	kctl = _ctl_find_id(card, id);
+	up_read(&card->controls_rwsem);
+	return kctl;
+}
+
+/* exported: with read lock */
+snd_kcontrol_t *snd_ctl_find_numid(snd_card_t * card, unsigned int numid)
+{
+	snd_kcontrol_t *kctl;
+	down_read(&card->controls_rwsem);
+	kctl = _ctl_find_numid(card, numid);
+	up_read(&card->controls_rwsem);
+	return kctl;
+}
+
 static int snd_ctl_card_info(snd_card_t * card, snd_ctl_file_t * ctl,
 			     unsigned int cmd, unsigned long arg)
 {
 	snd_ctl_card_info_t info;
 
 	memset(&info, 0, sizeof(info));
-	read_lock(&snd_ioctl_rwlock);
+	down_read(&snd_ioctl_rwsem);
 	info.card = card->number;
 	strncpy(info.id, card->id, sizeof(info.id) - 1);
 	strncpy(info.driver, card->driver, sizeof(info.driver) - 1);
@@ -330,7 +355,7 @@
 	strncpy(info.longname, card->longname, sizeof(info.longname) - 1);
 	strncpy(info.mixername, card->mixername, sizeof(info.mixername) - 1);
 	strncpy(info.components, card->components, sizeof(info.components) - 1);
-	read_unlock(&snd_ioctl_rwlock);
+	up_read(&snd_ioctl_rwsem);
 	if (copy_to_user((void *) arg, &info, sizeof(snd_ctl_card_info_t)))
 		return -EFAULT;
 	return 0;
@@ -356,7 +381,7 @@
 		dst = vmalloc(space * sizeof(snd_ctl_elem_id_t));
 		if (dst == NULL)
 			return -ENOMEM;
-		read_lock(&card->control_rwlock);
+		down_read(&card->controls_rwsem);
 		list.count = card->controls_count;
 		plist = card->controls.next;
 		while (offset-- > 0 && plist != &card->controls)
@@ -371,14 +396,14 @@
 			space--;
 			list.used++;
 		}
-		read_unlock(&card->control_rwlock);
+		up_read(&card->controls_rwsem);
 		if (list.used > 0 && copy_to_user(list.pids, dst, list.used * sizeof(snd_ctl_elem_id_t)))
 			return -EFAULT;
 		vfree(dst);
 	} else {
-		read_lock(&card->control_rwlock);
+		down_read(&card->controls_rwsem);
 		list.count = card->controls_count;
-		read_unlock(&card->control_rwlock);
+		up_read(&card->controls_rwsem);
 	}
 	if (copy_to_user(_list, &list, sizeof(list)))
 		return -EFAULT;
@@ -394,10 +419,10 @@
 	
 	if (copy_from_user(&info, _info, sizeof(info)))
 		return -EFAULT;
-	read_lock(&card->control_rwlock);
-	kctl = snd_ctl_find_id(card, &info.id);
+	down_read(&card->controls_rwsem);
+	kctl = _ctl_find_id(card, &info.id);
 	if (kctl == NULL) {
-		read_unlock(&card->control_rwlock);
+		up_read(&card->controls_rwsem);
 		return -ENOENT;
 	}
 #ifdef CONFIG_SND_DEBUG
@@ -417,7 +442,7 @@
 			info.owner = -1;
 		}
 	}
-	read_unlock(&card->control_rwlock);
+	up_read(&card->controls_rwsem);
 	if (result >= 0)
 		if (copy_to_user(_info, &info, sizeof(info)))
 			return -EFAULT;
@@ -435,8 +460,8 @@
 		return -ENOMEM;	
 	if (copy_from_user(control, _control, sizeof(*control)))
 		return -EFAULT;
-	read_lock(&card->control_rwlock);
-	kctl = snd_ctl_find_id(card, &control->id);
+	down_read(&card->controls_rwsem);
+	kctl = _ctl_find_id(card, &control->id);
 	if (kctl == NULL) {
 		result = -ENOENT;
 	} else {
@@ -452,7 +477,7 @@
 				result = -EPERM;
 		}
 	}
-	read_unlock(&card->control_rwlock);
+	up_read(&card->controls_rwsem);
 	if (result >= 0)
 		if (copy_to_user(_control, control, sizeof(*control)))
 			return -EFAULT;
@@ -472,8 +497,8 @@
 		return -ENOMEM;	
 	if (copy_from_user(control, _control, sizeof(*control)))
 		return -EFAULT;
-	read_lock(&card->control_rwlock);
-	kctl = snd_ctl_find_id(card, &control->id);
+	down_read(&card->controls_rwsem);
+	kctl = _ctl_find_id(card, &control->id);
 	if (kctl == NULL) {
 		result = -ENOENT;
 	} else {
@@ -481,7 +506,6 @@
 		if (control->indirect != indirect) {
 			result = -EACCES;
 		} else {
-			read_lock(&card->control_owner_lock);
 			if (!(kctl->access & SNDRV_CTL_ELEM_ACCESS_WRITE) ||
 			    kctl->put == NULL ||
 			    (kctl->owner != NULL && kctl->owner != file)) {
@@ -491,16 +515,15 @@
 				if (result >= 0)
 					control->id = kctl->id;
 			}
-			read_unlock(&card->control_owner_lock);
 			if (result > 0) {
-				read_unlock(&card->control_rwlock);
+				up_read(&card->controls_rwsem);
 				snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
 				result = 0;
 				goto __unlocked;
 			}
 		}
 	}
-	read_unlock(&card->control_rwlock);
+	up_read(&card->controls_rwsem);
       __unlocked:
 	if (result >= 0)
 		if (copy_to_user(_control, control, sizeof(*control)))
@@ -518,12 +541,11 @@
 	
 	if (copy_from_user(&id, _id, sizeof(id)))
 		return -EFAULT;
-	read_lock(&card->control_rwlock);
-	kctl = snd_ctl_find_id(card, &id);
+	down_write(&card->controls_rwsem);
+	kctl = _ctl_find_id(card, &id);
 	if (kctl == NULL) {
 		result = -ENOENT;
 	} else {
-		write_lock(&card->control_owner_lock);
 		if (kctl->owner != NULL)
 			result = -EBUSY;
 		else {
@@ -531,9 +553,8 @@
 			kctl->owner_pid = current->pid;
 			result = 0;
 		}
-		write_unlock(&card->control_owner_lock);
 	}
-	read_unlock(&card->control_rwlock);
+	up_write(&card->controls_rwsem);
 	return result;
 }
 
@@ -546,12 +567,11 @@
 	
 	if (copy_from_user(&id, _id, sizeof(id)))
 		return -EFAULT;
-	read_lock(&card->control_rwlock);
-	kctl = snd_ctl_find_id(card, &id);
+	down_write(&card->controls_rwsem);
+	kctl = _ctl_find_id(card, &id);
 	if (kctl == NULL) {
 		result = -ENOENT;
 	} else {
-		write_lock(&card->control_owner_lock);
 		if (kctl->owner == NULL)
 			result = -EINVAL;
 		else if (kctl->owner != file)
@@ -561,9 +581,8 @@
 			kctl->owner_pid = 0;
 			result = 0;
 		}
-		write_unlock(&card->control_owner_lock);
 	}
-	read_unlock(&card->control_rwlock);
+	up_write(&card->controls_rwsem);
 	return result;
 }
 
@@ -638,16 +657,16 @@
 		return put_user(SNDRV_CTL_POWER_D0, (int *)arg) ? -EFAULT : 0;
 #endif
 	}
-	read_lock(&snd_ioctl_rwlock);
+	down_read(&snd_ioctl_rwsem);
 	list_for_each(list, &snd_control_ioctls) {
 		p = list_entry(list, snd_kctl_ioctl_t, list);
 		err = p->fioctl(card, ctl, cmd, arg);
 		if (err != -ENOIOCTLCMD) {
-			read_unlock(&snd_ioctl_rwlock);
+			up_read(&snd_ioctl_rwsem);
 			return err;
 		}
 	}
-	read_unlock(&snd_ioctl_rwlock);
+	up_read(&snd_ioctl_rwsem);
 	snd_printd("unknown ioctl = 0x%x\n", cmd);
 	return -ENOTTY;
 }
@@ -732,9 +751,9 @@
 	if (pn == NULL)
 		return -ENOMEM;
 	pn->fioctl = fcn;
-	write_lock(&snd_ioctl_rwlock);
+	down_write(&snd_ioctl_rwsem);
 	list_add_tail(&pn->list, &snd_control_ioctls);
-	write_unlock(&snd_ioctl_rwlock);
+	up_write(&snd_ioctl_rwsem);
 	return 0;
 }
 
@@ -744,17 +763,17 @@
 	snd_kctl_ioctl_t *p;
 
 	snd_runtime_check(fcn != NULL, return -EINVAL);
-	write_lock(&snd_ioctl_rwlock);
+	down_write(&snd_ioctl_rwsem);
 	list_for_each(list, &snd_control_ioctls) {
 		p = list_entry(list, snd_kctl_ioctl_t, list);
 		if (p->fioctl == fcn) {
 			list_del(&p->list);
-			write_unlock(&snd_ioctl_rwlock);
+			up_write(&snd_ioctl_rwsem);
 			kfree(p);
 			return 0;
 		}
 	}
-	write_unlock(&snd_ioctl_rwlock);
+	up_write(&snd_ioctl_rwsem);
 	snd_BUG();
 	return -EINVAL;
 }
@@ -805,6 +824,21 @@
 	if ((err = snd_register_device(SNDRV_DEVICE_TYPE_CONTROL,
 					card, 0, &snd_ctl_reg, name)) < 0)
 		return err;
+	return 0;
+}
+
+int snd_ctl_disconnect(snd_card_t *card)
+{
+	struct list_head *flist;
+	snd_ctl_file_t *ctl;
+
+	down_read(&card->controls_rwsem);
+	list_for_each(flist, &card->ctl_files) {
+		ctl = snd_ctl_file(flist);
+		wake_up(&ctl->change_sleep);
+		kill_fasync(&ctl->fasync, SIGIO, POLL_ERR);
+	}
+	up_read(&card->controls_rwsem);
 	return 0;
 }
 
diff -Nru a/sound/core/device.c b/sound/core/device.c
--- a/sound/core/device.c	Mon Dec 23 21:21:57 2002
+++ b/sound/core/device.c	Mon Dec 23 21:21:57 2002
@@ -56,7 +56,8 @@
 			continue;
 		/* unlink */
 		list_del(&dev->list);
-		if (dev->state == SNDRV_DEV_REGISTERED && dev->ops->dev_unregister) {
+		if ((dev->state == SNDRV_DEV_REGISTERED || dev->state == SNDRV_DEV_DISCONNECTED) &&
+		    dev->ops->dev_unregister) {
 			if (dev->ops->dev_unregister(dev))
 				snd_printk(KERN_ERR "device unregister failure\n");
 		} else {
@@ -72,6 +73,28 @@
 	return -ENXIO;
 }
 
+int snd_device_disconnect(snd_card_t *card, void *device_data)
+{
+	struct list_head *list;
+	snd_device_t *dev;
+	
+	snd_assert(card != NULL, return -ENXIO);
+	snd_assert(device_data != NULL, return -ENXIO);
+	list_for_each(list, &card->devices) {
+		dev = snd_device(list);
+		if (dev->device_data != device_data)
+			continue;
+		if (dev->state == SNDRV_DEV_REGISTERED && dev->ops->dev_disconnect) {
+			if (dev->ops->dev_disconnect(dev))
+				snd_printk(KERN_ERR "device disconnect failure\n");
+			dev->state = SNDRV_DEV_DISCONNECTED;
+		}
+		return 0;
+	}
+	snd_printd("device disconnect %p (from %p), not found\n", device_data, __builtin_return_address(0));
+	return -ENXIO;
+}
+
 int snd_device_register(snd_card_t *card, void *device_data)
 {
 	struct list_head *list;
@@ -111,6 +134,21 @@
 		}
 	}
 	return 0;
+}
+
+int snd_device_disconnect_all(snd_card_t *card)
+{
+	snd_device_t *dev;
+	struct list_head *list;
+	int err = 0;
+
+	snd_assert(card != NULL, return -ENXIO);
+	list_for_each(list, &card->devices) {
+		dev = snd_device(list);
+		if (snd_device_disconnect(card, dev->device_data) < 0)
+			err = -ENXIO;
+	}
+	return err;
 }
 
 int snd_device_free_all(snd_card_t *card, snd_device_cmd_t cmd)
diff -Nru a/sound/core/info.c b/sound/core/info.c
--- a/sound/core/info.c	Mon Dec 23 21:22:00 2002
+++ b/sound/core/info.c	Mon Dec 23 21:22:00 2002
@@ -933,11 +933,7 @@
 	p = create_proc_entry(entry->name, entry->mode, snd_proc_dev);
 	if (p) {
 		snd_info_device_entry_prepare(p, entry);
-#ifndef LINUX_2_2
-		/* we should not set this - at least on 2.4.14 or later it causes
-		   problems! */
-		/* p->proc_fops = &snd_fops; */
-#else
+#ifdef LINUX_2_2
 		p->ops = &snd_info_device_inode_operations;
 #endif
 	} else {
@@ -1028,7 +1024,7 @@
 	snd_iprintf(buffer,
 		    "Advanced Linux Sound Architecture Driver Version " CONFIG_SND_VERSION CONFIG_SND_DATE ".\n"
 		    "Compiled on " __DATE__ " for kernel %s"
-#ifdef __SMP__
+#ifdef CONFIG_SMP
 		    " (SMP)"
 #endif
 #ifdef MODVERSIONS
diff -Nru a/sound/core/init.c b/sound/core/init.c
--- a/sound/core/init.c	Mon Dec 23 21:21:51 2002
+++ b/sound/core/init.c	Mon Dec 23 21:21:51 2002
@@ -21,15 +21,23 @@
 
 #include <sound/driver.h>
 #include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/file.h>
 #include <linux/slab.h>
 #include <linux/time.h>
 #include <linux/ctype.h>
+#include <linux/workqueue.h>
 #include <sound/core.h>
 #include <sound/control.h>
 #include <sound/info.h>
 
+struct snd_shutdown_f_ops {
+	struct file_operations f_ops;
+	struct snd_shutdown_f_ops *next;
+};
+
 int snd_cards_count = 0;
-static unsigned int snd_cards_lock = 0;	/* locked for registering/using */
+unsigned int snd_cards_lock = 0;	/* locked for registering/using */
 snd_card_t *snd_cards[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = NULL};
 rwlock_t snd_card_rwlock = RW_LOCK_UNLOCKED;
 
@@ -42,6 +50,16 @@
 	snd_iprintf(buffer, "%s\n", entry->card->id);
 }
 
+/**
+ *  snd_card_new: create and initialize a soundcard structure
+ *  @idx: card index (address) [0 ... (SNDRV_CARDS-1)]
+ *  @xid: card identification (ASCII string)
+ *  @module: top level module for locking
+ *  @extra_size: allocate this extra size after the main soundcard structure
+ *
+ *  Returns kmallocated snd_card_t structure. Creates the ALSA control interface
+ *  (which is blocked until #snd_card_register function is called).
+ */
 snd_card_t *snd_card_new(int idx, const char *xid,
 			 struct module *module, int extra_size)
 {
@@ -81,10 +99,12 @@
 	card->number = idx;
 	card->module = module;
 	INIT_LIST_HEAD(&card->devices);
-	rwlock_init(&card->control_rwlock);
-	rwlock_init(&card->control_owner_lock);
+	init_rwsem(&card->controls_rwsem);
+	rwlock_init(&card->ctl_files_rwlock);
 	INIT_LIST_HEAD(&card->controls);
 	INIT_LIST_HEAD(&card->ctl_files);
+	spin_lock_init(&card->files_lock);
+	init_waitqueue_head(&card->shutdown_sleep);
 #ifdef CONFIG_PM
 	init_MUTEX(&card->power_lock);
 	init_waitqueue_head(&card->power_sleep);
@@ -110,17 +130,129 @@
       	return NULL;
 }
 
+static unsigned int snd_disconnect_poll(struct file * file, poll_table * wait)
+{
+	return POLLERR | POLLNVAL;
+}
+
+/**
+ *  snd_card_disconnect: disconnect all APIs from the file-operations (user space)
+ *  @card: soundcard structure
+ *
+ *  Returns - zero, otherwise a negative error code.
+ *
+ *  Note: The current implementation replaces all active file->f_op with special
+ *        dummy file operations (they do nothing except release).
+ */
+int snd_card_disconnect(snd_card_t * card)
+{
+	struct snd_monitor_file *mfile;
+	struct file *file;
+	struct snd_shutdown_f_ops *s_f_ops;
+	struct file_operations *f_ops, *old_f_ops;
+	int err;
+
+	spin_lock(&card->files_lock);
+	if (card->shutdown) {
+		spin_unlock(&card->files_lock);
+		return 0;
+	}
+	card->shutdown = 1;
+	spin_unlock(&card->files_lock);
+
+	/* phase 1: disable fops (user space) operations for ALSA API */
+	write_lock(&snd_card_rwlock);
+	snd_cards[card->number] = NULL;
+	write_unlock(&snd_card_rwlock);
+	
+	/* phase 2: replace file->f_op with special dummy operations */
+	
+	spin_lock(&card->files_lock);
+	mfile = card->files;
+	while (mfile) {
+		file = mfile->file;
+
+		/* it's critical part, use endless loop */
+		/* we have no room to fail */
+		s_f_ops = kmalloc(sizeof(struct snd_shutdown_f_ops), GFP_ATOMIC);
+		if (s_f_ops == NULL)
+			panic("Atomic allocation failed for snd_shutdown_f_ops!");
+
+		f_ops = &s_f_ops->f_ops;
+
+		memset(f_ops, 0, sizeof(*f_ops));
+#ifndef LINUX_2_2
+		f_ops->owner = file->f_op->owner;
+#endif
+		f_ops->release = file->f_op->release;
+		f_ops->poll = snd_disconnect_poll;
+
+		s_f_ops->next = card->s_f_ops;
+		card->s_f_ops = s_f_ops;
+		
+		f_ops = fops_get(f_ops);
+
+		old_f_ops = file->f_op;
+		file->f_op = f_ops;	/* must be atomic */
+		fops_put(old_f_ops);
+		
+		mfile = mfile->next;
+	}
+	spin_unlock(&card->files_lock);	
+
+	/* phase 3: notify all connected devices about disconnection */
+	/* at this point, they cannot respond to any calls except release() */
+
+	snd_ctl_disconnect(card);
+
+#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
+	if (snd_mixer_oss_notify_callback)
+		snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_DISCONNECT);
+#endif
+
+	/* notify all devices that we are disconnected */
+	err = snd_device_disconnect_all(card);
+	if (err < 0)
+		snd_printk(KERN_ERR "not all devices for card %i can be disconnected\n", card->number);
+
+	return 0;	
+}
+
+/**
+ *  snd_card_free: frees given soundcard structure
+ *  @card: soundcard structure
+ *
+ *  This function releases the soundcard structure and the all assigned
+ *  devices automatically.  That is, you don't have to release the devices
+ *  by yourself.
+ *
+ *  Returns - zero. Frees all associated devices and frees the control
+ *  interface associated to given soundcard.
+ */
 int snd_card_free(snd_card_t * card)
 {
+	wait_queue_t wait;
+	struct snd_shutdown_f_ops *s_f_ops;
+
 	if (card == NULL)
 		return -EINVAL;
 	write_lock(&snd_card_rwlock);
 	snd_cards[card->number] = NULL;
 	snd_cards_count--;
 	write_unlock(&snd_card_rwlock);
+
+	/* wait, until all devices are ready for the free operation */
+	init_waitqueue_entry(&wait, current);
+	add_wait_queue(&card->shutdown_sleep, &wait);
+	while (card->files) {
+		set_current_state(TASK_UNINTERRUPTIBLE);
+		schedule_timeout(30 * HZ);
+	}
+	remove_wait_queue(&card->shutdown_sleep, &wait);
+
 #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
 	if (snd_mixer_oss_notify_callback)
-		snd_mixer_oss_notify_callback(card, 1);
+		snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_FREE);
 #endif
 	if (snd_device_free_all(card, SNDRV_DEV_CMD_PRE) < 0) {
 		snd_printk(KERN_ERR "unable to free all devices (pre)\n");
@@ -145,6 +277,11 @@
 		snd_printk(KERN_WARNING "unable to free card info\n");
 		/* Not fatal error */
 	}
+	while (card->s_f_ops) {
+		s_f_ops = card->s_f_ops;
+		card->s_f_ops = s_f_ops->next;
+		kfree(s_f_ops);
+	}
 	write_lock(&snd_card_rwlock);
 	snd_cards_lock &= ~(1 << card->number);
 	write_unlock(&snd_card_rwlock);
@@ -152,7 +289,56 @@
 	return 0;
 }
 
-static void choose_default_id(snd_card_t *card)
+static void snd_card_free_thread(void * __card)
+{
+	snd_card_t *card = __card;
+	struct module * module;
+
+	if (!try_inc_mod_count(module = card->module)) {
+		snd_printk(KERN_ERR "unable to lock toplevel module for card %i in free thread\n", card->number);
+		module = NULL;
+	}
+
+	wait_event(card->shutdown_sleep, card->files == NULL);
+
+	snd_card_free(card);
+
+	if (module)
+		__MOD_DEC_USE_COUNT(module);
+}
+
+/**
+ *  snd_card_free_in_thread: call snd_card_free() in thread
+ *  @card: soundcard structure
+ *
+ *  This function schedules the call of #snd_card_free function in a
+ *  work queue.  When all devices are released (non-busy), the work
+ *  is woken up and calls #snd_card_free.
+ *
+ *  When a card can be disconnected at any time by hotplug service,
+ *  this function should be used in disconnect (or detach) callback
+ *  instead of calling #snd_card_free directly.
+ *  
+ *  Returns - zero otherwise a negative error code if the start of thread failed.
+ */
+int snd_card_free_in_thread(snd_card_t * card)
+{
+	DECLARE_WORK(works, snd_card_free_thread, card);
+
+	if (card->files == NULL) {
+		snd_card_free(card);
+		return 0;
+	}
+	if (schedule_work(&works))
+		return 0;
+
+	snd_printk(KERN_ERR "kernel_thread failed in snd_card_free_in_thread for card %i\n", card->number);
+	/* try to free the structure immediately */
+	snd_card_free(card);
+	return -EFAULT;
+}
+
+static void choose_default_id(snd_card_t * card)
 {
 	int i, len, idx_flag = 0, loops = 8;
 	char *id, *spos;
@@ -204,10 +390,19 @@
 			idx_flag++;
 		}
 	}
-		
-	strcpy(card->id, id);
 }
 
+/**
+ *  snd_card_register: register the soundcard
+ *  @card: soundcard structure
+ *
+ *  This function registers all the devices assigned to the soundcard.
+ *  Until calling this, the ALSA control interface is blocked from the
+ *  external accesses.  Thus, you should call this function at the end
+ *  of the initialization of the card.
+ *
+ *  Returns - zero otherwise a negative error code if the registrain failed.
+ */
 int snd_card_register(snd_card_t * card)
 {
 	int err;
@@ -246,7 +441,7 @@
       __skip_info:
 #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
 	if (snd_mixer_oss_notify_callback)
-		snd_mixer_oss_notify_callback(card, 0);
+		snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_REGISTER);
 #endif
 	return 0;
 }
@@ -312,7 +507,6 @@
 		return -ENOMEM;
 	}
 	snd_card_info_entry = entry;
-	
 	return 0;
 }
 
@@ -323,6 +517,17 @@
 	return 0;
 }
 
+/**
+ *  snd_component_add: add a component string
+ *  @card: soundcard structure
+ *  @component: the component id string
+ *
+ *  This function adds the component id string to the supported list.
+ *  The component can be referred from the alsa-lib.
+ *
+ *  Returns - zero otherwise a negative error code.
+ */
+  
 int snd_component_add(snd_card_t *card, const char *component)
 {
 	char *ptr;
@@ -343,8 +548,87 @@
 	return 0;
 }
 
+/**
+ *  snd_card_file_add: add the file to the file list of the card
+ *  @card: soundcard structure
+ *  @file: file pointer
+ *
+ *  This function adds the file to the file linked-list of the card.
+ *  This linked-list is used to keep tracking the connection state,
+ *  and to avoid the release of busy resources by hotplug.
+ *
+ *  Returns zero or a negative error code.
+ */
+int snd_card_file_add(snd_card_t *card, struct file *file)
+{
+	struct snd_monitor_file *mfile;
+
+	mfile = kmalloc(sizeof(*mfile), GFP_KERNEL);
+	if (mfile == NULL)
+		return -ENOMEM;
+	mfile->file = file;
+	mfile->next = NULL;
+	spin_lock(&card->files_lock);
+	if (card->shutdown) {
+		spin_unlock(&card->files_lock);
+		kfree(mfile);
+		return -ENODEV;
+	}
+	mfile->next = card->files;
+	card->files = mfile;
+	spin_unlock(&card->files_lock);
+	return 0;
+}
+
+/**
+ *  snd_card_file_remove: remove the file from the file list
+ *  @card: soundcard structure
+ *  @file: file pointer
+ *
+ *  This function removes the file formerly added to the card via
+ *  #snd_card_file_add function.
+ *  If all files are removed and the release of the card is
+ *  scheduled, it will wake up the the thread to call #snd_card_free
+ *  (see #snd_card_free_in_thread function).
+ *
+ *  Returns zero or a negative error code.
+ */
+int snd_card_file_remove(snd_card_t *card, struct file *file)
+{
+	struct snd_monitor_file *mfile, *pfile = NULL;
+
+	spin_lock(&card->files_lock);
+	mfile = card->files;
+	while (mfile) {
+		if (mfile->file == file) {
+			if (pfile)
+				pfile->next = mfile->next;
+			else
+				card->files = mfile->next;
+			break;
+		}
+		pfile = mfile;
+		mfile = mfile->next;
+	}
+	spin_unlock(&card->files_lock);
+	if (card->files == NULL)
+		wake_up(&card->shutdown_sleep);
+	if (mfile) {
+		kfree(mfile);
+	} else {
+		snd_printk(KERN_ERR "ALSA card file remove problem (%p)\n", file);
+		return -ENOENT;
+	}
+	return 0;
+}
+
 #ifdef CONFIG_PM
-/* the power lock must be active before call */
+/**
+ *  snd_power_wait: wait until the power-state is changed.
+ *  @card: soundcard structure
+ *
+ *  Note: the power lock must be active before call.
+ */
 void snd_power_wait(snd_card_t *card)
 {
 	wait_queue_t wait;
@@ -352,6 +636,7 @@
 	init_waitqueue_entry(&wait, current);
 	add_wait_queue(&card->power_sleep, &wait);
 	snd_power_unlock(card);
+	set_current_state(TASK_UNINTERRUPTIBLE);
 	schedule_timeout(30 * HZ);
 	remove_wait_queue(&card->power_sleep, &wait);
 	snd_power_lock(card);
diff -Nru a/sound/core/ioctl32/ioctl32.c b/sound/core/ioctl32/ioctl32.c
--- a/sound/core/ioctl32/ioctl32.c	Mon Dec 23 21:21:51 2002
+++ b/sound/core/ioctl32/ioctl32.c	Mon Dec 23 21:21:51 2002
@@ -249,17 +249,14 @@
 
 	ctl = snd_magic_cast(snd_ctl_file_t, file->private_data, return -ENXIO);
 
-	read_lock(&ctl->card->control_rwlock);
 	kctl = snd_ctl_find_id(ctl->card, id);
-	if (! kctl) {
-		read_unlock(&ctl->card->control_rwlock);
+	if (! kctl)
 		return -ENXIO;
-	}
+
 	info.id = *id;
 	err = kctl->info(kctl, &info);
 	if (err >= 0)
 		err = info.type;
-	read_unlock(&ctl->card->control_rwlock);
 	return err;
 }
 
diff -Nru a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c
--- a/sound/core/oss/mixer_oss.c	Mon Dec 23 21:21:58 2002
+++ b/sound/core/oss/mixer_oss.c	Mon Dec 23 21:21:58 2002
@@ -45,14 +45,20 @@
 	int cardnum = SNDRV_MINOR_OSS_CARD(minor(inode->i_rdev));
 	snd_card_t *card;
 	snd_mixer_oss_file_t *fmixer;
+	int err;
 
 	if ((card = snd_cards[cardnum]) == NULL)
 		return -ENODEV;
 	if (card->mixer_oss == NULL)
 		return -ENODEV;
+	err = snd_card_file_add(card, file);
+	if (err < 0)
+		return err;
 	fmixer = (snd_mixer_oss_file_t *)snd_kcalloc(sizeof(*fmixer), GFP_KERNEL);
-	if (fmixer == NULL)
+	if (fmixer == NULL) {
+		snd_card_file_remove(card, file);
 		return -ENOMEM;
+	}
 	fmixer->card = card;
 	fmixer->mixer = card->mixer_oss;
 	file->private_data = fmixer;
@@ -64,6 +70,7 @@
 #ifdef LINUX_2_2
 		MOD_DEC_USE_COUNT;
 #endif
+		snd_card_file_remove(card, file);
 		return -EFAULT;
 	}
 	return 0;
@@ -79,6 +86,7 @@
 #ifdef LINUX_2_2
 		MOD_DEC_USE_COUNT;
 #endif
+		snd_card_file_remove(fmixer->card, file);
 		kfree(fmixer);
 	}
 	return 0;
@@ -554,7 +562,7 @@
 	struct slot *slot = (struct slot *)pslot->private_data;
 	
 	*left = *right = 100;
-	read_lock(&card->control_rwlock);
+	down_read(&card->controls_rwsem);
 	if (slot->present & SNDRV_MIXER_OSS_PRESENT_PVOLUME) {
 		snd_mixer_oss_get_volume1_vol(fmixer, pslot, slot->kcontrol[SNDRV_MIXER_OSS_ITEM_PVOLUME], left, right);
 	} else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GVOLUME) {
@@ -571,7 +579,7 @@
 	} else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GROUTE) {
 		snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->kcontrol[SNDRV_MIXER_OSS_ITEM_GROUTE], left, right, 1);
 	}
-	read_unlock(&card->control_rwlock);
+	up_read(&card->controls_rwsem);
 	return 0;
 }
 
@@ -647,7 +655,7 @@
 	snd_card_t *card = fmixer->card;
 	struct slot *slot = (struct slot *)pslot->private_data;
 	
-	read_lock(&card->control_rwlock);
+	down_read(&card->controls_rwsem);
 	if (slot->present & SNDRV_MIXER_OSS_PRESENT_PVOLUME) {
 		snd_mixer_oss_put_volume1_vol(fmixer, pslot, slot->kcontrol[SNDRV_MIXER_OSS_ITEM_PVOLUME], left, right);
 		if (slot->present & SNDRV_MIXER_OSS_PRESENT_CVOLUME)
@@ -677,7 +685,7 @@
 			snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->kcontrol[SNDRV_MIXER_OSS_ITEM_GROUTE], left, right, 1);
 		}
 	}
-	read_unlock(&card->control_rwlock);
+	up_read(&card->controls_rwsem);
 	return 0;
 }
 
@@ -690,9 +698,9 @@
 	int left, right;
 	
 	left = right = 1;
-	read_lock(&card->control_rwlock);
+	down_read(&card->controls_rwsem);
 	snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->kcontrol[SNDRV_MIXER_OSS_ITEM_CSWITCH], &left, &right, 0);
-	read_unlock(&card->control_rwlock);
+	up_read(&card->controls_rwsem);
 	*active = (left || right) ? 1 : 0;
 	return 0;
 }
@@ -706,9 +714,9 @@
 	int left, right;
 	
 	left = right = 1;
-	read_lock(&card->control_rwlock);
+	down_read(&card->controls_rwsem);
 	snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->kcontrol[SNDRV_MIXER_OSS_ITEM_CROUTE], &left, &right, 1);
-	read_unlock(&card->control_rwlock);
+	up_read(&card->controls_rwsem);
 	*active = (left || right) ? 1 : 0;
 	return 0;
 }
@@ -720,9 +728,9 @@
 	snd_card_t *card = fmixer->card;
 	struct slot *slot = (struct slot *)pslot->private_data;
 	
-	read_lock(&card->control_rwlock);
+	down_read(&card->controls_rwsem);
 	snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->kcontrol[SNDRV_MIXER_OSS_ITEM_CSWITCH], active, active, 0);
-	read_unlock(&card->control_rwlock);
+	up_read(&card->controls_rwsem);
 	return 0;
 }
 
@@ -733,9 +741,9 @@
 	snd_card_t *card = fmixer->card;
 	struct slot *slot = (struct slot *)pslot->private_data;
 	
-	read_lock(&card->control_rwlock);
+	down_read(&card->controls_rwsem);
 	snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->kcontrol[SNDRV_MIXER_OSS_ITEM_CROUTE], active, active, 1);
-	read_unlock(&card->control_rwlock);
+	up_read(&card->controls_rwsem);
 	return 0;
 }
 
@@ -756,16 +764,15 @@
 		err = -ENOMEM;
 		goto __unlock;
 	}
-	read_lock(&card->control_rwlock);
+	down_read(&card->controls_rwsem);
 	kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
 	snd_runtime_check(kctl != NULL, err = -ENOENT; goto __unlock);
 	snd_runtime_check(!(err = kctl->info(kctl, uinfo)), goto __unlock);
 	snd_runtime_check(!(err = kctl->get(kctl, uctl)), goto __unlock);
-	read_unlock(&card->control_rwlock);
 	for (idx = 0; idx < 32; idx++) {
 		if (!(mixer->mask_recsrc & (1 << idx)))
 			continue;
-		pslot = &fmixer->mixer->slots[idx];
+		pslot = &mixer->slots[idx];
 		slot = (struct slot *)pslot->private_data;
 		if (slot->signature != SNDRV_MIXER_OSS_SIGNATURE)
 			continue;
@@ -777,10 +784,8 @@
 		}
 	}
 	err = 0;
-	goto __unalloc;
       __unlock:
-      	read_unlock(&card->control_rwlock);
-      __unalloc:
+     	up_read(&card->controls_rwsem);
       	if (uctl)
       		kfree(uctl);
       	if (uinfo)
@@ -805,14 +810,14 @@
 		err = -ENOMEM;
 		goto __unlock;
 	}
-	read_lock(&card->control_rwlock);
+	down_read(&card->controls_rwsem);
 	kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
 	snd_runtime_check(kctl != NULL, err = -ENOENT; goto __unlock);
 	snd_runtime_check(!(err = kctl->info(kctl, uinfo)), goto __unlock);
 	for (idx = 0; idx < 32; idx++) {
 		if (!(mixer->mask_recsrc & (1 << idx)))
 			continue;
-		pslot = &fmixer->mixer->slots[idx];
+		pslot = &mixer->slots[idx];
 		slot = (struct slot *)pslot->private_data;
 		if (slot->signature != SNDRV_MIXER_OSS_SIGNATURE)
 			continue;
@@ -830,7 +835,7 @@
 		snd_ctl_notify(fmixer->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
 	err = 0;
       __unlock:
-	read_unlock(&card->control_rwlock);
+	up_read(&card->controls_rwsem);
 	if (uctl)
 		kfree(uctl);
 	if (uinfo)
@@ -1200,10 +1205,11 @@
 	return 0;
 }
 
-static int snd_mixer_oss_notify_handler(snd_card_t * card, int free_flag)
+static int snd_mixer_oss_notify_handler(snd_card_t * card, int cmd)
 {
-	if (!free_flag) {
-		snd_mixer_oss_t *mixer;
+	snd_mixer_oss_t *mixer;
+
+	if (cmd == SND_MIXER_OSS_NOTIFY_REGISTER) {
 		char name[128];
 		int idx, err;
 
@@ -1220,6 +1226,7 @@
 			snd_magic_kfree(mixer);
 			return err;
 		}
+		mixer->oss_dev_alloc = 1;
 		mixer->card = card;
 		if (*card->mixername) {
 			strncpy(mixer->name, card->mixername, sizeof(mixer->name) - 1);
@@ -1236,14 +1243,21 @@
 		card->mixer_oss = mixer;
 		snd_mixer_oss_build(mixer);
 		snd_mixer_oss_proc_init(mixer);
-	} else {
-		snd_mixer_oss_t *mixer = card->mixer_oss;
+	} else if (cmd == SND_MIXER_OSS_NOTIFY_DISCONNECT) {
+		mixer = card->mixer_oss;
+		if (mixer == NULL || !mixer->oss_dev_alloc)
+			return 0;
+		snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER, mixer->card, 0);
+		mixer->oss_dev_alloc = 0;
+	} else {		/* free */
+		mixer = card->mixer_oss;
 		if (mixer == NULL)
 			return 0;
 #ifdef SNDRV_OSS_INFO_DEV_MIXERS
 		snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_MIXERS, mixer->card->number);
 #endif
-		snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER, mixer->card, 0);
+		if (mixer->oss_dev_alloc)
+			snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER, mixer->card, 0);
 		snd_mixer_oss_proc_done(mixer);
 		return snd_mixer_oss_free1(mixer);
 	}
@@ -1257,7 +1271,7 @@
 	snd_mixer_oss_notify_callback = snd_mixer_oss_notify_handler;
 	for (idx = 0; idx < SNDRV_CARDS; idx++) {
 		if (snd_cards[idx])
-			snd_mixer_oss_notify_handler(snd_cards[idx], 0);
+			snd_mixer_oss_notify_handler(snd_cards[idx], SND_MIXER_OSS_NOTIFY_REGISTER);
 	}
 	return 0;
 }
@@ -1269,7 +1283,7 @@
 	snd_mixer_oss_notify_callback = NULL;
 	for (idx = 0; idx < SNDRV_CARDS; idx++) {
 		if (snd_cards[idx])
-			snd_mixer_oss_notify_handler(snd_cards[idx], 1);
+			snd_mixer_oss_notify_handler(snd_cards[idx], SND_MIXER_OSS_NOTIFY_FREE);
 	}
 }
 
diff -Nru a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
--- a/sound/core/oss/pcm_oss.c	Mon Dec 23 21:22:00 2002
+++ b/sound/core/oss/pcm_oss.c	Mon Dec 23 21:22:00 2002
@@ -1554,13 +1554,16 @@
 		err = -ENODEV;
 		goto __error1;
 	}
+	err = snd_card_file_add(pcm->card, file);
+	if (err < 0)
+		goto __error1;
 	if (!try_inc_mod_count(pcm->card->module)) {
 		err = -EFAULT;
-		goto __error1;
+		goto __error2;
 	}
 	if (snd_task_name(current, task_name, sizeof(task_name)) < 0) {
 		err = -EFAULT;
-		goto __error1;
+		goto __error;
 	}
 	if (file->f_mode & FMODE_WRITE)
 		psetup = snd_pcm_oss_look_for_setup(pcm, SNDRV_PCM_STREAM_PLAYBACK, task_name);
@@ -1584,13 +1587,12 @@
 
 	init_waitqueue_entry(&wait, current);
 	add_wait_queue(&pcm->open_wait, &wait);
+	down(&pcm->open_mutex);
 	while (1) {
-		down(&pcm->open_mutex);
 		err = snd_pcm_oss_open_file(file, pcm, &pcm_oss_file,
 					    minor, psetup, csetup);
 		if (err >= 0)
 			break;
-		up(&pcm->open_mutex);
 		if (err == -EAGAIN) {
 			if (nonblock) {
 				err = -EBUSY;
@@ -1599,7 +1601,9 @@
 		} else
 			break;
 		set_current_state(TASK_INTERRUPTIBLE);
+		up(&pcm->open_mutex);
 		schedule();
+		down(&pcm->open_mutex);
 		if (signal_pending(current)) {
 			err = -ERESTARTSYS;
 			break;
@@ -1607,13 +1611,15 @@
 	}
 	set_current_state(TASK_RUNNING);
 	remove_wait_queue(&pcm->open_wait, &wait);
+	up(&pcm->open_mutex);
 	if (err < 0)
 		goto __error;
-	up(&pcm->open_mutex);
 	return err;
 
       __error:
       	dec_mod_count(pcm->card->module);
+      __error2:
+      	snd_card_file_remove(pcm->card, file);
       __error1:
 #ifdef LINUX_2_2
 	MOD_DEC_USE_COUNT;
@@ -1639,6 +1645,7 @@
 	up(&pcm->open_mutex);
 	wake_up(&pcm->open_wait);
 	dec_mod_count(pcm->card->module);
+	snd_card_file_remove(pcm->card, file);
 #ifdef LINUX_2_2
 	MOD_DEC_USE_COUNT;
 #endif
@@ -2108,7 +2115,7 @@
 	.f_ops =	&snd_pcm_oss_f_reg,
 };
 
-static void register_oss_dsp(unsigned short native_minor, snd_pcm_t *pcm, int index)
+static void register_oss_dsp(snd_pcm_t *pcm, int index)
 {
 	char name[128];
 	sprintf(name, "dsp%i%i", pcm->card->number, pcm->device);
@@ -2119,14 +2126,13 @@
 	}
 }
 
-static int snd_pcm_oss_register_minor(unsigned short native_minor,
-				      snd_pcm_t * pcm)
+static int snd_pcm_oss_register_minor(snd_pcm_t * pcm)
 {
 	pcm->oss.reg = 0;
 	if (dsp_map[pcm->card->number] == pcm->device) {
 		char name[128];
 		int duplex;
-		register_oss_dsp(native_minor, pcm, 0);
+		register_oss_dsp(pcm, 0);
 		duplex = (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream_count > 0 && 
 			      pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream_count && 
 			      !(pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX));
@@ -2137,10 +2143,12 @@
 				      name);
 #endif
 		pcm->oss.reg++;
+		pcm->oss.reg_mask |= 1;
 	}
 	if (adsp_map[pcm->card->number] == pcm->device) {
-		register_oss_dsp(native_minor, pcm, 1);
+		register_oss_dsp(pcm, 1);
 		pcm->oss.reg++;
+		pcm->oss.reg_mask |= 2;
 	}
 
 	if (pcm->oss.reg)
@@ -2149,20 +2157,32 @@
 	return 0;
 }
 
-static int snd_pcm_oss_unregister_minor(unsigned short native_minor,
-				        snd_pcm_t * pcm)
+static int snd_pcm_oss_disconnect_minor(snd_pcm_t * pcm)
 {
 	if (pcm->oss.reg) {
-		if (dsp_map[pcm->card->number] == pcm->device) {
+		if (pcm->oss.reg_mask & 1) {
+			pcm->oss.reg_mask &= ~1;
 			snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_PCM,
 						  pcm->card, 0);
+		}
+		if (pcm->oss.reg_mask & 2) {
+			pcm->oss.reg_mask &= ~2;
+			snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_PCM,
+						  pcm->card, 1);
+		}
+	}
+	return 0;
+}
+
+static int snd_pcm_oss_unregister_minor(snd_pcm_t * pcm)
+{
+	snd_pcm_oss_disconnect_minor(pcm);
+	if (pcm->oss.reg) {
+		if (dsp_map[pcm->card->number] == pcm->device) {
 #ifdef SNDRV_OSS_INFO_DEV_AUDIO
 			snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_AUDIO, pcm->card->number);
 #endif
 		}
-		if (adsp_map[pcm->card->number] == pcm->device)
-			snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_PCM,
-						  pcm->card, 1);
 		pcm->oss.reg = 0;
 		snd_pcm_oss_proc_done(pcm);
 	}
@@ -2172,6 +2192,7 @@
 static snd_pcm_notify_t snd_pcm_oss_notify =
 {
 	.n_register =	snd_pcm_oss_register_minor,
+	.n_disconnect = snd_pcm_oss_disconnect_minor,
 	.n_unregister =	snd_pcm_oss_unregister_minor,
 };
 
@@ -2180,8 +2201,6 @@
 	int i;
 	int err;
 
-	if ((err = snd_pcm_notify(&snd_pcm_oss_notify, 0)) < 0)
-		return err;
 	/* check device map table */
 	for (i = 0; i < SNDRV_CARDS; i++) {
 		if (dsp_map[i] < 0 || dsp_map[i] >= SNDRV_PCM_DEVICES) {
@@ -2193,6 +2212,8 @@
 			adsp_map[i] = 1;
 		}
 	}
+	if ((err = snd_pcm_notify(&snd_pcm_oss_notify, 0)) < 0)
+		return err;
 	return 0;
 }
 
diff -Nru a/sound/core/pcm.c b/sound/core/pcm.c
--- a/sound/core/pcm.c	Mon Dec 23 21:22:02 2002
+++ b/sound/core/pcm.c	Mon Dec 23 21:22:02 2002
@@ -37,9 +37,10 @@
 static LIST_HEAD(snd_pcm_notify_list);
 static DECLARE_MUTEX(register_mutex);
 
-int snd_pcm_free(snd_pcm_t *pcm);
+static int snd_pcm_free(snd_pcm_t *pcm);
 static int snd_pcm_dev_free(snd_device_t *device);
 static int snd_pcm_dev_register(snd_device_t *device);
+static int snd_pcm_dev_disconnect(snd_device_t *device);
 static int snd_pcm_dev_unregister(snd_device_t *device);
 
 void snd_pcm_lock(int xup)
@@ -590,7 +591,7 @@
 }				
 
 int snd_pcm_new(snd_card_t * card, char *id, int device,
-	        int playback_count, int capture_count,
+		int playback_count, int capture_count,
 	        snd_pcm_t ** rpcm)
 {
 	snd_pcm_t *pcm;
@@ -598,6 +599,7 @@
 	static snd_device_ops_t ops = {
 		.dev_free = snd_pcm_dev_free,
 		.dev_register =	snd_pcm_dev_register,
+		.dev_disconnect = snd_pcm_dev_disconnect,
 		.dev_unregister = snd_pcm_dev_unregister
 	};
 
@@ -653,7 +655,7 @@
 #endif
 }
 
-int snd_pcm_free(snd_pcm_t *pcm)
+static int snd_pcm_free(snd_pcm_t *pcm)
 {
 	snd_assert(pcm != NULL, return -ENXIO);
 	if (pcm->private_free)
@@ -664,7 +666,7 @@
 	return 0;
 }
 
-int snd_pcm_dev_free(snd_device_t *device)
+static int snd_pcm_dev_free(snd_device_t *device)
 {
 	snd_pcm_t *pcm = snd_magic_cast(snd_pcm_t, device->device_data, return -ENXIO);
 	return snd_pcm_free(pcm);
@@ -696,7 +698,7 @@
 		return -ENODEV;
 
 	card = pcm->card;
-	read_lock(&card->control_rwlock);
+	down_read(&card->controls_rwsem);
 	list_for_each(list, &card->ctl_files) {
 		kctl = snd_ctl_file(list);
 		if (kctl->pid == current->pid) {
@@ -704,7 +706,7 @@
 			break;
 		}
 	}
-	read_unlock(&card->control_rwlock);
+	up_read(&card->controls_rwsem);
 
 	if (pstr->substream_count == 0)
 		return -ENODEV;
@@ -793,7 +795,7 @@
 	substream->pstr->substream_opened--;
 }
 
-int snd_pcm_dev_register(snd_device_t *device)
+static int snd_pcm_dev_register(snd_device_t *device)
 {
 	int idx, cidx, err;
 	unsigned short minor;
@@ -837,7 +839,25 @@
 	list_for_each(list, &snd_pcm_notify_list) {
 		snd_pcm_notify_t *notify;
 		notify = list_entry(list, snd_pcm_notify_t, list);
-		notify->n_register(-1 /* idx + SNDRV_MINOR_PCM */, pcm);
+		notify->n_register(pcm);
+	}
+	snd_pcm_lock(1);
+	return 0;
+}
+
+static int snd_pcm_dev_disconnect(snd_device_t *device)
+{
+	snd_pcm_t *pcm = snd_magic_cast(snd_pcm_t, device->device_data, return -ENXIO);
+	struct list_head *list;
+	int idx;
+
+	snd_pcm_lock(0);
+	idx = (pcm->card->number * SNDRV_PCM_DEVICES) + pcm->device;
+	snd_pcm_devices[idx] = NULL;
+	list_for_each(list, &snd_pcm_notify_list) {
+		snd_pcm_notify_t *notify;
+		notify = list_entry(list, snd_pcm_notify_t, list);
+		notify->n_disconnect(pcm);
 	}
 	snd_pcm_lock(1);
 	return 0;
@@ -853,10 +873,7 @@
 	snd_assert(pcm != NULL, return -ENXIO);
 	snd_pcm_lock(0);
 	idx = (pcm->card->number * SNDRV_PCM_DEVICES) + pcm->device;
-	if (snd_pcm_devices[idx] != pcm) {
-		snd_pcm_lock(1);
-		return -EINVAL;
-	}
+	snd_pcm_devices[idx] = NULL;
 	for (cidx = 0; cidx < 2; cidx++) {
 		devtype = -1;
 		switch (cidx) {
@@ -874,9 +891,8 @@
 	list_for_each(list, &snd_pcm_notify_list) {
 		snd_pcm_notify_t *notify;
 		notify = list_entry(list, snd_pcm_notify_t, list);
-		notify->n_unregister(-1 /* SNDRV_MINOR_PCM + idx */, pcm);
+		notify->n_unregister(pcm);
 	}
-	snd_pcm_devices[idx] = NULL;
 	snd_pcm_lock(1);
 	return snd_pcm_free(pcm);
 }
@@ -892,16 +908,14 @@
 		for (idx = 0; idx < SNDRV_CARDS * SNDRV_PCM_DEVICES; idx++) {
 			if (snd_pcm_devices[idx] == NULL)
 				continue;
-			notify->n_unregister(-1 /* idx + SNDRV_MINOR_PCM */,
-				             snd_pcm_devices[idx]);
+			notify->n_unregister(snd_pcm_devices[idx]);
 		}
 	} else {
 		list_add_tail(&notify->list, &snd_pcm_notify_list);
 		for (idx = 0; idx < SNDRV_CARDS * SNDRV_PCM_DEVICES; idx++) {
 			if (snd_pcm_devices[idx] == NULL)
 				continue;
-			notify->n_register(-1 /* idx + SNDRV_MINOR_PCM */,
-				           snd_pcm_devices[idx]);
+			notify->n_register(snd_pcm_devices[idx]);
 		}
 	}
 	snd_pcm_lock(1);
diff -Nru a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
--- a/sound/core/pcm_lib.c	Mon Dec 23 21:21:53 2002
+++ b/sound/core/pcm_lib.c	Mon Dec 23 21:21:53 2002
@@ -106,12 +106,12 @@
 	if (runtime->tstamp_mode & SNDRV_PCM_TSTAMP_MMAP)
 		snd_timestamp_now((snd_timestamp_t*)&runtime->status->tstamp);
 #ifdef CONFIG_SND_DEBUG
-	if (pos > runtime->buffer_size) {
+	if (pos >= runtime->buffer_size) {
 		snd_printk(KERN_ERR  "BUG: stream = %i, pos = 0x%lx, buffer size = 0x%lx, period size = 0x%lx\n", substream->stream, pos, runtime->buffer_size, runtime->period_size);
 	} else
 #endif
-	snd_runtime_check(pos <= runtime->buffer_size, return 0);
-	  
+	snd_runtime_check(pos < runtime->buffer_size, return 0);
+
 	pos -= pos % runtime->min_align;
 	new_hw_ptr = runtime->hw_ptr_base + pos;
 
@@ -172,12 +172,12 @@
 	if (runtime->tstamp_mode & SNDRV_PCM_TSTAMP_MMAP)
 		snd_timestamp_now((snd_timestamp_t*)&runtime->status->tstamp);
 #ifdef CONFIG_SND_DEBUG
-	if (pos > runtime->buffer_size) {
+	if (pos >= runtime->buffer_size) {
 		snd_printk(KERN_ERR "BUG: stream = %i, pos = 0x%lx, buffer size = 0x%lx, period size = 0x%lx\n", substream->stream, pos, runtime->buffer_size, runtime->period_size);
 	} else
 #endif
-	snd_runtime_check(pos <= runtime->buffer_size, return 0);
-	  
+	snd_runtime_check(pos < runtime->buffer_size, return 0);
+
 	pos -= pos % runtime->min_align;
 	new_hw_ptr = runtime->hw_ptr_base + pos;
 
diff -Nru a/sound/core/pcm_native.c b/sound/core/pcm_native.c
--- a/sound/core/pcm_native.c	Mon Dec 23 21:21:53 2002
+++ b/sound/core/pcm_native.c	Mon Dec 23 21:21:53 2002
@@ -1796,9 +1796,12 @@
 		err = -ENODEV;
 		goto __error1;
 	}
+	err = snd_card_file_add(pcm->card, file);
+	if (err < 0)
+		goto __error1;
 	if (!try_inc_mod_count(pcm->card->module)) {
 		err = -EFAULT;
-		goto __error1;
+		goto __error2;
 	}
 	init_waitqueue_entry(&wait, current);
 	add_wait_queue(&pcm->open_wait, &wait);
@@ -1831,6 +1834,8 @@
 
       __error:
 	dec_mod_count(pcm->card->module);
+      __error2:
+      	snd_card_file_remove(pcm->card, file);
       __error1:
 #ifdef LINUX_2_2
       	MOD_DEC_USE_COUNT;
@@ -1859,6 +1864,7 @@
 	up(&pcm->open_mutex);
 	wake_up(&pcm->open_wait);
 	dec_mod_count(pcm->card->module);
+	snd_card_file_remove(pcm->card, file);
 #ifdef LINUX_2_2
 	MOD_DEC_USE_COUNT;
 #endif
diff -Nru a/sound/core/pcm_sgbuf.c b/sound/core/pcm_sgbuf.c
--- a/sound/core/pcm_sgbuf.c	Mon Dec 23 21:22:00 2002
+++ b/sound/core/pcm_sgbuf.c	Mon Dec 23 21:22:00 2002
@@ -93,6 +93,56 @@
 }
 
 /*
+ * snd_pci_alloc_page - allocate a page in the valid pci dma mask
+ *
+ * returns the virtual address and stores the physical address on
+ * addrp.  this function cannot be called from interrupt handlers or
+ * within spinlocks.
+ */
+#ifdef __i386__
+/*
+ * on ix86, we allocate a page with GFP_KERNEL to assure the
+ * allocation.  the code is almost same with kernel/i386/pci-dma.c but
+ * it allocates only a single page and checkes the validity of the
+ * page address with the given pci dma mask.
+ */
+inline static void *snd_pci_alloc_page(struct pci_dev *pci, dma_addr_t *addrp)
+{
+	void *ptr;
+	dma_addr_t addr;
+	unsigned long rmask;
+
+	if (pci)
+		rmask = ~(unsigned long)pci->dma_mask;
+	else
+		rmask = 0;
+	ptr = (void *)__get_free_page(GFP_KERNEL);
+	if (ptr) {
+		addr = virt_to_phys(ptr);
+		if (((unsigned long)addr + PAGE_SIZE - 1) & rmask) {
+			/* try to reallocate with the GFP_DMA */
+			free_page((unsigned long)ptr);
+			ptr = (void *)__get_free_page(GFP_KERNEL | GFP_DMA);
+			if (ptr) /* ok, the address must be within lower 16MB... */
+				addr = virt_to_phys(ptr);
+			else
+				addr = 0;
+		}
+	} else
+		addr = 0;
+	if (ptr)
+		memset(ptr, 0, PAGE_SIZE);
+	*addrp = addr;
+	return ptr;
+}
+#else
+/* on other architectures, call snd_malloc_pci_pages() helper function
+ * which uses pci_alloc_consistent().
+ */
+#define snd_pci_alloc_page(pci, addrp) snd_malloc_pci_pages(pci, PAGE_SIZE, addrp)
+#endif
+
+/*
  * allocate sg buffer table with the given byte size.
  * if the buffer table already exists, try to resize it.
  * call this from hw_params callback.
@@ -128,7 +178,7 @@
 	while (sgbuf->pages < pages) {
 		void *ptr;
 		dma_addr_t addr;
-		ptr = snd_malloc_pci_pages(sgbuf->pci, PAGE_SIZE, &addr);
+		ptr = snd_pci_alloc_page(sgbuf->pci, &addr);
 		if (! ptr)
 			return -ENOMEM;
 		sgbuf->table[sgbuf->pages].buf = ptr;
diff -Nru a/sound/core/rawmidi.c b/sound/core/rawmidi.c
--- a/sound/core/rawmidi.c	Mon Dec 23 21:21:51 2002
+++ b/sound/core/rawmidi.c	Mon Dec 23 21:21:51 2002
@@ -51,6 +51,7 @@
 static int snd_rawmidi_free(snd_rawmidi_t *rawmidi);
 static int snd_rawmidi_dev_free(snd_device_t *device);
 static int snd_rawmidi_dev_register(snd_device_t *device);
+static int snd_rawmidi_dev_disconnect(snd_device_t *device);
 static int snd_rawmidi_dev_unregister(snd_device_t *device);
 
 snd_rawmidi_t *snd_rawmidi_devices[SNDRV_CARDS * SNDRV_RAWMIDI_DEVICES];
@@ -389,24 +390,29 @@
 	rmidi = snd_rawmidi_devices[(cardnum * SNDRV_RAWMIDI_DEVICES) + device];
 	if (rmidi == NULL)
 		return -ENODEV;
-	card = rmidi->card;
 #ifdef CONFIG_SND_OSSEMUL
 	if (maj == SOUND_MAJOR && !rmidi->ossreg)
 		return -ENXIO;
 #endif
-	fflags = snd_rawmidi_file_flags(file);
-	if ((file->f_flags & O_APPEND) && !(file->f_flags & O_NONBLOCK))
+	if ((file->f_flags & O_APPEND) && !(file->f_flags & O_NONBLOCK)) 
 		return -EINVAL;		/* invalid combination */
+	card = rmidi->card;
+	err = snd_card_file_add(card, file);
+	if (err < 0)
+		return -ENODEV;
+	fflags = snd_rawmidi_file_flags(file);
 	if ((file->f_flags & O_APPEND) || maj != CONFIG_SND_MAJOR) /* OSS emul? */
 		fflags |= SNDRV_RAWMIDI_LFLG_APPEND;
 	rawmidi_file = snd_magic_kmalloc(snd_rawmidi_file_t, 0, GFP_KERNEL);
-	if (rawmidi_file == NULL)
+	if (rawmidi_file == NULL) {
+		snd_card_file_remove(card, file);
 		return -ENOMEM;
+	}
 	init_waitqueue_entry(&wait, current);
 	add_wait_queue(&rmidi->open_wait, &wait);
 	while (1) {
 		subdevice = -1;
-		read_lock(&card->control_rwlock);
+		down_read(&card->controls_rwsem);
 		list_for_each(list, &card->ctl_files) {
 			kctl = snd_ctl_file(list);
 			if (kctl->pid == current->pid) {
@@ -414,7 +420,7 @@
 				break;
 			}
 		}
-		read_unlock(&card->control_rwlock);
+		up_read(&card->controls_rwsem);
 		err = snd_rawmidi_kernel_open(cardnum, device, subdevice, fflags, rawmidi_file);
 		if (err >= 0)
 			break;
@@ -443,6 +449,7 @@
 	if (err >= 0) {
 		file->private_data = rawmidi_file;
 	} else {
+		snd_card_file_remove(card, file);
 		snd_magic_kfree(rawmidi_file);
 	}
 	return err;
@@ -507,12 +514,15 @@
 static int snd_rawmidi_release(struct inode *inode, struct file *file)
 {
 	snd_rawmidi_file_t *rfile;
+	snd_rawmidi_t *rmidi;
 	int err;
 
 	rfile = snd_magic_cast(snd_rawmidi_file_t, file->private_data, return -ENXIO);
 	err = snd_rawmidi_kernel_release(rfile);
-	wake_up(&rfile->rmidi->open_wait);
+	rmidi = rfile->rmidi;
+	wake_up(&rmidi->open_wait);
 	snd_magic_kfree(rfile);
+	snd_card_file_remove(rmidi->card, file);
 	return err;
 }
 
@@ -1318,6 +1328,7 @@
 	static snd_device_ops_t ops = {
 		.dev_free = snd_rawmidi_dev_free,
 		.dev_register = snd_rawmidi_dev_register,
+		.dev_disconnect = snd_rawmidi_dev_disconnect,
 		.dev_unregister = snd_rawmidi_dev_unregister
 	};
 
@@ -1466,6 +1477,18 @@
 	return 0;
 }
 
+static int snd_rawmidi_dev_disconnect(snd_device_t *device)
+{
+	snd_rawmidi_t *rmidi = snd_magic_cast(snd_rawmidi_t, device->device_data, return -ENXIO);
+	int idx;
+
+	down(&register_mutex);
+	idx = (rmidi->card->number * SNDRV_RAWMIDI_DEVICES) + rmidi->device;
+	snd_rawmidi_devices[idx] = NULL;
+	up(&register_mutex);
+	return 0;
+}
+
 static int snd_rawmidi_dev_unregister(snd_device_t *device)
 {
 	int idx;
@@ -1474,10 +1497,7 @@
 	snd_assert(rmidi != NULL, return -ENXIO);
 	down(&register_mutex);
 	idx = (rmidi->card->number * SNDRV_RAWMIDI_DEVICES) + rmidi->device;
-	if (snd_rawmidi_devices[idx] != rmidi) {
-		up(&register_mutex);
-		return -EINVAL;
-	}
+	snd_rawmidi_devices[idx] = NULL;
 	if (rmidi->proc_entry) {
 		snd_info_unregister(rmidi->proc_entry);
 		rmidi->proc_entry = NULL;
@@ -1498,7 +1518,6 @@
 	if (rmidi->ops && rmidi->ops->dev_unregister)
 		rmidi->ops->dev_unregister(rmidi);
 	snd_unregister_device(SNDRV_DEVICE_TYPE_RAWMIDI, rmidi->card, rmidi->device);
-	snd_rawmidi_devices[idx] = NULL;
 	up(&register_mutex);
 #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
 	if (rmidi->seq_dev) {
@@ -1526,10 +1545,10 @@
 
 static int __init alsa_rawmidi_init(void)
 {
-	int i;
 
 	snd_ctl_register_ioctl(snd_rawmidi_control_ioctl);
 #ifdef CONFIG_SND_OSSEMUL
+	{ int i;
 	/* check device map table */
 	for (i = 0; i < SNDRV_CARDS; i++) {
 		if (midi_map[i] < 0 || midi_map[i] >= SNDRV_RAWMIDI_DEVICES) {
@@ -1540,6 +1559,7 @@
 			snd_printk(KERN_ERR "invalid amidi_map[%d] = %d\n", i, amidi_map[i]);
 			amidi_map[i] = 1;
 		}
+	}
 	}
 #endif /* CONFIG_SND_OSSEMUL */
 	return 0;
diff -Nru a/sound/core/seq/Makefile b/sound/core/seq/Makefile
--- a/sound/core/seq/Makefile	Mon Dec 23 21:22:00 2002
+++ b/sound/core/seq/Makefile	Mon Dec 23 21:22:00 2002
@@ -29,50 +29,53 @@
 obj-$(CONFIG_SND_SEQ_DUMMY) += snd-seq-dummy.o
 
 # Toplevel Module Dependency
-obj-$(CONFIG_SND_VIRMIDI) += snd-seq-virmidi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o
-obj-$(CONFIG_SND_SERIAL_U16550) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o
-obj-$(CONFIG_SND_MTPAV) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o
-obj-$(CONFIG_SND_MPU401) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o
-obj-$(CONFIG_SND_ALS100) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_AZT2320) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_DT019X) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_ES18XX) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_OPL3SA2) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_AD1816A) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_CS4231) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o
-obj-$(CONFIG_SND_CS4232) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_CS4236) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_ES1688) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_GUSCLASSIC) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_GUSMAX) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_GUSEXTREME) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_INTERWAVE) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_INTERWAVE_STB) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_OPTI92X_AD1848) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_OPTI92X_CS4231) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_OPTI93X) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_SB8) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_SB16) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_SBAWE) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o snd-seq-virmidi.o
-obj-$(CONFIG_SND_ES968) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o
-obj-$(CONFIG_SND_WAVEFRONT) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_ALS4000) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_CMIPCI) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_CS4281) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_ENS1370) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o
-obj-$(CONFIG_SND_ENS1371) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o
-obj-$(CONFIG_SND_ES1938) += snd-seq-device.o snd-seq-midi-emul.o snd-seq.o snd-seq-instr.o snd-seq-midi.o snd-seq-midi-event.o
-obj-$(CONFIG_SND_ES1968) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o
-obj-$(CONFIG_SND_FM801) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_ICE1712) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o
-obj-$(CONFIG_SND_INTEL8X0) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o
-obj-$(CONFIG_SND_SONICVIBES) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_VIA82XX) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o
-obj-$(CONFIG_SND_ALI5451) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o
-obj-$(CONFIG_SND_CS46XX) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o
-obj-$(CONFIG_SND_EMU10K1) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-virmidi.o
-obj-$(CONFIG_SND_TRIDENT) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_YMFPCI) += snd-seq-midi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
-obj-$(CONFIG_SND_USB_AUDIO) += snd-seq.o snd-seq-device.o snd-seq-midi-event.o
+RAWMIDI_OBJS = snd-seq-midi.o snd-seq-midi-event.o
+OPL3_OBJS = snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o
+obj-$(CONFIG_SND_VIRMIDI) += snd-seq-virmidi.o snd-seq-midi-event.o
+obj-$(CONFIG_SND_SERIAL_U16550) += $(RAWMIDI_OBJS)
+obj-$(CONFIG_SND_MTPAV) += $(RAWMIDI_OBJS)
+obj-$(CONFIG_SND_MPU401) += $(RAWMIDI_OBJS)
+obj-$(CONFIG_SND_ALS100) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_AZT2320) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_DT019X) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_ES18XX) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_OPL3SA2) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_AD1816A) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_CS4231) += $(RAWMIDI_OBJS)
+obj-$(CONFIG_SND_CS4232) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_CS4236) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_PC98_CS4232) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_ES1688) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_GUSCLASSIC) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_GUSMAX) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_GUSEXTREME) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_INTERWAVE) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_INTERWAVE_STB) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_OPTI92X_AD1848) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_OPTI92X_CS4231) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_OPTI93X) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_SB8) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_SB16) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_SBAWE) += $(RAWMIDI_OBJS) $(OPL3_OBJS) snd-seq-virmidi.o
+obj-$(CONFIG_SND_ES968) += $(RAWMIDI_OBJS)
+obj-$(CONFIG_SND_WAVEFRONT) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_ALS4000) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_CMIPCI) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_CS4281) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_ENS1370) += $(RAWMIDI_OBJS)
+obj-$(CONFIG_SND_ENS1371) += $(RAWMIDI_OBJS)
+obj-$(CONFIG_SND_ES1938) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_ES1968) += $(RAWMIDI_OBJS)
+obj-$(CONFIG_SND_FM801) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_ICE1712) += $(RAWMIDI_OBJS)
+obj-$(CONFIG_SND_INTEL8X0) += $(RAWMIDI_OBJS)
+obj-$(CONFIG_SND_SONICVIBES) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_VIA82XX) += $(RAWMIDI_OBJS)
+obj-$(CONFIG_SND_ALI5451) += $(RAWMIDI_OBJS)
+obj-$(CONFIG_SND_CS46XX) += $(RAWMIDI_OBJS)
+obj-$(CONFIG_SND_EMU10K1) += $(RAWMIDI_OBJS) snd-seq-midi-emul.o snd-seq-virmidi.o
+obj-$(CONFIG_SND_TRIDENT) += $(RAWMIDI_OBJS) snd-seq-midi-emul.o snd-seq-instr.o
+obj-$(CONFIG_SND_YMFPCI) += $(RAWMIDI_OBJS) $(OPL3_OBJS)
+obj-$(CONFIG_SND_USB_AUDIO) += $(RAWMIDI_OBJS)
 
 obj-m := $(sort $(obj-m))
diff -Nru a/sound/core/seq/instr/Makefile b/sound/core/seq/instr/Makefile
--- a/sound/core/seq/instr/Makefile	Mon Dec 23 21:21:59 2002
+++ b/sound/core/seq/instr/Makefile	Mon Dec 23 21:21:59 2002
@@ -19,6 +19,7 @@
 obj-$(CONFIG_SND_AD1816A) += snd-ainstr-fm.o
 obj-$(CONFIG_SND_CS4232) += snd-ainstr-fm.o
 obj-$(CONFIG_SND_CS4236) += snd-ainstr-fm.o
+obj-$(CONFIG_SND_PC98_CS4232) += snd-ainstr-fm.o
 obj-$(CONFIG_SND_ES1688) += snd-ainstr-fm.o
 obj-$(CONFIG_SND_GUSCLASSIC) += snd-ainstr-iw.o snd-ainstr-gf1.o snd-ainstr-simple.o
 obj-$(CONFIG_SND_GUSMAX) += snd-ainstr-iw.o snd-ainstr-gf1.o snd-ainstr-simple.o
diff -Nru a/sound/core/seq/seq.c b/sound/core/seq/seq.c
--- a/sound/core/seq/seq.c	Mon Dec 23 21:21:58 2002
+++ b/sound/core/seq/seq.c	Mon Dec 23 21:21:58 2002
@@ -134,7 +134,7 @@
 EXPORT_SYMBOL(snd_seq_event_port_attach);
 EXPORT_SYMBOL(snd_seq_event_port_detach);
   /* seq_lock.c */
-#if defined(__SMP__) || defined(CONFIG_SND_DEBUG)
+#if defined(CONFIG_SMP) || defined(CONFIG_SND_DEBUG)
 /*EXPORT_SYMBOL(snd_seq_sleep_in_lock);*/
 /*EXPORT_SYMBOL(snd_seq_sleep_timeout_in_lock);*/
 EXPORT_SYMBOL(snd_use_lock_sync_helper);
diff -Nru a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
--- a/sound/core/seq/seq_device.c	Mon Dec 23 21:21:52 2002
+++ b/sound/core/seq/seq_device.c	Mon Dec 23 21:21:52 2002
@@ -92,6 +92,7 @@
 static int snd_seq_device_free(snd_seq_device_t *dev);
 static int snd_seq_device_dev_free(snd_device_t *device);
 static int snd_seq_device_dev_register(snd_device_t *device);
+static int snd_seq_device_dev_disconnect(snd_device_t *device);
 static int snd_seq_device_dev_unregister(snd_device_t *device);
 
 static int init_device(snd_seq_device_t *dev, ops_list_t *ops);
@@ -166,6 +167,7 @@
 	static snd_device_ops_t dops = {
 		.dev_free = snd_seq_device_dev_free,
 		.dev_register = snd_seq_device_dev_register,
+		.dev_disconnect = snd_seq_device_dev_disconnect,
 		.dev_unregister = snd_seq_device_dev_unregister
 	};
 
@@ -263,6 +265,24 @@
 	 */
 	if (ops->driver & DRIVER_LOADED)
 		init_device(dev, ops);
+
+	unlock_driver(ops);
+	return 0;
+}
+
+/*
+ * disconnect the device
+ */
+static int snd_seq_device_dev_disconnect(snd_device_t *device)
+{
+	snd_seq_device_t *dev = snd_magic_cast(snd_seq_device_t, device->device_data, return -ENXIO);
+	ops_list_t *ops;
+
+	ops = find_driver(dev->id, 0);
+	if (ops == NULL)
+		return -ENOENT;
+
+	free_device(dev, ops);
 
 	unlock_driver(ops);
 	return 0;
diff -Nru a/sound/core/seq/seq_lock.c b/sound/core/seq/seq_lock.c
--- a/sound/core/seq/seq_lock.c	Mon Dec 23 21:21:53 2002
+++ b/sound/core/seq/seq_lock.c	Mon Dec 23 21:21:53 2002
@@ -23,7 +23,7 @@
 #include <sound/core.h>
 #include "seq_lock.h"
 
-#if defined(__SMP__) || defined(CONFIG_SND_DEBUG)
+#if defined(CONFIG_SMP) || defined(CONFIG_SND_DEBUG)
 
 #if 0 /* NOT USED */
 /* (interruptible) sleep_on during the specified spinlock */
diff -Nru a/sound/core/seq/seq_lock.h b/sound/core/seq/seq_lock.h
--- a/sound/core/seq/seq_lock.h	Mon Dec 23 21:21:55 2002
+++ b/sound/core/seq/seq_lock.h	Mon Dec 23 21:21:55 2002
@@ -3,7 +3,7 @@
 
 #include <linux/sched.h>
 
-#if defined(__SMP__) || defined(CONFIG_SND_DEBUG)
+#if defined(CONFIG_SMP) || defined(CONFIG_SND_DEBUG)
 
 typedef atomic_t snd_use_lock_t;
 
diff -Nru a/sound/core/sound.c b/sound/core/sound.c
--- a/sound/core/sound.c	Mon Dec 23 21:21:58 2002
+++ b/sound/core/sound.c	Mon Dec 23 21:21:58 2002
@@ -76,8 +76,12 @@
 void snd_request_card(int card)
 {
 	char str[32];
+	int locked;
 
-	if (snd_cards[card] != NULL)
+	read_lock(&snd_card_rwlock);
+	locked = snd_cards_lock & (1 << card);
+	read_unlock(&snd_card_rwlock);
+	if (locked)
 		return;
 	if (card < 0 || card >= snd_ecards_limit)
 		return;
@@ -423,9 +427,13 @@
 EXPORT_SYMBOL(snd_mixer_oss_notify_callback);
 #endif
 EXPORT_SYMBOL(snd_card_new);
+EXPORT_SYMBOL(snd_card_disconnect);
 EXPORT_SYMBOL(snd_card_free);
+EXPORT_SYMBOL(snd_card_free_in_thread);
 EXPORT_SYMBOL(snd_card_register);
 EXPORT_SYMBOL(snd_component_add);
+EXPORT_SYMBOL(snd_card_file_add);
+EXPORT_SYMBOL(snd_card_file_remove);
 #ifdef CONFIG_PM
 EXPORT_SYMBOL(snd_power_wait);
 #endif
diff -Nru a/sound/drivers/mpu401/mpu401.c b/sound/drivers/mpu401/mpu401.c
--- a/sound/drivers/mpu401/mpu401.c	Mon Dec 23 21:21:58 2002
+++ b/sound/drivers/mpu401/mpu401.c	Mon Dec 23 21:21:58 2002
@@ -40,6 +40,9 @@
 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;	/* Enable this card */
 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* MPU-401 port number */
 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;	/* MPU-401 IRQ */
+#ifdef CONFIG_PC9800
+static int pc98ii[SNDRV_CARDS];				/* PC98-II dauther board */
+#endif
 
 MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
 MODULE_PARM_DESC(index, "Index value for MPU-401 device.");
@@ -56,6 +59,11 @@
 MODULE_PARM(irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
 MODULE_PARM_DESC(irq, "IRQ # for MPU-401 device.");
 MODULE_PARM_SYNTAX(irq, SNDRV_IRQ_DESC);
+#ifdef CONFIG_PC9800
+MODULE_PARM(pc98ii, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
+MODULE_PARM_DESC(pc98ii, "Roland MPU-PC98II support.");
+MODULE_PARM_SYNTAX(pc98ii, SNDRV_BOOLEAN_FALSE_DESC);
+#endif
 
 static snd_card_t *snd_mpu401_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
 
@@ -76,7 +84,11 @@
 	card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
 	if (card == NULL)
 		return -ENOMEM;
-	if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
+	if (snd_mpu401_uart_new(card, 0,
+#ifdef CONFIG_PC9800
+				pc98ii[dev] ? MPU401_HW_PC98II :
+#endif
+				MPU401_HW_MPU401,
 				port[dev], 0,
 				irq[dev], irq[dev] >= 0 ? SA_INTERRUPT : 0, NULL) < 0) {
 		printk(KERN_ERR "MPU401 not detected at 0x%lx\n", port[dev]);
diff -Nru a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c
--- a/sound/drivers/mpu401/mpu401_uart.c	Mon Dec 23 21:21:53 2002
+++ b/sound/drivers/mpu401/mpu401_uart.c	Mon Dec 23 21:21:53 2002
@@ -401,12 +401,17 @@
 	spin_lock_init(&mpu->timer_lock);
 	mpu->hardware = hardware;
 	if (!integrated) {
-		if ((mpu->res = request_region(port, 2, "MPU401 UART")) == NULL) {
+		int res_size = hardware == MPU401_HW_PC98II ? 4 : 2;
+		if ((mpu->res = request_region(port, res_size, "MPU401 UART")) == NULL) {
 			snd_device_free(card, rmidi);
 			return -EBUSY;
 		}
 	}
 	mpu->port = port;
+	if (hardware == MPU401_HW_PC98II)
+		mpu->cport = port + 2;
+	else
+		mpu->cport = port + 1;
 	if (irq >= 0 && irq_flags) {
 		if (request_irq(irq, snd_mpu401_uart_interrupt, irq_flags, "MPU401 UART", (void *) mpu)) {
 			snd_printk("unable to grab IRQ %d\n", irq);
diff -Nru a/sound/drivers/mtpav.c b/sound/drivers/mtpav.c
--- a/sound/drivers/mtpav.c	Mon Dec 23 21:21:59 2002
+++ b/sound/drivers/mtpav.c	Mon Dec 23 21:21:59 2002
@@ -205,19 +205,19 @@
 
 static int translate_hwport_to_subdevice(mtpav_t *chip, int hwport)
 {
-	int port;
+	int p;
 	if (hwport <= 0x00) /* all ports */
 		return chip->num_ports + MTPAV_PIDX_BROADCAST;
 	else if (hwport <= 0x08) { /* single port */
-		port = hwport - 1;
-		if (port >= chip->num_ports)
-			port = 0;
-		return port;
+		p = hwport - 1;
+		if (p >= chip->num_ports)
+			p = 0;
+		return p;
 	} else if (hwport <= 0x10) { /* remote port */
-		port = hwport - 0x09 + chip->num_ports;
-		if (port >= chip->num_ports * 2)
-			port = chip->num_ports;
-		return port;
+		p = hwport - 0x09 + chip->num_ports;
+		if (p >= chip->num_ports * 2)
+			p = chip->num_ports;
+		return p;
 	} else if (hwport == 0x11)  /* computer port */
 		return chip->num_ports + MTPAV_PIDX_COMPUTER;
 	else  /* ADAT */
@@ -335,11 +335,11 @@
 
 static void snd_mtpav_portscan(mtpav_t *chip)	// put mtp into smart routing mode
 {
-	u8 port;
+	u8 p;
 
-	for (port = 0; port < 8; port++) {
+	for (p = 0; p < 8; p++) {
 		snd_mtpav_send_byte(chip, 0xf5);
-		snd_mtpav_send_byte(chip, port);
+		snd_mtpav_send_byte(chip, p);
 		snd_mtpav_send_byte(chip, 0xfe);
 	}
 }
@@ -350,12 +350,12 @@
 static int snd_mtpav_input_open(snd_rawmidi_substream_t * substream)
 {
 	unsigned long flags;
-	mtpav_port_t *port = &mtp_card->ports[substream->number];
+	mtpav_port_t *portp = &mtp_card->ports[substream->number];
 
 	//printk("mtpav port: %d opened\n", (int) substream->number);
 	spin_lock_irqsave(&mtp_card->spinlock, flags);
-	port->mode |= MTPAV_MODE_INPUT_OPENED;
-	port->input = substream;
+	portp->mode |= MTPAV_MODE_INPUT_OPENED;
+	portp->input = substream;
 	if (mtp_card->share_irq++ == 0)
 		snd_mtpav_mputreg(mtp_card, CREG, (SIGC_INTEN | SIGC_WRITE));	// enable pport interrupts
 	spin_unlock_irqrestore(&mtp_card->spinlock, flags);
@@ -368,14 +368,14 @@
 static int snd_mtpav_input_close(snd_rawmidi_substream_t *substream)
 {
 	unsigned long flags;
-	mtpav_port_t *port = &mtp_card->ports[substream->number];
+	mtpav_port_t *portp = &mtp_card->ports[substream->number];
 
-	//printk("mtpav port: %d closed\n", (int) port);
+	//printk("mtpav port: %d closed\n", (int) portp);
 
 	spin_lock_irqsave(&mtp_card->spinlock, flags);
 
-	port->mode &= (~MTPAV_MODE_INPUT_OPENED);
-	port->input = NULL;
+	portp->mode &= (~MTPAV_MODE_INPUT_OPENED);
+	portp->input = NULL;
 	if (--mtp_card->share_irq == 0)
 		snd_mtpav_mputreg(mtp_card, CREG, 0);	// disable pport interrupts
 
@@ -389,13 +389,13 @@
 static void snd_mtpav_input_trigger(snd_rawmidi_substream_t * substream, int up)
 {
 	unsigned long flags;
-	mtpav_port_t *port = &mtp_card->ports[substream->number];
+	mtpav_port_t *portp = &mtp_card->ports[substream->number];
 
 	spin_lock_irqsave(&mtp_card->spinlock, flags);
 	if (up)
-		port->mode |= MTPAV_MODE_INPUT_TRIGGERED;
+		portp->mode |= MTPAV_MODE_INPUT_TRIGGERED;
 	else
-		port->mode &= ~MTPAV_MODE_INPUT_TRIGGERED;
+		portp->mode &= ~MTPAV_MODE_INPUT_TRIGGERED;
 	spin_unlock_irqrestore(&mtp_card->spinlock, flags);
 
 }
@@ -416,9 +416,9 @@
 	add_timer(&chip->timer);
 	/* process each port */
 	for (p = 0; p <= chip->num_ports * 2 + MTPAV_PIDX_BROADCAST; p++) {
-		mtpav_port_t *port = &mtp_card->ports[p];
-		if ((port->mode & MTPAV_MODE_OUTPUT_TRIGGERED) && port->output)
-			snd_mtpav_output_port_write(port, port->output);
+		mtpav_port_t *portp = &mtp_card->ports[p];
+		if ((portp->mode & MTPAV_MODE_OUTPUT_TRIGGERED) && portp->output)
+			snd_mtpav_output_port_write(portp, portp->output);
 	}
 	spin_unlock(&chip->spinlock);
 }
@@ -445,11 +445,11 @@
 static int snd_mtpav_output_open(snd_rawmidi_substream_t * substream)
 {
 	unsigned long flags;
-	mtpav_port_t *port = &mtp_card->ports[substream->number];
+	mtpav_port_t *portp = &mtp_card->ports[substream->number];
 
 	spin_lock_irqsave(&mtp_card->spinlock, flags);
-	port->mode |= MTPAV_MODE_OUTPUT_OPENED;
-	port->output = substream;
+	portp->mode |= MTPAV_MODE_OUTPUT_OPENED;
+	portp->output = substream;
 	spin_unlock_irqrestore(&mtp_card->spinlock, flags);
 	return 0;
 };
@@ -460,11 +460,11 @@
 static int snd_mtpav_output_close(snd_rawmidi_substream_t * substream)
 {
 	unsigned long flags;
-	mtpav_port_t *port = &mtp_card->ports[substream->number];
+	mtpav_port_t *portp = &mtp_card->ports[substream->number];
 
 	spin_lock_irqsave(&mtp_card->spinlock, flags);
-	port->mode &= (~MTPAV_MODE_OUTPUT_OPENED);
-	port->output = NULL;
+	portp->mode &= (~MTPAV_MODE_OUTPUT_OPENED);
+	portp->output = NULL;
 	spin_unlock_irqrestore(&mtp_card->spinlock, flags);
 	return 0;
 };
@@ -475,17 +475,17 @@
 static void snd_mtpav_output_trigger(snd_rawmidi_substream_t * substream, int up)
 {
 	unsigned long flags;
-	mtpav_port_t *port = &mtp_card->ports[substream->number];
+	mtpav_port_t *portp = &mtp_card->ports[substream->number];
 
 	spin_lock_irqsave(&mtp_card->spinlock, flags);
 	if (up) {
-		if (! (port->mode  & MTPAV_MODE_OUTPUT_TRIGGERED)) {
+		if (! (portp->mode  & MTPAV_MODE_OUTPUT_TRIGGERED)) {
 			if (mtp_card->istimer++ == 0)
 				snd_mtpav_add_output_timer(mtp_card);
-			port->mode |= MTPAV_MODE_OUTPUT_TRIGGERED;
+			portp->mode |= MTPAV_MODE_OUTPUT_TRIGGERED;
 		}
 	} else {
-		port->mode &= ~MTPAV_MODE_OUTPUT_TRIGGERED;
+		portp->mode &= ~MTPAV_MODE_OUTPUT_TRIGGERED;
 		if (--mtp_card->istimer == 0)
 			snd_mtpav_remove_output_timer(mtp_card);
 	}
@@ -501,15 +501,15 @@
 
 static void snd_mtpav_inmidi_process(mtpav_t *mcrd, u8 inbyte)
 {
-	mtpav_port_t *port;
+	mtpav_port_t *portp;
 
 	if (mcrd->inmidiport > mcrd->num_ports * 2 + MTPAV_PIDX_BROADCAST)
 		return;
 
-	port = &mcrd->ports[mcrd->inmidiport];
-	if (port->mode & MTPAV_MODE_INPUT_TRIGGERED) {
+	portp = &mcrd->ports[mcrd->inmidiport];
+	if (portp->mode & MTPAV_MODE_INPUT_TRIGGERED) {
 		spin_unlock(&mcrd->spinlock);
-		snd_rawmidi_receive(port->input, &inbyte, 1);
+		snd_rawmidi_receive(portp->input, &inbyte, 1);
 		spin_lock(&mcrd->spinlock);
 	}
 }
diff -Nru a/sound/drivers/opl3/Makefile b/sound/drivers/opl3/Makefile
--- a/sound/drivers/opl3/Makefile	Mon Dec 23 21:21:50 2002
+++ b/sound/drivers/opl3/Makefile	Mon Dec 23 21:21:50 2002
@@ -13,56 +13,35 @@
 endif
 endif
 
-# Toplevel Module Dependency
-obj-$(CONFIG_SND_ALS100) += snd-opl3-lib.o
-obj-$(CONFIG_SND_AZT2320) += snd-opl3-lib.o
-obj-$(CONFIG_SND_DT019X) += snd-opl3-lib.o
-obj-$(CONFIG_SND_ES18XX) += snd-opl3-lib.o
-obj-$(CONFIG_SND_OPL3SA2) += snd-opl3-lib.o
-obj-$(CONFIG_SND_AD1816A) += snd-opl3-lib.o
-obj-$(CONFIG_SND_CS4232) += snd-opl3-lib.o
-obj-$(CONFIG_SND_CS4236) += snd-opl3-lib.o
-obj-$(CONFIG_SND_ES1688) += snd-opl3-lib.o
-obj-$(CONFIG_SND_GUSEXTREME) += snd-opl3-lib.o
-obj-$(CONFIG_SND_OPTI92X_AD1848) += snd-opl3-lib.o
-obj-$(CONFIG_SND_OPTI92X_CS4231) += snd-opl3-lib.o
-obj-$(CONFIG_SND_OPTI93X) += snd-opl3-lib.o
-obj-$(CONFIG_SND_SB8) += snd-opl3-lib.o
-obj-$(CONFIG_SND_SB16) += snd-opl3-lib.o
-obj-$(CONFIG_SND_SBAWE) += snd-opl3-lib.o
-obj-$(CONFIG_SND_WAVEFRONT) += snd-opl3-lib.o
-obj-$(CONFIG_SND_ALS4000) += snd-opl3-lib.o
-obj-$(CONFIG_SND_CMIPCI) += snd-opl3-lib.o
-obj-$(CONFIG_SND_CS4281) += snd-opl3-lib.o
-obj-$(CONFIG_SND_ES1938) += snd-opl3-lib.o
-obj-$(CONFIG_SND_FM801) += snd-opl3-lib.o
-obj-$(CONFIG_SND_SONICVIBES) += snd-opl3-lib.o
-obj-$(CONFIG_SND_YMFPCI) += snd-opl3-lib.o
+OPL3_OBJS = snd-opl3-lib.o
 ifeq ($(subst m,y,$(CONFIG_SND_SEQUENCER)),y)
-  obj-$(CONFIG_SND_ALS100) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_AZT2320) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_DT019X) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_ES18XX) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_OPL3SA2) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_AD1816A) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_CS4232) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_CS4236) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_ES1688) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_GUSEXTREME) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_OPTI92X_AD1848) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_OPTI92X_CS4231) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_OPTI93X) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_SB8) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_SB16) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_SBAWE) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_WAVEFRONT) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_ALS4000) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_CMIPCI) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_CS4281) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_ES1938) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_FM801) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_SONICVIBES) += snd-opl3-synth.o
-  obj-$(CONFIG_SND_YMFPCI) += snd-opl3-synth.o
+OPL3_OBJS += snd-opl3-synth.o
 endif
+
+# Toplevel Module Dependency
+obj-$(CONFIG_SND_ALS100) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_AZT2320) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_DT019X) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_ES18XX) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_OPL3SA2) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_AD1816A) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_CS4232) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_CS4236) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_ES1688) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_GUSEXTREME) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_OPTI92X_AD1848) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_OPTI92X_CS4231) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_OPTI93X) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_SB8) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_SB16) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_SBAWE) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_WAVEFRONT) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_ALS4000) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_CMIPCI) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_CS4281) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_ES1938) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_FM801) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_SONICVIBES) += $(OPL3_OBJS)
+obj-$(CONFIG_SND_YMFPCI) += $(OPL3_OBJS)
 
 obj-m := $(sort $(obj-m))
diff -Nru a/sound/drivers/opl3/opl3_lib.c b/sound/drivers/opl3/opl3_lib.c
--- a/sound/drivers/opl3/opl3_lib.c	Mon Dec 23 21:21:51 2002
+++ b/sound/drivers/opl3/opl3_lib.c	Mon Dec 23 21:21:51 2002
@@ -420,6 +420,26 @@
 	case OPL3_HW_OPL3_FM801:
 		opl3->command = &snd_opl3_command;
 		break;
+	case OPL3_HW_OPL3_PC98:
+		opl3->command = &snd_opl3_command;
+
+		/* Initialize? */
+		opl3->command(opl3, OPL3_RIGHT | 0x05, 0x05);
+		opl3->command(opl3, OPL3_RIGHT | 0x08, 0x04);
+		opl3->command(opl3, OPL3_RIGHT | 0x08, 0x00);
+		opl3->command(opl3, OPL3_LEFT | 0xf7, 0x00);
+		opl3->command(opl3, OPL3_LEFT | 0x04, 0x60);
+		opl3->command(opl3, OPL3_LEFT | 0x04, 0x80);
+		inb(opl3->l_port);
+		
+		opl3->command(opl3, OPL3_LEFT | 0x02, 0xff);
+		opl3->command(opl3, OPL3_LEFT | 0x04, 0x21);
+		inb(opl3->l_port);
+		
+		opl3->command(opl3, OPL3_LEFT | 0x04, 0x60);
+		opl3->command(opl3, OPL3_LEFT | 0x04, 0x80);
+
+		break;
 	case OPL3_HW_OPL3_CS4281:
 		opl3->command = &snd_opl3_cs4281_command;
 		break;
@@ -438,6 +458,7 @@
 			opl3->command = &snd_opl3_command;
 		}
 	}
+
 	opl3->command(opl3, OPL3_LEFT | OPL3_REG_TEST, OPL3_ENABLE_WAVE_SELECT);
 	opl3->command(opl3, OPL3_LEFT | OPL3_REG_PERCUSSION, 0x00);	/* Melodic mode */
 
diff -Nru a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
--- a/sound/drivers/opl3/opl3_seq.c	Mon Dec 23 21:21:57 2002
+++ b/sound/drivers/opl3/opl3_seq.c	Mon Dec 23 21:21:57 2002
@@ -266,7 +266,6 @@
 	snd_seq_fm_init(&opl3->fm_ops, NULL);
 
 	/* setup system timer */
-	memset(&opl3->tlist, 0, sizeof(opl3->tlist));
 	init_timer(&opl3->tlist);
 	opl3->tlist.function = snd_opl3_timer_func;
 	opl3->tlist.data = (unsigned long) opl3;
diff -Nru a/sound/drivers/virmidi.c b/sound/drivers/virmidi.c
--- a/sound/drivers/virmidi.c	Mon Dec 23 21:21:52 2002
+++ b/sound/drivers/virmidi.c	Mon Dec 23 21:21:52 2002
@@ -51,6 +51,9 @@
 #define SNDRV_GET_ID
 #include <sound/initval.h>
 
+/* hack: OSS defines midi_devs, so undefine it (versioned symbols) */
+#undef midi_devs
+
 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
 MODULE_DESCRIPTION("Dummy soundcard for virtual rawmidi devices");
 MODULE_LICENSE("GPL");
diff -Nru a/sound/isa/cs423x/cs4231_lib.c b/sound/isa/cs423x/cs4231_lib.c
--- a/sound/isa/cs423x/cs4231_lib.c	Mon Dec 23 21:21:51 2002
+++ b/sound/isa/cs423x/cs4231_lib.c	Mon Dec 23 21:21:52 2002
@@ -445,6 +445,9 @@
 {
 	cs4231_t *chip = snd_pcm_substream_chip(substream);
 	int result = 0;
+	unsigned int what;
+	snd_pcm_substream_t *s;
+	int do_start;
 
 #if 0
 	printk("codec trigger!!! - what = %i, enable = %i, status = 0x%x\n", what, enable, cs4231_inb(chip, CS4231P(STATUS)));
@@ -452,38 +455,39 @@
 
 	switch (cmd) {
 	case SNDRV_PCM_TRIGGER_START:
+	case SNDRV_PCM_TRIGGER_RESUME:
+		do_start = 1; break;
 	case SNDRV_PCM_TRIGGER_STOP:
-	{
-		unsigned int what = 0;
-		snd_pcm_substream_t *s = substream;
-		do {
-			if (s == chip->playback_substream) {
-				what |= CS4231_PLAYBACK_ENABLE;
-				snd_pcm_trigger_done(s, substream);
-			} else if (s == chip->capture_substream) {
-				what |= CS4231_RECORD_ENABLE;
-				snd_pcm_trigger_done(s, substream);
-			}
-			s = s->link_next;
-		} while (s != substream);
-		spin_lock(&chip->reg_lock);
-		if (cmd == SNDRV_PCM_TRIGGER_START) {
-			chip->image[CS4231_IFACE_CTRL] |= what;
-			if (chip->trigger)
-				chip->trigger(chip, what, 1);
-		} else {
-			chip->image[CS4231_IFACE_CTRL] &= ~what;
-			if (chip->trigger)
-				chip->trigger(chip, what, 0);
-		}
-		snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]);
-		spin_unlock(&chip->reg_lock);
-		break;
-	}
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+		do_start = 0; break;
 	default:
-		result = -EINVAL;
-		break;
+		return -EINVAL;
 	}
+
+	what = 0;
+	s = substream;
+	do {
+		if (s == chip->playback_substream) {
+			what |= CS4231_PLAYBACK_ENABLE;
+			snd_pcm_trigger_done(s, substream);
+		} else if (s == chip->capture_substream) {
+			what |= CS4231_RECORD_ENABLE;
+			snd_pcm_trigger_done(s, substream);
+		}
+		s = s->link_next;
+	} while (s != substream);
+	spin_lock(&chip->reg_lock);
+	if (do_start) {
+		chip->image[CS4231_IFACE_CTRL] |= what;
+		if (chip->trigger)
+			chip->trigger(chip, what, 1);
+	} else {
+		chip->image[CS4231_IFACE_CTRL] &= ~what;
+		if (chip->trigger)
+			chip->trigger(chip, what, 0);
+	}
+	snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]);
+	spin_unlock(&chip->reg_lock);
 #if 0
 	snd_cs4231_debug(chip);
 #endif
@@ -1188,7 +1192,9 @@
 static snd_pcm_hardware_t snd_cs4231_playback =
 {
 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
-				 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START),
+				 SNDRV_PCM_INFO_MMAP_VALID |
+				 SNDRV_PCM_INFO_RESUME |
+				 SNDRV_PCM_INFO_SYNC_START),
 	.formats =		(SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
 				 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
 	.rates =		SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
@@ -1207,7 +1213,9 @@
 static snd_pcm_hardware_t snd_cs4231_capture =
 {
 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
-				 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START),
+				 SNDRV_PCM_INFO_MMAP_VALID |
+				 SNDRV_PCM_INFO_RESUME |
+				 SNDRV_PCM_INFO_SYNC_START),
 	.formats =		(SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
 				 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
 	.rates =		SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
diff -Nru a/sound/isa/cs423x/cs4236.c b/sound/isa/cs423x/cs4236.c
--- a/sound/isa/cs423x/cs4236.c	Mon Dec 23 21:21:51 2002
+++ b/sound/isa/cs423x/cs4236.c	Mon Dec 23 21:21:51 2002
@@ -263,6 +263,8 @@
 	ISAPNP_CS4232('C','S','C',0xd937,0x0000,0x0010,0x0003),
 	/* CS4235 without MPU401 */
 	ISAPNP_CS4232_WOMPU('C','S','C',0xe825,0x0100,0x0110),
+	/* IBM IntelliStation M Pro 6898 11U - CS4236B */
+	ISAPNP_CS4232_WOMPU('C','S','C',0xe835,0x0000,0x0010),
 	/* Some noname CS4236 based card */
 	ISAPNP_CS4232('C','S','C',0xe936,0x0000,0x0010,0x0003),
 	/* CS4236B */
@@ -609,12 +611,10 @@
 
 /* format is: snd-cs4232=enable,index,id,isapnp,port,
 			 cport,mpu_port,fm_port,sb_port,
-			 irq,mpu_irq,dma1,dma1_size,
-			 dma2,dma2_size */
+			 irq,mpu_irq,dma1,dma2 */
 /* format is: snd-cs4236=enable,index,id,isapnp,port,
 			 cport,mpu_port,fm_port,sb_port,
-			 irq,mpu_irq,dma1,dma1_size,
-			 dma2,dma2_size */
+			 irq,mpu_irq,dma1,dma2 */
 
 static int __init alsa_card_cs423x_setup(char *str)
 {
diff -Nru a/sound/isa/es18xx.c b/sound/isa/es18xx.c
--- a/sound/isa/es18xx.c	Mon Dec 23 21:21:53 2002
+++ b/sound/isa/es18xx.c	Mon Dec 23 21:21:53 2002
@@ -444,8 +444,7 @@
 	if (snd_pcm_format_width(params_format(hw_params)) == 16)
 		shift++;
 
-	switch (substream->number) {
-	case 0:
+	if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
 		if ((chip->caps & ES18XX_DUPLEX_MONO) &&
 		    (chip->capture_a_substream) &&
 		    params_channels(hw_params) != 1) {
@@ -453,10 +452,8 @@
 			return -EBUSY;
 		}
 		chip->dma2_shift = shift;
-		break;
-	case 1:
+	} else {
 		chip->dma1_shift = shift;
-		break;
 	}
 	if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
 		return err;
@@ -495,19 +492,12 @@
 					snd_pcm_substream_t * substream,
 					int cmd)
 {
-        if (cmd == SNDRV_PCM_TRIGGER_START) {
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+	case SNDRV_PCM_TRIGGER_RESUME:
 		if (chip->active & DAC2)
 			return 0;
 		chip->active |= DAC2;
-	} else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
-		if (!(chip->active & DAC2))
-			return 0;
-		chip->active &= ~DAC2;
-	} else {
-		return -EINVAL;
-	}
-
-	if (cmd == SNDRV_PCM_TRIGGER_START) {	
                 /* Start DMA */
 		if (chip->dma2 >= 4)
 			snd_es18xx_mixer_write(chip, 0x78, 0xb3);
@@ -523,8 +513,12 @@
 			/* Enable PCM output */
 			snd_es18xx_dsp_command(chip, 0xD1);
 #endif
-        }
-        else {
+		break;
+	case SNDRV_PCM_TRIGGER_STOP:
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+		if (!(chip->active & DAC2))
+			return 0;
+		chip->active &= ~DAC2;
                 /* Stop DMA */
                 snd_es18xx_mixer_write(chip, 0x78, 0x00);
 #ifdef AVOID_POPS
@@ -536,7 +530,10 @@
 			/* Disable PCM output */
 			snd_es18xx_dsp_command(chip, 0xD3);
 #endif
-        }
+		break;
+	default:
+		return -EINVAL;
+	}
 
 	return 0;
 }
@@ -608,24 +605,27 @@
 {
         es18xx_t *chip = snd_pcm_substream_chip(substream);
 
-        if (cmd == SNDRV_PCM_TRIGGER_START) {
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+	case SNDRV_PCM_TRIGGER_RESUME:
 		if (chip->active & ADC1)
 			return 0;
 		chip->active |= ADC1;
-	} else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
+                /* Start DMA */
+                snd_es18xx_write(chip, 0xB8, 0x0f);
+		break;
+	case SNDRV_PCM_TRIGGER_STOP:
+	case SNDRV_PCM_TRIGGER_SUSPEND:
 		if (!(chip->active & ADC1))
 			return 0;
 		chip->active &= ~ADC1;
-	} else {
+                /* Stop DMA */
+                snd_es18xx_write(chip, 0xB8, 0x00);
+		break;
+	default:
 		return -EINVAL;
 	}
 
-	if (cmd == SNDRV_PCM_TRIGGER_START)
-                /* Start DMA */
-                snd_es18xx_write(chip, 0xB8, 0x0f);
-        else
-                /* Stop DMA */
-                snd_es18xx_write(chip, 0xB8, 0x00);
 	return 0;
 }
 
@@ -670,19 +670,12 @@
 					snd_pcm_substream_t *substream,
 					int cmd)
 {
-        if (cmd == SNDRV_PCM_TRIGGER_START) {
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+	case SNDRV_PCM_TRIGGER_RESUME:
 		if (chip->active & DAC1)
 			return 0;
 		chip->active |= DAC1;
-        } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
-		if (!(chip->active & DAC1))
-			return 0;
-		chip->active &= ~DAC1;
-	} else {
-		return -EINVAL;
-	}
-
-	if (cmd == SNDRV_PCM_TRIGGER_START) {
                 /* Start DMA */
                 snd_es18xx_write(chip, 0xB8, 0x05);
 #ifdef AVOID_POPS
@@ -691,8 +684,12 @@
                 /* Enable Audio 1 */
                 snd_es18xx_dsp_command(chip, 0xD1);
 #endif
-        }
-        else {
+		break;
+	case SNDRV_PCM_TRIGGER_STOP:
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+		if (!(chip->active & DAC1))
+			return 0;
+		chip->active &= ~DAC1;
                 /* Stop DMA */
                 snd_es18xx_write(chip, 0xB8, 0x00);
 #ifdef AVOID_POPS
@@ -701,33 +698,31 @@
                 /* Disable Audio 1 */
                 snd_es18xx_dsp_command(chip, 0xD3);
 #endif
-        }
+		break;
+	default:
+		return -EINVAL;
+	}
+
 	return 0;
 }
 
 static int snd_es18xx_playback_prepare(snd_pcm_substream_t *substream)
 {
         es18xx_t *chip = snd_pcm_substream_chip(substream);
-	switch (substream->number) {
-	case 0:
+	if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
 		return snd_es18xx_playback1_prepare(chip, substream);
-	case 1:
+	else
 		return snd_es18xx_playback2_prepare(chip, substream);
-	}
-	return -EINVAL;
 }
 
 static int snd_es18xx_playback_trigger(snd_pcm_substream_t *substream,
 				       int cmd)
 {
         es18xx_t *chip = snd_pcm_substream_chip(substream);
-	switch (substream->number) {
-	case 0:
+	if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
 		return snd_es18xx_playback1_trigger(chip, substream, cmd);
-	case 1:
+	else
 		return snd_es18xx_playback2_trigger(chip, substream, cmd);
-	}
-	return -EINVAL;
 }
 
 static void snd_es18xx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
@@ -798,19 +793,17 @@
         es18xx_t *chip = snd_pcm_substream_chip(substream);
 	int pos;
 
-	switch (substream->number) {
-	case 0:
+	if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
 		if (!(chip->active & DAC2))
 			return 0;
 		pos = chip->dma2_size - snd_dma_residue(chip->dma2);
 		return pos >> chip->dma2_shift;
-	case 1:
+	} else {
 		if (!(chip->active & DAC1))
 			return 0;
 		pos = chip->dma1_size - snd_dma_residue(chip->dma1);
 		return pos >> chip->dma1_shift;
 	}
-	return 0;
 }
 
 static snd_pcm_uframes_t snd_es18xx_capture_pointer(snd_pcm_substream_t * substream)
@@ -827,6 +820,7 @@
 static snd_pcm_hardware_t snd_es18xx_playback =
 {
 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+				 SNDRV_PCM_INFO_RESUME |
 				 SNDRV_PCM_INFO_MMAP_VALID),
 	.formats =		(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 | 
 				 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE),
@@ -846,6 +840,7 @@
 static snd_pcm_hardware_t snd_es18xx_capture =
 {
 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+				 SNDRV_PCM_INFO_RESUME |
 				 SNDRV_PCM_INFO_MMAP_VALID),
 	.formats =		(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 | 
 				 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE),
@@ -867,20 +862,17 @@
 	snd_pcm_runtime_t *runtime = substream->runtime;
         es18xx_t *chip = snd_pcm_substream_chip(substream);
 
-	switch (substream->number) {
-	case 0:
+	if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
 		if ((chip->caps & ES18XX_DUPLEX_MONO) &&
 		    chip->capture_a_substream && 
 		    chip->capture_a_substream->runtime->channels != 1)
 			return -EAGAIN;
 		chip->playback_a_substream = substream;
-		break;
-	case 1:
+	} else if (substream->number <= 1) {
 		if (chip->capture_a_substream)
 			return -EAGAIN;
 		chip->playback_b_substream = substream;
-		break;
-	default:
+	} else {
 		snd_BUG();
 		return -EINVAL;
 	}
@@ -912,17 +904,10 @@
 {
         es18xx_t *chip = snd_pcm_substream_chip(substream);
 
-	switch (substream->number) {
-	case 0:
+	if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
 		chip->playback_a_substream = NULL;
-		break;
-	case 1:
+	else
 		chip->playback_b_substream = NULL;
-		break;
-	default:
-		snd_BUG();
-		return -EINVAL;
-	}
 	
 	snd_pcm_lib_free_pages(substream);
 	return 0;
@@ -1544,6 +1529,9 @@
 
         snd_printd("[0x%lx] ESS%x chip found\n", chip->port, chip->version);
 
+	if (chip->dma1 == chip->dma2)
+		chip->caps &= ~(ES18XX_PCM2 | ES18XX_DUPLEX_SAME);
+
         return snd_es18xx_initialize(chip);
 }
 
@@ -1600,6 +1588,8 @@
         pcm->info_flags = 0;
 	if (chip->caps & ES18XX_DUPLEX_SAME)
 		pcm->info_flags |= SNDRV_PCM_INFO_JOINT_DUPLEX;
+	if (! (chip->caps & ES18XX_PCM2))
+		pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX;
 	sprintf(pcm->name, "ESS AudioDrive ES%x", chip->version);
         chip->pcm = pcm;
 
@@ -1709,7 +1699,7 @@
 		disable_dma(chip->dma1);
 		free_dma(chip->dma1);
 	}
-	if (chip->dma2 >= 0) {
+	if (chip->dma2 >= 0 && chip->dma1 != chip->dma2) {
 		disable_dma(chip->dma2);
 		free_dma(chip->dma2);
 	}
@@ -1773,7 +1763,7 @@
 	}
 	chip->dma1 = dma1;
 
-	if (request_dma(dma2, "ES18xx DMA 2")) {
+	if (dma2 != dma1 && request_dma(dma2, "ES18xx DMA 2")) {
 		snd_es18xx_free(chip);
 		printk(KERN_ERR PFX "unable to grap DMA2 %d\n", dma2);
 		return -EBUSY;
@@ -2181,10 +2171,16 @@
 #endif
 	sprintf(card->driver, "ES%x", chip->version);
 	sprintf(card->shortname, "ESS AudioDrive ES%x", chip->version);
-	sprintf(card->longname, "%s at 0x%lx, irq %d, dma1 %d, dma2 %d",
-		card->shortname,
-		chip->port,
-		xirq, xdma1, xdma2);
+	if (xdma1 != xdma2)
+		sprintf(card->longname, "%s at 0x%lx, irq %d, dma1 %d, dma2 %d",
+			card->shortname,
+			chip->port,
+			xirq, xdma1, xdma2);
+	else
+		sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
+			card->shortname,
+			chip->port,
+			xirq, xdma1);
 	if ((err = snd_card_register(card)) < 0) {
 		snd_card_free(card);
 		return err;
diff -Nru a/sound/isa/sb/sb16.c b/sound/isa/sb/sb16.c
--- a/sound/isa/sb/sb16.c	Mon Dec 23 21:21:59 2002
+++ b/sound/isa/sb/sb16.c	Mon Dec 23 21:21:59 2002
@@ -182,6 +182,8 @@
 	/* Sound Blaster 16 PnP */
 	ISAPNP_SB16('C','T','L',0x0024,0x0031),
 	/* Sound Blaster 16 PnP */
+	ISAPNP_SB16('C','T','L',0x0025,0x0031),
+	/* Sound Blaster 16 PnP */
 	ISAPNP_SB16('C','T','L',0x0026,0x0031),
 	/* Sound Blaster 16 PnP */
 	ISAPNP_SB16('C','T','L',0x0027,0x0031),
@@ -664,7 +666,7 @@
 {
 	static unsigned __initdata nr_dev = 0;
 	int __attribute__ ((__unused__)) pnp = INT_MAX;
-	int __attribute__ ((__unused__)) csp = INT_MAX;
+	int __attribute__ ((__unused__)) xcsp = INT_MAX;
 
 	if (nr_dev >= SNDRV_CARDS)
 		return 0;
@@ -681,7 +683,7 @@
 	       get_option(&str,&mic_agc[nr_dev]) == 2
 #ifdef CONFIG_SND_SB16_CSP
 	       &&
-	       get_option(&str,&csp[nr_dev]) == 2
+	       get_option(&str,&xcsp) == 2
 #endif
 #ifdef SNDRV_SBAWE_EMU8000
 	       &&
@@ -694,8 +696,8 @@
 		isapnp[nr_dev] = pnp;
 #endif
 #ifdef CONFIG_SND_SB16_CSP
-	if (csp != INT_MAX)
-		csp[nr_dev] = csp;
+	if (xcsp != INT_MAX)
+		csp[nr_dev] = xcsp;
 #endif
 	nr_dev++;
 	return 1;
diff -Nru a/sound/isa/sb/sb16_main.c b/sound/isa/sb/sb16_main.c
--- a/sound/isa/sb/sb16_main.c	Mon Dec 23 21:21:54 2002
+++ b/sound/isa/sb/sb16_main.c	Mon Dec 23 21:21:54 2002
@@ -10,6 +10,12 @@
  *  Note: 16-bit wide is assigned to first direction which made request.
  *        With full duplex - playback is preferred with abstract layer.
  *
+ *  Note: Some chip revisions have hardware bug. Changing capture
+ *        channel from full-duplex 8bit DMA to 16bit DMA will block
+ *        16bit DMA transfers from DSP chip (capture) until 8bit transfer
+ *        to DSP chip (playback) starts. This bug can be avoided with
+ *        "16bit DMA Allocation" setting set to Playback or Capture.
+ *
  *
  *   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
diff -Nru a/sound/isa/sb/sb_mixer.c b/sound/isa/sb/sb_mixer.c
--- a/sound/isa/sb/sb_mixer.c	Mon Dec 23 21:21:53 2002
+++ b/sound/isa/sb/sb_mixer.c	Mon Dec 23 21:21:53 2002
@@ -428,13 +428,22 @@
 	return change;
 }
 
-#define SB20_CONTROLS (sizeof(snd_sb20_controls)/sizeof(snd_kcontrol_new_t))
+#define SB20_CONTROLS (sizeof(snd_sb20_controls)/sizeof(snd_kcontrol_new_t *))
 
-static snd_kcontrol_new_t snd_sb20_controls[] = {
-SB_SINGLE("Master Playback Volume", SB_DSP20_MASTER_DEV, 1, 7),
-SB_SINGLE("PCM Playback Volume", SB_DSP20_PCM_DEV, 1, 3),
-SB_SINGLE("Synth Playback Volume", SB_DSP20_FM_DEV, 1, 7),
-SB_SINGLE("CD Playback Volume", SB_DSP20_CD_DEV, 1, 7)
+static snd_kcontrol_new_t snd_sb20_ctl_master_play_vol =
+	SB_SINGLE("Master Playback Volume", SB_DSP20_MASTER_DEV, 1, 7);
+static snd_kcontrol_new_t snd_sb20_ctl_pcm_play_vol =
+	SB_SINGLE("PCM Playback Volume", SB_DSP20_PCM_DEV, 1, 3);
+static snd_kcontrol_new_t snd_sb20_ctl_synth_play_vol =
+	SB_SINGLE("Synth Playback Volume", SB_DSP20_FM_DEV, 1, 7);
+static snd_kcontrol_new_t snd_sb20_ctl_cd_play_vol =
+	SB_SINGLE("CD Playback Volume", SB_DSP20_CD_DEV, 1, 7);
+
+static snd_kcontrol_new_t *snd_sb20_controls[] = {
+	&snd_sb20_ctl_master_play_vol,
+	&snd_sb20_ctl_pcm_play_vol,
+	&snd_sb20_ctl_synth_play_vol,
+	&snd_sb20_ctl_cd_play_vol
 };
 
 #define SB20_INIT_VALUES (sizeof(snd_sb20_init_values)/sizeof(unsigned char)/2)
@@ -444,25 +453,46 @@
 	{ SB_DSP20_FM_DEV, 0 },
 };
 
-#define SBPRO_CONTROLS (sizeof(snd_sbpro_controls)/sizeof(snd_kcontrol_new_t))
+#define SBPRO_CONTROLS (sizeof(snd_sbpro_controls)/sizeof(snd_kcontrol_new_t *))
 
-static snd_kcontrol_new_t snd_sbpro_controls[] = {
-SB_DOUBLE("Master Playback Volume", SB_DSP_MASTER_DEV, SB_DSP_MASTER_DEV, 5, 1, 7),
-SB_DOUBLE("PCM Playback Volume", SB_DSP_PCM_DEV, SB_DSP_PCM_DEV, 5, 1, 7),
-SB_SINGLE("PCM Playback Filter", SB_DSP_PLAYBACK_FILT, 5, 1),
-SB_DOUBLE("Synth Playback Volume", SB_DSP_FM_DEV, SB_DSP_FM_DEV, 5, 1, 7),
-SB_DOUBLE("CD Playback Volume", SB_DSP_CD_DEV, SB_DSP_CD_DEV, 5, 1, 7),
-SB_DOUBLE("Line Playback Volume", SB_DSP_LINE_DEV, SB_DSP_LINE_DEV, 5, 1, 7),
-SB_SINGLE("Mic Playback Volume", SB_DSP_MIC_DEV, 1, 3),
-{
-	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-	.name = "Capture Source",
-	.info = snd_sb8mixer_info_mux,
-	.get = snd_sb8mixer_get_mux,
-	.put = snd_sb8mixer_put_mux,
-},
-SB_SINGLE("Capture Filter", SB_DSP_CAPTURE_FILT, 5, 1),
-SB_SINGLE("Capture Low-Pass Filter", SB_DSP_CAPTURE_FILT, 3, 1)
+static snd_kcontrol_new_t snd_sbpro_ctl_master_play_vol =
+	SB_DOUBLE("Master Playback Volume", SB_DSP_MASTER_DEV, SB_DSP_MASTER_DEV, 5, 1, 7);
+static snd_kcontrol_new_t snd_sbpro_ctl_pcm_play_vol =
+	SB_DOUBLE("PCM Playback Volume", SB_DSP_PCM_DEV, SB_DSP_PCM_DEV, 5, 1, 7);
+static snd_kcontrol_new_t snd_sbpro_ctl_pcm_play_filter =
+	SB_SINGLE("PCM Playback Filter", SB_DSP_PLAYBACK_FILT, 5, 1);
+static snd_kcontrol_new_t snd_sbpro_ctl_synth_play_vol =
+	SB_DOUBLE("Synth Playback Volume", SB_DSP_FM_DEV, SB_DSP_FM_DEV, 5, 1, 7);
+static snd_kcontrol_new_t snd_sbpro_ctl_cd_play_vol =
+	SB_DOUBLE("CD Playback Volume", SB_DSP_CD_DEV, SB_DSP_CD_DEV, 5, 1, 7);
+static snd_kcontrol_new_t snd_sbpro_ctl_line_play_vol =
+	SB_DOUBLE("Line Playback Volume", SB_DSP_LINE_DEV, SB_DSP_LINE_DEV, 5, 1, 7);
+static snd_kcontrol_new_t snd_sbpro_ctl_mic_play_vol =
+	SB_SINGLE("Mic Playback Volume", SB_DSP_MIC_DEV, 1, 3);
+static snd_kcontrol_new_t snd_sbpro_ctl_capture_source =
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.name = "Capture Source",
+		.info = snd_sb8mixer_info_mux,
+		.get = snd_sb8mixer_get_mux,
+		.put = snd_sb8mixer_put_mux,
+	};
+static snd_kcontrol_new_t snd_sbpro_ctl_capture_filter =
+	SB_SINGLE("Capture Filter", SB_DSP_CAPTURE_FILT, 5, 1);
+static snd_kcontrol_new_t snd_sbpro_ctl_capture_low_filter =
+	SB_SINGLE("Capture Low-Pass Filter", SB_DSP_CAPTURE_FILT, 3, 1);
+
+static snd_kcontrol_new_t *snd_sbpro_controls[] = {
+	&snd_sbpro_ctl_master_play_vol,
+	&snd_sbpro_ctl_pcm_play_vol,
+	&snd_sbpro_ctl_pcm_play_filter,
+	&snd_sbpro_ctl_synth_play_vol,
+	&snd_sbpro_ctl_cd_play_vol,
+	&snd_sbpro_ctl_line_play_vol,
+	&snd_sbpro_ctl_mic_play_vol,
+	&snd_sbpro_ctl_capture_source,
+	&snd_sbpro_ctl_capture_filter,
+	&snd_sbpro_ctl_capture_low_filter
 };
 
 #define SBPRO_INIT_VALUES (sizeof(snd_sbpro_init_values)/sizeof(unsigned char)/2)
@@ -473,29 +503,70 @@
 	{ SB_DSP_FM_DEV, 0 },
 };
 
-#define SB16_CONTROLS (sizeof(snd_sb16_controls)/sizeof(snd_kcontrol_new_t))
+#define SB16_CONTROLS (sizeof(snd_sb16_controls)/sizeof(snd_kcontrol_new_t *))
 
-static snd_kcontrol_new_t snd_sb16_controls[] = {
-SB_DOUBLE("Master Playback Volume", SB_DSP4_MASTER_DEV, (SB_DSP4_MASTER_DEV + 1), 3, 3, 31),
-SB_SINGLE("3D Enhancement Switch", SB_DSP4_3DSE, 0, 1),
-SB_DOUBLE("Tone Control - Bass", SB_DSP4_BASS_DEV, (SB_DSP4_BASS_DEV + 1), 4, 4, 15),
-SB_DOUBLE("Tone Control - Treble", SB_DSP4_TREBLE_DEV, (SB_DSP4_TREBLE_DEV + 1), 4, 4, 15),
-SB_DOUBLE("PCM Playback Volume", SB_DSP4_PCM_DEV, (SB_DSP4_PCM_DEV + 1), 3, 3, 31),
-SB16_INPUT_SW("Synth Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 6, 5),
-SB_DOUBLE("Synth Playback Volume", SB_DSP4_SYNTH_DEV, (SB_DSP4_SYNTH_DEV + 1), 3, 3, 31),
-SB16_INPUT_SW("CD Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 2, 1),
-SB_DOUBLE("CD Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 2, 1, 1),
-SB_DOUBLE("CD Playback Volume", SB_DSP4_CD_DEV, (SB_DSP4_CD_DEV + 1), 3, 3, 31),
-SB16_INPUT_SW("Line Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 4, 3),
-SB_DOUBLE("Line Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3, 1),
-SB_DOUBLE("Line Playback Volume", SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31),
-SB_DOUBLE("Mic Capture Switch", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 0, 0, 1),
-SB_SINGLE("Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1),
-SB_SINGLE("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31),
-SB_SINGLE("PC Speaker Volume", SB_DSP4_SPEAKER_DEV, 6, 3),
-SB_DOUBLE("Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3),
-SB_DOUBLE("Playback Volume", SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3),
-SB_SINGLE("Auto Mic Gain", SB_DSP4_MIC_AGC, 0, 1)
+static snd_kcontrol_new_t snd_sb16_ctl_master_play_vol =
+	SB_DOUBLE("Master Playback Volume", SB_DSP4_MASTER_DEV, (SB_DSP4_MASTER_DEV + 1), 3, 3, 31);
+static snd_kcontrol_new_t snd_sb16_ctl_3d_enhance_switch =
+	SB_SINGLE("3D Enhancement Switch", SB_DSP4_3DSE, 0, 1);
+static snd_kcontrol_new_t snd_sb16_ctl_tone_bass =
+	SB_DOUBLE("Tone Control - Bass", SB_DSP4_BASS_DEV, (SB_DSP4_BASS_DEV + 1), 4, 4, 15);
+static snd_kcontrol_new_t snd_sb16_ctl_tone_treble =
+	SB_DOUBLE("Tone Control - Treble", SB_DSP4_TREBLE_DEV, (SB_DSP4_TREBLE_DEV + 1), 4, 4, 15);
+static snd_kcontrol_new_t snd_sb16_ctl_pcm_play_vol =
+	SB_DOUBLE("PCM Playback Volume", SB_DSP4_PCM_DEV, (SB_DSP4_PCM_DEV + 1), 3, 3, 31);
+static snd_kcontrol_new_t snd_sb16_ctl_synth_capture_route =
+	SB16_INPUT_SW("Synth Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 6, 5);
+static snd_kcontrol_new_t snd_sb16_ctl_synth_play_vol =
+	SB_DOUBLE("Synth Playback Volume", SB_DSP4_SYNTH_DEV, (SB_DSP4_SYNTH_DEV + 1), 3, 3, 31);
+static snd_kcontrol_new_t snd_sb16_ctl_cd_capture_route =
+	SB16_INPUT_SW("CD Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 2, 1);
+static snd_kcontrol_new_t snd_sb16_ctl_cd_play_switch =
+	SB_DOUBLE("CD Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 2, 1, 1);
+static snd_kcontrol_new_t snd_sb16_ctl_cd_play_vol =
+	SB_DOUBLE("CD Playback Volume", SB_DSP4_CD_DEV, (SB_DSP4_CD_DEV + 1), 3, 3, 31);
+static snd_kcontrol_new_t snd_sb16_ctl_line_capture_route =
+	SB16_INPUT_SW("Line Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 4, 3);
+static snd_kcontrol_new_t snd_sb16_ctl_line_play_switch =
+	SB_DOUBLE("Line Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3, 1);
+static snd_kcontrol_new_t snd_sb16_ctl_line_play_vol =
+	SB_DOUBLE("Line Playback Volume", SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31);
+static snd_kcontrol_new_t snd_sb16_ctl_mic_capture_route =
+	SB16_INPUT_SW("Mic Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 0, 0);
+static snd_kcontrol_new_t snd_sb16_ctl_mic_play_switch =
+	SB_SINGLE("Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1);
+static snd_kcontrol_new_t snd_sb16_ctl_mic_play_vol =
+	SB_SINGLE("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31);
+static snd_kcontrol_new_t snd_sb16_ctl_pc_speaker_vol =
+	SB_SINGLE("PC Speaker Volume", SB_DSP4_SPEAKER_DEV, 6, 3);
+static snd_kcontrol_new_t snd_sb16_ctl_capture_vol =
+	SB_DOUBLE("Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3);
+static snd_kcontrol_new_t snd_sb16_ctl_play_vol =
+	SB_DOUBLE("Playback Volume", SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3);
+static snd_kcontrol_new_t snd_sb16_ctl_auto_mic_gain =
+	SB_SINGLE("Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1);
+
+static snd_kcontrol_new_t *snd_sb16_controls[] = {
+	&snd_sb16_ctl_master_play_vol,
+	&snd_sb16_ctl_3d_enhance_switch,
+	&snd_sb16_ctl_tone_bass,
+	&snd_sb16_ctl_tone_treble,
+	&snd_sb16_ctl_pcm_play_vol,
+	&snd_sb16_ctl_synth_capture_route,
+	&snd_sb16_ctl_synth_play_vol,
+	&snd_sb16_ctl_cd_capture_route,
+	&snd_sb16_ctl_cd_play_switch,
+	&snd_sb16_ctl_cd_play_vol,
+	&snd_sb16_ctl_line_capture_route,
+	&snd_sb16_ctl_line_play_switch,
+	&snd_sb16_ctl_line_play_vol,
+	&snd_sb16_ctl_mic_capture_route,
+	&snd_sb16_ctl_mic_play_switch,
+	&snd_sb16_ctl_mic_play_vol,
+	&snd_sb16_ctl_pc_speaker_vol,
+	&snd_sb16_ctl_capture_vol,
+	&snd_sb16_ctl_play_vol,
+	&snd_sb16_ctl_auto_mic_gain
 };
 
 #define SB16_INIT_VALUES (sizeof(snd_sb16_init_values)/sizeof(unsigned char)/2)
@@ -513,28 +584,50 @@
 	{ SB_DSP4_SPEAKER_DEV, 0 },
 };
 
-#define DT019X_CONTROLS (sizeof(snd_dt019x_controls)/sizeof(snd_kcontrol_new_t))
+#define DT019X_CONTROLS (sizeof(snd_dt019x_controls)/sizeof(snd_kcontrol_new_t *))
 
-static snd_kcontrol_new_t snd_dt019x_controls[] = {
-SB_DOUBLE("Master Playback Volume", SB_DT019X_MASTER_DEV, SB_DT019X_MASTER_DEV, 4,0, 15),
-SB_DOUBLE("PCM Playback Volume", SB_DT019X_PCM_DEV, SB_DT019X_PCM_DEV, 4,0, 15),
-SB_DOUBLE("Synth Playback Volume", SB_DT019X_SYNTH_DEV, SB_DT019X_SYNTH_DEV, 4,0, 15),
-SB_DOUBLE("CD Playback Volume", SB_DT019X_CD_DEV, SB_DT019X_CD_DEV, 4,0, 15),
-SB_SINGLE("Mic Playback Volume", SB_DT019X_MIC_DEV, 4, 7),
-SB_SINGLE("PC Speaker Volume", SB_DT019X_SPKR_DEV, 0,  7),
-SB_DOUBLE("Line Playback Volume", SB_DT019X_LINE_DEV, SB_DT019X_LINE_DEV, 4,0, 15),
-SB_SINGLE("Mic Playback Switch", SB_DT019X_OUTPUT_SW1, 0, 1),
-SB_DOUBLE("CD Playback Switch", SB_DT019X_OUTPUT_SW1, SB_DT019X_OUTPUT_SW1, 2,1, 1),
-SB_DOUBLE("Line Playback Switch", SB_DT019X_OUTPUT_SW1, SB_DT019X_OUTPUT_SW1, 4,3, 1),
-SB_DOUBLE("PCM Playback Switch", SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 2,1, 1),
-SB_DOUBLE("Synth Playback Switch", SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 4,3, 1),
-{
-	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-	.name = "Capture Source",
-	.info = snd_dt019x_input_sw_info,
-	.get = snd_dt019x_input_sw_get,
-	.put = snd_dt019x_input_sw_put,
-},
+
+static snd_kcontrol_new_t snd_dt019x_ctl_master_play_vol =
+	SB_DOUBLE("Master Playback Volume", SB_DT019X_MASTER_DEV, SB_DT019X_MASTER_DEV, 4,0, 15);
+static snd_kcontrol_new_t snd_dt019x_ctl_pcm_play_vol =
+	SB_DOUBLE("PCM Playback Volume", SB_DT019X_PCM_DEV, SB_DT019X_PCM_DEV, 4,0, 15);
+static snd_kcontrol_new_t snd_dt019x_ctl_synth_play_vol =
+	SB_DOUBLE("Synth Playback Volume", SB_DT019X_SYNTH_DEV, SB_DT019X_SYNTH_DEV, 4,0, 15);
+static snd_kcontrol_new_t snd_dt019x_ctl_cd_play_vol =
+	SB_DOUBLE("CD Playback Volume", SB_DT019X_CD_DEV, SB_DT019X_CD_DEV, 4,0, 15);
+static snd_kcontrol_new_t snd_dt019x_ctl_mic_play_vol =
+	SB_SINGLE("Mic Playback Volume", SB_DT019X_MIC_DEV, 4, 7);
+static snd_kcontrol_new_t snd_dt019x_ctl_pc_speaker_vol =
+	SB_SINGLE("PC Speaker Volume", SB_DT019X_SPKR_DEV, 0,  7);
+static snd_kcontrol_new_t snd_dt019x_ctl_line_play_vol =
+	SB_DOUBLE("Line Playback Volume", SB_DT019X_LINE_DEV, SB_DT019X_LINE_DEV, 4,0, 15);
+static snd_kcontrol_new_t snd_dt019x_ctl_pcm_play_switch =
+	SB_DOUBLE("PCM Playback Switch", SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 2,1, 1);
+static snd_kcontrol_new_t snd_dt019x_ctl_synth_play_switch =
+	SB_DOUBLE("Synth Playback Switch", SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 4,3, 1);
+static snd_kcontrol_new_t snd_dt019x_ctl_capture_source =
+	{
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.name = "Capture Source",
+		.info = snd_dt019x_input_sw_info,
+		.get = snd_dt019x_input_sw_get,
+		.put = snd_dt019x_input_sw_put,
+	};
+
+static snd_kcontrol_new_t *snd_dt019x_controls[] = {
+	&snd_dt019x_ctl_master_play_vol,
+	&snd_dt019x_ctl_pcm_play_vol,
+	&snd_dt019x_ctl_synth_play_vol,
+	&snd_dt019x_ctl_cd_play_vol,
+	&snd_dt019x_ctl_mic_play_vol,
+	&snd_dt019x_ctl_pc_speaker_vol,
+	&snd_dt019x_ctl_line_play_vol,
+	&snd_sb16_ctl_mic_play_switch,
+	&snd_sb16_ctl_cd_play_switch,
+	&snd_sb16_ctl_line_play_switch,
+	&snd_dt019x_ctl_pcm_play_switch,
+	&snd_dt019x_ctl_synth_play_switch,
+	&snd_dt019x_ctl_capture_source
 };
 
 #define DT019X_INIT_VALUES (sizeof(snd_dt019x_init_values)/sizeof(unsigned char)/2)
@@ -546,13 +639,92 @@
         { SB_DT019X_CD_DEV, 0 },
         { SB_DT019X_MIC_DEV, 0 },	/* Includes PC-speaker in high nibble */
         { SB_DT019X_LINE_DEV, 0 },
-        { SB_DT019X_OUTPUT_SW1, 0 },
+        { SB_DSP4_OUTPUT_SW, 0 },
         { SB_DT019X_OUTPUT_SW2, 0 },
         { SB_DT019X_CAPTURE_SW, 0x06 },
 };
 
+/* FIXME: SB_ALS4000_MONO_IO_CTRL needs output select ctrl ! */
+static snd_kcontrol_new_t snd_als4000_ctl_mono_output_switch =
+	SB_SINGLE("Mono Output Switch", SB_ALS4000_MONO_IO_CTRL, 5, 1);
+/* FIXME: mono input switch also available on DT019X ? */
+static snd_kcontrol_new_t snd_als4000_ctl_mono_input_switch =
+	SB_SINGLE("Mono Input Switch", SB_DT019X_OUTPUT_SW2, 0, 1);
+static snd_kcontrol_new_t snd_als4000_ctl_mic_20db_boost =
+	SB_SINGLE("Mic Boost (+20dB)", SB_ALS4000_MIC_IN_GAIN, 0, 0x03);
+static snd_kcontrol_new_t snd_als4000_ctl_mixer_out_to_in =
+	SB_SINGLE("Mixer Out To In", SB_ALS4000_MIC_IN_GAIN, 7, 0x01);
+/* FIXME: 3D needs much more sophisticated controls, many more features ! */
+static snd_kcontrol_new_t snd_als4000_ctl_3d_output_switch =
+	SB_SINGLE("3D Output Switch", SB_ALS4000_3D_SND_FX, 6, 0x01);
+static snd_kcontrol_new_t snd_als4000_ctl_3d_output_ratio =
+	SB_SINGLE("3D Output Ratio", SB_ALS4000_3D_SND_FX, 0, 0x07);
+static snd_kcontrol_new_t snd_als4000_ctl_3d_poweroff_switch =
+	SB_SINGLE("3D PowerOff Switch", SB_ALS4000_3D_TIME_DELAY, 4, 0x01);
+static snd_kcontrol_new_t snd_als4000_ctl_3d_delay =
+	SB_SINGLE("3D Delay", SB_ALS4000_3D_TIME_DELAY, 0, 0x0f);
+#if NOT_AVAILABLE
+static snd_kcontrol_new_t snd_als4000_ctl_fmdac =
+	SB_SINGLE("FMDAC Switch (Option ?)", SB_ALS4000_FMDAC, 0, 0x01);
+static snd_kcontrol_new_t snd_als4000_ctl_qsound =
+	SB_SINGLE("QSound Mode", SB_ALS4000_QSOUND, 1, 0x1f);
+#endif
+
+#define ALS4000_CONTROLS (sizeof(snd_als4000_controls)/sizeof(snd_kcontrol_new_t *))
+
+static snd_kcontrol_new_t *snd_als4000_controls[] = {
+	&snd_sb16_ctl_master_play_vol,
+	&snd_dt019x_ctl_pcm_play_switch,
+	&snd_sb16_ctl_pcm_play_vol,
+	&snd_sb16_ctl_synth_capture_route,
+	&snd_dt019x_ctl_synth_play_switch,
+	&snd_sb16_ctl_synth_play_vol,
+	&snd_sb16_ctl_cd_capture_route,
+	&snd_sb16_ctl_cd_play_switch,
+	&snd_sb16_ctl_cd_play_vol,
+	&snd_sb16_ctl_line_capture_route,
+	&snd_sb16_ctl_line_play_switch,
+	&snd_sb16_ctl_line_play_vol,
+	&snd_sb16_ctl_mic_capture_route,
+	&snd_als4000_ctl_mic_20db_boost,
+	&snd_sb16_ctl_auto_mic_gain,
+	&snd_sb16_ctl_mic_play_switch,
+	&snd_sb16_ctl_mic_play_vol,
+	&snd_sb16_ctl_pc_speaker_vol,
+	&snd_sb16_ctl_capture_vol,
+	&snd_sb16_ctl_play_vol,
+	&snd_als4000_ctl_mono_output_switch,
+	&snd_als4000_ctl_mono_input_switch,
+	&snd_als4000_ctl_mixer_out_to_in,
+	&snd_als4000_ctl_3d_output_switch,
+	&snd_als4000_ctl_3d_output_ratio,
+	&snd_als4000_ctl_3d_delay,
+	&snd_als4000_ctl_3d_poweroff_switch,
+#if NOT_AVAILABLE
+	&snd_als4000_ctl_fmdac,
+	&snd_als4000_ctl_qsound,
+#endif
+};
+
+#define ALS4000_INIT_VALUES (sizeof(snd_als4000_init_values)/sizeof(unsigned char)/2)
+
+static unsigned char snd_als4000_init_values[][2] = {
+	{ SB_DSP4_MASTER_DEV + 0, 0 },
+	{ SB_DSP4_MASTER_DEV + 1, 0 },
+	{ SB_DSP4_PCM_DEV + 0, 0 },
+	{ SB_DSP4_PCM_DEV + 1, 0 },
+	{ SB_DSP4_SYNTH_DEV + 0, 0 },
+	{ SB_DSP4_SYNTH_DEV + 1, 0 },
+	{ SB_DSP4_SPEAKER_DEV, 0 },
+	{ SB_DSP4_OUTPUT_SW, 0 },
+	{ SB_DSP4_INPUT_LEFT, 0 },
+	{ SB_DSP4_INPUT_RIGHT, 0 },
+	{ SB_DT019X_OUTPUT_SW2, 0 },
+	{ SB_ALS4000_MIC_IN_GAIN, 0 },
+};
+
 static int snd_sbmixer_init(sb_t *chip,
-			    snd_kcontrol_new_t *controls,
+			    snd_kcontrol_new_t **controls,
 			    int controls_count,
 			    unsigned char map[][2],
 			    int map_count,
@@ -575,7 +747,7 @@
 	}
 
 	for (idx = 0; idx < controls_count; idx++) {
-		if ((err = snd_ctl_add(card, snd_ctl_new1(&controls[idx], chip))) < 0)
+		if ((err = snd_ctl_add(card, snd_ctl_new1(controls[idx], chip))) < 0)
 			return err;
 	}
 	snd_component_add(card, name);
@@ -612,11 +784,17 @@
 		break;
 	case SB_HW_16:
 	case SB_HW_ALS100:
-	case SB_HW_ALS4000:
 		if ((err = snd_sbmixer_init(chip,
 					    snd_sb16_controls, SB16_CONTROLS,
 					    snd_sb16_init_values, SB16_INIT_VALUES,
 					    "CTL1745")) < 0)
+			return err;
+		break;
+	case SB_HW_ALS4000:
+		if ((err = snd_sbmixer_init(chip,
+					    snd_als4000_controls, ALS4000_CONTROLS,
+					    snd_als4000_init_values, ALS4000_INIT_VALUES,
+					    "ALS4000")) < 0)
 			return err;
 		break;
 	case SB_HW_DT019X:
diff -Nru a/sound/oss/Kconfig b/sound/oss/Kconfig
--- a/sound/oss/Kconfig	Mon Dec 23 21:21:59 2002
+++ b/sound/oss/Kconfig	Mon Dec 23 21:21:59 2002
@@ -293,7 +293,7 @@
 	depends on SOUND_PRIME && SOUND_MSNDCLAS=y
 
 config MSNDCLAS_HAVE_BOOT
-	bool "Have MSNDINIT.BIN firmware file"
+	bool
 	depends on SOUND_MSNDCLAS=y
 	default y
 
@@ -355,7 +355,7 @@
 	depends on SOUND_PRIME && SOUND_MSNDPIN=y
 
 config MSNDPIN_HAVE_BOOT
-	bool "Have PNDSPINI.BIN firmware file"
+	bool
 	depends on SOUND_MSNDPIN=y
 	default y
 
diff -Nru a/sound/pci/Kconfig b/sound/pci/Kconfig
--- a/sound/pci/Kconfig	Mon Dec 23 21:21:53 2002
+++ b/sound/pci/Kconfig	Mon Dec 23 21:21:53 2002
@@ -104,13 +104,13 @@
 
 config SND_ENS1370
 	tristate "(Creative) Ensoniq AudioPCI 1370"
-	depends on SND
+	depends on SND && SOUND_GAMEPORT
 	help
 	  Say 'Y' or 'M' to include support for Ensoniq AudioPCI ES1370.
 
 config SND_ENS1371
 	tristate "(Creative) Ensoniq AudioPCI 1371/1373"
-	depends on SND
+	depends on SND && SOUND_GAMEPORT
 	help
 	  Say 'Y' or 'M' to include support for Ensoniq AudioPCI ES1371 and
 	  Sound Blaster PCI 64 or 128 soundcards.
diff -Nru a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
--- a/sound/pci/ac97/ac97_codec.c	Mon Dec 23 21:21:53 2002
+++ b/sound/pci/ac97/ac97_codec.c	Mon Dec 23 21:21:53 2002
@@ -126,6 +126,7 @@
 { 0x48525300, 0xffffff00, "HMP9701",		NULL },
 { 0x49434501, 0xffffffff, "ICE1230",		NULL },
 { 0x49434511, 0xffffffff, "ICE1232",		NULL }, // alias VIA VT1611A?
+{ 0x49434551, 0xffffffff, "VT1616", 		NULL }, 
 { 0x49544520, 0xffffffff, "IT2226E",		NULL },
 { 0x4e534300, 0xffffffff, "LM4540/43/45/46/48",	NULL }, // only guess --jk
 { 0x4e534331, 0xffffffff, "LM4549",		NULL },
@@ -145,7 +146,7 @@
 { 0x574d4c05, 0xffffffff, "WM9705",		NULL },	// patch?
 { 0x594d4800, 0xffffffff, "YMF743",		NULL },
 { 0x594d4802, 0xffffffff, "YMF752",		NULL },
-{ 0x594d4803, 0xffffffff, "YMF753",		NULL },
+{ 0x594d4803, 0xffffffff, "YMF753",		patch_yamaha_ymf753 },
 { 0x83847600, 0xffffffff, "STAC9700/83/84",	NULL },
 { 0x83847604, 0xffffffff, "STAC9701/3/4/5",	NULL },
 { 0x83847605, 0xffffffff, "STAC9704",		NULL },
@@ -678,6 +679,13 @@
 static const snd_kcontrol_new_t snd_ac97_control_eapd =
 AC97_SINGLE("External Amplifier Power Down", AC97_POWERDOWN, 15, 1, 0);
 
+static const snd_kcontrol_new_t snd_ac97_controls_vt1616[] = {
+AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
+AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
+AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
+AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
+};
+
 static int snd_ac97_spdif_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
 {
 	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
@@ -933,6 +941,151 @@
 #endif
 };
 
+/* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
+
+/* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */
+static int snd_ac97_ymf753_info_speaker(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+	static char *texts[3] = {
+		"Standard", "Small", "Smaller"
+	};
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+	uinfo->count = 1;
+	uinfo->value.enumerated.items = 3;
+	if (uinfo->value.enumerated.item > 2)
+		uinfo->value.enumerated.item = 2;
+	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
+	return 0;
+}
+
+static int snd_ac97_ymf753_get_speaker(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
+	unsigned short val;
+
+	val = ac97->regs[AC97_YMF753_3D_MODE_SEL];
+	val = (val >> 10) & 3;
+	if (val > 0)	/* 0 = invalid */
+		val--;
+	ucontrol->value.enumerated.item[0] = val;
+	return 0;
+}
+
+static int snd_ac97_ymf753_put_speaker(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
+	unsigned short val;
+
+	if (ucontrol->value.enumerated.item[0] > 2)
+		return -EINVAL;
+	val = (ucontrol->value.enumerated.item[0] + 1) << 10;
+	return snd_ac97_update(ac97, AC97_YMF753_3D_MODE_SEL, val);
+}
+
+static const snd_kcontrol_new_t snd_ac97_ymf753_controls_speaker =
+{
+	iface: SNDRV_CTL_ELEM_IFACE_MIXER,
+	name: "3D Control - Speaker",
+	info: snd_ac97_ymf753_info_speaker,
+	get: snd_ac97_ymf753_get_speaker,
+	put: snd_ac97_ymf753_put_speaker,
+};
+
+/* It is possible to indicate to the Yamaha YMF753 the source to direct to the S/PDIF output. */
+static int snd_ac97_ymf753_spdif_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+	static char *texts[2] = { "AC-Link", "A/D Converter" };
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+	uinfo->count = 1;
+	uinfo->value.enumerated.items = 2;
+	if (uinfo->value.enumerated.item > 1)
+		uinfo->value.enumerated.item = 1;
+	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
+	return 0;
+}
+
+static int snd_ac97_ymf753_spdif_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
+	unsigned short val;
+
+	val = ac97->regs[AC97_YMF753_DIT_CTRL2];
+	ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
+	return 0;
+}
+
+static int snd_ac97_ymf753_spdif_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
+	unsigned short val;
+
+	if (ucontrol->value.enumerated.item[0] > 1)
+		return -EINVAL;
+	val = ucontrol->value.enumerated.item[0] << 1;
+	return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0002, val);
+}
+
+/* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
+   The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
+   By default, no output pin is selected, and the S/PDIF signal is not output.
+   There is also a bit to mute S/PDIF output in a vendor-specific register. */
+static int snd_ac97_ymf753_spdif_output_pin_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+	static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" };
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+	uinfo->count = 1;
+	uinfo->value.enumerated.items = 3;
+	if (uinfo->value.enumerated.item > 2)
+		uinfo->value.enumerated.item = 2;
+	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
+	return 0;
+}
+
+static int snd_ac97_ymf753_spdif_output_pin_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
+	unsigned short val;
+
+	val = ac97->regs[AC97_YMF753_DIT_CTRL2];
+	ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
+	return 0;
+}
+
+static int snd_ac97_ymf753_spdif_output_pin_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
+	unsigned short val;
+
+	if (ucontrol->value.enumerated.item[0] > 2)
+		return -EINVAL;
+	val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
+	      (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
+	return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0028, val);
+	/* The following can be used to direct S/PDIF output to pin 47 (EAPD).
+	   snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
+}
+
+static const snd_kcontrol_new_t snd_ac97_ymf753_controls_spdif[3] = {
+	{
+		iface: SNDRV_CTL_ELEM_IFACE_MIXER,
+		name: SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
+		info: snd_ac97_ymf753_spdif_source_info,
+		get: snd_ac97_ymf753_spdif_source_get,
+		put: snd_ac97_ymf753_spdif_source_put,
+	},
+	{
+		iface: SNDRV_CTL_ELEM_IFACE_MIXER,
+		name: SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
+		info: snd_ac97_ymf753_spdif_output_pin_info,
+		get: snd_ac97_ymf753_spdif_output_pin_get,
+		put: snd_ac97_ymf753_spdif_output_pin_put,
+	},
+	AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE,NONE) "Mute", AC97_YMF753_DIT_CTRL2, 2, 1, 1)
+};
+
 /*
  *
  */
@@ -1163,9 +1316,14 @@
 	
 	/* build master tone controls */
 	if (snd_ac97_try_volume_mix(ac97, AC97_MASTER_TONE)) {
-		for (idx = 0; idx < 2; idx++)
-			if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_tone[idx], ac97))) < 0)
+		for (idx = 0; idx < 2; idx++) {
+			if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_tone[idx], ac97))) < 0)
 				return err;
+			if (ac97->id == AC97_ID_YMF753) {
+				kctl->private_value &= ~(0xff << 16);
+				kctl->private_value |= 7 << 16;
+			}
+		}
 		snd_ac97_write_cache(ac97, AC97_MASTER_TONE, 0x0f0f);
 	}
 	
@@ -1339,6 +1497,16 @@
 		kctl->private_value = AC97_3D_CONTROL | (3 << 16);
 		snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
 		break;
+	case AC97_ID_YMF753:
+		if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
+			return err;
+		strcpy(kctl->id.name, "3D Control - Wide");
+		kctl->private_value = AC97_3D_CONTROL | (9 << 8) | (7 << 16);
+		snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
+		if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker, ac97))) < 0)
+			return err;
+		snd_ac97_write_cache(ac97, AC97_YMF753_3D_MODE_SEL, 0x0c00);
+		break;
 	default:
 		if (snd_ac97_try_volume_mix(ac97, AC97_3D_CONTROL)) {
 			unsigned short val;
@@ -1366,7 +1534,7 @@
 					return err;
 			if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_cirrus_controls_spdif[0], ac97))) < 0)
 				return err;
-			switch (ac97->id) {
+			switch (ac97->id & AC97_ID_CS_MASK) {
 			case AC97_ID_CS4205:
 				if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_cirrus_controls_spdif[1], ac97))) < 0)
 					return err;
@@ -1390,6 +1558,11 @@
 			for (idx = 0; idx < 5; idx++)
 				if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_spdif[idx], ac97))) < 0)
 					return err;
+			if (ac97->id == AC97_ID_YMF753) {
+				for (idx = 0; idx < 3; idx++)
+					if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_ymf753_controls_spdif[idx], ac97))) < 0)
+						return err;
+			}
 			/* set default PCM S/PDIF params */
 			/* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
 			snd_ac97_write_cache(ac97, AC97_SPDIF, 0x2a20);
@@ -1418,6 +1591,14 @@
 			if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_alc650[idx], ac97))) < 0)
 				return err;
 		break;
+	case AC97_ID_VT1616:
+		if (snd_ac97_try_bit(ac97, 0x5a, 9))
+			if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_vt1616[0], ac97))) < 0)
+				return err;
+		for (idx = 1; idx < ARRAY_SIZE(snd_ac97_controls_vt1616); idx++)
+			if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_vt1616[idx], ac97))) < 0)
+				return err;
+		break;
 	default:
 		/* nothing */
 		break;
@@ -1697,7 +1878,8 @@
 	if ((ac97->scaps & AC97_SCAP_AUDIO) == 0)
 		goto __modem;
 
-	val = snd_ac97_read(ac97, AC97_RESET);
+	// val = snd_ac97_read(ac97, AC97_RESET);
+	val = ac97->caps;
 	snd_iprintf(buffer, "Capabilities     :%s%s%s%s%s%s\n",
 	    	    val & AC97_BC_DEDICATED_MIC ? " -dedicated MIC PCM IN channel-" : "",
 		    val & AC97_BC_RESERVED1 ? " -reserved1-" : "",
@@ -1946,6 +2128,45 @@
  *  PCM support
  */
 
+static int set_spdif_rate(ac97_t *ac97, unsigned short rate)
+{
+	unsigned short old, bits, reg;
+
+	if (! (ac97->ext_id & AC97_EI_SPDIF))
+		return -ENODEV;
+
+	if (ac97->flags & AC97_CS_SPDIF) {
+		switch (rate) {
+		case 48000: bits = 0; break;
+		case 44100: bits = 1 << AC97_SC_SPSR_SHIFT; break;
+		default: /* invalid - disable output */
+			snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
+			return -EINVAL;
+		}
+		reg = AC97_CSR_SPDIF;
+	} else {
+		switch (rate) {
+		case 44100: bits = AC97_SC_SPSR_44K; break;
+		case 48000: bits = AC97_SC_SPSR_48K; break;
+		case 32000: bits = AC97_SC_SPSR_32K; break;
+		default: /* invalid - disable output */
+			snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
+			return -EINVAL;
+		}
+		reg = AC97_SPDIF;
+	}
+
+	spin_lock(&ac97->reg_lock);
+	old = ac97->regs[reg] & ~AC97_SC_SPSR_MASK;
+	if (old != bits) {
+		snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
+		snd_ac97_update_bits_nolock(ac97, reg, AC97_SC_SPSR_MASK, bits);
+	}
+	snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF);
+	spin_unlock(&ac97->reg_lock);
+	return 0;
+}
+
 int snd_ac97_set_rate(ac97_t *ac97, int reg, unsigned short rate)
 {
 	unsigned short mask;
@@ -1971,8 +2192,9 @@
 				return -EINVAL;
 		break;
 	case AC97_SPDIF:
-		return 0;
-	default: return -EINVAL;
+		return set_spdif_rate(ac97, rate);
+	default:
+		return -EINVAL;
 	}
 	tmp = ((unsigned int)rate * ac97->clock) / 48000;
 	if (tmp > 65535)
diff -Nru a/sound/pci/ac97/ac97_id.h b/sound/pci/ac97/ac97_id.h
--- a/sound/pci/ac97/ac97_id.h	Mon Dec 23 21:22:00 2002
+++ b/sound/pci/ac97/ac97_id.h	Mon Dec 23 21:22:00 2002
@@ -43,4 +43,7 @@
 #define AC97_ID_CS4299		0x43525930
 #define AC97_ID_CS4201		0x43525948
 #define AC97_ID_CS4205		0x43525958
+#define AC97_ID_CS_MASK		0xfffffff8	/* bit 0-2: rev */
 #define AC97_ID_ALC650		0x414c4720
+#define AC97_ID_YMF753		0x594d4803
+#define AC97_ID_VT1616		0x49434551
diff -Nru a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
--- a/sound/pci/ac97/ac97_patch.c	Mon Dec 23 21:22:00 2002
+++ b/sound/pci/ac97/ac97_patch.c	Mon Dec 23 21:22:00 2002
@@ -37,6 +37,20 @@
  *  Chip specific initialization
  */
 
+int patch_yamaha_ymf753(ac97_t * ac97)
+{
+	/* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
+	   This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
+	   The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
+	   The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
+	   By default, no output pin is selected, and the S/PDIF signal is not output.
+	   There is also a bit to mute S/PDIF output in a vendor-specific register.
+	*/
+	ac97->caps |= AC97_BC_BASS_TREBLE;
+	ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
+	return 0;
+}
+
 int patch_wolfson00(ac97_t * ac97)
 {
 	/* This sequence is suspect because it was designed for
diff -Nru a/sound/pci/ac97/ac97_patch.h b/sound/pci/ac97/ac97_patch.h
--- a/sound/pci/ac97/ac97_patch.h	Mon Dec 23 21:21:50 2002
+++ b/sound/pci/ac97/ac97_patch.h	Mon Dec 23 21:21:50 2002
@@ -22,6 +22,7 @@
  *
  */
 
+int patch_yamaha_ymf753(ac97_t * ac97);
 int patch_wolfson00(ac97_t * ac97);
 int patch_wolfson03(ac97_t * ac97);
 int patch_wolfson04(ac97_t * ac97);
diff -Nru a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c
--- a/sound/pci/ali5451/ali5451.c	Mon Dec 23 21:22:00 2002
+++ b/sound/pci/ali5451/ali5451.c	Mon Dec 23 21:22:00 2002
@@ -529,7 +529,8 @@
 		udelay(5000);
 	}
 
-	return -1;
+	snd_printk(KERN_WARNING "ali5451: reset time out\n");
+	return 0;
 }
 
 #ifdef CODEC_RESET
@@ -1209,59 +1210,64 @@
 	unsigned int what, whati, capture_flag;
 	snd_ali_voice_t *pvoice = NULL, *evoice = NULL;
 	unsigned int val;
+	int do_start;
 
 	switch (cmd) {
 	case SNDRV_PCM_TRIGGER_START:
+	case SNDRV_PCM_TRIGGER_RESUME:
+		do_start = 1; break;
 	case SNDRV_PCM_TRIGGER_STOP:
-	{
-		what = whati = capture_flag = 0;
-		s = substream;
-		do {
-			if ((ali_t *) _snd_pcm_chip(s->pcm) == codec) {
-				pvoice = (snd_ali_voice_t *) s->runtime->private_data;
-				evoice = pvoice->extra;
-				what |= 1 << (pvoice->number & 0x1f);
-				if (evoice == NULL) {
-					whati |= 1 << (pvoice->number & 0x1f);
-				} else {
-					whati |= 1 << (evoice->number & 0x1f);
-					what |= 1 << (evoice->number & 0x1f);
-				}
-				if (cmd == SNDRV_PCM_TRIGGER_START) {
-					pvoice->running = 1;
-					if (evoice != NULL)
-						evoice->running = 1;
-				}
-				snd_pcm_trigger_done(s, substream);
-				if (pvoice->mode)
-					capture_flag = 1;
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+		do_start = 0; break;
+	default:
+		return -EINVAL;
+	}
+
+	what = whati = capture_flag = 0;
+	s = substream;
+	do {
+		if ((ali_t *) _snd_pcm_chip(s->pcm) == codec) {
+			pvoice = (snd_ali_voice_t *) s->runtime->private_data;
+			evoice = pvoice->extra;
+			what |= 1 << (pvoice->number & 0x1f);
+			if (evoice == NULL) {
+				whati |= 1 << (pvoice->number & 0x1f);
+			} else {
+				whati |= 1 << (evoice->number & 0x1f);
+				what |= 1 << (evoice->number & 0x1f);
 			}
-			s = s->link_next;
-		} while (s != substream);
-		spin_lock(&codec->reg_lock);
-		if (cmd == SNDRV_PCM_TRIGGER_STOP) {
-			outl(what, ALI_REG(codec, ALI_STOP));
-			pvoice->running = 0;
-			if (evoice != NULL)
-				evoice->running = 0;
-		}
-		val = inl(ALI_REG(codec, ALI_AINTEN));
-		if (cmd == SNDRV_PCM_TRIGGER_START) {
-			val |= whati;
-		} else {
-			val &= ~whati;
-		}
-		outl(val, ALI_REG(codec, ALI_AINTEN));
-		if (cmd == SNDRV_PCM_TRIGGER_START) {
-			outl(what, ALI_REG(codec, ALI_START));
+			if (do_start) {
+				pvoice->running = 1;
+				if (evoice != NULL)
+					evoice->running = 1;
+			} else {
+				pvoice->running = 0;
+				if (evoice != NULL)
+					evoice->running = 0;
+			}
+			snd_pcm_trigger_done(s, substream);
+			if (pvoice->mode)
+				capture_flag = 1;
 		}
-		snd_ali_printk("trigger: what=%xh whati=%xh\n",what,whati);
-		spin_unlock(&codec->reg_lock);
-		break;
+		s = s->link_next;
+	} while (s != substream);
+	spin_lock(&codec->reg_lock);
+	if (! do_start) {
+		outl(what, ALI_REG(codec, ALI_STOP));
 	}
-	default:
-		return -EINVAL;
+	val = inl(ALI_REG(codec, ALI_AINTEN));
+	if (do_start) {
+		val |= whati;
+	} else {
+		val &= ~whati;
+	}
+	outl(val, ALI_REG(codec, ALI_AINTEN));
+	if (do_start) {
+		outl(what, ALI_REG(codec, ALI_START));
 	}
+	snd_ali_printk("trigger: what=%xh whati=%xh\n",what,whati);
+	spin_unlock(&codec->reg_lock);
+
 	return 0;
 }
 
@@ -1543,7 +1549,9 @@
 {
 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
 				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
-				 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START),
+				 SNDRV_PCM_INFO_MMAP_VALID |
+				 SNDRV_PCM_INFO_RESUME |
+				 SNDRV_PCM_INFO_SYNC_START),
 	.formats =		(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |
 				 SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE),
 	.rates =		SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
@@ -1567,7 +1575,9 @@
 {
 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
 				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
-				 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START),
+				 SNDRV_PCM_INFO_MMAP_VALID |
+				 SNDRV_PCM_INFO_RESUME |
+				 SNDRV_PCM_INFO_SYNC_START),
 	.formats =		(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |
 				 SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE),
 	.rates =		SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
@@ -1821,9 +1831,10 @@
 	return change;
 }
 
-static snd_kcontrol_new_t snd_ali5451_mixer_spdif[] __devinit = {
+static snd_kcontrol_new_t snd_ali5451_mixer_spdif[] __devinitdata = {
 	/* spdif aplayback switch */
-	ALI5451_SPDIF(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), 0, 0),
+	/* FIXME: "IEC958 Playback Switch" may conflict with one on ac97_codec */
+	ALI5451_SPDIF("IEC958 Output switch", 0, 0),
 	/* spdif out to spdif channel */
 	ALI5451_SPDIF("IEC958 Channel Output Switch", 0, 1),
 	/* spdif in from spdif channel */
@@ -1851,7 +1862,7 @@
 		return err;
 	}
 	if (codec->revision == ALI_5451_V02) {
-		for(idx = 0; idx < 3; idx++) {
+		for(idx = 0; idx < ARRAY_SIZE(snd_ali5451_mixer_spdif); idx++) {
 			err=snd_ctl_add(codec->card, snd_ctl_new1(&snd_ali5451_mixer_spdif[idx], codec));
 			if (err < 0) return err;
 		}
@@ -1999,15 +2010,13 @@
 
 	if (codec->revision == ALI_5451_V02) {
         	pci_dev = codec->pci_m1533;
-        	if (pci_dev == NULL)
-                	return -1;
 		pci_read_config_byte(pci_dev, 0x59, &temp);
+		temp |= 0x80;
+		pci_write_config_byte(pci_dev, 0x59, temp);
 	
-		pci_dev = pci_find_device(0x10b9,0x7101, pci_dev);
-		if (pci_dev == NULL)
-                	return -1;
-		pci_read_config_byte(pci_dev,0xb8,&temp);
-		temp |= 1 << 6;
+		pci_dev = codec->pci_m7101;
+		pci_read_config_byte(pci_dev, 0xb8, &temp);
+		temp |= 0x20;
 		pci_write_config_byte(pci_dev, 0xB8, temp);
 	}
 
@@ -2139,10 +2148,22 @@
 	codec->chregs.data.aint   = 0x00;
 	codec->chregs.data.ainten = 0x00;
 
-       	pci_dev = pci_find_device(0x10b9,0x1533, pci_dev);
+	/* M1533: southbridge */
+       	pci_dev = pci_find_device(0x10b9, 0x1533, NULL);
 	codec->pci_m1533 = pci_dev;
-       	pci_dev = pci_find_device(0x10b9,0x7101, pci_dev);
+	if (! codec->pci_m1533) {
+		snd_printk(KERN_ERR "ali5451: cannot find ALi 1533 chip.\n");
+		snd_ali_free(codec);
+		return -ENODEV;
+	}
+	/* M7101: power management */
+       	pci_dev = pci_find_device(0x10b9, 0x7101, NULL);
 	codec->pci_m7101 = pci_dev;
+	if (! codec->pci_m7101) {
+		snd_printk(KERN_ERR "ali5451: cannot find ALi 7101 chip.\n");
+		snd_ali_free(codec);
+		return -ENODEV;
+	}
 
 	snd_ali_printk("snd_device_new is called.\n");
 	if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, codec, &ops)) < 0) {
diff -Nru a/sound/pci/als4000.c b/sound/pci/als4000.c
--- a/sound/pci/als4000.c	Mon Dec 23 21:22:00 2002
+++ b/sound/pci/als4000.c	Mon Dec 23 21:22:00 2002
@@ -2,6 +2,7 @@
  *  card-als4000.c - driver for Avance Logic ALS4000 based soundcards.
  *  Copyright (C) 2000 by Bart Hartgers <bart@etpmod.phys.tue.nl>,
  *			  Jaroslav Kysela <perex@suse.cz>
+ *  Copyright (C) 2002 by Andreas Mohr <hw7oshyuv3001@sneakemail.com>
  *
  *  Framework borrowed from Massimo Piccioni's card-als100.c.
  *
@@ -11,6 +12,9 @@
  *  bought an ALS4000 based soundcard, I was forced to base this driver
  *  on reverse engineering.
  *
+ *  Note: this is no longer true. Pretty verbose chip docu (ALS4000a.PDF)
+ *  can be found on the ALSA web site.
+ *
  *  The ALS4000 seems to be the PCI-cousin of the ALS100. It contains an
  *  ALS100-like SB DSP/mixer, an OPL3 synth, a MPU401 and a gameport 
  *  interface. These subsystems can be mapped into ISA io-port space, 
@@ -23,11 +27,21 @@
  * 
  * The ALS4000 can do real full duplex playback/capture.
  *
- * BUGS
- *   The box suggests there is some support for 3D sound, but I did not
- *   investigate this yet.
- * 
+ * FMDAC:
+ * - 0x4f -> port 0x14
+ * - port 0x15 |= 1
+ *
+ * Enable/disable 3D sound:
+ * - 0x50 -> port 0x14
+ * - change bit 6 (0x40) of port 0x15
+ *
+ * Set QSound:
+ * - 0xdb -> port 0x14
+ * - set port 0x15:
+ *   0x3e (mode 3), 0x3c (mode 2), 0x3a (mode 1), 0x38 (mode 0)
  *
+ * Set KSound:
+ * - value -> some port 0x0c0d
  *
  *  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
@@ -256,11 +270,18 @@
 		count >>=1;
 	count--;
 	
+	/* FIXME: from second playback on, there's a lot more clicks and pops
+	 * involved here than on first playback. Fiddling with
+	 * tons of different settings didn't help (DMA, speaker on/off,
+	 * reordering, ...). Something seems to get enabled on playback
+	 * that I haven't found out how to disable again, which then causes
+	 * the switching pops to reach the speakers the next time here. */
 	spin_lock_irqsave(&chip->reg_lock, flags);
 	snd_als4000_set_rate(chip, runtime->rate);
 	snd_als4000_set_playback_dma(chip, runtime->dma_addr, size);
 	
-	snd_sbdsp_command(chip, SB_DSP_SPEAKER_ON);
+	/* SPEAKER_ON not needed, since dma_on seems to also enable speaker */
+	/* snd_sbdsp_command(chip, SB_DSP_SPEAKER_ON); */
 	snd_sbdsp_command(chip, playback_cmd(chip).dsp_cmd);
 	snd_sbdsp_command(chip, playback_cmd(chip).format);
 	snd_sbdsp_command(chip, count);
@@ -359,9 +380,9 @@
 	spin_unlock_irqrestore(&chip->mixer_lock, flags);
 	
 	if (sb_status & SB_IRQTYPE_8BIT) 
-		inb(SBP(chip, DATA_AVAIL));
+		snd_sb_ack_8bit(chip);
 	if (sb_status & SB_IRQTYPE_16BIT) 
-		inb(SBP(chip, DATA_AVAIL_16));
+		snd_sb_ack_16bit(chip);
 	if (sb_status & SB_IRQTYPE_MPUIN)
 		inb(chip->mpu_port);
 	if (sb_status & 0x20)
@@ -547,14 +568,14 @@
 	spin_unlock_irqrestore(&chip->reg_lock,flags);
 }
 
-static void snd_card_als4k_free( snd_card_t *card )
+static void snd_card_als4000_free( snd_card_t *card )
 {
 	snd_card_als4000_t * acard = (snd_card_als4000_t *)card->private_data;
 	/* make sure that interrupts are disabled */
 	snd_als4000_gcr_write_addr( acard->gcr, 0x8c, 0);
 }
 
-static int __devinit snd_card_als4k_probe(struct pci_dev *pci,
+static int __devinit snd_card_als4000_probe(struct pci_dev *pci,
 					  const struct pci_device_id *pci_id)
 {
 	static int dev;
@@ -608,7 +629,7 @@
 
 	acard = (snd_card_als4000_t *)card->private_data;
 	acard->gcr = gcr;
-	card->private_free = snd_card_als4k_free;
+	card->private_free = snd_card_als4000_free;
 
 	if ((err = snd_sbdsp_create(card,
 				    gcr + 0x10,
@@ -672,7 +693,7 @@
 	return 0;
 }
 
-static void __devexit snd_card_als4k_remove(struct pci_dev *pci)
+static void __devexit snd_card_als4000_remove(struct pci_dev *pci)
 {
 	snd_card_free(pci_get_drvdata(pci));
 	pci_set_drvdata(pci, NULL);
@@ -681,11 +702,11 @@
 static struct pci_driver driver = {
 	.name = "ALS4000",
 	.id_table = snd_als4000_ids,
-	.probe = snd_card_als4k_probe,
-	.remove = __devexit_p(snd_card_als4k_remove),
+	.probe = snd_card_als4000_probe,
+	.remove = __devexit_p(snd_card_als4000_remove),
 };
 
-static int __init alsa_card_als4k_init(void)
+static int __init alsa_card_als4000_init(void)
 {
 	int err;
 	
@@ -698,13 +719,13 @@
 	return 0;
 }
 
-static void __exit alsa_card_als4k_exit(void)
+static void __exit alsa_card_als4000_exit(void)
 {
 	pci_unregister_driver(&driver);
 }
 
-module_init(alsa_card_als4k_init)
-module_exit(alsa_card_als4k_exit)
+module_init(alsa_card_als4000_init)
+module_exit(alsa_card_als4000_exit)
 
 #ifndef MODULE
 
diff -Nru a/sound/pci/cmipci.c b/sound/pci/cmipci.c
--- a/sound/pci/cmipci.c	Mon Dec 23 21:21:51 2002
+++ b/sound/pci/cmipci.c	Mon Dec 23 21:21:51 2002
@@ -17,8 +17,18 @@
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  */
  
+/* Does not work. Warning may block system in capture mode */
+/* #define USE_VAR48KRATE */
+
+/* Define this if you want soft ac3 encoding - it's still buggy..  */
+/* #define DO_SOFT_AC3 */
+/* #define USE_AES_IEC958 */
+#define DO_SOFT_AC3
+#define USE_AES_IEC958
+
 #include <sound/driver.h>
 #include <asm/io.h>
+#include <linux/delay.h>
 #include <linux/interrupt.h>
 #include <linux/init.h>
 #include <linux/pci.h>
@@ -151,9 +161,15 @@
 
 #define CM_REG_INT_STATUS	0x10
 #define CM_INTR			0x80000000
+#define CM_VCO			0x08000000	/* Voice Control? CMI8738 */
+#define CM_MCBINT		0x04000000	/* Master Control Block abort cond.? */
 #define CM_UARTINT		0x00010000
 #define CM_LTDMAINT		0x00008000
 #define CM_HTDMAINT		0x00004000
+#define CM_XDO46		0x00000080	/* Modell 033? Direct programming EEPROM (read data register) */
+#define CM_LHBTOG		0x00000040	/* High/Low status from DMA ctrl register */
+#define CM_LEG_HDMA		0x00000020	/* Legacy is in High DMA channel */
+#define CM_LEG_STEREO		0x00000010	/* Legacy is in Stereo mode */
 #define CM_CH1BUSY		0x00000008
 #define CM_CH0BUSY		0x00000004
 #define CM_CHINT1		0x00000002
@@ -218,6 +234,11 @@
 #define CM_REG_SB16_DATA	0x22
 #define CM_REG_SB16_ADDR	0x23
 
+#define CM_REFFREQ_XIN		(315*1000*1000)/22	/* 14.31818 Mhz reference clock frequency pin XIN */
+#define CM_ADCMULT_XIN		512			/* Guessed (487 best for 44.1kHz, not for 88/176kHz) */
+#define CM_TOLERANCE_RATE	0.001			/* Tolerance sample rate pitch (1000ppm) */
+#define CM_MAXIMUM_RATE		80000000		/* Note more than 80MHz */
+
 #define CM_REG_MIXER1		0x24
 #define CM_FMMUTE		0x80	/* mute FM */
 #define CM_FMMUTE_SHIFT		7
@@ -263,6 +284,39 @@
 #define CM_DMAUTO		0x01
 
 #define CM_REG_AC97		0x28	/* hmmm.. do we have ac97 link? */
+/*
+ * For CMI-8338 (0x28 - 0x2b) .. is this valid for CMI-8738
+ * or identical with AC97 codec?
+ */
+#define CM_REG_EXTERN_CODEC	CM_REG_AC97
+
+/*
+ * MPU401 pci port index address 0x40 - 0x4f (CMI-8738 spec ver. 0.6)
+ */
+#define CM_REG_MPU_PCI		0x40
+
+/*
+ * FM pci port index address 0x50 - 0x5f (CMI-8738 spec ver. 0.6)
+ */
+#define CM_REG_FM_PCI		0x50
+
+/*
+ * for CMI-8338 .. this is not valid for CMI-8738.
+ */
+#define CM_REG_EXTENT_IND	0xf0
+#define CM_VPHONE_MASK		0xe0	/* Phone volume control (0-3) << 5 */
+#define CM_VPHONE_SHIFT		5
+#define CM_VPHOM		0x10	/* Phone mute control */
+#define CM_VSPKM		0x08	/* Speaker mute control, default high */
+#define CM_RLOOPREN		0x04    /* Rec. R-channel enable */
+#define CM_RLOOPLEN		0x02	/* Rec. L-channel enable */
+
+/*
+ * CMI-8338 spec ver 0.5 (this is not valid for CMI-8738):
+ * the 8 registers 0xf8 - 0xff are used for programming m/n counter by the PLL
+ * unit (readonly?).
+ */
+#define CM_REG_PLL		0xf8
 
 /*
  * extended registers
@@ -331,12 +385,6 @@
 
 
 /*
- * define this if you want soft ac3 encoding - it's still buggy..
- */
-/* #define DO_SOFT_AC3 */
-
-
-/*
  * driver data
  */
 
@@ -401,6 +449,9 @@
 
 	unsigned int dig_status;
 	unsigned int dig_pcm_status;
+#ifdef USE_AES_IEC958
+	snd_ctl_elem_value_t *spdif_channel;
+#endif
 	snd_kcontrol_t *spdif_pcm_ctl;
 
 	snd_pcm_hardware_t *hw_info[3]; /* for playbacks */
@@ -515,12 +566,86 @@
 	return 0;
 }
 
+#ifdef USE_VAR48KRATE
+/*
+ * Determine PLL values for frequency setup, maybe the CMI8338 (CMI8738???)
+ * does it this way .. maybe not.  Never get any information from C-Media about
+ * that <werner@suse.de>.
+ */
+static int snd_cmipci_pll_rmn(unsigned int rate, unsigned int adcmult, int *r, int *m, int *n)
+{
+	unsigned int delta, tolerance;
+	int xm, xn, xr;
+
+	for (*r = 0; rate < CM_MAXIMUM_RATE/adcmult; *r += (1<<5))
+		rate <<= 1;
+	*n = -1;
+	if (*r > 0xff)
+		goto out;
+	tolerance = rate*CM_TOLERANCE_RATE;
+
+	for (xn = (1+2); xn < (0x1f+2); xn++) {
+		for (xm = (1+2); xm < (0xff+2); xm++) {
+			xr = ((CM_REFFREQ_XIN/adcmult) * xm) / xn;
+
+			if (xr < rate)
+				delta = rate - xr;
+			else
+				delta = xr - rate;
+
+			/*
+			 * If we found one, remember this,
+			 * and try to find a closer one
+			 */
+			if (delta < tolerance) {
+				tolerance = delta;
+				*m = xm - 2;
+				*n = xn - 2;
+			}
+		}
+	}
+out:
+	return (*n > -1);
+}
+
+/*
+ * Program pll register bits, I assume that the 8 registers 0xf8 upto 0xff
+ * are mapped onto the 8 ADC/DAC sampling frequency which can be choosen
+ * at the register CM_REG_FUNCTRL1 (0x04).
+ * Problem: other ways are also possible (any information about that?)
+ */
+static void snd_cmipci_set_pll(cmipci_t *cm, unsigned int rate, unsigned int slot)
+{
+	unsigned int reg = CM_REG_PLL + slot;
+	/*
+	 * Guess that this programs at reg. 0x04 the pos 15:13/12:10
+	 * for DSFC/ASFC (000 upto 111).
+	 */
+
+	/* FIXME: Init (Do we've to set an other register first before programming?) */
+
+	/* FIXME: Is this correct? Or shouldn't the m/n/r values be used for that? */
+	snd_cmipci_write_b(cm, reg, rate>>8);
+	snd_cmipci_write_b(cm, reg, rate&0xff);
+
+	/* FIXME: Setup (Do we've to set an other register first to enable this?) */
+}
+#endif /* USE_VAR48KRATE */
+
 static int snd_cmipci_hw_params(snd_pcm_substream_t * substream,
 				snd_pcm_hw_params_t * hw_params)
 {
 	return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
 }
 
+static void snd_cmipci_ch_reset(cmipci_t *cm, int ch)
+{
+	int reset = CM_RST_CH0 << (cm->channel[ch].ch);
+	snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl | reset);
+	snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl & ~reset);
+	udelay(10);
+}
+
 static int snd_cmipci_hw_free(snd_pcm_substream_t * substream)
 {
 	return snd_pcm_lib_free_pages(substream);
@@ -699,7 +824,7 @@
 		/* reset */
 		cm->ctrl &= ~chen;
 		snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl | reset);
-		snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl);
+		snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl & ~reset);
 		break;
 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
 		cm->ctrl |= pause;
@@ -784,8 +909,10 @@
  * write the raw subframe via 32bit data mode.
  */
 
+# ifndef USE_AES_IEC958
+
 /* find parity for bit 4~30 */
-static unsigned parity(unsigned int data)
+static unsigned int parity(unsigned int data)
 {
 	unsigned int parity = 0;
 	int counter = 4;
@@ -835,6 +962,187 @@
 	return data;
 }
 
+# else  /* if USE_AES_IEC958 */
+
+/*
+ * The bitstream handling
+ */
+typedef struct iec958_stru_bitstream {
+	u32 *data;		/* Holds the current position */
+	u32  left;		/* Bits left in current 32bit frame */
+	u32  word;		/* The 32bit frame of the current position */
+	u32  bits;		/* All bits together */
+	int   err;		/* Error condition */
+} iec958_bitstream_t ;
+
+static iec958_bitstream_t bs;
+
+/* Initialize ptr on the buffer */
+static void iec958_init_bitstream(u8 *buf, u32 size)
+{
+	bs.data = (u32 *)buf;		/* Set initial position */
+	bs.word = *bs.data;		/* The first 32bit frame */
+	bs.left = 32;			/* has exactly 32bits */
+	bs.bits = size;
+	bs.err = 0;
+}
+
+/* Remove ptr on the buffer */
+static void iec958_clear_bitstream(void)
+{
+	bs.data = NULL;
+	bs.left = 0;
+	bs.err = 0;
+}
+
+/* Get bits from bitstream (max 32) */
+static inline u32 iec958_getbits(u32 bits)
+{
+	u32 res;
+
+	if (bs.bits < bits) {
+		bits = bs.bits;
+		bs.err = 1;
+	}
+	if (bits > 32) {
+		bits = 32;
+		bs.err = 1;
+	}
+	bs.bits -= bits;
+
+#  ifdef WORDS_BIGENDIAN
+	if (bits < bs.left) {		/* Within 32bit frame */
+		res = (bs.word << (32 - bs.left)) >> (32 - bits);
+		bs.left -= bits;
+		goto out;
+	}				/* We may cross the frame boundary */
+	res   = (bs.word << (32 - bs.left)) >> (32 - bs.left);
+	bits -= bs.left;
+
+	bs.word = *(++bs.data);		/* Next 32bit frame */
+
+	if (bits)			/* Add remaining bits, if any */
+		res = (res << bits) | (bs.word >> (32 - bits));
+
+#  else  /* not WORDS_BIGENDIAN */
+
+	if (bits < bs.left) {		/* Within 32bit frame */
+		res = (bs.word << (32 - bits)) >> (32 - bits);
+		bs.word >>= bits;
+		bs.left -= bits;
+		goto out;
+	}				/* We may cross the frame boundary */
+	res   = bs.word;
+	bits -= bs.left;
+
+	bs.word = *(++bs.data);		/* Next 32bit frame */
+
+	if (bits) {			/* Add remaining bits, if any */
+		res = res | (((bs.word << (32 - bits)) >> (32 - bits)) << bits);
+		bs.word >>= bits;
+	}
+#  endif /* not WORDS_BIGENDIAN */
+
+	bs.left = (32 - bits);
+out:
+	return res;
+}
+
+static inline u32 iec958_bits_avail(void)
+{
+	return bs.bits;
+}
+
+static inline int iec958_error(void)
+{
+	return bs.err;
+}
+
+/*
+ * Determine parity for time slots 4 upto 30
+ * to be sure that bit 4 upt 31 will carry
+ * an even number of ones and zeros.
+ */
+static u32 iec958_parity(u32 data)
+{
+	u32 parity = 0;
+	int counter = 4;
+
+	data >>= 4;     /* start from bit 4 */
+	while (counter++ <= 30) {
+		if (data & 0x00000001)
+			parity++;
+		data >>= 1;
+	}
+	return (parity & 0x00000001);
+}
+
+/*
+ * Compose 32bit iec958 subframe, two sub frames
+ * build one frame with two channels.
+ *
+ * bit 0-3  = preamble
+ *     4-7  = AUX (=0)
+ *     8-27 = data (12-27 for 16bit, 8-27 for 20bit, and 24bit without AUX)
+ *     28   = validity (0 for valid data, else 'in error')
+ *     29   = user data (0)
+ *     30   = channel status (24 bytes for 192 frames)
+ *     31   = parity
+ */
+
+static inline u32 iec958_subframe(cmipci_t *cm, snd_ctl_elem_value_t * ucontrol)
+{
+	u32 data;
+	u32 byte = cm->spdif_counter >> 4;
+	u32 mask = 1 << ((cm->spdif_counter >> 1) - (byte << 3));
+	u8 * status = ucontrol->value.iec958.status;
+
+	if (status[2] & IEC958_AES2_PRO_SBITS_24) {
+		/* Does this work for LE systems ??? */
+		if (status[2] & IEC958_AES2_PRO_WORDLEN_24_20) {
+			data = iec958_getbits(24);
+			data <<= 4;
+		} else {
+			data = iec958_getbits(20);
+			data <<= 8;
+		}
+	} else {
+		if (status[2] & IEC958_AES2_PRO_WORDLEN_24_20) {
+			/* Does this work for LE systems ??? */
+			data = iec958_getbits(20);
+			data <<= 8;
+		} else {
+			data = iec958_getbits(16);
+			data <<= 12;
+		}
+	}
+
+	/*
+	 * Set one of the 192 bits of the channel status (AES3 and higher)
+	 */
+	if (status[byte] & mask)
+		data |= 0x40000000;
+
+	if (iec958_parity(data))	/* parity bit 4-30 */
+		data |= 0x80000000;
+
+	/* Preamble */
+	if      (!cm->spdif_counter)
+		data |= 0x03;		/* Block start, 'Z' */
+	else if (cm->spdif_counter % 2)
+		data |= 0x05;		/* odd sub frame, 'Y' */
+	else
+		data |= 0x09;		/* even sub frame, 'X' */
+
+	/*
+	 * sub frame counter: 2 sub frame are one audio frame
+	 * and 192 frames are one block
+	 */
+	cm->spdif_counter = (++cm->spdif_counter) % 384;
+
+	return data;
+}
+# endif /* if USE_AES_IEC958 */
 
 static int snd_cmipci_ac3_copy(snd_pcm_substream_t *subs, int channel,
 			       snd_pcm_uframes_t pos, void *src,
@@ -842,9 +1150,15 @@
 {
 	cmipci_t *cm = snd_pcm_substream_chip(subs);
 	u32 *dst;
-	u16 *srcp = src, val;
 	snd_pcm_uframes_t offset;
 	snd_pcm_runtime_t *runtime = subs->runtime;
+#ifndef USE_AES_IEC958
+	u16 *srcp = src, val;
+#else
+	char buf[1920];         /* bits can be divided by 20, 24, 16 */
+	size_t bytes = frames_to_bytes(runtime, count);
+#endif
+
 
 	if (!cm->channel[CM_CH_PLAY].ac3_shift) {
 		if (copy_from_user(runtime->dma_area +
@@ -860,14 +1174,34 @@
 	/* frame = 16bit stereo */
 	offset = (pos << 1) % (cm->channel[CM_CH_PLAY].dma_size << 2);
 	dst = (u32*)(runtime->dma_area + offset);
-
+# ifndef USE_AES_IEC958
 	count /= 2;
 	while (count-- > 0) {
 		get_user(val, srcp);
 		srcp++;
 		*dst++ = convert_ac3_32bit(cm, val);
 	}
+# else
+	while (bytes) {
+		size_t c = bytes;
 
+		if (c > sizeof(buf))
+			c = sizeof(buf);
+
+		if (copy_from_user(buf, src, c))
+			return -EFAULT;
+		bytes -= c;
+		src   += c;
+
+		iec958_init_bitstream(buf, c*8);
+		while (iec958_bits_avail()) {
+			*(dst++) = iec958_subframe(cm, cm->spdif_channel);
+			if (iec958_error())
+				return -EINVAL;
+		}
+		iec958_clear_bitstream();
+	}
+# endif
 	return 0;
 }
 
@@ -879,7 +1213,10 @@
 	u32 *dst;
 	snd_pcm_uframes_t offset;
 	snd_pcm_runtime_t *runtime = subs->runtime;
-
+# ifdef USE_AES_IEC958
+	char buf[1920];		/* bits can be divided by 20, 24, 16 */
+	size_t bytes = frames_to_bytes(runtime, count);
+# endif
 	if (! cm->channel[CM_CH_PLAY].ac3_shift)
 		return snd_pcm_format_set_silence(runtime->format,
 						  runtime->dma_area + frames_to_bytes(runtime, pos), count);
@@ -887,12 +1224,31 @@
 	/* frame = 16bit stereo */
 	offset = (pos << 1) % (cm->channel[CM_CH_PLAY].dma_size << 2);
 	dst = (u32*)(subs->runtime->dma_area + offset);
-
+# ifndef USE_AES_IEC958
 	count /= 2;
 	while (count-- > 0) {
 		*dst++ = convert_ac3_32bit(cm, 0);
 	}
+# else
+	while (bytes) {
+		size_t c = bytes;
 
+		if (c > sizeof(buf))
+			c = sizeof(buf);
+
+		/* Q: Does this function know about 24bit silence? */
+		if (snd_pcm_format_set_silence(runtime->format, buf, bytes_to_frames(runtime, c)))
+			return -EINVAL;
+
+		iec958_init_bitstream(buf, c*8);
+		while (iec958_bits_avail()) {
+			*(dst++) = iec958_subframe(cm, cm->spdif_channel);
+			if (iec958_error())
+				return -EINVAL;
+		}
+		iec958_clear_bitstream();
+	}
+# endif
 	return 0;
 }
 #endif /* DO_SOFT_AC3 */
@@ -996,6 +1352,9 @@
 	spin_lock_irqsave(&chip->reg_lock, flags);
 	for (i = 0; i < 4; i++)
 		ucontrol->value.iec958.status[i] = (chip->dig_pcm_status >> (i * 8)) & 0xff;
+#ifdef USE_AES_IEC958
+	ucontrol = chip->spdif_channel;
+#endif
 	spin_unlock_irqrestore(&chip->reg_lock, flags);
 	return 0;
 }
@@ -1014,6 +1373,9 @@
 		val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
 	change = val != chip->dig_pcm_status;
 	chip->dig_pcm_status = val;
+#ifdef USE_AES_IEC958
+	chip->spdif_channel = ucontrol;
+#endif
 	spin_unlock_irqrestore(&chip->reg_lock, flags);
 	return change;
 }
@@ -1128,9 +1490,11 @@
 		if (cm->can_ac3_hw) {
 			snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_SPD24SEL);
 		} else {
+#ifdef DO_SOFT_AC3
 			snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL);
 			snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_SPD24SEL);
 			snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_PLAYBACK_SRATE_176K);
+#endif /* DO_SOFT_AC3 */
 		}
 	}
 }
@@ -1248,7 +1612,7 @@
 static void snd_cmipci_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
 	cmipci_t *cm = snd_magic_cast(cmipci_t, dev_id, return);
-	unsigned int status;
+	unsigned int status, mask = 0;
 	
 	/* fastpath out, to ease interrupt sharing */
 	status = snd_cmipci_read(cm, CM_REG_INT_STATUS);
@@ -1257,14 +1621,12 @@
 
 	/* acknowledge interrupt */
 	spin_lock(&cm->reg_lock);
-	if (status & CM_CHINT0) {
-		snd_cmipci_clear_bit(cm, CM_REG_INT_HLDCLR, CM_CH0_INT_EN);
-		snd_cmipci_set_bit(cm, CM_REG_INT_HLDCLR, CM_CH0_INT_EN);
-	}
-	if (status & CM_CHINT1) {
-		snd_cmipci_clear_bit(cm, CM_REG_INT_HLDCLR, CM_CH1_INT_EN);
-		snd_cmipci_set_bit(cm, CM_REG_INT_HLDCLR, CM_CH1_INT_EN);
-	}
+	if (status & CM_CHINT0)
+		mask |= CM_CH0_INT_EN;
+	if (status & CM_CHINT1)
+		mask |= CM_CH1_INT_EN;
+	snd_cmipci_clear_bit(cm, CM_REG_INT_HLDCLR, mask);
+	snd_cmipci_set_bit(cm, CM_REG_INT_HLDCLR, mask);
 	spin_unlock(&cm->reg_lock);
 
 	if (cm->rmidi && (status & CM_UARTINT))
@@ -1419,6 +1781,7 @@
 
 	down(&cm->open_mutex);
 	if (cm->opened[ch] == mode) {
+		snd_cmipci_ch_reset(cm, ch);
 		cm->channel[ch].running = 0;
 		cm->channel[ch].substream = NULL;
 		cm->opened[ch] = 0;
@@ -2144,9 +2507,8 @@
 	DEFINE_SWITCH_ARG(sname, xreg, xmask, xmask, xis_byte, xac3)
 
 #if 0 /* these will be controlled in pcm device */
-DEFINE_BIT_SWITCH_ARG(spdif_in, CM_REG_FUNCTRL1, CM_SPDF_1, 0);
-DEFINE_BIT_SWITCH_ARG(spdif_0, CM_REG_FUNCTRL1, CM_SPDF_0, 0);
-DEFINE_BIT_SWITCH_ARG(spdo_48k, CM_REG_MISC_CTRL, CM_SPDF_AC97|CM_SPDIF48K, 0);
+DEFINE_BIT_SWITCH_ARG(spdif_in, CM_REG_FUNCTRL1, CM_SPDF_1, 0, 0);
+DEFINE_BIT_SWITCH_ARG(spdif_out, CM_REG_FUNCTRL1, CM_SPDF_0, 0, 0);
 #endif
 DEFINE_BIT_SWITCH_ARG(spdif_in_sel1, CM_REG_CHFORMAT, CM_SPDIF_SELECT1, 0, 0);
 DEFINE_BIT_SWITCH_ARG(spdif_in_sel2, CM_REG_MISC_CTRL, CM_SPDIF_SELECT2, 0, 0);
@@ -2156,6 +2518,7 @@
 DEFINE_BIT_SWITCH_ARG(spdif_copyright, CM_REG_LEGACY_CTRL, CM_SPDCOPYRHT, 0, 0);
 DEFINE_BIT_SWITCH_ARG(spdif_dac_out, CM_REG_LEGACY_CTRL, CM_DAC2SPDO, 0, 1);
 DEFINE_SWITCH_ARG(spdo_5v, CM_REG_MISC_CTRL, CM_SPDO5V, 0, 0, 0); /* inverse: 0 = 5V */
+// DEFINE_BIT_SWITCH_ARG(spdo_48k, CM_REG_MISC_CTRL, CM_SPDF_AC97|CM_SPDIF48K, 0, 1);
 DEFINE_BIT_SWITCH_ARG(spdif_loop, CM_REG_FUNCTRL1, CM_SPDFLOOP, 0, 1);
 DEFINE_BIT_SWITCH_ARG(spdi_monitor, CM_REG_MIXER1, CM_CDPLAY, 1, 0);
 /* DEFINE_BIT_SWITCH_ARG(spdi_phase, CM_REG_CHFORMAT, CM_SPDIF_INVERSE, 0, 0); */
@@ -2228,8 +2591,7 @@
 static snd_kcontrol_new_t snd_cmipci_8738_mixer_switches[] __devinitdata = {
 #if 0 /* controlled in pcm device */
 	DEFINE_MIXER_SWITCH("IEC958 In Record", spdif_in),
-	DEFINE_MIXER_SWITCH("IEC958 Out", spdif_0),
-	DEFINE_MIXER_SWITCH("IEC958 Out 48KHz", spdo_48k),
+	DEFINE_MIXER_SWITCH("IEC958 Out", spdif_out),
 	DEFINE_MIXER_SWITCH("IEC958 Out To DAC", spdo2dac),
 #endif
 	// DEFINE_MIXER_SWITCH("IEC958 Output Switch", spdif_enable),
@@ -2242,6 +2604,7 @@
 	DEFINE_MIXER_SWITCH("IEC958 In Valid", spdi_valid),
 	DEFINE_MIXER_SWITCH("IEC958 Copyright", spdif_copyright),
 	DEFINE_MIXER_SWITCH("IEC958 5V", spdo_5v),
+//	DEFINE_MIXER_SWITCH("IEC958 In/Out 48KHz", spdo_48k),
 	DEFINE_MIXER_SWITCH("IEC958 Loop", spdif_loop),
 	DEFINE_MIXER_SWITCH("IEC958 In Monitor", spdi_monitor),
 };
@@ -2475,6 +2838,8 @@
 		snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
 		snd_cmipci_clear_bit(cm, CM_REG_LEGACY_CTRL, CM_ENSPDOUT);
 		snd_cmipci_write(cm, CM_REG_INT_HLDCLR, 0);  /* disable ints */
+		snd_cmipci_ch_reset(cm, CM_CH_PLAY);
+		snd_cmipci_ch_reset(cm, CM_CH_CAPT);
 		snd_cmipci_write(cm, CM_REG_FUNCTRL0, 0); /* disable channels */
 		snd_cmipci_write(cm, CM_REG_FUNCTRL1, 0);
 
@@ -2547,7 +2912,6 @@
 
 	pci_set_master(cm->pci);
 
-
 	/*
 	 * check chip version, max channels and capabilities
 	 */
@@ -2568,6 +2932,8 @@
 
 	/* initialize codec registers */
 	snd_cmipci_write(cm, CM_REG_INT_HLDCLR, 0);	/* disable ints */
+	snd_cmipci_ch_reset(cm, CM_CH_PLAY);
+	snd_cmipci_ch_reset(cm, CM_CH_CAPT);
 	snd_cmipci_write(cm, CM_REG_FUNCTRL0, 0);	/* disable channels */
 	snd_cmipci_write(cm, CM_REG_FUNCTRL1, 0);
 
@@ -2578,6 +2944,30 @@
 #else
 	snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_XCHGDAC);
 #endif
+	/* Set Bus Master Request */
+	snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_BREQ);
+
+	/* Assume TX and compatible chip set (Autodetection required for VX chip sets) */
+	switch (pci->device) {
+		struct list_head *pos;
+		int txvx;
+	case PCI_DEVICE_ID_CMEDIA_CM8738:
+	case PCI_DEVICE_ID_CMEDIA_CM8738B:
+		txvx = 1;
+		list_for_each(pos, &(pci->global_list)) {
+			struct pci_dev * cur = list_entry(pos, struct pci_dev, global_list);
+			if (cur->vendor != 0x8086) /* PCI_VENDOR_ID_INTEL */
+				continue;
+			if (cur->device != 0x7030) /* PCI_DEVICE_ID_INTEL_82437VX */
+				continue;
+			txvx = 0;
+		}
+		if (txvx)
+			snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_TXVX);
+		break;
+	default:
+		break;
+	}
 
 	/* set MPU address */
 	switch (iomidi) {
@@ -2663,6 +3053,15 @@
 		snd_cmipci_free(cm);
 		return err;
 	}
+#ifdef USE_VAR48KRATE
+	for (val = 0; val < RATES; val++)
+		snd_cmipci_set_pll(cm, rates[val], val);
+
+	/*
+	 * (Re-)Enable external switch spdo_48k
+	 */
+	snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_SPDIF48K|CM_SPDF_AC97);
+#endif /* USE_VAR48KRATE */
 
 	*rcmipci = cm;
 	return 0;
diff -Nru a/sound/pci/cs4281.c b/sound/pci/cs4281.c
--- a/sound/pci/cs4281.c	Mon Dec 23 21:22:00 2002
+++ b/sound/pci/cs4281.c	Mon Dec 23 21:22:00 2002
@@ -735,12 +735,14 @@
 		dma->valFCR &= ~BA0_FCR_FEN;
 		break;
 	case SNDRV_PCM_TRIGGER_START:
+	case SNDRV_PCM_TRIGGER_RESUME:
 		snd_cs4281_pokeBA0(chip, dma->regDMR, dma->valDMR & ~BA0_DMR_DMA);
 		dma->valDMR |= BA0_DMR_DMA;
 		dma->valDCR &= ~BA0_DCR_MSK;
 		dma->valFCR |= BA0_FCR_FEN;
 		break;
 	case SNDRV_PCM_TRIGGER_STOP:
+	case SNDRV_PCM_TRIGGER_SUSPEND:
 		dma->valDMR &= ~(BA0_DMR_DMA|BA0_DMR_POLL);
 		dma->valDCR |= BA0_DCR_MSK;
 		dma->valFCR &= ~BA0_FCR_FEN;
@@ -900,6 +902,7 @@
 				 SNDRV_PCM_INFO_INTERLEAVED |
 				 SNDRV_PCM_INFO_MMAP_VALID |
 				 SNDRV_PCM_INFO_PAUSE |
+				 SNDRV_PCM_INFO_RESUME |
 				 SNDRV_PCM_INFO_SYNC_START),
 	.formats =		SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
 				SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_S16_LE |
@@ -925,6 +928,7 @@
 				 SNDRV_PCM_INFO_INTERLEAVED |
 				 SNDRV_PCM_INFO_MMAP_VALID |
 				 SNDRV_PCM_INFO_PAUSE |
+				 SNDRV_PCM_INFO_RESUME |
 				 SNDRV_PCM_INFO_SYNC_START),
 	.formats =		SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
 				SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_S16_LE |
@@ -1804,7 +1808,7 @@
 	spin_lock_irqsave(&chip->reg_lock, flags);
 	chip->uartm |= CS4281_MODE_OUTPUT;
 	chip->midcr |= BA0_MIDCR_TXE;
-	chip->midi_input = substream;
+	chip->midi_output = substream;
 	if (!(chip->uartm & CS4281_MODE_INPUT)) {
 		snd_cs4281_midi_reset(chip);
 	} else {
diff -Nru a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c
--- a/sound/pci/cs46xx/cs46xx_lib.c	Mon Dec 23 21:21:51 2002
+++ b/sound/pci/cs46xx/cs46xx_lib.c	Mon Dec 23 21:21:51 2002
@@ -849,7 +849,7 @@
 	cpcm->hw_io = ptr;
 	cpcm->hw_ready -= bytes;
 	cpcm->sw_io += bytes;
-	if (cpcm->sw_io > cpcm->sw_bufsize)
+	if (cpcm->sw_io >= cpcm->sw_bufsize)
 		cpcm->sw_io -= cpcm->sw_bufsize;
 	snd_cs46xx_playback_transfer(substream, 0);
 	return cpcm->sw_io >> cpcm->shift;
@@ -874,7 +874,7 @@
 	chip->capt.hw_io = ptr;
 	chip->capt.hw_ready += bytes;
 	chip->capt.sw_io += bytes;
-	if (chip->capt.sw_io > chip->capt.sw_bufsize)
+	if (chip->capt.sw_io >= chip->capt.sw_bufsize)
 		chip->capt.sw_io -= chip->capt.sw_bufsize;
 	snd_cs46xx_capture_transfer(substream, 0);
 	return chip->capt.sw_io >> chip->capt.shift;
@@ -950,15 +950,15 @@
 	case SNDRV_PCM_TRIGGER_START:
 	case SNDRV_PCM_TRIGGER_RESUME:
 #ifdef CONFIG_SND_CS46XX_NEW_DSP
+		/* magic value to unmute PCM stream  playback volume */
+		snd_cs46xx_poke(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 
+				       SCBVolumeCtrl) << 2, 0x80008000);
+
 		if (cpcm->pcm_channel->unlinked)
 			cs46xx_dsp_pcm_link(chip,cpcm->pcm_channel);
+
 		if (substream->runtime->periods != CS46XX_FRAGS)
 			snd_cs46xx_playback_transfer(substream, 0);
-
-		/* raise playback volume */
-		cs46xx_dsp_scb_set_volume (chip,cpcm->pcm_channel->pcm_reader_scb,
-					   chip->dsp_spos_instance->dac_volume_right,
-					   chip->dsp_spos_instance->dac_volume_left);
 #else
 		if (substream->runtime->periods != CS46XX_FRAGS)
 			snd_cs46xx_playback_transfer(substream, 0);
@@ -972,8 +972,9 @@
 	case SNDRV_PCM_TRIGGER_STOP:
 	case SNDRV_PCM_TRIGGER_SUSPEND:
 #ifdef CONFIG_SND_CS46XX_NEW_DSP
-		/* mute channel */
-		cs46xx_dsp_scb_set_volume (chip,cpcm->pcm_channel->pcm_reader_scb,0,0);
+		/* magic mute channel */
+		snd_cs46xx_poke(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 
+				       SCBVolumeCtrl) << 2, 0xffffffff);
 
 		if (!cpcm->pcm_channel->unlinked)
 			cs46xx_dsp_pcm_unlink(chip,cpcm->pcm_channel);
@@ -1031,32 +1032,27 @@
 static int _cs46xx_adjust_sample_rate (cs46xx_t *chip, cs46xx_pcm_t *cpcm,
 				       int sample_rate) 
 {
-	/* if this is the only PCMReaderSCB child under current
-	   SrcTask then there no need to re-create pcm-channel */
-	if ( cpcm->pcm_channel->src_scb->ref_count == 1 &&
-	     cpcm->pcm_channel->sample_rate != sample_rate &&
-	     /* never set a 0 khz sample rate */
-	     sample_rate) {
-		/* sample rate not set or we can reuse
-		   the same SRC*/
-		cs46xx_dsp_set_src_sample_rate (chip,cpcm->pcm_channel->src_scb,sample_rate);
-		cpcm->pcm_channel->sample_rate = sample_rate;
-	} 
 
-	/* if there is more then 1 PCMReaderSCB child's under current
-	   SrcTask then we must recreate channel */
-	if (cpcm->pcm_channel->sample_rate != sample_rate &&
-	    cpcm->pcm_channel->src_scb->ref_count != 1 &&
-	    /* never set a 0 khz sample rate */
-	    sample_rate) {
+	/* If PCMReaderSCB and SrcTaskSCB not created yet ... */
+	if ( cpcm->pcm_channel == NULL) {
+		cpcm->pcm_channel = cs46xx_dsp_create_pcm_channel (chip, sample_rate, 
+								   cpcm, cpcm->hw_addr,cpcm->pcm_channel_id);
+		if (cpcm->pcm_channel == NULL) {
+			snd_printk(KERN_ERR "cs46xx: failed to create virtual PCM channel\n");
+			return -ENOMEM;
+		}
+		cpcm->pcm_channel->sample_rate = sample_rate;
+	} else
+	/* if sample rate is changed */
+	if (cpcm->pcm_channel->sample_rate != sample_rate) {
 		int unlinked = cpcm->pcm_channel->unlinked;
 		cs46xx_dsp_destroy_pcm_channel (chip,cpcm->pcm_channel);
 
 		if ( (cpcm->pcm_channel = cs46xx_dsp_create_pcm_channel (chip, sample_rate, cpcm, 
 									 cpcm->hw_addr,
-									 cpcm->pcm_channel->pcm_channel_id)) == NULL) {
+									 cpcm->pcm_channel_id)) == NULL) {
 			snd_printk(KERN_ERR "cs46xx: failed to re-create virtual PCM channel\n");
-			return -ENXIO;
+			return -ENOMEM;
 		}
 
 		if (!unlinked) cs46xx_dsp_pcm_link (chip,cpcm->pcm_channel);
@@ -1067,6 +1063,7 @@
 }
 #endif
 
+
 static int snd_cs46xx_playback_hw_params(snd_pcm_substream_t * substream,
 					 snd_pcm_hw_params_t * hw_params)
 {
@@ -1080,18 +1077,19 @@
 	cpcm = snd_magic_cast(cs46xx_pcm_t, runtime->private_data, return -ENXIO);
 
 #ifdef CONFIG_SND_CS46XX_NEW_DSP
+	snd_assert (sample_rate != 0, return -ENXIO);
+
 	down (&chip->spos_mutex);
 
-	snd_assert (cpcm->pcm_channel != NULL);
+	if (_cs46xx_adjust_sample_rate (chip,cpcm,sample_rate)) {
+		up (&chip->spos_mutex);
+		return -ENXIO;
+	}
 
-	/* if IEC958 is opened in AC3 mode dont adjust SRCTask is not
-	   used so dont adjust sample rate */
-	if (cpcm->pcm_channel->pcm_channel_id != DSP_IEC958_CHANNEL ||
-	    !(chip->dsp_spos_instance->spdif_status_out & DSP_SPDIF_STATUS_AC3_MODE)) {
-		if (_cs46xx_adjust_sample_rate (chip,cpcm,sample_rate)) {
-			up (&chip->spos_mutex);
-			return -ENXIO;
-		}
+	snd_assert (cpcm->pcm_channel != NULL);
+	if (!cpcm->pcm_channel) {
+		up (&chip->spos_mutex);
+		return -ENXIO;
 	}
 
 	if (cs46xx_dsp_pcm_channel_set_period (chip,cpcm->pcm_channel,period_size * 4)) {
@@ -1111,11 +1109,11 @@
 
 
 #ifdef CONFIG_SND_CS46XX_NEW_DSP
-		if (cpcm->pcm_channel->pcm_channel_id == DSP_PCM_MAIN_CHANNEL) {
+		if (cpcm->pcm_channel_id == DSP_PCM_MAIN_CHANNEL) {
 			substream->ops = &snd_cs46xx_playback_ops;
-		} else if (cpcm->pcm_channel->pcm_channel_id == DSP_PCM_REAR_CHANNEL) {
+		} else if (cpcm->pcm_channel_id == DSP_PCM_REAR_CHANNEL) {
 			substream->ops = &snd_cs46xx_playback_rear_ops;
-		} else if (cpcm->pcm_channel->pcm_channel_id == DSP_IEC958_CHANNEL) {
+		} else if (cpcm->pcm_channel_id == DSP_IEC958_CHANNEL) {
 			substream->ops = &snd_cs46xx_playback_iec958_ops;
 		} else {
 			snd_assert(0);
@@ -1138,11 +1136,11 @@
 		}
 
 #ifdef CONFIG_SND_CS46XX_NEW_DSP
-		if (cpcm->pcm_channel->pcm_channel_id == DSP_PCM_MAIN_CHANNEL) {
+		if (cpcm->pcm_channel_id == DSP_PCM_MAIN_CHANNEL) {
 			substream->ops = &snd_cs46xx_playback_indirect_ops;
-		} else if (cpcm->pcm_channel->pcm_channel_id == DSP_PCM_REAR_CHANNEL) {
+		} else if (cpcm->pcm_channel_id == DSP_PCM_REAR_CHANNEL) {
 			substream->ops = &snd_cs46xx_playback_indirect_rear_ops;
-		} else if (cpcm->pcm_channel->pcm_channel_id == DSP_IEC958_CHANNEL) {
+		} else if (cpcm->pcm_channel_id == DSP_IEC958_CHANNEL) {
 			substream->ops = &snd_cs46xx_playback_indirect_iec958_ops;
 		} else {
 			snd_assert(0);
@@ -1168,6 +1166,10 @@
 
 	cpcm = snd_magic_cast(cs46xx_pcm_t, runtime->private_data, return -ENXIO);
 
+	/* if play_back open fails, then this function
+	   is called and cpcm can actually be NULL here */
+	if (!cpcm) return -ENXIO;
+
 	if (runtime->dma_area != cpcm->hw_area)
 		snd_pcm_lib_free_pages(substream);
     
@@ -1485,15 +1487,8 @@
 	cpcm->substream = substream;
 #ifdef CONFIG_SND_CS46XX_NEW_DSP
 	down (&chip->spos_mutex);
-	cpcm->pcm_channel = cs46xx_dsp_create_pcm_channel (chip, runtime->rate, cpcm, cpcm->hw_addr,pcm_channel_id);
-
-	if (cpcm->pcm_channel == NULL) {
-		snd_printk(KERN_ERR "cs46xx: failed to create virtual PCM channel\n");
-		snd_free_pci_pages(chip->pci, cpcm->hw_size, cpcm->hw_area, cpcm->hw_addr);
-		snd_magic_kfree(cpcm);
-		up (&chip->spos_mutex);
-		return -ENOMEM;
-	}
+	cpcm->pcm_channel = NULL; 
+	cpcm->pcm_channel_id = pcm_channel_id;
 
 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 
 				   &hw_constraints_period_sizes);
@@ -1586,6 +1581,9 @@
 
 	cpcm = snd_magic_cast(cs46xx_pcm_t, runtime->private_data, return -ENXIO);
 
+	/* when playback_open fails, then cpcm can be NULL */
+	if (!cpcm) return -ENXIO;
+
 #ifdef CONFIG_SND_CS46XX_NEW_DSP
 	down (&chip->spos_mutex);
 	if (cpcm->pcm_channel) {
@@ -1890,8 +1888,8 @@
 {
 	cs46xx_t *chip = snd_kcontrol_chip(kcontrol);
 
-	ucontrol->value.integer.value[0] = chip->dsp_spos_instance->dac_volume_right;
-	ucontrol->value.integer.value[1] = chip->dsp_spos_instance->dac_volume_left;
+	ucontrol->value.integer.value[0] = chip->dsp_spos_instance->dac_volume_left;
+	ucontrol->value.integer.value[1] = chip->dsp_spos_instance->dac_volume_right;
 
 	return 0;
 }
@@ -1916,8 +1914,8 @@
 {
 	cs46xx_t *chip = snd_kcontrol_chip(kcontrol);
 
-	ucontrol->value.integer.value[0] = chip->dsp_spos_instance->spdif_input_volume_right;
-	ucontrol->value.integer.value[1] = chip->dsp_spos_instance->spdif_input_volume_left;
+	ucontrol->value.integer.value[0] = chip->dsp_spos_instance->spdif_input_volume_left;
+	ucontrol->value.integer.value[1] = chip->dsp_spos_instance->spdif_input_volume_right;
 	return 0;
 }
 
@@ -1926,8 +1924,8 @@
 	cs46xx_t *chip = snd_kcontrol_chip(kcontrol);
 	int change = 0;
 
-	if (chip->dsp_spos_instance->spdif_input_volume_right != ucontrol->value.integer.value[0] ||
-	    chip->dsp_spos_instance->spdif_input_volume_left != ucontrol->value.integer.value[1]) {
+	if (chip->dsp_spos_instance->spdif_input_volume_left  != ucontrol->value.integer.value[0] ||
+	    chip->dsp_spos_instance->spdif_input_volume_right!= ucontrol->value.integer.value[1]) {
 		cs46xx_dsp_set_iec958_volume (chip,
 					      ucontrol->value.integer.value[0],
 					      ucontrol->value.integer.value[1]);
@@ -2042,34 +2040,6 @@
 	return 0;
 }
 
-static int snd_cs46xx_iec958_ac3_mode_get(snd_kcontrol_t *kcontrol, 
-					  snd_ctl_elem_value_t *ucontrol) 
-{
-	cs46xx_t *chip = snd_kcontrol_chip(kcontrol);
-	dsp_spos_instance_t * ins = chip->dsp_spos_instance;
-
-	if (!ins->spdif_status_out & DSP_SPDIF_STATUS_AC3_MODE) 
-		ucontrol->value.integer.value[0] = 1;
-	else
-		ucontrol->value.integer.value[0] = 0;
-
-	return 0;
-}
-
-static int snd_cs46xx_iec958_ac3_mode_put(snd_kcontrol_t *kcontrol, 
-                                      snd_ctl_elem_value_t *ucontrol) 
-{
-	cs46xx_t *chip = snd_kcontrol_chip(kcontrol);
-	dsp_spos_instance_t * ins = chip->dsp_spos_instance;
-	int old = ins->spdif_status_out;
-
-	if (ucontrol->value.integer.value[0]) 
-		ins->spdif_status_out |= DSP_SPDIF_STATUS_AC3_MODE;
-	else
-		ins->spdif_status_out &= ~DSP_SPDIF_STATUS_AC3_MODE;
-
-	return (old != ins->spdif_status_out);
-}
 
 static int snd_cs46xx_pcm_capture_put(snd_kcontrol_t *kcontrol, 
                                       snd_ctl_elem_value_t *ucontrol)
@@ -2131,8 +2101,113 @@
 	return (val1 != snd_cs46xx_peekBA0(chip, BA0_EGPIODR));
 }
 
+
+static int snd_cs46xx_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
+	uinfo->count = 1;
+	return 0;
+}
+
+static int snd_cs46xx_spdif_default_get(snd_kcontrol_t * kcontrol,
+					snd_ctl_elem_value_t * ucontrol)
+{
+	cs46xx_t *chip = snd_kcontrol_chip(kcontrol);
+	dsp_spos_instance_t * ins = chip->dsp_spos_instance;
+
+	down (&chip->spos_mutex);
+	ucontrol->value.iec958.status[0] = _wrap_all_bits((ins->spdif_csuv_default >> 24) & 0xff);
+	ucontrol->value.iec958.status[1] = _wrap_all_bits((ins->spdif_csuv_default >> 16) & 0xff);
+	ucontrol->value.iec958.status[2] = 0;
+	ucontrol->value.iec958.status[3] = _wrap_all_bits((ins->spdif_csuv_default) & 0xff);
+	up (&chip->spos_mutex);
+
+	return 0;
+}
+
+static int snd_cs46xx_spdif_default_put(snd_kcontrol_t * kcontrol,
+					snd_ctl_elem_value_t * ucontrol)
+{
+	cs46xx_t * chip = snd_kcontrol_chip(kcontrol);
+	dsp_spos_instance_t * ins = chip->dsp_spos_instance;
+	unsigned int val;
+	int change;
+
+	down (&chip->spos_mutex);
+	val = _wrap_all_bits(((u32)ucontrol->value.iec958.status[0] << 24)) |
+	      _wrap_all_bits(((u32)ucontrol->value.iec958.status[2] << 16)) |
+	      _wrap_all_bits( (u32)ucontrol->value.iec958.status[3])  |
+		/* left and right validity bit */
+		(1 << 13) | (1 << 12);
+
+
+	change = ins->spdif_csuv_default != val;
+	ins->spdif_csuv_default = val;
+
+	if ( !(ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN) )
+		cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV,val);
+
+	up (&chip->spos_mutex);
+
+	return change;
+}
+
+static int snd_cs46xx_spdif_mask_get(snd_kcontrol_t * kcontrol,
+				     snd_ctl_elem_value_t * ucontrol)
+{
+	ucontrol->value.iec958.status[0] = 0xff;
+	ucontrol->value.iec958.status[1] = 0xff;
+	ucontrol->value.iec958.status[2] = 0x00;
+	ucontrol->value.iec958.status[3] = 0xff;
+	return 0;
+}
+
+static int snd_cs46xx_spdif_stream_get(snd_kcontrol_t * kcontrol,
+                                         snd_ctl_elem_value_t * ucontrol)
+{
+	cs46xx_t *chip = snd_kcontrol_chip(kcontrol);
+	dsp_spos_instance_t * ins = chip->dsp_spos_instance;
+
+	down (&chip->spos_mutex);
+	ucontrol->value.iec958.status[0] = _wrap_all_bits((ins->spdif_csuv_stream >> 24) & 0xff);
+	ucontrol->value.iec958.status[1] = _wrap_all_bits((ins->spdif_csuv_stream >> 16) & 0xff);
+	ucontrol->value.iec958.status[2] = 0;
+	ucontrol->value.iec958.status[3] = _wrap_all_bits((ins->spdif_csuv_stream) & 0xff);
+	up (&chip->spos_mutex);
+
+	return 0;
+}
+
+static int snd_cs46xx_spdif_stream_put(snd_kcontrol_t * kcontrol,
+                                        snd_ctl_elem_value_t * ucontrol)
+{
+	cs46xx_t * chip = snd_kcontrol_chip(kcontrol);
+	dsp_spos_instance_t * ins = chip->dsp_spos_instance;
+	unsigned int val;
+	int change;
+
+	down (&chip->spos_mutex);
+	val = _wrap_all_bits(((u32)ucontrol->value.iec958.status[0] << 24)) |
+	      _wrap_all_bits(((u32)ucontrol->value.iec958.status[1] << 16)) |
+	      _wrap_all_bits( (u32)ucontrol->value.iec958.status[3]) |
+		/* left and right validity bit */
+		(1 << 13) | (1 << 12);
+
+
+	change = ins->spdif_csuv_stream != val;
+	ins->spdif_csuv_stream = val;
+
+	if ( ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN )
+		cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV,val);
+
+	up (&chip->spos_mutex);
+
+	return change;
+}
+
 #endif /* CONFIG_SND_CS46XX_NEW_DSP */
 
+
 #ifdef CONFIG_SND_CS46XX_DEBUG_GPIO
 static int snd_cs46xx_egpio_select_info(snd_kcontrol_t *kcontrol, 
                                         snd_ctl_elem_info_t *uinfo)
@@ -2242,7 +2317,7 @@
 },
 {
 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-	.name = "IEC 958 Output Switch",
+	.name = "IEC958 Output Switch",
 	.info = snd_mixer_boolean_info,
 	.get = snd_cs46xx_iec958_get,
 	.put = snd_cs46xx_iec958_put,
@@ -2250,14 +2325,7 @@
 },
 {
 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-	.name = "IEC 958 AC3 Mode Switch",
-	.info = snd_mixer_boolean_info,
-	.get = snd_cs46xx_iec958_ac3_mode_get,
-	.put = snd_cs46xx_iec958_ac3_mode_put,
-},
-{
-	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-	.name = "IEC 958 Input Switch",
+	.name = "IEC958 Input Switch",
 	.info = snd_mixer_boolean_info,
 	.get = snd_cs46xx_iec958_get,
 	.put = snd_cs46xx_iec958_put,
@@ -2265,12 +2333,34 @@
 },
 {
 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-	.name = "IEC 958 Input Volume",
+	.name = "IEC958 Input Volume",
 	.info = snd_cs46xx_vol_info,
 	.get = snd_cs46xx_vol_iec958_get,
 	.put = snd_cs46xx_vol_iec958_put,
 	.private_value = (ASYNCRX_SCB_ADDR + 0xE) << 2,
 },
+{
+	.iface = SNDRV_CTL_ELEM_IFACE_PCM,
+	.name =  SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
+	.info =	 snd_cs46xx_spdif_info,
+	.get =	 snd_cs46xx_spdif_default_get,
+	.put =   snd_cs46xx_spdif_default_put,
+},
+{
+	.iface = SNDRV_CTL_ELEM_IFACE_PCM,
+	.name =	 SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
+	.info =	 snd_cs46xx_spdif_info,
+        .get =	 snd_cs46xx_spdif_mask_get,
+	.access = SNDRV_CTL_ELEM_ACCESS_READ
+},
+{
+	.iface = SNDRV_CTL_ELEM_IFACE_PCM,
+	.name =	 SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
+	.info =	 snd_cs46xx_spdif_info,
+	.get =	 snd_cs46xx_spdif_stream_get,
+	.put =	 snd_cs46xx_spdif_stream_put
+},
+
 #endif
 #ifdef CONFIG_SND_CS46XX_DEBUG_GPIO
 {
@@ -3243,8 +3333,8 @@
 	
 #ifdef CONFIG_SND_CS46XX_NEW_DSP
 	/* set the attenuation to 0dB */ 
-	snd_cs46xx_poke(chip, (MASTERMIX_SCB_ADDR + 0xE) << 2, 0x80008000); 
-	snd_cs46xx_poke(chip, (VARIDECIMATE_SCB_ADDR + 0xE) << 2, 0x80008000);
+	/* snd_cs46xx_poke(chip, (MASTERMIX_SCB_ADDR + 0xE) << 2, 0x80008000); 
+	   snd_cs46xx_poke(chip, (VARIDECIMATE_SCB_ADDR + 0xE) << 2, 0x80008000); */
 
 	/*
 	 * Initialize cs46xx SPDIF controller
@@ -3601,7 +3691,7 @@
 	void (*mixer_init)(cs46xx_t *);
 };
 
-static struct cs_card_type __initdata cards[] = {
+static struct cs_card_type __devinitdata cards[] = {
 	{0x1489, 0x7001, "Genius Soundmaker 128 value", NULL, amp_none, NULL, NULL},
 	{0x5053, 0x3357, "Voyetra", NULL, amp_voyetra, NULL, voyetra_mixer_init},
 	{0x1071, 0x6003, "Mitac MI6020/21", NULL, amp_voyetra, NULL, NULL},
diff -Nru a/sound/pci/cs46xx/cs46xx_lib.h b/sound/pci/cs46xx/cs46xx_lib.h
--- a/sound/pci/cs46xx/cs46xx_lib.h	Mon Dec 23 21:21:51 2002
+++ b/sound/pci/cs46xx/cs46xx_lib.h	Mon Dec 23 21:21:51 2002
@@ -152,6 +152,7 @@
                                                         dsp_scb_descriptor_t * parent_scb,
                                                         int scb_child_type);
 dsp_scb_descriptor_t *  cs46xx_dsp_create_src_task_scb(cs46xx_t * chip,char * scb_name,
+						       int sample_rate,
                                                        u16 src_buffer_addr,
                                                        u16 src_delay_buffer_addr,u32 dest,
                                                        dsp_scb_descriptor_t * parent_scb,
@@ -202,8 +203,6 @@
                                                           int pcm_channel_id);
 void                       cs46xx_dsp_destroy_pcm_channel (cs46xx_t * chip,
                                                            pcm_channel_descriptor_t * pcm_channel);
-void                       cs46xx_dsp_set_src_sample_rate(cs46xx_t * chip,dsp_scb_descriptor_t * src, 
-                                                          u32 rate);
 int                        cs46xx_dsp_pcm_unlink (cs46xx_t * chip,pcm_channel_descriptor_t * pcm_channel);
 int                        cs46xx_dsp_pcm_link (cs46xx_t * chip,pcm_channel_descriptor_t * pcm_channel);
 dsp_scb_descriptor_t *     cs46xx_add_record_source (cs46xx_t *chip,dsp_scb_descriptor_t * source,
@@ -217,6 +216,6 @@
 							       int period_size);
 int                        cs46xx_dsp_pcm_ostream_set_period (cs46xx_t * chip,
 							      int period_size);
-int                        cs46xx_dsp_set_dac_volume (cs46xx_t * chip,u16 right,u16 left);
-int                        cs46xx_dsp_set_iec958_volume (cs46xx_t * chip,u16 right,u16 left);
+int                        cs46xx_dsp_set_dac_volume (cs46xx_t * chip,u16 left,u16 right);
+int                        cs46xx_dsp_set_iec958_volume (cs46xx_t * chip,u16 left,u16 right);
 #endif /* __CS46XX_LIB_H__ */
diff -Nru a/sound/pci/cs46xx/dsp_spos.c b/sound/pci/cs46xx/dsp_spos.c
--- a/sound/pci/cs46xx/dsp_spos.c	Mon Dec 23 21:21:59 2002
+++ b/sound/pci/cs46xx/dsp_spos.c	Mon Dec 23 21:21:59 2002
@@ -31,6 +31,7 @@
 #include <sound/core.h>
 #include <sound/control.h>
 #include <sound/info.h>
+#include <sound/asoundef.h>
 #include <sound/cs46xx.h>
 
 #include "cs46xx_lib.h"
@@ -262,6 +263,15 @@
 	ins->spdif_input_volume_right = 0x8000;
 	ins->spdif_input_volume_left = 0x8000;
 
+	/* set left and right validity bits and
+	   default channel status */
+	ins->spdif_csuv_default = 
+		ins->spdif_csuv_stream =  
+	 /* byte 0 */  (_wrap_all_bits(  (SNDRV_PCM_DEFAULT_CON_SPDIF        & 0xff)) << 24) |
+	 /* byte 1 */  (_wrap_all_bits( ((SNDRV_PCM_DEFAULT_CON_SPDIF >> 16) & 0xff)) << 16) |
+	 /* byte 3 */   _wrap_all_bits(  (SNDRV_PCM_DEFAULT_CON_SPDIF >> 24) & 0xff) |
+	 /* left and right validity bits */ (1 << 13) | (1 << 12);
+
 	return ins;
 }
 
@@ -605,7 +615,7 @@
 	snd_iprintf(buffer,"\nMIX_SAMPLE_BUF1:\n");
 
 	col = 0;
-	for (i = MIX_SAMPLE_BUF1;i < MIX_SAMPLE_BUF1 + 0x30; i += sizeof(u32),col ++) {
+	for (i = MIX_SAMPLE_BUF1;i < MIX_SAMPLE_BUF1 + 0x40; i += sizeof(u32),col ++) {
 		if (col == 4) {
 			snd_iprintf(buffer,"\n");
 			col = 0;
@@ -618,14 +628,14 @@
 		snd_iprintf(buffer,"%08X ",readl(dst + i));
 	}
 
-	snd_iprintf(buffer,"\n\n");
+	snd_iprintf(buffer,"\nSRC_TASK_SCB1:\n");
 	col = 0;
-	for (i = SPDIFI_IP_OUTPUT_BUFFER1;i < SPDIFI_IP_OUTPUT_BUFFER1 + 0x40; i += sizeof(u32),col ++) {
+	for (i = 0x2580 ; i < 0x2580 + 0x40 ; i += sizeof(u32),col ++) {
 		if (col == 4) {
 			snd_iprintf(buffer,"\n");
 			col = 0;
 		}
-
+		
 		if (col == 0) {
 			snd_iprintf(buffer, "%04X ",i);
 		}
@@ -636,7 +646,7 @@
 
 	snd_iprintf(buffer,"\nSPDIFO_BUFFER:\n");
 	col = 0;
-	for (i = SPDIFO_IP_OUTPUT_BUFFER1;i < SPDIFO_IP_OUTPUT_BUFFER1 + 0x40; i += sizeof(u32),col ++) {
+	for (i = SPDIFO_IP_OUTPUT_BUFFER1;i < SPDIFO_IP_OUTPUT_BUFFER1 + 0x30; i += sizeof(u32),col ++) {
 		if (col == 4) {
 			snd_iprintf(buffer,"\n");
 			col = 0;
@@ -695,7 +705,7 @@
 
 		snd_iprintf(buffer,"%08X ",readl(dst + i));
 	}
-
+#if 0
 	snd_iprintf(buffer,"\nWRITE_BACK_BUF1: \n");
 	col = 0;
 	for (i = WRITE_BACK_BUF1;i < WRITE_BACK_BUF1 + 0x40; i += sizeof(u32),col ++) {
@@ -710,7 +720,22 @@
 
 		snd_iprintf(buffer,"%08X ",readl(dst + i));
 	}
+#endif
 
+	snd_iprintf(buffer,"\nSPDIFI_IP_OUTPUT_BUFFER1: \n");
+	col = 0;
+	for (i = SPDIFI_IP_OUTPUT_BUFFER1;i < SPDIFI_IP_OUTPUT_BUFFER1 + 0x80; i += sizeof(u32),col ++) {
+		if (col == 4) {
+			snd_iprintf(buffer,"\n");
+			col = 0;
+		}
+
+		if (col == 0) {
+			snd_iprintf(buffer, "%04X ",i);
+		}
+		
+		snd_iprintf(buffer,"%08X ",readl(dst + i));
+	}
 	snd_iprintf(buffer,"\n");
 }
 
@@ -1346,6 +1371,7 @@
 
 	/* SPDIF input sampel rate converter */
 	src_task_scb = cs46xx_dsp_create_src_task_scb(chip,"SrcTaskSCB_SPDIFI",
+						      48000,
 						      SRC_OUTPUT_BUF1,
 						      SRC_DELAY_BUF1,SRCTASK_SCB_ADDR,
 						      master_mix_scb,
@@ -1549,7 +1575,7 @@
 	cs46xx_poke_via_dsp (chip,SP_SPDOUT_CONTROL, 0x80000000);
 
 	/* right and left validate bit */
-	cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, 0x00000000 | (1 << 13) | (1 << 12));
+	cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_default);
 
 	/* monitor state */
 	ins->spdif_status_out |= DSP_SPDIF_STATUS_HW_ENABLED;
@@ -1587,16 +1613,14 @@
 	cs46xx_poke_via_dsp (chip,SP_SPDIN_FIFOPTR, 0x0);
 	cs46xx_src_link(chip,ins->spdif_in_src);
 
-	/* restore SPDIF input volume */
-	cs46xx_dsp_scb_set_volume (chip,ins->spdif_in_src,
-				   ins->spdif_input_volume_right,
-				   ins->spdif_input_volume_left);
+	/* unmute SRC volume */
+	cs46xx_dsp_scb_set_volume (chip,ins->spdif_in_src,0x7fff,0x7fff);
 
 	spin_unlock_irq(&chip->reg_lock);
 
 	/* set SPDIF input sample rate and unmute
 	   NOTE: only 48khz support for SPDIF input this time */
-	cs46xx_dsp_set_src_sample_rate(chip,ins->spdif_in_src,48000);
+	/* cs46xx_dsp_set_src_sample_rate(chip,ins->spdif_in_src,48000); */
 
 	/* monitor state */
 	ins->spdif_status_in = 1;
@@ -1725,39 +1749,47 @@
 	return 0;
 }
 
-int cs46xx_dsp_set_dac_volume (cs46xx_t * chip,u16 right,u16 left)
+int cs46xx_dsp_set_dac_volume (cs46xx_t * chip,u16 left,u16 right)
 {
-	int i;
 	dsp_spos_instance_t * ins = chip->dsp_spos_instance;
+	dsp_scb_descriptor_t * scb; 
 
 	down(&chip->spos_mutex);
+	
+	/* main output */
+	scb = ins->master_mix_scb->sub_list_ptr;
+	while (scb != ins->the_null_scb) {
+		cs46xx_dsp_scb_set_volume (chip,scb,left,right);
+		scb = scb->next_scb_ptr;
+	}
 
-	ins->dac_volume_right = right;
-	ins->dac_volume_left = left;
-
-	for (i = 0; i < DSP_MAX_PCM_CHANNELS; ++i) {
-		if (ins->pcm_channels[i].active &&
-		    !ins->pcm_channels[i].unlinked) {
-			cs46xx_dsp_scb_set_volume (chip,ins->pcm_channels[i].pcm_reader_scb,
-						   right,left);
-			
-		}
+	/* rear output */
+	scb = ins->rear_mix_scb->sub_list_ptr;
+	while (scb != ins->the_null_scb) {
+		cs46xx_dsp_scb_set_volume (chip,scb,left,right);
+		scb = scb->next_scb_ptr;
 	}
 
+	ins->dac_volume_left = left;
+	ins->dac_volume_right = right;
+
 	up(&chip->spos_mutex);
 
 	return 0;
 }
 
-int cs46xx_dsp_set_iec958_volume (cs46xx_t * chip,u16 right,u16 left) {
+int cs46xx_dsp_set_iec958_volume (cs46xx_t * chip,u16 left,u16 right) {
 	dsp_spos_instance_t * ins = chip->dsp_spos_instance;
 
 	down(&chip->spos_mutex);
-	cs46xx_dsp_scb_set_volume (chip,ins->spdif_in_src,
-				   right,left);
 
-	ins->spdif_input_volume_right = right;
+	if (ins->asynch_rx_scb != NULL)
+		cs46xx_dsp_scb_set_volume (chip,ins->asynch_rx_scb,
+					   left,right);
+
 	ins->spdif_input_volume_left = left;
+	ins->spdif_input_volume_right = right;
+
 	up(&chip->spos_mutex);
 
 	return 0;
diff -Nru a/sound/pci/cs46xx/dsp_spos.h b/sound/pci/cs46xx/dsp_spos.h
--- a/sound/pci/cs46xx/dsp_spos.h	Mon Dec 23 21:21:50 2002
+++ b/sound/pci/cs46xx/dsp_spos.h	Mon Dec 23 21:21:50 2002
@@ -185,6 +185,25 @@
 #define SP_SPDOUT_CONTROL 0x804D
 #define SP_SPDOUT_CSUV    0x808E
 
+static inline u8 _wrap_all_bits (u8 val) {
+	u8 wrapped;
+	
+	/* wrap all 8 bits */
+	wrapped = 
+		((val & 0x1 ) << 7) |
+		((val & 0x2 ) << 5) |
+		((val & 0x4 ) << 3) |
+		((val & 0x8 ) << 1) |
+		((val & 0x10) >> 1) |
+		((val & 0x20) >> 3) |
+		((val & 0x40) >> 5) |
+		((val & 0x80) >> 7);
+
+	return wrapped;
+
+}
+
+
 static inline void cs46xx_dsp_spos_update_scb (cs46xx_t * chip,dsp_scb_descriptor_t * scb) 
 {
 	/* update nextSCB and subListPtr in SCB */
@@ -195,12 +214,11 @@
 }
 
 static inline void cs46xx_dsp_scb_set_volume (cs46xx_t * chip,dsp_scb_descriptor_t * scb,
-					      u16 right,u16 left) {
-	unsigned int val = ((0xffff - right) << 16 | (0xffff - left));	
+					      u16 left,u16 right) {
+	unsigned int val = ((0xffff - left) << 16 | (0xffff - right));
 
 	snd_cs46xx_poke(chip, (scb->address + SCBVolumeCtrl) << 2, val);
 	snd_cs46xx_poke(chip, (scb->address + SCBVolumeCtrl + 1) << 2, val);
 }
-
 #endif /* __DSP_SPOS_H__ */
 #endif /* CONFIG_SND_CS46XX_NEW_DSP  */
diff -Nru a/sound/pci/cs46xx/dsp_spos_scb_lib.c b/sound/pci/cs46xx/dsp_spos_scb_lib.c
--- a/sound/pci/cs46xx/dsp_spos_scb_lib.c	Mon Dec 23 21:22:00 2002
+++ b/sound/pci/cs46xx/dsp_spos_scb_lib.c	Mon Dec 23 21:22:00 2002
@@ -576,8 +576,11 @@
 	return scb;
 }
 
+#define GOF_PER_SEC 200
+
 dsp_scb_descriptor_t * 
 cs46xx_dsp_create_src_task_scb(cs46xx_t * chip,char * scb_name,
+			       int rate,
                                u16 src_buffer_addr,
                                u16 src_delay_buffer_addr,u32 dest,
                                dsp_scb_descriptor_t * parent_scb,
@@ -586,45 +589,81 @@
 
 	dsp_spos_instance_t * ins = chip->dsp_spos_instance;
 	dsp_scb_descriptor_t * scb;
-    
-	src_task_scb_t src_task_scb = {
-		0x0028,0x00c8,
-		0x5555,0x0000,
-		0x0000,0x0000,
-		src_buffer_addr,1,
-		0x0028,0x00c8,
-		RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_32,  
-		0x0000,src_delay_buffer_addr,                  
-		0x0,                                            
-		0x80,(src_delay_buffer_addr + (24 * 4)),
-		0,0, /* next_scb, sub_list_ptr */
-		0,0, /* entry, this_spb */
-		RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_8,
-		src_buffer_addr << 0x10,
-		0x04000000,
-		{ 
-			0x8000,0x8000,
-			0xffff,0xffff
-		}
-	};
+	unsigned int tmp1, tmp2;
+	unsigned int phiIncr;
+	unsigned int correctionPerGOF, correctionPerSec;
 
-	if (ins->s16_up == NULL) {
-		ins->s16_up =  cs46xx_dsp_lookup_symbol (chip,"S16_UPSRC",
-							 SYMBOL_CODE);
-    
-		if (ins->s16_up == NULL) {
-			snd_printk (KERN_ERR "dsp_spos: symbol S16_UPSRC not found\n");
-			return NULL;
-		}    
-	}
+	snd_printdd( "dsp_spos: setting %s rate to %u\n",scb_name,rate);
 
-	/* clear buffers */
-	_dsp_clear_sample_buffer (chip,src_buffer_addr,8);
-	_dsp_clear_sample_buffer (chip,src_delay_buffer_addr,32);
+	/*
+	 *  Compute the values used to drive the actual sample rate conversion.
+	 *  The following formulas are being computed, using inline assembly
+	 *  since we need to use 64 bit arithmetic to compute the values:
+	 *
+	 *  phiIncr = floor((Fs,in * 2^26) / Fs,out)
+	 *  correctionPerGOF = floor((Fs,in * 2^26 - Fs,out * phiIncr) /
+	 *                                   GOF_PER_SEC)
+	 *  ulCorrectionPerSec = Fs,in * 2^26 - Fs,out * phiIncr -M
+	 *                       GOF_PER_SEC * correctionPerGOF
+	 *
+	 *  i.e.
+	 *
+	 *  phiIncr:other = dividend:remainder((Fs,in * 2^26) / Fs,out)
+	 *  correctionPerGOF:correctionPerSec =
+	 *      dividend:remainder(ulOther / GOF_PER_SEC)
+	 */
+	tmp1 = rate << 16;
+	phiIncr = tmp1 / 48000;
+	tmp1 -= phiIncr * 48000;
+	tmp1 <<= 10;
+	phiIncr <<= 10;
+	tmp2 = tmp1 / 48000;
+	phiIncr += tmp2;
+	tmp1 -= tmp2 * 48000;
+	correctionPerGOF = tmp1 / GOF_PER_SEC;
+	tmp1 -= correctionPerGOF * GOF_PER_SEC;
+	correctionPerSec = tmp1;
 
-	scb = _dsp_create_generic_scb(chip,scb_name,(u32 *)&src_task_scb,
-				      dest,ins->s16_up,parent_scb,
-				      scb_child_type);
+	{
+		src_task_scb_t src_task_scb = {
+			0x0028,0x00c8,
+			0x5555,0x0000,
+			0x0000,0x0000,
+			src_buffer_addr,1,
+			correctionPerGOF,correctionPerSec,
+			RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_32,  
+			0x0000,src_delay_buffer_addr,                  
+			0x0,                                            
+			0x080,(src_delay_buffer_addr + (24 * 4)),
+			0,0, /* next_scb, sub_list_ptr */
+			0,0, /* entry, this_spb */
+			RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_8,
+			src_buffer_addr << 0x10,
+			phiIncr,
+			{ 
+				0xffff - ins->dac_volume_right,0xffff - ins->dac_volume_left,
+				0xffff - ins->dac_volume_right,0xffff - ins->dac_volume_left
+			}
+		};
+		
+		if (ins->s16_up == NULL) {
+			ins->s16_up =  cs46xx_dsp_lookup_symbol (chip,"S16_UPSRC",
+								 SYMBOL_CODE);
+			
+			if (ins->s16_up == NULL) {
+				snd_printk (KERN_ERR "dsp_spos: symbol S16_UPSRC not found\n");
+				return NULL;
+			}    
+		}
+		
+		/* clear buffers */
+		_dsp_clear_sample_buffer (chip,src_buffer_addr,8);
+		_dsp_clear_sample_buffer (chip,src_delay_buffer_addr,32);
+		
+		scb = _dsp_create_generic_scb(chip,scb_name,(u32 *)&src_task_scb,
+					      dest,ins->s16_up,parent_scb,
+					      scb_child_type);
+	}
 
 	return scb;
 }
@@ -658,7 +697,7 @@
 		/* D */ 0,
 		{
 			/* E */ 0x8000,0x8000,
-			/* F */ 0xffff,0xffff
+			/* F */ 0x8000,0x8000
 		}
 	};
 
@@ -796,7 +835,7 @@
 
 		RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_16,
 		0,
-		0,input_scb->address, 
+		0,input_scb->address,
 		{
 			0x8000,0x8000,
 			0x8000,0x8000
@@ -830,7 +869,7 @@
 		0,0x2aab,           /* Const 1/3 */
     
 		{
-			0,                /* Define the unused elements */
+			0,         /* Define the unused elements */
 			0,
 			0
 		},
@@ -846,7 +885,7 @@
 		   rate etc  */
 		0x18000000,                     /* Phi increment for approx 32k operation */
 		0x8000,0x8000,                  /* Volume controls are unused at this time */
-		0xffff,0xffff
+		0x8000,0x8000
 	};
   
 	scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&asynch_fg_tx_scb,
@@ -864,7 +903,7 @@
                                    dsp_scb_descriptor_t * parent_scb,
                                    int scb_child_type)
 {
-
+	dsp_spos_instance_t * ins = chip->dsp_spos_instance;
 	dsp_scb_descriptor_t * scb;
 
 	asynch_fg_rx_scb_t asynch_fg_rx_scb = {
@@ -893,9 +932,9 @@
 		   rate etc  */
 		0x18000000,         
 
-		/* Mute stream */
-		0x8000,0x8000,       
-		0xffff,0xffff
+		/* Set IEC958 input volume */
+		0xffff - ins->spdif_input_volume_right,0xffff - ins->spdif_input_volume_left,
+		0xffff - ins->spdif_input_volume_right,0xffff - ins->spdif_input_volume_left,
 	};
 
 	scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&asynch_fg_rx_scb,
@@ -1007,7 +1046,7 @@
 		/* C */ snoop_buffer_address  << 0x10,
 		/* D */ 0,
 		/* E */ { 0x8000,0x8000,
-			  /* F */   0xffff,0xffff
+	        /* F */   0xffff,0xffff
 		}
 	};
 
@@ -1093,6 +1132,8 @@
 {
 	dsp_spos_instance_t * ins = chip->dsp_spos_instance;
 	dsp_scb_descriptor_t * src_scb = NULL,* pcm_scb, * mixer_scb = NULL;
+	dsp_scb_descriptor_t * src_parent_scb = NULL;
+
 	/*dsp_scb_descriptor_t * pcm_parent_scb;*/
 	char scb_name[DSP_MAX_SCB_NAME];
 	int i,pcm_index = -1, insert_point, src_index = -1;
@@ -1116,10 +1157,13 @@
 	case DSP_IEC958_CHANNEL:
 		snd_assert (ins->asynch_tx_scb != NULL, return NULL);
 		mixer_scb = ins->asynch_tx_scb;
-		if (ins->spdif_status_out & DSP_SPDIF_STATUS_AC3_MODE) {
-			snd_printdd ("IEC958 opened in AC3 mode\n");
-			/*src_scb = ins->asynch_tx_scb;
-			  ins->asynch_tx_scb->ref_count ++;*/
+
+		/* if sample rate is set to 48khz we pass
+		   the Sample Rate Converted (which could
+		   alter the raw data stream ...) */
+		if (sample_rate == 48000) {
+			snd_printdd ("IEC958 pass through\n");
+			src_parent_scb = ins->asynch_tx_scb;
 		}
 		break;
 	default:
@@ -1156,8 +1200,6 @@
 	}
 
 	if (src_scb == NULL) {
-		dsp_scb_descriptor_t * src_parent_scb;
-
 		if (ins->nsrc_scb >= DSP_MAX_SRC_NR) {
 			snd_printk(KERN_ERR "dsp_spos: to many SRC instances\n!");
 			return NULL;
@@ -1174,18 +1216,21 @@
 		snd_assert (src_index != -1,return NULL);
 
 		/* we need to create a new SRC SCB */
-		if (mixer_scb->sub_list_ptr == ins->the_null_scb) {
-			src_parent_scb = mixer_scb;
-			insert_point = SCB_ON_PARENT_SUBLIST_SCB;
-		} else {
-			src_parent_scb = find_next_free_scb(chip,mixer_scb->sub_list_ptr);
-			insert_point = SCB_ON_PARENT_NEXT_SCB;
-		}
+		if (src_parent_scb == NULL) {
+			if (mixer_scb->sub_list_ptr == ins->the_null_scb) {
+				src_parent_scb = mixer_scb;
+				insert_point = SCB_ON_PARENT_SUBLIST_SCB;
+			} else {
+				src_parent_scb = find_next_free_scb(chip,mixer_scb->sub_list_ptr);
+				insert_point = SCB_ON_PARENT_NEXT_SCB;
+			}
+		} else insert_point = SCB_ON_PARENT_NEXT_SCB;
 
 		snprintf (scb_name,DSP_MAX_SCB_NAME,"SrcTask_SCB%d",src_index);
 
 		snd_printdd( "dsp_spos: creating SRC \"%s\"\n",scb_name);
 		src_scb = cs46xx_dsp_create_src_task_scb(chip,scb_name,
+							 sample_rate,
 							 src_output_buffer_addr[src_index],
 							 src_delay_buffer_addr[src_index],
 							 /* 0x400 - 0x600 source SCBs */
@@ -1198,9 +1243,7 @@
 			return NULL;
 		}
 
-		if (pcm_channel_id != DSP_IEC958_CHANNEL ||
-		    !(ins->spdif_status_out & DSP_SPDIF_STATUS_AC3_MODE))
-			cs46xx_dsp_set_src_sample_rate(chip,src_scb,sample_rate);
+		/* cs46xx_dsp_set_src_sample_rate(chip,src_scb,sample_rate); */
 
 		ins->nsrc_scb ++;
 	} 
@@ -1226,6 +1269,19 @@
 		return NULL;
 	}
 
+	if (pcm_channel_id == DSP_IEC958_CHANNEL && sample_rate == 48000) {
+		snd_assert (ins->spdif_pcm_input_scb == NULL);
+		
+		/* a hack to make the skip the SRC and pass the stream 
+		   directly to the SPDIF task */
+		ins->spdif_pcm_input_scb = 
+			cs46xx_dsp_create_pcm_serial_input_scb(chip,"PCMSerialInput_PCM",
+							       PCMSERIALINII_SCB_ADDR,
+							       pcm_scb,
+							       ins->asynch_tx_scb,
+							       SCB_ON_PARENT_SUBLIST_SCB);		
+	}
+	
 	spin_lock_irqsave(&chip->reg_lock, flags);
 	ins->pcm_channels[pcm_index].sample_rate = sample_rate;
 	ins->pcm_channels[pcm_index].pcm_reader_scb = pcm_scb;
@@ -1236,7 +1292,6 @@
 	ins->pcm_channels[pcm_index].active = 1;
 	ins->pcm_channels[pcm_index].pcm_slot = pcm_index;
 	ins->pcm_channels[pcm_index].mixer_scb = mixer_scb;
-	ins->pcm_channels[pcm_index].pcm_channel_id = pcm_channel_id;
 	ins->npcm_channels ++;
 	spin_unlock_irqrestore(&chip->reg_lock, flags);
 
@@ -1416,65 +1471,6 @@
 	return 0;
 }
 
-
-#define GOF_PER_SEC 200
-  
-void cs46xx_dsp_set_src_sample_rate(cs46xx_t *chip,dsp_scb_descriptor_t * src, u32 rate)
-{
-	unsigned long flags;
-	unsigned int tmp1, tmp2;
-	unsigned int phiIncr;
-	unsigned int correctionPerGOF, correctionPerSec;
-
-	snd_printdd( "dsp_spos: setting SRC rate to %u\n",rate);
-	/*
-	 *  Compute the values used to drive the actual sample rate conversion.
-	 *  The following formulas are being computed, using inline assembly
-	 *  since we need to use 64 bit arithmetic to compute the values:
-	 *
-	 *  phiIncr = floor((Fs,in * 2^26) / Fs,out)
-	 *  correctionPerGOF = floor((Fs,in * 2^26 - Fs,out * phiIncr) /
-	 *                                   GOF_PER_SEC)
-	 *  ulCorrectionPerSec = Fs,in * 2^26 - Fs,out * phiIncr -M
-	 *                       GOF_PER_SEC * correctionPerGOF
-	 *
-	 *  i.e.
-	 *
-	 *  phiIncr:other = dividend:remainder((Fs,in * 2^26) / Fs,out)
-	 *  correctionPerGOF:correctionPerSec =
-	 *      dividend:remainder(ulOther / GOF_PER_SEC)
-	 */
-	tmp1 = rate << 16;
-	phiIncr = tmp1 / 48000;
-	tmp1 -= phiIncr * 48000;
-	tmp1 <<= 10;
-	phiIncr <<= 10;
-	tmp2 = tmp1 / 48000;
-	phiIncr += tmp2;
-	tmp1 -= tmp2 * 48000;
-	correctionPerGOF = tmp1 / GOF_PER_SEC;
-	tmp1 -= correctionPerGOF * GOF_PER_SEC;
-	correctionPerSec = tmp1;
-
-	/*
-	 *  Fill in the SampleRateConverter control block.
-	 */
-	spin_lock_irqsave(&chip->reg_lock, flags);
-
-	/* mute SCB */
-	/* cs46xx_dsp_scb_set_volume (chip,src,0,0); */
-
-	snd_cs46xx_poke(chip, (src->address + SRCCorPerGof) << 2,
-	  ((correctionPerSec << 16) & 0xFFFF0000) | (correctionPerGOF & 0xFFFF));
-
-	snd_cs46xx_poke(chip, (src->address + SRCPhiIncr6Int26Frac) << 2, phiIncr);
-
-	/* raise volume */
-	/* cs46xx_dsp_scb_set_volume (chip,src,0x7fff,0x7fff); */
-	
-	spin_unlock_irqrestore(&chip->reg_lock, flags);
-}
-
 dsp_scb_descriptor_t * cs46xx_add_record_source (cs46xx_t *chip,dsp_scb_descriptor_t * source,
                                                  u16 addr,char * scb_name)
 {
@@ -1641,9 +1637,8 @@
 								SCB_ON_PARENT_NEXT_SCB);
 
 
-	if (ins->spdif_status_out & DSP_SPDIF_STATUS_AC3_MODE) 
-		/* set left (13), right validity bit (12) , and non-audio(1) and profsional bit (0) */
-		cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, 0x00000000 | (1 << 13) | (1 << 12) | (1 << 1) | 1);
+	/* set spdif channel status value for streaming */
+	cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_stream);
 
 	ins->spdif_status_out  |= DSP_SPDIF_STATUS_PLAYBACK_OPEN;
 
@@ -1659,13 +1654,22 @@
 	ins->spdif_status_out  &= ~DSP_SPDIF_STATUS_PLAYBACK_OPEN;
 
 	/* restore settings */
-	cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, 0x00000000 | (1 << 13) | (1 << 12));
+	cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_default);
 	
 	/* deallocate stuff */
+	if (ins->spdif_pcm_input_scb != NULL) {
+		cs46xx_dsp_remove_scb (chip,ins->spdif_pcm_input_scb);
+		ins->spdif_pcm_input_scb = NULL;
+	}
+
 	cs46xx_dsp_remove_scb (chip,ins->asynch_tx_scb);
 	ins->asynch_tx_scb = NULL;
 
+	/* clear buffer to prevent any undesired noise */
+	_dsp_clear_sample_buffer(chip,SPDIFO_IP_OUTPUT_BUFFER1,256);
+
 	/* restore state */
+
 	if ( ins->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED ) {
 		cs46xx_dsp_enable_spdif_out (chip);
 	}
diff -Nru a/sound/pci/emu10k1/emu10k1.c b/sound/pci/emu10k1/emu10k1.c
--- a/sound/pci/emu10k1/emu10k1.c	Mon Dec 23 21:21:50 2002
+++ b/sound/pci/emu10k1/emu10k1.c	Mon Dec 23 21:21:50 2002
@@ -199,7 +199,7 @@
 }
 
 static struct pci_driver driver = {
-	.name = "EMU10K1/Audigy",
+	.name = "EMU10K1_Audigy",
 	.id_table = snd_emu10k1_ids,
 	.probe = snd_card_emu10k1_probe,
 	.remove = __devexit_p(snd_card_emu10k1_remove),
diff -Nru a/sound/pci/ens1370.c b/sound/pci/ens1370.c
--- a/sound/pci/ens1370.c	Mon Dec 23 21:21:59 2002
+++ b/sound/pci/ens1370.c	Mon Dec 23 21:21:59 2002
@@ -26,6 +26,7 @@
 #include <linux/init.h>
 #include <linux/pci.h>
 #include <linux/slab.h>
+#include <linux/gameport.h>
 #include <sound/core.h>
 #include <sound/control.h>
 #include <sound/pcm.h>
@@ -403,6 +404,9 @@
 	unsigned char *bugbuf;
 	dma_addr_t bugbuf_addr;
 #endif
+
+	struct gameport gameport;
+	struct semaphore joy_sem;	// gameport configuration semaphore
 };
 
 static void snd_audiopci_interrupt(int irq, void *dev_id, struct pt_regs *regs);
@@ -1355,6 +1359,7 @@
 
 static snd_kcontrol_new_t snd_ens1373_spdif_mask __devinitdata =
 {
+	.access =	SNDRV_CTL_ELEM_ACCESS_READ,
 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM,
 	.name =		SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
 	.info =		snd_ens1373_spdif_info,
@@ -1509,6 +1514,8 @@
 	return 0;
 }
 
+#ifdef CHIP1370
+
 static int snd_ensoniq_control_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
 {
 	ensoniq_t *ensoniq = snd_kcontrol_chip(kcontrol);
@@ -1527,8 +1534,6 @@
 	return change;
 }
 
-#ifdef CHIP1370
-
 #define ES1370_CONTROLS 2
 
 static snd_kcontrol_new_t snd_es1370_controls[2] __devinitdata = {
@@ -1571,8 +1576,67 @@
  *  General Switches...
  */
 
+/* MQ: gameport driver connectivity */
+#define ENSONIQ_JOY_CONTROL(xname, mask) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_CARD, .name = xname, .info = snd_ensoniq_control_info, \
+  .get = snd_ensoniq_control_get, .put = snd_ensoniq_joy_control_put, \
+  .private_value = mask }
+
+static int snd_ensoniq_joy_enable(ensoniq_t *ensoniq)
+{
+	static int last_jiffies = 0;
+	unsigned long flags;
+
+	if (!request_region(ensoniq->gameport.io, 8, "ens137x: gameport")) {
+#define ES___GAMEPORT_LOG_DELAY (30*HZ)
+		// avoid log pollution: limit to 2 infos per minute
+		if (jiffies > last_jiffies + ES___GAMEPORT_LOG_DELAY) {
+			last_jiffies = jiffies;
+			snd_printk("gameport io port 0x%03x in use", ensoniq->gameport.io);
+		}
+		return 0;
+	}
+	spin_lock_irqsave(&ensoniq->reg_lock, flags);
+	ensoniq->ctrl |= ES_JYSTK_EN;
+	outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
+	spin_unlock_irqrestore(&ensoniq->reg_lock, flags);
+	gameport_register_port(&ensoniq->gameport);
+	return 1;
+}
+
+static int snd_ensoniq_joy_disable(ensoniq_t *ensoniq)
+{
+	unsigned long flags;
+
+	gameport_unregister_port(&ensoniq->gameport);
+	spin_lock_irqsave(&ensoniq->reg_lock, flags);
+	ensoniq->ctrl &= ~ES_JYSTK_EN;
+	outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
+	spin_unlock_irqrestore(&ensoniq->reg_lock, flags);
+	release_region(ensoniq->gameport.io, 8);
+	return 1;
+}
+
+static int snd_ensoniq_joy_control_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	ensoniq_t *ensoniq = snd_kcontrol_chip(kcontrol);
+	unsigned int nval;
+	int change;
+
+	down(&ensoniq->joy_sem);
+	nval = ucontrol->value.integer.value[0] ? ES_JYSTK_EN : 0;
+	change = (ensoniq->ctrl & ES_JYSTK_EN) != nval;	// spinlock shouldn't be needed because of joy_sem
+	if (change) {
+		if (nval)	// enable
+			change = snd_ensoniq_joy_enable(ensoniq);
+		else	change = snd_ensoniq_joy_disable(ensoniq);
+	}
+	up(&ensoniq->joy_sem);
+	return change;
+}
+
 static snd_kcontrol_new_t snd_ensoniq_control_joystick __devinitdata =
-ENSONIQ_CONTROL("Joystick Enable", ES_JYSTK_EN);
+ENSONIQ_JOY_CONTROL("Joystick Enable", ES_JYSTK_EN);
 
 #ifdef CHIP1371
 
@@ -1584,9 +1648,9 @@
 {
         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
         uinfo->count = 1;
-        uinfo->value.enumerated.items = 3;
-	if (uinfo->value.enumerated.item >= 3)
-		uinfo->value.enumerated.item = 2;
+        uinfo->value.enumerated.items = 4;
+	if (uinfo->value.enumerated.item >= 4)
+		uinfo->value.enumerated.item = 3;
 	sprintf(uinfo->value.enumerated.name, "port 0x%x", (uinfo->value.enumerated.item * 8) + 0x200);
         return 0;
 }
@@ -1608,14 +1672,20 @@
 	unsigned long flags;
 	unsigned int nval;
 	int change;
-	
+
+	down(&ensoniq->joy_sem);
 	nval = ES_1371_JOY_ASEL(ucontrol->value.integer.value[0]);
 	spin_lock_irqsave(&ensoniq->reg_lock, flags);
+	if (!(change = !(ensoniq->ctrl & ES_JYSTK_EN)))
+		goto no_change;	// FIXME: now we allow change only when joystick is disabled
 	change = (ensoniq->ctrl & ES_1371_JOY_ASELM) != nval;
 	ensoniq->ctrl &= ~ES_1371_JOY_ASELM;
 	ensoniq->ctrl |= nval;
 	outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
+	ensoniq->gameport.io = 0x200 + ES_1371_JOY_ASELI(nval) * 8;
+no_change:
 	spin_unlock_irqrestore(&ensoniq->reg_lock, flags);
+	up(&ensoniq->joy_sem);
 	return change;
 }
 
@@ -1679,6 +1749,8 @@
 
 static int snd_ensoniq_free(ensoniq_t *ensoniq)
 {
+	if (ensoniq->ctrl & ES_JYSTK_EN)
+		snd_ensoniq_joy_disable(ensoniq);
 	snd_ensoniq_proc_done(ensoniq);
 	if (ensoniq->irq < 0)
 		goto __hw_end;
@@ -1759,6 +1831,7 @@
 	if (ensoniq == NULL)
 		return -ENOMEM;
 	spin_lock_init(&ensoniq->reg_lock);
+	init_MUTEX(&ensoniq->joy_sem);
 	ensoniq->card = card;
 	ensoniq->pci = pci;
 	ensoniq->irq = -1;
@@ -1873,10 +1946,11 @@
 	outb(ensoniq->uartc = 0x00, ES_REG(ensoniq, UART_CONTROL));
 	outb(0x00, ES_REG(ensoniq, UART_RES));
 	outl(ensoniq->cssr, ES_REG(ensoniq, STATUS));
-	snd_ctl_add(card, snd_ctl_new1(&snd_ensoniq_control_joystick, ensoniq));
 #ifdef CHIP1371
 	snd_ctl_add(card, snd_ctl_new1(&snd_es1371_joystick_addr, ensoniq));
 #endif
+	snd_ctl_add(card, snd_ctl_new1(&snd_ensoniq_control_joystick, ensoniq));
+	ensoniq->gameport.io = 0x200;	// FIXME: is ES1371 configured like this above ?
 	synchronize_irq(ensoniq->irq);
 
 	if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ensoniq, &ops)) < 0) {
@@ -2181,10 +2255,10 @@
 		return err;
 	}
 #ifdef CHIP1370
-	strcpy(card->driver, "ES1370");
+	strcpy(card->driver, "ENS1370");
 #endif
 #ifdef CHIP1371
-	strcpy(card->driver, "ES1371");
+	strcpy(card->driver, "ENS1371");
 #endif
 	strcpy(card->shortname, "Ensoniq AudioPCI");
 	sprintf(card->longname, "%s %s at 0x%lx, irq %i",
diff -Nru a/sound/pci/es1938.c b/sound/pci/es1938.c
--- a/sound/pci/es1938.c	Mon Dec 23 21:21:58 2002
+++ b/sound/pci/es1938.c	Mon Dec 23 21:21:58 2002
@@ -985,7 +985,7 @@
 	snd_pcm_lib_preallocate_free_for_all(pcm);
 }
 
-static int __init snd_es1938_new_pcm(es1938_t *chip, int device, snd_pcm_t ** rpcm)
+static int __devinit snd_es1938_new_pcm(es1938_t *chip, int device, snd_pcm_t ** rpcm)
 {
 	snd_pcm_t *pcm;
 	int err;
@@ -1364,7 +1364,7 @@
 	return snd_es1938_free(chip);
 }
 
-static int __init snd_es1938_create(snd_card_t * card,
+static int __devinit snd_es1938_create(snd_card_t * card,
 				    struct pci_dev * pci,
 				    unsigned long dma1size,
 				    unsigned long dma2size,
@@ -1541,7 +1541,7 @@
 
 #define ES1938_DMA_SIZE 64
 
-static int __init snd_es1938_mixer(snd_pcm_t *pcm)
+static int __devinit snd_es1938_mixer(snd_pcm_t *pcm)
 {
 	snd_card_t *card;
 	es1938_t *chip;
diff -Nru a/sound/pci/es1968.c b/sound/pci/es1968.c
--- a/sound/pci/es1968.c	Mon Dec 23 21:21:58 2002
+++ b/sound/pci/es1968.c	Mon Dec 23 21:21:58 2002
@@ -129,6 +129,7 @@
 static int pcm_substreams_p[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 4 };
 static int pcm_substreams_c[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1 };
 static int clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
+static int use_pm[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
 
 MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
 MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
@@ -151,6 +152,9 @@
 MODULE_PARM(clock, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
 MODULE_PARM_DESC(clock, "Clock on " CARD_NAME " soundcard.  (0 = auto-detect)");
 MODULE_PARM_SYNTAX(clock, SNDRV_ENABLED);
+MODULE_PARM(use_pm, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
+MODULE_PARM_DESC(use_pm, "Toggle power-management.  (0 = off, 1 = on, 2 = auto)");
+MODULE_PARM_SYNTAX(use_pm, SNDRV_ENABLED ",allows:{{0,1,2}},skill:advanced");
 
 
 /* PCI Dev ID's */
@@ -493,6 +497,11 @@
 	ESM_APU_FREE
 };
 
+/* chip type */
+enum {
+	TYPE_MAESTRO, TYPE_MAESTRO2, TYPE_MAESTRO2E
+};
+
 /* DMA Hack! */
 struct snd_esm_memory {
 	char *buf;
@@ -558,6 +567,7 @@
 	struct pci_dev *pci;
 	snd_card_t *card;
 	snd_pcm_t *pcm;
+	int do_pm;		/* power-management enabled */
 
 	/* DMA memory block */
 	struct list_head buf_list;
@@ -593,17 +603,13 @@
 
 static void snd_es1968_interrupt(int irq, void *dev_id, struct pt_regs *regs);
 
-#define CARD_TYPE_ESS_ESOLDM1		0x12850100
-#define CARD_TYPE_ESS_ES1968		0x125d1968
-#define CARD_TYPE_ESS_ES1978		0x125d1978
-
 static struct pci_device_id snd_es1968_ids[] __devinitdata = {
 	/* Maestro 1 */
-        { 0x1285, 0x0100, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, },
+        { 0x1285, 0x0100, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, TYPE_MAESTRO },
 	/* Maestro 2 */
-	{ 0x125d, 0x1968, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, },
+	{ 0x125d, 0x1968, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, TYPE_MAESTRO2 },
 	/* Maestro 2E */
-        { 0x125d, 0x1978, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, },
+        { 0x125d, 0x1978, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, TYPE_MAESTRO2E },
 	{ 0, }
 };
 
@@ -2411,6 +2417,9 @@
 {
 	snd_card_t *card = chip->card;
 
+	if (! chip->do_pm)
+		return;
+
 	snd_power_lock(card);
 	if (card->power_state == SNDRV_CTL_POWER_D3hot)
 		goto __skip;
@@ -2426,6 +2435,9 @@
 {
 	snd_card_t *card = chip->card;
 
+	if (! chip->do_pm)
+		return;
+
 	snd_power_lock(card);
 	if (card->power_state == SNDRV_CTL_POWER_D0)
 		goto __skip;
@@ -2524,11 +2536,13 @@
 }
 
 static int __devinit snd_es1968_create(snd_card_t * card,
-				    struct pci_dev *pci,
-				    int total_bufsize,
-				    int play_streams,
-				    int capt_streams,
-				    es1968_t **chip_ret)
+				       struct pci_dev *pci,
+				       int total_bufsize,
+				       int play_streams,
+				       int capt_streams,
+				       int chip_type,
+				       int do_pm,
+				       es1968_t **chip_ret)
 {
 	static snd_device_ops_t ops = {
 		.dev_free =	snd_es1968_dev_free,
@@ -2553,7 +2567,7 @@
 		return -ENOMEM;
 
 	/* Set Vars */
-	chip->type = (pci->vendor << 16) | pci->device;
+	chip->type = chip_type;
 	spin_lock_init(&chip->reg_lock);
 	spin_lock_init(&chip->substream_lock);
 	spin_lock_init(&chip->bob_lock);
@@ -2595,11 +2609,26 @@
 	/* just to be sure */
 	pci_set_master(pci);
 
+	if (do_pm) {
+		/* disable power-management if not maestro2e or
+		 * if not on the whitelist
+		 */
+		unsigned int vend;
+		pci_read_config_dword(chip->pci, PCI_SUBSYSTEM_VENDOR_ID, &vend);
+		if (chip->type != TYPE_MAESTRO2E || (vend & 0xffff) != 0x1028) {
+			printk(KERN_INFO "es1968: not attempting power management.\n");
+			do_pm = 0;
+		}
+	}
+	chip->do_pm = do_pm;
+
 	snd_es1968_chip_init(chip);
 
 #ifdef CONFIG_PM
-	card->set_power_state = snd_es1968_set_power_state;
-	card->power_state_private_data = chip;
+	if (chip->do_pm) {
+		card->set_power_state = snd_es1968_set_power_state;
+		card->power_state_private_data = chip;
+	}
 #endif
 
 	if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
@@ -2693,21 +2722,23 @@
 				     total_bufsize[dev] * 1024, /* in bytes */
 				     pcm_substreams_p[dev], 
 				     pcm_substreams_c[dev],
+				     pci_id->driver_data,
+				     use_pm[dev],
 				     &chip)) < 0) {
 		snd_card_free(card);
 		return err;
 	}
 
 	switch (chip->type) {
-	case CARD_TYPE_ESS_ES1978:
+	case TYPE_MAESTRO2E:
 		strcpy(card->driver, "ES1978");
 		strcpy(card->shortname, "ESS ES1978 (Maestro 2E)");
 		break;
-	case CARD_TYPE_ESS_ES1968:
+	case TYPE_MAESTRO2:
 		strcpy(card->driver, "ES1968");
 		strcpy(card->shortname, "ESS ES1968 (Maestro 2)");
 		break;
-	case CARD_TYPE_ESS_ESOLDM1:
+	case TYPE_MAESTRO:
 		strcpy(card->driver, "ESM1");
 		strcpy(card->shortname, "ESS Maestro 1");
 		break;
diff -Nru a/sound/pci/fm801.c b/sound/pci/fm801.c
--- a/sound/pci/fm801.c	Mon Dec 23 21:21:59 2002
+++ b/sound/pci/fm801.c	Mon Dec 23 21:21:59 2002
@@ -164,7 +164,7 @@
 };
 
 static struct pci_device_id snd_fm801_ids[] __devinitdata = {
-	{ 0x1319, 0x0801, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },   /* FM801 */
+	{ 0x1319, 0x0801, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, },   /* FM801 */
 	{ 0, }
 };
 
@@ -517,18 +517,18 @@
 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
 				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
 				 SNDRV_PCM_INFO_MMAP_VALID),
-	formats:		SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
-	rates:			SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
-	rate_min:		5500,
-	rate_max:		48000,
-	channels_min:		1,
-	channels_max:		2,
-	buffer_bytes_max:	(128*1024),
-	period_bytes_min:	64,
-	period_bytes_max:	(128*1024),
-	periods_min:		1,
-	periods_max:		1024,
-	fifo_size:		0,
+	.formats =		SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
+	.rates =		SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
+	.rate_min =		5500,
+	.rate_max =		48000,
+	.channels_min =		1,
+	.channels_max =		2,
+	.buffer_bytes_max =	(128*1024),
+	.period_bytes_min =	64,
+	.period_bytes_max =	(128*1024),
+	.periods_min =		1,
+	.periods_max =		1024,
+	.fifo_size =		0,
 };
 
 static snd_pcm_hardware_t snd_fm801_capture =
@@ -536,18 +536,18 @@
 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
 				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
 				 SNDRV_PCM_INFO_MMAP_VALID),
-	formats:		SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
-	rates:			SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
-	rate_min:		5500,
-	rate_max:		48000,
-	channels_min:		1,
-	channels_max:		2,
-	buffer_bytes_max:	(128*1024),
-	period_bytes_min:	64,
-	period_bytes_max:	(128*1024),
-	periods_min:		1,
-	periods_max:		1024,
-	fifo_size:		0,
+	.formats =		SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
+	.rates =		SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
+	.rate_min =		5500,
+	.rate_max =		48000,
+	.channels_min =		1,
+	.channels_max =		2,
+	.buffer_bytes_max =	(128*1024),
+	.period_bytes_min =	64,
+	.period_bytes_max =	(128*1024),
+	.periods_min =		1,
+	.periods_max =		1024,
+	.fifo_size =		0,
 };
 
 static int snd_fm801_playback_open(snd_pcm_substream_t * substream)
@@ -834,7 +834,7 @@
 	}
 }
 
-static int __init snd_fm801_mixer(fm801_t *chip)
+static int __devinit snd_fm801_mixer(fm801_t *chip)
 {
 	ac97_t ac97;
 	int err, i;
@@ -907,7 +907,7 @@
 	static snd_device_ops_t ops = {
 		.dev_free =	snd_fm801_dev_free,
 	};
-	
+
 	*rchip = NULL;
 	if ((err = pci_enable_device(pci)) < 0)
 		return err;
@@ -920,13 +920,13 @@
 	chip->irq = -1;
 	chip->port = pci_resource_start(pci, 0);
 	if ((chip->res_port = request_region(chip->port, 0x80, "FM801")) == NULL) {
-		snd_fm801_free(chip);
 		snd_printk("unable to grab region 0x%lx-0x%lx\n", chip->port, chip->port + 0x80 - 1);
+		snd_fm801_free(chip);
 		return -EBUSY;
 	}
 	if (request_irq(pci->irq, snd_fm801_interrupt, SA_INTERRUPT|SA_SHIRQ, "FM801", (void *)chip)) {
-		snd_fm801_free(chip);
 		snd_printk("unable to grab IRQ %d\n", chip->irq);
+		snd_fm801_free(chip);
 		return -EBUSY;
 	}
 	chip->irq = pci->irq;
@@ -1070,7 +1070,7 @@
 		snd_card_free(card);
 		return err;
 	}
- 
+
 	strcpy(card->driver, "FM801");
 	strcpy(card->shortname, "ForteMedia FM801-");
 	strcat(card->shortname, chip->multichannel ? "AU" : "AS");
@@ -1098,7 +1098,7 @@
 	.probe = snd_card_fm801_probe,
 	.remove = __devexit_p(snd_card_fm801_remove),
 };
-                                                                
+
 static int __init alsa_card_fm801_init(void)
 {
 	int err;
diff -Nru a/sound/pci/ice1712/Makefile b/sound/pci/ice1712/Makefile
--- a/sound/pci/ice1712/Makefile	Mon Dec 23 21:21:53 2002
+++ b/sound/pci/ice1712/Makefile	Mon Dec 23 21:21:53 2002
@@ -5,7 +5,7 @@
 
 export-objs  := ice1712.o
 
-snd-ice1712-objs := ice1712.o ak4524.o delta.o hoontech.o ews.o
+snd-ice1712-objs := ice1712.o ak4524.o delta.o hoontech.o ews.o amp.o
 
 # Toplevel Module Dependency
 obj-$(CONFIG_SND_ICE1712) += snd-ice1712.o
diff -Nru a/sound/pci/ice1712/ak4524.c b/sound/pci/ice1712/ak4524.c
--- a/sound/pci/ice1712/ak4524.c	Mon Dec 23 21:21:55 2002
+++ b/sound/pci/ice1712/ak4524.c	Mon Dec 23 21:21:55 2002
@@ -65,10 +65,8 @@
 		tmp |= ak->cs_addr;
 	}
 
-	addr &= 0x07;
 	/* build I2C address + data byte */
-	/* assume C1=1, C0=0 */
-	addrdata = 0xa000 | (addr << 8) | data;
+	addrdata = (ak->caddr << 14) | 0x2000 | ((addr & 0x0f) << 8) | data;
 	for (idx = 15; idx >= 0; idx--) {
 		tmp &= ~(ak->data_mask | ak->clk_mask);
 		if (addrdata & (1 << idx))
@@ -81,11 +79,14 @@
 		udelay(1);
 	}
 
-	if (ak->type == SND_AK4524) {
+	if (ak->type == SND_AK4524 || ak->type == SND_AK4528) {
 		if ((addr != 0x04 && addr != 0x05) || (data & 0x80) == 0)
 			ak->images[chip][addr] = data;
 		else
 			ak->ipga_gain[chip][addr-4] = data;
+	} else {
+		/* AK4529 */
+		ak->images[chip][addr] = data;
 	}
 	
 	if (ak->cs_mask == ak->cs_addr) {
@@ -170,7 +171,7 @@
 	static unsigned char inits_ak4529[] = {
 		0x09, 0x01, /* 9: ATS=0, RSTN=1 */
 		0x0a, 0x3f, /* A: all power up, no zero/overflow detection */
-		0x00, 0x08, /* 0: TDM=0, 24bit I2S, SMUTE=0 */
+		0x00, 0x0c, /* 0: TDM=0, 24bit I2S, SMUTE=0 */
 		0x01, 0x00, /* 1: ACKS=0, ADC, loop off */
 		0x02, 0xff, /* 2: LOUT1 muted */
 		0x03, 0xff, /* 3: ROUT1 muted */
@@ -216,15 +217,20 @@
 
 #define AK_GET_CHIP(val)		(((val) >> 8) & 0xff)
 #define AK_GET_ADDR(val)		((val) & 0xff)
-#define AK_GET_SHIFT(val)		(((val) >> 16) & 0xff)
-#define AK_COMPOSE(chip,addr,shift)	(((chip) << 8) | (addr) | ((shift) << 16))
+#define AK_GET_SHIFT(val)		(((val) >> 16) & 0x7f)
+#define AK_GET_INVERT(val)		(((val) >> 23) & 1)
+#define AK_GET_MASK(val)		(((val) >> 24) & 0xff)
+#define AK_COMPOSE(chip,addr,shift,mask) (((chip) << 8) | (addr) | ((shift) << 16) | ((mask) << 24))
+#define AK_INVERT 			(1<<23)
 
 static int snd_ice1712_ak4524_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
 {
+	unsigned int mask = AK_GET_MASK(kcontrol->private_value);
+
 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
 	uinfo->count = 1;
 	uinfo->value.integer.min = 0;
-	uinfo->value.integer.max = 127;
+	uinfo->value.integer.max = mask;
 	return 0;
 }
 
@@ -233,7 +239,11 @@
 	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
 	int chip = AK_GET_CHIP(kcontrol->private_value);
 	int addr = AK_GET_ADDR(kcontrol->private_value);
-	ucontrol->value.integer.value[0] = ice->ak4524.images[chip][addr];
+	int invert = AK_GET_INVERT(kcontrol->private_value);
+	unsigned int mask = AK_GET_MASK(kcontrol->private_value);
+	unsigned char val = ice->ak4524.images[chip][addr];
+	
+	ucontrol->value.integer.value[0] = invert ? mask - val : val;
 	return 0;
 }
 
@@ -242,8 +252,14 @@
 	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
 	int chip = AK_GET_CHIP(kcontrol->private_value);
 	int addr = AK_GET_ADDR(kcontrol->private_value);
-	unsigned char nval = ucontrol->value.integer.value[0];
-	int change = ice->ak4524.images[chip][addr] != nval;
+	int invert = AK_GET_INVERT(kcontrol->private_value);
+	unsigned int mask = AK_GET_MASK(kcontrol->private_value);
+	unsigned char nval = ucontrol->value.integer.value[0] % (mask+1);
+	int change;
+
+	if (invert)
+		nval = mask - nval;
+	change = ice->ak4524.images[chip][addr] != nval;
 	if (change)
 		snd_ice1712_ak4524_write(ice, chip, addr, nval);
 	return change;
@@ -340,14 +356,14 @@
 		ctl.put = snd_ice1712_ak4524_volume_put;
 		switch (ak->type) {
 		case SND_AK4524:
-			ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 6, 0); /* register 6 & 7 */
+			ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 6, 0, 127); /* register 6 & 7 */
 			break;
 		case SND_AK4528:
-			ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0); /* register 4 & 5 */
+			ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127); /* register 4 & 5 */
 			break;
 		case SND_AK4529: {
 			int val = idx < 6 ? idx + 2 : (idx - 6) + 0xb; /* registers 2-7 and b,c */
-			ctl.private_value = AK_COMPOSE(0, val, 0);
+			ctl.private_value = AK_COMPOSE(0, val, 0, 255) | AK_INVERT;
 			break;
 		}
 		}
@@ -365,7 +381,7 @@
 		ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
 		ctl.get = snd_ice1712_ak4524_volume_get;
 		ctl.put = snd_ice1712_ak4524_volume_put;
-		ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0); /* register 4 & 5 */
+		ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127); /* register 4 & 5 */
 		ctl.private_data = ice;
 		if ((err = snd_ctl_add(ice->card, snd_ctl_new(&ctl))) < 0)
 			return err;
@@ -377,7 +393,7 @@
 		ctl.access = SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE;
 		ctl.get = snd_ice1712_ak4524_ipga_gain_get;
 		ctl.put = snd_ice1712_ak4524_ipga_gain_put;
-		ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0); /* register 4 & 5 */
+		ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, 0); /* register 4 & 5 */
 		ctl.private_data = ice;
 		if ((err = snd_ctl_add(ice->card, snd_ctl_new(&ctl))) < 0)
 			return err;
@@ -395,11 +411,11 @@
 		switch (ak->type) {
 		case SND_AK4524:
 		case SND_AK4528:
-			ctl.private_value = AK_COMPOSE(idx, 3, 0); /* register 3 */
+			ctl.private_value = AK_COMPOSE(idx, 3, 0, 0); /* register 3 */
 			break;
 		case SND_AK4529: {
 			int shift = idx == 3 ? 6 : (2 - idx) * 2;
-			ctl.private_value = AK_COMPOSE(0, 8, shift); /* register 8 with shift */
+			ctl.private_value = AK_COMPOSE(0, 8, shift, 0); /* register 8 with shift */
 			break;
 		}
 		}
diff -Nru a/sound/pci/ice1712/amp.c b/sound/pci/ice1712/amp.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/sound/pci/ice1712/amp.c	Mon Dec 23 21:22:04 2002
@@ -0,0 +1,55 @@
+/*
+ *   ALSA driver for ICEnsemble VT1724 (Envy24HT)
+ *
+ *   Lowlevel functions for Advanced Micro Peripherals Ltd AUDIO2000
+ *
+ *	Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
+ *
+ *   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 <sound/driver.h>
+#include <asm/io.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <sound/core.h>
+
+#include "ice1712.h"
+#include "amp.h"
+
+
+static int __devinit snd_vt1724_amp_init(ice1712_t *ice)
+{
+	/* only use basic functionality for now */
+
+	ice->num_total_dacs = 2;	/* only PSDOUT0 is connected */
+
+	return 0;
+}
+
+
+/* entry point */
+struct snd_ice1712_card_info snd_vt1724_amp_cards[] __devinitdata = {
+	{
+		VT1724_SUBDEVICE_AUDIO2000,
+		"AMP Ltd AUDIO2000",
+		snd_vt1724_amp_init,
+	},
+	{ } /* terminator */
+};
+
diff -Nru a/sound/pci/ice1712/amp.h b/sound/pci/ice1712/amp.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/sound/pci/ice1712/amp.h	Mon Dec 23 21:22:03 2002
@@ -0,0 +1,34 @@
+#ifndef __SOUND_AMP_H
+#define __SOUND_AMP_H
+
+/*
+ *   ALSA driver for VIA VT1724 (Envy24HT)
+ *
+ *   Lowlevel functions for Advanced Micro Peripherals Ltd AUDIO2000
+ *
+ *	Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
+ *
+ *   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
+ *
+ */      
+
+#define  AMP_AUDIO2000_DEVICE_DESC 	       "{AMP Ltd AUDIO2000},"
+
+#define VT1724_SUBDEVICE_AUDIO2000	0x12142417	/* Advanced Micro Peripherals Ltd AUDIO2000 */
+
+extern struct snd_ice1712_card_info  snd_vt1724_amp_cards[];
+
+
+#endif /* __SOUND_AMP_H */
diff -Nru a/sound/pci/ice1712/delta.c b/sound/pci/ice1712/delta.c
--- a/sound/pci/ice1712/delta.c	Mon Dec 23 21:21:51 2002
+++ b/sound/pci/ice1712/delta.c	Mon Dec 23 21:21:51 2002
@@ -189,19 +189,18 @@
 
 static int delta_spdif_default_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
 {
-	unsigned long flags;
 	unsigned int val;
 	int change;
 
 	val = snd_cs8403_encode_spdif_bits(&ucontrol->value.iec958);
-	spin_lock_irqsave(&ice->reg_lock, flags);
+	spin_lock_irq(&ice->reg_lock);
 	change = ice->spdif.cs8403_bits != val;
 	ice->spdif.cs8403_bits = val;
 	if (change && ice->playback_pro_substream == NULL) {
-		spin_unlock_irqrestore(&ice->reg_lock, flags);
+		spin_unlock_irq(&ice->reg_lock);
 		snd_ice1712_delta_cs8403_spdif_write(ice, val);
 	} else {
-		spin_unlock_irqrestore(&ice->reg_lock, flags);
+		spin_unlock_irq(&ice->reg_lock);
 	}
 	return change;
 }
@@ -213,19 +212,18 @@
 
 static int delta_spdif_stream_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
 {
-	unsigned long flags;
 	unsigned int val;
 	int change;
 
 	val = snd_cs8403_encode_spdif_bits(&ucontrol->value.iec958);
-	spin_lock_irqsave(&ice->reg_lock, flags);
+	spin_lock_irq(&ice->reg_lock);
 	change = ice->spdif.cs8403_stream_bits != val;
 	ice->spdif.cs8403_stream_bits = val;
 	if (change && ice->playback_pro_substream != NULL) {
-		spin_unlock_irqrestore(&ice->reg_lock, flags);
+		spin_unlock_irq(&ice->reg_lock);
 		snd_ice1712_delta_cs8403_spdif_write(ice, val);
 	} else {
-		spin_unlock_irqrestore(&ice->reg_lock, flags);
+		spin_unlock_irq(&ice->reg_lock);
 	}
 	return change;
 }
@@ -257,17 +255,20 @@
 /*
  * change the rate of AK4524 on Delta 44/66, AP, 1010LT
  */
-static void delta_ak4524_set_rate_val(ice1712_t *ice, unsigned char val)
+static void delta_ak4524_set_rate_val(ice1712_t *ice, unsigned int rate)
 {
 	unsigned char tmp, tmp2;
 
+	if (rate == 0)	/* no hint - S/PDIF input is master, simply return */
+		return;
+
 	/* check before reset ak4524 to avoid unnecessary clicks */
 	down(&ice->gpio_mutex);
 	tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
 	up(&ice->gpio_mutex);
 	tmp2 = tmp;
 	tmp2 &= ~ICE1712_DELTA_DFS; 
-	if (val == 15 || val == 11 || val == 7)
+	if (rate > 48000)
 		tmp2 |= ICE1712_DELTA_DFS;
 	if (tmp == tmp2)
 		return;
@@ -275,12 +276,9 @@
 	/* do it again */
 	snd_ice1712_ak4524_reset(ice, 1);
 	down(&ice->gpio_mutex);
-	tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
-	if (val == 15 || val == 11 || val == 7) {
+	tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ~ICE1712_DELTA_DFS;
+	if (rate > 48000)
 		tmp |= ICE1712_DELTA_DFS;
-	} else {
-		tmp &= ~ICE1712_DELTA_DFS;
-	}
 	snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
 	up(&ice->gpio_mutex);
 	snd_ice1712_ak4524_reset(ice, 0);
@@ -385,9 +383,11 @@
 	case ICE1712_SUBDEVICE_DELTA410:
 		ak->num_adcs = ak->num_dacs = 2;
 		ak->type = SND_AK4528;
+		ak->caddr = 2;
 		if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DELTA410) {
 			ak->num_dacs = 8;
 			ak->type = SND_AK4529;
+			ak->caddr = 0;
 		}
 		ak->cif = 0; /* the default level of the CIF pin from AK4528/4529 */
 		ak->data_mask = ICE1712_DELTA_AP_DOUT;
@@ -402,6 +402,7 @@
 	case ICE1712_SUBDEVICE_DELTA1010LT:
 		ak->num_adcs = ak->num_dacs = 8;
 		ak->type = SND_AK4524;
+		ak->caddr = 2;
 		ak->cif = 0; /* the default level of the CIF pin from AK4524 */
 		ak->data_mask = ICE1712_DELTA_1010LT_DOUT;
 		ak->clk_mask = ICE1712_DELTA_1010LT_CCLK;
@@ -417,6 +418,7 @@
 	case ICE1712_SUBDEVICE_DELTA44:
 		ak->num_adcs = ak->num_dacs = 4;
 		ak->type = SND_AK4524;
+		ak->caddr = 2;
 		ak->cif = 0; /* the default level of the CIF pin from AK4524 */
 		ak->data_mask = ICE1712_DELTA_CODEC_SERIAL_DATA;
 		ak->clk_mask = ICE1712_DELTA_CODEC_SERIAL_CLOCK;
diff -Nru a/sound/pci/ice1712/envy24ht.h b/sound/pci/ice1712/envy24ht.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/sound/pci/ice1712/envy24ht.h	Mon Dec 23 21:22:05 2002
@@ -0,0 +1,203 @@
+#ifndef __SOUND_VT1724_H
+#define __SOUND_VT1724_H
+
+/*
+ *   ALSA driver for ICEnsemble VT1724 (Envy24)
+ *
+ *	Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
+ *
+ *   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 <sound/control.h>
+#include <sound/ac97_codec.h>
+#include <sound/rawmidi.h>
+#include <sound/i2c.h>
+#include <sound/pcm.h>
+
+#include "ice1712.h"
+/*
+ *  Direct registers
+ */
+
+#define ICEREG1724(ice, x) ((ice)->port + VT1724_REG_##x)
+
+#define VT1724_REG_CONTROL		0x00	/* byte */
+#define   VT1724_RESET			0x80	/* reset whole chip */
+#define VT1724_REG_IRQMASK		0x01	/* byte */
+#define   VT1724_IRQ_MPU_RX		0x80
+#define   VT1724_IRQ_MPU_TX		0x20
+#define   VT1724_IRQ_MTPCM		0x10
+#define VT1724_REG_IRQSTAT		0x02	/* byte */
+/* look to VT1724_IRQ_* */
+#define VT1724_REG_SYS_CFG		0x04	/* byte - system configuration PCI60 on Envy24*/
+#define   VT1724_CFG_CLOCK	0xc0
+#define     VT1724_CFG_CLOCK512	0x00	/* 22.5692Mhz, 44.1kHz*512 */
+#define     VT1724_CFG_CLOCK384  0x40	/* 16.9344Mhz, 44.1kHz*384 */
+#define   VT1724_CFG_MPU401	0x20		/* MPU401 UARTs */
+#define   VT1724_CFG_ADC_MASK	0x0c	/* one, two or one and S/PDIF, stereo ADCs */
+#define   VT1724_CFG_DAC_MASK	0x03	/* one, two, three, four stereo DACs */
+
+#define VT1724_REG_AC97_CFG		0x05	/* byte */
+#define   VT1724_CFG_PRO_I2S	0x80	/* multitrack converter: I2S or AC'97 */
+#define   VT1724_CFG_AC97_PACKED	0x01	/* split or packed mode - AC'97 */
+
+#define VT1724_REG_I2S_FEATURES		0x06	/* byte */
+#define   VT1724_CFG_I2S_VOLUME	0x80	/* volume/mute capability */
+#define   VT1724_CFG_I2S_96KHZ	0x40	/* supports 96kHz sampling */
+#define   VT1724_CFG_I2S_RESMASK	0x30	/* resolution mask, 16,18,20,24-bit */
+#define   VT1724_CFG_I2S_192KHZ	0x08	/* supports 192kHz sampling */
+#define   VT1724_CFG_I2S_OTHER	0x07	/* other I2S IDs */
+
+#define VT1724_REG_SPDIF_CFG		0x07	/* byte */
+#define   VT1724_CFG_SPDIF_OUT_EN	0x80	/*Internal S/PDIF output is enabled*/
+#define   VT1724_CFG_SPDIF_OUT_INT	0x40	/*Internal S/PDIF output is implemented*/
+#define   VT1724_CFG_I2S_CHIPID	0x3c	/* I2S chip ID */
+#define   VT1724_CFG_SPDIF_IN	0x02	/* S/PDIF input is present */
+#define   VT1724_CFG_SPDIF_OUT	0x01	/* External S/PDIF output is present */
+
+/*there is no consumer AC97 codec with the VT1724*/
+//#define VT1724_REG_AC97_INDEX		0x08	/* byte */
+//#define VT1724_REG_AC97_CMD		0x09	/* byte */
+#define   VT1724_AC97_COLD		0x80	/* cold reset */
+#define   VT1724_AC97_WARM		0x40	/* warm reset */
+#define   VT1724_AC97_WRITE		0x20	/* W: write, R: write in progress */
+#define   VT1724_AC97_READ		0x10	/* W: read, R: read in progress */
+#define   VT1724_AC97_READY		0x08	/* codec ready status bit */
+#define   VT1724_AC97_PBK_VSR		0x02	/* playback VSR */
+#define   VT1724_AC97_CAP_VSR		0x01	/* capture VSR */
+
+#define VT1724_REG_MPU_TXFIFO		0x0a	/*byte ro. number of bytes in TX fifo*/
+#define VT1724_REG_MPU_RXFIFO		0x0b	/*byte ro. number of bytes in RX fifo*/
+
+//are these 2 the wrong way around? they don't seem to be used yet anyway
+#define VT1724_REG_MPU_CTRL		0x0c	/* byte */
+#define VT1724_REG_MPU_DATA		0x0d	/* byte */
+
+#define VT1724_REG_MPU_FIFO_WM	0x0e	/*byte set the high/low watermarks for RX/TX fifos*/
+#define   VT1724_MPU_RX_FIFO	0x20	//1=rx fifo watermark 0=tx fifo watermark
+#define   VT1724_MPU_FIFO_MASK	0x1f	
+
+#define VT1724_REG_I2C_DEV_ADDR	0x10	/* byte */
+#define   VT1724_I2C_WRITE		0x01	/* write direction */
+#define VT1724_REG_I2C_BYTE_ADDR	0x11	/* byte */
+#define VT1724_REG_I2C_DATA		0x12	/* byte */
+#define VT1724_REG_I2C_CTRL		0x13	/* byte */
+#define   VT1724_I2C_EEPROM		0x80	/* EEPROM exists */
+#define   VT1724_I2C_BUSY		0x01	/* busy bit */
+
+#define VT1724_REG_GPIO_DATA	0x14	/* word */
+#define VT1724_REG_GPIO_WRITE_MASK	0x15 /* word */
+#define VT1724_REG_GPIO_DIRECTION	0x16 /* dword? (3 bytes) 0=input 1=output. 
+							bit3 - during reset used for Eeprom power-on strapping
+							if TESTEN# pin active, bit 2 always input*/
+#define VT1724_REG_POWERDOWN	0x1c
+#define VT1724_REG_GPIO_DIRECTION_22	0x1e /* byte direction for GPIO 16:22 */
+#define VT1724_REG_GPIO_WRITE_MASK_22	0x1f /* byte write mask for GPIO 16:22 */
+
+
+/* 
+ *  Professional multi-track direct control registers
+ */
+
+#define ICEMT1724(ice, x) ((ice)->profi_port + VT1724_MT_##x)
+
+#define VT1724_MT_IRQ			0x00	/* byte - interrupt mask */
+#define   VT1724_MULTI_PDMA4	0x80	/* SPDIF Out / PDMA4 */
+#define	  VT1724_MULTI_PDMA3	0x40	/* PDMA3 */
+#define   VT1724_MULTI_PDMA2	0x20	/* PDMA2 */
+#define   VT1724_MULTI_PDMA1	0x10	/* PDMA1 */
+#define   VT1724_MULTI_FIFO_ERR 0x08	/* DMA FIFO underrun/overrun. */
+#define   VT1724_MULTI_RDMA1	0x04	/* RDMA1 (S/PDIF input) */
+#define   VT1724_MULTI_RDMA0	0x02	/* RMDA0 */
+#define   VT1724_MULTI_PDMA0	0x01	/* MC Interleave/PDMA0 */
+
+#define VT1724_MT_RATE			0x01	/* byte - sampling rate select */
+#define   VT1724_SPDIF_MASTER		0x10	/* S/PDIF input is master clock */
+#define VT1724_MT_I2S_FORMAT		0x02	/* byte - I2S data format */
+#define VT1724_MT_DMA_INT_MASK		0x03	/* byte -DMA Interrupt Mask */
+/* lool to VT1724_MULTI_* */
+#define VT1724_MT_AC97_INDEX		0x04	/* byte - AC'97 index */
+#define VT1724_MT_AC97_CMD		0x05	/* byte - AC'97 command & status */
+/* look to VT1724_AC97_* */
+#define VT1724_MT_AC97_DATA		0x06	/* word - AC'97 data */
+#define VT1724_MT_PLAYBACK_ADDR	0x10	/* dword - playback address */
+#define VT1724_MT_PLAYBACK_SIZE	0x14	/* dword - playback size */
+#define VT1724_MT_PLAYBACK_CONTROL	0x18	/* byte - control */
+#define   VT1724_PDMA4_START	0x80	/* SPDIF out / PDMA4 start */
+#define   VT1724_PDMA3_START	0x40	/* PDMA3 start */
+#define   VT1724_PDMA2_START	0x20	/* PDMA2 start */
+#define   VT1724_PDMA1_START	0x10	/* PDMA1 start */
+#define   VT1724_RDMA1_START	0x04	/* RDMA1 start */
+#define   VT1724_RDMA0_START	0x02	/* RMDA0 start */
+#define   VT1724_PDMA0_START	0x01	/* MC Interleave / PDMA0 start */
+#define VT1724_MT_BURST			0x19	/* Interleaved playback DMA Active streams / PCI burst size */
+#define VT1724_MT_DMA_FIFO_ERR	0x1a	/*Global playback and record DMA FIFO Underrun/Overrun */
+#define   VT1724_PDMA4_UNDERRUN	0x80
+#define   VT1724_PDMA2_UNDERRUN	0x40
+#define   VT1724_PDMA3_UNDERRUN	0x20
+#define   VT1724_PDMA1_UNDERRUN	0x10
+#define   VT1724_RDMA1_UNDERRUN	0x04
+#define   VT1724_RDMA0_UNDERRUN	0x02
+#define   VT1724_PDMA0_UNDERRUN	0x01
+#define VT1724_MT_DMA_PAUSE		0x1b	/*Global playback and record DMA FIFO pause/resume */
+#define	  VT1724_PDMA4_PAUSE	0x80
+#define	  VT1724_PDMA3_PAUSE	0x40
+#define	  VT1724_PDMA2_PAUSE	0x20
+#define	  VT1724_PDMA1_PAUSE	0x10
+#define	  VT1724_RDMA1_PAUSE	0x04
+#define	  VT1724_RDMA0_PAUSE	0x02
+#define	  VT1724_PDMA0_PAUSE	0x01
+#define VT1724_MT_PLAYBACK_COUNT	0x1c	/* word - playback count */
+#define VT1724_MT_CAPTURE_ADDR		0x20	/* dword - capture address */
+#define VT1724_MT_CAPTURE_SIZE		0x24	/* word - capture size */
+#define VT1724_MT_CAPTURE_COUNT	0x26	/* word - capture count */
+
+#define VT1724_MT_RDMA1_ADDR	0x30	/* dword - RDMA1 capture address */
+#define VT1724_MT_RDMA1_SIZE	0x34	/* word - RDMA1 capture size */
+#define VT1724_MT_RDMA1_COUNT	0x36	/* word - RDMA1 capture count */
+
+#define VT1724_MT_ROUTE_PLAYBACK	0x2c	/* word */
+//#define VT1724_MT_MONITOR_VOLUME	0x3f	/* word */
+//#define VT1724_MT_MONITOR_INDEX	0x3e	/* byte */
+
+
+#define VT1724_MT_PDMA4_ADDR	0x40	/* dword */
+#define VT7124_MT_PDMA4_SIZE	0x44	/* word */
+#define VT1724_MT_PDMA4_COUNT	0x46	/* word */
+#define VT1724_MT_PDMA3_ADDR	0x50	/* dword */
+#define VT7124_MT_PDMA3_SIZE	0x54	/* word */
+#define VT1724_MT_PDMA3_COUNT	0x56	/* word */
+#define VT1724_MT_PDMA2_ADDR	0x60	/* dword */
+#define VT7124_MT_PDMA2_SIZE	0x64	/* word */
+#define VT1724_MT_PDMA2_COUNT	0x66	/* word */
+#define VT1724_MT_PDMA1_ADDR	0x70	/* dword */
+#define VT7124_MT_PDMA1_SIZE	0x74	/* word */
+#define VT1724_MT_PDMA1_COUNT	0x76	/* word */
+
+
+//does VT1724 have these? don't think so
+//#define VT1724_MT_MONITOR_RATE		0x3b	/* byte */
+//#define VT1724_MT_MONITOR_ROUTECTRL	0x3c	/* byte */
+//#define   VT1724_ROUTE_AC97		0x01	/* route digital mixer output to AC'97 */
+#define VT1724_MT_MONITOR_PEAKINDEX	0x3e	/* byte */
+#define VT1724_MT_MONITOR_PEAKDATA	0x3f	/* byte */
+
+
+
+
+
+#endif /* __SOUND_VT1724_H */
diff -Nru a/sound/pci/ice1712/ews.c b/sound/pci/ice1712/ews.c
--- a/sound/pci/ice1712/ews.c	Mon Dec 23 21:21:52 2002
+++ b/sound/pci/ice1712/ews.c	Mon Dec 23 21:21:52 2002
@@ -245,19 +245,18 @@
 
 static int ews88_spdif_default_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
 {
-	unsigned long flags;
 	unsigned int val;
 	int change;
 
 	val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
-	spin_lock_irqsave(&ice->reg_lock, flags);
+	spin_lock_irq(&ice->reg_lock);
 	change = ice->spdif.cs8403_bits != val;
 	ice->spdif.cs8403_bits = val;
 	if (change && ice->playback_pro_substream == NULL) {
-		spin_unlock_irqrestore(&ice->reg_lock, flags);
+		spin_unlock_irq(&ice->reg_lock);
 		snd_ice1712_ews_cs8404_spdif_write(ice, val);
 	} else {
-		spin_unlock_irqrestore(&ice->reg_lock, flags);
+		spin_unlock_irq(&ice->reg_lock);
 	}
 	return change;
 }
@@ -269,19 +268,18 @@
 
 static int ews88_spdif_stream_put(ice1712_t *ice, snd_ctl_elem_value_t * ucontrol)
 {
-	unsigned long flags;
 	unsigned int val;
 	int change;
 
 	val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
-	spin_lock_irqsave(&ice->reg_lock, flags);
+	spin_lock_irq(&ice->reg_lock);
 	change = ice->spdif.cs8403_stream_bits != val;
 	ice->spdif.cs8403_stream_bits = val;
 	if (change && ice->playback_pro_substream != NULL) {
-		spin_unlock_irqrestore(&ice->reg_lock, flags);
+		spin_unlock_irq(&ice->reg_lock);
 		snd_ice1712_ews_cs8404_spdif_write(ice, val);
 	} else {
-		spin_unlock_irqrestore(&ice->reg_lock, flags);
+		spin_unlock_irq(&ice->reg_lock);
 	}
 	return change;
 }
@@ -407,6 +405,7 @@
 	case ICE1712_SUBDEVICE_EWS88MT:
 		ak->num_adcs = ak->num_dacs = 8;
 		ak->type = SND_AK4524;
+		ak->caddr = 2;
 		ak->cif = 1; /* CIF high */
 		ak->data_mask = ICE1712_EWS88_SERIAL_DATA;
 		ak->clk_mask = ICE1712_EWS88_SERIAL_CLOCK;
@@ -420,6 +419,7 @@
 	case ICE1712_SUBDEVICE_EWX2496:
 		ak->num_adcs = ak->num_dacs = 2;
 		ak->type = SND_AK4524;
+		ak->caddr = 2;
 		ak->cif = 1; /* CIF high */
 		ak->data_mask = ICE1712_EWS88_SERIAL_DATA;
 		ak->clk_mask = ICE1712_EWS88_SERIAL_CLOCK;
@@ -433,6 +433,7 @@
 	case ICE1712_SUBDEVICE_DMX6FIRE:
 		ak->num_adcs = ak->num_dacs = 6;
 		ak->type = SND_AK4524;
+		ak->caddr = 2;
 		ak->cif = 1; /* CIF high */
 		ak->data_mask = ICE1712_6FIRE_SERIAL_DATA;
 		ak->clk_mask = ICE1712_6FIRE_SERIAL_CLOCK;
diff -Nru a/sound/pci/ice1712/hoontech.c b/sound/pci/ice1712/hoontech.c
--- a/sound/pci/ice1712/hoontech.c	Mon Dec 23 21:21:56 2002
+++ b/sound/pci/ice1712/hoontech.c	Mon Dec 23 21:21:56 2002
@@ -218,6 +218,11 @@
 		"Hoontech SoundTrack Audio DSP24",
 		snd_ice1712_hoontech_init,
 	},
+	{
+		ICE1712_SUBDEVICE_STDSP24_MEDIA7_1,
+		"Hoontech STA DSP24 Media 7.1",
+		snd_ice1712_hoontech_init,
+	},
 	{ } /* terminator */
 };
 
diff -Nru a/sound/pci/ice1712/hoontech.h b/sound/pci/ice1712/hoontech.h
--- a/sound/pci/ice1712/hoontech.h	Mon Dec 23 21:21:58 2002
+++ b/sound/pci/ice1712/hoontech.h	Mon Dec 23 21:21:58 2002
@@ -24,9 +24,13 @@
  *
  */      
 
-#define  HOONTECH_DEVICE_DESC 	       "{Hoontech SoundTrack DSP 24},"
+#define  HOONTECH_DEVICE_DESC \
+	"{Hoontech SoundTrack DSP 24}," \
+	"{Hoontech SoundTrack DSP 24 Value}," \
+	"{Hoontech SoundTrack DSP 24 Media 7.1}," \
 
-#define ICE1712_SUBDEVICE_STDSP24	0x12141217	/* Hoontech SoundTrack Audio DSP 24 */
+#define ICE1712_SUBDEVICE_STDSP24		0x12141217	/* Hoontech SoundTrack Audio DSP 24 */
+#define ICE1712_SUBDEVICE_STDSP24_MEDIA7_1	0x16141217	/* Hoontech ST Audio DSP24 Media 7.1 */
 
 extern struct snd_ice1712_card_info snd_ice1712_hoontech_cards[];
 
diff -Nru a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
--- a/sound/pci/ice1712/ice1712.c	Mon Dec 23 21:21:53 2002
+++ b/sound/pci/ice1712/ice1712.c	Mon Dec 23 21:21:53 2002
@@ -32,6 +32,11 @@
  *	split the code to several files.  each low-level routine
  *	is stored in the local file and called from registration
  *	function from card_info struct.
+ *
+ *  2002.11.26	James Stafford <jstafford@ampltd.com>
+ *	Added support for VT1724 (Envy24HT)
+ *	I have left out support for 176.4 and 192 KHz for the moment. 
+ *  I also haven't done anything with the internal S/PDIF transmitter or the MPU-401
  */
 
 
@@ -52,11 +57,13 @@
 #include <sound/asoundef.h>
 
 #include "ice1712.h"
+#include "envy24ht.h"
 
 /* lowlevel routines */
 #include "delta.h"
 #include "ews.h"
 #include "hoontech.h"
+#include "amp.h"
 
 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
 MODULE_DESCRIPTION("ICEnsemble ICE1712 (Envy24)");
@@ -66,8 +73,11 @@
 	       HOONTECH_DEVICE_DESC
 	       DELTA_DEVICE_DESC
 	       EWS_DEVICE_DESC
+	       AMP_AUDIO2000_DEVICE_DESC
 		"{ICEnsemble,Generic ICE1712},"
-		"{ICEnsemble,Generic Envy24}}");
+		"{ICEnsemble,Generic Envy24},"
+		"{ICEnsemble,Generic ICE1724},"
+		"{ICEnsemble,Generic Envy24HT}}");
 
 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
@@ -93,9 +103,13 @@
 #ifndef PCI_DEVICE_ID_ICE_1712
 #define PCI_DEVICE_ID_ICE_1712		0x1712
 #endif
+#ifndef PCI_DEVICE_ID_VT1724
+#define PCI_DEVICE_ID_VT1724		0x1724
+#endif
 
 static struct pci_device_id snd_ice1712_ids[] __devinitdata = {
 	{ PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_ICE_1712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },   /* ICE1712 */
+	{ PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_VT1724, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },	   /* VT1724 */
 	{ 0, }
 };
 
@@ -104,10 +118,24 @@
 static int snd_ice1712_build_pro_mixer(ice1712_t *ice);
 static int snd_ice1712_build_controls(ice1712_t *ice);
 
+static int PRO_RATE_LOCKED = 0;
+static int PRO_RATE_RESET = 1;
+static unsigned int PRO_RATE_DEFAULT = 44100;
+
 /*
  *  Basic I/O
  */
  
+static inline int is_spdif_master(ice1712_t *ice)
+{
+	return (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER) ? 1 : 0;
+}
+
+static inline int is_pro_rate_locked(ice1712_t *ice)
+{
+	return is_spdif_master(ice) || PRO_RATE_LOCKED;
+}
+
 static inline void snd_ice1712_ds_write(ice1712_t * ice, u8 channel, u8 addr, u32 data)
 {
 	outb((channel << 4) | addr, ICEDS(ice, INDEX));
@@ -237,11 +265,8 @@
 static int snd_ice1712_digmix_route_ac97_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
 {
 	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
-	unsigned long flags;
 	
-	spin_lock_irqsave(&ice->reg_lock, flags);
 	ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0;
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
 	return 0;
 }
 
@@ -249,14 +274,13 @@
 {
 	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
 	unsigned char val, nval;
-	unsigned long flags;
 	
-	spin_lock_irqsave(&ice->reg_lock, flags);
+	spin_lock_irq(&ice->reg_lock);
 	val = inb(ICEMT(ice, MONITOR_ROUTECTRL));
 	nval = val & ~ICE1712_ROUTE_AC97;
 	if (ucontrol->value.integer.value[0]) nval |= ICE1712_ROUTE_AC97;
 	outb(nval, ICEMT(ice, MONITOR_ROUTECTRL));
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
+	spin_unlock_irq(&ice->reg_lock);
 	return val != nval;
 }
 
@@ -276,26 +300,67 @@
 void snd_ice1712_gpio_write_bits(ice1712_t *ice, int mask, int bits)
 {
 	ice->gpio_direction |= mask;
-	snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio_direction);
-	snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~mask);
-	snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, mask & bits);
+	if (ice->vt1724) {
+
+		outw(ice->gpio_direction, ICEREG1724(ice, GPIO_DIRECTION));
+		outb((ice->gpio_direction&0xff0000)>>16, ICEREG1724(ice, GPIO_DIRECTION_22));
+
+		outw(~mask, ICEREG1724(ice, GPIO_WRITE_MASK));
+		outb((~mask & 0xff0000)>>16, ICEREG1724(ice, GPIO_WRITE_MASK_22));
+
+		outl(mask & bits, ICEREG1724(ice, GPIO_DATA));
+
+	}
+	else {
+		snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio_direction);
+		snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~mask);
+		snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, mask & bits);
+	}
 }
 
 /*
  */
+/*
+	the VT1724 has 23 GPIO pins, so need 3 bytes for direction and 3 bytes for write mask
+ */
+
 void snd_ice1712_save_gpio_status(ice1712_t *ice, unsigned char *tmp)
 {
 	down(&ice->gpio_mutex);
-	tmp[0] = ice->gpio_direction;
-	tmp[1] = ice->gpio_write_mask;
+	if (ice->vt1724) {
+		tmp[0] = ice->gpio_direction & 0xff;
+		tmp[1] = (ice->gpio_direction &0xff00)>>8;
+		tmp[2] = (ice->gpio_direction &0xff0000)>>16;
+
+		tmp[3] = ice->gpio_write_mask & 0xff;
+		tmp[4] = (ice->gpio_write_mask &0xff00)>>8;
+		tmp[5] = (ice->gpio_write_mask &0xff0000)>>16;
+	}
+	else {
+		tmp[0] = ice->gpio_direction;
+		tmp[1] = ice->gpio_write_mask;
+	}
 }
 
 void snd_ice1712_restore_gpio_status(ice1712_t *ice, unsigned char *tmp)
 {
-	snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, tmp[0]);
-	snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, tmp[1]);
-	ice->gpio_direction = tmp[0];
-	ice->gpio_write_mask = tmp[1];
+	if (ice->vt1724) {
+
+		outw(tmp[0] | ((tmp[1]&0xff00)<<8), ICEREG1724(ice, GPIO_DIRECTION));
+		outb(tmp[2], ICEREG1724(ice, GPIO_DIRECTION_22));
+
+		outw(tmp[3] | ((tmp[4]&0xff00)<<8), ICEREG1724(ice, GPIO_WRITE_MASK));
+		outb(tmp[5], ICEREG1724(ice, GPIO_WRITE_MASK_22));
+
+		ice->gpio_direction=tmp[0] | ((tmp[1]<<8)&0xff00) |((tmp[2]<<16)&0xff0000);
+		ice->gpio_write_mask=tmp[3] | ((tmp[4]<<8)&0xff00) |((tmp[5]<<16)&0xff0000);
+	}
+	else {
+		snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, tmp[0]);
+		snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, tmp[1]);
+		ice->gpio_direction = tmp[0];
+		ice->gpio_write_mask = tmp[1];
+	}
 	up(&ice->gpio_mutex);
 }
 
@@ -449,6 +514,48 @@
 }
 
 
+static void snd_vt1724_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+	ice1712_t *ice = snd_magic_cast(ice1712_t, dev_id, return);
+	unsigned char status;
+
+	while (1) {
+		status = inb(ICEREG(ice, IRQSTAT));
+		if (status == 0)
+			break;
+		
+		/*  these should probably be separated at some point, 
+			but as we don't currently have MPU support on the board I will leave it */
+		if ((status & VT1724_IRQ_MPU_RX)||(status & VT1724_IRQ_MPU_TX)) {
+			if (ice->rmidi[0])
+				snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data, regs);
+			outb(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX, ICEREG(ice, IRQSTAT));
+			status &= ~(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX);
+		}
+		if (status & VT1724_IRQ_MTPCM) {
+			unsigned char mtstat = inb(ICEMT(ice, IRQ));
+			if (mtstat & VT1724_MULTI_PDMA0) {
+				if (ice->playback_pro_substream)
+					snd_pcm_period_elapsed(ice->playback_pro_substream);
+				outb(VT1724_MULTI_PDMA0, ICEMT(ice, IRQ));
+			}
+			if (mtstat & VT1724_MULTI_RDMA0) {
+				if (ice->capture_pro_substream)
+					snd_pcm_period_elapsed(ice->capture_pro_substream);
+				outb(VT1724_MULTI_RDMA0, ICEMT(ice, IRQ));
+			}
+			/* ought to really handle this properly */
+			if (mtstat & VT1724_MULTI_FIFO_ERR) {
+				unsigned char fstat = inb(ICEMT1724(ice, DMA_FIFO_ERR));
+				outb(fstat, ICEMT1724(ice, DMA_FIFO_ERR));	
+				outb(VT1724_MULTI_FIFO_ERR | inb(ICEMT1724(ice, DMA_INT_MASK)), ICEMT1724(ice, DMA_INT_MASK));	
+				/* If I don't do this, I get machine lockup due to continual interrupts */
+			}
+
+		}
+	}
+}
+
 /*
  *  PCM part - misc
  */
@@ -541,7 +648,6 @@
 
 static int snd_ice1712_playback_prepare(snd_pcm_substream_t * substream)
 {
-	unsigned long flags;
 	ice1712_t *ice = snd_pcm_substream_chip(substream);
 	snd_pcm_runtime_t *runtime = substream->runtime;
 	u32 period_size, buf_size, rate, tmp;
@@ -556,7 +662,7 @@
 	rate = (runtime->rate * 8192) / 375;
 	if (rate > 0x000fffff)
 		rate = 0x000fffff;
-	spin_lock_irqsave(&ice->reg_lock, flags);
+	spin_lock(&ice->reg_lock);
 	outb(0, ice->ddma_port + 15);
 	outb(ICE1712_DMA_MODE_WRITE | ICE1712_DMA_AUTOINIT, ice->ddma_port + 0x0b);
 	outl(runtime->dma_addr, ice->ddma_port + 0);
@@ -569,13 +675,12 @@
 	snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_HI, period_size >> 8);
 	snd_ice1712_write(ice, ICE1712_IREG_PBK_LEFT, 0);
 	snd_ice1712_write(ice, ICE1712_IREG_PBK_RIGHT, 0);
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
+	spin_unlock(&ice->reg_lock);
 	return 0;
 }
 
 static int snd_ice1712_playback_ds_prepare(snd_pcm_substream_t * substream)
 {
-	unsigned long flags;
 	ice1712_t *ice = snd_pcm_substream_chip(substream);
 	snd_pcm_runtime_t *runtime = substream->runtime;
 	u32 period_size, buf_size, rate, tmp, chn;
@@ -593,7 +698,7 @@
 	ice->playback_con_active_buf[substream->number] = 0;
 	ice->playback_con_virt_addr[substream->number] = runtime->dma_addr;
 	chn = substream->number * 2;
-	spin_lock_irqsave(&ice->reg_lock, flags);
+	spin_lock(&ice->reg_lock);
 	snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR0, runtime->dma_addr);
 	snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT0, period_size);
 	snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR1, runtime->dma_addr + (runtime->periods > 1 ? period_size + 1 : 0));
@@ -605,13 +710,12 @@
 		snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_RATE, rate);
 		snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_VOLUME, 0);
 	}
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
+	spin_unlock(&ice->reg_lock);
 	return 0;
 }
 
 static int snd_ice1712_capture_prepare(snd_pcm_substream_t * substream)
 {
-	unsigned long flags;
 	ice1712_t *ice = snd_pcm_substream_chip(substream);
 	snd_pcm_runtime_t *runtime = substream->runtime;
 	u32 period_size, buf_size;
@@ -624,13 +728,13 @@
 		tmp &= ~0x04;
 	if (runtime->channels == 2)
 		tmp &= ~0x02;
-	spin_lock_irqsave(&ice->reg_lock, flags);
+	spin_lock(&ice->reg_lock);
 	outl(ice->capture_con_virt_addr = runtime->dma_addr, ICEREG(ice, CONCAP_ADDR));
 	outw(buf_size, ICEREG(ice, CONCAP_COUNT));
 	snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_HI, period_size >> 8);
 	snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_LO, period_size & 0xff);
 	snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
+	spin_unlock(&ice->reg_lock);
 	snd_ac97_set_rate(ice->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
 	return 0;
 }
@@ -748,15 +852,14 @@
 {
 	snd_pcm_runtime_t *runtime = substream->runtime;
 	ice1712_t *ice = snd_pcm_substream_chip(substream);
-	unsigned long flags;
 	u32 tmp;
 
 	ice->playback_con_substream_ds[substream->number] = substream;
 	runtime->hw = snd_ice1712_playback_ds;
-	spin_lock_irqsave(&ice->reg_lock, flags); 
+	spin_lock_irq(&ice->reg_lock); 
 	tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2));
 	outw(tmp, ICEDS(ice, INTMASK));
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
+	spin_unlock_irq(&ice->reg_lock);
 	return 0;
 }
 
@@ -784,13 +887,12 @@
 static int snd_ice1712_playback_ds_close(snd_pcm_substream_t * substream)
 {
 	ice1712_t *ice = snd_pcm_substream_chip(substream);
-	unsigned long flags;
 	u32 tmp;
 
-	spin_lock_irqsave(&ice->reg_lock, flags); 
+	spin_lock_irq(&ice->reg_lock); 
 	tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2));
 	outw(tmp, ICEDS(ice, INTMASK));
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
+	spin_unlock_irq(&ice->reg_lock);
 	ice->playback_con_substream_ds[substream->number] = NULL;
 	return 0;
 }
@@ -934,16 +1036,30 @@
 		unsigned int old;
 		if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
 			return -EINVAL;
-		what = ICE1712_PLAYBACK_PAUSE;
-		snd_pcm_trigger_done(substream, substream);
-		spin_lock(&ice->reg_lock);
-		old = inl(ICEMT(ice, PLAYBACK_CONTROL));
-		if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
-			old |= what;
-		else
-			old &= ~what;
-		outl(old, ICEMT(ice, PLAYBACK_CONTROL));
-		spin_unlock(&ice->reg_lock);
+		if (ice->vt1724) {
+			what = VT1724_PDMA0_PAUSE;
+			snd_pcm_trigger_done(substream, substream);
+			spin_lock(&ice->reg_lock);
+			old = inl(ICEMT1724(ice, DMA_PAUSE));
+			if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
+				old |= what;
+			else
+				old &= ~what;
+			outl(old, ICEMT1724(ice, DMA_PAUSE));
+			spin_unlock(&ice->reg_lock);
+		}
+		else {
+			what = ICE1712_PLAYBACK_PAUSE;
+			snd_pcm_trigger_done(substream, substream);
+			spin_lock(&ice->reg_lock);
+			old = inl(ICEMT(ice, PLAYBACK_CONTROL));
+			if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
+				old |= what;
+			else
+				old &= ~what;
+			outl(old, ICEMT(ice, PLAYBACK_CONTROL));
+			spin_unlock(&ice->reg_lock);
+		}
 		break;
 	}
 	case SNDRV_PCM_TRIGGER_START:
@@ -952,12 +1068,16 @@
 		unsigned int what = 0;
 		unsigned int old;
 		snd_pcm_substream_t *s = substream;
+
 		do {
 			if (s == ice->playback_pro_substream) {
 				what |= ICE1712_PLAYBACK_START;
 				snd_pcm_trigger_done(s, substream);
 			} else if (s == ice->capture_pro_substream) {
-				what |= ICE1712_CAPTURE_START_SHADOW;
+				if (ice->vt1724)
+					what |= VT1724_RDMA0_START;
+				else
+					what |= ICE1712_CAPTURE_START_SHADOW;
 				snd_pcm_trigger_done(s, substream);
 			}
 			s = s->link_next;
@@ -980,21 +1100,29 @@
 
 /*
  */
-static void snd_ice1712_set_pro_rate(ice1712_t *ice, snd_pcm_substream_t *substream)
+static void snd_ice1712_set_pro_rate(ice1712_t *ice, unsigned int rate, int force)
 {
 	unsigned long flags;
-	unsigned int rate;
 	unsigned char val;
 
 	spin_lock_irqsave(&ice->reg_lock, flags);
-	if ((inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW|
-						  ICE1712_PLAYBACK_PAUSE|
-						  ICE1712_PLAYBACK_START)) ||
-	    (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER)) {
+	if (ice->vt1724 && 
+		((inb(ICEMT(ice, PLAYBACK_CONTROL)) & (VT1724_RDMA0_START|ICE1712_PLAYBACK_START)) || 
+		 (inb(ICEMT1724(ice, DMA_PAUSE) & VT1724_PDMA0_PAUSE)))) {
+		spin_unlock_irqrestore(&ice->reg_lock, flags);
+		return;
+	}
+	else if (!ice->vt1724 && (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW|
+						 ICE1712_PLAYBACK_PAUSE|
+						 ICE1712_PLAYBACK_START))) {
+		spin_unlock_irqrestore(&ice->reg_lock, flags);
+		return;
+	}
+	if (!force && is_pro_rate_locked(ice)) {
 		spin_unlock_irqrestore(&ice->reg_lock, flags);
 		return;
 	}
-	rate = substream->runtime->rate;
+
 	switch (rate) {
 	case 8000: val = 6; break;
 	case 9600: val = 3; break;
@@ -1015,24 +1143,46 @@
 		break;
 	}
 	outb(val, ICEMT(ice, RATE));
+
 	spin_unlock_irqrestore(&ice->reg_lock, flags);
 
 	if (ice->ak4524.ops.set_rate_val)
-		ice->ak4524.ops.set_rate_val(ice, val);
+		ice->ak4524.ops.set_rate_val(ice, rate);
 }
 
 static int snd_ice1712_playback_pro_prepare(snd_pcm_substream_t * substream)
 {
-	unsigned long flags;
 	ice1712_t *ice = snd_pcm_substream_chip(substream);
 
 	ice->playback_pro_size = snd_pcm_lib_buffer_bytes(substream);
-	snd_ice1712_set_pro_rate(ice, substream);
-	spin_lock_irqsave(&ice->reg_lock, flags);
+	snd_ice1712_set_pro_rate(ice, substream->runtime->rate, 0);
+	spin_lock(&ice->reg_lock);
 	outl(substream->runtime->dma_addr, ICEMT(ice, PLAYBACK_ADDR));
-	outw((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE));
-	outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, PLAYBACK_COUNT));
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
+	if (ice->vt1724) {
+		outl((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE));	
+		outl((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT1724(ice, PLAYBACK_COUNT));
+
+		switch(substream->runtime->channels)
+		{
+			case 8:
+				outb(0, ICEMT1724(ice, BURST));
+				break;
+			case 6:
+				outb(1, ICEMT1724(ice, BURST));
+				break;
+			case 4:
+				outb(2, ICEMT1724(ice, BURST));
+				break;
+			case 2:
+				outb(3, ICEMT1724(ice, BURST));
+				break;
+		}
+	}
+	else {
+		outw((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE));
+		outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, PLAYBACK_COUNT));
+	}
+	spin_unlock(&ice->reg_lock);
 
 	if (ice->spdif.ops.setup)
 		ice->spdif.ops.setup(ice, substream);
@@ -1042,16 +1192,15 @@
 
 static int snd_ice1712_capture_pro_prepare(snd_pcm_substream_t * substream)
 {
-	unsigned long flags;
 	ice1712_t *ice = snd_pcm_substream_chip(substream);
 
 	ice->capture_pro_size = snd_pcm_lib_buffer_bytes(substream);
-	snd_ice1712_set_pro_rate(ice, substream);
-	spin_lock_irqsave(&ice->reg_lock, flags);
+	snd_ice1712_set_pro_rate(ice, substream->runtime->rate, 0);
+	spin_lock(&ice->reg_lock);
 	outl(substream->runtime->dma_addr, ICEMT(ice, CAPTURE_ADDR));
 	outw((ice->capture_pro_size >> 2) - 1, ICEMT(ice, CAPTURE_SIZE));
 	outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, CAPTURE_COUNT));
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
+	spin_unlock(&ice->reg_lock);
 	return 0;
 }
 
@@ -1062,7 +1211,10 @@
 
 	if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_PLAYBACK_START))
 		return 0;
-	ptr = ice->playback_pro_size - (inw(ICEMT(ice, PLAYBACK_SIZE)) << 2);
+	if (ice->vt1724)
+		ptr = ice->playback_pro_size - ((inl(ICEMT(ice, PLAYBACK_SIZE))&0x7ffff) << 2);
+	else
+		ptr = ice->playback_pro_size - (inw(ICEMT(ice, PLAYBACK_SIZE)) << 2);
 	return bytes_to_frames(substream->runtime, ptr);
 }
 
@@ -1097,6 +1249,27 @@
 	.fifo_size =		0,
 };
 
+static snd_pcm_hardware_t snd_vt1724_playback_pro =
+{
+	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
+				 SNDRV_PCM_INFO_MMAP_VALID |
+				 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
+	.formats =		SNDRV_PCM_FMTBIT_S32_LE,
+	.rates =		SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
+	.rate_min =		4000,
+	.rate_max =		96000,
+	.channels_min =		2,
+	.channels_max =		8,
+	.buffer_bytes_max =	0x7ffff0,	/* we have 18bits for the buffer size, in dwords */
+	.period_bytes_min =	8 * 4 * 2,
+	.period_bytes_max =	131040,		/* do we have 18bits for terminal count? 
+										Datasheets says bits 18:0 but only has 2 byte registers (1C-1Dh ) */
+	.periods_min =		1,
+	.periods_max =		1024,
+	.fifo_size =		0,
+};
+
 static snd_pcm_hardware_t snd_ice1712_capture_pro =
 {
 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
@@ -1117,13 +1290,36 @@
 	.fifo_size =		0,
 };
 
+static snd_pcm_hardware_t snd_ice1724_capture_pro =
+{
+	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
+				 SNDRV_PCM_INFO_MMAP_VALID |
+				 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
+	.formats =		SNDRV_PCM_FMTBIT_S32_LE,
+	.rates =		SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
+	.rate_min =		4000,
+	.rate_max =		96000,
+	.channels_min =		2,
+	.channels_max =		2,
+	.buffer_bytes_max =	(256*1024),
+	.period_bytes_min =	2 * 4 * 2,
+	.period_bytes_max =	131040,
+	.periods_min =		1,
+	.periods_max =		1024,
+	.fifo_size =		0,
+};
+
 static int snd_ice1712_playback_pro_open(snd_pcm_substream_t * substream)
 {
 	snd_pcm_runtime_t *runtime = substream->runtime;
 	ice1712_t *ice = snd_pcm_substream_chip(substream);
 
 	ice->playback_pro_substream = substream;
-	runtime->hw = snd_ice1712_playback_pro;
+	if (ice->vt1724)
+		runtime->hw = snd_vt1724_playback_pro;
+	else
+		runtime->hw = snd_ice1712_playback_pro;
 	snd_pcm_set_sync(substream);
 	snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
@@ -1140,7 +1336,10 @@
 	snd_pcm_runtime_t *runtime = substream->runtime;
 
 	ice->capture_pro_substream = substream;
-	runtime->hw = snd_ice1712_capture_pro;
+	if (ice->vt1724)
+		runtime->hw = snd_ice1724_capture_pro;
+	else
+		runtime->hw = snd_ice1712_capture_pro;
 	snd_pcm_set_sync(substream);
 	snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
@@ -1151,6 +1350,8 @@
 {
 	ice1712_t *ice = snd_pcm_substream_chip(substream);
 
+	if (PRO_RATE_RESET)
+		snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
 	ice->playback_pro_substream = NULL;
 	if (ice->spdif.ops.close)
 		ice->spdif.ops.close(ice, substream);
@@ -1162,6 +1363,8 @@
 {
 	ice1712_t *ice = snd_pcm_substream_chip(substream);
 
+	if (PRO_RATE_RESET)
+		snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
 	ice->capture_pro_substream = NULL;
 	return 0;
 }
@@ -1261,31 +1464,29 @@
 static int snd_ice1712_pro_mixer_switch_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
 {
 	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
-	unsigned long flags;
 	int index = kcontrol->private_value;
 	
-	spin_lock_irqsave(&ice->reg_lock, flags);
+	spin_lock_irq(&ice->reg_lock);
 	ucontrol->value.integer.value[0] = !((ice->pro_volumes[index] >> 15) & 1);
 	ucontrol->value.integer.value[1] = !((ice->pro_volumes[index] >> 31) & 1);
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
+	spin_unlock_irq(&ice->reg_lock);
 	return 0;
 }
 
 static int snd_ice1712_pro_mixer_switch_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
 {
-	unsigned long flags;
 	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
 	int index = kcontrol->private_value;
 	unsigned int nval, change;
 
 	nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
 	       (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
-	spin_lock_irqsave(&ice->reg_lock, flags);
+	spin_lock_irq(&ice->reg_lock);
 	nval |= ice->pro_volumes[index] & ~0x80008000;
 	change = nval != ice->pro_volumes[index];
 	ice->pro_volumes[index] = nval;
 	snd_ice1712_update_volume(ice, index);
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
+	spin_unlock_irq(&ice->reg_lock);
 	return change;
 }
 
@@ -1301,36 +1502,34 @@
 static int snd_ice1712_pro_mixer_volume_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
 {
 	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
-	unsigned long flags;
 	int index = kcontrol->private_value;
 	
-	spin_lock_irqsave(&ice->reg_lock, flags);
+	spin_lock_irq(&ice->reg_lock);
 	ucontrol->value.integer.value[0] = (ice->pro_volumes[index] >> 0) & 127;
 	ucontrol->value.integer.value[1] = (ice->pro_volumes[index] >> 16) & 127;
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
+	spin_unlock_irq(&ice->reg_lock);
 	return 0;
 }
 
 static int snd_ice1712_pro_mixer_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
 {
-	unsigned long flags;
 	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
 	int index = kcontrol->private_value;
 	unsigned int nval, change;
 
 	nval = (ucontrol->value.integer.value[0] & 127) |
 	       ((ucontrol->value.integer.value[1] & 127) << 16);
-	spin_lock_irqsave(&ice->reg_lock, flags);
+	spin_lock_irq(&ice->reg_lock);
 	nval |= ice->pro_volumes[index] & ~0x007f007f;
 	change = nval != ice->pro_volumes[index];
 	ice->pro_volumes[index] = nval;
 	snd_ice1712_update_volume(ice, index);
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
+	spin_unlock_irq(&ice->reg_lock);
 	return change;
 }
 
 
-static int __init snd_ice1712_build_pro_mixer(ice1712_t *ice)
+static int __devinit snd_ice1712_build_pro_mixer(ice1712_t *ice)
 {
 	snd_card_t * card = ice->card;
 	snd_kcontrol_t ctl;
@@ -1475,6 +1674,20 @@
 		snd_iprintf(buffer, "  ADC ID #%i        : 0x%x\n", idx, ice->eeprom.adcID[idx]);
 	for (idx = 0x1c; idx < ice->eeprom.size && idx < 0x1c + sizeof(ice->eeprom.extra); idx++)
 		snd_iprintf(buffer, "  Extra #%02i        : 0x%x\n", idx, ice->eeprom.extra[idx - 0x1c]);
+	snd_iprintf(buffer, "\nRegisters:\n");
+	if (ice->vt1724) {
+		snd_iprintf(buffer, "  PSDOUT03         : 0x%08x\n", (unsigned)inl(ICEMT1724(ice, ROUTE_PLAYBACK)));
+		for (idx = 0x0; idx < 0x20 ; idx++)
+			snd_iprintf(buffer, "  CCS%02x         : 0x%02x\n", idx, inb(ice->port+idx));
+		for (idx = 0x0; idx < 0x30 ; idx++)
+			snd_iprintf(buffer, "  MT%02x         : 0x%02x\n", idx, inb(ice->profi_port+idx));
+
+	}
+	else {
+		snd_iprintf(buffer, "  PSDOUT03         : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_PSDOUT03)));
+		snd_iprintf(buffer, "  CAPTURE          : 0x%08x\n", inl(ICEMT(ice, ROUTE_CAPTURE)));
+		snd_iprintf(buffer, "  SPDOUT           : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_SPDOUT)));
+	}
 }
 
 static void __devinit snd_ice1712_proc_init(ice1712_t * ice)
@@ -1668,10 +1881,13 @@
 	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
 	unsigned char mask = kcontrol->private_value & 0xff;
 	int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
-	unsigned char saved[2];
+	unsigned char saved[6];
 	
 	snd_ice1712_save_gpio_status(ice, saved);
-	ucontrol->value.integer.value[0] = (snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0) ^ invert;
+	if (ice->vt1724)
+		ucontrol->value.integer.value[0] = (inb(ICEREG1724(ice, GPIO_DATA)) & mask ? 1 : 0) ^ invert;
+	else
+		ucontrol->value.integer.value[0] = (snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0) ^ invert;
 	snd_ice1712_restore_gpio_status(ice, saved);
 	return 0;
 }
@@ -1681,67 +1897,186 @@
 	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
 	unsigned char mask = kcontrol->private_value & 0xff;
 	int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
-	unsigned char saved[2];
+	unsigned char saved[6];
 	int val, nval;
 
 	if (kcontrol->private_value & (1 << 31))
 		return -EPERM;
 	nval = (ucontrol->value.integer.value[0] ? mask : 0) ^ invert;
 	snd_ice1712_save_gpio_status(ice, saved);
-	val = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
-	nval |= val & ~mask;
-	snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, nval);
+	if (ice->vt1724) {
+		val = inb(ICEREG1724(ice, GPIO_DATA));
+		nval |= val & ~mask;
+		outb(nval, ICEREG1724(ice, GPIO_DATA));
+	}
+	else {
+		val = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
+		nval |= val & ~mask;
+		snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, nval);
+	}
 	snd_ice1712_restore_gpio_status(ice, saved);
 	return val != nval;
 }
 
-static int snd_ice1712_pro_spdif_master_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+/*
+ *  rate
+ */
+static int snd_ice1712_pro_internal_clock_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
 {
-	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
+	static char *texts[] = {
+		"8000",		/* 0: 6 */
+		"9600",		/* 1: 3 */
+		"11025",	/* 2: 10 */
+		"12000",	/* 3: 2 */
+		"16000",	/* 4: 5 */
+		"22050",	/* 5: 9 */
+		"24000",	/* 6: 1 */
+		"32000",	/* 7: 4 */
+		"44100",	/* 8: 8 */
+		"48000",	/* 9: 0 */
+		"64000",	/* 10: 15 */
+		"88200",	/* 11: 11 */
+		"96000",	/* 12: 7 */
+		"IEC958 Input",	/* 13: -- */
+	};
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
 	uinfo->count = 1;
-	uinfo->value.integer.min = 0;
-	uinfo->value.integer.max = 1;
+	uinfo->value.enumerated.items = 14;
+	if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
+		uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
+	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
 	return 0;
 }
 
-static int snd_ice1712_pro_spdif_master_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_ice1712_pro_internal_clock_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
 {
 	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
-	unsigned long flags;
+	static unsigned char xlate[16] = {
+		9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 255, 255, 255, 10
+	};
+	unsigned char val;
 	
-	spin_lock_irqsave(&ice->reg_lock, flags);
-	ucontrol->value.integer.value[0] = inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER ? 1 : 0;
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
+	spin_lock_irq(&ice->reg_lock);
+	if (is_spdif_master(ice)) {
+		ucontrol->value.enumerated.item[0] = 13;
+	} else {
+		val = xlate[inb(ICEMT(ice, RATE)) & 15];
+		if (val == 255) {
+			snd_BUG();
+			val = 0;
+		}
+		ucontrol->value.enumerated.item[0] = val;
+	}
+	spin_unlock_irq(&ice->reg_lock);
 	return 0;
 }
 
-static int snd_ice1712_pro_spdif_master_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_ice1712_pro_internal_clock_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
 {
-	unsigned long flags;
 	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
-	int nval, change;
+	static unsigned int xrate[13] = {
+		8000, 9600, 11025, 12000, 1600, 22050, 24000,
+		32000, 44100, 48000, 64000, 88200, 96000
+	};
+	unsigned char oval;
+	int change = 0;
 
-	nval = ucontrol->value.integer.value[0] ? ICE1712_SPDIF_MASTER : 0;
-	spin_lock_irqsave(&ice->reg_lock, flags);
-	nval |= inb(ICEMT(ice, RATE)) & ~ICE1712_SPDIF_MASTER;
-	change = inb(ICEMT(ice, RATE)) != nval;
-	outb(nval, ICEMT(ice, RATE));
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
+	spin_lock_irq(&ice->reg_lock);
+	oval = inb(ICEMT(ice, RATE));
+	if (ucontrol->value.enumerated.item[0] == 13) {
+		outb(oval | ICE1712_SPDIF_MASTER, ICEMT(ice, RATE));
+	} else {
+		PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
+		spin_unlock_irq(&ice->reg_lock);
+		snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
+		spin_lock_irq(&ice->reg_lock);
+	}
+	change = inb(ICEMT(ice, RATE)) != oval;
+	spin_unlock_irq(&ice->reg_lock);
 
-	if (ice->cs8427) {
+	if ((oval & ICE1712_SPDIF_MASTER) != (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER)) {
 		/* change CS8427 clock source too */
-		snd_ice1712_cs8427_set_input_clock(ice, ucontrol->value.integer.value[0]);
+		if (ice->cs8427) {
+			snd_ice1712_cs8427_set_input_clock(ice, is_spdif_master(ice));
+		}
+		/* notify ak4524 chip as well */
+		if (is_spdif_master(ice) && ice->ak4524.ops.set_rate_val)
+			ice->ak4524.ops.set_rate_val(ice, 0);
 	}
 
 	return change;
 }
 
-static snd_kcontrol_new_t snd_ice1712_pro_spdif_master __devinitdata = {
+static snd_kcontrol_new_t snd_ice1712_pro_internal_clock = __devinitdata {
 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-	.name = "Multi Track IEC958 Master",
-	.info = snd_ice1712_pro_spdif_master_info,
-	.get = snd_ice1712_pro_spdif_master_get,
-	.put = snd_ice1712_pro_spdif_master_put
+	.name = "Multi Track Internal Clock",
+	.info = snd_ice1712_pro_internal_clock_info,
+	.get = snd_ice1712_pro_internal_clock_get,
+	.put = snd_ice1712_pro_internal_clock_put
+};
+
+static int snd_ice1712_pro_rate_locking_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
+	uinfo->count = 1;
+	uinfo->value.integer.min = 0;
+	uinfo->value.integer.max = 1;
+	return 0;
+}
+
+static int snd_ice1712_pro_rate_locking_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	ucontrol->value.integer.value[0] = PRO_RATE_LOCKED ? 1 : 0;
+	return 0;
+}
+
+static int snd_ice1712_pro_rate_locking_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	int change = 0;
+
+	change = PRO_RATE_LOCKED ? 1 : 0 != ucontrol->value.integer.value[0] ? 1 : 0;
+	PRO_RATE_LOCKED = ucontrol->value.integer.value[0] ? 1 : 0;
+	return change;
+}
+
+static snd_kcontrol_new_t snd_ice1712_pro_rate_locking __devinitdata = {
+	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+	.name = "Multi Track Rate Locking",
+	.info = snd_ice1712_pro_rate_locking_info,
+	.get = snd_ice1712_pro_rate_locking_get,
+	.put = snd_ice1712_pro_rate_locking_put
+};
+
+static int snd_ice1712_pro_rate_reset_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
+	uinfo->count = 1;
+	uinfo->value.integer.min = 0;
+	uinfo->value.integer.max = 1;
+	return 0;
+}
+
+static int snd_ice1712_pro_rate_reset_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	ucontrol->value.integer.value[0] = PRO_RATE_RESET ? 1 : 0;
+	return 0;
+}
+
+static int snd_ice1712_pro_rate_reset_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	int change = 0;
+
+	change = PRO_RATE_LOCKED ? 1 : 0 != ucontrol->value.integer.value[0] ? 1 : 0;
+	PRO_RATE_RESET = ucontrol->value.integer.value[0] ? 1 : 0;
+	return change;
+}
+
+static snd_kcontrol_new_t snd_ice1712_pro_rate_reset __devinitdata = {
+	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+	.name = "Multi Track Rate Reset",
+	.info = snd_ice1712_pro_rate_reset_info,
+	.get = snd_ice1712_pro_rate_reset_get,
+	.put = snd_ice1712_pro_rate_reset_put
 };
 
 /*
@@ -1771,10 +2106,14 @@
 	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
 	int idx = kcontrol->id.index;
 	unsigned int val, cval;
+
+	spin_lock_irq(&ice->reg_lock);
 	val = inw(ICEMT(ice, ROUTE_PSDOUT03));
+	cval = inl(ICEMT(ice, ROUTE_CAPTURE));
+	spin_unlock_irq(&ice->reg_lock);
+
 	val >>= ((idx % 2) * 8) + ((idx / 2) * 2);
 	val &= 3;
-	cval = inl(ICEMT(ice, ROUTE_CAPTURE));
 	cval >>= ((idx / 2) * 8) + ((idx % 2) * 4);
 	if (val == 1 && idx < 2)
 		ucontrol->value.enumerated.item[0] = 11;
@@ -1804,16 +2143,19 @@
 	else
 		nval = 0; /* pcm */
 	shift = ((idx % 2) * 8) + ((idx / 2) * 2);
+	spin_lock_irq(&ice->reg_lock);
 	val = old_val = inw(ICEMT(ice, ROUTE_PSDOUT03));
 	val &= ~(0x03 << shift);
 	val |= nval << shift;
 	change = val != old_val;
 	if (change)
 		outw(val, ICEMT(ice, ROUTE_PSDOUT03));
+	spin_unlock_irq(&ice->reg_lock);
 	if (nval < 2) /* dig mixer of pcm */
 		return change;
 
 	/* update CAPTURE */
+	spin_lock_irq(&ice->reg_lock);
 	val = old_val = inl(ICEMT(ice, ROUTE_CAPTURE));
 	shift = ((idx / 2) * 8) + ((idx % 2) * 4);
 	if (nval == 2) { /* analog in */
@@ -1829,6 +2171,7 @@
 		change = 1;
 		outl(val, ICEMT(ice, ROUTE_CAPTURE));
 	}
+	spin_unlock_irq(&ice->reg_lock);
 	return change;
 }
 
@@ -1859,6 +2202,7 @@
 	unsigned int val, old_val, nval;
 	
 	/* update SPDOUT */
+	spin_lock_irq(&ice->reg_lock);
 	val = old_val = inw(ICEMT(ice, ROUTE_SPDOUT));
 	if (ucontrol->value.enumerated.item[0] >= 11)
 		nval = 1;
@@ -1884,6 +2228,7 @@
 	change = val != old_val;
 	if (change)
 		outw(val, ICEMT(ice, ROUTE_SPDOUT));
+	spin_unlock_irq(&ice->reg_lock);
 	return change;
 }
 
@@ -1904,6 +2249,141 @@
 };
 
 
+static int snd_vt1724_pro_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+	static char *texts[] = {
+		"PCM Out", /* 0 */
+		"H/W In 0", "H/W In 1", /* 1-2 */
+		"IEC958 In L", "IEC958 In R", /* 3-4 */
+	};
+	
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+	uinfo->count = 1;
+	uinfo->value.enumerated.items = 5;//kcontrol->id.index < 2 ? 12 : 11;
+	if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
+		uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
+	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
+	return 0;
+}
+
+static int snd_vt1724_pro_route_analog_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
+{
+	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
+	int idx = kcontrol->id.index;
+	unsigned long val;
+	unsigned char eitem;
+	static unsigned char xlate[8] = {
+		0, 255, 1, 2, 255, 255, 3, 4,
+	};
+
+	val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
+	val >>= ((idx % 2) * 12) + ((idx / 2) * 3)+8;
+	val &= 7;	//we now have 3 bits per output
+	eitem=xlate[val];
+	if (eitem == 255) {
+		snd_BUG();
+		eitem = 0;
+	}
+	ucontrol->value.enumerated.item[0] = eitem;
+
+	return 0;
+}
+
+static int snd_vt1724_pro_route_analog_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
+{
+	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
+	int change, shift;
+	int idx = kcontrol->id.index;
+	unsigned int val, old_val, nval;
+	static unsigned char xroute[8] = {
+		0, /* PCM */
+		2, /* PSDIN0 Left */
+		3, /* PSDIN0 Right */
+		6, /* SPDIN Left */
+		7,  /* SPDIN Right */
+	};
+	
+	/* update PSDOUT */
+
+	nval=xroute[ucontrol->value.enumerated.item[0]&7];
+	shift = ((idx % 2) * 12) + ((idx / 2) * 3) +8;
+	val = old_val = inw(ICEMT1724(ice, ROUTE_PLAYBACK));
+	val &= ~(0x07 << shift);
+	val |= nval << shift;
+	change = val != old_val;
+	if (change)
+		outw(val, ICEMT1724(ice, ROUTE_PLAYBACK));
+	return change;
+}
+
+static int snd_vt1724_pro_route_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
+{
+	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
+	int idx = kcontrol->id.index;
+	unsigned long val;
+	unsigned char eitem;
+	static unsigned char xlate[8] = {
+		0, 255, 1, 2, 255, 255, 3, 4,
+	};
+
+	val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
+	val >>= idx*3;	//I hope this is right
+	val &= 7;	
+
+	eitem=xlate[val];
+	if (eitem == 255) {
+		snd_BUG();
+		eitem = 0;
+	}
+	ucontrol->value.enumerated.item[0] = eitem;
+	return 0;
+}
+
+static int snd_vt1724_pro_route_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucontrol)
+{
+	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
+	int change, shift;
+	int idx = kcontrol->id.index;
+	unsigned long val, old_val, nval;
+	static unsigned char xroute[8] = {
+		0, /* PCM */
+		2, /* PSDIN0 Left */
+		3, /* PSDIN0 Right */
+		6, /* SPDIN Left */
+		7,  /* SPDIN Right */
+	};
+	
+	/* update SPDOUT */
+	val = old_val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
+	nval = xroute[ucontrol->value.enumerated.item[0]&7];
+
+	shift = idx * 2;
+	val &= ~(0x07 << shift);
+	val |= nval << shift;
+	shift = idx * 4 + 8;
+	change = val != old_val;
+	if (change)
+		outl(val, ICEMT1724(ice, ROUTE_PLAYBACK));
+	return change;
+}
+
+static snd_kcontrol_new_t snd_vt1724_mixer_pro_analog_route __devinitdata = {
+	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+	.name = "H/W Playback Route",
+	.info = snd_vt1724_pro_route_info,
+	.get = snd_vt1724_pro_route_analog_get,
+	.put = snd_vt1724_pro_route_analog_put,
+};
+
+static snd_kcontrol_new_t snd_vt1724_mixer_pro_spdif_route __devinitdata = {
+	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+	.name = "IEC958 Playback Route",
+	.info = snd_vt1724_pro_route_info,
+	.get = snd_vt1724_pro_route_spdif_get,
+	.put = snd_vt1724_pro_route_spdif_put,
+};
+
+
 static int snd_ice1712_pro_volume_rate_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
 {
 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
@@ -1916,24 +2396,20 @@
 static int snd_ice1712_pro_volume_rate_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
 {
 	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
-	unsigned long flags;
 	
-	spin_lock_irqsave(&ice->reg_lock, flags);
 	ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE));
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
 	return 0;
 }
 
 static int snd_ice1712_pro_volume_rate_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
 {
-	unsigned long flags;
 	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
 	int change;
 
-	spin_lock_irqsave(&ice->reg_lock, flags);
+	spin_lock_irq(&ice->reg_lock);
 	change = inb(ICEMT(ice, MONITOR_RATE)) != ucontrol->value.integer.value[0];
 	outb(ucontrol->value.integer.value[0], ICEMT(ice, MONITOR_RATE));
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
+	spin_unlock_irq(&ice->reg_lock);
 	return change;
 }
 
@@ -1957,15 +2433,14 @@
 static int snd_ice1712_pro_peak_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
 {
 	ice1712_t *ice = snd_kcontrol_chip(kcontrol);
-	unsigned long flags;
 	int idx;
 	
-	spin_lock_irqsave(&ice->reg_lock, flags);
+	spin_lock_irq(&ice->reg_lock);
 	for (idx = 0; idx < 22; idx++) {
 		outb(idx, ICEMT(ice, MONITOR_PEAKINDEX));
 		ucontrol->value.integer.value[idx] = inb(ICEMT(ice, MONITOR_PEAKDATA));
 	}
-	spin_unlock_irqrestore(&ice->reg_lock, flags);
+	spin_unlock_irq(&ice->reg_lock);
 	return 0;
 }
 
@@ -2017,9 +2492,13 @@
 		return -EIO;
 	}
 	ice->eeprom.codec = snd_ice1712_read_i2c(ice, dev, 0x06);
+	if (ice->vt1724)
+		ice->eeprom.codec |= ICE1712_CFG_NO_CON_AC97;	/* little hack here */
 	ice->eeprom.aclink = snd_ice1712_read_i2c(ice, dev, 0x07);
 	ice->eeprom.i2sID = snd_ice1712_read_i2c(ice, dev, 0x08);
 	ice->eeprom.spdif = snd_ice1712_read_i2c(ice, dev, 0x09);
+	if (ice->vt1724)
+		ice->eeprom.spdif &= ~VT1724_CFG_SPDIF_OUT_EN;	/* little hack here */
 	ice->eeprom.gpiomask = snd_ice1712_read_i2c(ice, dev, 0x0a);
 	ice->eeprom.gpiostate = snd_ice1712_read_i2c(ice, dev, 0x0b);
 	ice->eeprom.gpiodir = snd_ice1712_read_i2c(ice, dev, 0x0c);
@@ -2076,6 +2555,27 @@
 	return 0;
 }
 
+static int __devinit snd_vt1724_chip_init(ice1712_t *ice)
+{
+	outb(VT1724_RESET , ICEREG(ice, CONTROL));
+	udelay(200);
+	outb(0, ICEREG(ice, CONTROL));
+	udelay(200);
+	outb(ice->eeprom.codec, ICEREG1724(ice, SYS_CFG));
+	outb(ice->eeprom.aclink&0x7f, ICEREG1724(ice, AC97_CFG));
+	outb(ice->eeprom.i2sID, ICEREG1724(ice, I2S_FEATURES));
+	outb(ice->eeprom.spdif, ICEREG1724(ice, SPDIF_CFG));
+
+	ice->gpio_write_mask = ice->eeprom.gpiomask;
+	ice->gpio_direction = ice->eeprom.gpiodir;
+	outb(ice->eeprom.gpiomask, ICEREG1724(ice, GPIO_WRITE_MASK));
+	outb(ice->eeprom.gpiodir, ICEREG1724(ice, GPIO_DIRECTION));
+	outb(ice->eeprom.gpiostate, ICEREG1724(ice, GPIO_DATA));
+
+	outb(0, ICEREG1724(ice, POWERDOWN));	
+
+	return 0;
+}
 
 int __devinit snd_ice1712_spdif_build_controls(ice1712_t *ice)
 {
@@ -2113,33 +2613,67 @@
 	err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_eeprom, ice));
 	if (err < 0)
 		return err;
-	err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_spdif_master, ice));
+	err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock, ice));
 	if (err < 0)
 		return err;
-	for (idx = 0; idx < ice->num_total_dacs; idx++) {
-		kctl = snd_ctl_new1(&snd_ice1712_mixer_pro_analog_route, ice);
-		if (kctl == NULL)
-			return -ENOMEM;
-		kctl->id.index = idx;
-		err = snd_ctl_add(ice->card, kctl);
+
+	if (ice->vt1724) {
+		for (idx = 0; idx < ice->num_total_dacs; idx++) {
+			kctl = snd_ctl_new1(&snd_vt1724_mixer_pro_analog_route, ice);
+			if (kctl == NULL)
+				return -ENOMEM;
+			kctl->id.index = idx;
+			err = snd_ctl_add(ice->card, kctl);
+			if (err < 0)
+				return err;
+		}
+		for (idx = 0; idx < 2; idx++) {
+			kctl = snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice);
+			if (kctl == NULL)
+				return -ENOMEM;
+			kctl->id.index = idx;
+			err = snd_ctl_add(ice->card, kctl);
+			if (err < 0)
+				return err;
+		}
+		err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice));
 		if (err < 0)
 			return err;
+
 	}
-	for (idx = 0; idx < 2; idx++) {
-		kctl = snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice);
-		if (kctl == NULL)
-			return -ENOMEM;
-		kctl->id.index = idx;
-		err = snd_ctl_add(ice->card, kctl);
+	else {
+		err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_locking, ice));
+		if (err < 0)
+			return err;
+		err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_reset, ice));
+		if (err < 0)
+			return err;
+
+		for (idx = 0; idx < ice->num_total_dacs; idx++) {
+			kctl = snd_ctl_new1(&snd_ice1712_mixer_pro_analog_route, ice);
+			if (kctl == NULL)
+				return -ENOMEM;
+			kctl->id.index = idx;
+			err = snd_ctl_add(ice->card, kctl);
+			if (err < 0)
+				return err;
+		}
+		for (idx = 0; idx < 2; idx++) {
+			kctl = snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice);
+			if (kctl == NULL)
+				return -ENOMEM;
+			kctl->id.index = idx;
+			err = snd_ctl_add(ice->card, kctl);
+			if (err < 0)
+				return err;
+		}
+		err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
+		if (err < 0)
+			return err;
+		err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice));
 		if (err < 0)
 			return err;
 	}
-	err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
-	if (err < 0)
-		return err;
-	err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice));
-	if (err < 0)
-		return err;
 	return 0;
 }
 
@@ -2148,7 +2682,10 @@
 	if (ice->res_port == NULL)
 		goto __hw_end;
 	/* mask all interrupts */
-	outb(0xc0, ICEMT(ice, IRQ));
+	if (ice->vt1724)
+		outb(0xff, ICEMT1724(ice, DMA_INT_MASK));
+	else
+		outb(0xc0, ICEMT(ice, IRQ));
 	outb(0xff, ICEREG(ice, IRQMASK));
 	/* --- */
       __hw_end:
@@ -2199,16 +2736,22 @@
         /* enable PCI device */
 	if ((err = pci_enable_device(pci)) < 0)
 		return err;
-	/* check, if we can restrict PCI DMA transfers to 28 bits */
-	if (!pci_dma_supported(pci, 0x0fffffff)) {
-		snd_printk("architecture does not support 28bit PCI busmaster DMA\n");
-		return -ENXIO;
+	/* VT1724 does not have 28bit DMA transfer limit */
+	if (pci->device==PCI_DEVICE_ID_ICE_1712) {
+		/* check, if we can restrict PCI DMA transfers to 28 bits */
+		if (!pci_dma_supported(pci, 0x0fffffff)) {
+			snd_printk("architecture does not support 28bit PCI busmaster DMA\n");
+			return -ENXIO;
+		}
+		pci_set_dma_mask(pci, 0x0fffffff);
 	}
-	pci_set_dma_mask(pci, 0x0fffffff);
+	else pci_set_dma_mask(pci, 0xffffffff); 
 
 	ice = snd_magic_kcalloc(ice1712_t, 0, GFP_KERNEL);
 	if (ice == NULL)
 		return -ENOMEM;
+	if (pci->device==PCI_DEVICE_ID_VT1724)
+		ice->vt1724=1;
 	ice->omni = omni ? 1 : 0;
 	spin_lock_init(&ice->reg_lock);
 	init_MUTEX(&ice->gpio_mutex);
@@ -2220,60 +2763,105 @@
 	ice->pci = pci;
 	ice->irq = -1;
 	ice->port = pci_resource_start(pci, 0);
-	ice->ddma_port = pci_resource_start(pci, 1);
-	ice->dmapath_port = pci_resource_start(pci, 2);
-	ice->profi_port = pci_resource_start(pci, 3);
-	pci_set_master(pci);
-	pci_write_config_word(ice->pci, 0x40, 0x807f);
-	pci_write_config_word(ice->pci, 0x42, 0x0006);
-	snd_ice1712_proc_init(ice);
-	synchronize_irq(pci->irq);
+	if (ice->vt1724) {
+		ice->profi_port = pci_resource_start(pci, 1);
+		pci_set_master(pci);
+		snd_ice1712_proc_init(ice);
+		synchronize_irq(pci->irq);
+
+		if ((ice->res_port = request_region(ice->port, 32, "ICE1724 - Controller")) == NULL) {
+			snd_ice1712_free(ice);
+			snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->port, ice->port + 32 - 1);
+			return -EIO;
+		}
 
-	if ((ice->res_port = request_region(ice->port, 32, "ICE1712 - Controller")) == NULL) {
-		snd_ice1712_free(ice);
-		snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->port, ice->port + 32 - 1);
-		return -EIO;
-	}
-	if ((ice->res_ddma_port = request_region(ice->ddma_port, 16, "ICE1712 - DDMA")) == NULL) {
-		snd_ice1712_free(ice);
-		snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->ddma_port, ice->ddma_port + 16 - 1);
-		return -EIO;
-	}
-	if ((ice->res_dmapath_port = request_region(ice->dmapath_port, 16, "ICE1712 - DMA path")) == NULL) {
-		snd_ice1712_free(ice);
-		snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->dmapath_port, ice->dmapath_port + 16 - 1);
-		return -EIO;
-	}
-	if ((ice->res_profi_port = request_region(ice->profi_port, 64, "ICE1712 - Professional")) == NULL) {
-		snd_ice1712_free(ice);
-		snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->profi_port, ice->profi_port + 16 - 1);
-		return -EIO;
-	}
-	if (request_irq(pci->irq, snd_ice1712_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1712", (void *) ice)) {
-		snd_ice1712_free(ice);
-		snd_printk("unable to grab IRQ %d\n", pci->irq);
-		return -EIO;
-	}
-	ice->irq = pci->irq;
+		if ((ice->res_profi_port = request_region(ice->profi_port, 128, "ICE1724 - Professional")) == NULL) {
+			snd_ice1712_free(ice);
+			snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->profi_port, ice->profi_port + 16 - 1);
+			return -EIO;
+		}
+		
+		if (request_irq(pci->irq, snd_vt1724_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1724", (void *) ice)) {
+			snd_ice1712_free(ice);
+			snd_printk("unable to grab IRQ %d\n", pci->irq);
+			return -EIO;
+		}
 
-	if (snd_ice1712_read_eeprom(ice) < 0) {
-		snd_ice1712_free(ice);
-		return -EIO;
-	}
-	if (snd_ice1712_chip_init(ice) < 0) {
-		snd_ice1712_free(ice);
-		return -EIO;
-	}
+		ice->irq = pci->irq;
+
+		if (snd_ice1712_read_eeprom(ice) < 0) {
+			snd_ice1712_free(ice);
+			return -EIO;
+		}
+		if (snd_vt1724_chip_init(ice) < 0) {
+			snd_ice1712_free(ice);
+			return -EIO;
+		}
 
-	/* unmask used interrupts */
-	outb((ice->eeprom.codec & ICE1712_CFG_2xMPU401) == 0 ? ICE1712_IRQ_MPU2 : 0 |
-	     (ice->eeprom.codec & ICE1712_CFG_NO_CON_AC97) ? ICE1712_IRQ_PBKDS | ICE1712_IRQ_CONCAP | ICE1712_IRQ_CONPBK : 0,
-	     ICEREG(ice, IRQMASK));
-	outb(0x00, ICEMT(ice, IRQ));
+		/* unmask used interrupts */
+		outb((ice->eeprom.codec & ICE1712_CFG_2xMPU401) == 0 ? (VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX) : 0 ,
+			 ICEREG(ice, IRQMASK));
+		/* don't handle FIFO overrun/underruns (just yet), since they cause machine lockups */
+		outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK));	
+	}
+	else {
+		ice->ddma_port = pci_resource_start(pci, 1);
+		ice->dmapath_port = pci_resource_start(pci, 2);
+		ice->profi_port = pci_resource_start(pci, 3);
+		pci_set_master(pci);
+		pci_write_config_word(ice->pci, 0x40, 0x807f);
+		pci_write_config_word(ice->pci, 0x42, 0x0006);
+		snd_ice1712_proc_init(ice);
+		synchronize_irq(pci->irq);
+	
+
+		if ((ice->res_port = request_region(ice->port, 32, "ICE1712 - Controller")) == NULL) {
+			snd_ice1712_free(ice);
+			snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->port, ice->port + 32 - 1);
+			return -EIO;
+		}
+		if ((ice->res_ddma_port = request_region(ice->ddma_port, 16, "ICE1712 - DDMA")) == NULL) {
+			snd_ice1712_free(ice);
+			snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->ddma_port, ice->ddma_port + 16 - 1);
+			return -EIO;
+		}
+		if ((ice->res_dmapath_port = request_region(ice->dmapath_port, 16, "ICE1712 - DMA path")) == NULL) {
+			snd_ice1712_free(ice);
+			snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->dmapath_port, ice->dmapath_port + 16 - 1);
+			return -EIO;
+		}
+		if ((ice->res_profi_port = request_region(ice->profi_port, 64, "ICE1712 - Professional")) == NULL) {
+			snd_ice1712_free(ice);
+			snd_printk("unable to grab ports 0x%lx-0x%lx\n", ice->profi_port, ice->profi_port + 16 - 1);
+			return -EIO;
+		}
+		if (request_irq(pci->irq, snd_ice1712_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1712", (void *) ice)) {
+			snd_ice1712_free(ice);
+			snd_printk("unable to grab IRQ %d\n", pci->irq);
+			return -EIO;
+		}
+	
+		ice->irq = pci->irq;
+
+		if (snd_ice1712_read_eeprom(ice) < 0) {
+			snd_ice1712_free(ice);
+			return -EIO;
+		}
+		if (snd_ice1712_chip_init(ice) < 0) {
+			snd_ice1712_free(ice);
+			return -EIO;
+		}
+
+		/* unmask used interrupts */
+		outb((ice->eeprom.codec & ICE1712_CFG_2xMPU401) == 0 ? ICE1712_IRQ_MPU2 : 0 |
+			 (ice->eeprom.codec & ICE1712_CFG_NO_CON_AC97) ? ICE1712_IRQ_PBKDS | ICE1712_IRQ_CONCAP | ICE1712_IRQ_CONPBK : 0,
+			 ICEREG(ice, IRQMASK));
+		outb(0x00, ICEMT(ice, IRQ));
+	}
 
 	if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
 		snd_ice1712_free(ice);
-		return err;
+ 		return err;
 	}
 
 	*r_ice1712 = ice;
@@ -2283,7 +2871,7 @@
 
 /*
  *
- * Registraton
+ * Registration
  *
  */
 
@@ -2293,6 +2881,7 @@
 	snd_ice1712_hoontech_cards,
 	snd_ice1712_delta_cards,
 	snd_ice1712_ews_cards,
+	snd_vt1724_amp_cards, 
 	0,
 };
 
@@ -2317,8 +2906,13 @@
 	if (card == NULL)
 		return -ENOMEM;
 
-	strcpy(card->driver, "ICE1712");
-	strcpy(card->shortname, "ICEnsemble ICE1712");
+	if (pci->device==PCI_DEVICE_ID_ICE_1712) {
+		strcpy(card->driver, "ICE1712");
+		strcpy(card->shortname, "ICEnsemble ICE1712");
+	} else {
+		strcpy(card->driver, "ICE1724");
+		strcpy(card->shortname, "ICEnsemble ICE1724");
+	}
 	
 	if ((err = snd_ice1712_create(card, pci, omni[dev], &ice)) < 0) {
 		snd_card_free(card);
diff -Nru a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
--- a/sound/pci/ice1712/ice1712.h	Mon Dec 23 21:21:50 2002
+++ b/sound/pci/ice1712/ice1712.h	Mon Dec 23 21:21:50 2002
@@ -248,6 +248,7 @@
 	unsigned int cif: 1;
 	unsigned char data_mask;
 	unsigned char clk_mask;
+	unsigned char caddr;		/* C0 and C1 bits */
 	unsigned char cs_mask;
 	unsigned char cs_addr;
 	unsigned char cs_none;
@@ -256,7 +257,7 @@
 	struct snd_ak4524_ops {
 		int (*start)(ice1712_t *, unsigned char *, int);
 		void (*stop)(ice1712_t *, unsigned char *);
-		void (*set_rate_val)(ice1712_t *, unsigned char);
+		void (*set_rate_val)(ice1712_t *, unsigned int);
 	} ops;
 };
 
@@ -335,7 +336,8 @@
 	snd_i2c_device_t *cs8427;	/* CS8427 I2C device */
 	snd_i2c_device_t *i2cdevs[2];	/* additional i2c devices */
 	
-	unsigned char gpio_direction, gpio_write_mask;
+	unsigned int gpio_direction, gpio_write_mask;
+	int vt1724;
 };
 
 #define chip_t ice1712_t
diff -Nru a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
--- a/sound/pci/intel8x0.c	Mon Dec 23 21:21:56 2002
+++ b/sound/pci/intel8x0.c	Mon Dec 23 21:21:57 2002
@@ -53,6 +53,7 @@
 		"{Intel,MX440},"
 		"{SiS,SI7012},"
 		"{NVidia,NForce Audio},"
+		"{NVidia,NForce2 Audio},"
 		"{AMD,AMD768},"
 		"{AMD,AMD8111},"
 	        "{ALI,M5455}}");
@@ -127,6 +128,9 @@
 #ifndef PCI_DEVICE_ID_NVIDIA_MCP_AUDIO
 #define PCI_DEVICE_ID_NVIDIA_MCP_AUDIO	0x01b1
 #endif
+#ifndef PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO
+#define PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO	0x006a
+#endif
 
 enum { DEVICE_INTEL, DEVICE_INTEL_ICH4, DEVICE_SIS, DEVICE_ALI };
 
@@ -383,6 +387,7 @@
 	{ 0x8086, 0x7195, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL },	/* 440MX */
 	{ 0x1039, 0x7012, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_SIS },	/* SI7012 */
 	{ 0x10de, 0x01b1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL },	/* NFORCE */
+	{ 0x10de, 0x006a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL },	/* NFORCE2 */
 	{ 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL },	/* AMD8111 */
 	{ 0x1022, 0x7445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL },	/* AMD768 */
 	{ 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI },   /* Ali5455 */
@@ -2298,6 +2303,7 @@
 	{ PCI_DEVICE_ID_INTEL_ICH4, "Intel 82801DB-ICH4" },
 	{ PCI_DEVICE_ID_SI_7012, "SiS SI7012" },
 	{ PCI_DEVICE_ID_NVIDIA_MCP_AUDIO, "NVidia NForce" },
+	{ PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO, "NVidia NForce2" },
 	{ 0x746d, "AMD AMD8111" },
 	{ 0x7445, "AMD AMD768" },
 	{ 0x5455, "ALi M5455" },
diff -Nru a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c
--- a/sound/pci/korg1212/korg1212.c	Mon Dec 23 21:21:50 2002
+++ b/sound/pci/korg1212/korg1212.c	Mon Dec 23 21:21:50 2002
@@ -1894,7 +1894,7 @@
         snd_iprintf(buffer, "      Irq count: %ld\n", korg1212->irqcount);
 }
 
-static void __init snd_korg1212_proc_init(korg1212_t *korg1212)
+static void __devinit snd_korg1212_proc_init(korg1212_t *korg1212)
 {
 	snd_info_entry_t *entry;
 
@@ -1920,7 +1920,7 @@
 	}
 }
 
-static int __init snd_korg1212_create(korg1212_t *korg1212)
+static int __devinit snd_korg1212_create(korg1212_t *korg1212)
 {
         struct pci_dev *pci = korg1212->pci;
         int err;
diff -Nru a/sound/pci/rme32.c b/sound/pci/rme32.c
--- a/sound/pci/rme32.c	Mon Dec 23 21:22:01 2002
+++ b/sound/pci/rme32.c	Mon Dec 23 21:22:01 2002
@@ -23,9 +23,38 @@
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  * 
  * 
- *   ToDo: full duplex (32, 32/8, 32Pro)
+ * ****************************************************************************
+ * 
+ * Note #1 "Sek'd models" ................................... martin 2002-12-07
+ * 
+ * Identical soundcards by Sek'd were labeled:
+ * RME Digi 32     = Sek'd Prodif 32
+ * RME Digi 32 Pro = Sek'd Prodif 96
+ * RME Digi 32/8   = Sek'd Prodif Gold
+ * 
+ * ****************************************************************************
+ * 
+ * Note #2 "full duplex mode" ............................... martin 2002-12-07
+ * 
+ * Full duplex doesn't work. All cards (32, 32/8, 32Pro) are working identical
+ * in this mode. Rec data and play data are using the same buffer therefore. At
+ * first you have got the playing bits in the buffer and then (after playing
+ * them) they were overwitten by the captured sound of the CS8412/14. Both 
+ * modes (play/record) are running harmonically hand in hand in the same buffer
+ * and you have only one start bit plus one interrupt bit to control this 
+ * paired action.
+ * This is opposite to the latter rme96 where playing and capturing is totally
+ * separated and so their full duplex mode is supported by alsa (using two 
+ * start bits and two interrupts for two different buffers). 
+ * But due to the wrong sequence of playing and capturing ALSA shows no solved
+ * full duplex support for the rme32 at the moment. That's bad, but I'm not
+ * able to solve it. Are you motivated enough to solve this problem now? Your
+ * patch would be welcome!
+ * 
+ * ****************************************************************************
  */
 
+
 #include <sound/driver.h>
 #include <linux/delay.h>
 #include <linux/init.h>
@@ -80,29 +109,29 @@
 #define RME32_IO_RESET_POS          0x20100
 
 /* Write control register bits */
-#define RME32_WCR_START     (1 << 0)
-#define RME32_WCR_MONO      (1 << 1)    /* 0: stereo, 1: mono
+#define RME32_WCR_START     (1 << 0)    /* startbit */
+#define RME32_WCR_MONO      (1 << 1)    /* 0=stereo, 1=mono
                                            Setting the whole card to mono
-                                           don't seems to be very useful.
+                                           doesn't seem to be very useful.
                                            A software-solution can handle 
                                            full-duplex with one direction in
                                            stereo and the other way in mono. 
                                            So, the hardware should work all 
                                            the time in stereo! */
-#define RME32_WCR_MODE24    (1 << 2)
-#define RME32_WCR_SEL       (1 << 3)
-#define RME32_WCR_FREQ_0    (1 << 4)
+#define RME32_WCR_MODE24    (1 << 2)    /* 0=16bit, 1=32bit */
+#define RME32_WCR_SEL       (1 << 3)    /* 0=input on output, 1=normal playback/capture */
+#define RME32_WCR_FREQ_0    (1 << 4)    /* frequency (play) */
 #define RME32_WCR_FREQ_1    (1 << 5)
-#define RME32_WCR_INP_0     (1 << 6)
+#define RME32_WCR_INP_0     (1 << 6)    /* input switch */
 #define RME32_WCR_INP_1     (1 << 7)
-#define RME32_WCR_RESET     (1 << 8)
-#define RME32_WCR_MUTE      (1 << 9)
-#define RME32_WCR_PRO       (1 << 10)
-#define RME32_WCR_DS_BM     (1 << 11)	/* only PRO/Adat-Version */
-#define RME32_WCR_ADAT      (1 << 12)	/* only Adat-Version */
-#define RME32_WCR_AUTOSYNC  (1 << 13)
-#define RME32_WCR_PD        (1 << 14)	/* only PRO-Version */
-#define RME32_WCR_EMP       (1 << 15)	/* only PRO-Version */
+#define RME32_WCR_RESET     (1 << 8)    /* Reset address */
+#define RME32_WCR_MUTE      (1 << 9)    /* digital mute for output */
+#define RME32_WCR_PRO       (1 << 10)   /* 1=professional, 0=consumer */
+#define RME32_WCR_DS_BM     (1 << 11)	/* 1=DoubleSpeed (only PRO-Version); 1=BlockMode (only Adat-Version) */
+#define RME32_WCR_ADAT      (1 << 12)	/* Adat Mode (only Adat-Version) */
+#define RME32_WCR_AUTOSYNC  (1 << 13)   /* AutoSync */
+#define RME32_WCR_PD        (1 << 14)	/* DAC Reset (only PRO-Version) */
+#define RME32_WCR_EMP       (1 << 15)	/* 1=Emphasis on (only PRO-Version) */
 
 #define RME32_WCR_BITPOS_FREQ_0 4
 #define RME32_WCR_BITPOS_FREQ_1 5
@@ -111,13 +140,13 @@
 
 /* Read control register bits */
 #define RME32_RCR_AUDIO_ADDR_MASK 0x10001
-#define RME32_RCR_LOCK      (1 << 23)
-#define RME32_RCR_ERF       (1 << 26)
-#define RME32_RCR_FREQ_0    (1 << 27)
+#define RME32_RCR_LOCK      (1 << 23)   /* 1=locked, 0=not locked */
+#define RME32_RCR_ERF       (1 << 26)   /* 1=Error, 0=no Error */
+#define RME32_RCR_FREQ_0    (1 << 27)   /* CS841x frequency (record) */
 #define RME32_RCR_FREQ_1    (1 << 28)
 #define RME32_RCR_FREQ_2    (1 << 29)
-#define RME32_RCR_KMODE     (1 << 30)
-#define RME32_RCR_IRQ       (1 << 31)
+#define RME32_RCR_KMODE     (1 << 30)   /* card mode: 1=PLL, 0=quartz */
+#define RME32_RCR_IRQ       (1 << 31)   /* interrupt */
 
 #define RME32_RCR_BITPOS_F0 27
 #define RME32_RCR_BITPOS_F1 28
@@ -153,12 +182,12 @@
 #ifndef PCI_DEVICE_ID_DIGI32
 # define PCI_DEVICE_ID_DIGI32 0x9896
 #endif
-#ifndef PCI_DEVICE_ID_DIGI32_8
-# define PCI_DEVICE_ID_DIGI32_8 0x9898
-#endif
 #ifndef PCI_DEVICE_ID_DIGI32_PRO
 # define PCI_DEVICE_ID_DIGI32_PRO 0x9897
 #endif
+#ifndef PCI_DEVICE_ID_DIGI32_8
+# define PCI_DEVICE_ID_DIGI32_8 0x9898
+#endif
 
 typedef struct snd_rme32 {
 	spinlock_t lock;
@@ -291,21 +320,21 @@
 			 SNDRV_PCM_INFO_MMAP_VALID |
 			 SNDRV_PCM_INFO_INTERLEAVED | 
 			 SNDRV_PCM_INFO_PAUSE),
-	formats:	(SNDRV_PCM_FMTBIT_S16_LE | 
+	.formats =	(SNDRV_PCM_FMTBIT_S16_LE | 
 			 SNDRV_PCM_FMTBIT_S32_LE),
-	rates:		(SNDRV_PCM_RATE_32000 |
+	.rates =	(SNDRV_PCM_RATE_32000 |
 			 SNDRV_PCM_RATE_44100 | 
 			 SNDRV_PCM_RATE_48000),
-	rate_min:	32000,
-	rate_max:	48000,
-	channels_min:	2,
-	channels_max:	2,
-	buffer_bytes_max: RME32_BUFFER_SIZE,
-	period_bytes_min: RME32_BLOCK_SIZE,
-	period_bytes_max: RME32_BLOCK_SIZE,
-	periods_min:	RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
-	periods_max:	RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
-	fifo_size:	0,
+	.rate_min =	32000,
+	.rate_max =	48000,
+	.channels_min =	2,
+	.channels_max =	2,
+	.buffer_bytes_max = RME32_BUFFER_SIZE,
+	.period_bytes_min = RME32_BLOCK_SIZE,
+	.period_bytes_max = RME32_BLOCK_SIZE,
+	.periods_min =	RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
+	.periods_max =	RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
+	.fifo_size =	0,
 };
 
 /*
@@ -314,20 +343,23 @@
 static snd_pcm_hardware_t snd_rme32_capture_spdif_info = {
 	.info =		(SNDRV_PCM_INFO_MMAP |
 			 SNDRV_PCM_INFO_MMAP_VALID |
-			 SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_PAUSE),
-	formats:	(SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE),
-	rates:		(SNDRV_PCM_RATE_32000 |
-			 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000),
-	rate_min:	32000,
-	rate_max:	48000,
-	channels_min:	2,
-	channels_max:	2,
-	buffer_bytes_max: RME32_BUFFER_SIZE,
-	period_bytes_min: RME32_BLOCK_SIZE,
-	period_bytes_max: RME32_BLOCK_SIZE,
-	periods_min:	RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
-	periods_max:	RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
-	fifo_size:	0,
+			 SNDRV_PCM_INFO_INTERLEAVED | 
+			 SNDRV_PCM_INFO_PAUSE),
+	.formats =	(SNDRV_PCM_FMTBIT_S16_LE | 
+			 SNDRV_PCM_FMTBIT_S32_LE),
+	.rates =	(SNDRV_PCM_RATE_32000 |
+			 SNDRV_PCM_RATE_44100 | 
+			 SNDRV_PCM_RATE_48000),
+	.rate_min =	32000,
+	.rate_max =	48000,
+	.channels_min =	2,
+	.channels_max =	2,
+	.buffer_bytes_max = RME32_BUFFER_SIZE,
+	.period_bytes_min = RME32_BLOCK_SIZE,
+	.period_bytes_max = RME32_BLOCK_SIZE,
+	.periods_min =	RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
+	.periods_max =	RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
+	.fifo_size =	0,
 };
 
 /*
@@ -339,19 +371,19 @@
 			      SNDRV_PCM_INFO_MMAP_VALID |
 			      SNDRV_PCM_INFO_INTERLEAVED |
 			      SNDRV_PCM_INFO_PAUSE),
-	formats:             SNDRV_PCM_FMTBIT_S16_LE,
-	rates:	             (SNDRV_PCM_RATE_44100 | 
+	.formats=            SNDRV_PCM_FMTBIT_S16_LE,
+	.rates =             (SNDRV_PCM_RATE_44100 | 
 			      SNDRV_PCM_RATE_48000),
-	rate_min:            44100,
-	rate_max:            48000,
-	channels_min:        8,
-	channels_max:	     8,
-	buffer_bytes_max:   RME32_BUFFER_SIZE,
-	period_bytes_min:   RME32_BLOCK_SIZE,
-	period_bytes_max:   RME32_BLOCK_SIZE,
-	periods_min:	     RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
-	periods_max:	     RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
-	fifo_size:	     0,
+	.rate_min =          44100,
+	.rate_max =          48000,
+	.channels_min =      8,
+	.channels_max =	     8,
+	.buffer_bytes_max =  RME32_BUFFER_SIZE,
+	.period_bytes_min =  RME32_BLOCK_SIZE,
+	.period_bytes_max =  RME32_BLOCK_SIZE,
+	.periods_min =	    RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
+	.periods_max =	    RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
+	.fifo_size =	    0,
 };
 
 /*
@@ -363,19 +395,19 @@
 			      SNDRV_PCM_INFO_MMAP_VALID |
 			      SNDRV_PCM_INFO_INTERLEAVED |
 			      SNDRV_PCM_INFO_PAUSE),
-	formats:             SNDRV_PCM_FMTBIT_S16_LE,
-	rates:	             (SNDRV_PCM_RATE_44100 | 
+	.formats =           SNDRV_PCM_FMTBIT_S16_LE,
+	.rates =             (SNDRV_PCM_RATE_44100 | 
 			      SNDRV_PCM_RATE_48000),
-	rate_min:            44100,
-	rate_max:            48000,
-	channels_min:        8,
-	channels_max:	     8,
-	buffer_bytes_max:   RME32_BUFFER_SIZE,
-	period_bytes_min:   RME32_BLOCK_SIZE,
-	period_bytes_max:   RME32_BLOCK_SIZE,
-	periods_min:	     RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
-	periods_max:	     RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
-	fifo_size:           0,
+	.rate_min =          44100,
+	.rate_max =          48000,
+	.channels_min =	     8,
+	.channels_max =	     8,
+	.buffer_bytes_max =  RME32_BUFFER_SIZE,
+	.period_bytes_min =  RME32_BLOCK_SIZE,
+	.period_bytes_max =  RME32_BLOCK_SIZE,
+	.periods_min =	     RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
+	.periods_max =	     RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
+	.fifo_size =         0,
 };
 
 static void snd_rme32_reset_dac(rme32_t *rme32)
diff -Nru a/sound/pci/rme96.c b/sound/pci/rme96.c
--- a/sound/pci/rme96.c	Mon Dec 23 21:21:53 2002
+++ b/sound/pci/rme96.c	Mon Dec 23 21:21:53 2002
@@ -305,7 +305,7 @@
 static snd_pcm_uframes_t
 snd_rme96_capture_pointer(snd_pcm_substream_t *substream);
 
-static void __init 
+static void __devinit 
 snd_rme96_proc_init(rme96_t *rme96);
 
 static void
@@ -1589,7 +1589,7 @@
 	snd_pcm_lib_preallocate_free_for_all(pcm);
 }
 
-static int __init
+static int __devinit
 snd_rme96_create(rme96_t *rme96)
 {
 	struct pci_dev *pci = rme96->pci;
@@ -1838,7 +1838,7 @@
 	}
 }
 
-static void __init 
+static void __devinit 
 snd_rme96_proc_init(rme96_t *rme96)
 {
 	snd_info_entry_t *entry;
diff -Nru a/sound/pci/rme9652/hammerfall_mem.c b/sound/pci/rme9652/hammerfall_mem.c
--- a/sound/pci/rme9652/hammerfall_mem.c	Mon Dec 23 21:21:51 2002
+++ b/sound/pci/rme9652/hammerfall_mem.c	Mon Dec 23 21:21:51 2002
@@ -178,7 +178,7 @@
 	printk ("Hammerfall memory allocator: unknown buffer address or PCI device ID");
 }
 
-static void hammerfall_free_buffers (void)
+static void __exit hammerfall_free_buffers (void)
 
 {
 	int i;
diff -Nru a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
--- a/sound/pci/rme9652/hdsp.c	Mon Dec 23 21:21:53 2002
+++ b/sound/pci/rme9652/hdsp.c	Mon Dec 23 21:21:53 2002
@@ -2,6 +2,7 @@
  *   ALSA driver for RME Hammerfall DSP audio interface(s)
  *
  *      Copyright (c) 2002  Paul Davis
+ *                          Marcus Andersson
  *
  *   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
@@ -81,7 +82,7 @@
 #define DIGIFACE_SS_CHANNELS     26
 #define DIGIFACE_DS_CHANNELS     14
 #define MULTIFACE_SS_CHANNELS    18
-#define MULTIFACE_DS_CHANNELS    10
+#define MULTIFACE_DS_CHANNELS    14
 
 /* Write registers. These are defined as byte-offsets from the iobase value.
  */
@@ -687,6 +688,7 @@
 		rate = HDSP_Frequency96KHz;
 		break;
 	default:
+		spin_unlock_irq(&hdsp->lock);
 		return -EINVAL;
 	}
 
@@ -747,10 +749,12 @@
 
 		mapped_channel = hdsp->channel_map[channel];
 
+		snd_assert(mapped_channel > -1, return);
+
 		if (enable) {
-			hdsp_write_gain (hdsp, INPUT_TO_OUTPUT_KEY(channel,channel), UNITY_GAIN);
+			hdsp_write_gain (hdsp, INPUT_TO_OUTPUT_KEY(mapped_channel,mapped_channel), UNITY_GAIN);
 		} else {
-			hdsp_write_gain (hdsp, INPUT_TO_OUTPUT_KEY(channel,channel), MINUS_INFINITY_GAIN);
+			hdsp_write_gain (hdsp, INPUT_TO_OUTPUT_KEY(mapped_channel,mapped_channel), MINUS_INFINITY_GAIN);
 		}
 	}
 }
@@ -1605,10 +1609,18 @@
 	hdsp_t *hdsp = _snd_kcontrol_chip(kcontrol);
 	unsigned long flags;
 	int addr;
-	int chn;
+	int channel;
+	int mapped_channel;
+
+	channel = ucontrol->id.index - 1;
+
+        snd_assert(channel >= 0 || channel < HDSP_MAX_CHANNELS, return -EINVAL);
+        
+	if ((mapped_channel = hdsp->channel_map[channel]) < 0) {
+		return -EINVAL;
+	}
 
-	chn = ucontrol->id.index - 1;
-	addr = PLAYBACK_TO_OUTPUT_KEY(chn, chn);
+	addr = PLAYBACK_TO_OUTPUT_KEY(mapped_channel, mapped_channel);
 
 	spin_lock_irqsave(&hdsp->lock, flags);
 	ucontrol->value.integer.value[0] = hdsp_read_gain (hdsp, addr);
@@ -1622,14 +1634,22 @@
 	unsigned long flags;
 	int change;
 	int addr;
-	int chn;
+	int channel;
+	int mapped_channel;
 	int gain;
 
 	if (!snd_hdsp_use_is_exclusive(hdsp))
 		return -EBUSY;
 	
-	chn = ucontrol->id.index - 1;
-	addr = PLAYBACK_TO_OUTPUT_KEY(chn, chn);
+	channel = ucontrol->id.index - 1;
+
+        snd_assert(channel >= 0 || channel < HDSP_MAX_CHANNELS, return -EINVAL);
+        
+	if ((mapped_channel = hdsp->channel_map[channel]) < 0) {
+		return -EINVAL;
+	}
+
+	addr = PLAYBACK_TO_OUTPUT_KEY(mapped_channel, mapped_channel);
 	gain = ucontrol->value.integer.value[0];
 
 
@@ -2434,15 +2454,15 @@
 				    snd_pcm_channel_info_t *info)
 {
 	hdsp_t *hdsp = _snd_pcm_substream_chip(substream);
-	int chn;
+	int mapped_channel;
 
 	snd_assert(info->channel < HDSP_MAX_CHANNELS, return -EINVAL);
 
-	if ((chn = hdsp->channel_map[info->channel]) < 0) {
+	if ((mapped_channel = hdsp->channel_map[info->channel]) < 0) {
 		return -EINVAL;
 	}
 
-	info->offset = chn * HDSP_CHANNEL_BUFFER_BYTES;
+	info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES;
 	info->first = 0;
 	info->step = 32;
 	return 0;
@@ -2567,7 +2587,7 @@
 				 SNDRV_PCM_RATE_96000),
 	.rate_min =		32000,
 	.rate_max =		96000,
-	.channels_min =		10,
+	.channels_min =		14,
 	.channels_max =		HDSP_MAX_CHANNELS,
 	.buffer_bytes_max =	1024*1024,
 	.period_bytes_min =	1,
@@ -2592,7 +2612,7 @@
 				 SNDRV_PCM_RATE_96000),
 	.rate_min =		32000,
 	.rate_max =		96000,
-	.channels_min =		10,
+	.channels_min =		14,
 	.channels_max =		HDSP_MAX_CHANNELS,
 	.buffer_bytes_max =	1024*1024,
 	.period_bytes_min =	1,
@@ -2902,11 +2922,15 @@
 			}
 		}
 		
-		if (hdsp_fifo_wait (hdsp, 3, HDSP_LONG_WAIT)) {
+		if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
 			snd_printk ("timeout at end of firmware loading\n");
 			return -EIO;
 		}
 
+		hdsp_write (hdsp, HDSP_jtagReg, 0);
+		snd_printk ("finished firmware loading\n");
+		mdelay(3000);
+
 	} else {
 
 		/* firmware already loaded, but we need to know what type
@@ -3045,9 +3069,11 @@
 
 static int snd_hdsp_free(hdsp_t *hdsp)
 {
-	/* stop the audio, and cancel all interrupts */
-	hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
-	hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
+	if (hdsp->res_port) {
+		/* stop the audio, and cancel all interrupts */
+		hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
+		hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
+	}
 
 	if (hdsp->irq >= 0)
 		free_irq(hdsp->irq, (void *)hdsp);
diff -Nru a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c
--- a/sound/pci/rme9652/rme9652.c	Mon Dec 23 21:21:54 2002
+++ b/sound/pci/rme9652/rme9652.c	Mon Dec 23 21:21:54 2002
@@ -1799,7 +1799,7 @@
 	snd_iprintf(buffer, "\n");
 }
 
-static void __init snd_rme9652_proc_init(rme9652_t *rme9652)
+static void __devinit snd_rme9652_proc_init(rme9652_t *rme9652)
 {
 	snd_info_entry_t *entry;
 
@@ -1869,7 +1869,7 @@
 	return 0;
 }
 
-static int __init snd_rme9652_initialize_memory(rme9652_t *rme9652)
+static int __devinit snd_rme9652_initialize_memory(rme9652_t *rme9652)
 {
 	void *pb, *cb;
 	dma_addr_t pb_addr, cb_addr;
@@ -2523,7 +2523,7 @@
 	.copy =		snd_rme9652_capture_copy,
 };
 
-static int __init snd_rme9652_create_pcm(snd_card_t *card,
+static int __devinit snd_rme9652_create_pcm(snd_card_t *card,
 					 rme9652_t *rme9652)
 {
 	snd_pcm_t *pcm;
@@ -2547,7 +2547,7 @@
 	return 0;
 }
 
-static int __init snd_rme9652_create(snd_card_t *card,
+static int __devinit snd_rme9652_create(snd_card_t *card,
 				     rme9652_t *rme9652,
 				     int precise_ptr)
 {
diff -Nru a/sound/pci/trident/trident.c b/sound/pci/trident/trident.c
--- a/sound/pci/trident/trident.c	Mon Dec 23 21:21:50 2002
+++ b/sound/pci/trident/trident.c	Mon Dec 23 21:21:50 2002
@@ -85,7 +85,7 @@
 	snd_card_t *card;
 	trident_t *trident;
 	const char *str;
-	int err;
+	int err, pcm_dev = 0;
 
 	if (dev >= SNDRV_CARDS)
 		return -ENODEV;
@@ -106,21 +106,21 @@
 		snd_card_free(card);
 		return err;
 	}
-	if ((err = snd_trident_pcm(trident, 0, NULL)) < 0) {
+	if ((err = snd_trident_pcm(trident, pcm_dev++, NULL)) < 0) {
 		snd_card_free(card);
 		return err;
 	}
 	switch (trident->device) {
 	case TRIDENT_DEVICE_ID_DX:
 	case TRIDENT_DEVICE_ID_NX:
-		if ((err = snd_trident_foldback_pcm(trident, 1, NULL)) < 0) {
+		if ((err = snd_trident_foldback_pcm(trident, pcm_dev++, NULL)) < 0) {
 			snd_card_free(card);
 			return err;
 		}
 		break;
 	}
-	if (trident->device == TRIDENT_DEVICE_ID_NX) {
-		if ((err = snd_trident_spdif_pcm(trident, 2, NULL)) < 0) {
+	if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018) {
+		if ((err = snd_trident_spdif_pcm(trident, pcm_dev++, NULL)) < 0) {
 			snd_card_free(card);
 			return err;
 		}
diff -Nru a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c
--- a/sound/pci/trident/trident_main.c	Mon Dec 23 21:21:57 2002
+++ b/sound/pci/trident/trident_main.c	Mon Dec 23 21:21:57 2002
@@ -23,6 +23,8 @@
  *   along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  *
+ *
+ *  SiS7018 S/PDIF support by Thomas Winischhofer <thomas@winischhofer.net>
  */
 
 #include <sound/driver.h>
@@ -52,6 +54,7 @@
 #ifdef CONFIG_PM
 static int snd_trident_set_power_state(snd_card_t *card, unsigned int power_state);
 #endif
+static int snd_trident_sis_reset(trident_t *trident);
 
 /*
  *  common I/O routines
@@ -149,7 +152,7 @@
 		} while (--count);
 	}
 
-	if (count == 0) {
+	if (count == 0 && !trident->ac97_detect) {
 		snd_printk("ac97 codec read TIMEOUT [0x%x/0x%x]!!!\n", reg, data);
 		data = 0;
 	}
@@ -477,6 +480,15 @@
 	outl(regs[2], TRID_REG(trident, CH_START + 8));
 	outl(regs[3], TRID_REG(trident, CH_START + 12));
 	outl(regs[4], TRID_REG(trident, CH_START + 16));
+
+#if 0
+	printk("written %i channel:\n", voice->number);
+	printk("  regs[0] = 0x%x/0x%x\n", regs[0], inl(TRID_REG(trident, CH_START + 0)));
+	printk("  regs[1] = 0x%x/0x%x\n", regs[1], inl(TRID_REG(trident, CH_START + 4)));
+	printk("  regs[2] = 0x%x/0x%x\n", regs[2], inl(TRID_REG(trident, CH_START + 8)));
+	printk("  regs[3] = 0x%x/0x%x\n", regs[3], inl(TRID_REG(trident, CH_START + 12)));
+	printk("  regs[4] = 0x%x/0x%x\n", regs[4], inl(TRID_REG(trident, CH_START + 16)));
+#endif
 }
 
 /*---------------------------------------------------------------------------
@@ -727,9 +739,9 @@
 }
 
 /*---------------------------------------------------------------------------
-   snd_trident_playback_hw_params
+   snd_trident_allocate_pcm_mem
   
-   Description: Set the hardware parameters for the playback device.
+   Description: Allocate PCM ring buffer for given substream
   
    Parameters:  substream  - PCM substream class
 		hw_params  - hardware parameters
@@ -738,14 +750,12 @@
   
   ---------------------------------------------------------------------------*/
 
-static int snd_trident_playback_hw_params(snd_pcm_substream_t * substream,
-					  snd_pcm_hw_params_t * hw_params)
+int snd_trident_allocate_pcm_mem(snd_pcm_substream_t * substream,
+				 snd_pcm_hw_params_t * hw_params)
 {
 	trident_t *trident = snd_pcm_substream_chip(substream);
 	snd_pcm_runtime_t *runtime = substream->runtime;
 	snd_trident_voice_t *voice = (snd_trident_voice_t *) runtime->private_data;
-	snd_trident_voice_t *evoice = voice->extra;
-	unsigned long flags;
 	int err;
 
 	if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
@@ -753,16 +763,38 @@
 	if (err > 0 && trident->tlb.entries) {
 		if (voice->memblk)
 			snd_trident_free_pages(trident, voice->memblk);
-		spin_lock_irqsave(&trident->reg_lock, flags);
+		spin_lock_irq(&trident->reg_lock);
 		voice->memblk = snd_trident_alloc_pages(trident, runtime->dma_area, runtime->dma_addr, runtime->dma_bytes);
-		spin_unlock_irqrestore(&trident->reg_lock, flags);
+		spin_unlock_irq(&trident->reg_lock);
 		if (voice->memblk == NULL)
 			return -ENOMEM;
 	}
+	return 0;
+}
+
+/*---------------------------------------------------------------------------
+   snd_trident_allocate_evoice
+  
+   Description: Allocate extra voice as interrupt generator
+  
+   Parameters:  substream  - PCM substream class
+		hw_params  - hardware parameters
+  
+   Returns:     Error status
+  
+  ---------------------------------------------------------------------------*/
+
+int snd_trident_allocate_evoice(snd_pcm_substream_t * substream,
+				snd_pcm_hw_params_t * hw_params)
+{
+	trident_t *trident = snd_pcm_substream_chip(substream);
+	snd_pcm_runtime_t *runtime = substream->runtime;
+	snd_trident_voice_t *voice = (snd_trident_voice_t *) runtime->private_data;
+	snd_trident_voice_t *evoice = voice->extra;
 
 	/* voice management */
 
-	if (params_buffer_size(hw_params) / 2 != params_period_size(hw_params)) {
+	if (params_buffer_size(hw_params) / 2 != params_buffer_size(hw_params)) {
 		if (evoice == NULL) {
 			evoice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0);
 			if (evoice == NULL)
@@ -781,6 +813,29 @@
 }
 
 /*---------------------------------------------------------------------------
+   snd_trident_hw_params
+  
+   Description: Set the hardware parameters for the playback device.
+  
+   Parameters:  substream  - PCM substream class
+		hw_params  - hardware parameters
+  
+   Returns:     Error status
+  
+  ---------------------------------------------------------------------------*/
+
+static int snd_trident_hw_params(snd_pcm_substream_t * substream,
+				 snd_pcm_hw_params_t * hw_params)
+{
+	int err;
+
+	err = snd_trident_allocate_pcm_mem(substream, hw_params);
+	if (err >= 0)
+		err = snd_trident_allocate_evoice(substream, hw_params);
+	return err;
+}
+
+/*---------------------------------------------------------------------------
    snd_trident_playback_hw_free
   
    Description: Release the hardware resources for the playback device.
@@ -791,7 +846,7 @@
   
   ---------------------------------------------------------------------------*/
 
-static int snd_trident_playback_hw_free(snd_pcm_substream_t * substream)
+static int snd_trident_hw_free(snd_pcm_substream_t * substream)
 {
 	trident_t *trident = snd_pcm_substream_chip(substream);
 	snd_pcm_runtime_t *runtime = substream->runtime;
@@ -828,9 +883,8 @@
 	snd_trident_voice_t *voice = (snd_trident_voice_t *) runtime->private_data;
 	snd_trident_voice_t *evoice = voice->extra;
 	snd_trident_pcm_mixer_t *mix = &trident->pcm_mixer[substream->number];
-	unsigned long flags;
 
-	spin_lock_irqsave(&trident->reg_lock, flags);	
+	spin_lock(&trident->reg_lock);	
 
 	/* set delta (rate) value */
 	voice->Delta = snd_trident_convert_rate(runtime->rate);
@@ -855,6 +909,12 @@
 	voice->CVol = mix->cvol;
 	voice->Pan = mix->pan;
 	voice->Attribute = 0;
+#if 0
+	voice->Attribute = (1<<(30-16))|(2<<(26-16))|
+			   (0<<(24-16))|(0x1f<<(19-16));
+#else
+	voice->Attribute = 0;
+#endif
 
 	snd_trident_write_voice_regs(trident, voice);
 
@@ -875,14 +935,14 @@
 		evoice->Pan = 0x7f;			/* mute */
 #if 0
 		evoice->Attribute = (1<<(30-16))|(2<<(26-16))|
-				    (1<<(24-16))|(0x1f<<(19-16));
+				    (0<<(24-16))|(0x1f<<(19-16));
 #else
 		evoice->Attribute = 0;
 #endif
 		snd_trident_write_voice_regs(trident, evoice);
 	}
 
-	spin_unlock_irqrestore(&trident->reg_lock, flags);
+	spin_unlock(&trident->reg_lock);
 
 	return 0;
 }
@@ -902,49 +962,7 @@
 static int snd_trident_capture_hw_params(snd_pcm_substream_t * substream,
 					 snd_pcm_hw_params_t * hw_params)
 {
-	trident_t *trident = snd_pcm_substream_chip(substream);
-	snd_pcm_runtime_t *runtime = substream->runtime;
-	snd_trident_voice_t *voice = (snd_trident_voice_t *) runtime->private_data;
-	unsigned long flags;
-	int err;
-
-	if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
-		return err;
-	if (err > 0 && trident->tlb.entries) {
-		if (voice->memblk)
-			snd_trident_free_pages(trident, voice->memblk);
-		spin_lock_irqsave(&trident->reg_lock, flags);
-		voice->memblk = snd_trident_alloc_pages(trident, runtime->dma_area, runtime->dma_addr, runtime->dma_bytes);
-		spin_unlock_irqrestore(&trident->reg_lock, flags);
-		if (voice->memblk == NULL)
-			return -ENOMEM;
-	}
-	return 0;
-}
-
-/*---------------------------------------------------------------------------
-   snd_trident_capture_hw_free
-  
-   Description: Release the hardware resources for the capture device.
-  
-   Parameters:  substream  - PCM substream class
-  
-   Returns:     Error status
-  
-  ---------------------------------------------------------------------------*/
-
-static int snd_trident_capture_hw_free(snd_pcm_substream_t * substream)
-{
-	trident_t *trident = snd_pcm_substream_chip(substream);
-	snd_pcm_runtime_t *runtime = substream->runtime;
-	snd_trident_voice_t *voice = (snd_trident_voice_t *) runtime->private_data;
-
-	if (trident->tlb.entries && voice && voice->memblk) {
-		snd_trident_free_pages(trident, voice->memblk);
-		voice->memblk = NULL;
-	}
-	snd_pcm_lib_free_pages(substream);
-	return 0;
+	return snd_trident_allocate_pcm_mem(substream, hw_params);
 }
 
 /*---------------------------------------------------------------------------
@@ -964,9 +982,8 @@
 	snd_pcm_runtime_t *runtime = substream->runtime;
 	snd_trident_voice_t *voice = (snd_trident_voice_t *) runtime->private_data;
 	unsigned int val, ESO_bytes;
-	unsigned long flags;
 
-	spin_lock_irqsave(&trident->reg_lock, flags);
+	spin_lock(&trident->reg_lock);
 
 	// Initilize the channel and set channel Mode
 	outb(0, TRID_REG(trident, LEGACY_DMAR15));
@@ -1037,7 +1054,7 @@
 
 	snd_trident_write_voice_regs(trident, voice);
 
-	spin_unlock_irqrestore(&trident->reg_lock, flags);
+	spin_unlock(&trident->reg_lock);
 	return 0;
 }
 
@@ -1056,33 +1073,12 @@
 static int snd_trident_si7018_capture_hw_params(snd_pcm_substream_t * substream,
 						snd_pcm_hw_params_t * hw_params)
 {
-	trident_t *trident = snd_pcm_substream_chip(substream);
-	snd_pcm_runtime_t *runtime = substream->runtime;
-	snd_trident_voice_t *voice = (snd_trident_voice_t *) runtime->private_data;
-	snd_trident_voice_t *evoice = voice->extra;
 	int err;
 
 	if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
 		return err;
 
-	/* voice management */
-
-	if (params_buffer_size(hw_params) / 2 != params_period_size(hw_params)) {
-		if (evoice == NULL) {
-			evoice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0);
-			if (evoice == NULL)
-				return -ENOMEM;
-			voice->extra = evoice;
-			evoice->substream = substream;
-		}
-	} else {
-		if (evoice != NULL) {
-			snd_trident_free_voice(trident, evoice);
-			voice->extra = evoice = NULL;
-		}
-	}
-
-	return 0;
+	return snd_trident_allocate_evoice(substream, hw_params);
 }
 
 /*---------------------------------------------------------------------------
@@ -1128,9 +1124,8 @@
 	snd_pcm_runtime_t *runtime = substream->runtime;
 	snd_trident_voice_t *voice = (snd_trident_voice_t *) runtime->private_data;
 	snd_trident_voice_t *evoice = voice->extra;
-	unsigned long flags;
 
-	spin_lock_irqsave(&trident->reg_lock, flags);
+	spin_lock(&trident->reg_lock);
 
 	voice->LBA = runtime->dma_addr;
 	voice->Delta = snd_trident_convert_adc_rate(runtime->rate);
@@ -1176,91 +1171,7 @@
 		snd_trident_write_voice_regs(trident, evoice);
 	}
 	
-	spin_unlock_irqrestore(&trident->reg_lock, flags);
-	return 0;
-}
-
-/*---------------------------------------------------------------------------
-   snd_trident_foldback_hw_params
-  
-   Description: Set the hardware parameters for the foldback device.
-  
-   Parameters:  substream  - PCM substream class
-		hw_params  - hardware parameters
-  
-   Returns:     Error status
-  
-  ---------------------------------------------------------------------------*/
-
-static int snd_trident_foldback_hw_params(snd_pcm_substream_t * substream,
-					  snd_pcm_hw_params_t * hw_params)
-{
-	trident_t *trident = snd_pcm_substream_chip(substream);
-	snd_pcm_runtime_t *runtime = substream->runtime;
-	snd_trident_voice_t *voice = (snd_trident_voice_t *) runtime->private_data;
-	snd_trident_voice_t *evoice = voice->extra;
-	unsigned long flags;
-	int err;
-
-	if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
-		return err;
-	if (err > 0 && trident->tlb.entries) {
-		if (voice->memblk)
-			snd_trident_free_pages(trident, voice->memblk);
-		spin_lock_irqsave(&trident->reg_lock, flags);
-		voice->memblk = snd_trident_alloc_pages(trident, runtime->dma_area, runtime->dma_addr, runtime->dma_bytes);
-		spin_unlock_irqrestore(&trident->reg_lock, flags);
-		if (voice->memblk == NULL)
-			return -ENOMEM;
-	}
-
-	/* voice management */
-
-	if (params_buffer_size(hw_params) / 2 != params_buffer_size(hw_params)) {
-		if (evoice == NULL) {
-			evoice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0);
-			if (evoice == NULL)
-				return -ENOMEM;
-			voice->extra = evoice;
-			evoice->substream = substream;
-		}
-	} else {
-		if (evoice != NULL) {
-			snd_trident_free_voice(trident, evoice);
-			voice->extra = evoice = NULL;
-		}
-	}
-
-	return 0;
-}
-
-/*---------------------------------------------------------------------------
-   snd_trident_foldback_hw_free
-  
-   Description: Release the hardware resources for the foldback device.
-  
-   Parameters:  substream  - PCM substream class
-  
-   Returns:     Error status
-  
-  ---------------------------------------------------------------------------*/
-
-static int snd_trident_foldback_hw_free(snd_pcm_substream_t * substream)
-{
-	trident_t *trident = snd_pcm_substream_chip(substream);
-	snd_pcm_runtime_t *runtime = substream->runtime;
-	snd_trident_voice_t *voice = (snd_trident_voice_t *) runtime->private_data;
-	snd_trident_voice_t *evoice = voice ? voice->extra : NULL;
-
-	if (trident->tlb.entries && voice && voice->memblk) {
-		snd_trident_free_pages(trident, voice->memblk);
-		voice->memblk = NULL;
-	}
-	snd_pcm_lib_free_pages(substream);
-	if (evoice != NULL) {
-		snd_trident_free_voice(trident, evoice);
-		voice->extra = NULL;
-	}
+	spin_unlock(&trident->reg_lock);
 	return 0;
 }
 
@@ -1281,9 +1192,8 @@
 	snd_pcm_runtime_t *runtime = substream->runtime;
 	snd_trident_voice_t *voice = (snd_trident_voice_t *) runtime->private_data;
 	snd_trident_voice_t *evoice = voice->extra;
-	unsigned long flags;
 
-	spin_lock_irqsave(&trident->reg_lock, flags);
+	spin_lock(&trident->reg_lock);
 
 	/* Set channel buffer Address */
 	if (voice->memblk)
@@ -1335,7 +1245,7 @@
 		snd_trident_write_voice_regs(trident, evoice);
 	}
 
-	spin_unlock_irqrestore(&trident->reg_lock, flags);
+	spin_unlock(&trident->reg_lock);
 	return 0;
 }
 
@@ -1355,26 +1265,21 @@
 				       snd_pcm_hw_params_t * hw_params)
 {
 	trident_t *trident = snd_pcm_substream_chip(substream);
-	snd_pcm_runtime_t *runtime = substream->runtime;
-	snd_trident_voice_t *voice = (snd_trident_voice_t *) runtime->private_data;
-	unsigned long flags;
 	unsigned int old_bits = 0, change = 0;
 	int err;
 
-	if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
+	err = snd_trident_allocate_pcm_mem(substream, hw_params);
+	if (err < 0)
 		return err;
-	if (err > 0 && trident->tlb.entries) {
-		if (voice->memblk)
-			snd_trident_free_pages(trident, voice->memblk);
-		spin_lock_irqsave(&trident->reg_lock, flags);
-		voice->memblk = snd_trident_alloc_pages(trident, runtime->dma_area, runtime->dma_addr, runtime->dma_bytes);
-		spin_unlock_irqrestore(&trident->reg_lock, flags);
-		if (voice->memblk == NULL)
-			return -ENOMEM;
+
+	if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
+		err = snd_trident_allocate_evoice(substream, hw_params);
+		if (err < 0)
+			return err;
 	}
 
 	/* prepare SPDIF channel */
-	spin_lock_irqsave(&trident->reg_lock, flags);
+	spin_lock_irq(&trident->reg_lock);
 	old_bits = trident->spdif_pcm_bits;
 	if (old_bits & IEC958_AES0_PROFESSIONAL)
 		trident->spdif_pcm_bits &= ~IEC958_AES0_PRO_FS;
@@ -1402,7 +1307,7 @@
 				(IEC958_AES3_CON_FS_32000 << 24);
 	}
 	change = old_bits != trident->spdif_pcm_bits;
-	spin_unlock_irqrestore(&trident->reg_lock, flags);
+	spin_unlock_irq(&trident->reg_lock);
 
 	if (change)
 		snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE, &trident->spdif_pcm_ctl->id);
@@ -1411,31 +1316,6 @@
 }
 
 /*---------------------------------------------------------------------------
-   snd_trident_spdif_hw_free
-  
-   Description: Release the hardware resources for the spdif device.
-  
-   Parameters:  substream  - PCM substream class
-  
-   Returns:     Error status
-  
-  ---------------------------------------------------------------------------*/
-
-static int snd_trident_spdif_hw_free(snd_pcm_substream_t * substream)
-{
-	trident_t *trident = snd_pcm_substream_chip(substream);
-	snd_pcm_runtime_t *runtime = substream->runtime;
-	snd_trident_voice_t *voice = (snd_trident_voice_t *) runtime->private_data;
-
-	if (trident->tlb.entries && voice && voice->memblk) {
-		snd_trident_free_pages(trident, voice->memblk);
-		voice->memblk = NULL;
-	}
-	snd_pcm_lib_free_pages(substream);
-	return 0;
-}
-
-/*---------------------------------------------------------------------------
    snd_trident_spdif_prepare
   
    Description: Prepare SPDIF device for playback.
@@ -1451,55 +1331,116 @@
 	trident_t *trident = snd_pcm_substream_chip(substream);
 	snd_pcm_runtime_t *runtime = substream->runtime;
 	snd_trident_voice_t *voice = (snd_trident_voice_t *) runtime->private_data;
+	snd_trident_voice_t *evoice = voice->extra;
+	snd_trident_pcm_mixer_t *mix = &trident->pcm_mixer[substream->number];
 	unsigned int RESO, LBAO;
-	unsigned long flags;
+	unsigned int temp;
 
-	spin_lock_irqsave(&trident->reg_lock, flags);	
+	spin_lock(&trident->reg_lock);
 
-	/* set delta (rate) value */
-	voice->Delta = snd_trident_convert_rate(runtime->rate);
-	voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size);
+	if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
 
-	/* set Loop Back Address */
-	LBAO = runtime->dma_addr;
-	if (voice->memblk)
-		voice->LBA = voice->memblk->offset;
-	else
-		voice->LBA = LBAO;
+		/* set delta (rate) value */
+		voice->Delta = snd_trident_convert_rate(runtime->rate);
+		voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size);
 
-	/* set target ESO for channel */
-	RESO = runtime->buffer_size - 1;
-	voice->ESO = (runtime->period_size * 2) - 1;
+		/* set Loop Back Address */
+		LBAO = runtime->dma_addr;
+		if (voice->memblk)
+			voice->LBA = voice->memblk->offset;
+		else
+			voice->LBA = LBAO;
+
+		/* set target ESO for channel */
+		RESO = runtime->buffer_size - 1;
+		voice->ESO = (runtime->period_size * 2) - 1;
+
+		/* set ctrl mode */
+		voice->CTRL = snd_trident_control_mode(substream);
+
+		voice->FMC = 3;
+		voice->RVol = 0x7f;
+		voice->CVol = 0x7f;
+		voice->GVSel = 1;
+		voice->Pan = 0x7f;
+		voice->Vol = 0x3ff;
+		voice->EC = 0;
+		voice->CSO = 0;
+		voice->Alpha = 0;
+		voice->FMS = 0;
+		voice->Attribute = 0;
+
+		/* prepare surrogate IRQ channel */
+		snd_trident_write_voice_regs(trident, voice);
+
+		outw((RESO & 0xffff), TRID_REG(trident, NX_SPESO));
+		outb((RESO >> 16), TRID_REG(trident, NX_SPESO + 2));
+		outl((LBAO & 0xfffffffc), TRID_REG(trident, NX_SPLBA));
+		outw((voice->CSO & 0xffff), TRID_REG(trident, NX_SPCTRL_SPCSO));
+		outb((voice->CSO >> 16), TRID_REG(trident, NX_SPCTRL_SPCSO + 2));
 
-	/* set ctrl mode */
-	voice->CTRL = snd_trident_control_mode(substream);
+		/* set SPDIF setting */
+		outb(trident->spdif_pcm_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
+		outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS));
 
-	voice->FMC = 3;
-	voice->RVol = 0x7f;
-	voice->CVol = 0x7f;
-	voice->GVSel = 1;
-	voice->Pan = 0x7f;
-	voice->Vol = 0x3ff;
-	voice->EC = 0;
-	voice->CSO = 0;
-	voice->Alpha = 0;
-	voice->FMS = 0;
-	voice->Attribute = 0;
+	} else {	/* SiS */
+	
+		/* set delta (rate) value */
+		voice->Delta = 0x800;
+		voice->spurious_threshold = snd_trident_spurious_threshold(48000, runtime->period_size);
 
-	/* prepare surrogate IRQ channel */
-	snd_trident_write_voice_regs(trident, voice);
+		/* set Loop Begin Address */
+		if (voice->memblk)
+			voice->LBA = voice->memblk->offset;
+		else
+			voice->LBA = runtime->dma_addr;
+
+		voice->CSO = 0;
+		voice->ESO = runtime->buffer_size - 1;	/* in samples */
+		voice->CTRL = snd_trident_control_mode(substream);
+		voice->FMC = 3;
+		voice->GVSel = 1;
+		voice->EC = 0;
+		voice->Alpha = 0;
+		voice->FMS = 0;
+		voice->Vol = mix->vol;
+		voice->RVol = mix->rvol;
+		voice->CVol = mix->cvol;
+		voice->Pan = mix->pan;
+		voice->Attribute = (1<<(30-16))|(7<<(26-16))|
+				   (0<<(24-16))|(0<<(19-16));
 
-	outw((RESO & 0xffff), TRID_REG(trident, NX_SPESO));
-	outb((RESO >> 16), TRID_REG(trident, NX_SPESO + 2));
-	outl((LBAO & 0xfffffffc), TRID_REG(trident, NX_SPLBA));
-	outw((voice->CSO & 0xffff), TRID_REG(trident, NX_SPCTRL_SPCSO));
-	outb((voice->CSO >> 16), TRID_REG(trident, NX_SPCTRL_SPCSO + 2));
-
-	/* set SPDIF setting */
-	outb(trident->spdif_pcm_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
-	outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS));
+		snd_trident_write_voice_regs(trident, voice);
 
-	spin_unlock_irqrestore(&trident->reg_lock, flags);
+		if (evoice != NULL) {
+			evoice->Delta = voice->Delta;
+			evoice->spurious_threshold = voice->spurious_threshold;
+			evoice->LBA = voice->LBA;
+			evoice->CSO = 0;
+			evoice->ESO = (runtime->period_size * 2) - 1; /* in samples */
+			evoice->CTRL = voice->CTRL;
+			evoice->FMC = 3;
+			evoice->GVSel = trident->device == TRIDENT_DEVICE_ID_SI7018 ? 0 : 1;
+			evoice->EC = 0;
+			evoice->Alpha = 0;
+			evoice->FMS = 0;
+			evoice->Vol = 0x3ff;			/* mute */
+			evoice->RVol = evoice->CVol = 0x7f;	/* mute */
+			evoice->Pan = 0x7f;			/* mute */
+			evoice->Attribute = 0;
+			snd_trident_write_voice_regs(trident, evoice);
+		}
+
+		outl(trident->spdif_pcm_bits, TRID_REG(trident, SI_SPDIF_CS));
+		temp = inl(TRID_REG(trident, T4D_LFO_GC_CIR));
+		temp &= ~(1<<19);
+		outl(temp, TRID_REG(trident, T4D_LFO_GC_CIR));
+		temp = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL));
+		temp |= SPDIF_EN;
+		outl(temp, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
+	}
+
+	spin_unlock(&trident->reg_lock);
 
 	return 0;
 }
@@ -1570,8 +1511,14 @@
 		s = s->link_next;
 	} while (s != substream);
 	if (spdif_flag) {
-		outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS));
-		outb(trident->spdif_pcm_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
+		if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
+			outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS));
+			outb(trident->spdif_pcm_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
+		} else {
+			outl(trident->spdif_pcm_bits, TRID_REG(trident, SI_SPDIF_CS));
+			val = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) | SPDIF_EN;
+			outl(val, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
+		}
 	}
 	if (!go)
 		outl(what, TRID_REG(trident, T4D_STOP_B));
@@ -1584,7 +1531,7 @@
 	outl(val, TRID_REG(trident, T4D_AINTEN_B));
 	if (go) {
 		outl(what, TRID_REG(trident, T4D_START_B));
-		
+
 		if (capture_flag && trident->device != TRIDENT_DEVICE_ID_SI7018)
 			outb(trident->bDMAStart, TRID_REG(trident, T4D_SBCTRL_SBE2R_SBDD));
 	} else {
@@ -1790,6 +1737,26 @@
 	.fifo_size =		0,
 };
 
+static snd_pcm_hardware_t snd_trident_spdif_7018 =
+{
+	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
+				 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START |
+				 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME),
+	.formats =		SNDRV_PCM_FMTBIT_S16_LE,
+	.rates =		SNDRV_PCM_RATE_48000,
+	.rate_min =		48000,
+	.rate_max =		48000,
+	.channels_min =		2,
+	.channels_max =		2,
+	.buffer_bytes_max =	(128*1024),
+	.period_bytes_min =	64,
+	.period_bytes_max =	(128*1024),
+	.periods_min =		1,
+	.periods_max =		1024,
+	.fifo_size =		0,
+};
+
 static void snd_trident_pcm_free_substream(snd_pcm_runtime_t *runtime)
 {
 	unsigned long flags;
@@ -1876,7 +1843,11 @@
 
 	runtime->private_data = voice;
 	runtime->private_free = snd_trident_pcm_free_substream;
-	runtime->hw = snd_trident_spdif;
+	if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
+		runtime->hw = snd_trident_spdif;
+	} else {
+		runtime->hw = snd_trident_spdif_7018;
+	}
 
 	trident->spdif_pcm_ctl->access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
 	snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE |
@@ -1899,11 +1870,23 @@
 static int snd_trident_spdif_close(snd_pcm_substream_t * substream)
 {
 	trident_t *trident = snd_pcm_substream_chip(substream);
+	unsigned int temp;
 
 	spin_lock_irq(&trident->reg_lock);
 	// restore default SPDIF setting
-	outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
-	outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
+	if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
+		outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
+		outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
+	} else {
+		outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
+		temp = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL));
+		if (trident->spdif_ctrl) {
+			temp |= SPDIF_EN;
+		} else {
+			temp &= ~SPDIF_EN;
+		}
+		outl(temp, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
+	}
 	spin_unlock_irq(&trident->reg_lock);
 	trident->spdif_pcm_ctl->access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
 	snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE |
@@ -2031,8 +2014,8 @@
 	.open =		snd_trident_playback_open,
 	.close =	snd_trident_playback_close,
 	.ioctl =	snd_trident_ioctl,
-	.hw_params =	snd_trident_playback_hw_params,
-	.hw_free =	snd_trident_playback_hw_free,
+	.hw_params =	snd_trident_hw_params,
+	.hw_free =	snd_trident_hw_free,
 	.prepare =	snd_trident_playback_prepare,
 	.trigger =	snd_trident_trigger,
 	.pointer =	snd_trident_playback_pointer,
@@ -2043,7 +2026,7 @@
 	.close =	snd_trident_capture_close,
 	.ioctl =	snd_trident_ioctl,
 	.hw_params =	snd_trident_capture_hw_params,
-	.hw_free =	snd_trident_capture_hw_free,
+	.hw_free =	snd_trident_hw_free,
 	.prepare =	snd_trident_capture_prepare,
 	.trigger =	snd_trident_trigger,
 	.pointer =	snd_trident_capture_pointer,
@@ -2064,8 +2047,8 @@
 	.open =		snd_trident_foldback_open,
 	.close =	snd_trident_foldback_close,
 	.ioctl =	snd_trident_ioctl,
-	.hw_params =	snd_trident_foldback_hw_params,
-	.hw_free =	snd_trident_foldback_hw_free,
+	.hw_params =	snd_trident_hw_params,
+	.hw_free =	snd_trident_hw_free,
 	.prepare =	snd_trident_foldback_prepare,
 	.trigger =	snd_trident_trigger,
 	.pointer =	snd_trident_playback_pointer,
@@ -2076,12 +2059,23 @@
 	.close =	snd_trident_spdif_close,
 	.ioctl =	snd_trident_ioctl,
 	.hw_params =	snd_trident_spdif_hw_params,
-	.hw_free =	snd_trident_spdif_hw_free,
+	.hw_free =	snd_trident_hw_free,
 	.prepare =	snd_trident_spdif_prepare,
 	.trigger =	snd_trident_trigger,
 	.pointer =	snd_trident_spdif_pointer,
 };
 
+static snd_pcm_ops_t snd_trident_spdif_7018_ops = {
+	.open =		snd_trident_spdif_open,
+	.close =	snd_trident_spdif_close,
+	.ioctl =	snd_trident_ioctl,
+	.hw_params =	snd_trident_spdif_hw_params,
+	.hw_free =	snd_trident_hw_free,
+	.prepare =	snd_trident_spdif_prepare,
+	.trigger =	snd_trident_trigger,
+	.pointer =	snd_trident_playback_pointer,
+};
+
 /*---------------------------------------------------------------------------
    snd_trident_pcm_free
   
@@ -2227,7 +2221,11 @@
 
 	spdif->private_data = trident;
 	spdif->private_free = snd_trident_spdif_pcm_free;
-	snd_pcm_set_ops(spdif, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_spdif_ops);
+	if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
+		snd_pcm_set_ops(spdif, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_spdif_ops);
+	} else {
+		snd_pcm_set_ops(spdif, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_spdif_7018_ops);
+	}
 	spdif->info_flags = 0;
 	strcpy(spdif->name, "Trident 4DWave IEC958");
 	trident->spdif = spdif;
@@ -2286,9 +2284,20 @@
 	/* S/PDIF C Channel bits 0-31 : 48khz, SCMS disabled */
 	change = trident->spdif_ctrl != val;
 	trident->spdif_ctrl = val;
-	if ((inb(TRID_REG(trident, NX_SPCTRL_SPCSO + 3)) & 0x10) == 0) {
-		outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
-		outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
+	if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
+		if ((inb(TRID_REG(trident, NX_SPCTRL_SPCSO + 3)) & 0x10) == 0) {
+			outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
+			outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
+		}
+	} else {
+		if (trident->spdif == NULL) {
+			unsigned int temp;
+			outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
+			temp = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & ~SPDIF_EN;
+			if (val)
+				temp |= SPDIF_EN;
+			outl(temp, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
+		}
 	}
 	spin_unlock_irqrestore(&trident->reg_lock, flags);
 	return change;
@@ -2347,16 +2356,21 @@
 	spin_lock_irqsave(&trident->reg_lock, flags);
 	change = trident->spdif_bits != val;
 	trident->spdif_bits = val;
-	if ((inb(TRID_REG(trident, NX_SPCTRL_SPCSO + 3)) & 0x10) == 0)
-		outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
+	if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
+		if ((inb(TRID_REG(trident, NX_SPCTRL_SPCSO + 3)) & 0x10) == 0)
+			outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS));
+	} else {
+		if (trident->spdif == NULL)
+			outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
+	}
 	spin_unlock_irqrestore(&trident->reg_lock, flags);
 	return change;
 }
 
 static snd_kcontrol_new_t snd_trident_spdif_default __devinitdata =
 {
-	.iface =		SNDRV_CTL_ELEM_IFACE_PCM,
-	.name =           SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
+	.iface =	SNDRV_CTL_ELEM_IFACE_PCM,
+	.name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
 	.info =		snd_trident_spdif_default_info,
 	.get =		snd_trident_spdif_default_get,
 	.put =		snd_trident_spdif_default_put
@@ -2437,8 +2451,13 @@
 	spin_lock_irqsave(&trident->reg_lock, flags);
 	change = trident->spdif_pcm_bits != val;
 	trident->spdif_pcm_bits = val;
-	if (trident->spdif != NULL)
-		outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS));
+	if (trident->spdif != NULL) {
+		if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
+			outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS));
+		} else {
+			outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
+		}
+	}
 	spin_unlock_irqrestore(&trident->reg_lock, flags);
 	return change;
 }
@@ -2873,7 +2892,7 @@
 	snd_card_t * card = trident->card;
 	snd_kcontrol_t *kctl;
 	snd_ctl_elem_value_t uctl;
-	int idx, err;
+	int idx, err, retries = 2;
 
 	memset(&uctl, 0, sizeof(uctl));
 
@@ -2881,8 +2900,19 @@
 	_ac97.write = snd_trident_codec_write;
 	_ac97.read = snd_trident_codec_read;
 	_ac97.private_data = trident;
-	if ((err = snd_ac97_mixer(trident->card, &_ac97, &ac97)) < 0)
+	trident->ac97_detect = 1;
+      __again:
+	if ((err = snd_ac97_mixer(trident->card, &_ac97, &ac97)) < 0) {
+		if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
+			if ((err = snd_trident_sis_reset(trident)) < 0)
+				return err;
+			if (retries-- > 0)
+				goto __again;
+			return -EIO;
+		}
 		return err;
+	}
+	trident->ac97_detect = 0;
 
 	if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
 		if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_trident_vol_wave_control, trident))) < 0)
@@ -2934,6 +2964,8 @@
 		if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_trident_ac97_rear_control, trident))) < 0)
 			return err;
 		kctl->put(kctl, &uctl);
+	}
+	if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018) {
 		if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_trident_spdif_control, trident))) < 0)
 			return err;
 		kctl->put(kctl, &uctl);
@@ -3046,6 +3078,55 @@
 }
 #endif
 
+/*
+ *  SiS reset routine
+ */
+
+static int snd_trident_sis_reset(trident_t *trident)
+{
+	signed long end_time;
+	unsigned int i;
+	int r;
+
+	r = 2;	/* count of retries */
+      __si7018_retry:
+	pci_write_config_byte(trident->pci, 0x46, 0x04);	/* SOFTWARE RESET */
+	udelay(100);
+	pci_write_config_byte(trident->pci, 0x46, 0x00);
+	udelay(100);
+	/* disable AC97 GPIO interrupt */
+	outb(0x00, TRID_REG(trident, SI_AC97_GPIO));
+	/* initialize serial interface, force cold reset */
+	i = PCMOUT|SURROUT|CENTEROUT|LFEOUT|SECONDARY_ID|COLD_RESET;
+	outl(i, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
+	udelay(1000);
+	/* remove cold reset */
+	i &= ~COLD_RESET;
+	outl(i, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
+	udelay(2000);
+	/* wait, until the codec is ready */
+	end_time = (jiffies + (HZ * 3) / 4) + 1;
+	do {
+		if ((inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & SI_AC97_PRIMARY_READY) != 0)
+			goto __si7018_ok;
+		set_current_state(TASK_UNINTERRUPTIBLE);
+		schedule_timeout(1);
+	} while (time_after_eq(end_time, jiffies));
+	snd_printk("AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)));
+	if (r-- > 0) {
+		end_time = jiffies + HZ;
+		do {
+			set_current_state(TASK_UNINTERRUPTIBLE);
+			schedule_timeout(1);
+		} while (time_after_eq(end_time, jiffies));
+		goto __si7018_retry;
+	}
+      __si7018_ok:
+	/* enable 64 channel mode */
+	outl(BANK_B_EN, TRID_REG(trident, T4D_LFO_GC_CIR));
+	return 0;
+}
+
 /*  
  *  /proc interface
  */
@@ -3072,8 +3153,9 @@
 	snd_iprintf(buffer, "%s\n\n", s);
 	snd_iprintf(buffer, "Spurious IRQs    : %d\n", trident->spurious_irq_count);
 	snd_iprintf(buffer, "Spurious IRQ dlta: %d\n", trident->spurious_irq_max_delta);
-	if (trident->device == TRIDENT_DEVICE_ID_NX) {
+	if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018)
 		snd_iprintf(buffer, "IEC958 Mixer Out : %s\n", trident->spdif_ctrl == 0x28 ? "on" : "off");
+	if (trident->device == TRIDENT_DEVICE_ID_NX) {
 		snd_iprintf(buffer, "Rear Speakers    : %s\n", trident->ac97_ctrl & 0x00000010 ? "on" : "off");
 		if (trident->tlb.entries) {
 			snd_iprintf(buffer,"\nVirtual Memory\n");
@@ -3318,35 +3400,10 @@
 		outl(NX_SB_IRQ_DISABLE, TRID_REG(trident, T4D_MISCINT));
 		break;
 	case TRIDENT_DEVICE_ID_SI7018:
-		pci_write_config_byte(pci, 0x46, 0x04);	/* SOFTWARE RESET */
-		udelay(100);
-		pci_write_config_byte(pci, 0x46, 0x00);
-		udelay(100);
-		/* disable AC97 GPIO interrupt */
-		outb(0x00, TRID_REG(trident, SI_AC97_GPIO));
-		/* initialize serial interface, force cold reset */
-		i = PCMOUT|SURROUT|CENTEROUT|LFEOUT|SECONDARY_ID|COLD_RESET;
-		outl(i, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
-		udelay(1000);
-		/* remove cold reset */
-		i &= ~COLD_RESET;
-		outl(i, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
-		udelay(2000);
-		/* wait, until the codec is ready */
-		end_time = (jiffies + (HZ * 3) / 4) + 1;
-		do {
-			if ((inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & SI_AC97_PRIMARY_READY) != 0)
-				goto __si7018_ok;
-			set_current_state(TASK_UNINTERRUPTIBLE);
-			schedule_timeout(1);
-		} while (end_time - (signed long)jiffies >= 0);
-		snd_printk("AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)));
-		snd_trident_free(trident);
-		return -EIO;
-	      __si7018_ok:
-		/* enable 64 channel mode */
-		outl(BANK_B_EN, TRID_REG(trident, T4D_LFO_GC_CIR));
-		break;
+		if ((err = snd_trident_sis_reset(trident)) < 0) {
+			snd_trident_free(trident);
+			return err;
+		}
 	}
 
 	outl(0xffffffff, TRID_REG(trident, T4D_STOP_A));
@@ -3374,6 +3431,12 @@
 		outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
 	}
 
+	if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
+		/* initialize S/PDIF */
+		trident->spdif_bits = trident->spdif_pcm_bits = SNDRV_PCM_DEFAULT_CON_SPDIF;
+		outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS));
+	}
+
 	/* initialise synth voices */
 	for (i = 0; i < 64; i++) {
 		voice = &trident->synth.voices[i];
@@ -3429,6 +3492,9 @@
 	// Disable S/PDIF out
 	if (trident->device == TRIDENT_DEVICE_ID_NX)
 		outb(0x00, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
+	else if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
+		outl(0, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
+	}
 	snd_trident_proc_done(trident);
 	if (trident->tlb.buffer) {
 		outl(0, TRID_REG(trident, NX_TLBC));
diff -Nru a/sound/pci/via82xx.c b/sound/pci/via82xx.c
--- a/sound/pci/via82xx.c	Mon Dec 23 21:21:52 2002
+++ b/sound/pci/via82xx.c	Mon Dec 23 21:21:52 2002
@@ -613,6 +613,9 @@
 	snd_pcm_runtime_t *runtime = substream->runtime;
 
 	snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate);
+	snd_ac97_set_rate(chip->ac97, AC97_PCM_SURR_DAC_RATE, runtime->rate);
+	snd_ac97_set_rate(chip->ac97, AC97_PCM_LFE_DAC_RATE, runtime->rate);
+	snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate);
 	if (chip->chip_type == TYPE_VIA8233 &&
 	    chip->playback.reg_offset != VIA_REG_MULTPLAY_STATUS) {
 		unsigned int tmp;
diff -Nru a/sound/synth/Makefile b/sound/synth/Makefile
--- a/sound/synth/Makefile	Mon Dec 23 21:21:50 2002
+++ b/sound/synth/Makefile	Mon Dec 23 21:21:50 2002
@@ -12,6 +12,5 @@
 obj-$(CONFIG_SND_TRIDENT) += snd-util-mem.o
 ifeq ($(subst m,y,$(CONFIG_SND_SEQUENCER)),y)
   obj-$(CONFIG_SND_SBAWE) += snd-util-mem.o
+  obj-$(CONFIG_SND) += emux/
 endif
-
-obj-$(CONFIG_SND) += emux/
diff -Nru a/sound/usb/Kconfig b/sound/usb/Kconfig
--- a/sound/usb/Kconfig	Mon Dec 23 21:21:58 2002
+++ b/sound/usb/Kconfig	Mon Dec 23 21:21:58 2002
@@ -5,7 +5,7 @@
 
 config SND_USB_AUDIO
 	tristate "USB Audio/MIDI driver"
-	depends on SND
+	depends on SND && USB
 	help
 	  Say 'Y' or 'M' to include support for USB audio and USB MIDI devices.
 
diff -Nru a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c
--- a/sound/usb/usbaudio.c	Mon Dec 23 21:21:58 2002
+++ b/sound/usb/usbaudio.c	Mon Dec 23 21:21:58 2002
@@ -526,7 +526,11 @@
 /*
  * complete callback from data urb
  */
+#ifndef OLD_USB
 static void snd_complete_urb(struct urb *urb, struct pt_regs *regs)
+#else
+static void snd_complete_urb(struct urb *urb)
+#endif
 {
 	snd_urb_ctx_t *ctx = (snd_urb_ctx_t *)urb->context;
 	snd_usb_substream_t *subs = ctx->subs;
@@ -551,7 +555,11 @@
 /*
  * complete callback from sync urb
  */
+#ifndef OLD_USB
 static void snd_complete_sync_urb(struct urb *urb, struct pt_regs *regs)
+#else
+static void snd_complete_sync_urb(struct urb *urb)
+#endif
 {
 	snd_urb_ctx_t *ctx = (snd_urb_ctx_t *)urb->context;
 	snd_usb_substream_t *subs = ctx->subs;
@@ -583,6 +591,9 @@
 
 	subs->running = 0;
 
+	if (subs->stream->chip->shutdown) /* to be sure... */
+		return 0;
+
 #ifndef SND_USB_ASYNC_UNLINK
 	if (in_interrupt())
 		return 0;
@@ -870,7 +881,7 @@
 		u->urb->transfer_flags = URB_ISO_ASAP | UNLINK_FLAGS;
 		u->urb->number_of_packets = u->packets;
 		u->urb->context = u;
-		u->urb->complete = snd_complete_urb;
+		u->urb->complete = (usb_complete_t)snd_complete_urb;
 	}
 
 	if (subs->syncpipe) {
@@ -892,7 +903,7 @@
 			u->urb->transfer_flags = URB_ISO_ASAP | UNLINK_FLAGS;
 			u->urb->number_of_packets = u->packets;
 			u->urb->context = u;
-			u->urb->complete = snd_complete_sync_urb;
+			u->urb->complete = (usb_complete_t)snd_complete_sync_urb;
 		}
 	}
 	return 0;
@@ -1181,7 +1192,6 @@
 	runtime->private_data = subs;
 	subs->pcm_substream = substream;
 	setup_hw_info(runtime, subs);
-
 	return 0;
 }
 
@@ -1189,6 +1199,7 @@
 {
 	snd_usb_stream_t *as = snd_pcm_substream_chip(substream);
 	snd_usb_substream_t *subs = &as->substream[direction];
+
 	release_substream_urbs(subs);
 	if (subs->interface >= 0)
 		usb_set_interface(subs->dev, subs->interface, 0);
@@ -2171,6 +2182,10 @@
 	for (i = 0; i < SNDRV_CARDS; i++) {
 		if (usb_chip[i] && usb_chip[i]->dev == dev) {
 			chip = usb_chip[i];
+			if (chip->shutdown) {
+				snd_printk(KERN_ERR "USB device is in the shutdown state, cannot create a card instance\n");
+				goto __error;
+			}
 			break;
 		}
 	}
@@ -2247,14 +2262,37 @@
 static void snd_usb_audio_disconnect(struct usb_device *dev, void *ptr)
 {
 	snd_usb_audio_t *chip;
+	snd_card_t *card;
+	struct list_head *p;
 
 	if (ptr == (void *)-1)
 		return;
 
 	chip = snd_magic_cast(snd_usb_audio_t, ptr, return);
+	card = chip->card;
+	down(&register_mutex);
+	chip->shutdown = 1;
 	chip->num_interfaces--;
-	if (chip->num_interfaces <= 0)
-		snd_card_free(chip->card);
+	if (chip->num_interfaces <= 0) {
+		snd_card_disconnect(card);
+		/* release the pcm resources */
+		list_for_each(p, &chip->pcm_list) {
+			snd_usb_stream_t *as;
+			int idx;
+			as = list_entry(p, snd_usb_stream_t, list);
+			for (idx = 0; idx < 2; idx++) {
+				snd_usb_substream_t *subs;
+				subs = &as->substream[idx];
+				if (!subs->num_formats)
+					continue;
+				release_substream_urbs(subs);
+			}
+		}
+		up(&register_mutex);
+		snd_card_free_in_thread(card);
+	} else {
+		up(&register_mutex);
+	}
 }
 
 
@@ -2317,7 +2355,7 @@
 
 #ifndef MODULE
 /*
- * format is snd-usb-audio=enable,index,id
+ * format is snd-usb-audio=enable,index,id,vid,pid
  */
 static int __init snd_usb_audio_module_setup(char* str)
 {
@@ -2327,7 +2365,9 @@
 		return 0;
 	(void)(get_option(&str, &enable[nr_dev]) == 2 &&
 	       get_option(&str, &index[nr_dev]) == 2 &&
-	       get_id(&str, &id[nr_dev]) == 2);
+	       get_id(&str, &id[nr_dev]) == 2 &&
+	       get_option(&str, &vid[nr_dev]) == 2 &&
+	       get_option(&str, &pid[nr_dev]) == 2);
 	++nr_dev;
 	return 1;
 }
diff -Nru a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
--- a/sound/usb/usbaudio.h	Mon Dec 23 21:21:57 2002
+++ b/sound/usb/usbaudio.h	Mon Dec 23 21:21:57 2002
@@ -133,6 +133,7 @@
 	int index;
 	struct usb_device *dev;
 	snd_card_t *card;
+	int shutdown;
 	int num_interfaces;
 
 	struct list_head pcm_list;	/* list of pcm streams */
@@ -171,7 +172,8 @@
 
 /* for QUIRK_MIDI_YAMAHA, data is NULL */
 
-/* for QUIRK_MIDI_MIDIMAN, data is the number of ports */
+/* for QUIRK_MIDI_MIDIMAN, data points to a snd_usb_midi_endpoint_info
+ * structure (out_cables and in_cables only) */
 
 /* for QUIRK_ROLAND_UA100, data is NULL */
 
@@ -200,6 +202,10 @@
 #define get_endpoint(alt,ep)	(&(alt)->endpoint[ep].desc)
 #define get_ep_desc(ep)		(&(ep)->desc)
 #define get_cfg_desc(cfg)	(&(cfg)->desc)
+#endif
+
+#ifndef usb_pipe_needs_resubmit
+#define usb_pipe_needs_resubmit(pipe) 1
 #endif
 
 #endif /* __USBAUDIO_H */
diff -Nru a/sound/usb/usbmidi.c b/sound/usb/usbmidi.c
--- a/sound/usb/usbmidi.c	Mon Dec 23 21:22:00 2002
+++ b/sound/usb/usbmidi.c	Mon Dec 23 21:22:00 2002
@@ -114,7 +114,6 @@
 	struct urb* urb;
 	struct usbmidi_in_port {
 		snd_rawmidi_substream_t* substream;
-		int active;
 	} ports[0x10];
 };
 
@@ -159,7 +158,12 @@
 	int cable = packet[0] >> 4;
 	usbmidi_in_port_t* port = &ep->ports[cable];
 
-	if (!port->active)
+	if (!port->substream) {
+		snd_printd("unexpected port %d!\n", cable);
+		return;
+	}
+	if (!port->substream->runtime ||
+	    !port->substream->runtime->trigger)
 		return;
 	snd_rawmidi_receive(port->substream, &packet[1],
 			    snd_usbmidi_cin_length[packet[0] & 0x0f]);
@@ -168,7 +172,11 @@
 /*
  * Processes the data read from the device.
  */
+#ifndef OLD_USB
 static void snd_usbmidi_in_urb_complete(struct urb* urb, struct pt_regs *regs)
+#else
+static void snd_usbmidi_in_urb_complete(struct urb* urb)
+#endif
 {
 	snd_usb_midi_in_endpoint_t* ep = snd_magic_cast(snd_usb_midi_in_endpoint_t, urb->context, return);
 
@@ -184,14 +192,20 @@
 			return;
 	}
 
-	urb->dev = ep->umidi->chip->dev;
-	snd_usbmidi_submit_urb(urb, GFP_ATOMIC);
+	if (usb_pipe_needs_resubmit(urb->pipe)) {
+		urb->dev = ep->umidi->chip->dev;
+		snd_usbmidi_submit_urb(urb, GFP_ATOMIC);
+	}
 }
 
 /*
  * Converts the data read from a Midiman device to standard USB MIDI packets.
  */
+#ifndef OLD_USB
 static void snd_usbmidi_in_midiman_complete(struct urb* urb, struct pt_regs *regs)
+#else
+static void snd_usbmidi_in_midiman_complete(struct urb* urb)
+#endif
 {
 	if (urb->status == 0) {
 		uint8_t* buffer = (uint8_t*)urb->transfer_buffer;
@@ -217,10 +231,18 @@
 			}
 		}
 	}
+#ifndef OLD_USB
 	snd_usbmidi_in_urb_complete(urb, regs);
+#else
+	snd_usbmidi_in_urb_complete(urb);
+#endif
 }
 
+#ifndef OLD_USB
 static void snd_usbmidi_out_urb_complete(struct urb* urb, struct pt_regs *regs)
+#else
+static void snd_usbmidi_out_urb_complete(struct urb* urb)
+#endif
 {
 	snd_usb_midi_out_endpoint_t* ep = snd_magic_cast(snd_usb_midi_out_endpoint_t, urb->context, return);
 
@@ -445,26 +467,14 @@
 	usbmidi_out_port_t* port = (usbmidi_out_port_t*)substream->runtime->private_data;
 
 	port->active = up;
-	if (up)
-		tasklet_hi_schedule(&port->ep->tasklet);
+	if (up) {
+		if (! port->ep->umidi->chip->shutdown) /* to be sure... */
+			tasklet_hi_schedule(&port->ep->tasklet);
+	}
 }
 
 static int snd_usbmidi_input_open(snd_rawmidi_substream_t* substream)
 {
-	snd_usb_midi_t* umidi = snd_magic_cast(snd_usb_midi_t, substream->rmidi->private_data, return -ENXIO);
-	usbmidi_in_port_t* port = NULL;
-	int i, j;
-
-	for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i)
-		if (umidi->endpoints[i].in)
-			for (j = 0; j < 0x10; ++j)
-				if (umidi->endpoints[i].in->ports[j].substream == substream) {
-					port = &umidi->endpoints[i].in->ports[j];
-					break;
-				}
-	if (!port)
-		return -ENXIO;
-	substream->runtime->private_data = port;
 	return 0;
 }
 
@@ -475,9 +485,6 @@
 
 static void snd_usbmidi_input_trigger(snd_rawmidi_substream_t* substream, int up)
 {
-	usbmidi_in_port_t* port = (usbmidi_in_port_t*)substream->runtime->private_data;
-
-	port->active = up;
 }
 
 static snd_rawmidi_ops_t snd_usbmidi_output_ops = {
@@ -500,7 +507,8 @@
 {
 	if (ep->urb) {
 		if (ep->urb->transfer_buffer) {
-			usb_unlink_urb(ep->urb);
+			if (! ep->umidi->chip->shutdown) /* to be sure */
+				usb_unlink_urb(ep->urb);
 			kfree(ep->urb->transfer_buffer);
 		}
 		usb_free_urb(ep->urb);
@@ -598,10 +606,12 @@
 	}
 	if (int_epd)
 		usb_fill_int_urb(ep->urb, umidi->chip->dev, pipe, buffer, length,
-			     snd_usbmidi_in_urb_complete, ep, int_epd->bInterval);
+				 (usb_complete_t)snd_usbmidi_in_urb_complete,
+				 ep, int_epd->bInterval);
 	else
 		usb_fill_bulk_urb(ep->urb, umidi->chip->dev, pipe, buffer, length,
-			      snd_usbmidi_in_urb_complete, ep);
+				  (usb_complete_t)snd_usbmidi_in_urb_complete,
+				  ep);
 
 	rep->in = ep;
 	return 0;
@@ -626,7 +636,8 @@
 		tasklet_kill(&ep->tasklet);
 	if (ep->urb) {
 		if (ep->urb->transfer_buffer) {
-			usb_unlink_urb(ep->urb);
+			if (! ep->umidi->chip->shutdown) /* to be sure */
+				usb_unlink_urb(ep->urb);
 			kfree(ep->urb->transfer_buffer);
 		}
 		usb_free_urb(ep->urb);
@@ -665,7 +676,8 @@
 		return -ENOMEM;
 	}
 	usb_fill_bulk_urb(ep->urb, umidi->chip->dev, pipe, buffer,
-		      ep->max_transfer, snd_usbmidi_out_urb_complete, ep);
+			  ep->max_transfer,
+			  (usb_complete_t)snd_usbmidi_out_urb_complete, ep);
 
 	spin_lock_init(&ep->buffer_lock);
 	tasklet_init(&ep->tasklet, snd_usbmidi_out_tasklet, (unsigned long)ep);
@@ -903,7 +915,8 @@
 /*
  * Creates the endpoints and their ports for Midiman devices.
  */
-static int snd_usbmidi_create_endpoints_midiman(snd_usb_midi_t* umidi, int ports)
+static int snd_usbmidi_create_endpoints_midiman(snd_usb_midi_t* umidi,
+						snd_usb_midi_endpoint_info_t* endpoint)
 {
 	snd_usb_midi_endpoint_info_t ep_info;
 	struct usb_interface* intf;
@@ -917,7 +930,7 @@
 		return -ENOENT;
 	hostif = intf->altsetting;
 	intfd = get_iface_desc(hostif);
-	if (intfd->bNumEndpoints < (ports > 1 ? 5 : 3)) {
+	if (intfd->bNumEndpoints < (endpoint->out_cables > 0x0001 ? 5 : 3)) {
 		snd_printdd(KERN_ERR "not enough endpoints\n");
 		return -ENOENT;
 	}
@@ -934,7 +947,7 @@
 		snd_printdd(KERN_ERR "endpoint[2] isn't bulk output\n");
 		return -ENXIO;
 	}
-	if (ports > 1) {
+	if (endpoint->out_cables > 0x0001) {
 		epd = get_endpoint(hostif, 4);
 		if ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) != USB_DIR_OUT ||
 		    (epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_BULK) {
@@ -944,31 +957,33 @@
 	}
 
 	ep_info.epnum = get_endpoint(hostif, 2)->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
-	ep_info.out_cables = 0x5555 & ((1 << ports) - 1);
+	ep_info.out_cables = endpoint->out_cables & 0x5555;
 	err = snd_usbmidi_out_endpoint_create(umidi, &ep_info, &umidi->endpoints[0]);
 	if (err < 0)
 		return err;
 
 	ep_info.epnum = get_endpoint(hostif, 0)->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
-	ep_info.in_cables = (1 << ports) - 1;
+	ep_info.in_cables = endpoint->in_cables;
 	err = snd_usbmidi_in_endpoint_create(umidi, &ep_info, &umidi->endpoints[0]);
 	if (err < 0)
 		return err;
-	umidi->endpoints[0].in->urb->complete = snd_usbmidi_in_midiman_complete;
+	umidi->endpoints[0].in->urb->complete = (usb_complete_t)snd_usbmidi_in_midiman_complete;
 
-	if (ports > 1) {
+	if (endpoint->out_cables > 0x0001) {
 		ep_info.epnum = get_endpoint(hostif, 4)->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
-		ep_info.out_cables = 0xaaaa & ((1 << ports) - 1);
+		ep_info.out_cables = endpoint->out_cables & 0xaaaa;
 		err = snd_usbmidi_out_endpoint_create(umidi, &ep_info, &umidi->endpoints[1]);
 		if (err < 0)
 			return err;
 	}
 
-	for (cable = 0; cable < ports; ++cable) {
-		snd_usbmidi_init_substream(umidi, SNDRV_RAWMIDI_STREAM_OUTPUT, cable,
-					   &umidi->endpoints[cable & 1].out->ports[cable].substream);
-		snd_usbmidi_init_substream(umidi, SNDRV_RAWMIDI_STREAM_INPUT, cable,
-					   &umidi->endpoints[0].in->ports[cable].substream);
+	for (cable = 0; cable < 0x10; ++cable) {
+		if (endpoint->out_cables & (1 << cable))
+			snd_usbmidi_init_substream(umidi, SNDRV_RAWMIDI_STREAM_OUTPUT, cable,
+						   &umidi->endpoints[cable & 1].out->ports[cable].substream);
+		if (endpoint->in_cables & (1 << cable))
+			snd_usbmidi_init_substream(umidi, SNDRV_RAWMIDI_STREAM_INPUT, cable,
+						   &umidi->endpoints[0].in->ports[cable].substream);
 	}
 	return 0;
 }
@@ -1031,6 +1046,8 @@
 			err = snd_usbmidi_detect_yamaha(umidi, &endpoints[0]);
 			break;
 		case QUIRK_MIDI_MIDIMAN:
+			memcpy(&endpoints[0], quirk->data,
+			       sizeof(snd_usb_midi_endpoint_info_t));
 			err = 0;
 			break;
 		default:
@@ -1045,15 +1062,11 @@
 	}
 
 	/* create rawmidi device */
-	if (quirk && quirk->type == QUIRK_MIDI_MIDIMAN) {
-		in_ports = out_ports = (int)quirk->data;
-	} else {
-		out_ports = 0;
-		in_ports = 0;
-		for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
-			out_ports += snd_usbmidi_count_bits(endpoints[i].out_cables);
-			in_ports += snd_usbmidi_count_bits(endpoints[i].in_cables);
-		}
+	out_ports = 0;
+	in_ports = 0;
+	for (i = 0; i < MIDI_MAX_ENDPOINTS; ++i) {
+		out_ports += snd_usbmidi_count_bits(endpoints[i].out_cables);
+		in_ports += snd_usbmidi_count_bits(endpoints[i].in_cables);
 	}
 	err = snd_usbmidi_create_rawmidi(umidi, out_ports, in_ports);
 	if (err < 0) {
@@ -1063,7 +1076,7 @@
 
 	/* create endpoint/port structures */
 	if (quirk && quirk->type == QUIRK_MIDI_MIDIMAN)
-		err = snd_usbmidi_create_endpoints_midiman(umidi, (int)quirk->data);
+		err = snd_usbmidi_create_endpoints_midiman(umidi, &endpoints[0]);
 	else
 		err = snd_usbmidi_create_endpoints(umidi, endpoints);
 	if (err < 0) {
diff -Nru a/sound/usb/usbmixer.c b/sound/usb/usbmixer.c
--- a/sound/usb/usbmixer.c	Mon Dec 23 21:21:52 2002
+++ b/sound/usb/usbmixer.c	Mon Dec 23 21:21:52 2002
@@ -65,6 +65,8 @@
 	unsigned char *buffer;
 	unsigned int buflen;
 	unsigned int ctrlif;
+	unsigned short vendor;
+	unsigned short product;
 	DECLARE_BITMAP(unitbitmap, 32*32);
 	usb_audio_term_t oterm;
 	const struct usbmix_name_map *map;
@@ -74,11 +76,11 @@
 	snd_usb_audio_t *chip;
 	unsigned int ctrlif;
 	unsigned int id;
-	unsigned int control;
+	unsigned int control;	/* CS or ICN (high byte) */
 	unsigned int cmask; /* channel mask bitmap: 0 = master */ 
 	int channels;
 	int val_type;
-	int min, max;
+	int min, max, res;
 	unsigned int initialized: 1;
 };
 
@@ -250,18 +252,23 @@
 
 static int get_relative_value(usb_mixer_elem_info_t *cval, int val)
 {
+	if (! cval->res)
+		cval->res = 1;
 	if (val < cval->min)
 		return 0;
 	else if (val > cval->max)
-		return cval->max - cval->min;
+		return (cval->max - cval->min) / cval->res;
 	else
-		return val - cval->min;
+		return (val - cval->min) / cval->res;
 }
 
 static int get_abs_value(usb_mixer_elem_info_t *cval, int val)
 {
 	if (val < 0)
 		return cval->min;
+	if (! cval->res)
+		cval->res = 1;
+	val *= cval->res;
 	val += cval->min;
 	if (val > cval->max)
 		return cval->max;
@@ -277,17 +284,20 @@
 {
 	unsigned char buf[2];
 	int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1;
+	int timeout = 10;
  
-	if (usb_control_msg(cval->chip->dev, usb_rcvctrlpipe(cval->chip->dev, 0),
-			    request,
-			    USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
-			    validx, cval->ctrlif | (cval->id << 8),
-			    buf, val_len, HZ) < 0) {
-		snd_printdd(KERN_ERR "cannot get ctl value: req = 0x%x, idx = 0x%x, val = 0x%x, type = %d\n", request, validx, cval->ctrlif | (cval->id << 8), cval->val_type);
-		return -EINVAL;
+	while (timeout-- > 0) {
+		if (usb_control_msg(cval->chip->dev, usb_rcvctrlpipe(cval->chip->dev, 0),
+				    request,
+				    USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
+				    validx, cval->ctrlif | (cval->id << 8),
+				    buf, val_len, HZ / 10) >= 0) {
+			*value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len));
+			return 0;
+		}
 	}
-	*value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len));
-	return 0;
+	snd_printdd(KERN_ERR "cannot get ctl value: req = 0x%x, wValue = 0x%x, wIndex = 0x%x, type = %d\n", request, validx, cval->ctrlif | (cval->id << 8), cval->val_type);
+	return -EINVAL;
 }
 
 static int get_cur_ctl_value(usb_mixer_elem_info_t *cval, int validx, int *value)
@@ -309,15 +319,20 @@
 {
 	unsigned char buf[2];
 	int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1;
+	int timeout = 10;
  
 	value_set = convert_bytes_value(cval, value_set);
 	buf[0] = value_set & 0xff;
 	buf[1] = (value_set >> 8) & 0xff;
-	return usb_control_msg(cval->chip->dev, usb_sndctrlpipe(cval->chip->dev, 0),
-			       request,
-			       USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
-			       validx, cval->ctrlif | (cval->id << 8),
-			       buf, val_len, HZ);
+	while (timeout -- > 0)
+		if (usb_control_msg(cval->chip->dev, usb_sndctrlpipe(cval->chip->dev, 0),
+				    request,
+				    USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
+				    validx, cval->ctrlif | (cval->id << 8),
+				    buf, val_len, HZ / 10) >= 0)
+			return 0;
+	snd_printdd(KERN_ERR "cannot set ctl value: req = 0x%x, wValue = 0x%x, wIndex = 0x%x, type = %d, data = 0x%x/0x%x\n", request, validx, cval->ctrlif | (cval->id << 8), cval->val_type, buf[0], buf[1]);
+	return -EINVAL;
 }
 
 static int set_cur_ctl_value(usb_mixer_elem_info_t *cval, int validx, int value)
@@ -557,11 +572,12 @@
 /*
  * retrieve the minimum and maximum values for the specified control
  */
-static int get_min_max(usb_mixer_elem_info_t *cval)
+static int get_min_max(usb_mixer_elem_info_t *cval, int default_min)
 {
 	/* for failsafe */
-	cval->min = 0;
-	cval->max = 1;
+	cval->min = default_min;
+	cval->max = cval->min + 1;
+	cval->res = 1;
 
 	if (cval->val_type == USB_MIXER_BOOLEAN ||
 	    cval->val_type == USB_MIXER_INV_BOOLEAN) {
@@ -581,6 +597,21 @@
 			snd_printd(KERN_ERR "%d:%d: cannot get min/max values for control %d (id %d)\n", cval->id, cval->ctrlif, cval->control, cval->id);
 			return -EINVAL;
 		}
+		if (get_ctl_value(cval, GET_RES, (cval->control << 8) | minchn, &cval->res) < 0) {
+			cval->res = 1;
+		} else {
+			int last_valid_res = cval->res;
+		
+			while (cval->res > 1) {
+				if (set_ctl_value(cval, SET_RES, (cval->control << 8) | minchn, cval->res / 2) < 0)
+					break;
+				cval->res /= 2;
+			}
+			if (get_ctl_value(cval, GET_RES, (cval->control << 8) | minchn, &cval->res) < 0)
+				cval->res = last_valid_res;
+		}
+		if (cval->res == 0)
+			cval->res = 1;
 		cval->initialized = 1;
 	}
 	return 0;
@@ -604,9 +635,9 @@
 		uinfo->value.integer.max = 1;
 	} else {
 		if (! cval->initialized)
-			get_min_max(cval);
+			get_min_max(cval,  0);
 		uinfo->value.integer.min = 0;
-		uinfo->value.integer.max = cval->max - cval->min;
+		uinfo->value.integer.max = (cval->max - cval->min) / cval->res;
 	}
 	return 0;
 }
@@ -680,6 +711,7 @@
 					set_cur_mix_value(cval, c + 1, val);
 					changed = 1;
 				}
+				get_cur_mix_value(cval, c + 1, &val);
 				cnt++;
 			}
 		}
@@ -753,7 +785,7 @@
 	}
 
 	/* get min/max values */
-	get_min_max(cval);
+	get_min_max(cval, 0);
 
 	kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval);
 	if (! kctl) {
@@ -812,8 +844,19 @@
 		break;
 	}
 
-	snd_printdd(KERN_INFO "[%d] FU [%s] ch = %d, val = %d/%d\n",
-		    cval->id, kctl->id.name, cval->channels, cval->min, cval->max);
+	/* quirk for UDA1321/N101 */
+	/* note that detection between firmware 2.1.1.7 (N101) and later 2.1.1.21 */
+	/* is not very clear from datasheets */
+	/* I hope that the min value is -15360 for newer firmware --jk */
+	if (((state->vendor == 0x471 && (state->product == 0x104 || state->product == 0x105 || state->product == 0x101)) ||
+	     (state->vendor == 0x672 && state->product == 0x1041)) && !strcmp(kctl->id.name, "PCM Playback Volume") &&
+	     cval->min == -15616) {
+		snd_printk("USB Audio: using volume control quirk for the UDA1321/N101 chip\n");
+		cval->max = -256;
+	}
+
+	snd_printdd(KERN_INFO "[%d] FU [%s] ch = %d, val = %d/%d/%d\n",
+		    cval->id, kctl->id.name, cval->channels, cval->min, cval->max, cval->res);
 	add_control_to_empty(state->chip->card, kctl);
 }
 
@@ -910,7 +953,7 @@
 	}
 
 	/* get min/max values */
-	get_min_max(cval);
+	get_min_max(cval, 0);
 
 	kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval);
 	if (! kctl) {
@@ -965,7 +1008,7 @@
 	usb_mixer_elem_info_t *cval = snd_magic_cast(usb_mixer_elem_info_t, kcontrol->private_data, return -EINVAL);
 	int err, val;
 
-	err = get_cur_ctl_value(cval, cval->control, &val);
+	err = get_cur_ctl_value(cval, cval->control << 8, &val);
 #ifdef IGNORE_CTL_ERROR
 	if (err < 0) {
 		ucontrol->value.integer.value[0] = cval->min;
@@ -985,7 +1028,7 @@
 	usb_mixer_elem_info_t *cval = snd_magic_cast(usb_mixer_elem_info_t, kcontrol->private_data, return -EINVAL);
 	int val, oval, err;
 
-	err = get_cur_ctl_value(cval, cval->control, &oval);
+	err = get_cur_ctl_value(cval, cval->control << 8, &oval);
 #ifdef IGNORE_CTL_ERROR
 	if (err < 0)
 		return 0;
@@ -995,7 +1038,7 @@
 	val = ucontrol->value.integer.value[0];
 	val = get_abs_value(cval, val);
 	if (val != oval) {
-		set_cur_ctl_value(cval, cval->control, val);
+		set_cur_ctl_value(cval, cval->control << 8, val);
 		return 1;
 	}
 	return 0;
@@ -1018,6 +1061,7 @@
 	int control;
 	char *suffix;
 	int val_type;
+	int min_value;
 };
 
 struct procunit_info {
@@ -1028,12 +1072,12 @@
 
 static struct procunit_value_info updown_proc_info[] = {
 	{ USB_PROC_UPDOWN_SWITCH, "Switch", USB_MIXER_BOOLEAN },
-	{ USB_PROC_UPDOWN_MODE_SEL, "Mode Select", USB_MIXER_U8 },
+	{ USB_PROC_UPDOWN_MODE_SEL, "Mode Select", USB_MIXER_U8, 1 },
 	{ 0 }
 };
 static struct procunit_value_info prologic_proc_info[] = {
 	{ USB_PROC_PROLOGIC_SWITCH, "Switch", USB_MIXER_BOOLEAN },
-	{ USB_PROC_PROLOGIC_MODE_SEL, "Mode Select", USB_MIXER_U8 },
+	{ USB_PROC_PROLOGIC_MODE_SEL, "Mode Select", USB_MIXER_U8, 1 },
 	{ 0 }
 };
 static struct procunit_value_info threed_enh_proc_info[] = {
@@ -1131,7 +1175,7 @@
 		cval->channels = 1;
 
 		/* get min/max values */
-		get_min_max(cval);
+		get_min_max(cval, valinfo->min_value);
 
 		kctl = snd_ctl_new1(&mixer_procunit_ctl, cval);
 		if (! kctl) {
@@ -1309,6 +1353,7 @@
 	cval->channels = 1;
 	cval->min = 1;
 	cval->max = num_ins;
+	cval->res = 1;
 	cval->initialized = 1;
 
 	namelist = kmalloc(sizeof(char *) * num_ins, GFP_KERNEL);
@@ -1430,6 +1475,8 @@
 	state.buffer = buffer;
 	state.buflen = buflen;
 	state.ctrlif = ctrlif;
+	state.vendor = dev->idVendor;
+	state.product = dev->idProduct;
 
 	/* check the mapping table */
 	for (map = usbmix_ctl_maps; map->vendor; map++) {
diff -Nru a/sound/usb/usbmixer_maps.c b/sound/usb/usbmixer_maps.c
--- a/sound/usb/usbmixer_maps.c	Mon Dec 23 21:22:00 2002
+++ b/sound/usb/usbmixer_maps.c	Mon Dec 23 21:22:00 2002
@@ -39,9 +39,9 @@
 /*
  * Topology of SB Extigy (see on the wide screen :)
 
-USB_IN[1] --->FU[2]------------------------------+->MU[16]-->PE[17]-+->FU[18]--+->EU[27]--+->EU[21]-->FU[22]--+->FU[23] > Dig_OUT[24]
+USB_IN[1] --->FU[2]------------------------------+->MU[16]-->PU[17]-+->FU[18]--+->EU[27]--+->EU[21]-->FU[22]--+->FU[23] > Dig_OUT[24]
                                                  ^                  |          |          |                   |
-USB_IN[3] -+->SU[5]-->FU[6]--+->MU[14] ->PE[15]->+                  |          |          |                   +->FU[25] > Dig_OUT[26]
+USB_IN[3] -+->SU[5]-->FU[6]--+->MU[14] ->PU[15]->+                  |          |          |                   +->FU[25] > Dig_OUT[26]
            ^                 ^                   |                  |          |          |
 Dig_IN[4] -+                 |                   |                  |          |          +->FU[28]---------------------> Spk_OUT[19]
                              |                   |                  |          |
@@ -69,9 +69,9 @@
 	{ 12, "Capture" }, /* FU */
 	/* 13: OT pcm capture */
 	/* 14: MU (w/o controls) */
-	/* 15: PE (3D enh) */
+	/* 15: PU (3D enh) */
 	/* 16: MU (w/o controls) */
-	/* 17: PE (updown) */		/* FIXME: what control? */
+	/* 17: PU (updown) */		/* FIXME: what control? */
 	{ 18, "Tone Control - Bass", USB_FEATURE_BASS }, /* FU */
 	{ 18, "Tone Control - Treble", USB_FEATURE_TREBLE }, /* FU */
 	{ 18, "Master Playback" }, /* FU; others */
diff -Nru a/sound/usb/usbquirks.h b/sound/usb/usbquirks.h
--- a/sound/usb/usbquirks.h	Mon Dec 23 21:21:53 2002
+++ b/sound/usb/usbquirks.h	Mon Dec 23 21:21:53 2002
@@ -161,6 +161,60 @@
 		.type = QUIRK_MIDI_YAMAHA
 	}
 },
+{
+	USB_DEVICE(0x0499, 0x1012),
+	.driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
+		.vendor_name = "Yamaha",
+		.product_name = "TYROS",
+		.ifnum = QUIRK_ANY_INTERFACE,
+		.type = QUIRK_MIDI_YAMAHA
+	}
+},
+{
+	USB_DEVICE(0x0499, 0x1013),
+	.driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
+		.vendor_name = "Yamaha",
+		.product_name = "PF-500",
+		.ifnum = QUIRK_ANY_INTERFACE,
+		.type = QUIRK_MIDI_YAMAHA
+	}
+},
+{
+	USB_DEVICE(0x0499, 0x1014),
+	.driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
+		.vendor_name = "Yamaha",
+		.product_name = "S90",
+		.ifnum = QUIRK_ANY_INTERFACE,
+		.type = QUIRK_MIDI_YAMAHA
+	}
+},
+{
+	USB_DEVICE(0x0499, 0x5002),
+	.driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
+		.vendor_name = "Yamaha",
+		.product_name = "DME32",
+		.ifnum = QUIRK_ANY_INTERFACE,
+		.type = QUIRK_MIDI_YAMAHA
+	}
+},
+{
+	USB_DEVICE(0x0499, 0x5003),
+	.driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
+		.vendor_name = "Yamaha",
+		.product_name = "DM2000",
+		.ifnum = QUIRK_ANY_INTERFACE,
+		.type = QUIRK_MIDI_YAMAHA
+	}
+},
+{
+	USB_DEVICE(0x0499, 0x5004),
+	.driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
+		.vendor_name = "Yamaha",
+		.product_name = "02R96",
+		.ifnum = QUIRK_ANY_INTERFACE,
+		.type = QUIRK_MIDI_YAMAHA
+	}
+},
 
 /*
  * Once upon a time people thought, "Wouldn't it be nice if there was a
@@ -421,6 +475,20 @@
 		}
 	}
 },
+{
+	USB_DEVICE(0x0582, 0x0033),
+	.driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
+		.vendor_name = "EDIROL",
+		.product_name = "PCR",
+		.ifnum = 0,
+		.type = QUIRK_MIDI_FIXED_ENDPOINT,
+		.data = & (const snd_usb_midi_endpoint_info_t) {
+			.epnum = -1,
+			.out_cables = 0x0003,
+			.in_cables  = 0x0007
+		}
+	}
+},
 
 /* Midiman/M-Audio devices */
 {
@@ -430,7 +498,10 @@
 		.product_name = "MidiSport 2x2",
 		.ifnum = QUIRK_ANY_INTERFACE,
 		.type = QUIRK_MIDI_MIDIMAN,
-		.data = (void*) 2
+		.data = & (const snd_usb_midi_endpoint_info_t) {
+			.out_cables = 0x0003,
+			.in_cables  = 0x0003
+		}
 	}
 },
 {
@@ -440,7 +511,10 @@
 		.product_name = "MidiSport 1x1",
 		.ifnum = QUIRK_ANY_INTERFACE,
 		.type = QUIRK_MIDI_MIDIMAN,
-		.data = (void*) 1
+		.data = & (const snd_usb_midi_endpoint_info_t) {
+			.out_cables = 0x0001,
+			.in_cables  = 0x0001
+		}
 	}
 },
 {
@@ -450,7 +524,10 @@
 		.product_name = "Keystation",
 		.ifnum = QUIRK_ANY_INTERFACE,
 		.type = QUIRK_MIDI_MIDIMAN,
-		.data = (void*) 1
+		.data = & (const snd_usb_midi_endpoint_info_t) {
+			.out_cables = 0x0001,
+			.in_cables  = 0x0001
+		}
 	}
 },
 {
@@ -460,7 +537,10 @@
 		.product_name = "MidiSport 4x4",
 		.ifnum = QUIRK_ANY_INTERFACE,
 		.type = QUIRK_MIDI_MIDIMAN,
-		.data = (void*) 4
+		.data = & (const snd_usb_midi_endpoint_info_t) {
+			.out_cables = 0x000f,
+			.in_cables  = 0x000f
+		}
 	}
 },
 {
@@ -470,7 +550,23 @@
 		.product_name = "MidiSport 8x8",
 		.ifnum = QUIRK_ANY_INTERFACE,
 		.type = QUIRK_MIDI_MIDIMAN,
-		.data = (void*) 9
+		.data = & (const snd_usb_midi_endpoint_info_t) {
+			.out_cables = 0x01ff,
+			.in_cables  = 0x01ff
+		}
+	}
+},
+{
+	USB_DEVICE_VENDOR_SPEC(0x0763, 0x1041),
+	.driver_info = (unsigned long) & (const snd_usb_audio_quirk_t) {
+		.vendor_name = "M-Audio",
+		.product_name = "MidiSport 2x4",
+		.ifnum = QUIRK_ANY_INTERFACE,
+		.type = QUIRK_MIDI_MIDIMAN,
+		.data = & (const snd_usb_midi_endpoint_info_t) {
+			.out_cables = 0x000f,
+			.in_cables  = 0x0003
+		}
 	}
 },
 {
@@ -480,7 +576,10 @@
 		.product_name = "Quattro",
 		.ifnum = 9,
 		.type = QUIRK_MIDI_MIDIMAN,
-		.data = (void*) 1
+		.data = & (const snd_usb_midi_endpoint_info_t) {
+			.out_cables = 0x0001,
+			.in_cables  = 0x0001
+		}
 	}
 },
 {
@@ -490,7 +589,10 @@
 		.product_name = "AudioPhile",
 		.ifnum = 9,
 		.type = QUIRK_MIDI_MIDIMAN,
-		.data = (void*) 1
+		.data = & (const snd_usb_midi_endpoint_info_t) {
+			.out_cables = 0x0001,
+			.in_cables  = 0x0001
+		}
 	}
 },
 
